Skip to content

Commit

Permalink
Cleanup PR
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Sep 12, 2022
1 parent 3e69aca commit 9e82587
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 317 deletions.
5 changes: 1 addition & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<version.auto-service>1.0.1</version.auto-service>
<version.auto-value>1.9</version.auto-value>
<version.error-prone>${version.error-prone-orig}</version.error-prone>
<version.error-prone-fork>v2.14.0-picnic-3</version.error-prone-fork>
<version.error-prone-fork>v${version.error-prone-orig}-picnic-3</version.error-prone-fork>
<version.error-prone-orig>2.14.0</version.error-prone-orig>
<version.error-prone-slf4j>0.1.15</version.error-prone-slf4j>
<version.guava-beta-checker>1.0</version.guava-beta-checker>
Expand Down Expand Up @@ -1572,9 +1572,6 @@
-XepOpt:NullAway:AssertsEnabled=true
-XepOpt:NullAway:CheckOptionalEmptiness=true
-XepOpt:Nullness:Conservative=false
<!-- XXX: Fix this -->
-Xep:VoidMissingNullable:OFF
-Xep:ReturnMissingNullable:OFF
<!-- Append additional custom arguments. -->
${error-prone.patch-args}
${error-prone.self-check-args}
Expand Down
5 changes: 5 additions & 0 deletions refaster-rule-selector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<artifactId>auto-value-annotations</artifactId>
<version>${version.auto-value}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public boolean isClassPathCompatible(ClassLoader classLoader) {
Class.forName(
"com.google.errorprone.ErrorProneOptions", /* initialize= */ false, classLoader);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Cannot load `com.google.errorprone.ErrorProneOptions`", e);
return false;
// throw new IllegalStateException("Cannot load
// `com.google.errorprone.ErrorProneOptions`", e);
}

return Arrays.stream(clazz.getDeclaredMethods())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;

/** XXX: Write this */
@AutoService(RefasterRuleSelector.class)
Expand Down Expand Up @@ -88,6 +89,7 @@ private static ImmutableSet<ImmutableSortedSet<String>> extractTemplateIdentifie

// XXX: Make the scanner static, then make also its helper methods static.
new TreeScanner<Void, List<Set<String>>>() {
@Nullable
@Override
public Void visitIdentifier(IdentifierTree node, List<Set<String>> identifierCombinations) {
// XXX: Also include the package name if not `java.lang`; it must be present.
Expand Down Expand Up @@ -117,6 +119,7 @@ private String getSimpleName(String fcqn) {
return index < 0 ? fcqn : fcqn.substring(index + 1);
}

@Nullable
@Override
public Void visitMemberReference(
MemberReferenceTree node, List<Set<String>> identifierCombinations) {
Expand All @@ -126,6 +129,7 @@ public Void visitMemberReference(
return null;
}

@Nullable
@Override
public Void visitMemberSelect(
MemberSelectTree node, List<Set<String>> identifierCombinations) {
Expand All @@ -135,25 +139,29 @@ public Void visitMemberSelect(
return null;
}

@Nullable
@Override
public Void visitAssignment(AssignmentTree node, List<Set<String>> identifierCombinations) {
registerOperator(node, identifierCombinations);
return super.visitAssignment(node, identifierCombinations);
}

@Nullable
@Override
public Void visitCompoundAssignment(
CompoundAssignmentTree node, List<Set<String>> identifierCombinations) {
registerOperator(node, identifierCombinations);
return super.visitCompoundAssignment(node, identifierCombinations);
}

@Nullable
@Override
public Void visitUnary(UnaryTree node, List<Set<String>> identifierCombinations) {
registerOperator(node, identifierCombinations);
return super.visitUnary(node, identifierCombinations);
}

@Nullable
@Override
public Void visitBinary(BinaryTree node, List<Set<String>> identifierCombinations) {
registerOperator(node, identifierCombinations);
Expand All @@ -165,6 +173,7 @@ private void registerOperator(ExpressionTree node, List<Set<String>> identifierC
identifierCombinations.forEach(ids -> ids.add(treeKindToString(node.getKind())));
}

@Nullable
@Override
public Void visitOther(Tree node, List<Set<String>> identifierCombinations) {
if (node instanceof UAnyOf) {
Expand Down Expand Up @@ -199,44 +208,51 @@ private ImmutableSortedSet<String> extractSourceIdentifiers(Tree tree) {

// XXX: Make the scanner static.
new TreeScanner<Void, Set<String>>() {
@Nullable
@Override
public Void visitIdentifier(IdentifierTree node, Set<String> identifiers) {
identifiers.add(node.getName().toString());
return null;
}

@Nullable
@Override
public Void visitMemberReference(MemberReferenceTree node, Set<String> identifiers) {
super.visitMemberReference(node, identifiers);
identifiers.add(node.getName().toString());
return null;
}

@Nullable
@Override
public Void visitMemberSelect(MemberSelectTree node, Set<String> identifiers) {
super.visitMemberSelect(node, identifiers);
identifiers.add(node.getIdentifier().toString());
return null;
}

@Nullable
@Override
public Void visitAssignment(AssignmentTree node, Set<String> identifiers) {
registerOperator(node, identifiers);
return super.visitAssignment(node, identifiers);
}

@Nullable
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree node, Set<String> identifiers) {
registerOperator(node, identifiers);
return super.visitCompoundAssignment(node, identifiers);
}

@Nullable
@Override
public Void visitUnary(UnaryTree node, Set<String> identifiers) {
registerOperator(node, identifiers);
return super.visitUnary(node, identifiers);
}

@Nullable
@Override
public Void visitBinary(BinaryTree node, Set<String> identifiers) {
registerOperator(node, identifiers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ public Refaster(ErrorProneFlags flags) {

@CanIgnoreReturnValue
@Override
@SuppressWarnings("UnusedVariable")
public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) {
// XXX: Inline this variable.
// Set<RefasterRule<?, ?>> candidateRules = getCandidateRefasterRules(tree);

DefaultRuleSelectorFactory ruleSelectorFactory = new DefaultRuleSelectorFactory();
RefasterRuleSelector selector =
ruleSelectorFactory.createRefasterRuleSelector(
Expand Down Expand Up @@ -112,15 +108,6 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s
return Description.NO_MATCH;
}

// XXX: Here and below: drop redundant `Refaster` from method names?
// private Set<RefasterRule<?, ?>> getCandidateRefasterRules(CompilationUnitTree tree) {
// Set<RefasterRule<?, ?>> candidateRules = newSetFromMap(new IdentityHashMap<>());
// refasterRules.collectCandidateTemplates(
// extractSourceIdentifiers(tree).asList(), candidateRules::add);
//
// return candidateRules;
// }

private static List<RefasterRule<?, ?>> getRefasterRules(ErrorProneFlags flags) {
CodeTransformer compositeCodeTransformer = createCompositeCodeTransformer(flags);

Expand Down Expand Up @@ -215,201 +202,4 @@ private static ImmutableList<CodeTransformer> filterCodeTransformers(
.map(Map.Entry::getValue)
.collect(toImmutableList());
}

// XXX: Decompose `RefasterRule`s such that each has exactly one `@BeforeTemplate`.
// private static ImmutableSet<ImmutableSortedSet<String>> extractTemplateIdentifiers(
// RefasterRule<?, ?> refasterRule) {
// ImmutableSet.Builder<ImmutableSortedSet<String>> results = ImmutableSet.builder();
//
// for (Object template : refasterRule.beforeTemplates()) {
// if (template instanceof ExpressionTemplate) {
// UExpression expr = ((ExpressionTemplate) template).expression();
// results.addAll(extractTemplateIdentifiers(ImmutableList.of(expr)));
// } else if (template instanceof BlockTemplate) {
// ImmutableList<UStatement> statements = ((BlockTemplate) template).templateStatements();
// results.addAll(extractTemplateIdentifiers(statements));
// } else {
// throw new IllegalStateException(
// String.format("Unexpected template type '%s'", template.getClass()));
// }
// }
//
// return results.build();
// }
//
// // XXX: Consider interning the strings (once a benchmark is in place).
// private static ImmutableSet<ImmutableSortedSet<String>> extractTemplateIdentifiers(
// ImmutableList<? extends Tree> trees) {
// List<Set<String>> identifierCombinations = new ArrayList<>();
// identifierCombinations.add(new HashSet<>());
//
// // XXX: Make the scanner static, then make also its helper methods static.
// new TreeScanner<Void, List<Set<String>>>() {
// @Override
// public Void visitIdentifier(IdentifierTree node, List<Set<String>> identifierCombinations)
// {
// // XXX: Also include the package name if not `java.lang`; it must be present.
// if (node instanceof UClassIdent) {
// for (Set<String> ids : identifierCombinations) {
// ids.add(getSimpleName(((UClassIdent) node).getTopLevelClass()));
// ids.add(getIdentifier(node));
// }
// } else if (node instanceof UStaticIdent) {
// UClassIdent subNode = ((UStaticIdent) node).classIdent();
// for (Set<String> ids : identifierCombinations) {
// ids.add(getSimpleName(subNode.getTopLevelClass()));
// ids.add(getIdentifier(subNode));
// ids.add(node.getName().toString());
// }
// }
//
// return null;
// }
//
// private String getIdentifier(IdentifierTree tree) {
// return getSimpleName(tree.getName().toString());
// }
//
// private String getSimpleName(String fcqn) {
// int index = fcqn.lastIndexOf('.');
// return index < 0 ? fcqn : fcqn.substring(index + 1);
// }
//
// @Override
// public Void visitMemberReference(
// MemberReferenceTree node, List<Set<String>> identifierCombinations) {
// super.visitMemberReference(node, identifierCombinations);
// String id = node.getName().toString();
// identifierCombinations.forEach(ids -> ids.add(id));
// return null;
// }
//
// @Override
// public Void visitMemberSelect(
// MemberSelectTree node, List<Set<String>> identifierCombinations) {
// super.visitMemberSelect(node, identifierCombinations);
// String id = node.getIdentifier().toString();
// identifierCombinations.forEach(ids -> ids.add(id));
// return null;
// }
//
// @Override
// public Void visitAssignment(AssignmentTree node, List<Set<String>> identifierCombinations)
// {
// registerOperator(node, identifierCombinations);
// return super.visitAssignment(node, identifierCombinations);
// }
//
// @Override
// public Void visitCompoundAssignment(
// CompoundAssignmentTree node, List<Set<String>> identifierCombinations) {
// registerOperator(node, identifierCombinations);
// return super.visitCompoundAssignment(node, identifierCombinations);
// }
//
// @Override
// public Void visitUnary(UnaryTree node, List<Set<String>> identifierCombinations) {
// registerOperator(node, identifierCombinations);
// return super.visitUnary(node, identifierCombinations);
// }
//
// @Override
// public Void visitBinary(BinaryTree node, List<Set<String>> identifierCombinations) {
// registerOperator(node, identifierCombinations);
// return super.visitBinary(node, identifierCombinations);
// }
//
// // XXX: Rename!
// private void registerOperator(ExpressionTree node, List<Set<String>>
// identifierCombinations) {
// identifierCombinations.forEach(ids -> ids.add(Util.treeKindToString(node.getKind())));
// }
//
// @Override
// public Void visitOther(Tree node, List<Set<String>> identifierCombinations) {
// if (node instanceof UAnyOf) {
// List<Set<String>> base = copy(identifierCombinations);
// identifierCombinations.clear();
//
// for (UExpression expr : ((UAnyOf) node).expressions()) {
// List<Set<String>> branch = copy(base);
// scan(expr, branch);
// identifierCombinations.addAll(branch);
// }
// }
//
// return null;
// }
//
// private List<Set<String>> copy(List<Set<String>> identifierCombinations) {
// return identifierCombinations.stream()
// .map(HashSet::new)
// .collect(toCollection(ArrayList::new));
// }
// }.scan(trees, identifierCombinations);
//
// return identifierCombinations.stream()
// .map(ImmutableSortedSet::copyOf)
// .collect(toImmutableSet());
// }
//
// // XXX: Consider interning!
// private static ImmutableSortedSet<String> extractSourceIdentifiers(Tree tree) {
// Set<String> identifiers = new HashSet<>();
//
// // XXX: Make the scanner static.
// new TreeScanner<Void, Set<String>>() {
// @Override
// public Void visitIdentifier(IdentifierTree node, Set<String> identifiers) {
// identifiers.add(node.getName().toString());
// return null;
// }
//
// @Override
// public Void visitMemberReference(MemberReferenceTree node, Set<String> identifiers) {
// super.visitMemberReference(node, identifiers);
// identifiers.add(node.getName().toString());
// return null;
// }
//
// @Override
// public Void visitMemberSelect(MemberSelectTree node, Set<String> identifiers) {
// super.visitMemberSelect(node, identifiers);
// identifiers.add(node.getIdentifier().toString());
// return null;
// }
//
// @Override
// public Void visitAssignment(AssignmentTree node, Set<String> identifiers) {
// registerOperator(node, identifiers);
// return super.visitAssignment(node, identifiers);
// }
//
// @Override
// public Void visitCompoundAssignment(CompoundAssignmentTree node, Set<String> identifiers)
// {
// registerOperator(node, identifiers);
// return super.visitCompoundAssignment(node, identifiers);
// }
//
// @Override
// public Void visitUnary(UnaryTree node, Set<String> identifiers) {
// registerOperator(node, identifiers);
// return super.visitUnary(node, identifiers);
// }
//
// @Override
// public Void visitBinary(BinaryTree node, Set<String> identifiers) {
// registerOperator(node, identifiers);
// return super.visitBinary(node, identifiers);
// }
//
// // XXX: Rename!
// private void registerOperator(ExpressionTree node, Set<String> identifiers) {
// identifiers.add(Util.treeKindToString(node.getKind()));
// }
// }.scan(tree, identifiers);
//
// return ImmutableSortedSet.copyOf(identifiers);
// }
}
Loading

0 comments on commit 9e82587

Please sign in to comment.