Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get default type for new class tree #414

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/checkers/inference/util/SlotDefaultTypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.sun.source.tree.AnnotatedTypeTree;
import com.sun.source.tree.ArrayTypeTree;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.PrimitiveTypeTree;
import com.sun.source.tree.Tree;
Expand Down Expand Up @@ -185,5 +187,21 @@ public Void visitAnnotatedType(AnnotatedTypeTree tree, Void unused) {

return super.visitAnnotatedType(tree, unused);
}

@Override
public Void visitNewClass(NewClassTree tree, Void unused) {
AnnotatedTypeMirror defaultType = getDefaultTypeFor(tree);
if (InferenceUtil.isAnonymousClass(tree)) {
// don't associate the identifier with the defaultType if it's an anonymousclass
// should associate the identifier with the direct super type of the defaultType.
// choose the last one of the directSupertypes, which is either the direct super class
// or implemented interface
List<? extends AnnotatedTypeMirror> superTypes = defaultType.directSupertypes();
defaultTypes.put(tree.getIdentifier(), superTypes.get(superTypes.size()-1));
} else {
defaultTypes.put(tree.getIdentifier(), defaultType);
}
return super.visitNewClass(tree, unused);
}
}
}