comparison graal/com.oracle.graal.java/src/com/oracle/graal/java/InvocationPlugins.java @ 19495:c4173ea6c8c7

allow an InvocationPlugin concrete class to implement more than one apply method
author Doug Simon <doug.simon@oracle.com>
date Thu, 19 Feb 2015 11:02:48 +0100
parents d59f813786f6
children 14e703edb2ab
comparison
equal deleted inserted replaced
19492:5a91549293df 19495:c4173ea6c8c7
220 } 220 }
221 221
222 public static boolean check(ResolvedJavaMethod method, InvocationPlugin plugin) { 222 public static boolean check(ResolvedJavaMethod method, InvocationPlugin plugin) {
223 int arguments = method.getSignature().getParameterCount(!method.isStatic()); 223 int arguments = method.getSignature().getParameterCount(!method.isStatic());
224 assert arguments < SIGS.length : format("need to extend %s to support method with %d arguments: %s", InvocationPlugin.class.getSimpleName(), arguments, method.format("%H.%n(%p)")); 224 assert arguments < SIGS.length : format("need to extend %s to support method with %d arguments: %s", InvocationPlugin.class.getSimpleName(), arguments, method.format("%H.%n(%p)"));
225 Method expected = null;
226 for (Method m : plugin.getClass().getDeclaredMethods()) { 225 for (Method m : plugin.getClass().getDeclaredMethods()) {
227 if (m.getName().equals("apply")) { 226 if (m.getName().equals("apply")) {
228 Class<?>[] parameterTypes = m.getParameterTypes(); 227 Class<?>[] parameterTypes = m.getParameterTypes();
229 assert Arrays.equals(SIGS[arguments], parameterTypes) : format("graph builder plugin for %s has wrong signature%nexpected: (%s)%n actual: (%s)", method.format("%H.%n(%p)"), 228 if (Arrays.equals(SIGS[arguments], parameterTypes)) {
230 sigString(SIGS[arguments]), sigString(m.getParameterTypes())); 229 return true;
231 expected = m; 230 }
232 } 231 }
233 } 232 }
234 assert expected != null : format("graph builder plugin %s must define exactly one \"apply\" method, none found", plugin); 233 throw new AssertionError(format("graph builder plugin for %s not found", method.format("%H.%n(%p)")));
235 return true;
236 }
237
238 protected static String sigString(Class<?>... sig) {
239 StringBuilder sb = new StringBuilder();
240 for (Class<?> t : sig) {
241 if (sb.length() != 0) {
242 sb.append(", ");
243 }
244 sb.append(t.getSimpleName());
245 }
246 return sb.toString();
247 } 234 }
248 } 235 }
249 } 236 }