Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct J.FieldAccess#isFullyQualifiedClassReference() #4774

Merged
merged 10 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
knutwannheden marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading