Skip to content

Commit 9126717

Browse files
author
emmanue1
committed
Add Java 9+ module support
1 parent 4e1300e commit 9126717

24 files changed

+877
-67
lines changed

src/main/java/org/jd/core/v1/api/loader/LoaderException.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010

1111
public class LoaderException extends Exception {
12-
private static final long serialVersionUID = 9506606333927794L;
13-
public LoaderException() {}
14-
15-
public LoaderException(String msg) { super(msg); }
12+
private static final long serialVersionUID = 9506606333927794L;
13+
public LoaderException() {}
1614

17-
public LoaderException(Throwable cause) { super(cause); }
15+
public LoaderException(String msg) { super(msg); }
16+
17+
public LoaderException(Throwable cause) { super(cause); }
1818
}

src/main/java/org/jd/core/v1/api/printer/Printer.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
public interface Printer {
12-
int UNKNOWN_LINE_NUMBER = 0;
12+
int UNKNOWN_LINE_NUMBER = 0;
1313

1414
// Declaration & reference flags
1515
int TYPE_FLAG = 1;
@@ -27,20 +27,20 @@ public interface Printer {
2727
void end();
2828

2929
void printText(String text);
30-
void printNumericConstant(String constant);
31-
void printStringConstant(String constant, String ownerInternalName);
32-
void printKeyword(String keyword);
30+
void printNumericConstant(String constant);
31+
void printStringConstant(String constant, String ownerInternalName);
32+
void printKeyword(String keyword);
3333

3434
void printDeclaration(int flags, String internalTypeName, String name, String descriptor);
35-
void printReference(int flags, String internalTypeName, String name, String descriptor, String ownerInternalName);
35+
void printReference(int flags, String internalTypeName, String name, String descriptor, String ownerInternalName);
3636

37-
void indent();
38-
void unindent();
39-
40-
void startLine(int lineNumber);
41-
void endLine();
42-
void extraLine(int count);
37+
void indent();
38+
void unindent();
4339

44-
void startMarker(int type);
45-
void endMarker(int type);
40+
void startLine(int lineNumber);
41+
void endLine();
42+
void extraLine(int count);
43+
44+
void startMarker(int type);
45+
void endMarker(int type);
4646
}

src/main/java/org/jd/core/v1/model/classfile/Constants.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@
88
package org.jd.core.v1.model.classfile;
99

1010
public interface Constants {
11-
// Access flag for Class, Field, Method, Nested class
12-
short ACC_PUBLIC = 0x0001; // C F M N
13-
short ACC_PRIVATE = 0x0002; // F M N
14-
short ACC_PROTECTED = 0x0004; // F M N
15-
short ACC_STATIC = 0x0008; // C F M N
16-
short ACC_FINAL = 0x0010; // C F M N
17-
short ACC_SYNCHRONIZED = 0x0020; // M
18-
short ACC_SUPER = 0x0020; // C
19-
short ACC_VOLATILE = 0x0040; // F
20-
short ACC_BRIDGE = 0x0040; // M
21-
short ACC_TRANSIENT = 0x0080; // F
22-
short ACC_VARARGS = 0x0080; // M
23-
short ACC_NATIVE = 0x0100; // M
24-
short ACC_INTERFACE = 0x0200; // C N
25-
short ACC_ABSTRACT = 0x0400; // C M N
26-
short ACC_STRICT = 0x0800; // M
27-
short ACC_SYNTHETIC = 0x1000; // C F M N
28-
short ACC_ANNOTATION = 0x2000; // C N
29-
short ACC_ENUM = 0x4000; // C F N
11+
// Access flags for Class, Field, Method, Nested class, Module, Module Requires, Module Exports, Module Opens
12+
int ACC_PUBLIC = 0x0001; // C F M N . . . .
13+
int ACC_PRIVATE = 0x0002; // . F M N . . . .
14+
int ACC_PROTECTED = 0x0004; // . F M N . . . .
15+
int ACC_STATIC = 0x0008; // C F M N . . . .
16+
int ACC_FINAL = 0x0010; // C F M N . . . .
17+
int ACC_SYNCHRONIZED = 0x0020; // . . M . . . . .
18+
int ACC_SUPER = 0x0020; // C . . . . . . .
19+
int ACC_OPEN = 0x0020; // . . . . Mo . . .
20+
int ACC_TRANSITIVE = 0x0020; // . . . . . MR . .
21+
int ACC_VOLATILE = 0x0040; // . F . . . . . .
22+
int ACC_BRIDGE = 0x0040; // . . M . . . . .
23+
int ACC_STATIC_PHASE = 0x0040; // . . M . . MR . .
24+
int ACC_TRANSIENT = 0x0080; // . F . . . . . .
25+
int ACC_VARARGS = 0x0080; // . . M . . . . .
26+
int ACC_NATIVE = 0x0100; // . . M . . . . .
27+
int ACC_INTERFACE = 0x0200; // C . . N . . . .
28+
int ACC_ABSTRACT = 0x0400; // C . M N . . . .
29+
int ACC_STRICT = 0x0800; // . . M . . . . .
30+
int ACC_SYNTHETIC = 0x1000; // C F M N Mo MR ME MO
31+
int ACC_ANNOTATION = 0x2000; // C . . N . . . .
32+
int ACC_ENUM = 0x4000; // C F . N . . . .
33+
int ACC_MODULE = 0x8000; // C . . . . . . .
34+
int ACC_MANDATED = 0x8000; // . . . . Mo MR ME MO
3035
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.core.v1.model.classfile.attribute;
9+
10+
public class AttributeMethodParameters implements Attribute {
11+
protected MethodParameter[] parameters;
12+
13+
public AttributeMethodParameters(MethodParameter[] parameters) {
14+
this.parameters = parameters;
15+
}
16+
17+
public MethodParameter[] getParameters() {
18+
return parameters;
19+
}
20+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.core.v1.model.classfile.attribute;
9+
10+
// Example: https://github.com/netroby/jdk9-dev/blob/master/jdk/src/java.management/share/classes/module-info.java
11+
public class AttributeModule implements Attribute {
12+
protected String name;
13+
protected int flags;
14+
protected String version;
15+
16+
protected ModuleInfo[] requires;
17+
protected PackageInfo[] exports;
18+
protected PackageInfo[] opens;
19+
protected String[] uses;
20+
protected ServiceInfo[] provides;
21+
22+
public AttributeModule(String name, int flags, String version, ModuleInfo[] requires, PackageInfo[] exports, PackageInfo[] opens, String[] uses, ServiceInfo[] provides) {
23+
this.name = name;
24+
this.flags = flags;
25+
this.version = version;
26+
this.requires = requires;
27+
this.exports = exports;
28+
this.opens = opens;
29+
this.uses = uses;
30+
this.provides = provides;
31+
}
32+
33+
public String getName() {
34+
return name;
35+
}
36+
37+
public int getFlags() {
38+
return flags;
39+
}
40+
41+
public String getVersion() {
42+
return version;
43+
}
44+
45+
public ModuleInfo[] getRequires() {
46+
return requires;
47+
}
48+
49+
public PackageInfo[] getExports() {
50+
return exports;
51+
}
52+
53+
public PackageInfo[] getOpens() {
54+
return opens;
55+
}
56+
57+
public String[] getUses() {
58+
return uses;
59+
}
60+
61+
public ServiceInfo[] getProvides() {
62+
return provides;
63+
}
64+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.core.v1.model.classfile.attribute;
9+
10+
import org.jd.core.v1.model.classfile.constant.ConstantClass;
11+
12+
public class AttributeModuleMainClass implements Attribute {
13+
protected ConstantClass mainClass;
14+
15+
public AttributeModuleMainClass(ConstantClass mainClass) {
16+
this.mainClass = mainClass;
17+
}
18+
19+
public ConstantClass getMainClass() {
20+
return mainClass;
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.core.v1.model.classfile.attribute;
9+
10+
public class AttributeModulePackages implements Attribute {
11+
protected String[] packageNames;
12+
13+
public AttributeModulePackages(String[] packageNames) {
14+
this.packageNames = packageNames;
15+
}
16+
17+
public String[] getPackageNames() {
18+
return packageNames;
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.core.v1.model.classfile.attribute;
9+
10+
public class MethodParameter {
11+
protected String name;
12+
protected int access;
13+
14+
public MethodParameter(String name, int access) {
15+
this.name = name;
16+
this.access = access;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public int getAccess() {
24+
return access;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
StringBuilder sb = new StringBuilder();
30+
31+
sb.append("Parameter{name=").append(name);
32+
sb.append(", access=").append(access);
33+
34+
return sb.append("}").toString();
35+
}
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.core.v1.model.classfile.attribute;
9+
10+
public class ModuleInfo {
11+
protected String name;
12+
protected int flags;
13+
protected String version;
14+
15+
public ModuleInfo(String name, int flags, String version) {
16+
this.name = name;
17+
this.flags = flags;
18+
this.version = version;
19+
}
20+
21+
public String getName() {
22+
return name;
23+
}
24+
25+
public int getFlags() {
26+
return flags;
27+
}
28+
29+
public String getVersion() {
30+
return version;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
StringBuilder sb = new StringBuilder();
36+
37+
sb.append("ModuleInfo{name=").append(name);
38+
sb.append(", flags=").append(flags);
39+
40+
if (version != null) {
41+
sb.append(", version=").append(version);
42+
}
43+
44+
return sb.append("}").toString();
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2008-2019 Emmanuel Dupuy.
3+
* This project is distributed under the GPLv3 license.
4+
* This is a Copyleft license that gives the user the right to use,
5+
* copy and modify the code freely for non-commercial purposes.
6+
*/
7+
8+
package org.jd.core.v1.model.classfile.attribute;
9+
10+
public class PackageInfo {
11+
protected String internalName;
12+
protected int flags;
13+
protected String[] moduleInfoNames;
14+
15+
public PackageInfo(String internalName, int flags, String[] moduleInfoNames) {
16+
this.internalName = internalName;
17+
this.flags = flags;
18+
this.moduleInfoNames = moduleInfoNames;
19+
}
20+
21+
public String getInternalName() {
22+
return internalName;
23+
}
24+
25+
public int getFlags() {
26+
return flags;
27+
}
28+
29+
public String[] getModuleInfoNames() {
30+
return moduleInfoNames;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
StringBuilder sb = new StringBuilder();
36+
37+
sb.append("PackageInfo{internalName=").append(internalName);
38+
sb.append(", flags=").append(flags);
39+
40+
if (moduleInfoNames != null) {
41+
sb.append(", moduleInfoNames=").append(moduleInfoNames);
42+
}
43+
44+
return sb.append("}").toString();
45+
}
46+
}

0 commit comments

Comments
 (0)