-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve and remove some of the suppressed warnings
The code generator required changing how the context was passed around so that it was not nullable. Otherwise minor touchups and deletion of suppressions that are not reproducable.
- Loading branch information
Showing
45 changed files
with
523 additions
and
577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,6 @@ | |
* | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
@SuppressWarnings("PMD.AvoidDuplicateLiterals") | ||
public final class NodeFactoryGenerator { | ||
private final List<NodeRule> rules = List.of(new AddSubtype(), new AddConstructors(), | ||
new AddKey(), new AddValue(), new AddMaximum(), new AddExpiration(), new AddDeques(), | ||
|
@@ -86,7 +85,6 @@ public final class NodeFactoryGenerator { | |
private final List<TypeSpec> nodeTypes; | ||
private final Path directory; | ||
|
||
@SuppressWarnings("NullAway.Init") | ||
private NodeFactoryGenerator(Path directory) { | ||
this.directory = requireNonNull(directory); | ||
this.nodeTypes = new ArrayList<>(); | ||
|
@@ -129,7 +127,7 @@ private void reformat() throws FormatterException, IOException { | |
} | ||
|
||
private void generatedNodes() { | ||
NavigableMap<String, Set<Feature>> classNameToFeatures = getClassNameToFeatures(); | ||
NavigableMap<String, ImmutableSet<Feature>> classNameToFeatures = getClassNameToFeatures(); | ||
classNameToFeatures.forEach((className, features) -> { | ||
String higherKey = classNameToFeatures.higherKey(className); | ||
boolean isLeaf = (higherKey == null) || !higherKey.startsWith(className); | ||
|
@@ -138,8 +136,8 @@ private void generatedNodes() { | |
}); | ||
} | ||
|
||
private NavigableMap<String, Set<Feature>> getClassNameToFeatures() { | ||
var classNameToFeatures = new TreeMap<String, Set<Feature>>(); | ||
private NavigableMap<String, ImmutableSet<Feature>> getClassNameToFeatures() { | ||
var classNameToFeatures = new TreeMap<String, ImmutableSet<Feature>>(); | ||
for (List<Object> combination : combinations()) { | ||
var features = getFeatures(combination); | ||
var className = Feature.makeClassName(features); | ||
|
@@ -163,27 +161,28 @@ private ImmutableSet<Feature> getFeatures(List<Object> combination) { | |
return ImmutableSet.copyOf(features); | ||
} | ||
|
||
@SuppressWarnings("NullAway") | ||
private TypeSpec makeNodeSpec(String className, boolean isFinal, Set<Feature> features) { | ||
private TypeSpec makeNodeSpec(String className, boolean isFinal, ImmutableSet<Feature> features) { | ||
TypeName superClass; | ||
Set<Feature> parentFeatures; | ||
Set<Feature> generateFeatures; | ||
ImmutableSet<Feature> parentFeatures; | ||
ImmutableSet<Feature> generateFeatures; | ||
if (features.size() == 2) { | ||
parentFeatures = Set.of(); | ||
parentFeatures = ImmutableSet.of(); | ||
generateFeatures = features; | ||
superClass = TypeName.OBJECT; | ||
} else { | ||
parentFeatures = ImmutableSet.copyOf(Iterables.limit(features, features.size() - 1)); | ||
generateFeatures = ImmutableSet.of(Iterables.getLast(features)); | ||
generateFeatures = ImmutableSet.of(features.asList().get(features.size() - 1)); | ||
superClass = ParameterizedTypeName.get(ClassName.get(PACKAGE_NAME, | ||
encode(Feature.makeClassName(parentFeatures))), kTypeVar, vTypeVar); | ||
} | ||
|
||
var context = new NodeContext(superClass, className, isFinal, parentFeatures, generateFeatures); | ||
for (NodeRule rule : rules) { | ||
rule.accept(context); | ||
if (rule.applies(context)) { | ||
rule.execute(context); | ||
} | ||
} | ||
return context.nodeSubtype.build(); | ||
return context.build(); | ||
} | ||
|
||
private Set<List<Object>> combinations() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,26 +16,28 @@ | |
package com.github.benmanes.caffeine.cache.local; | ||
|
||
import static com.github.benmanes.caffeine.cache.Specifications.ASYNC_CACHE_LOADER_PARAM; | ||
import static com.github.benmanes.caffeine.cache.Specifications.LOCAL_CACHE_FACTORY; | ||
import static com.github.benmanes.caffeine.cache.Specifications.BOUNDED_LOCAL_CACHE; | ||
import static com.github.benmanes.caffeine.cache.Specifications.BUILDER_PARAM; | ||
import static com.github.benmanes.caffeine.cache.Specifications.LOCAL_CACHE_FACTORY; | ||
|
||
import javax.lang.model.element.Modifier; | ||
|
||
import com.squareup.javapoet.FieldSpec; | ||
|
||
/** | ||
* Adds the constructor to the cache. | ||
* | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class AddConstructor extends LocalCacheRule { | ||
public final class AddConstructor implements LocalCacheRule { | ||
|
||
@Override | ||
protected boolean applies() { | ||
public boolean applies(LocalCacheContext context) { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
public void execute(LocalCacheContext context) { | ||
context.constructor | ||
.addParameter(BUILDER_PARAM) | ||
.addParameter(ASYNC_CACHE_LOADER_PARAM) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,21 +28,21 @@ | |
/** | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class AddDeques extends LocalCacheRule { | ||
public final class AddDeques implements LocalCacheRule { | ||
|
||
@Override | ||
protected boolean applies() { | ||
public boolean applies(LocalCacheContext context) { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
addAccessOrderWindowDeque(); | ||
addAccessOrderMainDeque(); | ||
addWriteOrderDeque(); | ||
public void execute(LocalCacheContext context) { | ||
addAccessOrderWindowDeque(context); | ||
addAccessOrderMainDeque(context); | ||
addWriteOrderDeque(context); | ||
} | ||
|
||
private void addAccessOrderWindowDeque() { | ||
private void addAccessOrderWindowDeque(LocalCacheContext context) { | ||
if (Feature.usesAccessOrderWindowDeque(context.parentFeatures) | ||
|| !Feature.usesAccessOrderWindowDeque(context.generateFeatures)) { | ||
return; | ||
|
@@ -51,39 +51,39 @@ private void addAccessOrderWindowDeque() { | |
context.constructor.addStatement( | ||
"this.$L = builder.evicts() || builder.expiresAfterAccess()\n? new $T()\n: null", | ||
"accessOrderWindowDeque", ACCESS_ORDER_DEQUE); | ||
addFieldAndMethod(ACCESS_ORDER_DEQUE, "accessOrderWindowDeque"); | ||
addFieldAndMethod(context, ACCESS_ORDER_DEQUE, "accessOrderWindowDeque"); | ||
context.suppressedWarnings.add("NullAway"); | ||
} | ||
|
||
private void addAccessOrderMainDeque() { | ||
private void addAccessOrderMainDeque(LocalCacheContext context) { | ||
if (Feature.usesAccessOrderMainDeque(context.parentFeatures) | ||
|| !Feature.usesAccessOrderMainDeque(context.generateFeatures)) { | ||
return; | ||
} | ||
addDeque(ACCESS_ORDER_DEQUE, "accessOrderProbationDeque"); | ||
addDeque(ACCESS_ORDER_DEQUE, "accessOrderProtectedDeque"); | ||
addDeque(context, ACCESS_ORDER_DEQUE, "accessOrderProbationDeque"); | ||
addDeque(context, ACCESS_ORDER_DEQUE, "accessOrderProtectedDeque"); | ||
context.suppressedWarnings.add("NullAway"); | ||
} | ||
|
||
private void addWriteOrderDeque() { | ||
private void addWriteOrderDeque(LocalCacheContext context) { | ||
if (Feature.usesWriteOrderDeque(context.parentFeatures) | ||
|| !Feature.usesWriteOrderDeque(context.generateFeatures)) { | ||
return; | ||
} | ||
addDeque(WRITE_ORDER_DEQUE, "writeOrderDeque"); | ||
addDeque(context, WRITE_ORDER_DEQUE, "writeOrderDeque"); | ||
context.suppressedWarnings.add("NullAway"); | ||
} | ||
|
||
private void addDeque(TypeName type, String name) { | ||
addConstructor(type, name); | ||
addFieldAndMethod(type, name); | ||
private void addDeque(LocalCacheContext context, TypeName type, String name) { | ||
addConstructor(context, type, name); | ||
addFieldAndMethod(context, type, name); | ||
} | ||
|
||
private void addConstructor(TypeName type, String name) { | ||
private void addConstructor(LocalCacheContext context, TypeName type, String name) { | ||
context.constructor.addStatement("this.$L = new $T()", name, type); | ||
} | ||
|
||
private void addFieldAndMethod(TypeName type, String name) { | ||
private void addFieldAndMethod(LocalCacheContext context, TypeName type, String name) { | ||
context.cache.addField(FieldSpec.builder(type, name, Modifier.FINAL).build()); | ||
context.cache.addMethod(MethodSpec.methodBuilder(name) | ||
.addModifiers(context.protectedFinalModifiers()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,16 +26,16 @@ | |
/** | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class AddExpirationTicker extends LocalCacheRule { | ||
public final class AddExpirationTicker implements LocalCacheRule { | ||
|
||
@Override | ||
protected boolean applies() { | ||
public boolean applies(LocalCacheContext context) { | ||
return !(Feature.usesExpirationTicker(context.parentFeatures) | ||
|| !Feature.usesExpirationTicker(context.generateFeatures)); | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
public void execute(LocalCacheContext context) { | ||
context.constructor.addStatement("this.ticker = builder.getTicker()"); | ||
context.cache.addField(FieldSpec.builder(TICKER, "ticker", Modifier.FINAL).build()); | ||
context.cache.addMethod(MethodSpec.methodBuilder("expirationTicker") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,21 +27,21 @@ | |
/** | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class AddExpireAfterAccess extends LocalCacheRule { | ||
public final class AddExpireAfterAccess implements LocalCacheRule { | ||
|
||
@Override | ||
protected boolean applies() { | ||
public boolean applies(LocalCacheContext context) { | ||
return context.generateFeatures.contains(Feature.EXPIRE_ACCESS); | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
public void execute(LocalCacheContext context) { | ||
context.suppressedWarnings.add("NullAway"); | ||
variableExpiration(); | ||
fixedExpiration(); | ||
variableExpiration(context); | ||
fixedExpiration(context); | ||
} | ||
|
||
private void fixedExpiration() { | ||
private void fixedExpiration(LocalCacheContext context) { | ||
context.constructor.addStatement( | ||
"this.expiresAfterAccessNanos = builder.getExpiresAfterAccessNanos()"); | ||
context.cache.addField(FieldSpec.builder(long.class, "expiresAfterAccessNanos") | ||
|
@@ -63,7 +63,7 @@ private void fixedExpiration() { | |
.build()); | ||
} | ||
|
||
private void variableExpiration() { | ||
private void variableExpiration(LocalCacheContext context) { | ||
context.cache.addMethod(MethodSpec.methodBuilder("expiresVariable") | ||
.addModifiers(context.protectedFinalModifiers()) | ||
.addStatement("return (timerWheel != null)") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,15 @@ | |
/** | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class AddExpireAfterWrite extends LocalCacheRule { | ||
public final class AddExpireAfterWrite implements LocalCacheRule { | ||
|
||
@Override | ||
protected boolean applies() { | ||
public boolean applies(LocalCacheContext context) { | ||
return context.generateFeatures.contains(Feature.EXPIRE_WRITE); | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
public void execute(LocalCacheContext context) { | ||
context.constructor.addStatement( | ||
"this.expiresAfterWriteNanos = builder.getExpiresAfterWriteNanos()"); | ||
context.cache.addField(FieldSpec.builder(long.class, "expiresAfterWriteNanos") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,18 @@ | |
/** | ||
* @author [email protected] (Ben Manes) | ||
*/ | ||
public final class AddFastPath extends LocalCacheRule { | ||
public final class AddFastPath implements LocalCacheRule { | ||
|
||
@Override | ||
protected boolean applies() { | ||
public boolean applies(LocalCacheContext context) { | ||
boolean parentFastPath = Feature.usesFastPath(context.parentFeatures); | ||
boolean fastpath = Feature.usesFastPath(Sets.union( | ||
context.parentFeatures, context.generateFeatures)); | ||
return (parentFastPath != fastpath); | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
public void execute(LocalCacheContext context) { | ||
boolean fastpath = Feature.usesFastPath(Sets.union( | ||
context.parentFeatures, context.generateFeatures)); | ||
context.cache.addMethod(MethodSpec.methodBuilder("fastpath") | ||
|
Oops, something went wrong.