Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Errors set in JavaValidator don't appear in the generation
Errors set in JavaValidator don't appear in the generation [message #757491] Fri, 18 November 2011 16:05 Go to next message
Rafael Angarita is currently offline Rafael AngaritaFriend
Messages: 94
Registered: November 2010
Member
Hello,

I found out, in the code generation, that my resources don't have the errors I set in my JavaValidator, even though those errors appear in the Problems View. This happens using both a BuilderParticipant and a Context Menu. I wrote a little example using the Context Menu.

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID '!';



public class MyDslJavaValidator extends AbstractMyDslJavaValidator {

	@Check
	public void checkGreetingStartsWithCapital(Greeting greeting) {
		if (!Character.isUpperCase(greeting.getName().charAt(0))) {
			error("Name should start with a capital", MyDslPackage.Literals.GREETING__NAME);
		}
	}

}


public class Action1
	extends ActionDelegate
	implements IObjectActionDelegate {

	
	@Inject
	IResourceDescriptions resourceDescriptions;

	@Inject
	IResourceSetProvider resourceSetProvider;
	
	private ISelection selection;
	
	private IProject project;
	/**
	 * @see ActionDelegate#run(IAction)
	 */
	public void run(IAction action) {
		IFile file = (IFile) ( (IStructuredSelection) selection).getFirstElement();
		project =  file.getProject();
		String path = file.getFullPath().toString();
	
		
		URI uri = URI.createPlatformResourceURI(path, true);
		ResourceSet rs = resourceSetProvider.get(project);
		
		
		Resource r = rs.getResource(uri, true);
		
		EcoreUtil.resolveAll(r);

		if(r.getErrors().size() == 0) {
			//it always enters here if I have errors set in the JavaValidator
		}

	}


 <extension
        point="org.eclipse.ui.popupMenus">
     <objectContribution
           id="org.xtext.example.mydsl.ui.objectContribution1"
           nameFilter="*.mydsl"
           objectClass="org.eclipse.core.resources.IFile">
        <action
              class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.xtext.example.mydsl.ui.Action1"
              enablesFor="1"
              id="org.xtext.example.mydsl.ui.action1"
              label="Test"
              menubarPath="addition"
              style="push">
        </action>
     </objectContribution>
  </extension>



If I make a grammar mistake that is detected by default, it is saved in the resource, and the validation in my Action or BuilderParticipant works fine. I guess I missing something.

Thanks!
Re: Errors set in JavaValidator don't appear in the generation [message #757493 is a reply to message #757491] Fri, 18 November 2011 16:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

you dont call the validator. see http://www.eclipse.org/Xtext/documentation/2_1_0/060-validation.php#validation_4

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Invalidating the builder state
Next Topic:GeneratorFragment refused to work
Goto Forum:
  


Current Time: Sat Apr 27 00:21:28 GMT 2024

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

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

Back to the top