private void generateMethod(ClassStructureBuilder<?> classBuilder, MetaMethod method) { final List<Class<?>> interceptors = interceptorProvider.getInterceptors(remote, method); final boolean intercepted = !interceptors.isEmpty(); final Parameter[] parms = DefParameters.from(method).getParameters().toArray(new Parameter[0]); final Parameter[] finalParms = new Parameter[parms.length]; final List<Statement> parmVars = new ArrayList<Statement>(); for (int i = 0; i < parms.length; i++) { finalParms[i] = Parameter.of(parms[i].getType().getErased(), parms[i].getName(), true); parmVars.add(Stmt.loadVariable(parms[i].getName())); } final Statement parameters = (intercepted) ? new StringStatement("getParameters()", MetaClassFactory.get(Object[].class)) : Stmt.newArray(Object.class).initialize(parmVars.toArray()); final BlockBuilder<?> methodBlock = classBuilder.publicMethod(method.getReturnType().getErased(), method.getName(), finalParms); if (intercepted) { methodBlock.append(generateInterceptorLogic(classBuilder, method, generateRequest(classBuilder, method, parameters, true), parmVars, interceptors)); } else { methodBlock.append(generateRequest(classBuilder, method, parameters, false)); } final Statement returnStmt = ProxyUtil.generateProxyMethodReturnStatement(method); if (returnStmt != null) { methodBlock.append(returnStmt); } methodBlock.finish(); }
private void setEntityParameter(Statement entityParameter, MetaMethod method) { if (this.entityParameter != null) { throw new RuntimeException("Only one non-annotated entity parameter allowed per method:" + method.getName()); } this.entityParameter = entityParameter; }
@Override public String generate(final Context context) { if (generatedCache != null) return generatedCache; return generatedCache = method.getName().concat(callParameters.generate(context)); }
public static String createCallSignature(final MetaMethod m) { final StringBuilder append = new StringBuilder(m.getName()).append(':'); for (final MetaParameter parm : m.getParameters()) { append.append(parm.getType().getCanonicalName()).append(':'); } return append.toString(); }
public static Collection<MetaMethod> getNonBindingAttributes(final MetaClass annoClass) { return filterAnnotationMethods(Arrays.stream(annoClass.getDeclaredMethods()), method -> method.isAnnotationPresent(Nonbinding.class) && method.isPublic() && !method.getName().equals("equals") && !method.getName().equals("hashCode")); }
public static Collection<MetaMethod> getAnnotationAttributes(final MetaClass annoClass) { return filterAnnotationMethods(Arrays.stream(annoClass.getDeclaredMethods()), method -> !method.isAnnotationPresent(Nonbinding.class) && method.isPublic() && !method.getName().equals("equals") && !method.getName().equals("hashCode")); }
public static Collection<MetaMethod> getAnnotationAttributes(final MetaClass annoClass) { return filterAnnotationMethods(Arrays.stream(annoClass.getDeclaredMethods()), method -> !method.isAnnotationPresent(Nonbinding.class) && method.isPublic() && !method.getName().equals("equals") && !method.getName().equals("hashCode")); }
public static boolean shouldProxyMethod(final MetaMethod method) { final String methodName = method.getName(); return !method.isFinal() && !method.isStatic() && !method.isPrivate() && !methodName.equals("hashCode") && !methodName.equals("equals") && !methodName.equals("toString") && !methodName.equals("clone") && !methodName.equals("finalize"); }
public static boolean isMethodInInterface(final MetaClass iface, final MetaMethod member) { if (iface.getMethod(member.getName(), Arrays.stream(member.getParameters()).map(p -> p.getType()).toArray(MetaClass[]::new)) != null) return true; return false; }
private void validateNonEmptyEventHandlerTargets(final MetaClass declaringClass, final MetaMethod method, final String[] targetDataFieldNames) { if (targetDataFieldNames.length == 0) { throw new GenerationException("@EventHandler annotation on method [" + declaringClass.getFullyQualifiedName() + "." + method.getName() + "] must specify at least one data-field target."); } }
public String hashString() { if (_hashString != null) return _hashString; return _hashString = MetaMethod.class + ":" + getDeclaringClass().getFullyQualifiedName() + "." + getName() + "(" + Arrays.toString(getParameters()) + ")"; }
public String hashString() { if (_hashString != null) return _hashString; return _hashString = MetaMethod.class + ":" + getDeclaringClass().getFullyQualifiedName() + "." + getName() + "(" + Arrays.toString(getParameters()) + ")"; }
/** * Returns true if the method signature is the same as the methods generated by BindableProxyGenerator */ private boolean isBindableProxyGeneratedMethod(MetaMethod method) { if(method.getName().equals("get") && method.getParameters().length == 1 && method.getParameters()[0].getType().isAssignableFrom(String.class)) { return true; } if(method.getName().equals("set") && method.getParameters().length == 2 && method.getParameters()[0].getType().isAssignableFrom(String.class)) { return true; } return false; }
/** * Returns true if the method signature is the same as the methods generated by BindableProxyGenerator */ private boolean isBindableProxyGeneratedMethod(MetaMethod method) { if(method.getName().equals("get") && method.getParameters().length == 1 && method.getParameters()[0].getType().isAssignableFrom(String.class)) { return true; } if(method.getName().equals("set") && method.getParameters().length == 2 && method.getParameters()[0].getType().isAssignableFrom(String.class)) { return true; } return false; }
static MetaMethod getOverridenMethod(final MetaMethod specializingMethod) { final MetaClass[] producerParams = GraphUtil.getParameterTypes(specializingMethod); MetaClass enclosingType = specializingMethod.getDeclaringClass(); MetaMethod specializedMethod = null; while (specializedMethod == null && enclosingType.getSuperClass() != null) { enclosingType = enclosingType.getSuperClass(); specializedMethod = enclosingType.getDeclaredMethod(specializingMethod.getName(), producerParams); } return specializedMethod; }
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(); }
private ObjectBuilder createAnnoImpl(final MetaClass annoType) { final AnonymousClassStructureBuilder builder = ObjectBuilder.newInstanceOf(annoType).extend(); Arrays.stream(annoType.getDeclaredMethods()) .forEach(m -> builder.publicOverridesMethod(m.getName()) .append(castTo(m.getReturnType(), loadVariable("parameters").invoke("get", m.getName())).returnValue()).finish()); builder.publicOverridesMethod("annotationType").append(loadLiteral(annoType).returnValue()).finish(); return builder.finish(); }
public static String getPrivateMethodName(final MetaMethod method) { final MetaClass declaringClass = method.getDeclaringClass(); String name = declaringClass.getName() + "_" + method.getName(); if (method.getParameters() != null) { for (final MetaParameter p : method.getParameters()) { name += "_" + getTypeName(p.getType()); } } return name; }
public static String initCachedMethod(final ClassStructureBuilder<?> classBuilder, final MetaMethod m) { createJavaReflectionMethodInitializerUtilMethod(classBuilder); final String fieldName = PrivateAccessUtil.getPrivateMethodName(m) + "_meth"; classBuilder.privateField(fieldName, Method.class).modifiers(Modifier.Static) .initializesWith(Stmt.invokeStatic(classBuilder.getClassDefinition(), JAVA_REFL_METH_UTIL_METH, m.getDeclaringClass(), m.getName(), MetaClassFactory.asClassArray(m.getParameters()))).finish(); return fieldName; }