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

The following examples show how to use org.eclipse.xtext.validation.Issue#getLength() . 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: MarkerCreator.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.0
 */
protected void setMarkerAttributes(Issue issue, IResource resource, IMarker marker) throws CoreException {
	String lineNR = "";
	if (issue.getLineNumber() != null) {
		lineNR = "line: " + issue.getLineNumber() + " ";
	}
	marker.setAttribute(IMarker.LOCATION, lineNR + resource.getFullPath().toString());
	marker.setAttribute(Issue.CODE_KEY, issue.getCode());		
	marker.setAttribute(IMarker.SEVERITY, getSeverity(issue));
	marker.setAttribute(IMarker.CHAR_START, issue.getOffset());
	if(issue.getOffset() != null && issue.getLength() != null)
		marker.setAttribute(IMarker.CHAR_END, issue.getOffset()+issue.getLength());
	marker.setAttribute(IMarker.LINE_NUMBER, issue.getLineNumber());
	marker.setAttribute(Issue.COLUMN_KEY, issue.getColumn());
	marker.setAttribute(IMarker.MESSAGE, issue.getMessage());

	if (issue.getUriToProblem()!=null) 
		marker.setAttribute(Issue.URI_KEY, issue.getUriToProblem().toString());
	if(issue.getData() != null && issue.getData().length > 0) {
		marker.setAttribute(Issue.DATA_KEY, Strings.pack(issue.getData()));
	}
	if (resolutionProvider != null && resolutionProvider.hasResolutionFor(issue.getCode())) {
		marker.setAttribute(FIXABLE_KEY, true);
	}
}
 
Example 3
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 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: SARLQuickfixProvider.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Remove the element related to the issue, and the whitespaces after the element until the given separator.
 *
 * @param issue the issue.
 * @param document the document.
 * @param separator the separator to consider.
 * @return <code>true</code> if the separator was found, <code>false</code> if not.
 * @throws BadLocationException if there is a problem with the location of the element.
 */
public boolean removeToNextSeparator(Issue issue, IXtextDocument document, String separator)
		throws BadLocationException {
	// Skip spaces after the identifier until the separator
	int index = issue.getOffset() + issue.getLength();
	char c = document.getChar(index);
	while (Character.isWhitespace(c)) {
		index++;
		c = document.getChar(index);
	}

	// Test if it next non-space character is the separator
	final boolean foundSeparator = document.getChar(index) == separator.charAt(0);
	if (foundSeparator) {
		index++;
		c = document.getChar(index);
		// Skip the previous spaces
		while (Character.isWhitespace(c)) {
			index++;
			c = document.getChar(index);
		}

		final int newLength = index - issue.getOffset();
		document.replace(issue.getOffset(), newLength, ""); //$NON-NLS-1$
	}

	return foundSeparator;
}
 
Example 6
Source File: SARLQuickfixProvider.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Remove the element related to the issue, and the whitespaces before the element until the begin separator,
 * and the whitespaces after the element until the end separator.
 *
 * @param issue the issue.
 * @param document the document.
 * @param beginSeparator the separator before the element.
 * @param endSeparator the separator after the element.
 * @return <code>true</code> if the separator was found, <code>false</code> if not.
 * @throws BadLocationException if there is a problem with the location of the element.
 */
public boolean removeBetweenSeparators(Issue issue, IXtextDocument document,
		String beginSeparator, String endSeparator) throws BadLocationException {
	int offset = issue.getOffset();
	int length = issue.getLength();

	// Skip spaces before the identifier until the separator
	int index = offset - 1;
	char c = document.getChar(index);
	while (Character.isWhitespace(c)) {
		index--;
		c = document.getChar(index);
	}

	// Test if it previous non-space character is the separator
	boolean foundSeparator = document.getChar(index) == beginSeparator.charAt(0);
	if (foundSeparator) {
		index--;
		c = document.getChar(index);
		// Skip the previous spaces
		while (Character.isWhitespace(c)) {
			index--;
			c = document.getChar(index);
		}

		length = length + (offset - index - 1);
		offset = index + 1;

		// Skip spaces after the identifier until the separator
		index = offset + length;
		c = document.getChar(index);
		while (Character.isWhitespace(c)) {
			index++;
			c = document.getChar(index);
		}

		// Test if it next non-space character is the separator
		foundSeparator = document.getChar(index) == endSeparator.charAt(0);
		if (foundSeparator) {
			index++;

			length = index - offset;
			document.replace(offset, length, ""); //$NON-NLS-1$
		}
	}

	return foundSeparator;
}