1010import java .io .File ;
1111import java .io .IOException ;
1212import java .util .ArrayList ;
13- import java .util .Arrays ;
1413import java .util .Collection ;
14+ import java .util .Collections ;
1515import java .util .EnumSet ;
1616import java .util .HashSet ;
1717import java .util .List ;
@@ -57,7 +57,7 @@ public enum Library {
5757
5858 private final String name ;
5959
60- private Library (String name ) {
60+ Library (String name ) {
6161 this .name = name ;
6262 }
6363
@@ -82,7 +82,7 @@ public String getName() {
8282 PROCESSOR_OUT_DIR = new File ( TARGET_DIR , "processor-generated-test-classes" );
8383 if ( !PROCESSOR_OUT_DIR .exists () ) {
8484 if ( !PROCESSOR_OUT_DIR .mkdirs () ) {
85- fail ( "Unable to create test output directory " + PROCESSOR_OUT_DIR . toString () );
85+ fail ( "Unable to create test output directory " + PROCESSOR_OUT_DIR );
8686 }
8787 }
8888 }
@@ -163,7 +163,23 @@ public boolean compile(Processor annotationProcessor, DiagnosticCollector<JavaFi
163163 EnumSet <Library > dependencies , File ... sourceFiles ) {
164164 StandardJavaFileManager fileManager = compiler .getStandardFileManager ( null , null , null );
165165 Iterable <? extends JavaFileObject > compilationUnits = fileManager .getJavaFileObjects ( sourceFiles );
166- List <String > options = new ArrayList <String >();
166+ try {
167+ fileManager .setLocation ( StandardLocation .CLASS_PATH , getDependenciesAsFiles ( dependencies ) );
168+ fileManager .setLocation ( StandardLocation .CLASS_OUTPUT , Collections .singletonList ( PROCESSOR_OUT_DIR ) );
169+ }
170+ catch (IOException e ) {
171+ throw new RuntimeException ( e );
172+ }
173+
174+ final List <String > options = extractOptions ( diagnosticKind , verbose , allowMethodConstraints );
175+ CompilationTask task = compiler .getTask ( null , fileManager , diagnostics , options , null , compilationUnits );
176+ task .setProcessors ( Collections .singletonList ( annotationProcessor ) );
177+
178+ return task .call ();
179+ }
180+
181+ private static List <String > extractOptions (Kind diagnosticKind , Boolean verbose , Boolean allowMethodConstraints ) {
182+ final List <String > options = new ArrayList <>();
167183
168184 if ( diagnosticKind != null ) {
169185 options .add ( StringHelper .format ( "-A%s=%s" , Configuration .DIAGNOSTIC_KIND_PROCESSOR_OPTION , diagnosticKind ) );
@@ -174,27 +190,9 @@ public boolean compile(Processor annotationProcessor, DiagnosticCollector<JavaFi
174190 }
175191
176192 if ( allowMethodConstraints != null ) {
177- options .add (
178- StringHelper .format (
179- "-A%s=%b" ,
180- Configuration .METHOD_CONSTRAINTS_SUPPORTED_PROCESSOR_OPTION ,
181- allowMethodConstraints
182- )
183- );
193+ options .add ( StringHelper .format ( "-A%s=%b" , Configuration .METHOD_CONSTRAINTS_SUPPORTED_PROCESSOR_OPTION , allowMethodConstraints ) );
184194 }
185-
186- try {
187- fileManager .setLocation ( StandardLocation .CLASS_PATH , getDependenciesAsFiles ( dependencies ) );
188- fileManager .setLocation ( StandardLocation .CLASS_OUTPUT , Arrays .asList ( PROCESSOR_OUT_DIR ) );
189- }
190- catch (IOException e ) {
191- throw new RuntimeException ( e );
192- }
193-
194- CompilationTask task = compiler .getTask ( null , fileManager , diagnostics , options , null , compilationUnits );
195- task .setProcessors ( Arrays .asList ( annotationProcessor ) );
196-
197- return task .call ();
195+ return options ;
198196 }
199197
200198 /**
@@ -226,7 +224,7 @@ private static Set<DiagnosticExpectation> asExpectations(Collection<Diagnostic<?
226224 }
227225
228226 private Set <File > getDependenciesAsFiles (EnumSet <Library > dependencies ) {
229- Set <File > files = new HashSet <File >();
227+ Set <File > files = new HashSet <>();
230228
231229 for ( Library oneDependency : dependencies ) {
232230 files .add ( new File ( testLibraryDir + File .separator + oneDependency .getName () ) );
0 commit comments