Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Reusing XAnnotation
Reusing XAnnotation [message #1692853] Mon, 20 April 2015 09:10 Go to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 111
Registered: July 2009
Senior Member
Hello,


In my Xbase grammar a user can specify custom annotations like this:

CustomAnnotation:
    userAnnotation = XAnnotation;


In Inferrer I would like to add this annotation to multiple targets.

As it can't be done straight forward I tried to clone the XAnnotation objects and use clones in the JvmModelInferrer. Unfortunately without success:

I copied XAnnotation like this

Copier copier = new Copier();
T copy = (T) copier.copy(original);
copier.copyReferences();


Then I added a new attribute to the CustomAnnotation XClass:

class CustomAnnotation {
  XAnnotation userAnnotation;
  List<XAnnotation> copiedUserAnnotations;
}


In the inferrer I created a copy of the annotation, added it to my new list and passed it to the addAnnotation method:

  // myClass.addAnnotation(userAnnotation) WORKS WITH SINGLE TARGET ONLY

  val copy = copier.cloneWithProxies(userAnnotation)
  myClass.copiedUserAnnotations += copy
  myClass.addAnnotation(copy)


The good news are: the first build finishes without any exceptions.
The bad news are:
- no annotation get added to the class
- the second build produces an exception (see stacktrace at the bottom)

I think, that the exception get thrown due to the some missing deinitialization of my cloned EMF objects. Are there any EMF-object cleaner class, that I have to extend?

Am I moving in the right direction?

Thank you!


Cheers,
Boris


15   [Worker-9] ERROR org.eclipse.xtext.common.types.access.jdt.JdtTypeMirror  - Error initializing type java:/Objects/org.jnario.feature.tests.integration.BackgroundsFeature
java.lang.IllegalStateException: Could not create binding for 'org.jnario.feature.tests.integration.BackgroundsFeature' in context of project 'org.jnario.tests'.
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createType(JdtBasedTypeFactory.java:404)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createType(JdtBasedTypeFactory.java:491)
	at org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.createType(JdtBasedTypeFactory.java:1)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeMirror.initialize(JdtTypeMirror.java:67)
	at org.eclipse.xtext.common.types.access.TypeResource.doLoad(TypeResource.java:129)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
	at org.eclipse.xtext.common.types.access.TypeResource.load(TypeResource.java:115)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.createResourceAndFindType(JdtTypeProvider.java:273)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.findObjectTypeInJavaProject(JdtTypeProvider.java:256)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.doFindObjectType(JdtTypeProvider.java:201)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.findObjectType(JdtTypeProvider.java:184)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.doFindTypeByName(JdtTypeProvider.java:145)
	at org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.findTypeByName(JdtTypeProvider.java:161)
	at org.eclipse.xtext.common.types.xtext.AbstractTypeScope.getSingleElement(AbstractTypeScope.java:59)
	at org.eclipse.xtext.common.types.xtext.AbstractTypeScope.getSingleElement(AbstractTypeScope.java:54)
	at org.eclipse.xtext.common.types.xtext.AbstractTypeScope.getElements(AbstractTypeScope.java:73)
	at org.eclipse.xtext.scoping.impl.AbstractScope.getElements(AbstractScope.java:137)
	at org.eclipse.xtext.scoping.impl.ScopeBasedSelectable.getExportedObjects(ScopeBasedSelectable.java:40)
	at org.eclipse.xtext.scoping.impl.ImportScope.getLocalElementsByName(ImportScope.java:154)
	at org.eclipse.xtext.scoping.impl.ImportScope.getSingleLocalElementByName(ImportScope.java:142)
	at org.eclipse.xtext.scoping.impl.AbstractScope.getSingleElement(AbstractScope.java:105)
	at org.eclipse.xtext.scoping.impl.AbstractScope.getSingleElement(AbstractScope.java:108)
	at org.eclipse.xtext.linking.impl.DefaultLinkingService.getLinkedObjects(DefaultLinkingService.java:121)
	at org.jnario.feature.linking.FeatureLinkingService.getLinkedObjects(FeatureLinkingService.java:45)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:250)
	at org.eclipse.xtext.xbase.resource.BatchLinkableResource.getEObject(BatchLinkableResource.java:119)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:223)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:199)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:259)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1473)
	at org.eclipse.xtext.xbase.annotations.xAnnotations.impl.XAnnotationImpl.getAnnotationType(XAnnotationImpl.java:127)
	at org.jnario.jvmmodel.JnarioJvmModelInferrer.hasExtendsAnnotation(JnarioJvmModelInferrer.java:202)
	at org.jnario.jvmmodel.JnarioJvmModelInferrer$1.apply(JnarioJvmModelInferrer.java:172)
	at org.jnario.jvmmodel.JnarioJvmModelInferrer$1.apply(JnarioJvmModelInferrer.java:1)
	at org.eclipse.xtext.xbase.lib.internal.BooleanFunctionDelegate.apply(BooleanFunctionDelegate.java:41)
	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:647)
	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
	at com.google.common.collect.TransformedIterator.hasNext(TransformedIterator.java:43)
	at org.jnario.jvmmodel.JnarioJvmModelInferrer.addSuperClass(JnarioJvmModelInferrer.java:184)
	at org.jnario.feature.jvmmodel.FeatureJvmModelInferrer.toClass(FeatureJvmModelInferrer.java:206)
	at org.jnario.feature.jvmmodel.FeatureJvmModelInferrer.doInfer(FeatureJvmModelInferrer.java:158)
	at org.jnario.jvmmodel.JnarioJvmModelInferrer.infer(JnarioJvmModelInferrer.java:130)
	at org.eclipse.xtext.xbase.jvmmodel.JvmModelAssociator.installDerivedState(JvmModelAssociator.java:382)
	at org.eclipse.xtext.resource.DerivedStateAwareResource.installDerivedState(DerivedStateAwareResource.java:227)
	at org.eclipse.xtext.xbase.resource.BatchLinkableResource.getContents(BatchLinkableResource.java:148)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObjectForURIFragmentRootSegment(ResourceImpl.java:721)
	at org.eclipse.xtext.resource.DerivedStateAwareResource.getEObjectForURIFragmentRootSegment(DerivedStateAwareResource.java:197)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:763)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:742)
	at org.eclipse.xtext.resource.XtextResource.access$1(XtextResource.java:1)
	at org.eclipse.xtext.resource.XtextResource$1.getEObject(XtextResource.java:115)
	at org.eclipse.xtext.resource.DefaultFragmentProvider.getEObject(DefaultFragmentProvider.java:28)
	at org.eclipse.xtext.resource.XtextResource.basicGetEObject(XtextResource.java:323)
	at org.eclipse.xtext.resource.XtextResource.getEObject(XtextResource.java:309)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject(LazyLinkingResource.java:235)
	at org.eclipse.xtext.resource.persistence.StorageAwareResource.getEObject(StorageAwareResource.java:124)
	at org.eclipse.xtext.xbase.resource.BatchLinkableResource.getEObject(BatchLinkableResource.java:124)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:223)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:199)
	at org.eclipse.emf.ecore.util.EcoreUtil.resolve(EcoreUtil.java:259)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy(BasicEObjectImpl.java:1473)
	at org.jnario.feature.feature.impl.StepReferenceImplCustom.getReference(StepReferenceImplCustom.java:21)
	at org.jnario.feature.ui.highlighting.FeatureSemanticHighlightingCalculator$Implementation.caseStep(FeatureSemanticHighlightingCalculator.java:114)
	at org.jnario.feature.ui.highlighting.FeatureSemanticHighlightingCalculator$Implementation.caseStep(FeatureSemanticHighlightingCalculator.java:1)
	at org.jnario.feature.feature.util.FeatureSwitch.doSwitch(FeatureSwitch.java:236)
	at org.jnario.feature.feature.util.FeatureSwitch.doSwitch(FeatureSwitch.java:86)
	at org.jnario.feature.feature.util.FeatureSwitch.doSwitch(FeatureSwitch.java:72)
	at org.jnario.feature.ui.highlighting.FeatureSemanticHighlightingCalculator.searchAndHighlightElements(FeatureSemanticHighlightingCalculator.java:218)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultSemanticHighlightingCalculator.doProvideHighlightingFor(DefaultSemanticHighlightingCalculator.java:67)
	at org.eclipse.xtext.xbase.ui.highlighting.XbaseHighlightingCalculator.doProvideHighlightingFor(XbaseHighlightingCalculator.java:111)
	at org.eclipse.xtext.xbase.ui.highlighting.XbaseHighlightingCalculator.provideHighlightingFor(XbaseHighlightingCalculator.java:101)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.MergingHighlightedPositionAcceptor.provideHighlightingFor(MergingHighlightedPositionAcceptor.java:53)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingReconciler.reconcilePositions(HighlightingReconciler.java:142)
	at org.eclipse.xtext.ui.editor.syntaxcoloring.HighlightingReconciler.modelChanged(HighlightingReconciler.java:385)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.notifyModelListeners(XtextDocument.java:215)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.modify(XtextDocument.java:444)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.internalModify(XtextDocument.java:162)
	at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport$UpdateEditorStateJob.unloadAffectedResourcesAndReparseDocument(DirtyStateEditorSupport.java:186)
	at org.eclipse.xtext.ui.editor.DirtyStateEditorSupport$UpdateEditorStateJob.run(DirtyStateEditorSupport.java:164)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Re: Reusing XAnnotation [message #1692870 is a reply to message #1692853] Mon, 20 April 2015 10:40 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1775
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi Boris

I had a similar problem in another DSL; please have a look at the
forum... IIRC I had to remove also some associations explicitly. Sorry
I can't check that right now...

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Reusing XAnnotation [message #1692872 is a reply to message #1692870] Mon, 20 April 2015 11:09 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 111
Registered: July 2009
Senior Member
Hello Lorenzo,


thank you very much for the reply. I already studied your conversation with Sebastian about this: https://www.eclipse.org/forums/index.php/t/864890/

But after applying your solution only the last inferred annotation get generated. But you managed to get your annotation generated on all needed targets?


Cheers,
Boris
Re: Reusing XAnnotation [message #1692886 is a reply to message #1692872] Mon, 20 April 2015 12:53 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1775
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 20/04/2015 13:09, Boris Brodski wrote:
> Hello Lorenzo,
>
>
> thank you very much for the reply. I already studied your conversation
> with Sebastian about this:
> https://www.eclipse.org/forums/index.php/t/864890/
>
> But after applying your solution only the last inferred annotation get
> generated. But you managed to get your annotation generated on all
> needed targets?

Hi Boris

Yes I did; but that code was built with Xtext 2.7.3: I still haven't
upgraded it to Xtext 2.8...


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Reusing XAnnotation [message #1693642 is a reply to message #1692886] Mon, 27 April 2015 08:47 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 111
Registered: July 2009
Senior Member
Hello Lorenzo,


it works indeed! Thank you very much!


Cheers,
Boris
Re: Reusing XAnnotation [message #1693712 is a reply to message #1693642] Mon, 27 April 2015 19:06 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1775
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 27/04/2015 10:47, Boris Brodski wrote:
> Hello Lorenzo,
>
>
> it works indeed! Thank you very much!

Oh, so it works in Xtext 2.8 as well, following the same strategy?

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Reusing XAnnotation [message #1694026 is a reply to message #1693712] Thu, 30 April 2015 07:36 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 111
Registered: July 2009
Senior Member
Hello Lorenzo,

yes, I tested it with Xtext 2.8.1.v201503230617.

Cheers,
Boris
Re: Reusing XAnnotation [message #1694036 is a reply to message #1694026] Thu, 30 April 2015 08:23 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1775
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 30/04/2015 09:36, Boris Brodski wrote:
> Hello Lorenzo,
>
> yes, I tested it with Xtext 2.8.1.v201503230617.
>
> Cheers,
> Boris

great! :)

in the meantime I also ported that DSL to Xtext 2.8.2 and everything works.

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Previous Topic:How to avoid validation trigger in Xtext
Next Topic:assigned value will possible override itself
Goto Forum:
  


Current Time: Sun Apr 18 21:53:51 GMT 2021

Powered by FUDForum. Page generated in 0.03028 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top