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)
- ShortenFullyQualifiedNames don't shorten FQN Annotations HOT 6
- java file "is not print idempotent" - case vs defaultcase HOT 1
- Merge Yaml to a specific File HOT 1
- UpgradeDependencyVersion creates constraints inside constraint block
- TabsAndIndents: continuationIndentSize fails by `!DOCTYPE` HOT 2
- `CatchClauseOnlyRethrows` should not remove empty catch if the exception then gets caught by another catch block
- The InMemoryDiffEntry defaults diffs with UTF-8 encoding when a file could be in another encoding e.g. ISO-8859
- LST SourceFile for file encoded as ISO-8859 produced with encoding set to UTF-8
- "Add Maven Parent" recipe HOT 3
- JSP parse errors logged to console during `mod build`
- No newline in import statements added by maybeAddImport / AddImportVisitor HOT 3
- org.openrewrite.java.RemoveObjectsIsNull fails on negated expressions HOT 4
- Json formatting/style doesn't seem to be respected when adding values/members
- Add option to skip parsing Javadoc HOT 3
- add clang-format style HOT 1
- Groovy Enum is throwing "Failed to parse" "UnsupportedOperationException: enum fields are not implemented." HOT 2
- Getting StringIndexOutOfBoundsException with Groovy class that has groovy transform. HOT 2
- java/ChangePackage does not update JPMS module-info.java HOT 2
- `maybeAddImport` adds import although all references are fully qualified HOT 1
- Maven profiles, active profiles, and activeByDefault
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.