コード例 #1
0
  private void expectDiagnostic(
      Kind kind, String message, @Nullable String source, long start, long end, long col)
      throws IOException {

    expect(diagnostic.getKind()).andReturn(kind);
    expect(diagnostic.getMessage(EasyMock.<Locale>notNull())).andReturn(message);
    expect(diagnostic.getSource()).andReturn(file).anyTimes();
    expect(diagnostic.getStartPosition()).andReturn(start).anyTimes();
    expect(diagnostic.getEndPosition()).andReturn(end).anyTimes();
    expect(diagnostic.getColumnNumber()).andReturn(col).anyTimes();
    expect(file.getCharContent(anyBoolean())).andReturn(source).anyTimes();
  }
コード例 #2
0
 public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
   final CompilerMessage.Kind kind;
   switch (diagnostic.getKind()) {
     case ERROR:
       kind = BuildMessage.Kind.ERROR;
       myErrorCount++;
       break;
     case MANDATORY_WARNING:
     case WARNING:
     case NOTE:
       kind = BuildMessage.Kind.WARNING;
       myWarningCount++;
       break;
     default:
       kind = BuildMessage.Kind.INFO;
   }
   File sourceFile = null;
   try {
     // for eclipse compiler just an attempt to call getSource() may lead to an NPE,
     // so calling this method under try/catch to avoid induced compiler errors
     final JavaFileObject source = diagnostic.getSource();
     sourceFile = source != null ? Utils.convertToFile(source.toUri()) : null;
   } catch (Exception e) {
     LOG.info(e);
   }
   final String srcPath =
       sourceFile != null ? FileUtil.toSystemIndependentName(sourceFile.getPath()) : null;
   String message = diagnostic.getMessage(Locale.US);
   if (Utils.IS_TEST_MODE) {
     LOG.info(message);
   }
   myContext.processMessage(
       new CompilerMessage(
           BUILDER_NAME,
           kind,
           message,
           srcPath,
           diagnostic.getStartPosition(),
           diagnostic.getEndPosition(),
           diagnostic.getPosition(),
           diagnostic.getLineNumber(),
           diagnostic.getColumnNumber()));
 }
コード例 #3
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();
          }
        }
      }
    }
  }