generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic parse for multiple codeblocks
- Loading branch information
Showing
2 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cc.unitmesh.devti.flow | ||
|
||
object JavaParseUtil { | ||
// split it to 3 parts: | ||
fun splitClass(code: String): List<String> { | ||
val classPattern = Regex("(public\\s+class|public\\s+interface).*?\\{.*?}", RegexOption.DOT_MATCHES_ALL) | ||
val matches = classPattern.findAll(code) | ||
return matches.map { it.value }.toList() | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
src/test/kotlin/cc/unitmesh/devti/flow/JavaParseUtilTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package cc.unitmesh.devti.flow | ||
|
||
import org.junit.Test | ||
|
||
class JavaParseUtilTest { | ||
val demoCode = """ | ||
// Request DTO | ||
public class CreateBlogRequest { | ||
private String title; | ||
private String content; | ||
public String getTitle() { | ||
return title; | ||
} | ||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
public String getContent() { | ||
return content; | ||
} | ||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
} | ||
// Response DTO | ||
public class CreateBlogResponse { | ||
private long id; | ||
private String title; | ||
private String content; | ||
public long getId() { | ||
return id; | ||
} | ||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
public String getTitle() { | ||
return title; | ||
} | ||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
public String getContent() { | ||
return content; | ||
} | ||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
} | ||
// Entity | ||
public class BlogPost { | ||
private long id; | ||
private String title; | ||
private String content; | ||
public long getId() { | ||
return id; | ||
} | ||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
public String getTitle() { | ||
return title; | ||
} | ||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
public String getContent() { | ||
return content; | ||
} | ||
public void setContent(String content) { | ||
this.content = content; | ||
} | ||
} | ||
""".trimIndent() | ||
|
||
@Test | ||
fun splitClass() { | ||
val classes = JavaParseUtil.splitClass(demoCode) | ||
assert(classes.size == 3) | ||
assert(classes[0].contains("CreateBlogRequest")) | ||
assert(classes[1].contains("CreateBlogResponse")) | ||
assert(classes[2].contains("BlogPost")) | ||
} | ||
} |