private void printProblemXML(IMarker marker, Document doc, StringBuilder sb)
      throws JavaModelException, CoreException {
    Object[] attribs = marker.getAttributes(MARKER_ATTRIBUTES);
    String problemType;
    int lineNumber = 0;
    int startOfLine = 0;
    int lineLength = 0;
    String lineOfCode = "";
    try {
      lineNumber = Integer.parseInt(attribs[1].toString()) - 1;
      startOfLine = doc.getLineOffset(lineNumber);
      lineLength = doc.getLineLength(lineNumber);
      lineOfCode = doc.get(startOfLine, lineLength);
    } catch (NumberFormatException e) {
      e.printStackTrace(Constants.writer);
    } catch (BadLocationException e) {
      e.printStackTrace(Constants.writer);
    }

    if (attribs[0].equals(IMarker.SEVERITY_ERROR)) problemType = "ERROR";
    else if (attribs[0].equals(IMarker.SEVERITY_WARNING)) problemType = "WARNING";
    else problemType = "INFORMATION";

    sb.append("<" + problemType + ">");
    sb.append("<LINE>" + attribs[1] + "</LINE>");
    sb.append("<MESSAGE>" + attribs[2] + "</MESSAGE>");
    sb.append("<CODELINE>" + lineOfCode.trim() + "</CODELINE>");
    sb.append("</" + problemType + ">");
  }
 /**
  * This method is here for use by the SABER validator's reporter instance ONLY. Do not use. See
  * defect 260144 for details.
  */
 @SuppressWarnings("unchecked")
 public static IMarker setPriority(IMarker item, int priority) throws CoreException {
   Map attrib = item.getAttributes();
   attrib.put(IMarker.PRIORITY, new Integer(priority));
   item.setAttributes(attrib);
   return item;
 }
Exemple #3
0
 /**
  * Gets a string representation of marker
  *
  * @param marker The marker instance
  * @return Readable description of the marker
  */
 @SuppressWarnings("unchecked")
 protected String getDescription(IMarker marker) {
   try {
     HashMap<String, Object> map = new HashMap<String, Object>();
     map.put("resource", marker.getResource().getName());
     map.put("type", marker.getType());
     map.put("attributes", new HashMap<String, Object>(marker.getAttributes()).toString());
     return map.toString();
   } catch (CoreException e) {
     throw new RuntimeException(e);
   }
 }