Skip to content
This repository was archived by the owner on Sep 26, 2020. It is now read-only.

Commit 4747eaa

Browse files
committed
Allow GWT to continue even in presence of internal JDT compiler Errors.
Change-Id: Id7df86271fc64ac75e0857d17e557e79d870854a
1 parent b919270 commit 4747eaa

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ public CompilationUnitDeclaration parse(ICompilationUnit sourceUnit,
375375
}
376376
}
377377

378+
/**
379+
* Maximum number of JDT compiler errors or abort requests before it actually returns
380+
* a fatal error to the user.
381+
*/
382+
private static final double ABORT_COUNT_MAX = 100;
383+
378384
private class CompilerImpl extends Compiler {
379385
private TreeLogger logger;
380386
private int abortCount = 0;
@@ -418,11 +424,19 @@ public void process(CompilationUnitDeclaration cud, int i) {
418424
String filename = new String(cud.getFileName());
419425
logger.log(TreeLogger.Type.ERROR,
420426
"JDT aborted: " + filename + ": " + e.problem.getMessage());
427+
if (abortCount >= ABORT_COUNT_MAX) {
428+
throw e;
429+
}
421430
return; // continue without it; it might be a server-side class.
422431
} catch (RuntimeException e) {
432+
abortCount++;
433+
String filename = new String(cud.getFileName());
423434
logger.log(TreeLogger.Type.ERROR,
424-
"JDT died after " + abortCount + " previous errors", e);
425-
throw new AbortCompilation(cud.compilationResult, e);
435+
"JDT threw an exception: " + filename + ": " + e);
436+
if (abortCount >= ABORT_COUNT_MAX) {
437+
throw new AbortCompilation(cud.compilationResult, e);
438+
}
439+
return; // continue without it; it might be a server-side class.
426440
}
427441
ClassFile[] classFiles = cud.compilationResult().getClassFiles();
428442
Map<ClassFile, CompiledClass> results = new LinkedHashMap<ClassFile, CompiledClass>();
@@ -459,6 +473,10 @@ private void createCompiledClass(ClassFile classFile, Map<ClassFile, CompiledCla
459473
internalName);
460474
results.put(classFile, result);
461475
}
476+
477+
int getAbortCount() {
478+
return abortCount;
479+
}
462480
}
463481

464482
/**
@@ -922,15 +940,17 @@ public void doCompile(TreeLogger logger, Collection<CompilationUnitBuilder> buil
922940
try {
923941
compilerImpl.compile(icus.toArray(new ICompilationUnit[icus.size()]));
924942
} catch (AbortCompilation e) {
943+
final String compilerAborted = String.format("JDT compiler aborted after %d errors",
944+
compilerImpl.getAbortCount());
925945
if (e.problem == null) {
926-
logger.log(TreeLogger.Type.ERROR, "JDT compiler aborted");
946+
logger.log(TreeLogger.Type.ERROR, compilerAborted + ".");
927947
} else if (e.problem.getOriginatingFileName() == null) {
928-
logger.log(TreeLogger.Type.ERROR, "JDT compiler aborted: " + e.problem.getMessage());
948+
logger.log(TreeLogger.Type.ERROR, compilerAborted + ": " + e.problem.getMessage());
929949
} else {
930950
String filename = new String(e.problem.getOriginatingFileName());
931951
TreeLogger branch = logger.branch(TreeLogger.Type.ERROR,
932952
"At " + filename + ": " + e.problem.getSourceLineNumber());
933-
branch.log(TreeLogger.Type.ERROR, "JDT compiler aborted: " + e.problem.getMessage());
953+
branch.log(TreeLogger.Type.ERROR, compilerAborted + ": " + e.problem.getMessage());
934954
}
935955
throw new UnableToCompleteException();
936956
} finally {

0 commit comments

Comments
 (0)