Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Sep 23, 2022
1 parent b69750f commit 3b232c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,6 @@ public void finished(TaskEvent taskEvent) {
}
}

private boolean containsRefasterTemplates(ClassTree tree) {
return Boolean.TRUE.equals(
new TreeScanner<Boolean, Void>() {
@Override
public Boolean visitAnnotation(AnnotationTree node, @Nullable Void v) {
Symbol sym = ASTHelpers.getSymbol(node);
return (sym != null
&& sym.getQualifiedName()
.contentEquals(BeforeTemplate.class.getCanonicalName()))
|| super.visitAnnotation(node, v);
}

@Override
public Boolean reduce(Boolean r1, Boolean r2) {
return Boolean.TRUE.equals(r1) || Boolean.TRUE.equals(r2);
}
}.scan(tree, null));
}

private ImmutableMap<ClassTree, CodeTransformer> compileRefasterTemplates(ClassTree tree) {
ImmutableMap.Builder<ClassTree, CodeTransformer> rules = ImmutableMap.builder();
new TreeScanner<Void, ImmutableClassToInstanceMap<Annotation>>() {
Expand All @@ -112,15 +93,6 @@ public Void visitClass(ClassTree node, ImmutableClassToInstanceMap<Annotation> a
return rules.buildOrThrow();
}

// XXX: Move down?
private static ImmutableClassToInstanceMap<Annotation> merge(
ImmutableClassToInstanceMap<Annotation> left, ImmutableClassToInstanceMap<Annotation> right) {
return ImmutableClassToInstanceMap.<Annotation>builder()
.putAll(Maps.filterKeys(left, k -> !right.containsKey(k)))
.putAll(right)
.build();
}

private FileObject getOutputFile(TaskEvent taskEvent, ClassTree tree) throws IOException {
ClassSymbol symbol = ASTHelpers.getSymbol(tree);
PackageSymbol enclosingPackage = ASTHelpers.enclosingPackage(symbol);
Expand All @@ -132,6 +104,35 @@ private FileObject getOutputFile(TaskEvent taskEvent, ClassTree tree) throws IOE
StandardLocation.CLASS_OUTPUT, packageName, relativeName, taskEvent.getSourceFile());
}

private static boolean containsRefasterTemplates(ClassTree tree) {
return Boolean.TRUE.equals(
new TreeScanner<Boolean, Void>() {
@Override
public Boolean visitAnnotation(AnnotationTree node, @Nullable Void unused) {
Symbol sym = ASTHelpers.getSymbol(node);
return (sym != null
&& sym.getQualifiedName()
.contentEquals(BeforeTemplate.class.getCanonicalName()))
|| super.visitAnnotation(node, unused);
}

@Override
public Boolean reduce(Boolean r1, Boolean r2) {
return Boolean.TRUE.equals(r1) || Boolean.TRUE.equals(r2);
}
}.scan(tree, null));
}

/** Merges two annotation mappings, preferring the second over the first in case of conflicts. */
private static ImmutableClassToInstanceMap<Annotation> merge(
ImmutableClassToInstanceMap<Annotation> first,
ImmutableClassToInstanceMap<Annotation> second) {
return ImmutableClassToInstanceMap.<Annotation>builder()
.putAll(Maps.filterKeys(first, k -> !second.containsKey(k)))
.putAll(second)
.build();
}

private static CharSequence toSimpleFlatName(ClassSymbol classSymbol) {
Name flatName = classSymbol.flatName();
int lastDot = flatName.lastIndexOf((byte) '.');
Expand Down
8 changes: 8 additions & 0 deletions refaster-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
`annotationProcessorPaths` configuration below. -->
<scope>provided</scope>
</dependency>
<!-- XXX: Maybe it's better if we move
`AnnotatedCompositeCodeTransformer` to `refaster-compiler` and drop the
`provided` above. -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>refaster-support</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service-annotations</artifactId>
Expand Down

0 comments on commit 3b232c3

Please sign in to comment.