├── plantuml-parser-plugin ├── gradle.properties ├── src │ └── main │ │ ├── resources │ │ ├── META-INF │ │ │ ├── plantuml-parser-withKotlin.xml │ │ │ └── plugin.xml │ │ └── i18n │ │ │ ├── info.properties │ │ │ └── info_zh.properties │ │ └── java │ │ └── com │ │ └── shuzijun │ │ └── plantumlparser │ │ └── plugin │ │ ├── utils │ │ ├── PropertiesUtils.java │ │ └── MTAUtils.java │ │ ├── window │ │ ├── ParserConfigPanel.java │ │ └── ParserConfigPanel.form │ │ └── action │ │ └── ParserProgramAction.java └── build.gradle ├── doc └── demo.gif ├── plantuml-parser-core ├── src │ ├── test │ │ ├── resources │ │ │ ├── ClassWOConstructor.java │ │ │ ├── Record1.java │ │ │ ├── Record2.java │ │ │ ├── Record3.java │ │ │ ├── Record6.java │ │ │ ├── ClassWOConstructorNoConstructorOutput.txt │ │ │ ├── ClassWithConstructor.java │ │ │ ├── ClassWOConstructorOutput.txt │ │ │ ├── Record5.java │ │ │ ├── ClassWithConstructorOutput.txt │ │ │ ├── Record4.java │ │ │ ├── kt │ │ │ │ ├── KtExtend2.kt │ │ │ │ ├── KtObject.kt │ │ │ │ ├── Generics.kt │ │ │ │ ├── CompanionObject.kt │ │ │ │ ├── KtClass.kt │ │ │ │ ├── Enum.kt │ │ │ │ ├── KtExtend3.kt │ │ │ │ ├── KtExtend.kt │ │ │ │ ├── InnerClass.kt │ │ │ │ ├── Factory.kt │ │ │ │ └── Observer.kt │ │ │ ├── Record1Desugared.java │ │ │ ├── Record2Desugared.java │ │ │ ├── Record3Desugared.java │ │ │ ├── Record4Desugared.java │ │ │ ├── Record6Desugared.java │ │ │ └── Record5Desugared.java │ │ └── java │ │ │ └── com │ │ │ └── shuzijun │ │ │ └── plantumlparser │ │ │ └── core │ │ │ ├── Test.java │ │ │ ├── KtTester.java │ │ │ └── UmlGenerationTester.java │ └── main │ │ └── java │ │ └── com │ │ └── shuzijun │ │ └── plantumlparser │ │ └── core │ │ ├── PUml.java │ │ ├── Constant.java │ │ ├── PUmlRelation.java │ │ ├── MyVisitor.java │ │ ├── PUmlView.java │ │ ├── PUmlField.java │ │ ├── VisibilityUtils.java │ │ ├── KtParserProgram.java │ │ ├── PUmlMethod.java │ │ ├── ParserProgram.java │ │ ├── PUmlClass.java │ │ ├── ParserConfig.java │ │ ├── KtClassVOidVisitor.java │ │ └── ClassVoidVisitor.java └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── plantuml-parser-cli ├── src │ └── main │ │ └── java │ │ └── com │ │ └── shuzijun │ │ └── plantumlparser │ │ └── cli │ │ ├── options │ │ ├── CliOption.java │ │ ├── OptionProvider.java │ │ ├── ParserConfigUpdater.java │ │ ├── fieldmodifier │ │ │ ├── FieldPublicModifier.java │ │ │ ├── FieldDefaultModifier.java │ │ │ ├── FieldPrivateModifier.java │ │ │ ├── FieldProtectedModifier.java │ │ │ └── FieldModifierWrapper.java │ │ ├── methodmodifier │ │ │ ├── MethodPublicModifier.java │ │ │ ├── MethodDefaultModifier.java │ │ │ ├── MethodPrivateModifier.java │ │ │ ├── MethodProtectedModifier.java │ │ │ └── MethodModifierWrapper.java │ │ ├── filepath │ │ │ └── FilePathOption.java │ │ ├── showcomment │ │ │ └── ShowCommentOption.java │ │ ├── showconstructors │ │ │ └── ShowConstructorsOption.java │ │ ├── showdefaultconstructors │ │ │ └── ShowDefaultConstructorsOption.java │ │ ├── outfilepath │ │ │ └── OutfilePathOption.java │ │ ├── showpackage │ │ │ └── ShowPackageOption.java │ │ ├── languagelevel │ │ │ └── LanguageLevelOption.java │ │ ├── help │ │ │ └── HelpOption.java │ │ └── CliOptionsHolder.java │ │ ├── ParserModifiers.java │ │ └── CliRunner.java ├── build.gradle ├── README.md └── LICENSE ├── .gitignore ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ ├── discuss.md │ └── bug_report.md ├── no-response.yml └── workflows │ ├── gradle-publish.yml │ └── plugin.yml ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /plantuml-parser-plugin/gradle.properties: -------------------------------------------------------------------------------- 1 | idea_local_path = -------------------------------------------------------------------------------- /doc/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzijun/plantuml-parser/HEAD/doc/demo.gif -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/ClassWOConstructor.java: -------------------------------------------------------------------------------- 1 | class NoConstructor { 2 | 3 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record1.java: -------------------------------------------------------------------------------- 1 | record Person(String name, int age) { 2 | } 3 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record2.java: -------------------------------------------------------------------------------- 1 | public record Person2(String name, int age) { 2 | } 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuzijun/plantuml-parser/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record3.java: -------------------------------------------------------------------------------- 1 | public record Person3(String name, int age) { 2 | public String name(); 3 | } 4 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record6.java: -------------------------------------------------------------------------------- 1 | public record Person6(Name name, int age) { 2 | public class Name {} 3 | } 4 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/ClassWOConstructorNoConstructorOutput.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | class NoConstructor { 3 | } 4 | @enduml 5 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/ClassWithConstructor.java: -------------------------------------------------------------------------------- 1 | class WithConstructor { 2 | public WithConstructor() { 3 | 4 | } 5 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/ClassWOConstructorOutput.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | class NoConstructor { 3 | + <> NoConstructor() 4 | } 5 | @enduml -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record5.java: -------------------------------------------------------------------------------- 1 | record Person5(Name name, int age) { 2 | record Name(String personalName, String familyName) {} 3 | } 4 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/ClassWithConstructorOutput.txt: -------------------------------------------------------------------------------- 1 | @startuml 2 | class WithConstructor { 3 | + <> WithConstructor() 4 | } 5 | @enduml 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'plantuml-parser' 2 | include 'plantuml-parser-core' 3 | include 'plantuml-parser-plugin' 4 | include 'plantuml-parser-cli' 5 | 6 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record4.java: -------------------------------------------------------------------------------- 1 | public record Person4(String name, int age) { 2 | public Person4(String name,int age){} 3 | public String name(); 4 | } 5 | -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/resources/META-INF/plantuml-parser-withKotlin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/KtExtend2.kt: -------------------------------------------------------------------------------- 1 | package kt2 2 | 3 | open class Animal(val name: String) { 4 | open fun makeSound() { 5 | println("$name makes a sound") 6 | } 7 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/PUml.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | /** 4 | * 5 | * 6 | * @author shuzijun 7 | */ 8 | public interface PUml { 9 | } 10 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/CliOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options; 2 | 3 | public interface CliOption extends OptionProvider, ParserConfigUpdater { 4 | } 5 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/KtObject.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | object KtObject { 3 | val field1 = "Value 1" 4 | val field2 = "Value 2" 5 | 6 | fun createProduct(type: String): String { 7 | return "" 8 | } 9 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/resources/i18n/info.properties: -------------------------------------------------------------------------------- 1 | test=hello 2 | success=Parse successful, file address:{0} 3 | select.empty=Files containing Java types are not selected 4 | fileName.empty=File Name Can't be empty 5 | io.exception=Read file exception,{0} -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/OptionProvider.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options; 2 | 3 | import org.apache.commons.cli.Option; 4 | 5 | public interface OptionProvider { 6 | 7 | Option getOption(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/resources/i18n/info_zh.properties: -------------------------------------------------------------------------------- 1 | test=\u4F60\u597D 2 | success=\u89E3\u6790\u6210\u529F,\u6587\u4EF6\u5730\u5740:{0} 3 | select.empty=\u672A\u9009\u4E2D\u5305\u542Bjava\u7C7B\u578B\u7684\u6587\u4EF6 4 | fileName.empty=File Name \u4E0D\u80FD\u4E3A\u7A7A 5 | io.exception=\u8BFB\u53D6\u6587\u4EF6\u5F02\u5E38,{0} -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record1Desugared.java: -------------------------------------------------------------------------------- 1 | class Person { 2 | private String name; 3 | private int age; 4 | 5 | Person(String name, int age) { 6 | this.name = name; 7 | this.age = age; 8 | } 9 | 10 | public String name() { 11 | return this.name; 12 | } 13 | 14 | public int age() { 15 | return this.age; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/ParserConfigUpdater.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options; 2 | 3 | import com.shuzijun.plantumlparser.core.ParserConfig; 4 | import org.apache.commons.cli.CommandLine; 5 | 6 | public interface ParserConfigUpdater { 7 | 8 | ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/Generics.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | 3 | interface Repository { 4 | fun findAll(): Array 5 | } 6 | 7 | class CustomRepo: Repository { 8 | override fun findAll(): Array { 9 | return arrayOf("Sorted1, Sorted2") 10 | } 11 | } 12 | fun main() { 13 | val customRepo = CustomRepo() 14 | println(customRepo.findAll().joinToString()) 15 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record2Desugared.java: -------------------------------------------------------------------------------- 1 | public class Person2 { 2 | private String name; 3 | private int age; 4 | 5 | public Person2(String name, int age) { 6 | this.name = name; 7 | this.age = age; 8 | } 9 | 10 | public String name() { 11 | return this.name; 12 | } 13 | 14 | public int age() { 15 | return this.age; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record3Desugared.java: -------------------------------------------------------------------------------- 1 | public class Person3 { 2 | private String name; 3 | private int age; 4 | 5 | public Person3(String name, int age) { 6 | this.name = name; 7 | this.age = age; 8 | } 9 | 10 | public String name() { 11 | return this.name; 12 | } 13 | 14 | public int age() { 15 | return this.age; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record4Desugared.java: -------------------------------------------------------------------------------- 1 | public class Person4 { 2 | private String name; 3 | private int age; 4 | 5 | public Person4(String name, int age) { 6 | this.name = name; 7 | this.age = age; 8 | } 9 | 10 | public String name() { 11 | return this.name; 12 | } 13 | 14 | public int age() { 15 | return this.age; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/CompanionObject.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | 3 | class MyClass { 4 | companion object { 5 | const val staticField = "This is a static field" 6 | 7 | fun staticFunction() { 8 | println("This is a static function") 9 | } 10 | } 11 | } 12 | 13 | fun main() { 14 | println(MyClass.staticField) // 访问静态字段 15 | MyClass.staticFunction() // 调用静态函数 16 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/KtClass.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | 3 | /** 4 | * This is a documentation comment for MyClass. 5 | */ 6 | class KtClass { 7 | val myVal: Int = 42 8 | var myVar: String = "Hello" 9 | lateinit var myLateInitVar: String 10 | 11 | /** 12 | * This is a documentation comment for myFunction. 13 | */ 14 | fun myFunction(): String? { 15 | return null 16 | } 17 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record6Desugared.java: -------------------------------------------------------------------------------- 1 | public class Person6 { 2 | private Name name; 3 | private int age; 4 | 5 | public Person6(Name name, int age) { 6 | this.name = name; 7 | this.age = age; 8 | } 9 | 10 | public Name name() { 11 | return this.name; 12 | } 13 | 14 | public int age() { 15 | return this.age; 16 | } 17 | 18 | public class Name { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | .idea 4 | .gradle 5 | /build/ 6 | 7 | plantuml-parser-core/build 8 | plantuml-parser-plugin/build 9 | 10 | # Ignore Gradle GUI config 11 | gradle-app.setting 12 | 13 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 14 | !gradle-wrapper.jar 15 | 16 | # Cache of project 17 | .gradletasknamecache 18 | 19 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 20 | # gradle/wrapper/gradle-wrapper.properties 21 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/Constant.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | public class Constant { 4 | 5 | public static String VisibilityAll = "*"; 6 | public static String VisibilityPrivate = "private"; 7 | public static String VisibilityDefault = "default"; 8 | public static String VisibilityProtected = "protected"; 9 | public static String VisibilityPublic = "public"; 10 | 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/ParserModifiers.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli; 2 | 3 | public final class ParserModifiers { 4 | 5 | private ParserModifiers() { 6 | throw new UnsupportedOperationException(); 7 | } 8 | 9 | public static final String PUBLIC = "public"; 10 | public static final String PROTECTED = "protected"; 11 | public static final String DEFAULT = "default"; 12 | public static final String PRIVATE = "private"; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/Enum.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | enum class DayOfWeek { 3 | MONDAY, 4 | TUESDAY, 5 | WEDNESDAY, 6 | THURSDAY, 7 | FRIDAY, 8 | SATURDAY, 9 | SUNDAY 10 | } 11 | 12 | fun main() { 13 | val today = DayOfWeek.WEDNESDAY 14 | 15 | // 使用 when 表达式匹配枚举值 16 | val message = when (today) { 17 | DayOfWeek.MONDAY -> "It's Monday!" 18 | DayOfWeek.WEDNESDAY -> "It's Wednesday!" 19 | else -> "It's not Monday or Wednesday." 20 | } 21 | 22 | println(message) // 输出: It's Wednesday! 23 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/discuss.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Discuss 3 | about: Start a discussion or ask for help 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Desc** 11 | Start a discussion or ask for help 12 | 13 | **Software versions(*Help* -> *About*)(Optional)** 14 | - Product: [e.g IDEA 2020.2] 15 | - Runtime version:[e.g 11.0.7+10-b944.20 amd64] 16 | - VM:[e.g OpenJDK 64-Bit Server VM by JetBrains s.r.o.] 17 | - OS:[e.g Windows 10] 18 | 19 | **Question(Optional)** 20 | - URL:[e.g leetcode.com] 21 | - Code Type:[e.g JAVA] 22 | - code: 23 | ``` 24 | 25 | ``` 26 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/java/com/shuzijun/plantumlparser/core/Test.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import java.io.IOException; 4 | 5 | public class Test { 6 | public static void main(String[]args)throws IOException { 7 | ParserConfig parserConfig=new ParserConfig(); 8 | parserConfig.addFilePath("/Users/shuzijun/plantuml-parser/plantuml-parser-core/src"); 9 | parserConfig.addExcludeClassRegex("Test"); 10 | 11 | ParserProgram parserProgram=new ParserProgram(parserConfig); 12 | parserProgram.execute(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/KtExtend3.kt: -------------------------------------------------------------------------------- 1 | package kt3 2 | import kt2.Animal as Animal2 3 | class Dog(name: String) : Animal2(name) { 4 | override fun makeSound() { 5 | println("$name barks") 6 | } 7 | 8 | fun fetch() { 9 | println("$name is fetching a ball") 10 | } 11 | } 12 | 13 | fun main() { 14 | val animal = Animal2("Generic Animal") 15 | val dog = Dog("Buddy") 16 | 17 | animal.makeSound() // 输出: Generic Animal makes a sound 18 | dog.makeSound() // 输出: Buddy barks 19 | dog.fetch() // 输出: Buddy is fetching a ball 20 | } -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/java/com/shuzijun/plantumlparser/plugin/utils/PropertiesUtils.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.plugin.utils; 2 | 3 | import java.text.MessageFormat; 4 | import java.util.ResourceBundle; 5 | 6 | /** 7 | * @author shuzijun 8 | */ 9 | public class PropertiesUtils { 10 | 11 | private final static String baseName = "i18n/info"; 12 | private final static ResourceBundle rb1 = ResourceBundle.getBundle(baseName); 13 | 14 | public static String getInfo(String key, String... params) { 15 | return new MessageFormat(rb1.getString(key)).format(params); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Software versions(*Help* -> *About*)** 21 | - Product: [e.g IDEA 2020.2] 22 | - Runtime version:[e.g 11.0.7+10-b944.20 amd64] 23 | - VM:[e.g OpenJDK 64-Bit Server VM by JetBrains s.r.o.] 24 | - OS:[e.g Windows 10] 25 | 26 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/fieldmodifier/FieldPublicModifier.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.fieldmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.ParserModifiers; 4 | 5 | public class FieldPublicModifier extends FieldModifierWrapper { 6 | 7 | @Override 8 | protected String getOptName() { 9 | return "fpub"; 10 | } 11 | 12 | @Override 13 | protected String getLongOptName() { 14 | return "field_public"; 15 | } 16 | 17 | @Override 18 | protected String getModifier() { 19 | return ParserModifiers.PUBLIC; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/fieldmodifier/FieldDefaultModifier.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.fieldmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.ParserModifiers; 4 | 5 | public class FieldDefaultModifier extends FieldModifierWrapper { 6 | 7 | @Override 8 | protected String getOptName() { 9 | return "fdef"; 10 | } 11 | 12 | @Override 13 | protected String getLongOptName() { 14 | return "field_default"; 15 | } 16 | 17 | @Override 18 | protected String getModifier() { 19 | return ParserModifiers.DEFAULT; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/fieldmodifier/FieldPrivateModifier.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.fieldmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.ParserModifiers; 4 | 5 | public class FieldPrivateModifier extends FieldModifierWrapper { 6 | 7 | @Override 8 | protected String getOptName() { 9 | return "fpri"; 10 | } 11 | 12 | @Override 13 | protected String getLongOptName() { 14 | return "field_private"; 15 | } 16 | 17 | @Override 18 | protected String getModifier() { 19 | return ParserModifiers.PRIVATE; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/methodmodifier/MethodPublicModifier.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.methodmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.ParserModifiers; 4 | 5 | public class MethodPublicModifier extends MethodModifierWrapper { 6 | 7 | @Override 8 | protected String getOptName() { 9 | return "mpub"; 10 | } 11 | 12 | @Override 13 | protected String getLongOptName() { 14 | return "method_public"; 15 | } 16 | 17 | @Override 18 | protected String getModifier() { 19 | return ParserModifiers.PUBLIC; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/fieldmodifier/FieldProtectedModifier.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.fieldmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.ParserModifiers; 4 | 5 | public class FieldProtectedModifier extends FieldModifierWrapper { 6 | 7 | @Override 8 | protected String getOptName() { 9 | return "fpro"; 10 | } 11 | 12 | @Override 13 | protected String getLongOptName() { 14 | return "field_protected"; 15 | } 16 | 17 | @Override 18 | protected String getModifier() { 19 | return ParserModifiers.PROTECTED; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/methodmodifier/MethodDefaultModifier.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.methodmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.ParserModifiers; 4 | 5 | public class MethodDefaultModifier extends MethodModifierWrapper { 6 | 7 | @Override 8 | protected String getOptName() { 9 | return "mdef"; 10 | } 11 | 12 | @Override 13 | protected String getLongOptName() { 14 | return "method_default"; 15 | } 16 | 17 | @Override 18 | protected String getModifier() { 19 | return ParserModifiers.DEFAULT; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/methodmodifier/MethodPrivateModifier.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.methodmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.ParserModifiers; 4 | 5 | public class MethodPrivateModifier extends MethodModifierWrapper { 6 | 7 | @Override 8 | protected String getOptName() { 9 | return "mpri"; 10 | } 11 | 12 | @Override 13 | protected String getLongOptName() { 14 | return "method_private"; 15 | } 16 | 17 | @Override 18 | protected String getModifier() { 19 | return ParserModifiers.PRIVATE; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/methodmodifier/MethodProtectedModifier.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.methodmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.ParserModifiers; 4 | 5 | public class MethodProtectedModifier extends MethodModifierWrapper { 6 | 7 | @Override 8 | protected String getOptName() { 9 | return "mpro"; 10 | } 11 | 12 | @Override 13 | protected String getLongOptName() { 14 | return "method_protected"; 15 | } 16 | 17 | @Override 18 | protected String getModifier() { 19 | return ParserModifiers.PROTECTED; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/KtExtend.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | 3 | open class Animal(val name: String) { 4 | open fun makeSound() { 5 | println("$name makes a sound") 6 | } 7 | } 8 | 9 | class Dog(name: String) : Animal(name) { 10 | override fun makeSound() { 11 | println("$name barks") 12 | } 13 | 14 | fun fetch() { 15 | println("$name is fetching a ball") 16 | } 17 | } 18 | 19 | fun main() { 20 | val animal = Animal("Generic Animal") 21 | val dog = Dog("Buddy") 22 | 23 | animal.makeSound() // 输出: Generic Animal makes a sound 24 | dog.makeSound() // 输出: Buddy barks 25 | dog.fetch() // 输出: Buddy is fetching a ball 26 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/InnerClass.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | 3 | class OuterClass { 4 | private val outerProperty = "Outer Property" 5 | 6 | class NestedClass { 7 | fun accessOuterProperty() { 8 | // 无法访问外部类的属性 9 | // println(outerProperty) // 错误:无法访问外部类的属性 10 | } 11 | } 12 | 13 | inner class InnerClass { 14 | fun accessOuterProperty() { 15 | // 可以访问外部类的属性 16 | println(outerProperty) // 可以访问外部类的属性 17 | } 18 | } 19 | } 20 | 21 | fun main() { 22 | val nested = OuterClass.NestedClass() 23 | val inner = OuterClass().InnerClass() 24 | 25 | nested.accessOuterProperty() // 无法访问外部类的属性 26 | inner.accessOuterProperty() // 可以访问外部类的属性 27 | } -------------------------------------------------------------------------------- /.github/no-response.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-no-response - https://github.com/probot/no-response 2 | 3 | # Number of days of inactivity before an Issue is closed for lack of response 4 | daysUntilClose: 14 5 | # Label requiring a response 6 | responseRequiredLabel: more-information-needed 7 | # Comment to post when closing an Issue for lack of response. Set to `false` to disable 8 | closeComment: > 9 | This issue has been automatically closed because there has been no response 10 | to our request for more information from the original author. With only the 11 | information that is currently in the issue, we don't have enough information 12 | to take action. Please reach out if you have or find the answers we need so 13 | that we can investigate further. 14 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/PUmlRelation.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | /** 4 | * class之间的关系 5 | * 6 | * @author 关系 7 | */ 8 | public class PUmlRelation { 9 | 10 | private String source; 11 | 12 | private String target; 13 | 14 | private String relation; 15 | 16 | public void setSource(String source) { 17 | this.source = source; 18 | } 19 | 20 | public void setTarget(String target) { 21 | this.target = target; 22 | } 23 | 24 | public void setRelation(String relation) { 25 | this.relation = relation; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return source + " " + relation + " " + target; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /plantuml-parser-cli/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | group 'com.shuzijun' 6 | archivesBaseName = 'plantuml-parser-cli' 7 | version '0.0.1' 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | implementation 'commons-cli:commons-cli:1.5.0' 15 | implementation project(":plantuml-parser-core") 16 | } 17 | 18 | tasks.withType(JavaCompile) { 19 | options.encoding = "UTF-8" 20 | } 21 | 22 | tasks.withType(Jar) { 23 | manifest { 24 | attributes["Main-Class"] = "com.shuzijun.plantumlparser.cli.CliRunner" 25 | } 26 | } 27 | 28 | task fatJar(type: Jar) { 29 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 30 | with jar 31 | } 32 | 33 | test { 34 | useJUnitPlatform() 35 | } -------------------------------------------------------------------------------- /plantuml-parser-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'org.jetbrains.intellij' version '0.6.5' 4 | } 5 | 6 | group 'com.shuzijun' 7 | version '0.0.9' 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | implementation (project(path: ":plantuml-parser-core")) { 15 | exclude (group: 'org.jetbrains.kotlin', module: 'kotlin-compiler') 16 | } 17 | } 18 | 19 | intellij { 20 | pluginName 'plantuml-parser' 21 | version '2020.1' 22 | type 'IU' 23 | downloadSources false 24 | updateSinceUntilBuild false 25 | buildSearchableOptions.enabled(false) 26 | plugins ['org.jetbrains.kotlin'] 27 | } 28 | 29 | tasks.withType(JavaCompile) { 30 | options.encoding = "UTF-8" 31 | } 32 | test { 33 | useJUnitPlatform() 34 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/MyVisitor.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | public interface MyVisitor { 4 | 5 | default PUmlClass createUmlClass() { 6 | PUmlClass pUmlClass = new PUmlClass(); 7 | if (getParserConfig().isShowPackage()) { 8 | pUmlClass.setPackageName(getPackageName()); 9 | } else { 10 | pUmlClass.setPackageName(""); 11 | } 12 | return pUmlClass; 13 | } 14 | default String getPackageNamePrefix(String packageName) { 15 | if (packageName == null || packageName.trim().equals("")) { 16 | return ""; 17 | } else { 18 | return packageName + "."; 19 | } 20 | } 21 | 22 | String getPackageName(); 23 | ParserConfig getParserConfig(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/Factory.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | 3 | interface Product { 4 | fun create() 5 | } 6 | 7 | class ConcreteProductA : Product { 8 | override fun create() { 9 | println("Product A is created") 10 | } 11 | } 12 | 13 | class ConcreteProductB : Product { 14 | override fun create() { 15 | println("Product B is created") 16 | } 17 | } 18 | 19 | object Factory { 20 | fun createProduct(type: String): Product { 21 | return when (type) { 22 | "A" -> ConcreteProductA() 23 | "B" -> ConcreteProductB() 24 | else -> throw IllegalArgumentException("Invalid product type") 25 | } 26 | } 27 | } 28 | 29 | fun main() { 30 | val productA = Factory.createProduct("A") 31 | val productB = Factory.createProduct("B") 32 | 33 | productA.create() 34 | productB.create() 35 | } -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/Record5Desugared.java: -------------------------------------------------------------------------------- 1 | class Person5 { 2 | private Name name; 3 | private int age; 4 | 5 | Person5(Name name, int age) { 6 | this.name = name; 7 | this.age = age; 8 | } 9 | 10 | public Name name() { 11 | return this.name; 12 | } 13 | 14 | public int age() { 15 | return this.age; 16 | } 17 | 18 | static class Name { 19 | private String personalName; 20 | private String familyName; 21 | 22 | Name(String personalName, String familyName) { 23 | this.personalName = personalName; 24 | this.familyName = familyName; 25 | } 26 | 27 | public String personalName() { 28 | return this.personalName; 29 | } 30 | 31 | public String familyName() { 32 | return this.familyName; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/resources/kt/Observer.kt: -------------------------------------------------------------------------------- 1 | package kt 2 | interface Observer { 3 | fun update(message: String) 4 | } 5 | 6 | class ConcreteObserver(private val name: String) : Observer { 7 | override fun update(message: String) { 8 | println("$name received message: $message") 9 | } 10 | } 11 | 12 | class Subject { 13 | private val observers = mutableListOf() 14 | 15 | fun addObserver(observer: Observer) { 16 | observers.add(observer) 17 | } 18 | 19 | fun removeObserver(observer: Observer) { 20 | observers.remove(observer) 21 | } 22 | 23 | fun notifyObservers(message: String) { 24 | observers.forEach { it.update(message) } 25 | } 26 | } 27 | 28 | fun main() { 29 | val subject = Subject() 30 | val observer1 = ConcreteObserver("Observer 1") 31 | val observer2 = ConcreteObserver("Observer 2") 32 | 33 | subject.addObserver(observer1) 34 | subject.addObserver(observer2) 35 | 36 | subject.notifyObservers("Hello, observers!") 37 | } -------------------------------------------------------------------------------- /.github/workflows/gradle-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created 2 | # For more information see: https://github.com/actions/setup-java#publishing-using-gradle 3 | 4 | name: Gradle Package 5 | 6 | on: workflow_dispatch 7 | 8 | jobs: 9 | 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up JDK 1.8 17 | uses: actions/setup-java@v1 18 | with: 19 | java-version: '8' # The JDK version to make available on the path. 20 | java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk 21 | architecture: x64 # (x64 or x86) - defaults to x64 22 | 23 | - name: Grant execute permission for gradlew 24 | run: chmod +x gradlew 25 | 26 | - name: Build with Gradle 27 | run: ./gradlew plantuml-parser-core:build 28 | 29 | - name: Publish to GitHub Packages 30 | run: gradle plantuml-parser-core:publish 31 | env: 32 | USERNAME: ${{ github.actor }} 33 | TOKEN: ${{ secrets.GITHUB_TOKEN }} 34 | -------------------------------------------------------------------------------- /plantuml-parser-core/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'maven-publish' 4 | id 'org.jetbrains.kotlin.jvm' version '1.9.10' 5 | } 6 | 7 | group 'com.shuzijun' 8 | archivesBaseName = 'plantuml-parser-core' 9 | version '0.0.10' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | api "com.github.javaparser:javaparser-core:3.25.3" 17 | 18 | api "commons-io:commons-io:2.8.0" 19 | api "org.jetbrains.kotlin:kotlin-compiler" 20 | } 21 | 22 | tasks.withType(JavaCompile) { 23 | options.encoding = "UTF-8" 24 | } 25 | 26 | publishing { 27 | repositories { 28 | maven { 29 | name = "GitHubPackages" 30 | url = uri("https://maven.pkg.github.com/shuzijun/plantuml-parser") 31 | credentials { 32 | username = project.findProperty("gpr.user") ?: System.getenv("USERNAME") 33 | password = project.findProperty("gpr.key") ?: System.getenv("TOKEN") 34 | } 35 | } 36 | } 37 | publications { 38 | gpr(MavenPublication) { 39 | from(components.java) 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /.github/workflows/plugin.yml: -------------------------------------------------------------------------------- 1 | name: plugin 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | 9 | jobs: 10 | greet: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v2 16 | 17 | - name: Set up JDK 1.8 18 | uses: actions/setup-java@v1 19 | with: 20 | java-version: 1.8 21 | 22 | - name: Grant execute permission for gradlew 23 | run: chmod +x gradlew 24 | 25 | - name: Build the plugin 26 | run: ./gradlew plantuml-parser-plugin:buildPlugin 27 | 28 | - name: Print verify contents 29 | run: | 30 | echo "The log file path is: ${{steps.verify.outputs.verification-output-log-filename}}" ; 31 | cat ${{steps.verify.outputs.verification-output-log-filename}} 32 | 33 | - name: Upload Artifact 34 | uses: actions/upload-artifact@v2 35 | with: 36 | # TODO: This uploads a zip called `distributions`; see what we can do to just upload the produced plugin itself. 37 | name: plantuml-parser 38 | path: plantuml-parser-plugin/build/distributions/plantuml-parser-*.*.*.zip 39 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/PUmlView.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * PUml视图 9 | * 10 | * @author shuzijun 11 | */ 12 | public class PUmlView implements PUml { 13 | 14 | private List pUmlClassList = new ArrayList<>(); 15 | 16 | private List pUmlRelationList = new ArrayList<>(); 17 | 18 | public void addPUmlClass(PUmlClass pUmlClass) { 19 | pUmlClassList.add(pUmlClass); 20 | } 21 | 22 | public void addPUmlRelation(PUmlRelation pUmlRelation) { 23 | pUmlRelationList.add(pUmlRelation); 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "@startuml\n" + 29 | (pUmlClassList.isEmpty() ? "" : pUmlClassList.stream().map(pUmlClass -> pUmlClass.toString()).collect(Collectors.joining("\n")) + "\n") + 30 | (pUmlRelationList.isEmpty() ? "" : "\n\n" + pUmlRelationList.stream().map(pUmlRelation -> pUmlRelation.toString()).collect(Collectors.joining("\n")) + "\n") + 31 | "@enduml" 32 | ; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/java/com/shuzijun/plantumlparser/core/KtTester.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import com.intellij.openapi.Disposable; 4 | import com.intellij.openapi.util.Disposer; 5 | import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; 6 | import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; 7 | import org.jetbrains.kotlin.config.CompilerConfiguration; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.util.Objects; 12 | 13 | public class KtTester { 14 | 15 | public static void main(String[]args)throws IOException { 16 | String filePath = KtTester.class.getClassLoader().getResource("kt").getPath(); 17 | 18 | ParserConfig parserConfig=new ParserConfig(); 19 | parserConfig.addFilePath(filePath); 20 | parserConfig.setShowPackage(true); 21 | parserConfig.setShowComment(true); 22 | parserConfig.setShowConstructors(true); 23 | 24 | parserConfig.addFieldModifier(Constant.VisibilityAll); 25 | parserConfig.addMethodModifier(Constant.VisibilityAll); 26 | 27 | ParserProgram parserProgram=new ParserProgram(parserConfig); 28 | parserProgram.execute(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/CliRunner.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOptionsHolder; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import com.shuzijun.plantumlparser.core.ParserProgram; 6 | import org.apache.commons.cli.CommandLine; 7 | import org.apache.commons.cli.CommandLineParser; 8 | import org.apache.commons.cli.DefaultParser; 9 | import org.apache.commons.cli.Options; 10 | 11 | public class CliRunner { 12 | 13 | public static void main(String[] args) { 14 | 15 | try { 16 | final Options options = CliOptionsHolder.createOptions(); 17 | final CommandLineParser parser = new DefaultParser(); 18 | final CommandLine cmd = parser.parse(options, args); 19 | 20 | // Updated ParserConfig 21 | final ParserConfig config = new ParserConfig(); 22 | CliOptionsHolder.getParserConfigUpdater() 23 | .forEach(parserConfigUpdater -> parserConfigUpdater.updateConfig(config, cmd)); 24 | 25 | final ParserProgram program = new ParserProgram(config); 26 | program.execute(); 27 | } catch (final Exception ex) { 28 | ex.printStackTrace(); 29 | } 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/filepath/FilePathOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.filepath; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | 8 | import java.util.Arrays; 9 | 10 | public class FilePathOption implements CliOption { 11 | 12 | protected final String optName = "f"; 13 | protected final String longOptName = "filepath"; 14 | protected final Option option; 15 | 16 | public FilePathOption() { 17 | this.option = new Option(this.optName, this.longOptName, true, "Set the input file/directory"); 18 | } 19 | 20 | @Override 21 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 22 | Arrays.stream(cmd.getOptions()).map(Option::getOpt) 23 | .filter(option -> option.equalsIgnoreCase(this.optName)) 24 | .forEach(option -> { 25 | final String path = cmd.getOptionValue(option); 26 | parserConfig.addFilePath(path); 27 | }); 28 | return parserConfig; 29 | } 30 | 31 | @Override 32 | public Option getOption() { 33 | return this.option; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/showcomment/ShowCommentOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.showcomment; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | 8 | import java.util.Arrays; 9 | 10 | public class ShowCommentOption implements CliOption { 11 | 12 | protected final String optName = "scom"; 13 | protected final String longOptName = "show_comment"; 14 | protected final Option option; 15 | 16 | public ShowCommentOption() { 17 | this.option = new Option(this.optName, this.longOptName, false, "Show comment"); 18 | } 19 | 20 | @Override 21 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 22 | return Arrays.stream(cmd.getOptions()).map(Option::getOpt) 23 | .filter(option -> option.equalsIgnoreCase(this.optName)) 24 | .findAny() 25 | .map(option -> { 26 | parserConfig.setShowComment(true); 27 | return parserConfig; 28 | }) 29 | .orElse(parserConfig); 30 | } 31 | 32 | @Override 33 | public Option getOption() { 34 | return this.option; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/showconstructors/ShowConstructorsOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.showconstructors; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | 8 | import java.util.Arrays; 9 | 10 | public class ShowConstructorsOption implements CliOption { 11 | 12 | protected final String optName = "sctr"; 13 | protected final String longOptName = "show_constructors"; 14 | protected final Option option; 15 | 16 | public ShowConstructorsOption() { 17 | this.option = new Option(this.optName, this.longOptName, false, "Show constructors"); 18 | } 19 | 20 | @Override 21 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 22 | return Arrays.stream(cmd.getOptions()).map(Option::getOpt) 23 | .filter(option -> option.equalsIgnoreCase(this.optName)) 24 | .findAny() 25 | .map(option -> { 26 | parserConfig.setShowConstructors(true); 27 | return parserConfig; 28 | }) 29 | .orElse(parserConfig); 30 | } 31 | 32 | @Override 33 | public Option getOption() { 34 | return this.option; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/showdefaultconstructors/ShowDefaultConstructorsOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.showdefaultconstructors; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import java.util.Arrays; 6 | import org.apache.commons.cli.CommandLine; 7 | import org.apache.commons.cli.Option; 8 | 9 | public class ShowDefaultConstructorsOption implements CliOption { 10 | 11 | protected final String optName = "sdctr"; 12 | protected final String longOptName = "show_default_constructors"; 13 | protected final Option option; 14 | 15 | public ShowDefaultConstructorsOption() { 16 | this.option = new Option(this.optName, this.longOptName, false, "Show default constructors"); 17 | } 18 | 19 | @Override 20 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 21 | return Arrays.stream(cmd.getOptions()).map(Option::getOpt) 22 | .filter(option -> option.equalsIgnoreCase(this.optName)) 23 | .findAny() 24 | .map(option -> { 25 | parserConfig.setShowDefaultConstructors(true); 26 | return parserConfig; 27 | }) 28 | .orElse(parserConfig); 29 | } 30 | 31 | @Override 32 | public Option getOption() { 33 | return this.option; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/outfilepath/OutfilePathOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.outfilepath; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | 8 | import java.util.Arrays; 9 | 10 | public class OutfilePathOption implements CliOption { 11 | 12 | protected final String optName = "o"; 13 | protected final String longOptName = "outfile"; 14 | protected final Option option; 15 | 16 | public OutfilePathOption() { 17 | this.option = new Option(this.optName, this.longOptName, true, "Set the output file"); 18 | } 19 | 20 | @Override 21 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 22 | return Arrays.stream(cmd.getOptions()).map(Option::getOpt) 23 | .filter(option -> option.equalsIgnoreCase(this.optName)) 24 | .findAny() 25 | .map(option -> { 26 | final String path = cmd.getOptionValue(option); 27 | parserConfig.setOutFilePath(path); 28 | return parserConfig; 29 | }) 30 | .orElse(parserConfig); 31 | } 32 | 33 | @Override 34 | public Option getOption() { 35 | return this.option; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/showpackage/ShowPackageOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.showpackage; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | 8 | import java.util.Arrays; 9 | 10 | public class ShowPackageOption implements CliOption { 11 | 12 | protected final String optName = "spkg"; 13 | protected final String longOptName = "show_package"; 14 | protected final Option option; 15 | 16 | public ShowPackageOption() { 17 | this.option = new Option(this.optName, this.longOptName, false, "Show package"); 18 | } 19 | 20 | @Override 21 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 22 | return Arrays.stream(cmd.getOptions()).map(Option::getOpt) 23 | .filter(option -> option.equalsIgnoreCase(this.optName)) 24 | .findAny() 25 | .map(option -> { 26 | parserConfig.setShowPackage(true); 27 | return parserConfig; 28 | }) 29 | .orElseGet(() -> { 30 | parserConfig.setShowPackage(false); 31 | return parserConfig; 32 | }); 33 | } 34 | 35 | @Override 36 | public Option getOption() { 37 | return this.option; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/fieldmodifier/FieldModifierWrapper.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.fieldmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | 8 | import java.util.Arrays; 9 | 10 | public abstract class FieldModifierWrapper implements CliOption { 11 | 12 | protected abstract String getOptName(); 13 | protected abstract String getLongOptName(); 14 | protected abstract String getModifier(); 15 | 16 | protected final Option option; 17 | 18 | public FieldModifierWrapper() { 19 | this.option = new Option(this.getOptName(), this.getLongOptName(), false, String.format("Add %s fields", this.getModifier())); 20 | } 21 | 22 | @Override 23 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 24 | return Arrays.stream(cmd.getOptions()).map(Option::getOpt) 25 | .filter(option -> option.equalsIgnoreCase(this.getOptName())) 26 | .findAny() 27 | .map(option -> { 28 | parserConfig.addFieldModifier(this.getModifier()); 29 | return parserConfig; 30 | }) 31 | .orElse(parserConfig); 32 | } 33 | 34 | @Override 35 | public Option getOption() { 36 | return this.option; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/methodmodifier/MethodModifierWrapper.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.methodmodifier; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | 8 | import java.util.Arrays; 9 | 10 | public abstract class MethodModifierWrapper implements CliOption { 11 | 12 | protected abstract String getOptName(); 13 | protected abstract String getLongOptName(); 14 | protected abstract String getModifier(); 15 | 16 | protected final Option option; 17 | 18 | public MethodModifierWrapper() { 19 | this.option = new Option(this.getOptName(), this.getLongOptName(), false, String.format("Add %s methods", this.getModifier())); 20 | } 21 | 22 | @Override 23 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 24 | return Arrays.stream(cmd.getOptions()).map(Option::getOpt) 25 | .filter(option -> option.equalsIgnoreCase(this.getOptName())) 26 | .findAny() 27 | .map(option -> { 28 | parserConfig.addMethodModifier(this.getModifier()); 29 | return parserConfig; 30 | }) 31 | .orElse(parserConfig); 32 | } 33 | 34 | @Override 35 | public Option getOption() { 36 | return this.option; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/PUmlField.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | /** 4 | * plantUml字段 5 | * 6 | * @author shuzijun 7 | */ 8 | public class PUmlField implements PUml { 9 | 10 | private String visibility = "default"; 11 | 12 | private boolean isStatic; 13 | 14 | private String type; 15 | 16 | private String name; 17 | 18 | private String comment; 19 | 20 | public String getVisibility() { 21 | return visibility; 22 | } 23 | 24 | public void setVisibility(String visibility) { 25 | this.visibility = visibility; 26 | } 27 | 28 | public boolean isStatic() { 29 | return isStatic; 30 | } 31 | 32 | public void setStatic(boolean aStatic) { 33 | isStatic = aStatic; 34 | } 35 | 36 | public String getType() { 37 | return type; 38 | } 39 | 40 | public void setType(String type) { 41 | this.type = type; 42 | } 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public void setName(String name) { 49 | this.name = name; 50 | } 51 | 52 | public String getComment() { 53 | return comment; 54 | } 55 | 56 | public void setComment(String comment) { 57 | this.comment = comment; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return VisibilityUtils.toCharacter(visibility) + " " + (isStatic ? "{static} " : "") 63 | + type + " " + name; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/languagelevel/LanguageLevelOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.languagelevel; 2 | 3 | import com.github.javaparser.ParserConfiguration; 4 | import com.shuzijun.plantumlparser.cli.options.CliOption; 5 | import com.shuzijun.plantumlparser.core.ParserConfig; 6 | import org.apache.commons.cli.CommandLine; 7 | import org.apache.commons.cli.Option; 8 | 9 | import java.util.Arrays; 10 | 11 | public class LanguageLevelOption implements CliOption { 12 | 13 | protected final String optName = "l"; 14 | protected final String longOptName = "language_level"; 15 | protected final Option option; 16 | 17 | public LanguageLevelOption() { 18 | this.option = new Option(this.optName, this.longOptName, true, "Set language level"); 19 | } 20 | 21 | @Override 22 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 23 | return Arrays.stream(cmd.getOptions()).map(Option::getOpt) 24 | .filter(option -> option.equalsIgnoreCase(this.optName)) 25 | .findAny() 26 | .map(option -> { 27 | final String languageLevelStr = cmd.getOptionValue(option); 28 | final ParserConfiguration.LanguageLevel languageLevel = ParserConfiguration.LanguageLevel.valueOf(languageLevelStr); 29 | parserConfig.setLanguageLevel(languageLevel); 30 | return parserConfig; 31 | }) 32 | .orElse(parserConfig); 33 | } 34 | 35 | @Override 36 | public Option getOption() { 37 | return this.option; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /plantuml-parser-cli/README.md: -------------------------------------------------------------------------------- 1 | # plantuml-parser ![Gradle Package](https://github.com/shuzijun/plantuml-parser/workflows/Gradle%20Package/badge.svg) ![plugin](https://github.com/shuzijun/plantuml-parser/workflows/plugin/badge.svg) 2 | 3 | This is a CLI for the plantuml-parser-core. It supports easy usage of the `ParserProgram`by setting the `ParserConfig` via CLI. 4 | 5 | **Possible options are:** 6 | 7 | ```bash 8 | usage: plantuml-parser-cli [-f ] [-fdef] [-fpri] [-fpro] [-fpub] [-h] 9 | [-l ] [-mdef] [-mpri] [-mpro] [-mpub] [-o ] [-scom] 10 | [-sctr] [-spkg] 11 | -f,--filepath Set the input file/directory 12 | -fdef,--field_default Add default fields 13 | -fpri,--field_private Add private fields 14 | -fpro,--field_protected Add protected fields 15 | -fpub,--field_public Add public fields 16 | -h,--help Show the help 17 | -l,--language_level Set language level 18 | -mdef,--method_default Add default methods 19 | -mpri,--method_private Add private methods 20 | -mpro,--method_protected Add protected methods 21 | -mpub,--method_public Add public methods 22 | -o,--outfile Set the output file 23 | -scom,--show_comment Show comment 24 | -sctr,--show_constructors Show constructors 25 | -spkg,--show_package Show package 26 | ``` 27 | 28 | ## plantuml-parser-cli 29 | 30 | Example usage: 31 | 32 | ```Bash 33 | java -jar plantuml-parser-cli.jar -o 34 | "˜/projects/plantuml-parser/plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/out.puml" 35 | -f 36 | "˜/projects/plantuml-parser/plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/" 37 | -sctr -spkg -fpub -mpub -fpro -mpro 38 | ``` 39 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/help/HelpOption.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options.help; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.CliOption; 4 | import com.shuzijun.plantumlparser.core.ParserConfig; 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.HelpFormatter; 7 | import org.apache.commons.cli.Option; 8 | import org.apache.commons.cli.Options; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class HelpOption implements CliOption { 14 | 15 | protected final String optName = "h"; 16 | protected final String longOptName = "help"; 17 | protected final Option option; 18 | 19 | protected final List cliOptions; 20 | 21 | public HelpOption(final List cliOptions) { 22 | this.option = new Option(this.optName, this.longOptName, false, "Show the help"); 23 | this.cliOptions = cliOptions; 24 | } 25 | 26 | @Override 27 | public ParserConfig updateConfig(final ParserConfig parserConfig, final CommandLine cmd) { 28 | Arrays.stream(cmd.getOptions()).map(Option::getOpt) 29 | .filter(option -> option.equalsIgnoreCase(this.optName)) 30 | .findAny() 31 | .ifPresent(option -> { 32 | final HelpFormatter formatter = new HelpFormatter(); 33 | final Options options = new Options(); 34 | cliOptions.forEach(cliOption -> options.addOption(cliOption.getOption())); 35 | formatter.printHelp("plantuml-parser-cli", options, true); 36 | }); 37 | return parserConfig; 38 | } 39 | 40 | @Override 41 | public Option getOption() { 42 | return this.option; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/VisibilityUtils.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import org.jetbrains.kotlin.lexer.KtTokens; 4 | import org.jetbrains.kotlin.psi.KtModifierListOwner; 5 | 6 | /** 7 | * 转换限定符 8 | * 9 | * @author shuzijun 10 | */ 11 | public class VisibilityUtils { 12 | 13 | public static String toCharacter(String visibility) { 14 | if (visibility == null) { 15 | return "+"; 16 | } else if ("private".equals(visibility)) { 17 | return "-"; 18 | } else if ("default".equals(visibility)) { 19 | return "~"; 20 | } else if ("protected".equals(visibility)) { 21 | return "#"; 22 | } else { 23 | return "+"; 24 | } 25 | } 26 | 27 | public static boolean isVisibility(String visibility) { 28 | if (visibility == null) { 29 | return false; 30 | } else if ("private".equals(visibility)) { 31 | return true; 32 | } else if ("default".equals(visibility)) { 33 | return true; 34 | } else if ("protected".equals(visibility)) { 35 | return true; 36 | } else if ("public".equals(visibility)) { 37 | return true; 38 | } else { 39 | return false; 40 | } 41 | } 42 | 43 | public static String toVisibility(KtModifierListOwner ktModifierListOwner) { 44 | if (ktModifierListOwner.hasModifier(KtTokens.PRIVATE_KEYWORD)){ 45 | return "private"; 46 | } else if (ktModifierListOwner.hasModifier(KtTokens.INTERNAL_KEYWORD)){ 47 | return "private"; 48 | } else if (ktModifierListOwner.hasModifier(KtTokens.PROTECTED_KEYWORD)){ 49 | return "protected"; 50 | } else { 51 | return "public"; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/KtParserProgram.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import com.intellij.openapi.Disposable; 4 | import com.intellij.openapi.util.Disposer; 5 | import com.intellij.psi.PsiFile; 6 | import com.intellij.psi.PsiFileFactory; 7 | import org.apache.commons.io.FileUtils; 8 | import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; 9 | import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; 10 | import org.jetbrains.kotlin.config.CompilerConfiguration; 11 | import org.jetbrains.kotlin.idea.KotlinFileType; 12 | import org.jetbrains.kotlin.name.FqName; 13 | import org.jetbrains.kotlin.psi.KtFile; 14 | 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.nio.charset.Charset; 18 | 19 | public class KtParserProgram { 20 | 21 | public static void execute(ParserConfig parserConfig, File file,PUmlView pUmlView) throws IOException { 22 | if (parserConfig.getProject() == null) { 23 | Disposable disposable = Disposer.newDisposable(); 24 | KotlinCoreEnvironment env = KotlinCoreEnvironment.createForProduction( 25 | disposable, new CompilerConfiguration(), EnvironmentConfigFiles.JVM_CONFIG_FILES); 26 | parserConfig.setProject( env.getProject()); 27 | 28 | } 29 | 30 | PsiFile ktFile = PsiFileFactory.getInstance(parserConfig.getProject()).createFileFromText(file.getName(), KotlinFileType.INSTANCE, FileUtils.readFileToString(file, Charset.defaultCharset())); 31 | if (!(ktFile instanceof KtFile)) { 32 | return; 33 | } 34 | FqName packageFqName = ((KtFile)ktFile).getPackageFqName(); 35 | KtClassVOidVisitor ktClassVOidVisitor = new KtClassVOidVisitor(packageFqName.asString(),parserConfig); 36 | ((KtFile) ktFile).accept(ktClassVOidVisitor,pUmlView); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/PUmlMethod.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * plantUml方法 9 | * 10 | * @author mafayun 11 | */ 12 | public class PUmlMethod { 13 | 14 | private String visibility = "default"; 15 | 16 | private boolean isStatic; 17 | 18 | private boolean isAbstract; 19 | 20 | private String returnType; 21 | 22 | private String name; 23 | 24 | private List paramList = new LinkedList<>(); 25 | 26 | private String comment; 27 | 28 | public String getVisibility() { 29 | return visibility; 30 | } 31 | 32 | public void setVisibility(String visibility) { 33 | this.visibility = visibility; 34 | } 35 | 36 | public boolean isStatic() { 37 | return isStatic; 38 | } 39 | 40 | public void setStatic(boolean aStatic) { 41 | isStatic = aStatic; 42 | } 43 | 44 | public boolean isAbstract() { 45 | return isAbstract; 46 | } 47 | 48 | public void setAbstract(boolean anAbstract) { 49 | isAbstract = anAbstract; 50 | } 51 | 52 | public String getReturnType() { 53 | return returnType; 54 | } 55 | 56 | public void setReturnType(String returnType) { 57 | this.returnType = returnType; 58 | } 59 | 60 | public String getName() { 61 | return name; 62 | } 63 | 64 | public void setName(String name) { 65 | this.name = name; 66 | } 67 | 68 | public List getParamList() { 69 | return paramList; 70 | } 71 | 72 | public void addParam(String param) { 73 | this.paramList.add(param); 74 | } 75 | 76 | public void setComment(String comment) { 77 | this.comment = comment; 78 | } 79 | 80 | public String getComment() { 81 | return comment; 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | return VisibilityUtils.toCharacter(visibility) + " " + (isStatic ? "{static} " : "") + (isAbstract ? "{abstract}" : "") 87 | + returnType + " " + name + "(" 88 | + (paramList.isEmpty() ? "" : paramList.stream().collect(Collectors.joining(","))) 89 | + ")"; 90 | } 91 | 92 | public String getFullName(){ 93 | return name + "(" 94 | + (paramList.isEmpty() ? "" : paramList.stream().collect(Collectors.joining(","))) 95 | + ")"; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | plantuml-parser 3 | PlantUML Parser 4 | 0.0.2 5 | shuzijun 6 | 7 | 9 |

Convert the Java(or kotlin) source code to Plantuml.

10 | 11 |
12 |
13 |

This plug-in can convert java source code into plantuml syntax, and can be displayed with the help of PlantUML integration or markdown.This will greatly save your time to write puml.

14 |
15 |
16 |
17 |

Select the java file or folder to be parsed in the project, right-click and select "Plantuml Parser", fill in the output file name (you can see the complete path in the dialog box) and configure other options, and click "generate" to complete.

18 |
19 |
20 |
21 |

If you have any questions or suggestions, you can talk to plantuml-parser

22 |
23 |
24 |

You can refer to the gif below to start your use.

25 |

26 | demo 27 |

28 | ]]>
29 | 30 | 32 | 1.support kotlin 33 | 34 | ]]> 35 | 36 | 37 | 39 | com.intellij.modules.platform 40 | org.jetbrains.kotlin 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 |
-------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/ParserProgram.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import com.github.javaparser.ParserConfiguration; 4 | import com.github.javaparser.StaticJavaParser; 5 | import com.github.javaparser.ast.CompilationUnit; 6 | import com.github.javaparser.ast.PackageDeclaration; 7 | import com.github.javaparser.ast.visitor.VoidVisitor; 8 | import org.apache.commons.io.FileUtils; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.nio.charset.Charset; 13 | import java.util.Optional; 14 | import java.util.Set; 15 | 16 | /** 17 | * 解析程序 18 | * 19 | * @author shuzijun 20 | */ 21 | public class ParserProgram { 22 | 23 | private ParserConfig parserConfig; 24 | 25 | 26 | public ParserProgram(ParserConfig parserConfig) { 27 | this.parserConfig = parserConfig; 28 | } 29 | 30 | 31 | public void execute() throws IOException { 32 | if(parserConfig.getLanguageLevel()!=null) { 33 | StaticJavaParser.getConfiguration().setLanguageLevel(parserConfig.getLanguageLevel()); 34 | }else { 35 | StaticJavaParser.getConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_8); 36 | } 37 | Set files = this.parserConfig.getFilePaths(); 38 | 39 | PUmlView pUmlView = new PUmlView(); 40 | for (File file : files) { 41 | if (file.getPath().endsWith("java")){ 42 | CompilationUnit compilationUnit = StaticJavaParser.parse(file); 43 | Optional packageDeclaration = compilationUnit.getPackageDeclaration(); 44 | VoidVisitor classNameCollector = new ClassVoidVisitor(packageDeclaration.isPresent() ? packageDeclaration.get().getNameAsString() : "", parserConfig); 45 | classNameCollector.visit(compilationUnit, pUmlView); 46 | } else if (file.getPath().endsWith("kt")){ 47 | try { 48 | KtParserProgram.execute(parserConfig,file,pUmlView); 49 | }catch (NoClassDefFoundError e){ 50 | throw new IOException("Environment not support kotlin"); 51 | } 52 | } 53 | } 54 | 55 | if (this.parserConfig.getOutFilePath() == null) { 56 | System.out.println(pUmlView); 57 | } else { 58 | File outFile = new File(this.parserConfig.getOutFilePath()); 59 | if (!outFile.getParentFile().exists()) { 60 | outFile.getParentFile().mkdirs(); 61 | } 62 | if (!outFile.exists()) { 63 | outFile.createNewFile(); 64 | } 65 | FileUtils.write(outFile, pUmlView.toString(), Charset.forName("UTF-8")); 66 | } 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /plantuml-parser-cli/src/main/java/com/shuzijun/plantumlparser/cli/options/CliOptionsHolder.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.cli.options; 2 | 3 | import com.shuzijun.plantumlparser.cli.options.fieldmodifier.FieldDefaultModifier; 4 | import com.shuzijun.plantumlparser.cli.options.fieldmodifier.FieldPrivateModifier; 5 | import com.shuzijun.plantumlparser.cli.options.fieldmodifier.FieldProtectedModifier; 6 | import com.shuzijun.plantumlparser.cli.options.fieldmodifier.FieldPublicModifier; 7 | import com.shuzijun.plantumlparser.cli.options.filepath.FilePathOption; 8 | import com.shuzijun.plantumlparser.cli.options.help.HelpOption; 9 | import com.shuzijun.plantumlparser.cli.options.languagelevel.LanguageLevelOption; 10 | import com.shuzijun.plantumlparser.cli.options.methodmodifier.MethodDefaultModifier; 11 | import com.shuzijun.plantumlparser.cli.options.methodmodifier.MethodPrivateModifier; 12 | import com.shuzijun.plantumlparser.cli.options.methodmodifier.MethodProtectedModifier; 13 | import com.shuzijun.plantumlparser.cli.options.methodmodifier.MethodPublicModifier; 14 | import com.shuzijun.plantumlparser.cli.options.outfilepath.OutfilePathOption; 15 | import com.shuzijun.plantumlparser.cli.options.showcomment.ShowCommentOption; 16 | import com.shuzijun.plantumlparser.cli.options.showconstructors.ShowConstructorsOption; 17 | import com.shuzijun.plantumlparser.cli.options.showdefaultconstructors.ShowDefaultConstructorsOption; 18 | import com.shuzijun.plantumlparser.cli.options.showpackage.ShowPackageOption; 19 | import org.apache.commons.cli.Options; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.stream.Collectors; 24 | 25 | public class CliOptionsHolder { 26 | 27 | private CliOptionsHolder() { 28 | throw new UnsupportedOperationException(); 29 | } 30 | 31 | private static final List cliOptions = new ArrayList<>(); 32 | static { 33 | cliOptions.add(new FieldPublicModifier()); 34 | cliOptions.add(new FieldProtectedModifier()); 35 | cliOptions.add(new FieldDefaultModifier()); 36 | cliOptions.add(new FieldPrivateModifier()); 37 | 38 | cliOptions.add(new MethodPublicModifier()); 39 | cliOptions.add(new MethodProtectedModifier()); 40 | cliOptions.add(new MethodDefaultModifier()); 41 | cliOptions.add(new MethodPrivateModifier()); 42 | 43 | cliOptions.add(new OutfilePathOption()); 44 | cliOptions.add(new FilePathOption()); 45 | 46 | cliOptions.add(new LanguageLevelOption()); 47 | cliOptions.add(new ShowCommentOption()); 48 | cliOptions.add(new ShowConstructorsOption()); 49 | cliOptions.add(new ShowDefaultConstructorsOption()); 50 | cliOptions.add(new ShowPackageOption()); 51 | 52 | // This is a special cli option for displaying the help 53 | cliOptions.add(new HelpOption(cliOptions)); 54 | } 55 | 56 | public static Options createOptions() { 57 | final Options options = new Options(); 58 | cliOptions.stream().map(CliOption::getOption).forEach(options::addOption); 59 | return options; 60 | } 61 | 62 | public static List getParserConfigUpdater(){ 63 | return cliOptions.stream() 64 | .map(ParserConfigUpdater.class::cast) 65 | .collect(Collectors.toList()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # plantuml-parser ![Gradle Package](https://github.com/shuzijun/plantuml-parser/workflows/Gradle%20Package/badge.svg) ![plugin](https://github.com/shuzijun/plantuml-parser/workflows/plugin/badge.svg) 2 | 3 | 将Java源代码转换为plantuml 4 | Convert the Java source code to Plantuml 5 | 6 | ## plantuml-parser-core 7 | 8 | ```java 9 | public static void main(String[]args)throws IOException{ 10 | ParserConfig parserConfig=new ParserConfig(); 11 | parserConfig.addFilePath(filePath or fileDirectory); 12 | parserConfig.setOutFilePath(out file path); 13 | parserConfig.addMethodModifier(private or protected or default or public ); 14 | parserConfig.addFieldModifier(private or protected or default or public ); 15 | 16 | ParserProgram parserProgram=new ParserProgram(parserConfig); 17 | parserProgram.execute(); 18 | } 19 | ``` 20 | 21 | ## plantuml-parser-plugin 22 | 23 |

24 | demo 25 |

26 | 27 | ## output 28 | ### demo 29 | ```puml 30 | @startuml 31 | class com.shuzijun.plantumlparser.core.PUmlClass { 32 | + String getPackageName() 33 | + void setPackageName(String) 34 | + String getClassName() 35 | + void setClassName(String) 36 | + String getClassType() 37 | + void setClassType(String) 38 | + void addPUmlFieldList(PUmlField) 39 | + void addPUmlMethodList(PUmlMethod) 40 | + String toString() 41 | } 42 | class com.shuzijun.plantumlparser.core.PUmlField { 43 | + String getVisibility() 44 | + void setVisibility(String) 45 | + boolean isStatic() 46 | + void setStatic(boolean) 47 | + String getType() 48 | + void setType(String) 49 | + String getName() 50 | + void setName(String) 51 | + String toString() 52 | } 53 | class com.shuzijun.plantumlparser.core.ParserConfig { 54 | + String getOutFilePath() 55 | + void setOutFilePath(String) 56 | + Set getFilePaths() 57 | + void addFilePath(String) 58 | + void addFieldModifier(String) 59 | + boolean isFieldModifier(String) 60 | + void addMethodModifier(String) 61 | + boolean isMethodModifier(String) 62 | } 63 | class com.shuzijun.plantumlparser.core.ClassVoidVisitor { 64 | + void visit(ClassOrInterfaceDeclaration,PUmlView) 65 | } 66 | class com.shuzijun.plantumlparser.core.PUmlMethod { 67 | + String getVisibility() 68 | + void setVisibility(String) 69 | + boolean isStatic() 70 | + void setStatic(boolean) 71 | + boolean isAbstract() 72 | + void setAbstract(boolean) 73 | + String getReturnType() 74 | + void setReturnType(String) 75 | + String getName() 76 | + void setName(String) 77 | + List getParamList() 78 | + void addParam(String) 79 | + String toString() 80 | } 81 | class com.shuzijun.plantumlparser.core.PUmlView { 82 | + void addPUmlClass(PUmlClass) 83 | + void addPUmlRelation(PUmlRelation) 84 | + String toString() 85 | } 86 | class com.shuzijun.plantumlparser.core.PUmlRelation { 87 | + void setSource(String) 88 | + void setTarget(String) 89 | + void setRelation(String) 90 | + String toString() 91 | } 92 | class com.shuzijun.plantumlparser.core.VisibilityUtils { 93 | + {static} String toCharacter(String) 94 | } 95 | class com.shuzijun.plantumlparser.core.ParserProgram { 96 | + void execute(ParserConfig) 97 | } 98 | 99 | 100 | com.github.javaparser.ast.visitor.VoidVisitorAdapter <|-- com.shuzijun.plantumlparser.core.ClassVoidVisitor 101 | @enduml 102 | ``` 103 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/PUmlClass.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | /** 8 | * plantUml类 9 | * 10 | * @author shuzijun 11 | */ 12 | public class PUmlClass implements PUml{ 13 | private String packageName; 14 | 15 | private String className; 16 | 17 | private String classType; 18 | 19 | private String classComment; 20 | 21 | private List pUmlFieldList = new LinkedList<>(); 22 | 23 | private List pUmlMethodList = new LinkedList<>(); 24 | 25 | public String getPackageName() { 26 | return packageName; 27 | } 28 | 29 | public void setPackageName(String packageName) { 30 | this.packageName = packageName; 31 | } 32 | 33 | public String getClassName() { 34 | return className; 35 | } 36 | 37 | public void setClassName(String className) { 38 | this.className = className; 39 | } 40 | 41 | public String getClassType() { 42 | return classType; 43 | } 44 | 45 | public void setClassType(String classType) { 46 | this.classType = classType; 47 | } 48 | 49 | public String getClassComment() { 50 | return classComment; 51 | } 52 | 53 | public void setClassComment(String classComment) { 54 | this.classComment = classComment; 55 | } 56 | 57 | public void addPUmlFieldList(PUmlField pUmlField) { 58 | this.pUmlFieldList.add(pUmlField); 59 | } 60 | 61 | 62 | public void addPUmlMethodList(PUmlMethod pUmlMethod) { 63 | this.pUmlMethodList.add(pUmlMethod); 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | 69 | String fullClassName = ((packageName == null || packageName.trim().equals("")) ? "" : (packageName + ".")) + className; 70 | 71 | String classStr = classType + " " + fullClassName + " {\n" + 72 | (pUmlFieldList.isEmpty() ? "" : pUmlFieldList.stream().map(pUmlField -> pUmlField.toString()).collect(Collectors.joining("\n")) + "\n") + 73 | (pUmlMethodList.isEmpty() ? "" : pUmlMethodList.stream().map(pUmlField -> pUmlField.toString()).collect(Collectors.joining("\n")) + "\n") + 74 | "}"; 75 | 76 | if(getClassComment() != null && getClassComment().length() > 0){ 77 | classStr += "\nnote top of "+fullClassName+"\n"+getClassComment()+"\nend note\n"; 78 | } 79 | 80 | StringBuilder fieldComment = new StringBuilder(); 81 | 82 | if(!pUmlFieldList.isEmpty()){ 83 | int commentIdx = 0; 84 | fieldComment.append("\n"); 85 | for (PUmlField pUmlField : pUmlFieldList) { 86 | if(pUmlField.getComment() != null && pUmlField.getComment().length() > 0){ 87 | fieldComment.append("note "); 88 | if(commentIdx % 2 != 0){ 89 | fieldComment.append("right"); 90 | }else{ 91 | fieldComment.append("left"); 92 | } 93 | fieldComment.append(" of ").append(fullClassName).append("::").append(pUmlField.getName()).append("\n"); 94 | fieldComment.append(pUmlField.getComment()).append("\n"); 95 | fieldComment.append("end note\n"); 96 | commentIdx++; 97 | } 98 | } 99 | } 100 | 101 | 102 | if(!pUmlMethodList.isEmpty()){ 103 | int commentIdx = 0; 104 | fieldComment.append("\n"); 105 | for (PUmlMethod pUmlMethod : pUmlMethodList) { 106 | if(pUmlMethod.getComment() != null && pUmlMethod.getComment().length() > 0){ 107 | fieldComment.append("note "); 108 | if(commentIdx % 2 != 0){ 109 | fieldComment.append("right"); 110 | }else{ 111 | fieldComment.append("left"); 112 | } 113 | fieldComment.append(" of ").append(fullClassName).append("::").append(pUmlMethod.getFullName()).append("\n"); 114 | fieldComment.append(pUmlMethod.getComment()).append("\n"); 115 | fieldComment.append("end note\n"); 116 | commentIdx++; 117 | } 118 | } 119 | } 120 | 121 | classStr += fieldComment.toString(); 122 | return classStr; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/java/com/shuzijun/plantumlparser/plugin/utils/MTAUtils.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.plugin.utils; 2 | 3 | import com.intellij.ide.plugins.PluginManager; 4 | import com.intellij.openapi.extensions.PluginId; 5 | import com.intellij.openapi.util.SystemInfo; 6 | import com.intellij.util.io.HttpRequests; 7 | import org.apache.http.client.utils.URIBuilder; 8 | 9 | import java.awt.*; 10 | import java.net.URI; 11 | import java.util.Calendar; 12 | import java.util.Locale; 13 | import java.util.concurrent.ExecutorService; 14 | import java.util.concurrent.Executors; 15 | 16 | /** 17 | * @author shuzijun 18 | */ 19 | public class MTAUtils { 20 | 21 | private static String URL = "http://pingtcss.qq.com/pingd"; 22 | private static String SID = "500735096"; 23 | private static String SI = getI("s"); 24 | private static String version = null; 25 | private static String userAgent = null; 26 | 27 | private static ExecutorService cachedThreadPool = Executors.newCachedThreadPool(); 28 | 29 | public static String getI(String prefix) { 30 | int[] b = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 31 | for (int e = 10; 1 < e; e--) { 32 | int c = (int) Math.floor(10 * Math.random()); 33 | int f = b[c]; 34 | b[c] = b[e - 1]; 35 | b[e - 1] = f; 36 | } 37 | int c = 0; 38 | for (int e = 0; 5 > e; e++) { 39 | c = 10 * c + b[e]; 40 | } 41 | return prefix + c + System.currentTimeMillis(); 42 | } 43 | 44 | public static void click(String actionsId) { 45 | cachedThreadPool.execute(new ClickTask(actionsId)); 46 | } 47 | 48 | private static class ClickTask implements Runnable { 49 | 50 | 51 | private String actionsId; 52 | 53 | public ClickTask(String actionsId) { 54 | this.actionsId = actionsId; 55 | } 56 | 57 | @Override 58 | public void run() { 59 | try { 60 | if (version == null) { 61 | version = PluginManager.getPlugin(PluginId.getId("plantuml-parser")).getVersion() 62 | .replace("v", "").replaceAll("-|_", "."); 63 | } 64 | if (userAgent == null) { 65 | if (SystemInfo.OS_NAME.toUpperCase().contains("MAC")) { 66 | userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"; 67 | } else if (SystemInfo.OS_NAME.toUpperCase().contains("LINUX")) { 68 | userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"; 69 | } else { 70 | userAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"; 71 | } 72 | } 73 | Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize(); 74 | Calendar calendar = Calendar.getInstance(); 75 | URI uri = new URIBuilder(URL) 76 | .setParameter("dm", "127.0.0.1") 77 | .setParameter("pvi", getI("")) 78 | .setParameter("si", SI) 79 | .setParameter("url", "/" + actionsId) 80 | .setParameter("arg", "") 81 | .setParameter("ty", "0") 82 | .setParameter("rdm", "") 83 | .setParameter("rurl", "") 84 | .setParameter("rarg", "") 85 | .setParameter("adt", version) 86 | .setParameter("r2", SID) 87 | .setParameter("scr", (int) screensize.getWidth() + "x" + (int) screensize.getHeight()) 88 | .setParameter("scl", Toolkit.getDefaultToolkit().getScreenResolution() + "-bit") 89 | .setParameter("lg", Locale.getDefault().toString().replace("_", "-").toLowerCase()) 90 | .setParameter("tz", -(calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000 / 60 + "") 91 | .setParameter("ext", "version=2.0.14") 92 | .setParameter("random", System.currentTimeMillis() + "") 93 | .build(); 94 | 95 | HttpRequests.request(uri.toURL().toString()).userAgent(userAgent).tryConnect(); 96 | 97 | } catch (Exception e) { 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/ParserConfig.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import com.github.javaparser.ParserConfiguration; 4 | import com.intellij.openapi.Disposable; 5 | import com.intellij.openapi.project.Project; 6 | import com.intellij.openapi.util.Disposer; 7 | import org.apache.commons.io.FileUtils; 8 | import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; 9 | import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; 10 | import org.jetbrains.kotlin.config.CompilerConfiguration; 11 | 12 | import java.io.File; 13 | import java.util.*; 14 | import java.util.regex.PatternSyntaxException; 15 | 16 | /** 17 | * 解析配置 18 | * 19 | * @author shuzijun 20 | */ 21 | public class ParserConfig { 22 | /** 23 | * 解析的文件路径 24 | */ 25 | private Map fileMap = new HashMap<>(); 26 | 27 | /** 28 | * 输出文件路径 29 | */ 30 | private String outFilePath; 31 | 32 | private Set excludeClassRegex = new HashSet<>(); 33 | 34 | private Set fieldModifier = new HashSet<>(); 35 | 36 | private Set methodModifier = new HashSet<>(); 37 | 38 | private boolean showPackage = true; 39 | 40 | private boolean showConstructors = false; 41 | 42 | private boolean showDefaultConstructors = false; 43 | 44 | private boolean showComment = false; 45 | 46 | public Project getProject() { 47 | return project; 48 | } 49 | 50 | public void setProject(Project project) { 51 | this.project = project; 52 | } 53 | 54 | private Project project; 55 | 56 | private ParserConfiguration.LanguageLevel languageLevel = ParserConfiguration.LanguageLevel.JAVA_8; 57 | 58 | public String getOutFilePath() { 59 | return outFilePath; 60 | } 61 | 62 | public void setOutFilePath(String outFilePath) { 63 | this.outFilePath = outFilePath; 64 | } 65 | 66 | public Set getFilePaths() { 67 | return new HashSet<>(fileMap.values()); 68 | } 69 | 70 | public void addFilePath(String filePath) { 71 | File file = new File(filePath); 72 | if (!file.exists()) { 73 | return; 74 | } else if (file.isDirectory()) { 75 | Collection files = FileUtils.listFiles(file, new String[]{"java","kt"}, Boolean.TRUE); 76 | files.forEach(fileTemp -> fileMap.put(fileTemp.getPath(), fileTemp)); 77 | } else if (filePath.endsWith("java") || filePath.endsWith("kt")) { 78 | fileMap.put(file.getPath(), file); 79 | } 80 | } 81 | 82 | public void addFieldModifier(String modifier) { 83 | fieldModifier.add(modifier); 84 | } 85 | 86 | public boolean isFieldModifier(String modifier) { 87 | if (fieldModifier.contains(Constant.VisibilityAll)){ 88 | return true; 89 | } 90 | return fieldModifier.contains(modifier); 91 | } 92 | 93 | public void addMethodModifier(String modifier) { 94 | methodModifier.add(modifier); 95 | } 96 | 97 | public boolean isMethodModifier(String modifier) { 98 | if (methodModifier.contains(Constant.VisibilityAll)){ 99 | return true; 100 | } 101 | return methodModifier.contains(modifier); 102 | } 103 | 104 | public boolean isShowPackage() { 105 | return showPackage; 106 | } 107 | 108 | public void setShowPackage(boolean showPackage) { 109 | this.showPackage = showPackage; 110 | } 111 | 112 | public boolean isShowConstructors() { 113 | return showConstructors; 114 | } 115 | 116 | public void setShowConstructors(boolean showConstructors) { 117 | this.showConstructors = showConstructors; 118 | } 119 | 120 | public boolean isShowDefaultConstructors() { 121 | return showDefaultConstructors; 122 | } 123 | 124 | public void setShowDefaultConstructors(boolean showDefaultConstructors) { 125 | this.showDefaultConstructors = showDefaultConstructors; 126 | } 127 | 128 | public ParserConfiguration.LanguageLevel getLanguageLevel() { 129 | return languageLevel; 130 | } 131 | 132 | public void setLanguageLevel(ParserConfiguration.LanguageLevel languageLevel) { 133 | this.languageLevel = languageLevel; 134 | } 135 | 136 | public boolean isShowComment() { 137 | return showComment; 138 | } 139 | 140 | public void setShowComment(boolean showComment) { 141 | this.showComment = showComment; 142 | } 143 | 144 | public Set getExcludeClassRegex() { 145 | return excludeClassRegex; 146 | } 147 | 148 | public void addExcludeClassRegex(String excludeClassRegex) { 149 | this.excludeClassRegex.add(excludeClassRegex); 150 | } 151 | public boolean isExcludeClass(String className) { 152 | if(className == null || className.trim().length() == 0){ 153 | return false; 154 | } 155 | for (String regex : excludeClassRegex) { 156 | try { 157 | if(className.matches(regex)){ 158 | return true; 159 | } 160 | }catch (PatternSyntaxException ignore){ 161 | } 162 | } 163 | return false; 164 | } 165 | 166 | 167 | } 168 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/test/java/com/shuzijun/plantumlparser/core/UmlGenerationTester.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import com.github.javaparser.ParserConfiguration; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.File; 6 | import java.io.FileNotFoundException; 7 | import java.io.IOException; 8 | import java.io.PrintStream; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | import java.util.Objects; 13 | import java.util.Scanner; 14 | 15 | public class UmlGenerationTester { 16 | 17 | private static ParserConfig makeParserConfig(String filename, boolean showDefaultCon) { 18 | ParserConfig parserConfig = new ParserConfig(); 19 | parserConfig.setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_17); 20 | parserConfig.setShowConstructors(true); 21 | parserConfig.setShowDefaultConstructors(showDefaultCon); 22 | parserConfig.addFieldModifier("private"); 23 | parserConfig.addMethodModifier("public"); 24 | parserConfig.addMethodModifier("default"); 25 | File file = new File(Objects.requireNonNull( 26 | UmlGenerationTester.class.getClassLoader().getResource(filename)).getFile()); 27 | parserConfig.addFilePath(file.getAbsolutePath()); 28 | return parserConfig; 29 | } 30 | 31 | private static String getUml(String filename, boolean showDefaultCon) throws IOException { 32 | ParserProgram parserProgram = new ParserProgram(makeParserConfig(filename, showDefaultCon)); 33 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 34 | PrintStream oldOut = System.out; 35 | System.setOut(new PrintStream(baos)); 36 | parserProgram.execute(); 37 | String result = baos.toString(); 38 | System.setOut(oldOut); 39 | return result; 40 | } 41 | 42 | private static boolean isUmlEquivalent(String uml1, String uml2) { 43 | String[] lines1 = uml1.replaceAll("\r", "").split("\n"); 44 | List lines2 = new ArrayList<>(Arrays.asList(uml2.replaceAll("\r", "").split("\n"))); 45 | if (lines1.length != lines2.size()) { 46 | return false; 47 | } 48 | for (String line : lines1) { 49 | if (!lines2.contains(line)) { 50 | System.out.println(line); 51 | return false; 52 | } 53 | lines2.remove(line); 54 | } 55 | return lines2.isEmpty(); 56 | } 57 | 58 | private static boolean isUmlEquivalent(String uml, File umlFile) { 59 | StringBuilder sb = new StringBuilder(); 60 | try (Scanner sc = new Scanner(umlFile)) { 61 | while (sc.hasNextLine()) { 62 | String cur = sc.nextLine(); 63 | sb.append(cur).append("\n"); 64 | } 65 | } catch (FileNotFoundException e) { 66 | e.printStackTrace(); 67 | } 68 | return isUmlEquivalent(uml, sb.toString()); 69 | } 70 | 71 | private static void testFilesRecord(String filename1, String filename2) 72 | throws IOException { 73 | String uml1 = getUml(filename1, false); 74 | String uml2 = getUml(filename2, false); 75 | if (!isUmlEquivalent(uml1, uml2)) { 76 | System.err.println("UML unequal: "); 77 | System.err.println(uml1); 78 | System.err.println(uml2); 79 | throw new RuntimeException("UML unequal"); 80 | } 81 | } 82 | 83 | private static void testFilesDefaultConstructor( 84 | String fileNameUmlExpected, String fileNameSrc, boolean showDefaultCon) 85 | throws IOException { 86 | String uml = getUml(fileNameSrc, showDefaultCon); 87 | File file = new File(Objects.requireNonNull( 88 | UmlGenerationTester.class.getClassLoader().getResource(fileNameUmlExpected)).getFile()); 89 | if (!isUmlEquivalent(uml, file)) { 90 | System.err.println(uml); 91 | throw new RuntimeException("UML not equal"); 92 | } 93 | } 94 | 95 | private static void testRecord() throws IOException { 96 | for (int i = 1; i <= 6; i++) { 97 | testFilesRecord( 98 | String.format("Record%d.java", i), 99 | String.format("Record%dDesugared.java", i)); 100 | } 101 | } 102 | 103 | private static void testDefaultConstructor() throws IOException { 104 | // A class without a constructor should contain a default constructor in the output 105 | // when showDefaultConstructor is true 106 | testFilesDefaultConstructor("ClassWOConstructorOutput.txt", "ClassWOConstructor.java", true); 107 | testFilesDefaultConstructor("ClassWithConstructorOutput.txt", "ClassWithConstructor.java", true); 108 | 109 | // A class without a constructor should not contain a default constructor in the output 110 | // when showDefaultConstructor is false 111 | testFilesDefaultConstructor("ClassWOConstructorNoConstructorOutput.txt", "ClassWOConstructor.java", false); 112 | testFilesDefaultConstructor("ClassWithConstructorOutput.txt", "ClassWithConstructor.java", false); 113 | } 114 | 115 | public static void main(String[] args) throws IOException { 116 | testRecord(); 117 | testDefaultConstructor(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/java/com/shuzijun/plantumlparser/plugin/window/ParserConfigPanel.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.plugin.window; 2 | 3 | import com.github.javaparser.ParserConfiguration; 4 | import com.intellij.openapi.fileChooser.FileChooserDescriptor; 5 | import com.intellij.openapi.fileChooser.FileChooserFactory; 6 | import com.intellij.openapi.fileChooser.PathChooserDialog; 7 | import com.intellij.openapi.project.Project; 8 | import com.intellij.openapi.vfs.VirtualFile; 9 | import com.intellij.ui.DocumentAdapter; 10 | import com.shuzijun.plantumlparser.plugin.utils.PropertiesUtils; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | import javax.swing.*; 14 | import javax.swing.event.DocumentEvent; 15 | import java.awt.event.MouseAdapter; 16 | import java.awt.event.MouseEvent; 17 | import java.io.File; 18 | import java.util.*; 19 | 20 | /** 21 | * 解析配置 22 | * 23 | * @author shuzijun 24 | */ 25 | public class ParserConfigPanel { 26 | 27 | private String basePath; 28 | 29 | private JPanel jpanel; 30 | private JTextField fileName; 31 | private JLabel fileDirectory; 32 | private JLabel filePath; 33 | private JCheckBox fieldPrivateCheckBox; 34 | private JCheckBox fieldDefaultCheckBox; 35 | private JCheckBox fieldProtectedCheckBox; 36 | private JCheckBox fieldPublicCheckBox; 37 | private JCheckBox methodPrivateCheckBox; 38 | private JCheckBox methodProtectedCheckBox; 39 | private JCheckBox methodDefaultCheckBox; 40 | private JCheckBox methodPublicCheckBox; 41 | private JComboBox languageLevelComboBox; 42 | private JCheckBox showPackageCheckBox; 43 | private JCheckBox constructorsCheckBox; 44 | private JButton chooseFilePath; 45 | private JCheckBox commentCheckBox; 46 | private JTextField excludeClass; 47 | private PathChooserDialog pathChooserDialog; 48 | 49 | public ParserConfigPanel(Project project) { 50 | this.basePath = project.getBasePath(); 51 | fileDirectory.setText(basePath); 52 | filePath.setText(basePath + File.separator + fileName.getText() + ".puml"); 53 | fileName.getDocument().addDocumentListener(new DocumentAdapter() { 54 | @Override 55 | protected void textChanged(@NotNull DocumentEvent documentEvent) { 56 | filePath.setText(fileDirectory.getText() + File.separator + fileName.getText() + ".puml"); 57 | } 58 | }); 59 | for (ParserConfiguration.LanguageLevel value : ParserConfiguration.LanguageLevel.values()) { 60 | languageLevelComboBox.addItem(value); 61 | } 62 | languageLevelComboBox.setSelectedItem(ParserConfiguration.LanguageLevel.JAVA_8); 63 | 64 | FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor( 65 | false, true, false, 66 | false, false, false); 67 | 68 | chooseFilePath.addMouseListener(new MouseAdapter() { 69 | @Override 70 | public void mouseClicked(MouseEvent e) { 71 | pathChooserDialog = FileChooserFactory.getInstance().createPathChooser(fileChooserDescriptor,project,jpanel); 72 | 73 | pathChooserDialog.choose(project.getProjectFile(), choose -> { 74 | if(choose.size() > 0){ 75 | VirtualFile file = choose.get(0); 76 | fileDirectory.setText(file.getPath()); 77 | filePath.setText(fileDirectory.getText() + File.separator + fileName.getText() + ".puml"); 78 | } 79 | }); 80 | } 81 | }); 82 | } 83 | 84 | public JPanel getJpanel() { 85 | return jpanel; 86 | } 87 | 88 | public Set getField() { 89 | Set fieldModifier = new HashSet<>(); 90 | if (fieldPrivateCheckBox.isSelected()) { 91 | fieldModifier.add(fieldPrivateCheckBox.getText()); 92 | } 93 | if (fieldProtectedCheckBox.isSelected()) { 94 | fieldModifier.add(fieldProtectedCheckBox.getText()); 95 | } 96 | 97 | if (fieldDefaultCheckBox.isSelected()) { 98 | fieldModifier.add(fieldDefaultCheckBox.getText()); 99 | } 100 | 101 | if (fieldPublicCheckBox.isSelected()) { 102 | fieldModifier.add(fieldPublicCheckBox.getText()); 103 | } 104 | return fieldModifier; 105 | } 106 | 107 | public Set getMethod() { 108 | Set methodModifier = new HashSet<>(); 109 | if (methodPrivateCheckBox.isSelected()) { 110 | methodModifier.add(methodPrivateCheckBox.getText()); 111 | } 112 | if (methodProtectedCheckBox.isSelected()) { 113 | methodModifier.add(methodProtectedCheckBox.getText()); 114 | } 115 | 116 | if (methodDefaultCheckBox.isSelected()) { 117 | methodModifier.add(methodDefaultCheckBox.getText()); 118 | } 119 | 120 | if (methodPublicCheckBox.isSelected()) { 121 | methodModifier.add(methodPublicCheckBox.getText()); 122 | } 123 | return methodModifier; 124 | } 125 | 126 | public String getFilePath() { 127 | if (fileName.getText() == null || fileName.getText().trim().length() == 0) { 128 | throw new NullPointerException(PropertiesUtils.getInfo("fileName.empty")); 129 | } 130 | return filePath.getText(); 131 | } 132 | 133 | public ParserConfiguration.LanguageLevel getLanguageLevel() { 134 | return (ParserConfiguration.LanguageLevel) languageLevelComboBox.getSelectedItem(); 135 | } 136 | 137 | public boolean getShowPackage() { 138 | return showPackageCheckBox.isSelected(); 139 | } 140 | 141 | public boolean getConstructors() { 142 | return constructorsCheckBox.isSelected(); 143 | } 144 | 145 | public boolean getShowComment() { 146 | return commentCheckBox.isSelected(); 147 | } 148 | 149 | public List getExcludeClass(){ 150 | if (excludeClass.getText() == null || excludeClass.getText().trim().length() == 0) { 151 | return new ArrayList<>(); 152 | } 153 | return Arrays.asList(excludeClass.getText().trim().split(",")); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/java/com/shuzijun/plantumlparser/plugin/action/ParserProgramAction.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.plugin.action; 2 | 3 | import com.intellij.ide.BrowserUtil; 4 | import com.intellij.notification.Notification; 5 | import com.intellij.notification.NotificationType; 6 | import com.intellij.notification.Notifications; 7 | import com.intellij.openapi.actionSystem.AnAction; 8 | import com.intellij.openapi.actionSystem.AnActionEvent; 9 | import com.intellij.openapi.actionSystem.CommonDataKeys; 10 | import com.intellij.openapi.fileEditor.FileEditorManager; 11 | import com.intellij.openapi.fileEditor.OpenFileDescriptor; 12 | import com.intellij.openapi.project.Project; 13 | import com.intellij.openapi.ui.DialogWrapper; 14 | import com.intellij.openapi.ui.ValidationInfo; 15 | import com.intellij.openapi.vfs.LocalFileSystem; 16 | import com.intellij.openapi.vfs.VirtualFile; 17 | import com.intellij.tools.ToolsBundle; 18 | import com.shuzijun.plantumlparser.core.ParserConfig; 19 | import com.shuzijun.plantumlparser.core.ParserProgram; 20 | import com.shuzijun.plantumlparser.plugin.utils.MTAUtils; 21 | import com.shuzijun.plantumlparser.plugin.utils.PropertiesUtils; 22 | import com.shuzijun.plantumlparser.plugin.window.ParserConfigPanel; 23 | import org.jetbrains.annotations.NotNull; 24 | import org.jetbrains.annotations.Nullable; 25 | 26 | import javax.swing.*; 27 | import java.awt.event.ActionEvent; 28 | import java.io.File; 29 | import java.io.IOException; 30 | 31 | /** 32 | * 解析动作 33 | * 34 | * @author shuzijun 35 | */ 36 | public class ParserProgramAction extends AnAction { 37 | @Override 38 | public void actionPerformed(@NotNull AnActionEvent e) { 39 | MTAUtils.click(e.getActionManager().getId(this)); 40 | ParserConfig parserConfig = new ParserConfig(); 41 | VirtualFile[] virtualFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY); 42 | for (VirtualFile virtualFile : virtualFiles) { 43 | parserConfig.addFilePath(virtualFile.getPath()); 44 | } 45 | if (parserConfig.getFilePaths().isEmpty()) { 46 | Notifications.Bus.notify(new Notification("plantuml-parser", "", PropertiesUtils.getInfo("select.empty"), NotificationType.WARNING), e.getProject()); 47 | return; 48 | } 49 | ParserConfigDialog parserConfigDialog = new ParserConfigDialog(e.getProject(), parserConfig); 50 | if (parserConfigDialog.showAndGet()) { 51 | try { 52 | parserConfig = parserConfigDialog.getParserConfig(); 53 | }catch (NullPointerException nullPointerException){ 54 | Notifications.Bus.notify(new Notification("plantuml-parser", "", nullPointerException.getMessage(), NotificationType.ERROR), e.getProject()); 55 | throw nullPointerException; 56 | } 57 | ParserProgram parserProgram = new ParserProgram(parserConfig); 58 | try { 59 | parserProgram.execute(); 60 | Notifications.Bus.notify(new Notification("plantuml-parser", "", PropertiesUtils.getInfo("success", parserConfig.getOutFilePath()), NotificationType.INFORMATION), e.getProject()); 61 | VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(parserConfig.getOutFilePath())); 62 | OpenFileDescriptor descriptor = new OpenFileDescriptor(e.getProject(), vf); 63 | FileEditorManager.getInstance(e.getProject()).openTextEditor(descriptor, false); 64 | } catch (NullPointerException n) { 65 | Notifications.Bus.notify(new Notification("plantuml-parser", "", n.getMessage(), NotificationType.WARNING), e.getProject()); 66 | } catch (IOException ioException) { 67 | Notifications.Bus.notify(new Notification("plantuml-parser", "", PropertiesUtils.getInfo("io.exception", ioException.getMessage()), NotificationType.WARNING), e.getProject()); 68 | } 69 | } 70 | 71 | } 72 | 73 | class ParserConfigDialog extends DialogWrapper { 74 | 75 | private ParserConfigPanel parserConfigPanel; 76 | 77 | private ParserConfig parserConfig; 78 | 79 | private Project project; 80 | 81 | public ParserConfigDialog(@Nullable Project project, ParserConfig parserConfig) { 82 | super(project, true); 83 | parserConfigPanel = new ParserConfigPanel(project); 84 | this.parserConfig = parserConfig; 85 | this.project = project; 86 | setModal(true); 87 | init(); 88 | setTitle("ParserConfig"); 89 | } 90 | 91 | @Override 92 | protected @Nullable JComponent createCenterPanel() { 93 | return parserConfigPanel.getJpanel(); 94 | } 95 | 96 | @Override 97 | protected @NotNull Action getOKAction() { 98 | Action action = super.getOKAction(); 99 | action.putValue(Action.NAME, "generate"); 100 | return action; 101 | } 102 | 103 | @Override 104 | protected @NotNull Action getCancelAction() { 105 | return super.getCancelAction(); 106 | } 107 | 108 | @Override 109 | protected @NotNull Action getHelpAction() { 110 | Action action = new AbstractAction() { 111 | @Override 112 | public void actionPerformed(ActionEvent e) { 113 | BrowserUtil.browse("https://github.com/shuzijun/plantuml-parser"); 114 | } 115 | }; 116 | action.putValue(Action.NAME, "help"); 117 | return action; 118 | } 119 | 120 | @Override 121 | protected @Nullable ValidationInfo doValidate() { 122 | try { 123 | parserConfigPanel.getFilePath(); 124 | }catch (NullPointerException nullPointerException){ 125 | return new ValidationInfo(nullPointerException.getMessage(),null); 126 | } 127 | return null; 128 | } 129 | 130 | public ParserConfig getParserConfig() { 131 | parserConfig.setOutFilePath(parserConfigPanel.getFilePath()); 132 | parserConfigPanel.getField().forEach(s -> parserConfig.addFieldModifier(s)); 133 | parserConfigPanel.getMethod().forEach(s -> parserConfig.addMethodModifier(s)); 134 | parserConfig.setLanguageLevel(parserConfigPanel.getLanguageLevel()); 135 | parserConfig.setShowPackage(parserConfigPanel.getShowPackage()); 136 | parserConfig.setShowConstructors(parserConfigPanel.getConstructors()); 137 | parserConfig.setShowComment(parserConfigPanel.getShowComment()); 138 | parserConfig.setProject(this.project); 139 | parserConfigPanel.getExcludeClass().forEach(s -> parserConfig.addExcludeClassRegex(s)); 140 | return parserConfig; 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /plantuml-parser-plugin/src/main/java/com/shuzijun/plantumlparser/plugin/window/ParserConfigPanel.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 |
230 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /plantuml-parser-cli/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/KtClassVOidVisitor.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | 4 | import com.intellij.psi.PsiElement; 5 | import org.jetbrains.kotlin.lexer.KtTokens; 6 | import org.jetbrains.kotlin.psi.*; 7 | import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes; 8 | import org.jetbrains.kotlin.resolve.ImportPath; 9 | 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | public class KtClassVOidVisitor extends KtTreeVisitor implements MyVisitor { 15 | 16 | private final String packageName; 17 | 18 | private final ParserConfig parserConfig; 19 | 20 | public KtClassVOidVisitor(String packageName, ParserConfig parserConfig) { 21 | this.packageName = packageName; 22 | this.parserConfig = parserConfig; 23 | } 24 | 25 | 26 | @Override 27 | public Void visitClassOrObject(KtClassOrObject ktClass, PUml pUml) { 28 | 29 | if (!(pUml instanceof PUmlView)) { 30 | super.visitClassOrObject(ktClass, pUml); 31 | return null; 32 | } 33 | 34 | if (parserConfig.isExcludeClass(ktClass.getName())) { 35 | return null; 36 | } 37 | 38 | 39 | PUmlView pUmlView = (PUmlView) pUml; 40 | PUmlClass pUmlClass = createUmlClass(); 41 | 42 | pUmlClass.setClassName(ktClass.getName()); 43 | if (ktClass instanceof KtObjectDeclaration) { 44 | pUmlClass.setClassType("class"); 45 | } else { 46 | if (((KtClass) ktClass).isInterface()) { 47 | pUmlClass.setClassType("interface"); 48 | } else if (((KtClass) ktClass).isEnum()) { 49 | pUmlClass.setClassType("enum"); 50 | } else { 51 | if (ktClass.hasModifier(KtTokens.ABSTRACT_KEYWORD)) { 52 | pUmlClass.setClassType("abstract class"); 53 | } else { 54 | pUmlClass.setClassType("class"); 55 | } 56 | 57 | } 58 | } 59 | 60 | if (parserConfig.isShowComment()) { 61 | if (ktClass.getDocComment() != null) { 62 | pUmlClass.setClassComment(ktClass.getDocComment().getText()); 63 | } 64 | } 65 | 66 | if (ktClass.getPrimaryConstructor() != null) { 67 | ktClass.getPrimaryConstructor().accept(this, pUmlClass); 68 | } 69 | 70 | ktClass.getDeclarations().forEach(p -> { 71 | if (p instanceof KtProperty) { 72 | p.accept(this, pUmlClass); 73 | } else if (p instanceof KtConstructor) { 74 | p.accept(this, pUmlClass); 75 | } else if (p instanceof KtNamedFunction) { 76 | p.accept(this, pUmlClass); 77 | } else if (p instanceof KtEnumEntry) { 78 | p.accept(this, pUmlClass); 79 | } else if (p instanceof KtObjectDeclaration) { 80 | p.accept(this, pUml); 81 | } else if (p instanceof KtClassOrObject) { 82 | p.accept(this, pUml); 83 | } 84 | }); 85 | 86 | pUmlView.addPUmlClass(pUmlClass); 87 | 88 | 89 | PsiElement node = ktClass.getParent(); 90 | 91 | List importDeclarations = parseImport(node, pUmlClass, pUmlView); 92 | 93 | Map importMap = new HashMap<>(); 94 | if (importDeclarations != null) { 95 | for (KtImportDirective importDeclaration : importDeclarations) { 96 | ImportPath importPath = importDeclaration.getImportPath(); 97 | if (importPath.getAlias() != null) { 98 | importMap.put(importPath.getAlias().asString(), importPath.getFqName().toString()); 99 | } else if (importPath.getImportedName() != null) { 100 | importMap.put(importPath.getImportedName().asString(), importPath.getFqName().toString()); 101 | } 102 | 103 | } 104 | } 105 | 106 | List superClassEntries = ktClass.getSuperTypeListEntries(); 107 | for (KtSuperTypeListEntry superClassEntry : superClassEntries) { 108 | if (superClassEntry != null) { 109 | String sourceClassName = superClassEntry.getText(); 110 | if (superClassEntry.getTypeAsUserType() !=null) { 111 | sourceClassName = superClassEntry.getTypeAsUserType().getReferencedName(); 112 | } 113 | 114 | if (superClassEntry.getElementType() == KtStubElementTypes.SUPER_TYPE_ENTRY) { 115 | PUmlRelation pUmlRelation = new PUmlRelation(); 116 | pUmlRelation.setTarget(getPackageNamePrefix(pUmlClass.getPackageName()) + pUmlClass.getClassName()); 117 | if (importMap.containsKey(sourceClassName)) { 118 | if (parserConfig.isShowPackage()) { 119 | pUmlRelation.setSource(importMap.get(sourceClassName)); 120 | } else { 121 | pUmlRelation.setSource(sourceClassName); 122 | } 123 | } else { 124 | pUmlRelation.setSource(getPackageNamePrefix(pUmlClass.getPackageName()) + sourceClassName); 125 | } 126 | pUmlRelation.setRelation("<|.."); 127 | pUmlView.addPUmlRelation(pUmlRelation); 128 | } else if (superClassEntry.getElementType() == KtStubElementTypes.SUPER_TYPE_CALL_ENTRY) { 129 | PUmlRelation pUmlRelation = new PUmlRelation(); 130 | pUmlRelation.setTarget(getPackageNamePrefix(pUmlClass.getPackageName()) + pUmlClass.getClassName()); 131 | if (importMap.containsKey(sourceClassName)) { 132 | if (parserConfig.isShowPackage()) { 133 | pUmlRelation.setSource(importMap.get(sourceClassName)); 134 | } else { 135 | pUmlRelation.setSource(sourceClassName); 136 | } 137 | } else { 138 | pUmlRelation.setSource(getPackageNamePrefix(pUmlClass.getPackageName()) + sourceClassName); 139 | } 140 | pUmlRelation.setRelation("<|--"); 141 | pUmlView.addPUmlRelation(pUmlRelation); 142 | } 143 | 144 | } 145 | } 146 | return null; 147 | } 148 | 149 | @Override 150 | public Void visitProperty(KtProperty property, PUml pUml) { 151 | if (!(pUml instanceof PUmlClass)) { 152 | super.visitProperty(property, pUml); 153 | return null; 154 | } 155 | PUmlClass pUmlClass = (PUmlClass) pUml; 156 | PUmlField pUmlField = new PUmlField(); 157 | 158 | pUmlField.setVisibility(VisibilityUtils.toVisibility(property)); 159 | 160 | if (parserConfig.isFieldModifier(pUmlField.getVisibility())) { 161 | pUmlField.setType(getKtTypeReference(property.getTypeReference(), "")); 162 | pUmlField.setName(property.getName()); 163 | pUmlClass.addPUmlFieldList(pUmlField); 164 | } 165 | 166 | if (parserConfig.isShowComment()) { 167 | if (property.getDocComment() != null) { 168 | pUmlField.setComment(property.getDocComment().getText()); 169 | } 170 | } 171 | return null; 172 | } 173 | 174 | @Override 175 | public Void visitEnumEntry(KtEnumEntry enumEntry, PUml pUml) { 176 | 177 | if (!(pUml instanceof PUmlClass)) { 178 | super.visitEnumEntry(enumEntry, pUml); 179 | return null; 180 | } 181 | PUmlClass pUmlClass = (PUmlClass) pUml; 182 | PUmlField pUmlField = new PUmlField(); 183 | 184 | pUmlField.setVisibility(Constant.VisibilityPublic); 185 | 186 | if (parserConfig.isFieldModifier(pUmlField.getVisibility())) { 187 | pUmlField.setType(""); 188 | pUmlField.setName(enumEntry.getName()); 189 | pUmlClass.addPUmlFieldList(pUmlField); 190 | } 191 | 192 | if (parserConfig.isShowComment()) { 193 | if (enumEntry.getDocComment() != null) { 194 | pUmlField.setComment(enumEntry.getDocComment().getText()); 195 | } 196 | } 197 | return null; 198 | } 199 | 200 | private String getKtTypeReference(KtTypeReference reference, String defaultValue) { 201 | 202 | if (reference != null) { 203 | return reference.getText(); 204 | } 205 | 206 | return defaultValue; 207 | } 208 | 209 | public Void visitPrimaryConstructor(KtPrimaryConstructor constructor, PUml pUml) { 210 | return this.visitConstructor(constructor, pUml); 211 | } 212 | 213 | public Void visitSecondaryConstructor(KtSecondaryConstructor constructor, PUml pUml) { 214 | return this.visitConstructor(constructor, pUml); 215 | } 216 | 217 | public Void visitConstructor(KtConstructor constructor, PUml pUml) { 218 | if (!(pUml instanceof PUmlClass)) { 219 | return null; 220 | } 221 | if (!parserConfig.isShowConstructors()) { 222 | return null; 223 | } 224 | PUmlClass pUmlClass = (PUmlClass) pUml; 225 | PUmlMethod pUmlMethod = new PUmlMethod(); 226 | 227 | 228 | pUmlMethod.setVisibility(VisibilityUtils.toVisibility(constructor)); 229 | 230 | if (parserConfig.isMethodModifier(pUmlMethod.getVisibility())) { 231 | pUmlMethod.setReturnType("<>"); 232 | pUmlMethod.setName(constructor.getName()); 233 | 234 | for (Object parameter : constructor.getValueParameters()) { 235 | pUmlMethod.addParam(getKtTypeReference(((KtParameter) parameter).getTypeReference(), "")); 236 | } 237 | pUmlClass.addPUmlMethodList(pUmlMethod); 238 | } 239 | if (parserConfig.isShowComment()) { 240 | if (constructor.getDocComment() != null) { 241 | pUmlMethod.setComment(constructor.getDocComment().getText()); 242 | } 243 | } 244 | 245 | return null; 246 | } 247 | 248 | @Override 249 | public Void visitNamedFunction(KtNamedFunction function, PUml pUml) { 250 | if (!(pUml instanceof PUmlClass)) { 251 | super.visitNamedFunction(function, pUml); 252 | return null; 253 | } 254 | PUmlClass pUmlClass = (PUmlClass) pUml; 255 | 256 | PUmlMethod pUmlMethod = new PUmlMethod(); 257 | 258 | pUmlMethod.setVisibility(VisibilityUtils.toVisibility(function)); 259 | 260 | if (parserConfig.isMethodModifier(pUmlMethod.getVisibility())) { 261 | pUmlMethod.setReturnType(getKtTypeReference(function.getTypeReference(), "void")); 262 | pUmlMethod.setName(function.getName()); 263 | for (Object parameter : function.getValueParameters()) { 264 | pUmlMethod.addParam(getKtTypeReference(((KtParameter) parameter).getTypeReference(), "void")); 265 | } 266 | pUmlClass.addPUmlMethodList(pUmlMethod); 267 | } 268 | 269 | if (parserConfig.isShowComment()) { 270 | if (function.getDocComment() != null) { 271 | pUmlMethod.setComment(function.getDocComment().getText()); 272 | } 273 | } 274 | return null; 275 | } 276 | 277 | @Override 278 | public Void visitKtElement(KtElement element, PUml pUml) { 279 | super.visitKtElement(element, pUml); 280 | return null; 281 | } 282 | 283 | @Override 284 | public Void visitKtFile(KtFile file, PUml pUml) { 285 | super.visitKtFile(file, pUml); 286 | return null; 287 | } 288 | 289 | @Override 290 | public Void visitDeclaration(KtDeclaration dcl, PUml pUml) { 291 | super.visitDeclaration(dcl, pUml); 292 | return null; 293 | } 294 | 295 | private List parseImport(PsiElement node, PUmlClass pUmlClass, PUmlView pUmlView) { 296 | if (node instanceof KtFile) { 297 | return ((KtFile) node).getImportDirectives(); 298 | } else if (node != null) { 299 | if (node instanceof KtClassBody && node.getParent() instanceof KtClassOrObject) { 300 | pUmlClass.setClassName(((KtClassOrObject) node.getParent()).getName() + "$" + pUmlClass.getClassName()); 301 | 302 | PUmlRelation pUmlRelation = new PUmlRelation(); 303 | pUmlRelation.setTarget(getPackageNamePrefix(pUmlClass.getPackageName()) + pUmlClass.getClassName()); 304 | pUmlRelation.setSource(getPackageNamePrefix(pUmlClass.getPackageName()) + pUmlClass.getClassName().substring(0, pUmlClass.getClassName().lastIndexOf("$"))); 305 | pUmlRelation.setRelation("+.."); 306 | pUmlView.addPUmlRelation(pUmlRelation); 307 | } 308 | parseImport(node.getParent(), pUmlClass, pUmlView); 309 | } 310 | return null; 311 | } 312 | 313 | @Override 314 | public String getPackageName() { 315 | return packageName; 316 | } 317 | 318 | @Override 319 | public ParserConfig getParserConfig() { 320 | return parserConfig; 321 | } 322 | } 323 | -------------------------------------------------------------------------------- /plantuml-parser-core/src/main/java/com/shuzijun/plantumlparser/core/ClassVoidVisitor.java: -------------------------------------------------------------------------------- 1 | package com.shuzijun.plantumlparser.core; 2 | 3 | import com.github.javaparser.ast.*; 4 | import com.github.javaparser.ast.body.*; 5 | import com.github.javaparser.ast.type.ClassOrInterfaceType; 6 | import com.github.javaparser.ast.visitor.VoidVisitorAdapter; 7 | 8 | import java.util.EnumSet; 9 | import java.util.HashMap; 10 | import java.util.HashSet; 11 | import java.util.Map; 12 | import java.util.Set; 13 | 14 | /** 15 | * 类 16 | * 17 | * @author shuzijun 18 | */ 19 | public class ClassVoidVisitor extends VoidVisitorAdapter implements MyVisitor { 20 | 21 | private final String packageName; 22 | 23 | private final ParserConfig parserConfig; 24 | 25 | public ClassVoidVisitor(String packageName, ParserConfig parserConfig) { 26 | this.packageName = packageName; 27 | this.parserConfig = parserConfig; 28 | } 29 | 30 | @Override 31 | public void visit(ClassOrInterfaceDeclaration cORid, PUml pUml) { 32 | if (!(pUml instanceof PUmlView)) { 33 | super.visit(cORid, pUml); 34 | return; 35 | } 36 | if (parserConfig.isExcludeClass(cORid.getNameAsString())){ 37 | return; 38 | } 39 | PUmlView pUmlView = (PUmlView) pUml; 40 | PUmlClass pUmlClass = createUmlClass(); 41 | 42 | pUmlClass.setClassName(cORid.getNameAsString()); 43 | if (cORid.isInterface()) { 44 | pUmlClass.setClassType("interface"); 45 | } else { 46 | pUmlClass.setClassType("class"); 47 | for (Modifier modifier : cORid.getModifiers()) { 48 | if (modifier.toString().trim().contains("abstract")) { 49 | pUmlClass.setClassType("abstract class"); 50 | break; 51 | } 52 | } 53 | } 54 | 55 | if (parserConfig.isShowComment()) { 56 | cORid.getComment().ifPresent(comment -> { 57 | pUmlClass.setClassComment(comment.getContent()); 58 | }); 59 | } 60 | 61 | cORid.getFields().forEach(p -> p.accept(this, pUmlClass)); 62 | 63 | if (cORid.getConstructors().isEmpty() && parserConfig.isShowDefaultConstructors()) { 64 | ConstructorDeclaration defaultConstructor = new ConstructorDeclaration(cORid.getNameAsString()); 65 | defaultConstructor.accept(this, pUmlClass); 66 | } else { 67 | cORid.getConstructors().forEach(p -> p.accept(this, pUmlClass)); 68 | } 69 | 70 | cORid.getMethods().forEach(p -> p.accept(this, pUmlClass)); 71 | 72 | pUmlView.addPUmlClass(pUmlClass); 73 | 74 | Node node = cORid.getParentNode().get(); 75 | 76 | NodeList importDeclarations = parseImport(node, pUmlClass, pUmlView); 77 | 78 | Map importMap = new HashMap<>(); 79 | if (importDeclarations != null) { 80 | for (ImportDeclaration importDeclaration : importDeclarations) { 81 | importMap.put(importDeclaration.getName().getIdentifier(), importDeclaration.getName().toString()); 82 | } 83 | } 84 | if (cORid.getImplementedTypes().size() != 0) { 85 | for (ClassOrInterfaceType implementedType : cORid.getImplementedTypes()) { 86 | PUmlRelation pUmlRelation = new PUmlRelation(); 87 | pUmlRelation.setTarget(getPackageNamePrefix(pUmlClass.getPackageName()) + pUmlClass.getClassName()); 88 | if (importMap.containsKey(implementedType.getNameAsString())) { 89 | if (parserConfig.isShowPackage()) { 90 | pUmlRelation.setSource(importMap.get(implementedType.getNameAsString())); 91 | } else { 92 | pUmlRelation.setSource(implementedType.getNameAsString()); 93 | } 94 | } else { 95 | pUmlRelation.setSource(getPackageNamePrefix(pUmlClass.getPackageName()) + implementedType.getNameAsString()); 96 | } 97 | pUmlRelation.setRelation("<|.."); 98 | pUmlView.addPUmlRelation(pUmlRelation); 99 | } 100 | } 101 | 102 | if (cORid.getExtendedTypes().size() != 0) { 103 | for (ClassOrInterfaceType extendedType : cORid.getExtendedTypes()) { 104 | PUmlRelation pUmlRelation = new PUmlRelation(); 105 | pUmlRelation.setTarget(getPackageNamePrefix(pUmlClass.getPackageName()) + pUmlClass.getClassName()); 106 | if (importMap.containsKey(extendedType.getNameAsString())) { 107 | if (parserConfig.isShowPackage()) { 108 | pUmlRelation.setSource(importMap.get(extendedType.getNameAsString())); 109 | } else { 110 | pUmlRelation.setSource(extendedType.getNameAsString()); 111 | } 112 | } else { 113 | pUmlRelation.setSource(getPackageNamePrefix(pUmlClass.getPackageName()) + extendedType.getNameAsString()); 114 | } 115 | pUmlRelation.setRelation("<|--"); 116 | pUmlView.addPUmlRelation(pUmlRelation); 117 | 118 | } 119 | } 120 | super.visit(cORid, pUml); 121 | } 122 | 123 | @Override 124 | public void visit(EnumDeclaration enumDeclaration, PUml pUml) { 125 | if (!(pUml instanceof PUmlView)) { 126 | super.visit(enumDeclaration, pUml); 127 | return; 128 | } 129 | PUmlView pUmlView = (PUmlView) pUml; 130 | PUmlClass pUmlClass = createUmlClass(); 131 | 132 | pUmlClass.setClassName(enumDeclaration.getNameAsString()); 133 | pUmlClass.setClassType("enum"); 134 | 135 | if (parserConfig.isShowComment()) { 136 | enumDeclaration.getComment().ifPresent(comment -> { 137 | pUmlClass.setClassComment(comment.getContent()); 138 | }); 139 | } 140 | 141 | enumDeclaration.getEntries().forEach(p -> p.accept(this, pUmlClass)); 142 | enumDeclaration.getFields().forEach(p -> p.accept(this, pUmlClass)); 143 | enumDeclaration.getConstructors().forEach(p -> p.accept(this, pUmlClass)); 144 | enumDeclaration.getMethods().forEach(p -> p.accept(this, pUmlClass)); 145 | 146 | pUmlView.addPUmlClass(pUmlClass); 147 | super.visit(enumDeclaration, pUml); 148 | } 149 | 150 | @Override 151 | public void visit(final RecordDeclaration recordDeclaration, PUml pUml) { 152 | if (!(pUml instanceof PUmlView)) { 153 | super.visit(recordDeclaration, pUml); 154 | return; 155 | } 156 | PUmlView pUmlView = (PUmlView) pUml; 157 | PUmlClass pUmlClass = createUmlClass(); 158 | 159 | pUmlClass.setClassName(recordDeclaration.getNameAsString()); 160 | pUmlClass.setClassType("class"); 161 | 162 | if (parserConfig.isShowComment()) { 163 | recordDeclaration.getComment().ifPresent(comment -> { 164 | pUmlClass.setClassComment(comment.getContent()); 165 | }); 166 | } 167 | 168 | // Create a constructor unless a default constructor was provided. 169 | boolean needsDefaultConstructor = recordDeclaration.getConstructors().stream().noneMatch(c -> 170 | c.getParameters().equals(recordDeclaration.getParameters())); 171 | if (needsDefaultConstructor) { 172 | // Visibility should be the same as for the class itself. 173 | NodeList modifiers = new NodeList<>(); 174 | for (Modifier modifier : recordDeclaration.getModifiers()) { 175 | if (VisibilityUtils.isVisibility(modifier.toString().trim())) { 176 | modifiers.add(modifier); 177 | break; 178 | } 179 | } 180 | ConstructorDeclaration c = new ConstructorDeclaration(modifiers, pUmlClass.getClassName()); 181 | c.setParameters(recordDeclaration.getParameters()); 182 | c.accept(this, pUmlClass); 183 | } 184 | 185 | // We need to convert the parameters to private final instance variables. 186 | Set parameters = new HashSet<>(); 187 | recordDeclaration.getParameters().forEach(p -> { 188 | parameters.add(p); 189 | NodeList modifiers = new NodeList<>(); 190 | modifiers.add(Modifier.privateModifier()); 191 | modifiers.add(Modifier.finalModifier()); 192 | FieldDeclaration field = new FieldDeclaration(modifiers, p.getType(), p.getName().asString()); 193 | field.accept(this, pUmlClass); 194 | }); 195 | 196 | // Add constructors and methods, removing parameters from set 197 | // if there are explicit getters. 198 | for (BodyDeclaration m: recordDeclaration.getMembers()) { 199 | if (m instanceof MethodDeclaration) { 200 | MethodDeclaration md = (MethodDeclaration) m; 201 | Parameter parm = new Parameter(md.getType(), md.getName()); 202 | parameters.remove(parm); 203 | } 204 | m.accept(this, pUmlClass); 205 | } 206 | // Add any getters that were not explicitly created. 207 | for (Parameter p : parameters) { 208 | MethodDeclaration md = new MethodDeclaration( 209 | new NodeList<>(Modifier.publicModifier()), p.getType(), p.getNameAsString()); 210 | md.accept(this, pUmlClass); 211 | } 212 | 213 | pUmlView.addPUmlClass(pUmlClass); 214 | Node node = recordDeclaration.getParentNode().get(); 215 | parseImport(node, pUmlClass, pUmlView); 216 | super.visit(recordDeclaration, pUml); 217 | } 218 | 219 | @Override 220 | public void visit(FieldDeclaration field, PUml pUml) { 221 | if (!(pUml instanceof PUmlClass)) { 222 | super.visit(field, pUml); 223 | return; 224 | } 225 | PUmlClass pUmlClass = (PUmlClass) pUml; 226 | PUmlField pUmlField = new PUmlField(); 227 | if (field.getModifiers().size() != 0) { 228 | for (Modifier modifier : field.getModifiers()) { 229 | if (VisibilityUtils.isVisibility(modifier.toString().trim())) { 230 | pUmlField.setVisibility(modifier.toString().trim()); 231 | break; 232 | } 233 | } 234 | } 235 | if (parserConfig.isFieldModifier(pUmlField.getVisibility())) { 236 | pUmlField.setStatic(field.isStatic()); 237 | pUmlField.setType(field.getVariables().getFirst().get().getTypeAsString()); 238 | pUmlField.setName(field.getVariables().getFirst().get().getNameAsString()); 239 | pUmlClass.addPUmlFieldList(pUmlField); 240 | } 241 | 242 | if (parserConfig.isShowComment()) { 243 | field.getComment().ifPresent(comment -> { 244 | pUmlField.setComment(comment.getContent()); 245 | }); 246 | } 247 | } 248 | 249 | 250 | @Override 251 | public void visit(ConstructorDeclaration constructor, PUml pUml) { 252 | if (!(pUml instanceof PUmlClass)) { 253 | super.visit(constructor, pUml); 254 | return; 255 | } 256 | if (!parserConfig.isShowConstructors()) { 257 | return; 258 | } 259 | PUmlClass pUmlClass = (PUmlClass) pUml; 260 | PUmlMethod pUmlMethod = new PUmlMethod(); 261 | if (constructor.getModifiers().size() != 0) { 262 | for (Modifier modifier : constructor.getModifiers()) { 263 | if (VisibilityUtils.isVisibility(modifier.toString().trim())) { 264 | pUmlMethod.setVisibility(modifier.toString().trim()); 265 | break; 266 | } 267 | } 268 | } 269 | if (parserConfig.isMethodModifier(pUmlMethod.getVisibility())) { 270 | pUmlMethod.setStatic(constructor.isStatic()); 271 | pUmlMethod.setAbstract(constructor.isAbstract()); 272 | pUmlMethod.setReturnType("<>"); 273 | pUmlMethod.setName(constructor.getNameAsString()); 274 | for (Parameter parameter : constructor.getParameters()) { 275 | pUmlMethod.addParam(parameter.getTypeAsString()); 276 | } 277 | pUmlClass.addPUmlMethodList(pUmlMethod); 278 | } 279 | if (parserConfig.isShowComment()) { 280 | constructor.getComment().ifPresent(comment -> { 281 | pUmlMethod.setComment(comment.getContent()); 282 | }); 283 | } 284 | } 285 | 286 | @Override 287 | public void visit(MethodDeclaration method, PUml pUml) { 288 | if (!(pUml instanceof PUmlClass)) { 289 | super.visit(method, pUml); 290 | return; 291 | } 292 | PUmlClass pUmlClass = (PUmlClass) pUml; 293 | 294 | PUmlMethod pUmlMethod = new PUmlMethod(); 295 | 296 | if (method.getModifiers().size() != 0) { 297 | for (Modifier modifier : method.getModifiers()) { 298 | if (VisibilityUtils.isVisibility(modifier.toString().trim())) { 299 | pUmlMethod.setVisibility(modifier.toString().trim()); 300 | break; 301 | } 302 | } 303 | } 304 | if (parserConfig.isMethodModifier(pUmlMethod.getVisibility())) { 305 | pUmlMethod.setStatic(method.isStatic()); 306 | pUmlMethod.setAbstract(method.isAbstract()); 307 | pUmlMethod.setReturnType(method.getTypeAsString()); 308 | pUmlMethod.setName(method.getNameAsString()); 309 | for (Parameter parameter : method.getParameters()) { 310 | pUmlMethod.addParam(parameter.getTypeAsString()); 311 | } 312 | pUmlClass.addPUmlMethodList(pUmlMethod); 313 | } 314 | 315 | if (parserConfig.isShowComment()) { 316 | method.getComment().ifPresent(comment -> { 317 | pUmlMethod.setComment(comment.getContent()); 318 | }); 319 | } 320 | } 321 | 322 | @Override 323 | public void visit(EnumConstantDeclaration enumConstantDeclaration, PUml pUml) { 324 | if (!(pUml instanceof PUmlClass)) { 325 | super.visit(enumConstantDeclaration, pUml); 326 | return; 327 | } 328 | PUmlClass pUmlClass = (PUmlClass) pUml; 329 | PUmlField pUmlField = new PUmlField(); 330 | 331 | pUmlField.setName(enumConstantDeclaration.getNameAsString()); 332 | pUmlField.setType(""); 333 | pUmlField.setVisibility("public"); 334 | pUmlClass.addPUmlFieldList(pUmlField); 335 | 336 | if (parserConfig.isShowComment()) { 337 | enumConstantDeclaration.getComment().ifPresent(comment -> { 338 | pUmlField.setComment(comment.getContent()); 339 | }); 340 | } 341 | } 342 | 343 | private NodeList parseImport(Node node, PUmlClass pUmlClass, PUmlView pUmlView) { 344 | if (node instanceof CompilationUnit) { 345 | return ((CompilationUnit) node).getImports(); 346 | } else if (node instanceof ClassOrInterfaceDeclaration || node instanceof RecordDeclaration) { 347 | pUmlClass.setClassName(((TypeDeclaration) node).getNameAsString() + "$" + pUmlClass.getClassName()); 348 | 349 | Node parentNode = node.getParentNode().get(); 350 | if (parentNode instanceof CompilationUnit) { 351 | PUmlRelation pUmlRelation = new PUmlRelation(); 352 | pUmlRelation.setTarget(getPackageNamePrefix(pUmlClass.getPackageName()) + pUmlClass.getClassName()); 353 | pUmlRelation.setSource(getPackageNamePrefix(pUmlClass.getPackageName()) + pUmlClass.getClassName().substring(0, pUmlClass.getClassName().lastIndexOf("$"))); 354 | pUmlRelation.setRelation("+.."); 355 | pUmlView.addPUmlRelation(pUmlRelation); 356 | } 357 | parseImport(parentNode, pUmlClass, pUmlView); 358 | } 359 | return null; 360 | } 361 | 362 | 363 | @Override 364 | public String getPackageName() { 365 | return packageName; 366 | } 367 | 368 | @Override 369 | public ParserConfig getParserConfig() { 370 | return parserConfig; 371 | } 372 | } 373 | --------------------------------------------------------------------------------