├── .gitignore
├── .idea
├── .gitignore
├── compiler.xml
├── gradle.xml
├── jarRepositories.xml
├── libraries-with-intellij-classes.xml
├── misc.xml
├── modules.xml
├── modules
│ ├── JavaStringFormat.main.iml
│ └── test
│ │ ├── com.122006.JavaStringFormat.test.main.iml
│ │ └── com.122006.JavaStringFormat.test.test.iml
├── uiDesigner.xml
└── vcs.xml
├── Build.md
├── LICENSE
├── README.md
├── base
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── sun
│ └── tools
│ └── javac
│ └── parser
│ ├── CompareSameMethod.java
│ ├── FStringFormatter.java
│ ├── Formatter.java
│ ├── Item.java
│ ├── ReflectionUtil.java
│ ├── SStringFormatter.java
│ ├── STRStringFormatter.java
│ ├── StringRange.java
│ ├── ZrConstants.java
│ ├── ZrStringModel.java
│ └── ZrUnSupportCodeError.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle_plugin
├── build.gradle
└── src
│ └── main
│ └── groovy
│ └── com
│ └── by122006
│ └── zircon
│ └── ZrPlugin.groovy
├── gradlew
├── gradlew.bat
├── ijplugin
├── README.md
├── build.gradle
├── build
│ └── distributions
│ │ ├── ijplugin-4.0.zip
│ │ ├── ijplugin-4.1.zip
│ │ └── ijplugin-4.2.zip
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── by122006
│ │ └── zircon
│ │ ├── ijplugin
│ │ ├── ZirconSettings.java
│ │ ├── ZrAnnotator.java
│ │ ├── ZrCheckLevelHighlightInfoHolder.java
│ │ ├── ZrCompletionContributor.java
│ │ ├── ZrDeReplaceAllAction.java
│ │ ├── ZrEnterInStringLiteralHandler.java
│ │ ├── ZrExMethodSettingsConfigurable.java
│ │ ├── ZrExMethodUsageProvider.java
│ │ ├── ZrFindUsagesHandlerFactory.java
│ │ ├── ZrFoldingBuilder.java
│ │ ├── ZrHighlightInfoFilter.java
│ │ ├── ZrHighlightVisitor.java
│ │ ├── ZrImportHelper.java
│ │ ├── ZrJavaCodeStyleManagerImpl.java
│ │ ├── ZrJavaFileHighlighter.java
│ │ ├── ZrJavaHighlightingLexer.java
│ │ ├── ZrJavaLexer.java
│ │ ├── ZrJavaParserDefinition.java
│ │ ├── ZrJavaQuoteHandler.java
│ │ ├── ZrJavacException.java
│ │ ├── ZrPsiAugmentProvider.java
│ │ ├── ZrPsiBuilderFactoryImpl.java
│ │ ├── ZrPsiExtensionMethod.java
│ │ ├── ZrPsiPolyadicExpressionImpl.java
│ │ ├── ZrReplaceAllAction.java
│ │ ├── ZrRootSettingsConfigurable.java
│ │ ├── ZrStartupActivity.java
│ │ ├── ZrStringLiteralInjector.java
│ │ ├── ZrStringLiteralTemplateUsageProvider.java
│ │ └── ZrStringSettingsConfigurable.java
│ │ └── util
│ │ ├── ReflectUtil.java
│ │ ├── ZrPluginUtil.java
│ │ └── ZrUtil.java
│ └── resources
│ └── META-INF
│ └── plugin.xml
├── inject_java11
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── sun
│ └── tools
│ └── javac
│ ├── comp
│ ├── ExMethodInfo.java
│ ├── NeedRedirectMethod.java
│ ├── NeedReplaceLambda.java
│ ├── ZrAttr.java
│ ├── ZrLookupHelper.java
│ ├── ZrLookupHelper2.java
│ ├── ZrMethodReferenceLookupHelper.java
│ └── ZrResolve.java
│ ├── parser
│ ├── ZrJavaTokenizer.java
│ └── ZrParserFactory.java
│ └── util
│ ├── ZrJavadocTokenizer.java
│ ├── ZrScanner.java
│ └── ZrScannerFactory.java
├── inject_java16
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── sun
│ └── tools
│ └── javac
│ ├── comp
│ ├── ExMethodInfo.java
│ ├── NeedRedirectMethod.java
│ ├── NeedReplaceLambda.java
│ ├── ZrAttr.java
│ ├── ZrLookupHelper.java
│ ├── ZrLookupHelper2.java
│ ├── ZrMethodReferenceLookupHelper.java
│ └── ZrResolve.java
│ ├── parser
│ ├── ZrJavaTokenizer.java
│ └── ZrParserFactory.java
│ └── util
│ ├── ZrJavadocTokenizer.java
│ ├── ZrScanner.java
│ └── ZrScannerFactory.java
├── inject_java7
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── sun
│ └── tools
│ └── javac
│ ├── comp
│ ├── ExMethodInfo.java
│ ├── NeedRedirectMethod.java
│ ├── NeedReplaceLambda.java
│ ├── ZrAttr.java
│ ├── ZrLookupHelper.java
│ ├── ZrLookupHelper2.java
│ ├── ZrMethodReferenceLookupHelper.java
│ ├── ZrResolve.java
│ └── ZrResolveEx.java
│ ├── parser
│ ├── ZrJavaTokenizer.java
│ └── ZrParserFactory.java
│ └── util
│ ├── ZrJavadocTokenizer.java
│ ├── ZrScanner.java
│ └── ZrScannerFactory.java
├── javac
├── build.gradle
├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
├── out
│ └── production
│ │ └── resources
│ │ └── clazz
│ │ ├── java11
│ │ ├── ZrAttr.clazz
│ │ ├── ZrJavaTokenizer$JavaCException.clazz
│ │ ├── ZrJavaTokenizer.clazz
│ │ ├── ZrJavadocTokenizer.clazz
│ │ ├── ZrParserFactory.clazz
│ │ ├── ZrResolve$ExMethodInfo.clazz
│ │ ├── ZrResolve$NeedRedirectMethod.clazz
│ │ ├── ZrResolve$NeedReplaceLambda.clazz
│ │ ├── ZrResolve$ZrLookupHelper.clazz
│ │ ├── ZrResolve$ZrLookupHelper2.clazz
│ │ ├── ZrResolve$ZrMethodReferenceLookupHelper.clazz
│ │ ├── ZrResolve.clazz
│ │ ├── ZrScanner.clazz
│ │ └── ZrScannerFactory.clazz
│ │ ├── java16
│ │ ├── ZrAttr.clazz
│ │ ├── ZrJavaTokenizer$JavaCException.clazz
│ │ ├── ZrJavaTokenizer.clazz
│ │ ├── ZrJavadocTokenizer.clazz
│ │ ├── ZrParserFactory.clazz
│ │ ├── ZrResolve$ExMethodInfo.clazz
│ │ ├── ZrResolve$NeedRedirectMethod.clazz
│ │ ├── ZrResolve$NeedReplaceLambda.clazz
│ │ ├── ZrResolve$ZrLookupHelper.clazz
│ │ ├── ZrResolve$ZrLookupHelper2.clazz
│ │ ├── ZrResolve$ZrMethodReferenceLookupHelper.clazz
│ │ ├── ZrResolve.clazz
│ │ ├── ZrScanner.clazz
│ │ └── ZrScannerFactory.clazz
│ │ └── java7
│ │ ├── ZrAttr.clazz
│ │ ├── ZrJavaTokenizer$JavaCException.clazz
│ │ ├── ZrJavaTokenizer.clazz
│ │ ├── ZrJavadocTokenizer.clazz
│ │ ├── ZrParserFactory.clazz
│ │ ├── ZrResolve$ExMethodInfo.clazz
│ │ ├── ZrResolve$NeedRedirectMethod.clazz
│ │ ├── ZrResolve$NeedReplaceLambda.clazz
│ │ ├── ZrResolve$ZrLookupHelper.clazz
│ │ ├── ZrResolve$ZrLookupHelper2.clazz
│ │ ├── ZrResolve$ZrMethodReferenceLookupHelper.clazz
│ │ ├── ZrResolve.clazz
│ │ ├── ZrResolveEx.clazz
│ │ ├── ZrScanner.clazz
│ │ └── ZrScannerFactory.clazz
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── by122006
│ │ └── zircon
│ │ ├── Parent.java
│ │ ├── ZirconExMethodPlugin.java
│ │ ├── ZirconPlugin.java
│ │ └── ZirconStringPlugin.java
│ └── resources
│ ├── META-INF
│ └── services
│ │ └── com.sun.source.util.Plugin
│ └── clazz
│ ├── java11
│ ├── ExMethodInfo.clazz
│ ├── NeedRedirectMethod.clazz
│ ├── NeedReplaceLambda.clazz
│ ├── ZrAttr.clazz
│ ├── ZrJavaTokenizer$JavaCException.clazz
│ ├── ZrJavaTokenizer.clazz
│ ├── ZrJavadocTokenizer.clazz
│ ├── ZrLookupHelper.clazz
│ ├── ZrLookupHelper2.clazz
│ ├── ZrMethodReferenceLookupHelper.clazz
│ ├── ZrParserFactory.clazz
│ ├── ZrResolve.clazz
│ ├── ZrScanner.clazz
│ └── ZrScannerFactory.clazz
│ ├── java16
│ ├── ExMethodInfo.clazz
│ ├── NeedRedirectMethod.clazz
│ ├── NeedReplaceLambda.clazz
│ ├── ZrAttr.clazz
│ ├── ZrJavaTokenizer$JavaCException.clazz
│ ├── ZrJavaTokenizer.clazz
│ ├── ZrJavadocTokenizer.clazz
│ ├── ZrLookupHelper.clazz
│ ├── ZrLookupHelper2.clazz
│ ├── ZrMethodReferenceLookupHelper.clazz
│ ├── ZrParserFactory.clazz
│ ├── ZrResolve.clazz
│ ├── ZrScanner.clazz
│ └── ZrScannerFactory.clazz
│ └── java7
│ ├── ExMethodInfo.clazz
│ ├── NeedRedirectMethod.clazz
│ ├── NeedReplaceLambda.clazz
│ ├── ZrAttr.clazz
│ ├── ZrJavaTokenizer$JavaCException.clazz
│ ├── ZrJavaTokenizer.clazz
│ ├── ZrJavadocTokenizer.clazz
│ ├── ZrLookupHelper.clazz
│ ├── ZrLookupHelper2.clazz
│ ├── ZrMethodReferenceLookupHelper.clazz
│ ├── ZrParserFactory.clazz
│ ├── ZrResolve.clazz
│ ├── ZrResolveEx.clazz
│ ├── ZrScanner.clazz
│ └── ZrScannerFactory.clazz
├── mds
├── README_ZrExMethod.md
├── README_ZrString.md
├── README_old.md
├── TODO
└── zhihu.md
├── others
├── exmethod_show.png
├── exmethod_show2.png
├── exmethod_show3.png
├── exmethod_show4.gif
├── zircon_show.png
└── zircon_show2.png
├── settings.gradle
├── test
├── build.gradle
├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
└── src
│ └── test
│ └── java
│ ├── RootExMethod.java
│ └── test
│ ├── NearExMethod.java
│ ├── TestClass2.java
│ ├── TestExMethod.java
│ ├── TestExMethodImpl.java
│ ├── TestImport.java
│ ├── TestNoEncounteredMethod.java
│ ├── TextStringFormat.java
│ ├── TextStringFormat2.java
│ ├── child
│ └── ChildExMethod.java
│ ├── extendsobj
│ ├── ChildChildObj.java
│ ├── ChildObj.java
│ └── FatherObj.java
│ └── filter
│ ├── FilterAnnotation.java
│ ├── TestFilterAnnotation1.java
│ └── TestFilterAnnotation2.java
├── tools
└── tools.jar
└── zircon
├── build.gradle
└── src
└── main
└── java
└── zircon
├── BiOp.java
├── ExMethod.java
└── ExMethodIDE.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Project exclude paths
2 | /.gradle/
3 | /.idea/
4 | /.intellijPlatform/
5 | /impl/build/
6 | /base/build/
7 | /javac/build/
8 | /test/build/
9 | /gradle_plugin/build/
10 | /inject_java16/build/
11 | /inject_java7/build/
12 | /inject_java11/build/
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /../../../../:\Java\JavaStringFormat\.idea/dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
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 |
55 |
56 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
25 |
26 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/libraries-with-intellij-classes.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/modules/JavaStringFormat.main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules/test/com.122006.JavaStringFormat.test.main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/modules/test/com.122006.JavaStringFormat.test.test.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Build.md:
--------------------------------------------------------------------------------
1 | ## 构建
2 |
3 | ### `gradle buildClazzByJava8`
4 |
5 | > 生成java7~10版本的clazz文件
6 |
7 | ### `gradle buildClazzByJava11`
8 |
9 | > 生成java16~15版本的clazz文件
10 |
11 | ### `gradle buildClazzByJava17`
12 |
13 | > 生成java16及以上版本的clazz文件
14 |
15 | ### `gradle buildClazzByAllJavaVersion`
16 |
17 | > 生成全部3个版本的clazz文件
18 |
19 | ## 测试
20 |
21 | ### `gradle testWithDiffJavaVersion`
22 |
23 | > 生成对应版本clazz文件,对test模块以指定java版本编译,并在对应java环境下运行test模块测试内容。
24 | > 可使用`-Ptjv=`指定版本号,默认java版本环境为java22
25 | > ### `gradle testWithDiffJavaVersion -Ptjv=8`
26 | > ### `gradle testWithDiffJavaVersion -Ptjv=11`
27 | > ### `gradle testWithDiffJavaVersion -Ptjv=17`
28 | > ### `gradle testWithDiffJavaVersion -Ptjv=21`
29 | > ### `gradle testWithDiffJavaVersion -Ptjv=22`
--------------------------------------------------------------------------------
/base/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'maven-publish'
4 | }
5 | repositories {
6 | maven { url 'https://maven.aliyun.com/repository/public/' }
7 | mavenCentral()
8 | }
9 | dependencies {
10 | compileOnly rootProject.fileTree(dir: 'tools', include: ['*.jar'])
11 | }
12 | compileJava {
13 | sourceCompatibility = JavaVersion.VERSION_1_8
14 | targetCompatibility = JavaVersion.VERSION_1_8
15 | options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore:symbol.file"
16 | }
17 |
18 | task sourceJar(type: Jar) {
19 | from sourceSets.main.allJava
20 | archiveClassifier = "sources"
21 | }
22 |
23 | publishing {
24 | publications {
25 | maven(MavenPublication) {
26 | groupId rootProject.ext.groupId
27 | artifactId "base"
28 | version rootProject.ext.version
29 | from components.java
30 | artifact sourceJar
31 | }
32 | }
33 | repositories {
34 | maven {
35 | url = uri('../../repo')
36 | }
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/base/src/main/java/com/sun/tools/javac/parser/CompareSameMethod.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 |
4 | public class CompareSameMethod {
5 | public static int compare(CompareEnv env, MethodInfo info1, MethodInfo info2) {
6 | final String[] methodOwnerClassNameInfo1 = info1.ownerClassName.split("\\.");
7 | final String[] methodOwnerClassNameInfo2 = info2.ownerClassName.split("\\.");
8 | String[] split = env.nowClassName.split("\\.");
9 | for (int i = 0; i < split.length; i++) {
10 | String s = split[i];
11 | final boolean equals1 = methodOwnerClassNameInfo1.length > i && methodOwnerClassNameInfo1[i].equals(s);
12 | final boolean equals2 = methodOwnerClassNameInfo2.length > i && methodOwnerClassNameInfo2[i].equals(s);
13 | if (equals1 && equals2) {
14 | continue;
15 | }
16 | if (equals1) return 1;
17 | if (equals2) return -1;
18 | }
19 | if (methodOwnerClassNameInfo1.length < methodOwnerClassNameInfo2.length) {
20 | return 1;
21 | }
22 | if (methodOwnerClassNameInfo1.length > methodOwnerClassNameInfo2.length) {
23 | return -1;
24 | }
25 | return 0;
26 | }
27 |
28 | public static class MethodInfo {
29 | String ownerClassName;
30 |
31 | public T method;
32 |
33 | public static MethodInfo create(String ownerClassName, T method) {
34 | final MethodInfo methodInfo = new MethodInfo<>();
35 | methodInfo.ownerClassName = ownerClassName;
36 | methodInfo.method = method;
37 | return methodInfo;
38 | }
39 | }
40 |
41 | public static class CompareEnv {
42 | String nowClassName;
43 |
44 | public static CompareEnv create(String nowClassName) {
45 | final CompareEnv env = new CompareEnv();
46 | env.nowClassName = nowClassName;
47 | return env;
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/base/src/main/java/com/sun/tools/javac/parser/Formatter.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 |
4 | import java.util.ArrayList;
5 | import java.util.Arrays;
6 | import java.util.List;
7 | import java.util.Objects;
8 | import java.util.stream.Collectors;
9 |
10 | public interface Formatter {
11 | // Logger logger = Logger.getLogger(Formatter.class.getSimpleName());
12 | List FORMATTERS = new ArrayList<>();
13 | List PREFIXES = new ArrayList<>();
14 |
15 | static List getAllFormattersClazz() {
16 | List clazzList = new ArrayList<>();
17 | clazzList.add("com.sun.tools.javac.parser.SStringFormatter");
18 | clazzList.add("com.sun.tools.javac.parser.FStringFormatter");
19 | if (!javaVersionUpper(21))
20 | clazzList.add("com.sun.tools.javac.parser.STRStringFormatter");
21 | return clazzList;
22 | }
23 |
24 | public static boolean javaVersionUpper(int versionCode) {
25 | final String version = System.getProperty("java.version");
26 | return Integer.parseInt(version.split("\\.")[0]) >= versionCode;
27 | }
28 |
29 | @SuppressWarnings("unchecked")
30 | static List getAllFormatters() {
31 | if (!FORMATTERS.isEmpty()) {
32 | return FORMATTERS;
33 | }
34 | List> classes = getAllFormattersClazz()
35 | .stream()
36 | .map(a -> {
37 | try {
38 | return (Class extends Formatter>) Class.forName(a);
39 | } catch (ClassNotFoundException e) {
40 | e.printStackTrace();
41 | return null;
42 | }
43 | }).filter(Objects::nonNull)
44 | .collect(Collectors.toList());
45 | List collect = classes.stream().map(a -> {
46 | try {
47 | return (Formatter) a.getConstructor().newInstance();
48 | } catch (Exception e) {
49 | e.printStackTrace();
50 | return null;
51 | }
52 | }).filter(Objects::nonNull).collect(Collectors.toList());
53 | FORMATTERS.addAll(collect);
54 | return collect;
55 | }
56 |
57 | static List getPrefixes() {
58 | if (!PREFIXES.isEmpty()) {
59 | return PREFIXES;
60 | }
61 | return getAllFormatters().stream().map(Formatter::prefix).collect(Collectors.toList());
62 | }
63 |
64 | public String prefix();
65 |
66 | public String printOut(List build, String text);
67 |
68 | public List- stringRange2Group(JavaTokenizer javaTokenizer, char[] buf, List build, String text, int groupStartIndex) throws Exception;
69 |
70 | ZrStringModel build(String text);
71 |
72 | String stringTransfer(String text);
73 |
74 | default String codeTransfer(String text) {
75 | // todo :这是一个测试,或许可以让字符串代码段格式完全按照非字符串内容格式?
76 | // if (text.matches( "^\".*|.*[^'\\\\]{1}\".*")) {
77 | // return text;
78 | // } else {
79 | // String toStr = text.replaceAll( "\\\\?([a-z0-9\"']{1})" , "$1")
80 | // .replace( "\\\\" , "\\");
81 | // return toStr;
82 | // }
83 | String toStr = text.replaceAll("\\\\?([a-z0-9\"']{1})", "$1")
84 | .replace("\\\\", "\\");
85 | return toStr;
86 | }
87 |
88 | default String codeTransfer(char[] buf, int groupStartIndex, String text, int startIndex, int endIndex) {
89 | String str = text.substring(startIndex, endIndex);
90 | String toStr = codeTransfer(str);
91 | int replaceCount = str.length() - toStr.length();
92 | if (!Objects.equals(str, toStr)) {
93 | // System.err.println( "替代后续文本 ${" + str + "}->${" + toStr + "}");
94 | System.arraycopy(toStr.toCharArray(), 0, buf, groupStartIndex + startIndex, toStr.length());
95 | char[] array = new char[replaceCount];
96 | Arrays.fill(array, ' ');
97 | System.arraycopy(array, 0, buf, groupStartIndex + startIndex + toStr.length(), replaceCount);
98 | }
99 | return toStr;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/base/src/main/java/com/sun/tools/javac/parser/ReflectionUtil.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 |
4 | import java.lang.reflect.Field;
5 |
6 | public class ReflectionUtil {
7 | public static void setDeclaredField(T t,Class super T> tClazz,String fieldName,Object object){
8 | try {
9 | Field declaredField = tClazz.getDeclaredField(fieldName);
10 | declaredField.setAccessible(true);
11 | declaredField.set(t,object);
12 | } catch (Exception e) {
13 | throw new RuntimeException(e);
14 | }
15 | }
16 | @SuppressWarnings("unchecked")
17 | public static M getDeclaredField(T t, Class super T> tClazz, String fieldName){
18 | try {
19 | Field declaredField = tClazz.getDeclaredField(fieldName);
20 | declaredField.setAccessible(true);
21 | return (M) declaredField.get(t);
22 | } catch (Exception e) {
23 | throw new RuntimeException(e);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/base/src/main/java/com/sun/tools/javac/parser/STRStringFormatter.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 | import java.util.List;
4 |
5 | public class STRStringFormatter extends SStringFormatter {
6 | @Override
7 | public String prefix() {
8 | return "STR." ;
9 | }
10 |
11 | @Override
12 | public ZrStringModel build(String text) {
13 | ZrStringModel model = new ZrStringModel();
14 | model.setFormatter(this);
15 | List list = model.getList();
16 | int startI = prefix().length() + 1;
17 | int selectModel = -1;
18 | int pCount = 0;
19 | for (int thisIndex = startI; thisIndex < text.length() - 1; thisIndex++) {
20 | char ch = text.charAt(thisIndex);
21 | if (text.charAt(thisIndex) != '{' &&text.charAt(thisIndex - 1) == '\\' && text.charAt(thisIndex - 2) != '\\') {
22 | continue;
23 | }
24 | if (selectModel == 2) {
25 | if (ch == '{') pCount++;
26 | if (ch == '}') {
27 | pCount--;
28 | if (pCount == 0) {
29 | if (thisIndex - startI > 0) {
30 | list.add(StringRange.code(this, text, startI, thisIndex));
31 | }
32 | startI = thisIndex + 1;
33 | selectModel = -1;
34 | }
35 | }
36 | continue;
37 | }
38 | if (ch == '\\' && !(text.charAt(thisIndex - 1) == '\\' && text.charAt(thisIndex - 2) == '\\')
39 | && String.valueOf(text.charAt(thisIndex + 1)).equals("{")) {
40 | if (thisIndex - startI != 0)
41 | list.add(StringRange.string(this, text, startI, thisIndex));
42 | if (text.charAt(thisIndex + 1) == '{') {
43 | startI = thisIndex + 2;
44 | selectModel = 2;
45 | pCount = 0;
46 | }
47 | }
48 | if (selectModel == -1) {
49 | if (ch == '"') {
50 | if (thisIndex > startI) {
51 | list.add(StringRange.string(this, text, startI, thisIndex));
52 | }
53 | model.setOriginalString(text.substring(0, thisIndex + 1));
54 | model.setEndQuoteIndex(thisIndex);
55 | return model;
56 | }
57 | }
58 | }
59 | if (text.length() - 1 > startI) {
60 | if (selectModel > 0) {
61 | list.add(StringRange.code(this, text, startI, text.length() - 1));
62 | } else {
63 | list.add(StringRange.string(this, text, startI, text.length() - 1));
64 | }
65 | }
66 | model.setOriginalString(text);
67 | model.setEndQuoteIndex(text.length() - 1);
68 | return model;
69 | }
70 |
71 | @Override
72 | public String stringTransfer(String str) {
73 | return str;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/base/src/main/java/com/sun/tools/javac/parser/StringRange.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 | public class StringRange {
4 | public static StringRange of(int codeStyle, int startIndex, int endIndex) {
5 | StringRange stringRange = new StringRange();
6 | stringRange.endIndex = endIndex;
7 | stringRange.codeStyle = codeStyle;
8 | stringRange.startIndex = startIndex;
9 | return stringRange;
10 | }
11 |
12 | public static StringRange code(Formatter formatter, String text, int startIndex, int endIndex) {
13 | StringRange stringRange = new StringRange();
14 | stringRange.endIndex = endIndex;
15 | stringRange.codeStyle = 1;
16 | stringRange.stringVal = formatter.codeTransfer(text.substring(startIndex, endIndex));
17 | stringRange.startIndex = startIndex;
18 | return stringRange;
19 | }
20 |
21 | public static StringRange string(Formatter formatter, String text, int startIndex, int endIndex) {
22 | StringRange stringRange = new StringRange();
23 | stringRange.endIndex = endIndex;
24 | stringRange.codeStyle = 0;
25 | stringRange.stringVal = formatter.stringTransfer(text.substring(startIndex, endIndex));
26 | stringRange.startIndex = startIndex;
27 | return stringRange;
28 | }
29 |
30 | /**
31 | * -1 ignore space
32 | * 0 hard String
33 | * 1 java code
34 | * 2 format info
35 | */
36 | public int codeStyle = -1;
37 | public int startIndex;
38 | public int endIndex;
39 |
40 | public String stringVal = null;
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/base/src/main/java/com/sun/tools/javac/parser/ZrConstants.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 |
7 | public class ZrConstants {
8 | public static List exMethodIgnorePackages = new ArrayList<>();
9 |
10 | static {
11 | final String zrExMethodIgnorePackages = System.getenv().get("zr_igp");
12 | if (zrExMethodIgnorePackages != null) {
13 | System.out.println("use env property [zr_igp]:" + zrExMethodIgnorePackages);
14 | exMethodIgnorePackages.addAll(Arrays.asList(zrExMethodIgnorePackages.split(",")));
15 | } else {
16 | exMethodIgnorePackages.addAll(Arrays.asList("org.graalvm.", "com.sun.", "org.springframework.", "org.apache.", "sun.", "jdk.", "org.junit.", "java.", "androidx.", "javax.", "org.junit.", "junit.", "kotlin."));
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/base/src/main/java/com/sun/tools/javac/parser/ZrStringModel.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Objects;
6 |
7 | public class ZrStringModel {
8 | List list= new ArrayList();
9 | Formatter formatter;
10 | String originalString;
11 | int endQuoteIndex=-1;
12 |
13 | public List getList() {
14 | return list;
15 | }
16 |
17 | public void setList(List list) {
18 | this.list = list;
19 | }
20 |
21 | public Formatter getFormatter() {
22 | return formatter;
23 | }
24 |
25 | public void setFormatter(Formatter formatter) {
26 | this.formatter = formatter;
27 | }
28 |
29 | public String getOriginalString() {
30 | return originalString;
31 | }
32 |
33 | public void setOriginalString(String originalString) {
34 | this.originalString = originalString;
35 | }
36 |
37 | public int getEndQuoteIndex() {
38 | return endQuoteIndex;
39 | }
40 |
41 | public void setEndQuoteIndex(int endQuoteIndex) {
42 | this.endQuoteIndex = endQuoteIndex;
43 | }
44 |
45 | @Override
46 | public boolean equals(Object o) {
47 | if (this == o) return true;
48 | if (o == null || getClass() != o.getClass()) return false;
49 |
50 | ZrStringModel that = (ZrStringModel) o;
51 |
52 | if (endQuoteIndex != that.endQuoteIndex) return false;
53 | if (!Objects.equals(list, that.list)) return false;
54 | if (!Objects.equals(formatter, that.formatter)) return false;
55 | return Objects.equals(originalString, that.originalString);
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | int result = list != null ? list.hashCode() : 0;
61 | result = 31 * result + (formatter != null ? formatter.hashCode() : 0);
62 | result = 31 * result + (originalString != null ? originalString.hashCode() : 0);
63 | result = 31 * result + endQuoteIndex;
64 | return result;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/base/src/main/java/com/sun/tools/javac/parser/ZrUnSupportCodeError.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 | import com.sun.tools.javac.tree.JCTree;
4 |
5 | public class ZrUnSupportCodeError extends RuntimeException {
6 | public ZrUnSupportCodeError(String message) {
7 | super(message );
8 | setStackTrace(new StackTraceElement[0]);
9 | }
10 | public ZrUnSupportCodeError(String message, JCTree tree) {
11 | super(message + ":\n" + tree.toString());
12 | setStackTrace(new StackTraceElement[0]);
13 | }
14 |
15 | public ZrUnSupportCodeError(String message, JCTree tree, String detail) {
16 | super(message + ":\n" + tree.toString() + (detail == null ? "" : detail));
17 | setStackTrace(new StackTraceElement[0]);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | version = "3.4"
3 | groupId = "com.github.122006.Zircon"
4 | }
5 |
6 | buildscript {
7 | repositories {
8 | maven {
9 | url uri('../repo')
10 | }
11 | maven {
12 | url 'https://maven.aliyun.com/repository/public/'
13 | }
14 | maven { url 'https://jitpack.io' }
15 | maven {
16 | url 'https://maven.aliyun.com/repository/spring/'
17 | }
18 | maven { url 'https://maven.aliyun.com/repository/jcenter/' }
19 | google()
20 | maven { url "https://s01.oss.sonatype.org/content/groups/public" }
21 | mavenCentral()
22 |
23 | }
24 | }
25 |
26 | repositories {
27 | maven { url 'https://maven.aliyun.com/repository/public/' }
28 | maven {
29 | url uri('../../repo')
30 | }
31 | maven { url 'https://jitpack.io' }
32 | mavenCentral()
33 | }
34 | ext {
35 | testJavaVersion = Integer.valueOf(project.getProperties().getOrDefault('tjv', 22))
36 | // gradle testWithDiffJavaVersion -Ptjv=21
37 | }
38 | if (System.getProperty("user.name", "") != "jitpack") {
39 | def allData = [
40 | [version: 8, project: ":inject_java7"]
41 | , [version: 11, project: ":inject_java11"]
42 | , [version: 17, project: ":inject_java16"]]
43 | def useJavaVersion = allData.collect {it-> it.get("version") }.findAll { it <= ext.testJavaVersion }.max { it }
44 |
45 | task testWithDiffJavaVersion {
46 | group "zircon"
47 | dependsOn "buildClazzByJava${useJavaVersion}", ":test:clean", ":test:compileTestJava"
48 | doLast {
49 | project(":test").test.executeTests()
50 | }
51 | }
52 |
53 | allData.forEach(data -> {
54 | task "cleanJava${data.version}Clazz"(type: Delete) {
55 | group "zircon"
56 | delete "javac/src/main/resources/clazz/" + data.project.split("_")[1]
57 | }
58 | task "buildClazzByJava${data.version}" {
59 | group "zircon"
60 | dependsOn "${data.project}:clean", "${data.project}:compileJava", "${data.project}:copyJavacClass"
61 | }
62 | tasks.findByPath("${data.project}:copyJavacClass").dependsOn("${data.project}:clean", "${data.project}:compileJava")
63 | tasks.findByPath(":javac:processResources").mustRunAfter(allData.collect { "${it.project}:copyJavacClass" })
64 | })
65 |
66 |
67 |
68 | task cleanAllClazz(type: Delete) {
69 | group "zircon"
70 | delete "javac/src/main/resources/clazz/"
71 | }
72 | task buildClazzByAllJavaVersion {
73 | group "zircon"
74 | dependsOn allData.collect { "buildClazzByJava${it.version}" }
75 | }
76 |
77 | cleanAllClazz.mustRunAfter(buildClazzByAllJavaVersion)
78 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Sun Feb 05 09:34:32 CST 2017
16 | #systemProp.http.proxyHost=127.0.0.1
17 | #systemProp.http.proxyPort=1080
18 | android.injected.studio.version.check=false
19 |
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.7-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradle_plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'java-gradle-plugin'
3 | apply plugin: 'maven-publish'
4 |
5 | dependencies {
6 | compileOnly gradleApi()
7 | }
8 | gradlePlugin {
9 | plugins {
10 | zircon {
11 | id = 'zircon'
12 | implementationClass = 'com.by122006.zircon.ZrPlugin'
13 | }
14 | ZrString {
15 | id = 'ZrString'
16 | implementationClass = 'com.by122006.zircon.ZrPlugin'
17 | }
18 | }
19 | }
20 | java {
21 | toolchain {
22 | languageVersion = JavaLanguageVersion.of(8)
23 | }
24 | }
25 | compileJava {
26 | sourceCompatibility = JavaVersion.VERSION_1_8
27 | targetCompatibility = JavaVersion.VERSION_1_8
28 | options.compilerArgs << "-Xlint:deprecation" << "-XDignore:symbol.file"
29 | }
30 | publishing {
31 | publications {
32 | maven(MavenPublication) {
33 | groupId rootProject.ext.groupId
34 | artifactId "gradle"
35 | version rootProject.ext.version
36 | from components.java
37 | }
38 | }
39 | repositories {
40 | maven {
41 | url = uri('../../repo')
42 | }
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/gradle_plugin/src/main/groovy/com/by122006/zircon/ZrPlugin.groovy:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon
2 |
3 | import org.gradle.api.Plugin
4 | import org.gradle.api.Project
5 | import org.gradle.api.tasks.compile.JavaCompile
6 |
7 |
8 | class ZrPlugin implements Plugin {
9 | void apply(Project project) {
10 | project.tasks.withType(JavaCompile) { JavaCompile it ->
11 | if (!project.hasProperty("zircon_ex_method") || project.zircon_ex_method) it.options.compilerArgs << "-Xplugin:ZrExMethod"
12 | if (!project.hasProperty("zircon_temp_string") || project.zircon_temp_string) it.options.compilerArgs << "-Xplugin:ZrString"
13 | if (Integer.parseInt(System.getProperty("java.version").split("\\.")[0]) >= 9) {
14 | it.options.forkOptions.jvmArgs << "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" << "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" << "--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED" << "--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED" << "--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"
15 | it.options.fork = true
16 | }
17 | }
18 | var version = project.hasProperty("zircon_version") ? project.zircon_version : "3.2.6";
19 | project.dependencies.add("annotationProcessor"
20 | , project.dependencies.create("com.github.122006.Zircon:javac:" + version))
21 | project.dependencies.add("implementation"
22 | , project.dependencies.create("com.github.122006.Zircon:zircon:" + version))
23 | try {
24 | project.dependencies.add("androidTestImplementation"
25 | , project.dependencies.create("com.github.122006.Zircon:javac:" + version))
26 | } catch (ignored) {
27 |
28 | }
29 | try {
30 | project.dependencies.add("testAnnotationProcessor"
31 | , project.dependencies.create("com.github.122006.Zircon:javac:" + version))
32 | } catch (ignored) {
33 |
34 | }
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/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 init
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 init
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 | :init
68 | @rem Get command-line arguments, handling Windows variants
69 |
70 | if not "%OS%" == "Windows_NT" goto win9xME_args
71 |
72 | :win9xME_args
73 | @rem Slurp the command line arguments.
74 | set CMD_LINE_ARGS=
75 | set _SKIP=2
76 |
77 | :win9xME_args_slurp
78 | if "x%~1" == "x" goto execute
79 |
80 | set CMD_LINE_ARGS=%*
81 |
82 | :execute
83 | @rem Setup the command line
84 |
85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
86 |
87 |
88 | @rem Execute Gradle
89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
90 |
91 | :end
92 | @rem End local scope for the variables with windows NT shell
93 | if "%ERRORLEVEL%"=="0" goto mainEnd
94 |
95 | :fail
96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
97 | rem the _cmd.exe /c_ return code!
98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
99 | exit /b 1
100 |
101 | :mainEnd
102 | if "%OS%"=="Windows_NT" endlocal
103 |
104 | :omega
105 |
--------------------------------------------------------------------------------
/ijplugin/README.md:
--------------------------------------------------------------------------------
1 | ## 插件编译说明
2 |
3 | 设置Gradle jvm 运行版本为jdk11,ijplugin模块下buildPlugin进行打包,
4 |
5 | 打包成功插件文件位置 [ijplugin.zip](ijplugin/build/distributions/)
6 |
--------------------------------------------------------------------------------
/ijplugin/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'org.jetbrains.intellij.platform' version '2.2.1'
4 | }
5 |
6 | group 'com.by122006.zircon'
7 | version '4.2'
8 |
9 | compileJava {
10 | sourceCompatibility = JavaVersion.VERSION_11
11 | targetCompatibility = JavaVersion.VERSION_11
12 | }
13 |
14 | java {
15 | toolchain {
16 | languageVersion = JavaLanguageVersion.of(17)
17 | }
18 | }
19 | buildPlugin {
20 | buildSearchableOptions.enabled = false
21 | }
22 |
23 | repositories {
24 | maven {
25 | url uri('../../repo')
26 | }
27 | intellijPlatform {
28 | defaultRepositories()
29 | }
30 | maven { url 'https://jitpack.io' }
31 | maven { url 'https://maven.aliyun.com/repository/public/' }
32 | mavenCentral()
33 |
34 | }
35 | patchPluginXml {
36 | sinceBuild = "212.*"
37 | untilBuild = "251.*"
38 | }
39 | dependencies {
40 | // annotationProcessor 'com.github.122006.zircon:javac:3.2.3'
41 | implementation project(":base")
42 | implementation project(":javac")
43 | intellijPlatform {
44 | intellijIdeaCommunity '2024.1'
45 | // intellijIdeaCommunity '251.21418.62'
46 | bundledPlugin 'com.intellij.java'
47 | instrumentationTools()
48 | }
49 | implementation('com.github.122006:ExMethodUtil:1.1.7') {
50 | exclude group: 'com.github.122006.zircon', module: 'zircon'
51 | }
52 | implementation project(":zircon")
53 | }
54 | tasks.findByPath(':ijplugin:runIde').dependsOn(':buildClazzByJava17')
55 | ////IU-202.7319.50
56 | //intellij {
57 | // plugins = ['java']
58 | // version = "2024.1"
59 | // type = "IC"
60 | //}
61 |
62 | tasks.withType(JavaCompile) {
63 | it.options.compilerArgs << "-Xplugin:ZrExMethod"
64 | it.options.compilerArgs << "-Xplugin:ZrString"
65 | it.options.fork = true
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/ijplugin/build/distributions/ijplugin-4.0.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/ijplugin/build/distributions/ijplugin-4.0.zip
--------------------------------------------------------------------------------
/ijplugin/build/distributions/ijplugin-4.1.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/ijplugin/build/distributions/ijplugin-4.1.zip
--------------------------------------------------------------------------------
/ijplugin/build/distributions/ijplugin-4.2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/ijplugin/build/distributions/ijplugin-4.2.zip
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZirconSettings.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.openapi.application.ApplicationManager;
4 | import com.intellij.openapi.components.PersistentStateComponent;
5 | import com.intellij.openapi.components.State;
6 | import com.intellij.openapi.components.Storage;
7 | import com.intellij.util.xmlb.XmlSerializerUtil;
8 |
9 | import org.jetbrains.annotations.NotNull;
10 | import org.jetbrains.annotations.Nullable;
11 |
12 | @State(
13 | name = "com.by122006.zircon",
14 | storages = @Storage("ZirconSettingsPlugin.xml")
15 | )
16 | public class ZirconSettings implements PersistentStateComponent {
17 |
18 | public boolean ZrStringFoldEnable = true;
19 |
20 | public int ZrStringFoldCharCount = 10;
21 | public boolean ZrMethodAllowUseStaticOnNoStaticMethod = true;
22 | public boolean ZrMethodAllowAutoFind = false;
23 |
24 | public boolean enableAll = true;
25 |
26 |
27 | public static ZirconSettings getInstance() {
28 | return ApplicationManager.getApplication().getService(ZirconSettings.class);
29 | }
30 |
31 | @Nullable
32 | @Override
33 | public ZirconSettings getState() {
34 | return this;
35 | }
36 |
37 | @Override
38 | public void loadState(@NotNull ZirconSettings state) {
39 | XmlSerializerUtil.copyBean(state, this);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrExMethodSettingsConfigurable.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.openapi.options.Configurable;
4 | import com.intellij.ui.components.JBCheckBox;
5 | import com.intellij.util.ui.FormBuilder;
6 |
7 | import org.jetbrains.annotations.Nls;
8 | import org.jetbrains.annotations.Nullable;
9 |
10 | import javax.swing.JComponent;
11 | import javax.swing.JPanel;
12 | import java.util.Objects;
13 |
14 | public class ZrExMethodSettingsConfigurable implements Configurable {
15 |
16 | private AppSettingsComponent mySettingsComponent;
17 |
18 | @Nls(capitalization = Nls.Capitalization.Title)
19 | @Override
20 | public String getDisplayName() {
21 | return "Extension Method";
22 | }
23 |
24 | @Override
25 | public JComponent getPreferredFocusedComponent() {
26 | return mySettingsComponent.getPreferredFocusedComponent();
27 | }
28 |
29 | @Nullable
30 | @Override
31 | public JComponent createComponent() {
32 | mySettingsComponent = new AppSettingsComponent();
33 | return mySettingsComponent.getPanel();
34 | }
35 |
36 | @Override
37 | public boolean isModified() {
38 | ZirconSettings settings = ZirconSettings.getInstance();
39 | boolean modified = !Objects.equals(mySettingsComponent.allowUseStaticOnNoStaticMethod.isSelected(), settings.ZrMethodAllowUseStaticOnNoStaticMethod);
40 | modified |= !Objects.equals(mySettingsComponent.allowZrMethodAllowAutoFind.isSelected(), settings.ZrMethodAllowAutoFind);
41 | return modified;
42 | }
43 |
44 | @Override
45 | public void apply() {
46 | ZirconSettings settings = ZirconSettings.getInstance();
47 | settings.ZrMethodAllowUseStaticOnNoStaticMethod = mySettingsComponent.allowUseStaticOnNoStaticMethod.isSelected();
48 | settings.ZrMethodAllowAutoFind = mySettingsComponent.allowZrMethodAllowAutoFind.isSelected();
49 |
50 | }
51 |
52 | @Override
53 | public void reset() {
54 | ZirconSettings settings = ZirconSettings.getInstance();
55 | mySettingsComponent.allowUseStaticOnNoStaticMethod.setSelected(settings.ZrMethodAllowUseStaticOnNoStaticMethod);
56 | mySettingsComponent.allowZrMethodAllowAutoFind.setSelected(settings.ZrMethodAllowAutoFind);
57 |
58 | }
59 |
60 | @Override
61 | public void disposeUIResources() {
62 | mySettingsComponent = null;
63 | }
64 |
65 | public static class AppSettingsComponent {
66 |
67 | private final JPanel myMainPanel;
68 | private final JBCheckBox allowUseStaticOnNoStaticMethod = new JBCheckBox("是否允许在实例上调用静态方法");
69 | private final JBCheckBox allowZrMethodAllowAutoFind = new JBCheckBox("快速自动注册拓展方法");
70 |
71 |
72 | public AppSettingsComponent() {
73 | myMainPanel = FormBuilder
74 | .createFormBuilder()
75 | .addComponent(allowUseStaticOnNoStaticMethod, 1)
76 | .addComponent(allowZrMethodAllowAutoFind, 1)
77 | .addComponentFillVertically(new JPanel(), 0)
78 | .getPanel();
79 | }
80 |
81 | public JPanel getPanel() {
82 | return myMainPanel;
83 | }
84 |
85 | public JComponent getPreferredFocusedComponent() {
86 | return myMainPanel;
87 | }
88 |
89 |
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrExMethodUsageProvider.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.by122006.zircon.util.ZrPluginUtil;
4 | import com.intellij.codeInsight.daemon.ImplicitUsageProvider;
5 | import com.intellij.lang.java.JavaLanguage;
6 | import com.intellij.openapi.progress.ProgressManager;
7 | import com.intellij.openapi.progress.util.ProgressIndicatorBase;
8 | import com.intellij.openapi.project.DumbService;
9 | import com.intellij.psi.*;
10 | import com.intellij.psi.search.LocalSearchScope;
11 | import com.intellij.psi.search.searches.ReferencesSearch;
12 | import com.intellij.psi.util.CachedValueProvider;
13 | import com.intellij.psi.util.CachedValuesManager;
14 | import org.jetbrains.annotations.NotNull;
15 | import zircon.ExMethod;
16 |
17 | public class ZrExMethodUsageProvider implements ImplicitUsageProvider {
18 | @Override
19 | public boolean isImplicitUsage(@NotNull PsiElement element) {
20 | if (!(element instanceof PsiMethod)) return false;
21 | final PsiAnnotation annotation = ((PsiMethod) element).getAnnotation(ExMethod.class.getName());
22 | return annotation != null;
23 | }
24 |
25 | @Override
26 | public boolean isImplicitRead(@NotNull PsiElement element) {
27 | return false;
28 | }
29 |
30 | @Override
31 | public boolean isImplicitWrite(@NotNull PsiElement element) {
32 | return false;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrFindUsagesHandlerFactory.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.find.findUsages.FindUsagesHandler;
4 | import com.intellij.find.findUsages.FindUsagesHandlerFactory;
5 | import com.intellij.openapi.module.Module;
6 | import com.intellij.openapi.module.ModuleUtilCore;
7 | import com.intellij.openapi.project.DumbService;
8 | import com.intellij.openapi.project.Project;
9 | import com.intellij.psi.*;
10 | import com.intellij.psi.augment.PsiExtensionMethod;
11 | import com.intellij.psi.impl.source.PsiClassReferenceType;
12 | import com.intellij.psi.search.GlobalSearchScope;
13 | import com.intellij.psi.util.PsiTypesUtil;
14 | import org.jetbrains.annotations.NotNull;
15 | import org.jetbrains.annotations.Nullable;
16 | import zircon.ExMethod;
17 | import zircon.example.ExCollection;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.Objects;
22 | import java.util.Optional;
23 | import java.util.stream.Collectors;
24 |
25 | public class ZrFindUsagesHandlerFactory extends FindUsagesHandlerFactory {
26 | @Override
27 | public boolean canFindUsages(@NotNull PsiElement element) {
28 | if (!(element instanceof PsiMethod)) return false;
29 | final PsiAnnotation annotation = ((PsiMethod) element).getAnnotation(ExMethod.class.getName());
30 | return annotation != null;
31 | }
32 |
33 | @Override
34 | public @Nullable FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {
35 | @Nullable Module module = ModuleUtilCore.findModuleForPsiElement(element.getContainingFile());
36 | if (module == null) return null;
37 | final GlobalSearchScope searchScope = module.getModuleWithDependenciesAndLibrariesScope(true);
38 | final Project project = element.getProject();
39 | final List psiMethods
40 | = ZrPsiAugmentProvider.getCachedAllMethod(element);
41 | return new FindUsagesHandler(element) {
42 | @NotNull
43 | public PsiElement[] getSecondaryElements() {
44 | try {
45 | final Optional first = psiMethods.stream().filter(a -> a.method.isEquivalentTo(element) )
46 | .findFirst();
47 | if (first.isEmpty()) return PsiElement.EMPTY_ARRAY;
48 | final ZrPsiAugmentProvider.CacheMethodInfo cacheMethodInfo = first.get();
49 | final List list = cacheMethodInfo.targetType.map(type -> {
50 | PsiClass psiClass;
51 | if (type instanceof PsiClassReferenceType) {
52 | final String qualifiedName = ((PsiClassReferenceType) type).getReference().getQualifiedName();
53 | final PsiClass[] classes = JavaPsiFacade.getInstance(project)
54 | .findClasses(qualifiedName, searchScope);
55 | psiClass = classes.length > 0 ? classes[0] : null;
56 | } else {
57 | psiClass = PsiTypesUtil.getPsiClass(type);
58 |
59 | }
60 | if (psiClass == null) return null;
61 | return ZrPsiAugmentProvider.buildMethodBy(cacheMethodInfo, psiClass, PsiTypesUtil.getClassType(psiClass));
62 | }).filterNoNull();
63 | return list.toArray(PsiElement.EMPTY_ARRAY);
64 | } catch (PsiInvalidElementAccessException e) {
65 | e.printStackTrace();
66 | return new PsiElement[0];
67 | }
68 | }
69 | };
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrFoldingBuilder.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.by122006.zircon.util.ZrPluginUtil;
4 | import com.by122006.zircon.util.ZrUtil;
5 | import com.intellij.lang.ASTNode;
6 | import com.intellij.lang.folding.FoldingBuilderEx;
7 | import com.intellij.lang.folding.FoldingDescriptor;
8 | import com.intellij.lang.java.JavaLanguage;
9 | import com.intellij.openapi.editor.Document;
10 | import com.intellij.openapi.util.TextRange;
11 | import com.intellij.psi.JavaRecursiveElementWalkingVisitor;
12 | import com.intellij.psi.JavaTokenType;
13 | import com.intellij.psi.PsiElement;
14 | import com.intellij.psi.PsiLiteralExpression;
15 | import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
16 | import com.sun.tools.javac.parser.FStringFormatter;
17 | import com.sun.tools.javac.parser.Formatter;
18 | import com.sun.tools.javac.parser.StringRange;
19 | import com.sun.tools.javac.parser.ZrStringModel;
20 | import org.jetbrains.annotations.NotNull;
21 | import org.jetbrains.annotations.Nullable;
22 | import zircon.example.ExCollection;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 | import java.util.Objects;
27 | import java.util.stream.Collectors;
28 |
29 | public class ZrFoldingBuilder extends FoldingBuilderEx {
30 | ZirconSettings settings = ZirconSettings.getInstance();
31 | @NotNull
32 | @Override
33 | public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
34 | if (!ZrPluginUtil.hasZrPlugin(root)) return FoldingDescriptor.EMPTY;
35 | if (root.getLanguage() != JavaLanguage.INSTANCE || quick) {
36 | return FoldingDescriptor.EMPTY;
37 | }
38 | if (!settings.ZrStringFoldEnable) return FoldingDescriptor.EMPTY;
39 | final List result = new ArrayList<>();
40 | root.accept(new JavaRecursiveElementWalkingVisitor() {
41 | @Override
42 | public void visitLiteralExpression(PsiLiteralExpression expression) {
43 | if (expression instanceof PsiLiteralExpressionImpl
44 | && ((PsiLiteralExpressionImpl) expression).getLiteralElementType() == JavaTokenType.STRING_LITERAL) {
45 | if (expression.getText().startsWith("\"")) return;
46 | String text = expression.getText();
47 | Formatter formatter = ZrUtil.checkPsiLiteralExpression(expression);
48 | if (formatter != null) {
49 | final ZrStringModel model = formatter.build(text);
50 | List build = model.getList();
51 | List collect = build.stream().filter(a -> a.codeStyle == 1)
52 | .map(a -> {
53 | TextRange textRange;
54 | int textOffset = expression.getTextOffset();
55 | if (text.charAt(a.startIndex - 1) == '$') {
56 | textRange = new TextRange(a.startIndex - 1 + textOffset, a.endIndex + textOffset);
57 | } else if (text.charAt(a.startIndex - 1) == '{') {
58 | textRange = new TextRange(a.startIndex - 2 + textOffset, a.endIndex + 1 + textOffset);
59 | } else if (formatter instanceof FStringFormatter) {
60 | int start = text.lastIndexOf("${", a.startIndex);
61 | textRange = new TextRange(start + textOffset, a.endIndex + 1 + textOffset);
62 | } else
63 | textRange = new TextRange(a.startIndex + textOffset, a.endIndex + textOffset);
64 | if (textRange.getLength() < settings.ZrStringFoldCharCount) return null;
65 | if (text.matches("[0-9A-Za-z_\\u4e00-\\u9fa5$]+(?:\\(\\))?")) return null;
66 | return new FoldingDescriptor(expression, textRange);
67 | }).filter(Objects::nonNull).collect(Collectors.toList());
68 | result.addAll(collect);
69 | }
70 | }
71 | super.visitLiteralExpression(expression);
72 | }
73 | });
74 | return result.toArray(FoldingDescriptor.EMPTY);
75 | }
76 |
77 |
78 | @Nullable
79 | public String getPlaceholderText(@NotNull ASTNode node, @NotNull TextRange range) {
80 | return "${...}";
81 | }
82 |
83 | @Override
84 | public @Nullable
85 | String getPlaceholderText(@NotNull ASTNode node) {
86 | return "...";
87 | }
88 |
89 | @Override
90 | public boolean isCollapsedByDefault(@NotNull ASTNode node) {
91 | return true;
92 | }
93 |
94 | @Override
95 | public boolean isCollapsedByDefault(@NotNull FoldingDescriptor foldingDescriptor) {
96 | return true;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrHighlightInfoFilter.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.by122006.zircon.util.ZrPluginUtil;
4 | import com.intellij.codeInsight.daemon.impl.HighlightInfo;
5 | import com.intellij.codeInsight.daemon.impl.HighlightInfoFilter;
6 | import com.intellij.java.analysis.JavaAnalysisBundle;
7 | import com.intellij.lang.java.JavaLanguage;
8 | import com.intellij.openapi.util.Key;
9 | import com.intellij.psi.*;
10 | import com.intellij.psi.util.PsiTreeUtil;
11 | import org.jetbrains.annotations.NotNull;
12 | import org.jetbrains.annotations.Nullable;
13 |
14 | import java.util.HashSet;
15 | import java.util.Objects;
16 | import java.util.Set;
17 |
18 | public class ZrHighlightInfoFilter implements HighlightInfoFilter {
19 | public static final Key> CACHE_IMPORT_EXMETHOD = Key.create("ZrHighlightInfoFilter_CACHE_IMPORT_EXMETHOD");
20 |
21 | @Override
22 | public boolean accept(@NotNull HighlightInfo highlightInfo, @Nullable PsiFile file) {
23 | if (file == null || file.getLanguage() != JavaLanguage.INSTANCE) return true;
24 | if (!ZrPluginUtil.hasZrPlugin(file)) return true;
25 | if (Objects.equals(highlightInfo.getDescription(), JavaAnalysisBundle.message("unused.import.statement"))) {
26 | final PsiElement elementAt = file.findElementAt(highlightInfo.getStartOffset());
27 | if (elementAt == null) return true;
28 | final PsiImportStatement importStatement = PsiTreeUtil.getParentOfType(elementAt, PsiImportStatement.class);
29 | if (importStatement==null) return true;
30 | final String qualifiedName = importStatement.getQualifiedName();
31 | Set cacheExMethodClasses;
32 | if ((file.getUserData(CACHE_IMPORT_EXMETHOD)) == null) {
33 | cacheExMethodClasses = new HashSet<>();
34 | file.putUserData(CACHE_IMPORT_EXMETHOD, cacheExMethodClasses);
35 | file.accept(new JavaRecursiveElementWalkingVisitor() {
36 | @Override
37 | public void visitMethodCallExpression(PsiMethodCallExpression expression) {
38 | super.visitMethodCallExpression(expression);
39 | final PsiElement resolve = expression.resolveMethod();
40 | if (resolve instanceof ZrPsiExtensionMethod) {
41 | final PsiClass containingClass = ((ZrPsiExtensionMethod) resolve).targetMethod.getContainingClass();
42 | if (containingClass==null)return;
43 | cacheExMethodClasses.add(containingClass.getQualifiedName());
44 | }
45 | }
46 |
47 | @Override
48 | public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
49 | super.visitMethodReferenceExpression(expression);
50 | final PsiElement resolve = expression.resolve();
51 | if (resolve instanceof ZrPsiExtensionMethod) {
52 | final PsiClass containingClass = ((ZrPsiExtensionMethod) resolve).targetMethod.getContainingClass();
53 | if (containingClass==null)return;
54 | cacheExMethodClasses.add(containingClass.getQualifiedName());
55 | }
56 | }
57 | });
58 | } else {
59 | cacheExMethodClasses = file.getUserData(CACHE_IMPORT_EXMETHOD);
60 | }
61 | return cacheExMethodClasses.contains(qualifiedName) ? false : true;
62 | }
63 | return true;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrJavaFileHighlighter.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.ide.highlighter.JavaFileHighlighter;
4 | import com.intellij.lexer.Lexer;
5 | import com.intellij.openapi.editor.HighlighterColors;
6 | import com.intellij.openapi.editor.colors.TextAttributesKey;
7 | import com.intellij.pom.java.LanguageLevel;
8 | import com.intellij.psi.JavaTokenType;
9 | import com.intellij.psi.tree.IElementType;
10 | import org.jetbrains.annotations.NotNull;
11 |
12 |
13 | public class ZrJavaFileHighlighter extends JavaFileHighlighter {
14 |
15 | public static final TextAttributesKey COMMENT = TextAttributesKey.createTextAttributesKey("SIMPLE_COMMENT", HighlighterColors.TEXT);
16 |
17 | public ZrJavaFileHighlighter() {
18 | this(LanguageLevel.HIGHEST);
19 | }
20 |
21 | public ZrJavaFileHighlighter(@NotNull LanguageLevel languageLevel) {
22 | super(languageLevel);
23 | }
24 |
25 | @NotNull
26 | @Override
27 | public Lexer getHighlightingLexer() {
28 | return new ZrJavaHighlightingLexer(this.myLanguageLevel);
29 | }
30 |
31 |
32 | @NotNull
33 | @Override
34 | public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
35 | if (tokenType.equals(JavaTokenType.STRING_LITERAL)) {
36 | return new TextAttributesKey[]{COMMENT};
37 | }
38 | return super.getTokenHighlights(tokenType);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrJavaHighlightingLexer.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.lexer.LayeredLexer;
4 | import com.intellij.lexer.StringLiteralLexer;
5 | import com.intellij.pom.java.LanguageLevel;
6 | import com.intellij.psi.JavaTokenType;
7 | import com.intellij.psi.tree.IElementType;
8 |
9 | public class ZrJavaHighlightingLexer extends LayeredLexer {
10 | public ZrJavaHighlightingLexer(LanguageLevel languageLevel) {
11 | super(ZrJavaParserDefinition.createLexer(languageLevel));
12 | // this.registerSelfStoppingLayer(new ZrStringLiteralLexer(JavaTokenType.STRING_LITERAL), new IElementType[]{JavaTokenType.STRING_LITERAL}, IElementType.EMPTY_ARRAY);
13 | this.registerSelfStoppingLayer(new StringLiteralLexer('"', JavaTokenType.STRING_LITERAL, false, ""), new IElementType[]{JavaTokenType.STRING_LITERAL}, IElementType.EMPTY_ARRAY);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrJavaParserDefinition.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.lang.injection.InjectedLanguageManager;
4 | import com.intellij.lang.java.JavaParserDefinition;
5 | import com.intellij.lexer.Lexer;
6 | import com.intellij.openapi.diagnostic.Logger;
7 | import com.intellij.openapi.project.Project;
8 | import com.intellij.openapi.roots.LanguageLevelProjectExtension;
9 | import com.intellij.pom.java.LanguageLevel;
10 | import org.jetbrains.annotations.NotNull;
11 | import org.jetbrains.annotations.Nullable;
12 |
13 | public class ZrJavaParserDefinition extends JavaParserDefinition {
14 | private static final Logger LOG = Logger.getInstance(ZrJavaParserDefinition.class.getName());
15 |
16 | public ZrJavaParserDefinition() {
17 | LOG.info( "ZrJavaParserDefinition" );
18 | }
19 |
20 | @NotNull
21 | @Override
22 | public Lexer createLexer(@Nullable Project project) {
23 | LanguageLevel level = project != null ? LanguageLevelProjectExtension.getInstance(project).getLanguageLevel() : LanguageLevel.HIGHEST;
24 | return createLexer(level);
25 | }
26 |
27 | @NotNull
28 | public static Lexer createLexer(@NotNull LanguageLevel level) {
29 | return new ZrJavaLexer(level);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrJavaQuoteHandler.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.codeInsight.editorActions.JavaQuoteHandler;
4 | import com.intellij.codeInsight.editorActions.QuoteHandler;
5 | import com.intellij.openapi.editor.Editor;
6 | import com.intellij.openapi.editor.highlighter.HighlighterIterator;
7 | import com.intellij.openapi.util.TextRange;
8 | import com.sun.tools.javac.parser.Formatter;
9 | import com.sun.tools.javac.parser.ZrStringModel;
10 |
11 | import java.util.Objects;
12 |
13 | public class ZrJavaQuoteHandler extends JavaQuoteHandler {
14 | @Override
15 | public boolean isInsideLiteral(HighlighterIterator iterator) {
16 | final boolean insideLiteral = super.isInsideLiteral(iterator);
17 | if (insideLiteral) {
18 | if (iterator.getDocument() == null) return true;
19 | final String text = iterator.getDocument().getText();
20 | int checkStart = iterator.getStart();
21 | int checkEndIndex = iterator.getStart();
22 | final CharSequence charsSequence = iterator.getDocument().getCharsSequence();
23 | while (charsSequence.charAt(checkStart) != '\n' && checkStart < charsSequence.length()) checkStart--;
24 | if (checkStart >= charsSequence.length()) return true;
25 | checkEndIndex = checkStart+1;
26 | while (charsSequence.charAt(checkEndIndex) != '\n' && checkEndIndex < charsSequence.length())
27 | checkEndIndex++;
28 | while (checkStart < checkEndIndex) {
29 | while (charsSequence.charAt(checkStart) != '"' && checkStart < checkEndIndex) checkStart++;
30 | if (checkStart == checkEndIndex) return true;
31 | int finalCheckStart = checkStart;
32 | final Formatter formatter = Formatter.getAllFormatters().stream()
33 | .filter(a -> Objects.equals(text.substring(finalCheckStart - a.prefix().length(), finalCheckStart), a.prefix()))
34 | .findFirst().orElse(null);
35 | if (formatter == null) return true;
36 | final ZrStringModel build = formatter.build(charsSequence.subSequence(checkStart, checkEndIndex).toString());
37 | if (build.getEndQuoteIndex()+1+checkStart >= iterator.getEnd()) return false;
38 | checkStart=build.getEndQuoteIndex()+1+checkStart;
39 | }
40 | return true;
41 | }
42 | return insideLiteral;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrJavacException.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | public class ZrJavacException {
4 | }
5 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrPsiBuilderFactoryImpl.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.lang.ASTNode;
4 | import com.intellij.lang.Language;
5 | import com.intellij.lang.ParserDefinition;
6 | import com.intellij.lang.PsiBuilder;
7 | import com.intellij.lang.impl.PsiBuilderFactoryImpl;
8 | import com.intellij.lang.impl.PsiBuilderImpl;
9 | import com.intellij.lang.java.lexer.JavaLexer;
10 | import com.intellij.lexer.Lexer;
11 | import com.intellij.openapi.progress.ProcessCanceledException;
12 | import com.intellij.openapi.project.Project;
13 | import com.intellij.openapi.roots.LanguageLevelProjectExtension;
14 | import com.intellij.pom.java.LanguageLevel;
15 |
16 | import org.jetbrains.annotations.NotNull;
17 | import org.jetbrains.annotations.Nullable;
18 |
19 | import zircon.example.ExReflection;
20 |
21 | public class ZrPsiBuilderFactoryImpl extends PsiBuilderFactoryImpl {
22 | @NotNull
23 | public PsiBuilder createBuilder(@NotNull Project project, @NotNull ASTNode chameleon, @Nullable Lexer lexer, @NotNull Language lang, @NotNull CharSequence seq) {
24 | ParserDefinition parserDefinition = reflectionInvokeMethod("getParserDefinition",lang, chameleon.getElementType());
25 | if (lexer instanceof JavaLexer) {
26 | LanguageLevel level = LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();
27 | lexer = new ZrJavaLexer(level);
28 | } else if (lexer == null) {
29 | try {
30 | lexer=parserDefinition.createLexer(project);
31 | } catch (ProcessCanceledException e) {
32 | throw e;
33 | } catch (Exception e) {
34 | e.printStackTrace();
35 | throw new RuntimeException("createLexer error:"+e.getMessage());
36 | }
37 | }
38 |
39 | return new PsiBuilderImpl(project, parserDefinition, lexer, chameleon, seq);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrPsiPolyadicExpressionImpl.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.openapi.diagnostic.Logger;
4 | import com.intellij.psi.PsiType;
5 | import com.intellij.psi.impl.source.tree.java.PsiPolyadicExpressionImpl;
6 | import com.intellij.psi.util.TypeConversionUtil;
7 |
8 | public class ZrPsiPolyadicExpressionImpl extends PsiPolyadicExpressionImpl {
9 | private static final Logger LOG = Logger.getInstance(ZrPsiPolyadicExpressionImpl.class.getName());
10 | public static final PsiType NoType = TypeConversionUtil.NULL_TYPE;
11 |
12 |
13 | // public PsiType getType() {
14 | // return JavaResolveCache.getInstance(getProject()).getType(this, OO_TYPE_EVALUATOR);
15 | // }
16 |
17 | // private static final Function OO_TYPE_EVALUATOR = new NullableFunction() {
18 | // @Override
19 | // public PsiType fun(PsiPolyadicExpressionImpl param) {
20 | // // copied from com.intellij.psi.impl.source.tree.java.PsiPolyadicExpressionImpl.doGetType
21 | // PsiExpression[] operands = param.getOperands();
22 | // PsiType lType = null;
23 | //
24 | // IElementType sign = param.getOperationTokenType();
25 | // for (int i=1; i psiMethods = ZrPsiAugmentProvider.freshCachedAllMethod(project);
36 | WriteCommandAction.runWriteCommandAction(project, () -> {
37 | for (ZrPsiAugmentProvider.CacheMethodInfo zrMethod : psiMethods) {
38 | if (zrMethod.cover || zrMethod.isStatic) continue;
39 | final Collection all = ReferencesSearch.search(zrMethod.method, ProjectScope.getProjectScope(project)).findAll();
40 | for (PsiReference reference : all) {
41 | if (!(reference instanceof PsiReferenceExpression)) {
42 | LOG.info("unknown reference type" + reference.getClass().getSimpleName() + " by method" + reference.resolve());
43 | continue;
44 | }
45 | final PsiElement parent = ((PsiReferenceExpressionImpl) reference).getParent();
46 | if (!(parent instanceof PsiMethodCallExpression)) {
47 | LOG.info("unknown reference parent type" + parent.getClass().getSimpleName() + " by method" + reference.resolve());
48 | continue;
49 | }
50 | final PsiMethodCallExpression element = (PsiMethodCallExpression) parent;
51 | PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
52 | final PsiExpression[] expressions = element.getArgumentList().getExpressions();
53 | final String collect = Arrays.stream(expressions)
54 | .map(PsiElement::getText).collect(Collectors.joining(","));
55 | LOG.info(collect);
56 | if (expressions.size() == 0) {
57 | continue;
58 | }
59 | final String skip1 = Arrays.stream(expressions)
60 | .map(PsiElement::getText).skip(1).collect(Collectors.joining(","));
61 | String s = expressions.get(0).getText() + "." + zrMethod.method.getName() + "(" + skip1 + ")";
62 | @NotNull PsiExpression codeBlockFromText = elementFactory.createExpressionFromText(s, element);
63 | element.replace(codeBlockFromText);
64 | // LOG.warn("will replace " + element.getText() + " to " + codeBlockFromText);
65 |
66 | }
67 | }
68 | });
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrRootSettingsConfigurable.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.openapi.options.Configurable;
4 | import com.intellij.ui.components.JBCheckBox;
5 | import com.intellij.util.ui.FormBuilder;
6 |
7 | import org.jetbrains.annotations.Nls;
8 | import org.jetbrains.annotations.Nullable;
9 |
10 | import java.util.Objects;
11 |
12 | import javax.swing.JComponent;
13 | import javax.swing.JPanel;
14 |
15 | public class ZrRootSettingsConfigurable implements Configurable {
16 |
17 | private AppSettingsComponent mySettingsComponent;
18 |
19 | @Nls(capitalization = Nls.Capitalization.Title)
20 | @Override
21 | public String getDisplayName() {
22 | return "Zircon";
23 | }
24 |
25 | @Override
26 | public JComponent getPreferredFocusedComponent() {
27 | return mySettingsComponent.getPreferredFocusedComponent();
28 | }
29 |
30 | @Nullable
31 | @Override
32 | public JComponent createComponent() {
33 | mySettingsComponent = new AppSettingsComponent();
34 | return mySettingsComponent.getPanel();
35 | }
36 |
37 | @Override
38 | public boolean isModified() {
39 | ZirconSettings settings = ZirconSettings.getInstance();
40 | boolean modified = !Objects.equals(mySettingsComponent.enableAll.isSelected(), settings.enableAll);
41 | return modified;
42 | }
43 |
44 | @Override
45 | public void apply() {
46 | ZirconSettings settings = ZirconSettings.getInstance();
47 | settings.enableAll = mySettingsComponent.enableAll.isSelected();
48 | }
49 |
50 | @Override
51 | public void reset() {
52 | ZirconSettings settings = ZirconSettings.getInstance();
53 | mySettingsComponent.enableAll.setSelected(settings.enableAll);
54 | }
55 |
56 | @Override
57 | public void disposeUIResources() {
58 | mySettingsComponent = null;
59 | }
60 |
61 | public static class AppSettingsComponent {
62 |
63 | private final JPanel myMainPanel;
64 |
65 | private final JBCheckBox enableAll = new JBCheckBox("插件启用 ");
66 |
67 | public AppSettingsComponent() {
68 | myMainPanel = FormBuilder.createFormBuilder()
69 | .addTooltip("已支持的语法特性:")
70 | .addTooltip("1. 全局拓展方法\n" + "自由拓展已有代码的实现方法。可以实现诸如顶级方法、方法替换等功能")
71 | .addTooltip("2. 内插模板字符串\n" + "字符串插值功能构建在复合格式设置功能的基础之上,提供更具有可读性、更方便的语法,用于将表达式结果包括到结果字符串。")
72 | .addComponent(enableAll)
73 | .addComponentFillVertically(new JPanel(), 0)
74 | .getPanel();
75 | }
76 |
77 | public JPanel getPanel() {
78 | return myMainPanel;
79 | }
80 |
81 | public JComponent getPreferredFocusedComponent() {
82 | return myMainPanel;
83 | }
84 |
85 |
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrStartupActivity.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.openapi.diagnostic.Logger;
4 | import com.intellij.openapi.project.Project;
5 | import com.intellij.openapi.startup.StartupActivity;
6 | import org.jetbrains.annotations.NotNull;
7 |
8 | public class ZrStartupActivity implements StartupActivity {
9 | private static final Logger LOG = Logger.getInstance("#" + ZrStartupActivity.class.getName());
10 |
11 | @Override
12 | public void runActivity(@NotNull Project project) {
13 | // Util.setJavaElementConstructor(JavaElementType.POLYADIC_EXPRESSION, ZrPsiPolyadicExpressionImpl::new);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrStringLiteralInjector.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.by122006.zircon.util.ZrPluginUtil;
4 | import com.intellij.lang.injection.InjectedLanguageManager;
5 | import com.intellij.lang.java.JavaLanguage;
6 | import com.intellij.openapi.diagnostic.Logger;
7 | import com.intellij.openapi.util.TextRange;
8 | import com.intellij.psi.InjectedLanguagePlaces;
9 | import com.intellij.psi.JavaTokenType;
10 | import com.intellij.psi.LanguageInjector;
11 | import com.intellij.psi.PsiImportList;
12 | import com.intellij.psi.PsiJavaFile;
13 | import com.intellij.psi.PsiLanguageInjectionHost;
14 | import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
15 | import com.sun.tools.javac.parser.Formatter;
16 | import com.sun.tools.javac.parser.StringRange;
17 | import com.sun.tools.javac.parser.ZrStringModel;
18 |
19 | import org.jetbrains.annotations.NotNull;
20 |
21 | import java.util.List;
22 |
23 | public class ZrStringLiteralInjector implements LanguageInjector {
24 | private static final Logger LOG = Logger.getInstance(ZrStringLiteralInjector.class.getName());
25 |
26 | @Override
27 | public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces places) {
28 | if (!ZrPluginUtil.hasZrPlugin(host)) return;
29 | if (!(host instanceof PsiLiteralExpressionImpl)) return;
30 | if (!(host.getLanguage().isKindOf(JavaLanguage.INSTANCE))) return;
31 | if (InjectedLanguageManager.getInstance(host.getProject()).isInjectedFragment(host.getContainingFile())) return;
32 | PsiLiteralExpressionImpl impl = (PsiLiteralExpressionImpl) host;
33 | if (!(impl.getLiteralElementType() == JavaTokenType.STRING_LITERAL)) return;
34 | String text = impl.getCanonicalText();
35 | if (text.startsWith("\"")) return;
36 | List allFormatters = Formatter.getAllFormatters();
37 | int endIndex = text.indexOf("\"");
38 | if (endIndex == -1) {
39 | LOG.error("字符串前缀无法识别");
40 | return;
41 | }
42 | String prefix = text.substring(0, endIndex);
43 | Formatter formatter = allFormatters.stream()
44 | .filter(a -> a.prefix().equals(prefix)).findFirst().orElse(null);
45 | if (formatter == null) {
46 | LOG.error("未识别的字符串前缀");
47 | return;
48 | }
49 | final ZrStringModel model = formatter.build(text);
50 | List build = model.getList();
51 | String printOut = formatter.printOut(build, text);
52 | if (printOut == null) return;
53 | final PsiJavaFile containingFile = (PsiJavaFile) impl.getContainingFile();
54 | final PsiImportList importList = containingFile.getImportList();
55 | String addText = "";
56 | addText += "package " + containingFile.getPackageName() + ";\n";
57 | if (importList != null) {
58 | addText += importList.getText();
59 | addText += "\n";
60 | }
61 | addText+="@SuppressWarnings(\"unused\") class __ZRStringObj {\n // " + printOut + "\n public Object _zr_obj_str = ";
62 | for (StringRange a : build) {
63 | if (a.codeStyle == 1) {
64 | if (a.startIndex != a.endIndex) {
65 | TextRange textRange = new TextRange(a.startIndex, a.endIndex);
66 | if (textRange.getLength() == 0) continue;
67 | // LOG.info("addPlace "+a.stringVal);
68 | places.addPlace(JavaLanguage.INSTANCE, textRange,
69 | addText, ";\n}");
70 |
71 | }
72 | }
73 | }
74 |
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrStringLiteralTemplateUsageProvider.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.by122006.zircon.util.ZrPluginUtil;
4 | import com.intellij.codeInsight.daemon.ImplicitUsageProvider;
5 | import com.intellij.lang.java.JavaLanguage;
6 | import com.intellij.openapi.progress.ProgressManager;
7 | import com.intellij.openapi.progress.util.ProgressIndicatorBase;
8 | import com.intellij.openapi.project.DumbService;
9 | import com.intellij.psi.*;
10 | import com.intellij.psi.search.LocalSearchScope;
11 | import com.intellij.psi.search.searches.ReferencesSearch;
12 | import com.intellij.psi.util.CachedValueProvider;
13 | import com.intellij.psi.util.CachedValuesManager;
14 | import org.jetbrains.annotations.NotNull;
15 |
16 | public class ZrStringLiteralTemplateUsageProvider implements ImplicitUsageProvider {
17 | @Override
18 | public boolean isImplicitUsage(@NotNull PsiElement element) {
19 | return checkReferencedFromZrStringLiteral(element);
20 | }
21 |
22 | @Override
23 | public boolean isImplicitRead(@NotNull PsiElement element) {
24 | return checkReferencedFromZrStringLiteral(element);
25 | }
26 |
27 | @Override
28 | public boolean isImplicitWrite(@NotNull PsiElement element) {
29 | return false;
30 | }
31 |
32 | private boolean checkReferencedFromZrStringLiteral(PsiElement elem) {
33 | if (DumbService.isDumb(elem.getProject())) return false;
34 | if (elem.getLanguage() != JavaLanguage.INSTANCE) return false;
35 | if (!ZrPluginUtil.hasZrPlugin(elem)) return false;
36 | PsiNamedElement namedElement = this.findNamedElement(elem);
37 | if (namedElement != null) {
38 | PsiFile containingFile = elem.getContainingFile();
39 | if (containingFile instanceof PsiJavaFile) {
40 | return CachedValuesManager.getCachedValue(elem, () -> {
41 | final Boolean aBoolean = ProgressManager.getInstance().runProcess(() -> {
42 | return !ReferencesSearch.search(namedElement, new LocalSearchScope(containingFile))
43 | .forEach((e) -> !this.isInStringLiteral(e.getElement()));
44 | }, new ProgressIndicatorBase());
45 | return CachedValueProvider.Result.create(aBoolean, elem);
46 | });
47 | }
48 | }
49 |
50 | return false;
51 | }
52 |
53 | private boolean isInStringLiteral(PsiElement element) {
54 | if (element == null) {
55 | return false;
56 | } else {
57 | return element instanceof PsiField && "_zr_obj_str".equals(((PsiField) element).getName()) || this.isInStringLiteral(element.getParent());
58 | }
59 | }
60 |
61 | private PsiNamedElement findNamedElement(PsiElement elem) {
62 | if (elem == null) {
63 | return null;
64 | } else {
65 | for (int offset = elem.getTextOffset(); elem != null && elem.getTextOffset() == offset && !(elem instanceof PsiNamedElement); elem = elem.getParent()) {
66 | }
67 | return (PsiNamedElement) elem;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/ijplugin/ZrStringSettingsConfigurable.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.ijplugin;
2 |
3 | import com.intellij.openapi.options.Configurable;
4 | import com.intellij.ui.JBIntSpinner;
5 | import com.intellij.ui.components.JBCheckBox;
6 | import com.intellij.ui.components.JBLabel;
7 | import com.intellij.util.ui.FormBuilder;
8 |
9 | import org.jetbrains.annotations.Nls;
10 | import org.jetbrains.annotations.Nullable;
11 |
12 | import java.util.Objects;
13 |
14 | import javax.swing.JComponent;
15 | import javax.swing.JPanel;
16 |
17 | public class ZrStringSettingsConfigurable implements Configurable {
18 | private AppSettingsComponent mySettingsComponent;
19 |
20 | @Nls(capitalization = Nls.Capitalization.Title)
21 | @Override
22 | public String getDisplayName() {
23 | return "Template String";
24 | }
25 |
26 | @Override
27 | public @Nullable JComponent getPreferredFocusedComponent() {
28 | return mySettingsComponent.getPreferredFocusedComponent();
29 | }
30 |
31 | @Nullable
32 | @Override
33 | public JComponent createComponent() {
34 | mySettingsComponent = new AppSettingsComponent();
35 | return mySettingsComponent.getPanel();
36 | }
37 |
38 | @Override
39 | public boolean isModified() {
40 | ZirconSettings settings = ZirconSettings.getInstance();
41 | boolean modified = !Objects.equals(mySettingsComponent.autoFoldJavaCodeLength.getNumber(), settings.ZrStringFoldCharCount);
42 | modified |= !Objects.equals(mySettingsComponent.autoFoldJavaCode.isSelected(), settings.ZrStringFoldEnable);
43 | return modified;
44 | }
45 |
46 | @Override
47 | public void apply() {
48 | ZirconSettings settings = ZirconSettings.getInstance();
49 | settings.ZrStringFoldCharCount = mySettingsComponent.autoFoldJavaCodeLength.getNumber();
50 | settings.ZrStringFoldEnable = mySettingsComponent.autoFoldJavaCode.isSelected();
51 | }
52 |
53 | @Override
54 | public void reset() {
55 | ZirconSettings settings = ZirconSettings.getInstance();
56 | mySettingsComponent.autoFoldJavaCodeLength.setNumber(settings.ZrStringFoldCharCount);
57 | mySettingsComponent.autoFoldJavaCode.setSelected(settings.ZrStringFoldEnable);
58 | mySettingsComponent.autoFoldJavaCodeLength.setEnabled(settings.ZrStringFoldEnable);
59 | }
60 |
61 | @Override
62 | public void disposeUIResources() {
63 | mySettingsComponent = null;
64 | }
65 |
66 | public static class AppSettingsComponent {
67 |
68 | private final JPanel myMainPanel;
69 | private final JBIntSpinner autoFoldJavaCodeLength = new JBIntSpinner(10, 0, 999);
70 | private final JBCheckBox autoFoldJavaCode = new JBCheckBox("应用自动收缩java代码? ");
71 |
72 | public AppSettingsComponent() {
73 | myMainPanel = FormBuilder
74 | .createFormBuilder()
75 | .addComponent(autoFoldJavaCode, 1)
76 | .addLabeledComponent(new JBLabel("代码收缩长度:"), autoFoldJavaCodeLength, 3)
77 | .addComponentFillVertically(new JPanel(), 0)
78 | .getPanel();
79 | autoFoldJavaCode.addActionListener(actionEvent -> autoFoldJavaCodeLength.setEnabled(autoFoldJavaCode.isSelected()));
80 | }
81 |
82 | public JPanel getPanel() {
83 | return myMainPanel;
84 | }
85 |
86 | public JComponent getPreferredFocusedComponent() {
87 | return autoFoldJavaCode;
88 | }
89 |
90 |
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/util/ReflectUtil.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.util;
2 |
3 | public class ReflectUtil {
4 | }
5 |
--------------------------------------------------------------------------------
/ijplugin/src/main/java/com/by122006/zircon/util/ZrUtil.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon.util;
2 |
3 | import com.intellij.lang.ASTNode;
4 | import com.intellij.psi.JavaTokenType;
5 | import com.intellij.psi.PsiElement;
6 | import com.intellij.psi.PsiJavaToken;
7 | import com.intellij.psi.PsiLiteralExpression;
8 | import com.sun.tools.javac.parser.Formatter;
9 | import org.jetbrains.annotations.NotNull;
10 |
11 | public class ZrUtil {
12 | public static Formatter checkPsiLiteralExpression(ASTNode psiElement) {
13 | if (psiElement == null) return null;
14 | final String text = psiElement.getText();
15 | return Formatter.getAllFormatters().stream()
16 | .filter(a -> text.startsWith(a.prefix() + "\"" ))
17 | .findFirst()
18 | .orElse(null);
19 | }
20 | public static Formatter checkPsiLiteralExpression(PsiLiteralExpression psiElement) {
21 | return checkPsiLiteralExpression(psiElement.getNode());
22 | }
23 |
24 | public static boolean isJavaStringLiteral(PsiElement psiElement){
25 | return psiElement instanceof PsiLiteralExpression
26 | && psiElement.getFirstChild() instanceof PsiJavaToken
27 | && ((PsiJavaToken) psiElement.getFirstChild()).getTokenType() == JavaTokenType.STRING_LITERAL;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/inject_java11/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'maven-publish'
4 | }
5 |
6 | repositories {
7 | maven { url 'https://maven.aliyun.com/repository/public/' }
8 | mavenCentral()
9 | maven {
10 | url uri('../../repo')
11 | }
12 | }
13 | dependencies {
14 | implementation project(":base")
15 | implementation project(":zircon")
16 | }
17 | java {
18 | toolchain {
19 | languageVersion = JavaLanguageVersion.of(11)
20 | }
21 | }
22 | compileJava {
23 | sourceCompatibility = JavaVersion.VERSION_1_8
24 | targetCompatibility = JavaVersion.VERSION_1_8
25 | options.fork = true;
26 | options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore:symbol.file"
27 |
28 |
29 | }
30 | task copyJavacClass(type: Copy) {
31 | from "${buildDir}/classes/java/main/com/sun/tools/javac/comp"
32 | from "${buildDir}/classes/java/main/com/sun/tools/javac/parser"
33 | from "${buildDir}/classes/java/main/com/sun/tools/javac/util"
34 | into "${rootDir}/javac/src/main/resources/clazz/java11"
35 | rename ~/(.*)\.class/, '$1.clazz'
36 | }
37 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/comp/ExMethodInfo.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 |
7 | import java.util.Objects;
8 |
9 | /**
10 | * @ClassName: ExMethodInfo
11 | * @Author: 122006
12 | * @Date: 2025/4/16 9:52
13 | * @Description:
14 | */
15 | public class ExMethodInfo {
16 | Symbol.MethodSymbol methodSymbol;
17 | boolean isStatic;
18 | boolean cover;
19 | List targetClass;
20 | List filterAnnotation;
21 | boolean siteCopyByClassHeadArgMethod = false;
22 |
23 | @Override
24 | public String toString() {
25 | return "ExMethodInfo{" +
26 | "methodSymbol=" + methodSymbol +
27 | ", isStatic=" + isStatic +
28 | ", cover=" + cover +
29 | ", targetClass=" + targetClass +
30 | ", filterAnnotation=" + filterAnnotation +
31 | ", siteCopyByClassHeadArgMethod=" + siteCopyByClassHeadArgMethod +
32 | '}';
33 | }
34 |
35 | public ExMethodInfo(Symbol.MethodSymbol methodSymbol, boolean isStatic, boolean cover, List targetClass, List filterAnnotation) {
36 | this.methodSymbol = methodSymbol;
37 | this.isStatic = isStatic;
38 | this.cover = cover;
39 | this.targetClass = targetClass;
40 | this.filterAnnotation = filterAnnotation;
41 | }
42 |
43 | @Override
44 | public boolean equals(Object o) {
45 | if (this == o) return true;
46 | if (o == null || getClass() != o.getClass()) return false;
47 |
48 | ExMethodInfo that = (ExMethodInfo) o;
49 |
50 | if (isStatic != that.isStatic) return false;
51 | if (cover != that.cover) return false;
52 | if (siteCopyByClassHeadArgMethod != that.siteCopyByClassHeadArgMethod) return false;
53 | if (!Objects.equals(methodSymbol, that.methodSymbol)) return false;
54 | if (!Objects.equals(targetClass, that.targetClass)) return false;
55 | return Objects.equals(filterAnnotation, that.filterAnnotation);
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | int result = methodSymbol != null ? methodSymbol.hashCode() : 0;
61 | result = 31 * result + (isStatic ? 1 : 0);
62 | result = 31 * result + (cover ? 1 : 0);
63 | result = 31 * result + (targetClass != null ? targetClass.hashCode() : 0);
64 | result = 31 * result + (filterAnnotation != null ? filterAnnotation.hashCode() : 0);
65 | result = 31 * result + (siteCopyByClassHeadArgMethod ? 1 : 0);
66 | return result;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/comp/NeedRedirectMethod.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 |
6 | /**
7 | * @ClassName: NeedRedirectMethod
8 | * @Author: 122006
9 | * @Date: 2025/4/16 9:52
10 | * @Description:
11 | */
12 | public class NeedRedirectMethod extends RuntimeException {
13 | public NeedRedirectMethod(Symbol bestSoFar, ExMethodInfo methodInfo, Type site) {
14 | this.bestSoFar = bestSoFar;
15 | this.exMethodInfo = methodInfo;
16 | this.site = site;
17 | }
18 |
19 | Symbol bestSoFar;
20 | ExMethodInfo exMethodInfo;
21 | Type site;
22 | }
23 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/comp/NeedReplaceLambda.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.tree.JCTree;
4 |
5 | /**
6 | * @ClassName: NeedReplaceLambda
7 | * @Author: 122006
8 | * @Date: 2025/4/16 9:52
9 | * @Description:
10 | */
11 | public class NeedReplaceLambda extends RuntimeException {
12 | public NeedReplaceLambda(JCTree.JCLambda bestSoFar, JCTree.JCMemberReference memberReference, ExMethodInfo methodInfo) {
13 | super("搜索到不支持且被拓展的非静态方法引用:" + memberReference + "\n暂不支持该拓展形式,请替换为lambda表达式:\n" + bestSoFar + "\n请至github联系开发者以修复该情况");
14 | this.bestSoFar = bestSoFar;
15 | this.memberReference = memberReference;
16 | this.methodInfo = methodInfo;
17 | }
18 |
19 | JCTree.JCLambda bestSoFar;
20 | JCTree.JCMemberReference memberReference;
21 | ExMethodInfo methodInfo;
22 | }
23 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/comp/ZrLookupHelper.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 | import com.sun.tools.javac.util.Name;
7 | import com.sun.tools.javac.util.Pair;
8 |
9 | /**
10 | * @ClassName: ZrLookupHelper
11 | * @Author: 122006
12 | * @Date: 2025/4/16 9:58
13 | * @Description:
14 | */
15 | class ZrLookupHelper extends Resolve.BasicLookupHelper {
16 |
17 | ZrResolve zrResolve;
18 |
19 | ZrLookupHelper(ZrResolve zrResolve, Name name, Type site, List argtypes, List typeargtypes) {
20 | zrResolve.super(name, site, argtypes, typeargtypes);
21 | this.zrResolve = zrResolve;
22 | }
23 |
24 | @Override
25 | Symbol doLookup(Env env, Resolve.MethodResolutionPhase phase) {
26 | final Symbol bestSoFar = zrResolve.findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired());
27 | final Pair method2 = zrResolve.findMethod2(env, site, name, argtypes, typeargtypes, bestSoFar, phase.isBoxingRequired(), phase.isVarargsRequired(), false);
28 | final Symbol newSymbol = method2.fst;
29 | if (method2.snd != null && (newSymbol instanceof Symbol.MethodSymbol && !(bestSoFar instanceof Symbol.MethodSymbol)) || ((newSymbol instanceof Symbol.MethodSymbol) && (bestSoFar instanceof Symbol.MethodSymbol) && newSymbol != bestSoFar)) {
30 | throw new NeedRedirectMethod(method2.fst, method2.snd, site);
31 | } else {
32 | return newSymbol;
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/comp/ZrLookupHelper2.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 | import com.sun.tools.javac.util.Name;
7 | import com.sun.tools.javac.util.Pair;
8 |
9 | /**
10 | * @ClassName: ZrLookupHelper2
11 | * @Author: 122006
12 | * @Date: 2025/4/16 9:53
13 | * @Description:
14 | */
15 | class ZrLookupHelper2 extends Resolve.BasicLookupHelper {
16 |
17 | private final ZrResolve zrResolve;
18 |
19 | ZrLookupHelper2(ZrResolve zrResolve, Name name, Type site, List argtypes, List typeargtypes) {
20 | zrResolve.super(name, site, argtypes, typeargtypes);
21 | this.zrResolve = zrResolve;
22 | }
23 |
24 | @Override
25 | Symbol doLookup(Env env, Resolve.MethodResolutionPhase phase) {
26 | final Symbol bestSoFar = zrResolve.findFun(env, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired());
27 | final Pair pair = zrResolve.findMethod2(env, site, name, argtypes, typeargtypes, bestSoFar, phase.isBoxingRequired(), phase.isVarargsRequired(), false);
28 | final Symbol method2 = pair.fst;
29 | if (pair.snd != null && method2 != bestSoFar && zrResolve.methodSymbolEnable(method2)) {
30 | throw new NeedRedirectMethod(pair.fst, pair.snd, site);
31 | }
32 | return bestSoFar;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/comp/ZrMethodReferenceLookupHelper.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.tree.JCTree;
6 | import com.sun.tools.javac.tree.TreeInfo;
7 | import com.sun.tools.javac.util.List;
8 | import com.sun.tools.javac.util.Name;
9 | import com.sun.tools.javac.util.Pair;
10 |
11 | import static com.sun.tools.javac.code.TypeTag.NONE;
12 |
13 | /**
14 | * @ClassName: ZrMethodReferenceLookupHelper
15 | * @Author: 122006
16 | * @Date: 2025/4/16 9:55
17 | * @Description:
18 | */
19 | class ZrMethodReferenceLookupHelper extends Resolve.ReferenceLookupHelper {
20 |
21 | Resolve.MethodReferenceLookupHelper helper;
22 | Type oSite;
23 | ExMethodInfo info;
24 | ZrResolve zrResolve;
25 |
26 |
27 | ZrMethodReferenceLookupHelper(ZrResolve zrResolve, JCTree.JCMemberReference referenceTree, Name name, Type site, List argtypes, List typeargtypes, Resolve.MethodResolutionPhase maxPhase) {
28 | zrResolve.super(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
29 | this.zrResolve = zrResolve;
30 | oSite = site;
31 | helper = zrResolve.new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
32 | }
33 |
34 | @Override
35 | @SuppressWarnings({"unchecked", "rawtypes"})
36 | final Symbol lookup(Env env, Resolve.MethodResolutionPhase phase) {
37 | final Symbol method = zrResolve.findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired());
38 | if (!TreeInfo.isStaticSelector(referenceTree.expr, zrResolve.names)) {
39 | for (ExMethodInfo methodInfo : zrResolve.findRedirectMethod(env, name, zrResolve.methodSymbolEnable(method))) {
40 | final List nParams = methodInfo.methodSymbol.params();
41 | if (nParams.size() == 0) continue;
42 | if (!zrResolve.types.isCastable(site, nParams.get(0).type)) {
43 | continue;
44 | }
45 | final JCTree.JCLambda lambdaTree = zrResolve.createLambdaTree(referenceTree, methodInfo);
46 | throw new NeedReplaceLambda(lambdaTree, referenceTree, methodInfo);
47 | }
48 | return method;
49 | } else {
50 | for (ExMethodInfo methodInfo : zrResolve.findRedirectMethod(env, name, zrResolve.methodSymbolEnable(method))) {
51 | if (!methodInfo.siteCopyByClassHeadArgMethod) continue;
52 | final List nParams = methodInfo.methodSymbol.params();
53 | if (nParams.size() == 0) continue;
54 | if (!zrResolve.types.isCastable(site, methodInfo.targetClass.head)) {
55 | continue;
56 | }
57 | final JCTree.JCLambda lambdaTree = zrResolve.createLambdaTree(referenceTree, methodInfo);
58 | throw new NeedReplaceLambda(lambdaTree, referenceTree, methodInfo);
59 | }
60 | }
61 | Pair method2 = zrResolve.findMethod2(env, oSite, name, argtypes, typeargtypes, method, phase.isBoxingRequired(), phase.isVarargsRequired(), true);
62 | if (!zrResolve.methodSymbolEnable(method2.fst)) {
63 | info = null;
64 | return method;
65 | } else {
66 | info = method2.snd;
67 | return method2.fst;
68 | }
69 | }
70 |
71 |
72 | @Override
73 | Resolve.ReferenceLookupHelper unboundLookup(InferenceContext inferenceContext) {
74 | if (info != null && (TreeInfo.isStaticSelector(referenceTree.expr, zrResolve.names) && !info.siteCopyByClassHeadArgMethod)) {
75 | if (argtypes.nonEmpty() && (argtypes.head.hasTag(NONE) ||
76 | zrResolve.types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), oSite))) {
77 | return this;
78 | }
79 | }
80 | return helper.unboundLookup(inferenceContext);
81 | }
82 |
83 | @Override
84 | JCTree.JCMemberReference.ReferenceKind referenceKind(Symbol sym) {
85 | return helper.referenceKind(sym);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/parser/ZrParserFactory.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 | import com.sun.tools.javac.util.Context;
4 | import com.sun.tools.javac.util.ZrScanner;
5 |
6 | import java.nio.CharBuffer;
7 |
8 | public class ZrParserFactory extends ParserFactory {
9 | private Context context;
10 |
11 | protected ZrParserFactory(Context context) {
12 | super(context);
13 | this.context = context;
14 | }
15 | public JavacParser newParser(CharSequence var1, boolean var2, boolean var3, boolean var4) {
16 | Scanner var5 = newScanner(var1, var2);
17 | return new JavacParser(this, var5, var2, var4, var3);
18 | }
19 | public Scanner newScanner(CharSequence var1, boolean var2) {
20 | ScannerFactory scannerFactory=ScannerFactory.instance(context);
21 | if (var1 instanceof CharBuffer) {
22 | CharBuffer var4 = (CharBuffer)var1;
23 | return var2 ? new ZrScanner(scannerFactory, new JavadocTokenizer(scannerFactory, var4)) : new ZrScanner(scannerFactory, var4);
24 | } else {
25 | char[] var3 = var1.toString().toCharArray();
26 | return this.newScanner(var3, var3.length, var2);
27 | }
28 | }
29 | public Scanner newScanner(char[] var1, int var2, boolean var3) {
30 | return var3 ? new ZrScanner(scannerFactory, new JavadocTokenizer(scannerFactory, var1, var2)) : new ZrScanner(scannerFactory, var1, var2);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/util/ZrJavadocTokenizer.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.ScannerFactory;
4 | import com.sun.tools.javac.parser.UnicodeReader;
5 | import com.sun.tools.javac.parser.ZrJavaTokenizer;
6 |
7 | import java.nio.CharBuffer;
8 |
9 | public class ZrJavadocTokenizer extends ZrJavaTokenizer {
10 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, CharBuffer charBuffer) {
11 | super(scannerFactory, charBuffer);
12 | }
13 |
14 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, char[] chars, int i) {
15 | super(scannerFactory, chars, i);
16 | }
17 |
18 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, UnicodeReader unicodeReader) {
19 | super(scannerFactory, unicodeReader);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/util/ZrScanner.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.JavaTokenizer;
4 | import com.sun.tools.javac.parser.Scanner;
5 | import com.sun.tools.javac.parser.ScannerFactory;
6 | import com.sun.tools.javac.parser.ZrJavaTokenizer;
7 |
8 | import java.nio.CharBuffer;
9 |
10 | public class ZrScanner extends Scanner {
11 |
12 | public ZrScanner(ScannerFactory scannerFactory, CharBuffer charBuffer) {
13 | this(scannerFactory, new ZrJavaTokenizer(scannerFactory, charBuffer));
14 | }
15 |
16 | public ZrScanner(ScannerFactory scannerFactory, char[] chars, int i) {
17 | this(scannerFactory, new ZrJavaTokenizer(scannerFactory, chars, i));
18 | }
19 |
20 | public ZrScanner(ScannerFactory scannerFactory, JavaTokenizer javaTokenizer) {
21 | super(scannerFactory,javaTokenizer);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/inject_java11/src/main/java/com/sun/tools/javac/util/ZrScannerFactory.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.Scanner;
4 | import com.sun.tools.javac.parser.ScannerFactory;
5 |
6 | import java.nio.CharBuffer;
7 |
8 | public class ZrScannerFactory extends ScannerFactory {
9 |
10 | public ZrScannerFactory(Context context) {
11 | super(preSuper(context));
12 | }
13 | public static ZrScannerFactory instance(Context var0) {
14 | Object var1 = var0.get(scannerFactoryKey);
15 | if (!(var1 instanceof ZrScannerFactory)) {
16 | var1 = new ZrScannerFactory(var0);
17 | var0.put(scannerFactoryKey,(ZrScannerFactory)var1);
18 | }
19 | return (ZrScannerFactory) var1;
20 | }
21 | private static Context preSuper(Context context) {
22 | context.put(ScannerFactory.scannerFactoryKey,(ScannerFactory) null);
23 | return context;
24 | }
25 |
26 | public Scanner newScanner(CharSequence var1, boolean var2) {
27 | if (var1 instanceof CharBuffer) {
28 | CharBuffer var4 = (CharBuffer)var1;
29 | return var2 ? new ZrScanner(this, new ZrJavadocTokenizer(this, var4)) : new ZrScanner(this, var4);
30 | } else {
31 | char[] var3 = var1.toString().toCharArray();
32 | return this.newScanner(var3, var3.length, var2);
33 | }
34 | }
35 |
36 | public Scanner newScanner(char[] var1, int var2, boolean var3) {
37 | return var3 ? new ZrScanner(this, new ZrJavadocTokenizer(this, var1, var2)) : new ZrScanner(this, var1, var2);
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/inject_java16/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'maven-publish'
4 | }
5 |
6 | repositories {
7 | maven { url 'https://maven.aliyun.com/repository/public/' }
8 | mavenCentral()
9 | maven {
10 | url uri('../../repo')
11 | }
12 | }
13 | dependencies {
14 | implementation project(":base")
15 | implementation project(":zircon")
16 | }
17 | java {
18 | toolchain {
19 | languageVersion = JavaLanguageVersion.of(17)
20 | }
21 | }
22 | compileJava {
23 | sourceCompatibility = JavaVersion.VERSION_1_8
24 | targetCompatibility = JavaVersion.VERSION_1_8
25 | options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore:symbol.file"
26 | }
27 | task copyJavacClass(type: Copy) {
28 | from "${buildDir}/classes/java/main/com/sun/tools/javac/parser"
29 | from "${buildDir}/classes/java/main/com/sun/tools/javac/comp"
30 | from "${buildDir}/classes/java/main/com/sun/tools/javac/util"
31 | into "${rootDir}/javac/src/main/resources/clazz/java16"
32 | rename ~/(.*)\.class/, '$1.clazz'
33 | }
34 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/comp/ExMethodInfo.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 |
7 | import java.util.Objects;
8 |
9 | /**
10 | * @ClassName: ExMethodInfo
11 | * @Author: 122006
12 | * @Date: 2025/4/16 9:52
13 | * @Description:
14 | */
15 | public class ExMethodInfo {
16 | Symbol.MethodSymbol methodSymbol;
17 | boolean isStatic;
18 | boolean cover;
19 | List targetClass;
20 | List filterAnnotation;
21 | boolean siteCopyByClassHeadArgMethod = false;
22 |
23 | @Override
24 | public String toString() {
25 | return "ExMethodInfo{" +
26 | "methodSymbol=" + methodSymbol +
27 | ", isStatic=" + isStatic +
28 | ", cover=" + cover +
29 | ", targetClass=" + targetClass +
30 | ", filterAnnotation=" + filterAnnotation +
31 | ", siteCopyByClassHeadArgMethod=" + siteCopyByClassHeadArgMethod +
32 | '}';
33 | }
34 |
35 | public ExMethodInfo(Symbol.MethodSymbol methodSymbol, boolean isStatic, boolean cover, List targetClass, List filterAnnotation) {
36 | this.methodSymbol = methodSymbol;
37 | this.isStatic = isStatic;
38 | this.cover = cover;
39 | this.targetClass = targetClass;
40 | this.filterAnnotation = filterAnnotation;
41 | }
42 |
43 | @Override
44 | public boolean equals(Object o) {
45 | if (this == o) return true;
46 | if (o == null || getClass() != o.getClass()) return false;
47 |
48 | ExMethodInfo that = (ExMethodInfo) o;
49 |
50 | if (isStatic != that.isStatic) return false;
51 | if (cover != that.cover) return false;
52 | if (siteCopyByClassHeadArgMethod != that.siteCopyByClassHeadArgMethod) return false;
53 | if (!Objects.equals(methodSymbol, that.methodSymbol)) return false;
54 | if (!Objects.equals(targetClass, that.targetClass)) return false;
55 | return Objects.equals(filterAnnotation, that.filterAnnotation);
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | int result = methodSymbol != null ? methodSymbol.hashCode() : 0;
61 | result = 31 * result + (isStatic ? 1 : 0);
62 | result = 31 * result + (cover ? 1 : 0);
63 | result = 31 * result + (targetClass != null ? targetClass.hashCode() : 0);
64 | result = 31 * result + (filterAnnotation != null ? filterAnnotation.hashCode() : 0);
65 | result = 31 * result + (siteCopyByClassHeadArgMethod ? 1 : 0);
66 | return result;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/comp/NeedRedirectMethod.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 |
6 | /**
7 | * @ClassName: NeedRedirectMethod
8 | * @Author: 122006
9 | * @Date: 2025/4/16 9:52
10 | * @Description:
11 | */
12 | public class NeedRedirectMethod extends RuntimeException {
13 | public NeedRedirectMethod(Symbol bestSoFar, ExMethodInfo methodInfo, Type site) {
14 | this.bestSoFar = bestSoFar;
15 | this.exMethodInfo = methodInfo;
16 | this.site = site;
17 | }
18 |
19 | Symbol bestSoFar;
20 | ExMethodInfo exMethodInfo;
21 | Type site;
22 | }
23 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/comp/NeedReplaceLambda.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.tree.JCTree;
4 |
5 | /**
6 | * @ClassName: NeedReplaceLambda
7 | * @Author: 122006
8 | * @Date: 2025/4/16 9:52
9 | * @Description:
10 | */
11 | public class NeedReplaceLambda extends RuntimeException {
12 | public NeedReplaceLambda(JCTree.JCLambda bestSoFar, JCTree.JCMemberReference memberReference, ExMethodInfo methodInfo) {
13 | super("搜索到不支持且被拓展的非静态方法引用:" + memberReference + "\n暂不支持该拓展形式,请替换为lambda表达式:\n" + bestSoFar + "\n请至github联系开发者以修复该情况");
14 | this.bestSoFar = bestSoFar;
15 | this.memberReference = memberReference;
16 | this.methodInfo = methodInfo;
17 | }
18 |
19 | JCTree.JCLambda bestSoFar;
20 | JCTree.JCMemberReference memberReference;
21 | ExMethodInfo methodInfo;
22 | }
23 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/comp/ZrLookupHelper.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 | import com.sun.tools.javac.util.Name;
7 | import com.sun.tools.javac.util.Pair;
8 |
9 | /**
10 | * @ClassName: ZrLookupHelper
11 | * @Author: 122006
12 | * @Date: 2025/4/16 9:58
13 | * @Description:
14 | */
15 | class ZrLookupHelper extends Resolve.BasicLookupHelper {
16 |
17 | ZrResolve zrResolve;
18 |
19 | ZrLookupHelper(ZrResolve zrResolve, Name name, Type site, List argtypes, List typeargtypes) {
20 | zrResolve.super(name, site, argtypes, typeargtypes);
21 | this.zrResolve = zrResolve;
22 | }
23 |
24 | @Override
25 | Symbol doLookup(Env env, Resolve.MethodResolutionPhase phase) {
26 | final Symbol bestSoFar = zrResolve.findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired());
27 | final Pair method2 = zrResolve.findMethod2(env, site, name, argtypes, typeargtypes, bestSoFar, phase.isBoxingRequired(), phase.isVarargsRequired(), false);
28 | final Symbol newSymbol = method2.fst;
29 | if (method2.snd != null && (newSymbol instanceof Symbol.MethodSymbol && !(bestSoFar instanceof Symbol.MethodSymbol)) || ((newSymbol instanceof Symbol.MethodSymbol) && (bestSoFar instanceof Symbol.MethodSymbol) && newSymbol != bestSoFar)) {
30 | throw new NeedRedirectMethod(method2.fst, method2.snd,site);
31 | } else {
32 | return newSymbol;
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/comp/ZrLookupHelper2.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 | import com.sun.tools.javac.util.Name;
7 | import com.sun.tools.javac.util.Pair;
8 |
9 | /**
10 | * @ClassName: ZrLookupHelper2
11 | * @Author: 122006
12 | * @Date: 2025/4/16 9:53
13 | * @Description:
14 | */
15 | class ZrLookupHelper2 extends Resolve.BasicLookupHelper {
16 |
17 | private final ZrResolve zrResolve;
18 |
19 | ZrLookupHelper2(ZrResolve zrResolve, Name name, Type site, List argtypes, List typeargtypes) {
20 | zrResolve.super(name, site, argtypes, typeargtypes);
21 | this.zrResolve = zrResolve;
22 | }
23 |
24 | @Override
25 | Symbol doLookup(Env env, Resolve.MethodResolutionPhase phase) {
26 | final Symbol bestSoFar = zrResolve.findFun(env, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired());
27 | final Pair pair = zrResolve.findMethod2(env, site, name, argtypes, typeargtypes, bestSoFar, phase.isBoxingRequired(), phase.isVarargsRequired(), false);
28 | final Symbol method2 = pair.fst;
29 | if (pair.snd != null && method2 != bestSoFar && zrResolve.methodSymbolEnable(method2)) {
30 | throw new NeedRedirectMethod(pair.fst, pair.snd, site);
31 | }
32 | return bestSoFar;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/comp/ZrMethodReferenceLookupHelper.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.tree.JCTree;
6 | import com.sun.tools.javac.tree.TreeInfo;
7 | import com.sun.tools.javac.util.List;
8 | import com.sun.tools.javac.util.Name;
9 | import com.sun.tools.javac.util.Pair;
10 |
11 | import static com.sun.tools.javac.code.TypeTag.NONE;
12 |
13 | /**
14 | * @ClassName: ZrMethodReferenceLookupHelper
15 | * @Author: 122006
16 | * @Date: 2025/4/16 9:55
17 | * @Description:
18 | */
19 | class ZrMethodReferenceLookupHelper extends Resolve.ReferenceLookupHelper {
20 |
21 | Resolve.MethodReferenceLookupHelper helper;
22 | Type oSite;
23 | ExMethodInfo info;
24 | ZrResolve zrResolve;
25 |
26 |
27 | ZrMethodReferenceLookupHelper(ZrResolve zrResolve, JCTree.JCMemberReference referenceTree, Name name, Type site, List argtypes, List typeargtypes, Resolve.MethodResolutionPhase maxPhase) {
28 | zrResolve.super(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
29 | this.zrResolve = zrResolve;
30 | oSite = site;
31 | helper = zrResolve.new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
32 | }
33 |
34 | @Override
35 | @SuppressWarnings({"unchecked", "rawtypes"})
36 | final Symbol lookup(Env env, Resolve.MethodResolutionPhase phase) {
37 | final Symbol method = zrResolve.findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired());
38 | if (!TreeInfo.isStaticSelector(referenceTree.expr, zrResolve.names)) {
39 | for (ExMethodInfo methodInfo : zrResolve.findRedirectMethod(env, name, zrResolve.methodSymbolEnable(method))) {
40 | final List nParams = methodInfo.methodSymbol.params();
41 | if (nParams.size() == 0) continue;
42 | if (!zrResolve.types.isCastable(site, nParams.get(0).type)) {
43 | continue;
44 | }
45 | final JCTree.JCLambda lambdaTree = zrResolve.createLambdaTree(referenceTree, methodInfo);
46 | throw new NeedReplaceLambda(lambdaTree, referenceTree, methodInfo);
47 | }
48 | return method;
49 | } else {
50 | for (ExMethodInfo methodInfo : zrResolve.findRedirectMethod(env, name, zrResolve.methodSymbolEnable(method))) {
51 | if (!methodInfo.siteCopyByClassHeadArgMethod) continue;
52 | final List nParams = methodInfo.methodSymbol.params();
53 | if (nParams.size() == 0) continue;
54 | if (!zrResolve.types.isCastable(site, methodInfo.targetClass.head)) {
55 | continue;
56 | }
57 | final JCTree.JCLambda lambdaTree = zrResolve.createLambdaTree(referenceTree, methodInfo);
58 | throw new NeedReplaceLambda(lambdaTree, referenceTree, methodInfo);
59 | }
60 | }
61 | Pair method2 = zrResolve.findMethod2(env, oSite, name, argtypes, typeargtypes, method, phase.isBoxingRequired(), phase.isVarargsRequired(), true);
62 | if (!zrResolve.methodSymbolEnable(method2.fst)) {
63 | info = null;
64 | return method;
65 | } else {
66 | info = method2.snd;
67 | return method2.fst;
68 | }
69 | }
70 |
71 |
72 | @Override
73 | Resolve.ReferenceLookupHelper unboundLookup(InferenceContext inferenceContext) {
74 | if (info != null && (TreeInfo.isStaticSelector(referenceTree.expr, zrResolve.names) && !info.siteCopyByClassHeadArgMethod)) {
75 | if (argtypes.nonEmpty() && (argtypes.head.hasTag(NONE) ||
76 | zrResolve.types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), oSite))) {
77 | return this;
78 | }
79 | }
80 | return helper.unboundLookup(inferenceContext);
81 | }
82 |
83 | @Override
84 | JCTree.JCMemberReference.ReferenceKind referenceKind(Symbol sym) {
85 | return helper.referenceKind(sym);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/parser/ZrParserFactory.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 | import com.sun.tools.javac.util.Context;
4 | import com.sun.tools.javac.util.ZrScanner;
5 |
6 | import java.nio.CharBuffer;
7 |
8 | public class ZrParserFactory extends ParserFactory {
9 | private Context context;
10 |
11 | protected ZrParserFactory(Context context) {
12 | super(context);
13 | this.context = context;
14 | }
15 | public JavacParser newParser(CharSequence var1, boolean var2, boolean var3, boolean var4) {
16 | Scanner var5 = newScanner(var1, var2);
17 | return new JavacParser(this, var5, var2, var4, var3);
18 | }
19 | public Scanner newScanner(CharSequence var1, boolean var2) {
20 | ScannerFactory scannerFactory=ScannerFactory.instance(context);
21 | if (var1 instanceof CharBuffer) {
22 | CharBuffer var4 = (CharBuffer)var1;
23 | return var2 ? new ZrScanner(scannerFactory, new JavadocTokenizer(scannerFactory, var4)) : new ZrScanner(scannerFactory, var4);
24 | } else {
25 | char[] var3 = var1.toString().toCharArray();
26 | return this.newScanner(var3, var3.length, var2);
27 | }
28 | }
29 | public Scanner newScanner(char[] var1, int var2, boolean var3) {
30 | return var3 ? new ZrScanner(scannerFactory, new JavadocTokenizer(scannerFactory, var1, var2)) : new ZrScanner(scannerFactory, var1, var2);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/util/ZrJavadocTokenizer.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.ScannerFactory;
4 | import com.sun.tools.javac.parser.UnicodeReader;
5 | import com.sun.tools.javac.parser.ZrJavaTokenizer;
6 |
7 | import java.nio.CharBuffer;
8 |
9 | public class ZrJavadocTokenizer extends ZrJavaTokenizer {
10 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, CharBuffer charBuffer) {
11 | super(scannerFactory, charBuffer);
12 | }
13 |
14 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, char[] chars, int i) {
15 | super(scannerFactory, chars, i);
16 | }
17 |
18 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, UnicodeReader unicodeReader) {
19 | super(scannerFactory, unicodeReader);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/util/ZrScanner.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.JavaTokenizer;
4 | import com.sun.tools.javac.parser.Scanner;
5 | import com.sun.tools.javac.parser.ScannerFactory;
6 | import com.sun.tools.javac.parser.ZrJavaTokenizer;
7 |
8 | import java.nio.CharBuffer;
9 |
10 | public class ZrScanner extends Scanner {
11 |
12 | public ZrScanner(ScannerFactory scannerFactory, CharBuffer charBuffer) {
13 | this(scannerFactory, ZrJavaTokenizer.build(scannerFactory, charBuffer));
14 | }
15 |
16 | public ZrScanner(ScannerFactory scannerFactory, char[] chars, int i) {
17 | this(scannerFactory, ZrJavaTokenizer.build(scannerFactory, chars, i));
18 | }
19 |
20 | public ZrScanner(ScannerFactory scannerFactory, JavaTokenizer javaTokenizer) {
21 | super(scannerFactory,javaTokenizer);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/inject_java16/src/main/java/com/sun/tools/javac/util/ZrScannerFactory.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.Scanner;
4 | import com.sun.tools.javac.parser.ScannerFactory;
5 |
6 | import java.nio.CharBuffer;
7 |
8 | public class ZrScannerFactory extends ScannerFactory {
9 |
10 | public ZrScannerFactory(Context context) {
11 | super(preSuper(context));
12 | }
13 | public static ZrScannerFactory instance(Context var0) {
14 | Object var1 = var0.get(scannerFactoryKey);
15 | if (!(var1 instanceof ZrScannerFactory)) {
16 | var1 = new ZrScannerFactory(var0);
17 | var0.put(scannerFactoryKey,(ZrScannerFactory)var1);
18 | }
19 | return (ZrScannerFactory) var1;
20 | }
21 | private static Context preSuper(Context context) {
22 | context.put(ScannerFactory.scannerFactoryKey,(ScannerFactory) null);
23 | return context;
24 | }
25 |
26 | public Scanner newScanner(CharSequence var1, boolean var2) {
27 | if (var1 instanceof CharBuffer) {
28 | CharBuffer var4 = (CharBuffer)var1;
29 | return var2 ? new ZrScanner(this, new ZrJavadocTokenizer(this, var4)) : new ZrScanner(this, var4);
30 | } else {
31 | char[] var3 = var1.toString().toCharArray();
32 | return this.newScanner(var3, var3.length, var2);
33 | }
34 | }
35 |
36 | public Scanner newScanner(char[] var1, int var2, boolean var3) {
37 | return var3 ? new ZrScanner(this, new ZrJavadocTokenizer(this, var1, var2)) : new ZrScanner(this, var1, var2);
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/inject_java7/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'maven-publish'
4 | }
5 |
6 | repositories {
7 | maven { url 'https://maven.aliyun.com/repository/public/' }
8 | mavenCentral()
9 | maven {
10 | url uri('../../repo')
11 | }
12 | }
13 | dependencies {
14 | compileOnly rootProject.fileTree(dir: 'tools', include: ['*.jar'])
15 | implementation project(":base")
16 | implementation project(":zircon")
17 | }
18 | java {
19 | toolchain {
20 | languageVersion = JavaLanguageVersion.of(8)
21 | }
22 | }
23 | compileJava {
24 | sourceCompatibility = JavaVersion.VERSION_1_8
25 | targetCompatibility = JavaVersion.VERSION_1_8
26 | options.compilerArgs << "-Xlint:deprecation" << "-XDignore:symbol.file"
27 | }
28 | task copyJavacClass(type: Copy) {
29 | from "${buildDir}/classes/java/main/com/sun/tools/javac/comp"
30 | from "${buildDir}/classes/java/main/com/sun/tools/javac/parser"
31 | from "${buildDir}/classes/java/main/com/sun/tools/javac/util"
32 | into "${rootDir}/javac/src/main/resources/clazz/java7"
33 | rename ~/(.*)\.class/, '$1.clazz'
34 | }
35 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/comp/ExMethodInfo.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 |
7 | import java.util.Objects;
8 |
9 | /**
10 | * @ClassName: ExMethodInfo
11 | * @Author: 122006
12 | * @Date: 2025/4/16 9:52
13 | * @Description:
14 | */
15 | public class ExMethodInfo {
16 | Symbol.MethodSymbol methodSymbol;
17 | boolean isStatic;
18 | boolean cover;
19 | List targetClass;
20 | List filterAnnotation;
21 | boolean siteCopyByClassHeadArgMethod = false;
22 |
23 | @Override
24 | public String toString() {
25 | return "ExMethodInfo{" +
26 | "methodSymbol=" + methodSymbol +
27 | ", isStatic=" + isStatic +
28 | ", cover=" + cover +
29 | ", targetClass=" + targetClass +
30 | ", filterAnnotation=" + filterAnnotation +
31 | ", siteCopyByClassHeadArgMethod=" + siteCopyByClassHeadArgMethod +
32 | '}';
33 | }
34 |
35 | public ExMethodInfo(Symbol.MethodSymbol methodSymbol, boolean isStatic, boolean cover, List targetClass, List filterAnnotation) {
36 | this.methodSymbol = methodSymbol;
37 | this.isStatic = isStatic;
38 | this.cover = cover;
39 | this.targetClass = targetClass;
40 | this.filterAnnotation = filterAnnotation;
41 | }
42 |
43 |
44 | @Override
45 | public boolean equals(Object o) {
46 | if (this == o) return true;
47 | if (o == null || getClass() != o.getClass()) return false;
48 |
49 | ExMethodInfo that = (ExMethodInfo) o;
50 |
51 | if (isStatic != that.isStatic) return false;
52 | if (cover != that.cover) return false;
53 | if (siteCopyByClassHeadArgMethod != that.siteCopyByClassHeadArgMethod) return false;
54 | if (!Objects.equals(methodSymbol, that.methodSymbol)) return false;
55 | if (!Objects.equals(targetClass, that.targetClass)) return false;
56 | return Objects.equals(filterAnnotation, that.filterAnnotation);
57 | }
58 |
59 | @Override
60 | public int hashCode() {
61 | int result = methodSymbol != null ? methodSymbol.hashCode() : 0;
62 | result = 31 * result + (isStatic ? 1 : 0);
63 | result = 31 * result + (cover ? 1 : 0);
64 | result = 31 * result + (targetClass != null ? targetClass.hashCode() : 0);
65 | result = 31 * result + (filterAnnotation != null ? filterAnnotation.hashCode() : 0);
66 | result = 31 * result + (siteCopyByClassHeadArgMethod ? 1 : 0);
67 | return result;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/comp/NeedRedirectMethod.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 |
6 | /**
7 | * @ClassName: NeedRedirectMethod
8 | * @Author: 122006
9 | * @Date: 2025/4/16 9:52
10 | * @Description:
11 | */
12 | public class NeedRedirectMethod extends RuntimeException {
13 | public NeedRedirectMethod(Symbol bestSoFar, ExMethodInfo methodInfo, Type site) {
14 | this.bestSoFar = bestSoFar;
15 | this.exMethodInfo = methodInfo;
16 | this.site = site;
17 | }
18 |
19 | Symbol bestSoFar;
20 | ExMethodInfo exMethodInfo;
21 | Type site;
22 | }
23 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/comp/NeedReplaceLambda.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.tree.JCTree;
4 |
5 | /**
6 | * @ClassName: NeedReplaceLambda
7 | * @Author: 122006
8 | * @Date: 2025/4/16 9:52
9 | * @Description:
10 | */
11 | public class NeedReplaceLambda extends RuntimeException {
12 | public NeedReplaceLambda(JCTree.JCLambda bestSoFar, JCTree.JCMemberReference memberReference, ExMethodInfo methodInfo) {
13 | super("搜索到不支持且被拓展的非静态方法引用:" + memberReference + "\n暂不支持该拓展形式,请替换为lambda表达式:\n" + bestSoFar + "\n请至github联系开发者以修复该情况");
14 | this.bestSoFar = bestSoFar;
15 | this.memberReference = memberReference;
16 | this.methodInfo = methodInfo;
17 | }
18 |
19 | JCTree.JCLambda bestSoFar;
20 | JCTree.JCMemberReference memberReference;
21 | ExMethodInfo methodInfo;
22 | }
23 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/comp/ZrLookupHelper.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 | import com.sun.tools.javac.util.Name;
7 | import com.sun.tools.javac.util.Pair;
8 |
9 | /**
10 | * @ClassName: ZrLookupHelper
11 | * @Author: 122006
12 | * @Date: 2025/4/16 10:05
13 | * @Description:
14 | */
15 | class ZrLookupHelper extends Resolve.BasicLookupHelper {
16 |
17 | private final ZrResolve zrResolve;
18 |
19 | ZrLookupHelper(ZrResolve zrResolve, Name name, Type site, List argtypes, List typeargtypes) {
20 | zrResolve.super(name, site, argtypes, typeargtypes);
21 | this.zrResolve = zrResolve;
22 | }
23 |
24 | @Override
25 | Symbol doLookup(Env env, Resolve.MethodResolutionPhase phase) {
26 | final Symbol bestSoFar = zrResolve.findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired(), false);
27 | final Pair method2 = zrResolve.findMethod2(env, site, name, argtypes, typeargtypes, bestSoFar, phase.isBoxingRequired(), phase.isVarargsRequired(), false, false);
28 | final Symbol newSymbol = method2.fst;
29 | if (method2.snd != null && (newSymbol instanceof Symbol.MethodSymbol && !(bestSoFar instanceof Symbol.MethodSymbol)) || ((newSymbol instanceof Symbol.MethodSymbol) && (bestSoFar instanceof Symbol.MethodSymbol) && newSymbol != bestSoFar)) {
30 | throw new NeedRedirectMethod(method2.fst, method2.snd, site);
31 | } else {
32 | return newSymbol;
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/comp/ZrLookupHelper2.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.util.List;
6 | import com.sun.tools.javac.util.Name;
7 | import com.sun.tools.javac.util.Pair;
8 |
9 | /**
10 | * @ClassName: ZrLookupHelper2
11 | * @Author: 122006
12 | * @Date: 2025/4/16 10:05
13 | * @Description:
14 | */
15 | class ZrLookupHelper2 extends Resolve.BasicLookupHelper {
16 |
17 | private final ZrResolve zrResolve;
18 |
19 | ZrLookupHelper2(ZrResolve zrResolve, Name name, Type site, List argtypes, List typeargtypes) {
20 | zrResolve.super(name, site, argtypes, typeargtypes);
21 | this.zrResolve = zrResolve;
22 | }
23 |
24 | @Override
25 | Symbol doLookup(Env env, Resolve.MethodResolutionPhase phase) {
26 | final Symbol bestSoFar = zrResolve.findFun(env, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired());
27 | final Pair pair = zrResolve.findMethod2(env, site, name, argtypes, typeargtypes, bestSoFar, phase.isBoxingRequired(), phase.isVarargsRequired(), false, false);
28 | final Symbol method2 = pair.fst;
29 | if (pair.snd != null && method2 != bestSoFar && zrResolve.methodSymbolEnable(method2)) {
30 | throw new NeedRedirectMethod(pair.fst, pair.snd, site);
31 | }
32 | return bestSoFar;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/comp/ZrMethodReferenceLookupHelper.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.comp;
2 |
3 | import com.sun.tools.javac.code.Symbol;
4 | import com.sun.tools.javac.code.Type;
5 | import com.sun.tools.javac.tree.JCTree;
6 | import com.sun.tools.javac.tree.TreeInfo;
7 | import com.sun.tools.javac.util.List;
8 | import com.sun.tools.javac.util.Name;
9 | import com.sun.tools.javac.util.Pair;
10 |
11 | import static com.sun.tools.javac.code.TypeTag.NONE;
12 |
13 | /**
14 | * @ClassName: ZrMethodReferenceLookupHelper
15 | * @Author: 122006
16 | * @Date: 2025/4/16 10:05
17 | * @Description:
18 | */
19 | class ZrMethodReferenceLookupHelper extends Resolve.ReferenceLookupHelper {
20 |
21 | private final ZrResolve zrResolve;
22 | Resolve.MethodReferenceLookupHelper helper;
23 | Type oSite;
24 |
25 | ExMethodInfo info;
26 |
27 |
28 | ZrMethodReferenceLookupHelper(ZrResolve zrResolve, JCTree.JCMemberReference referenceTree, Name name, Type site, List argtypes, List typeargtypes, Resolve.MethodResolutionPhase maxPhase) {
29 | zrResolve.super(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
30 | this.zrResolve = zrResolve;
31 | oSite = site;
32 | helper = zrResolve.new MethodReferenceLookupHelper(referenceTree, name, site, argtypes, typeargtypes, maxPhase);
33 | }
34 |
35 | @Override
36 | @SuppressWarnings({"rawtypes"})
37 | Symbol lookup(Env env, Resolve.MethodResolutionPhase phase) {
38 | final Symbol method = zrResolve.findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired(), false);
39 | if (!TreeInfo.isStaticSelector(referenceTree.expr, zrResolve.names)) {
40 | Symbol method2 = method;
41 | for (ExMethodInfo methodInfo : zrResolve.findRedirectMethod(env, name, zrResolve.methodSymbolEnable(method))) {
42 | final List nParams = methodInfo.methodSymbol.params();
43 | if (nParams.size() == 0) continue;
44 | if (!zrResolve.types.isCastable(site, nParams.get(0).type)) {
45 | continue;
46 | }
47 | final JCTree.JCLambda lambdaTree = ZrResolveEx.createLambdaTree(zrResolve, referenceTree, methodInfo);
48 | throw new NeedReplaceLambda(lambdaTree, referenceTree, methodInfo);
49 | }
50 | return method2;
51 | } else {
52 | for (ExMethodInfo methodInfo : zrResolve.findRedirectMethod(env, name, zrResolve.methodSymbolEnable(method))) {
53 | if (!methodInfo.siteCopyByClassHeadArgMethod) continue;
54 | final List nParams = methodInfo.methodSymbol.params();
55 | if (nParams.size() == 0) continue;
56 | if (!zrResolve.types.isCastable(site, methodInfo.targetClass.head)) {
57 | continue;
58 | }
59 | final JCTree.JCLambda lambdaTree = ZrResolveEx.createLambdaTree(zrResolve, referenceTree, methodInfo);
60 | throw new NeedReplaceLambda(lambdaTree, referenceTree, methodInfo);
61 | }
62 | }
63 |
64 | Pair method2 = zrResolve.findMethod2(env, oSite, name, argtypes, typeargtypes, method, phase.isBoxingRequired(), phase.isVarargsRequired(), true, true);
65 | if (!zrResolve.methodSymbolEnable(method2.fst)) {
66 | info = null;
67 | return method;
68 | } else {
69 | info = method2.snd;
70 | return method2.fst;
71 | }
72 | }
73 |
74 |
75 | @Override
76 | Resolve.ReferenceLookupHelper unboundLookup(Infer.InferenceContext inferenceContext) {
77 | if (info != null && (TreeInfo.isStaticSelector(referenceTree.expr, zrResolve.names) && !info.siteCopyByClassHeadArgMethod)) {
78 | if (argtypes.nonEmpty() && (argtypes.head.hasTag(NONE) ||
79 | zrResolve.types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), oSite))) {
80 | return this;
81 | }
82 | }
83 | return helper.unboundLookup(inferenceContext);
84 | }
85 |
86 | @Override
87 | JCTree.JCMemberReference.ReferenceKind referenceKind(Symbol sym) {
88 | return helper.referenceKind(sym);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/parser/ZrParserFactory.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.parser;
2 |
3 | import com.sun.tools.javac.util.Context;
4 | import com.sun.tools.javac.util.ZrScanner;
5 |
6 | import java.nio.CharBuffer;
7 |
8 | public class ZrParserFactory extends ParserFactory {
9 | private Context context;
10 |
11 | protected ZrParserFactory(Context context) {
12 | super(context);
13 | this.context = context;
14 | }
15 | public JavacParser newParser(CharSequence var1, boolean var2, boolean var3, boolean var4) {
16 | Scanner var5 = newScanner(var1, var2);
17 | return new JavacParser(this, var5, var2, var4, var3);
18 | }
19 | public Scanner newScanner(CharSequence var1, boolean var2) {
20 | ScannerFactory scannerFactory=ScannerFactory.instance(context);
21 | if (var1 instanceof CharBuffer) {
22 | CharBuffer var4 = (CharBuffer)var1;
23 | return var2 ? new ZrScanner(scannerFactory, new JavadocTokenizer(scannerFactory, var4)) : new ZrScanner(scannerFactory, var4);
24 | } else {
25 | char[] var3 = var1.toString().toCharArray();
26 | return this.newScanner(var3, var3.length, var2);
27 | }
28 | }
29 | public Scanner newScanner(char[] var1, int var2, boolean var3) {
30 | return var3 ? new ZrScanner(scannerFactory, new JavadocTokenizer(scannerFactory, var1, var2)) : new ZrScanner(scannerFactory, var1, var2);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/util/ZrJavadocTokenizer.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.ScannerFactory;
4 | import com.sun.tools.javac.parser.UnicodeReader;
5 | import com.sun.tools.javac.parser.ZrJavaTokenizer;
6 |
7 | import java.nio.CharBuffer;
8 |
9 | public class ZrJavadocTokenizer extends ZrJavaTokenizer {
10 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, CharBuffer charBuffer) {
11 | super(scannerFactory, charBuffer);
12 | }
13 |
14 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, char[] chars, int i) {
15 | super(scannerFactory, chars, i);
16 | }
17 |
18 | public ZrJavadocTokenizer(ScannerFactory scannerFactory, UnicodeReader unicodeReader) {
19 | super(scannerFactory, unicodeReader);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/util/ZrScanner.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.JavaTokenizer;
4 | import com.sun.tools.javac.parser.Scanner;
5 | import com.sun.tools.javac.parser.ScannerFactory;
6 | import com.sun.tools.javac.parser.ZrJavaTokenizer;
7 |
8 | import java.nio.CharBuffer;
9 |
10 | public class ZrScanner extends Scanner {
11 |
12 | public ZrScanner(ScannerFactory scannerFactory, CharBuffer charBuffer) {
13 | this(scannerFactory, new ZrJavaTokenizer(scannerFactory, charBuffer));
14 | }
15 |
16 | public ZrScanner(ScannerFactory scannerFactory, char[] chars, int i) {
17 | this(scannerFactory, new ZrJavaTokenizer(scannerFactory, chars, i));
18 | }
19 |
20 | public ZrScanner(ScannerFactory scannerFactory, JavaTokenizer javaTokenizer) {
21 | super(scannerFactory,javaTokenizer);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/inject_java7/src/main/java/com/sun/tools/javac/util/ZrScannerFactory.java:
--------------------------------------------------------------------------------
1 | package com.sun.tools.javac.util;
2 |
3 | import com.sun.tools.javac.parser.Scanner;
4 | import com.sun.tools.javac.parser.ScannerFactory;
5 |
6 | import java.nio.CharBuffer;
7 |
8 | public class ZrScannerFactory extends ScannerFactory {
9 |
10 | public ZrScannerFactory(Context context) {
11 | super(preSuper(context));
12 | }
13 | public static ZrScannerFactory instance(Context var0) {
14 | Object var1 = var0.get(scannerFactoryKey);
15 | if (!(var1 instanceof ZrScannerFactory)) {
16 | var1 = new ZrScannerFactory(var0);
17 | var0.put(scannerFactoryKey,(ZrScannerFactory)var1);
18 | }
19 | return (ZrScannerFactory) var1;
20 | }
21 | private static Context preSuper(Context context) {
22 | context.put(ScannerFactory.scannerFactoryKey,(ScannerFactory) null);
23 | return context;
24 | }
25 |
26 | public Scanner newScanner(CharSequence var1, boolean var2) {
27 | if (var1 instanceof CharBuffer) {
28 | CharBuffer var4 = (CharBuffer)var1;
29 | return var2 ? new ZrScanner(this, new ZrJavadocTokenizer(this, var4)) : new ZrScanner(this, var4);
30 | } else {
31 | char[] var3 = var1.toString().toCharArray();
32 | return this.newScanner(var3, var3.length, var2);
33 | }
34 | }
35 |
36 | public Scanner newScanner(char[] var1, int var2, boolean var3) {
37 | return var3 ? new ZrScanner(this, new ZrJavadocTokenizer(this, var1, var2)) : new ZrScanner(this, var1, var2);
38 | }
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/javac/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'maven-publish'
4 | id 'java-library'
5 | }
6 |
7 | repositories {
8 | maven { url 'https://maven.aliyun.com/repository/public/' }
9 | mavenCentral()
10 | maven {
11 | url uri('../../repo')
12 | }
13 | }
14 | dependencies {
15 | compileOnly rootProject.fileTree(dir: 'tools', include: ['*.jar'])
16 | api project(":base")
17 | api project(":zircon")
18 | }
19 | java {
20 | toolchain {
21 | languageVersion = JavaLanguageVersion.of(8)
22 | }
23 | }
24 | jar {
25 | manifest {
26 | attributes(
27 | 'Add-Exports': "jdk.compiler/com.sun.tools.javac.api jdk.compiler/com.sun.tools.javac.code jdk.compiler/com.sun.tools.javac.util jdk.compiler/com.sun.tools.javac.comp",
28 | 'Add-Opens': "jdk.compiler/com.sun.tools.javac.main jdk.compiler/com.sun.tools.javac.parser",
29 | )
30 | }
31 | }
32 | compileJava {
33 | sourceCompatibility = JavaVersion.VERSION_1_8
34 | targetCompatibility = JavaVersion.VERSION_1_8
35 | options.fork = true
36 | options.compilerArgs << "-Xlint:deprecation" << "-XDignore.symbol.file"
37 | }
38 | task sourceJar(type: Jar) {
39 | from sourceSets.main.allJava
40 | archiveClassifier = "sources"
41 | }
42 |
43 | publishing {
44 | publications {
45 | maven(MavenPublication) {
46 | groupId rootProject.ext.groupId
47 | artifactId "javac"
48 | version rootProject.ext.version
49 | from components.java
50 | artifact sourceJar
51 | }
52 | }
53 | repositories {
54 | maven {
55 | url = uri('../../repo')
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/javac/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.7-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrAttr.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrAttr.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrJavaTokenizer$JavaCException.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrJavaTokenizer$JavaCException.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrJavaTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrJavaTokenizer.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrJavadocTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrJavadocTokenizer.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrParserFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrParserFactory.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrResolve$ExMethodInfo.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrResolve$ExMethodInfo.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrResolve$NeedRedirectMethod.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrResolve$NeedRedirectMethod.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrResolve$NeedReplaceLambda.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrResolve$NeedReplaceLambda.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrResolve$ZrLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrResolve$ZrLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrResolve$ZrLookupHelper2.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrResolve$ZrLookupHelper2.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrResolve$ZrMethodReferenceLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrResolve$ZrMethodReferenceLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrResolve.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrResolve.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrScanner.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrScanner.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java11/ZrScannerFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java11/ZrScannerFactory.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrAttr.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrAttr.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrJavaTokenizer$JavaCException.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrJavaTokenizer$JavaCException.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrJavaTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrJavaTokenizer.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrJavadocTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrJavadocTokenizer.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrParserFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrParserFactory.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrResolve$ExMethodInfo.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrResolve$ExMethodInfo.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrResolve$NeedRedirectMethod.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrResolve$NeedRedirectMethod.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrResolve$NeedReplaceLambda.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrResolve$NeedReplaceLambda.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrResolve$ZrLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrResolve$ZrLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrResolve$ZrLookupHelper2.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrResolve$ZrLookupHelper2.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrResolve$ZrMethodReferenceLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrResolve$ZrMethodReferenceLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrResolve.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrResolve.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrScanner.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrScanner.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java16/ZrScannerFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java16/ZrScannerFactory.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrAttr.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrAttr.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrJavaTokenizer$JavaCException.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrJavaTokenizer$JavaCException.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrJavaTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrJavaTokenizer.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrJavadocTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrJavadocTokenizer.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrParserFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrParserFactory.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrResolve$ExMethodInfo.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrResolve$ExMethodInfo.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrResolve$NeedRedirectMethod.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrResolve$NeedRedirectMethod.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrResolve$NeedReplaceLambda.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrResolve$NeedReplaceLambda.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrResolve$ZrLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrResolve$ZrLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrResolve$ZrLookupHelper2.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrResolve$ZrLookupHelper2.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrResolve$ZrMethodReferenceLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrResolve$ZrMethodReferenceLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrResolve.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrResolve.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrResolveEx.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrResolveEx.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrScanner.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrScanner.clazz
--------------------------------------------------------------------------------
/javac/out/production/resources/clazz/java7/ZrScannerFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/out/production/resources/clazz/java7/ZrScannerFactory.clazz
--------------------------------------------------------------------------------
/javac/src/main/java/com/by122006/zircon/Parent.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon;
2 |
3 | public class Parent {
4 | boolean first;
5 | }
6 |
--------------------------------------------------------------------------------
/javac/src/main/java/com/by122006/zircon/ZirconExMethodPlugin.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon;
2 |
3 | import com.sun.tools.javac.main.JavaCompiler;
4 | import com.sun.tools.javac.util.Context;
5 |
6 | @SuppressWarnings({"unchecked", "rawtypes"})
7 | public class ZirconExMethodPlugin extends ZirconPlugin {
8 |
9 |
10 | @Override
11 | public String getName() {
12 | return "ZrExMethod";
13 | }
14 |
15 | @Override
16 | public String getCName() {
17 | return "拓展方法";
18 | }
19 |
20 |
21 | @Override
22 | public void startTask(Context context, JavaCompiler compiler, ClassLoader pcl, ClassLoader classLoader) throws Exception {
23 | if (!javaVersionUpper(11))
24 | reloadClassJavacVersion("com.sun.tools.javac.comp.ZrResolveEx", pcl, classLoader);
25 |
26 | reloadClass("com.sun.tools.javac.parser.CompareSameMethod", pcl, classLoader);
27 | reloadClass("com.sun.tools.javac.parser.CompareSameMethod$MethodInfo", pcl, classLoader);
28 | reloadClass("com.sun.tools.javac.parser.CompareSameMethod$CompareEnv", pcl, classLoader);
29 |
30 | reloadClassJavacVersion("com.sun.tools.javac.comp.NeedRedirectMethod", pcl, classLoader);
31 | reloadClassJavacVersion("com.sun.tools.javac.comp.NeedReplaceLambda", pcl, classLoader);
32 | reloadClassJavacVersion("com.sun.tools.javac.comp.ExMethodInfo", pcl, classLoader);
33 | reloadClassJavacVersion("com.sun.tools.javac.comp.ZrMethodReferenceLookupHelper", pcl, classLoader);
34 | reloadClassJavacVersion("com.sun.tools.javac.comp.ZrLookupHelper", pcl, classLoader);
35 | reloadClassJavacVersion("com.sun.tools.javac.comp.ZrLookupHelper2", pcl, classLoader);
36 |
37 |
38 | final Class> OOZrAttrClass = reloadClassJavacVersion("com.sun.tools.javac.comp.ZrAttr", pcl, classLoader);
39 | final Object myAttr = getInstance(OOZrAttrClass, context);
40 | set(compiler, "attr", myAttr);
41 | final Class> ZrResolve = reloadClassJavacVersion("com.sun.tools.javac.comp.ZrResolve", pcl, classLoader);
42 | getInstance(ZrResolve, context);
43 | }
44 |
45 | public boolean autoStart() {
46 | return true;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/javac/src/main/java/com/by122006/zircon/ZirconStringPlugin.java:
--------------------------------------------------------------------------------
1 | package com.by122006.zircon;
2 |
3 | import com.sun.tools.javac.main.JavaCompiler;
4 | import com.sun.tools.javac.parser.ParserFactory;
5 | import com.sun.tools.javac.parser.ScannerFactory;
6 | import com.sun.tools.javac.util.Context;
7 |
8 | import java.util.List;
9 |
10 | public class ZirconStringPlugin extends ZirconPlugin {
11 |
12 |
13 | @Override
14 | public String getName() {
15 | return "ZrString" ;
16 | }
17 |
18 | @Override
19 | public String getCName() {
20 | return "模板字符串" ;
21 | }
22 |
23 |
24 | @Override
25 | @SuppressWarnings("unchecked")
26 | public void startTask(Context context, JavaCompiler compiler, ClassLoader pcl, ClassLoader classLoader) throws Exception {
27 | reloadClass("com.sun.tools.javac.parser.Item", pcl, classLoader);
28 | reloadClass("com.sun.tools.javac.parser.ZrStringModel", pcl, classLoader);
29 | reloadClass("com.sun.tools.javac.parser.StringRange", pcl, classLoader);
30 | final Class> formatterClass = reloadClass("com.sun.tools.javac.parser.Formatter", pcl, classLoader);
31 | final List AllFormatters = (List) formatterClass.getMethod("getAllFormattersClazz").invoke(null);
32 | for (String clazz : AllFormatters) {
33 | reloadClass(clazz, pcl, classLoader);
34 | }
35 | reloadClassJavacVersion("com.sun.tools.javac.parser.ZrJavaTokenizer$JavaCException", pcl, classLoader);
36 | reloadClassJavacVersion("com.sun.tools.javac.parser.ZrJavaTokenizer", pcl, classLoader);
37 | reloadClassJavacVersion("com.sun.tools.javac.parser.ZrParserFactory", pcl, classLoader);
38 | reloadClassJavacVersion("com.sun.tools.javac.util.ZrJavadocTokenizer", pcl, classLoader);
39 | reloadClassJavacVersion("com.sun.tools.javac.util.ZrScanner", pcl, classLoader);
40 | Class> OOScannerFactoryClass = reloadClassJavacVersion("com.sun.tools.javac.util.ZrScannerFactory", pcl, classLoader);
41 | context.get(ScannerFactory.scannerFactoryKey);
42 | ParserFactory parserFactory = (ParserFactory) get(compiler, "parserFactory");
43 | Object instance = getInstance(OOScannerFactoryClass, context);
44 | set(parserFactory, "scannerFactory", instance);
45 | }
46 |
47 | public boolean autoStart() {
48 | return true;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/javac/src/main/resources/META-INF/services/com.sun.source.util.Plugin:
--------------------------------------------------------------------------------
1 | com.by122006.zircon.ZirconStringPlugin
2 | com.by122006.zircon.ZirconExMethodPlugin
3 |
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ExMethodInfo.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ExMethodInfo.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/NeedRedirectMethod.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/NeedRedirectMethod.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/NeedReplaceLambda.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/NeedReplaceLambda.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrAttr.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrAttr.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrJavaTokenizer$JavaCException.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrJavaTokenizer$JavaCException.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrJavaTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrJavaTokenizer.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrJavadocTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrJavadocTokenizer.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrLookupHelper2.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrLookupHelper2.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrMethodReferenceLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrMethodReferenceLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrParserFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrParserFactory.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrResolve.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrResolve.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrScanner.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrScanner.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java11/ZrScannerFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java11/ZrScannerFactory.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ExMethodInfo.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ExMethodInfo.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/NeedRedirectMethod.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/NeedRedirectMethod.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/NeedReplaceLambda.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/NeedReplaceLambda.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrAttr.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrAttr.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrJavaTokenizer$JavaCException.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrJavaTokenizer$JavaCException.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrJavaTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrJavaTokenizer.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrJavadocTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrJavadocTokenizer.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrLookupHelper2.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrLookupHelper2.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrMethodReferenceLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrMethodReferenceLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrParserFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrParserFactory.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrResolve.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrResolve.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrScanner.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrScanner.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java16/ZrScannerFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java16/ZrScannerFactory.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ExMethodInfo.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ExMethodInfo.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/NeedRedirectMethod.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/NeedRedirectMethod.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/NeedReplaceLambda.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/NeedReplaceLambda.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrAttr.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrAttr.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrJavaTokenizer$JavaCException.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrJavaTokenizer$JavaCException.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrJavaTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrJavaTokenizer.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrJavadocTokenizer.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrJavadocTokenizer.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrLookupHelper2.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrLookupHelper2.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrMethodReferenceLookupHelper.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrMethodReferenceLookupHelper.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrParserFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrParserFactory.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrResolve.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrResolve.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrResolveEx.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrResolveEx.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrScanner.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrScanner.clazz
--------------------------------------------------------------------------------
/javac/src/main/resources/clazz/java7/ZrScannerFactory.clazz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/javac/src/main/resources/clazz/java7/ZrScannerFactory.clazz
--------------------------------------------------------------------------------
/mds/README_ZrExMethod.md:
--------------------------------------------------------------------------------
1 | ### 什么是拓展方法
2 |
3 | > 能够向现有类型直接“添加”方法,而无需创建新的派生类型、重新编译或以其他方式修改现有类型。调用扩展方法的时候,与调用在类型中实际定义的方法相比没有明显的差异。
4 |
5 |
6 | ### 拓展方法的必要性
7 | > 拓展方法没有必要性。拓展方法只是为了能让你更简单地完成你的代码,专注于业务逻辑而不是各种工具类的记忆中。
8 | > 在任何场景,你都可以用工具类的静态方法以替换拓展方法的实现,但是拓展方法可以让你写得更轻松以及代码更加简洁。
9 | > 欢迎使用`Zircon`,希望能给你带来更好的java代码体验。
10 |
11 | ### 使用方法及注意事项
12 |
13 | > 在项目任意位置中,声明一个包含注解`@ExMethod`的方法。后续你可以在项目任何地方中使用这个方法。
14 |
15 | > 如何定义一个拓展方法?[*快速跳转至示例`ExMethodUtil`*](https://github.com/122006/ExMethodUtil/tree/main/impl/src/main/java/zircon/example)
16 |
17 |
18 | #### 1.添加静态方法
19 |
20 | ```
21 | @ExMethod(ex = {List.class})
22 | public static List synchronizedList(T... data){
23 | return Collections.synchronizedList(Arrays.asList(data));
24 | }
25 | ```
26 |
27 | > 以上方法声明了一个静态拓展方法:为List增加了一个传入泛型可变参数并返回同步列表的静态方法。\
28 | > 在任何地方,你可以`List.synchronizedList(xxxx)`以使用该方法\
29 | > 你可以声明多个类,以同时实现同个静态方法。也可以不使用大括号直接声明单个类\
30 | > 特别地,如果申明的方法为实例方法,且对Class进行代理,则调用时可以省略`.class`。如果如此调用,该行为类似于静态方法,且可以获得实际代理的Class类型
31 |
32 | #### 2.添加动态方法
33 |
34 | ```
35 | @ExMethod
36 | public static T find(Collection collection, Predicate predicate) {
37 | return collection.stream().filter(predicate).findFirst().orElse(null);
38 | }
39 | ```
40 |
41 | > 以上方法声明了一个动态拓展方法:为集合对象增加了一个方法以筛选出其中第一个符合条件的值。
42 | > 在方法外,你可以对集合对象调用`.find(it->it!=null)`以使用该方法。
43 |
44 | ```
45 | @ExMethod
46 | public static boolean isNull(Object obj) {
47 | return obj == null;
48 | }
49 | ```
50 |
51 | > 动态拓展方法的本质是将动态调用在编译时静态替换为静态方法。故而对null对象使用将不会抛出空指针异常。
52 | > 特别地,如果申明的方法为实例方法,且对Class进行代理,则调用时可以省略`.class`
53 |
54 | #### 3.已有方法替换
55 |
56 | ```
57 | @ExMethod(ex = {PrintStream.class},cover = true)
58 | public static void println(String a) {
59 | System.out.print("\n ex: success hook static method:" + a);
60 | }
61 | ```
62 |
63 | > 如果你声明的方法已有实现,你的方法不会生效。特别的,你可以指定`cover=true`以强制指向至你声明的方法
64 |
65 |
66 | #### 4.指定限制注解
67 |
68 | ```
69 | @ExMethod(ex = {Object.class}, filterAnnotation = {TestFilterAnnotation1.class, TestFilterAnnotation2.class})
70 | public static void staticTestFilterAnnotation() {
71 | methodNames.add("staticFatherMExtendRT(");
72 | }
73 | ```
74 |
75 | > 限制归属类必须包含指定注解
76 | > 使用中,如果是静态方法,其对应Class必须直接包含全部指定的注解,不支持继承
77 | > 如果是实例方法,其对应直接类型必须包含全部指定的注解,不支持继承
78 | > 注解会在编译阶段进行检查
79 |
80 | ----------------
81 |
82 | ### FAQ
83 |
84 | 1. 定义的方法可以影响到引用的依赖么?
85 |
86 | > 不可以,已经编译为class的代码无法进行修改。但是,如果在依赖中定义的拓展方法可以继续传递到你当前的项目中。
87 | > 你可以封装一个独立的拓展项目以应用到其他项目中。
88 | > 当然,后续更新中也会增加对已有class的修改需求(asm)、拓展方法作用域定义
89 |
90 | 2. ~~为什么我声明在`List`对象的方法在`List`上也能看到?~~
91 | > ~~声明的动态方法不会被类型参数限制。但是定义完备其代理对象的类型参数后,可以参与其他参数的类型推断。~~
92 | > ~~idea插件会下划线高亮该方法代理的对象~~
93 | > 现在(idea插件3.0及以上)已支持指定代理不同泛型参数的对象,以分配不同的方法。
94 |
95 | 3. 我可以代理数组么?
96 | > 数组是一个特殊的对象,可以代理数组。
97 | > ~~但是无法通过数组的类型来区分不同的对象(idea插件会下划线高亮数组中括号以提示)~~
98 | > 现在(idea插件3.0及以上)已支持指定代理不同类型的数组,以分配不同的方法。(基本类型数组和他们的包装器类型属于完全不同的类型,无法相互调用)
99 | > 以下提供了一个为数组对象增加add方法的拓展方法声明
100 |
101 | ```
102 | @ExMethod
103 | public static T[] add(T[] array,T... add) {
104 | final T[] nArray = (T[]) Array.newInstance(array.getClass().getComponentType(), array.length + add.length);
105 | System.arraycopy(array,0,nArray,0,array.length);
106 | System.arraycopy(add,0,nArray,array.length,add.length);
107 | return nArray;
108 | }
109 | ```
110 |
111 | 4. 我声明了动态拓展方法为什么没有反应(或者需要重启生效)?
112 | > 1. 收集拓展方法需要全局遍历,且该方法通常并不需要经常修改,故而拓展方法的缓存只有在部分时候进行更新。当你更新了拓展方法后,请sync项目而无需重新打开。
113 | > 2. 插件已提供手动同步方法与未同步警告,请根据idea提示进行修复即可
114 |
115 | 5. 为什么拓展方法需要import相关声明类?
116 | > 1. 在实际注入点声明前,引入涉及到的相关类,以保证能够正确替换
117 | > 2. 插件已支持自动引包
118 |
119 | 6. 相比lombok、manifold等有什么优势呢
120 | > 1. 更简单的声明:在任意代码地方可声明。只需要方法为静态且增加`@ExMethod`方法注解。不需要特殊包名或者引用处声明
121 | > 2. 更易用的泛型支持:支持方法参数泛型推导,不需要将方法泛型维护为原有类泛型名,且不需要手动绑定泛型关系。
122 | > 3. 更明确的泛型约束:非静态方法支持代理至复杂泛型。例:`flat()`方法只对`List>`可见
123 | > 4. idea插件支持更强:输入时支持方法匹配及提示
124 | > 5. lambda表达式、成员方法引用支持:支持面更广
125 | > 6. 拓展方法支持限制注解,更加适合Java项目
126 | >
127 | > 但是lombok真的好用,manifold其他功能是真的强,推荐搭配使用 ^^
128 |
--------------------------------------------------------------------------------
/mds/README_ZrString.md:
--------------------------------------------------------------------------------
1 | ### 什么叫内插字符串?
2 |
3 | > 字符串插值功能构建在复合格式设置功能的基础之上,提供更具有可读性、更方便的语法,用于将表达式结果包括到结果字符串。
4 |
5 | >对某个表达式执行计算后,其结果立即转换为一个字符串并包含到结果字符串中
6 |
7 | ### 如何使用内插字符串
8 |
9 | >若要将字符串标识为内插字符串,可在该字符串前面加上 `$`或`f` 符号。 可嵌入任何会在内插字符串中返回值的有效 JAVA 表达式。
10 |
11 |
12 |
13 | ### 效果图
14 |
15 | 
16 |
17 | 常见字符串拼接写法对比
18 | 
19 |
20 | ----------------
21 | ### 使用示例
22 |
23 |
24 | `String text=f" this is F-$String.class.getSimpleName() ";`
25 |
26 | `assert Objects.equals($"Zircon: [ ${text.trim()} ]","Zircon: [ "+text.trim()+" ]");`
27 |
28 | ----------------
29 |
30 | ### 高级语法糖
31 |
32 | 1. 根据字符串前的前缀不同,拥有不同的字符串内插逻辑,请注意区别使用
33 |
34 | #### 1. `$`前缀字符串(`$-string`):
35 |
36 | > 直接使用加号进行字符串的拼接,拥有最快的运行
37 |
38 | 1. JDK1.6的情况,javac遇到加号(`+`)链接的字符串会自动转化成`StringBuilder.append()`,不存在加号连接字符串额外的对象开销
39 |
40 | 2. 如果首个子部分为非硬编码字符串,会自动包裹`String.valueOf()`以防止拼接异常
41 |
42 | #### 2. `f`前缀字符串(`f-string`):
43 |
44 | > 使用String.format函数进行拼接,速度相比`$-string`较慢
45 |
46 | 1. 如果是使用大括号包裹的`${}`代码块,你可以指定的每个内插代码块的显示格式:
47 | 在代码块的前部,增加一个以`%`号开始的`String.format`格式化标识,并且使用`:`与后续代码块进行分隔 。形如:`${%03d:12}`会输出`012`的格式化结果
48 |
49 |
50 | 2. 未被大括号`{}`包裹的简易代码块,拥有java特性自动识别代码范围的功能
51 |
52 | 1. 请不要完全依赖该功能,只能简单判断括号匹配及后续引用,复杂语句请使用`${}`
53 |
54 | 2. 如果要使用该功能,请注意根据插件提示的java代码注入范围来判断是否使用错误
55 |
56 | 3. 字符串中代码段支持直接使用引号而不需要转义(需配置1.9版本以上idea插件+v2.5以上编译插件)
57 |
58 | > 在2.0及以上版本,**不再支持使用单引号替代双引号**,单引号转义在复杂字符串中难以进行解析。
59 | >
60 | > 你可以使用正则 `(\$|f)"(.*'.*)+?"` 全局搜索项目以找到可能影响的地方
61 |
--------------------------------------------------------------------------------
/mds/TODO:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/mds/TODO
--------------------------------------------------------------------------------
/mds/zhihu.md:
--------------------------------------------------------------------------------
1 | ##### 最近写了个java语法相关的库,为java支持了拓展函数和模板字符串。
2 |
3 | ## Zircon (github路径为122006/Zircon)
4 |
5 | > 引入该库可以为原有java的项目基础上自由使用拓展函数和模板字符串的语法。
6 |
7 | 3分钟上手,尽力减少学习成本,使用无感知。
8 |
9 | ## 1. 拓展方法
10 |
11 | ### 什么是拓展方法
12 |
13 | > 能够向现有类型直接“添加”方法,而无需创建新的派生类型、重新编译或以其他方式修改现有类型。调用扩展方法的时候,与调用在类型中实际定义的方法相比没有明显的差异。
14 |
15 |
16 | ### 拓展方法的必要性
17 | > 拓展方法没有必要性。拓展方法只是为了能让你更简单地完成你的代码,专注于业务逻辑而不是各种工具类的记忆中。
18 | >
19 | > 在任何场景,你都可以用工具类的静态方法以替换拓展方法的实现,但是拓展方法可以让你写得更嗨以及代码更加简洁。
20 | >
21 | > 比如java的集合类不好用,你可以设计个第三方库叫JAVA-Collection-plus,让引用其的项目都能使用自定义且强壮的方法
22 | >
23 | > 欢迎使用`Zircon`,希望能给你带来更好的java代码体验。
24 |
25 |
26 | ### 使用方法及注意事项
27 |
28 | > 在项目任意位置中,声明一个包含注解`@ExMethod`的方法。后续你可以在该项目、及引入该项目的项目的任何地方中使用这个方法。
29 |
30 | ## 2. 内插字符串
31 |
32 | ### 什么叫内插字符串?
33 |
34 | > 字符串插值功能构建在复合格式设置功能的基础之上,提供更具有可读性、更方便的语法,用于将表达式结果包括到结果字符串。
35 |
36 | > 对某个表达式执行计算后,其结果立即转换为一个字符串并包含到结果字符串中
37 |
38 | ### 如何使用内插字符串
39 |
40 | >若要将字符串标识为内插字符串,可在该字符串前面加上 `$`或`f` 符号。 可嵌入任何会在内插字符串中返回值的有效 JAVA 表达式。
41 |
42 |
43 |
44 | ## 常见问题回答:
45 | 1. 为什么不用kotlin:
46 | > 一个项目切kotlin麻烦,但是这个库引用之后就可以直接使用,几乎0改造成本
47 | 2. 你在生产环境上用么?
48 | > 该库都是编译时织入,对运行没有任何影响。(个人项目用得爽得了)
49 | 3. 为什么不用lombok、manifold?
50 | > lombok的拓展方法用起来很麻烦,实用性很低。manifold的拓展方法和模板字符串方面有部分缺陷,功能上也更局限,而且太重了。
51 | 4. 公司都不用lombok,为啥要用你这个
52 | > 说得对,但是个人项目真的写得很爽~ :)
53 | 5. java21已经支持了模板字符串
54 | > 众所众知中国互联网的java版本只有8。本库可以给各个java版本增加模板字符串功能
55 |
56 |
57 | github传送门:https://github.com/122006/Zircon
58 | 欢迎各位大佬指教(走过路过给个star呗~
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/others/exmethod_show.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/others/exmethod_show.png
--------------------------------------------------------------------------------
/others/exmethod_show2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/others/exmethod_show2.png
--------------------------------------------------------------------------------
/others/exmethod_show3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/others/exmethod_show3.png
--------------------------------------------------------------------------------
/others/exmethod_show4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/others/exmethod_show4.gif
--------------------------------------------------------------------------------
/others/zircon_show.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/others/zircon_show.png
--------------------------------------------------------------------------------
/others/zircon_show2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/others/zircon_show2.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("org.gradle.toolchains.foojay-resolver") version "0.8.0"
3 | }
4 |
5 | rootProject.name = 'Zircon'
6 | include ':javac'
7 | include ':zircon'
8 | include ':base'
9 | include ':gradle_plugin'
10 |
11 | if (System.getProperty("user.name", "") == "jitpack") {
12 | System.out.println("build by JITPACK")
13 | } else {
14 | include ':ijplugin'
15 | include ':test'
16 | include ':inject_java7'
17 | include ':inject_java11'
18 | include ':inject_java16'
19 | }
20 |
21 |
22 |
23 | toolchainManagement {
24 | jvm {
25 | javaRepositories {
26 | repository("foojay") {
27 | resolverClass = org.gradle.toolchains.foojay.FoojayToolchainResolver
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/test/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | maven {
4 | url uri('../../repo')
5 | }
6 | maven { url 'https://jitpack.io' }
7 | }
8 | dependencies {
9 | // classpath 'com.github.122006.Zircon:gradle:2.8t'
10 | }
11 | }
12 | apply plugin: 'java'
13 | //apply plugin: 'zircon'
14 |
15 | java.getToolchain().languageVersion = JavaLanguageVersion.of(rootProject.extensions.ext.testJavaVersion)
16 |
17 | repositories {
18 | maven { url 'https://maven.aliyun.com/repository/public/' }
19 | maven {
20 | url uri('../../repo')
21 | }
22 | maven { url 'https://jitpack.io' }
23 | mavenCentral()
24 | }
25 |
26 |
27 |
28 | //sourceCompatibility = JavaVersion.VERSION_1_8
29 | //targetCompatibility = JavaVersion.VERSION_1_8
30 |
31 | test {
32 | useJUnitPlatform()
33 | testLogging {
34 | events "passed", "skipped", "failed", "STANDARD_OUT", "STANDARD_ERROR"
35 | }
36 | }
37 | dependencies {
38 | annotationProcessor project(":javac")
39 | implementation project(":zircon")
40 | annotationProcessor "org.projectlombok:lombok:1.18.20"
41 | compileOnly 'org.projectlombok:lombok:1.18.20'
42 | implementation('com.github.122006:ExMethodUtil:1.1.7') {
43 | exclude group: 'com.github.122006.zircon', module: 'zircon'
44 | }
45 | implementation 'com.alibaba:fastjson:1.1.72.android'
46 | implementation('org.springframework.boot:spring-boot-starter-web:2.7.3')
47 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
48 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
49 | testAnnotationProcessor project(":javac")
50 | }
51 | tasks.withType(JavaCompile).configureEach {
52 | javaCompiler = javaToolchains.compilerFor {
53 | languageVersion = JavaLanguageVersion.of(rootProject.extensions.ext.testJavaVersion)
54 | }
55 | if (rootProject.extensions.ext.testJavaVersion <= 11) {
56 | options.compilerArgs << "-Xplugin:ZrExMethod"
57 | options.compilerArgs << "-Xplugin:ZrString"
58 | }
59 | def version = (it as JavaCompile).javaCompiler.get().metadata.languageVersion.asInt()
60 | if (version >= 21) {
61 | options.compilerArgs += "--enable-preview"
62 | }
63 | options.fork = true;
64 | }
65 | tasks.withType(Test).configureEach {
66 | javaLauncher = javaToolchains.launcherFor {
67 | languageVersion = JavaLanguageVersion.of(rootProject.extensions.ext.testJavaVersion)
68 | }
69 | if (rootProject.extensions.ext.testJavaVersion >= 21) {
70 | jvmArgs += "--enable-preview"
71 | }
72 | }
73 | tasks.withType(JavaExec).configureEach {
74 | jvmArgs += "--enable-preview"
75 | }
--------------------------------------------------------------------------------
/test/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.7-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/test/src/test/java/RootExMethod.java:
--------------------------------------------------------------------------------
1 | import test.TestExMethod;
2 | import zircon.ExMethod;
3 |
4 | public class RootExMethod {
5 | @ExMethod
6 | public static void testSameMethod1(Object object,Number arg0, String arg1) {
7 | TestExMethod.methodNames.add("RootExMethod,testSameMethod1");
8 | }
9 |
10 | @ExMethod
11 | public static void testSameMethod2(Object object,Number arg0, String arg1) {
12 | TestExMethod.methodNames.add("RootExMethod,testSameMethod2");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/test/src/test/java/test/NearExMethod.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import zircon.ExMethod;
4 |
5 | public class NearExMethod {
6 | @ExMethod
7 | public static void testSameMethod1(Object object,Number arg0, String arg1) {
8 | TestExMethod.methodNames.add("NearExMethod,testSameMethod1");
9 | }
10 |
11 | @ExMethod
12 | public static void testSameMethod2(Object object,Number arg0, String arg1) {
13 | TestExMethod.methodNames.add("NearExMethod,testSameMethod2");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/test/src/test/java/test/TestClass2.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | import zircon.example.ExObject;
7 |
8 |
9 | public class TestClass2 {
10 | @SpringBootApplication
11 | public static class GradleDemoApplication {
12 | public static void main(String[] args) {
13 | System.out.println("31231".isNull());
14 | SpringApplication.run(GradleDemoApplication.class, args);
15 | }
16 | }
17 |
18 | public static void main(String[] args) {
19 | System.out.println("31231".isNull());
20 |
21 | // String nullStr = null;
22 | // System.out.println(("2131" + "12312").concat("123"));
23 | // System.out.println(Test.addStatic("test", "test2"));
24 | // System.out.println(new Test().add("test", 2));
25 | // System.out.println(new TestChildren().add("test", 2));
26 | // System.out.println(("2131" + "12312").add("123"));
27 | // System.out.println(("2131".toString()).add("123", "456"));
28 | // System.out.println(("2131").add("123", BigDecimal.ZERO));
29 | // System.out.println("".isEmpty());
30 | // System.out.println(nullStr.isEmpty());
31 | // System.out.println("2131".add("12").add("123type2").add("4112").add(1).add("123type3"));
32 | //// System.out.println("2131".add(1));
33 | // System.out.println(Integer.addStatic("a"));
34 | // System.out.println((Integer.valueOf("1")).addStatic("a"));
35 | // System.out.println(((Integer.valueOf("1") == null ? null : (Integer.valueOf("2")).addStatic("a"))).addStatic("a"));
36 | // (Test.getIntegerReturn("123")).addStaticRVoid("a");
37 | // System.out.println(java.lang.String.addStatic("a"));
38 | //// System.out.println((Integer.valueOf("1")).toString(1,1));
39 | //
40 | // Test testOi = new Test() {
41 | // public Object apply(Object b) {
42 | // return super.addForTest("123", 1);
43 | // }
44 | // };
45 | // ("2131" + "12312").add("123");
46 | //// Function function = a -> Integer.addStatic(a);
47 | //// function.apply("function");
48 | // new ArrayList().addList("12", "32");
49 | // System.out.println((new String[1]).add("123")[1]);
50 | // Integer testString = 456;
51 | // final List collect2 = Stream.of(123, 543).map(Test::addStatic2).list();
52 | // Stream.of("1").map(TestExMethod::add3).collect(Collectors.toList());
53 | // Stream.of("1").map(String::add3).collect(Collectors.toList());
54 | // Stream.of("1").map(String::add2).collect(Collectors.toList());
55 | //// System.out.println("lambda2=" + collect2);
56 | // BiFunction a = Test::addStatic;
57 | // System.out.println("lambda3=" + a.apply("12", 3));
58 | // final List collect4 = Stream.of("122", "132").map(System.out::append).list();
59 | // System.out.println("lambda4=" + collect4);
60 | //// Function b = ""::addStatic;
61 | //// System.out.println("test lambda b=" + b);
62 | // final Stream stringStream = Stream.of("12", "13");
63 | //// final Stream mapStream = stringStream.map(""::toInteger);
64 | //// final List collect = mapStream.collect(Collectors.toList());
65 | //// System.out.println("lambda1="+collect);
66 | // final Stream mapStream2 = stringStream.map((String str) -> "concat".concat(str));
67 | // final List collect5 = mapStream2.list();
68 | // System.out.println("lambda5=" + collect5);
69 | // }
70 | //
71 | // private static String apply(String a) {
72 | // return a.add("12");
73 | // }
74 | //
75 | // public static class TestChildren extends Test {
76 | // public static void testStaticMethod() {
77 | // }
78 | //
79 | // public void test() {
80 | // TestChildren.testStaticMethod();
81 | // }
82 | // }
83 | //
84 | //
85 | // public static void a() {
86 | // String a = "";
87 | // String b = (a + null).concat("12");
88 | // }
89 | //
90 | // public static void b() {
91 | // String a = "";
92 | //// String b=Test.add(a+null,"12");
93 | // }
94 | //
95 | // public static void c() {
96 | // String a = "";
97 | //// Function function= obj -> Test.add(a+null,"12");
98 | // }
99 | //
100 | // public static void d() {
101 | // String b = "";
102 | // Function function = (String a) -> a.concat("12");
103 | // }
104 | //
105 | // public static class Test {
106 | // public static void testStaticMethod() {
107 | // }
108 | //
109 | // }
110 | //
111 | //
112 | // public static class Test2 {
113 | // public static String add23(String a, String b) {
114 | // return a + b;
115 | // }
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/test/src/test/java/test/TestImport.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import zircon.example.ExObject;
5 | import zircon.example.ExString;
6 |
7 | public class TestImport {
8 | public String a23 = "";
9 | public String a24 = "";
10 |
11 | /**
12 | * 123
13 | */
14 | //123
15 | @Test
16 | public void test() {
17 | a23.nullOr("123");
18 | a23.nullOr("123");
19 |
20 | String a23 = $"{${"123".toBigDecimal()}}";
21 | a23 = "123";
22 |
23 |
24 | }
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/test/src/test/java/test/TestNoEncounteredMethod.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import zircon.ExMethod;
4 |
5 | public class TestNoEncounteredMethod {
6 | @ExMethod
7 | public static String testNoEncounteredMethod(String str) {
8 | return str;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/test/src/test/java/test/TextStringFormat2.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 |
4 | public class TextStringFormat2 {
5 | // static Logger logger = Logger.getLogger(TextStringFormat2.class.getSimpleName());
6 | //
7 | // public static void main(String[] str) {
8 | // String las = "1234";
9 | // System.out.println(las);
10 | // String testOther = $"$TextStringFormat.test2" +
11 | // $"";
12 | //
13 | //
14 | // User user = new User();
15 | //
16 | // String show = null;
17 | // //Zircon内插字符串
18 | // show = f"${user.name}是一个${user.age}岁的${user.gender?"男生":"女生"},工号是${%06d:user.number}";
19 | // //Zircon内插字符串(收缩后)
20 | // show = f"${user.name}是一个${user.age}岁的${user.gender?"男生":"女生"},工号是${%06d:user.number}";
21 | //
22 | // //'+'号拼接
23 | // show = user.name + "是一个" + user.age + "岁的" + (user.gender ? "男生" : "女生") + ",工号是" + fillNumberStringWithLeftZero(user.number);
24 | // //String.format
25 | // show = String.format(Locale.getDefault(), "%s是一个%d岁的%s,工号是%06d", user.name, user.age
26 | // , user.gender ? "男生" : "女生", user.number);
27 | //
28 | // }
29 | //
30 | // private static String fillNumberStringWithLeftZero(int number) {
31 | // return "";
32 | // }
33 | //
34 | //
35 | // public static void test2(String arg0, int arg1) {
36 | // String arg3 = "2131231";
37 | // }
38 | //
39 | // private static class User {
40 | // String name = "小明";
41 | // int number = 1234;
42 | // int age = 24;
43 | // boolean gender = true;
44 | // }
45 | }
46 |
--------------------------------------------------------------------------------
/test/src/test/java/test/child/ChildExMethod.java:
--------------------------------------------------------------------------------
1 | package test.child;
2 |
3 | import test.TestExMethod;
4 | import zircon.ExMethod;
5 |
6 | public class ChildExMethod {
7 | @ExMethod
8 | public static void testSameMethod1(Object object,Number arg0, String arg1) {
9 | TestExMethod.methodNames.add("ChildExMethod,testSameMethod1");
10 | }
11 |
12 | @ExMethod
13 | public static void testSameMethod2(Object object,Number arg0, String arg1) {
14 | TestExMethod.methodNames.add("ChildExMethod,testSameMethod2");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/test/src/test/java/test/extendsobj/ChildChildObj.java:
--------------------------------------------------------------------------------
1 | package test.extendsobj;
2 |
3 | /**
4 | * @ClassName: ChildObj
5 | * @Author: 122006
6 | * @Date: 2025/1/21 16:59
7 | * @Description:
8 | */
9 | public class ChildChildObj extends ChildObj {
10 | }
11 |
--------------------------------------------------------------------------------
/test/src/test/java/test/extendsobj/ChildObj.java:
--------------------------------------------------------------------------------
1 | package test.extendsobj;
2 |
3 | /**
4 | * @ClassName: ChildObj
5 | * @Author: 122006
6 | * @Date: 2025/1/21 16:59
7 | * @Description:
8 | */
9 | public class ChildObj extends FatherObj{
10 | }
11 |
--------------------------------------------------------------------------------
/test/src/test/java/test/extendsobj/FatherObj.java:
--------------------------------------------------------------------------------
1 | package test.extendsobj;
2 |
3 | /**
4 | * @ClassName: ChildObj
5 | * @Author: 122006
6 | * @Date: 2025/1/21 16:59
7 | * @Description:
8 | */
9 | public class FatherObj {
10 | }
11 |
--------------------------------------------------------------------------------
/test/src/test/java/test/filter/FilterAnnotation.java:
--------------------------------------------------------------------------------
1 | package test.filter;
2 |
3 | public class FilterAnnotation {
4 | public static class NoAnnotation {
5 |
6 | }
7 |
8 | @TestFilterAnnotation2
9 | @TestFilterAnnotation1
10 | public static class HasFilterAnnotation {
11 |
12 | }
13 |
14 | public static class HasFilterAnnotationExtend extends HasFilterAnnotation {
15 |
16 | }
17 |
18 | public static class HasFilterAnnotation2 {
19 |
20 | }
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/test/src/test/java/test/filter/TestFilterAnnotation1.java:
--------------------------------------------------------------------------------
1 | package test.filter;
2 |
3 | public @interface TestFilterAnnotation1 {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/test/src/test/java/test/filter/TestFilterAnnotation2.java:
--------------------------------------------------------------------------------
1 | package test.filter;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Inherited;
5 | import java.lang.annotation.Target;
6 |
7 | @Inherited
8 | @Target(ElementType.TYPE)
9 | public @interface TestFilterAnnotation2 {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/tools/tools.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/122006/Zircon/0c6dd7235c9109e5f0fd66dd38373226ca505065/tools/tools.jar
--------------------------------------------------------------------------------
/zircon/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'maven-publish'
4 | }
5 |
6 | repositories {
7 | maven { url 'https://maven.aliyun.com/repository/public/' }
8 | mavenCentral()
9 | maven {
10 | url uri('../../repo')
11 | }
12 | }
13 | dependencies {
14 |
15 | }
16 |
17 | compileJava {
18 | sourceCompatibility = JavaVersion.VERSION_1_8
19 | targetCompatibility = JavaVersion.VERSION_1_8
20 | options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore:symbol.file"
21 | }
22 |
23 | task sourceJar(type: Jar) {
24 | from sourceSets.main.allJava
25 | archiveClassifier = "sources"
26 | }
27 |
28 | publishing {
29 | publications {
30 | maven(MavenPublication) {
31 | groupId "com.github.122006.Zircon"
32 | artifactId "zircon"
33 | version rootProject.ext.version
34 | from components.java
35 | artifact sourceJar
36 | }
37 | }
38 | repositories {
39 | maven {
40 | url = uri('../../repo')
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/zircon/src/main/java/zircon/BiOp.java:
--------------------------------------------------------------------------------
1 | package zircon;
2 |
3 | public class BiOp {
4 | public static void sInvoke(Object obj, Void cName) {
5 | }
6 |
7 | public static T sec(Object obj, T obj2) {
8 | return obj2;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/zircon/src/main/java/zircon/ExMethod.java:
--------------------------------------------------------------------------------
1 | package zircon;
2 |
3 | import java.lang.annotation.*;
4 |
5 | /**
6 | * 拓展方法标识,在你需要声明为拓展方法的原始方法上增加该注解。
7 | * 如果你需要申明实例拓展方法,指定原始方法的首个参数为拓展对象的类型,支持复杂泛型,在实际运行中会传入拓展对象实例。
8 | * 如果你需要申明静态拓展方法,你需要使用ex参数指定拓展对象类型。
9 | * 特别的,如果申明实例拓展方法,拓展对象类型为Class,调用时.class可省略,其作用效果与静态方法相似,但是会额外获得该Class实例。
10 | */
11 | @Target({ElementType.METHOD})
12 | @Retention(RetentionPolicy.RUNTIME)
13 | public @interface ExMethod {
14 | /**
15 | * 当方法需要注册为静态方法时,声明静态方法所在的类。
16 | * 可以复数指定。
17 | * 当指定了该参数时,方法中首个变量不再指向方法的调用者对象
18 | */
19 | Class>[] ex() default {};
20 |
21 | /**
22 | * 限制归属类必须包含指定注解
23 | * 使用中,如果是静态方法,其对应Class必须直接包含全部指定的注解,不支持继承
24 | * 如果是实例方法,其对应直接类型必须包含全部指定的注解,不支持继承
25 | * 注解会在编译阶段进行检查
26 | */
27 | Class extends Annotation>[] filterAnnotation() default {};
28 |
29 | /**
30 | * 当方法已有java实现时:false(默认):不覆盖原有方法实现。true:覆盖原有方法实现
31 | */
32 | boolean cover() default false;
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/zircon/src/main/java/zircon/ExMethodIDE.java:
--------------------------------------------------------------------------------
1 | package zircon;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Target({ElementType.METHOD})
9 | @Retention(RetentionPolicy.RUNTIME)
10 | public @interface ExMethodIDE {
11 | /**
12 | * 标记是否需要直接调用:false(默认):无限制。true:只能在类中直接调用
13 | * 不会限制编译时校验,错误使用时不会报错,仅在IDE联想提示时生效
14 | */
15 | boolean shouldInvokeDirectly() default false;
16 | }
17 |
--------------------------------------------------------------------------------