Skip to content

Commit 42c5303

Browse files
committed
License header
1 parent c30baac commit 42c5303

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaMapsNewLinkedHashMap.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.openrewrite.java.migrate.guava;
217

318
import org.openrewrite.ExecutionContext;
@@ -12,7 +27,7 @@
1227

1328
public class NoGuavaMapsNewLinkedHashMap extends Recipe {
1429
private static final MethodMatcher NEW_LINKED_HASH_MAP = new MethodMatcher("com.google.common.collect.Maps newLinkedHashMap()");
15-
private static final MethodMatcher NEW_LINKED_HASH_MAP_ITERABLE = new MethodMatcher("com.google.common.collect.Maps newLinkedHashMap(java.util.Map)");
30+
private static final MethodMatcher NEW_LINKED_HASH_MAP_WITH_MAP = new MethodMatcher("com.google.common.collect.Maps newLinkedHashMap(java.util.Map)");
1631
private static final MethodMatcher NEW_LINKED_HASH_MAP_CAPACITY = new MethodMatcher("com.google.common.collect.Maps newLinkedHashMapWithExpectedSize(int)");
1732

1833
@Override
@@ -31,7 +46,7 @@ protected TreeVisitor<?, ExecutionContext> getApplicableTest() {
3146
@Override
3247
public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) {
3348
doAfterVisit(new UsesMethod<>(NEW_LINKED_HASH_MAP));
34-
doAfterVisit(new UsesMethod<>(NEW_LINKED_HASH_MAP_ITERABLE));
49+
doAfterVisit(new UsesMethod<>(NEW_LINKED_HASH_MAP_WITH_MAP));
3550
doAfterVisit(new UsesMethod<>(NEW_LINKED_HASH_MAP_CAPACITY));
3651
return cu;
3752
}
@@ -45,7 +60,7 @@ protected TreeVisitor<?, ExecutionContext> getVisitor() {
4560
.imports("java.util.LinkedHashMap")
4661
.build();
4762

48-
private final JavaTemplate newLinkedHashMapIterable = JavaTemplate.builder(this::getCursor, "new LinkedHashMap<>(#{any(java.util.Map)})")
63+
private final JavaTemplate newLinkedHashMapWithMap = JavaTemplate.builder(this::getCursor, "new LinkedHashMap<>(#{any(java.util.Map)})")
4964
.imports("java.util.LinkedHashMap")
5065
.build();
5166

@@ -59,10 +74,10 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext execu
5974
maybeRemoveImport("com.google.common.collect.Maps");
6075
maybeAddImport("java.util.LinkedHashMap");
6176
return method.withTemplate(newLinkedHashMap, method.getCoordinates().replace());
62-
} else if (NEW_LINKED_HASH_MAP_ITERABLE.matches(method)) {
77+
} else if (NEW_LINKED_HASH_MAP_WITH_MAP.matches(method)) {
6378
maybeRemoveImport("com.google.common.collect.Maps");
6479
maybeAddImport("java.util.LinkedHashMap");
65-
return method.withTemplate(newLinkedHashMapIterable, method.getCoordinates().replace(),
80+
return method.withTemplate(newLinkedHashMapWithMap, method.getCoordinates().replace(),
6681
method.getArguments().get(0));
6782
} else if (NEW_LINKED_HASH_MAP_CAPACITY.matches(method)) {
6883
maybeRemoveImport("com.google.common.collect.Maps");

0 commit comments

Comments
 (0)