Active Annotations: is there a way to check if a MutableTypeDeclaration is an interface?

27 views
Skip to first unread message

christi...@nineconnections.com

unread,
Mar 22, 2017, 10:22:21 AM3/22/17
to Xtend Programming Language
I'm annotating a field, and I would like to add different code to the declaring type depending on if it is an interface or a class.
Message has been deleted

Christian Dietrich

unread,
Mar 23, 2017, 8:09:58 AM3/23/17
to Xtend Programming Language
a simple instanceof check does not work? MutableTypeDeclaration has sub-interfaces MutableClassDeclaration, MutableInterfaceDeclaration, etc

christi...@nineconnections.com

unread,
Mar 23, 2017, 4:38:54 PM3/23/17
to Xtend Programming Language
Hi Christian,

I tried an instanceof check, and that did not work. However it turned out that there is a bug in active annotation processing that can occur if multiple classes/interfaces are defined in the same xtend source file. The instanceof did not work because both times, the same instance was being passed (both times the class, instead of class and interface as expected).

I had a test where the test class, the interface class and the class which I used to test were in the same Xtend file. Giving each its own .xtend source file solved the issue. 

Christian Dietrich

unread,
Mar 24, 2017, 3:02:53 AM3/24/17
to Xtend Programming Language
Hi,

i cannnot reproduce this do you have any hints on the bug?

import org.eclipse.xtend.lib.macro.AbstractFieldProcessor
import org.eclipse.xtend.lib.macro.Active
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration

@Active(ActiveFooProcessor)
annotation ActiveFoo {
   
}

class ActiveFooProcessor extends AbstractFieldProcessor {
   
    override doTransform(MutableFieldDeclaration annotatedField, extension TransformationContext context) {
        super.doTransform(annotatedField, context)
        annotatedField.docComment = "Hallo" + annotatedField.declaringType.class
    }
   
}

The following example model (in one file)

class Demoooo {

    @ActiveFoo
    var String name = "name"
   
}

interface IDemoooo {
   
    @ActiveFoo
    val String NAME = "name"
   
}

gives

public interface IDemoooo {
  /**
   * Halloclass org.eclipse.xtend.core.macro.declaration.MutableJvmInterfaceDeclarationImpl
   */
  @ActiveFoo
  public final static String NAME = "name";
}

and

public class Demoooo {
  /**
   * Halloclass org.eclipse.xtend.core.macro.declaration.MutableJvmClassDeclarationImpl
   */
  @ActiveFoo
  private String name = "name";
}

christi...@nineconnections.com

unread,
Mar 24, 2017, 6:51:13 AM3/24/17
to Xtend Programming Language
Hi Christian, just tried to reproduce it, and I could not either. I am not sure what triggered this issue.

However we have seen this issue before. For example, we created this @Entity active annotation library (https://github.com/blueneogeo/xtend-entity), and we found that in some circumstances, there were issues in declaring several entity annotated entities on the same page. If we then copied the code into separate xtend files, the problem would resolve. Since then, we made it mandatory that entities are defined in their own files.

I will keep an eye out for when this happens again and will try to narrow it down to something repeatable.

In this case, I suspect it may have to do with the Eclipse Xtend plugin being of a different version than the Xtend library. The library is added by the gradle configuration, and may have been lower than the Eclipse Xtend version being used (2.11 for Eclipse vs 2.9.1 for gradle if I am not mistaken).

Thank you for your quick support.

Christian Dietrich

unread,
Mar 24, 2017, 6:59:24 AM3/24/17
to Xtend Programming Language
the question is: how did you created the gradle config and which version of the xtend gradle plugin do you use. i think the newest is 1.0.17
Reply all
Reply to author
Forward
0 new messages