Java Code Examples for org.eclipse.core.resources.IMarker#isSubtypeOf()

The following examples show how to use org.eclipse.core.resources.IMarker#isSubtypeOf() . 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: CompilationUnitAnnotationModelEvent.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void testIfProblemMarker(Annotation annotation) {
	if (fIncludesProblemMarkerAnnotations) {
		return;
	}
	if (annotation instanceof JavaMarkerAnnotation) {
		fIncludesProblemMarkerAnnotations= ((JavaMarkerAnnotation) annotation).isProblem();
	} else if (annotation instanceof MarkerAnnotation) {
		try {
			IMarker marker= ((MarkerAnnotation) annotation).getMarker();
			if (!marker.exists() || marker.isSubtypeOf(IMarker.PROBLEM)) {
				fIncludesProblemMarkerAnnotations= true;
			}
		} catch (CoreException e) {
			JavaPlugin.log(e);
		}
	}
}
 
Example 2
Source File: MarkerResolutionGenerator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
	final IMarkerResolution[] emptyResult = new IMarkerResolution[0];
	try {
		if (!marker.isSubtypeOf(MarkerTypes.ANY_VALIDATION))
			return emptyResult;
	} catch (CoreException e) {
		return emptyResult;
	}
	if (!languageResourceHelper.isLanguageResource(marker.getResource())) {
		return emptyResult;
	}
	XtextEditor editor = findEditor(marker.getResource());
	if (editor != null) {
		IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
		if (annotationModel != null && !isMarkerStillValid(marker, annotationModel))
			return emptyResult;
	}
	Issue issue = getIssueUtil().createIssue(marker);
	if (issue == null)
		return emptyResult;

	List<IssueResolution> resolutions = getResolutionProvider().getResolutions(issue);
	List<IMarkerResolution> result = Lists.newArrayList();
	List<IssueResolution> remaining = Lists.newArrayList();
	for (IssueResolution resolution : resolutions) {
		if (resolution.getModification() instanceof IBatchableModification) {
			result.add(adapterFactory.create(marker, resolution));
		} else if (resolution.getModification() instanceof ITextualMultiModification) {
			result.add(textualMultiModificationAdapterFactory.create(marker, resolution));
		} else {
			remaining.add(resolution);
		}
	}
	result.addAll(Lists.newArrayList(getAdaptedResolutions(remaining)));
	return result.toArray(new IMarkerResolution[result.size()]);
}
 
Example 3
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param marker
 * @return
 */
private static Range convertRange(IDocument document, IMarker marker) {
	int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1;
	if (line < 0) {
		int end = marker.getAttribute(IMarker.CHAR_END, -1);
		int start = marker.getAttribute(IMarker.CHAR_START, -1);
		if (start >= 0 && end >= start) {
			int[] startPos = JsonRpcHelpers.toLine(document, start);
			int[] endPos = JsonRpcHelpers.toLine(document, end);
			return new Range(new Position(startPos[0], startPos[1]), new Position(endPos[0], endPos[1]));
		}
		return new Range(new Position(0, 0), new Position(0, 0));
	}
	int cStart = 0;
	int cEnd = 0;
	try {
		//Buildship doesn't provide markers for gradle files, Maven does
		if (marker.isSubtypeOf(IMavenConstants.MARKER_ID)) {
			cStart = marker.getAttribute(IMavenConstants.MARKER_COLUMN_START, -1);
			cEnd = marker.getAttribute(IMavenConstants.MARKER_COLUMN_END, -1);
		} else {
			int lineOffset = 0;
			try {
				lineOffset = document.getLineOffset(line);
			} catch (BadLocationException unlikelyException) {
				JavaLanguageServerPlugin.logException(unlikelyException.getMessage(), unlikelyException);
				return new Range(new Position(line, 0), new Position(line, 0));
			}
			cEnd = marker.getAttribute(IMarker.CHAR_END, -1) - lineOffset;
			cStart = marker.getAttribute(IMarker.CHAR_START, -1) - lineOffset;
		}
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException(e.getMessage(), e);
	}
	cStart = Math.max(0, cStart);
	cEnd = Math.max(0, cEnd);

	return new Range(new Position(line, cStart), new Position(line, cEnd));
}
 
Example 4
Source File: MarkerUtil.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean isFindBugsMarker(IMarker marker) {
    try {
        return marker != null &&
                marker.exists() &&
                marker.isSubtypeOf(FindBugsMarker.NAME);
    } catch (CoreException e) {
        FindbugsPlugin.getDefault().logException(e, "Exception while checking SpotBugs type on marker.");
    }
    return false;
}
 
Example 5
Source File: WorkbenchMarkerResolutionGenerator.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * Note : this method is largely copied from the superclass, all we need to override is the call to
 * getAdaptedResolutions to provider the marker.
 */
@Override
public IMarkerResolution[] getResolutions(final IMarker marker) {
  final IMarkerResolution[] emptyResult = new IMarkerResolution[0];
  try {
    if (!marker.isSubtypeOf(MarkerTypes.ANY_VALIDATION)) {
      return emptyResult;
    }
  } catch (CoreException e) {
    return emptyResult;
  }
  if (!languageResourceHelper.isLanguageResource(marker.getResource())) {
    return emptyResult;
  }

  final XtextEditor editor = getEditor(marker.getResource());
  if (editor != null) {
    final IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
    if (annotationModel != null && !isMarkerStillValid(marker, annotationModel)) {
      return emptyResult;
    }
  }

  final Iterable<IssueResolution> resolutions = getResolutionProvider().getResolutions(getIssueUtil().createIssue(marker));
  if (editor != null && editor.isEditorInputReadOnly()) {
    editor.close(false);
  }

  return getAdaptedResolutions(resolutions, marker);
}
 
Example 6
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isMarkerInRange(IMarker marker, ISourceReference sourceElement) throws CoreException {
	if (marker.isSubtypeOf(IMarker.TEXT)) {
		int pos= marker.getAttribute(IMarker.CHAR_START, -1);
		return isInside(pos, sourceElement);
	}
	return false;
}
 
Example 7
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IMarker isAnnotationInRange(IAnnotationModel model, Annotation annot, ISourceReference sourceElement) throws CoreException {
	if (annot instanceof MarkerAnnotation) {
		if (sourceElement == null || isInside(model.getPosition(annot), sourceElement)) {
			IMarker marker= ((MarkerAnnotation) annot).getMarker();
			if (marker.exists() && marker.isSubtypeOf(IMarker.PROBLEM)) {
				return marker;
			}
		}
	}
	return null;
}