Search in sources :

Example 1 with CodeGenerationContextImpl

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

the class XtendGenerator method callMacroProcessors.

public void callMacroProcessors(final Resource input) {
    final ActiveAnnotationContexts ctxs = ActiveAnnotationContexts.find(input);
    if ((ctxs == null)) {
        return;
    }
    try {
        ctxs.before(ActiveAnnotationContexts.AnnotationCallback.GENERATION);
        Collection<ActiveAnnotationContext> _values = ctxs.getContexts().values();
        for (final ActiveAnnotationContext context : _values) {
            try {
                Object _processorInstance = context.getProcessorInstance();
                final Object processor = _processorInstance;
                boolean _matched = false;
                if (processor instanceof CodeGenerationParticipant) {
                    _matched = true;
                    CodeGenerationContextImpl _codeGenerationContextImpl = new CodeGenerationContextImpl();
                    final Procedure1<CodeGenerationContextImpl> _function = (CodeGenerationContextImpl it) -> {
                        it.setUnit(context.getCompilationUnit());
                    };
                    final CodeGenerationContextImpl codeGenServices = ObjectExtensions.<CodeGenerationContextImpl>operator_doubleArrow(_codeGenerationContextImpl, _function);
                    final Function1<XtendAnnotationTarget, MemberDeclaration> _function_1 = (XtendAnnotationTarget it) -> {
                        return context.getCompilationUnit().toXtendMemberDeclaration(((XtendMember) it));
                    };
                    final List<MemberDeclaration> elements = ListExtensions.<XtendAnnotationTarget, MemberDeclaration>map(context.getAnnotatedSourceElements(), _function_1);
                    ((CodeGenerationParticipant<NamedElement>) processor).doGenerateCode(elements, codeGenServices);
                }
            } catch (final Throwable _t) {
                if (_t instanceof Throwable) {
                    final Throwable t = (Throwable) _t;
                    this.operationCanceledManager.propagateAsErrorIfCancelException(t);
                    context.handleProcessingError(input, t);
                } else {
                    throw Exceptions.sneakyThrow(_t);
                }
            }
        }
    } finally {
        ctxs.after(ActiveAnnotationContexts.AnnotationCallback.GENERATION);
    }
}
Also used : MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) ActiveAnnotationContexts(org.eclipse.xtend.core.macro.ActiveAnnotationContexts) ActiveAnnotationContext(org.eclipse.xtend.core.macro.ActiveAnnotationContext) CodeGenerationParticipant(org.eclipse.xtend.lib.macro.CodeGenerationParticipant) CodeGenerationContextImpl(org.eclipse.xtend.core.macro.CodeGenerationContextImpl) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)1 ActiveAnnotationContext (org.eclipse.xtend.core.macro.ActiveAnnotationContext)1 ActiveAnnotationContexts (org.eclipse.xtend.core.macro.ActiveAnnotationContexts)1 CodeGenerationContextImpl (org.eclipse.xtend.core.macro.CodeGenerationContextImpl)1 XtendAnnotationTarget (org.eclipse.xtend.core.xtend.XtendAnnotationTarget)1 CodeGenerationParticipant (org.eclipse.xtend.lib.macro.CodeGenerationParticipant)1 MemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MemberDeclaration)1