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

Fix junit5 excavator #2631

Open
wants to merge 130 commits into
base: roomba/junit5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
a7fafcd
Excavator: Upgrade dependencies (#2523)
svc-excavator-bot Mar 16, 2023
1331867
Excavator: Upgrades Baseline to the latest version (#2524)
svc-excavator-bot Mar 16, 2023
b9008c0
Excavator: Update policy-bot config (#2527)
svc-excavator-bot Mar 22, 2023
1ee4197
Excavator: Upgrade dependencies (#2525)
svc-excavator-bot Mar 22, 2023
bbde931
Excavator: Upgrade dependencies (#2528)
svc-excavator-bot Mar 23, 2023
538c1e4
Excavator: Upgrade dependencies (#2529)
svc-excavator-bot Mar 23, 2023
e04a307
Excavator: Upgrade dependencies (#2531)
svc-excavator-bot Mar 25, 2023
8d58986
Excavator: Upgrade dependencies (#2532)
svc-excavator-bot Mar 26, 2023
0f4dd36
Excavator: Upgrade dependencies (#2533)
svc-excavator-bot Mar 28, 2023
b39a706
Excavator: Upgrade dependencies (#2536)
svc-excavator-bot Mar 29, 2023
71612e7
SafeLoggingPropagation uses new ASTHelpers.isRecord function (#2535)
carterkozak Mar 30, 2023
db7cd72
StrictUnusedVariable is not suppressed when UnusedVariable is disable…
carterkozak Mar 30, 2023
18de5e4
Autorelease 5.1.0
svc-autorelease Mar 30, 2023
bbf722a
Excavator: Upgrades Baseline to the latest version (#2538)
svc-excavator-bot Mar 30, 2023
0f4ce77
Excavator: Upgrade dependencies (#2539)
svc-excavator-bot Mar 31, 2023
33fb217
Excavator: Update gradle-jdks infrastructure plugins (#2540)
svc-excavator-bot Mar 31, 2023
11ef5b5
Add check: Use Collection.isEmpty() instead of comparing size() with …
mpritham Mar 31, 2023
3d9b353
Autorelease 5.2.0
svc-autorelease Mar 31, 2023
63856ba
Fix #2543 CardinalityEqualsZero equality comparison check (#2544)
schlosna Apr 1, 2023
d3e5faf
Autorelease 5.3.0
svc-autorelease Apr 1, 2023
9482b9f
Excavator: Upgrades Baseline to the latest version (#2542)
svc-excavator-bot Apr 1, 2023
df78651
Add OptionalOrElseMethodInvocation to README.md (#2534)
David132639 Apr 4, 2023
d3a622c
Add check: Use InvoationTargetException.getCause instead of getTarget…
mpritham Apr 4, 2023
1fa42ab
Autorelease 5.4.0
svc-autorelease Apr 4, 2023
200dc43
Excavator: Upgrades Baseline to the latest version (#2546)
svc-excavator-bot Apr 5, 2023
1705edd
Stop suggesting the save actions plugin (#2547)
CRogers Apr 6, 2023
a18bc7e
Autorelease 5.5.0
svc-autorelease Apr 6, 2023
9f6d53a
Excavator: Upgrades Baseline to the latest version (#2548)
svc-excavator-bot Apr 6, 2023
e835aff
Excavator: Upgrade dependencies (#2549)
svc-excavator-bot Apr 7, 2023
2997305
Excavator: Update open-source publishing plugins (#2550)
svc-excavator-bot Apr 7, 2023
92481db
Remove Save Actions external dep from persistent .idea config (#2551)
CRogers Apr 11, 2023
267dd19
Autorelease 5.6.0
svc-autorelease Apr 11, 2023
40a8f3a
Excavator: Upgrades Baseline to the latest version (#2553)
svc-excavator-bot Apr 11, 2023
ad9ee08
Excavator: Format Java files (#2554)
svc-excavator-bot Apr 12, 2023
b73d1a9
Excavator: Upgrade dependencies (#2556)
svc-excavator-bot Apr 16, 2023
d3771e5
Excavator: Upgrade buildscript dependencies (#2557)
svc-excavator-bot Apr 16, 2023
3db5e60
Excavator: Upgrade dependencies (#2558)
svc-excavator-bot Apr 17, 2023
d5d4c36
Excavator: Upgrade dependencies (#2559)
svc-excavator-bot Apr 17, 2023
b86a264
Excavator: Upgrade dependencies (#2560)
svc-excavator-bot Apr 18, 2023
d0da831
Excavator: Upgrade dependencies (#2562)
svc-excavator-bot Apr 19, 2023
6be194e
Excavator: Upgrade dependencies (#2564)
svc-excavator-bot Apr 19, 2023
5951355
fix eclipse classpath generation (#2563)
rzpt Apr 19, 2023
7433f16
Autorelease 5.7.0
svc-autorelease Apr 19, 2023
210d49b
Excavator: Upgrade dependencies (#2566)
svc-excavator-bot Apr 20, 2023
b33f802
Excavator: Upgrade dependencies (#2567)
svc-excavator-bot Apr 21, 2023
a192b76
Excavator: Upgrade dependencies (#2568)
svc-excavator-bot Apr 22, 2023
65823a6
Excavator: Upgrade dependencies (#2569)
svc-excavator-bot Apr 24, 2023
6a78e2e
Excavator: Upgrade dependencies (#2570)
svc-excavator-bot Apr 25, 2023
e26cd9e
Excavator: Format Java files (#2571)
svc-excavator-bot Apr 25, 2023
370f4a6
Excavator: Upgrades Baseline to the latest version (#2565)
svc-excavator-bot Apr 26, 2023
72d0b0a
Excavator: Upgrade dependencies (#2572)
svc-excavator-bot Apr 26, 2023
d18a14f
Excavator: Update policy-bot config (#2574)
svc-excavator-bot May 3, 2023
2f65d9d
Only pass posix file attributes if not on Windows (#2577)
athabet812 May 17, 2023
9bf2f07
Fix changelog (#2579)
athabet812 May 17, 2023
b659af1
Autorelease 5.8.0
svc-autorelease May 17, 2023
d72c1c2
Excavator: Upgrades Baseline to the latest version (#2580)
svc-excavator-bot May 17, 2023
e5a6139
Don't ignore all directories named build/ (#2578)
alxhill May 17, 2023
f7daf09
Autorelease 5.9.0
svc-autorelease May 17, 2023
0f379f2
Excavator: Upgrades Baseline to the latest version (#2581)
svc-excavator-bot May 18, 2023
d9bab71
Revert "Don't ignore all directories named build/ (#2578)" (#2582)
carterkozak May 18, 2023
34d3e3b
Autorelease 5.10.0
svc-autorelease May 18, 2023
18f8c5a
Excavator: Upgrades Baseline to the latest version (#2583)
svc-excavator-bot May 18, 2023
b8a4f49
Excavator: Format Java files (#2584)
svc-excavator-bot May 22, 2023
b619dab
Excavator: Format Java files (#2585)
svc-excavator-bot May 23, 2023
905734b
Add check replacing `stream.sorted().findFirst()` with `stream.min()`…
mpritham Jun 1, 2023
7822daa
Autorelease 5.11.0
svc-autorelease Jun 1, 2023
96ccf26
Excavator: Upgrades Baseline to the latest version (#2587)
svc-excavator-bot Jun 1, 2023
cea3491
Add instructions for turning error-prone's warnings into errors (#2575)
ash211 Jun 5, 2023
8355aa7
Upgrade errorprone to 2.19.1 (#2576)
AlexLandau Jun 5, 2023
c141f28
Autorelease 5.12.0
svc-autorelease Jun 5, 2023
1d55ad7
Excavator: Upgrades Baseline to the latest version (#2588)
svc-excavator-bot Jun 5, 2023
99524c3
Excavator: Update gradle-jdks infrastructure plugins (#2590)
svc-excavator-bot Jun 10, 2023
d1cf1d2
Opt out of the 'NotJavadoc' errorprone check (#2591)
carterkozak Jun 12, 2023
8a9c39f
Autorelease 5.13.0
svc-autorelease Jun 12, 2023
982f35e
Excavator: Upgrades Baseline to the latest version (#2592)
svc-excavator-bot Jun 13, 2023
1c48a0e
Excavator: Format Java files (#2594)
svc-excavator-bot Jun 20, 2023
b28b49c
Excavator: Upgrade Jackson to the latest stable release (#2595)
svc-excavator-bot Jun 21, 2023
d18d970
Excavator: Upgrade buildscript dependencies (#2598)
svc-excavator-bot Jun 26, 2023
a377360
Fix unintentional suppression of StrictUnusedVariable (#2599)
carterkozak Jun 26, 2023
4716923
Autorelease 5.14.0
svc-autorelease Jun 26, 2023
6dc5767
Excavator: Upgrade dependencies (#2573)
svc-excavator-bot Jun 26, 2023
72cff0d
Excavator: Upgrades Baseline to the latest version (#2600)
svc-excavator-bot Jun 26, 2023
c8e0bab
Excavator: Upgrades Baseline to the latest version (#2601)
svc-excavator-bot Jun 27, 2023
cafa70e
Fix nullaway checkerframework dependency (#2602)
carterkozak Jun 27, 2023
572905e
Autorelease 5.16.0
svc-autorelease Jun 27, 2023
b9e5c7c
Excavator: Upgrades Baseline to the latest version (#2603)
svc-excavator-bot Jun 27, 2023
7d340b8
Add error-prone check to prefer ZoneId constants (#2596)
pkoenig10 Jun 27, 2023
8577f4d
Autorelease 5.17.0
svc-autorelease Jun 27, 2023
0621df9
Excavator: Upgrades Baseline to the latest version (#2604)
svc-excavator-bot Jun 27, 2023
62e3161
Excavator: Upgrade dependencies (#2606)
svc-excavator-bot Jun 29, 2023
1f34a77
Excavator: Upgrade dependencies (#2607)
svc-excavator-bot Jun 30, 2023
80a8000
Excavator: Update policy-bot config (#2609)
svc-excavator-bot Jul 13, 2023
ead7d6b
Excavator: Upgrade dependencies (#2610)
svc-excavator-bot Jul 18, 2023
823192d
Excavator: Upgrade dependencies (#2611)
svc-excavator-bot Jul 21, 2023
c1a525c
Excavator: Upgrade dependencies (#2612)
svc-excavator-bot Jul 23, 2023
aae5041
Excavator: Update gradle-jdks infrastructure plugins (#2613)
svc-excavator-bot Jul 27, 2023
69a2a1c
Excavator: Upgrade dependencies (#2614)
svc-excavator-bot Jul 28, 2023
02124bd
Excavator: Upgrade dependencies (#2617)
svc-excavator-bot Jul 30, 2023
5230156
Excavator: Upgrade dependencies (#2618)
svc-excavator-bot Jul 31, 2023
8c28a5e
Excavator: Upgrade dependencies (#2619)
svc-excavator-bot Aug 2, 2023
345dfd7
Excavator: Update Caffeine Cache (#2621)
svc-excavator-bot Aug 7, 2023
1ece0a9
Excavator: Upgrade dependencies (#2620)
svc-excavator-bot Aug 7, 2023
206c106
Excavator: Update gradle-jdks infrastructure plugins (#2622)
svc-excavator-bot Aug 7, 2023
77a63c4
Excavator: Upgrade dependencies (#2623)
svc-excavator-bot Aug 10, 2023
9146919
Excavator: Upgrades Baseline to the latest version (#2625)
svc-excavator-bot Aug 13, 2023
e471cdc
Prefer InputStream.transferTo(OutputStream) (#2616)
schlosna Aug 18, 2023
16be1b5
Autorelease 5.19.0
svc-autorelease Aug 18, 2023
ea1f872
Excavator: Upgrades Baseline to the latest version (#2626)
svc-excavator-bot Aug 18, 2023
617d205
Excavator: Update open-source publishing plugins (#2627)
svc-excavator-bot Aug 20, 2023
390207d
Excavator: Upgrade buildscript dependencies (#2630)
svc-excavator-bot Aug 28, 2023
8ef9438
Fix junit5 excavator
schlosna Aug 28, 2023
f265e1c
Excavator: Update gradle-jdks infrastructure plugins (#2632)
svc-excavator-bot Aug 29, 2023
41af8c7
Improve SafeLoggingPropagation on Immutables (#2629)
carterkozak Aug 29, 2023
1b02033
Autorelease 5.20.0
svc-autorelease Aug 29, 2023
ec6287d
Excavator: Upgrades Baseline to the latest version (#2633)
svc-excavator-bot Aug 30, 2023
efe82a6
Upgrade error-prone to 2.21.1 (from 2.19.1) (#2628)
carterkozak Aug 31, 2023
cd14fa2
Autorelease 5.21.0
svc-autorelease Aug 31, 2023
7d4594c
Excavator: Upgrades Baseline to the latest version (#2634)
svc-excavator-bot Aug 31, 2023
dca88ac
Allow incubating method use inside other incubating methods (#2636)
pkoenig10 Sep 28, 2023
1eefbf5
Excavator: Upgrades Baseline to the latest version (#2637)
svc-excavator-bot Sep 28, 2023
777e9f7
Excavator: Upgrade buildscript dependencies (#2638)
svc-excavator-bot Oct 6, 2023
437d392
Use a `Proxy` for `JavaInstallationMetadata` so we can work across Gr…
felixdesouza Oct 12, 2023
642e1e3
Autorelease 5.23.0
svc-autorelease Oct 12, 2023
f6e4309
Lazy exact dependencies (#2639)
CRogers Oct 12, 2023
2381f40
Autorelease 5.24.0
svc-autorelease Oct 12, 2023
3d12d9e
Excavator: Upgrades Baseline to the latest version (#2640)
svc-excavator-bot Oct 12, 2023
bee51c4
Revert "Lazy exact dependencies (#2639)" (#2642)
CRogers Oct 13, 2023
aac80ff
Autorelease 5.25.0
svc-autorelease Oct 13, 2023
837b9c2
Excavator: Upgrades Baseline to the latest version (#2643)
svc-excavator-bot Oct 13, 2023
79e6fde
Merge remote-tracking branch 'origin/develop' into ds/junit5
schlosna Oct 17, 2023
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
.java-version
.project
.settings
.factorypath
.apt_generated_tests/
bin/
build
out/
docs/node_modules/
Expand Down
17 changes: 10 additions & 7 deletions .policy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ approval_rules:
allow_contributor: false
requires:
count: 1
admins: true
permissions: ["admin", "maintain"]

- name: two admins have approved
options:
allow_contributor: true
requires:
count: 2
admins: true
permissions: ["admin", "maintain"]

- name: changelog only and contributor approval
options:
allow_contributor: true
requires:
count: 1
admins: true
permissions: ["admin", "maintain"]
if:
only_changed_files:
paths:
Expand All @@ -45,23 +45,25 @@ approval_rules:
allow_contributor: true
requires:
count: 1
admins: true
permissions: ["admin", "maintain"]
if:
has_author_in:
users: [ "svc-excavator-bot" ]
users: [ "svc-excavator-bot", "dependabot[bot]" ]

- name: excavator only touched baseline, circle, gradle files, godel files, generated code, go dependencies, docker-compose-rule config or versions.props
requires:
count: 0
if:
has_author_in:
users: [ "svc-excavator-bot" ]
users: [ "svc-excavator-bot", "dependabot[bot]" ]
only_changed_files:
# product-dependencies.lock should never go here, to force review of all product (SLS) dependency changes
# this way excavator cannot change the deployability of a service or product via auto-merge
paths:
- "changelog/@unreleased/.*\\.yml"
- "^\\.baseline/.*$"
- "^(.+/)?Cargo.toml$"
- "^Cargo.lock$"
- "^\\.circleci/.*$"
- "^\\.docker-compose-rule\\.yml$"
- "^.*gradle$"
Expand All @@ -81,8 +83,9 @@ approval_rules:
- "^versions.lock$"
- "^internal/generated/.*"
- "^internal/generated_src/.*"
- "^gradle-baseline-java/src/main/resources/checkstyle.version$"
has_valid_signatures_by_keys:
key_ids: ["C9AF124A484882E0"]
key_ids: ["C9AF124A484882E0", "4AEE18F83AFDEB23"]

- name: excavator only touched config files
requires:
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ tasks.withType(JavaCompile).configureEach(new Action<Task>() {
})
```

To turn all of error-prone's warnings into errors:

```gradle
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs += ['-Werror']
}
}
```

More information on error-prone severity handling can be found at [errorprone.info/docs/flags](http://errorprone.info/docs/flags).

#### Baseline error-prone checks
Expand Down Expand Up @@ -166,6 +176,7 @@ Safe Logging can be found at [github.com/palantir/safe-logging](https://github.c
- `DangerousStringInternUsage`: Disallow String.intern() invocations in favor of more predictable, scalable alternatives.
- `OptionalOrElseThrowThrows`: Optional.orElseThrow argument must return an exception, not throw one.
- `OptionalOrElseGetValue`: Prefer `Optional.orElse(value)` over `Optional.orElseGet(() -> value)` for trivial expressions.
- `OptionalOrElseMethodInvocation`: Prefer `Optional.orElseGet(() -> methodInvocation())` over `Optional.orElse(methodInvocation())`.
- `LambdaMethodReference`: Lambda should use a method reference.
- `SafeLoggingExceptionMessageFormat`: SafeLoggable exceptions do not interpolate parameters.
- `StrictUnusedVariable`: Functions shouldn't have unused parameters.
Expand Down Expand Up @@ -204,6 +215,7 @@ Safe Logging can be found at [github.com/palantir/safe-logging](https://github.c
- `UnnecessarilyQualified`: Types should not be qualified if they are also imported.
- `DeprecatedGuavaObjects`: `com.google.common.base.Objects` has been obviated by `java.util.Objects`.
- `JavaTimeSystemDefaultTimeZone`: Avoid using the system default time zone.
- `ZoneIdConstant`: Prefer `ZoneId` constants.
- `IncubatingMethod`: Prevents calling Conjure incubating APIs unless you explicitly opt-out of the check on a per-use or per-project basis.
- `CompileTimeConstantViolatesLiskovSubstitution`: Requires consistent application of the `@CompileTimeConstant` annotation to resolve inconsistent validation based on the reference type on which the met is invoked.
- `ClassInitializationDeadlock`: Detect type structures which can cause deadlocks initializing classes.
Expand All @@ -215,6 +227,8 @@ Safe Logging can be found at [github.com/palantir/safe-logging](https://github.c
- `BugCheckerAutoService`: Concrete BugChecker implementations should be annotated `@AutoService(BugChecker.class)` for auto registration with error-prone.
- `DangerousCollapseKeysUsage`: Disallow usage of `EntryStream#collapseKeys()`.
- `JooqBatchWithoutBindArgs`: jOOQ batch methods that execute without bind args can cause performance problems.
- `InvocationTargetExceptionGetTargetException`: InvocationTargetException.getTargetException() predates the general-purpose exception chaining facility. The Throwable.getCause() method is now the preferred means of obtaining this information. [(source)](https://docs.oracle.com/en/java/javase/17/docs/api//java.base/java/lang/reflect/InvocationTargetException.html#getTargetException())
- `PreferInputStreamTransferTo`: Prefer JDK `InputStream.transferTo(OutputStream)` over utility methods such as `com.google.common.io.ByteStreams.copy(InputStream, OutputStream)`, `org.apache.commons.io.IOUtils.copy(InputStream, OutputStream)`, `org.apache.commons.io.IOUtils.copyLong(InputStream, OutputStream)`.

### Programmatic Application

Expand Down
2 changes: 1 addition & 1 deletion baseline-error-prone/baseline-class-uniqueness.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Run ./gradlew checkClassUniqueness --write-locks to update this file

## runtimeClasspath
[org.checkerframework:checker-qual, org.checkerframework:dataflow-errorprone]
[io.github.eisop:dataflow-errorprone, org.checkerframework:checker-qual]
- org.checkerframework.dataflow.qual.Deterministic
- org.checkerframework.dataflow.qual.Pure
- org.checkerframework.dataflow.qual.Pure$Kind
Expand Down
3 changes: 2 additions & 1 deletion baseline-error-prone/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ javaVersion {
dependencies {
implementation 'com.google.errorprone:error_prone_core'
// Ensure a new enough version of dataflow-errorprone is available
implementation 'org.checkerframework:dataflow-errorprone'
implementation 'io.github.eisop:dataflow-errorprone'

testImplementation gradleApi()
testImplementation 'com.palantir.tokens:auth-tokens'
Expand All @@ -23,6 +23,7 @@ dependencies {
testImplementation 'com.palantir.safe-logging:logger'
testImplementation 'org.slf4j:slf4j-api'
testImplementation 'org.apache.commons:commons-lang3'
testImplementation 'commons-io:commons-io'
testImplementation 'commons-lang:commons-lang'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.immutables:value::annotations'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* (c) Copyright 2023 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.baseline.errorprone;

import com.google.auto.service.AutoService;
import com.google.errorprone.BugPattern;
import com.google.errorprone.BugPattern.SeverityLevel;
import com.google.errorprone.VisitorState;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.fixes.SuggestedFix;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.matchers.Matchers;
import com.google.errorprone.matchers.method.MethodMatchers;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.BinaryTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.Tree.Kind;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import org.immutables.value.Value.Immutable;

@AutoService(BugChecker.class)
@BugPattern(
link = "https://github.com/palantir/gradle-baseline#baseline-error-prone-checks",
linkType = BugPattern.LinkType.CUSTOM,
severity = SeverityLevel.SUGGESTION,
summary = "Use the isEmpty method instead of checking collection size")
public final class CardinalityEqualsZero extends BugChecker implements BugChecker.BinaryTreeMatcher {
private static final Matcher<ExpressionTree> COLLECTION_SIZE_METHOD_MATCHER = MethodMatchers.instanceMethod()
.onDescendantOf(Collection.class.getName())
.named("size")
.withNoParameters();

private static final Matcher<ExpressionTree> INT_ZERO = Matchers.intLiteral(0);

@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
Optional<EqualsZeroExpression> maybeEqualsZeroExpression = getEqualsZeroExpression(tree, state);
if (maybeEqualsZeroExpression.isEmpty()) {
return Description.NO_MATCH;
}

EqualsZeroExpression equalsZeroExpression = maybeEqualsZeroExpression.get();
ExpressionTree operand = equalsZeroExpression.operand();
if (!Objects.equals(operand.getKind(), Kind.METHOD_INVOCATION)) {
return Description.NO_MATCH;
}

ExpressionTree collectionInstance = ASTHelpers.getReceiver(operand);
if (collectionInstance == null || isExpressionThis(collectionInstance)) {
return Description.NO_MATCH;
}

if (COLLECTION_SIZE_METHOD_MATCHER.matches(operand, state)) {
return describeMatch(
tree,
SuggestedFix.replace(
tree,
(equalsZeroExpression.type() == ExpressionType.NEQ ? "!" : "")
+ state.getSourceForNode(collectionInstance)
+ ".isEmpty()"));
}

return Description.NO_MATCH;
}

private static boolean isExpressionThis(ExpressionTree tree) {
switch (tree.getKind()) {
case IDENTIFIER:
return ((IdentifierTree) tree).getName().contentEquals("this");
case MEMBER_SELECT:
return ((MemberSelectTree) tree).getIdentifier().contentEquals("this");
default:
return false;
}
}

private static Optional<EqualsZeroExpression> getEqualsZeroExpression(BinaryTree tree, VisitorState state) {
ExpressionType ret;
switch (tree.getKind()) {
case EQUAL_TO:
ret = ExpressionType.EQ;
break;
case NOT_EQUAL_TO:
ret = ExpressionType.NEQ;
break;
default:
return Optional.empty();
}
ExpressionTree leftOperand = tree.getLeftOperand();
ExpressionTree rightOperand = tree.getRightOperand();

if (INT_ZERO.matches(leftOperand, state)) {
return Optional.of(EqualsZeroExpression.builder()
.type(ret)
.operand(rightOperand)
.build());
} else if (INT_ZERO.matches(rightOperand, state)) {
return Optional.of(EqualsZeroExpression.builder()
.type(ret)
.operand(leftOperand)
.build());
}

return Optional.empty();
}

enum ExpressionType {
EQ,
NEQ
}

@Immutable
interface EqualsZeroExpression {
ExpressionType type();

ExpressionTree operand();

class Builder extends ImmutableEqualsZeroExpression.Builder {}

static Builder builder() {
return new Builder();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
for (VarSymbol parameter : methodSymbol.getParameters()) {
++parameterIndex;

if (ASTHelpers.hasAnnotation(parameter, CompileTimeConstant.class, state)) {
if (ASTHelpers.hasAnnotation(parameter, CompileTimeConstant.class.getName(), state)) {
if (anySuperMethodsMissingParameterAnnotation(superMethods, parameterIndex, state)) {
state.reportMatch(buildDescription(tree.getParameters().get(parameterIndex))
.setMessage("@CompileTimeConstant annotations on method parameters "
Expand Down Expand Up @@ -98,7 +98,7 @@ private boolean anySuperMethodsMissingParameterAnnotation(
Set<MethodSymbol> superMethods, int parameterIndex, VisitorState state) {
for (MethodSymbol superMethod : superMethods) {
VarSymbol parameter = superMethod.getParameters().get(parameterIndex);
if (!ASTHelpers.hasAnnotation(parameter, CompileTimeConstant.class, state)) {
if (!ASTHelpers.hasAnnotation(parameter, CompileTimeConstant.class.getName(), state)) {
return true;
}
}
Expand All @@ -109,7 +109,7 @@ private boolean anySuperMethodsHaveParameterAnnotation(
Set<MethodSymbol> superMethods, int parameterIndex, VisitorState state) {
for (MethodSymbol superMethod : superMethods) {
VarSymbol parameter = superMethod.getParameters().get(parameterIndex);
if (ASTHelpers.hasAnnotation(parameter, CompileTimeConstant.class, state)) {
if (ASTHelpers.hasAnnotation(parameter, CompileTimeConstant.class.getName(), state)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private boolean hasJavaxInclusionsOnType(TypeSymbol symbol, VisitorState state)
.addAll(classType.getInterfaces())
.build();
for (Type t : thisAndParents) {
for (Symbol sym : t.tsym.getEnclosedElements()) {
for (Symbol sym : ASTHelpers.getEnclosedElements(t.tsym)) {
if (HAS_JAXRS_ANNOTATION.test(sym)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
public final class IncubatingMethod extends BugChecker
implements BugChecker.MethodInvocationTreeMatcher, BugChecker.MemberReferenceTreeMatcher {

/** Matcher for the Incubating annotation, using the full qualified path. */
private static final Matcher<Tree> INCUBATING_MATCHER =
Matchers.symbolHasAnnotation("com.palantir.conjure.java.lib.internal.Incubating");
private static final String INCUBATING = "com.palantir.conjure.java.lib.internal.Incubating";

private static final Matcher<Tree> INCUBATING_MATCHER = Matchers.symbolHasAnnotation(INCUBATING);
private static final Matcher<Tree> IN_INCUBATING_MATCHER =
Matchers.enclosingMethod(Matchers.symbolHasAnnotation(INCUBATING));

@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
Expand All @@ -55,6 +57,10 @@ private Description checkTree(Tree tree, VisitorState state) {
return Description.NO_MATCH;
}

if (IN_INCUBATING_MATCHER.matches(tree, state)) {
return Description.NO_MATCH;
}

// Allow users to test incubating endpoints in test code without complaining.
if (TestCheckUtils.isTestCode(state)) {
return Description.NO_MATCH;
Expand Down
Loading