Skip to content

Commit

Permalink
IntelliJ static analysis cleanup
Browse files Browse the repository at this point in the history
IntelliJ seems to have some import quirks which this reduces. It seems
to still get confused, after a few edits forget about sibling modules,
and complains about imports to those classes. Eclipse is a lot smarter.

Resolved IntelliJ compilation issues by degrading to raw types, even
though javac is happy. Ran their static analyzer and fixed all issues
that could be somewhat justified. Most were dead code removals.

Hopefully this makes the project a little friendlier for those who
want to hack with that IDE.
  • Loading branch information
ben-manes committed May 11, 2017
1 parent e851a83 commit 00ff445
Show file tree
Hide file tree
Showing 55 changed files with 110 additions and 225 deletions.
13 changes: 9 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ allprojects {
subprojects {
apply plugin: 'com.github.ethankhall.semantic-versioning'
apply plugin: 'nebula.provided-base'
apply plugin: 'eclipse'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'osgi'

apply from: "${rootDir}/gradle/publish.gradle"
Expand All @@ -73,6 +75,10 @@ subprojects {
}
archivesBaseName = path[1..-1].replaceAll(':', '-').toLowerCase()

idea.module {
scopes.PROVIDED.plus += [ configurations.provided ]
}

dependencies {
provided libraries.jsr305
provided libraries.error_prone_annotations
Expand Down Expand Up @@ -128,6 +134,9 @@ task jacocoMerge(type: JacocoMerge) {
publishedProjects.each { subproject ->
executionData subproject.tasks.withType(Test)
}
doFirst {
executionData = files(executionData.findAll { it.exists() })
}
}

task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') {
Expand All @@ -143,10 +152,6 @@ task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') {
html.enabled = true // human readable
xml.enabled = true // required by coveralls
}

doFirst {
executionData = files(executionData.findAll { it.exists() })
}
}

coveralls {
Expand Down
4 changes: 4 additions & 0 deletions caffeine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ configurations {
javaAgent
}

idea.module {
scopes.PROVIDED.plus += [ configurations.javaPoetCompile ]
}

plugins.withType(EclipsePlugin) {
project.eclipse.classpath.plusConfigurations += [ configurations.javaPoetCompile ]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ public static boolean usesExpirationTicker(Set<Feature> features) {
|| features.contains(Feature.REFRESH_WRITE);
}

public static boolean usesStatsTicker(Set<Feature> features) {
return features.contains(Feature.STATS);
}

public static boolean usesMaximum(Set<Feature> features) {
return features.contains(Feature.MAXIMUM_SIZE)
|| features.contains(Feature.MAXIMUM_WEIGHT);
Expand All @@ -111,9 +107,6 @@ public static boolean usesMaximum(Set<Feature> features) {
public static boolean usesFastPath(Set<Feature> features) {
Set<Feature> incompatible = Sets.immutableEnumSet(Feature.EXPIRE_ACCESS,
Feature.WEAK_KEYS, Feature.INFIRM_VALUES, Feature.WEAK_VALUES, Feature.SOFT_VALUES);
if (features.stream().anyMatch(incompatible::contains)) {
return false;
}
return usesMaximum(features);
return !features.stream().anyMatch(incompatible::contains) && usesMaximum(features);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private void addGetFactoryMethods() {
.build());
}

private void generatedNodes() throws IOException {
private void generatedNodes() {
fillClassNameToFeatures();
classNameToFeatures.forEach((className, features) -> {
String higherKey = classNameToFeatures.higherKey(className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public final class Specifications {
public static final ParameterSpec valueRefQueueSpec =
ParameterSpec.builder(vRefQueueType, "valueReferenceQueue").build();

public static final ParameterSpec weightSpec = ParameterSpec.builder(int.class, "weight").build();
public static final TypeName NODE = ParameterizedTypeName.get(nodeType, kTypeVar, vTypeVar);
public static final TypeName UNSAFE_ACCESS =
ClassName.get("com.github.benmanes.caffeine.base", "UnsafeAccess");
Expand All @@ -86,11 +85,6 @@ public final class Specifications {

public static final TypeName TICKER = ClassName.get(PACKAGE_NAME, "Ticker");

public static final TypeName WEIGHER = ParameterizedTypeName.get(
ClassName.get(PACKAGE_NAME, "Weigher"),
TypeVariableName.get("? super K"),
TypeVariableName.get("? super V"));

public static final TypeName ACCESS_ORDER_DEQUE = ParameterizedTypeName.get(
ClassName.get(PACKAGE_NAME, "AccessOrderDeque"), NODE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.github.benmanes.caffeine.cache.local;

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.CACHE_LOADER_PARAM;

Expand All @@ -32,10 +33,13 @@ protected boolean applies() {

@Override
protected void execute() {
String cacheLoader = context.superClass.equals(BOUNDED_LOCAL_CACHE)
? "(CacheLoader<K, V>) cacheLoader"
: "cacheLoader";
context.constructor
.addParameter(BUILDER_PARAM)
.addParameter(CACHE_LOADER_PARAM)
.addParameter(boolean.class, "async")
.addStatement("super(builder, (CacheLoader<K, V>) cacheLoader, async)");
.addStatement("super(builder, $L, async)", cacheLoader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ public final class AddExpirationTicker extends LocalCacheRule {

@Override
protected boolean applies() {
if (Feature.usesExpirationTicker(context.parentFeatures)
|| !Feature.usesExpirationTicker(context.generateFeatures)) {
return false;
}
return true;
return !(Feature.usesExpirationTicker(context.parentFeatures)
|| !Feature.usesExpirationTicker(context.generateFeatures));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ public final class AddMaximum extends LocalCacheRule {

@Override
protected boolean applies() {
if (Feature.usesMaximum(context.parentFeatures)
|| !Feature.usesMaximum(context.generateFeatures)) {
return false;
}
return true;
return !(Feature.usesMaximum(context.parentFeatures)
|| !Feature.usesMaximum(context.generateFeatures));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ public final class AddWriteBuffer extends LocalCacheRule {

@Override
protected boolean applies() {
if (Feature.usesWriteQueue(context.parentFeatures)
|| !Feature.usesWriteQueue(context.generateFeatures)) {
return false;
}
return true;
return !(Feature.usesWriteQueue(context.parentFeatures)
|| !Feature.usesWriteQueue(context.generateFeatures));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ private TypeName keyReferenceType() {
/** Adds a constructor assignment. */
private void addKeyConstructorAssignment(MethodSpec.Builder constructor, boolean isReference) {
if (isReference || isStrongKeys()) {
String refAssignment = isStrongKeys()
? "(K) keyReference"
: "(WeakKeyReference<K>) keyReference";
constructor.addStatement("$T.UNSAFE.putObject(this, $N, $N)",
UNSAFE_ACCESS, offsetName("key"), isReference ? refAssignment : "key");
UNSAFE_ACCESS, offsetName("key"), isReference ? "keyReference" : "key");
} else {
constructor.addStatement("$T.UNSAFE.putObject(this, $N, new $T($N, $N))",
UNSAFE_ACCESS, offsetName("key"), keyReferenceType(), "key", "keyReferenceQueue");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,15 @@ private Strength strengthOf(Feature feature) {
}

protected enum Strength {
STRONG, WEAK, SOFT;
STRONG, WEAK, SOFT,
}

protected enum Visibility {
IMMEDIATE(false), LAZY(true);

final boolean isRelaxed;
private Visibility(boolean mode) {

Visibility(boolean mode) {
this.isRelaxed = mode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private SingleConsumerQueue(Function<E, Node<E>> factory) {
for (int i = 0; i < ARENA_LENGTH; i++) {
arena[i] = new AtomicReference<>();
}
Node<E> node = new Node<E>(null);
Node<E> node = new Node<>(null);
this.factory = factory;
lazySetTail(node);
head = node;
Expand Down Expand Up @@ -275,7 +275,7 @@ public boolean addAll(Collection<? extends E> c) {
first = factory.apply(e);
last = first;
} else {
Node<E> newLast = new Node<E>(e);
Node<E> newLast = new Node<>(e);
last.lazySetNext(newLast);
last = newLast;
}
Expand Down Expand Up @@ -438,7 +438,7 @@ Node<E> awaitNext() {
static final long serialVersionUID = 1;

Object writeReplace() {
return new SerializationProxy<E>(this);
return new SerializationProxy<>(this);
}

private void readObject(ObjectInputStream stream) throws InvalidObjectException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.github.benmanes.caffeine.cache;

import static com.github.benmanes.caffeine.cache.BoundedBuffer.OFFSET;

import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Consumer;

Expand Down Expand Up @@ -64,7 +66,6 @@ static final class RingBuffer<E> extends BBHeader.ReadAndWriteCounterRef impleme

@SuppressWarnings({"unchecked", "cast", "rawtypes"})
public RingBuffer(E e) {
super(OFFSET);
buffer = new AtomicReferenceArray<>(SPACED_SIZE);
buffer.lazySet(0, e);
}
Expand Down Expand Up @@ -152,8 +153,8 @@ static abstract class ReadAndWriteCounterRef extends PadWriteCounter {

volatile long writeCounter;

ReadAndWriteCounterRef(int writes) {
UnsafeAccess.UNSAFE.putOrderedLong(this, WRITE_OFFSET, writes);
ReadAndWriteCounterRef() {
UnsafeAccess.UNSAFE.putOrderedLong(this, WRITE_OFFSET, OFFSET);
}

long relaxedWriteCounter() {
Expand Down
Loading

0 comments on commit 00ff445

Please sign in to comment.