Skip to content

Commit

Permalink
add kotlin parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kunli2 committed Oct 9, 2023
1 parent f41f599 commit 466755f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<!-- Pinned versions, as RELEASE would make it into the published pom.xml -->
<rewrite.version>8.8.0-SNAPSHOT</rewrite.version>
<rewrite.python.version>1.2.0-SNAPSHOT</rewrite.python.version>
<rewrite.kotlin.version>1.5.0-SNAPSHOT</rewrite.kotlin.version>

<!-- using 'ssh' url scheme by default, which assumes a human is performing git operations leveraging an ssh key -->
<developerConnectionUrl>scm:git:ssh://[email protected]/openrewrite/rewrite-maven-plugin.git
Expand Down Expand Up @@ -208,7 +209,11 @@
<artifactId>rewrite-python</artifactId>
<version>${rewrite.python.version}</version>
</dependency>

<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-kotlin</artifactId>
<version>${rewrite.kotlin.version}</version>
</dependency>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/openrewrite/maven/ResourceParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.openrewrite.hcl.HclParser;
import org.openrewrite.java.JavaParser;
import org.openrewrite.json.JsonParser;
import org.openrewrite.kotlin.KotlinParser;
import org.openrewrite.properties.PropertiesParser;
import org.openrewrite.protobuf.ProtoParser;
import org.openrewrite.python.PythonParser;
Expand Down Expand Up @@ -148,6 +149,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
PythonParser pythonParser = PythonParser.builder().build();
List<Path> pythonPaths = new ArrayList<>();

KotlinParser kotlinParser = KotlinParser.builder().build();
List<Path> kotlinPaths = new ArrayList<>();

HclParser hclParser = HclParser.builder().build();
List<Path> hclPaths = new ArrayList<>();

Expand All @@ -172,6 +176,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
protoPaths.add(path);
} else if (pythonParser.accept(path)) {
pythonPaths.add(path);
} else if (kotlinParser.accept(path)) {
kotlinPaths.add(path);
} else if (hclParser.accept(path)) {
hclPaths.add(path);
} else if (quarkParser.accept(path)) {
Expand Down Expand Up @@ -214,6 +220,11 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
alreadyParsed.addAll(pythonPaths);
}

if (!kotlinPaths.isEmpty()) {
sourceFiles = Stream.concat(sourceFiles, (Stream<S>) kotlinParser.parse(kotlinPaths, baseDir, ctx));
alreadyParsed.addAll(kotlinPaths);
}

if (!hclPaths.isEmpty()) {
sourceFiles = Stream.concat(sourceFiles, (Stream<S>) hclParser.parse(hclPaths, baseDir, ctx));
alreadyParsed.addAll(hclPaths);
Expand Down

0 comments on commit 466755f

Please sign in to comment.