Java Code Examples for org.eclipse.xtext.validation.Issue#getMessage()

The following examples show how to use org.eclipse.xtext.validation.Issue#getMessage() . 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: LSPIssue.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Copy constructor
 */
public LSPIssue(Issue copyFrom) {
	this();
	if (copyFrom.getOffset() != null)
		this.setOffset(copyFrom.getOffset());
	if (copyFrom.getLength() != null)
		this.setLength(copyFrom.getLength());
	if (copyFrom.getColumn() != null)
		this.setColumn(copyFrom.getColumn());
	if (copyFrom.getLineNumber() != null)
		this.setLineNumber(copyFrom.getLineNumber());
	if (copyFrom.getCode() != null)
		this.setCode(copyFrom.getCode());
	if (copyFrom.getMessage() != null)
		this.setMessage(copyFrom.getMessage());
	if (copyFrom.getUriToProblem() != null)
		this.setUriToProblem(copyFrom.getUriToProblem());
	if (copyFrom.getSeverity() != null)
		this.setSeverity(copyFrom.getSeverity());
	if (copyFrom.getType() != null)
		this.setType(copyFrom.getType());
	if (copyFrom.getData() != null)
		this.setData(copyFrom.getData());
}
 
Example 2
Source File: MarkerIdentity.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Instantiates a new MarkerIdentity.
 *
 * @param annotation
 *          the Annotation
 * @return MarkerIdentity - this
 */
public MarkerIdentity create(final Annotation annotation) {
  MarkerIdentity result = provider.get();
  if (annotation instanceof XtextAnnotation) {
    Issue issue = ((XtextAnnotation) annotation).getIssue();
    result.start = issue.getOffset();
    result.end = result.start == ATTRIBUTE_MISSING ? ATTRIBUTE_MISSING : result.start + issue.getLength();
    result.message = issue.getMessage();
  } else if (annotation instanceof org.eclipse.ui.texteditor.MarkerAnnotation) {
    result.start = MarkerUtilities.getCharStart(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
    result.end = MarkerUtilities.getCharEnd(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
    result.message = MarkerUtilities.getMessage(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
  } else {
    result.end = ATTRIBUTE_MISSING;
    result.start = ATTRIBUTE_MISSING;
    result.message = null; // NOPMD
  }
  result.problemCode = issueUtil.getCode(annotation);
  result.problemURI = issueUtil.getUriToProblem(annotation);
  result.resourceURI = result.problemURI == null ? null : result.problemURI.trimFragment();
  return result;
}
 
Example 3
Source File: XtextAnnotation.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public XtextAnnotation(String type, boolean isPersistent, IXtextDocument document, Issue issue, boolean isQuickfixable) {
	super(type, isPersistent, issue.getMessage());
	
	AnnotationPreference preference= lookup.getAnnotationPreference(this);
	if (preference != null)
		this.layer = preference.getPresentationLayer() + 1;
	else
		this.layer = IAnnotationAccessExtension.DEFAULT_LAYER + 1;
	
	this.document = document;
	this.issue = issue;
	this.isQuickfixable = isQuickfixable;
}
 
Example 4
Source File: AnnotationIssueProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected Map<Annotation, Position> getAnnotationsToAdd(Multimap<Position, Annotation> positionToAnnotations,
		List<Issue> issues, IProgressMonitor monitor) {
	if (monitor.isCanceled()) {
		return HashBiMap.create();
	}
	Map<Annotation, Position> annotationToPosition = Maps.newHashMapWithExpectedSize(issues.size());
	for (Issue issue : issues) {
		if (monitor.isCanceled()) {
			return annotationToPosition;
		}
		if (isSet(issue.getOffset()) && isSet(issue.getLength()) && issue.getMessage() != null) {
			String type = lookup.getAnnotationType(EValidator.MARKER, getMarkerSeverity(issue.getSeverity()));
			boolean isQuickfixable = false;
			if (issueResolutionProvider instanceof IssueResolutionProviderExtension) {
				isQuickfixable = ((IssueResolutionProviderExtension)issueResolutionProvider).hasResolutionFor(issue);
			} else {
				isQuickfixable = issueResolutionProvider.hasResolutionFor(issue.getCode());
			}
			Annotation annotation = new XtextAnnotation(type, false, xtextDocument, issue, isQuickfixable);
			if (issue.getOffset() < 0 || issue.getLength() < 0) {
				LOG.error("Invalid annotation position offset=" + issue.getOffset() + " length = "
						+ issue.getLength());
			}
			Position position = new Position(Math.max(0, issue.getOffset()), Math.max(0, issue.getLength()));
			annotationToPosition.put(annotation, position);
			positionToAnnotations.put(position, annotation);
		}
	}
	return annotationToPosition;
}
 
Example 5
Source File: XbaseQuickfixProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Fix(IssueCodes.INVALID_TYPE_ARGUMENTS_ON_TYPE_LITERAL)
public void fixTypeArguments(final Issue issue, IssueResolutionAcceptor acceptor) {
	String message = issue.getMessage();
	String fixup = "Remove invalid type arguments";
	if (message.contains("argument.")) {
		fixup = "Remove invalid type argument";
	}
	acceptor.accept(issue, fixup, fixup, null, new IModification() {
		@Override
		public void apply(IModificationContext context) throws Exception {
			IXtextDocument document = context.getXtextDocument();
			document.replace(issue.getOffset(), issue.getLength(), "");
		}
	});
}
 
Example 6
Source File: XtendValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testOverridingBug515801() throws Exception {
	XtendClass clazz = clazz(
			"class Foo implements int {"+
				"override void doSth(Object obj){ "+
				"}"+
			"}");
	List<Issue> issues = helper.validate(clazz);
	for (Issue issue : issues) {
		if (issue.getMessage() != null && issue.getMessage().contains("Error executing EValidator")) {
			fail(issue.getMessage());
		}
	}
}
 
Example 7
Source File: FormatFragmentUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Retrieve the format model associated with a given grammar.
 * <p>
 * <em>Note</em>: Expected to either be in same folder with the same name (except for the extension) or in the SRC outlet.
 * </p>
 *
 * @param grammar
 *          the grammar, must not be {@code null}
 * @param context
 *          xpand execution context, must not be {@code null}
 * @return the format model, or {@code null} if the resource could not be loaded
 * @throws FileNotFoundException
 *           thrown if the format file could not be found
 */
@SuppressWarnings("PMD.NPathComplexity")
public static FormatConfiguration getFormatModel(final Grammar grammar, final XpandExecutionContext context) throws FileNotFoundException {
  Variable resourceUriVariable = context.getVariable("resourceUri");
  if (resourceUriVariable == null) {
    return null;
  }
  URI uri = (URI) resourceUriVariable.getValue();
  final Resource grammarResource = grammar.eResource();
  final ResourceSet resourceSet = grammarResource.getResourceSet();
  Resource formatResource = null;
  try {
    formatResource = resourceSet.getResource(uri, true);
  } catch (final ClasspathUriResolutionException e) {
    // make another attempt
    uri = getDefaultFormatLocation(grammar, context);
    try {
      formatResource = resourceSet.getResource(uri, true);
    } catch (WrappedException e1) {
      formatResource = resourceSet.getResource(uri, false);
      if (formatResource != null) {
        resourceSet.getResources().remove(formatResource);
      }
      throw new FileNotFoundException(uri.toString()); // NOPMD
    }
  }
  if (formatResource == null) {
    throw new FileNotFoundException(uri.toString());
  }

  final List<Issue> issues = getModelValidator().validate(formatResource, LOG);

  for (final Issue issue : issues) {
    if (issue.isSyntaxError() || issue.getSeverity() == Severity.ERROR) {
      throw new WorkflowInterruptedException("Errors found in " + uri.toString() + ": " + issue.getMessage());
    }
  }

  return formatResource.getContents().size() == 0 ? null : (FormatConfiguration) formatResource.getContents().get(0);
}
 
Example 8
Source File: IssueMatcher.java    From n4js with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a builder for an issue's message.
 *
 * @see Issue#getMessage()
 *
 * @return an instance of {@link StringPropertyMatcher} that can be used to specify the actual expectation
 */
public StringPropertyMatcherBuilder message() {
	return new StringPropertyMatcherBuilder(this, "message", (Issue issue) -> issue.getMessage());
}