< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/StringConcat.java

Print this page

        

@@ -31,12 +31,11 @@
 import com.sun.tools.javac.tree.TreeInfo;
 import com.sun.tools.javac.tree.TreeMaker;
 import com.sun.tools.javac.util.*;
 
 import static com.sun.tools.javac.code.Kinds.Kind.MTH;
-import static com.sun.tools.javac.code.TypeTag.DOUBLE;
-import static com.sun.tools.javac.code.TypeTag.LONG;
+import static com.sun.tools.javac.code.TypeTag.*;
 import static com.sun.tools.javac.jvm.ByteCodes.*;
 import static com.sun.tools.javac.tree.JCTree.Tag.PLUS;
 import com.sun.tools.javac.jvm.Items.*;
 
 import java.util.HashMap;

@@ -141,10 +140,29 @@
         }
         return res.append(tree);
     }
 
     /**
+     * If the type is not accessible from current context, try to figure out the
+     * sharpest accessible supertype.
+     *
+     * @param originalType type to sharpen
+     * @return sharped type
+     */
+    protected Type sharpestAccessible(Type originalType) {
+        if (originalType.hasTag(ARRAY)) {
+            return types.makeArrayType(sharpestAccessible(types.elemtype(originalType)));
+        }
+
+        Type type = originalType;
+        while (!rs.isAccessible(gen.getAttrEnv(), type.asElement())) {
+            type = types.supertype(type);
+        }
+        return type;
+    }
+
+    /**
      * "Legacy" bytecode flavor: emit the StringBuilder.append chains for string
      * concatenation.
      */
     private static class Inline extends StringConcat {
         public Inline(Context context) {

@@ -312,11 +330,11 @@
                     Object constVal = arg.type.constValue();
                     if ("".equals(constVal)) continue;
                     if (arg.type == syms.botType) {
                         dynamicArgs.add(types.boxedClass(syms.voidType).type);
                     } else {
-                        dynamicArgs.add(arg.type);
+                        dynamicArgs.add(sharpestAccessible(arg.type));
                     }
                     gen.genExpr(arg, arg.type).load();
                 }
 
                 doCall(type, pos, dynamicArgs.toList());

@@ -413,11 +431,11 @@
                             recipe.append(a);
                         }
                     } else {
                         // Ordinary arguments come through the dynamic arguments.
                         recipe.append(TAG_ARG);
-                        dynamicArgs.add(arg.type);
+                        dynamicArgs.add(sharpestAccessible(arg.type));
                         gen.genExpr(arg, arg.type).load();
                     }
                 }
 
                 doCall(type, pos, recipe.toString(), staticArgs.toList(), dynamicArgs.toList());
< prev index next >