コード例 #1
0
ファイル: T7086261.java プロジェクト: mioyoytu/OpenJML
 public void report(Diagnostic message) {
   if (!(message instanceof DiagnosticSourceUnwrapper)) {
     throw new AssertionError("Wrapped diagnostic expected!");
   }
   String actual = message.toString();
   JCDiagnostic jd = (JCDiagnostic) ((DiagnosticSourceUnwrapper) message).d;
   String expected = jd.toString();
   if (!actual.equals(expected)) {
     throw new AssertionError("expected = " + expected + "\nfound = " + actual);
   }
 }
コード例 #2
0
  public static Set<TestDiagnostic> fromJavaxDiagnosticList(
      List<Diagnostic<? extends JavaFileObject>> javaxDiagnostics, boolean noMsgText) {
    Set<TestDiagnostic> diagnostics = new LinkedHashSet<>(javaxDiagnostics.size());

    for (Diagnostic<? extends JavaFileObject> diagnostic : javaxDiagnostics) {
      // See TestDiagnosticUtils as to why we use diagnostic.toString rather
      // than convert from the diagnostic itself
      final String diagnosticString = diagnostic.toString();

      // suppress Xlint warnings
      if (diagnosticString.contains("uses unchecked or unsafe operations.")
          || diagnosticString.contains("Recompile with -Xlint:unchecked for details.")
          || diagnosticString.endsWith(" declares unsafe vararg methods.")
          || diagnosticString.contains("Recompile with -Xlint:varargs for details.")) continue;

      diagnostics.add(TestDiagnosticUtils.fromJavaxToolsDiagnostic(diagnosticString, noMsgText));
    }

    return diagnostics;
  }
コード例 #3
0
ファイル: JavaSourceClassLoader.java プロジェクト: Bio7/bio7
 public DiagnosticException(Diagnostic<? extends JavaFileObject> diagnostic) {
   super(diagnostic.toString());
 }
コード例 #4
0
ファイル: JavaSourceClassLoader.java プロジェクト: Bio7/bio7
  private void markError(
      DiagnosticCollector<JavaFileObject> diagnosticsCollector, boolean markerCreation) {

    for (Diagnostic diagnostic : diagnosticsCollector.getDiagnostics()) {
      System.out.format("Error on line %d" + " -> ", diagnostic.getLineNumber(), diagnostic);
      System.out.println(diagnostic.getMessage(null) + "\n");
      System.err.println("*** " + diagnostic.toString() + " *** " + diagnostic.getCode());
      JavaFileObject source = (JavaFileObject) diagnostic.getSource();
      String longFileName = source == null ? null : source.toUri().getPath();
      // String shortFileName = source == null ? null : source.getName();

      // System.out.println("Error in: " + longFileName);
      // Path path = new Path(longFileName);
      // IFile ifile =
      // ResourcesPlugin.getWorkspace().getRoot().getFile(path);
      if (diagnostic.getLineNumber() > -1) {
        File fileToOpen = new File(longFileName);

        if (fileToOpen.exists() && fileToOpen.isFile()) {
          final IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());

          Display display = PlatformUI.getWorkbench().getDisplay();
          display.syncExec(
              new Runnable() {

                public void run() {

                  try {
                    IEditorPart part = IDE.openEditorOnFileStore(pag, fileStore);

                    if (part != null) {
                      IEditorInput input = part.getEditorInput();
                      ifile = ((IFileEditorInput) input).getFile();

                      // ... use activeProjectName
                    }

                  } catch (PartInitException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }
              });

        } else {
          // Do something if the file does not exist
        }
      }

      // System.out.format("Error on line %d in %s"+"\n",
      // diagnostic.getLineNumber(), diagnostic);
      if (markerCreation == true) {
        int lnr = (int) diagnostic.getLineNumber();
        int startPos = (int) diagnostic.getStartPosition();
        int stopPos = (int) diagnostic.getEndPosition();
        if (ifile != null) {
          IMarker marker;
          try {
            marker = ifile.createMarker(IMarker.PROBLEM);
            marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
            marker.setAttribute(IMarker.MESSAGE, diagnostic.getMessage(null));
            marker.setAttribute(IMarker.LINE_NUMBER, lnr);
            // if (pos.offset != 0) {
            // System.out.println(startPos);
            // System.out.println(stopPos);

            marker.setAttribute(IMarker.CHAR_START, startPos);
            marker.setAttribute(IMarker.CHAR_END, stopPos - 1);
          } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
    }
  }