public void add(Diagnostic diagnostic) {
   if (diagnostic == null) return;
   List<Diagnostic> kids = diagnostic.getChildren();
   if (!kids.isEmpty()) {
     for (Diagnostic kid : kids) add(kid);
   } else {
     List<?> objects = diagnostic.getData();
     CSTNode cstNode = null;
     if (!objects.isEmpty()) {
       Object object = objects.get(0);
       if (object != null) {
         if (environment != null) cstNode = environment.getASTMapping(object);
         else if (object instanceof CSTNode) cstNode = (CSTNode) object;
       }
     }
     int startOffset = cstNode != null ? cstNode.getStartOffset() : 0;
     int endOffset = cstNode != null ? cstNode.getEndOffset() : 0;
     Severity problemSeverity = Severity.INFO;
     if (diagnostic.getSeverity() >= Diagnostic.ERROR) problemSeverity = Severity.ERROR;
     else if (diagnostic.getSeverity() >= Diagnostic.WARNING) problemSeverity = Severity.WARNING;
     String problemMessage = diagnostic.getMessage();
     String problemContext = diagnostic.getSource();
     handleProblem(problemSeverity, problemMessage, problemContext, startOffset, endOffset);
   }
 }
  protected boolean adjustMarker(IMarker marker, Diagnostic diagnostic) throws CoreException {
    if (diagnostic.getData() != null) {
      for (Object element : diagnostic.getData()) {
        if (element instanceof Resource.Diagnostic) {
          Resource.Diagnostic resourceDiagnostic = (Resource.Diagnostic) element;
          if (resourceDiagnostic.getLocation() != null) {
            marker.setAttribute(
                IMarker.LOCATION,
                EMFEditUIPlugin.getPlugin()
                    .getString(
                        "_UI_MarkerLocation",
                        new String[] {
                          Integer.toString(resourceDiagnostic.getLine()),
                          Integer.toString(resourceDiagnostic.getColumn())
                        }));

            marker.setAttribute(IMarker.LINE_NUMBER, resourceDiagnostic.getLine());
            return true;
          }
        }
      }
    }
    return false;
  }
예제 #3
0
  protected Diagnostic findProblem(Diagnostic diagnostic, EObject target) {
    if (ExpressionsValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource())
        && (diagnostic.getSeverity() != Diagnostic.OK)
        && diagnostic.getData().contains(target)) {
      return diagnostic;
    }

    for (Diagnostic child : diagnostic.getChildren()) {
      Diagnostic result = findProblem(child, target);

      if (result != null) {
        return result;
      }
    }

    return null;
  }