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!