2020import java .util .HashSet ;
2121import java .util .Map ;
2222import java .util .Set ;
23+ import javax .annotation .processing .Messager ;
24+ import javax .tools .Diagnostic .Kind ;
2325
2426public class Covariancer {
27+ private Messager messager ;
28+ private String sourceFolder ;
29+ private SourceRoot sourceRoot ;
2530
26- public void makeCovariant () {
27- String sourceFolder = "example" ;
28- SourceRoot sourceRoot = new SourceRoot (
31+ public Covariancer (Messager messager , String sourceFolder ) {
32+ this .messager = messager ;
33+ this .sourceFolder = sourceFolder ;
34+ sourceRoot = new SourceRoot (
2935 CodeGenerationUtils .mavenModuleRoot (Covariancer .class ).resolve (sourceFolder ));
36+ }
37+
38+ public void makeCovariant (String cls ) {
39+ messager .printMessage (Kind .NOTE , "Now parsing AST's" );
3040 MethodCollector collector = new MethodCollector (Arrays .asList ("T" ));
3141 Map <String , MethodData > methodMap = new HashMap <>();
3242 Set <ClassData > classesToWatch = new HashSet <>();
33- sourceRoot .parse ("" , "Herd.java" ).accept (collector , methodMap );
43+ sourceRoot .parse ("" , cls ).accept (collector , methodMap );
3444
3545 File dir = Paths .get (sourceFolder ).toFile ();
3646 assert dir .exists ();
@@ -52,6 +62,11 @@ public void makeCovariant() {
5262
5363 }
5464 }
55- sourceRoot .saveAll (CodeGenerationUtils .mavenModuleRoot (Covariancer .class ).resolve (Paths .get ("output" )));
65+
66+ }
67+
68+ public void applyChanges () {
69+ this .sourceRoot .saveAll (
70+ CodeGenerationUtils .mavenModuleRoot (Covariancer .class ).resolve (Paths .get (sourceFolder + "/output" )));
5671 }
57- }
72+ }
0 commit comments