Skip to content

Commit

Permalink
refactor: OpenRewrite best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek and TeamModerne committed Sep 3, 2024
1 parent a87263c commit 6aa2464
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/openrewrite/FindCallGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
return new JavaIsoVisitor<ExecutionContext>() {

@Override
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext executionContext) {
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) {
if (classDecl.getType() == null) {
return Markup.warn(classDecl, new IllegalStateException("Class declaration is missing type attribution"));
}
return super.visitClassDeclaration(classDecl, executionContext);
return super.visitClassDeclaration(classDecl, ctx);
}

@Override
Expand Down
31 changes: 21 additions & 10 deletions src/test/java/org/openrewrite/FindCallGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void findUniqueCallsPerDeclaration() {
)
),
//language=java
java("""
java(
"""
class Test {
void test() {
System.out.println("Hello");
Expand Down Expand Up @@ -103,7 +104,8 @@ void filterStdLib() {
)
)),
//language=java
java("""
java(
"""
import java.util.List;
import java.util.ArrayList;
class Test {
Expand Down Expand Up @@ -150,7 +152,8 @@ void staticInitializer() {
)
),
//language=java
java("""
java(
"""
class Scratch {
static int i = bar();
static {
Expand Down Expand Up @@ -195,7 +198,8 @@ void initializer() {
)
),
//language=java
java("""
java(
"""
class Scratch {
int i = bar();
int j;
Expand Down Expand Up @@ -242,7 +246,8 @@ void innerClass() {
)
),
//language=java
java("""
java(
"""
class A {
class B {
void b() {
Expand Down Expand Up @@ -303,7 +308,8 @@ void anonymousClass() {
)
),
//language=java
java("""
java(
"""
class A {
public void method() {}
}
Expand Down Expand Up @@ -341,7 +347,8 @@ void companionObject() {
)
)
),
kotlin("""
kotlin(
"""
class A {
companion object {
@JvmStatic
Expand All @@ -354,12 +361,14 @@ fun main(args: Array<String>) {
);
}

@DocumentExample
@Test
void missingMethodMarked() {
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.none()),
//language=java
java("""
java(
"""
class A {
String s = foo();
}
Expand Down Expand Up @@ -404,7 +413,8 @@ void fieldDeclarationInitialization() {
)
),
//language=java
java("""
java(
"""
class A {
String instanceField = foo();
static String staticField = foo();
Expand Down Expand Up @@ -446,7 +456,8 @@ void initializerBlocks() {
)
),
//language=java
java("""
java(
"""
class A {
String instanceField;
{
Expand Down

0 comments on commit 6aa2464

Please sign in to comment.