org.eclipse.emf.ecore.resource.Resource.Diagnostic Java Examples
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: Executor.java From joynr with Apache License 2.0 | 6 votes |
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); } } }
Example #2
Source File: DiagnosticConverterImpl.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.4 */ protected String[] getIssueData(org.eclipse.emf.common.util.Diagnostic diagnostic) { if (diagnostic instanceof AbstractValidationDiagnostic) { AbstractValidationDiagnostic diagnosticImpl = (AbstractValidationDiagnostic) diagnostic; return diagnosticImpl.getIssueData(); } else { // replace any EObjects by their URIs EObject causer = getCauser(diagnostic); List<String> issueData = newArrayList(); for (Object object : diagnostic.getData()) { if (object != causer && object instanceof EObject) { EObject eObject = (EObject)object; issueData.add(EcoreUtil.getURI(eObject).toString()); } else if (object instanceof String) { issueData.add( (String) object); } } return issueData.toArray(new String[issueData.size()]); } }
Example #3
Source File: DiagnosticConverterImpl.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override 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.setColumn(diagnostic.getColumn()); issue.setMessage(diagnostic.getMessage()); 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.setLineNumberEnd(castedDiagnostic.getLineEnd()); issue.setColumnEnd(castedDiagnostic.getColumnEnd()); } issue.setType(CheckType.FAST); acceptor.accept(issue); }
Example #4
Source File: LinkingTest.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Test public void testBug464264_01() throws Exception { XtendFile file = file( "import java.util.List\n" + "class C {\n" + " def m(I i, List<CharSequence> list) {\n" + " i.strings += list.map[it]\n" + " }\n" + " interface I {\n" + " def List<String> getStrings()\n" + " }\n" + "}"); XtendClass c = (XtendClass) file.getXtendTypes().get(0); XtendFunction m = (XtendFunction) c.getMembers().get(0); XBlockExpression body = (XBlockExpression) m.getExpression(); XBinaryOperation featureCall = (XBinaryOperation) body.getExpressions().get(0); JvmIdentifiableElement feature = featureCall.getFeature(); assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.operator_add(java.util.Collection,java.lang.Iterable)", feature.getIdentifier()); assertNull(featureCall.getImplicitReceiver()); assertNull(featureCall.getImplicitFirstArgument()); List<Diagnostic> errors = c.eResource().getErrors(); assertEquals(1, errors.size()); assertEquals("Type mismatch: cannot convert from List<CharSequence> to Iterable<? extends String>", errors.get(0).getMessage()); }
Example #5
Source File: ToEcoreTrafoTest.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testAbstractLanguageToMetamodel() throws Exception { XtextResource r = getResource("classpath:/" + AbstractTestLanguage.class.getName().replace('.', '/') + ".xtext"); Grammar element = (Grammar) r.getParseResult().getRootASTElement(); if (!r.getErrors().isEmpty()) { EList<Diagnostic> errors = r.getErrors(); for (Diagnostic syntaxError : errors) { logger.debug(syntaxError.getMessage() + " - " + syntaxError.getLine()); } fail(errors.toString()); } List<TerminalRule> lexerRules = GrammarUtil.allTerminalRules(element); assertEquals(8, lexerRules.size()); List<EPackage> list = Xtext2EcoreTransformer.doGetGeneratedPackages(element); assertNotNull(list); assertEquals(0, list.size()); }
Example #6
Source File: AbstractXtextTests.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
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; }
Example #7
Source File: DefaultFoldingStructureProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * @see org.eclipse.xtext.ui.editor.model.IXtextModelListener#modelChanged(org.eclipse.xtext.resource.XtextResource) */ @Override public void modelChanged(XtextResource resource) { if (resource == null) return; boolean existingSyntaxErrors = Iterables.any(resource.getErrors(), new Predicate<Diagnostic>() { @Override public boolean apply(Diagnostic diagnostic) { return diagnostic instanceof XtextSyntaxDiagnostic; } }); if (!existingSyntaxErrors) { calculateProjectionAnnotationModel(false); } }
Example #8
Source File: AbstractXtextTests.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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)) { SerializerTestHelper tester = get(SerializerTestHelper.class); EObject obj = resource.getContents().get(0); tester.assertSerializeWithNodeModel(obj); tester.assertSerializeWithoutNodeModel(obj); } return resource; }
Example #9
Source File: AbstractXtextTests.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
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)) { SerializerTestHelper tester = get(SerializerTestHelper.class); EObject obj = resource.getContents().get(0); tester.assertSerializeWithNodeModel(obj); tester.assertSerializeWithoutNodeModel(obj); } return resource; }
Example #10
Source File: AbstractUnresolvableReferenceWithNode.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public void applyToModel(IResolvedTypes resolvedTypes) { Resource resource = getExpression().eResource(); if (resource instanceof LazyLinkingResource) { LazyLinkingResource lazyLinkingResource = (LazyLinkingResource) resource; TypeAwareLinkingDiagnosticContext context = new TypeAwareLinkingDiagnosticContext(this, resolvedTypes); DiagnosticMessage message = lazyLinkingResource.getDiagnosticMessageProvider() .getUnresolvedProxyMessage(context); if (message != null) { List<Resource.Diagnostic> diagnostics = getDiagnosticList(lazyLinkingResource, message); Diagnostic diagnostic = createDiagnostic(message); diagnostics.add(diagnostic); } EObject referenced = (InternalEObject) getExpression().eGet(getReference(), false); lazyLinkingResource.markUnresolvable(referenced); } }
Example #11
Source File: BuiltInTypeScopeTest.java From n4js with Eclipse Public License 1.0 | 6 votes |
@SuppressWarnings("javadoc") @Test public void testLoadingBuiltInTypes() { BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet); IEObjectDescription anyType = scope.getSingleElement(QualifiedName.create("any")); Assert.assertNotNull(anyType); String s = ""; for (Resource resource : resourceSet.getResources()) { if (resource.getErrors().size() > 0) { for (Diagnostic d : resource.getErrors()) { s += "\n " + d.getMessage() + " at " + resource.getURI() + ":" + d.getLine(); } } } Assert.assertEquals("Resources definine built-in types must have no error.", "", s); }
Example #12
Source File: NegativeAnalyser.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public void analyse(Script script, String codeName, String code) { List<Diagnostic> errors = super.getScriptErrors(script); if (errors.isEmpty()) { String msg = "expected errors in " + codeName + " but there was not a single one"; 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("========================================").append("\n"); this.logger.debug(sb); } assertEquals(msg, code, codeName); } }
Example #13
Source File: ExceptionAnalyser.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override protected List<Diagnostic> getScriptErrors(Script script) { EcoreUtil.resolveAll(script.eResource()); List<Diagnostic> diagnostics = super.getScriptErrors(script); Iterator<TypableElement> typableASTNodes = Iterators.filter(EcoreUtil2.eAll(script), TypableElement.class); List<Diagnostic> result = Lists.<Diagnostic> newArrayList(Iterables.filter(diagnostics, ExceptionDiagnostic.class)); while (typableASTNodes.hasNext()) { TypableElement typableASTNode = typableASTNodes.next(); RuleEnvironment ruleEnvironment = RuleEnvironmentExtensions.newRuleEnvironment(typableASTNode); try { typeSystem.type(ruleEnvironment, typableASTNode); } catch (Throwable cause) { if (cause instanceof Exception) { result.add(new ExceptionDiagnostic((Exception) cause)); } else { throw new RuntimeException(cause); } } } validator.validate(script.eResource(), CheckMode.ALL, CancelIndicator.NullImpl); return result; }
Example #14
Source File: LinkingErrorTest.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void assertNoExceptions(EObject object) { Resource resource = object.eResource(); if (resource instanceof LazyLinkingResource) ((LazyLinkingResource) resource).resolveLazyCrossReferences(CancelIndicator.NullImpl); List<Diagnostic> errors = object.eResource().getErrors(); for(Diagnostic error: errors) { if (error instanceof ExceptionDiagnostic) { ((ExceptionDiagnostic) error).getException().printStackTrace(); } assertFalse(error.toString(), error instanceof ExceptionDiagnostic); } validateWithoutException((XtextResource) resource); }
Example #15
Source File: ResourceValidator.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@Check(CheckType.FAST) public void checkUnresolvableProxies(Statechart sc) { if (!(sc.eResource() instanceof AbstractSCTResource)) { return; } AbstractSCTResource resource = (AbstractSCTResource) sc.eResource(); for (Map.Entry<SpecificationElement, Collection<Diagnostic>> entry : resource.getLinkingDiagnostics().asMap() .entrySet()) { for (Diagnostic diag : entry.getValue()) { if (entry.getKey().eResource() != null) error(diag.getMessage(), entry.getKey(), null, -1); } } }
Example #16
Source File: DiagnosticConverterImpl.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.4 */ protected String getIssueCode(org.eclipse.emf.common.util.Diagnostic diagnostic) { if (diagnostic instanceof AbstractValidationDiagnostic) { AbstractValidationDiagnostic diagnosticImpl = (AbstractValidationDiagnostic) diagnostic; return diagnosticImpl.getIssueCode(); } else { return diagnostic.getSource() + "." + diagnostic.getCode(); } }
Example #17
Source File: DiagnosticConverterImpl.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.4 */ protected Severity getSeverity(org.eclipse.emf.common.util.Diagnostic diagnostic) { if (diagnostic.getSeverity() == org.eclipse.emf.common.util.Diagnostic.OK) return null; switch (diagnostic.getSeverity()) { case org.eclipse.emf.common.util.Diagnostic.WARNING: return Severity.WARNING; case org.eclipse.emf.common.util.Diagnostic.INFO: return Severity.INFO; default : return Severity.ERROR; } }
Example #18
Source File: ScriptEngineImpl.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws ScriptParsingException { XtextResourceSet resourceSet = getResourceSet(); Resource resource = resourceSet.createResource(computeUnusedUri(resourceSet)); // IS-A XtextResource try { resource.load(new StringInputStream(scriptAsString, StandardCharsets.UTF_8.name()), resourceSet.getLoadOptions()); } catch (IOException e) { throw new ScriptParsingException( "Unexpected IOException; from close() of a String-based ByteArrayInputStream, no real I/O; how is that possible???", scriptAsString, e); } List<Diagnostic> errors = resource.getErrors(); if (errors.size() != 0) { throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)", scriptAsString).addDiagnosticErrors(errors); } EList<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { Iterable<Issue> validationErrors = getValidationErrors(contents.get(0)); if (!validationErrors.iterator().hasNext()) { return (XExpression) contents.get(0); } else { throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)", scriptAsString).addValidationIssues(validationErrors); } } else { return null; } }
Example #19
Source File: DiagnosticConverterImpl.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected EObject getCauser(org.eclipse.emf.common.util.Diagnostic diagnostic) { // causer is the first element see Diagnostician.getData if (diagnostic.getData().isEmpty()) return null; Object causer = diagnostic.getData().get(0); return causer instanceof EObject ? (EObject) causer : null; }
Example #20
Source File: ReducedXtextResourceValidator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override protected void issueFromXtextResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) { if (diagnostic instanceof XtextSyntaxDiagnostic) { super.issueFromXtextResourceDiagnostic(diagnostic, severity, acceptor); } else if (diagnostic instanceof XtextLinkingDiagnostic) { XtextLinkingDiagnostic linkingDiagnostic = (XtextLinkingDiagnostic) diagnostic; if (linkingDiagnostic.getCode().equals(XtextLinkingDiagnosticMessageProvider.UNRESOLVED_RULE)) { super.issueFromXtextResourceDiagnostic(diagnostic, severity, acceptor); } else if (linkingDiagnostic.getMessage().contains("reference to Grammar")) { super.issueFromXtextResourceDiagnostic(diagnostic, severity, acceptor); } } }
Example #21
Source File: ResourceLoadTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private void assertNoExceptionDiagnostic(Resource r, String model) throws Exception { for (Diagnostic d : r.getErrors()) { if (d instanceof ExceptionDiagnostic) { throw new Exception(model, ((ExceptionDiagnostic) d).getException()); } } }
Example #22
Source File: ParseErrorHandlingTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testTrailingRecoverableError() throws Exception { with(TreeTestLanguageStandaloneSetup.class); String model = "parent ('Teststring') { \n" + " child ('Teststring'){};\n" + " child ('Teststring'){};\n" + "};\n" + "};\n" + "\n"; Resource res = getResourceFromStringAndExpect(model, 1); assertEquals(res.getErrors().size(), 1, res.getErrors().size()); Diagnostic diag = res.getErrors().get(0); assertNotNull(diag); assertEquals(5, diag.getLine()); Model parsedModel = (Model) res.getContents().get(0); assertNotNull(parsedModel); ICompositeNode composite = NodeModelUtils.getNode(parsedModel); assertNotNull(composite); List<ILeafNode> leafs = Lists.newArrayList(composite.getLeafNodes()); ILeafNode lastWs = leafs.get(leafs.size() - 1); assertTrue(lastWs.isHidden()); assertNull(lastWs.getSyntaxErrorMessage()); ILeafNode lastNode = leafs.get(leafs.size() - 2); assertFalse(lastNode.isHidden()); assertNotNull(lastNode); assertEquals("};", lastNode.getText()); assertNotNull(lastNode.getSyntaxErrorMessage()); }
Example #23
Source File: XtextFileLoader.java From orcas with Apache License 2.0 | 5 votes |
private T loadModelDslFile( File pFile, Parameters pParameters, XtextResourceSet pResourceSet, Map<Object, Object> pLoadOptions, int pCounter ) { Resource lResource = pResourceSet.createResource( URI.createURI( "dummy:/dummy" + pCounter + "." + getXtextExpectedFileEnding() ) ); try { loadFileIntoResource( pFile, pLoadOptions, lResource ); EList<EObject> lContents = lResource.getContents(); if( lContents.isEmpty() ) { return null; } @SuppressWarnings( "unchecked" ) T lModel = (T) lContents.get( 0 ); if( !lResource.getErrors().isEmpty() ) { throw new RuntimeException( "parse errors" + pFile + " :" + lResource.getErrors().get( 0 ) ); } return lModel; } catch( Exception e ) { if( lResource != null ) { for( Diagnostic lDiagnostic : lResource.getErrors() ) { Orcas.logError( "Error in File: " + pFile, pParameters ); Orcas.logError( lDiagnostic + "", pParameters ); } } throw new RuntimeException( e ); } }
Example #24
Source File: SARLEditorErrorTickUpdater.java From sarl with Apache License 2.0 | 5 votes |
private static boolean notSame(Set<String> markers, List<Diagnostic> diagnostics) { //FIXME: for helping to resolve #661 for (final Diagnostic diag : diagnostics) { if (!markers.contains(diag.getMessage())) { return true; } } return false; }
Example #25
Source File: SARLEditorErrorTickUpdater.java From sarl with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("checkstyle:nestedifdepth") public void modelChanged(IAnnotationModel model) { super.modelChanged(model); //FIXME: for helping to resolve #661 final XtextEditor editor = getEditor(); if (editor != null && !editor.isDirty() && editor.getInternalSourceViewer() != null) { final IAnnotationModel currentModel = editor.getInternalSourceViewer().getAnnotationModel(); if (currentModel != null && currentModel == model) { final Resource resource = getXtextResource(); if (isReconciliable(resource)) { final Set<String> markers = extractErrorMarkerMessages(currentModel); final List<Diagnostic> resourceErrors = resource.getErrors(); if (markers.size() != resourceErrors.size() || notSame(markers, resourceErrors)) { final Display display = PlatformUI.getWorkbench().getDisplay(); display.asyncExec(new Runnable() { @Override public void run() { LangActivator.getInstance().getLog().log( new Status(IStatus.ERROR, LangActivator.PLUGIN_ID, MessageFormat.format(Messages.SARLEditorErrorTickUpdater_0, resource.getURI()))); } }); } } } } }
Example #26
Source File: OnChangeEvictingCacheAdapterTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testCacheSurvivesChangeToDiagnostics() throws Exception { EcoreFactory factory = EcoreFactory.eINSTANCE; EClass eClass = factory.createEClass(); Resource resource = new ResourceImpl(); resource.getContents().add(eClass); CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource); setValue(ca); List<Diagnostic> errors = resource.getErrors(); assertIsSet(ca); errors.clear(); assertIsSet(ca); }
Example #27
Source File: Bug362902Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testNoExceptionUncaught() throws Exception { String modelAsString = "Hello max ! Hello peter! favourite peter"; Model model = (Model)getModelAndExpect(modelAsString, 2); EList<Diagnostic> errors = model.eResource().getErrors(); Diagnostic diagnosticSyntax = errors.get(0); Diagnostic diagnosticLinking = errors.get(1); assertTrue(diagnosticSyntax instanceof XtextSyntaxDiagnostic); assertTrue(diagnosticLinking instanceof XtextLinkingDiagnostic); }
Example #28
Source File: ScriptEngineImpl.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws ScriptParsingException { XtextResourceSet resourceSet = getResourceSet(); Resource resource = resourceSet.createResource(computeUnusedUri(resourceSet)); // IS-A XtextResource try { resource.load(new StringInputStream(scriptAsString, StandardCharsets.UTF_8.name()), resourceSet.getLoadOptions()); } catch (IOException e) { throw new ScriptParsingException( "Unexpected IOException; from close() of a String-based ByteArrayInputStream, no real I/O; how is that possible???", scriptAsString, e); } List<Diagnostic> errors = resource.getErrors(); if (!errors.isEmpty()) { throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)", scriptAsString).addDiagnosticErrors(errors); } EList<EObject> contents = resource.getContents(); if (!contents.isEmpty()) { Iterable<Issue> validationErrors = getValidationErrors(contents.get(0)); if (!validationErrors.iterator().hasNext()) { return (XExpression) contents.get(0); } else { throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)", scriptAsString).addValidationIssues(validationErrors); } } else { return null; } }
Example #29
Source File: ResourceValidator.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@Check(CheckType.FAST) public void checkSyntaxErrors(Statechart sc) { if (!(sc.eResource() instanceof AbstractSCTResource)) { return; } AbstractSCTResource resource = (AbstractSCTResource) sc.eResource(); for (Map.Entry<SpecificationElement, Collection<Diagnostic>> entry : resource.getSyntaxDiagnostics().asMap() .entrySet()) { for (Diagnostic diag : entry.getValue()) { if (entry.getKey().eResource() != null) error(diag.getMessage(), entry.getKey(), null, -1); } } }
Example #30
Source File: STextExpressionParser.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public EObject parseExpression(String expression, String ruleName, String specification) { StextResource resource = getResource(); resource.setURI(URI.createPlatformResourceURI(getUri(), true)); ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule(); parserRule.setName(ruleName); IParseResult result = parser.parse(parserRule, new StringReader(expression)); EObject rootASTElement = result.getRootASTElement(); resource.getContents().add(rootASTElement); ListBasedDiagnosticConsumer diagnosticsConsumer = new ListBasedDiagnosticConsumer(); Statechart sc = SGraphFactory.eINSTANCE.createStatechart(); sc.setDomainID(domainId); sc.setName("sc"); if (specification != null) { sc.setSpecification(specification); } resource.getContents().add(sc); resource.getLinkingDiagnostics().clear(); linker.linkModel(sc, diagnosticsConsumer); linker.linkModel(rootASTElement, diagnosticsConsumer); resource.resolveLazyCrossReferences(CancelIndicator.NullImpl); resource.resolveLazyCrossReferences(CancelIndicator.NullImpl); Multimap<SpecificationElement, Diagnostic> diagnostics = resource.getLinkingDiagnostics(); if (diagnostics.size() > 0) { throw new LinkingException(diagnostics.toString()); } if (result.hasSyntaxErrors()) { StringBuilder errorMessages = new StringBuilder(); Iterable<INode> syntaxErrors = result.getSyntaxErrors(); for (INode iNode : syntaxErrors) { errorMessages.append(iNode.getSyntaxErrorMessage()); errorMessages.append("\n"); } throw new SyntaxException("Could not parse expression, syntax errors: " + errorMessages); } if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) { throw new LinkingException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR)); } return rootASTElement; }