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

Moe Sync #1294

Merged
merged 37 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bb00ae1
Replace google.github.io/dagger with dagger.dev
ronshapiro May 28, 2019
221fde7
Flag instances of Duration.of(long, ChronoUnit) where the ChronoUnit …
kluever May 28, 2019
0faf698
Fix an incorrect UnnecessaryAnonymousClass refactoring
cushon May 28, 2019
7bb2a77
Fix NPE on JDK13+ when InconsistentHashCode visits a break statement …
nick-someone May 28, 2019
5ddc53f
Expand SelfAssignment to cover the Precondition-style APIs in c.g.c.t…
kluever May 29, 2019
254f3f2
Allow ChronoUnit.DAYS explicitly in Duration.of(long, TemporalUnit).
kluever May 29, 2019
beef3d8
Rename DurationOfLongTemporalUnit to DurationTemporalUnit and cover d…
kluever May 29, 2019
e2cb9fe
Provide an example of using proto3's primitive wrappers.
graememorgan May 30, 2019
c875077
Migrate org.mockito.Matchers#any* to org.mockito.ArgumentMatchers
TimvdLippe May 30, 2019
8e131a2
Optimize VisitorState.inferBinaryName() by iterating directly over th…
ronshapiro May 30, 2019
fc36200
Replace google.github.io/dagger with dagger.dev
ronshapiro May 31, 2019
266ffcc
Cache references to "JavacSingletonType.instance(context)" references…
ronshapiro May 31, 2019
9dc8eaf
Update docs for the Truth migration from an `actual()` method to an `…
cpovirk May 31, 2019
567b765
Use the latest checker framework dataflow version
cushon Jun 3, 2019
ced971d
Remove the custom link from UnusedException.
graememorgan Jun 3, 2019
21599b7
Add valueOf to list of BadImport static imports
awturner Jun 3, 2019
d013d6a
Make LocalDate.plus/minus(Duration) a compile-time error.
kluever Jun 4, 2019
64bf016
Add Class to list of bad imports.
phst Jun 4, 2019
1a8c868
Update to Truth 0.45, and address deprecations.
cpovirk Jun 4, 2019
3cdc1fd
Remove obsolete todo
epmjohnston Jun 4, 2019
d1aad72
Recommend Period in the LocalDateTemporalAmount summary.
kluever Jun 5, 2019
eae7d4d
Replace some for loops with stream operatoins
amalloy Jun 5, 2019
a716544
Cleanups in CheckReturnValue
amalloy Jun 6, 2019
c0e3539
Move @CheckReturnValue to the class level
amalloy Jun 6, 2019
205ad1a
Clean up EmptyIfStatement
cushon Jun 6, 2019
bd513dd
Don't repeat a bunch of work in MethodMatcher usage
amalloy Jun 6, 2019
b530fca
Remove an unused parameter
amalloy Jun 6, 2019
fc972db
Add the TemporalAmount implementations from org.threeten.extra to the…
tesztbela Jun 6, 2019
a63e46f
Fix open-source breakages caused by my recent update to Truth 0.45:
cpovirk Jun 6, 2019
47dfcb4
Make Matchers.parentNode type-safer
cushon Jun 6, 2019
e3766e4
Add a TODO to revisit nextStatement's handling of the last statement …
cushon Jun 7, 2019
163a2b7
Make methodName a String
ronshapiro Jun 7, 2019
4ed49ef
Discourage calling #toString on lite protos.
graememorgan Jun 10, 2019
0fbefb0
Add a check for calling checkNotNull twice on the same variable.
graememorgan Jun 11, 2019
7052474
Migrate AbstractToString onto java.util.Optional
graememorgan Jun 11, 2019
231d8b6
Fix typo in UnsafeFinalization.md
nick-someone Jun 11, 2019
03f19c9
Turn off ErrorProne for large code generators.
ronshapiro Jun 11, 2019
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
2 changes: 1 addition & 1 deletion annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.44</version>
<version>0.45</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ErrorProneOptions {
private static final String PATCH_OUTPUT_LOCATION = "-XepPatchLocation:";
private static final String PATCH_IMPORT_ORDER_PREFIX = "-XepPatchImportOrder:";
private static final String EXCLUDED_PATHS_PREFIX = "-XepExcludedPaths:";
private static final String IGNORE_LARGE_CODE_GENERATORS = "-XepIgnoreLargeCodeGenerators:";

private static final String ERRORS_AS_WARNINGS_FLAG = "-XepAllErrorsAsWarnings";
private static final String ENABLE_ALL_CHECKS = "-XepAllDisabledChecksAsWarnings";
Expand Down Expand Up @@ -165,6 +166,7 @@ final PatchingOptions build() {
private final PatchingOptions patchingOptions;
private final Pattern excludedPattern;
private final boolean ignoreSuppressionAnnotations;
private final boolean ignoreLargeCodeGenerators;

private ErrorProneOptions(
ImmutableMap<String, Severity> severityMap,
Expand All @@ -178,7 +180,8 @@ private ErrorProneOptions(
ErrorProneFlags flags,
PatchingOptions patchingOptions,
Pattern excludedPattern,
boolean ignoreSuppressionAnnotations) {
boolean ignoreSuppressionAnnotations,
boolean ignoreLargeCodeGenerators) {
this.severityMap = severityMap;
this.remainingArgs = remainingArgs;
this.ignoreUnknownChecks = ignoreUnknownChecks;
Expand All @@ -191,6 +194,7 @@ private ErrorProneOptions(
this.patchingOptions = patchingOptions;
this.excludedPattern = excludedPattern;
this.ignoreSuppressionAnnotations = ignoreSuppressionAnnotations;
this.ignoreLargeCodeGenerators = ignoreLargeCodeGenerators;
}

public String[] getRemainingArgs() {
Expand Down Expand Up @@ -221,6 +225,10 @@ public boolean isIgnoreSuppressionAnnotations() {
return ignoreSuppressionAnnotations;
}

public boolean ignoreLargeCodeGenerators() {
ronshapiro marked this conversation as resolved.
Show resolved Hide resolved
return ignoreLargeCodeGenerators;
}

public ErrorProneFlags getFlags() {
return flags;
}
Expand All @@ -241,6 +249,7 @@ private static class Builder {
private boolean disableAllChecks = false;
private boolean isTestOnlyTarget = false;
private boolean ignoreSuppressionAnnotations = false;
private boolean ignoreLargeCodeGenerators = true;
private Map<String, Severity> severityMap = new HashMap<>();
private final ErrorProneFlags.Builder flagsBuilder = ErrorProneFlags.builder();
private final PatchingOptions.Builder patchingOptionsBuilder = PatchingOptions.builder();
Expand Down Expand Up @@ -299,6 +308,10 @@ public void setEnableAllChecksAsWarnings(boolean enableAllChecksAsWarnings) {
this.enableAllChecksAsWarnings = enableAllChecksAsWarnings;
}

public void setIgnoreLargeCodeGenerators(boolean ignoreLargeCodeGenerators) {
this.ignoreLargeCodeGenerators = ignoreLargeCodeGenerators;
}

public void setDisableAllChecks(boolean disableAllChecks) {
// Discard previously set severities so that the DisableAllChecks flag is position sensitive.
severityMap.clear();
Expand Down Expand Up @@ -326,7 +339,8 @@ public ErrorProneOptions build(ImmutableList<String> remainingArgs) {
flagsBuilder.build(),
patchingOptionsBuilder.build(),
excludedPattern,
ignoreSuppressionAnnotations);
ignoreSuppressionAnnotations,
ignoreLargeCodeGenerators);
}

public void setExcludedPattern(Pattern excludedPattern) {
Expand Down Expand Up @@ -426,6 +440,7 @@ public static ErrorProneOptions processArgs(Iterable<String> args) {
} else if (arg.startsWith(EXCLUDED_PATHS_PREFIX)) {
String pathRegex = arg.substring(EXCLUDED_PATHS_PREFIX.length());
builder.setExcludedPattern(Pattern.compile(pathRegex));

} else {
remainingArgs.add(arg);
}
Expand Down
141 changes: 90 additions & 51 deletions check_api/src/main/java/com/google/errorprone/VisitorState.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package com.google.errorprone;

import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultiset;
import com.google.errorprone.BugPattern.SeverityLevel;
Expand Down Expand Up @@ -62,10 +64,8 @@ public class VisitorState {
private final StatisticsCollector statisticsCollector;
private final Map<String, SeverityLevel> severityMap;
private final ErrorProneOptions errorProneOptions;
private final Map<String, Optional<Type>> typeCache;
private final ErrorProneTimings timings;
private final SharedState sharedState;
public final Context context;

private final TreePath path;
private final SuppressionInfo.SuppressedState suppressedState;

Expand All @@ -87,8 +87,8 @@ public static VisitorState createForUtilityPurposes(Context context) {
// Can't use this VisitorState to report results, so no-op collector.
StatisticsCollector.createNoOpCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
SuppressedState.UNSUPPRESSED,
null);
}

/**
Expand All @@ -104,8 +104,8 @@ public static VisitorState createForCustomFindingCollection(
ErrorProneOptions.empty(),
StatisticsCollector.createCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
SuppressedState.UNSUPPRESSED,
null);
}

/**
Expand All @@ -123,8 +123,8 @@ public static VisitorState createConfiguredForCompilation(
errorProneOptions,
StatisticsCollector.createCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
SuppressedState.UNSUPPRESSED,
null);
}

/**
Expand All @@ -143,8 +143,8 @@ public VisitorState(Context context) {
// Can't use this VisitorState to report results, so no-op collector.
StatisticsCollector.createNoOpCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
SuppressedState.UNSUPPRESSED,
null);
}

/**
Expand All @@ -162,8 +162,8 @@ public VisitorState(Context context, DescriptionListener listener) {
ErrorProneOptions.empty(),
StatisticsCollector.createCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
SuppressedState.UNSUPPRESSED,
null);
}

/**
Expand All @@ -184,8 +184,8 @@ public VisitorState(
errorProneOptions,
StatisticsCollector.createCollector(),
null,
null,
SuppressedState.UNSUPPRESSED);
SuppressedState.UNSUPPRESSED,
null);
}

private VisitorState(
Expand All @@ -194,9 +194,9 @@ private VisitorState(
Map<String, SeverityLevel> severityMap,
ErrorProneOptions errorProneOptions,
StatisticsCollector statisticsCollector,
Map<String, Optional<Type>> typeCache,
TreePath path,
SuppressedState suppressedState) {
SuppressedState suppressedState,
SharedState sharedState) {
this.context = context;
this.descriptionListener = descriptionListener;
this.severityMap = severityMap;
Expand All @@ -205,14 +205,7 @@ private VisitorState(

this.suppressedState = suppressedState;
this.path = path;
this.timings = ErrorProneTimings.instance(context);
this.typeCache =
typeCache != null
? typeCache
// TODO(ronshapiro): should we presize this with a reasonable size? We can check for the
// smallest build and see how many types are loaded and use that. Or perhaps a heuristic
// based on number of files?
: new HashMap<>();
this.sharedState = sharedState != null ? sharedState : new SharedState(context);
}

public VisitorState withPath(TreePath path) {
Expand All @@ -222,9 +215,9 @@ public VisitorState withPath(TreePath path) {
severityMap,
errorProneOptions,
statisticsCollector,
typeCache,
path,
suppressedState);
suppressedState,
sharedState);
}

public VisitorState withPathAndSuppression(TreePath path, SuppressedState suppressedState) {
Expand All @@ -234,25 +227,29 @@ public VisitorState withPathAndSuppression(TreePath path, SuppressedState suppre
severityMap,
errorProneOptions,
statisticsCollector,
typeCache,
path,
suppressedState);
suppressedState,
sharedState);
}

public TreePath getPath() {
return path;
}

public TreeMaker getTreeMaker() {
return TreeMaker.instance(context);
return sharedState.treeMaker;
}

public Types getTypes() {
return Types.instance(context);
return sharedState.types;
}

public Symtab getSymtab() {
return Symtab.instance(context);
return sharedState.symtab;
}

public Names getNames() {
return sharedState.names;
}

public NullnessAnalysis getNullnessAnalysis() {
Expand Down Expand Up @@ -315,7 +312,7 @@ public ImmutableMultiset<String> counters() {
}

public Name getName(String nameStr) {
return Names.instance(context).fromString(nameStr);
return getNames().fromString(nameStr);
}

/**
Expand All @@ -331,7 +328,8 @@ public Name getName(String nameStr) {
*/
@Nullable
public Type getTypeFromString(String typeStr) {
return typeCache
return sharedState
.typeCache
.computeIfAbsent(typeStr, key -> Optional.fromNullable(getTypeFromStringInternal(key)))
.orNull();
}
Expand Down Expand Up @@ -360,12 +358,11 @@ private Type getTypeFromStringInternal(String typeStr) {
public Symbol getSymbolFromString(String symStr) {
symStr = inferBinaryName(symStr);
Name name = getName(symStr);
Modules modules = Modules.instance(context);
boolean modular = modules.getDefaultModule() != getSymtab().noModule;
boolean modular = sharedState.modules.getDefaultModule() != getSymtab().noModule;
if (!modular) {
return getSymbolFromString(getSymtab().noModule, name);
}
for (ModuleSymbol msym : Modules.instance(context).allModules()) {
for (ModuleSymbol msym : sharedState.modules.allModules()) {
ClassSymbol result = getSymbolFromString(msym, name);
if (result != null) {
// TODO(cushon): the path where we iterate over all modules is probably slow.
Expand Down Expand Up @@ -401,19 +398,32 @@ public ClassSymbol getSymbolFromString(ModuleSymbol msym, Name name) {
// TODO(cushon): consider migrating call sites to use binary names and removing this code.
// (But then we'd probably want error handling for probably-incorrect canonical names,
// so it may not end up being a performance win.)
private static String inferBinaryName(String classname) {
StringBuilder sb = new StringBuilder();
boolean first = true;
char sep = '.';
for (String bit : Splitter.on('.').split(classname)) {
if (!first) {
sb.append(sep);
}
sb.append(bit);
if (Character.isUpperCase(bit.charAt(0))) {
sep = '$';
@VisibleForTesting
static String inferBinaryName(String classname) {
int len = classname.length();
checkArgument(!classname.isEmpty(), "class name must be non-empty");
checkArgument(classname.charAt(len - 1) != '.', "invalid class name: %s", classname);

int lastPeriod = classname.lastIndexOf('.');
if (lastPeriod == -1) {
return classname; // top level class in default package
}
int secondToLastPeriod = classname.lastIndexOf('.', lastPeriod - 1);
if (secondToLastPeriod != -1
&& !Character.isUpperCase(classname.charAt(secondToLastPeriod + 1))) {
return classname; // top level class
}

StringBuilder sb = new StringBuilder(len);
boolean foundUppercase = false;
for (int i = 0; i < len; i++) {
char c = classname.charAt(i);
foundUppercase = foundUppercase || Character.isUpperCase(c);
if (c == '.') {
sb.append(foundUppercase ? '$' : '.');
} else {
sb.append(c);
}
first = false;
}
return sb.toString();
}
Expand Down Expand Up @@ -605,6 +615,35 @@ public boolean isAndroidCompatible() {

/** Returns a timing span for the given {@link Suppressible}. */
public AutoCloseable timingSpan(Suppressible suppressible) {
return timings.span(suppressible);
return sharedState.timings.span(suppressible);
}

/**
* Instances that every {@link VisitorState} instance can share.
*
* <p>For the types that are typically stored in {@link Context}, caching the references over
* {@code SomeClass.instance(context)} has sizable performance improvements in aggregate.
*/
private static final class SharedState {
private final Modules modules;
private final Names names;
private final Symtab symtab;
private final ErrorProneTimings timings;
private final Types types;
private final TreeMaker treeMaker;

// TODO(ronshapiro): should we presize this with a reasonable size? We can check for the
// smallest build and see how many types are loaded and use that. Or perhaps a heuristic
// based on number of files?
private final Map<String, Optional<Type>> typeCache = new HashMap<>();

SharedState(Context context) {
this.modules = Modules.instance(context);
this.names = Names.instance(context);
this.symtab = Symtab.instance(context);
this.timings = ErrorProneTimings.instance(context);
this.types = Types.instance(context);
this.treeMaker = TreeMaker.instance(context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ public boolean supportsSuppressWarnings() {
return info.supportsSuppressWarnings();
}

public boolean disableable() {
return info.disableable();
}

@Override
public Set<Class<? extends Annotation>> customSuppressionAnnotations() {
return info.customSuppressionAnnotations();
Expand Down
Loading