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

The following examples show how to use org.eclipse.core.resources.IMarker#exists() . 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: JavaMarkerAnnotation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public int getId() {
		IMarker marker= getMarker();
		if (marker == null  || !marker.exists())
			return -1;

		if (isProblem())
			return marker.getAttribute(IJavaModelMarker.ID, -1);

//		if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) {
//			try {
//				if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) {
//					return IProblem.Task;
//				}
//			} catch (CoreException e) {
//				JavaPlugin.log(e); // should no happen, we test for marker.exists
//			}
//		}

		return -1;
	}
 
Example 2
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 3
Source File: BugPrioritySorter.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Sorts markers on rank, then priority, and then on name if requested
 *
 * @param m1
 * @param m2
 * @return
 */
static int compareMarkers(IMarker m1, IMarker m2) {
    if (m1 == null || m2 == null || !m1.exists() || !m2.exists()) {
        return 0;
    }
    int rank1 = MarkerUtil.findBugRankForMarker(m1);
    int rank2 = MarkerUtil.findBugRankForMarker(m2);
    int result = rank1 - rank2;
    if (result != 0) {
        return result;
    }
    int prio1 = MarkerUtil.findConfidenceForMarker(m1).ordinal();
    int prio2 = MarkerUtil.findConfidenceForMarker(m2).ordinal();
    result = prio1 - prio2;
    if (result != 0) {
        return result;
    }
    String a1 = m1.getAttribute(IMarker.MESSAGE, "");
    String a2 = m2.getAttribute(IMarker.MESSAGE, "");
    return a1.compareToIgnoreCase(a2);
}
 
Example 4
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static Diagnostic toDiagnostic(Range range, IMarker marker, boolean isDiagnosticTagSupported) {
	if (marker == null || !marker.exists()) {
		return null;
	}
	Diagnostic d = new Diagnostic();
	d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
	String message = marker.getAttribute(IMarker.MESSAGE, "");
	if (Messages.ProjectConfigurationUpdateRequired.equals(message)) {
		message = PROJECT_CONFIGURATION_IS_NOT_UP_TO_DATE_WITH_POM_XML;
	}
	d.setMessage(message);
	d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY, -1)));
	int problemId = marker.getAttribute(IJavaModelMarker.ID, 0);
	d.setCode(String.valueOf(problemId));
	if (isDiagnosticTagSupported) {
		d.setTags(DiagnosticsHandler.getDiagnosticTag(problemId));
	}
	d.setRange(range);
	return d;
}
 
Example 5
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static Diagnostic toDiagnostic(IDocument document, IMarker marker, boolean isDiagnosticTagSupported) {
	if (marker == null || !marker.exists()) {
		return null;
	}
	Diagnostic d = new Diagnostic();
	d.setSource(JavaLanguageServerPlugin.SERVER_SOURCE_ID);
	d.setMessage(marker.getAttribute(IMarker.MESSAGE, ""));
	int problemId = marker.getAttribute(IJavaModelMarker.ID, 0);
	d.setCode(String.valueOf(problemId));
	d.setSeverity(convertSeverity(marker.getAttribute(IMarker.SEVERITY, -1)));
	d.setRange(convertRange(document, marker));
	if (isDiagnosticTagSupported) {
		d.setTags(DiagnosticsHandler.getDiagnosticTag(problemId));
	}
	return d;
}
 
Example 6
Source File: XBookmarksDialogHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
protected XBookmarksDialog.Model.Row getDescription (IMarker marker) {
    if (marker!= null && marker.exists()) {
        int markerNumber = marker.getAttribute(XBookmarksPlugin.BOOKMARK_NUMBER_ATTR, -1);
        if (markerNumber >=0 && markerNumber <= 9) {
            int    line       = MarkerUtilities.getLineNumber(marker);
            String resName    = marker.getResource().getName();
            
            String markerName = MarkerUtilities.getMessage(marker);
            String prefix     = mkBookmarkNamePrefix(markerNumber);
            if (markerName.startsWith(prefix)) {
                markerName = markerName.substring(prefix.length());
                if (markerName.startsWith(": ")) { //$NON-NLS-1$
                    markerName = markerName.substring(2);
                }
                markerName = markerName.trim();
                if (markerName.isEmpty()) {
                    markerName = prefix;
                }
            }
            return new XBookmarksDialog.Model.Row(new String[]{ "" + markerNumber + "."  //$NON-NLS-1$ //$NON-NLS-2$
                                                              , resName + ":" + line     //$NON-NLS-1$ 
                                                              , markerName}).setData(markerNumber);  
        }
    }
    return null;
}
 
Example 7
Source File: JavaCorrectionProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean hasCorrections(IMarker marker) {
	if (marker == null || !marker.exists())
		return false;

	IMarkerHelpRegistry registry= IDE.getMarkerHelpRegistry();
	return registry != null && registry.hasResolutions(marker);
}
 
Example 8
Source File: JavaMarkerAnnotation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getMarkerType() {
	IMarker marker= getMarker();
	if (marker == null  || !marker.exists())
		return null;

	return  MarkerUtilities.getMarkerType(getMarker());
}
 
Example 9
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;
}
 
Example 10
Source File: BugLabelProvider.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public String getText(Object element) {
    if (element instanceof BugGroup) {
        BugGroup group = (BugGroup) element;
        Object data = group.getData();
        if (group.getType() == GroupType.Project && data != null) {
            try {
                SortedBugCollection bc = FindbugsPlugin.getBugCollection((IProject) data, null);
            } catch (CoreException e) {
                FindbugsPlugin.getDefault().logException(e, "Failed to load bug collection");
            }
        }
        if (isStandalone()) {
            return group.getShortDescription();
        }
        int filtered = getFilteredMarkersCount(group);
        String filterCount = filtered > 0 ? "/" + filtered + " filtered" : "";
        String str = group.getShortDescription() + " (" + (group.getMarkersCount() - filtered) + filterCount + ")";
        return str;
    }
    if (element instanceof IMarker) {
        IMarker marker = (IMarker) element;
        if (!marker.exists()) {
            return null;
        }
    }
    if (element instanceof IStructuredSelection) {
        return getDescriptionAndBugCount(((IStructuredSelection) element).toArray());
    }
    if (element instanceof Object[]) {
        return getDescriptionAndBugCount((Object[]) element);
    }
    return wbProvider.getText(element);
}
 
Example 11
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 12
Source File: ModulaEditor.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
 	public boolean paint(SourceCodeTextEditor editor, MarkerAnnotation annotation,
 			GC gc, Canvas canvas, Rectangle bounds) {
 		IMarker marker = annotation.getMarker();
try {
	if (marker.exists() && XdsMarkerConstants.PARSER_PROBLEM.equals(marker.getType())) {
		boolean isInCompilationSet = CompilationSetManager.getInstance().isInCompilationSet((IFile)marker.getResource());
		if (!isInCompilationSet) {
			int actualSeverity = marker.getAttribute(XdsMarkerConstants.PARSER_PROBLEM_SEVERITY_ATTRIBUTE, -1);
			if (actualSeverity > -1) {
				Image image = null;
				switch (actualSeverity) {
				case IMarker.SEVERITY_ERROR:
					image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); 
					break;
				case IMarker.SEVERITY_WARNING:
					image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK); 
					break;
				default:
					break;
				}

				if (image != null) {
					ImageUtilities.drawImage(image, gc, canvas, bounds, SWT.CENTER, SWT.TOP);
					return true;
				}

				return false;
			}
		}
	}
} catch (CoreException e) {
	LogHelper.logError(e);
}
 		return false;
 	}
 
Example 13
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private List<IMarker> getProblemMarkers(IProgressMonitor monitor) throws CoreException {
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	List<IMarker> markers = new ArrayList<>();
	for (IProject project : projects) {
		if (monitor != null && monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		if (JavaLanguageServerPlugin.getProjectsManager().getDefaultProject().equals(project)) {
			continue;
		}
		IMarker[] allMarkers = project.findMarkers(null, true, IResource.DEPTH_INFINITE);
		for (IMarker marker : allMarkers) {
			if (!marker.exists() || CheckMissingNaturesListener.MARKER_TYPE.equals(marker.getType())) {
				continue;
			}
			if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(marker.getType()) || IJavaModelMarker.TASK_MARKER.equals(marker.getType())) {
				markers.add(marker);
				continue;
			}
			IResource resource = marker.getResource();
			if (project.equals(resource) || projectsManager.isBuildFile(resource)) {
				markers.add(marker);
			}
		}
	}
	return markers;
}
 
Example 14
Source File: WorkspaceDiagnosticsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void publishMarkers(IProject project, IMarker[] markers) throws CoreException {
	Range range = new Range(new Position(0, 0), new Position(0, 0));

	List<IMarker> projectMarkers = new ArrayList<>(markers.length);

	String uri = JDTUtils.getFileURI(project);
	IFile pom = project.getFile("pom.xml");
	List<IMarker> pomMarkers = new ArrayList<>();
	for (IMarker marker : markers) {
		if (!marker.exists() || CheckMissingNaturesListener.MARKER_TYPE.equals(marker.getType())) {
			continue;
		}
		if (IMavenConstants.MARKER_CONFIGURATION_ID.equals(marker.getType())) {
			pomMarkers.add(marker);
		} else {
			projectMarkers.add(marker);
		}
	}
	List<Diagnostic> diagnostics = toDiagnosticArray(range, projectMarkers, isDiagnosticTagSupported);
	String clientUri = ResourceUtils.toClientUri(uri);
	connection.publishDiagnostics(new PublishDiagnosticsParams(clientUri, diagnostics));
	if (pom.exists()) {
		IDocument document = JsonRpcHelpers.toDocument(pom);
		diagnostics = toDiagnosticsArray(document, pom.findMarkers(null, true, IResource.DEPTH_ZERO), isDiagnosticTagSupported);
		List<Diagnostic> diagnosicts2 = toDiagnosticArray(range, pomMarkers, isDiagnosticTagSupported);
		diagnostics.addAll(diagnosicts2);
		String pomSuffix = clientUri.endsWith("/") ? "pom.xml" : "/pom.xml";
		connection.publishDiagnostics(new PublishDiagnosticsParams(ResourceUtils.toClientUri(clientUri + pomSuffix), diagnostics));
	}
}
 
Example 15
Source File: DerivedResourceMarkers.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
public List<IFile> findDerivedResources(List<IMarker> generatorMarkers, String source) throws CoreException {
	List<IFile> result = newArrayList();
	for (IMarker marker : generatorMarkers) {
		if (marker.exists() && (source == null || source.equals(marker.getAttribute(ATTR_SOURCE)))) {
			result.add((IFile)marker.getResource());
		}
	}
	return result;
}
 
Example 16
Source File: WorkbenchMarkerResolutionAdapter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run(IMarker marker) {
	if (!marker.exists()) {
		return;
	}
	run(new IMarker[] { marker }, new NullProgressMonitor());
}
 
Example 17
Source File: TraceMarkers.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public List<IPath> findTraceFiles(IFile sourceFile, String generatorName) throws CoreException {
	List<IPath> result = newArrayList();
	for (IMarker marker : findTraceMarkers(sourceFile)) {
		if (marker.exists()) {
			String markerGeneratorName = marker.getAttribute(ATTR_GENERATOR_NAME, DEFAULT_GENERATOR_NAME);
			if (generatorName.equals(markerGeneratorName)) {
				String portablePath = marker.getAttribute(ATTR_PATH, (String) null);
				if (portablePath != null) {
					result.add(Path.fromPortableString(portablePath));
				}
			}
		}
	}
	return result;
}
 
Example 18
Source File: CodeHighlighterController.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
private void remove(IMarker marker) throws CoreException {
	if (marker.exists()) {
		marker.delete();
	}
}
 
Example 19
Source File: BugContentProvider.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @return list of the *visible* parents with changed children to refresh
 *         the viewer. Returns empty list if the full refresh is needed
 */
public synchronized Set<BugGroup> updateContent(List<DeltaInfo> deltas) {
    int oldRootSize = rootElement.getChildren().length;
    Set<BugGroup> changedParents = new HashSet<>();
    bugFilterActive = isBugFilterActive();
    Set<String> patternFilter = getPatternFilter();
    for (DeltaInfo delta : deltas) {
        if (DEBUG) {
            System.out.println(delta + " (contentProvider.updateContent)");
        }
        IMarker changedMarker = delta.marker;
        switch (delta.changeKind) {
        case IResourceDelta.REMOVED:
            BugGroup parent = findParent(changedMarker);
            if (parent == null) {
                if (DEBUG) {
                    System.out.println(delta + " IGNORED because marker does not have parent!");
                }
                continue;
            }
            removeMarker(parent, changedMarker, changedParents);
            break;
        case IResourceDelta.ADDED:
            if (!changedMarker.exists()) {
                if (DEBUG) {
                    System.out.println(delta + " IGNORED because marker does not exists anymore!");
                }
                continue;
            }
            addMarker(changedMarker, changedParents, patternFilter);
            break;
        default:
            FindbugsPlugin.getDefault()
                    .logWarning("UKNOWN delta change kind" + delta.changeKind);

        }
    }
    if (rootElement.getMarkersCount() == 0 || rootElement.getChildren().length != oldRootSize) {
        if (oldRootSize == 0 || rootElement.getChildren().length == 0) {
            changedParents.clear();
        } else {
            changedParents.add(rootElement);
        }
        return changedParents;
    }
    // XXX this is a fix for not updating of children on incremental build
    // and
    // for "empty" groups which can never be empty... I don't know where the
    // bug is...
    changedParents.add(rootElement);
    return changedParents;
}
 
Example 20
Source File: JavaMarkerAnnotation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public String[] getArguments() {
	IMarker marker= getMarker();
	if (marker != null && marker.exists() && isProblem())
		return CorrectionEngine.getProblemArguments(marker);
	return null;
}