Skip to content

Commit

Permalink
Escape package pattern with dots
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Jun 15, 2020
1 parent c508353 commit 9dfc098
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ commands:
- save_cache:
key: gradle-dependencies-{{ checksum "build.gradle.kts" }}
paths:
- ~/rewrite/rewrite-java-8/.tools/
- ~/.gradle
- run:
name: run gradle command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public ImportPackage(boolean statik, String packageWildcard, boolean withSubpack
this.classCountToUseStarImport = classCountToUseStarImport;
this.nameCountToUseStarImport = nameCountToUseStarImport;
this.packageWildcard = Pattern.compile(packageWildcard
.replace(".", "\\.")
.replace("*", withSubpackages ? ".+" : "[^.]+"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,23 @@ interface OrderImportTest {
}
""".trimIndent())
}

@Test
fun packagePatternEscapesDots(jp: JavaParser) {
val a = jp.parse("""
import javax.annotation.Nonnull;
public class A {}
""".trimIndent())

val fixed = a.refactor().visit(OrderImports.intellij().apply {
setRemoveUnused(false)
}).fix().fixed

assertRefactored(fixed, """
import javax.annotation.Nonnull;
public class A {}
""".trimIndent())
}
}

0 comments on commit 9dfc098

Please sign in to comment.