changeset 1898:5b76c6a55f2b

Sync lambda langtools repo to TL lambda javac code
author rfield
date Thu, 07 Mar 2013 21:51:35 -0800
parents 2a8ba01b4f08
children 8e932c496ef2
files src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
diffstat 1 files changed, 36 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Mar 07 08:18:27 2013 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Mar 07 21:51:35 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -70,7 +70,7 @@
  *  deletion without notice.</b>
  */
 public class LambdaToMethod extends TreeTranslator {
-    
+
     private Lower lower;
     private Names names;
     private Symtab syms;
@@ -127,7 +127,8 @@
             MethodType type = new MethodType(List.of(syms.serializedLambdaType), syms.objectType,
                     List.<Type>nil(), syms.methodClass);
             deserMethodSym = makeSyntheticMethod(flags, names.deserializeLambda, type, kSym);
-            deserParamSym = new VarSymbol(FINAL, names.fromString("lambda"), syms.serializedLambdaType, deserMethodSym);
+            deserParamSym = new VarSymbol(FINAL, names.fromString("lambda"),
+                    syms.serializedLambdaType, deserMethodSym);
         }
 
         private void addMethod(JCTree decl) {
@@ -741,7 +742,8 @@
                 List<Type> refPTypes = tree.sym.type.getParameterTypes();
                 int refSize = refPTypes.size();
                 int samSize = samPTypes.size();
-                int last = localContext.needsVarArgsConversion() ? refSize - 1 : refSize;   // Last parameter to copy from referenced method
+                // Last parameter to copy from referenced method
+                int last = localContext.needsVarArgsConversion() ? refSize - 1 : refSize;
 
                 List<Type> l = refPTypes;
                 // Use parameter types of the referenced method, excluding final var args
@@ -766,7 +768,8 @@
                         null,
                         null);
                 bridgeDecl.sym = (MethodSymbol) localContext.bridgeSym;
-                bridgeDecl.type = localContext.bridgeSym.type = types.createMethodTypeWithParameters(samDesc, TreeInfo.types(params.toList()));
+                bridgeDecl.type = localContext.bridgeSym.type =
+                        types.createMethodTypeWithParameters(samDesc, TreeInfo.types(params.toList()));
 
                 //bridge method body generation - this can be either a method call or a
                 //new instance creation expression, depending on the member reference kind
@@ -816,7 +819,8 @@
 
             //create the method call expression
             JCExpression apply = make.Apply(List.<JCExpression>nil(), select,
-                    convertArgs(tree.sym, args.toList(), tree.varargsElement)).setType(tree.sym.erasure(types).getReturnType());
+                    convertArgs(tree.sym, args.toList(), tree.varargsElement)).
+                    setType(tree.sym.erasure(types).getReturnType());
 
             apply = transTypes.coerce(apply, localContext.generatedRefSig().getReturnType());
             setVarargsIfNeeded(apply, tree.varargsElement);
@@ -830,7 +834,8 @@
         private JCExpression bridgeExpressionNew() {
             if (tree.kind == ReferenceKind.ARRAY_CTOR) {
                 //create the array creation expression
-                JCNewArray newArr = make.NewArray(make.Type(types.elemtype(tree.getQualifierExpression().type)),
+                JCNewArray newArr = make.NewArray(
+                        make.Type(types.elemtype(tree.getQualifierExpression().type)),
                         List.of(make.Ident(params.first())),
                         null);
                 newArr.type = tree.getQualifierExpression().type;
@@ -885,7 +890,8 @@
         Type mtype = types.erasure(tree.descriptorType);
         MethodSymbol samSym = (MethodSymbol) types.findDescriptorSymbol(tree.type.tsym);
         List<Object> staticArgs = List.<Object>of(
-                new Pool.MethodHandle(ClassFile.REF_invokeInterface, types.findDescriptorSymbol(tree.type.tsym), types),
+                new Pool.MethodHandle(ClassFile.REF_invokeInterface,
+                    types.findDescriptorSymbol(tree.type.tsym), types),
                 new Pool.MethodHandle(refKind, refSym, types),
                 new MethodType(mtype.getParameterTypes(),
                         mtype.getReturnType(),
@@ -935,7 +941,8 @@
      * Generate an indy method call with given name, type and static bootstrap
      * arguments types
      */
-    private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName, List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs) {
+    private JCExpression makeIndyCall(DiagnosticPosition pos, Type site, Name bsmName,
+            List<Object> staticArgs, MethodType indyType, List<JCExpression> indyArgs) {
         int prevPos = make.pos;
         try {
             make.at(pos);
@@ -949,7 +956,9 @@
             DynamicMethodSymbol dynSym =
                     new DynamicMethodSymbol(names.lambda,
                                             syms.noSymbol,
-                                            bsm.isStatic() ? ClassFile.REF_invokeStatic : ClassFile.REF_invokeVirtual,
+                                            bsm.isStatic() ?
+                                                ClassFile.REF_invokeStatic :
+                                                ClassFile.REF_invokeVirtual,
                                             (MethodSymbol)bsm,
                                             indyType,
                                             staticArgs.toArray());
@@ -1042,7 +1051,7 @@
          */
         private Map<String, Integer> serializableLambdaCounts =
                 new HashMap<String, Integer>();
-        
+
         private Map<Symbol, JCClassDecl> localClassDefs;
 
         /**
@@ -1073,7 +1082,7 @@
         }
 
         @Override
-        public void visitClassDef(final JCClassDecl tree) {
+        public void visitClassDef(JCClassDecl tree) {
             List<Frame> prevStack = frameStack;
             Map<String, Integer> prevSerializableLambdaCount =
                     serializableLambdaCounts;
@@ -1120,7 +1129,8 @@
                         if (localContext.tree.getTag() == LAMBDA) {
                             JCTree block = capturedDecl(localContext.depth, tree.sym);
                             if (block == null) break;
-                            ((LambdaTranslationContext)localContext).addSymbol(tree.sym, CAPTURED_VAR);
+                            ((LambdaTranslationContext)localContext)
+                                    .addSymbol(tree.sym, CAPTURED_VAR);
                         }
                         localContext = localContext.prev;
                     }
@@ -1133,7 +1143,8 @@
                             switch (block.getTag()) {
                                 case CLASSDEF:
                                     JCClassDecl cdecl = (JCClassDecl)block;
-                                    ((LambdaTranslationContext)localContext).addSymbol(cdecl.sym, CAPTURED_THIS);
+                                    ((LambdaTranslationContext)localContext)
+                                            .addSymbol(cdecl.sym, CAPTURED_THIS);
                                     break;
                                 default:
                                     Assert.error("bad block kind");
@@ -1190,7 +1201,7 @@
                 }
             }
             if (context() != null && tree.type.tsym.owner.kind == MTH) {
-                LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context();                
+                LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context();
                 captureLocalClassDefs(tree.type.tsym, lambdaContext);
             }
             super.visitNewClass(tree);
@@ -1333,7 +1344,8 @@
                         return ((JCMethodDecl)frameStack2.head.tree).sym;
                     case LAMBDA:
                         if (!skipLambda)
-                            return ((LambdaTranslationContext)contextMap.get(frameStack2.head.tree)).translatedSym;
+                            return ((LambdaTranslationContext)contextMap
+                                    .get(frameStack2.head.tree)).translatedSym;
                     default:
                         frameStack2 = frameStack2.tail;
                 }
@@ -1518,13 +1530,6 @@
         }
 
         /**
-         * Listener class used to keep track of lambda translation context changes
-         */
-        abstract class LambdaTranslationContextListener {
-            abstract void onComplete(LambdaTranslationContext context);
-        }
-
-        /**
          * This class is used to store important information regarding translation of
          * lambda expression/method references (see subclasses).
          */
@@ -1617,7 +1622,8 @@
                         return sym;  // self represented
                     case TYPE_VAR:
                         // Just erase the type var
-                        return new VarSymbol(sym.flags(), names.fromString(name), types.erasure(sym.type), sym.owner);
+                        return new VarSymbol(sym.flags(), names.fromString(name),
+                                types.erasure(sym.type), sym.owner);
                     case CAPTURED_VAR:
                         return new VarSymbol(SYNTHETIC | FINAL, names.fromString(name), types.erasure(sym.type), translatedSym) {
                             @Override
@@ -1703,7 +1709,8 @@
 
                 // If instance access isn't needed, make it static
                 // Interface methods much be public default methods, otherwise make it private
-                translatedSym.flags_field = SYNTHETIC | (needInstance? 0 : STATIC) | (inInterface? PUBLIC | DEFAULT : PRIVATE);
+                translatedSym.flags_field = SYNTHETIC | (needInstance? 0 : STATIC) |
+                        (inInterface? PUBLIC | DEFAULT : PRIVATE);
 
                 //compute synthetic params
                 ListBuffer<JCVariableDecl> params = ListBuffer.lb();
@@ -1771,12 +1778,15 @@
 
             boolean isPrivateConstructor() {
                 //hack needed to workaround 292 bug (8005122)
+                //when 292 issue is fixed we should simply remove this
                 return tree.sym.name == names.init &&
                         (tree.sym.flags() & PRIVATE) != 0;
             }
-            
+
             boolean receiverAccessible() {
                 //hack needed to workaround 292 bug (7087658)
+                //when 292 issue is fixed we should remove this and change the backend
+                //code to always generate a method handle to an accessible method
                 return tree.ownerAccessible;
             }