use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class AbstractDeclarativeValidator method createDiagnostic.
protected Diagnostic createDiagnostic(Severity severity, String message, EObject object, int offset, int length, String code, String... issueData) {
int diagnosticSeverity = toDiagnosticSeverity(severity);
Diagnostic result = new RangeBasedDiagnostic(diagnosticSeverity, message, object, offset, length, state.get().currentCheckType, code, issueData);
return result;
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testWarningWithCode.
@Test
public void testWarningWithCode() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
warning("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, "42");
}
};
BasicDiagnostic chain = new BasicDiagnostic();
test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
assertEquals(1, chain.getChildren().size());
Diagnostic diag = chain.getChildren().get(0);
assertEquals("Error Message", diag.getMessage());
assertEquals(0, diag.getCode());
assertTrue(diag instanceof FeatureBasedDiagnostic);
assertEquals("42", ((FeatureBasedDiagnostic) diag).getIssueCode());
assertEquals(Diagnostic.WARNING, diag.getSeverity());
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class DeclarativeValidatorTest method testErrorWithCode.
@Test
public void testErrorWithCode() {
AbstractDeclarativeValidator test = new AbstractDeclarativeValidator() {
@Check
public void foo(Object x) {
error("Error Message", EcorePackage.Literals.ENAMED_ELEMENT__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, "42");
}
};
BasicDiagnostic chain = new BasicDiagnostic();
test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.emptyMap());
assertEquals(1, chain.getChildren().size());
Diagnostic diag = chain.getChildren().get(0);
assertEquals("Error Message", diag.getMessage());
assertEquals(0, diag.getCode());
assertTrue(diag instanceof FeatureBasedDiagnostic);
assertEquals("42", ((FeatureBasedDiagnostic) diag).getIssueCode());
assertEquals(Diagnostic.ERROR, diag.getSeverity());
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class ImportUriValidatorTest method emptyImportURIStringShouldBeInvalid.
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=385620
*/
@Test
public void emptyImportURIStringShouldBeInvalid() throws Exception {
String model = "import ''";
Resource resource = getResourceFromString(model);
Diagnostic diagnostics = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
assertEquals(Diagnostic.ERROR, diagnostics.getSeverity());
}
use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.
the class AbstractDeclarativeValidator method createDiagnostic.
protected Diagnostic createDiagnostic(Severity severity, String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) {
int diagnosticSeverity = toDiagnosticSeverity(severity);
Diagnostic result = new FeatureBasedDiagnostic(diagnosticSeverity, message, object, feature, index, state.get().currentCheckType, code, issueData);
return result;
}
Aggregations