Search in sources :

Example 1 with JvmAnnotationReferenceImpl

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

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

the class JvmAnnotationTargetImpl method addAnnotation.

public AnnotationReference addAnnotation(final AnnotationReference annotationReference) {
    AnnotationReference _xblockexpression = null;
    {
        this.checkMutable();
        Preconditions.checkArgument((annotationReference != null), "annotationReference cannot be null");
        AnnotationReference _xifexpression = null;
        if ((annotationReference instanceof JvmAnnotationReferenceImpl)) {
            AnnotationReference _xblockexpression_1 = null;
            {
                final JvmAnnotationReference jvmAnnotationReference = EcoreUtil2.<JvmAnnotationReference>cloneWithProxies(((JvmAnnotationReferenceImpl) annotationReference).getDelegate());
                EList<JvmAnnotationReference> _annotations = this.getDelegate().getAnnotations();
                _annotations.add(jvmAnnotationReference);
                _xblockexpression_1 = this.getCompilationUnit().toAnnotationReference(jvmAnnotationReference);
            }
            _xifexpression = _xblockexpression_1;
        } else {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append(annotationReference);
            _builder.append(" is not annotation reference");
            throw new IllegalArgumentException(_builder.toString());
        }
        _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) JvmAnnotationReferenceImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Example 3 with JvmAnnotationReferenceImpl

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

the class DeclarationsTest method testAnnotation4.

/**
 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=465007
 */
@Test
public void testAnnotation4() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class MyClass {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@test.Annotation2 String foo");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@test.Annotation2(\"hubble\") String foo2");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@test.Annotation2(value=\"hubble\") String foo3");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final Procedure1<CompilationUnitImpl> _function = (CompilationUnitImpl it) -> {
        final AnnotationReference anno = IterableExtensions.head(IterableExtensions.head(it.getTypeLookup().findClass("MyClass").getDeclaredFields()).getAnnotations());
        final AnnotationReference copied = it.getAnnotationReferenceProvider().newAnnotationReference(anno);
        Assert.assertTrue(((JvmAnnotationReferenceImpl) copied).getDelegate().getExplicitValues().isEmpty());
        final AnnotationReference anno2 = IterableExtensions.head(((MutableFieldDeclaration[]) Conversions.unwrapArray(it.getTypeLookup().findClass("MyClass").getDeclaredFields(), MutableFieldDeclaration.class))[1].getAnnotations());
        final AnnotationReference copied2 = it.getAnnotationReferenceProvider().newAnnotationReference(anno2);
        Assert.assertEquals(1, ((JvmAnnotationReferenceImpl) copied2).getDelegate().getExplicitValues().size());
        final AnnotationReference anno3 = IterableExtensions.head(((MutableFieldDeclaration[]) Conversions.unwrapArray(it.getTypeLookup().findClass("MyClass").getDeclaredFields(), MutableFieldDeclaration.class))[2].getAnnotations());
        final AnnotationReference copied3 = it.getAnnotationReferenceProvider().newAnnotationReference(anno3);
        Assert.assertEquals(1, ((JvmAnnotationReferenceImpl) copied3).getDelegate().getExplicitValues().size());
    };
    this.asCompilationUnit(this.validFile(_builder), _function);
}
Also used : MutableFieldDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration) CompilationUnitImpl(org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) JvmAnnotationReferenceImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl) Test(org.junit.Test)

Example 4 with JvmAnnotationReferenceImpl

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

the class AnnotationReferenceBuildContextImpl method _setValue.

protected void _setValue(final JvmAnnotationAnnotationValue it, final AnnotationReference[] value, final String componentType, final boolean mustBeArray) {
    this.checkType(it, componentType, mustBeArray);
    for (final AnnotationReference annotationValue : value) {
        boolean _matched = false;
        if (annotationValue instanceof JvmAnnotationReferenceImpl) {
            _matched = true;
            it.getValues().add(EcoreUtil2.<JvmAnnotationReference>cloneWithProxies(((JvmAnnotationReferenceImpl) annotationValue).getDelegate()));
        }
        if (!_matched) {
            if (annotationValue instanceof XtendAnnotationReferenceImpl) {
                _matched = true;
                throw new IllegalArgumentException("Multiple source annotations cannot be set as values. Please the the expression not the value.");
            }
        }
    }
}
Also used : JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) AnnotationReference(org.eclipse.xtend.lib.macro.declaration.AnnotationReference) JvmAnnotationReferenceImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl) XtendAnnotationReferenceImpl(org.eclipse.xtend.core.macro.declaration.XtendAnnotationReferenceImpl)

Example 5 with JvmAnnotationReferenceImpl

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

the class CompilationUnitImpl method toAnnotationReference.

public AnnotationReference toAnnotationReference(final JvmAnnotationReference delegate) {
    final Function1<JvmAnnotationReference, JvmAnnotationReferenceImpl> _function = (JvmAnnotationReference it) -> {
        JvmAnnotationReferenceImpl _jvmAnnotationReferenceImpl = new JvmAnnotationReferenceImpl();
        final Procedure1<JvmAnnotationReferenceImpl> _function_1 = (JvmAnnotationReferenceImpl it_1) -> {
            it_1.setDelegate(delegate);
            it_1.setCompilationUnit(this);
        };
        return ObjectExtensions.<JvmAnnotationReferenceImpl>operator_doubleArrow(_jvmAnnotationReferenceImpl, _function_1);
    };
    return this.<JvmAnnotationReference, JvmAnnotationReferenceImpl>getOrCreate(delegate, _function);
}
Also used : Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmAnnotationReferenceImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference)

Aggregations

JvmAnnotationReferenceImpl (org.eclipse.xtend.core.macro.declaration.JvmAnnotationReferenceImpl)5 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)4 AnnotationReference (org.eclipse.xtend.lib.macro.declaration.AnnotationReference)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 List (java.util.List)1 AnnotationReferenceBuildContextImpl (org.eclipse.xtend.core.macro.declaration.AnnotationReferenceBuildContextImpl)1 CompilationUnitImpl (org.eclipse.xtend.core.macro.declaration.CompilationUnitImpl)1 XtendAnnotationReferenceImpl (org.eclipse.xtend.core.macro.declaration.XtendAnnotationReferenceImpl)1 MutableFieldDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration)1 JvmAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationValue)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1 Test (org.junit.Test)1