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

The following examples show how to use org.eclipse.core.resources.IMarker#delete() . 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: ErrorMarkerGenerator.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
public boolean clearMarkers(final IProject curProj) {
	final boolean allMarkersDeleted = true;
	try {
		for (final IMarker marker : this.markers) {
			if (curProj == null || (curProj != null && curProj.equals(marker.getResource().getProject()))) {
				marker.delete();
			}
		}
		if (curProj != null) {
			curProj.refreshLocal(IResource.DEPTH_INFINITE, null);
		}
	}
	catch (final CoreException e) {
		Activator.getDefault().logError(e);
	}
	this.markers.clear();
	return allMarkersDeleted;
}
 
Example 2
Source File: AbstractProblemHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testAnnotationOnMultipleLines() throws Exception {
	IMarker warning = file.createMarker(MarkerTypes.NORMAL_VALIDATION);
	warning.setAttribute(IMarker.LOCATION, "line: 1 " + file.getFullPath().toString());
	warning.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
	warning.setAttribute(IMarker.CHAR_START, 0);
	warning.setAttribute(IMarker.CHAR_END, 43);
	warning.setAttribute(IMarker.LINE_NUMBER, 1);
	warning.setAttribute(IMarker.MESSAGE, "Foo");
	
	List<Annotation> annotations = hover.getAnnotations(1, 40);
	assertEquals(2, annotations.size());
	// The error is on the same line as the requested position, so it should be returned first
	assertEquals("org.eclipse.xtext.ui.editor.error", annotations.get(0).getType());
	assertEquals("org.eclipse.xtext.ui.editor.warning", annotations.get(1).getType());
	
	warning.delete();
}
 
Example 3
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.7
 */
protected void cleanDerivedResources(Delta delta, Set<IFile> derivedResources, IBuildContext context,
		EclipseResourceFileSystemAccess2 access, IProgressMonitor deleteMonitor) throws CoreException {
	String uri = delta.getUri().toString();
	for (IFile iFile : newLinkedHashSet(derivedResources)) {
		if (deleteMonitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		IMarker marker = derivedResourceMarkers.findDerivedResourceMarker(iFile, uri);
		if (marker != null)
			marker.delete();
		if (derivedResourceMarkers.findDerivedResourceMarkers(iFile).length == 0) {
			access.deleteFile(iFile, deleteMonitor);
			context.needRebuild();
		}
	}
}
 
Example 4
Source File: RemoveAllXBookmarksHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute (ExecutionEvent event) throws ExecutionException {
    IResource scope = XBookmarksUtils.getWorkspaceScope();
    if (scope == null) {
        return null;
    }
    
    for (int markerNumber = 0; markerNumber <= 9; ++markerNumber) {
        IMarker marker = XBookmarksUtils.fetchBookmark(scope, markerNumber);
        if (marker != null) {
            try {
                marker.delete();
            }
            catch (CoreException e) {
                XBookmarksUtils.logError(e);
                statusLine.showErrMessage(MessageFormat.format(Messages.BookmarkAction_CantDeleteBM, markerNumber));
                break;
            }
        }
    }
    XBookmarksState xBbookmarkStateService = (XBookmarksState)WorkbenchUtils.getSourceProvider(XBookmarksState.EXIST_STATE);
    if (xBbookmarkStateService != null) {
    	xBbookmarkStateService.fireAllBookmarkRemoved();
    }
    return null;
}
 
Example 5
Source File: XBookmarksDialogHandler.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes all bookmarks
 */
protected void removeAllBookmarks() {
    IResource scope = XBookmarksUtils.getWorkspaceScope();
    if (scope == null) {
        return;
    }
    
    for (int markerNumber = 0; markerNumber <= 9; ++markerNumber) {
        IMarker marker = XBookmarksUtils.fetchBookmark(scope, markerNumber);
        if (marker != null) {
            try {
                marker.delete();
            }
            catch (CoreException e) {
                XBookmarksUtils.logError(e);
                statusLine.showErrMessage(MessageFormat.format(Messages.BookmarkAction_CantDeleteBM, markerNumber));
                break;
            }
        }
    }
}
 
Example 6
Source File: WorkItem.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void clearMarkers() throws CoreException {
    IResource res = getMarkerTarget();
    if (javaElt == null || !(res instanceof IProject)) {
        MarkerUtil.removeMarkers(res);
    } else {
        // this is the case of external class folders/libraries: if we would
        // cleanup ALL project markers, it would also remove markers from
        // ALL
        // source/class files, not only for the selected one.
        IMarker[] allMarkers = MarkerUtil.getAllMarkers(res);
        Set<IMarker> set = MarkerUtil.findMarkerForJavaElement(javaElt, allMarkers, true);
        // TODO can be very slow. May think about batch operation w/o
        // resource notifications
        // P.S. if executing "clean+build", package explorer first doesn't
        // notice
        // any change because the external class file labels are not
        // refreshed after clean,
        // but after build we trigger an explicit view refresh, see
        // FindBugsAction
        for (IMarker marker : set) {
            marker.delete();
        }
    }
}
 
Example 7
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private void toggleBookmark(final Long rank) {
    if (fBookmarksFile == null) {
        return;
    }
    if (fBookmarksMap.containsKey(rank)) {
        final Collection<Long> markerIds = fBookmarksMap.removeAll(rank);
        fTable.refresh();
        try {
            for (long markerId : markerIds) {
                final IMarker bookmark = fBookmarksFile.findMarker(markerId);
                if (bookmark != null) {
                    bookmark.delete();
                }
            }
        } catch (final CoreException e) {
            TraceUtils.displayErrorMsg(e);
        }
    } else {
        addBookmark(fBookmarksFile);
    }
}
 
Example 8
Source File: SuppressResolution.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
public void run(IMarker marker) {
	try {
		IResource resource = (IResource)marker.getResource();
		IProject project = resource.getProject();
		String problemId = marker.getAttribute(ProblemReporter.ATTRIBUTE_ID, ""); //$NON-NLS-1$
		int line = marker.getAttribute(ProblemReporter.ATTRIBUTE_ORIGINAL_LINE_NUMBER, 0);
		File file = new File(marker.getAttribute(ProblemReporter.ATTRIBUTE_FILE, "")); //$NON-NLS-1$
		marker.delete();
		SuppressionProfile profile = new SuppressionProfile(CppcheclipsePlugin.getProjectPreferenceStore(project), project);
		suppress(profile, resource, file, problemId, line);
		profile.save();
	} 
	catch (Exception e) {
		CppcheclipsePlugin.logError("Could not save suppression", e);
	}
}
 
Example 9
Source File: MarkerUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Delete all Markers with the given type.
 * 
 * @param resource
 * @param type
 * @param includeSubtypes
 * @return IMarker[]
 * @throws CoreException
 *             with a multi-status problems in case some markers where not successfully deleted.
 */
public static void deleteMarkers(IUniformResource resource, String type, boolean includeSubtypes)
		throws CoreException
{
	IMarker[] toDelete = findMarkers(resource, type, includeSubtypes);
	MultiStatus status = new MultiStatus(CorePlugin.PLUGIN_ID, 0, "Errors deleting markers", null); //$NON-NLS-1$
	for (IMarker marker : toDelete)
	{
		try
		{
			marker.delete();
		}
		catch (CoreException e)
		{
			status.add(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, e.getMessage(), e));
		}
	}
	if (status.getChildren().length > 0)
	{
		throw new CoreException(status);
	}
}
 
Example 10
Source File: QuickFix.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
public void run(IMarker marker) {
	try {
		String[] path = ((String) marker.getAttribute("PATH")).split("/");
		switch (fixType) {
			case ADD_TO_TAXONOMY:
				addToTaxonomy(path);
				break;
			case DELETE_FROM_FILE:
				deleteFromFile(path, marker.getAttribute(IMarker.LOCATION).toString());
				break;
			case MATCH_TAXONOMY:
				moveTermInFile(path, ((String) marker.getAttribute("PATH2")).split("/"), marker.getAttribute(IMarker.LOCATION).toString());
				break;
		}
		
		marker.delete();
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 11
Source File: BuildInstruction.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void deleteObsoleteResources(final String uri, IProgressMonitor progressMonitor) throws CoreException {
	SubMonitor deleteMonitor = SubMonitor.convert(progressMonitor, derivedResources.size());
	for (IFile iFile : newLinkedHashSet(derivedResources)) {
		IMarker marker = derivedResourceMarkers.findDerivedResourceMarker(iFile, uri);
		if (marker != null)
			marker.delete();
		if (derivedResourceMarkers.findDerivedResourceMarkers(iFile).length == 0) {
			for (String outputName : outputConfigurations.keySet()) {
				access.deleteFile(iFile, outputName, deleteMonitor);
			}
			needRebuild();
		}
	}
}
 
Example 12
Source File: AbstractProblemHoverTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testMultipleAnnotationTypes() throws Exception {
	IMarker warning = file.createMarker(MarkerTypes.NORMAL_VALIDATION);
	warning.setAttribute(IMarker.LOCATION, "line: 2 " + file.getFullPath().toString());
	warning.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
	warning.setAttribute(IMarker.CHAR_START, 14);
	warning.setAttribute(IMarker.CHAR_END, 19);
	warning.setAttribute(IMarker.LINE_NUMBER, 2);
	warning.setAttribute(IMarker.MESSAGE, "Foo");
	
	IMarker info = file.createMarker(MarkerTypes.NORMAL_VALIDATION);
	info.setAttribute(IMarker.LOCATION, "line: 2 " + file.getFullPath().toString());
	info.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
	info.setAttribute(IMarker.CHAR_START, 20);
	info.setAttribute(IMarker.CHAR_END, 29);
	info.setAttribute(IMarker.LINE_NUMBER, 2);
	info.setAttribute(IMarker.MESSAGE, "Bar");
	
	List<Annotation> annotations = hover.getAnnotations(1, -1);
	List<Annotation> sorted = hover.sortBySeverity(annotations);
	assertEquals(3, sorted.size());
	// First errors, then warnings, then the rest
	assertEquals("org.eclipse.xtext.ui.editor.error", sorted.get(0).getType());
	assertEquals("org.eclipse.xtext.ui.editor.warning", sorted.get(1).getType());
	assertEquals("org.eclipse.xtext.ui.editor.info", sorted.get(2).getType());
	
	warning.delete();
	info.delete();
}
 
Example 13
Source File: DerivedResourceMarkerCopier.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void cleanUpCreatedMarkers(IFile javaFile, IResource srcFile) throws CoreException {
	for (IMarker iMarker : srcFile.findMarkers(MarkerTypes.ANY_VALIDATION, true, IResource.DEPTH_ZERO)) {
		if (javaFile.getFullPath().toString().equals(iMarker.getAttribute(COPIED_FROM_FILE, ""))) {
			iMarker.delete();
		}
	}
}
 
Example 14
Source File: ImpexTypeHyperlink.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void open() {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	
	String typeLocation = Activator.getDefault().getTypeLoaderInfo(location);
	String fileName = typeLocation.substring(0, typeLocation.indexOf(":"));
	String extensionName = fileName.replaceAll("-items.xml", "");
	String lineNumberStr = typeLocation.substring(typeLocation.indexOf(":") + 1, typeLocation.indexOf("("));
	
	IProject extension = ResourcesPlugin.getWorkspace().getRoot().getProject(extensionName);
   	IFile itemsxml = extension.getFile("resources/" + fileName);
   	if (itemsxml.exists()) {
       	IMarker marker;
       	try {
			marker = itemsxml.createMarker(IMarker.TEXT);
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put(IMarker.LINE_NUMBER, Integer.parseInt(lineNumberStr));
			marker.setAttributes(map);
			//IDE.openEditor(getSite().getPage(), marker);
			IDE.openEditor(page, marker);
			marker.delete();
		}
       	catch (CoreException e) {
       		Activator.logError("Eclipse CoreException", e);
		}
   	}
   	else {
   		MessageBox dialog = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
   		dialog.setText("Extension not found");
   		dialog.setMessage("The extension " + extensionName + " was not found in the workspace. Please import it and try again.");
   		dialog.open();
   	}
}
 
Example 15
Source File: TodoTaskMarkerManager.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates and returns the "to do" task marker with the specified position 
 * on the given file. All previous markers with position up to the given will
 * be removed. 
 * 
 * @param project a project to operate on, must not be <tt>null</tt>
 * @param file a source file in which the task takes place or <tt>null</tt>
 * @param task instance of discovered task.
 * @param message text of the task
 * @param position a start position of the task
 * @param endOffset a end offset of the task
 * @param oldMarkers markers from the previous parsing to be reused or removed.
 * 
 * @return the handle of the new marker, or <tt>null</tt> if marker wasn't created. 
 */
public static IMarker updateMarkers( IResource resource
                                   , TextPosition position, int endOffset 
                                   , TodoTask task, String message
                                   , IMarker[] oldMarkers
                                   ) throws CoreException 
{
    int startOffs = position.getOffset();
    IMarker newMarker = null;
    String newMessage = createMessage(task, message);
    
    // Remove or reuse 'to-do' markers from previous parsing
    for (int i = 0; i < oldMarkers.length; ++i) {
        IMarker marker = oldMarkers[i];
        if (marker != null) {
            int markerOffs = marker.getAttribute(IMarker.CHAR_START, 0);
            if (markerOffs <= startOffs) {
            	// to remove all editable markers
            	boolean isMarkerNotEditable = Boolean.FALSE.equals(marker.getAttribute(IMarker.USER_EDITABLE));
                boolean isMarkerEqual = (markerOffs == startOffs)
                                     && newMessage.equals(marker.getAttribute(IMarker.MESSAGE, null))
                                     && isMarkerNotEditable;
                if (isMarkerEqual) {
                    newMarker = marker;  // reuse the marker from previous parsing
                } else {
                    marker.delete();
                }
                oldMarkers[i] = null;
            }
        }
    }
    
    if (newMarker == null) {          
        newMarker = createMarker(resource, position, endOffset, task, message);
    }

    return newMarker;
}
 
Example 16
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Remove all markers denoting classpath problems
 */ //TODO (philippe) should improve to use a bitmask instead of booleans (CYCLE, FORMAT, VALID)
protected void flushClasspathProblemMarkers(boolean flushCycleMarkers, boolean flushClasspathFormatMarkers, boolean flushOverlappingOutputMarkers) {
	try {
		if (this.project.isAccessible()) {
			IMarker[] markers = this.project.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
			for (int i = 0, length = markers.length; i < length; i++) {
				IMarker marker = markers[i];
				if (flushCycleMarkers && flushClasspathFormatMarkers && flushOverlappingOutputMarkers) {
					marker.delete();
				} else {
					String cycleAttr = (String)marker.getAttribute(IJavaModelMarker.CYCLE_DETECTED);
					String classpathFileFormatAttr =  (String)marker.getAttribute(IJavaModelMarker.CLASSPATH_FILE_FORMAT);
					String overlappingOutputAttr = (String) marker.getAttribute(IJavaModelMarker.OUTPUT_OVERLAPPING_SOURCE);
					if ((flushCycleMarkers == (cycleAttr != null && cycleAttr.equals("true"))) //$NON-NLS-1$
						&& (flushOverlappingOutputMarkers == (overlappingOutputAttr != null && overlappingOutputAttr.equals("true"))) //$NON-NLS-1$
						&& (flushClasspathFormatMarkers == (classpathFileFormatAttr != null && classpathFileFormatAttr.equals("true")))){ //$NON-NLS-1$
						marker.delete();
					}
				}
			}
		}
	} catch (CoreException e) {
		// could not flush markers: not much we can do
		if (JavaModelManager.VERBOSE) {
			e.printStackTrace();
		}
	}
}
 
Example 17
Source File: MarkerReporter.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void addMarker(MarkerParameter mp) throws CoreException {
    Map<String, Object> attributes = createMarkerAttributes(mp);
    if (attributes.isEmpty()) {
        collection.remove(mp.bug);
        return;
    }
    IResource markerTarget = mp.resource.getMarkerTarget();
    IMarker[] existingMarkers = markerTarget.findMarkers(mp.markerType, true, IResource.DEPTH_ZERO);

    // XXX Workaround for bug 2785257 (has to be solved better)
    // see
    // http://sourceforge.net/tracker/?func=detail&atid=614693&aid=2785257&group_id=96405
    // currently we can't run FB only on a subset of classes related to the
    // specific
    // source folder if source folders have same class output directory.
    // In this case the classes from BOTH source folders are examined by FB
    // and
    // new markers can be created for issues which are already reported.
    // Therefore here we check if a marker with SAME bug id is already
    // known,
    // and if yes, delete it (replacing with newer one)
    if (existingMarkers.length > 0) {
        IMarker oldMarker = findSameBug(attributes, existingMarkers);
        if (oldMarker != null) {
            oldMarker.delete();
        }
    }
    IMarker newMarker = markerTarget.createMarker(mp.markerType);
    newMarker.setAttributes(attributes);
}
 
Example 18
Source File: DsfGdbAdaptor.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void gotoRank(IEditorPart editor, int rank) {
    IEditorInput editorInput = editor.getEditorInput();
    if (editorInput instanceof IFileEditorInput) {
        IFile file = ((IFileEditorInput) editorInput).getFile();
        try {
            final IMarker marker = file.createMarker(IMarker.MARKER);
            marker.setAttribute(IMarker.LOCATION, (Integer) rank);
            IDE.gotoMarker(editor, marker);
            marker.delete();
        } catch (CoreException e) {
            GdbTraceCorePlugin.logError(e.getMessage(), e);
        }
    }
}
 
Example 19
Source File: JavaSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException {
	try {
		IMarker marker= file.createMarker(NewSearchUI.SEARCH_MARKER);
		HashMap<String, Integer> attributes= new HashMap<String, Integer>(4);
		attributes.put(IMarker.CHAR_START, new Integer(offset));
		attributes.put(IMarker.CHAR_END, new Integer(offset + length));
		marker.setAttributes(attributes);
		IDE.gotoMarker(editor, marker);
		marker.delete();
	} catch (CoreException e) {
		throw new PartInitException(SearchMessages.JavaSearchResultPage_error_marker, e);
	}
}
 
Example 20
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();
	}
}