File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
src/main/java/anthonisen/felix/astParsing Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 11package anthonisen .felix .astParsing ;
22
33import com .github .javaparser .ast .CompilationUnit ;
4+ import com .github .javaparser .ast .PackageDeclaration ;
5+ import com .github .javaparser .ast .expr .Name ;
46import com .github .javaparser .utils .CodeGenerationUtils ;
57import com .github .javaparser .utils .SourceRoot ;
68
@@ -53,6 +55,7 @@ public void makeCovariant(String cls) {
5355
5456 for (File file : dir .listFiles ()) {
5557 CompilationUnit cu = sourceRoot .parse ("" , file .getName ());
58+ changePackageDeclaration (cu );
5659 Set <Pair <String , String >> varsToWatch = new HashSet <>();
5760 cu .accept (new VariableCollector (classesToWatch ), varsToWatch );
5861 cu .accept (new TypeEraserVisitor (classesToWatch ), null );
@@ -69,4 +72,13 @@ public void applyChanges() {
6972 this .sourceRoot .saveAll (
7073 CodeGenerationUtils .mavenModuleRoot (Covariancer .class ).resolve (Paths .get (sourceFolder + "/output" )));
7174 }
75+
76+ public SourceRoot getSourceRoot () {
77+ return sourceRoot ;
78+ }
79+
80+ private void changePackageDeclaration (CompilationUnit cu ) {
81+ String newPackageName = cu .getPackageDeclaration ().get ().getNameAsString () + ".output" ;
82+ cu .setPackageDeclaration (new PackageDeclaration (new Name (newPackageName )));
83+ }
7284}
You can’t perform that action at this time.
0 commit comments