Bug 427549 - [Serializer] InstanceFeatureDescription is accidentally created for static JvmFeature
Summary: [Serializer] InstanceFeatureDescription is accidentally created for static Jv...
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.5.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-06 05:11 EST by Oliver Libutzki CLA
Modified: 2014-02-06 06:56 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Libutzki CLA 2014-02-06 05:11:40 EST
After applying a semantic modification quick fix I get this exception:

java.lang.IllegalArgumentException: JvmField: org.example.Foo$FooInner.MAX_LENGTH (visibility: PUBLIC, simpleName: MAX_LENGTH, identifier: org.example.Foo$FooInner.MAX_LENGTH) (static: true, final: true, volatile: false, transient: false, constant: <unset>, constantValue: null)
	at org.eclipse.xtext.xbase.scoping.batch.InstanceFeatureDescription.<init>(InstanceFeatureDescription.java:45)
	at org.eclipse.xtext.xbase.scoping.batch.ReceiverFeatureScope.createDescription(ReceiverFeatureScope.java:107)
	at org.eclipse.xtext.xbase.scoping.batch.ReceiverFeatureScope.getAllLocalElements(ReceiverFeatureScope.java:147)
	at org.eclipse.xtext.xbase.scoping.batch.AbstractSessionBasedScope.getLocalElementsByEObject(AbstractSessionBasedScope.java:148)

Maybe the ReceiverFeatureScope has to filter static JvmMembers?

Do you have an idea for a workaround (beside manipulating the Xtext document directly)?
Comment 1 Sebastian Zarnekow CLA 2014-02-06 05:28:46 EST
Looks like the AST is messed up after the semantic modification.

What did you try to do? Just XAbstractFeatureCall.setFeature?
Did you also refine the implicit receiver and potentially implicit first arguments?

Generally speaking, modifying the text is often simpler / yields to easier to maintain code than trying to create / maintain a valid AST from code.
Comment 2 Sebastian Zarnekow CLA 2014-02-06 05:32:25 EST
But yes, AbstractSessionBasedScope#getLocalElementsByEObject may need some refinement.

In fact I would have expected that org.eclipse.xtext.xbase.serializer.SerializerScopeProvider.createFeatureCallSerializationScope(EObject) is used to create the scope.
Comment 3 Oliver Libutzki CLA 2014-02-06 06:19:29 EST
I have an XBlockExpression containing a XFeatureCall to org.example.Foo$FooInner.

But this XBlockExpression is not part of the semantic modification. It's just in the same resource.

I prefer creating the AST as you benefit from Java's typesystem. Changes in the metamodel might result in compile errors and you do not have to care about syntactic grammar changes.

The modification creates some qualified cross references. Modifying the text means I have to calculate (taking imports into account) the (shortest) qualified name by myself. I don't think the code is easier to maintain.

Generally, using text modification ports the failure detection to runtime, so you need tests to check. But I know which argument is in your mind now: "You need tests anyway." ;-)