@@ -375,6 +375,12 @@ public CompilationUnitDeclaration parse(ICompilationUnit sourceUnit,
375
375
}
376
376
}
377
377
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
+
378
384
private class CompilerImpl extends Compiler {
379
385
private TreeLogger logger ;
380
386
private int abortCount = 0 ;
@@ -418,11 +424,19 @@ public void process(CompilationUnitDeclaration cud, int i) {
418
424
String filename = new String (cud .getFileName ());
419
425
logger .log (TreeLogger .Type .ERROR ,
420
426
"JDT aborted: " + filename + ": " + e .problem .getMessage ());
427
+ if (abortCount >= ABORT_COUNT_MAX ) {
428
+ throw e ;
429
+ }
421
430
return ; // continue without it; it might be a server-side class.
422
431
} catch (RuntimeException e ) {
432
+ abortCount ++;
433
+ String filename = new String (cud .getFileName ());
423
434
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.
426
440
}
427
441
ClassFile [] classFiles = cud .compilationResult ().getClassFiles ();
428
442
Map <ClassFile , CompiledClass > results = new LinkedHashMap <ClassFile , CompiledClass >();
@@ -459,6 +473,10 @@ private void createCompiledClass(ClassFile classFile, Map<ClassFile, CompiledCla
459
473
internalName );
460
474
results .put (classFile , result );
461
475
}
476
+
477
+ int getAbortCount () {
478
+ return abortCount ;
479
+ }
462
480
}
463
481
464
482
/**
@@ -922,15 +940,17 @@ public void doCompile(TreeLogger logger, Collection<CompilationUnitBuilder> buil
922
940
try {
923
941
compilerImpl .compile (icus .toArray (new ICompilationUnit [icus .size ()]));
924
942
} catch (AbortCompilation e ) {
943
+ final String compilerAborted = String .format ("JDT compiler aborted after %d errors" ,
944
+ compilerImpl .getAbortCount ());
925
945
if (e .problem == null ) {
926
- logger .log (TreeLogger .Type .ERROR , "JDT compiler aborted " );
946
+ logger .log (TreeLogger .Type .ERROR , compilerAborted + ". " );
927
947
} 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 ());
929
949
} else {
930
950
String filename = new String (e .problem .getOriginatingFileName ());
931
951
TreeLogger branch = logger .branch (TreeLogger .Type .ERROR ,
932
952
"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 ());
934
954
}
935
955
throw new UnableToCompleteException ();
936
956
} finally {
0 commit comments