diff options
author | md_5 <git@md-5.net> | 2017-08-03 23:00:00 +1000 |
---|---|---|
committer | md_5 <git@md-5.net> | 2017-08-03 23:00:00 +1000 |
commit | cbcd1a61d6908fa5779d0c1b6a0c980a67f41b07 (patch) | |
tree | a43b701c04d700f48e2dc92deff16ba925dd0701 | |
parent | 20ea719b7479a7ed66979f6f1766575bfc6fecab (diff) | |
download | fernflower-cbcd1a61d6908fa5779d0c1b6a0c980a67f41b07.tar fernflower-cbcd1a61d6908fa5779d0c1b6a0c980a67f41b07.tar.gz fernflower-cbcd1a61d6908fa5779d0c1b6a0c980a67f41b07.tar.lz fernflower-cbcd1a61d6908fa5779d0c1b6a0c980a67f41b07.tar.xz fernflower-cbcd1a61d6908fa5779d0c1b6a0c980a67f41b07.zip |
More lambda fixes
-rw-r--r-- | src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java | 26 | ||||
-rw-r--r-- | src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java | 35 |
2 files changed, 14 insertions, 47 deletions
diff --git a/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java b/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java index 743ce12..437568b 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java @@ -36,10 +36,9 @@ import java.util.*; public class LambdaProcessor { - private static final String JAVAC_LAMBDA_CLASS = "java/lang/invoke/LambdaMetafactory"; - private static final String JAVAC_LAMBDA_METHOD = "metafactory"; - private static final String JAVAC_LAMBDA_METHOD_DESCRIPTOR = - "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"; + @SuppressWarnings("SpellCheckingInspection") private static final String JAVAC_LAMBDA_CLASS = "java/lang/invoke/LambdaMetafactory"; + @SuppressWarnings("SpellCheckingInspection") private static final String JAVAC_LAMBDA_METHOD = "metafactory"; + @SuppressWarnings("SpellCheckingInspection") private static final String JAVAC_LAMBDA_ALT_METHOD = "altMetafactory"; public void processClass(ClassNode node) throws IOException { @@ -47,9 +46,7 @@ public class LambdaProcessor { processClass(child); } - if (node.nested.isEmpty()) { - hasLambda(node); - } + hasLambda(node); } public boolean hasLambda(ClassNode node) throws IOException { @@ -67,17 +64,16 @@ public class LambdaProcessor { return false; // no bootstrap constants in pool } - Set<Integer> lambda_methods = new HashSet<Integer>(); + BitSet lambda_methods = new BitSet(); // find lambda bootstrap constants for (int i = 0; i < bootstrap.getMethodsNumber(); ++i) { LinkConstant method_ref = bootstrap.getMethodReference(i); // method handle + // FIXME: extend for Eclipse etc. at some point if (JAVAC_LAMBDA_CLASS.equals(method_ref.classname) && - JAVAC_LAMBDA_METHOD.equals(method_ref.elementname) && - JAVAC_LAMBDA_METHOD_DESCRIPTOR - .equals(method_ref.descriptor)) { // check for javac lambda structure. FIXME: extend for Eclipse etc. at some point - lambda_methods.add(i); + (JAVAC_LAMBDA_METHOD.equals(method_ref.elementname) || JAVAC_LAMBDA_ALT_METHOD.equals(method_ref.elementname))) { + lambda_methods.set(i); } } @@ -101,7 +97,7 @@ public class LambdaProcessor { if (instr.opcode == CodeConstants.opc_invokedynamic) { LinkConstant invoke_dynamic = cl.getPool().getLinkConstant(instr.getOperand(0)); - if (lambda_methods.contains(invoke_dynamic.index1)) { // lambda invocation found + if (lambda_methods.get(invoke_dynamic.index1)) { // lambda invocation found List<PooledConstant> bootstrap_arguments = bootstrap.getMethodArguments(invoke_dynamic.index1); MethodDescriptor md = MethodDescriptor.parseDescriptor(invoke_dynamic.descriptor); @@ -122,7 +118,9 @@ public class LambdaProcessor { node_lambda.parent = node; clprocessor.getMapRootClasses().put(node_lambda.simpleName, node_lambda); - mapMethodsLambda.put(node_lambda.lambda_information.content_method_key, node_lambda.simpleName); + if (!node_lambda.lambda_information.is_method_reference) { + mapMethodsLambda.put(node_lambda.lambda_information.content_method_key, node_lambda.simpleName); + } } } } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java index d2b717c..68e8cfb 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java @@ -147,6 +147,7 @@ public class InvocationExprent extends Exprent { instance = instance.copy(); } invocationTyp = expr.getInvocationTyp(); + invoke_dynamic_classsuffix = expr.getInvokeDynamicClassSuffix(); stringDescriptor = expr.getStringDescriptor(); descriptor = expr.getDescriptor(); lstParameters = new ArrayList<Exprent>(expr.getLstParameters()); @@ -198,39 +199,7 @@ public class InvocationExprent extends Exprent { tracer.addMapping(bytecode); - if (invocationTyp == INVOKE_DYNAMIC) { - // ClassNode node = (ClassNode)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASSNODE); - // - // if(node != null) { - // ClassNode lambda_node = DecompilerContext.getClassprocessor().getMapRootClasses().get(node.classStruct.qualifiedName + invoke_dynamic_classsuffix); - // if(lambda_node != null) { - // - // String typename = ExprProcessor.getCastTypeName(lambda_node.anonimousClassType); - // - // StringWriter strwriter = new StringWriter(); - // BufferedWriter bufstrwriter = new BufferedWriter(strwriter); - // - // ClassWriter clwriter = new ClassWriter(); - // - // try { - // bufstrwriter.write("new " + typename + "() {"); - // bufstrwriter.newLine(); - // - // - // - // bufstrwriter.flush(); - // } catch(IOException ex) { - // throw new RuntimeException(ex); - // } - // - // buf.append(strwriter.toString()); - // - // } - // } - - } - else if (isStatic) { - + if (isStatic) { ClassNode node = (ClassNode)DecompilerContext.getProperty(DecompilerContext.CURRENT_CLASS_NODE); if (node == null || !classname.equals(node.classStruct.qualifiedName)) { buf.append(DecompilerContext.getImportCollector().getShortName(ExprProcessor.buildJavaClassName(classname))); |