java-decompiler: fixes and cleanups
- unified attribute loading code - common methods for checking member flags - verifying skip() - correct resource closing - typos
This commit is contained in:
@@ -82,7 +82,7 @@ public class IdeaNotNullHelper {
|
||||
if (first_param.type == Exprent.EXPRENT_VAR) {
|
||||
VarExprent var = (VarExprent)first_param;
|
||||
|
||||
boolean thisvar = (mt.getAccessFlags() & CodeConstants.ACC_STATIC) == 0;
|
||||
boolean thisvar = !mt.hasModifier(CodeConstants.ACC_STATIC);
|
||||
|
||||
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
|
||||
VBStyleCollection<StructGeneralAttribute, String> attributes = mt.getAttributes();
|
||||
|
||||
@@ -109,6 +109,28 @@ public class AssignmentExprent extends Exprent {
|
||||
VarType leftType = left.getExprType();
|
||||
VarType rightType = right.getExprType();
|
||||
|
||||
boolean fieldInStatInit = false;
|
||||
if (left.type == Exprent.EXPRENT_FIELD) { // first assignment to a final field. Field name without "this" in front of it
|
||||
FieldExprent field = (FieldExprent)left;
|
||||
ClassNode node = ((ClassNode)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS_NODE));
|
||||
if (node != null) {
|
||||
StructClass cl = node.classStruct;
|
||||
StructField fd = cl.getField(field.getName(), field.getDescriptor().descriptorString);
|
||||
if (fd != null && field.isStatic() && fd.hasModifier(CodeConstants.ACC_FINAL)) {
|
||||
fieldInStatInit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
if (fieldInStatInit) {
|
||||
buffer.append(((FieldExprent)left).getName());
|
||||
}
|
||||
else {
|
||||
buffer.append(left.toJava(indent));
|
||||
}
|
||||
|
||||
String res = right.toJava(indent);
|
||||
|
||||
if (condtype == CONDITION_NONE &&
|
||||
@@ -121,31 +143,6 @@ public class AssignmentExprent extends Exprent {
|
||||
res = "(" + ExprProcessor.getCastTypeName(leftType) + ")" + res;
|
||||
}
|
||||
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
||||
boolean finstat_init = false;
|
||||
if (left.type == Exprent.EXPRENT_FIELD) { // first assignment to a final field. Field name without "this" in front of it
|
||||
FieldExprent field = (FieldExprent)left;
|
||||
if (field.isStatic()) {
|
||||
ClassNode node = ((ClassNode)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS_NODE));
|
||||
if (node != null) {
|
||||
StructClass cl = node.classStruct;
|
||||
StructField fd = cl.getField(field.getName(), field.getDescriptor().descriptorString);
|
||||
|
||||
if (fd != null && (fd.access_flags & CodeConstants.ACC_FINAL) != 0) {
|
||||
finstat_init = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (finstat_init) {
|
||||
buffer.append(((FieldExprent)left).getName());
|
||||
}
|
||||
else {
|
||||
buffer.append(left.toJava(indent));
|
||||
}
|
||||
|
||||
buffer.append(condtype == CONDITION_NONE ? " = " : funceq[condtype]).append(res);
|
||||
|
||||
return buffer.toString();
|
||||
|
||||
@@ -330,20 +330,19 @@ public class InvocationExprent extends Exprent {
|
||||
List<VarVersionPaar> sigFields = null;
|
||||
boolean isEnum = false;
|
||||
if (functype == TYP_INIT) {
|
||||
ClassNode newnode = DecompilerContext.getClassProcessor().getMapRootClasses().get(classname);
|
||||
ClassNode newNode = DecompilerContext.getClassProcessor().getMapRootClasses().get(classname);
|
||||
|
||||
if (newnode != null) { // own class
|
||||
if (newnode.wrapper != null) {
|
||||
sigFields = newnode.wrapper.getMethodWrapper("<init>", stringDescriptor).signatureFields;
|
||||
if (newNode != null) { // own class
|
||||
if (newNode.wrapper != null) {
|
||||
sigFields = newNode.wrapper.getMethodWrapper("<init>", stringDescriptor).signatureFields;
|
||||
}
|
||||
else {
|
||||
if (newnode.type == ClassNode.CLASS_MEMBER && (newnode.access & CodeConstants.ACC_STATIC) == 0) { // non-static member class
|
||||
if (newNode.type == ClassNode.CLASS_MEMBER && (newNode.access & CodeConstants.ACC_STATIC) == 0) { // non-static member class
|
||||
sigFields = new ArrayList<VarVersionPaar>(Collections.nCopies(lstParameters.size(), (VarVersionPaar)null));
|
||||
sigFields.set(0, new VarVersionPaar(-1, 0));
|
||||
}
|
||||
}
|
||||
isEnum = (newnode.classStruct.access_flags & CodeConstants.ACC_ENUM) != 0 &&
|
||||
DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM);
|
||||
isEnum = newNode.classStruct.hasModifier(CodeConstants.ACC_ENUM) && DecompilerContext.getOption(IFernflowerPreferences.DECOMPILE_ENUM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -487,8 +487,7 @@ public class SSAConstructorSparseEx {
|
||||
}
|
||||
|
||||
private SFormsFastMapDirect createFirstMap(StructMethod mt) {
|
||||
|
||||
boolean thisvar = (mt.getAccessFlags() & CodeConstants.ACC_STATIC) == 0;
|
||||
boolean thisvar = !mt.hasModifier(CodeConstants.ACC_STATIC);
|
||||
|
||||
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
|
||||
|
||||
|
||||
@@ -756,8 +756,7 @@ public class SSAUConstructorSparseEx {
|
||||
}
|
||||
|
||||
private SFormsFastMapDirect createFirstMap(StructMethod mt, RootStatement root) {
|
||||
|
||||
boolean thisvar = (mt.getAccessFlags() & CodeConstants.ACC_STATIC) == 0;
|
||||
boolean thisvar = !mt.hasModifier(CodeConstants.ACC_STATIC);
|
||||
|
||||
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class VarDefinitionHelper {
|
||||
|
||||
VarNamesCollector vc = DecompilerContext.getVarNamesCollector();
|
||||
|
||||
boolean thisvar = (mt.getAccessFlags() & CodeConstants.ACC_STATIC) == 0;
|
||||
boolean thisvar = !mt.hasModifier(CodeConstants.ACC_STATIC);
|
||||
|
||||
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class VarTypeProcessor {
|
||||
StructMethod mt = (StructMethod)DecompilerContext.getProperty(DecompilerContext.CURRENT_METHOD);
|
||||
|
||||
// method descriptor
|
||||
boolean thisvar = (mt.getAccessFlags() & CodeConstants.ACC_STATIC) == 0;
|
||||
boolean thisvar = !mt.hasModifier(CodeConstants.ACC_STATIC);
|
||||
|
||||
MethodDescriptor md = (MethodDescriptor)DecompilerContext.getProperty(DecompilerContext.CURRENT_METHOD_DESCRIPTOR);
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ public class VarVersionsProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
boolean is_method_static = (mt.getAccessFlags() & CodeConstants.ACC_STATIC) != 0;
|
||||
boolean is_method_static = mt.hasModifier(CodeConstants.ACC_STATIC);
|
||||
|
||||
final HashMap<VarVersionPaar, Integer> mapMergedVersions = new HashMap<VarVersionPaar, Integer>();
|
||||
|
||||
|
||||
@@ -232,11 +232,10 @@ public class IdentifierConverter {
|
||||
StructMethod mt = methods.get(i);
|
||||
String key = methods.getKey(i);
|
||||
|
||||
int access_flags = mt.getAccessFlags();
|
||||
boolean isPrivate = ((access_flags & CodeConstants.ACC_PRIVATE) != 0);
|
||||
boolean isPrivate = mt.hasModifier(CodeConstants.ACC_PRIVATE);
|
||||
|
||||
String name = mt.getName();
|
||||
if (!cl.isOwn() || (access_flags & CodeConstants.ACC_NATIVE) != 0) {
|
||||
if (!cl.isOwn() || mt.hasModifier(CodeConstants.ACC_NATIVE)) {
|
||||
// external and native methods must not be renamed
|
||||
if (!isPrivate) {
|
||||
names.put(key, name);
|
||||
@@ -426,8 +425,7 @@ public class IdentifierConverter {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
||||
boolean isInterface = ((clstr.access_flags & CodeConstants.ACC_INTERFACE) != 0);
|
||||
boolean isInterface = clstr.hasModifier(CodeConstants.ACC_INTERFACE);
|
||||
boolean found_parent = false;
|
||||
|
||||
if (isInterface) {
|
||||
|
||||
Reference in New Issue
Block a user