Skip to content

Commit

Permalink
Fix calls to TreeScanner.scan(TreePath, param).
Browse files Browse the repository at this point in the history
This is probably not what was intended: because TreePath implements Iterable<Tree>, this will scan from all nodes in the TreePath.
It don't think this is a problem in either case, because they only look to be called with a path referring to a CompilationUnitTree; but this is a bit brittle.

(An alternative fix would be to make these scanners into TreePathScanners. That TreeScanner and TreePathScanner do very different things with a TreePath parameter is quite insidious.

RELNOTES: None

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=228960415
  • Loading branch information
awturner authored and ronshapiro committed Jan 15, 2019
1 parent 5e5912a commit 1a5c9d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Expand Up @@ -213,7 +213,7 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
// We will skip reporting on the whole compilation if there are any native methods found.
// Use a TreeScanner to find all local variables and fields.
// The only reason type is atomic here is that we need to set its value from inside the closure.
if (hasNativeMethods(state.getPath())) {
if (hasNativeMethods(tree)) {
// Skipping the analysis of this file because it has native methods.
return Description.NO_MATCH;
}
Expand Down Expand Up @@ -650,7 +650,7 @@ public Void visitMethodInvocation(MethodInvocationTree tree, Void unused) {
return Description.NO_MATCH;
}

private static boolean hasNativeMethods(TreePath path) {
private static boolean hasNativeMethods(CompilationUnitTree tree) {
AtomicBoolean hasAnyNativeMethods = new AtomicBoolean(false);
new TreeScanner<Void, Void>() {
@Override
Expand All @@ -660,7 +660,7 @@ public Void visitMethod(MethodTree tree, Void unused) {
}
return null;
}
}.scan(path, null);
}.scan(tree, null);
return hasAnyNativeMethods.get();
}

Expand Down
Expand Up @@ -120,7 +120,8 @@ public abstract class RefasterRule<M extends TemplateMatch, T extends Template<M
@Override
public void apply(TreePath path, Context context, DescriptionListener listener) {
RefasterScanner.create(this, listener)
.scan(path, prepareContext(context, (JCCompilationUnit) path.getCompilationUnit()));
.scan(
path.getLeaf(), prepareContext(context, (JCCompilationUnit) path.getCompilationUnit()));
}

boolean rejectMatchesWithComments() {
Expand Down

0 comments on commit 1a5c9d8

Please sign in to comment.