Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Put error mark at right EStructuralFeature
Put error mark at right EStructuralFeature [message #1011999] Wed, 20 February 2013 17:00 Go to next message
Mr Manner is currently offline Mr Manner
Messages: 26
Registered: January 2013
Junior Member
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 #1012547 is a reply to message #1011999] Thu, 21 February 2013 19:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6378
Registered: July 2009
Senior Member
Hi,

if your object does not have a name so why do you attach the error the the name feature then?
so in your case if you want to mark name then you have to pass a Generic as object
(use the method org.eclipse.xtext.validation.AbstractDeclarativeValidator.error(String, EObject, EStructuralFeature, int)
instead - use -1 as index)
Re: Put error mark at right EStructuralFeature [message #1015168 is a reply to message #1012547] Wed, 27 February 2013 16:01 Go to previous messageGo to next message
Mr Manner is currently offline Mr Manner
Messages: 26
Registered: January 2013
Junior Member
Sorry for the post bump.
The issue here seems that I have a validation function that gets called when an Object changes and this validation functions validates the entire file not just the eobject that gets passed to it.
Because of that it expect the structural feature to be a Generic but in this validation function it can be any eobject type that can be in the grammar.

The pseudo code of the validation function is something like this:

@Check
validateRootObject(Object obj)
  if (obj.eContainer != null)
    return;

  String text = NodeModelUtils.getTokenText(NodeModelUtils.findActualNodeFor(object));
  EObject errorObj = validateAll(text);
  if (errorObj != null) {
    error(put error on the place where errorObj is in the editor);
  }


Maybe I am using the validation function wrong.
Is there a way I can use any eobject to put an error mark in place or alternatively a way to add error marks to the editor without going through the validation functions?

Thanks
Re: Put error mark at right EStructuralFeature [message #1015195 is a reply to message #1015168] Wed, 27 February 2013 17:36 Go to previous message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6378
Registered: July 2009
Senior Member
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);
Previous Topic:Adding a toolbar item to an xtext editor (org.eclipse.ui.editorActions is depcreated in 4.2 eclipse
Next Topic:XtextEditor with folding disabled by default
Goto Forum:
  


Current Time: Tue Oct 21 00:32:44 GMT 2014

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

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