Java Code Examples for org.eclipse.jdt.internal.compiler.CompilationResult#hasProblems()

The following examples show how to use org.eclipse.jdt.internal.compiler.CompilationResult#hasProblems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public ICompilerRequestor getBatchRequestor() {
	return new ICompilerRequestor() {
		int lineDelta = 0;
		public void acceptResult(CompilationResult compilationResult) {
			if (compilationResult.lineSeparatorPositions != null) {
				int unitLineCount = compilationResult.lineSeparatorPositions.length;
				this.lineDelta += unitLineCount;
				if (Main.this.showProgress && this.lineDelta > 2000) {
					// in -log mode, dump a dot every 2000 lines compiled
					Main.this.logger.logProgress();
					this.lineDelta = 0;
				}
			}
			Main.this.logger.startLoggingSource(compilationResult);
			if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
				Main.this.logger.logProblems(compilationResult.getAllProblems(), compilationResult.compilationUnit.getContents(), Main.this);
			}
			outputClassFiles(compilationResult);
			Main.this.logger.endLoggingSource();
		}
	};
}
 
Example 2
Source File: CompilerJdt.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void acceptResult(CompilationResult result) {
  if (result == null) {
    return; // ah?
  }

  final String sourceName = new String(result.getFileName());
  final File sourceFile = new File(sourceName);

  Resource<File> input = context.getProcessedSource(sourceFile);

  // track type references
  if (result.rootReferences != null && result.qualifiedReferences != null && result.simpleNameReferences != null) {
    context.setAttribute(input.getResource(), ATTR_REFERENCES, new ReferenceCollection(result.rootReferences, result.qualifiedReferences, result.simpleNameReferences));
  }

  if (result.hasProblems()) {
    for (CategorizedProblem problem : result.getProblems()) {
      if (problem.isError() || isShowWarnings()) {
        MessageSeverity severity = problem.isError() ? MessageSeverity.ERROR : MessageSeverity.WARNING;
        input.addMessage(problem.getSourceLineNumber(), ((DefaultProblem) problem).column, problem.getMessage(), severity, null /* cause */);
      }
    }
  }

  try {
    if (!result.hasErrors() && !isProcOnly()) {
      for (ClassFile classFile : result.getClassFiles()) {
        char[] filename = classFile.fileName();
        int length = filename.length;
        char[] relativeName = new char[length + 6];
        System.arraycopy(filename, 0, relativeName, 0, length);
        System.arraycopy(SuffixConstants.SUFFIX_class, 0, relativeName, length, 6);
        CharOperation.replace(relativeName, '/', File.separatorChar);
        String relativeStringName = new String(relativeName);
        writeClassFile(input, relativeStringName, classFile);
      }
    }
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  // XXX double check affected sources are recompiled when this source has errors
}