/** * 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); }
protected Resource.Diagnostic createDiagnostic(DiagnosticMessage message) { Diagnostic diagnostic = new XtextLinkingDiagnostic( node, message.getMessage(), message.getIssueCode(), message.getIssueData()); return diagnostic; }
@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); } } }
@Test public void testErrorMarkers() throws Exception { String model = "spielplatz 1 {kind(B 1) erwachsener(E 1) familie(F E E B, C)}"; resource.update(0, 0, model); EcoreUtil.resolveAll(resource); assertEquals(1, resource.getErrors().size()); XtextLinkingDiagnostic diag = (XtextLinkingDiagnostic) resource.getErrors().get(0); assertEquals(model.indexOf("C)"), diag.getOffset()); assertEquals(1, diag.getLength()); }
@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); }
protected void createDiagnostic(Triple<EObject, EReference, INode> triple) { SpecificationElement specificationElement = EcoreUtil2.getContainerOfType(triple.getFirst(), SpecificationElement.class); DiagnosticMessage message = createDiagnosticMessage(triple); Diagnostic diagnostic = new XtextLinkingDiagnostic(triple.getThird(), message.getMessage(), message.getIssueCode(), message.getIssueData()); linkingDiagnostics.put(specificationElement, diagnostic); }
@Override protected Diagnostic createDiagnostic(DiagnosticMessage message) { return new XtextLinkingDiagnostic(getNode(), message.getMessage(), message.getIssueCode(), message.getIssueData()); }
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); }
protected Diagnostic createDiagnostic(Triple<EObject, EReference, INode> triple, DiagnosticMessage message) { Diagnostic diagnostic = new XtextLinkingDiagnostic(triple.getThird(), message.getMessage(), message.getIssueCode(), message.getIssueData()); return diagnostic; }
protected void createAndAddDiagnostic(Resource resource, INode node, String message, String commaSeparatedAlternatives) { resource.getErrors().add(new XtextLinkingDiagnostic(node, message, AMBIGUOUS_NAME_ISSUE_CODE, commaSeparatedAlternatives)); }
protected org.eclipse.xtext.diagnostics.Diagnostic createLinkingDiagnostic(CS2ASDiagnostic diagnostic) { return new XtextLinkingDiagnostic(NodeModelUtils.getNode(diagnostic.getCSObject()), diagnostic.getMessage(), diagnostic.getSource()); }