use of org.eclipse.jdt.internal.core.util.CommentRecorderParser in project spoon by INRIA.
the class JDTBatchCompiler method getUnits.
/**
* Calls JDT to retrieve the list of compilation unit declarations.
* Depends on the actual implementation of {@link #getCompilationUnits()}
*/
public CompilationUnitDeclaration[] getUnits() {
startTime = System.currentTimeMillis();
INameEnvironment environment = this.jdtCompiler.environment;
if (environment == null) {
environment = getLibraryAccess();
}
CompilerOptions compilerOptions = new CompilerOptions(this.options);
compilerOptions.parseLiteralExpressionsAsConstants = false;
IErrorHandlingPolicy errorHandlingPolicy;
if (jdtCompiler.getEnvironment().getNoClasspath()) {
// in no classpath, we should proceed on error,
// as we will encounter some
errorHandlingPolicy = new IErrorHandlingPolicy() {
@Override
public boolean proceedOnErrors() {
return true;
}
@Override
public boolean stopOnFirstError() {
return false;
}
// we cannot ignore them, because JDT will continue its process
// and it led to NPE in several places
@Override
public boolean ignoreAllErrors() {
return false;
}
};
} else {
// when there is a classpath, we should not have any error
errorHandlingPolicy = new IErrorHandlingPolicy() {
@Override
public boolean proceedOnErrors() {
return false;
}
// we wait for all errors to be gathered before stopping
@Override
public boolean stopOnFirstError() {
return false;
}
@Override
public boolean ignoreAllErrors() {
return false;
}
};
}
TreeBuilderCompiler treeBuilderCompiler = new TreeBuilderCompiler(environment, errorHandlingPolicy, compilerOptions, this.jdtCompiler.requestor, getProblemFactory(), this.out, null);
if (jdtCompiler.getEnvironment().getNoClasspath()) {
treeBuilderCompiler.lookupEnvironment.mayTolerateMissingType = true;
}
// they have to be done all at once
final CompilationUnitDeclaration[] result = treeBuilderCompiler.buildUnits(getCompilationUnits());
// now adding the doc
if (jdtCompiler.getEnvironment().isCommentsEnabled()) {
// compile comments only if they are needed
for (int i = 0; i < result.length; i++) {
CompilationUnitDeclaration unit = result[i];
CommentRecorderParser parser = new CommentRecorderParser(new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new DefaultProblemFactory(Locale.getDefault())), false);
// reuse the source compilation unit
ICompilationUnit sourceUnit = unit.compilationResult.compilationUnit;
final CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit);
CompilationUnitDeclaration tmpDeclForComment = parser.dietParse(sourceUnit, compilationResult);
unit.comments = tmpDeclForComment.comments;
}
}
return result;
}
Aggregations