org.eclipse.xtext.validation.FeatureBasedDiagnostic Java Examples

The following examples show how to use org.eclipse.xtext.validation.FeatureBasedDiagnostic. 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: AbstractXtextTestUtil.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: ErrorToDiagnoticTranslator.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #3
Source File: DefaultCheckImpl.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * 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);
}