public ZenModel loadAndValidateModel(URI modelUri) { Resource resource = getResource(modelUri); if (validator != null) { List<Issue> issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl); if (!issues.isEmpty()) { throw new RuntimeException(String.format(errorMessage, issues.get(0).getMessage())); } } else if (!resource.getErrors().isEmpty()) { throw new RuntimeException(String.format(errorMessage, resource.getErrors().get(0).getMessage())); } return (ZenModel) resource.getContents().get(0); }
/** * Returns a string representation of the given diagnostic object. * * @param diagnostic * The diagnostic * @return a string representation of the given diagnostic object. */ private static String diagnosticString(Diagnostic diagnostic) { StringBuffer buffer = new StringBuffer(); buffer.append(AcceleoCommonMessages .getString("ModelUtils.DiagnosticMessage", diagnostic.getMessage())); //$NON-NLS-1$ buffer.append('\n'); buffer.append(AcceleoCommonMessages.getString("ModelUtils.DiagnosticLocation", diagnostic //$NON-NLS-1$ .getLocation(), Integer.valueOf(diagnostic.getLine()), Integer .valueOf(diagnostic.getColumn()))); return buffer.toString(); }
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); } } }
criticalErrors .append(MessageFormat.format("[{0},{1}]: {2}\n", Integer.toString(diagnostic.getLine()), Integer.toString(diagnostic.getColumn()), diagnostic.getMessage()));
criticalErrors .append(MessageFormat.format("[{0},{1}]: {2}\n", Integer.toString(diagnostic.getLine()), Integer.toString(diagnostic.getColumn()), diagnostic.getMessage()));
"org.eclipse.emf.ecore.resource", 0, resourceDiagnostic.getMessage(), new Object[]{resourceDiagnostic}); "org.eclipse.emf.ecore.resource", 0, resourceDiagnostic.getMessage(), new Object[]{resourceDiagnostic});
"org.eclipse.emf.ecore.resource", 0, resourceDiagnostic.getMessage(), new Object[]{resourceDiagnostic}); "org.eclipse.emf.ecore.resource", 0, resourceDiagnostic.getMessage(), new Object[]{resourceDiagnostic});
System.out.println("Warning: " + diagnostic.getMessage()); if (errors != null && !errors.isEmpty()) { for (Diagnostic diagnostic : errors) { System.out.println("Error: " + diagnostic.getMessage());
System.out.println("Warning: " + diagnostic.getMessage()); if (errors != null && !errors.isEmpty()) { for (Diagnostic diagnostic : errors) { System.out.println("Error: " + diagnostic.getMessage());
System.out.println("Warning: " + diagnostic.getMessage()); if (errors != null && !errors.isEmpty()) { for (Diagnostic diagnostic : errors) { System.out.println("Error: " + diagnostic.getMessage());
public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception { XtextResource resource = doGetResource(in, uri); if (expectedErrors != UNKNOWN_EXPECTATION) { if (expectedErrors == EXPECT_ERRORS) assertFalse(resource.getErrors().toString(), resource.getErrors().isEmpty()); else assertEquals(resource.getErrors().toString(), expectedErrors, resource.getErrors().size()); } for(Diagnostic d: resource.getErrors()) { if (d instanceof ExceptionDiagnostic) fail(d.getMessage()); } for(Diagnostic d: resource.getWarnings()) System.out.println("Resource Warning: "+d); if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) { SerializerTester tester = get(SerializerTester.class); EObject obj = resource.getContents().get(0); tester.assertSerializeWithNodeModel(obj); tester.assertSerializeWithoutNodeModel(obj); } return resource; }
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) { IssueImpl issue = new Issue.IssueImpl(); issue.setSyntaxError(diagnostic instanceof XtextSyntaxDiagnostic); issue.setSeverity(severity); issue.setLineNumber(diagnostic.getLine()); issue.setMessage(diagnostic.getMessage()); // issue.setmarker.put(IMarker.PRIORITY, Integer.valueOf(IMarker.PRIORITY_LOW)); if (diagnostic instanceof org.eclipse.xtext.diagnostics.Diagnostic) { org.eclipse.xtext.diagnostics.Diagnostic xtextDiagnostic = (org.eclipse.xtext.diagnostics.Diagnostic) diagnostic; issue.setOffset(xtextDiagnostic.getOffset()); issue.setLength(xtextDiagnostic.getLength()); } if (diagnostic instanceof AbstractDiagnostic) { AbstractDiagnostic castedDiagnostic = (AbstractDiagnostic)diagnostic; issue.setUriToProblem(castedDiagnostic.getUriToProblem()); issue.setCode(castedDiagnostic.getCode()); issue.setData(castedDiagnostic.getData()); } issue.setType(CheckType.FAST); acceptor.accept(issue); }
public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception { XtextResource resource = doGetResource(in, uri); checkNodeModel(resource); if (expectedErrors != UNKNOWN_EXPECTATION) { if (expectedErrors == EXPECT_ERRORS) assertFalse(Joiner.on('\n').join(resource.getErrors()), resource.getErrors().isEmpty()); else assertEquals(Joiner.on('\n').join(resource.getErrors()), expectedErrors, resource.getErrors().size()); } for(Diagnostic d: resource.getErrors()) { if (d instanceof ExceptionDiagnostic) fail(d.getMessage()); } if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) { SerializerTester tester = get(SerializerTester.class); EObject obj = resource.getContents().get(0); tester.assertSerializeWithNodeModel(obj); tester.assertSerializeWithoutNodeModel(obj); } return resource; }
public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception { XtextResource resource = doGetResource(in, uri); checkNodeModel(resource); if (expectedErrors != UNKNOWN_EXPECTATION) { if (expectedErrors == EXPECT_ERRORS) assertFalse(resource.getErrors().toString(), resource.getErrors().isEmpty()); else assertEquals(resource.getErrors().toString(), expectedErrors, resource.getErrors().size()); } for(Diagnostic d: resource.getErrors()) { if (d instanceof ExceptionDiagnostic) fail(d.getMessage()); } for(Diagnostic d: resource.getWarnings()) System.out.println("Resource Warning: "+d); if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) { SerializerTester tester = get(SerializerTester.class); EObject obj = resource.getContents().get(0); tester.assertSerializeWithNodeModel(obj); tester.assertSerializeWithoutNodeModel(obj); } return resource; }
protected void handleErrors() throws IOException { if (!resource.getErrors().isEmpty()) { Resource.Diagnostic error = resource.getErrors().get(0); if (error instanceof Exception) { throw new Resource.IOWrappedException((Exception)error); } else { throw new IOException(error.getMessage()); } } }
protected void handleErrors() throws IOException { if (!resource.getErrors().isEmpty()) { Resource.Diagnostic error = resource.getErrors().get(0); if (error instanceof Exception) { throw new Resource.IOWrappedException((Exception)error); } else { throw new IOException(error.getMessage()); } } }
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; }