Skip to content

Commit

Permalink
Improve handling of synthetic generated constructors in refaster
Browse files Browse the repository at this point in the history
The return type is a non-null 'void' type in recent JDK versions.

#1106

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=313289453
  • Loading branch information
cushon authored and kevinb9n committed May 26, 2020
1 parent bb4f1d9 commit 7b072f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Range;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.ModifiersTree;
Expand Down Expand Up @@ -112,11 +113,12 @@ public Choice<Unifier> visitClass(ClassTree node, Unifier unifier) {
Choice<UnifierWithRemainingMembers> path =
Choice.of(UnifierWithRemainingMembers.create(unifier, getMembers()));
for (Tree targetMember : node.getMembers()) {
if (!(targetMember instanceof MethodTree)
|| ((MethodTree) targetMember).getReturnType() != null) {
if (targetMember instanceof MethodTree
&& ASTHelpers.isGeneratedConstructor((MethodTree) targetMember)) {
// skip synthetic constructors
path = path.thenChoose(match(targetMember));
continue;
}
path = path.thenChoose(match(targetMember));
}
return path.condition(s -> s.remainingMembers().isEmpty())
.transform(UnifierWithRemainingMembers::unifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,11 @@ public UNewClass visitNewClass(NewClassTree tree, Void v) {
public UClassDecl visitClass(ClassTree tree, Void v) {
ImmutableList.Builder<UMethodDecl> decls = ImmutableList.builder();
for (MethodTree decl : Iterables.filter(tree.getMembers(), MethodTree.class)) {
if (decl.getReturnType() != null) {
decls.add(visitMethod(decl, null));
if (ASTHelpers.isGeneratedConstructor(decl)) {
// skip synthetic constructors
continue;
}
decls.add(visitMethod(decl, null));
}
return UClassDecl.create(decls.build());
}
Expand Down

0 comments on commit 7b072f7

Please sign in to comment.