Skip to content

Commit 8749941

Browse files
author
Vincent Potucek
committed
[rewrite] Add Java8toJava11
Signed-off-by: Vincent Potucek <[email protected]>
1 parent 0d4cf65 commit 8749941

40 files changed

+134
-62
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ jobs:
9090
- name: 'Test'
9191
shell: bash
9292
run: mvn test -B
93+
- name: 'SanityCheck'
94+
shell: bash
95+
run: mvn rewrite:dryRun
9396
- name: 'Javadoc'
9497
shell: bash
9598
run: mvn -P '!examples' javadoc:javadoc

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
# intellij
1010
.idea/ant.xml
11-
.idea/codestream.xml
11+
.idea/checkstyle-idea.xml
1212
.idea/codeStyleSettings.xml
13+
.idea/codestream.xml
1314
.idea/compiler.xml
1415
.idea/copyright
1516
.idea/dataSources.ids
@@ -21,6 +22,7 @@
2122
.idea/libraries
2223
.idea/misc.xml
2324
.idea/modules.xml
25+
.idea/palantir-java-format.xml
2426
.idea/shelf
2527
.idea/tasks.xml
2628
.idea/uiDesigner.xml

check_api/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
<artifactId>jspecify</artifactId>
5050
<version>${jspecify.version}</version>
5151
</dependency>
52+
<dependency>
53+
<groupId>jakarta.annotation</groupId>
54+
<artifactId>jakarta.annotation-api</artifactId>
55+
<version>1.3.5</version>
56+
<scope>provided</scope>
57+
</dependency>
5258
<dependency>
5359
<!-- GPLv2 with Classpath Exception -->
5460
<groupId>io.github.eisop</groupId>
@@ -103,6 +109,12 @@
103109
<version>${truth.version}</version>
104110
<scope>test</scope>
105111
</dependency>
112+
<dependency>
113+
<groupId>jakarta.inject</groupId>
114+
<artifactId>jakarta.inject-api</artifactId>
115+
<version>1.0.3</version>
116+
<scope>test</scope>
117+
</dependency>
106118
<dependency>
107119
<!-- MIT -->
108120
<groupId>org.mockito</groupId>

check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.sun.tools.javac.tree.EndPosTable;
2727
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
2828
import java.net.URI;
29-
import java.nio.file.Paths;
29+
import java.nio.file.Path;
3030
import java.util.LinkedHashSet;
3131
import java.util.Objects;
3232
import java.util.Set;
@@ -68,7 +68,7 @@ private DescriptionBasedDiff(
6868
URI sourceFileUri = compilationUnit.getSourceFile().toUri();
6969
this.sourcePath =
7070
(sourceFileUri.isAbsolute() && Objects.equals(sourceFileUri.getScheme(), "file"))
71-
? Paths.get(sourceFileUri).toAbsolutePath().toString()
71+
? Path.of(sourceFileUri).toAbsolutePath().toString()
7272
: sourceFileUri.getPath();
7373
this.ignoreOverlappingFixes = ignoreOverlappingFixes;
7474
this.importsToAdd = new LinkedHashSet<>();

check_api/src/main/java/com/google/errorprone/dataflow/nullnesspropagation/inference/InferredNullability.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,18 @@ private Optional<Nullness> getNullness(InferenceVariable iv) {
8787
result =
8888
constraintGraph.predecessors(iv).stream()
8989
.map(this::getNullness)
90-
.filter(Optional::isPresent)
91-
.map(Optional::get)
90+
.flatMap(Optional::stream)
9291
.reduce(Nullness::leastUpperBound); // use least upper bound (lub) to combine
9392
// 2. If not, resolve successors and use them as upper bounds
94-
if (!result.isPresent()) {
93+
if (result.isEmpty()) {
9594
result =
9695
constraintGraph.successors(iv).stream()
9796
.map(this::getNullness)
98-
.filter(Optional::isPresent)
99-
.map(Optional::get)
97+
.flatMap(Optional::stream)
10098
.reduce(Nullness::greatestLowerBound); // use greatest lower bound (glb) to combine
10199
}
102100

103-
checkState(!inferredMemoTable.put(iv, result).isPresent());
101+
checkState(inferredMemoTable.put(iv, result).isEmpty());
104102
return result;
105103
}
106104
}

check_api/src/main/java/com/google/errorprone/dataflow/nullnesspropagation/inference/NullnessQualifierInference.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ private void generateConstraintsFromAnnotations(
153153

154154
Optional<Nullness> fromAnnotations =
155155
extractExplicitNullness(declaredType, argSelector.isEmpty() ? decl : null);
156-
if (!fromAnnotations.isPresent()) {
156+
if (fromAnnotations.isEmpty()) {
157157
// Check declared type before inferred type so that type annotations on the declaration take
158158
// precedence (just like declaration annotations) over annotations on the inferred type.
159159
// For instance, we want a @Nullable T m() to take precedence over annotations on T's inferred
160160
// type (e.g., @NotNull String), whether @Nullable is a declaration or type annotation.
161161
fromAnnotations = NullnessAnnotations.fromAnnotationsOn(inferredType);
162162
}
163-
if (!fromAnnotations.isPresent()) {
163+
if (fromAnnotations.isEmpty()) {
164164
if (declaredType instanceof TypeVariable typeVariable) {
165165
// Check bounds second so explicit annotations take precedence. Even for bounds we still use
166166
// equality constraint below since we have to assume the bound as the "worst" case.
@@ -482,7 +482,7 @@ private void generateConstraintsForWrite(
482482
boolean isBound = false;
483483
Optional<Nullness> fromAnnotations =
484484
extractExplicitNullness(lType, argSelector.isEmpty() ? decl : null);
485-
if (!fromAnnotations.isPresent()) {
485+
if (fromAnnotations.isEmpty()) {
486486
if (lType instanceof TypeVariable typeVariable) {
487487
fromAnnotations = NullnessAnnotations.getUpperBound(typeVariable);
488488
isBound = true;

check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ public static SuggestedFix.Builder addValuesToAnnotationArgument(
11321132
.replaceFirst("\\(\\)", "(" + parameterPrefix + newArgument(newValues) + ")"));
11331133
}
11341134
Optional<ExpressionTree> maybeExistingArgument = findArgument(annotation, parameterName);
1135-
if (!maybeExistingArgument.isPresent()) {
1135+
if (maybeExistingArgument.isEmpty()) {
11361136
return SuggestedFix.builder()
11371137
.prefixWith(
11381138
annotation.getArguments().getFirst(),
@@ -1192,7 +1192,7 @@ public static SuggestedFix.Builder updateAnnotationArgumentValues(
11921192
+ ')');
11931193
}
11941194
Optional<ExpressionTree> maybeExistingArgument = findArgument(annotation, parameterName);
1195-
if (!maybeExistingArgument.isPresent()) {
1195+
if (maybeExistingArgument.isEmpty()) {
11961196
return SuggestedFix.builder()
11971197
.prefixWith(
11981198
annotation.getArguments().getFirst(),

check_api/src/main/java/com/google/errorprone/matchers/method/MethodInvocationMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public static Matcher<ExpressionTree> compile(Iterable<Rule> rules) {
483483
// First collect all the nodes that accept any token at all
484484
for (Node node : curr) {
485485
for (Map.Entry<Optional<Token>, Node> entry : nfa.row(node).entrySet()) {
486-
if (!entry.getKey().isPresent()) {
486+
if (entry.getKey().isEmpty()) {
487487
acceptsAny.add(entry.getValue());
488488
}
489489
}

check_api/src/main/java/com/google/errorprone/util/Comments.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static ImmutableList<Commented<ExpressionTree>> findCommentsForArguments
111111

112112
CharSequence sourceCode = state.getSourceCode();
113113
Optional<Integer> endPosition = computeEndPosition(tree, sourceCode, state);
114-
if (!endPosition.isPresent()) {
114+
if (endPosition.isEmpty()) {
115115
return noComments(arguments);
116116
}
117117

check_api/src/test/java/com/google/errorprone/util/CommentsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static class ComputeEndPosition extends BugChecker implements MethodInvoc
5454
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
5555
CharSequence sourceCode = state.getSourceCode();
5656
Optional<Integer> endPosition = Comments.computeEndPosition(tree, sourceCode, state);
57-
if (!endPosition.isPresent()) {
57+
if (endPosition.isEmpty()) {
5858
return Description.NO_MATCH;
5959
}
6060
int startPosition = endPosition.get();

0 commit comments

Comments
 (0)