Skip to content

Commit

Permalink
Correct J.FieldAccess.isFullyQualifiedClassReference()
Browse files Browse the repository at this point in the history
The commit e536ed2 introduced a regression here.

Fixes: #4773
  • Loading branch information
knutwannheden committed Dec 11, 2024
1 parent a473f26 commit e28e4bd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.SourceSpec;
import org.openrewrite.test.TypeValidation;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -2072,10 +2073,12 @@ void changeTypeInPropertiesFile() {
properties(
"""
a.property=java.lang.String
c.property=java.lang.StringBuilder
b.property=String
""",
"""
a.property=java.lang.Integer
c.property=java.lang.StringBuilder
b.property=String
""", spec -> spec.path("application.properties"))
);
Expand Down Expand Up @@ -2104,4 +2107,54 @@ void changeTypeInYaml() {
)
);
}

@Test
void testRecipe() {
// language=java
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.all())
.recipe(new ChangeType("org.codehaus.jackson.annotate.JsonIgnoreProperties", "com.fasterxml.jackson.annotation.JsonIgnoreProperties", false))
.parser(JavaParser.fromJavaVersion()
.dependsOn(
"""
package org.codehaus.jackson.annotate;
public @interface JsonIgnoreProperties {
boolean ignoreUnknown() default false;
}
""",
"""
package org.codehaus.jackson.annotate;
public @interface JsonIgnore {
}
"""
)
),
java(
"""
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class myClass {
@JsonIgnore
public boolean isDirty() {
return false;
}
}
""",
"""
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonIgnore;
@JsonIgnoreProperties(ignoreUnknown = true)
public class myClass {
@JsonIgnore
public boolean isDirty() {
return false;
}
}
"""
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ private boolean isFullyQualifiedClassReference(J.FieldAccess fieldAccess, String
return false;
}
String simpleName = fieldAccess.getName().getSimpleName();
if (!simpleName.regionMatches(0, className, dotIndex + 1, simpleName.length())) {
if (!simpleName.regionMatches(0, className, dotIndex + 1, className.length())) {
return false;
}
if (fieldAccess.getTarget() instanceof J.FieldAccess) {
Expand Down

0 comments on commit e28e4bd

Please sign in to comment.