Java Code Examples for org.eclipse.core.resources.IFile#createMarker()

The following examples show how to use org.eclipse.core.resources.IFile#createMarker() . 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: CrossflowMarkerNavigationProvider.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
* @generated
*/
public static IMarker addMarker(IFile file, String elementId, String location, String message, int statusSeverity) {
	IMarker marker = null;
	try {
		marker = file.createMarker(MARKER_TYPE);
		marker.setAttribute(IMarker.MESSAGE, message);
		marker.setAttribute(IMarker.LOCATION, location);
		marker.setAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, elementId);
		int markerSeverity = IMarker.SEVERITY_INFO;
		if (statusSeverity == IStatus.WARNING) {
			markerSeverity = IMarker.SEVERITY_WARNING;
		} else if (statusSeverity == IStatus.ERROR || statusSeverity == IStatus.CANCEL) {
			markerSeverity = IMarker.SEVERITY_ERROR;
		}
		marker.setAttribute(IMarker.SEVERITY, markerSeverity);
	} catch (CoreException e) {
		CrossflowDiagramEditorPlugin.getInstance().logError("Failed to create validation marker", e); //$NON-NLS-1$
	}
	return marker;
}
 
Example 2
Source File: Model.java    From tlaplus with MIT License 6 votes vote down vote up
private void setMarker(final String markerType, final String attributeName, boolean value) {
	final IFile resource = getFile();
	if (resource.exists()) {
		try {
			IMarker marker;
			final IMarker[] foundMarkers = resource.findMarkers(markerType, false, IResource.DEPTH_ZERO);
			if (foundMarkers.length > 0) {
				marker = foundMarkers[0];
				// remove trash if any
				for (int i = 1; i < foundMarkers.length; i++) {
					foundMarkers[i].delete();
				}
			} else {
				marker = resource.createMarker(markerType);
			}

			marker.setAttribute(attributeName, value);
		} catch (CoreException shouldNotHappen) {
			TLCActivator.logError(shouldNotHappen.getMessage(), shouldNotHappen);
		}
	}
}
 
Example 3
Source File: CompileCommandsJsonParser.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private static void createMarker(IFile file, String message) throws CoreException {
  IMarker marker;
  try {
    marker = file.createMarker(MARKER_ID);
  } catch (CoreException ex) {
    // resource is not (yet) known by the workbench
    try {
      file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
      marker = file.createMarker(MARKER_ID);
    } catch (CoreException ex2) {
      // resource is not known by the workbench, use project instead of file
      marker = file.getProject().createMarker(MARKER_ID);
    }
  }
  marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
  marker.setAttribute(IMarker.MESSAGE, message);
  marker.setAttribute(IMarker.LOCATION, CompileCommandsJsonParser.class.getName());
}
 
Example 4
Source File: UnifiedBuilder.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void addMarkers(Collection<IProblem> items, String markerType, IFile file, IProgressMonitor monitor)
		throws CoreException
{
	if (CollectionsUtil.isEmpty(items))
	{
		return;
	}
	SubMonitor sub = SubMonitor.convert(monitor, items.size() * 2);
	for (IProblem item : items)
	{
		IMarker marker = file.createMarker(markerType);
		sub.worked(1);
		marker.setAttributes(item.createMarkerAttributes());
		sub.worked(1);
	}
	sub.done();
}
 
Example 5
Source File: ProcessMarkerNavigationProvider.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
* @generated
*/
public static IMarker addMarker(IFile file, String elementId, String location, String message, int statusSeverity) {
	IMarker marker = null;
	try {
		marker = file.createMarker(MARKER_TYPE);
		marker.setAttribute(IMarker.MESSAGE, message);
		marker.setAttribute(IMarker.LOCATION, location);
		marker.setAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, elementId);
		int markerSeverity = IMarker.SEVERITY_INFO;
		if (statusSeverity == IStatus.WARNING) {
			markerSeverity = IMarker.SEVERITY_WARNING;
		} else if (statusSeverity == IStatus.ERROR || statusSeverity == IStatus.CANCEL) {
			markerSeverity = IMarker.SEVERITY_ERROR;
		}
		marker.setAttribute(IMarker.SEVERITY, markerSeverity);
	} catch (CoreException e) {
		ProcessDiagramEditorPlugin.getInstance().logError("Failed to create validation marker", e); //$NON-NLS-1$
	}
	return marker;
}
 
Example 6
Source File: CodeHighlighterController.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private void highlight(CodeChunk codeChunk) throws CoreException {
	IProject project = codeChunk.getProject();
	String filePath = codeChunk.getFilePath();
	IFile file = project.getFile(filePath);
	String markerID = getModel().getMarkerID();

	IMarker marker = file.createMarker(markerID);
	initializeMarker(marker, codeChunk);
	markers.add(marker);
}
 
Example 7
Source File: DerivedResourceMarkerCopier.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void copyProblemMarker(IFile javaFile, IEclipseTrace traceToSource, Set<IMarker> problemsInJava, IFile srcFile)
		throws CoreException {
	String sourceMarkerType = null;
	for (IMarker marker : problemsInJava) {
		String message = (String) marker.getAttribute(IMarker.MESSAGE);
		if (message == null) {
			continue;
		}
		Integer charStart = marker.getAttribute(IMarker.CHAR_START, 0);
		Integer charEnd = marker.getAttribute(IMarker.CHAR_END, 0);
		int severity = MarkerUtilities.getSeverity(marker);

		ILocationInEclipseResource associatedLocation = traceToSource.getBestAssociatedLocation(new TextRegion(charStart,
				charEnd - charStart));
		if (associatedLocation != null) {
			if (sourceMarkerType == null) {
				sourceMarkerType = determinateMarkerTypeByURI(associatedLocation.getSrcRelativeResourceURI());
			}
			if (!srcFile.equals(findIFile(associatedLocation, srcFile.getWorkspace()))) {
				LOG.error("File in associated location is not the same as main source file.");
			}
			IMarker xtendMarker = srcFile.createMarker(sourceMarkerType);
			xtendMarker.setAttribute(IMarker.MESSAGE, "Java problem: " + message);
			xtendMarker.setAttribute(IMarker.SEVERITY, severity);
			ITextRegionWithLineInformation region = associatedLocation.getTextRegion();
			xtendMarker.setAttribute(IMarker.LINE_NUMBER, region.getLineNumber());
			xtendMarker.setAttribute(IMarker.CHAR_START, region.getOffset());
			xtendMarker.setAttribute(IMarker.CHAR_END, region.getOffset() + region.getLength());
			xtendMarker.setAttribute(COPIED_FROM_FILE, javaFile.getFullPath().toString());
		}
	}

}
 
Example 8
Source File: TsvBuilder.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
private void addMarker(final IFile file, String message, int lineNumber, int severity, int priority) throws CoreException {
	final IMarker marker = file.createMarker(TsvBuilder.MARKER_TYPE);
	marker.setAttribute(IMarker.MESSAGE, message);
	marker.setAttribute(IMarker.SEVERITY, severity);
	if (lineNumber == -1) {
		lineNumber = 1;
	}
	marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
	marker.setAttribute(IMarker.PRIORITY, priority);
}
 
Example 9
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 10
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 11
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 12
Source File: ProblemMarkerUpdater.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
protected void createMarker(final Location location, IFile file, ParserError problem) throws CoreException {
	IMarker marker = file.createMarker(LangCore_Actual.SOURCE_PROBLEM_ID);
	marker.setAttribute(IMarker.LOCATION, location.toPathString());
	marker.setAttribute(IMarker.MESSAGE, problem.getUserMessage());
	marker.setAttribute(IMarker.SEVERITY, ToolMarkersHelper.markerSeverityFrom(problem.getSeverity()));
	marker.setAttribute(IMarker.CHAR_START, problem.getStartPos());
	marker.setAttribute(IMarker.CHAR_END, problem.getEndPos());
}
 
Example 13
Source File: AbstractLiveValidationMarkerConstraint.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void addMarker(final DiagramEditor editor, final EditPartViewer viewer, final IFile target,
        final String elementId, final String location, final String message,
        final int statusSeverity) {
    if (target == null) {
        return;
    }
    IMarker marker = null;
    try {
        marker = target.createMarker(getMarkerType(editor));
        marker.setAttribute(IMarker.MESSAGE, message);
        marker.setAttribute(IMarker.LOCATION, location);
        marker.setAttribute(
                org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID,
                elementId);
        marker.setAttribute(CONSTRAINT_ID, getConstraintId());
        int markerSeverity = IMarker.SEVERITY_INFO;
        if (statusSeverity == IStatus.WARNING) {
            markerSeverity = IMarker.SEVERITY_WARNING;
        } else if (statusSeverity == IStatus.ERROR
                || statusSeverity == IStatus.CANCEL) {
            markerSeverity = IMarker.SEVERITY_ERROR;
        }
        marker.setAttribute(IMarker.SEVERITY, markerSeverity);
    } catch (final CoreException e) {
        ProcessDiagramEditorPlugin.getInstance().logError("Failed to create validation marker", e); //$NON-NLS-1$
    }
}
 
Example 14
Source File: MarkerManager.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a bunch of markers in the workspace as the single atomic operation - thus resulting in a single delta
 * @param fileToMarkerInfo
 * @param progressMonitor
 */
public static void commitParserMarkers(final Map<IFileStore, FileMarkerInfo> fileToMarkerInfo, IProgressMonitor progressMonitor) {
	int i = 0;
	
	final IFileStore[] files = new IFileStore[fileToMarkerInfo.size()];
	IFile[] ifiles = new IFile[fileToMarkerInfo.size()];
	
	for (Entry<IFileStore, FileMarkerInfo> keyValue : fileToMarkerInfo.entrySet()) {
		files[i] = keyValue.getKey();
		ifiles[i] = keyValue.getValue().getIFile();
		i++;
	}
	
	ISchedulingRule rule = ResourceUtils.createRule(Arrays.asList(ifiles));
	
	WorkspaceJob job = new WorkspaceJob("Update markers job") { //$NON-NLS-1$
		@Override
		public IStatus runInWorkspace(IProgressMonitor monitor){
			for (int j = 0; j < files.length; j++) {
				FileMarkerInfo fileMarkerInfo = fileToMarkerInfo.get(files[j]);
				if (fileMarkerInfo != null) {
					IFile iFile = fileMarkerInfo.getIFile();
					
					try {
						if (iFile.exists()) {
							Map<Integer, IMarker> offset2BuildMarker = createOffset2BuildMarkerMap(iFile);
							
							MarkerUtils.deleteParserProblemMarkers(iFile, IResource.DEPTH_INFINITE);
							Set<MarkerInfo> parserMarkers = fileMarkerInfo.getParserMarkers();
							for (MarkerInfo parserMarker : parserMarkers) {
								if (offset2BuildMarker.containsKey(parserMarker.getCharStart())) {
									continue;
								}
								IMarker marker = iFile.createMarker(parserMarker.getType());
								marker.setAttributes(parserMarker.getAttributes());
							}
						}
					} catch (CoreException e) {
						LogHelper.logError(e);
					}
				}
			}
			return Status.OK_STATUS;
		}
	};
	job.setRule(rule);
	job.schedule();
}