Java Code Examples for org.eclipse.xtext.parser.IParseResult#getSyntaxErrors()
The following examples show how to use
org.eclipse.xtext.parser.IParseResult#getSyntaxErrors() .
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: DotValidator.java From gef with Eclipse Public License 2.0 | 5 votes |
private void doRecordLabelValidation(Attribute attribute) { Injector recordLabelInjector = new DotRecordLabelStandaloneSetup() .createInjectorAndDoEMFRegistration(); DotRecordLabelValidator validator = recordLabelInjector .getInstance(DotRecordLabelValidator.class); IParser parser = recordLabelInjector.getInstance(IParser.class); DotSubgrammarValidationMessageAcceptor messageAcceptor = new DotSubgrammarValidationMessageAcceptor( attribute, DotPackage.Literals.ATTRIBUTE__VALUE, "record-based label", getMessageAcceptor(), "\"".length()); validator.setMessageAcceptor(messageAcceptor); IParseResult result = parser .parse(new StringReader(attribute.getValue().toValue())); for (INode error : result.getSyntaxErrors()) messageAcceptor.acceptSyntaxError(error); Map<Object, Object> validationContext = new HashMap<Object, Object>(); validationContext.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, ReflectionUtils.getPrivateFieldValue(validator, "languageName")); // validate both the children (loop) and root element Iterator<EObject> iterator = result.getRootASTElement().eAllContents(); while (iterator.hasNext()) validator.validate(iterator.next(), null/* diagnostic chain */, validationContext); validator.validate(result.getRootASTElement(), null, validationContext); }
Example 2
Source File: XtextResource.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * Creates {@link org.eclipse.emf.ecore.resource.Resource.Diagnostic diagnostics} from {@link SyntaxErrorMessage syntax errors} in {@link IParseResult}. * No diagnostics will be created if {@link #isValidationDisabled() validation is disabled} for this * resource. * * @param parseResult the parse result that provides the syntax errors. * @return list of {@link org.eclipse.emf.ecore.resource.Resource.Diagnostic}. Never <code>null</code>. */ private List<Diagnostic> createDiagnostics(IParseResult parseResult) { if (validationDisabled) return Collections.emptyList(); List<Diagnostic> diagnostics = new ArrayList<Diagnostic>(); for (INode error : parseResult.getSyntaxErrors()) { addSyntaxDiagnostic(diagnostics, error); } return diagnostics; }
Example 3
Source File: AbstractSGenTest.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected EObject parseExpression(String expression, String ruleName) { XtextResource resource = resourceProvider.get(); resource.setURI(URI.createPlatformPluginURI("path", 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(); linker.linkModel(result.getRootASTElement(), diagnosticsConsumer); 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 RuntimeException( "Could not parse expression, syntax errors: " + errorMessages); } if (diagnosticsConsumer.hasConsumedDiagnostics(Severity.ERROR)) { throw new RuntimeException("Error during linking: " + diagnosticsConsumer.getResult(Severity.ERROR)); } return rootASTElement; }
Example 4
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; }
Example 5
Source File: AbstractSCTResource.java From statecharts with Eclipse Public License 1.0 | 4 votes |
protected void createDiagnostics(IParseResult parseResult, SpecificationElement semanticTarget) { syntaxDiagnostics.get(semanticTarget).clear(); for (INode error : parseResult.getSyntaxErrors()) { syntaxDiagnostics.put(semanticTarget, new XtextSyntaxDiagnostic(error)); } }