Skip to content

Commit

Permalink
Merge branch 'main' into example-yaml-recipe-test
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Feb 6, 2024
2 parents 1d36f24 + 20b3d00 commit c6a7dfa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/
.gradle/
.idea/
out/
src/main/generated/
2 changes: 1 addition & 1 deletion gradle/licenseHeader.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 the original author or authors.
Copyright ${year} the original author or authors.
<p>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/yourorg/NoGuavaListsNewArrayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
.build();

@Override
public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) {
public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
if (NEW_ARRAY_LIST.matches(method)) {
maybeRemoveImport("com.google.common.collect.Lists");
maybeAddImport("java.util.ArrayList");
Expand All @@ -84,7 +84,7 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext execu
return newArrayListCapacity.apply(getCursor(), method.getCoordinates().replace(),
method.getArguments().get(0));
}
return super.visitMethodInvocation(method, executionContext);
return super.visitMethodInvocation(method, ctx);
}
}
);
Expand Down
11 changes: 8 additions & 3 deletions src/test/java/com/yourorg/NoGuavaListsNewArrayListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.yourorg;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
Expand All @@ -35,6 +36,7 @@ public void defaults(RecipeSpec spec) {
.classpath("guava"));
}

@DocumentExample
@Test
void replaceWithNewArrayList() {
rewriteRun(
Expand All @@ -45,7 +47,8 @@ void replaceWithNewArrayList() {
.logCompilationWarningsAndErrors(false)
.classpath("guava")),
// language=java
java("""
java(
"""
import com.google.common.collect.*;
import java.util.List;
Expand All @@ -70,7 +73,8 @@ class Test {
void replaceWithNewArrayListIterable() {
rewriteRun(
// language=java
java("""
java(
"""
import com.google.common.collect.*;
import java.util.Collections;
Expand Down Expand Up @@ -99,7 +103,8 @@ class Test {
void replaceWithNewArrayListWithCapacity() {
rewriteRun(
// language=java
java("""
java(
"""
import com.google.common.collect.*;
import java.util.ArrayList;
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/yourorg/SimplifyTernaryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package com.yourorg;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RewriteTest;

import static org.openrewrite.java.Assertions.java;

class SimplifyTernaryTest implements RewriteTest {
@DocumentExample
@Test
void simplified() {
rewriteRun(
Expand Down

0 comments on commit c6a7dfa

Please sign in to comment.