/** * Gets the offset and the error message for a given {@link Diagnostic}. * * @param diagnostic * instance of {@link Diagnostic} * @return * offset and error message */ private Pair<Integer, String> processDiagnostic(final Diagnostic diagnostic) { StringBuilder errorMessage = new StringBuilder(); if (diagnostic instanceof AbstractValidationDiagnostic) { AbstractValidationDiagnostic avd = (AbstractValidationDiagnostic) diagnostic; errorMessage.append("Unexpected issue found. Code '"); errorMessage.append(avd.getIssueCode()).append("'\n"); errorMessage.append(avd.getMessage()); if (avd instanceof FeatureBasedDiagnostic && ((FeatureBasedDiagnostic) avd).getFeature() != null) { List<INode> nodes = NodeModelUtils.findNodesForFeature(avd.getSourceEObject(), ((FeatureBasedDiagnostic) avd).getFeature()); if (nodes != null && !nodes.isEmpty()) { return new Pair<Integer, String>(findFirstNonHiddenLeafNode(nodes.get(0)).getTotalOffset(), errorMessage.toString()); } } else if (avd instanceof RangeBasedDiagnostic) { return new Pair<Integer, String>(((RangeBasedDiagnostic) avd).getOffset(), errorMessage.toString()); } else { return new Pair<Integer, String>(NodeModelUtils.getNode(avd.getSourceEObject()).getTotalOffset(), errorMessage.toString()); } } return null; }
private Diagnostic createDiagnostic(final CheckMode mode, final int diagnosticSeverity, final String message, final EObject object, final EStructuralFeature feature, final int index, final String code, final String... issueData) { final Diagnostic result = new FeatureBasedDiagnostic(diagnosticSeverity, message, object, feature, index, getType(mode), code, issueData); return result; }
protected Diagnostic createDiagnostic(int diagnosticSeverity, String message, IssueLocator locator, String code) { String[] data = new String[0]; if (locator.getRealObject().isPresent()) { EObject realEObject = locator.getRealObject().get(); URI realEObjectUri = realEObject.eResource().getURI() .appendFragment(realEObject.eResource().getURIFragment(realEObject)); data = new String[] { ISSUE_DATA_MARKER, realEObjectUri.toString() }; } FeatureBasedDiagnostic diagnostic = new FeatureBasedDiagnostic(diagnosticSeverity, message, locator.getObject(), locator.getFeature(), locator.getIndex(), CheckType.FAST, code, data); return diagnostic; }
/** * Creates an EMF Eclipse diagnostic instance. * * @param severity the severity of the diagnostic * @param message the message * @param object the causing EMF element in the parse tree * @param feature the causing grammar feature * @param index an optional index value (aka code) * @param code a textual description of the code (may be <b>null</b>) * @param issueData optional user specific data * @return the created diagnostic element */ private static Diagnostic createDiagnostic(Severity severity, String message, EObject object, EStructuralFeature feature, int index, String code, String... issueData) { int diagnosticSeverity = toDiagnosticSeverity(severity); Diagnostic result = new FeatureBasedDiagnostic(diagnosticSeverity, message, object, feature, index, CheckType.NORMAL, code, issueData); return result; }
/** * Creates a diagnostic for given parameters. * * @param severity * the issue severity * @param message * the issue message * @param object * the context object * @param feature * the structural feature on which to create a marker * @param index * the index at which to create a marker * @param code * the issue code * @param issueData * the issue data * @return the diagnostic */ protected Diagnostic createDiagnostic(final Severity severity, final String message, final EObject object, final EStructuralFeature feature, final int index, final String code, final String... issueData) { int diagnosticSeverity = toDiagnosticSeverity(severity); return new FeatureBasedDiagnostic(diagnosticSeverity, message, object, feature, index, state.get().currentCheckType, code, issueData); }