Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code-quality assurance tools to pom.xml #16

Merged
merged 8 commits into from
Oct 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,4 @@
</plugin>
</plugins>
</reporting>

</project>
186 changes: 111 additions & 75 deletions src/me/coley/recaf/asm/Access.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,118 @@

/**
* A utility for checking and generating object access.
*
*
* @author Matt
*/
public class Access {
// @formatter:off
// Modifiers - Public
public static final int PUBLIC = 0x00001;
public static final int PRIVATE = 0x00002;
public static final int PROTECTED = 0x00004;
public static final int STATIC = 0x00008;
public static final int FINAL = 0x00010;
public static final int SYNCHRONIZED = 0x00020;
public static final int VOLATILE = 0x00040;
public static final int TRANSIENT = 0x00080;
public static final int NATIVE = 0x00100;
public static final int INTERFACE = 0x00200;
public static final int ABSTRACT = 0x00400;
public static final int STRICT = 0x00800;
// Modifiers - Non-Public
public static final int BRIDGE = 0x00040;
public static final int VARARGS = 0x00080;
public static final int SYNTHETIC = 0x01000;
public static final int ANNOTATION = 0x02000;
public static final int ENUM = 0x04000;
public static final int MANDATED = 0x08000;
public static final int SUPER = 0x00020;
// Modifier sets
public static final int CLASS_MODIFIERS =
PUBLIC | PRIVATE | FINAL |
STATIC | ANNOTATION | ENUM |
SYNTHETIC | INTERFACE | SUPER |
ABSTRACT | STRICT;
public static final int INTERFACE_MODIFIERS =
PUBLIC | PROTECTED | PRIVATE |
ABSTRACT | STATIC | STRICT |
SYNTHETIC;
public static final int CONSTRUCTOR_MODIFIERS =
PUBLIC | PROTECTED | PRIVATE |
BRIDGE | SYNTHETIC | VARARGS;
public static final int METHOD_MODIFIERS =
PUBLIC | PROTECTED | PRIVATE |
ABSTRACT | STATIC | FINAL |
SYNCHRONIZED | NATIVE | STRICT |
SYNTHETIC | BRIDGE | VARARGS;
public static final int FIELD_MODIFIERS =
PUBLIC | PROTECTED | PRIVATE |
STATIC | TRANSIENT | FINAL |
VOLATILE | SYNTHETIC;
// Access checking
public static boolean isAbstract(int acc){return(acc & ABSTRACT)!=0;}
public static boolean isAnnotation(int acc){return(acc & ANNOTATION)!=0;}
public static boolean isBridge(int acc){return(acc & BRIDGE)!=0;}
public static boolean isEnum(int acc){return(acc & ENUM)!=0;}
public static boolean isFinal(int acc){return(acc & FINAL)!=0;}
public static boolean isInterface(int acc){return(acc & INTERFACE)!=0;}
public static boolean isNative(int acc){return(acc & NATIVE)!=0;}
public static boolean isPrivate(int acc){return(acc & PRIVATE)!=0;}
public static boolean isProtected(int acc){return(acc & PROTECTED)!=0;}
public static boolean isPublic(int acc){return(acc & PUBLIC)!=0;}
public static boolean isStatic(int acc){return(acc & STATIC)!=0;}
public static boolean isStrict(int acc){return(acc & STRICT)!=0;}
public static boolean isSuper(int acc){return(acc & SUPER)!=0;}
public static boolean isSynchronized(int acc){return(acc & SYNCHRONIZED)!=0;}
public static boolean isSynthetic(int acc){return(acc & SYNTHETIC)!=0;}
public static boolean isTransient(int acc){return(acc & TRANSIENT)!=0;}
public static boolean isVarargs(int acc){return(acc & VARARGS)!=0;}
public static boolean isVolatile(int acc){return(acc & VOLATILE)!=0;}
// Access creation
public static int createAccess(int... acArgs) {
int access = 0;
for (int acArg : acArgs) access |= acArg;
return access;
}
public static boolean hasAccess(int access, int... acArgs) {
for (int acArg : acArgs)
if ((access & acArg) == 0) return false;
return true;
}
// @formatter:off
// Modifiers - Public
public static final int PUBLIC = 0x00001;
public static final int PRIVATE = 0x00002;
public static final int PROTECTED = 0x00004;
public static final int STATIC = 0x00008;
public static final int FINAL = 0x00010;
public static final int SYNCHRONIZED = 0x00020;
public static final int VOLATILE = 0x00040;
public static final int TRANSIENT = 0x00080;
public static final int NATIVE = 0x00100;
public static final int INTERFACE = 0x00200;
public static final int ABSTRACT = 0x00400;
public static final int STRICT = 0x00800;
// Modifiers - Non-Public
public static final int BRIDGE = 0x00040;
public static final int VARARGS = 0x00080;
public static final int SYNTHETIC = 0x01000;
public static final int ANNOTATION = 0x02000;
public static final int ENUM = 0x04000;
public static final int MANDATED = 0x08000;
public static final int SUPER = 0x00020;
// Modifier sets
public static final int CLASS_MODIFIERS =
PUBLIC | PRIVATE | FINAL |
STATIC | ANNOTATION | ENUM |
SYNTHETIC | INTERFACE | SUPER |
ABSTRACT | STRICT;
public static final int INTERFACE_MODIFIERS =
PUBLIC | PROTECTED | PRIVATE |
ABSTRACT | STATIC | STRICT |
SYNTHETIC;
public static final int CONSTRUCTOR_MODIFIERS =
PUBLIC | PROTECTED | PRIVATE |
BRIDGE | SYNTHETIC | VARARGS;
public static final int METHOD_MODIFIERS =
PUBLIC | PROTECTED | PRIVATE |
ABSTRACT | STATIC | FINAL |
SYNCHRONIZED | NATIVE | STRICT |
SYNTHETIC | BRIDGE | VARARGS;
public static final int FIELD_MODIFIERS =
PUBLIC | PROTECTED | PRIVATE |
STATIC | TRANSIENT | FINAL |
VOLATILE | SYNTHETIC;
// Access checking
public static boolean isAbstract(int acc) {
return(acc & ABSTRACT)!=0;
}
public static boolean isAnnotation(int acc) {
return(acc & ANNOTATION)!=0;
}
public static boolean isBridge(int acc) {
return(acc & BRIDGE)!=0;
}
public static boolean isEnum(int acc) {
return(acc & ENUM)!=0;
}
public static boolean isFinal(int acc) {
return(acc & FINAL)!=0;
}
public static boolean isInterface(int acc) {
return(acc & INTERFACE)!=0;
}
public static boolean isNative(int acc) {
return(acc & NATIVE)!=0;
}
public static boolean isPrivate(int acc) {
return(acc & PRIVATE)!=0;
}
public static boolean isProtected(int acc) {
return(acc & PROTECTED)!=0;
}
public static boolean isPublic(int acc) {
return(acc & PUBLIC)!=0;
}
public static boolean isStatic(int acc) {
return(acc & STATIC)!=0;
}
public static boolean isStrict(int acc) {
return(acc & STRICT)!=0;
}
public static boolean isSuper(int acc) {
return(acc & SUPER)!=0;
}
public static boolean isSynchronized(int acc) {
return(acc & SYNCHRONIZED)!=0;
}
public static boolean isSynthetic(int acc) {
return(acc & SYNTHETIC)!=0;
}
public static boolean isTransient(int acc) {
return(acc & TRANSIENT)!=0;
}
public static boolean isVarargs(int acc) {
return(acc & VARARGS)!=0;
}
public static boolean isVolatile(int acc) {
return(acc & VOLATILE)!=0;
}
// Access creation
public static int createAccess(int... acArgs) {
int access = 0;
for (int acArg : acArgs) access |= acArg;
return access;
}
public static boolean hasAccess(int access, int... acArgs) {
for (int acArg : acArgs)
if ((access & acArg) == 0) return false;
return true;
}
}
40 changes: 21 additions & 19 deletions src/me/coley/recaf/asm/AsmUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public class AsmUtil {

/**
* Reads the classes of the given jar into a map.
*
* @param jarPath
* @return
* @throws IOException
*
* @param jarPath Path to jarfile to read classes from.
* @return Map of classes from the specified jarfile.
* @throws IOException If an error was encountered while reading the
* jarfile.
*/
public Map<String, ClassNode> readClasses(String jarPath) throws IOException {
Map<String, ClassNode> map = new HashMap<>();
Expand All @@ -42,7 +43,7 @@ public Map<String, ClassNode> readClasses(String jarPath) throws IOException {
} catch (IndexOutOfBoundsException ioobe) {
if (name == null) {
recaf.window.displayError(new RuntimeException("Failed reading class from: " + entry.getName(),
ioobe));
ioobe));
} else {
recaf.window.displayError(new RuntimeException("Failed reading into node structure: " + name, ioobe));
}
Expand All @@ -54,10 +55,11 @@ public Map<String, ClassNode> readClasses(String jarPath) throws IOException {

/**
* Reads non-classes from the given jar.
*
* @param jarPath
* @return
* @throws IOException
*
* @param jarPath Path to jarfile to read non-classes from.
* @return Map of non-classes from the specified jarfile.
* @throws IOException If an error was encountered while reading the
* jarfile.
*/
public Map<String, byte[]> readNonClasses(String jarPath) throws IOException {
Map<String, byte[]> map = new HashMap<>();
Expand All @@ -78,9 +80,9 @@ public Map<String, byte[]> readNonClasses(String jarPath) throws IOException {

/**
* Creates a ClassNode from the given ClassReader.
*
* @param cr
* @return
*
* @param cr The class read to obtain the node from.
* @return The node obtained from cr.
*/
private ClassNode getNode(ClassReader cr) {
ClassNode cn = new ClassNode();
Expand All @@ -90,10 +92,10 @@ private ClassNode getNode(ClassReader cr) {

/**
* Creates a ClassNode from the given class.
*
* @param c
* @return
* @throws IOException
*
* @param c The target class.
* @return Node generated from c.
* @throws IOException If an error occurs while loading the class.
*/
public ClassNode getNode(Class<?> c) throws IOException {
String name = c.getName();
Expand All @@ -109,9 +111,9 @@ public ClassNode getNode(Class<?> c) throws IOException {

/**
* Writes a ClassNode to a byte array.
*
* @param cn
* @return
*
* @param cn The target class node.
* @return ByteArray representation of cn.
*/
public byte[] toBytes(ClassNode cn) {
ClassWriter cw = new NonReflectionWriter(recaf.options.classFlagsOutput);
Expand Down
4 changes: 2 additions & 2 deletions src/me/coley/recaf/asm/NonReflectionWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected String getCommonSuperClass(String type1, String type2) {
/**
* Checks if the given parent is a superclass or superinterface of the given
* child.
*
*
* @param parent
* @param child
* @return
Expand All @@ -78,7 +78,7 @@ private boolean isAssignableFrom(ClassNode parent, ClassNode child) {

/**
* Load node from the node map.
*
*
* @param type
* @return
*/
Expand Down
38 changes: 26 additions & 12 deletions src/me/coley/recaf/asm/OpcodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,41 @@ public class OpcodeUtil implements Opcodes {
"LSHL", "ISHR", "LSHR", "IUSHR", "LUSHR", "IAND", "LAND", "IOR", "LOR", "IXOR", "LXOR", "I2L", "I2F", "I2D", "L2I",
"L2F", "L2D", "F2I", "F2L", "F2D", "D2I", "D2L", "D2F", "I2B", "I2C", "I2S", "LCMP", "FCMPL", "FCMPG", "DCMPL",
"DCMPG", "IRETURN", "LRETURN", "FRETURN", "DRETURN", "ARETURN", "RETURN", "ARRAYLENGTH", "ATHROW", "MONITORENTER",
"MONITOREXIT" };
"MONITOREXIT"
};
/**
* Subset of {@link #OPS_INSN} for constants.
*/
public static String[] OPS_INSN_SUB_CONSTS = new String[] { "ACONST_NULL", "ICONST_M1", "ICONST_0", "ICONST_1", "ICONST_2",
"ICONST_3", "ICONST_4", "ICONST_5", "LCONST_0", "LCONST_1", "FCONST_0", "FCONST_1", "FCONST_2", "DCONST_0",
"DCONST_1" };
"DCONST_1"
};
/**
* Subset of {@link #OPS_INSN} for array loads/saves/etc.
*/
public static String[] OPS_INSN_SUB_ARRAY = new String[] { "IALOAD", "LALOAD", "FALOAD", "DALOAD", "AALOAD", "BALOAD",
"CALOAD", "SALOAD", "IASTORE", "LASTORE", "FASTORE", "DASTORE", "AASTORE", "BASTORE", "CASTORE", "SASTORE",
"ARRAYLENGTH" };
"ARRAYLENGTH"
};
/**
* Subset of {@link #OPS_INSN} for stack management.
*/
public static String[] OPS_INSN_SUB_STACK = new String[] { "POP", "POP2", "DUP", "DUP_X1", "DUP_X2", "DUP2", "DUP2_X1",
"DUP2_X2", "SWAP" };
"DUP2_X2", "SWAP"
};
/**
* Subset of {@link #OPS_INSN} for math handling.
*/
public static String[] OPS_INSN_SUB_MATH = new String[] { "IADD", "LADD", "FADD", "DADD", "ISUB", "LSUB", "FSUB", "DSUB",
"IMUL", "LMUL", "FMUL", "DMUL", "IDIV", "LDIV", "FDIV", "DDIV", "IREM", "LREM", "FREM", "DREM", "INEG", "LNEG",
"FNEG", "DNEG", "ISHL", "LSHL", "ISHR", "LSHR", "IUSHR", "LUSHR", "IAND", "LAND", "IOR", "LOR", "IXOR" };
"FNEG", "DNEG", "ISHL", "LSHL", "ISHR", "LSHR", "IUSHR", "LUSHR", "IAND", "LAND", "IOR", "LOR", "IXOR"
};
/**
* Subset of {@link #OPS_INSN} for type conversion.
*/
public static String[] OPS_INSN_SUB_CONVERT = new String[] { "I2L", "I2F", "I2D", "L2I", "L2F", "L2D", "F2I", "F2L", "F2D",
"D2I", "D2L", "D2F", "I2B", "I2C", "I2S" };
"D2I", "D2L", "D2F", "I2B", "I2C", "I2S"
};
/**
* Subset of {@link #OPS_INSN} for primitve comparisons.
*/
Expand All @@ -79,7 +85,8 @@ public class OpcodeUtil implements Opcodes {
* Opcodes of INT type.
*/
public static String[] OPS_VAR = new String[] { "ILOAD", "LLOAD", "FLOAD", "DLOAD", "ALOAD", "ISTORE", "LSTORE", "FSTORE",
"DSTORE", "ASTORE", "RET" };
"DSTORE", "ASTORE", "RET"
};
/**
* Opcodes of TYPE type.
*/
Expand All @@ -100,7 +107,8 @@ public class OpcodeUtil implements Opcodes {
* Opcodes of JUMP type.
*/
public static String[] OPS_JUMP = new String[] { "IFEQ", "IFNE", "IFLT", "IFGE", "IFGT", "IFLE", "IF_ICMPEQ", "IF_ICMPNE",
"IF_ICMPLT", "IF_ICMPGE", "IF_ICMPGT", "IF_ICMPLE", "IF_ACMPEQ", "IF_ACMPNE", "GOTO", "JSR", "IFNULL", "IFNONNULL" };
"IF_ICMPLT", "IF_ICMPGE", "IF_ICMPGT", "IF_ICMPLE", "IF_ACMPEQ", "IF_ACMPNE", "GOTO", "JSR", "IFNULL", "IFNONNULL"
};
/**
* Opcodes of LDC type.
*/
Expand Down Expand Up @@ -129,7 +137,8 @@ public class OpcodeUtil implements Opcodes {
* Empty list.
*/
public static String[] OPS_TAG = new String[] { "H_GETFIELD", "H_GETSTATIC", "H_PUTFIELD", "H_PUTSTATIC", "H_INVOKEINTERFACE",
"H_INVOKESPECIAL", "H_INVOKESTATIC", "H_INVOKEVIRTUAL", "H_NEWINVOKESPECIAL" };
"H_INVOKESPECIAL", "H_INVOKESTATIC", "H_INVOKEVIRTUAL", "H_NEWINVOKESPECIAL"
};
/**
* Opcodes of LABEL type. Also see {@link #OPS_FRAME}[0].
*/
Expand Down Expand Up @@ -173,9 +182,14 @@ public static String[] typeToCodes(int type) {

/**
* Return smaller subset of the {@link #OPS_INSN} string array.
*
* @param name
* @return
*
* @param name The name of the target array.
* @return The desired subset.
*
* TODO: I have no idea what this is, just filling in some stubs
* so JavaDoc is happy.
*
* - Charles
*/
public static String[] getInsnSubset(String name) {
//@formatter:off
Expand Down
Loading