Java 类org.eclipse.ui.texteditor.MarkerUtilities 实例源码

项目:n4js    文件:ProjectUtils.java   
/***/
public static IMarker[] assertMarkers(String assertMessage, final IResource resource, String markerType, int count,
        final Predicate<IMarker> markerPredicate) throws CoreException {
    IMarker[] markers = resource.findMarkers(markerType, true, IResource.DEPTH_INFINITE);
    List<IMarker> markerList = from(Arrays.asList(markers)).filter(markerPredicate).toList();
    if (markerList.size() != count) {
        StringBuilder message = new StringBuilder(assertMessage);
        message.append("\nbut was:");
        for (IMarker marker : markerList) {
            message.append("\n");
            message.append("line " + MarkerUtilities.getLineNumber(marker) + ": ");
            message.append(marker.getAttribute(IMarker.MESSAGE, "<no message>"));
        }
        Assert.assertEquals(message.toString(), count, markers.length);
    }
    return markers;
}
项目:n4js    文件:ProjectUtils.java   
/**
 * Asserts that the given resource (usually an N4JS file) contains issues with the given messages and no other
 * issues. Each message given should be prefixed with the line numer where the issues occurs, e.g.:
 *
 * <pre>
 * line 5: Couldn't resolve reference to identifiable element 'unknown'.
 * </pre>
 *
 * Column information is not provided, so this method is not intended for several issues within a single line.
 */
public static void assertIssues(final IResource resource, String... expectedMessages) throws CoreException {
    final IMarker[] markers = resource.findMarkers(MarkerTypes.ANY_VALIDATION, true, IResource.DEPTH_INFINITE);
    final String[] actualMessages = new String[markers.length];
    for (int i = 0; i < markers.length; i++) {
        final IMarker m = markers[i];
        actualMessages[i] = "line " + MarkerUtilities.getLineNumber(m) + ": " + m.getAttribute(IMarker.MESSAGE);
    }
    if (!Objects.equals(
            new HashSet<>(Arrays.asList(actualMessages)),
            new HashSet<>(Arrays.asList(expectedMessages)))) {
        final Joiner joiner = Joiner.on("\n    ");
        final String msg = "expected these issues:\n"
                + "    " + joiner.join(expectedMessages) + "\n"
                + "but got these:\n"
                + "    " + joiner.join(actualMessages);
        System.out.println("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*");
        System.out.println(msg);
        System.out.println("*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*");
        Assert.fail(msg);
    }
}
项目:eclipse-batch-editor    文件:AbstractMarkerHelper.java   
private void createMarker(IResource resource, String message, int lineNumber, String markerType, int severity,
        int charStart, int charEnd) throws CoreException {
    if (lineNumber <= 0)
        lineNumber = 1;
    IMarker marker = findMarker(resource, message, lineNumber, markerType);
    if (marker == null) {
        HashMap<String, Object> map = new HashMap<>();
        map.put(IMarker.SEVERITY, new Integer(severity));
        map.put(IMarker.LOCATION, resource.getFullPath().toOSString());
        map.put(IMarker.MESSAGE, message);
        MarkerUtilities.setLineNumber(map, lineNumber);
        MarkerUtilities.setMessage(map, message);
        if (charStart != -1) {
            MarkerUtilities.setCharStart(map, charStart);
            MarkerUtilities.setCharEnd(map, charEnd);
        }
        internalCreateMarker(resource, map, markerType);
    }
}
项目:eclipse-bash-editor    文件:AbstractMarkerHelper.java   
private void createMarker(IResource resource, String message, int lineNumber, String markerType, int severity,
        int charStart, int charEnd) throws CoreException {
    if (lineNumber <= 0)
        lineNumber = 1;
    IMarker marker = findMarker(resource, message, lineNumber, markerType);
    if (marker == null) {
        HashMap<String, Object> map = new HashMap<>();
        map.put(IMarker.SEVERITY, new Integer(severity));
        map.put(IMarker.LOCATION, resource.getFullPath().toOSString());
        map.put(IMarker.MESSAGE, message);
        MarkerUtilities.setLineNumber(map, lineNumber);
        MarkerUtilities.setMessage(map, message);
        if (charStart != -1) {
            MarkerUtilities.setCharStart(map, charStart);
            MarkerUtilities.setCharEnd(map, charEnd);
        }
        internalCreateMarker(resource, map, markerType);
    }
}
项目:ec4e    文件:ValidateEditorConfigStrategy.java   
private IMarker getExistingMarkerFor(IResource resource, String message, int start, int end,
        Set<IMarker> remainingMarkers) {
    ITextFileBuffer textFileBuffer = FileBuffers.getTextFileBufferManager()
            .getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
    if (textFileBuffer == null) {
        return null;
    }
    try {
        for (IMarker marker : remainingMarkers) {
            int startOffset = MarkerUtilities.getCharStart(marker);
            int endOffset = MarkerUtilities.getCharEnd(marker);
            if (MarkerUtils.getOptionType(marker) == null && message.equals(MarkerUtilities.getMessage(marker))) {
                if (start <= startOffset && end >= endOffset) {
                    return marker;
                }
            }
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    return null;
}
项目:egradle    文件:AbstractMarkerHelper.java   
private void createMarker(IResource resource, String message, int lineNumber, String markerType, int severity,
        int charStart, int charEnd) throws CoreException {
    if (lineNumber <= 0)
        lineNumber = 1;
    IMarker marker = findMarker(resource, message, lineNumber, markerType);
    if (marker == null) {
        HashMap<String, Object> map = new HashMap<>();
        map.put(IMarker.SEVERITY, new Integer(severity));
        map.put(IMarker.LOCATION, resource.getFullPath().toOSString());
        map.put(IMarker.MESSAGE, message);
        MarkerUtilities.setLineNumber(map, lineNumber);
        MarkerUtilities.setMessage(map, message);
        if (charStart != -1) {
            MarkerUtilities.setCharStart(map, charStart);
            MarkerUtilities.setCharEnd(map, charEnd);
        }
        internalCreateMarker(resource, map, markerType);
    }
}
项目:JAADAS    文件:SootAttributesJavaHover.java   
protected void addSootAttributeMarkers() {

    if (getAttrsHandler() == null)return;
    if (getAttrsHandler().getAttrList() == null) return;
    Iterator it = getAttrsHandler().getAttrList().iterator();
    HashMap markerAttr = new HashMap();

    while (it.hasNext()) {
        SootAttribute sa = (SootAttribute)it.next();
        if (((sa.getAllTextAttrs("<br>") == null) || (sa.getAllTextAttrs("<br>").length() == 0)) && 
            ((sa.getAllLinkAttrs() == null) || (sa.getAllLinkAttrs().size() ==0))) continue;

        markerAttr.put(IMarker.LINE_NUMBER, new Integer(sa.getJavaStartLn()));

        try {
            MarkerUtilities.createMarker(getRec(), markerAttr, "ca.mcgill.sable.soot.sootattributemarker");
        }
        catch(CoreException e) {
            System.out.println(e.getMessage());
        }

    }

}
项目:JAADAS    文件:SootAttrJimpleIconGenerator.java   
public void addSootAttributeMarkers(){//SootAttributesHandler handler, IFile rec) {

    if (getHandler().getAttrList() == null) return;
    Iterator it = getHandler().getAttrList().iterator();
    HashMap markerAttr = new HashMap();

    while (it.hasNext()) {
        SootAttribute sa = (SootAttribute)it.next();
        if (getHandler().isShowAllTypes() || typesContainsOneOf(sa.getAnalysisTypes())){
            if (((sa.getAllTextAttrs("") == null) || (sa.getAllTextAttrs("").length() == 0)) && 
                ((sa.getAllLinkAttrs() == null) || (sa.getAllLinkAttrs().size() ==0))) continue;
            markerAttr.put(IMarker.LINE_NUMBER, new Integer(sa.getJimpleStartLn()));

            try {
                MarkerUtilities.createMarker(getRec(), markerAttr, "ca.mcgill.sable.soot.sootattributemarker");
            }
            catch(CoreException e) {
                System.out.println(e.getMessage());
            }
        }
    }
}
项目:JAADAS    文件:SootAttrJavaIconGenerator.java   
public void addSootAttributeMarkers(){//SootAttributesHandler handler, IFile rec) {

    if (getHandler().getAttrList() == null) return;
    Iterator it = getHandler().getAttrList().iterator();
    HashMap markerAttr = new HashMap();

    while (it.hasNext()) {
        SootAttribute sa = (SootAttribute)it.next();
        if (getHandler().isShowAllTypes() || typesContainsOneOf(sa.getAnalysisTypes())) {
            if (((sa.getAllTextAttrs("<br>") == null) || (sa.getAllTextAttrs("<br>").length() == 0)) && 
                ((sa.getAllLinkAttrs() == null) || (sa.getAllLinkAttrs().size() ==0))) continue;
            markerAttr.put(IMarker.LINE_NUMBER, new Integer(sa.getJavaStartLn()));
            try {
                MarkerUtilities.createMarker(getRec(), markerAttr, "ca.mcgill.sable.soot.sootattributemarker");
            }
            catch(CoreException e) {
                System.out.println(e.getMessage());
            }
        }
    }
}
项目:texlipse    文件:MarkerHandler.java   
/**
 * Creates warning markers for undefined references. 
 * 
 * @param editor The editor to add the errors to
 * @param errors The errors to add as instances of <code>DocumentReference</code>
 */
public void createReferencingErrorMarkers(ITextEditor editor, List<DocumentReference> errors) {

    IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
    if (resource == null) return;
    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

    for (DocumentReference msg : errors) {
        try {
            int beginOffset = document.getLineOffset(msg.getLine() - 1) + msg.getPos();

            Map<String, ? super Object> map = new HashMap<String, Object>();
            map.put(IMarker.LINE_NUMBER, Integer.valueOf(msg.getLine()));
            map.put(IMarker.CHAR_START, Integer.valueOf(beginOffset));
            map.put(IMarker.CHAR_END, Integer.valueOf(beginOffset + msg.getLength()));
            map.put(IMarker.MESSAGE, "Key " + msg.getKey() + " is undefined");
            map.put(IMarker.SEVERITY, Integer.valueOf(IMarker.SEVERITY_WARNING));

            MarkerUtilities.createMarker(resource, map, IMarker.PROBLEM);
        } catch (CoreException ce) {
            TexlipsePlugin.log("Creating marker", ce);
        } catch (BadLocationException ble) {
            TexlipsePlugin.log("Creating marker", ble);
        }
    }
}
项目:texlipse    文件:AbstractProgramRunner.java   
/**
    * Create a layout warning marker to the given resource.
    *
    * @param resource the file where the problem occurred
    * @param message error message
    * @param lineNumber line number
    * @param markerType
    * @param severity Severity of the error
    */
   @SuppressWarnings("unchecked")
protected static void createMarker(IResource resource, 
        Integer lineNumber, String message, String markerType, int severity) {
    int lineNr = -1;
    if (lineNumber != null) {
        lineNr = lineNumber;
    }
    IMarker marker = AbstractProgramRunner.findMarker(resource, lineNr, message, markerType);
    if (marker == null) {
        try {
            HashMap map = new HashMap();
            map.put(IMarker.MESSAGE, message);
            map.put(IMarker.SEVERITY, new Integer (severity));

            if (lineNumber != null)
                map.put(IMarker.LINE_NUMBER, lineNumber);

            MarkerUtilities.createMarker(resource, map, markerType);
        } catch (CoreException e) {
            throw new RuntimeException(e);
        }
    }
   }
项目:bts    文件:IssueUtil.java   
public Issue createIssue(IMarker marker) {
    Issue.IssueImpl issue = new Issue.IssueImpl();
    issue.setMessage(MarkerUtilities.getMessage(marker));

    issue.setLineNumber(MarkerUtilities.getLineNumber(marker) - 1);
    issue.setOffset(MarkerUtilities.getCharStart(marker));
    issue.setLength(MarkerUtilities.getCharEnd(marker)-MarkerUtilities.getCharStart(marker));

    issue.setCode(getCode(marker));
    issue.setData(getIssueData(marker));
    issue.setUriToProblem(getUriToProblem(marker));
    issue.setSeverity(getSeverity(marker));

    issue.setType(getCheckType(marker));
    // Note, isSyntaxError is unset, but currently the api does not allow fixing
    // syntax errors anyway.
    return issue;
}
项目:velocity-edit    文件:EditorUtil.java   
@SuppressWarnings("rawtypes")
public static void addMarker(IFile file, String message, int line, int colPos, int markerType) {
    try {
        Map<String, Comparable> attributes = new HashMap<String, Comparable>(5);
        attributes.put(IMarker.SEVERITY, new Integer(markerType));
        attributes.put(IMarker.MESSAGE, message);
        attributes.put(IMarker.TEXT, message);
        if (colPos > 0) {
            attributes.put(IMarker.CHAR_START, new Integer(colPos));
            attributes.put(IMarker.CHAR_END, new Integer(colPos));
        }
        else {
            attributes.put(IMarker.LINE_NUMBER, new Integer(line));
        }
        MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
    } catch (Exception e) {}
}
项目:eclipse-tslint    文件:Linter.java   
private void addMarker(RuleFailure ruleViolation) {
    try {
        Path path = new Path(ruleViolation.getName());
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);

        RuleFailurePosition startPosition = ruleViolation.getStartPosition();
        RuleFailurePosition endPosition = ruleViolation.getEndPosition();

        Map<String, Object> attributes = Maps.newHashMap();
        attributes.put(IMarker.LINE_NUMBER, startPosition.getLine() + 1);
        attributes.put(IMarker.CHAR_START, startPosition.getPosition());
        attributes.put(IMarker.CHAR_END, endPosition.getPosition());
        attributes.put(IMarker.MESSAGE, ruleViolation.getFailure());
        attributes.put(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
        attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);

        MarkerUtilities.createMarker(file, attributes, MARKER_TYPE);
    } catch (CoreException e) {
        throw new RuntimeException(e);
    }
}
项目:ESPSecurityPlugin    文件:EclipseMarkerFeedbackReporter.java   
@Override
    public void sendFeedback(FeedbackInstance feedbackInstance) {
        // Get all markers on the resource in question
        // place the marker
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
        map.put(IMarker.MESSAGE, feedbackInstance.getMessage());
        map.put(IMarker.CHAR_START, feedbackInstance.getStartPosition());
        map.put(IMarker.CHAR_END, feedbackInstance.getEndPosition());

        try {
            MarkerUtilities.createMarker(contextModel.getResource(), map, "ESPSecurityPlugin.secproblem");
        } catch (CoreException e) {
//          LOG.log(Level.INFO, "Could not create marker: " + e.getMessage());
        }
    }
项目:gemoc-studio    文件:EclipseReporter.java   
public void addMarker(int markerSeverity, String Marker,IFile file, String message, Integer lineNumber, Integer beginChar, Integer endChar, String msgGroup) {
    try {
        HashMap<String, java.lang.Object> datas = new HashMap<String, java.lang.Object>();
        datas.put( IMarker.MESSAGE, message != null ? message : "<null>" );
        datas.put( IMarker.SEVERITY, markerSeverity );

        if ( beginChar != null )
            datas.put( IMarker.CHAR_START, beginChar );
        else
            datas.put( IMarker.CHAR_START, 0 );

        if ( endChar != null )
            datas.put( IMarker.CHAR_END, endChar );
        else
            datas.put( IMarker.CHAR_END, 0 );
        if(lineNumber != null)
            datas.put(IMarker.LINE_NUMBER, lineNumber);
        datas.put(KERMETA_MARKER_ATTRIBUTE, msgGroup);
        MarkerUtilities.createMarker( file, datas, IMarker.PROBLEM );
    /*
        IMarker marker = file.createMarker(Marker);
        marker.setAttribute(IMarker.MESSAGE, message != null ? message : "<null>");
        marker.setAttribute(IMarker.SEVERITY, markerSeverity);
        if (lineNumber == -1) {
            lineNumber = 1;
        }
        marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
        marker.setAttribute(IMarker.CHAR_START, beginChar);
        marker.setAttribute(IMarker.CHAR_END, endChar);
        marker.setAttribute(KERMETA_MARKER_ATTRIBUTE, msgGroup);
    */
    } catch (CoreException e) {
        ms.log(Kind.DevERROR, "Failed to mark TextFile", Activator.PLUGIN_ID, e);
    }
}
项目:texlipse    文件:MarkerHandler.java   
/**
 * Creates markers from a given list of <code>ParseErrorMessage</code>s.
 * 
 * @param editor The editor to add the errors to
 * @param markers The markers to add as instances of <code>ParseErrorMessage</code>
 * @param markerType The type of the markers as <code>IMarker</code> types
 */
private void createMarkers(ITextEditor editor, List<ParseErrorMessage> markers, final String markerType) {
    IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
    if (resource == null) return;
    //IResource resource = ((FileEditorInput)editor.getEditorInput()).getFile();
    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

    for (ParseErrorMessage msg : markers) {
        try {
            int beginOffset = document.getLineOffset(msg.getLine() - 1) + msg.getPos();

            Map<String, ? super Object> map = new HashMap<String, Object>();
            map.put(IMarker.LINE_NUMBER, Integer.valueOf(msg.getLine()));
            map.put(IMarker.CHAR_START, Integer.valueOf(beginOffset));
            map.put(IMarker.CHAR_END, Integer.valueOf(beginOffset + msg.getLength()));
            map.put(IMarker.MESSAGE, msg.getMsg());

            // we can do this since we're referring to a static field
            if (IMarker.PROBLEM == markerType)
                map.put(IMarker.SEVERITY, Integer.valueOf(msg.getSeverity()));

            if (IMarker.TASK == markerType)
                map.put(IMarker.PRIORITY, Integer.valueOf(msg.getSeverity()));

            MarkerUtilities.createMarker(resource, map, markerType);
        } catch (CoreException ce) {
            TexlipsePlugin.log("Creating marker", ce);
        } catch (BadLocationException ble) {
            TexlipsePlugin.log("Creating marker", ble);
        }
    }
}
项目:texlipse    文件:MarkerHandler.java   
/**
 * Adds a fatal error to the problem log.
 * 
 * @param editor The editor to add the errors to
 * @param error The error message 
 */
public void addFatalError(ITextEditor editor, String error) {
    IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
    if (resource == null) return;
    //IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
    try {
        Map<String, ? super Object> map = new HashMap<String, Object>();
        map.put(IMarker.MESSAGE, error);
        map.put(IMarker.SEVERITY, Integer.valueOf(IMarker.SEVERITY_ERROR));

        MarkerUtilities.createMarker(resource, map, IMarker.PROBLEM);
    } catch (CoreException ce) {
        TexlipsePlugin.log("Creating marker", ce);
    }
}
项目:texlipse    文件:MarkerHandler.java   
/**
 * Creates an error marker on the given line
 * 
 * @param resource The resource to create the error to
 * @param message The message for the marker
 * @param lineNumber The line number to create the error on
 */
public void createErrorMarker(IResource resource, String message, int lineNumber) {
    try {
        Map<String, ? super Object> map = new HashMap<String, Object>();
        map.put(IMarker.LINE_NUMBER, Integer.valueOf(lineNumber));
        map.put(IMarker.MESSAGE, message);

        map.put(IMarker.SEVERITY, Integer.valueOf(IMarker.SEVERITY_ERROR));

        MarkerUtilities.createMarker(resource, map, IMarker.PROBLEM);
    } catch (CoreException ce) {
        TexlipsePlugin.log("Creating marker", ce);
    }
}
项目:bts    文件:IssueUtil.java   
/**
 * @since 2.3
 */
protected CheckType getCheckType(IMarker marker) {
    String markerType = MarkerUtilities.getMarkerType(marker);
    if (markerTypeProvider != null)
        return markerTypeProvider.getCheckType(markerType);
    return MarkerTypes.toCheckType(markerType);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaMarkerAnnotation.java   
/**
 * 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
 */
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);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaMarkerAnnotation.java   
public String getMarkerType() {
    IMarker marker= getMarker();
    if (marker == null  || !marker.exists())
        return null;

    return  MarkerUtilities.getMarkerType(getMarker());
}
项目:EclipseEditorPluginExample    文件:EditorActions.java   
/**
 * Creates a 'red cross' flag on the given file, at the line number specified, with the
 * hover-message specificed.
 * 
 * Remember that linenumber starts at 1!
 */
public static void createMarkerForResource(IResource resource, int linenumber, String message)
    throws CoreException {

  if (linenumber == 0) {
    linenumber = 1;
  }
  HashMap<String, Object> map = new HashMap<String, Object>();
  MarkerUtilities.setLineNumber(map, linenumber);
  MarkerUtilities.setMessage(map, message);
  map.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
  MarkerUtilities.createMarker(resource, map, IMarker.PROBLEM);
}
项目:idecore    文件:ApexErrorMarkerHandler.java   
private Map<String, Object> createSyntacticMarkerIfApplicable(final ParseException parseException) {
    Location loc = parseException.getLoc();
    if (Locations.isReal(loc)) {
        try {
            UserError userError = parseException.getUserError();
            Map<String, Object> config = new HashMap<>();

            // There is the option to set the line number as well. However, that config is ignored if
            // we set the CharStart and CharEnd. So, we only set the latter.
            MarkerUtilities.setCharStart(config, getStartOffset(loc));
            MarkerUtilities.setCharEnd(config, getEndOffset(loc));

            MarkerUtilities.setMessage(config,
                    printerUtil.getFactory().userErrorPrinter().print(userError, printContext));

            // Not sure why there aren't any utilities methods for these fields in MarkerUtilities
            // So set them directly instead.
            config.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
            config.put(IMarker.LOCATION, fFile.getFullPath().toString());
            return config;
        } catch (BadLocationException ble) {
            logger.warn("Error calculating offset to document using parser position", ble);
            return null;
        }
    } else {
        return null;
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaMarkerAnnotation.java   
/**
 * 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
 */
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);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaMarkerAnnotation.java   
public String getMarkerType() {
    IMarker marker= getMarker();
    if (marker == null  || !marker.exists())
        return null;

    return  MarkerUtilities.getMarkerType(getMarker());
}
项目:Pydev    文件:PyMarkerUtils.java   
/**
 * @return the position for a marker.
 */
public static Position getMarkerPosition(IDocument document, IMarker marker, IAnnotationModel model) {
    if (model instanceof AbstractMarkerAnnotationModel) {
        Position ret = ((AbstractMarkerAnnotationModel) model).getMarkerPosition(marker);
        if (ret != null) {
            return ret;
        }
    }
    int start = MarkerUtilities.getCharStart(marker);
    int end = MarkerUtilities.getCharEnd(marker);

    if (start > end) {
        end = start + end;
        start = end - start;
        end = end - start;
    }

    if (start == -1 && end == -1) {
        // marker line number is 1-based
        int line = MarkerUtilities.getLineNumber(marker);
        if (line > 0 && document != null) {
            try {
                start = document.getLineOffset(line - 1);
                end = start;
            } catch (BadLocationException x) {
            }
        }
    }

    if (start > -1 && end > -1) {
        return new Position(start, end - start);
    }

    return null;
}
项目:Pydev    文件:PyParser.java   
/**
 * Adds the error markers for some error that was found in the parsing process.
 *
 * @param error the error find while parsing the document
 * @param resource the resource that should have the error added
 * @param doc the document with the resource contents
 * @return the error description (or null)
 *
 * @throws BadLocationException
 * @throws CoreException
 */
public static ErrorDescription createParserErrorMarkers(Throwable error, IAdaptable resource, IDocument doc) {
    ErrorDescription errDesc;
    errDesc = createErrorDesc(error, doc);

    //Create marker only if possible...
    if (resource != null) {
        IResource fileAdapter = resource.getAdapter(IResource.class);
        if (fileAdapter != null) {
            try {
                Map<String, Object> map = new HashMap<String, Object>();

                map.put(IMarker.MESSAGE, errDesc.message);
                map.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                map.put(IMarker.LINE_NUMBER, errDesc.errorLine);
                map.put(IMarker.CHAR_START, errDesc.errorStart);
                map.put(IMarker.CHAR_END, errDesc.errorEnd);
                map.put(IMarker.TRANSIENT, true);
                MarkerUtilities.createMarker(fileAdapter, map, IMarker.PROBLEM);
            } catch (Exception e) {
                Log.log(e);
            }
        }
    }

    return errDesc;
}
项目:goclipse    文件:ExternalBreakpointWatcher.java   
protected int getMarkerPosition(IMarker marker) throws BadLocationException {
    int line = MarkerUtilities.getLineNumber(marker);
    if (line > 0) {
        return document.getLineOffset(line - 1);
    }
    throw new BadLocationException();
}
项目:n4js    文件:N4JSMarkerResolutionGenerator.java   
@Override
public void run(IMarker[] markers, IProgressMonitor monitor) {
    if (isBasedOnN4Modification()) {
        // applying an N4Modification to one or more markers

        try {
            // collect all changes
            final List<IChange> changes = new ArrayList<>();
            for (IMarker currMarker : markers) {

                if (!isMarkerStillValid(currMarker))
                    continue;

                final Issue currIssue = issueUtil.createIssue(currMarker);
                final IModificationContext currContext = modificationContextFactory
                        .createModificationContext(currIssue);
                final int offset = MarkerUtilities.getCharStart(currMarker);
                final int length = MarkerUtilities.getCharEnd(currMarker) - offset;
                final EObject element = getElementForMarker(currContext, currMarker);

                Collection<? extends IChange> changeSet = null;
                if (markers.length == 1) {
                    changeSet = getN4Modification().computeChanges(
                            currContext, currMarker, offset, length, element);
                } else {
                    changeSet = getN4Modification().computeOneOfMultipleChanges(
                            currContext, currMarker, offset, length, element);
                }

                changes.addAll(changeSet);
            }

            getN4Modification().computeFinalChanges();

            // perform changes
            changeManager.applyAll(changes);

        } catch (Exception e) {
            throw new WrappedException(
                    "exception while applying resolution for quick fix '" + resolution.getLabel() + "'", e);
        }
    } else {
        // support for applying modifications other than N4Modification

        // applying a single quick fix to multiple markers only supported for N4Modifications (see
        // #findOtherMarkers(IMarker[]) below), so we assert markers.length==1 here
        if (markers.length != 1)
            throw new IllegalStateException();

        // default Xtext implementation
        resolution.apply();
    }
}
项目:Tarski    文件:MarkerUpdater.java   
public static void updateSourcesToDelete(final IMarker beDeleted) {
  try {
    if (MarkUtilities.getSourceList(beDeleted).size() != 0) {
      final ArrayList<MarkElement> sourceElements = MarkUtilities.getSourceList(beDeleted);

      for (final MarkElement sourceElement : sourceElements) {

        final IMarker sourceMarker = sourceElement.getiMarker();
        List<IMarker> groupSourceMarkers = new ArrayList<IMarker>();

        if (MarkUtilities.getGroupId(sourceMarker) != null) {
          groupSourceMarkers = MarkerFactory.findMarkersByGroupId(sourceMarker.getResource(),
              MarkUtilities.getGroupId(sourceMarker));
        }
        if (groupSourceMarkers.isEmpty()) {
          groupSourceMarkers.add(sourceMarker);
        }

        for (final IMarker groupSourceMarker : groupSourceMarkers) {

          if (MarkUtilities.getTargetList(groupSourceMarker).size() != 0) {
            final ArrayList<MarkElement> targetElementsofSource =
                MarkUtilities.getTargetList(groupSourceMarker);

            for (int i = targetElementsofSource.size() - 1; i >= 0; i--) {
              if (MarkUtilities.compare(targetElementsofSource.get(i).getiMarker(), beDeleted)) {
                targetElementsofSource.remove(i);
              }
            }
            MarkUtilities.setTargetList(groupSourceMarker, targetElementsofSource);

            if (groupSourceMarker.getType().equals(MarkerFactory.MARKER_MAPPING)
                && targetElementsofSource.size() == 0) {
              // final IEditorPart part =
              IDE.openEditor(MarkerActivator.getActiveWorkbenchWindow().getActivePage(),
                  groupSourceMarker, false);
              final Map<String, Object> attributes = groupSourceMarker.getAttributes();
              final IResource res = groupSourceMarker.getResource();
              AnnotationFactory.removeAnnotation(groupSourceMarker);
              groupSourceMarker.delete();
              MarkerUtilities.createMarker(res, attributes, MarkerFactory.MARKER_MARKING);
              final IMarker newMarker = MarkerFactory.findMarkerBySourceId(res,
                  (String) attributes.get(IMarker.SOURCE_ID));
              AnnotationFactory.addAnnotation(newMarker, AnnotationFactory.ANNOTATION_MARKING);
            }
          }
        }
      }
    }
  } catch (final CoreException e) {
    e.printStackTrace();
  }
}
项目:ec4e    文件:ValidateAppliedOptionsStrategy.java   
/**
 * Validate 'trim_trailing_whitespace' of the lines where region changed if
 * needed and update the given set of marker.
 *
 * @param partition
 *            the region which changed
 * @param remainingMarkers
 *            set of markers to update.
 * @throws BadLocationException
 */
private void validateTrimTrailingWhiteSpace(IDocument document, IRegion partition, Set<IMarker> remainingMarkers)
        throws BadLocationException, CoreException {
    boolean trimTrailingWhiteSpace = preferenceStore.getBoolean(EDITOR_TRIM_TRAILING_WHITESPACE);
    if (!trimTrailingWhiteSpace) {
        return;
    }
    int startLine = document.getLineOfOffset(partition.getOffset());
    int endLine = document.getLineOfOffset(partition.getOffset() + partition.getLength());

    IRegion region = null;
    for (int i = startLine; i < endLine + 1; i++) {
        region = document.getLineInformation(i);
        if (region.getLength() == 0)
            continue;
        int lineStart = region.getOffset();
        int lineExclusiveEnd = lineStart + region.getLength();
        int j = lineExclusiveEnd - 1;
        while (j >= lineStart && Character.isWhitespace(document.getChar(j)))
            --j;
        ++j;
        if (j < lineExclusiveEnd) {
            addOrUpdateMarker(j, lineExclusiveEnd, trimTrailingWhitespaceType, document, remainingMarkers);
        }
    }
    if (region != null) {
        for (IMarker marker : new HashSet<>(remainingMarkers)) {
            if (MarkerUtils.getOptionType(marker) == trimTrailingWhitespaceType) {
                int line = MarkerUtilities.getLineNumber(marker) + 1;
                if (line < startLine || line > endLine) {
                    remainingMarkers.remove(marker);
                }
            }
        }
    }
}
项目:cppcheclipse    文件:ProblemReporter.java   
private void reportProblem(IResource resource, String message,
        int severity, int lineNumber, String id, File file,
        int originalLineNumber) throws CoreException {
    // TODO: open external file, see
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=151005 on how to
    // generate markers for external files

    // Do not put in duplicates
    IMarker[] cur = resource.findMarkers(CHECKER_MARKER_TYPE, false,
            IResource.DEPTH_ZERO);
    if (cur != null) {
        for (IMarker element : cur) {
            int oldLineNumber = element
                    .getAttribute(IMarker.LINE_NUMBER, 0);
            if (lineNumber == oldLineNumber) {
                String oldMessage = element.getAttribute(IMarker.MESSAGE,
                        ""); //$NON-NLS-1$
                int oldSeverity = element.getAttribute(IMarker.SEVERITY,
                        100);
                if (severity == oldSeverity && message.equals(oldMessage))
                    return;
            }
        }
    }

    // see
    // http://wiki.eclipse.org/FAQ_Why_don%27t_my_markers_appear_in_the_editor%27s_vertical_ruler%3F
    Map<String, Object> attributes = new HashMap<String, Object>();
    if (lineNumber != 0) {
        MarkerUtilities.setLineNumber(attributes, lineNumber);
    }
    MarkerUtilities.setMessage(attributes, message);
    attributes.put(IMarker.SEVERITY, severity);
    // the following attributes are only used for the quick fixes
    attributes.put(ATTRIBUTE_ID, id);
    if (file != null) {
        attributes.put(ATTRIBUTE_FILE, file.toString());
    }
    attributes.put(ATTRIBUTE_ORIGINAL_LINE_NUMBER, originalLineNumber);
    MarkerUtilities.createMarker(resource, attributes, CHECKER_MARKER_TYPE);
}
项目:testability-explorer    文件:TestabilityReportLaunchListener.java   
private void createMarkersFromClassIssues(List<ClassIssues> classIssues,
    IJavaProject javaProject) throws CoreException {
  javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_COLLABORATOR_MARKER_TYPE,
      true, IResource.DEPTH_INFINITE);
  javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_CONSTRUCTOR_MARKER_TYPE,
          true, IResource.DEPTH_INFINITE);
  javaProject.getProject().deleteMarkers(TestabilityConstants.TESTABILITY_DIRECT_COST_MARKER_TYPE,
          true, IResource.DEPTH_INFINITE);
  IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
  List<IPath> sourceFolderPaths = new ArrayList<IPath>();
  for (IPackageFragmentRoot root : roots) {
    if (!root.isArchive()) {
      IResource rootResource = root.getCorrespondingResource();
      sourceFolderPaths.add(rootResource.getFullPath().removeFirstSegments(1));
    }
  }
  for (ClassIssues classIssue : classIssues) {
    IResource resource = getAbsolutePathFromJavaFile(classIssue.getClassName(), sourceFolderPaths,
        javaProject.getProject());
    if (resource != null) {
      for (Issue issue : classIssue.getMostImportantIssues()) {
        Map<String, Object> attributes = new HashMap<String, Object>();
        attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
        attributes.put(IMarker.LINE_NUMBER, issue.getLocation().getLineNumber());
        attributes.put(IMarker.MESSAGE,
            retriever.getSuggestion(issue.getType(), issue.getSubType()));
        IssueType issueType = issue.getType(); 
        attributes.put(TestabilityConstants.ISSUE_TYPE, issue.getType().toString());
        String markerType = null;
        if (IssueType.COLLABORATOR.equals(issueType)) {
          markerType = TestabilityConstants.TESTABILITY_COLLABORATOR_MARKER_TYPE;
        } else if (IssueType.CONSTRUCTION.equals(issueType)) {
          markerType = TestabilityConstants.TESTABILITY_CONSTRUCTOR_MARKER_TYPE;
        } else if (IssueType.DIRECT_COST.equals(issueType)) {
          markerType = TestabilityConstants.TESTABILITY_DIRECT_COST_MARKER_TYPE;
        }
        if (markerType != null) {
          MarkerUtilities.createMarker(resource, attributes, markerType);
        }
      }
    } else {
      logger.logException("No Resource found for Class : " + classIssue.getClassName(), null);
    }
  }
}
项目:Eclipse-Postfix-Code-Completion    文件:CorrectionMarkerResolutionGenerator.java   
private static boolean internalHasResolutions(IMarker marker) {
    int id= marker.getAttribute(IJavaModelMarker.ID, -1);
    ICompilationUnit cu= getCompilationUnit(marker);
    return cu != null && JavaCorrectionProcessor.hasCorrections(cu, id, MarkerUtilities.getMarkerType(marker));
}
项目:WP3    文件:MarkerUpdater.java   
public static void updateSourcesToDelete(final IMarker beDeleted) {
  try {
    if (MarkUtilities.getSourceList(beDeleted).size() != 0) {
      final ArrayList<MarkElement> sourceElements = MarkUtilities.getSourceList(beDeleted);

      for (final MarkElement sourceElement : sourceElements) {

        final IMarker sourceMarker = sourceElement.getiMarker();
        List<IMarker> groupSourceMarkers = new ArrayList<IMarker>();

        if (MarkUtilities.getGroupId(sourceMarker) != null) {
          groupSourceMarkers = MarkerFactory.findMarkersByGroupId(sourceMarker.getResource(),
              MarkUtilities.getGroupId(sourceMarker));
        }
        if (groupSourceMarkers.isEmpty()) {
          groupSourceMarkers.add(sourceMarker);
        }

        for (final IMarker groupSourceMarker : groupSourceMarkers) {

          if (MarkUtilities.getTargetList(groupSourceMarker).size() != 0) {
            final ArrayList<MarkElement> targetElementsofSource =
                MarkUtilities.getTargetList(groupSourceMarker);

            for (int i = targetElementsofSource.size() - 1; i >= 0; i--) {
              if (MarkUtilities.compare(targetElementsofSource.get(i).getiMarker(), beDeleted)) {
                targetElementsofSource.remove(i);
              }
            }
            MarkUtilities.setTargetList(groupSourceMarker, targetElementsofSource);

            if (groupSourceMarker.getType().equals(MarkerFactory.MARKER_MAPPING)
                && targetElementsofSource.size() == 0) {
              // final IEditorPart part =
              IDE.openEditor(MarkerActivator.getActiveWorkbenchWindow().getActivePage(),
                  groupSourceMarker, false);
              final Map<String, Object> attributes = groupSourceMarker.getAttributes();
              final IResource res = groupSourceMarker.getResource();
              AnnotationFactory.removeAnnotation(groupSourceMarker);
              groupSourceMarker.delete();
              MarkerUtilities.createMarker(res, attributes, MarkerFactory.MARKER_MARKING);
              final IMarker newMarker = MarkerFactory.findMarkerBySourceId(res,
                  (String) attributes.get(IMarker.SOURCE_ID));
              AnnotationFactory.addAnnotation(newMarker, AnnotationFactory.ANNOTATION_MARKING);
            }
          }
        }
      }
    }
  } catch (final CoreException e) {
    e.printStackTrace();
  }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CorrectionMarkerResolutionGenerator.java   
private static boolean internalHasResolutions(IMarker marker) {
    int id= marker.getAttribute(IJavaModelMarker.ID, -1);
    ICompilationUnit cu= getCompilationUnit(marker);
    return cu != null && JavaCorrectionProcessor.hasCorrections(cu, id, MarkerUtilities.getMarkerType(marker));
}
项目:birt    文件:ReportXMLSourceEditorFormPage.java   
public boolean selectReveal( Object marker )
{
    int start = MarkerUtilities.getCharStart( (IMarker) marker );
    int end = MarkerUtilities.getCharEnd( (IMarker) marker );

    boolean selectLine = start < 0 || end < 0;

    // look up the current range of the marker when the document has been
    // edited
    IAnnotationModel model = reportXMLEditor.getDocumentProvider( )
            .getAnnotationModel( reportXMLEditor.getEditorInput( ) );
    if ( model instanceof AbstractMarkerAnnotationModel )
    {
        AbstractMarkerAnnotationModel markerModel = (AbstractMarkerAnnotationModel) model;
        Position pos = markerModel.getMarkerPosition( (IMarker) marker );
        if ( pos != null )
        {
            if ( !pos.isDeleted( ) )
            {
                // use position instead of marker values
                start = pos.getOffset( );
                end = pos.getOffset( ) + pos.getLength( );
            }
            else
            {
                return false;
            }
        }
    }

    IDocument document = reportXMLEditor.getDocumentProvider( )
            .getDocument( reportXMLEditor.getEditorInput( ) );
    if ( selectLine )
    {
        int line;
        try
        {
            if ( start >= 0 )
                line = document.getLineOfOffset( start );
            else
            {
                line = MarkerUtilities.getLineNumber( (IMarker) marker );
                // Marker line numbers are 1-based
                if ( line >= 1 )
                {
                    line--;
                }
                start = document.getLineOffset( line );
            }
            end = start + document.getLineLength( line ) - 1;
        }
        catch ( BadLocationException e )
        {
            return false;
        }
    }

    int length = document.getLength( );
    if ( end - 1 < length && start < length )
        reportXMLEditor.selectAndReveal( start, end - start );
    return true;
}
项目:ncl30-eclipse    文件:MarkingErrorHandler.java   
protected XMLValidationError nextError(SAXParseException e, boolean isFatal) {

        XMLValidationError validationError = super.nextError(e, isFatal);

        Map <String, Object> map = new HashMap <String, Object> ();
        int lineNumber = e.getLineNumber();
        int columnNumber = e.getColumnNumber();
        MarkerUtilities.setLineNumber(map, lineNumber);
        Object[] tmp = { e.getMessage() };


        MarkerUtilities.setMessage(map, NCLEditorMessages.getInstance()
                .getString("NCLValidator.Error.XMLParserError", tmp));

        map.put(IMarker.LOCATION, file.getFullPath().toString());

        Integer charStart = getCharStart(lineNumber, columnNumber);

        if (charStart != null)
            map.put(IMarker.CHAR_START, charStart);

        Integer charEnd = getCharEnd(lineNumber, columnNumber);
        if (charEnd != null)
            map.put(IMarker.CHAR_END, charEnd);

        map.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));

        MessagesUtilities.put(NCLEditorMessages.getInstance()
                .getString("NCLValidator.Error.XMLParserError", tmp), null);

        map.put(MarkingErrorHandler.NCLValidatorMessage, NCLEditorMessages.getInstance()
                .getString("NCLValidator.Error.XMLParserError", tmp) );

        map.put(MarkingErrorHandler.NCLSourceDocument, document.get());

        try {
            MarkerUtilities.createMarker(file, map, NCLMarkerError);

        } catch (CoreException ee) {
            ee.printStackTrace();

        }

        return validationError;

    }