Search in sources :

Example 1 with NamedElement

use of org.eclipse.xtend.lib.macro.declaration.NamedElement 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 2 with NamedElement

use of org.eclipse.xtend.lib.macro.declaration.NamedElement 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)

Example 3 with NamedElement

use of org.eclipse.xtend.lib.macro.declaration.NamedElement in project xtext-xtend by eclipse.

the class CompilationUnitImpl method translateAnnotationValue.

public Object translateAnnotationValue(final JvmAnnotationValue value, final boolean isArray) {
    Pair<List<?>, Class<?>> _switchResult = null;
    boolean _matched = false;
    if (value instanceof JvmCustomAnnotationValue) {
        if ((((JvmCustomAnnotationValue) value).getValues().isEmpty() && isArray)) {
            _matched = true;
            List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
            Class<?> _arrayComponentType = this.toArrayComponentType(this.findExpectedType(value));
            _switchResult = Pair.<List<?>, Class<?>>of(_emptyList, _arrayComponentType);
        }
    }
    if (!_matched) {
        if (value instanceof JvmCustomAnnotationValue) {
            _matched = true;
            final JvmTypeReference expectedType = this.findExpectedType(value);
            final Function1<XExpression, Object> _function = (XExpression it) -> {
                return this.evaluate(it, expectedType);
            };
            final Object result = IterableExtensions.<Object>head(IterableExtensions.<XExpression, Object>map(Iterables.<XExpression>filter(((JvmCustomAnnotationValue) value).getValues(), XExpression.class), _function));
            return this.translateAnnotationValue(result, expectedType, isArray);
        }
    }
    if (!_matched) {
        if (value instanceof JvmTypeAnnotationValue) {
            _matched = true;
            final Function1<JvmTypeReference, TypeReference> _function = (JvmTypeReference it) -> {
                return this.toTypeReference(it);
            };
            List<TypeReference> _map = ListExtensions.<JvmTypeReference, TypeReference>map(((JvmTypeAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, TypeReference.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmAnnotationAnnotationValue) {
            _matched = true;
            final Function1<JvmAnnotationReference, AnnotationReference> _function = (JvmAnnotationReference it) -> {
                return this.toAnnotationReference(it);
            };
            List<AnnotationReference> _map = ListExtensions.<JvmAnnotationReference, AnnotationReference>map(((JvmAnnotationAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, AnnotationReference.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmStringAnnotationValue) {
            _matched = true;
            EList<String> _values = ((JvmStringAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, String.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmBooleanAnnotationValue) {
            _matched = true;
            EList<Boolean> _values = ((JvmBooleanAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, boolean.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmIntAnnotationValue) {
            _matched = true;
            EList<Integer> _values = ((JvmIntAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, int.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmByteAnnotationValue) {
            _matched = true;
            EList<Byte> _values = ((JvmByteAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, byte.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmCharAnnotationValue) {
            _matched = true;
            EList<Character> _values = ((JvmCharAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, char.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmDoubleAnnotationValue) {
            _matched = true;
            EList<Double> _values = ((JvmDoubleAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, double.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmEnumAnnotationValue) {
            _matched = true;
            final Function1<JvmEnumerationLiteral, NamedElement> _function = (JvmEnumerationLiteral it) -> {
                return this.toNamedElement(it);
            };
            List<NamedElement> _map = ListExtensions.<JvmEnumerationLiteral, NamedElement>map(((JvmEnumAnnotationValue) value).getValues(), _function);
            _switchResult = Pair.<List<?>, Class<?>>of(_map, EnumerationValueDeclaration.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmFloatAnnotationValue) {
            _matched = true;
            EList<Float> _values = ((JvmFloatAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, float.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmLongAnnotationValue) {
            _matched = true;
            EList<Long> _values = ((JvmLongAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, long.class);
        }
    }
    if (!_matched) {
        if (value instanceof JvmShortAnnotationValue) {
            _matched = true;
            EList<Short> _values = ((JvmShortAnnotationValue) value).getValues();
            _switchResult = Pair.<List<?>, Class<?>>of(_values, short.class);
        }
    }
    if (!_matched) {
        List<Object> _emptyList = CollectionLiterals.<Object>emptyList();
        _switchResult = Pair.<List<?>, Class<?>>of(_emptyList, Object.class);
    }
    final Pair<List<?>, Class<?>> result = _switchResult;
    if (isArray) {
        return this.toArrayOfType(result.getKey(), result.getValue());
    } else {
        return IterableExtensions.head(result.getKey());
    }
}
Also used : JvmEnumAnnotationValue(org.eclipse.xtext.common.types.JvmEnumAnnotationValue) JvmByteAnnotationValue(org.eclipse.xtext.common.types.JvmByteAnnotationValue) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) JvmLongAnnotationValue(org.eclipse.xtext.common.types.JvmLongAnnotationValue) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList) JvmStringAnnotationValue(org.eclipse.xtext.common.types.JvmStringAnnotationValue) JvmFloatAnnotationValue(org.eclipse.xtext.common.types.JvmFloatAnnotationValue) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) EObject(org.eclipse.emf.ecore.EObject) NamedElement(org.eclipse.xtend.lib.macro.declaration.NamedElement) EnumerationValueDeclaration(org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration) JvmTypeAnnotationValue(org.eclipse.xtext.common.types.JvmTypeAnnotationValue) JvmBooleanAnnotationValue(org.eclipse.xtext.common.types.JvmBooleanAnnotationValue) JvmIntAnnotationValue(org.eclipse.xtext.common.types.JvmIntAnnotationValue) JvmCharAnnotationValue(org.eclipse.xtext.common.types.JvmCharAnnotationValue) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmShortAnnotationValue(org.eclipse.xtext.common.types.JvmShortAnnotationValue) JvmDoubleAnnotationValue(org.eclipse.xtext.common.types.JvmDoubleAnnotationValue) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XExpression(org.eclipse.xtext.xbase.XExpression) JvmAnnotationAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationAnnotationValue)

Aggregations

NamedElement (org.eclipse.xtend.lib.macro.declaration.NamedElement)3 List (java.util.List)2 XtendAnnotationTarget (org.eclipse.xtend.core.xtend.XtendAnnotationTarget)2 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 Declaration (org.eclipse.xtend.lib.macro.declaration.Declaration)2 MutableNamedElement (org.eclipse.xtend.lib.macro.declaration.MutableNamedElement)2 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)2 ArrayList (java.util.ArrayList)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 RegisterGlobalsContextImpl (org.eclipse.xtend.core.macro.RegisterGlobalsContextImpl)1 ValidationContextImpl (org.eclipse.xtend.core.macro.ValidationContextImpl)1 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)1 RegisterGlobalsParticipant (org.eclipse.xtend.lib.macro.RegisterGlobalsParticipant)1 ValidationParticipant (org.eclipse.xtend.lib.macro.ValidationParticipant)1 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)1 Element (org.eclipse.xtend.lib.macro.declaration.Element)1 EnumerationValueDeclaration (org.eclipse.xtend.lib.macro.declaration.EnumerationValueDeclaration)1 TypeReference (org.eclipse.xtend.lib.macro.declaration.TypeReference)1