Example usage for org.eclipse.jdt.core IJavaModelMarker ID

List of usage examples for org.eclipse.jdt.core IJavaModelMarker ID

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaModelMarker ID.

Prototype

String ID

To view the source code for org.eclipse.jdt.core IJavaModelMarker ID.

Click Source Link

Document

ID marker attribute (value "id").

Usage

From source file:com.google.gdt.eclipse.core.markers.quickfixes.JavaMarkerResolutionGenerator.java

License:Open Source License

public IMarkerResolution[] getResolutions(IMarker marker) {
    if (!hasResolutions(marker)) {
        return NO_RESOLUTIONS;
    }/*from  ww w .j  av  a 2s  .  c o  m*/

    ICompilationUnit cu = getCompilationUnit(marker);
    if (cu != null) {
        IEditorInput input = new FileEditorInput((IFile) cu.getPrimary().getResource());
        if (input != null) {
            int offset = marker.getAttribute(IMarker.CHAR_START, -1);
            int length = marker.getAttribute(IMarker.CHAR_END, -1) - offset;
            int problemId = marker.getAttribute(IJavaModelMarker.ID, -1);
            boolean isError = (marker.getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR);
            String[] arguments = CorrectionEngine.getProblemArguments(marker);

            IProblemLocation location = new ProblemLocation(offset, length, problemId, arguments, isError,
                    null);
            IInvocationContext context = new AssistContext(cu, offset, length);

            IJavaCompletionProposal[] proposals = new IJavaCompletionProposal[0];

            try {
                proposals = getCorrections(context, new IProblemLocation[] { location });
            } catch (CoreException e) {
                CorePluginLog.logError(e);
            }

            int nProposals = proposals.length;
            IMarkerResolution[] resolutions = new IMarkerResolution[nProposals];
            for (int i = 0; i < nProposals; i++) {
                resolutions[i] = new QuickFixCompletionProposalWrapper(cu, offset, length, proposals[i]);
            }
            return resolutions;
        }
    }

    return NO_RESOLUTIONS;
}

From source file:com.google.gdt.eclipse.core.markers.quickfixes.JavaMarkerResolutionGenerator.java

License:Open Source License

public boolean hasResolutions(IMarker marker) {
    int problemId = marker.getAttribute(IJavaModelMarker.ID, -1);
    return hasCorrections(getCompilationUnit(marker), problemId);
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockUtil.java

License:Open Source License

static void outputMarker(IMarker xmk, File fil, IvyXmlWriter xw) {
    if (xmk instanceof IProblem) {
        BedrockUtil.outputProblem(null, (IProblem) xmk, xw);
    } else {/*from  ww w .j  a v  a2 s.  com*/
        String mtyp = null;
        try {
            mtyp = xmk.getType();
        } catch (CoreException e) {
            return;
        }
        if (mtyp.contains("Breakpoint"))
            return;

        xw.begin("PROBLEM");
        xw.field("TYPE", mtyp);
        xw.field("ID", xmk.getId());
        int sev = xmk.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
        if (sev == IMarker.SEVERITY_ERROR)
            xw.field("ERROR", true);
        else if (sev == IMarker.SEVERITY_WARNING)
            xw.field("WARNING", true);
        int lno = xmk.getAttribute(IMarker.LINE_NUMBER, -1);
        if (lno >= 0) {
            xw.field("LINE", lno);
            xw.field("START", xmk.getAttribute(IMarker.CHAR_START, 0));
            xw.field("END", xmk.getAttribute(IMarker.CHAR_END, 0));
        }
        xw.field("MSGID", xmk.getAttribute(IJavaModelMarker.ID, 0));
        xw.field("FLAGS", xmk.getAttribute(IJavaModelMarker.FLAGS, 0));
        xw.textElement("FILE", fil.getPath());
        String msg = xmk.getAttribute(IMarker.MESSAGE, "");
        msg = IvyXml.xmlSanitize(msg, false);
        xw.textElement("MESSAGE", msg);
        String args = xmk.getAttribute(IJavaModelMarker.ARGUMENTS, null);
        if (args != null) {
            StringTokenizer tok = new StringTokenizer(args, ":#");
            if (tok.hasMoreTokens())
                tok.nextToken(); // skip count
            while (tok.hasMoreTokens()) {
                xw.cdataElement("ARG", tok.nextToken());
            }
        }
        BedrockPlugin.getPlugin().addFixes(xmk, xw);
        xw.end("PROBLEM");
    }
}

From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java

License:Open Source License

/**
 * Creates a marker from each problem and adds it to the resource.
 * The marker is as follows://w  w w  .j  a  va2s . c om
 *   - its type is T_PROBLEM
 *   - its plugin ID is the JavaBuilder's plugin ID
 *    - its message is the problem's message
 *    - its priority reflects the severity of the problem
 *    - its range is the problem's range
 *    - it has an extra attribute "ID" which holds the problem's id
 *   - it's {@link IMarker#SOURCE_ID} attribute is positioned to {@link JavaBuilder#SOURCE_ID} if
 *     the problem was generated by JDT; else the {@link IMarker#SOURCE_ID} attribute is
 *     carried from the problem to the marker in extra attributes, if present.
 */
protected void storeProblemsFor(SourceFile sourceFile, CategorizedProblem[] problems) throws CoreException {
    if (sourceFile == null || problems == null || problems.length == 0)
        return;
    // once a classpath error is found, ignore all other problems for this project so the user can see the main error
    // but still try to compile as many source files as possible to help the case when the base libraries are in source
    if (!this.keepStoringProblemMarkers)
        return; // only want the one error recorded on this source file

    HashSet managedMarkerTypes = JavaModelManager.getJavaModelManager().compilationParticipants
            .managedMarkerTypes();
    problems: for (int i = 0, l = problems.length; i < l; i++) {
        CategorizedProblem problem = problems[i];
        int id = problem.getID();
        // we may use a different resource for certain problems such as IProblem.MissingNonNullByDefaultAnnotationOnPackage
        // but at the start of the next problem we should reset it to the source file's resource
        IResource resource = sourceFile.resource;

        // handle missing classfile situation
        if (id == IProblem.IsClassPathCorrect) {
            String missingClassfileName = problem.getArguments()[0];
            if (JavaBuilder.DEBUG)
                System.out.println(Messages.bind(Messages.build_incompleteClassPath, missingClassfileName));
            boolean isInvalidClasspathError = JavaCore.ERROR
                    .equals(this.javaBuilder.javaProject.getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true));
            // insert extra classpath problem, and make it the only problem for this project (optional)
            if (isInvalidClasspathError && JavaCore.ABORT.equals(
                    this.javaBuilder.javaProject.getOption(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, true))) {
                JavaBuilder.removeProblemsAndTasksFor(this.javaBuilder.currentProject); // make this the only problem for this project
                this.keepStoringProblemMarkers = false;
            }
            IMarker marker = this.javaBuilder.currentProject
                    .createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
            marker.setAttributes(
                    new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID,
                            IMarker.SOURCE_ID },
                    new Object[] { Messages.bind(Messages.build_incompleteClassPath, missingClassfileName),
                            new Integer(isInvalidClasspathError ? IMarker.SEVERITY_ERROR
                                    : IMarker.SEVERITY_WARNING),
                            new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID });
            // even if we're not keeping more markers, still fall through rest of the problem reporting, so that offending
            // IsClassPathCorrect problem gets recorded since it may help locate the offending reference
        }

        String markerType = problem.getMarkerType();
        boolean managedProblem = false;
        if (IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER.equals(markerType)
                || (managedProblem = managedMarkerTypes.contains(markerType))) {
            if (id == IProblem.MissingNonNullByDefaultAnnotationOnPackage
                    && !(CharOperation.equals(sourceFile.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME))) {
                // for this kind of problem, marker needs to be created on the package instead of on the source file
                // see bug 372012
                char[] fileName = sourceFile.getFileName();
                int pkgEnd = CharOperation.lastIndexOf('/', fileName);
                if (pkgEnd == -1)
                    pkgEnd = CharOperation.lastIndexOf(File.separatorChar, fileName);
                PackageFragment pkg = null;
                if (pkgEnd != -1)
                    pkg = (PackageFragment) Util.getPackageFragment(sourceFile.getFileName(), pkgEnd,
                            -1 /*no jar separator for java files*/);

                if (pkg != null) {
                    try {
                        IMarker[] existingMarkers = pkg.resource().findMarkers(
                                IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
                        int len = existingMarkers.length;
                        for (int j = 0; j < len; j++) {
                            if (((Integer) existingMarkers[j].getAttribute(IJavaModelMarker.ID))
                                    .intValue() == IProblem.MissingNonNullByDefaultAnnotationOnPackage) {
                                continue problems; // marker already present
                            }
                        }
                    } catch (CoreException e) {
                        // marker retrieval failed, cannot do much
                        if (JavaModelManager.VERBOSE) {
                            e.printStackTrace();
                        }
                    }
                    IResource tempRes = pkg.resource();
                    if (tempRes != null) {
                        resource = tempRes;
                    }
                }
            }
            IMarker marker = resource.createMarker(markerType);

            String[] attributeNames = JAVA_PROBLEM_MARKER_ATTRIBUTE_NAMES;
            int standardLength = attributeNames.length;
            String[] allNames = attributeNames;
            int managedLength = managedProblem ? 0 : 1;
            String[] extraAttributeNames = problem.getExtraMarkerAttributeNames();
            int extraLength = extraAttributeNames == null ? 0 : extraAttributeNames.length;
            if (managedLength > 0 || extraLength > 0) {
                allNames = new String[standardLength + managedLength + extraLength];
                System.arraycopy(attributeNames, 0, allNames, 0, standardLength);
                if (managedLength > 0)
                    allNames[standardLength] = IMarker.SOURCE_ID;
                System.arraycopy(extraAttributeNames, 0, allNames, standardLength + managedLength, extraLength);
            }

            Object[] allValues = new Object[allNames.length];
            // standard attributes
            int index = 0;
            allValues[index++] = problem.getMessage(); // message
            allValues[index++] = problem.isError() ? S_ERROR : S_WARNING; // severity
            allValues[index++] = new Integer(id); // ID
            allValues[index++] = new Integer(problem.getSourceStart()); // start
            allValues[index++] = new Integer(problem.getSourceEnd() + 1); // end
            allValues[index++] = new Integer(problem.getSourceLineNumber()); // line
            allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments
            allValues[index++] = new Integer(problem.getCategoryID()); // category ID
            // SOURCE_ID attribute for JDT problems
            if (managedLength > 0)
                allValues[index++] = JavaBuilder.SOURCE_ID;
            // optional extra attributes
            if (extraLength > 0)
                System.arraycopy(problem.getExtraMarkerAttributeValues(), 0, allValues, index, extraLength);

            marker.setAttributes(allNames, allValues);

            if (!this.keepStoringProblemMarkers)
                return; // only want the one error recorded on this source file
        }
    }
}

From source file:org.eclipse.ajdt.internal.ui.ajde.UIMessageHandler.java

License:Open Source License

private void showMessages(final IProject project) {

    // THIS MUST STAY IN A SEPARATE THREAD - This is because we need
    // to create and setup the marker in an atomic operation. See
    // AMC or ASC.
    IWorkspaceRunnable r = new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) {

            try {

                Iterator<IResource> affectedResourceIterator = affectedResources.iterator();
                AJLog.log(AJLog.COMPILER, "Types affected during build = " + affectedResources.size()); //$NON-NLS-1$
                IResource ir = null;/* w w w . j  av a 2 s .com*/
                while (affectedResourceIterator.hasNext()) {
                    ir = (IResource) affectedResourceIterator.next();
                    try {
                        if (ir.exists()) {
                            ir.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false,
                                    IResource.DEPTH_INFINITE);
                            ir.deleteMarkers(IAJModelMarker.AJDT_PROBLEM_MARKER, true,
                                    IResource.DEPTH_INFINITE);
                            ir.deleteMarkers(IMarker.TASK, true, IResource.DEPTH_INFINITE);
                            // now removed markers from compilation participants
                            HashSet<String> managedMarkers = JavaModelManager
                                    .getJavaModelManager().compilationParticipants.managedMarkerTypes();
                            for (String managedMarker : managedMarkers) {
                                ir.deleteMarkers(managedMarker, true, IResource.DEPTH_INFINITE);
                            }
                        }
                    } catch (CoreException re) {
                        AJLog.log("Failed marker deletion: resource=" //$NON-NLS-1$
                                + ir.getLocation());
                        throw re;
                    }
                }

                Iterator<ProblemTracker> problemIterator = problems.iterator();
                ProblemTracker p = null;
                while (problemIterator.hasNext()) {
                    p = (ProblemTracker) problemIterator.next();
                    ir = null;
                    IMarker marker = null;
                    try {
                        if (p.location != null) {
                            ir = locationToResource(p.location, project);
                            if ((ir != null) && ir.exists()) {
                                // 128803 - only add problems to affected resources
                                if (lastBuildWasFull || affectedResources.contains(ir)
                                        || ir.getProject() != project) {
                                    int prio = getTaskPriority(p);
                                    if (prio != -1) {
                                        marker = ir.createMarker(IMarker.TASK);
                                        marker.setAttribute(IMarker.PRIORITY, prio);
                                    } else {
                                        if (p.declaredErrorOrWarning) {
                                            marker = ir.createMarker(IAJModelMarker.AJDT_PROBLEM_MARKER);
                                        } else {
                                            // create Java marker with problem id so
                                            // that quick fix is available
                                            marker = ir
                                                    .createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
                                            marker.setAttribute(IJavaModelMarker.ID, p.id);
                                        }
                                    }
                                    if ((p.start >= 0) && (p.end >= 0)) {
                                        marker.setAttribute(IMarker.CHAR_START, new Integer(p.start));
                                        marker.setAttribute(IMarker.CHAR_END, new Integer(p.end + 1));
                                    }
                                    if (!ir.getProject().equals(project)) {
                                        addOtherProjectMarker(project, marker);
                                    }
                                    if (p.location.getLine() > 0) {
                                        marker.setAttribute(IMarker.LINE_NUMBER,
                                                new Integer(p.location.getLine()));
                                    }
                                } else {
                                    AJLog.log(AJLog.COMPILER_MESSAGES,
                                            "Not adding marker for problem because it's " //$NON-NLS-1$
                                                    + "against a resource which is not in the list of affected resources" //$NON-NLS-1$
                                                    + " provided by the compiler. Resource=" + ir //$NON-NLS-1$
                                                    + " Problem message=" //$NON-NLS-1$
                                                    + p.message + " line=" + p.location.getLine()); //$NON-NLS-1$
                                }
                            }
                        } else {
                            marker = project.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);
                        }
                        if (marker != null) {
                            setSeverity(marker, p.kind);

                            if ((p.extraLocs != null) && (p.extraLocs.size() > 0)) { // multiple
                                // part
                                // message
                                int relCount = 0;
                                for (Iterator<?> iter = p.extraLocs.iterator(); iter.hasNext();) {
                                    ISourceLocation sLoc = (ISourceLocation) iter.next();
                                    StringBuffer attrData = new StringBuffer();
                                    attrData.append(sLoc.getSourceFile().getAbsolutePath());
                                    attrData.append(":::"); //$NON-NLS-1$
                                    attrData.append(sLoc.getLine());
                                    attrData.append(":::"); //$NON-NLS-1$
                                    attrData.append(sLoc.getEndLine());
                                    attrData.append(":::"); //$NON-NLS-1$
                                    attrData.append(sLoc.getColumn());
                                    marker.setAttribute(
                                            AspectJUIPlugin.RELATED_LOCATIONS_ATTRIBUTE_PREFIX + (relCount++),
                                            attrData.toString());
                                }
                            }

                            setMessage(marker, p.message);
                        }
                    } catch (CoreException re) {
                        AJLog.log("Failed marker creation: resource=" //$NON-NLS-1$
                                + p.location.getSourceFile().getPath() + " line=" //$NON-NLS-1$
                                + p.location.getLine() + " message=" + p.message); //$NON-NLS-1$
                        throw re;
                    }
                }
                clearMessages();
            } catch (CoreException e) {
                AJDTErrorHandler.handleAJDTError(UIMessages.CompilerTaskListManager_Error_creating_marker, e);
            }
        }
    };

    try {
        AspectJPlugin.getWorkspace().run(r, null);
    } catch (CoreException cEx) {
        AJDTErrorHandler.handleAJDTError(UIMessages.CompilerTaskListManager_Error_adding_problem_markers, cEx);
    }
    // Part of the fix for bug 89793 - editor image is not updated
    Collection<AspectJEditor> activeEditorList = AspectJEditor.getActiveEditorList();
    synchronized (activeEditorList) {
        for (AspectJEditor editor : activeEditorList) {
            editor.resetTitleImage();
        }
    }
}

From source file:org.eclipse.ajdt.ui.tests.editor.quickfix.AbstractQuickFixTest.java

License:Open Source License

protected ITextEditor quickFixSetup(IFile sourceFile, boolean shouldFindError) throws Exception {
    ITextEditor editorPart = (ITextEditor) openFileInAspectJEditor(sourceFile, false);

    //wait for annotation model to be created
    waitForJobsToComplete();//from  www.j a v  a  2  s .  co m

    IMarker[] markers = getMarkers(sourceFile);

    assertTrue("Should have found some Java model markers", markers.length > 0); //$NON-NLS-1$

    boolean foundWarning = false;
    boolean foundError = false;
    for (int i = 0; i < markers.length; i++) {
        IMarker m = markers[i];
        //String msg = (String)m.getAttribute(IMarker.MESSAGE);
        Integer sev = (Integer) m.getAttribute(IMarker.SEVERITY);
        if (!foundError && (sev.intValue() == IMarker.SEVERITY_ERROR)) {
            foundError = true;
            Integer pid = (Integer) m.getAttribute(IJavaModelMarker.ID);
            assertNotNull("Problem id attribute must be set", pid); //$NON-NLS-1$
            Integer start = (Integer) m.getAttribute(IMarker.CHAR_START);
            assertNotNull("Character start attribute must be set", start); //$NON-NLS-1$
            Integer end = (Integer) m.getAttribute(IMarker.CHAR_END);
            assertNotNull("Character end attribute must be set", end); //$NON-NLS-1$
        }
        if (!foundWarning && (sev.intValue() == IMarker.SEVERITY_WARNING)) {
            foundWarning = true;
            Integer pid = (Integer) m.getAttribute(IJavaModelMarker.ID);
            assertNotNull("Problem id attribute must be set", pid); //$NON-NLS-1$
            Integer start = (Integer) m.getAttribute(IMarker.CHAR_START);
            assertNotNull("Character start attribute must be set", start); //$NON-NLS-1$
            Integer end = (Integer) m.getAttribute(IMarker.CHAR_END);
            assertNotNull("Character end attribute must be set", end); //$NON-NLS-1$
        }
    }
    assertTrue("Didn't find a warning marker", foundWarning); //$NON-NLS-1$
    assertEquals("Didn't find an error marker", shouldFindError, foundError); //$NON-NLS-1$

    return editorPart;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Record a new marker denoting a classpath problem
 *//*from   w ww.  j av a2s. c  o  m*/
public void createClasspathProblemMarker(IJavaModelStatus status) {

    IMarker marker = null;
    int severity;
    String[] arguments = CharOperation.NO_STRINGS;
    boolean isCycleProblem = false, isClasspathFileFormatProblem = false, isOutputOverlapping = false;
    switch (status.getCode()) {

    case IJavaModelStatusConstants.CLASSPATH_CYCLE:
        isCycleProblem = true;
        if (JavaCore.ERROR.equals(getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))) {
            severity = IMarker.SEVERITY_ERROR;
        } else {
            severity = IMarker.SEVERITY_WARNING;
        }
        break;

    case IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT:
        isClasspathFileFormatProblem = true;
        severity = IMarker.SEVERITY_ERROR;
        break;

    case IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL:
        String setting = getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true);
        if (JavaCore.ERROR.equals(setting)) {
            severity = IMarker.SEVERITY_ERROR;
        } else if (JavaCore.WARNING.equals(setting)) {
            severity = IMarker.SEVERITY_WARNING;
        } else {
            return; // setting == IGNORE
        }
        break;
    case IJavaModelStatusConstants.OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE:
        isOutputOverlapping = true;
        setting = getOption(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, true);
        if (JavaCore.ERROR.equals(setting)) {
            severity = IMarker.SEVERITY_ERROR;
        } else if (JavaCore.WARNING.equals(setting)) {
            severity = IMarker.SEVERITY_WARNING;
        } else {
            return; // setting == IGNORE
        }
        break;
    default:
        IPath path = status.getPath();
        if (path != null)
            arguments = new String[] { path.toString() };
        if (JavaCore.ERROR.equals(getOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, true))
                && status.getSeverity() != IStatus.WARNING) {
            severity = IMarker.SEVERITY_ERROR;
        } else {
            severity = IMarker.SEVERITY_WARNING;
        }
        break;
    }

    try {
        marker = this.project.createMarker(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER);
        marker.setAttributes(
                new String[] { IMarker.MESSAGE, IMarker.SEVERITY, IMarker.LOCATION,
                        IJavaModelMarker.CYCLE_DETECTED, IJavaModelMarker.CLASSPATH_FILE_FORMAT,
                        IJavaModelMarker.OUTPUT_OVERLAPPING_SOURCE, IJavaModelMarker.ID,
                        IJavaModelMarker.ARGUMENTS, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID, },
                new Object[] { status.getMessage(), new Integer(severity), Messages.classpath_buildPath,
                        isCycleProblem ? "true" : "false", //$NON-NLS-1$ //$NON-NLS-2$
                        isClasspathFileFormatProblem ? "true" : "false", //$NON-NLS-1$ //$NON-NLS-2$
                        isOutputOverlapping ? "true" : "false", //$NON-NLS-1$ //$NON-NLS-2$
                        new Integer(status.getCode()), Util.getProblemArgumentsForMarker(arguments),
                        new Integer(CategorizedProblem.CAT_BUILDPATH), JavaBuilder.SOURCE_ID, });
    } catch (CoreException e) {
        // could not create marker: cannot do much
        if (JavaModelManager.VERBOSE) {
            e.printStackTrace();
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.ui.callinmarkers.AnnotationHelper.java

License:Open Source License

/** If a callout binds to an unused private method/field, remove the "unused" warning. */
<M> void removeSomeWarnings(IResource resource, ISourceRange nameRange) throws CoreException {
    if (fAnnotationModel == null)
        return;//from w w w  . j a  v a2 s  .  c om

    Iterator annotationIterator = new JavaAnnotationIterator(
            fAnnotationModel.getAnnotationIterator(nameRange.getOffset(), nameRange.getLength(), false, true),
            false); // not all, only problems
    boolean needRemoveMarker = false;
    annotations: while (annotationIterator.hasNext()) {
        Object next = annotationIterator.next();
        if (next instanceof IJavaAnnotation) {
            IJavaAnnotation javaAnnot = (IJavaAnnotation) next;
            if (javaAnnot.isProblem() || isProblemMarkerAnnotation(javaAnnot)) {
                switch (javaAnnot.getId()) {
                case IProblem.UnusedPrivateField:
                case IProblem.UnusedPrivateMethod:
                    fAnnotationModel.removeAnnotation((Annotation) javaAnnot); // remove from the ruler
                    if (javaAnnot instanceof MarkerAnnotation) {
                        ((MarkerAnnotation) javaAnnot).getMarker().delete(); // remove from problems view
                    } else {
                        needRemoveMarker = true;
                    }
                    break annotations;
                }
            }
        }
    }
    if (!needRemoveMarker)
        return;
    IMarker[] problems = resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
            IResource.DEPTH_ZERO);
    if (problems != null) {
        markers: for (IMarker problem : problems) {
            int problemStart = problem.getAttribute(IMarker.CHAR_START, -1);
            if (problemStart >= nameRange.getOffset()
                    && problemStart < (nameRange.getOffset() + nameRange.getLength())) {
                switch (problem.getAttribute(IJavaModelMarker.ID, -1)) {
                case IProblem.UnusedPrivateField:
                case IProblem.UnusedPrivateMethod:
                    problem.delete();
                    break markers;
                }
            }
        }
    }
}

From source file:org.gw4e.eclipse.builder.GW4EBuilder.java

License:Open Source License

/**
 * @param project/*from   w  w  w.  j a v a  2 s.  c om*/
 * @param file
 */
public static void removeMarkerForAbstractContextUsed(IFile file) {
    try {
        IMarker[] markers = file.findMarkers(GW4EBuilder.MARKER_TYPE, true, IResource.DEPTH_INFINITE);
        for (int i = 0; i < markers.length; i++) {
            IMarker m = markers[i];
            Integer pbId = (Integer) m.getAttribute(IJavaModelMarker.ID);
            if (pbId != null) {
                if (GW4EParser.ABSTRACT_CONTEXT_USED == pbId.intValue()) {
                    m.delete();
                }
            }
        }
    } catch (CoreException ce) {
    }
}

From source file:org.gw4e.eclipse.builder.marker.MarkerResolutionGenerator.java

License:Open Source License

@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    Object attr;//from w  w  w .j a v a2s.  c  o m
    try {
        attr = marker.getAttribute(IJavaModelMarker.ID);
        IMarkerResolution[] resolutions = resolvers.get(attr);
        return resolutions;
    } catch (CoreException e) {
        ResourceManager.logException(e);
    }
    return new IMarkerResolution[0];
}