/** * Tells whether the given marker can be treated as a Java annotation which will later be update * by JDT Core problems. * * @param marker the marker * @return <code>true</code> if the marker can be treated as a Java annotation * @since 3.3.2 */ public static final boolean isJavaAnnotation(IMarker marker) { // Performance String markerType = MarkerUtilities.getMarkerType(marker); if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType) || IJavaModelMarker.TASK_MARKER.equals(markerType) || IJavaModelMarker.TRANSIENT_PROBLEM.equals(markerType) || IJavaModelMarker.BUILDPATH_PROBLEM_MARKER.equals(markerType)) return true; return MarkerUtilities.isMarkerType(marker, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER); }
/** * Corrects the {@link IMarker#CHAR_START} and {@link IMarker#CHAR_END} values as needed * * @param document * @param marker * @param line * @throws BadLocationException */ void ensureRanges(IDocument document, IMarker marker, int line) throws BadLocationException { if (line < 0 || line > document.getNumberOfLines()) { return; } IRegion region = document.getLineInformation(line - 1); int charstart = region.getOffset(); int charend = charstart + region.getLength(); MarkerUtilities.setCharStart(marker, charstart); MarkerUtilities.setCharEnd(marker, charend); }
/** * Adds a new quickmark in the active editor. If the same quickmark number already exists (in the * workspace), the existing quickmark is replaced with the new (i.e. the quickmark is moved). If * the same quickmark already exists in the same location, the quickmark is removed. * * @param quickmarkNumber */ private void addBookmark(int quickmarkNumber) { ITextEditor editor = getActiveEditor(); if (editor != null) { Integer key = new Integer(quickmarkNumber); Map attributes = new HashMap(); ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); int charStart = selection.getOffset(); int charEnd = charStart; MarkerUtilities.setCharStart(attributes, charStart); MarkerUtilities.setCharEnd(attributes, charEnd); IFile file = getActiveFile(); String message = MessageFormat.format( Messages.getString("SetQuickmarkAction.quickmarkMessage"), new Object[] {key}); // $NON-NLS-1$ MarkerUtilities.setMessage(attributes, message); attributes.put(QuickmarksPlugin.NUMBER, key); attributes.put(QuickmarksPlugin.FILE, file); boolean OK = true; Map markers = getMarkers(); if (markers.containsKey(key)) { IMarker marker = (IMarker) markers.get(key); try { Integer markerCharStart = (Integer) marker.getAttribute(IMarker.CHAR_START); Integer markerCharEnd = (Integer) marker.getAttribute(IMarker.CHAR_END); if (markerCharStart != null && markerCharStart.intValue() == charStart && markerCharEnd != null && markerCharEnd.intValue() == charEnd) { OK = false; } marker.delete(); } catch (CoreException e) { QuickmarksPlugin.debug(e); } } if (OK) { try { MarkerUtilities.createMarker(file, attributes, getMarkerType()); } catch (Exception e) { QuickmarksPlugin.log(e); } } } }
private void assertNoErrors(final IFile file) { try { final IMarker[] findMarkers = file.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); for (final IMarker iMarker : findMarkers) { String _message = MarkerUtilities.getMessage(iMarker); int _severity = MarkerUtilities.getSeverity(iMarker); boolean _equals = (_severity == IMarker.SEVERITY_ERROR); Assert.assertFalse(_message, _equals); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
private static boolean internalHasResolutions(IMarker marker) { ErrorCode id = new DartMarkerAnnotation(marker).getId(); CompilationUnit cu = getCompilationUnit(marker); return cu != null && DartCorrectionProcessor_OLD.hasCorrections( cu, id, MarkerUtilities.getMarkerType(marker)); }
/* * (non-Javadoc) * * @see * org.eclipse.ui.texteditor.IMarkerUpdater#updateMarker(org.eclipse.core * .resources.IMarker, org.eclipse.jface.text.IDocument, * org.eclipse.jface.text.Position) */ public boolean updateMarker( final IMarker marker, final IDocument document, final Position position) { if (position.isDeleted()) { return false; } try { final int line = MarkerUtilities.getLineNumber(marker); final int newLine = document.getLineOfOffset(position.getOffset()) + 1; if (line == newLine) { return true; } final IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); final IBreakpoint breakpoint = manager.getBreakpoint(marker); if (breakpoint == null) { return false; } if (breakpoint instanceof ErlangLineBreakpoint) { final ErlangLineBreakpoint erlangLineBreakpoint = (ErlangLineBreakpoint) breakpoint; final ErlangDebugTarget target = erlangLineBreakpoint.getTarget(); erlangLineBreakpoint.remove(target); MarkerUtilities.setLineNumber(marker, newLine); erlangLineBreakpoint.install(target); return true; } // if there exists a breakpoint on the line remove this one if (isLineBreakpointMarker(marker)) { ensureRanges(document, marker, line); return lineBreakpointExists(marker.getResource(), line, marker) == null; } // if the line info is a valid location with an invalid line // number, // a line breakpoint must be removed if (isLineBreakpointMarker(marker) && line == -1) { return false; } MarkerUtilities.setLineNumber(marker, line); if (isLineBreakpointMarker(marker)) { ensureRanges(document, marker, line); } return true; } catch (final BadLocationException e) { ErlLogger.error(e); } catch (final CoreException e) { ErlLogger.error(e); } return false; }
@Override public boolean select(Viewer viewer, Object parentElem, Object elem) { IMarker marker = (IMarker) elem; if (MarkerUtilities.getSeverity(marker) == severityToPermit) return ErrorWarningFilterAction.this.isChecked(); // Allow only if button pushed else return true; // We're not interested in this marker; let another filter handle it }
private void createCustomMarkerOnResource(IResource resource, int severenity) throws CoreException { HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put(IMarker.MESSAGE, CUSTOM_MARKER_TEST_MESSAGE); attributes.put(IMarker.LINE_NUMBER, 1); attributes.put(IMarker.LOCATION, resource.getFullPath().toPortableString()); attributes.put(IMarker.SEVERITY, severenity); MarkerUtilities.createMarker(resource, attributes, CUSTOM_MARKER_ID); }
@Override public void executeCommand() throws BadLocationException, CoreException { List<IMarker> bookmarks = getCurrentEditorBookmarks(); if (bookmarks.isEmpty()) { setTimedErrorMessage("There are no bookmarks in File to delete!"); return; } for (IMarker marker : bookmarks) { getEditor().getDeleteLine(MarkerUtilities.getLineNumber(marker) - 1); marker.delete(); } }
/* (non-Javadoc) * @see org.eclipse.ui.texteditor.IMarkerUpdater#updateMarker(org.eclipse.core.resources.IMarker, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.Position) */ public boolean updateMarker(IMarker marker, IDocument document, Position position) { if (position.isDeleted()) { return false; } IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); IBreakpoint breakpoint = manager.getBreakpoint(marker); if (breakpoint == null) { return false; } IFile file = (IFile) marker.getResource(); if (JavaScriptCore.isJavaScriptLikeFileName(file.getName())) { IJavaScriptUnit unit = JavaScriptCore.createCompilationUnitFrom(file); if (unit == null) { return false; } JavaScriptUnit jsunit = JavaScriptPlugin.getDefault().getASTProvider().getAST(unit, ASTProvider.WAIT_YES, null); try { BreakpointLocationFinder finder = new BreakpointLocationFinder( jsunit, document.getLineOfOffset(position.getOffset()) + 1, true); jsunit.accept(finder); if (finder.getLocation() == BreakpointLocationFinder.UNKNOWN) { return false; } int line = finder.getLineNumber(); if (MarkerUtilities.getLineNumber(marker) == line) { // if there exists a breakpoint on the line remove this one if (isLineBreakpoint(marker)) { ensureRanges(document, marker, line); return lineBreakpointExists( marker.getResource(), ((IJavaScriptLineBreakpoint) breakpoint).getScriptPath(), line, marker, true) == null; } return true; } if (isLineBreakpoint(marker) & line == -1) { return false; } if (lineBreakpointExists( marker.getResource(), ((IJavaScriptLineBreakpoint) breakpoint).getScriptPath(), line, marker, false) != null) { return false; } MarkerUtilities.setLineNumber(marker, line); if (isLineBreakpoint(marker)) { ensureRanges(document, marker, line); } return true; } catch (BadLocationException ble) { JavaScriptDebugUIPlugin.log(ble); } catch (CoreException e) { JavaScriptDebugUIPlugin.log(e); } } return true; }
/** * Returns if the given marker is of the type {@link IJavaScriptLineBreakpoint#MARKER_ID} * * @param marker * @return true if the marker is a {@link IJavaScriptLineBreakpoint} marker */ boolean isLineBreakpoint(IMarker marker) { return MarkerUtilities.isMarkerType(marker, IJavaScriptLineBreakpoint.MARKER_ID); }
/* * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getMarkerType() */ public String getMarkerType() { IMarker marker = getMarker(); if (marker == null || !marker.exists()) return null; return MarkerUtilities.getMarkerType(getMarker()); }