List of usage examples for com.google.gwt.dev.asm.commons Method getName
public String getName()
From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java
License:Apache License
private static String print(Method method) { StringBuilder sb = new StringBuilder(); sb.append(print(method.getReturnType())).append(" ").append(method.getName()).append("("); for (Type t : method.getArgumentTypes()) { sb.append(print(t)).append(" "); }/* w ww. j a va 2 s. co m*/ sb.append(")"); return sb.toString(); }
From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java
License:Apache License
/** * Convert a method declaration using client types (e.g. FooProxy) to domain * types (e.g. Foo)./* w w w. j a va 2 s. c o m*/ */ private Method createDomainMethod(ErrorContext logger, Method clientMethod) { Type[] args = clientMethod.getArgumentTypes(); for (int i = 0, j = args.length; i < j; i++) { args[i] = getDomainType(logger, args[i], true); } Type returnType = getDomainType(logger, clientMethod.getReturnType(), true); return new Method(clientMethod.getName(), returnType, args); }
From source file:com.google.web.bindery.requestfactory.server.RequestFactoryInterfaceValidator.java
License:Apache License
/** * Finds a compatible method declaration in <code>domainType</code>'s * hierarchy that is assignment-compatible with the given Method. *///from www . j ava2 s. co m private RFMethod findCompatibleMethod(final ErrorContext logger, Type domainType, Method searchFor, boolean mustFind, boolean allowOverloads, boolean boxReturnTypes) { String methodName = searchFor.getName(); Type[] clientArgs = searchFor.getArgumentTypes(); Type clientReturnType = searchFor.getReturnType(); if (boxReturnTypes) { clientReturnType = maybeBoxType(clientReturnType); } // Pull all methods out of the domain type Map<String, List<RFMethod>> domainLookup = new LinkedHashMap<String, List<RFMethod>>(); for (RFMethod method : getMethodsInHierarchy(logger, domainType)) { List<RFMethod> list = domainLookup.get(method.getName()); if (list == null) { list = new ArrayList<RFMethod>(); domainLookup.put(method.getName(), list); } list.add(method); } // Find the matching method in the domain object List<RFMethod> methods = domainLookup.get(methodName); if (methods == null) { if (mustFind) { logger.poison("Could not find any methods named %s in %s", methodName, print(domainType)); } return null; } if (methods.size() > 1 && !allowOverloads) { StringBuilder sb = new StringBuilder(); sb.append( String.format("Method overloads found in type %s named %s:\n", print(domainType), methodName)); for (RFMethod method : methods) { sb.append(" ").append(print(method)).append("\n"); } logger.poison(sb.toString()); return null; } // Check each overloaded name for (RFMethod domainMethod : methods) { Type[] domainArgs = domainMethod.getArgumentTypes(); Type domainReturnType = domainMethod.getReturnType(); if (boxReturnTypes) { /* * When looking for the implementation of a Request<Integer>, we want to * match either int or Integer, so we'll box the domain method's return * type. */ domainReturnType = maybeBoxType(domainReturnType); } /* * Make sure the client args can be passed into the domain args and the * domain return type into the client return type. */ if (isAssignable(logger, domainArgs, clientArgs) && isAssignable(logger, clientReturnType, domainReturnType)) { logger.spam("Mapped client method " + print(searchFor) + " to " + print(domainMethod)); return domainMethod; } } if (mustFind) { logger.poison(messageCouldNotFindMethod(domainType, methods)); } return null; }
From source file:com.googlecode.gwt.test.internal.rewrite.RewriteSingleJsoImplDispatches.java
License:Apache License
/** * For regular Java objects that implement a SingleJsoImpl interface, write instance trampoline * dispatchers for mangled method names to the implementing method. *//*from w ww .j ava 2 s.co m*/ private void writeTrampoline(String stubIntr) { /* * This is almost the same kind of trampoline as the ones generated in WriteJsoImpl, however * there are enough small differences between the semantics of the dispatches that would make * a common implementation far more awkward than the duplication of code. */ for (String mangledName : toImplement(stubIntr)) { for (Method method : jsoData.getDeclarations(mangledName)) { Method toCall = new Method(method.getName(), method.getDescriptor()); // Must not be final MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName, method.getDescriptor(), null, null); if (mv != null) { mv.visitCode(); /* * It just so happens that the stack and local variable sizes are the same, but * they're kept distinct to aid in clarity should the dispatch logic change. * * These start at 1 because we need to load "this" onto the stack */ int var = 1; int size = 1; // load this mv.visitVarInsn(Opcodes.ALOAD, 0); // then the rest of the arguments for (Type t : toCall.getArgumentTypes()) { size += t.getSize(); mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var); var += t.getSize(); } // Make sure there's enough room for the return value size = Math.max(size, toCall.getReturnType().getSize()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(), toCall.getDescriptor()); mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN)); mv.visitMaxs(size, var); mv.visitEnd(); } } } }