Reusing XAnnotation [message #1692853] |
Mon, 20 April 2015 05:10  |
Eclipse User |
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.10790 seconds