Search in sources :

Example 1 with AnnotationReferenceBuildContextImpl

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

the class AnnotationReferenceProviderImpl method newAnnotationReference.

@Override
public AnnotationReference newAnnotationReference(final String annotationTypeName, final Procedure1<AnnotationReferenceBuildContext> initializer) {
    AnnotationReference _xblockexpression = null;
    {
        this.compilationUnit.checkCanceled();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotationTypeName cannot be null");
        Preconditions.checkArgument((annotationTypeName != null), _builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("initializer cannot be null");
        Preconditions.checkArgument((initializer != null), _builder_1);
        final JvmAnnotationReference jvmAnnotationReference = this.createJvmAnnotationReference(this.compilationUnit.getTypeReferences().findDeclaredType(annotationTypeName, this.compilationUnit.getXtendFile()));
        if ((jvmAnnotationReference == null)) {
            return null;
        }
        AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
        final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
            it.setDelegate(jvmAnnotationReference);
            it.setCompilationUnit(this.compilationUnit);
        };
        final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
        initializer.apply(buildContext);
        _xblockexpression = this.compilationUnit.toAnnotationReference(jvmAnnotationReference);
    }
    return _xblockexpression;
}
Also used : AnnotationReferenceBuildContextImpl(org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 2 with AnnotationReferenceBuildContextImpl

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

the class AnnotationReferenceProviderImpl method newAnnotationReference.

@Override
public AnnotationReference newAnnotationReference(final AnnotationReference annotationReference, final Procedure1<AnnotationReferenceBuildContext> initializer) {
    Object _xblockexpression = null;
    {
        this.compilationUnit.checkCanceled();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotationReference cannot be null");
        Preconditions.checkArgument((annotationReference != null), _builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("initializer cannot be null");
        Preconditions.checkArgument((initializer != null), _builder_1);
        if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
            final JvmAnnotationReference baseJvmAnnotationReference = ((JvmAnnotationReferenceImpl) annotationReference).getDelegate();
            ConditionUtils.notRemoved(baseJvmAnnotationReference, "annotationReference");
            final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(baseJvmAnnotationReference.getAnnotation());
            AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
            final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
                it.setDelegate(newJvmAnnotationReference);
                it.setCompilationUnit(this.compilationUnit);
            };
            final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
            final Function1<JvmAnnotationValue, String> _function_1 = (JvmAnnotationValue it) -> {
                String _elvis = null;
                String _valueName = it.getValueName();
                if (_valueName != null) {
                    _elvis = _valueName;
                } else {
                    _elvis = "value";
                }
                return _elvis;
            };
            List<String> _map = ListExtensions.<JvmAnnotationValue, String>map(baseJvmAnnotationReference.getExplicitValues(), _function_1);
            for (final String valueName : _map) {
                {
                    final Object value = ((JvmAnnotationReferenceImpl) annotationReference).getValue(valueName);
                    buildContext.set(valueName, value);
                }
            }
            initializer.apply(buildContext);
            return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
        }
        _xblockexpression = null;
    }
    return ((AnnotationReference) _xblockexpression);
}
Also used : AnnotationReferenceBuildContextImpl(org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) List(java.util.List) JvmAnnotationReferenceImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Example 3 with AnnotationReferenceBuildContextImpl

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

the class AnnotationReferenceProviderImpl method newAnnotationReference.

@Override
public AnnotationReference newAnnotationReference(final Type annotationTypeDelcaration, final Procedure1<AnnotationReferenceBuildContext> initializer) {
    Object _xblockexpression = null;
    {
        this.compilationUnit.checkCanceled();
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotationTypeDelcaration cannot be null");
        Preconditions.checkArgument((annotationTypeDelcaration != null), _builder);
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("initializer cannot be null");
        Preconditions.checkArgument((initializer != null), _builder_1);
        JvmDeclaredType _switchResult = null;
        boolean _matched = false;
        if (annotationTypeDelcaration instanceof JvmAnnotationTypeDeclarationImpl) {
            _matched = true;
            _switchResult = ((JvmAnnotationTypeDeclarationImpl) annotationTypeDelcaration).getDelegate();
        }
        if (!_matched) {
            if (annotationTypeDelcaration instanceof XtendAnnotationTypeDeclarationImpl) {
                _matched = true;
                _switchResult = this.compilationUnit.getJvmModelAssociations().getInferredType(((XtendAnnotationTypeDeclarationImpl) annotationTypeDelcaration).getDelegate());
            }
        }
        if (!_matched) {
            throw new IllegalArgumentException(("couldn\'t construct type reference for type " + annotationTypeDelcaration));
        }
        final JvmDeclaredType type = _switchResult;
        if ((type instanceof JvmAnnotationType)) {
            final JvmAnnotationReference newJvmAnnotationReference = this.createJvmAnnotationReference(type);
            AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
            final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
                it.setDelegate(newJvmAnnotationReference);
                it.setCompilationUnit(this.compilationUnit);
            };
            final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
            initializer.apply(buildContext);
            return this.compilationUnit.toAnnotationReference(newJvmAnnotationReference);
        }
        _xblockexpression = null;
    }
    return ((AnnotationReference) _xblockexpression);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) AnnotationReferenceBuildContextImpl(org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl) JvmAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeDeclarationImpl) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) XtendAnnotationTypeDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendAnnotationTypeDeclarationImpl) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 4 with AnnotationReferenceBuildContextImpl

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

the class CompilationUnitImpl method translateAnnotation.

protected AnnotationReference translateAnnotation(final XAnnotation annotation) {
    AnnotationReference _xblockexpression = null;
    {
        AnnotationReferenceBuildContextImpl _annotationReferenceBuildContextImpl = new AnnotationReferenceBuildContextImpl();
        final Procedure1<AnnotationReferenceBuildContextImpl> _function = (AnnotationReferenceBuildContextImpl it) -> {
            it.setCompilationUnit(this);
            JvmAnnotationReference _createJvmAnnotationReference = this.typesFactory.createJvmAnnotationReference();
            final Procedure1<JvmAnnotationReference> _function_1 = (JvmAnnotationReference reference) -> {
                JvmType _annotationType = annotation.getAnnotationType();
                reference.setAnnotation(((JvmAnnotationType) _annotationType));
            };
            JvmAnnotationReference _doubleArrow = ObjectExtensions.<JvmAnnotationReference>operator_doubleArrow(_createJvmAnnotationReference, _function_1);
            it.setDelegate(_doubleArrow);
        };
        final AnnotationReferenceBuildContextImpl buildContext = ObjectExtensions.<AnnotationReferenceBuildContextImpl>operator_doubleArrow(_annotationReferenceBuildContextImpl, _function);
        EList<XAnnotationElementValuePair> _elementValuePairs = annotation.getElementValuePairs();
        for (final XAnnotationElementValuePair valuePair : _elementValuePairs) {
            {
                final XExpression value = valuePair.getValue();
                if ((value != null)) {
                    final JvmOperation operation = valuePair.getElement();
                    final Object annotationValue = this.translateAnnotationValue(value, operation.getReturnType());
                    buildContext.set(operation.getSimpleName(), annotationValue);
                }
            }
        }
        XExpression _value = annotation.getValue();
        boolean _tripleNotEquals = (_value != null);
        if (_tripleNotEquals) {
            final Object annotationValue = this.translateAnnotationValue(annotation.getValue(), null);
            buildContext.set("value", annotationValue);
        }
        _xblockexpression = this.toAnnotationReference(buildContext.getDelegate());
    }
    return _xblockexpression;
}
Also used : AnnotationReferenceBuildContextImpl(org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) XAnnotationElementValuePair(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair) EList(org.eclipse.emf.common.util.EList) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) XExpression(org.eclipse.xtext.xbase.XExpression) EObject(org.eclipse.emf.ecore.EObject) JvmType(org.eclipse.xtext.common.types.JvmType) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Aggregations

AnnotationReferenceBuildContextImpl (org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl)4 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)4 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)2 List (java.util.List)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 JvmAnnotationReferenceImpl (org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl)1 JvmAnnotationTypeDeclarationImpl (org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeDeclarationImpl)1 XtendAnnotationTypeDeclarationImpl (org.eclipse.xtend.core.macro.declaration.XtendAnnotationTypeDeclarationImpl)1 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)1 JvmAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationValue)1 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)1 JvmType (org.eclipse.xtext.common.types.JvmType)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 XAnnotationElementValuePair (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotationElementValuePair)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1