test/tools/javac/lambda/TestInvokeDynamic.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

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

mercurial