Search in sources :

Example 1 with XtendMember

use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.

the class XtendFormatter method _format.

protected void _format(final XtendEnum enumeration, @Extension final IFormattableDocument format) {
    this.formatAnnotations(enumeration, format, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations);
    this.formatModifiers(enumeration, format);
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
    };
    format.append(this.textRegionExtensions.regionFor(enumeration).keyword("enum"), _function);
    final ISemanticRegion open = this.textRegionExtensions.regionFor(enumeration).keyword("{");
    final ISemanticRegion close = this.textRegionExtensions.regionFor(enumeration).keyword("}");
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
        it.indent();
    };
    format.<ISemanticRegion, ISemanticRegion>interior(open, close, _function_1);
    format.prepend(open, XbaseFormatterPreferenceKeys.bracesInNewLine);
    boolean _isEmpty = enumeration.getMembers().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        format.append(open, XtendFormatterPreferenceKeys.blankLinesBeforeFirstMember);
        int _size = enumeration.getMembers().size();
        int _minus = (_size - 1);
        IntegerRange _upTo = new IntegerRange(0, _minus);
        for (final Integer i : _upTo) {
            {
                final XtendMember current = enumeration.getMembers().get((i).intValue());
                format.<XtendMember>format(current);
                int _size_1 = enumeration.getMembers().size();
                int _minus_1 = (_size_1 - 1);
                boolean _lessThan = ((i).intValue() < _minus_1);
                if (_lessThan) {
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                        it.noSpace();
                    };
                    format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(current).keyword(","), _function_2), XtendFormatterPreferenceKeys.blankLinesBetweenEnumLiterals);
                } else {
                    format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesAfterLastMember);
                }
            }
        }
    } else {
        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
            it.newLine();
        };
        format.append(open, _function_2);
    }
}
Also used : IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint)

Example 2 with XtendMember

use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.

the class XtendFormatter method formatBody.

protected ISemanticRegion formatBody(final XtendTypeDeclaration type, @Extension final IFormattableDocument format) {
    ISemanticRegion _xblockexpression = null;
    {
        final ISemanticRegion open = this.textRegionExtensions.regionFor(type).keyword("{");
        final ISemanticRegion close = this.textRegionExtensions.regionFor(type).keyword("}");
        final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
            it.indent();
        };
        format.<ISemanticRegion, ISemanticRegion>interior(open, close, _function);
        format.prepend(open, XbaseFormatterPreferenceKeys.bracesInNewLine);
        ISemanticRegion _xifexpression = null;
        boolean _isEmpty = type.getMembers().isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            format.append(open, XtendFormatterPreferenceKeys.blankLinesBeforeFirstMember);
            int _size = type.getMembers().size();
            int _minus = (_size - 1);
            IntegerRange _upTo = new IntegerRange(0, _minus);
            for (final Integer i : _upTo) {
                {
                    final XtendMember current = type.getMembers().get((i).intValue());
                    format.<XtendMember>format(current);
                    int _size_1 = type.getMembers().size();
                    int _minus_1 = (_size_1 - 1);
                    boolean _lessThan = ((i).intValue() < _minus_1);
                    if (_lessThan) {
                        final XtendMember next = type.getMembers().get(((i).intValue() + 1));
                        if (((current instanceof XtendField) && (next instanceof XtendField))) {
                            format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFields);
                        } else {
                            if (((current instanceof XtendFunction) && (next instanceof XtendFunction))) {
                                format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenMethods);
                            } else {
                                format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFieldsAndMethods);
                            }
                        }
                    } else {
                        final XtendMember member = type.getMembers().get((i).intValue());
                        format.<XtendMember>append(member, XtendFormatterPreferenceKeys.blankLinesAfterLastMember);
                    }
                }
            }
        } else {
            final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                it.newLine();
            };
            _xifexpression = format.append(open, _function_1);
        }
        _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 3 with XtendMember

use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.

the class AnnotationProcessor method inferencePhase.

public Object inferencePhase(final ActiveAnnotationContext ctx, final CancelIndicator monitor) {
    Object _xblockexpression = null;
    {
        final Stopwatches.StoppedTask task = Stopwatches.forTask("[macros] inferencePhase (AnnotationProcessor.inferencePhase)");
        task.start();
        Object _xtrycatchfinallyexpression = null;
        try {
            Object _switchResult = null;
            Object _processorInstance = ctx.getProcessorInstance();
            final Object processor = _processorInstance;
            boolean _matched = false;
            if (processor instanceof TransformationParticipant) {
                _matched = true;
                Object _xblockexpression_1 = null;
                {
                    final TransformationContextImpl modifyCtx = this.modifyContextProvider.get();
                    modifyCtx.setUnit(ctx.getCompilationUnit());
                    final Runnable _function = () -> {
                        final Function1<XtendAnnotationTarget, MutableNamedElement> _function_1 = (XtendAnnotationTarget it) -> {
                            Declaration _switchResult_1 = null;
                            boolean _matched_1 = false;
                            if (it instanceof XtendMember) {
                                _matched_1 = true;
                                _switchResult_1 = ctx.getCompilationUnit().toXtendMemberDeclaration(((XtendMember) it));
                            }
                            if (!_matched_1) {
                                if (it instanceof XtendParameter) {
                                    _matched_1 = true;
                                    _switchResult_1 = ctx.getCompilationUnit().toXtendParameterDeclaration(((XtendParameter) it));
                                }
                            }
                            final Declaration xtendMember = _switchResult_1;
                            Element _primaryGeneratedJavaElement = modifyCtx.getPrimaryGeneratedJavaElement(xtendMember);
                            return ((MutableNamedElement) _primaryGeneratedJavaElement);
                        };
                        final List<MutableNamedElement> map = ListExtensions.<XtendAnnotationTarget, MutableNamedElement>map(ctx.getAnnotatedSourceElements(), _function_1);
                        ((TransformationParticipant<MutableNamedElement>) processor).doTransform(map, modifyCtx);
                    };
                    _xblockexpression_1 = this.runWithCancelIndiciator(ctx, monitor, _function);
                }
                _switchResult = _xblockexpression_1;
            }
            _xtrycatchfinallyexpression = _switchResult;
        } finally {
            task.stop();
        }
        _xblockexpression = _xtrycatchfinallyexpression;
    }
    return _xblockexpression;
}
Also used : MutableNamedElement(org.eclipse.xtend.lib.macro.declaration.MutableNamedElement) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) MutableNamedElement(org.eclipse.xtend.lib.macro.declaration.MutableNamedElement) NamedElement(org.eclipse.xtend.lib.macro.declaration.NamedElement) Element(org.eclipse.xtend.lib.macro.declaration.Element) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) TransformationParticipant(org.eclipse.xtend.lib.macro.TransformationParticipant) List(java.util.List) Declaration(org.eclipse.xtend.lib.macro.declaration.Declaration) TransformationContextImpl(org.eclipse.xtend.core.macro.TransformationContextImpl)

Example 4 with XtendMember

use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.

the class AnnotationProcessor method indexingPhase.

/**
 * gets called from Xtend compiler, during "model inference", i.e. translation of Xtend AST to Java AST
 */
public Object indexingPhase(final ActiveAnnotationContext ctx, final IJvmDeclaredTypeAcceptor acceptor, final CancelIndicator monitor) {
    Object _xblockexpression = null;
    {
        final Stopwatches.StoppedTask task = Stopwatches.forTask("[macros] indexingPhase (AnnotationProcessor.indexingPhase)");
        task.start();
        Object _xtrycatchfinallyexpression = null;
        try {
            Object _switchResult = null;
            Object _processorInstance = ctx.getProcessorInstance();
            final Object processor = _processorInstance;
            boolean _matched = false;
            if (processor instanceof RegisterGlobalsParticipant) {
                _matched = true;
                Object _xblockexpression_1 = null;
                {
                    final RegisterGlobalsContextImpl registerGlobalsCtx = this.registerGlobalsContextProvider.get();
                    registerGlobalsCtx.setAcceptor(acceptor);
                    registerGlobalsCtx.setCompilationUnit(ctx.getCompilationUnit());
                    final Runnable _function = () -> {
                        final Function1<XtendAnnotationTarget, Declaration> _function_1 = (XtendAnnotationTarget it) -> {
                            Declaration _switchResult_1 = null;
                            boolean _matched_1 = false;
                            if (it instanceof XtendMember) {
                                _matched_1 = true;
                                _switchResult_1 = ctx.getCompilationUnit().toXtendMemberDeclaration(((XtendMember) it));
                            }
                            if (!_matched_1) {
                                if (it instanceof XtendParameter) {
                                    _matched_1 = true;
                                    _switchResult_1 = ctx.getCompilationUnit().toXtendParameterDeclaration(((XtendParameter) it));
                                }
                            }
                            final Declaration xtendMember = _switchResult_1;
                            return xtendMember;
                        };
                        ((RegisterGlobalsParticipant<NamedElement>) processor).doRegisterGlobals(ListExtensions.<XtendAnnotationTarget, Declaration>map(ctx.getAnnotatedSourceElements(), _function_1), registerGlobalsCtx);
                    };
                    _xblockexpression_1 = this.runWithCancelIndiciator(ctx, monitor, _function);
                }
                _switchResult = _xblockexpression_1;
            }
            _xtrycatchfinallyexpression = _switchResult;
        } finally {
            task.stop();
        }
        _xblockexpression = _xtrycatchfinallyexpression;
    }
    return _xblockexpression;
}
Also used : XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) RegisterGlobalsParticipant(org.eclipse.xtend.lib.macro.RegisterGlobalsParticipant) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Declaration(org.eclipse.xtend.lib.macro.declaration.Declaration) MutableNamedElement(org.eclipse.xtend.lib.macro.declaration.MutableNamedElement) NamedElement(org.eclipse.xtend.lib.macro.declaration.NamedElement) RegisterGlobalsContextImpl(org.eclipse.xtend.core.macro.RegisterGlobalsContextImpl)

Example 5 with XtendMember

use of org.eclipse.xtend.core.xtend.XtendMember in project xtext-xtend by eclipse.

the class AnnotationProcessor method validationPhase.

public Object validationPhase(final ActiveAnnotationContext ctx, final CancelIndicator monitor) {
    Object _xblockexpression = null;
    {
        final Stopwatches.StoppedTask task = Stopwatches.forTask("[macros] validationPhase (AnnotationProcessor.validationPhase)");
        task.start();
        Object _xtrycatchfinallyexpression = null;
        try {
            Object _switchResult = null;
            Object _processorInstance = ctx.getProcessorInstance();
            final Object processor = _processorInstance;
            boolean _matched = false;
            if (processor instanceof ValidationParticipant) {
                _matched = true;
                Object _xblockexpression_1 = null;
                {
                    final ValidationContextImpl validationContext = this.validationContextProvider.get();
                    validationContext.setUnit(ctx.getCompilationUnit());
                    final Runnable _function = () -> {
                        final Function1<XtendAnnotationTarget, NamedElement> _function_1 = (XtendAnnotationTarget it) -> {
                            Declaration _switchResult_1 = null;
                            boolean _matched_1 = false;
                            if (it instanceof XtendMember) {
                                _matched_1 = true;
                                _switchResult_1 = ctx.getCompilationUnit().toXtendMemberDeclaration(((XtendMember) it));
                            }
                            if (!_matched_1) {
                                if (it instanceof XtendParameter) {
                                    _matched_1 = true;
                                    _switchResult_1 = ctx.getCompilationUnit().toXtendParameterDeclaration(((XtendParameter) it));
                                }
                            }
                            final Declaration xtendMember = _switchResult_1;
                            Element _primaryGeneratedJavaElement = validationContext.getPrimaryGeneratedJavaElement(xtendMember);
                            return ((NamedElement) _primaryGeneratedJavaElement);
                        };
                        final List<NamedElement> map = ListExtensions.<XtendAnnotationTarget, NamedElement>map(ctx.getAnnotatedSourceElements(), _function_1);
                        ((ValidationParticipant<NamedElement>) processor).doValidate(map, validationContext);
                    };
                    _xblockexpression_1 = this.runWithCancelIndiciator(ctx, monitor, _function);
                }
                _switchResult = _xblockexpression_1;
            }
            _xtrycatchfinallyexpression = _switchResult;
        } finally {
            task.stop();
        }
        _xblockexpression = _xtrycatchfinallyexpression;
    }
    return _xblockexpression;
}
Also used : ValidationParticipant(org.eclipse.xtend.lib.macro.ValidationParticipant) ValidationContextImpl(org.eclipse.xtend.core.macro.ValidationContextImpl) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) MutableNamedElement(org.eclipse.xtend.lib.macro.declaration.MutableNamedElement) NamedElement(org.eclipse.xtend.lib.macro.declaration.NamedElement) Element(org.eclipse.xtend.lib.macro.declaration.Element) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) List(java.util.List) Declaration(org.eclipse.xtend.lib.macro.declaration.Declaration) MutableNamedElement(org.eclipse.xtend.lib.macro.declaration.MutableNamedElement) NamedElement(org.eclipse.xtend.lib.macro.declaration.NamedElement)

Aggregations

XtendMember (org.eclipse.xtend.core.xtend.XtendMember)175 Test (org.junit.Test)140 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)131 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)119 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)101 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)91 XExpression (org.eclipse.xtext.xbase.XExpression)84 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)57 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)56 XtendField (org.eclipse.xtend.core.xtend.XtendField)33 EObject (org.eclipse.emf.ecore.EObject)17 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)14 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)12 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)10 XtendConstructor (org.eclipse.xtend.core.xtend.XtendConstructor)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)8 JvmType (org.eclipse.xtext.common.types.JvmType)8