/* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */
  public void selectionChanged(SelectionChangedEvent event) {

    RuleViolation violation = selectedViolationFrom(event);
    if (violation == null) return;

    String varName = violation.getVariableName();
    if (StringUtil.isEmpty(varName)) return;

    int beginLine = violation.getBeginLine();
    int endLine = violation.getEndLine();

    if (beginLine != 0 && endLine != 0) {
      try {
        int offset = getDocument().getLineOffset(violation.getBeginLine() - 1);
        int length = getDocument().getLineOffset(violation.getEndLine()) - offset;
        highlight(offset, length);
      } catch (BadLocationException ble) {
        logError(
            StringKeys.ERROR_RUNTIME_EXCEPTION + "Exception when selecting a line in the editor",
            ble);
      }

      // showMethodToMarker(marker);
      showMethodToViolation(violation);

      // then we calculate and color _a possible_ Path
      // for this Error in the Dataflow
      DataflowGraph graph = graphViewer.getGraph();
      if (!graphViewer.isDisposed() && graph != null) {
        graph.markPath(beginLine, endLine, varName);
      }
    }
  }
Ejemplo n.º 2
0
  /** Generates a html table with violation information. */
  private String displayRuleViolation(RuleViolation vio) {

    StringBuilder sb = new StringBuilder(200);
    sb.append("<table border=\"0\">");
    renderViolationRow(sb, "Rule:", vio.getRule().getName());
    renderViolationRow(sb, "Description:", vio.getDescription());

    if (StringUtil.isNotEmpty(vio.getVariableName())) {
      renderViolationRow(sb, "Variable:", vio.getVariableName());
    }

    if (vio.getEndLine() > 0) {
      renderViolationRow(sb, "Line:", vio.getEndLine() + " and " + vio.getBeginLine());
    } else {
      renderViolationRow(sb, "Line:", Integer.toString(vio.getBeginLine()));
    }

    sb.append("</table>");
    return sb.toString();
  }
Ejemplo n.º 3
0
  private MarkerInfo2 getMarkerInfo(RuleViolation violation, String type)
      throws PropertiesException {

    Rule rule = violation.getRule();

    MarkerInfo2 info = new MarkerInfo2(type, 7);

    info.add(IMarker.MESSAGE, violation.getDescription());
    info.add(IMarker.LINE_NUMBER, violation.getBeginLine());
    info.add(PMDRuntimeConstants.KEY_MARKERATT_LINE2, violation.getEndLine());
    info.add(PMDRuntimeConstants.KEY_MARKERATT_RULENAME, rule.getName());
    info.add(PMDRuntimeConstants.KEY_MARKERATT_PRIORITY, rule.getPriority().getPriority());

    switch (rule.getPriority().getPriority()) {
      case 1:
        info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
        info.add(
            IMarker.SEVERITY,
            projectProperties.violationsAsErrors()
                ? IMarker.SEVERITY_ERROR
                : IMarker.SEVERITY_WARNING);
        break;
      case 2:
        if (projectProperties.violationsAsErrors()) {
          info.add(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
        } else {
          info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
          info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
        }
        break;

      case 5:
        info.add(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
        break;

      case 3:
        info.add(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
      case 4:
      default:
        info.add(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
        break;
    }

    return info;
  }