Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Issue with active annotations depending on external model files #664

Closed
nils-christian opened this issue Dec 10, 2018 · 13 comments
Closed

Comments

@nils-christian
Copy link

Hi,

I would like to thank you first for providing us with Xtend. We really appreciate the language and everything that comes with it.

Now about our issue. We encountered a problem with the active annotations. I try to simplify it as much as possible. We encountered it with Xtend 2.14, but I have the same issue with an Eclipse with 2.16.

  • We have ActiveAnnotation1, which reads a model file (let's call it File.txt) located next to the annotated class. It generates a new annotation GeneratedAnnotation (a simple Java annotation).
  • We have another annotation ActiveAnnotation2, which reads this file as well and adds the generated annotation to the annotated class.

So far this works without any issues. When we change File.txt, everything is updated as expected. Now we want to use the same model file to generate some more elements in another project. It is not possible to put the model file somewhere else and reference it from another project. It seems that the active annotation can not "break out" from its project context using the FileSystemSupport etc. We therefore use the elements, generated from ActiveAnnotation1 and ActiveAnnotation2 to generate further elements.

  • We have ActiveAnnotation3 which gets a reference to the class annotated with ActiveAnnotation2. This annotation retrieves the given class and locates the GeneratedAnnotation instance at this class.

This is where our issue occurs. ActiveAnnotation3 cannot find GeneratedAnnotation. It can only find ActiveAnnotation2 and the suppress warnings annotation. If we perform a Maven install on the project in which the class annotated with ActiveAnnotation2 lies and close it, ActiveAnnotation3 can locate GeneratedAnnotation as expected.

I created a simple project to demonstrate the issue: https://github.com/nils-christian/xtend-active-annotation-issue. It consists of four modules. Module a contains the first two active annotations. Module b uses these annotations and contains thus classes annotated with ActiveAnnotation1 and ActiveAnnotation2. Module c contains ActiveAnnotation3 which only retrieves the given class, assembles a string from all annotations and writes it as warning to the annotated class. Module d finally contains the class annotated with ActiveAnnotation3. Note how it references the class annotated with ActiveAnnotation2. If you perform a Maven install and close Module b the annotation can be found again.

Can you help us here? We tried to debug the issue. It seems that ActiveAnnotation2 is called multiple times by Eclipse. If the context is in Module b it works, but then it is called again in the context of Module d and Eclipse no longer likes the path to the model file (because it is located in another project).

Best regards

Nils Ehmke

@kthoms
Copy link

kthoms commented Dec 11, 2018

Thank you Nils for the detailed report and the example project. This sounds like a corner case where I have doubts that we can invest enough time into ATM. Please bare with us if it will take a while until we can have a deeper look into it.
Is this a blocker for your project or can you work around?

@OLibutzki
Copy link

Hi @kthoms,

we currently prepare a conference talk in January. In the first place it's a blocker for what we want to present there. In this context we just need a very simple generator. We currently investigate how to circumvent this issue with a Java main method (and exec-maven-plugin and m2e for IDE integration). That's not elegant, but might work for the moment.

Anyway, we are keen to support you as much as we can to fix this.

@cdietrich
Copy link
Member

@szarnekow do you have any idea?

@nils-christian
Copy link
Author

Hello @kthoms,

I expected this to be a corner case. However, I appreciate a fix or a suggestion for the issue. For the moment, as Oliver already told you, we will use a workaround for our generator.

Thank you very much and best regards

Nils

@cdietrich
Copy link
Member

cdietrich commented Dec 14, 2018

@nils-christian i tried to follow your description but could not really find out how to "reproduce" the problem. is the problem that the xtend class does not contain the annotation that is added to the generated class?

@cdietrich
Copy link
Member

there is a hidden java.lang.IllegalArgumentException: The file cannot be found: /xtend-issue-b/src/main/java/de/rhocas/b/File.txt

the problem is that

org.eclipse.xtend.core.macro.AbstractFileSystemSupport.getPath(URI, URI, Path)

cannot deal with

  • absoluteUri: platform:/resource/xtend-issue-b/src/main/java/de/rhocas/b/AnnotatedClass2.xtend
  • baseUri: platform:/resource/xtend-issue-d/
  • basePath: /xtend-issue-d

@cdietrich
Copy link
Member

=> basePath looks bogus to me.

@cdietrich
Copy link
Member

relates to #383

@cdietrich
Copy link
Member

org.eclipse.xtend.core.macro.AbstractFileSystemSupport.getContentsAsStream(Path)
get null for getUri on /xtend-issue-b/src/main/java/de/rhocas/b/File.txt

@cdietrich
Copy link
Member

cdietrich commented Dec 14, 2018

i wonder why the code only looks at the project config and if we should look at the workspace in eclipse.
i am not sure if changing this will break something

@nils-christian
Copy link
Author

Hello @cdietrich,

Yes, this is exactly the problem. One would expect that ActiveAnnotation3 could detect also the newly generated annotation.

We also recognized the IllegalArgumentException and wondered that Eclipse "hides" this exception.

@szarnekow
Copy link
Contributor

IIRC it is related to the read tracking. When AA read files from disc, their interest in the contents of these files is recorded. If arbitrary read operations throughout the workspace would be allowed, it would not be possible to rebuild automatically if the related file contents changed. At least that would be my guess here.

@cdietrich
Copy link
Member

Closed as wont-fix. Feel free to reopen at github.com/eclipse/xtext

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants