Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350748 - [Xbase] XExpressionHelper.isLiteral(XExpression) doesn't support extensions
Summary: [Xbase] XExpressionHelper.isLiteral(XExpression) doesn't support extensions
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: SR1   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-29 16:45 EDT by Stephane Barbey CLA
Modified: 2017-09-19 17:59 EDT (History)
3 users (show)

See Also:
sven.efftinge: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephane Barbey CLA 2011-06-29 16:45:10 EDT
Build Identifier:  20110615-0604

The implementation of org.eclipse.xtext.xbase.util.XExpressionHelper.isLiteral(XExpression) is based on the value yielded by expr.eClass().getClassifierID(). 

This value is unique within an EPackage, but not within a language: I have e.g. a language that extends XBase and adds an

XGuardExpression returns xbase::XExpression : ...; 

that gets the classifier ID 13, i.e. the same as XSTRING_LITERAL in Xbase. As a consequence, this rule is considered as being a Literal by XExpressionHelper.

This can have various consequences depending on the usage of this helper function. In my particular case, I have introduced XGuardExpression as part of a XBlockExpression, and thus the validation rule 

	@Check
	public void checkInnerExpressions(XBlockExpression block) {
		for (int i = 0; i < block.getExpressions().size() - 1; ++i) {
			XExpression expr = block.getExpressions().get(i);
			if (expressionHelper.isLiteral(expr)) {
				error("Literals can only appear as the last element of a block expression", expr, null,
						ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_INNER_EXPRESSION);
			}
		}
	}

fails each time it encounters a XGuardExpression.



Reproducible: Always
Comment 1 Stephane Barbey CLA 2011-06-29 17:15:17 EDT
Workaround: inject one's XExpressionHelper instead of the standard one.
Comment 2 Jan Koehnlein CLA 2011-07-07 07:04:46 EDT
Maybe we should introduce a marker interface for literal classes?
Comment 3 Sebastian Zarnekow CLA 2011-07-19 09:49:20 EDT
The default implementation checks only types from XbasePackage
Comment 4 Karsten Thoms CLA 2017-09-19 17:48:40 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:59:42 EDT
Closing all bugs that were set to RESOLVED before Neon.0