test/tools/javac/lambda/TestInvokeDynamic.java

Tue, 18 Dec 2012 22:16:45 +0000

author
mcimadamore
date
Tue, 18 Dec 2012 22:16:45 +0000
changeset 1461
250f0acf880c
parent 1452
de1ec6fc93fe
child 1482
954541f13717
permissions
-rw-r--r--

8005193: New regression test test/tools/javac/lambda/BadMethodCall2.java fails
Summary: Bad golden file in negative test
Reviewed-by: jjh

mcimadamore@1336 1 /*
mcimadamore@1336 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
mcimadamore@1336 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mcimadamore@1336 4 *
mcimadamore@1336 5 * This code is free software; you can redistribute it and/or modify it
mcimadamore@1336 6 * under the terms of the GNU General Public License version 2 only, as
mcimadamore@1336 7 * published by the Free Software Foundation.
mcimadamore@1336 8 *
mcimadamore@1336 9 * This code is distributed in the hope that it will be useful, but WITHOUT
mcimadamore@1336 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mcimadamore@1336 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mcimadamore@1336 12 * version 2 for more details (a copy is included in the LICENSE file that
mcimadamore@1336 13 * accompanied this code).
mcimadamore@1336 14 *
mcimadamore@1336 15 * You should have received a copy of the GNU General Public License version
mcimadamore@1336 16 * 2 along with this work; if not, write to the Free Software Foundation,
mcimadamore@1336 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mcimadamore@1336 18 *
mcimadamore@1336 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mcimadamore@1336 20 * or visit www.oracle.com if you need additional information or have any
mcimadamore@1336 21 * questions.
mcimadamore@1336 22 */
mcimadamore@1336 23
mcimadamore@1336 24 /*
mcimadamore@1336 25 * @test
mcimadamore@1336 26 * @bug 7194586
mcimadamore@1336 27 *
mcimadamore@1415 28 * @bug 8003280
mcimadamore@1415 29 * @summary Add lambda tests
mcimadamore@1415 30 * Add back-end support for invokedynamic
mcimadamore@1336 31 *
mcimadamore@1336 32 */
mcimadamore@1336 33
mcimadamore@1336 34 import com.sun.source.tree.MethodInvocationTree;
mcimadamore@1336 35 import com.sun.source.tree.MethodTree;
mcimadamore@1336 36 import com.sun.source.util.TaskEvent;
mcimadamore@1336 37 import com.sun.source.util.TaskListener;
mcimadamore@1336 38 import com.sun.source.util.TreeScanner;
mcimadamore@1336 39
mcimadamore@1336 40 import com.sun.tools.classfile.Attribute;
mcimadamore@1336 41 import com.sun.tools.classfile.BootstrapMethods_attribute;
mcimadamore@1336 42 import com.sun.tools.classfile.ClassFile;
mcimadamore@1336 43 import com.sun.tools.classfile.Code_attribute;
mcimadamore@1336 44 import com.sun.tools.classfile.ConstantPool.*;
mcimadamore@1336 45 import com.sun.tools.classfile.Instruction;
mcimadamore@1336 46 import com.sun.tools.classfile.Method;
mcimadamore@1336 47
mcimadamore@1336 48 import com.sun.tools.javac.api.JavacTaskImpl;
mcimadamore@1336 49 import com.sun.tools.javac.api.JavacTool;
mcimadamore@1336 50 import com.sun.tools.javac.code.Symbol;
mcimadamore@1336 51 import com.sun.tools.javac.code.Symbol.MethodSymbol;
mcimadamore@1336 52 import com.sun.tools.javac.code.Symtab;
vromero@1452 53 import com.sun.tools.javac.code.Types;
mcimadamore@1336 54 import com.sun.tools.javac.jvm.Pool;
mcimadamore@1336 55 import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
mcimadamore@1336 56 import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
mcimadamore@1336 57 import com.sun.tools.javac.tree.JCTree.JCIdent;
mcimadamore@1336 58 import com.sun.tools.javac.util.Context;
mcimadamore@1336 59 import com.sun.tools.javac.util.Names;
mcimadamore@1336 60
mcimadamore@1336 61 import java.io.File;
mcimadamore@1336 62 import java.net.URI;
mcimadamore@1336 63 import java.util.ArrayList;
mcimadamore@1336 64 import java.util.Arrays;
mcimadamore@1336 65 import java.util.Locale;
mcimadamore@1336 66
mcimadamore@1336 67 import javax.tools.Diagnostic;
mcimadamore@1336 68 import javax.tools.JavaCompiler;
mcimadamore@1336 69 import javax.tools.JavaFileManager;
mcimadamore@1336 70 import javax.tools.JavaFileObject;
mcimadamore@1336 71 import javax.tools.SimpleJavaFileObject;
mcimadamore@1336 72 import javax.tools.StandardJavaFileManager;
mcimadamore@1336 73 import javax.tools.ToolProvider;
mcimadamore@1336 74
mcimadamore@1336 75 import static com.sun.tools.javac.jvm.ClassFile.*;
mcimadamore@1336 76
mcimadamore@1336 77 public class TestInvokeDynamic {
mcimadamore@1336 78
mcimadamore@1336 79 static int checkCount = 0;
mcimadamore@1336 80
mcimadamore@1336 81 enum StaticArgumentKind {
mcimadamore@1336 82 STRING("Hello!", "String", "Ljava/lang/String;") {
mcimadamore@1336 83 @Override
mcimadamore@1336 84 boolean check(CPInfo cpInfo) throws Exception {
mcimadamore@1336 85 return (cpInfo instanceof CONSTANT_String_info) &&
mcimadamore@1336 86 ((CONSTANT_String_info)cpInfo).getString().equals(value);
mcimadamore@1336 87 }
mcimadamore@1336 88 },
mcimadamore@1336 89 CLASS(null, "Class<?>", "Ljava/lang/Class;") {
mcimadamore@1336 90 @Override
mcimadamore@1336 91 boolean check(CPInfo cpInfo) throws Exception {
mcimadamore@1336 92 return (cpInfo instanceof CONSTANT_Class_info) &&
mcimadamore@1336 93 ((CONSTANT_Class_info)cpInfo).getName().equals("java/lang/String");
mcimadamore@1336 94 }
mcimadamore@1336 95 },
mcimadamore@1336 96 INTEGER(1, "int", "I") {
mcimadamore@1336 97 @Override
mcimadamore@1336 98 boolean check(CPInfo cpInfo) throws Exception {
mcimadamore@1336 99 return (cpInfo instanceof CONSTANT_Integer_info) &&
mcimadamore@1336 100 ((CONSTANT_Integer_info)cpInfo).value == ((Integer)value).intValue();
mcimadamore@1336 101 }
mcimadamore@1336 102 },
mcimadamore@1336 103 LONG(1L, "long", "J") {
mcimadamore@1336 104 @Override
mcimadamore@1336 105 boolean check(CPInfo cpInfo) throws Exception {
mcimadamore@1336 106 return (cpInfo instanceof CONSTANT_Long_info) &&
mcimadamore@1336 107 ((CONSTANT_Long_info)cpInfo).value == ((Long)value).longValue();
mcimadamore@1336 108 }
mcimadamore@1336 109 },
mcimadamore@1336 110 FLOAT(1.0f, "float", "F") {
mcimadamore@1336 111 @Override
mcimadamore@1336 112 boolean check(CPInfo cpInfo) throws Exception {
mcimadamore@1336 113 return (cpInfo instanceof CONSTANT_Float_info) &&
mcimadamore@1336 114 ((CONSTANT_Float_info)cpInfo).value == ((Float)value).floatValue();
mcimadamore@1336 115 }
mcimadamore@1336 116 },
mcimadamore@1336 117 DOUBLE(1.0, "double","D") {
mcimadamore@1336 118 @Override
mcimadamore@1336 119 boolean check(CPInfo cpInfo) throws Exception {
mcimadamore@1336 120 return (cpInfo instanceof CONSTANT_Double_info) &&
mcimadamore@1336 121 ((CONSTANT_Double_info)cpInfo).value == ((Double)value).doubleValue();
mcimadamore@1336 122 }
mcimadamore@1336 123 },
mcimadamore@1336 124 METHOD_HANDLE(null, "MethodHandle", "Ljava/lang/invoke/MethodHandle;") {
mcimadamore@1336 125 @Override
mcimadamore@1336 126 boolean check(CPInfo cpInfo) throws Exception {
mcimadamore@1336 127 if (!(cpInfo instanceof CONSTANT_MethodHandle_info)) return false;
mcimadamore@1336 128 CONSTANT_MethodHandle_info handleInfo = (CONSTANT_MethodHandle_info)cpInfo;
mcimadamore@1336 129 return handleInfo.getCPRefInfo().getClassName().equals("Array") &&
mcimadamore@1336 130 handleInfo.reference_kind == RefKind.REF_invokeVirtual &&
mcimadamore@1336 131 handleInfo.getCPRefInfo().getNameAndTypeInfo().getName().equals("clone") &&
mcimadamore@1336 132 handleInfo.getCPRefInfo().getNameAndTypeInfo().getType().equals("()Ljava/lang/Object;");
mcimadamore@1336 133 }
mcimadamore@1336 134 },
mcimadamore@1336 135 METHOD_TYPE(null, "MethodType", "Ljava/lang/invoke/MethodType;") {
mcimadamore@1336 136 @Override
mcimadamore@1336 137 boolean check(CPInfo cpInfo) throws Exception {
mcimadamore@1336 138 return (cpInfo instanceof CONSTANT_MethodType_info) &&
mcimadamore@1336 139 ((CONSTANT_MethodType_info)cpInfo).getType().equals("()Ljava/lang/Object;");
mcimadamore@1336 140 }
mcimadamore@1336 141 };
mcimadamore@1336 142
mcimadamore@1336 143 Object value;
mcimadamore@1336 144 String sourceTypeStr;
mcimadamore@1336 145 String bytecodeTypeStr;
mcimadamore@1336 146
mcimadamore@1336 147 StaticArgumentKind(Object value, String sourceTypeStr, String bytecodeTypeStr) {
mcimadamore@1336 148 this.value = value;
mcimadamore@1336 149 this.sourceTypeStr = sourceTypeStr;
mcimadamore@1336 150 this.bytecodeTypeStr = bytecodeTypeStr;
mcimadamore@1336 151 }
mcimadamore@1336 152
mcimadamore@1336 153 abstract boolean check(CPInfo cpInfo) throws Exception;
mcimadamore@1336 154
vromero@1452 155 Object getValue(Symtab syms, Names names, Types types) {
mcimadamore@1336 156 switch (this) {
mcimadamore@1336 157 case STRING:
mcimadamore@1336 158 case INTEGER:
mcimadamore@1336 159 case LONG:
mcimadamore@1336 160 case FLOAT:
mcimadamore@1336 161 case DOUBLE:
mcimadamore@1336 162 return value;
mcimadamore@1336 163 case CLASS:
mcimadamore@1336 164 return syms.stringType.tsym;
mcimadamore@1336 165 case METHOD_HANDLE:
vromero@1452 166 return new Pool.MethodHandle(REF_invokeVirtual, syms.arrayCloneMethod, types);
mcimadamore@1336 167 case METHOD_TYPE:
mcimadamore@1336 168 return syms.arrayCloneMethod.type;
mcimadamore@1336 169 default:
mcimadamore@1336 170 throw new AssertionError();
mcimadamore@1336 171 }
mcimadamore@1336 172 }
mcimadamore@1336 173 }
mcimadamore@1336 174
mcimadamore@1336 175 enum StaticArgumentsArity {
mcimadamore@1336 176 ZERO(0),
mcimadamore@1336 177 ONE(1),
mcimadamore@1336 178 TWO(2),
mcimadamore@1336 179 THREE(3);
mcimadamore@1336 180
mcimadamore@1336 181 int arity;
mcimadamore@1336 182
mcimadamore@1336 183 StaticArgumentsArity(int arity) {
mcimadamore@1336 184 this.arity = arity;
mcimadamore@1336 185 }
mcimadamore@1336 186 }
mcimadamore@1336 187
mcimadamore@1336 188 public static void main(String... args) throws Exception {
mcimadamore@1336 189 // Create a single file manager and compiler and reuse it for each compile to save time.
mcimadamore@1336 190 StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
mcimadamore@1336 191 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
mcimadamore@1336 192 for (StaticArgumentsArity arity : StaticArgumentsArity.values()) {
mcimadamore@1336 193 if (arity.arity == 0) {
mcimadamore@1336 194 new TestInvokeDynamic(arity).compileAndCheck(fm, tool);
mcimadamore@1336 195 } else {
mcimadamore@1336 196 for (StaticArgumentKind sak1 : StaticArgumentKind.values()) {
mcimadamore@1336 197 if (arity.arity == 1) {
mcimadamore@1336 198 new TestInvokeDynamic(arity, sak1).compileAndCheck(fm, tool);
mcimadamore@1336 199 } else {
mcimadamore@1336 200 for (StaticArgumentKind sak2 : StaticArgumentKind.values()) {
mcimadamore@1336 201 if (arity.arity == 2) {
mcimadamore@1336 202 new TestInvokeDynamic(arity, sak1, sak2).compileAndCheck(fm, tool);
mcimadamore@1336 203 } else {
mcimadamore@1336 204 for (StaticArgumentKind sak3 : StaticArgumentKind.values()) {
mcimadamore@1336 205 new TestInvokeDynamic(arity, sak1, sak2, sak3).compileAndCheck(fm, tool);
mcimadamore@1336 206 }
mcimadamore@1336 207 }
mcimadamore@1336 208 }
mcimadamore@1336 209 }
mcimadamore@1336 210 }
mcimadamore@1336 211 }
mcimadamore@1336 212 }
mcimadamore@1336 213
mcimadamore@1336 214 System.out.println("Total checks made: " + checkCount);
mcimadamore@1336 215 }
mcimadamore@1336 216
mcimadamore@1336 217 StaticArgumentsArity arity;
mcimadamore@1336 218 StaticArgumentKind[] saks;
mcimadamore@1336 219 JavaSource source;
mcimadamore@1336 220 DiagChecker dc;
mcimadamore@1336 221
mcimadamore@1336 222 TestInvokeDynamic(StaticArgumentsArity arity, StaticArgumentKind... saks) {
mcimadamore@1336 223 this.arity = arity;
mcimadamore@1336 224 this.saks = saks;
mcimadamore@1336 225 source = new JavaSource();
mcimadamore@1336 226 dc = new DiagChecker();
mcimadamore@1336 227 }
mcimadamore@1336 228
mcimadamore@1336 229 void compileAndCheck(JavaFileManager fm, JavaCompiler tool) throws Exception {
mcimadamore@1336 230 JavacTaskImpl ct = (JavacTaskImpl)tool.getTask(null, fm, dc,
mcimadamore@1336 231 null, null, Arrays.asList(source));
mcimadamore@1336 232 Context context = ct.getContext();
mcimadamore@1336 233 Symtab syms = Symtab.instance(context);
mcimadamore@1336 234 Names names = Names.instance(context);
vromero@1452 235 Types types = Types.instance(context);
vromero@1452 236 ct.addTaskListener(new Indifier(syms, names, types));
mcimadamore@1336 237 try {
mcimadamore@1336 238 ct.generate();
mcimadamore@1336 239 } catch (Throwable t) {
mcimadamore@1336 240 t.printStackTrace();
mcimadamore@1336 241 throw new AssertionError(String.format("Error thrown when compiling following code\n%s", source.source));
mcimadamore@1336 242 }
mcimadamore@1336 243 if (dc.diagFound) {
mcimadamore@1336 244 throw new AssertionError(String.format("Diags found when compiling following code\n%s\n\n%s", source.source, dc.printDiags()));
mcimadamore@1336 245 }
mcimadamore@1336 246 verifyBytecode();
mcimadamore@1336 247 }
mcimadamore@1336 248
mcimadamore@1336 249 void verifyBytecode() {
mcimadamore@1336 250 File compiledTest = new File("Test.class");
mcimadamore@1336 251 try {
mcimadamore@1336 252 ClassFile cf = ClassFile.read(compiledTest);
mcimadamore@1336 253 Method testMethod = null;
mcimadamore@1336 254 for (Method m : cf.methods) {
mcimadamore@1336 255 if (m.getName(cf.constant_pool).equals("test")) {
mcimadamore@1336 256 testMethod = m;
mcimadamore@1336 257 break;
mcimadamore@1336 258 }
mcimadamore@1336 259 }
mcimadamore@1336 260 if (testMethod == null) {
mcimadamore@1336 261 throw new Error("Test method not found");
mcimadamore@1336 262 }
mcimadamore@1336 263 Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
mcimadamore@1336 264 if (testMethod == null) {
mcimadamore@1336 265 throw new Error("Code attribute for test() method not found");
mcimadamore@1336 266 }
mcimadamore@1336 267
mcimadamore@1336 268 int bsmIdx = -1;
mcimadamore@1336 269
mcimadamore@1336 270 for (Instruction i : ea.getInstructions()) {
mcimadamore@1336 271 if (i.getMnemonic().equals("invokedynamic")) {
mcimadamore@1336 272 CONSTANT_InvokeDynamic_info indyInfo =
mcimadamore@1336 273 (CONSTANT_InvokeDynamic_info)cf.constant_pool.get(i.getShort(1));
mcimadamore@1336 274 bsmIdx = indyInfo.bootstrap_method_attr_index;
mcimadamore@1336 275 if (!indyInfo.getNameAndTypeInfo().getType().equals("()V")) {
mcimadamore@1336 276 throw new AssertionError("type mismatch for CONSTANT_InvokeDynamic_info");
mcimadamore@1336 277 }
mcimadamore@1336 278 }
mcimadamore@1336 279 }
mcimadamore@1336 280 if (bsmIdx == -1) {
mcimadamore@1336 281 throw new Error("Missing invokedynamic in generated code");
mcimadamore@1336 282 }
mcimadamore@1336 283
mcimadamore@1336 284 BootstrapMethods_attribute bsm_attr = (BootstrapMethods_attribute)cf.getAttribute(Attribute.BootstrapMethods);
mcimadamore@1336 285 if (bsm_attr.bootstrap_method_specifiers.length != 1) {
mcimadamore@1336 286 throw new Error("Bad number of method specifiers in BootstrapMethods attribute");
mcimadamore@1336 287 }
mcimadamore@1336 288 BootstrapMethods_attribute.BootstrapMethodSpecifier bsm_spec =
mcimadamore@1336 289 bsm_attr.bootstrap_method_specifiers[0];
mcimadamore@1336 290
mcimadamore@1336 291 if (bsm_spec.bootstrap_arguments.length != arity.arity) {
mcimadamore@1336 292 throw new Error("Bad number of static invokedynamic args in BootstrapMethod attribute");
mcimadamore@1336 293 }
mcimadamore@1336 294
mcimadamore@1336 295 int count = 0;
mcimadamore@1336 296 for (StaticArgumentKind sak : saks) {
mcimadamore@1336 297 if (!sak.check(cf.constant_pool.get(bsm_spec.bootstrap_arguments[count]))) {
mcimadamore@1336 298 throw new Error("Bad static argument value " + sak);
mcimadamore@1336 299 }
mcimadamore@1336 300 count++;
mcimadamore@1336 301 }
mcimadamore@1336 302
mcimadamore@1336 303 CONSTANT_MethodHandle_info bsm_handle =
mcimadamore@1336 304 (CONSTANT_MethodHandle_info)cf.constant_pool.get(bsm_spec.bootstrap_method_ref);
mcimadamore@1336 305
mcimadamore@1336 306 if (bsm_handle.reference_kind != RefKind.REF_invokeStatic) {
mcimadamore@1336 307 throw new Error("Bad kind on boostrap method handle");
mcimadamore@1336 308 }
mcimadamore@1336 309
mcimadamore@1336 310 CONSTANT_Methodref_info bsm_ref =
mcimadamore@1336 311 (CONSTANT_Methodref_info)cf.constant_pool.get(bsm_handle.reference_index);
mcimadamore@1336 312
mcimadamore@1336 313 if (!bsm_ref.getClassInfo().getName().equals("Bootstrap")) {
mcimadamore@1336 314 throw new Error("Bad owner of boostrap method");
mcimadamore@1336 315 }
mcimadamore@1336 316
mcimadamore@1336 317 if (!bsm_ref.getNameAndTypeInfo().getName().equals("bsm")) {
mcimadamore@1336 318 throw new Error("Bad boostrap method name");
mcimadamore@1336 319 }
mcimadamore@1336 320
mcimadamore@1336 321 if (!bsm_ref.getNameAndTypeInfo().getType().equals(asBSMSignatureString())) {
mcimadamore@1336 322 throw new Error("Bad boostrap method type" + bsm_ref.getNameAndTypeInfo().getType() + " " + asBSMSignatureString());
mcimadamore@1336 323 }
mcimadamore@1336 324 } catch (Exception e) {
mcimadamore@1336 325 e.printStackTrace();
mcimadamore@1336 326 throw new Error("error reading " + compiledTest +": " + e);
mcimadamore@1336 327 }
mcimadamore@1336 328 }
mcimadamore@1336 329
mcimadamore@1336 330 String asBSMSignatureString() {
mcimadamore@1336 331 StringBuilder buf = new StringBuilder();
mcimadamore@1336 332 buf.append("(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;");
mcimadamore@1336 333 for (StaticArgumentKind sak : saks) {
mcimadamore@1336 334 buf.append(sak.bytecodeTypeStr);
mcimadamore@1336 335 }
mcimadamore@1336 336 buf.append(")Ljava/lang/invoke/CallSite;");
mcimadamore@1336 337 return buf.toString();
mcimadamore@1336 338 }
mcimadamore@1336 339
mcimadamore@1336 340 class JavaSource extends SimpleJavaFileObject {
mcimadamore@1336 341
mcimadamore@1336 342 static final String source_template = "import java.lang.invoke.*;\n" +
mcimadamore@1336 343 "class Bootstrap {\n" +
mcimadamore@1336 344 " public static CallSite bsm(MethodHandles.Lookup lookup, String name, MethodType methodType #SARGS) {\n" +
mcimadamore@1336 345 " return null;\n" +
mcimadamore@1336 346 " }\n" +
mcimadamore@1336 347 "}\n" +
mcimadamore@1336 348 "class Test {\n" +
mcimadamore@1336 349 " void m() { }\n" +
mcimadamore@1336 350 " void test() { m(); }\n" +
mcimadamore@1336 351 "}";
mcimadamore@1336 352
mcimadamore@1336 353 String source;
mcimadamore@1336 354
mcimadamore@1336 355 JavaSource() {
mcimadamore@1336 356 super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
mcimadamore@1336 357 source = source_template.replace("#SARGS", asSignatureString());
mcimadamore@1336 358 }
mcimadamore@1336 359
mcimadamore@1336 360 @Override
mcimadamore@1336 361 public CharSequence getCharContent(boolean ignoreEncodingErrors) {
mcimadamore@1336 362 return source;
mcimadamore@1336 363 }
mcimadamore@1336 364
mcimadamore@1336 365 String asSignatureString() {
mcimadamore@1336 366 int count = 0;
mcimadamore@1336 367 StringBuilder buf = new StringBuilder();
mcimadamore@1336 368 for (StaticArgumentKind sak : saks) {
mcimadamore@1336 369 buf.append(",");
mcimadamore@1336 370 buf.append(sak.sourceTypeStr);
mcimadamore@1336 371 buf.append(' ');
mcimadamore@1336 372 buf.append(String.format("x%d", count++));
mcimadamore@1336 373 }
mcimadamore@1336 374 return buf.toString();
mcimadamore@1336 375 }
mcimadamore@1336 376 }
mcimadamore@1336 377
mcimadamore@1336 378 class Indifier extends TreeScanner<Void, Void> implements TaskListener {
mcimadamore@1336 379
mcimadamore@1336 380 MethodSymbol bsm;
mcimadamore@1336 381 Symtab syms;
mcimadamore@1336 382 Names names;
vromero@1452 383 Types types;
mcimadamore@1336 384
vromero@1452 385 Indifier(Symtab syms, Names names, Types types) {
mcimadamore@1336 386 this.syms = syms;
mcimadamore@1336 387 this.names = names;
vromero@1452 388 this.types = types;
mcimadamore@1336 389 }
mcimadamore@1336 390
mcimadamore@1336 391 @Override
mcimadamore@1336 392 public void started(TaskEvent e) {
mcimadamore@1336 393 //do nothing
mcimadamore@1336 394 }
mcimadamore@1336 395
mcimadamore@1336 396 @Override
mcimadamore@1336 397 public void finished(TaskEvent e) {
mcimadamore@1336 398 if (e.getKind() == TaskEvent.Kind.ANALYZE) {
mcimadamore@1336 399 scan(e.getCompilationUnit(), null);
mcimadamore@1336 400 }
mcimadamore@1336 401 }
mcimadamore@1336 402
mcimadamore@1336 403 @Override
mcimadamore@1336 404 public Void visitMethodInvocation(MethodInvocationTree node, Void p) {
mcimadamore@1336 405 super.visitMethodInvocation(node, p);
mcimadamore@1336 406 JCMethodInvocation apply = (JCMethodInvocation)node;
mcimadamore@1336 407 JCIdent ident = (JCIdent)apply.meth;
mcimadamore@1336 408 Symbol oldSym = ident.sym;
mcimadamore@1336 409 if (!oldSym.isConstructor()) {
mcimadamore@1336 410 Object[] staticArgs = new Object[arity.arity];
mcimadamore@1336 411 for (int i = 0; i < arity.arity ; i++) {
vromero@1452 412 staticArgs[i] = saks[i].getValue(syms, names, types);
mcimadamore@1336 413 }
mcimadamore@1336 414 ident.sym = new Symbol.DynamicMethodSymbol(oldSym.name, oldSym.owner, REF_invokeStatic, bsm, oldSym.type, staticArgs);
mcimadamore@1336 415 }
mcimadamore@1336 416 return null;
mcimadamore@1336 417 }
mcimadamore@1336 418
mcimadamore@1336 419 @Override
mcimadamore@1336 420 public Void visitMethod(MethodTree node, Void p) {
mcimadamore@1336 421 super.visitMethod(node, p);
mcimadamore@1336 422 if (node.getName().toString().equals("bsm")) {
mcimadamore@1336 423 bsm = ((JCMethodDecl)node).sym;
mcimadamore@1336 424 }
mcimadamore@1336 425 return null;
mcimadamore@1336 426 }
mcimadamore@1336 427 }
mcimadamore@1336 428
mcimadamore@1336 429 static class DiagChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
mcimadamore@1336 430
mcimadamore@1336 431 boolean diagFound;
mcimadamore@1336 432 ArrayList<String> diags = new ArrayList<>();
mcimadamore@1336 433
mcimadamore@1336 434 public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
mcimadamore@1336 435 diags.add(diagnostic.getMessage(Locale.getDefault()));
mcimadamore@1336 436 diagFound = true;
mcimadamore@1336 437 }
mcimadamore@1336 438
mcimadamore@1336 439 String printDiags() {
mcimadamore@1336 440 StringBuilder buf = new StringBuilder();
mcimadamore@1336 441 for (String s : diags) {
mcimadamore@1336 442 buf.append(s);
mcimadamore@1336 443 buf.append("\n");
mcimadamore@1336 444 }
mcimadamore@1336 445 return buf.toString();
mcimadamore@1336 446 }
mcimadamore@1336 447 }
mcimadamore@1336 448 }

mercurial