Search in sources :

Example 91 with XExpression

use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.

the class ExtractMethodRefactoring method initialize.

public boolean initialize(XtextEditor editor, List<XExpression> selectedExpressions, boolean doSave) {
    if (selectedExpressions.isEmpty() || editor.getDocument() == null)
        return false;
    this.document = editor.getDocument();
    this.doSave = doSave;
    this.editor = editor;
    this.expressions = calculateExpressions(selectedExpressions);
    this.firstExpression = this.expressions.get(0);
    this.originalMethod = EcoreUtil2.getContainerOfType(firstExpression, XtendFunction.class);
    this.lastExpression = this.expressions.get(this.expressions.size() - 1);
    this.resourceURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(firstExpression).trimFragment();
    this.xtendClass = EcoreUtil2.getContainerOfType(firstExpression, XtendClass.class);
    if (xtendClass == null || originalMethod == null)
        return false;
    this.visibility = JvmVisibility.PROTECTED;
    this.isStatic = originalMethod.isStatic();
    this.isExplicitlyDeclareReturnType = true;
    XExpression successorExpression = expressionUtil.findSuccessorExpressionForVariableDeclaration(lastExpression);
    nameUtil.setFeatureScopeContext(successorExpression);
    rewriter = rewriterFactory.create(document, (XtextResource) firstExpression.eResource());
    return true;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XExpression(org.eclipse.xtext.xbase.XExpression) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 92 with XExpression

use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.

the class XtendHighlightingCalculator method highlightElement.

protected void highlightElement(XtendFunction function, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
    highlightFeature(acceptor, function, XtendPackage.Literals.XTEND_FUNCTION__NAME, METHOD);
    XExpression rootExpression = function.getExpression();
    highlightRichStrings(rootExpression, acceptor);
    CreateExtensionInfo createExtensionInfo = function.getCreateExtensionInfo();
    if (createExtensionInfo != null) {
        highlightRichStrings(createExtensionInfo.getCreateExpression(), acceptor);
    }
}
Also used : XExpression(org.eclipse.xtext.xbase.XExpression) CreateExtensionInfo(org.eclipse.xtend.core.xtend.CreateExtensionInfo)

Example 93 with XExpression

use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.

the class XtendHighlightingCalculator method highlightElement.

protected void highlightElement(XtendField field, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
    highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, FIELD);
    if (field.isStatic()) {
        highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, STATIC_FIELD);
        if (field.isFinal()) {
            highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, STATIC_FINAL_FIELD);
        }
    }
    XExpression initializer = field.getInitialValue();
    highlightRichStrings(initializer, acceptor);
}
Also used : XExpression(org.eclipse.xtext.xbase.XExpression)

Example 94 with XExpression

use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendField field, @Extension final IFormattableDocument document) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.append(this.textRegionExtensions.regionFor(field).keyword("extension"), _function);
    this.formatAnnotations(field, document, XbaseFormatterPreferenceKeys.newLineAfterFieldAnnotations);
    this.formatModifiers(field, document);
    String _name = field.getName();
    boolean _tripleNotEquals = (_name != null);
    if (_tripleNotEquals) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        document.<JvmTypeReference>append(field.getType(), _function_1);
    }
    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    document.append(document.prepend(this.textRegionExtensions.regionFor(field).keyword("="), _function_2), _function_3);
    document.<JvmTypeReference>format(field.getType());
    document.<XExpression>format(field.getInitialValue());
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XExpression(org.eclipse.xtext.xbase.XExpression) RichString(org.eclipse.xtend.core.xtend.RichString)

Example 95 with XExpression

use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendFunction func, @Extension final IFormattableDocument format) {
    this.formatAnnotations(func, format, XbaseFormatterPreferenceKeys.newLineAfterMethodAnnotations);
    this.formatModifiers(func, format);
    boolean _isEmpty = func.getTypeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        format.append(this.textRegionExtensions.regionFor(func).keyword("<"), _function);
        EList<JvmTypeParameter> _typeParameters = func.getTypeParameters();
        for (final JvmTypeParameter arg : _typeParameters) {
            {
                format.<JvmTypeParameter>format(arg);
                final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                    it.noSpace();
                };
                final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                    it.oneSpace();
                };
                format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_1), _function_2);
            }
        }
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
            it.oneSpace();
        };
        format.append(format.prepend(this.textRegionExtensions.regionFor(func).keyword(">"), _function_1), _function_2);
    }
    final ISemanticRegion nameNode = this.textRegionExtensions.regionFor(func).feature(XtendPackage.Literals.XTEND_FUNCTION__NAME);
    ISemanticRegionFinder _immediatelyFollowing = null;
    if (nameNode != null) {
        _immediatelyFollowing = nameNode.immediatelyFollowing();
    }
    ISemanticRegion _keyword = null;
    if (_immediatelyFollowing != null) {
        _keyword = _immediatelyFollowing.keyword("(");
    }
    final ISemanticRegion open = _keyword;
    final ISemanticRegion close = this.textRegionExtensions.regionFor(func).keyword(")");
    final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.<JvmTypeReference>append(func.getReturnType(), _function_3);
    final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    format.prepend(open, _function_4);
    XExpression _expression = func.getExpression();
    boolean _tripleNotEquals = (_expression != null);
    if (_tripleNotEquals) {
        format.append(close, XbaseFormatterPreferenceKeys.bracesInNewLine);
    }
    this.formatCommaSeparatedList(func.getParameters(), open, close, format);
    format.<JvmTypeReference>format(func.getReturnType());
    format.<XExpression>format(func.getExpression());
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) ISemanticRegionFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionFinder)

Aggregations

XExpression (org.eclipse.xtext.xbase.XExpression)266 Test (org.junit.Test)134 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)97 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)86 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)85 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)84 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)83 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)64 EObject (org.eclipse.emf.ecore.EObject)40 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)37 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)29 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)28 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)25 XtendField (org.eclipse.xtend.core.xtend.XtendField)24 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)23 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)22 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)22 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)21 XtextResource (org.eclipse.xtext.resource.XtextResource)18 XClosure (org.eclipse.xtext.xbase.XClosure)18