Skip to content

Commit

Permalink
rename astmanipulator class
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixAnthonisen committed Oct 28, 2024
1 parent 22f61c3 commit 3948673
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/anthonisen/felix/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package anthonisen.felix;

import anthonisen.felix.astParsing.Covariancer;
import anthonisen.felix.astParsing.AstManipulator;

import javax.annotation.processing.Messager;
import javax.lang.model.element.AnnotationMirror;
Expand All @@ -10,7 +10,7 @@

class Main {
public static void main(String[] args) {
Covariancer manip = new Covariancer(new StdoutMessager(), "example");
AstManipulator manip = new AstManipulator(new StdoutMessager(), "example");
manip.eraseTypesAndInsertCasts("Herd.java", "", "T");
manip.applyChanges();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import javax.lang.model.element.TypeParameterElement;
import javax.tools.Diagnostic.Kind;
import com.google.auto.service.AutoService;
import anthonisen.felix.astParsing.Covariancer;
import anthonisen.felix.astParsing.AstManipulator;
import anthonisen.felix.astParsing.util.TypeHandler;
import anthonisen.felix.astParsing.visitors.ParameterTypeCollector;
import anthonisen.felix.astParsing.visitors.ReturnTypeCollector;
Expand All @@ -26,12 +26,12 @@
@SupportedAnnotationTypes("anthonisen.felix.annotationProcessing.MyVariance")
public class VarianceProcessor extends AbstractProcessor {
private Messager messager;
private Covariancer covariancer;
private AstManipulator astManipulator;

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
messager = processingEnv.getMessager();
covariancer = new Covariancer(messager,
astManipulator = new AstManipulator(messager,
System.getProperty("user.dir") + "/src/main/java");
messager.printMessage(Kind.NOTE, "Processing annotations:\n");
for (Element e : roundEnv.getElementsAnnotatedWith(MyVariance.class)) {
Expand All @@ -55,16 +55,16 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
}

checkVariance(className, annotation.variance(), packageName, tE.getSimpleName().toString());
covariancer.eraseTypesAndInsertCasts(className + ".java", packageName, tE.getSimpleName().toString());
astManipulator.eraseTypesAndInsertCasts(className + ".java", packageName, tE.getSimpleName().toString());

}
covariancer.applyChanges();
astManipulator.applyChanges();
return true;
}

private void checkVariance(String className, VarianceType variance, String packageName, String typeOfInterest) {
Set<Type> types = new HashSet<>();
CompilationUnit cu = covariancer.getSourceRoot().parse(packageName, className
CompilationUnit cu = astManipulator.getSourceRoot().parse(packageName, className
+ ".java");
if (variance == VarianceType.CONTRAVARIANT)
cu.accept(new ReturnTypeCollector(), types);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
import javax.annotation.processing.Messager;
import javax.tools.Diagnostic.Kind;

public class Covariancer {
public class AstManipulator {
private final Messager messager;
private final String sourceFolder;
private final SourceRoot sourceRoot;

public Covariancer(Messager messager, String sourceFolder) {
public AstManipulator(Messager messager, String sourceFolder) {
this.messager = messager;
this.sourceFolder = sourceFolder;
sourceRoot = new SourceRoot(
CodeGenerationUtils.mavenModuleRoot(Covariancer.class).resolve(sourceFolder));
CodeGenerationUtils.mavenModuleRoot(AstManipulator.class).resolve(sourceFolder));
}

public void eraseTypesAndInsertCasts(String cls, String packageName, String typeOfInterest) {
Expand Down Expand Up @@ -99,7 +99,7 @@ private void changeAST(File dir, ClassData classData, Map<String, MethodData> me
public void applyChanges() {
this.sourceRoot.getCompilationUnits().forEach(cu -> changePackageDeclaration(cu));
this.sourceRoot.saveAll(
CodeGenerationUtils.mavenModuleRoot(Covariancer.class).resolve(Paths.get(sourceFolder + "/output")));
CodeGenerationUtils.mavenModuleRoot(AstManipulator.class).resolve(Paths.get(sourceFolder + "/output")));
}

public SourceRoot getSourceRoot() {
Expand Down

0 comments on commit 3948673

Please sign in to comment.