Java Code Examples for org.eclipse.core.resources.IMarker#getAttribute()
The following examples show how to use
org.eclipse.core.resources.IMarker#getAttribute() .
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: OrganizeImports.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * @return the markers representing undefined variables found in the editor. */ private ArrayList<MarkerAnnotationAndPosition> getUndefinedVariableMarkers(final PyEdit edit) { PySourceViewer s = edit.getPySourceViewer(); ArrayList<MarkerAnnotationAndPosition> undefinedVariablesMarkers = new ArrayList<MarkerAnnotationAndPosition>(); //get the markers we are interested in (undefined variables) for (Iterator<MarkerAnnotationAndPosition> it = s.getMarkerIterator(); it.hasNext();) { MarkerAnnotationAndPosition m = it.next(); IMarker marker = m.markerAnnotation.getMarker(); try { String type = marker.getType(); if (type != null && type.equals(AnalysisRunner.PYDEV_ANALYSIS_PROBLEM_MARKER)) { Integer attribute = marker.getAttribute(AnalysisRunner.PYDEV_ANALYSIS_TYPE, -1); if (attribute != null && attribute.equals(IAnalysisPreferences.TYPE_UNDEFINED_VARIABLE)) { undefinedVariablesMarkers.add(m); } } } catch (Exception e) { Log.log(e); } } return undefinedVariablesMarkers; }
Example 2
Source File: CreateStatsJob.java From eclipse-cs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns the standard, untranslated message for a Checkstyle violation * marker. * * @param marker * the marker * @return the untranslated message * @throws CoreException * error accessing marker attributes */ public static String getUnlocalizedMessage(IMarker marker) throws CoreException { String key = (String) marker.getAttribute(CheckstyleMarker.MESSAGE_KEY); String moduleInternalName = (String) marker.getAttribute(CheckstyleMarker.MODULE_NAME); String standardMessage = MetadataFactory.getStandardMessage(key, moduleInternalName); if (standardMessage == null) { standardMessage = (String) marker.getAttribute(IMarker.MESSAGE); } return standardMessage; }
Example 3
Source File: MarkerUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public static Integer getCharStart(IMarker marker) { Integer charStart = marker.getAttribute(IMarker.CHAR_START, -1); if (charStart == -1) { charStart = null; } return charStart; }
Example 4
Source File: SCTBuilder.java From statecharts with Eclipse Public License 1.0 | 5 votes |
private boolean hasError(IResource resource) { IMarker[] findMarkers = null; try { findMarkers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); for (IMarker iMarker : findMarkers) { Integer attribute = (Integer) iMarker.getAttribute(IMarker.SEVERITY); if (attribute.intValue() == IMarker.SEVERITY_ERROR) { return true; } } } catch (CoreException e) { e.printStackTrace(); } return false; }
Example 5
Source File: SuppressWarningFix.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
/** * This method adds a new entry to the SuppressWarnings.xml file * * @param m ErrorMarker * @throws CoreException * @throws IOException */ public void createSuppressWarningEntry(final IMarker m) throws CoreException, IOException { final int id = (int) m.getAttribute(IMarker.SOURCE_ID); final String ressource = m.getResource().getName(); final int lineNumber = (int) m.getAttribute(IMarker.LINE_NUMBER); final String message = (String) m.getAttribute(IMarker.MESSAGE); final Element warningEntry = this.xmlParser.createChildElement(this.xmlParser.getRoot(), Constants.SUPPRESSWARNING_ELEMENT); this.xmlParser.createAttrForElement(warningEntry, Constants.ID_ATTR, String.valueOf(id)); this.xmlParser.createChildElement(warningEntry, Constants.FILE_ELEMENT, ressource); this.xmlParser.createChildElement(warningEntry, Constants.LINENUMBER_ELEMENT, String.valueOf(lineNumber)); this.xmlParser.createChildElement(warningEntry, Constants.MESSAGE_ELEMENT, message); }
Example 6
Source File: QuickFixes.java From yang-design-studio with Eclipse Public License 1.0 | 5 votes |
public IMarkerResolution[] getResolutions(IMarker mk) { try { Object problem = mk.getAttribute("WhatsUp"); return new IMarkerResolution[] { new Quick("Fix #1 for "+problem), new Quick("Fix #2 for "+problem), }; } catch (CoreException e) { return new IMarkerResolution[0]; } }
Example 7
Source File: JavaSCTGeneratorTest.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@Test public void testCompileStatechart() throws Exception { IMarker[] marker = generateAndCompile(statechart); for (IMarker diagnostic : marker) { int severity = (Integer) diagnostic.getAttribute("severity"); if (severity == IMarker.SEVERITY_ERROR) { Assert.fail("Unable to compile '" + statechart.getName() + "': " + diagnostic.getAttribute(IMarker.MESSAGE, "")); } } }
Example 8
Source File: TLAAnnotationHover.java From tlaplus with MIT License | 5 votes |
private String[] getMessagesForLine(final ISourceViewer viewer, final int line) { final IAnnotationModel model = viewer.getAnnotationModel(); if (model == null) { return new String[0]; } final Iterator<Annotation> it = model.getAnnotationIterator(); final IDocument document = viewer.getDocument(); final ArrayList<String> messages = new ArrayList<>(); final HashMap<Position, Set<String>> placeMessagesMap = new HashMap<>(); while (it.hasNext()) { final Annotation annotation = it.next(); if (annotation instanceof MarkerAnnotation) { final MarkerAnnotation ma = (MarkerAnnotation) annotation; final Position p = model.getPosition(ma); if (compareRulerLine(p, document, line)) { final IMarker marker = ma.getMarker(); final String message = marker.getAttribute(IMarker.MESSAGE, null); if ((message != null) && (message.trim().length() > 0)) { Set<String> priorMessages = placeMessagesMap.get(p); if (priorMessages == null) { priorMessages = new HashSet<>(); placeMessagesMap.put(p, priorMessages); } if (!priorMessages.contains(message)) { messages.add(message); priorMessages.add(message); } } } } } return (String[]) messages.toArray(new String[messages.size()]); }
Example 9
Source File: WorkspaceDiagnosticsHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * @param marker * @return */ private static Range convertRange(IDocument document, IMarker marker) { int line = marker.getAttribute(IMarker.LINE_NUMBER, -1) - 1; if (line < 0) { int end = marker.getAttribute(IMarker.CHAR_END, -1); int start = marker.getAttribute(IMarker.CHAR_START, -1); if (start >= 0 && end >= start) { int[] startPos = JsonRpcHelpers.toLine(document, start); int[] endPos = JsonRpcHelpers.toLine(document, end); return new Range(new Position(startPos[0], startPos[1]), new Position(endPos[0], endPos[1])); } return new Range(new Position(0, 0), new Position(0, 0)); } int cStart = 0; int cEnd = 0; try { //Buildship doesn't provide markers for gradle files, Maven does if (marker.isSubtypeOf(IMavenConstants.MARKER_ID)) { cStart = marker.getAttribute(IMavenConstants.MARKER_COLUMN_START, -1); cEnd = marker.getAttribute(IMavenConstants.MARKER_COLUMN_END, -1); } else { int lineOffset = 0; try { lineOffset = document.getLineOffset(line); } catch (BadLocationException unlikelyException) { JavaLanguageServerPlugin.logException(unlikelyException.getMessage(), unlikelyException); return new Range(new Position(line, 0), new Position(line, 0)); } cEnd = marker.getAttribute(IMarker.CHAR_END, -1) - lineOffset; cStart = marker.getAttribute(IMarker.CHAR_START, -1) - lineOffset; } } catch (CoreException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } cStart = Math.max(0, cStart); cEnd = Math.max(0, cEnd); return new Range(new Position(line, cStart), new Position(line, cEnd)); }
Example 10
Source File: CheckstyleMarkerFilter.java From eclipse-cs with GNU Lesser General Public License v2.1 | 5 votes |
/** * Selects markers by its severity. * * @param item * the marker * @return <code>true</code> if the marker is selected */ private boolean selectBySeverity(IMarker item) { if (mSelectBySeverity) { int markerSeverity = item.getAttribute(IMarker.SEVERITY, -1); if (markerSeverity == IMarker.SEVERITY_ERROR) { return (mSeverity & SEVERITY_ERROR) > 0; } else if (markerSeverity == IMarker.SEVERITY_WARNING) { return (mSeverity & SEVERITY_WARNING) > 0; } else if (markerSeverity == IMarker.SEVERITY_INFO) { return (mSeverity & SEVERITY_INFO) > 0; } } return true; }
Example 11
Source File: EditorUtil.java From tlaplus with MIT License | 5 votes |
/** * Returns true iff the module has been set to read only using * the method {@link EditorUtil#setReadOnly(IResource, boolean)}. * * @param module * @return * @throws CoreException */ public static boolean isReadOnly(IResource module) { try { if (module.exists()) { IMarker marker; // Try to find any existing markers. IMarker[] foundMarkers = module.findMarkers(READ_ONLY_MODULE_MARKER, false, IResource.DEPTH_ZERO); // There should only be one such marker at most. // In case there is more than one existing marker, // remove extra markers. if (foundMarkers.length > 0) { marker = foundMarkers[0]; // remove trash if any for (int i = 1; i < foundMarkers.length; i++) { foundMarkers[i].delete(); } return marker.getAttribute(IS_READ_ONLY_ATR, false); } else { return false; } } else { return false; } } catch (CoreException e) { Activator.getDefault().logError("Error determining if module " + module + " is read only.", e); } return false; }
Example 12
Source File: DerivedResourceMarkerCopier.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
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 13
Source File: AbstractASTResolution.java From eclipse-cs with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ @Override public boolean canFix(IMarker marker) { String moduleName = marker.getAttribute(CheckstyleMarker.MODULE_NAME, null); try { return CheckstyleMarker.MARKER_ID.equals(marker.getType()) && (mMetaData.getInternalName().equals(moduleName) || mMetaData.getAlternativeNames().contains(moduleName)); } catch (CoreException e) { throw new IllegalStateException(e); } }
Example 14
Source File: UndefinedVariableFixParticipant.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * @see IAnalysisMarkersParticipant#addProps(MarkerAnnotation, IAnalysisPreferences, String, PySelection, int, IPythonNature, * PyEdit, List) * */ @Override public void addProps(MarkerAnnotationAndPosition markerAnnotation, IAnalysisPreferences analysisPreferences, String line, PySelection ps, int offset, IPythonNature initialNature, PyEdit edit, List<ICompletionProposalHandle> props) throws BadLocationException, CoreException { IMarker marker = markerAnnotation.markerAnnotation.getMarker(); Integer id = (Integer) marker.getAttribute(AnalysisRunner.PYDEV_ANALYSIS_TYPE); if (id != IAnalysisPreferences.TYPE_UNDEFINED_VARIABLE) { return; } if (initialNature == null) { return; } ICodeCompletionASTManager astManager = initialNature.getAstManager(); if (astManager == null) { return; } if (markerAnnotation.position == null) { return; } int start = markerAnnotation.position.offset; int end = start + markerAnnotation.position.length; UndefinedVariableQuickFixCreator.createImportQuickProposalsFromMarkerSelectedText(ps, offset, initialNature, props, astManager, start, end, forceReparseOnApply); }
Example 15
Source File: ReviewMarkerContributionFactory.java From git-appraise-eclipse with Eclipse Public License 1.0 | 4 votes |
private boolean markerHasBeenClicked(IMarker marker, IVerticalRulerInfo rulerInfo) { return (marker.getAttribute(IMarker.LINE_NUMBER, 0)) == (rulerInfo.getLineOfLastMouseButtonActivity() + 1); }
Example 16
Source File: ResourceUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public static String getMessage(IMarker marker) { if (marker == null) { return null; } return marker.getAttribute(IMarker.MESSAGE, null); }
Example 17
Source File: MarkerUtil.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
/** * @param marker marker to check for plugin id * @return detector plugin id, or empty string if the detector plugin is unknown */ @Nonnull public static String getPluginId(@Nonnull IMarker marker) { return marker.getAttribute(FindBugsMarker.DETECTOR_PLUGIN_ID, ""); }
Example 18
Source File: JavaHotCodeReplaceProvider.java From java-debug with Eclipse Public License 1.0 | 4 votes |
/** * Answers whether children should be visited. * <p> * If the associated resource is a class file which has been changed, record it. * </p> */ @Override public boolean visit(IResourceDelta delta) { if (delta == null || 0 == (delta.getKind() & IResourceDelta.CHANGED)) { return false; } IResource resource = delta.getResource(); if (resource != null) { switch (resource.getType()) { case IResource.FILE: if (0 == (delta.getFlags() & IResourceDelta.CONTENT)) { return false; } if (CLASS_FILE_EXTENSION.equals(resource.getFullPath().getFileExtension())) { IPath localLocation = resource.getLocation(); if (localLocation != null) { String path = localLocation.toOSString(); IClassFileReader reader = ToolFactory.createDefaultClassFileReader(path, IClassFileReader.CLASSFILE_ATTRIBUTES); if (reader != null) { // this name is slash-delimited String qualifiedName = new String(reader.getClassName()); boolean hasBlockingErrors = false; try { // If the user doesn't want to replace // classfiles containing // compilation errors, get the source // file associated with // the class file and query it for // compilation errors IJavaProject pro = JavaCore.create(resource.getProject()); ISourceAttribute sourceAttribute = reader.getSourceFileAttribute(); String sourceName = null; if (sourceAttribute != null) { sourceName = new String(sourceAttribute.getSourceFileName()); } IResource sourceFile = getSourceFile(pro, qualifiedName, sourceName); if (sourceFile != null) { IMarker[] problemMarkers = null; problemMarkers = sourceFile.findMarkers( IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); for (IMarker problemMarker : problemMarkers) { if (problemMarker.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR) { hasBlockingErrors = true; break; } } } } catch (CoreException e) { logger.log(Level.SEVERE, "Failed to visit classes: " + e.getMessage(), e); } if (!hasBlockingErrors) { changedFiles.add(resource); // dot-delimit the name fullyQualifiedNames.add(qualifiedName.replace('/', '.')); } } } } return false; default: return true; } } return true; }
Example 19
Source File: MultiQuickFixTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Test public void testFixSingleMarker() throws Exception { StringConcatenation _builder = new StringConcatenation(); _builder.append("\"no doc\""); _builder.newLine(); _builder.append("Foo { ref Bor }"); _builder.newLine(); _builder.append("\"no doc\" Bor { }"); _builder.newLine(); final IFile resource = this.dslFile(_builder); final IMarker[] markers = this.getMarkers(resource); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("<0<\"no doc\">0>"); _builder_1.newLine(); _builder_1.append("Foo { ref Bor }"); _builder_1.newLine(); _builder_1.append("<1<\"no doc\">1> Bor { }"); _builder_1.newLine(); _builder_1.append("----------------------"); _builder_1.newLine(); _builder_1.append("0: message=multiFixableIssue"); _builder_1.newLine(); _builder_1.append("1: message=multiFixableIssue"); _builder_1.newLine(); this.assertContentsAndMarkers(resource, markers, _builder_1); final Function1<IMarker, Integer> _function = (IMarker it) -> { try { Object _attribute = it.getAttribute(IMarker.CHAR_START); return ((Integer) _attribute); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; final IMarker firstMarker = IterableExtensions.<IMarker>head(IterableExtensions.<IMarker, Integer>sortBy(((Iterable<IMarker>)Conversions.doWrapArray(markers)), _function)); this.applyQuickfixOnSingleMarkers(firstMarker); StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append("\"Better documentation\""); _builder_2.newLine(); _builder_2.append("Foo { ref Bor }"); _builder_2.newLine(); _builder_2.append("<0<\"no doc\">0> Bor { }"); _builder_2.newLine(); _builder_2.append("----------------------"); _builder_2.newLine(); _builder_2.append("0: message=multiFixableIssue"); _builder_2.newLine(); this.assertContentsAndMarkers(resource, _builder_2); }
Example 20
Source File: MarkerUtil.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
/** * Find the BugCollectionAndInstance associated with given FindBugs marker. * * @param marker * a FindBugs marker * @return the BugInstance associated with the marker, or null if we can't * find the BugInstance */ public static @CheckForNull BugCollectionAndInstance findBugCollectionAndInstanceForMarker(IMarker marker) { IResource resource = marker.getResource(); IProject project = resource.getProject(); if (project == null) { // Also shouldn't happen. FindbugsPlugin.getDefault().logError("No project for warning marker"); return null; } if (!isFindBugsMarker(marker)) { // log disabled because otherwise each selection in problems view // generates // 6 new errors (we need refactor all bug views to get rid of this). // FindbugsPlugin.getDefault().logError("Selected marker is not a FindBugs marker"); // FindbugsPlugin.getDefault().logError(marker.getType()); // FindbugsPlugin.getDefault().logError(FindBugsMarker.NAME); return null; } // We have a FindBugs marker. Get the corresponding BugInstance. String bugId = marker.getAttribute(FindBugsMarker.UNIQUE_ID, null); if (bugId == null) { FindbugsPlugin.getDefault().logError("Marker does not contain unique id for warning"); return null; } try { BugCollection bugCollection = FindbugsPlugin.getBugCollection(project, null); if (bugCollection == null) { FindbugsPlugin.getDefault().logError("Could not get BugCollection for SpotBugs marker"); return null; } String bugType = (String) marker.getAttribute(FindBugsMarker.BUG_TYPE); Integer primaryLineNumber = (Integer) marker.getAttribute(FindBugsMarker.PRIMARY_LINE); // compatibility if (primaryLineNumber == null) { primaryLineNumber = Integer.valueOf(getEditorLine(marker)); } if (bugType == null) { FindbugsPlugin.getDefault().logError( "Could not get find attributes for marker " + marker + ": (" + bugId + ", " + primaryLineNumber + ")"); return null; } BugInstance bug = bugCollection.findBug(bugId, bugType, primaryLineNumber.intValue()); if (bug == null) { FindbugsPlugin.getDefault().logError( "Could not get find bug for marker on " + resource + ": (" + bugId + ", " + primaryLineNumber + ")"); return null; } return new BugCollectionAndInstance(bugCollection, bug); } catch (CoreException e) { FindbugsPlugin.getDefault().logException(e, "Could not get BugInstance for SpotBugs marker"); return null; } }