use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testDefinedLiteralTwice.
@Test
public void testDefinedLiteralTwice() throws Exception {
XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/validation/literal/2'\n" + "Model: enumValue=GeneratedEnum;\n" + "enum GeneratedEnum: SameName ='value' | SameName='otherValue';");
assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
assertNotNull("diag", diag);
assertEquals(diag.getChildren().toString(), 1, diag.getChildren().size());
assertEquals("diag.isWarning", diag.getSeverity(), Diagnostic.WARNING);
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testLeftRecursion_Bug_285605_05.
@Test
public void testLeftRecursion_Bug_285605_05() throws Exception {
XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate foo 'http://foo/bar'\n" + "RuleA : ruleB=RuleB;\n" + "RuleB : ruleC=RuleC;\n" + "RuleC : ruleA=RuleA ruleB=RuleB;\n");
assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
assertNotNull("diag", diag);
assertEquals(diag.getChildren().toString(), 4, diag.getChildren().size());
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testExplicitOverride05.
@Test
public void testExplicitOverride05() throws Exception {
XtextResource resource = getResourceFromString("grammar org.foo.Bar\n" + "import \"http://www.eclipse.org/emf/2002/Ecore\" as ecore" + "@Override\n" + "terminal ID: ('a'..'z'|'A'..'Z'|'_');");
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
List<Diagnostic> issues = diag.getChildren();
assertEquals(issues.toString(), 1, issues.size());
assertEquals("This grammar has no super grammar and therefore cannot override any rules.", issues.get(0).getMessage());
assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextGeneratorLanguage method validateGrammar.
protected void validateGrammar(final Grammar grammar) {
this.validateAllImports(grammar);
final EValidator validator = EValidator.Registry.INSTANCE.getEValidator(XtextPackage.eINSTANCE);
if ((validator != null)) {
final DiagnosticChain chain = new DiagnosticChain() {
@Override
public void add(final Diagnostic diagnostic) {
int _severity = diagnostic.getSeverity();
boolean _equals = (_severity == Diagnostic.ERROR);
if (_equals) {
String _name = grammar.getName();
String _plus = ("Validation Error in " + _name);
final String grammarName = (_plus + ": ");
Throwable _exception = diagnostic.getException();
boolean _tripleEquals = (_exception == null);
if (_tripleEquals) {
String _message = diagnostic.getMessage();
String _plus_1 = (grammarName + _message);
throw new IllegalStateException(_plus_1);
} else {
String _message_1 = diagnostic.getMessage();
String _plus_2 = (grammarName + _message_1);
Throwable _exception_1 = diagnostic.getException();
throw new IllegalStateException(_plus_2, _exception_1);
}
}
}
@Override
public void addAll(final Diagnostic diagnostic) {
this.add(diagnostic);
}
@Override
public void merge(final Diagnostic diagnostic) {
throw new UnsupportedOperationException();
}
};
validator.validate(grammar, chain, null);
final TreeIterator<EObject> iterator = grammar.eAllContents();
while (iterator.hasNext()) {
EObject _next = iterator.next();
HashMap<Object, Object> _hashMap = new HashMap<Object, Object>();
validator.validate(_next, chain, _hashMap);
}
}
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class EMFGeneratorFragment2 method doGenerate.
protected void doGenerate(final GenModel genModel) {
final Generator generator = new Generator() {
@Override
public JControlModel getJControlModel() {
if ((this.jControlModel == null)) {
JControlModel _jControlModel = new JControlModel();
this.jControlModel = _jControlModel;
this.jControlModel.initialize(null, this.options.mergeRulesURI);
}
return this.jControlModel;
}
};
GeneratorAdapterFactory.Descriptor.Registry _adapterFactoryDescriptorRegistry = generator.getAdapterFactoryDescriptorRegistry();
String _lineDelimiter = this.codeConfig.getLineDelimiter();
CvsIdFilteringGeneratorAdapterFactoryDescriptor _cvsIdFilteringGeneratorAdapterFactoryDescriptor = new CvsIdFilteringGeneratorAdapterFactoryDescriptor(_lineDelimiter);
_adapterFactoryDescriptorRegistry.addDescriptor(GenModelPackage.eNS_URI, _cvsIdFilteringGeneratorAdapterFactoryDescriptor);
genModel.setCanGenerate(true);
generator.setInput(genModel);
BasicMonitor _basicMonitor = new BasicMonitor();
final Diagnostic diagnostic = generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, _basicMonitor);
int _severity = diagnostic.getSeverity();
boolean _notEquals = (_severity != Diagnostic.OK);
if (_notEquals) {
EMFGeneratorFragment2.LOG.warn(diagnostic);
}
if (this.generateEdit) {
BasicMonitor _basicMonitor_1 = new BasicMonitor();
final Diagnostic editDiag = generator.generate(genModel, GenBaseGeneratorAdapter.EDIT_PROJECT_TYPE, _basicMonitor_1);
int _severity_1 = editDiag.getSeverity();
boolean _notEquals_1 = (_severity_1 != Diagnostic.OK);
if (_notEquals_1) {
EMFGeneratorFragment2.LOG.warn(editDiag);
}
}
if (this.generateEditor) {
BasicMonitor _basicMonitor_2 = new BasicMonitor();
final Diagnostic editorDiag = generator.generate(genModel, GenBaseGeneratorAdapter.EDITOR_PROJECT_TYPE, _basicMonitor_2);
int _severity_2 = editorDiag.getSeverity();
boolean _notEquals_2 = (_severity_2 != Diagnostic.OK);
if (_notEquals_2) {
EMFGeneratorFragment2.LOG.warn(editorDiag);
}
}
}
Aggregations