use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project n4js by eclipse.
the class ErrorAwareLinkingService method addError.
/**
* Add the error to the resource of the given {@code context} if it does support validation.
*
* @param context
* the context object that caused the error.
* @param node
* the error location.
* @param error
* the actual error description.
*/
protected void addError(EObject context, INode node, IEObjectDescriptionWithError error) {
N4JSResource resource = (N4JSResource) context.eResource();
if (resource.isValidationDisabled())
return;
List<Diagnostic> list = resource.getErrors();
// Convert key value user data to String array
String[] userData = null;
if (error.getUserDataKeys() != null) {
ArrayList<String> userDataList = new ArrayList<>(error.getUserDataKeys().length * 2);
for (String userDataKey : error.getUserDataKeys()) {
final String userDataValue = error.getUserData(userDataKey);
if (userDataValue != null) {
userDataList.add(userDataKey);
userDataList.add(userDataValue);
}
}
userData = userDataList.toArray(new String[userDataList.size()]);
}
Diagnostic diagnostic = new XtextLinkingDiagnostic(node, error.getMessage(), error.getIssueCode(), userData);
if (!list.contains(diagnostic))
list.add(diagnostic);
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project joynr by bmwcarit.
the class Executor method generate.
public void generate() {
ModelLoader modelLoader = prepareGeneratorEnvironment();
for (Resource resource : modelLoader.getResources()) {
if (resource.getErrors().size() > 0) {
StringBuilder errorMsg = new StringBuilder();
errorMsg.append("Error loading model " + resource.getURI().toString() + ". The following errors occured: \n");
for (Diagnostic error : resource.getErrors()) {
errorMsg.append(error.getMessage());
}
logger.log(Level.SEVERE, errorMsg.toString());
System.exit(-1);
} else {
generator.doGenerate(resource, outputFileSystem);
}
}
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project smarthome by eclipse.
the class ScriptParsingException method addDiagnosticErrors.
public ScriptParsingException addDiagnosticErrors(List<Diagnostic> errors) {
for (Diagnostic emfDiagnosticError : errors) {
if (emfDiagnosticError instanceof AbstractDiagnostic) {
AbstractDiagnostic e = (AbstractDiagnostic) emfDiagnosticError;
this.getErrors().add(new ScriptError(e.getMessage(), e.getLine(), e.getOffset(), e.getLength()));
} else if (emfDiagnosticError instanceof ExceptionDiagnostic) {
ExceptionDiagnostic e = (ExceptionDiagnostic) emfDiagnosticError;
this.getErrors().add(new ScriptError(e.getMessage(), e.getLine(), e.getOffset(), e.getLength()));
} else {
this.getErrors().add(new ScriptError(emfDiagnosticError.getMessage(), -1, -1, -1));
}
}
return this;
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project n4js by eclipse.
the class PositiveAnalyser method analyse.
/*
* (non-Javadoc)
*
* @see org.eclipse.n4js.tests.libraryparsing.analysis.DiagnosticAnalyser #analyse(java.util.List, java.lang.String,
* java.lang.String)
*/
@Override
public void analyse(Script script, String codeName, String code) {
List<Diagnostic> errors = null;
try {
errors = getScriptErrors(script);
// if (serializerTester != null) {
// serializerTester.assertSerializeWithNodeModel(script);
// }
} catch (Throwable t) {
StringWriter writer = new StringWriter();
t.printStackTrace(new PrintWriter(writer));
assertEquals(code, writer.toString());
return;
}
if (!errors.isEmpty()) {
String msg = "expected no errors in " + codeName + " but I got : " + errors.size();
if (this.logger.isDebugEnabled()) {
StringBuilder sb = new StringBuilder(msg).append("\n");
sb.append("========== " + codeName + " ==========\n");
if (this.logCode) {
sb.append(code).append("\n");
}
sb.append(">>>> errors: ").append("\n");
sb.append(this.aggregateDiagnosticsToStringBuilder(codeName, errors));
sb.append(">>>> warnings: ").append("\n");
sb.append("<<<<").append("\n");
sb.append("========================================").append("\n");
this.logger.debug(sb);
}
assertEquals(msg, withLineNumbers(code), this.aggregateDiagnosticsToStringBuilder(codeName, errors).toString());
}
}
use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project coffeescript-eclipse by adamschmideg.
the class ParserTestBase method expect.
/**
* Parse and check for errors and warnings
* @param errorCount 1 means expect error(s)
* @param warningCount -1 means don't care about warnings
*/
protected void expect(CharSequence input, int errorCount, int warningCount) {
List<String> tokens = null;
// Assert::assertEquals('warnings ' + resource.warnings, 0, resource.warnings.size)
// Assert::assertEquals('errors ' + resource.errors, 0, resource.errors.size)
EObject parseResult = null;
EList<Diagnostic> errors = null;
EList<Diagnostic> warnings = null;
try {
Lexer lexer = new Lexer(input);
tokens = lexer.tokenizeToStrings();
InputStream in = getAsStream("" + input);
URI uri = URI.createURI("mytestmodel." + getCurrentFileExtension());
XtextResource resource = doGetResource(in, uri);
parseResult = getModel(resource);
errors = resource.getErrors();
warnings = resource.getWarnings();
if (errorCount == 0)
assertEquals("Errors: " + errors, 0, errors.size());
else if (errorCount > 0)
assertTrue("No errors", errors.size() > 0);
if (warningCount >= 0) {
assertEquals("Warnings: " + warnings, warningCount, warnings.size());
}
} catch (AssertionFailedError afe) {
if (logger.isDebugEnabled()) {
String debug = "" + this.getClass().getSimpleName() + " input: \n" + input + "\n";
debug += "Tokens: " + tokens + "\n" + Helper.stringify(parseResult);
for (Diagnostic d : errors) {
debug += "\tError: " + d + "\n";
}
for (Diagnostic d : warnings) {
debug += "\tWarning: " + d + "\n";
}
logger.debug(debug);
}
throw new AssertionError(afe);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations