) {
19 | project.tasks.create(taskName) {
20 | it.doLast {
21 | //
22 | project.configurations.getByName(configurationName).resolvedConfiguration.resolvedArtifacts.forEach {
23 | // 版本
24 | println(it.moduleVersion.toString()+" --> "+it.file)
25 | }
26 |
27 |
28 | val list = project.configurations.getByName(configurationName).asPath.split(File.pathSeparator)
29 | .toList()
30 |
31 | IndexHtml.cleanSection()
32 |
33 | val startTime = System.currentTimeMillis()
34 |
35 | checkFiles.forEach {
36 | it.onStart()
37 | }
38 |
39 | list.forEach { path ->
40 | val input = FileInputStream(path)
41 | val zipInputStream = ZipInputStream(BufferedInputStream(input))
42 | var ze: ZipEntry?
43 | while (zipInputStream.nextEntry.also { ze = it } != null) {
44 | if (ze!!.isDirectory) {
45 | continue
46 | }
47 | checkFiles.forEach { fileCheck ->
48 | val lastIndex = path.lastIndexOf("/") + 1
49 | fileCheck.onIteratorFile(path.substring(0, lastIndex), path.substring(lastIndex), ze!!.name, ze!!.size, zipInputStream)
50 | }
51 | }
52 | zipInputStream.closeEntry()
53 | input.close()
54 | }
55 |
56 | checkFiles.forEach {
57 | it.onEnd()
58 | }
59 |
60 | val endTime = System.currentTimeMillis()
61 | println("耗时:" + ((endTime - startTime) / 1000f) + "s")
62 |
63 | generatorHtml()
64 | }
65 | }
66 | }
67 |
68 | private fun generatorHtml() {
69 | val buildDir = File(project.buildDir.absolutePath)
70 | if (!buildDir.exists()) {
71 | buildDir.mkdir()
72 | }
73 |
74 | // 写文件
75 | val tempDir = File(project.buildDir.absolutePath + File.separator + "checkPlugin")
76 | if (!tempDir.exists()) {
77 | tempDir.mkdir()
78 | }
79 |
80 | val htmlFile = File(tempDir, "check.html")
81 | if (htmlFile.exists()) {
82 | htmlFile.delete()
83 | }
84 |
85 | htmlFile.createNewFile()
86 | htmlFile.writeText(IndexHtml.getHtml())
87 |
88 | println("report file:" + htmlFile.absolutePath)
89 | }
90 |
91 | }
--------------------------------------------------------------------------------
/plugin/classAnalysis/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/plugin/classAnalysis/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'kotlin'
3 | apply plugin: 'java-gradle-plugin'
4 | apply plugin: 'maven-publish'
5 |
6 | dependencies {
7 | implementation gradleApi()
8 | implementation localGroovy()
9 | api "com.android.tools.build:gradle-api:$apgVersion"
10 | api "com.android.tools.build:gradle:$apgVersion"
11 | implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
12 | implementation 'com.google.code.gson:gson:2.10'
13 | }
14 |
15 | gradlePlugin {
16 | plugins {
17 | version {
18 | id = 'classAnalysisPlugin'
19 | implementationClass = 'com.codelang.parse.ClassAnalysis'
20 | }
21 | }
22 | }
23 | version="1.0.0"
24 |
25 | afterEvaluate {
26 | publishing {
27 | publications {
28 | maven(MavenPublication) {
29 | from components.java
30 | groupId = "com.github.MRwangqi"
31 | artifactId = "classAnalysis"
32 | version = "1.0.0"
33 | }
34 | }
35 |
36 | repositories {
37 | maven {
38 | url = uri("../../build/Maven")
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/AnnotationDefault_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.15.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class AnnotationDefault_attribute extends Attribute {
39 | AnnotationDefault_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(name_index, length);
42 | default_value = Annotation.element_value.read(cr);
43 | }
44 |
45 | public AnnotationDefault_attribute(ConstantPool constant_pool, Annotation.element_value default_value)
46 | throws ConstantPoolException {
47 | this(constant_pool.getUTF8Index(Attribute.AnnotationDefault), default_value);
48 | }
49 |
50 | public AnnotationDefault_attribute(int name_index, Annotation.element_value default_value) {
51 | super(name_index, default_value.length());
52 | this.default_value = default_value;
53 | }
54 |
55 | public R accept(Visitor visitor, D data) {
56 | return visitor.visitAnnotationDefault(this, data);
57 | }
58 |
59 | public final Annotation.element_value default_value;
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/AttributeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | /*
29 | * This is NOT part of any supported API.
30 | * If you write code that depends on this, you do so at your own risk.
31 | * This code and its internal interfaces are subject to change or
32 | * deletion without notice.
33 | */
34 | public class AttributeException extends Exception {
35 | private static final long serialVersionUID = -4231486387714867770L;
36 | AttributeException() { }
37 |
38 | AttributeException(String msg) {
39 | super(msg);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/CompilationID_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | *
This is NOT part of any supported API.
32 | * If you write code that depends on this, you do so at your own risk.
33 | * This code and its internal interfaces are subject to change or
34 | * deletion without notice.
35 | */
36 | public class CompilationID_attribute extends Attribute {
37 |
38 | CompilationID_attribute(ClassReader cr, int name_index, int length) throws IOException {
39 | super(name_index, length);
40 | compilationID_index = cr.readUnsignedShort();
41 | }
42 |
43 | public CompilationID_attribute(ConstantPool constant_pool, int compilationID_index)
44 | throws ConstantPoolException {
45 | this(constant_pool.getUTF8Index(Attribute.CompilationID), compilationID_index);
46 | }
47 |
48 | public CompilationID_attribute(int name_index, int compilationID_index) {
49 | super(name_index, 2);
50 | this.compilationID_index = compilationID_index;
51 | }
52 |
53 | String getCompilationID(ConstantPool constant_pool)
54 | throws ConstantPoolException {
55 | return constant_pool.getUTF8Value(compilationID_index);
56 | }
57 |
58 | public R accept(Visitor visitor, D data) {
59 | return visitor.visitCompilationID(this, data);
60 | }
61 |
62 | public final int compilationID_index;
63 | }
64 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/ConstantPoolException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | /*
29 | * This is NOT part of any supported API.
30 | * If you write code that depends on this, you do so at your own risk.
31 | * This code and its internal interfaces are subject to change or
32 | * deletion without notice.
33 | */
34 | public class ConstantPoolException extends Exception {
35 | private static final long serialVersionUID = -2324397349644754565L;
36 | ConstantPoolException(int index) {
37 | this.index = index;
38 | }
39 |
40 | public final int index;
41 | }
42 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/ConstantValue_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.2.
32 | *
33 | *
This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class ConstantValue_attribute extends Attribute {
39 | ConstantValue_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | constantvalue_index = cr.readUnsignedShort();
42 | }
43 |
44 | public ConstantValue_attribute(ConstantPool constant_pool, int constantvalue_index)
45 | throws ConstantPoolException {
46 | this(constant_pool.getUTF8Index(Attribute.ConstantValue), constantvalue_index);
47 | }
48 |
49 | public ConstantValue_attribute(int name_index, int constantvalue_index) {
50 | super(name_index, 2);
51 | this.constantvalue_index = constantvalue_index;
52 | }
53 |
54 | public R accept(Visitor visitor, D data) {
55 | return visitor.visitConstantValue(this, data);
56 | }
57 |
58 | public final int constantvalue_index;
59 | }
60 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/DefaultAttribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | /*
29 | * This is NOT part of any supported API.
30 | * If you write code that depends on this, you do so at your own risk.
31 | * This code and its internal interfaces are subject to change or
32 | * deletion without notice.
33 | */
34 | public class DefaultAttribute extends Attribute {
35 | DefaultAttribute(ClassReader cr, int name_index, byte[] data) {
36 | this(cr, name_index, data, null);
37 | }
38 |
39 | DefaultAttribute(ClassReader cr, int name_index, byte[] data, String reason) {
40 | super(name_index, data.length);
41 | info = data;
42 | this.reason = reason;
43 | }
44 |
45 | public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) {
46 | this(constant_pool, name_index, info, null);
47 | }
48 |
49 | public DefaultAttribute(ConstantPool constant_pool, int name_index,
50 | byte[] info, String reason) {
51 | super(name_index, info.length);
52 | this.info = info;
53 | this.reason = reason;
54 | }
55 |
56 | public R accept(Visitor visitor, P p) {
57 | return visitor.visitDefault(this, p);
58 | }
59 |
60 | public final byte[] info;
61 | /** Why did we need to generate a DefaultAttribute
62 | */
63 | public final String reason;
64 | }
65 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/Deprecated_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.15.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class Deprecated_attribute extends Attribute {
39 | Deprecated_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | }
42 |
43 | public Deprecated_attribute(ConstantPool constant_pool)
44 | throws ConstantPoolException {
45 | this(constant_pool.getUTF8Index(Attribute.Deprecated));
46 | }
47 |
48 | public Deprecated_attribute(int name_index) {
49 | super(name_index, 0);
50 | }
51 |
52 | public R accept(Visitor visitor, D data) {
53 | return visitor.visitDeprecated(this, data);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/DescriptorException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | /*
29 | * This is NOT part of any supported API.
30 | * If you write code that depends on this, you do so at your own risk.
31 | * This code and its internal interfaces are subject to change or
32 | * deletion without notice.
33 | */
34 | public class DescriptorException extends Exception {
35 | private static final long serialVersionUID = 2411890273788901032L;
36 | }
37 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/EnclosingMethod_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 |
27 | package classfile;
28 |
29 | import java.io.IOException;
30 |
31 | /**
32 | * See JVMS, section 4.8.7.
33 | *
34 | *
This is NOT part of any supported API.
35 | * If you write code that depends on this, you do so at your own risk.
36 | * This code and its internal interfaces are subject to change or
37 | * deletion without notice.
38 | */
39 | public class EnclosingMethod_attribute extends Attribute {
40 | EnclosingMethod_attribute(ClassReader cr, int name_index, int length) throws IOException {
41 | super(name_index, length);
42 | class_index = cr.readUnsignedShort();
43 | method_index = cr.readUnsignedShort();
44 | }
45 |
46 | public EnclosingMethod_attribute(ConstantPool constant_pool, int class_index, int method_index)
47 | throws ConstantPoolException {
48 | this(constant_pool.getUTF8Index(Attribute.EnclosingMethod), class_index, method_index);
49 | }
50 |
51 | public EnclosingMethod_attribute(int name_index, int class_index, int method_index) {
52 | super(name_index, 4);
53 | this.class_index = class_index;
54 | this.method_index = method_index;
55 | }
56 |
57 | public String getClassName(ConstantPool constant_pool) throws ConstantPoolException {
58 | return constant_pool.getClassInfo(class_index).getName();
59 | }
60 |
61 | public String getMethodName(ConstantPool constant_pool) throws ConstantPoolException {
62 | if (method_index == 0)
63 | return "";
64 | return constant_pool.getNameAndTypeInfo(method_index).getName();
65 | }
66 |
67 | public R accept(Visitor visitor, D data) {
68 | return visitor.visitEnclosingMethod(this, data);
69 | }
70 |
71 | public final int class_index;
72 | public final int method_index;
73 | }
74 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/Exceptions_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.5.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class Exceptions_attribute extends Attribute {
39 | Exceptions_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | number_of_exceptions = cr.readUnsignedShort();
42 | exception_index_table = new int[number_of_exceptions];
43 | for (int i = 0; i < number_of_exceptions; i++)
44 | exception_index_table[i] = cr.readUnsignedShort();
45 | }
46 |
47 | public Exceptions_attribute(ConstantPool constant_pool, int[] exception_index_table)
48 | throws ConstantPoolException {
49 | this(constant_pool.getUTF8Index(Attribute.Exceptions), exception_index_table);
50 | }
51 |
52 | public Exceptions_attribute(int name_index, int[] exception_index_table) {
53 | super(name_index, 2 + 2 * exception_index_table.length);
54 | this.number_of_exceptions = exception_index_table.length;
55 | this.exception_index_table = exception_index_table;
56 | }
57 |
58 | public String getException(int index, ConstantPool constant_pool) throws ConstantPoolException {
59 | int exception_index = exception_index_table[index];
60 | return constant_pool.getClassInfo(exception_index).getName();
61 | }
62 |
63 | public R accept(Visitor visitor, D data) {
64 | return visitor.visitExceptions(this, data);
65 | }
66 |
67 | public final int number_of_exceptions;
68 | public final int[] exception_index_table;
69 | }
70 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/Field.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /*
31 | * This is NOT part of any supported API.
32 | * If you write code that depends on this, you do so at your own risk.
33 | * This code and its internal interfaces are subject to change or
34 | * deletion without notice.
35 | */
36 | public class Field {
37 | Field(ClassReader cr) throws IOException {
38 | access_flags = new AccessFlags(cr);
39 | name_index = cr.readUnsignedShort();
40 | descriptor = new Descriptor(cr);
41 | attributes = new Attributes(cr);
42 | }
43 |
44 | public Field(AccessFlags access_flags,
45 | int name_index, Descriptor descriptor,
46 | Attributes attributes) {
47 | this.access_flags = access_flags;
48 | this.name_index = name_index;
49 | this.descriptor = descriptor;
50 | this.attributes = attributes;
51 | }
52 |
53 | public int byteLength() {
54 | return 6 + attributes.byteLength();
55 | }
56 |
57 | public String getName(ConstantPool constant_pool) throws ConstantPoolException {
58 | return constant_pool.getUTF8Value(name_index);
59 | }
60 |
61 | public final AccessFlags access_flags;
62 | public final int name_index;
63 | public final Descriptor descriptor;
64 | public final Attributes attributes;
65 | }
66 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/LineNumberTable_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.12.
32 | *
33 | *
This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class LineNumberTable_attribute extends Attribute {
39 | LineNumberTable_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | line_number_table_length = cr.readUnsignedShort();
42 | line_number_table = new Entry[line_number_table_length];
43 | for (int i = 0; i < line_number_table_length; i++)
44 | line_number_table[i] = new Entry(cr);
45 | }
46 |
47 | public LineNumberTable_attribute(ConstantPool constant_pool, Entry[] line_number_table)
48 | throws ConstantPoolException {
49 | this(constant_pool.getUTF8Index(Attribute.LineNumberTable), line_number_table);
50 | }
51 |
52 | public LineNumberTable_attribute(int name_index, Entry[] line_number_table) {
53 | super(name_index, 2 + line_number_table.length * Entry.length());
54 | this.line_number_table_length = line_number_table.length;
55 | this.line_number_table = line_number_table;
56 | }
57 |
58 | public R accept(Visitor visitor, D data) {
59 | return visitor.visitLineNumberTable(this, data);
60 | }
61 |
62 | public final int line_number_table_length;
63 | public final Entry[] line_number_table;
64 |
65 | public static class Entry {
66 | Entry(ClassReader cr) throws IOException {
67 | start_pc = cr.readUnsignedShort();
68 | line_number = cr.readUnsignedShort();
69 | }
70 |
71 | public static int length() {
72 | return 4;
73 | }
74 |
75 | public final int start_pc;
76 | public final int line_number;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/Method.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /*
31 | * This is NOT part of any supported API.
32 | * If you write code that depends on this, you do so at your own risk.
33 | * This code and its internal interfaces are subject to change or
34 | * deletion without notice.
35 | */
36 | public class Method {
37 | Method(ClassReader cr) throws IOException {
38 | access_flags = new AccessFlags(cr);
39 | name_index = cr.readUnsignedShort();
40 | descriptor = new Descriptor(cr);
41 | attributes = new Attributes(cr);
42 | }
43 |
44 | public Method(AccessFlags access_flags,
45 | int name_index, Descriptor descriptor,
46 | Attributes attributes) {
47 | this.access_flags = access_flags;
48 | this.name_index = name_index;
49 | this.descriptor = descriptor;
50 | this.attributes = attributes;
51 | }
52 |
53 | public int byteLength() {
54 | return 6 + attributes.byteLength();
55 | }
56 |
57 | public String getName(ConstantPool constant_pool) throws ConstantPoolException {
58 | return constant_pool.getUTF8Value(name_index);
59 | }
60 |
61 | public final AccessFlags access_flags;
62 | public final int name_index;
63 | public final Descriptor descriptor;
64 | public final Attributes attributes;
65 | }
66 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/ModuleMainClass_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.15.
32 | *
33 | *
This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class ModuleMainClass_attribute extends Attribute {
39 | ModuleMainClass_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | main_class_index = cr.readUnsignedShort();
42 | }
43 |
44 | public ModuleMainClass_attribute(ConstantPool constant_pool, int mainClass_index)
45 | throws ConstantPoolException {
46 | this(constant_pool.getUTF8Index(Attribute.ModuleMainClass), mainClass_index);
47 | }
48 |
49 | public ModuleMainClass_attribute(int name_index, int mainClass_index) {
50 | super(name_index, 2);
51 | this.main_class_index = mainClass_index;
52 | }
53 |
54 | public String getMainClassName(ConstantPool constant_pool) throws ConstantPoolException {
55 | return constant_pool.getClassInfo(main_class_index).getName();
56 | }
57 |
58 | @Override
59 | public R accept(Visitor visitor, D data) {
60 | return visitor.visitModuleMainClass(this, data);
61 | }
62 |
63 | public final int main_class_index;
64 | }
65 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/ModulePackages_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import classfile.ConstantPool.CONSTANT_Package_info;
29 |
30 | import java.io.IOException;
31 |
32 | /**
33 | * See JVMS, section 4.8.15.
34 | *
35 | * This is NOT part of any supported API.
36 | * If you write code that depends on this, you do so at your own risk.
37 | * This code and its internal interfaces are subject to change or
38 | * deletion without notice.
39 | */
40 | public class ModulePackages_attribute extends Attribute {
41 | ModulePackages_attribute(ClassReader cr, int name_index, int length)
42 | throws IOException {
43 | super(name_index, length);
44 | packages_count = cr.readUnsignedShort();
45 | packages_index = new int[packages_count];
46 | for (int i = 0; i < packages_count; i++)
47 | packages_index[i] = cr.readUnsignedShort();
48 | }
49 |
50 | public ModulePackages_attribute(ConstantPool constant_pool,
51 | int[] packages_index)
52 | throws ConstantPoolException {
53 | this(constant_pool.getUTF8Index(Attribute.ModulePackages),
54 | packages_index);
55 | }
56 |
57 | public ModulePackages_attribute(int name_index,
58 | int[] packages_index) {
59 | super(name_index, 2 + packages_index.length * 2);
60 | this.packages_count = packages_index.length;
61 | this.packages_index = packages_index;
62 | }
63 |
64 | public String getPackage(int index, ConstantPool constant_pool) throws ConstantPoolException {
65 | int package_index = packages_index[index];
66 | CONSTANT_Package_info info = constant_pool.getPackageInfo(package_index);
67 | return info.getName();
68 | }
69 |
70 | @Override
71 | public R accept(Visitor visitor, D data) {
72 | return visitor.visitModulePackages(this, data);
73 | }
74 |
75 | public final int packages_count;
76 | public final int[] packages_index;
77 | }
78 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/ModuleResolution_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.15.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class ModuleResolution_attribute extends Attribute {
39 | public static final int DO_NOT_RESOLVE_BY_DEFAULT = 0x0001;
40 | public static final int WARN_DEPRECATED = 0x0002;
41 | public static final int WARN_DEPRECATED_FOR_REMOVAL = 0x0004;
42 | public static final int WARN_INCUBATING = 0x0008;
43 |
44 | ModuleResolution_attribute(ClassReader cr, int name_index, int length)
45 | throws IOException {
46 | super(name_index, length);
47 | resolution_flags = cr.readUnsignedShort();
48 | }
49 |
50 | public ModuleResolution_attribute(ConstantPool constant_pool,
51 | int resolution_flags)
52 | throws ConstantPoolException {
53 | this(constant_pool.getUTF8Index(Attribute.ModuleResolution),
54 | resolution_flags);
55 | }
56 |
57 | public ModuleResolution_attribute(int name_index,
58 | int resolution_flags) {
59 | super(name_index, 2);
60 | this.resolution_flags = resolution_flags;
61 | }
62 |
63 | @Override
64 | public R accept(Visitor visitor, D data) {
65 | return visitor.visitModuleResolution(this, data);
66 | }
67 |
68 | public final int resolution_flags;
69 | }
70 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/ModuleTarget_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.15.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class ModuleTarget_attribute extends Attribute {
39 | ModuleTarget_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | target_platform_index = cr.readUnsignedShort();
42 | }
43 |
44 | public ModuleTarget_attribute(int name_index, int target_platform_index) {
45 | super(name_index, 2);
46 | this.target_platform_index = target_platform_index;
47 | }
48 |
49 | @Override
50 | public R accept(Visitor visitor, D data) {
51 | return visitor.visitModuleTarget(this, data);
52 | }
53 |
54 | public final int target_platform_index;
55 | }
56 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/NestHost_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import classfile.ConstantPool.CONSTANT_Class_info;
29 |
30 | import java.io.IOException;
31 |
32 | /**
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class NestHost_attribute extends Attribute {
39 | NestHost_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | top_index = cr.readUnsignedShort();
42 | }
43 |
44 | public NestHost_attribute(ConstantPool constant_pool, int signature_index)
45 | throws ConstantPoolException {
46 | this(constant_pool.getUTF8Index(Attribute.Signature), signature_index);
47 | }
48 |
49 | public NestHost_attribute(int name_index, int top_index) {
50 | super(name_index, 2);
51 | this.top_index = top_index;
52 | }
53 |
54 | public CONSTANT_Class_info getNestTop(ConstantPool constant_pool) throws ConstantPoolException {
55 | return constant_pool.getClassInfo(top_index);
56 | }
57 |
58 | public R accept(Visitor visitor, D data) {
59 | return visitor.visitNestHost(this, data);
60 | }
61 |
62 | public final int top_index;
63 | }
64 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/NestMembers_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import classfile.ConstantPool.CONSTANT_Class_info;
29 |
30 | import java.io.IOException;
31 | import java.util.stream.IntStream;
32 |
33 | /**
34 | * This is NOT part of any supported API.
35 | * If you write code that depends on this, you do so at your own risk.
36 | * This code and its internal interfaces are subject to change or
37 | * deletion without notice.
38 | */
39 | public class NestMembers_attribute extends Attribute {
40 | NestMembers_attribute(ClassReader cr, int name_index, int length) throws IOException {
41 | super(name_index, length);
42 | int len = cr.readUnsignedShort();
43 | members_indexes = new int[len];
44 | for (int i = 0 ; i < len ; i++) {
45 | members_indexes[i] = cr.readUnsignedShort();
46 | }
47 | }
48 |
49 | public NestMembers_attribute(int name_index, int[] members_indexes) {
50 | super(name_index, 2);
51 | this.members_indexes = members_indexes;
52 | }
53 |
54 | public CONSTANT_Class_info[] getChildren(ConstantPool constant_pool) throws ConstantPoolException {
55 | return IntStream.of(members_indexes)
56 | .mapToObj(i -> {
57 | try {
58 | return constant_pool.getClassInfo(i);
59 | } catch (ConstantPoolException ex) {
60 | throw new AssertionError(ex);
61 | }
62 | }).toArray(CONSTANT_Class_info[]::new);
63 | }
64 |
65 | public R accept(Visitor visitor, D data) {
66 | return visitor.visitNestMembers(this, data);
67 | }
68 |
69 | public final int[] members_indexes;
70 | }
71 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/Record_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * This is NOT part of any supported API.
32 | * If you write code that depends on this, you do so at your own risk.
33 | * This code and its internal interfaces are subject to change or
34 | * deletion without notice.
35 | */
36 | public class Record_attribute extends Attribute {
37 | Record_attribute(ClassReader cr, int name_index, int length) throws IOException {
38 | super(name_index, length);
39 | component_count = cr.readUnsignedShort();
40 | component_info_arr = new ComponentInfo[component_count];
41 | for (int i = 0; i < component_count; i++) {
42 | component_info_arr[i] = new ComponentInfo(cr);
43 | }
44 | }
45 |
46 | @Override
47 | public R accept(Visitor visitor, D data) {
48 | return visitor.visitRecord(this, data);
49 | }
50 |
51 | public final int component_count;
52 | public final ComponentInfo[] component_info_arr;
53 |
54 | public static class ComponentInfo {
55 | ComponentInfo(ClassReader cr) throws IOException {
56 | name_index = cr.readUnsignedShort();
57 | descriptor = new Descriptor(cr);
58 | attributes = new Attributes(cr);
59 | }
60 |
61 | public String getName(ConstantPool constant_pool) throws ConstantPoolException {
62 | return constant_pool.getUTF8Value(name_index);
63 | }
64 |
65 | public final int name_index;
66 | public final Descriptor descriptor;
67 | public final Attributes attributes;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.16 and 4.8.17.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public abstract class RuntimeAnnotations_attribute extends Attribute {
39 | protected RuntimeAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(name_index, length);
42 | int num_annotations = cr.readUnsignedShort();
43 | annotations = new Annotation[num_annotations];
44 | for (int i = 0; i < annotations.length; i++)
45 | annotations[i] = new Annotation(cr);
46 | }
47 |
48 | protected RuntimeAnnotations_attribute(int name_index, Annotation[] annotations) {
49 | super(name_index, length(annotations));
50 | this.annotations = annotations;
51 | }
52 |
53 | private static int length(Annotation[] annos) {
54 | int n = 2;
55 | for (Annotation anno: annos)
56 | n += anno.length();
57 | return n;
58 | }
59 |
60 | public final Annotation[] annotations;
61 | }
62 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeInvisibleAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.17.
32 | *
33 | *
This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class RuntimeInvisibleAnnotations_attribute extends RuntimeAnnotations_attribute {
39 | RuntimeInvisibleAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, AttributeException {
41 | super(cr, name_index, length);
42 | }
43 |
44 | public RuntimeInvisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations)
45 | throws ConstantPoolException {
46 | this(cp.getUTF8Index(Attribute.RuntimeInvisibleAnnotations), annotations);
47 | }
48 |
49 | public RuntimeInvisibleAnnotations_attribute(int name_index, Annotation[] annotations) {
50 | super(name_index, annotations);
51 | }
52 |
53 | public R accept(Visitor visitor, P p) {
54 | return visitor.visitRuntimeInvisibleAnnotations(this, p);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeInvisibleParameterAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.18.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class RuntimeInvisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute {
39 | RuntimeInvisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(cr, name_index, length);
42 | }
43 |
44 | public RuntimeInvisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations)
45 | throws ConstantPoolException {
46 | this(cp.getUTF8Index(Attribute.RuntimeInvisibleParameterAnnotations), parameter_annotations);
47 | }
48 |
49 | public RuntimeInvisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
50 | super(name_index, parameter_annotations);
51 | }
52 |
53 | public R accept(Visitor visitor, P p) {
54 | return visitor.visitRuntimeInvisibleParameterAnnotations(this, p);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeInvisibleTypeAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JSR 308 specification, Section 3.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class RuntimeInvisibleTypeAnnotations_attribute extends RuntimeTypeAnnotations_attribute {
39 | RuntimeInvisibleTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(cr, name_index, length);
42 | }
43 |
44 | public RuntimeInvisibleTypeAnnotations_attribute(ConstantPool cp, TypeAnnotation[] annotations)
45 | throws ConstantPoolException {
46 | this(cp.getUTF8Index(Attribute.RuntimeInvisibleTypeAnnotations), annotations);
47 | }
48 |
49 | public RuntimeInvisibleTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) {
50 | super(name_index, annotations);
51 | }
52 |
53 | public R accept(Visitor visitor, P p) {
54 | return visitor.visitRuntimeInvisibleTypeAnnotations(this, p);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeParameterAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.18 and 4.8.19.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public abstract class RuntimeParameterAnnotations_attribute extends Attribute {
39 | RuntimeParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(name_index, length);
42 | int num_parameters = cr.readUnsignedByte();
43 | parameter_annotations = new Annotation[num_parameters][];
44 | for (int p = 0; p < parameter_annotations.length; p++) {
45 | int num_annotations = cr.readUnsignedShort();
46 | Annotation[] annotations = new Annotation[num_annotations];
47 | for (int i = 0; i < num_annotations; i++)
48 | annotations[i] = new Annotation(cr);
49 | parameter_annotations[p] = annotations;
50 | }
51 | }
52 |
53 | protected RuntimeParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
54 | super(name_index, length(parameter_annotations));
55 | this.parameter_annotations = parameter_annotations;
56 | }
57 |
58 | private static int length(Annotation[][] anno_arrays) {
59 | int n = 1;
60 | for (Annotation[] anno_array: anno_arrays) {
61 | n += 2;
62 | for (Annotation anno: anno_array)
63 | n += anno.length();
64 | }
65 | return n;
66 | }
67 |
68 | public final Annotation[][] parameter_annotations;
69 | }
70 |
71 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeTypeAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JSR 308 specification, Section 3.
32 | *
33 | *
This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public abstract class RuntimeTypeAnnotations_attribute extends Attribute {
39 | protected RuntimeTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(name_index, length);
42 | int num_annotations = cr.readUnsignedShort();
43 | annotations = new TypeAnnotation[num_annotations];
44 | for (int i = 0; i < annotations.length; i++)
45 | annotations[i] = new TypeAnnotation(cr);
46 | }
47 |
48 | protected RuntimeTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) {
49 | super(name_index, length(annotations));
50 | this.annotations = annotations;
51 | }
52 |
53 | private static int length(TypeAnnotation[] annos) {
54 | int n = 2;
55 | for (TypeAnnotation anno: annos)
56 | n += anno.length();
57 | return n;
58 | }
59 |
60 | public final TypeAnnotation[] annotations;
61 | }
62 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeVisibleAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.16.
32 | *
33 | *
This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class RuntimeVisibleAnnotations_attribute extends RuntimeAnnotations_attribute {
39 | RuntimeVisibleAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(cr, name_index, length);
42 | }
43 |
44 | public RuntimeVisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations)
45 | throws ConstantPoolException {
46 | this(cp.getUTF8Index(Attribute.RuntimeVisibleAnnotations), annotations);
47 | }
48 |
49 | public RuntimeVisibleAnnotations_attribute(int name_index, Annotation[] annotations) {
50 | super(name_index, annotations);
51 | }
52 |
53 | public R accept(Visitor visitor, P p) {
54 | return visitor.visitRuntimeVisibleAnnotations(this, p);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeVisibleParameterAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.18.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class RuntimeVisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute {
39 | RuntimeVisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(cr, name_index, length);
42 | }
43 |
44 | public RuntimeVisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations)
45 | throws ConstantPoolException {
46 | this(cp.getUTF8Index(Attribute.RuntimeVisibleParameterAnnotations), parameter_annotations);
47 | }
48 |
49 | public RuntimeVisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) {
50 | super(name_index, parameter_annotations);
51 | }
52 |
53 | public R accept(Visitor visitor, P p) {
54 | return visitor.visitRuntimeVisibleParameterAnnotations(this, p);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/RuntimeVisibleTypeAnnotations_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JSR 308 specification, Section 3.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class RuntimeVisibleTypeAnnotations_attribute extends RuntimeTypeAnnotations_attribute {
39 | RuntimeVisibleTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
40 | throws IOException, Annotation.InvalidAnnotation {
41 | super(cr, name_index, length);
42 | }
43 |
44 | public RuntimeVisibleTypeAnnotations_attribute(ConstantPool cp, TypeAnnotation[] annotations)
45 | throws ConstantPoolException {
46 | this(cp.getUTF8Index(Attribute.RuntimeVisibleTypeAnnotations), annotations);
47 | }
48 |
49 | public RuntimeVisibleTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) {
50 | super(name_index, annotations);
51 | }
52 |
53 | public R accept(Visitor visitor, P p) {
54 | return visitor.visitRuntimeVisibleTypeAnnotations(this, p);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/Signature_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.9.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class Signature_attribute extends Attribute {
39 | Signature_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | signature_index = cr.readUnsignedShort();
42 | }
43 |
44 | public Signature_attribute(ConstantPool constant_pool, int signature_index)
45 | throws ConstantPoolException {
46 | this(constant_pool.getUTF8Index(Attribute.Signature), signature_index);
47 | }
48 |
49 | public Signature_attribute(int name_index, int signature_index) {
50 | super(name_index, 2);
51 | this.signature_index = signature_index;
52 | }
53 |
54 | public String getSignature(ConstantPool constant_pool) throws ConstantPoolException {
55 | return constant_pool.getUTF8Value(signature_index);
56 | }
57 |
58 | public Signature getParsedSignature() {
59 | return new Signature(signature_index);
60 | }
61 |
62 | public R accept(Visitor visitor, D data) {
63 | return visitor.visitSignature(this, data);
64 | }
65 |
66 | public final int signature_index;
67 | }
68 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/SourceDebugExtension_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 | import java.nio.charset.Charset;
30 |
31 | /**
32 | * See JVMS, section 4.8.15.
33 | *
34 | * This is NOT part of any supported API.
35 | * If you write code that depends on this, you do so at your own risk.
36 | * This code and its internal interfaces are subject to change or
37 | * deletion without notice.
38 | */
39 | public class SourceDebugExtension_attribute extends Attribute {
40 | private static final Charset UTF8 = Charset.forName("UTF-8");
41 |
42 | SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException {
43 | super(name_index, length);
44 | debug_extension = new byte[attribute_length];
45 | cr.readFully(debug_extension);
46 | }
47 |
48 | public SourceDebugExtension_attribute(ConstantPool constant_pool, byte[] debug_extension)
49 | throws ConstantPoolException {
50 | this(constant_pool.getUTF8Index(Attribute.SourceDebugExtension), debug_extension);
51 | }
52 |
53 | public SourceDebugExtension_attribute(int name_index, byte[] debug_extension) {
54 | super(name_index, debug_extension.length);
55 | this.debug_extension = debug_extension;
56 | }
57 |
58 | public String getValue() {
59 | return new String(debug_extension, UTF8);
60 | }
61 |
62 | public R accept(Visitor visitor, D data) {
63 | return visitor.visitSourceDebugExtension(this, data);
64 | }
65 |
66 | public final byte[] debug_extension;
67 | }
68 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/SourceFile_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.10.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class SourceFile_attribute extends Attribute {
39 | SourceFile_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | sourcefile_index = cr.readUnsignedShort();
42 | }
43 |
44 | public SourceFile_attribute(ConstantPool constant_pool, int sourcefile_index)
45 | throws ConstantPoolException {
46 | this(constant_pool.getUTF8Index(Attribute.SourceFile), sourcefile_index);
47 | }
48 |
49 | public SourceFile_attribute(int name_index, int sourcefile_index) {
50 | super(name_index, 2);
51 | this.sourcefile_index = sourcefile_index;
52 | }
53 |
54 | public String getSourceFile(ConstantPool constant_pool) throws ConstantPoolException {
55 | return constant_pool.getUTF8Value(sourcefile_index);
56 | }
57 |
58 | public R accept(Visitor visitor, P p) {
59 | return visitor.visitSourceFile(this, p);
60 | }
61 |
62 | public final int sourcefile_index;
63 | }
64 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/SourceID_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * This is NOT part of any supported API.
32 | * If you write code that depends on this, you do so at your own risk.
33 | * This code and its internal interfaces are subject to change or
34 | * deletion without notice.
35 | */
36 | public class SourceID_attribute extends Attribute {
37 |
38 | SourceID_attribute(ClassReader cr, int name_index, int length) throws IOException {
39 | super(name_index, length);
40 | sourceID_index = cr.readUnsignedShort();
41 | }
42 |
43 | public SourceID_attribute(ConstantPool constant_pool, int sourceID_index)
44 | throws ConstantPoolException {
45 | this(constant_pool.getUTF8Index(Attribute.SourceID), sourceID_index);
46 | }
47 |
48 | public SourceID_attribute(int name_index, int sourceID_index) {
49 | super(name_index, 2);
50 | this.sourceID_index = sourceID_index;
51 | }
52 |
53 | String getSourceID(ConstantPool constant_pool) throws ConstantPoolException {
54 | return constant_pool.getUTF8Value(sourceID_index);
55 | }
56 |
57 | public R accept(Visitor visitor, D data) {
58 | return visitor.visitSourceID(this, data);
59 | }
60 |
61 | public final int sourceID_index;
62 | }
63 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/StackMap_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * This is NOT part of any supported API.
32 | * If you write code that depends on this, you do so at your own risk.
33 | * This code and its internal interfaces are subject to change or
34 | * deletion without notice.
35 | */
36 | public class StackMap_attribute extends Attribute {
37 | StackMap_attribute(ClassReader cr, int name_index, int length)
38 | throws IOException, StackMapTable_attribute.InvalidStackMap {
39 | super(name_index, length);
40 | number_of_entries = cr.readUnsignedShort();
41 | entries = new stack_map_frame[number_of_entries];
42 | for (int i = 0; i < number_of_entries; i++)
43 | entries[i] = new stack_map_frame(cr);
44 | }
45 |
46 | public StackMap_attribute(ConstantPool constant_pool, stack_map_frame[] entries)
47 | throws ConstantPoolException {
48 | this(constant_pool.getUTF8Index(Attribute.StackMap), entries);
49 | }
50 |
51 | public StackMap_attribute(int name_index, stack_map_frame[] entries) {
52 | super(name_index, StackMapTable_attribute.length(entries));
53 | this.number_of_entries = entries.length;
54 | this.entries = entries;
55 | }
56 |
57 | public R accept(Visitor visitor, D data) {
58 | return visitor.visitStackMap(this, data);
59 | }
60 |
61 | public final int number_of_entries;
62 | public final stack_map_frame entries[];
63 |
64 | public static class stack_map_frame extends StackMapTable_attribute.full_frame {
65 | stack_map_frame(ClassReader cr)
66 | throws IOException, StackMapTable_attribute.InvalidStackMap {
67 | super(255, cr);
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/Synthetic_attribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | package classfile;
27 |
28 | import java.io.IOException;
29 |
30 | /**
31 | * See JVMS, section 4.8.8.
32 | *
33 | * This is NOT part of any supported API.
34 | * If you write code that depends on this, you do so at your own risk.
35 | * This code and its internal interfaces are subject to change or
36 | * deletion without notice.
37 | */
38 | public class Synthetic_attribute extends Attribute {
39 | Synthetic_attribute(ClassReader cr, int name_index, int length) throws IOException {
40 | super(name_index, length);
41 | }
42 |
43 | public Synthetic_attribute(ConstantPool constant_pool)
44 | throws ConstantPoolException {
45 | this(constant_pool.getUTF8Index(Attribute.Synthetic));
46 | }
47 |
48 | public Synthetic_attribute(int name_index) {
49 | super(name_index, 0);
50 | }
51 |
52 | public R accept(Visitor visitor, D data) {
53 | return visitor.visitSynthetic(this, data);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/classfile/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 | *
5 | * This code is free software; you can redistribute it and/or modify it
6 | * under the terms of the GNU General Public License version 2 only, as
7 | * published by the Free Software Foundation. Oracle designates this
8 | * particular file as subject to the "Classpath" exception as provided
9 | * by Oracle in the LICENSE file that accompanied this code.
10 | *
11 | * This code is distributed in the hope that it will be useful, but WITHOUT
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 | * version 2 for more details (a copy is included in the LICENSE file that
15 | * accompanied this code).
16 | *
17 | * You should have received a copy of the GNU General Public License version
18 | * 2 along with this work; if not, write to the Free Software Foundation,
19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 | *
21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 | * or visit www.oracle.com if you need additional information or have any
23 | * questions.
24 | */
25 |
26 | /**
27 | A minimalist library to read and write class files into objects closely
28 | based on the corresponding definitions in
29 | The Java™ Virtual Machine Specification (JVMS).
30 |
31 | This is NOT part of any supported API.
32 | If you write code that depends on this, you do so at your own risk.
33 | This code and its internal interfaces are subject to change or
34 | deletion without notice.
35 | */
36 | package classfile;
37 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/com/codelang/parse/bean/ConfigBean.java:
--------------------------------------------------------------------------------
1 | package com.codelang.parse.bean;
2 |
3 | import java.util.List;
4 |
5 | import javax.annotation.Nullable;
6 |
7 | public class ConfigBean {
8 | private List stringRef;
9 | private List methodRef;
10 | private List fieldRef;
11 |
12 | @Nullable
13 | public List getStringRef() {
14 | return stringRef;
15 | }
16 |
17 | public void setStringRef(List stringRef) {
18 | this.stringRef = stringRef;
19 | }
20 |
21 | @Nullable
22 | public List getFieldRef() {
23 | return fieldRef;
24 | }
25 |
26 | public void setFieldRef(List fieldRef) {
27 | this.fieldRef = fieldRef;
28 | }
29 |
30 | @Nullable
31 | public List getMethodRef() {
32 | return methodRef;
33 | }
34 |
35 | public void setMethodRef(List methodRef) {
36 | this.methodRef = methodRef;
37 | }
38 |
39 | public static class Method {
40 | private String className;
41 | private String method;
42 | private String signature;
43 |
44 | public String getClassName() {
45 | return className;
46 | }
47 |
48 | public void setClassName(String className) {
49 | this.className = className;
50 | }
51 |
52 | public String getMethod() {
53 | return method;
54 | }
55 |
56 | public void setMethod(String method) {
57 | this.method = method;
58 | }
59 |
60 | public String getSignature() {
61 | return signature;
62 | }
63 |
64 | public void setSignature(String signature) {
65 | this.signature = signature;
66 | }
67 | }
68 |
69 | public static class Feild {
70 | private String className;
71 | private String fieldName;
72 | private String signature;
73 |
74 | public String getClassName() {
75 | return className;
76 | }
77 |
78 | public void setClassName(String className) {
79 | this.className = className;
80 | }
81 |
82 | public String getFieldName() {
83 | return fieldName;
84 | }
85 |
86 | public void setFieldName(String fieldName) {
87 | this.fieldName = fieldName;
88 | }
89 |
90 | public String getSignature() {
91 | return signature;
92 | }
93 |
94 | public void setSignature(String signature) {
95 | this.signature = signature;
96 | }
97 |
98 | @Override
99 | public String toString() {
100 | return "Feild{" +
101 | "className='" + className + '\'' +
102 | ", fieldName='" + fieldName + '\'' +
103 | ", signature='" + signature + '\'' +
104 | '}';
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/plugin/classAnalysis/src/main/java/com/codelang/parse/extension/ConfigFileExtension.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.parse.extension
2 |
3 | open class ConfigFileExtension {
4 | var configFile: String = ""
5 | }
--------------------------------------------------------------------------------
/plugin/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | #org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
23 | apgVersion=7.0.0
24 | kotlinVersion=1.5.30
25 |
26 | org.gradle.jvmargs=-XX:MaxPermSize=4g -XX:+HeapDumpOnOutOfMemoryError -Xmx4g -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006
--------------------------------------------------------------------------------
/plugin/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MRwangqi/pluginDemo/aa7a2d0c8bcbcc8fcd8438ca273a468b7a4d4725/plugin/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/plugin/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Feb 09 10:43:29 CST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/plugin/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/plugin/modulePlugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/plugin/modulePlugin/README.md:
--------------------------------------------------------------------------------
1 | 本地 module 与 GAV 转换插件,适用于使用壳工程改造的组件化,效果可查看 demo
2 |
3 | 配置 maven 镜像源和依赖
4 | ```java
5 | buildscript {
6 | repositories {
7 | ...
8 | // maven 源
9 | maven{
10 | url "https://raw.githubusercontent.com/MRwangqi/Maven/main"
11 | }
12 | }
13 | dependencies {
14 | classpath "com.android.tools.build:gradle:7.0.4"
15 | // 依赖 check 插件
16 | classpath "com.github.MRwangqi:modulePlugin:1.0.0"
17 | }
18 | }
19 | ```
20 |
21 | 在 app 工程的 build.gradle 中依赖插件(app 为主壳模块)
22 |
23 | ```java
24 | plugins {
25 | id 'com.android.application'
26 | // apply modulePlugin 插件
27 | id 'modulePlugin'
28 | }
29 | ```
30 |
31 |
32 | gradle.properties 配置
33 |
34 | ```
35 | # GAV 转本地 module 开关
36 | gav2project.enable=true
37 | # 如果指定跳过模块,则不会参与 GAV 与 Project 的转换(仅在 gav2project.enable=true 时生效)
38 | gav2project.skips=android-lib,android-lib
39 | ```
40 |
41 |
42 | 开启转换开关效果:
43 | ```
44 | > Configure project :app
45 | 排除依赖:implementation com.codelang.library:android-lib:1.0.0
46 | 替换本地模块:implementation project(:android-lib)
47 | ```
48 |
49 | 开启跳过模块效果:
50 | ```
51 | > Configure project :app
52 | ------- 跳过模块:android-lib----依赖为:com.codelang.library:android-lib--------
53 | ```
--------------------------------------------------------------------------------
/plugin/modulePlugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'kotlin'
3 | apply plugin: 'java-gradle-plugin'
4 | apply plugin: 'maven-publish'
5 |
6 | dependencies {
7 | implementation gradleApi()
8 | implementation localGroovy()
9 | api "com.android.tools.build:gradle-api:$apgVersion"
10 | api "com.android.tools.build:gradle:$apgVersion"
11 | implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
12 | }
13 |
14 | version = "1.0.0"
15 | group = "com.github.MRwangqi"
16 |
17 | gradlePlugin {
18 | plugins {
19 | version {
20 | id = 'modulePlugin'
21 | implementationClass = 'com.codelang.plugin.ModulePlugin'
22 | }
23 | }
24 | }
25 |
26 |
27 | afterEvaluate {
28 | publishing {
29 | publications {
30 | maven(MavenPublication) {
31 | from components.java
32 | groupId = "com.github.MRwangqi"
33 | artifactId = "modulePlugin"
34 | version = "1.0.0"
35 | }
36 | }
37 |
38 | repositories {
39 | maven {
40 | url = "../../build/Maven"
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/plugin/modulePlugin/src/main/java/com/codelang/plugin/utils/Utils.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.plugin.utils
2 |
3 | import org.gradle.api.Project
4 |
5 | object Utils {
6 |
7 | private const val GAV_ENABLE = "gav2project.enable"
8 | private const val GAV_SKIPS = "gav2project.skips"
9 |
10 | fun isEnable(project: Project): Boolean {
11 | try {
12 | if (project.rootProject.hasProperty(GAV_ENABLE)) {
13 | return project.rootProject.properties[GAV_ENABLE].toString().toBoolean()
14 | }
15 | } catch (e: Exception) {
16 | }
17 | return true
18 | }
19 |
20 | fun getSkips(project: Project): List {
21 | try {
22 | if (project.rootProject.hasProperty(GAV_SKIPS)) {
23 | return project.rootProject.properties[GAV_SKIPS].toString().split(",")
24 | }
25 | } catch (e: Exception) {
26 | }
27 | return arrayListOf()
28 | }
29 | }
--------------------------------------------------------------------------------
/plugin/permissionPlugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/plugin/permissionPlugin/PermissionPlugin.gradle:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MRwangqi/pluginDemo/aa7a2d0c8bcbcc8fcd8438ca273a468b7a4d4725/plugin/permissionPlugin/PermissionPlugin.gradle
--------------------------------------------------------------------------------
/plugin/permissionPlugin/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MRwangqi/pluginDemo/aa7a2d0c8bcbcc8fcd8438ca273a468b7a4d4725/plugin/permissionPlugin/README.md
--------------------------------------------------------------------------------
/plugin/permissionPlugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'kotlin'
3 | apply plugin: 'java-gradle-plugin'
4 | apply plugin: 'maven-publish'
5 |
6 | dependencies {
7 | implementation gradleApi()
8 | implementation localGroovy()
9 | api "com.android.tools.build:gradle-api:$apgVersion"
10 | api "com.android.tools.build:gradle:$apgVersion"
11 | implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
12 | }
13 |
14 | version = "1.0.0"
15 | group = "com.github.MRwangqi"
16 |
17 | gradlePlugin {
18 | plugins {
19 | version {
20 | id = 'permissionPlugin'
21 | implementationClass = 'com.codelang.plugin.PermissionPlugin'
22 | }
23 | }
24 | }
25 |
26 |
27 | afterEvaluate {
28 | publishing {
29 | publications {
30 | maven(MavenPublication) {
31 | from components.java
32 | groupId = "com.github.MRwangqi"
33 | artifactId = "permissionPlugin"
34 | version = "1.0.0"
35 | }
36 | }
37 |
38 | repositories {
39 | maven {
40 | url = "../../build/Maven"
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/plugin/permissionPlugin/src/main/java/com/codelang/plugin/PermissionPlugin.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.plugin
2 |
3 | import com.android.build.gradle.AppExtension
4 | import groovy.util.Node
5 | import groovy.xml.XmlParser
6 | import groovy.xml.XmlUtil
7 | import org.gradle.api.Plugin
8 | import org.gradle.api.Project
9 | import java.io.File
10 |
11 | /**
12 | * 官方清单文件合并规则:
13 | * https://developer.android.com/studio/build/manifest-merge?hl=zh-cn
14 | */
15 | class PermissionPlugin : Plugin {
16 |
17 | override fun apply(project: Project) {
18 | println("PermissionPlugin start ---------->")
19 |
20 |
21 | // 获取 main 下的清单文件,如果找不到,则手动指定清单文件
22 | val mainAndroidManifest = project.extensions.getByType(AppExtension::class.java)
23 | .sourceSets.find { it.name == "main" }?.manifest?.srcFile
24 | ?: File(project.projectDir, "src/main/AndroidManifest.xml")
25 |
26 | // 1、读取主工程下清单文件的权限,并从主工程中删除,避免有小伙伴在该文件中提交敏感权限
27 | val parentNode = XmlParser(false, false).parse(mainAndroidManifest)
28 | val childrenNode = parentNode.children()
29 | val permissionNodes = childrenNode.map { it as Node }.filter { it.name() == "uses-permission" }.toList()
30 | if (permissionNodes.isNotEmpty()) {
31 | childrenNode.removeAll(permissionNodes)
32 | val xmlText = XmlUtil.serialize(parentNode)
33 | mainAndroidManifest.writeText(xmlText)
34 | }
35 |
36 |
37 | // 2、生成权限文件,直接使用主工程清单文件去除权限的模板
38 | val permissionPath = File(project.projectDir, "permission")
39 | permissionPath.mkdir()
40 | val permissionFile = File(permissionPath, "AndroidManifest.xml")
41 | if (permissionFile.exists()) {
42 | permissionFile.delete()
43 | }
44 | permissionFile.createNewFile()
45 |
46 | // 添加自定义权限
47 | getPermission().forEach {
48 | childrenNode.add(0, Node(null, it))
49 | }
50 | val xmlText2 = XmlUtil.serialize(parentNode)
51 | permissionFile.writeText(xmlText2)
52 |
53 | // 将生成的权限文件添加进 main sourceSet 中参与项目编译
54 | project.afterEvaluate {
55 | project.extensions.getByType(AppExtension::class.java)
56 | .sourceSets.find { it.name == "main" }?.manifest?.srcFile(permissionFile)
57 | }
58 | }
59 |
60 |
61 | private fun getPermission(): List {
62 | val list = arrayListOf()
63 | list.addAll(getCommonPermissions())
64 | list.addAll(getPhoneBlackPermission())
65 | return list
66 | }
67 |
68 | /**
69 | * 设置通用权限
70 | */
71 | private fun getCommonPermissions(): List {
72 | val list = arrayListOf()
73 | list.add(Utils.getPermission("android.permission.INTERNET"))
74 | return list
75 | }
76 |
77 | /**
78 | * phone 相关的敏感权限需要移除
79 | */
80 | private fun getPhoneBlackPermission(): List {
81 | val list = arrayListOf()
82 | list.add(Utils.getRemovePermission("android.permission.CALL_PHONE"))
83 | list.add(Utils.getRemovePermission("android.permission.READ_PHONE_STATE"))
84 | return list
85 | }
86 |
87 | }
--------------------------------------------------------------------------------
/plugin/permissionPlugin/src/main/java/com/codelang/plugin/Utils.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.plugin
2 |
3 | object Utils {
4 |
5 | fun getRemovePermission(name: String): String {
6 | return """
7 | uses-permission android:name="$name" tools:node="remove"
8 | """.trimIndent()
9 | }
10 |
11 |
12 | fun getPermission(name: String): String {
13 | return """
14 | uses-permission android:name="$name"
15 | """.trimIndent()
16 | }
17 | }
--------------------------------------------------------------------------------
/plugin/resourcePlugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/plugin/resourcePlugin/README.md:
--------------------------------------------------------------------------------
1 | 资源重复检查,目前仅支持:
2 | - Drawable 目录重复资源检查
3 | - Assets 目录重复资源检查
4 | - layout 目录重复资源检查
5 |
6 | 配置 maven 镜像源和依赖
7 | ```java
8 | buildscript {
9 | repositories {
10 | ...
11 | // maven 源
12 | maven{
13 | url "https://raw.githubusercontent.com/MRwangqi/Maven/main"
14 | }
15 | }
16 | dependencies {
17 | classpath "com.android.tools.build:gradle:7.0.4"
18 | // 依赖 resourcePlugin 插件
19 | classpath "com.github.MRwangqi:resourcePlugin:1.0.0"
20 | }
21 | }
22 | ```
23 |
24 | 在 app 工程的 build.gradle 中依赖插件(app 为主壳模块)
25 |
26 | ```java
27 | plugins {
28 | id 'com.android.application'
29 | // apply resourcePlugin 插件
30 | id 'resourcePlugin'
31 | }
32 | ```
33 |
34 |
35 |
36 | 也有一些小伙伴的项目没有适配 AGP 7.X,所以,这里用 gradle file 写了一遍,但只实现了 layout 的重复检查,其他两个就交由大家自己实现了,照葫芦画瓢,我觉得应该不难。
37 |
38 | 在 app 工程的 build.gradle 中引入 [resourcePlugin.gradle](resourcePlugin.gradle) 文件
39 | ```aidl
40 | plugins {
41 | id 'com.android.application'
42 | }
43 | apply from :"resourcePlugin.gradle"
44 | ```
45 |
46 |
47 | 示例 demo 运行效果:
48 | 
49 |
50 |
--------------------------------------------------------------------------------
/plugin/resourcePlugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'kotlin'
3 | apply plugin: 'java-gradle-plugin'
4 | apply plugin: 'maven-publish'
5 |
6 | dependencies {
7 | implementation gradleApi()
8 | implementation localGroovy()
9 | api "com.android.tools.build:gradle-api:$apgVersion"
10 | api "com.android.tools.build:gradle:$apgVersion"
11 | implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
12 | }
13 |
14 | version = "1.0.0"
15 | group = "com.github.MRwangqi"
16 |
17 | gradlePlugin {
18 | plugins {
19 | version {
20 | id = 'resourcePlugin'
21 | implementationClass = 'com.codelang.plugin.ResourcePlugin'
22 | }
23 | }
24 | }
25 |
26 |
27 | afterEvaluate {
28 | publishing {
29 | publications {
30 | maven(MavenPublication) {
31 | from components.java
32 | groupId = "com.github.MRwangqi"
33 | artifactId = "resourcePlugin"
34 | version = "1.0.0"
35 | }
36 | }
37 |
38 | repositories {
39 | maven {
40 | url = "../../build/Maven"
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/plugin/resourcePlugin/resourcePlugin.gradle:
--------------------------------------------------------------------------------
1 | project.extensions.getByName("android").applicationVariants.all { variant ->
2 | def mergeResourcesTask = variant.mergeResourcesProvider.get()
3 | def mergeAssetsTask = variant.mergeAssetsProvider.get()
4 |
5 | def resourceTask = project.task("DuplicateResource${variant.name.capitalize()}Check")
6 | resourceTask.doLast {
7 | def files = variant.allRawAndroidResources.files
8 | checkResLayout(project, files)
9 | checkResDrawable(files)
10 | checkAssets(mergeAssetsTask.getLibraries().files, mergeAssetsTask.sourceFolderInputs.files)
11 | }
12 | mergeResourcesTask.dependsOn(resourceTask)
13 | }
14 |
15 |
16 | def checkResLayout(Project project, Set files) {
17 | def hashMap = new HashMap()
18 | def duplicateLayout = new HashMap>()
19 | // todo 处理 layout
20 | files.each { file ->
21 | def layoutDir = file.listFiles().find { it.isDirectory() && it.name == "layout" }
22 | if (layoutDir != null) {
23 | layoutDir.listFiles().each { layout ->
24 | if (hashMap.containsKey(layout.name)) {
25 | def list = duplicateLayout[layout.name]
26 | if (list == null) {
27 | list = new ArrayList()
28 | list.add(hashMap[layout.name])
29 | }
30 | list.add(layout.absolutePath)
31 | // 资源重复
32 | duplicateLayout[layout.name] = list
33 | } else {
34 | hashMap[layout.name] = layout.absolutePath
35 | }
36 | }
37 | }
38 | }
39 |
40 | if (!duplicateLayout.isEmpty()) {
41 | println()
42 | project.logger.error("-------- layout 资源重复----------")
43 | duplicateLayout.each { entry ->
44 | println(entry.key)
45 | entry.value.each {
46 | project.logger.error("----> " + it)
47 | }
48 | }
49 | }
50 | }
51 |
52 | def checkResDrawable(Set files) {
53 | // todo 处理 Drawable
54 | }
55 |
56 | def checkAssets(Set libraryFolder, Set sourceFolder) {
57 | // todo 处理 assets
58 | }
--------------------------------------------------------------------------------
/plugin/resourcePlugin/result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MRwangqi/pluginDemo/aa7a2d0c8bcbcc8fcd8438ca273a468b7a4d4725/plugin/resourcePlugin/result.png
--------------------------------------------------------------------------------
/plugin/settings.gradle:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | }
6 | }
7 | rootProject.name = "plugin"
8 | include ':checkPlugin'
9 | include ':uploadPlugin'
10 | include ':modulePlugin'
11 | include ':resourcePlugin'
12 | include ':permissionPlugin'
13 | include ':classAnalysis'
14 |
--------------------------------------------------------------------------------
/plugin/uploadPlugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/plugin/uploadPlugin/README.md:
--------------------------------------------------------------------------------
1 | ## 一、配置 maven 镜像源和依赖
2 | ```java
3 | buildscript {
4 | repositories {
5 | ...
6 | // 配上 maven 源
7 | maven{
8 | url "https://raw.githubusercontent.com/MRwangqi/Maven/main"
9 | }
10 | }
11 | dependencies {
12 | classpath "com.android.tools.build:gradle:7.0.4"
13 | // 依赖 upload 插件
14 | classpath "com.github.MRwangqi:uploadPlugin:1.0.0"
15 | }
16 | }
17 | ```
18 |
19 | ## 二、依赖插件
20 |
21 | 目前插件支持两种方式上传:
22 |
23 | ### 1、上传到 github
24 |
25 | 在模块工程的 build.gradle 中依赖插件:
26 |
27 | ```java
28 | plugins {
29 | id 'com.android.library'
30 | // 配置上传到 github
31 | id 'uploadGithub'
32 | }
33 |
34 | upload {
35 | // 必选
36 | groupId = ""
37 | // 必选
38 | artifactId = ""
39 | // 必选
40 | version = ""
41 | }
42 | ```
43 |
44 | 插件在运行时会读取 local.properties 中 github 的内容
45 |
46 | > local.properties 配置
47 | ```
48 | # github 仓库链接(可选,如果不配置的话则发布到 project 下的 build/repo 目录)
49 | # XXX 为填充区域
50 | githubURL = XXX
51 | # github 仓库分支(可选,如果不配置的话则以仓库当前配置的分支为准)
52 | githubBranch = XXX
53 | ```
54 |
55 |
56 | ### 2、上传到 maven
57 |
58 | 在模块工程的 build.gradle 中依赖插件:
59 |
60 | ```java
61 | plugins {
62 | id 'com.android.library'
63 | // 配置上传到 maven nexus
64 | id 'uploadMaven'
65 | }
66 |
67 | upload {
68 | // 必选
69 | groupId = ""
70 | // 必选
71 | artifactId = ""
72 | // 必选
73 | version = ""
74 | }
75 | ```
76 |
77 | 插件在运行时会读取 local.properties 中 nexus 的内容
78 |
79 | > local.properties 配置
80 |
81 | ```
82 | # nexus 地址 (可选,如果不配置的话则发布到 project 下的 build/repo 目录)
83 | # XXX 为填充区域
84 | nexusURL = XXX
85 | nexusName = XXX
86 | nexusPsw = XXX
87 | ```
88 |
89 |
90 | uploadMaven 也支持通过命令参数来输入:
91 | > ./gradlew :android-lib:upload -Pname=${nexusName} -Ppsw=${nexusPsw} -Purl=${nexusURL}
92 |
93 | 例如要打包 android-lib 模块,用户名和密码都是 admin,则命令行为:
94 | > ./gradlew :android-lib:upload -Pname=admin -Ppsw=admin -Purl=http://localhost:8081/repository/android/
95 |
96 |
97 |
98 | 通用配置:
99 | ```
100 | upload {
101 | // 模块下的依赖是否打入 pom : (可选,默认会打入)
102 | hasPomDepend = true
103 | // 模块是否打入 source 源码: (可选,默认会打入)
104 | sourceJar = true
105 | }
106 | ```
107 |
108 |
--------------------------------------------------------------------------------
/plugin/uploadPlugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'kotlin'
3 | apply plugin: 'java-gradle-plugin'
4 | apply plugin: 'maven-publish'
5 |
6 | version = "2.0.0"
7 | group = "com.github.MRwangqi"
8 |
9 |
10 | dependencies {
11 | implementation gradleApi()
12 | implementation localGroovy()
13 | api "com.android.tools.build:gradle-api:$apgVersion"
14 | api "com.android.tools.build:gradle:$apgVersion"
15 | implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
16 | implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '6.1.0.202203080745-r'
17 |
18 | }
19 |
20 | gradlePlugin {
21 | plugins {
22 | nexus {
23 | id = 'uploadMaven'
24 | implementationClass = 'com.codelang.upload.UploadMaven'
25 | }
26 | github {
27 | id = 'uploadGithub'
28 | implementationClass = 'com.codelang.upload.UploadGithub'
29 | }
30 | }
31 | }
32 |
33 |
34 | afterEvaluate {
35 | publishing {
36 | publications {
37 | maven(MavenPublication) {
38 | from components.java
39 | groupId = "com.github.MRwangqi"
40 | artifactId = "uploadPlugin"
41 | version = "1.0.0"
42 | }
43 | }
44 |
45 | repositories {
46 | maven {
47 | url = "../../build/Maven"
48 | }
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/plugin/uploadPlugin/src/main/java/com/codelang/upload/UploadMaven.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.upload
2 |
3 |
4 | import com.codelang.upload.config.UploadConfig
5 | import org.gradle.api.Project
6 | import java.net.URI
7 | import java.util.*
8 |
9 | class UploadMaven : BaseUploadPlugin() {
10 |
11 | private val PARAMS_URL = "url"
12 | private val PARAM_NAME = "name"
13 | private val PARAM_PSW = "psw"
14 |
15 | override fun isSupportUpload(uploadConfig: UploadConfig, project: Project): Boolean {
16 | val properties = Properties()
17 | properties.load(project.rootProject.file("local.properties").inputStream())
18 |
19 | val nexusUrl = properties.getProperty("nexusURL")?:""
20 | if (nexusUrl.isNotEmpty()){
21 | uploadConfig.nexusURL = nexusUrl
22 | }
23 | val nexusName = properties.getProperty("nexusName")?:""
24 | if (nexusUrl.isNotEmpty()){
25 | uploadConfig.nexusName = nexusName
26 | }
27 |
28 | val nexusPsw = properties.getProperty("nexusPsw")?:""
29 | if (nexusUrl.isNotEmpty()){
30 | uploadConfig.nexusPsw = nexusPsw
31 | }
32 |
33 |
34 | // ./gradlew upload -Pname=admin -Ppsw=admin -Purl=http://localhost:8081/repository/android/
35 | val params = project.gradle.startParameter.projectProperties
36 |
37 | if (params.containsKey(PARAM_NAME)) {
38 | uploadConfig.nexusName = params[PARAM_NAME] ?: ""
39 | }
40 | if (params.containsKey(PARAM_PSW)) {
41 | uploadConfig.nexusPsw = params[PARAM_PSW] ?: ""
42 | }
43 | if (params.containsKey(PARAMS_URL)) {
44 | uploadConfig.nexusURL = params[PARAMS_URL] ?: ""
45 | }
46 |
47 | if (uploadConfig.nexusURL.isEmpty() ||
48 | uploadConfig.nexusName.isEmpty() ||
49 | uploadConfig.nexusPsw.isEmpty()) {
50 |
51 | println("upload 配置的 nexus 有空值:")
52 | println("nexusURL=${uploadConfig.nexusURL}")
53 | println("nexusName=${uploadConfig.nexusName}")
54 | println("nexusPsw=${uploadConfig.nexusPsw}")
55 |
56 | println("upload 采取降级发布到本地目录}")
57 | }
58 | return true
59 | }
60 |
61 | override fun isCredentials(uploadConfig: UploadConfig): Boolean {
62 | if (uploadConfig.nexusURL.startsWith("http")
63 | || uploadConfig.nexusURL.startsWith("https")) {
64 | return true
65 | }
66 | return false
67 | }
68 |
69 | override fun uploadComplete(uploadConfig: UploadConfig, mavenUrl: String, project: Project) {
70 | println("""
71 | 已上传到仓库, maven 镜像源为:
72 |
73 | maven{
74 | url "$mavenUrl"
75 | }
76 |
77 | 可添加依赖使用:
78 |
79 | implementation '${uploadConfig.groupId}:${uploadConfig.artifactId}:${uploadConfig.version}'
80 | """.trimIndent())
81 | }
82 | }
--------------------------------------------------------------------------------
/plugin/uploadPlugin/src/main/java/com/codelang/upload/config/UploadConfig.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.upload.config
2 |
3 | open class UploadConfig {
4 | var version: String = ""
5 | var artifactId: String = ""
6 | var groupId: String = ""
7 | var sourceJar: Boolean = true
8 | var hasPomDepend: Boolean = true
9 |
10 |
11 | // github 相关
12 | var githubURL: String = ""
13 | var githubBranch: String = ""
14 |
15 | // nexus 相关
16 | var nexusURL: String = ""
17 | var nexusName: String = ""
18 | var nexusPsw: String = ""
19 |
20 |
21 | override fun toString(): String {
22 | return "UploadConfig(version='$version', artifactId='$artifactId', groupId='$groupId', sourceJar=$sourceJar, githubURL='$githubURL', githubBranch='$githubBranch', hasPomDepend=$hasPomDepend, nexusURL='$nexusURL', nexusName='$nexusName', nexusPsw='$nexusPsw')"
23 | }
24 |
25 |
26 | }
--------------------------------------------------------------------------------
/plugin/uploadPlugin/src/main/java/com/codelang/upload/task/SourceJarTask.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.upload.task
2 |
3 | import com.android.build.gradle.LibraryExtension
4 | import org.gradle.api.Project
5 | import org.gradle.api.Task
6 | import org.gradle.api.plugins.JavaPluginConvention
7 | import org.gradle.api.tasks.TaskProvider
8 | import org.gradle.api.tasks.bundling.Jar
9 |
10 | /**
11 | * @author wangqi
12 | * @since 2022/3/19.
13 | */
14 |
15 | fun Project.emptySourcesJar(): Task = tasks.create("emptySourcesJar", Jar::class.java)
16 |
17 | fun Project.androidSourcesJar(): Task {
18 | return tasks.create("androidSourcesJar", Jar::class.java) {
19 | val androidExtension = extensions.getByType(LibraryExtension::class.java)
20 |
21 | val set = androidExtension.sourceSets.filter {
22 | it.name == "main"
23 | }.map {
24 | it.java.srcDirs
25 | }.toSet()
26 |
27 | it.classifier = "sources"
28 | it.version = ""
29 | it.from(set)
30 | }
31 | }
32 |
33 | fun Project.javaSourcesJar(): Task {
34 | return tasks.create("javaSourcesJar", Jar::class.java) {
35 | val javaPlugin = convention.getPlugin(JavaPluginConvention::class.java)
36 |
37 | val set = javaPlugin.sourceSets.filter {
38 | it.name == "main"
39 | }.map {
40 | it.java.srcDirs
41 | }.toSet()
42 |
43 | it.classifier = "sources"
44 | it.version = ""
45 | it.from(set)
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/plugin/uploadPlugin/src/main/java/com/codelang/upload/utils/FileUtils.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.upload.utils
2 |
3 | import java.io.File
4 |
5 | /**
6 | * @author wangqi
7 | * @since 2022/3/19.
8 | */
9 | object FileUtils {
10 | fun copyFolder(src: File, dest: File) {
11 | if (src.isDirectory) {
12 | if (!dest.exists()) {
13 | dest.mkdir();
14 | }
15 | src.list()?.forEach {
16 | val srcFile = File(src, it)
17 | val destFile = File(dest, it)
18 | // 递归复制
19 | copyFolder(srcFile, destFile);
20 | }
21 | } else {
22 | src.runCatching {
23 | inputStream().use { input ->
24 | dest.apply {
25 | outputStream().use { output ->
26 | input.copyTo(output)
27 | }
28 | }
29 | }
30 | }.onFailure {
31 | println("error: " + it.message)
32 | }
33 | }
34 | }
35 |
36 |
37 | }
--------------------------------------------------------------------------------
/plugin/uploadPlugin/src/main/java/com/codelang/upload/utils/Util.kt:
--------------------------------------------------------------------------------
1 | package com.codelang.upload.utils
2 |
3 | import com.android.tools.build.apkzlib.sign.SigningExtension
4 | import org.gradle.api.Project
5 | import org.gradle.api.publish.PublishingExtension
6 |
7 | object Util {
8 |
9 | fun isApplication(project: Project): Boolean {
10 | return project.plugins.hasPlugin("com.android.application")
11 | }
12 |
13 | fun isAndroidModule(project: Project): Boolean {
14 | return project.hasProperty("android")
15 | }
16 |
17 | //publishing
18 | fun publishingExtension(project: Project): PublishingExtension? {
19 | return project.extensions.findByType(PublishingExtension::class.java)
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | // repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3 | repositories {
4 | google()
5 | mavenCentral()
6 | maven { url 'https://jitpack.io' }
7 | maven {
8 | allowInsecureProtocol = true
9 | url "http://localhost:8081/repository/android/"
10 | }
11 | maven{
12 | url "https://raw.githubusercontent.com/MRwangqi/Maven/main"
13 | }
14 | }
15 | }
16 | rootProject.name = "pluginDemo"
17 | include ':app'
18 | include ':java-lib'
19 |
20 | includeBuild("./plugin")
21 |
22 | include ':android-lib2'
23 | include ':android-lib'
24 |
25 |
26 |
--------------------------------------------------------------------------------