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

The following examples show how to use org.eclipse.core.resources.IMarker#getType() . 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: CorrectionMarkerResolutionGenerator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IProblemLocation createFromMarker(IMarker marker, ICompilationUnit cu) {
	try {
		int id= marker.getAttribute(IJavaModelMarker.ID, -1);
		int start= marker.getAttribute(IMarker.CHAR_START, -1);
		int end= marker.getAttribute(IMarker.CHAR_END, -1);
		int severity= marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
		String[] arguments= CorrectionEngine.getProblemArguments(marker);
		String markerType= marker.getType();
		if (cu != null && id != -1 && start != -1 && end != -1 && arguments != null) {
			boolean isError= (severity == IMarker.SEVERITY_ERROR);
			return new ProblemLocation(start, end - start, id, arguments, isError, markerType);
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example 2
Source File: OrganizeImports.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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 3
Source File: CrossflowValidationDecoratorProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
private String getType(IMarker marker) {
	try {
		return marker.getType();
	} catch (CoreException e) {
		CrossflowDiagramEditorPlugin.getInstance().logError("Validation marker refresh failure", e); //$NON-NLS-1$
		return ""; //$NON-NLS-1$
	}
}
 
Example 4
Source File: BugResolution.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@CheckForNull
private PendingRewrite resolveWithoutWriting(IMarker marker) {
    requireNonNull(marker, "marker");
    ICompilationUnit originalUnit = null;
    try {
        BugInstance bug = MarkerUtil.findBugInstanceForMarker(marker);
        if (bug == null) {
            throw new BugResolutionException(MISSING_BUG_INSTANCE);
        }

        IProject project = marker.getResource().getProject();
        originalUnit = getCompilationUnit(marker);
        if (originalUnit == null) {
            throw new BugResolutionException("No compilation unit found for marker " + marker.getType() + " ("
                    + marker.getId() + ')');
        }

        Document doc = new Document(originalUnit.getBuffer().getContents());
        CompilationUnit workingUnit = makeOrReuseWorkingCopy(originalUnit);

        ASTRewrite rewrite = makeOrReuseRewrite(workingUnit);

        repairBug(rewrite, workingUnit, bug);
        marker.delete();
        FindbugsPlugin.getBugCollection(project, monitor).remove(bug);
        return new PendingRewrite(rewrite, doc, originalUnit);
    } catch (BugResolutionException | CoreException e) {
        try {
            if (originalUnit != null) {
                originalUnit.discardWorkingCopy();
            }
        } catch (JavaModelException e1) {
            reportException(e1);
        }
        reportException(e);
        return null;
    }
}
 
Example 5
Source File: TLAMarkerHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * @param problem
 * @return
 */
public static String getType(IMarker problem)
{
    try
    {
        return problem.getType();
    } catch (CoreException e)
    {
        Activator.getDefault().logError("Error retriving marker type", e);
    }
    return null;
}
 
Example 6
Source File: ProcessValidationDecoratorProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
private String getType(IMarker marker) {
	try {
		return marker.getType();
	} catch (CoreException e) {
		ProcessDiagramEditorPlugin.getInstance().logError("Validation marker refresh failure", e); //$NON-NLS-1$
		return ""; //$NON-NLS-1$
	}
}
 
Example 7
Source File: N4JSIssue.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Issue createIssue(IMarker marker) {
	final N4JSIssue issue = new N4JSIssue();
	issue.setMarker(marker);

	// ---- BEGIN: copied from super class ----

	try {
		Map<String, Object> attributes = marker.getAttributes();
		String markerType = marker.getType();
		Object message = attributes.get(IMarker.MESSAGE);
		issue.setMessage(message instanceof String ? (String) message : null);
		Object lineNumber = attributes.get(IMarker.LINE_NUMBER);
		issue.setLineNumber(lineNumber instanceof Integer ? (Integer) lineNumber - 1 : null);
		Object offset = attributes.get(IMarker.CHAR_START);
		Object endOffset = attributes.get(IMarker.CHAR_END);
		if (offset instanceof Integer && endOffset instanceof Integer) {
			issue.setOffset((Integer) offset);
			issue.setLength((Integer) endOffset - (Integer) offset);
		} else {
			issue.setOffset(-1);
			issue.setLength(0);
		}
		Object code = attributes.get(Issue.CODE_KEY);
		issue.setCode(code instanceof String ? (String) code : null);
		Object data = attributes.get(Issue.DATA_KEY);
		issue.setData(data instanceof String ? Strings.unpack((String) data) : null);
		Object uri = attributes.get(Issue.URI_KEY);
		issue.setUriToProblem(uri instanceof String ? URI.createURI((String) uri) : null);
		Object severity = attributes.get(IMarker.SEVERITY);
		Severity translatedSeverity = translateSeverity(severity instanceof Integer ? (Integer) severity : 0);
		if (translatedSeverity == null)
			throw new IllegalArgumentException(marker.toString());
		issue.setSeverity(translatedSeverity);
		if (markerTypeProvider != null)
			issue.setType(markerTypeProvider.getCheckType(markerType));
		else
			issue.setType(MarkerTypes.toCheckType(markerType));
	} catch (CoreException e) {
		return null;
	}
	return issue;

	// ---- END: copied from super class ----
}
 
Example 8
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates an Issue out of a Marker.
 * setSyntaxError is unset since the current API does not allow fixing systax errors anyway.
 * 
 * @param marker The marker to create an issue from
 * @return an issue created out of the given marker or <code>null</code>
 */
public Issue createIssue(IMarker marker) {
	Issue.IssueImpl issue = new Issue.IssueImpl();
	try {
		Map<String, Object> attributes = marker.getAttributes();
		String markerType = marker.getType();
		Object message = attributes.get(IMarker.MESSAGE);
		issue.setMessage(message  instanceof String ? (String) message : null);
		Object lineNumber = attributes.get(IMarker.LINE_NUMBER);
		issue.setLineNumber(lineNumber instanceof Integer ? (Integer) lineNumber : null);
		Object column = attributes.get(Issue.COLUMN_KEY);
		issue.setColumn(column instanceof Integer ? (Integer) column : null);
		Object offset = attributes.get(IMarker.CHAR_START);
		Object endOffset = attributes.get(IMarker.CHAR_END);
		if(offset instanceof Integer && endOffset instanceof Integer) {
			issue.setOffset((Integer) offset);
			issue.setLength((Integer) endOffset - (Integer) offset); 
		} else {
			issue.setOffset(-1);
			issue.setLength(0);
		}
		Object code = attributes.get(Issue.CODE_KEY);
		issue.setCode(code instanceof String ? (String) code:null);
		Object data = attributes.get(Issue.DATA_KEY);
		issue.setData(data instanceof String ? Strings.unpack((String) data) : null);
		Object uri = attributes.get(Issue.URI_KEY);
		issue.setUriToProblem(uri instanceof String ? URI.createURI((String) uri) : null);
		Object severity = attributes.get(IMarker.SEVERITY);
		Severity translatedSeverity = translateSeverity(severity instanceof Integer ? (Integer) severity : 0);
		if(translatedSeverity == null)
			throw new IllegalArgumentException(marker.toString());
		issue.setSeverity(translatedSeverity);
		if(markerTypeProvider != null)
			issue.setType(markerTypeProvider.getCheckType(markerType));
		else
			issue.setType(MarkerTypes.toCheckType(markerType));
	} catch (CoreException e) {
		return null;
	}
	return issue;
}