Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public class NullnessNoInitAnnotatedTypeFactory
private final ExecutableElement mapGet =
TreeUtils.getMethod("java.util.Map", "get", 1, processingEnv);

// High-level optimization: cache entire addComputedTypeAnnotations processing flow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Javadocs should document what is being cached, in particular if the key/value is a String. What format is the String in?
For a cache you would also expect to see the value it is mapped to, so why is a Set enough?

Who cleans up this cache? There are many allocations in large programs and we don't want a Set that becomes arbitrarily large.
Maybe it should be cleared every time a new root is set? See here.

private final java.util.Set<String> fullyProcessedTrees = new java.util.HashSet<>();
Comment thread
zyf265600 marked this conversation as resolved.
Outdated

// List is in alphabetical order. If you update it, also update
// ../../../../../../../../docs/manual/nullness-checker.tex
// and make a pull request for variables NONNULL_ANNOTATIONS and BASE_COPYABLE_ANNOTATIONS in
Expand Down Expand Up @@ -483,6 +486,19 @@ protected void replacePolyQualifier(AnnotatedTypeMirror lhsType, Tree context) {
}
}

@Override
protected void addComputedTypeAnnotations(Tree tree, AnnotatedTypeMirror type) {
if (tree != null && tree instanceof NewClassTree) {
Comment thread
zyf265600 marked this conversation as resolved.
Outdated
String treeKey = tree.toString();
Comment thread
zyf265600 marked this conversation as resolved.
Outdated
if (fullyProcessedTrees.contains(treeKey)) {
return;
}
fullyProcessedTrees.add(treeKey);
}

super.addComputedTypeAnnotations(tree, type);
}

@Override
protected NullnessNoInitAnalysis createFlowAnalysis() {
return new NullnessNoInitAnalysis(checker, this);
Expand Down
5 changes: 5 additions & 0 deletions docs/examples/NewObject.java
Comment thread
zyf265600 marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class NewObject {
void test() {
Object object = new Object();
}
}
Loading