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 #642

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
35b4442
Fix false positives from FunctionalInterfaceClash.
May 24, 2017
971f4de
Automated rollback of 8a87d5714da2668a0044983ae3a86912ec160582.
cushon May 25, 2017
0c31402
Support all annotations named 'GuardedBy'
cushon May 25, 2017
88e39d0
Refactor duplicated code for finding super-method symbol to the Error…
panhania May 25, 2017
c44ae4c
Fix docs for NamedParameters
plumpy May 26, 2017
75f7a2b
Add java.util.Optional{Double,Int,Long} and java.util.UUID to the lis…
nick-someone May 26, 2017
6d4472d
Add a simplified checker to warn about inconsistent overloads.
panhania May 26, 2017
a60e149
Fix ASTHelpers.hasAnnotation and Matchers.hasAnnotation to not consid…
May 30, 2017
3a79fd6
Add MultimapSubject.containsExactly() and MultimapSubject.comparingVa…
Monnoroch May 31, 2017
3215c1c
Bug Fix: BugCheckers should *only* be instantiated by ScannerSupplier…
epmjohnston Jun 2, 2017
f2aaa2c
Add a second reverification pass to placeholder methods.
lowasser Jun 2, 2017
a9cdfd7
Update documentation for PackageLocation to clarify that the package …
nick-someone Jun 2, 2017
5f9a2ec
Swap IterableAndIterator{Positive,Negative}Cases, as they represent the
nick-someone Jan 7, 2017
8e7e8b4
Fix test breakage due to removal of GeneratedMessage.Builder#parseUnk…
Jun 7, 2017
a9c4a64
Updated NamedParameters to improve error message when comment doesn't…
Apr 7, 2017
92e5179
Deprecate BugPattern.category, replacing it with a set of String tags…
nick-someone Jun 12, 2017
215ee79
Edited ShortCircuitBoolean ErrorProne fix to only show one suggested …
Jun 13, 2017
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
82 changes: 80 additions & 2 deletions annotation/src/main/java/com/google/errorprone/BugPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,65 @@
*/
@Retention(RUNTIME)
public @interface BugPattern {

/** A collection of standardized tags that can be applied to BugPatterns. */
final class StandardTags {
private StandardTags() {}

/**
* This check, for reasons of backwards compatibility or difficulty in cleaning up, should be
* considered very likely to represent a real error in the vast majority ({@code >99.9%}) of
* cases, but couldn't otherwise be turned on as an ERROR.
*
* <p>Systems trying to determine the set of likely errors from a collection of BugPatterns
* should act as if any BugPattern with {@link #severity()} of {@link SeverityLevel#ERROR} also
* has this tag.
*/
public static final String LIKELY_ERROR = "LikelyError";

/**
* This check detects a coding pattern that is valid within the Java language and doesn't
* represent a runtime defect, but is otherwise discouraged for reasons of consistency within a
* project or ease of understanding by other programmers.
*
* <p>Checks using this tag should limit their replacements to those that don't change the
* behavior of the code (for example: adding clarifying parentheses, reordering modifiers in a
* single declaration, removing implicit modifiers like {@code public} for members in an {@code
* interface}).
*/
public static final String STYLE = "Style";

/**
* This check detects a potential performance issue, where an easily-identifiable replacement
* for the code being made will always result in a net positive performance improvement.
*/
public static final String PERFORMANCE = "Performance";

/**
* This check detects code that may technically be working within a limited domain, but is
* fragile, or violates generally-accepted assumptions of behavior.
*
* <p>Examples: DefaultCharset, where code implicitly uses the JVM default charset, will work in
* circumstances where data being fed to the system happens to be compatible with the Charset,
* but breaks down if fed data outside.
*/
public static final String FRAGILE_CODE = "FragileCode";

/**
* This check points out potential issues when operating in a concurrent context
*
* <p>The code may work fine when accessed by 1 thread at a time, but may have some unintended
* behavior when running in multiple threads.
*/
public static final String CONCURRENCY = "Concurrency";

/**
* This check points out a coding pattern that, while functional, has an easier-to-read or
* faster alternative.
*/
public static final String SIMPLIFICATION = "Simplification";
}

/**
* A unique identifier for this bug, used for @SuppressWarnings and in the compiler error message.
*/
Expand All @@ -52,8 +111,27 @@ public enum LinkType {
NONE
}

/** The class of bug this bug checker detects. */
Category category();
/**
* A list of Stringly-typed tags to apply to this check. These tags can be consumed by tools
* aggregating Error Prone checks (for example: a git pre-commit hook could clean up Java source
* by finding any checks tagged "Style", run an Error Prone compile over the code with those
* checks enabled, collect the fixes suggested and apply them).
*
* <p>To allow for sharing of tags across systems, a number of standard tags are available as
* static constants in {@link StandardTags}. It is strongly encouraged to extract any custom tags
* used in annotation property to constants that are shared by your codebase.
*/
String[] tags() default {};

/**
* The class of bug this bug checker detects.
*
* @deprecated This category field hasn't provided much value, as the 'problem domain' of each
* BugChecker is evident from the checker itself. We've introduced {@link #tags} as a means to
* apply general tags to checks.
*/
@Deprecated
Category category() default Category.ONE_OFF;

public enum Category {
/** General Java or JDK errors. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.errorprone;

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Collections2;
import java.lang.annotation.Annotation;
Expand All @@ -31,14 +30,6 @@
*/
public class BugPatternValidator {

private static final Function<Class<? extends Annotation>, String> GET_CANONICAL_NAME =
new Function<Class<? extends Annotation>, String>() {
@Override
public String apply(Class<? extends Annotation> input) {
return input.getCanonicalName();
}
};

private static final Joiner COMMA_JOINER = Joiner.on(", ");

public static void validate(BugPattern pattern) throws ValidationException {
Expand Down Expand Up @@ -81,7 +72,8 @@ public static void validate(BugPattern pattern) throws ValidationException {
String.format(
"Expected no custom suppression annotations but found these: %s",
COMMA_JOINER.join(
Collections2.transform(customSuppressionAnnotations, GET_CANONICAL_NAME))));
Collections2.transform(
customSuppressionAnnotations, Class::getCanonicalName))));
}
break;
}
Expand Down

This file was deleted.

39 changes: 24 additions & 15 deletions check_api/src/main/java/com/google/errorprone/BugCheckerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class BugCheckerInfo implements Serializable {
*/
private final ImmutableSet<String> allNames;

/** Set of String tags associated with the checker. */
private final ImmutableSet<String> tags;

/**
* The error message to print in compiler diagnostics when this check triggers. Corresponds to the
* {@code summary} attribute from its {@code BugPattern}.
Expand Down Expand Up @@ -105,19 +108,18 @@ public static BugCheckerInfo create(Class<? extends BugChecker> checker) {
}

private BugCheckerInfo(Class<? extends BugChecker> checker, BugPattern pattern) {
this.checker = checker;
canonicalName = pattern.name();
allNames = ImmutableSet.<String>builder().add(canonicalName).add(pattern.altNames()).build();
message = pattern.summary();
defaultSeverity = pattern.severity();
linkUrl = createLinkUrl(pattern);
suppressibility = pattern.suppressibility();
if (suppressibility == Suppressibility.CUSTOM_ANNOTATION) {
customSuppressionAnnotations =
new HashSet<>(Arrays.asList(pattern.customSuppressionAnnotations()));
} else {
customSuppressionAnnotations = Collections.<Class<? extends Annotation>>emptySet();
}
this(
checker,
pattern.name(),
ImmutableSet.<String>builder().add(pattern.name()).add(pattern.altNames()).build(),
pattern.summary(),
pattern.severity(),
createLinkUrl(pattern),
pattern.suppressibility(),
pattern.suppressibility() == Suppressibility.CUSTOM_ANNOTATION
? new HashSet<>(Arrays.asList(pattern.customSuppressionAnnotations()))
: Collections.emptySet(),
ImmutableSet.copyOf(pattern.tags()));
}

private BugCheckerInfo(
Expand All @@ -128,7 +130,8 @@ private BugCheckerInfo(
SeverityLevel defaultSeverity,
String linkUrl,
Suppressibility suppressibility,
Set<Class<? extends Annotation>> customSuppressionAnnotations) {
Set<Class<? extends Annotation>> customSuppressionAnnotations,
ImmutableSet<String> tags) {
this.checker = checker;
this.canonicalName = canonicalName;
this.allNames = allNames;
Expand All @@ -137,6 +140,7 @@ private BugCheckerInfo(
this.linkUrl = linkUrl;
this.suppressibility = suppressibility;
this.customSuppressionAnnotations = customSuppressionAnnotations;
this.tags = tags;
}

/**
Expand All @@ -156,7 +160,8 @@ public BugCheckerInfo withCustomDefaultSeverity(SeverityLevel defaultSeverity) {
defaultSeverity,
linkUrl,
suppressibility,
customSuppressionAnnotations);
customSuppressionAnnotations,
tags);
}

private static final String URL_FORMAT = "http://errorprone.info/bugpattern/%s";
Expand Down Expand Up @@ -229,6 +234,10 @@ public Set<Class<? extends Annotation>> customSuppressionAnnotations() {
return customSuppressionAnnotations;
}

public ImmutableSet<String> getTags() {
return tags;
}

public Class<? extends BugChecker> checkerClass() {
return checker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static RefactoringCollection refactor(PatchingOptions patchingOptions) {
Function<URI, RefactoringResult> postProcess;

if (patchingOptions.inPlace()) {
fileDestination = new FsFileDestination();
fileDestination = new FsFileDestination(rootPath);
postProcess =
uri ->
RefactoringResult.create(
Expand Down Expand Up @@ -160,7 +160,7 @@ RefactoringResult applyChanges(URI uri) throws Exception {
return RefactoringResult.create("", RefactoringResultType.NO_CHANGES);
}

doApplyProcess(fileDestination, new FsFileSource(), listeners);
doApplyProcess(fileDestination, new FsFileSource(rootPath), listeners);
return postProcess.apply(uri);
}

Expand All @@ -186,16 +186,19 @@ private void doApplyProcess(
Collection<DelegatingDescriptionListener> listeners) {
for (DelegatingDescriptionListener listener : listeners) {
try {
SourceFile file = fileSource.readFile(listener.base.getPath());
SourceFile file = fileSource.readFile(listener.base.getRelevantFileName());
listener.base.applyDifferences(file);
fileDestination.writeFile(file);
} catch (IOException e) {
logger.log(Level.WARNING, "Failed to apply diff to file " + listener.base.getPath(), e);
logger.log(
Level.WARNING,
"Failed to apply diff to file " + listener.base.getRelevantFileName(),
e);
}
}
}

private static final class DelegatingDescriptionListener implements DescriptionListener {
private final class DelegatingDescriptionListener implements DescriptionListener {
final DescriptionBasedDiff base;
final DescriptionListener listener;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.google.errorprone.matchers.Description;
import com.sun.tools.javac.tree.EndPosTable;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedHashSet;
import java.util.Set;

Expand All @@ -40,6 +38,7 @@
*/
public final class DescriptionBasedDiff implements DescriptionListener, Diff {

private final String sourcePath;
private final boolean ignoreOverlappingFixes;
private final JCCompilationUnit compilationUnit;
private final Set<String> importsToAdd;
Expand All @@ -63,6 +62,7 @@ private DescriptionBasedDiff(
boolean ignoreOverlappingFixes,
ImportOrganizer importOrganizer) {
this.compilationUnit = checkNotNull(compilationUnit);
this.sourcePath = compilationUnit.getSourceFile().toUri().getPath();
this.ignoreOverlappingFixes = ignoreOverlappingFixes;
this.importsToAdd = new LinkedHashSet<>();
this.importsToRemove = new LinkedHashSet<>();
Expand All @@ -71,8 +71,8 @@ private DescriptionBasedDiff(
}

@Override
public Path getPath() {
return Paths.get(compilationUnit.getSourceFile().toUri());
public String getRelevantFileName() {
return sourcePath;
}

public boolean isEmpty() {
Expand Down
6 changes: 2 additions & 4 deletions check_api/src/main/java/com/google/errorprone/apply/Diff.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@

package com.google.errorprone.apply;

import java.nio.file.Path;

/**
* All the differences to be applied to a source file to be applied in a refactoring.
*
* @author [email protected] (Simon Nickerson)
*/
public interface Diff {
/** Gets the path of the file this difference applies to */
public Path getPath();
/** Gets the name of the file this difference applies to */
public String getRelevantFileName();

/**
* Applies this difference to the supplied {@code sourceFile}.
Expand Down
Loading