Comments (6)
Findings:
- Compilation errors being swallowed for classes provided via
dependsOn
, if a class is not declared on the default package:
1255073806633000:3: error: class MySchemaType is public, should be declared in a file named MySchemaType.java
public class MySchemaType {}
^
There's a fix for this issue: #4040
-
Identified a possible small optimization on
ChangeTypeVisitor
- There's a fix for this issue: #4039 -
Package names used the failing test does not follow the the conventions, although their values are valid. For example,
ChangeType
usesJavaType.ShallowClass.build(oldFullyQualifiedTypeName)
to create type references. Thebuild
method identifies names based on conventions; it considers that if an uppercase letter comes after a dot, the next identifier is a class name.
from rewrite.
Updated the last comment with the fixes for the first 2 findings.
from rewrite.
That's a strange case indeed; thanks for the detailed runnable example. I wouldn't quite know why that's missed here. I'm guessing you ran into this when doing something similar in an actual recipe beyond this test case?
Thanks for the offer to look into this as well!
from rewrite.
Thanks for the fixes so far! I've given the test that you provided above another go and I can replicate it using only a capital letter in the package name already 🤔
@Test
void renamePackageWithDependsOn() {
@Language("java") final String schemaClass1 = """
package foo.Capital;
public class MySchemaType {}
""";
@Language("java") final String schemaClass2 = """
package bar.Capital;
public class MySchemaType {}
""";
rewriteRun(
spec -> spec
.parser(JavaParser.fromJavaVersion().dependsOn(schemaClass1, schemaClass2))
.recipe(new ChangeType(
"foo.Capital.MySchemaType",
"bar.Capital.MySchemaType",
true
)),
//language=java
java(
"""
package my.example.app;
import foo.Capital.MySchemaType;
class MyApp {
void doWork(MySchemaType mySchema) {}
}
""",
"""
package my.example.app;
import bar.Capital.MySchemaType;
class MyApp {
void doWork(MySchemaType mySchema) {}
}
"""
)
);
}
Which again fails with
diff --git a/my/example/app/MyApp.java b/my/example/app/MyApp.java
index 7fe83d7..9ff90dd 100644
--- a/my/example/app/MyApp.java
+++ b/my/example/app/MyApp.java
@@ -1,7 +1,5 @@
package my.example.app;
-import bar.Capital.MySchemaType;
-
class MyApp {
void doWork(MySchemaType mySchema) {}
}
from rewrite.
Look like we misidentify an owning class where there is none, just because the package contains an uppercase letter. :/
from rewrite.
Here's a simpler test:
@Test
void changeTypeWithCapitalLettersInPackageName() {
@Language("java") final String schemaClass = """
package bar.Capital;
public class MySchemaType {}
""";
rewriteRun(
java(schemaClass, spec -> spec.afterRecipe(cu -> {
JavaType.FullyQualified typeFromParser = cu.getClasses().get(0).getType();
// Called on ChangeClassDefinition constructor
JavaType.ShallowClass shallowClass = JavaType.ShallowClass
.build(typeFromParser.getFullyQualifiedName());
assertThat(shallowClass)
.hasFieldOrPropertyWithValue("fullyQualifiedName", typeFromParser.getFullyQualifiedName())
.hasFieldOrPropertyWithValue("owningClass", typeFromParser.getOwningClass());
}
))
);
}
And a variant for classes starting with lowercase letters, also failing:
@Test
void changeTypeWithClassNamesStartingWithLowercaseLetters() {
@Language("java") final String schemaClass = """
package bar.capital;
public class mySchemaType {}
""";
rewriteRun(
java(schemaClass, spec -> spec.afterRecipe(cu -> {
JavaType.FullyQualified typeFromParser = cu.getClasses().get(0).getType();
// Called on ChangeClassDefinition constructor
JavaType.ShallowClass shallowClass = JavaType.ShallowClass
.build(typeFromParser.getFullyQualifiedName());
assertThat(shallowClass)
.hasFieldOrPropertyWithValue("fullyQualifiedName", typeFromParser.getFullyQualifiedName())
.hasFieldOrPropertyWithValue("owningClass", typeFromParser.getOwningClass());
}
))
);
}
from rewrite.
Related Issues (20)
- UpdateMavenWrapper inconsistent when the wrapper is in a nested directory HOT 10
- Trailing comma in an array end up in white-space HOT 2
- Declarative Preconditions - `or` association
- Declarative Preconditions - Control applicability to ScanningRecipes HOT 6
- Split method signature line into multiple lines based on the length HOT 1
- Add or merge content to yaml file HOT 7
- Create YAML File with remote content HOT 2
- Create a folder HOT 8
- [Windows build from source] Gradle JDK auto-download doesn't work as expected HOT 2
- Unirest 4.x HOT 1
- foo.properties is not print idempotent due to `key==value` HOT 1
- RemoveObjectsIsNull doesn't remove unnecessary parentheses, if it HOT 1
- `AddManagedDependency` should allow version placeholder properties HOT 7
- org.openrewrite.gradle.RemoveDependency does not remove dependency in subproject HOT 3
- Performance issue with classpath scanning HOT 2
- Openrewrite: apply recipe list step by step (to have a proper commit history) HOT 1
- `module-info.java` trips up the JavaParser and Gradle/Maven plugin HOT 35
- Problem with parsing groovy files HOT 1
- RenameVariable does not modify variables referenced through type casts HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rewrite.