1 /* 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang.invoke; 27 28 import sun.misc.Unsafe; 29 30 /** 31 * This class consists exclusively of static names internal to the 32 * method handle implementation. 33 * Usage: {@code import static java.lang.invoke.MethodHandleStatics.*} 34 * @author John Rose, JSR 292 EG 35 */ 36 /*non-public*/ class MethodHandleStatics { 37 MethodHandleStatics()38 private MethodHandleStatics() { } // do not instantiate 39 40 static final Unsafe UNSAFE = Unsafe.getUnsafe(); 41 42 // Android-changed: Remove debugging related static fields. They are unused and have 43 // no equivalent on Android. 44 45 // Android-changed: Temporarily hide methods that operate on MethodHandles until the 46 // MethodHandle class is imported. 47 // 48 // /*non-public*/ static String getNameString(MethodHandle target, MethodType type) { 49 // if (type == null) 50 // type = target.type(); 51 // MemberName name = null; 52 // if (target != null) 53 // name = target.internalMemberName(); 54 // if (name == null) 55 // return "invoke" + type; 56 // return name.getName() + type; 57 // } 58 // 59 // /*non-public*/ static String getNameString(MethodHandle target, MethodHandle typeHolder) { 60 // return getNameString(target, typeHolder == null ? (MethodType) null : typeHolder.type()); 61 // } 62 // 63 // /*non-public*/ static String getNameString(MethodHandle target) { 64 // return getNameString(target, (MethodType) null); 65 // } 66 // 67 // /*non-public*/ static String addTypeString(Object obj, MethodHandle target) { 68 // String str = String.valueOf(obj); 69 // if (target == null) return str; 70 // int paren = str.indexOf('('); 71 // if (paren >= 0) str = str.substring(0, paren); 72 // return str + target.type(); 73 // } 74 75 // handy shared exception makers (they simplify the common case code) newInternalError(String message)76 /*non-public*/ static InternalError newInternalError(String message) { 77 return new InternalError(message); 78 } newInternalError(String message, Throwable cause)79 /*non-public*/ static InternalError newInternalError(String message, Throwable cause) { 80 return new InternalError(message, cause); 81 } newInternalError(Throwable cause)82 /*non-public*/ static InternalError newInternalError(Throwable cause) { 83 return new InternalError(cause); 84 } newIllegalStateException(String message)85 /*non-public*/ static RuntimeException newIllegalStateException(String message) { 86 return new IllegalStateException(message); 87 } newIllegalStateException(String message, Object obj)88 /*non-public*/ static RuntimeException newIllegalStateException(String message, Object obj) { 89 return new IllegalStateException(message(message, obj)); 90 } newIllegalArgumentException(String message)91 /*non-public*/ static RuntimeException newIllegalArgumentException(String message) { 92 return new IllegalArgumentException(message); 93 } newIllegalArgumentException(String message, Object obj)94 /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj) { 95 return new IllegalArgumentException(message(message, obj)); 96 } newIllegalArgumentException(String message, Object obj, Object obj2)97 /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj, Object obj2) { 98 return new IllegalArgumentException(message(message, obj, obj2)); 99 } 100 /** Propagate unchecked exceptions and errors, but wrap anything checked and throw that instead. */ uncaughtException(Throwable ex)101 /*non-public*/ static Error uncaughtException(Throwable ex) { 102 if (ex instanceof Error) throw (Error) ex; 103 if (ex instanceof RuntimeException) throw (RuntimeException) ex; 104 throw newInternalError("uncaught exception", ex); 105 } NYI()106 static Error NYI() { 107 throw new AssertionError("NYI"); 108 } message(String message, Object obj)109 private static String message(String message, Object obj) { 110 if (obj != null) message = message + ": " + obj; 111 return message; 112 } message(String message, Object obj, Object obj2)113 private static String message(String message, Object obj, Object obj2) { 114 if (obj != null || obj2 != null) message = message + ": " + obj + ", " + obj2; 115 return message; 116 } 117 } 118