public ClassStructureBuilder<?> generate() { final String safeProxyClassName = remote.getFullyQualifiedName().replace('.', '_') + "Impl"; final ClassStructureBuilder<?> classBuilder = ClassBuilder.define(safeProxyClassName, AbstractRpcProxy.class) .packageScope() .implementsInterface(remote) .body(); for (final MetaMethod method : remote.getMethods()) { if (ProxyUtil.shouldProxyMethod(method)) { generateMethod(classBuilder, method); } } return classBuilder; }
for (final MetaMethod method : enclosingType.getMethods()) { for (final MetaParameter param : method.getParameters()) { if (param.isAnnotationPresent(annoType)) {
private Collection<MetaMethod> getAllDisposesMethods(final MetaClass type, final boolean staticOnly) { final Collection<MetaMethod> disposers = new ArrayList<>(); for (final MetaMethod method : type.getMethods()) { if (staticOnly && !method.isStatic()) { continue; } final List<MetaParameter> disposerParams = method.getParametersAnnotatedWith(Disposes.class); if (disposerParams.size() > 1) { throw new RuntimeException("Found method " + method + " in " + method.getDeclaringClassName() + " with multiple @Disposes parameters."); } else if (disposerParams.size() == 1) { disposers.add(method); } } return disposers; }
for (final MetaMethod method : enclosingType.getMethods()) { for (final MetaParameter param : method.getParameters()) { if (param.isAnnotationPresent(annoType)) {
/** * Callback interface for providing custom method bodies in snapshots. There are three major use cases: * <ol> * <li>To implement methods that take parameters (snapshots of * these methods cannot be generated automatically) * <li>To return a reference to some object that's already in the * scope of the snapshot (such as a reference to a parent object * from a getParent() method) * <li>To implement additional methods in the case that the snapshot * type is not the same as the type to extend. * </ol> * * @author Jonathan Fuerth <jfuerth@gmail.com> */ public interface MethodBodyCallback { /** * Optionally returns the statement that should be used as the body of the * given method for the given object's snapshot. If the default snapshot * behaviour provided by SnapshotMaker is sufficient for the given method, * this callback can simply return null. * * @param method * The method to provide the body for. * @param o * The instance object that we are taking the snapshot of. You can * use this reference if you need to invoke {@code method}. * @param containingClass * The class that will contain the generated method. During the * callback, you can generate additional methods and fields within
/** * Callback interface for providing custom method bodies in snapshots. There are three major use cases: * <ol> * <li>To implement methods that take parameters (snapshots of * these methods cannot be generated automatically) * <li>To return a reference to some object that's already in the * scope of the snapshot (such as a reference to a parent object * from a getParent() method) * <li>To implement additional methods in the case that the snapshot * type is not the same as the type to extend. * </ol> * * @author Jonathan Fuerth <jfuerth@gmail.com> */ public interface MethodBodyCallback { /** * Optionally returns the statement that should be used as the body of the * given method for the given object's snapshot. If the default snapshot * behaviour provided by SnapshotMaker is sufficient for the given method, * this callback can simply return null. * * @param method * The method to provide the body for. * @param o * The instance object that we are taking the snapshot of. You can * use this reference if you need to invoke {@code method}. * @param containingClass * The class that will contain the generated method. During the * callback, you can generate additional methods and fields within
@Override public MetaMethod[] getMethods() { if (_methodsCache != null) return _methodsCache; final MetaMethod[] methodArray = methods.toArray(new MetaMethod[methods.size()]); final MetaMethod[] outputMethods; if (superClass != null) { final List<MetaMethod> methodList = new ArrayList<>(); for (final MetaMethod m : superClass.getMethods()) { if (_getMethod(methodArray, m.getName(), GenUtil.fromParameters(m.getParameters())) == null) { methodList.add(m); } } methodList.addAll(Arrays.asList(methodArray)); outputMethods = methodList.toArray(new MetaMethod[methodList.size()]); } else { outputMethods = methodArray; } return _methodsCache = outputMethods; }
@Override public MetaMethod[] getMethods() { if (_methodsCache != null) return _methodsCache; final MetaMethod[] methodArray = methods.toArray(new MetaMethod[methods.size()]); final MetaMethod[] outputMethods; if (superClass != null) { final List<MetaMethod> methodList = new ArrayList<>(); for (final MetaMethod m : superClass.getMethods()) { if (_getMethod(methodArray, m.getName(), GenUtil.fromParameters(m.getParameters())) == null) { methodList.add(m); } } methodList.addAll(Arrays.asList(methodArray)); outputMethods = methodList.toArray(new MetaMethod[methodList.size()]); } else { outputMethods = methodArray; } return _methodsCache = outputMethods; }
for (final MetaMethod ifaceMethod : Arrays.asList(JavaReflectionClass.newInstance(interfaceType).getMethods())) { final String readableMethodDecl = GenUtil.getMethodString(ifaceMethod); if (!processedMethods.contains(readableMethodDecl)) {
for (final MetaMethod ifaceMethod : Arrays.asList(JavaReflectionClass.newInstance(interfaceType).getMethods())) { final String readableMethodDecl = GenUtil.getMethodString(ifaceMethod); if (!processedMethods.contains(readableMethodDecl)) {
for (final MetaMethod ifaceMethod : Arrays.asList(GWTClass.newInstance(oracle, interfaceType).getMethods())) { final String readableMethodDecl = GenUtil.getMethodString(ifaceMethod); if (!processedMethods.contains(readableMethodDecl)) {
for (final MetaMethod ifaceMethod : Arrays.asList(GWTClass.newInstance(oracle, interfaceType).getMethods())) { final String readableMethodDecl = GenUtil.getMethodString(ifaceMethod); if (!processedMethods.contains(readableMethodDecl)) {
private ObjectBuilder createAnonymousImpl(final MetaClass type) { final AnonymousClassStructureBuilder builder = newObject(type).extend(); stream(type.getMethods()) .filter(m -> m.isPublic() && m.isAbstract()) .forEach(m -> { builder .publicOverridesMethod(m.getName(), of(m.getParameters())) .append(Stmt.throw_(RuntimeException.class)) .finish(); }); return builder.finish(); }
@Test public void testNoDuplicateMethodsInClassHierarchy() throws NotFoundException { final MetaClass child = getMetaClass(Child.class); final List<MetaMethod> foundMethods = new ArrayList<>(); for (final MetaMethod m : child.getMethods()) { if (m.getName().equals("interfaceMethodOverriddenMultipleTimes")) { foundMethods.add(m); } } assertEquals("Only one copy of the method should have been found", 1, foundMethods.size()); }
final MetaMethod[] objMethods = Object_MetaClass.getMethods(); final MetaMethod[] nMethods = new MetaMethod[methods.length + objMethods.length]; System.arraycopy(methods, 0, nMethods, 0, methods.length);
public ClassStructureBuilder<?> generate() { final String safeProxyClassName = remote.getFullyQualifiedName().replace('.', '_') + "Impl"; final ClassStructureBuilder<?> classBuilder = ClassBuilder.define(safeProxyClassName, AbstractRpcProxy.class) .packageScope() .implementsInterface(remote) .body(); for (final MetaMethod method : remote.getMethods()) { if (ProxyUtil.shouldProxyMethod(method)) { generateMethod(classBuilder, method); } } return classBuilder; }
for (final MetaMethod m : eventType.getMethods()) { if ("getAssociatedType".equals(m.getName())) { method = m;
@Test public void testGetMethods() { final MetaClass c = getMetaClass(Child.class); final MetaMethod[] methods = c.getMethods(); assertNotNull(methods); final List<String> methodSignatures = new ArrayList<>(); for(final MetaMethod m : methods) { methodSignatures.add(GenUtil.getMethodString(m)); } final List<String> expectedMethods = new ArrayList<>(); expectedMethods.add("protectedMethod([])"); expectedMethods.add("interfaceMethodOverriddenMultipleTimes([])"); expectedMethods.add("packagePrivateMethod([])"); expectedMethods.add("finalize([])"); expectedMethods.add("equals([java.lang.Object])"); expectedMethods.add("toString([])"); expectedMethods.add("notify([])"); expectedMethods.add("wait([])"); expectedMethods.add("clone([])"); expectedMethods.add("notifyAll([])"); expectedMethods.add("getClass([])"); expectedMethods.add("wait([long])"); expectedMethods.add("hashCode([])"); expectedMethods.add("wait([long, int])"); Collections.sort(expectedMethods); Collections.sort(methodSignatures); assertEquals(expectedMethods.toString(), methodSignatures.toString()); }
.finish(); for (MetaMethod method : remote.getMethods()) { if (ProxyUtil.shouldProxyMethod(method)) { JaxrsResourceMethod resourceMethod = new JaxrsResourceMethod(method, headers, rootResourcePath);
private void implementAccessibleMethods(final ClassStructureBuilder<?> proxyImpl, final Injectable injectable, final BuildMetaClass factoryClass) { final Multimap<String, MetaMethod> proxiedMethodsByName = HashMultimap.create(); final MetaClass injectedType = injectable.getInjectedType(); for (final MetaMethod method : injectedType.getMethods()) { if (shouldProxyMethod(method, proxiedMethodsByName)) { proxiedMethodsByName.put(method.getName(), method);