Search in sources :

Example 1 with MutableAnnotationTypeElementDeclaration

use of org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeElementDeclaration in project xtext-xtend by eclipse.

the class MutableJvmAnnotationTypeDeclarationImpl method addAnnotationTypeElement.

@Override
public MutableAnnotationTypeElementDeclaration addAnnotationTypeElement(final String name, final Procedure1<MutableAnnotationTypeElementDeclaration> initializer) {
    this.checkMutable();
    ConditionUtils.checkJavaIdentifier(name, "name");
    Preconditions.checkArgument((initializer != null), "initializer cannot be null");
    final JvmOperation newAnnotationElement = TypesFactory.eINSTANCE.createJvmOperation();
    newAnnotationElement.setSimpleName(name);
    newAnnotationElement.setVisibility(JvmVisibility.PUBLIC);
    this.getDelegate().getMembers().add(newAnnotationElement);
    MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newAnnotationElement);
    final MutableAnnotationTypeElementDeclaration mutableAnnotationTypeElementDeclaration = ((MutableAnnotationTypeElementDeclaration) _memberDeclaration);
    initializer.apply(mutableAnnotationTypeElementDeclaration);
    return mutableAnnotationTypeElementDeclaration;
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) MutableAnnotationTypeElementDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeElementDeclaration) MutableMemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableMemberDeclaration) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration)

Example 2 with MutableAnnotationTypeElementDeclaration

use of org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeElementDeclaration in project xtext-xtend by eclipse.

the class ToAnnoProcessor method doTransform.

@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
    super.doTransform(annotatedClass, context);
    Type _findTypeGlobally = context.findTypeGlobally(this.generatedAnnotationName(annotatedClass));
    final MutableAnnotationTypeDeclaration annotationType = ((MutableAnnotationTypeDeclaration) _findTypeGlobally);
    final Procedure1<MutableAnnotationTypeElementDeclaration> _function = (MutableAnnotationTypeElementDeclaration it) -> {
        it.setDocComment("Best building strategy game ever");
        it.setType(context.newTypeReference(Integer.TYPE));
        boolean _booleanValue = annotatedClass.findAnnotation(context.findTypeGlobally(ToAnno.class)).getBooleanValue("defaultValue");
        if (_booleanValue) {
            StringConcatenationClient _client = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append("1602");
                }
            };
            it.setDefaultValueExpression(_client);
        }
    };
    annotationType.addAnnotationTypeElement("anno", _function);
}
Also used : Type(org.eclipse.xtend.lib.macro.declaration.Type) MutableAnnotationTypeElementDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeElementDeclaration) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ToAnno(org.eclipse.xtend.core.tests.macro.ToAnno) MutableAnnotationTypeDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeDeclaration)

Aggregations

MutableAnnotationTypeElementDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeElementDeclaration)2 ToAnno (org.eclipse.xtend.core.tests.macro.ToAnno)1 MemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MemberDeclaration)1 MutableAnnotationTypeDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableAnnotationTypeDeclaration)1 MutableMemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MutableMemberDeclaration)1 Type (org.eclipse.xtend.lib.macro.declaration.Type)1 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)1 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)1