Put error mark at right EStructuralFeature [message #1011999] |
Wed, 20 February 2013 12:00  |
Eclipse User |
|
|
|
I have a custom validation fucntion that validates the entire docuemtn against a json schema.
The json schema validator return the path to element in the document it found an error against.
if you have this json doc
{
"test1": "test1",
"test2": {
"test1": "test1",
"test2": []
}
}
The validator returns something like this "/test1/test2 should be a sting"
I am now trying to have xtext put the error mark on the right line.
I just go over the root eobject and find the right member for the json path.
But if I pass this eobject.eContainingFeature() to error() I get the folowing error:
ERROR org.eclipse.xtext.validation.CompositeEValidator - Error executing EValidator
java.lang.IllegalArgumentException: The sources EClass 'Object' does not expose the feature 'Generic.name'
at org.eclipse.xtext.validation.FeatureBasedDiagnostic.<init>(FeatureBasedDiagnostic.java:33)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.createDiagnostic(AbstractDeclarativeValidator.java:427)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.acceptError(AbstractDeclarativeValidator.java:400)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.error(AbstractDeclarativeValidator.java:381)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.error(AbstractDeclarativeValidator.java:369)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.error(AbstractDeclarativeValidator.java:357)
at com.nuance.voconhint.validation.JsonJavaValidator.validateSchema(JsonJavaValidator.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator$MethodWrapper.invoke(AbstractDeclarativeValidator.java:109)
at org.eclipse.xtext.validation.AbstractDeclarativeValidator.internalValidate(AbstractDeclarativeValidator.java:291)
at org.eclipse.xtext.validation.AbstractInjectableValidator.validate(AbstractInjectableValidator.java:62)
at org.eclipse.xtext.validation.CompositeEValidator.validate(CompositeEValidator.java:126)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:159)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:137)
at org.eclipse.xtext.validation.CancelableDiagnostician.validate(CancelableDiagnostician.java:36)
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:120)
at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:108)
at org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:79)
at org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:1)
at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:32)
at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:78)
at org.eclipse.xtext.ui.editor.validation.ValidationJob.createIssues(ValidationJob.java:75)
at org.eclipse.xtext.ui.editor.validation.ValidationJob.run(ValidationJob.java:64)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
The eobject that I pass to error() is an Array (as described in the grammar),
it is not a Generic eobject but why should it be?
Object:
{Object} '{'
(members+=Member)?
(',' members+=Member)*
'}';
Member:
Generic | ...;
Generic:
key=STRING ':' name=Value;
Value:
Object | STRING | Array | Boolean | Null | NUMBER;
Array:
{Array} '[' (values+=Value)? (',' values+=Value)* ']';
...
If I try to take the eContainer() of the "error object" it puts the error mark on /test1 instead of on /test2.
How can I get tight EStructuralFeature from the
|
|
|
|
|
Re: Put error mark at right EStructuralFeature [message #1015195 is a reply to message #1015168] |
Wed, 27 February 2013 12:36  |
Eclipse User |
|
|
|
Hi,
i am not quite sure what your problem is. if your a looking for a kind of holzhammer and do not
want to mark a specific feature you can try
error ("bad", errorObj.eContainer(), errorObj.eContainingFeature(), -1);
but i still would prefer
error ("bad", errorObj, Yourpackage.Literals.SOME_SPECIFIC_FEATURE, -1);
|
|
|
Powered by
FUDForum. Page generated in 0.05471 seconds