Java Code Examples for org.eclipse.emf.ecore.resource.Resource#Diagnostic
The following examples show how to use
org.eclipse.emf.ecore.resource.Resource#Diagnostic .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Xtext2EcoreTransformerTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testNoException_01() throws Exception { StringConcatenation _builder = new StringConcatenation(); _builder.append("grammar test with org.eclipse.xtext.common.Terminals import \'http://www.eclipse.org/emf/2002/Ecore\' as ecore generate test \'http://test\'"); _builder.newLine(); _builder.append("CompositeModel: (model+=Model)+;"); _builder.newLine(); _builder.append("Model: id=NestedModelId (\':\' value=Fraction)? (\'#\' vector=Vector)? (\'+\' dots=Dots)? \';\'"); _builder.newLine(); _builder.append("ModelId returns ecore::EString: ID \'.\' ID;"); _builder.newLine(); _builder.append("NestedModelId : ModelId \'.\' ModelId;"); _builder.newLine(); _builder.append("Fraction returns EBigDecimal: INT (\'/\' INT)?;"); _builder.newLine(); _builder.append("Vector : \'(\' INT I"); String grammar = _builder.toString(); final XtextResource resource = this.getResourceFromStringAndExpect(grammar, 10); EList<Resource.Diagnostic> _errors = resource.getErrors(); for (final Resource.Diagnostic d : _errors) { Assert.assertFalse((d instanceof ExceptionDiagnostic)); } }
Example 2
Source File: ErrorTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testErrorModel_138() throws Exception { StringConcatenation _builder = new StringConcatenation(); _builder.append("package test"); _builder.newLine(); _builder.append("class Bar<T> extends test.Bar.Foo<T> {}"); _builder.newLine(); final XtendFile file = this.processWithoutException(_builder); EList<Resource.Diagnostic> _errors = file.eResource().getErrors(); final Procedure1<EList<Resource.Diagnostic>> _function = (EList<Resource.Diagnostic> it) -> { final Function1<Resource.Diagnostic, Boolean> _function_1 = (Resource.Diagnostic it_1) -> { return Boolean.valueOf(it_1.getMessage().startsWith("Cyclic ")); }; Assert.assertFalse(it.toString(), IterableExtensions.<Resource.Diagnostic>exists(it, _function_1)); }; ObjectExtensions.<EList<Resource.Diagnostic>>operator_doubleArrow(_errors, _function); }
Example 3
Source File: Xtext2EcoreTransformerTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug_266807() throws Exception { final XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class); rs.setClasspathURIContext(this.getClass()); StringConcatenation _builder = new StringConcatenation(); _builder.append("classpath:/"); String _replace = this.getClass().getPackage().getName().replace(Character.valueOf('.').charValue(), Character.valueOf('/').charValue()); _builder.append(_replace); _builder.append("/Test.xtext"); Resource _createResource = rs.createResource( URI.createURI(_builder.toString()), ContentHandler.UNSPECIFIED_CONTENT_TYPE); final XtextResource resource = ((XtextResource) _createResource); resource.load(null); EList<Resource.Diagnostic> _errors = resource.getErrors(); for (final Resource.Diagnostic d : _errors) { Assert.fail(d.getMessage()); } }
Example 4
Source File: AbstractValidationTest.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Persist list diagnostics into string to display the list of issue codes. * * @param diagnostics * list of diagnostics * @param displayPathToTargetObject * if true, the path through the object hierarchy is printed out up to the root node * @return * string with list of issue codes, separated with a line break */ // TODO (ACF-4153) generalize for all kinds of errors and move to AbstractXtextTest private String diagnosticsToString(final List<Resource.Diagnostic> diagnostics, final boolean displayPathToTargetObject) { StringBuilder sb = new StringBuilder(); for (Resource.Diagnostic diagnostic : diagnostics) { if (diagnostic instanceof AbstractDiagnostic) { AbstractDiagnostic diag = (AbstractDiagnostic) diagnostic; sb.append(" "); sb.append(diag.getCode()); if (displayPathToTargetObject) { sb.append(" at line: "); sb.append(diag.getLine()); sb.append(" on \n"); sb.append(" "); sb.append(diag.getUriToProblem()); } sb.append(LINE_BREAK); } } return sb.toString(); }
Example 5
Source File: AbstractBuilderParticipantTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Will only return parse errors, not validation errors! */ protected List<Resource.Diagnostic> getEditorErrors(XtextEditor fileXtextEditor) { return fileXtextEditor.getDocument().readOnly(new IUnitOfWork<List<Diagnostic>, XtextResource>() { @Override public List<Resource.Diagnostic> exec(XtextResource state) throws Exception { EcoreUtil.resolveAll(state); return state.getErrors(); } }); }
Example 6
Source File: ProblemSupportImpl.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public void addError(final Element element, final String message) { this.checkCanceled(); this.checkValidationAllowed(); final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element); EList<Resource.Diagnostic> _errors = resAndObj.getKey().getErrors(); EObject _value = resAndObj.getValue(); EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue()); EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.ERROR, "user.issue", message, _value, _significantFeature, (-1), null); _errors.add(_eObjectDiagnosticImpl); }
Example 7
Source File: GamlExpressionCompiler.java From gama with GNU General Public License v3.0 | 5 votes |
private EObject getEObjectOf(final String string, final IExecutionContext tempContext) throws GamaRuntimeException { EObject result = null; final String s = "dummy <- " + string; final GamlResource resource = GamlResourceServices.getTemporaryResource(getContext()); try { final InputStream is = new ByteArrayInputStream(s.getBytes()); try { resource.loadSynthetic(is, tempContext); } catch (final Exception e1) { e1.printStackTrace(); return null; } if (!resource.hasErrors()) { final EObject e = resource.getContents().get(0); if (e instanceof StringEvaluator) { result = ((StringEvaluator) e).getExpr(); } } else { final Resource.Diagnostic d = resource.getErrors().get(0); throw GamaRuntimeException.error(d.getMessage(), tempContext.getScope()); } return result; } finally { GamlResourceServices.discardTemporaryResource(resource); } }
Example 8
Source File: AbstractXbaseLinkingTest.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Test public void testGenerics_2() throws Exception { // linking is ok but should trigger a validation error XExpression expression = expression("(null as testdata.GenericType1<? extends java.lang.StringBuffer>) += new StringBuffer", false); EcoreUtil.resolveAll(expression); List<Resource.Diagnostic> errors = expression.eResource().getErrors(); assertEquals(errors.toString(), 1, errors.size()); assertEquals("Type mismatch: type StringBuffer is not applicable at this location", errors.get(0).getMessage()); }
Example 9
Source File: SuspiciousOverloadValidationTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
private XtendFile getParsedXtendFile(final CharSequence contents) { try { final XtendFile file = this._parseHelper.parse(contents); final EList<Resource.Diagnostic> errors = file.eResource().getErrors(); Assert.assertTrue(errors.toString(), errors.isEmpty()); EcoreUtil.resolveAll(file); return file; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 10
Source File: AbstractValidationTest.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Assert no linking errors on resource with the given message exist. * * @param object * the object * @param referenceType * the type of the referenced elements * @param referenceNames * the names of the referenced elements */ public static void assertNoLinkingErrorsOnResource(final EObject object, final String referenceType, final String... referenceNames) { final List<Resource.Diagnostic> linkingErrors = object.eResource().getErrors().stream().filter(error -> error instanceof XtextLinkingDiagnostic).collect(Collectors.toList()); final List<String> errorMessages = Lists.transform(linkingErrors, Resource.Diagnostic::getMessage); for (final String referenceName : referenceNames) { boolean found = false; for (final String errMessage : errorMessages) { if (errMessage.startsWith(referenceName)) { found = true; break; } } assertFalse(NLS.bind("Expecting no linking errors on resource for \"{0}\".", referenceName), found); } }
Example 11
Source File: AmbiguityValidationTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected XtendFile getParsedXtendFile(final CharSequence contents) { try { final XtendFile file = this._parseHelper.parse(contents); final EList<Resource.Diagnostic> errors = file.eResource().getErrors(); Assert.assertTrue(errors.toString(), errors.isEmpty()); EcoreUtil.resolveAll(file); return file; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 12
Source File: BuilderParticipantPluginUITest.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * * 01. Class0 * 02. Class1.field0 * 03. Class0 -> Class1.field0 * 04. delete Class1 * 05. Class0 -> Class1 import and Class1.field0 should get error marker * 06. recreate Class1 file * 07. Class0 should have no error markers */ //@formatter:on @Test public void testReferenceDeleted() throws Exception { logger.info("BuilderParticipantPluginUITest.testReferenceDeleted"); // create project and test files final IProject project = createJSProject("testReferenceBrokenToOtherClassesMethod"); IFolder folder = configureProjectWithXtext(project); IFolder moduleFolder = createFolder(folder, TestFiles.moduleFolder()); IFile file2 = createTestFile(moduleFolder, "Class1", TestFiles.class1()); assertMarkers("File2 should have no errors", file2, 0); IFile file1 = createTestFile(moduleFolder, "Class0", TestFiles.class0()); assertMarkers("File1 should have no errors", file1, 0); // open editors of test files IWorkbenchPage page = EclipseUIUtils.getActivePage(); XtextEditor file1XtextEditor = openAndGetXtextEditor(file1, page); List<Resource.Diagnostic> errors = getEditorErrors(file1XtextEditor); assertEquals("Editor of Class0 should have no errors", 0, errors.size()); XtextEditor file2XtextEditor = openAndGetXtextEditor(file2, page); errors = getEditorErrors(file2XtextEditor); assertEquals("Editor of Class1 should have no errors", 0, errors.size()); file2.delete(true, monitor()); moduleFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor()); waitForAutoBuild(); waitForUpdateEditorJob(); // check if editor 1 contain error markers errors = getEditorErrors(file1XtextEditor); // Consequential errors are omitted, so there is no error reported for unknown field, as the receiver is of // unknown type assertEquals("Content of editor 1 should be broken, because now linking to missing resource", Sets.newHashSet( "line 4: Cannot resolve plain module specifier (without project name as first segment): no matching module found.", "line 7: Couldn't resolve reference to Type 'Class1'."), toSetOfStrings(errors)); file2 = createTestFile(folder, "Class1", TestFiles.class1()); assertMarkers("File2 should have no errors", file2, 0); // editor 1 should not contain any error markers anymore file2 = createTestFile(moduleFolder, "Class1", TestFiles.class1()); waitForAutoBuild(); waitForUpdateEditorJob(); errors = getEditorErrors(file1XtextEditor); assertEquals( "Content of editor 1 should be valid again, as Class1 in editor has got the field with name 'field0' again", 0, errors.size()); }
Example 13
Source File: AmbiguityValidationTest.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
protected void assertUnambiguous(final CharSequence contents) { final XtendFile file = this.getParsedXtendFile(contents); final EList<Resource.Diagnostic> errors = file.eResource().getErrors(); Assert.assertEquals(errors.toString(), 0, errors.size()); this._validationTestHelper.assertNoErrors(file); }
Example 14
Source File: Case_8.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
public EList<Resource.Diagnostic> getErrors(final EObject obj) { return obj.eResource().getErrors(); }
Example 15
Source File: AbstractTypeResolverTest.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
public Iterable<Resource.Diagnostic> getLinkingAndSyntaxErrors(final Resource resource) { final Function1<Resource.Diagnostic, Boolean> _function = (Resource.Diagnostic it) -> { return Boolean.valueOf(((it instanceof XtextSyntaxDiagnostic) || (it instanceof XtextLinkingDiagnostic))); }; return IterableExtensions.<Resource.Diagnostic>filter(resource.getErrors(), _function); }
Example 16
Source File: BuilderParticipantPluginUITest.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * * 01. Class0 uses Class1 in require statement and in isa function * 02. Class1 is deleted * 05. Class0 should get error marker at require statement and at isa function * 06. recreate Class1 file * 07. Class0 should have no error markers * */ //@formatter:on @Test public void testSuperClassDeleted() throws Exception { logger.info("BuilderParticipantPluginUITest.testSuperClassDeleted"); // create project and test files final IProject project = createJSProject("testSuperClassDeleted"); IFolder folder = configureProjectWithXtext(project); IFolder moduleFolder = createFolder(folder, InheritanceTestFiles.inheritanceModule()); IFile parentFile = createTestFile(moduleFolder, "Parent", InheritanceTestFiles.Parent()); assertMarkers("Parent file should have no errors", parentFile, 0); IFile childFile = createTestFile(moduleFolder, "Child", InheritanceTestFiles.Child()); assertMarkers("Child file should have no errors", childFile, 0); // open editors of test files IWorkbenchPage page = EclipseUIUtils.getActivePage(); XtextEditor parentFileXtextEditor = openAndGetXtextEditor(parentFile, page); List<Resource.Diagnostic> errors = getEditorErrors(parentFileXtextEditor); assertEquals("Editor of parent should have no errors", 0, errors.size()); XtextEditor childFileXtextEditor = openAndGetXtextEditor(childFile, page); errors = getEditorErrors(childFileXtextEditor); assertEquals("Editor of child should have no errors", 0, errors.size()); parentFileXtextEditor.close(true); parentFile.delete(true, true, monitor()); moduleFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor()); waitForAutoBuild(); waitForUpdateEditorJob(); assertFalse("Parent.n4js doesn't exist anymore", moduleFolder.getFile(new Path("Parent" + "." + N4JSGlobals.N4JS_FILE_EXTENSION)).exists()); errors = getEditorErrors(childFileXtextEditor); assertEquals("Editor of child should have error markers", Sets.newHashSet( "line 1: Cannot resolve plain module specifier (without project name as first segment): no matching module found.", "line 2: Couldn't resolve reference to Type 'ParentObjectLiteral'."), toSetOfStrings(errors)); IFile recreatedParentFile = createTestFile(moduleFolder, "Parent", InheritanceTestFiles.Parent()); assertMarkers("File1 should have no errors", recreatedParentFile, 0); waitForUpdateEditorJob(); errors = getEditorErrors(childFileXtextEditor); assertEquals("Editor of child should have no errors", 0, errors.size()); }
Example 17
Source File: AbstractValidationTest.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Assert no linking errors on resource with the given message exist. * * @param object * the object, must not be {@code null} * @param messages * the linking error messages, must not be {@code null} */ public static void assertNoLinkingErrorsWithCustomMessageOnResource(final EObject object, final String... messages) { List<String> messageList = Arrays.asList(messages); final List<Resource.Diagnostic> linkingErrors = object.eResource().getErrors().stream().filter(error -> error instanceof XtextLinkingDiagnostic).collect(Collectors.toList()); for (String errorMessage : Lists.transform(linkingErrors, Resource.Diagnostic::getMessage)) { assertFalse(NLS.bind("Expecting no linking errors on resource with message \"{0}\".", errorMessage), messageList.contains(errorMessage)); } }
Example 18
Source File: AbstractValidationTest.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Expect the given linking error messages on the resource of the given model. * * @param object * the object, must not be {@code null} * @param errorStrings * the expected linking error error messages, must not be {@code null} */ public static void assertLinkingErrorsWithCustomMessageOnResourceExist(final EObject object, final String... errorStrings) { final List<Resource.Diagnostic> linkingErrors = object.eResource().getErrors().stream().filter(error -> error instanceof XtextLinkingDiagnostic).collect(Collectors.toList()); final List<String> errorMessages = Lists.transform(linkingErrors, Resource.Diagnostic::getMessage); for (final String s : errorStrings) { assertTrue(NLS.bind("Expected linking error \"{0}\" but could not find it", s), errorMessages.contains(s)); } }
Example 19
Source File: AbstractValidationTest.java From dsl-devkit with Eclipse Public License 1.0 | 3 votes |
/** * Expect given error messages on the resource of given model. * * @param object * the object * @param errorStrings * the error strings */ public static void assertErrorsOnResourceExist(final EObject object, final String... errorStrings) { final EList<Resource.Diagnostic> errors = object.eResource().getErrors(); final List<String> errorMessages = Lists.transform(errors, Resource.Diagnostic::getMessage); for (final String s : errorStrings) { assertTrue(NLS.bind("Expected error \"{0}\" but could not find it", s), errorMessages.contains(s)); } }
Example 20
Source File: AbstractValidationTest.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * Returns the unexpectedDiagnostics. * * @return the unexpectedDiagnostics */ protected Set<Resource.Diagnostic> getUnexpectedResourceDiagnostics() { return unexpectedResourceDiagnostics; }