124 * deserialize method parameter symbol |
124 * deserialize method parameter symbol |
125 */ |
125 */ |
126 private final VarSymbol deserParamSym; |
126 private final VarSymbol deserParamSym; |
127 |
127 |
128 private KlassInfo(Symbol kSym) { |
128 private KlassInfo(Symbol kSym) { |
129 appendedMethodList = ListBuffer.lb(); |
129 appendedMethodList = new ListBuffer<>(); |
130 deserializeCases = new HashMap<String, ListBuffer<JCStatement>>(); |
130 deserializeCases = new HashMap<String, ListBuffer<JCStatement>>(); |
131 long flags = PRIVATE | STATIC | SYNTHETIC; |
131 long flags = PRIVATE | STATIC | SYNTHETIC; |
132 MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType, |
132 MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType, |
133 List.<Type>nil(), syms.methodClass); |
133 List.<Type>nil(), syms.methodClass); |
134 deserMethodSym = makeSyntheticMethod(flags, names.deserializeLambda, type, kSym); |
134 deserMethodSym = makeSyntheticMethod(flags, names.deserializeLambda, type, kSym); |
189 context = prevContext; |
189 context = prevContext; |
190 } |
190 } |
191 } |
191 } |
192 |
192 |
193 <T extends JCTree> List<T> translate(List<T> trees, TranslationContext<?> newContext) { |
193 <T extends JCTree> List<T> translate(List<T> trees, TranslationContext<?> newContext) { |
194 ListBuffer<T> buf = ListBuffer.lb(); |
194 ListBuffer<T> buf = new ListBuffer<>(); |
195 for (T tree : trees) { |
195 for (T tree : trees) { |
196 buf.append(translate(tree, newContext)); |
196 buf.append(translate(tree, newContext)); |
197 } |
197 } |
198 return buf.toList(); |
198 return buf.toList(); |
199 } |
199 } |
302 //should be added the following synthetic arguments: |
302 //should be added the following synthetic arguments: |
303 // |
303 // |
304 // * the "this" argument if it is an instance method |
304 // * the "this" argument if it is an instance method |
305 // * enclosing locals captured by the lambda expression |
305 // * enclosing locals captured by the lambda expression |
306 |
306 |
307 ListBuffer<JCExpression> syntheticInits = ListBuffer.lb(); |
307 ListBuffer<JCExpression> syntheticInits = new ListBuffer<>(); |
308 |
308 |
309 if (!sym.isStatic()) { |
309 if (!sym.isStatic()) { |
310 syntheticInits.append(makeThis( |
310 syntheticInits.append(makeThis( |
311 sym.owner.enclClass().asType(), |
311 sym.owner.enclClass().asType(), |
312 localContext.owner.enclClass())); |
312 localContext.owner.enclClass())); |
467 JCStatement stat = make.Exec(expr); |
467 JCStatement stat = make.Exec(expr); |
468 return make.Block(0, List.<JCStatement>of(stat)); |
468 return make.Block(0, List.<JCStatement>of(stat)); |
469 } else if (isLambda_void && isTarget_Void) { |
469 } else if (isLambda_void && isTarget_Void) { |
470 //void to Void conversion: |
470 //void to Void conversion: |
471 // BODY; return null; |
471 // BODY; return null; |
472 ListBuffer<JCStatement> stats = ListBuffer.lb(); |
472 ListBuffer<JCStatement> stats = new ListBuffer<>(); |
473 stats.append(make.Exec(expr)); |
473 stats.append(make.Exec(expr)); |
474 stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType))); |
474 stats.append(make.Return(make.Literal(BOT, null).setType(syms.botType))); |
475 return make.Block(0, stats.toList()); |
475 return make.Block(0, stats.toList()); |
476 } else { |
476 } else { |
477 //non-void to non-void conversion: |
477 //non-void to non-void conversion: |
529 } |
529 } |
530 return trans_block; |
530 return trans_block; |
531 } |
531 } |
532 |
532 |
533 private JCMethodDecl makeDeserializeMethod(Symbol kSym) { |
533 private JCMethodDecl makeDeserializeMethod(Symbol kSym) { |
534 ListBuffer<JCCase> cases = ListBuffer.lb(); |
534 ListBuffer<JCCase> cases = new ListBuffer<>(); |
535 ListBuffer<JCBreak> breaks = ListBuffer.lb(); |
535 ListBuffer<JCBreak> breaks = new ListBuffer<>(); |
536 for (Map.Entry<String, ListBuffer<JCStatement>> entry : kInfo.deserializeCases.entrySet()) { |
536 for (Map.Entry<String, ListBuffer<JCStatement>> entry : kInfo.deserializeCases.entrySet()) { |
537 JCBreak br = make.Break(null); |
537 JCBreak br = make.Break(null); |
538 breaks.add(br); |
538 breaks.add(br); |
539 List<JCStatement> stmts = entry.getValue().append(br).toList(); |
539 List<JCStatement> stmts = entry.getValue().append(br).toList(); |
540 cases.add(make.Case(make.Literal(entry.getKey()), stmts)); |
540 cases.add(make.Case(make.Literal(entry.getKey()), stmts)); |
592 String implClass = classSig(types.erasure(refSym.owner.type)); |
592 String implClass = classSig(types.erasure(refSym.owner.type)); |
593 String implMethodName = refSym.getQualifiedName().toString(); |
593 String implMethodName = refSym.getQualifiedName().toString(); |
594 String implMethodSignature = methodSig(types.erasure(refSym.type)); |
594 String implMethodSignature = methodSig(types.erasure(refSym.type)); |
595 |
595 |
596 JCExpression kindTest = eqTest(syms.intType, deserGetter("getImplMethodKind", syms.intType), make.Literal(implMethodKind)); |
596 JCExpression kindTest = eqTest(syms.intType, deserGetter("getImplMethodKind", syms.intType), make.Literal(implMethodKind)); |
597 ListBuffer<JCExpression> serArgs = ListBuffer.lb(); |
597 ListBuffer<JCExpression> serArgs = new ListBuffer<>(); |
598 int i = 0; |
598 int i = 0; |
599 for (Type t : indyType.getParameterTypes()) { |
599 for (Type t : indyType.getParameterTypes()) { |
600 List<JCExpression> indexAsArg = ListBuffer.<JCExpression>lb().append(make.Literal(i)).toList(); |
600 List<JCExpression> indexAsArg = new ListBuffer<JCExpression>().append(make.Literal(i)).toList(); |
601 List<Type> argTypes = ListBuffer.<Type>lb().append(syms.intType).toList(); |
601 List<Type> argTypes = new ListBuffer<Type>().append(syms.intType).toList(); |
602 serArgs.add(make.TypeCast(types.erasure(t), deserGetter("getCapturedArg", syms.objectType, argTypes, indexAsArg))); |
602 serArgs.add(make.TypeCast(types.erasure(t), deserGetter("getCapturedArg", syms.objectType, argTypes, indexAsArg))); |
603 ++i; |
603 ++i; |
604 } |
604 } |
605 JCStatement stmt = make.If( |
605 JCStatement stmt = make.If( |
606 deserTest(deserTest(deserTest(deserTest(deserTest( |
606 deserTest(deserTest(deserTest(deserTest(deserTest( |
616 names.altMetafactory, |
616 names.altMetafactory, |
617 staticArgs, indyType, serArgs.toList(), samSym.name)), |
617 staticArgs, indyType, serArgs.toList(), samSym.name)), |
618 null); |
618 null); |
619 ListBuffer<JCStatement> stmts = kInfo.deserializeCases.get(implMethodName); |
619 ListBuffer<JCStatement> stmts = kInfo.deserializeCases.get(implMethodName); |
620 if (stmts == null) { |
620 if (stmts == null) { |
621 stmts = ListBuffer.lb(); |
621 stmts = new ListBuffer<>(); |
622 kInfo.deserializeCases.put(implMethodName, stmts); |
622 kInfo.deserializeCases.put(implMethodName, stmts); |
623 } |
623 } |
624 /**** |
624 /**** |
625 System.err.printf("+++++++++++++++++\n"); |
625 System.err.printf("+++++++++++++++++\n"); |
626 System.err.printf("*functionalInterfaceClass: '%s'\n", functionalInterfaceClass); |
626 System.err.printf("*functionalInterfaceClass: '%s'\n", functionalInterfaceClass); |
726 */ |
726 */ |
727 private class MemberReferenceBridger { |
727 private class MemberReferenceBridger { |
728 |
728 |
729 private final JCMemberReference tree; |
729 private final JCMemberReference tree; |
730 private final ReferenceTranslationContext localContext; |
730 private final ReferenceTranslationContext localContext; |
731 private final ListBuffer<JCExpression> args = ListBuffer.lb(); |
731 private final ListBuffer<JCExpression> args = new ListBuffer<>(); |
732 private final ListBuffer<JCVariableDecl> params = ListBuffer.lb(); |
732 private final ListBuffer<JCVariableDecl> params = new ListBuffer<>(); |
733 |
733 |
734 MemberReferenceBridger(JCMemberReference tree, ReferenceTranslationContext localContext) { |
734 MemberReferenceBridger(JCMemberReference tree, ReferenceTranslationContext localContext) { |
735 this.tree = tree; |
735 this.tree = tree; |
736 this.localContext = localContext; |
736 this.localContext = localContext; |
737 } |
737 } |
932 typeToMethodType(samSym.type), |
932 typeToMethodType(samSym.type), |
933 new Pool.MethodHandle(refKind, refSym, types), |
933 new Pool.MethodHandle(refKind, refSym, types), |
934 typeToMethodType(tree.getDescriptorType(types))); |
934 typeToMethodType(tree.getDescriptorType(types))); |
935 |
935 |
936 //computed indy arg types |
936 //computed indy arg types |
937 ListBuffer<Type> indy_args_types = ListBuffer.lb(); |
937 ListBuffer<Type> indy_args_types = new ListBuffer<>(); |
938 for (JCExpression arg : indy_args) { |
938 for (JCExpression arg : indy_args) { |
939 indy_args_types.append(arg.type); |
939 indy_args_types.append(arg.type); |
940 } |
940 } |
941 |
941 |
942 //finally, compute the type of the indy call |
942 //finally, compute the type of the indy call |
947 |
947 |
948 Name metafactoryName = context.needsAltMetafactory() ? |
948 Name metafactoryName = context.needsAltMetafactory() ? |
949 names.altMetafactory : names.metafactory; |
949 names.altMetafactory : names.metafactory; |
950 |
950 |
951 if (context.needsAltMetafactory()) { |
951 if (context.needsAltMetafactory()) { |
952 ListBuffer<Object> markers = ListBuffer.lb(); |
952 ListBuffer<Object> markers = new ListBuffer<>(); |
953 for (Type t : tree.targets.tail) { |
953 for (Type t : tree.targets.tail) { |
954 if (t.tsym != syms.serializableType.tsym) { |
954 if (t.tsym != syms.serializableType.tsym) { |
955 markers.append(t.tsym); |
955 markers.append(t.tsym); |
956 } |
956 } |
957 } |
957 } |
1025 make.at(prevPos); |
1025 make.at(prevPos); |
1026 } |
1026 } |
1027 } |
1027 } |
1028 //where |
1028 //where |
1029 private List<Type> bsmStaticArgToTypes(List<Object> args) { |
1029 private List<Type> bsmStaticArgToTypes(List<Object> args) { |
1030 ListBuffer<Type> argtypes = ListBuffer.lb(); |
1030 ListBuffer<Type> argtypes = new ListBuffer<>(); |
1031 for (Object arg : args) { |
1031 for (Object arg : args) { |
1032 argtypes.append(bsmStaticArgToType(arg)); |
1032 argtypes.append(bsmStaticArgToType(arg)); |
1033 } |
1033 } |
1034 return argtypes.toList(); |
1034 return argtypes.toList(); |
1035 } |
1035 } |
1849 translatedSym.flags_field = SYNTHETIC | |
1849 translatedSym.flags_field = SYNTHETIC | |
1850 ((inInterface && thisReferenced)? PUBLIC : PRIVATE) | |
1850 ((inInterface && thisReferenced)? PUBLIC : PRIVATE) | |
1851 (thisReferenced? (inInterface? DEFAULT : 0) : STATIC); |
1851 (thisReferenced? (inInterface? DEFAULT : 0) : STATIC); |
1852 |
1852 |
1853 //compute synthetic params |
1853 //compute synthetic params |
1854 ListBuffer<JCVariableDecl> params = ListBuffer.lb(); |
1854 ListBuffer<JCVariableDecl> params = new ListBuffer<>(); |
1855 |
1855 |
1856 // The signature of the method is augmented with the following |
1856 // The signature of the method is augmented with the following |
1857 // synthetic parameters: |
1857 // synthetic parameters: |
1858 // |
1858 // |
1859 // 1) reference to enclosing contexts captured by the lambda expression |
1859 // 1) reference to enclosing contexts captured by the lambda expression |