use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class ResourceValidatorImpl method validate.
/**
* @since 2.4
*/
protected void validate(Resource resource, EObject element, final CheckMode mode, final CancelIndicator monitor, IAcceptor<Issue> acceptor) {
try {
Map<Object, Object> options = Maps.newHashMap();
options.put(CheckMode.KEY, mode);
options.put(CancelableDiagnostician.CANCEL_INDICATOR, monitor);
// disable concrete syntax validation, since a semantic model that has been parsed
// from the concrete syntax always complies with it - otherwise there are parse errors.
options.put(ConcreteSyntaxEValidator.DISABLE_CONCRETE_SYNTAX_EVALIDATOR, Boolean.TRUE);
// see EObjectValidator.getRootEValidator(Map<Object, Object>)
options.put(EValidator.class, diagnostician);
if (resource instanceof XtextResource) {
options.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, ((XtextResource) resource).getLanguageName());
}
Diagnostic diagnostic = diagnostician.validate(element, options);
if (!diagnostic.getChildren().isEmpty()) {
for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
issueFromEValidatorDiagnostic(childDiagnostic, acceptor);
}
} else {
issueFromEValidatorDiagnostic(diagnostic, acceptor);
}
} catch (RuntimeException e) {
operationCanceledManager.propagateAsErrorIfCancelException(e);
log.error(e.getMessage(), e);
}
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidator method checkGeneratedPackage.
public void checkGeneratedPackage(GeneratedMetamodel metamodel, Diagnostician diagnostician, Map<?, ?> params) {
EPackage pack = metamodel.getEPackage();
if (pack != null) {
Diagnostic packageValidationResult = diagnostician.validate(pack, params);
ValidationMessageAcceptor filter = new AbstractValidationMessageAcceptor() {
Set<Triple<EObject, EStructuralFeature, String>> accepted = Sets.newHashSet();
@Override
public void acceptInfo(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) {
if (accepted.add(Tuples.create(object, feature, message))) {
XtextValidator.this.getMessageAcceptor().acceptInfo(message, object, feature, index, code, issueData);
}
}
@Override
public void acceptWarning(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) {
if (accepted.add(Tuples.create(object, feature, message))) {
XtextValidator.this.getMessageAcceptor().acceptWarning(message, object, feature, index, code, issueData);
}
}
@Override
public void acceptError(String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) {
if (accepted.add(Tuples.create(object, feature, message))) {
XtextValidator.this.getMessageAcceptor().acceptError(message, object, feature, index, code, issueData);
}
}
};
propageValidationResult(packageValidationResult, metamodel, filter);
}
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class Bug456789Test method doesNotHang_02.
@Test(timeout = 5000)
public void doesNotHang_02() {
try {
StringConcatenation _builder = new StringConcatenation();
_builder.append("grammar com.acme.G with org.eclipse.xtext.common.Terminals");
_builder.newLine();
_builder.newLine();
_builder.append("generate g \"bug456789\"");
_builder.newLine();
_builder.newLine();
_builder.append("File: (NL | statements+=Statement)*;");
_builder.newLine();
_builder.newLine();
_builder.append("Declaration: ClassDeclaration | FunctionDeclaration;");
_builder.newLine();
_builder.append("FunctionDeclaration: \'def\' name=ID parameters=Parameters \':\' body=Suite;");
_builder.newLine();
_builder.append("Parameters: \'(\' list=Varargslist? \')\';");
_builder.newLine();
_builder.append("Varargslist:");
_builder.newLine();
_builder.append("\t");
_builder.append("(params+=ParameterWithDefault (\',\' params+=ParameterWithDefault)*");
_builder.newLine();
_builder.append("\t");
_builder.append("(\',\' (params+=ExcessPositionalParameterDef (\',\' params+=ExcessKeywordParameterDef)? | params+=ExcessKeywordParameterDef)?)?)?");
_builder.newLine();
_builder.append("\t");
_builder.append("| params+=ExcessPositionalParameterDef (\',\' params+=ExcessKeywordParameterDef)? ");
_builder.newLine();
_builder.append("\t");
_builder.append("| params+=ExcessKeywordParameterDef;");
_builder.newLine();
_builder.newLine();
_builder.append("ParameterWithDefault returns ParameterDef:");
_builder.newLine();
_builder.append("\t");
_builder.append("ParameterDef ({ParameterWithDefault.param=current} \'=\' default=Test)");
_builder.newLine();
_builder.append(";");
_builder.newLine();
_builder.append("ParameterDef: SimpleParameterDef | TupleParameterDef;");
_builder.newLine();
_builder.append("ExcessPositionalParameterDef returns ParameterDef: {ExcessPositionalParameterDef} \'*\' name=ID;");
_builder.newLine();
_builder.append("ExcessKeywordParameterDef returns ParameterDef: {ExcessKeywordParameterDef} \'**\' name=ID;");
_builder.newLine();
_builder.append("SimpleParameterDef: name=ID;");
_builder.newLine();
_builder.append("TupleParameterDef: params+=ParameterDef (\',\' params+=ParameterDef)* (\',\')?;");
_builder.newLine();
_builder.newLine();
_builder.append("Statement: SimpleStatement | CompoundStatement;");
_builder.newLine();
_builder.append("SimpleStatement: SmallStatement ({SmallStatementList.statements+=current} \';\' statements+=SmallStatement)* \';\'? NL;");
_builder.newLine();
_builder.append("SmallStatement: ");
_builder.newLine();
_builder.append("\t");
_builder.append("ExprStatement | PrintStatement | DelStatement | PassStatement | FlowStatement |");
_builder.newLine();
_builder.append(" ");
_builder.append("ExecStatement | AssertStatement;");
_builder.newLine();
_builder.append("ExprStatement: Testlist ");
_builder.newLine();
_builder.append("\t");
_builder.append("(assignment=AugAssign value=Assignable | (\'=\' value=Assignable)*);");
_builder.newLine();
_builder.newLine();
_builder.append("Assignable returns Expression: YieldExpression | Testlist;");
_builder.newLine();
_builder.append("AugAssign: \'+=\' | \'-=\' | \'*=\' | \'/=\' | \'%=\' | \'&=\' | \'|=\' | \'^=\' |");
_builder.newLine();
_builder.append(" ");
_builder.append("\'<<=\' | \'>>=\' | \'**=\' | \'//=\';");
_builder.newLine();
_builder.append("PrintStatement: \'print\'|\'>>\' ( values+=Test (\',\' values+=Test)* (\',\')? )?;");
_builder.newLine();
_builder.append("DelStatement: \'del\' expression=Expressionlist;");
_builder.newLine();
_builder.append("PassStatement: {PassStatement} \'pass\';");
_builder.newLine();
_builder.append("FlowStatement: BreakStatement | ContinueStatement | ReturnStatement | RaiseStatement | YieldStatement;");
_builder.newLine();
_builder.append("BreakStatement: {BreakStatement} \'break\';");
_builder.newLine();
_builder.append("ContinueStatement: {ContinueStatement} \'continue\';");
_builder.newLine();
_builder.append("ReturnStatement: {ReturnStatement} \'return\' value=Testlist?;");
_builder.newLine();
_builder.append("YieldStatement: {YieldStatement} value=YieldExpression;");
_builder.newLine();
_builder.append("RaiseStatement: {RaiseStatement} \'raise\' (firstValue=Test (\',\' secondValue=Test (\',\' thirdValue=Test)?)?)?;");
_builder.newLine();
_builder.append("FQN: ID (\'.\' ID)*;");
_builder.newLine();
_builder.append("ExecStatement: \'exec\' expression=Expression (\'in\' tests+=Test (\',\' tests+=Test)?)?;");
_builder.newLine();
_builder.append("AssertStatement: \'assert\' tests+=Test (\',\' tests+=Test)?;");
_builder.newLine();
_builder.newLine();
_builder.append("CompoundStatement: IfStatement | WhileStatement | ForStatement | TryStatement | WithStatement | Declaration;");
_builder.newLine();
_builder.append("IfStatement: \'if\' conditions=Test \':\' thens=Suite (\'elif\' conditions=Test \':\' thens=Suite)* (\'else\' \':\' else=Suite)?;");
_builder.newLine();
_builder.append("WhileStatement: \'while\' conditions=Test \':\' body=Suite (\'else\' \':\' else=Suite)?;");
_builder.newLine();
_builder.append("ForStatement: \'for\' expressionList=Exprlist \'in\' in=Testlist \':\' body=Suite (\'else\' \':\' else=Suite)?;");
_builder.newLine();
_builder.append("TryStatement: (\'try\' \':\' try=Suite");
_builder.newLine();
_builder.append(" ");
_builder.append("((except_clause \':\' Suite)+");
_builder.newLine();
_builder.append(" ");
_builder.append("(\'else\' \':\' else=Suite)?");
_builder.newLine();
_builder.append(" ");
_builder.append("(\'finally\' \':\' finally=Suite)? |");
_builder.newLine();
_builder.append(" ");
_builder.append("\'finally\' \':\' finally=Suite));");
_builder.newLine();
_builder.append("withStatement: \'with\' with_item (\',\' with_item)* \':\' suite;");
_builder.newLine();
_builder.append("with_item: test (\'as\' expr)?;");
_builder.newLine();
_builder.append("except_clause: \'except\' (test ((\'as\' | \',\') test)?)?;");
_builder.newLine();
_builder.append("suite: simpleStatement | NL INDENT stmt+ DEDENT;");
_builder.newLine();
_builder.newLine();
_builder.append("testlist_safe: old_test ((\',\' old_test)+ (\',\')?)?;");
_builder.newLine();
_builder.append("old_test: or_test | old_lambdef;");
_builder.newLine();
_builder.append("old_lambdef: \'lambda\' (varargslist)? \':\' old_test;");
_builder.newLine();
_builder.newLine();
_builder.append("test: or_test (\'if\' or_test \'else\' test)? | lambdef;");
_builder.newLine();
_builder.append("or_test: and_test (\'or\' and_test)*;");
_builder.newLine();
_builder.append("and_test: not_test (\'and\' not_test)*;");
_builder.newLine();
_builder.append("not_test: \'not\' not_test | comparison;");
_builder.newLine();
_builder.append("comparison: expr (comp_op expr)*;");
_builder.newLine();
_builder.append("comp_op: \'<\'|\'>\'|\'==\'|\'>=\'|\'<=\'|\'<>\'|\'!=\'|\'in\'|\'not\' \'in\'|\'is\'|\'is\' \'not\';");
_builder.newLine();
_builder.append("expr: xorExpression (\'|\' xorExpression)*;");
_builder.newLine();
_builder.append("xorExpression: andExpression (\'^\' andExpression)*;");
_builder.newLine();
_builder.append("andExpression: shiftExpression (\'&\' shiftExpression)*;");
_builder.newLine();
_builder.append("shiftExpression: arithExpression ((\'<<\'|\'>>\') arithExpression)*;");
_builder.newLine();
_builder.append("arithExpression: term ((\'+\'|\'-\') term)*;");
_builder.newLine();
_builder.append("term: factor ((\'*\'|\'/\'|\'%\'|\'//\') factor)*;");
_builder.newLine();
_builder.append("factor: (\'+\'|\'-\'|\'~\') factor | power;");
_builder.newLine();
_builder.append("power: atom trailer* (\'**\' factor)?;");
_builder.newLine();
_builder.append("atom: (\'(\' (yieldExpression|testlist_comp)? \')\' |");
_builder.newLine();
_builder.append(" ");
_builder.append("\'(\' (listmaker)? \')?\' |");
_builder.newLine();
_builder.append(" ");
_builder.append("\'{\' (dictorsetmaker)? \'}\' |");
_builder.newLine();
_builder.append(" ");
_builder.append("\'`\' testlist1 \'`\' |");
_builder.newLine();
_builder.append(" ");
_builder.append("ID | NUMBER | STRING+);");
_builder.newLine();
_builder.append("listmaker: test ( list_for | (\',\' test)* (\',\')? );");
_builder.newLine();
_builder.append("testlist_comp: test ( comp_for | (\',\' test)* (\',\')? );");
_builder.newLine();
_builder.append("lambdef: \'lambda\' (varargslist)? \':\' test;");
_builder.newLine();
_builder.append("trailer: \'(\' (arglist)? \')\' | \'(\' subscriptlist \')?\' | \'.\' ID;");
_builder.newLine();
_builder.append("subscriptlist: subscript (\',\' subscript)* (\',\')?;");
_builder.newLine();
_builder.append("subscript: \'.\' \'.\' \'.\' | test | (test)? \':\' (test)? (sliceop)?;");
_builder.newLine();
_builder.append("sliceop: \':\' (test)?;");
_builder.newLine();
_builder.append("exprlist: expr (\',\' expr)* (\',\')?;");
_builder.newLine();
_builder.append("testlist: test (\',\' test)* (\',\')?;");
_builder.newLine();
_builder.append("dictorsetmaker: ( (test \':\' test (comp_for | (\',\' test \':\' test)* (\',\')?)) |");
_builder.newLine();
_builder.append(" ");
_builder.append("(test (comp_for | (\',\' test)* (\',\')?)) );");
_builder.newLine();
_builder.newLine();
_builder.append("ClassDeclaration: \'class\' ID=ID (\'(\' (testlist)? \')\')? \':\' suite;");
_builder.newLine();
_builder.newLine();
_builder.append("arglist: (argument \',\')* (argument (\',\')?");
_builder.newLine();
_builder.append(" ");
_builder.append("|\'*\' test (\',\' argument)* (\',\' \'**\' test)? ");
_builder.newLine();
_builder.append(" ");
_builder.append("|\'**\' test);");
_builder.newLine();
_builder.append("argument: test (comp_for)? | test \'=\' test;");
_builder.newLine();
_builder.newLine();
_builder.append("list_iter: list_for | list_if;");
_builder.newLine();
_builder.append("list_for: \'for\' exprlist \'in\' testlist_safe (list_iter)?;");
_builder.newLine();
_builder.append("list_if: \'if\' old_test (list_iter)?;");
_builder.newLine();
_builder.newLine();
_builder.append("comp_iter: comp_for | comp_if;");
_builder.newLine();
_builder.append("comp_for: \'for\' exprlist \'in\' or_test (comp_iter)?;");
_builder.newLine();
_builder.append("comp_if: \'if\' old_test (comp_iter)?;");
_builder.newLine();
_builder.newLine();
_builder.append("testlist1: test (\',\' test)*;");
_builder.newLine();
_builder.newLine();
_builder.append("encoding_decl: ID;");
_builder.newLine();
_builder.newLine();
_builder.append("yieldExpression: \'yield\' (testlist)?;");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("INDENT: \'synthetic:INDENT\';");
_builder.newLine();
_builder.append("DEDENT: \'synthetic:DEDENT\';");
_builder.newLine();
_builder.newLine();
_builder.append("terminal SL_COMMENT: \'#\' !(\'\\n\'|\'\\r\'|EOF)*;");
_builder.newLine();
_builder.newLine();
_builder.append("terminal NL: \'\\r\'? \'\\n\'|\'\\r\';");
_builder.newLine();
_builder.newLine();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* tabs make 8 spaces");
_builder.newLine();
_builder.append(" ");
_builder.append("* indentation is computed from all spaces (tabs are converted first)");
_builder.newLine();
_builder.append(" ");
_builder.append("* ");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
final XtextResource resource = this.getResourceFromStringAndExpect(_builder.toString(), AbstractXtextTests.UNKNOWN_EXPECTATION);
final Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
Assert.assertNotNull("diag", diag);
Assert.assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class XtextValidationTest method testOverrideFinal.
@Test
public void testOverrideFinal() throws Exception {
XtextResourceSet rs = get(XtextResourceSet.class);
getResourceFromString("grammar org.xtext.Supergrammar with org.eclipse.xtext.common.Terminals\n" + "generate supergrammar \"http://org.xtext.supergrammar\"\n" + "@Final\n" + "RuleFinal:name=ID;\n" + "Rule: name=ID;", "superGrammar.xtext", rs);
XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.xtext.Supergrammar\n" + "generate bar \"http://org.xtext.Bar\"\n" + "RuleFinal: name=ID;", "foo.xtext", rs);
Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
List<Diagnostic> issues = diag.getChildren();
assertEquals(issues.toString(), 1, issues.size());
assertEquals("This rule illegally overrides RuleFinal in org.xtext.Supergrammar which is final.", 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 XtextValidationTest method testBug_280413_03.
@Test
@Ignore("TODO this one should yield a warning, because two different instances of a package (ecore itself) might be referenced.")
public void testBug_280413_03() throws Exception {
XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "import 'classpath:/org/eclipse/xtext/Xtext.ecore' as xtext\n" + "ParserRule returns xtext::ParserRule: name = ID;");
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.getSeverity(), Diagnostic.OK);
assertTrue(diag.getChildren().toString(), diag.getChildren().isEmpty());
}
Aggregations