/** * Propagates the given marker to the given source line * * @param marker The marker to propagate * @param file The features file * @param line The marker line at the features file */ protected void propagateMarker(IMarker marker, IFile file, int line) { if (file != null && file.exists()) { Object severity = null; String message = marker.getAttribute(IMarker.MESSAGE, NO_ATTRIBUTE); if (NO_ATTRIBUTE.equals(message)) { return; } try { severity = marker.getAttribute(IMarker.SEVERITY); } catch (CoreException e) { severity = IMarker.SEVERITY_ERROR; } if (!hasSameMarker(message, line, file)) { IMarker newMarker = null; try { newMarker = file.createMarker(FeatureHouseCorePlugin.BUILDER_PROBLEM_MARKER); newMarker.setAttribute(IMarker.LINE_NUMBER, line); newMarker.setAttribute(IMarker.MESSAGE, message); newMarker.setAttribute(IMarker.SEVERITY, severity); } catch (CoreException e) { FeatureHouseCorePlugin.getDefault().logError(e); } } } }
IMarker createMarkerFromSearchMatch(IFile file, SearchMatch match) { IMarker marker = null; try { if (CHOICE_METHOD_DECLARATION.equals(mChoice)) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put(IMarker.CHAR_START, new Integer(match.getOffset())); map.put(IMarker.CHAR_END, new Integer(match.getOffset() + match.getLength())); marker = file.createMarker(IMarker.TEXT); marker.setAttributes(map); } else if (CHOICE_ERROR_LINE.equals(mChoice)) { marker = file.createMarker(IMarker.TEXT); marker.setAttribute(IMarker.LINE_NUMBER, mLineNumber); } } catch (CoreException e) { Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e); DdmsPlugin.getDefault().getLog().log(s); } return marker; }
private static void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException { try { IMarker marker = file.createMarker(NewSearchUI.SEARCH_MARKER); HashMap attributes = new HashMap(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) { } }
@Override public void handleError(IStatus status) { try { IMarker m = file.createMarker(IMarker.PROBLEM); // m.setAttribute(IMarker.LINE_NUMBER, line); m.setAttribute(IMarker.MESSAGE, status.toString()); m.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH); m.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); } catch (CoreException e) { // an error while marking an error, lets throw it throw new RuntimeException(e); } }
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(); }
void doHandleErrorsJob(Task[] errors, IFile file) { synchronized (this) // prevent simultaneous error updates on the same file { if (ResourcesPlugin.getWorkspace().isTreeLocked()) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error updating the document errors. The workspace tree is locked.", PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ } if (file == null || !file.exists()) { return; } int depth = IResource.DEPTH_INFINITE; try { IMarker[] problemMarkers = file.findMarkers(IMarker.TASK, true, depth); for (IMarker m : problemMarkers) { Object attribute2 = m.getAttribute(APTANA_TASK); if (attribute2 != null && attribute2.equals("true")) // $NON-NLS-1$ { m.delete(); } } for (Task t : errors) { IMarker problemMarker = file.createMarker(IMarker.TASK); problemMarker.setAttribute(IMarker.PRIORITY, t.getPriority()); problemMarker.setAttribute(IMarker.CHAR_START, t.getStart()); problemMarker.setAttribute(IMarker.CHAR_END, t.getEnd()); problemMarker.setAttribute(APTANA_TASK, Boolean.TRUE.toString()); problemMarker.setAttribute(IMarker.MESSAGE, t.getDescription()); problemMarker.setAttribute(IMarker.LINE_NUMBER, t.getLineNumber()); } } catch (Exception e) { IdeLog.logWarning( PHPEditorPlugin.getDefault(), "Error updating the PHP task-tags.", e, PHPEditorPlugin.DEBUG_SCOPE); // $NON-NLS-1$ } } }
public IMarker createMarker(IFile file, String severityPreference) { IMarker marker = null; try { marker = _htmlFile.createMarker(Activator.TEMPLATE_PROBLEM_MARKER); marker.setAttribute(IMarker.MESSAGE, getMessage()); int severity; if (isWarning() || PreferenceConstants.WARNING.equals(severityPreference)) { severity = IMarker.SEVERITY_WARNING; } else { severity = IMarker.SEVERITY_ERROR; } marker.setAttribute(IMarker.SEVERITY, new Integer(severity)); marker.setAttribute(IMarker.LINE_NUMBER, _lineNumber); marker.setAttribute(IMarker.CHAR_START, _position.getOffset()); marker.setAttribute(IMarker.CHAR_END, _position.getOffset() + _position.getLength()); marker.setAttribute(IMarker.TRANSIENT, false); } catch (CoreException e) { Activator.getDefault().log(e); } return marker; }
private static void createMarkers(final Map<String, List<Diagnostic>> diagnostics) throws CoreException { for (Map.Entry<String, List<Diagnostic>> entry : diagnostics.entrySet()) { String fileName = entry.getKey(); // ignore the default library if (fileName.equals("lib.d.ts")) { continue; } // create the markers for this file Path path = new Path(fileName); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); List<Diagnostic> fileDiagnostics = entry.getValue(); for (Diagnostic diagnostic : fileDiagnostics) { IMarker marker = file.createMarker(MARKER_TYPE); Map<String, Object> attributes = createMarkerAttributes(diagnostic); marker.setAttributes(attributes); } } }
/** @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) { UMLDiagramEditorPlugin.getInstance() .logError("Failed to create validation marker", e); // $NON-NLS-1$ } return marker; }
public static IMarker createMarker(IFile file, IDocument document, IRegion region) { String waypointDefinition; try { waypointDefinition = document.get(region.getOffset(), region.getLength()); } catch (BadLocationException e) { e.printStackTrace(); return null; } IMarker marker; try { marker = file.createMarker(JavaWaypoint.MARKER_ID); marker.setAttribute(IMarker.MESSAGE, waypointDefinition); marker.setAttribute(IMarker.CHAR_START, region.getOffset()); marker.setAttribute(IMarker.CHAR_END, region.getOffset() + region.getLength()); } catch (CoreException e) { e.printStackTrace(); return null; } return marker; }
/** * Utility to add a problem marker to a file. * * @param file: the file to be marked * @param message: the text describing the problem * @param severity: the severity code (see <code>IMarker</code>). * @throws CoreException */ public static IMarker addMarker(IFile file, String message, int severity) throws CoreException { IMarker marker = file.createMarker(MARKER_TYPE); marker.setAttribute(IMarker.MESSAGE, message); marker.setAttribute(IMarker.SEVERITY, severity); return marker; }
void performValidation(IFile f, IReporter reporter, IStructuredModel model, boolean inBatch) { if (model instanceof IDOMModel) { IDOMModel domModel = (IDOMModel) model; JsTranslationAdapterFactory.setupAdapterFactory(domModel); IDOMDocument xmlDoc = domModel.getDocument(); JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class); // translationAdapter.resourceChanged(); IJsTranslation translation = translationAdapter.getJsTranslation(false); if (!reporter.isCancelled()) { translation.setProblemCollectingActive(true); translation.reconcileCompilationUnit(); List problems = translation.getProblems(); // only update task markers if the model is the same as what's on disk boolean updateTasks = !domModel.isDirty() && f != null && f.isAccessible(); if (updateTasks) { // remove old JavaScript task markers try { IMarker[] foundMarkers = f.findMarkers(JAVASCRIPT_TASK_MARKER_TYPE, true, IResource.DEPTH_ONE); for (int i = 0; i < foundMarkers.length; i++) { foundMarkers[i].delete(); } } catch (CoreException e) { Logger.logException(e); } } // if(!inBatch) reporter.removeAllMessages(this, f); // add new messages for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) { IProblem problem = (IProblem) problems.get(i); IMessage m = createMessageFromProblem(problem, f, translation, domModel.getStructuredDocument()); if (m != null) { if (problem.getID() == IProblem.Task) { if (updateTasks) { // add new JavaScript task marker try { IMarker task = f.createMarker(JAVASCRIPT_TASK_MARKER_TYPE); task.setAttribute(IMarker.LINE_NUMBER, new Integer(m.getLineNumber())); task.setAttribute(IMarker.CHAR_START, new Integer(m.getOffset())); task.setAttribute(IMarker.CHAR_END, new Integer(m.getOffset() + m.getLength())); task.setAttribute(IMarker.MESSAGE, m.getText()); task.setAttribute(IMarker.USER_EDITABLE, Boolean.FALSE); switch (m.getSeverity()) { case IMessage.HIGH_SEVERITY: { task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH)); task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); } break; case IMessage.LOW_SEVERITY: { task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_LOW)); task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); } break; default: { task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_NORMAL)); task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); } } } catch (CoreException e) { Logger.logException(e); } } } else { reporter.addMessage(fMessageOriginator, m); } } } } } }
private void markError( DiagnosticCollector<JavaFileObject> diagnosticsCollector, boolean markerCreation) { for (Diagnostic diagnostic : diagnosticsCollector.getDiagnostics()) { System.out.format("Error on line %d" + " -> ", diagnostic.getLineNumber(), diagnostic); System.out.println(diagnostic.getMessage(null) + "\n"); System.err.println("*** " + diagnostic.toString() + " *** " + diagnostic.getCode()); JavaFileObject source = (JavaFileObject) diagnostic.getSource(); String longFileName = source == null ? null : source.toUri().getPath(); // String shortFileName = source == null ? null : source.getName(); // System.out.println("Error in: " + longFileName); // Path path = new Path(longFileName); // IFile ifile = // ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (diagnostic.getLineNumber() > -1) { File fileToOpen = new File(longFileName); if (fileToOpen.exists() && fileToOpen.isFile()) { final IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI()); Display display = PlatformUI.getWorkbench().getDisplay(); display.syncExec( new Runnable() { public void run() { try { IEditorPart part = IDE.openEditorOnFileStore(pag, fileStore); if (part != null) { IEditorInput input = part.getEditorInput(); ifile = ((IFileEditorInput) input).getFile(); // ... use activeProjectName } } catch (PartInitException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } else { // Do something if the file does not exist } } // System.out.format("Error on line %d in %s"+"\n", // diagnostic.getLineNumber(), diagnostic); if (markerCreation == true) { int lnr = (int) diagnostic.getLineNumber(); int startPos = (int) diagnostic.getStartPosition(); int stopPos = (int) diagnostic.getEndPosition(); if (ifile != null) { IMarker marker; try { marker = ifile.createMarker(IMarker.PROBLEM); marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); marker.setAttribute(IMarker.MESSAGE, diagnostic.getMessage(null)); marker.setAttribute(IMarker.LINE_NUMBER, lnr); // if (pos.offset != 0) { // System.out.println(startPos); // System.out.println(stopPos); marker.setAttribute(IMarker.CHAR_START, startPos); marker.setAttribute(IMarker.CHAR_END, stopPos - 1); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
public IMarker createMarker(IFile file, int id, String category) throws CoreException { IMarker marker = file.createMarker(MARKER_ID); marker.setAttribute("id", id); // $NON-NLS-1$ marker.setAttribute(CAT_ID, category); return marker; }