Search in sources :

Example 11 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class ErrorTest method testErrorModel_006.

@Test
public void testErrorModel_006() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("@Data class A {}");
    _builder.newLine();
    _builder.append("@");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration typeDeclaration = IterableExtensions.<XtendTypeDeclaration>last(file.getXtendTypes());
    final EList<XAnnotation> annotations = typeDeclaration.getAnnotations();
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(IterableExtensions.<XAnnotation>head(annotations));
    Assert.assertNotNull(resolvedTypes.getActualType(IterableExtensions.<XAnnotation>head(annotations)));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Example 12 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class XtendJvmModelInferrer method transform.

protected void transform(XtendEnumLiteral literal, JvmEnumerationType container) {
    if (literal.getName() == null)
        return;
    JvmEnumerationLiteral jvmLiteral = typesFactory.createJvmEnumerationLiteral();
    associator.associatePrimary(literal, jvmLiteral);
    jvmLiteral.setSimpleName(literal.getName());
    jvmLiteral.setVisibility(JvmVisibility.PUBLIC);
    jvmLiteral.setStatic(true);
    jvmLiteral.setFinal(true);
    jvmTypesBuilder.copyDocumentationTo(literal, jvmLiteral);
    for (XAnnotation anno : literal.getAnnotations()) {
        if (!annotationTranslationFilter.apply(anno))
            continue;
        JvmAnnotationReference annotationReference = jvmTypesBuilder.getJvmAnnotationReference(anno);
        if (annotationReference != null)
            jvmLiteral.getAnnotations().add(annotationReference);
    }
    container.getMembers().add(jvmLiteral);
}
Also used : JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 13 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class XtendJvmModelInferrer method transform.

protected void transform(XtendField source, JvmGenericType container) {
    if ((source.isExtension() && source.getType() != null) || source.getName() != null) {
        JvmField field = typesFactory.createJvmField();
        final String computeFieldName = computeFieldName(source);
        field.setSimpleName(computeFieldName);
        container.getMembers().add(field);
        associator.associatePrimary(source, field);
        field.setVisibility(source.getVisibility());
        field.setStatic(source.isStatic());
        field.setTransient(source.isTransient());
        field.setVolatile(source.isVolatile());
        field.setFinal(source.isFinal());
        if (source.getType() != null) {
            field.setType(jvmTypesBuilder.cloneWithProxies(source.getType()));
        } else if (source.getInitialValue() != null) {
            field.setType(jvmTypesBuilder.inferredType(source.getInitialValue()));
        }
        for (XAnnotation anno : source.getAnnotations()) {
            if (!annotationTranslationFilter.apply(anno))
                continue;
            JvmAnnotationReference annotationReference = jvmTypesBuilder.getJvmAnnotationReference(anno);
            if (annotationReference != null)
                field.getAnnotations().add(annotationReference);
        }
        if (source.isExtension() && typeReferences.findDeclaredType(Extension.class, source) != null) {
            field.getAnnotations().add(_annotationTypesBuilder.annotationRef(Extension.class));
        }
        jvmTypesBuilder.copyDocumentationTo(source, field);
        jvmTypesBuilder.setInitializer(field, source.getInitialValue());
        initializeLocalTypes(field, source.getInitialValue());
    }
}
Also used : Extension(org.eclipse.xtext.xbase.lib.Extension) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) JvmField(org.eclipse.xtext.common.types.JvmField) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 14 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation in project xtext-xtend by eclipse.

the class XtendFormatter method formatAnnotations.

protected void formatAnnotations(final XtendAnnotationTarget target, @Extension final IFormattableDocument document, final Procedure1<? super IHiddenRegionFormatter> configKey) {
    boolean _isEmpty = target.getAnnotations().isEmpty();
    if (_isEmpty) {
        return;
    }
    EList<XAnnotation> _annotations = target.getAnnotations();
    for (final XAnnotation a : _annotations) {
        {
            document.<XAnnotation>format(a);
            document.<XAnnotation>append(a, configKey);
        }
    }
}
Also used : XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)

Example 15 with XAnnotation

use of org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation 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);
                        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();
                        }
                        final String msg = _switchResult;
                        EList<Resource.Diagnostic> _errors = file.eResource().getErrors();
                        StringConcatenation _builder = new StringConcatenation();
                        _builder.append("Problem while loading annotation processor: ");
                        _builder.append(msg);
                        XAnnotation _value = it.getValue();
                        EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, IssueCodes.PROCESSING_ERROR, _builder.toString(), _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) ActiveAnnotationContexts(org.eclipse.xtend.core.macro.ActiveAnnotationContexts) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ActiveAnnotationContext(org.eclipse.xtend.core.macro.ActiveAnnotationContext) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) Pair(org.eclipse.xtext.xbase.lib.Pair)

Aggregations

XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)24 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)13 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)13 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 Test (org.junit.Test)12 IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)11 EObject (org.eclipse.emf.ecore.EObject)4 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)4 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)4 XtendAnnotationTarget (org.eclipse.xtend.core.xtend.XtendAnnotationTarget)3 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)3 XtendField (org.eclipse.xtend.core.xtend.XtendField)2 XtendParameter (org.eclipse.xtend.core.xtend.XtendParameter)2 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)2 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)2 EObjectDiagnosticImpl (org.eclipse.xtext.validation.EObjectDiagnosticImpl)2 Pair (org.eclipse.xtext.xbase.lib.Pair)2 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1