Search in sources :

Example 51 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project xtext-core by eclipse.

the class SerializerFragment2 method genMethodCreateSequence.

private StringConcatenationClient genMethodCreateSequence() {
    StringConcatenationClient _xblockexpression = null;
    {
        final Function1<IGrammarConstraintProvider.IConstraint, Pair<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>> _function = (IGrammarConstraintProvider.IConstraint it) -> {
            return Pair.<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>of(it, it);
        };
        final Map<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint> superConstraints = SerializerFragment2.<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>toMap(IterableExtensions.<IGrammarConstraintProvider.IConstraint, Pair<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>>map(this._semanticSequencerExtensions.getGrammarConstraints(this._semanticSequencerExtensions.getSuperGrammar(this.getGrammar())), _function));
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("@Override");
                _builder.newLine();
                _builder.append("public void sequence(");
                _builder.append(ISerializationContext.class);
                _builder.append(" context, ");
                _builder.append(EObject.class);
                _builder.append(" semanticObject) {");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append(EPackage.class, "\t");
                _builder.append(" epackage = semanticObject.eClass().getEPackage();");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append(ParserRule.class, "\t");
                _builder.append(" rule = context.getParserRule();");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append(Action.class, "\t");
                _builder.append(" action = context.getAssignedAction();");
                _builder.newLineIfNotEmpty();
                _builder.append("\t");
                _builder.append(Set.class, "\t");
                _builder.append("<");
                _builder.append(Parameter.class, "\t");
                _builder.append("> parameters = context.getEnabledBooleanParameters();");
                _builder.newLineIfNotEmpty();
                {
                    Iterable<Pair<Integer, EPackage>> _indexed = IterableExtensions.<EPackage>indexed(SerializerFragment2.this.getAccessedPackages());
                    for (final Pair<Integer, EPackage> pkg : _indexed) {
                        _builder.append("\t");
                        {
                            Integer _key = pkg.getKey();
                            boolean _greaterThan = ((_key).intValue() > 0);
                            if (_greaterThan) {
                                _builder.append("else ");
                            }
                        }
                        _builder.append("if (epackage == ");
                        EPackage _value = pkg.getValue();
                        _builder.append(_value, "\t");
                        _builder.append(".");
                        String _packageLiteral = GenModelUtil2.getPackageLiteral();
                        _builder.append(_packageLiteral, "\t");
                        _builder.append(")");
                        _builder.newLineIfNotEmpty();
                        _builder.append("\t");
                        _builder.append("\t");
                        _builder.append("switch (semanticObject.eClass().getClassifierID()) {");
                        _builder.newLine();
                        {
                            Iterable<EClass> _accessedClasses = SerializerFragment2.this.getAccessedClasses(pkg.getValue());
                            for (final EClass type : _accessedClasses) {
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("case ");
                                EPackage _value_1 = pkg.getValue();
                                _builder.append(_value_1, "\t\t");
                                _builder.append(".");
                                String _intLiteral = GenModelUtil2.getIntLiteral(type, SerializerFragment2.this.getLanguage().getResourceSet());
                                _builder.append(_intLiteral, "\t\t");
                                _builder.append(":");
                                _builder.newLineIfNotEmpty();
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("\t");
                                StringConcatenationClient _genMethodCreateSequenceCaseBody = SerializerFragment2.this.genMethodCreateSequenceCaseBody(superConstraints, type);
                                _builder.append(_genMethodCreateSequenceCaseBody, "\t\t\t");
                                _builder.newLineIfNotEmpty();
                            }
                        }
                        _builder.append("\t");
                        _builder.append("\t");
                        _builder.append("}");
                        _builder.newLine();
                    }
                }
                _builder.append("\t");
                _builder.append("if (errorAcceptor != null)");
                _builder.newLine();
                _builder.append("\t\t");
                _builder.append("errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));");
                _builder.newLine();
                _builder.append("}");
                _builder.newLine();
            }
        };
        _xblockexpression = _client;
    }
    return _xblockexpression;
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) HashSet(java.util.HashSet) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) EPackage(org.eclipse.emf.ecore.EPackage) EClass(org.eclipse.emf.ecore.EClass) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) EObject(org.eclipse.emf.ecore.EObject) IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) Parameter(org.eclipse.xtext.Parameter) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 52 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project xtext-core by eclipse.

the class AbstractAntlrGrammarWithActionsGenerator method _dataTypeEbnf2.

@Override
protected String _dataTypeEbnf2(final UnorderedGroup it, final boolean supportActions) {
    String _xifexpression = null;
    if (supportActions) {
        String _xblockexpression = null;
        {
            final Function1<AbstractElement, Boolean> _function = (AbstractElement it_1) -> {
                boolean _isOptionalCardinality = GrammarUtil.isOptionalCardinality(it_1);
                return Boolean.valueOf((!_isOptionalCardinality));
            };
            final int mandatoryContent = IterableExtensions.size(IterableExtensions.<AbstractElement>filter(it.getElements(), _function));
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("(");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("{ ");
            _builder.newLine();
            _builder.append("\t  ");
            _builder.append("getUnorderedGroupHelper().enter(grammarAccess.");
            UnorderedGroup _originalElement = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
            String _gaRuleElementAccessor = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement));
            _builder.append(_gaRuleElementAccessor, "\t  ");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("(");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("(");
            _builder.newLine();
            {
                Iterable<Pair<Integer, AbstractElement>> _indexed = IterableExtensions.<AbstractElement>indexed(it.getElements());
                boolean _hasElements = false;
                for (final Pair<Integer, AbstractElement> element : _indexed) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate("|", "");
                    }
                    _builder.append("(");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("{getUnorderedGroupHelper().canSelect(grammarAccess.");
                    UnorderedGroup _originalElement_1 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
                    String _gaRuleElementAccessor_1 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_1));
                    _builder.append(_gaRuleElementAccessor_1, "\t");
                    _builder.append(", ");
                    Integer _key = element.getKey();
                    _builder.append(_key, "\t");
                    _builder.append(")}?=>(");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("{");
                    _builder.newLine();
                    _builder.append("\t\t\t");
                    _builder.append("getUnorderedGroupHelper().select(grammarAccess.");
                    UnorderedGroup _originalElement_2 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
                    String _gaRuleElementAccessor_2 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_2));
                    _builder.append(_gaRuleElementAccessor_2, "\t\t\t");
                    _builder.append(", ");
                    Integer _key_1 = element.getKey();
                    _builder.append(_key_1, "\t\t\t");
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t\t\t\t\t");
                    _builder.append("({true}?=>(");
                    String _dataTypeEbnf2 = this.dataTypeEbnf2(element.getValue(), supportActions);
                    _builder.append(_dataTypeEbnf2, "\t\t\t\t\t");
                    _builder.append("))");
                    {
                        boolean _isMultipleCardinality = GrammarUtil.isMultipleCardinality(element.getValue());
                        if (_isMultipleCardinality) {
                            _builder.append("+");
                        }
                    }
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("{ ");
                    _builder.newLine();
                    _builder.append("\t\t\t");
                    _builder.append("getUnorderedGroupHelper().returnFromSelection(grammarAccess.");
                    UnorderedGroup _originalElement_3 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
                    String _gaRuleElementAccessor_3 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_3));
                    _builder.append(_gaRuleElementAccessor_3, "\t\t\t");
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append(")");
                    _builder.newLine();
                    _builder.append(")");
                    _builder.newLine();
                }
            }
            _builder.append("\t\t");
            _builder.append(")");
            {
                if ((mandatoryContent != 0)) {
                    _builder.append("+");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("{getUnorderedGroupHelper().canLeave(grammarAccess.");
                    UnorderedGroup _originalElement_4 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
                    String _gaRuleElementAccessor_4 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_4));
                    _builder.append(_gaRuleElementAccessor_4, "\t\t");
                    _builder.append(")}?");
                } else {
                    _builder.append("*");
                }
            }
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(")");
            _builder.newLine();
            _builder.append(")");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("{ ");
            _builder.newLine();
            _builder.append("\t  ");
            _builder.append("getUnorderedGroupHelper().leave(grammarAccess.");
            UnorderedGroup _originalElement_5 = AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it);
            String _gaRuleElementAccessor_5 = this._grammarAccessExtensions.gaRuleElementAccessor(((AbstractElement) _originalElement_5));
            _builder.append(_gaRuleElementAccessor_5, "\t  ");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
            _xblockexpression = _builder.toString();
        }
        _xifexpression = _xblockexpression;
    } else {
        _xifexpression = super._dataTypeEbnf2(it, supportActions);
    }
    return _xifexpression;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 53 with Pair

use of org.eclipse.xtext.xbase.lib.Pair in project xtext-core by eclipse.

the class AntlrContentAssistGrammarGenerator method ruleImpl.

protected CharSequence ruleImpl(final UnorderedGroup it, final Grammar grammar, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
    _builder.append(_contentAssistRuleName);
    _builder.append("__");
    String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
    _builder.append(_gaElementIdentifier);
    _builder.append("__Impl");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("@init {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int stackSize = keepStackSize();");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("boolean selected = false;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append(":");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("(");
    _builder.newLine();
    {
        Iterable<Pair<Integer, AbstractElement>> _indexed = IterableExtensions.<AbstractElement>indexed(it.getElements());
        boolean _hasElements = false;
        for (final Pair<Integer, AbstractElement> element : _indexed) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate("|", "\t\t");
            }
            _builder.append("\t\t");
            _builder.append("( ");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("{getUnorderedGroupHelper().canSelect(grammarAccess.");
            String _gaRuleElementAccessor = this._grammarAccessExtensions.gaRuleElementAccessor(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
            _builder.append(_gaRuleElementAccessor, "\t\t\t");
            _builder.append(", ");
            Integer _key = element.getKey();
            _builder.append(_key, "\t\t\t");
            _builder.append(")}?=>(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t\t");
            _builder.append("getUnorderedGroupHelper().select(grammarAccess.");
            String _gaRuleElementAccessor_1 = this._grammarAccessExtensions.gaRuleElementAccessor(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
            _builder.append(_gaRuleElementAccessor_1, "\t\t\t\t\t");
            _builder.append(", ");
            Integer _key_1 = element.getKey();
            _builder.append(_key_1, "\t\t\t\t\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t\t");
            _builder.append("selected = true;");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("(");
            _builder.newLine();
            {
                boolean _isMultipleCardinality = GrammarUtil.isMultipleCardinality(element.getValue());
                if (_isMultipleCardinality) {
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("(");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("{ before(grammarAccess.");
                    String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess, "\t\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("(");
                    String _ebnf2 = this.ebnf2(element.getValue(), options, false);
                    _builder.append(_ebnf2, "\t\t\t\t\t\t");
                    _builder.append(")");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("{ after(grammarAccess.");
                    String _grammarElementAccess_1 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_1, "\t\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append(")");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("(");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("{ before(grammarAccess.");
                    String _grammarElementAccess_2 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_2, "\t\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("((");
                    String _ebnf2_1 = this.ebnf2(element.getValue(), options, false);
                    _builder.append(_ebnf2_1, "\t\t\t\t\t\t");
                    _builder.append(")=>");
                    String _ebnf2_2 = this.ebnf2(element.getValue(), options, false);
                    _builder.append(_ebnf2_2, "\t\t\t\t\t\t");
                    _builder.append(")*");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("{ after(grammarAccess.");
                    String _grammarElementAccess_3 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_3, "\t\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append(")");
                    _builder.newLine();
                } else {
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("{ before(grammarAccess.");
                    String _grammarElementAccess_4 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_4, "\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("(");
                    String _ebnf2_3 = this.ebnf2(element.getValue(), options, false);
                    _builder.append(_ebnf2_3, "\t\t\t\t\t");
                    _builder.append(")");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("{ after(grammarAccess.");
                    String _grammarElementAccess_5 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_5, "\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append(")");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append(")");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append(")");
            _builder.newLine();
        }
    }
    _builder.append("\t\t");
    _builder.append(")");
    _builder.newLine();
    _builder.append(";");
    _builder.newLine();
    _builder.append("finally {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("if (selected)");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("getUnorderedGroupHelper().returnFromSelection(grammarAccess.");
    String _gaRuleElementAccessor_2 = this._grammarAccessExtensions.gaRuleElementAccessor(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
    _builder.append(_gaRuleElementAccessor_2, "\t\t");
    _builder.append(");");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("restoreStackSize(stackSize);");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 54 with Pair

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

the class ActiveAnnotationContextProvider method computeContext.

public ActiveAnnotationContexts computeContext(final XtendFile file) {
    final Stopwatches.StoppedTask task = Stopwatches.forTask("[macros] findActiveAnnotations (ActiveAnnotationContextProvider.computeContext)");
    task.start();
    try {
        final ActiveAnnotationContexts result = ActiveAnnotationContexts.installNew(file.eResource());
        final CompilationUnitImpl compilationUnit = this.compilationUnitProvider.get();
        compilationUnit.setXtendFile(file);
        result.compilationUnit = compilationUnit;
        final IAcceptor<Pair<JvmAnnotationType, XAnnotation>> _function = (Pair<JvmAnnotationType, XAnnotation> it) -> {
            boolean _containsKey = result.getContexts().containsKey(it.getKey());
            boolean _not = (!_containsKey);
            if (_not) {
                final ActiveAnnotationContext fa = new ActiveAnnotationContext();
                fa.setCompilationUnit(compilationUnit);
                final JvmType processorType = this._xAnnotationExtensions.getProcessorType(it.getKey());
                try {
                    final Object processorInstance = this._processorInstanceForJvmTypeProvider.getProcessorInstance(processorType);
                    if ((processorInstance == null)) {
                        String _identifier = processorType.getIdentifier();
                        String _plus = ("Couldn\'t instantiate the annotation processor of type \'" + _identifier);
                        String _plus_1 = (_plus + "\'. This is usually the case when the processor resides in the same project as the annotated element.");
                        throw new IllegalStateException(_plus_1);
                    }
                    fa.setProcessorInstance(processorInstance);
                } catch (final Throwable _t) {
                    if (_t instanceof VirtualMachineError) {
                        final VirtualMachineError e = (VirtualMachineError) _t;
                        throw e;
                    } else if (_t instanceof Throwable) {
                        final Throwable e_1 = (Throwable) _t;
                        this.operationCanceledManager.propagateAsErrorIfCancelException(e_1);
                        StringConcatenation _builder = new StringConcatenation();
                        _builder.append("Problem while loading annotation processor: ");
                        String _switchResult = null;
                        boolean _matched = false;
                        if (e_1 instanceof ExceptionInInitializerError) {
                            _matched = true;
                            _switchResult = ((ExceptionInInitializerError) e_1).getException().getMessage();
                        }
                        if (!_matched) {
                            _switchResult = e_1.getMessage();
                        }
                        _builder.append(_switchResult);
                        final String msg = _builder.toString();
                        ActiveAnnotationContextProvider.logger.error(msg, e_1);
                        EList<Resource.Diagnostic> _errors = file.eResource().getErrors();
                        XAnnotation _value = it.getValue();
                        EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, msg, _value, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, (-1), null);
                        _errors.add(_eObjectDiagnosticImpl);
                    } else {
                        throw Exceptions.sneakyThrow(_t);
                    }
                }
                result.getContexts().put(it.getKey(), fa);
            }
            List<XtendAnnotationTarget> _annotatedSourceElements = result.getContexts().get(it.getKey()).getAnnotatedSourceElements();
            XtendAnnotationTarget _annotatedTarget = this._xAnnotationExtensions.getAnnotatedTarget(it.getValue());
            _annotatedSourceElements.add(_annotatedTarget);
        };
        this.searchAnnotatedElements(file, _function);
        return result;
    } catch (final Throwable _t) {
        if (_t instanceof Throwable) {
            final Throwable e = (Throwable) _t;
            this.operationCanceledManager.propagateAsErrorIfCancelException(e);
            boolean _matched = false;
            if (e instanceof VirtualMachineError) {
                _matched = true;
                throw ((VirtualMachineError) e);
            }
            if (!_matched) {
                if (e instanceof LinkageError) {
                    _matched = true;
                    throw ((LinkageError) e);
                }
            }
            ActiveAnnotationContextProvider.logger.warn("Error finding the elements to be processed by active annotations", e);
            return ActiveAnnotationContexts.installNew(file.eResource());
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    } finally {
        task.stop();
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) Stopwatches(org.eclipse.xtext.util.internal.Stopwatches) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) Resource(org.eclipse.emf.ecore.resource.Resource) JvmType(org.eclipse.xtext.common.types.JvmType) EList(org.eclipse.emf.common.util.EList) EObjectDiagnosticImpl(org.eclipse.xtext.validation.EObjectDiagnosticImpl) XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 55 with Pair

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

the class ActiveAnnotationContextProvider method registerMacroAnnotations.

protected void registerMacroAnnotations(final XtendAnnotationTarget candidate, final IAcceptor<Pair<JvmAnnotationType, XAnnotation>> acceptor) {
    final Function1<XAnnotation, Boolean> _function = (XAnnotation it) -> {
        return Boolean.valueOf(this._xAnnotationExtensions.isProcessed(it));
    };
    Iterable<XAnnotation> _filter = IterableExtensions.<XAnnotation>filter(candidate.getAnnotations(), _function);
    for (final XAnnotation annotation : _filter) {
        {
            final JvmAnnotationType activeAnnotationDeclaration = this._xAnnotationExtensions.tryFindAnnotationType(annotation);
            if ((activeAnnotationDeclaration != null)) {
                boolean _isValid = this.isValid(annotation, activeAnnotationDeclaration);
                if (_isValid) {
                    Pair<JvmAnnotationType, XAnnotation> _mappedTo = Pair.<JvmAnnotationType, XAnnotation>of(activeAnnotationDeclaration, annotation);
                    acceptor.accept(_mappedTo);
                }
            }
        }
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Pair(org.eclipse.xtext.xbase.lib.Pair)

Aggregations

Pair (org.eclipse.xtext.xbase.lib.Pair)67 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)22 Test (org.junit.Test)15 Collection (java.util.Collection)11 List (java.util.List)11 AbstractHierarchyBuilderTest (org.eclipse.xtext.junit4.ide.AbstractHierarchyBuilderTest)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)7 EObject (org.eclipse.emf.ecore.EObject)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 AbstractElement (org.eclipse.xtext.AbstractElement)6 HashMap (java.util.HashMap)5 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)5 Type (org.eclipse.n4js.ts.types.Type)5 EList (org.eclipse.emf.common.util.EList)4 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)4 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3