public static MetaMethod get(final Method method) { return get(method.getDeclaringClass()).getDeclaredMethod(method.getName(), method.getParameterTypes()); }
public static MetaMethod get(final Method method) { return get(method.getDeclaringClass()).getDeclaredMethod(method.getName(), method.getParameterTypes()); }
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; }
@Test public void testFieldWithSingleUpperBoundedTypeVarParam() throws Exception { final MetaClass metaClass = getMetaClass(ClassWithGenericCollections.class); final MetaMethod field = metaClass.getDeclaredMethod("hasSingleBoundedTypeVarFromSelf", new Class[] {}); assertNotNull(field); final MetaTypeVariable returnType = (MetaTypeVariable) field.getGenericReturnType(); assertEquals("B", returnType.getName()); assertEquals("Should have a single upper bound", Arrays.asList(getMetaClass(Serializable.class)), Arrays.asList(returnType.getBounds())); }
@Test public void testFieldWithTwoUpperBoundedTypeVarParam() throws Exception { final MetaClass metaClass = getMetaClass(ClassWithGenericCollections.class); final MetaMethod field = metaClass.getDeclaredMethod("hasDoubleBoundedTypeVarFromSelf", new Class[] {}); assertNotNull(field); final MetaTypeVariable returnType = (MetaTypeVariable) field.getGenericReturnType(); assertEquals("B", returnType.getName()); assertEquals("Should have two upper bounds", Arrays.asList(getMetaClass(Collection.class), getMetaClass(Serializable.class)), Arrays.asList(returnType.getBounds())); }
@Override public void makeMethodAccessible(final ClassStructureBuilder<?> classBuilder, final MetaMethod method, final Modifier[] modifiers) { final MetaMethod erasedMethod = method.getDeclaringClass().getErased().getDeclaredMethod(method.getName(), getErasedParamterTypes(method)); final List<Parameter> wrapperDefParms = new ArrayList<Parameter>(); if (!erasedMethod.isStatic()) { wrapperDefParms.add(Parameter.of(erasedMethod.getDeclaringClass().getErased(), "instance")); } final List<Parameter> methodDefParms = DefParameters.from(erasedMethod).getParameters(); wrapperDefParms.addAll(methodDefParms); Annotation[] annotations = NO_ANNOTATIONS; for (MetaParameter p : erasedMethod.getParameters()) { if (p.getType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } } if (erasedMethod.getReturnType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } classBuilder.publicMethod(erasedMethod.getReturnType(), PrivateAccessUtil.getPrivateMethodName(method)) .annotatedWith(annotations) .parameters(DefParameters.fromParameters(wrapperDefParms)) .modifiers(appendJsni(modifiers)) .body() ._(StringStatement.of(JSNIUtil.methodAccess(erasedMethod))) .finish(); }
@Override public void makeMethodAccessible(final ClassStructureBuilder<?> classBuilder, final MetaMethod method, final Modifier[] modifiers) { final MetaMethod erasedMethod = method.getDeclaringClass().getErased().getDeclaredMethod(method.getName(), getErasedParamterTypes(method)); final List<Parameter> wrapperDefParms = new ArrayList<Parameter>(); if (!erasedMethod.isStatic()) { wrapperDefParms.add(Parameter.of(erasedMethod.getDeclaringClass().getErased(), "instance")); } final List<Parameter> methodDefParms = DefParameters.from(erasedMethod).getParameters(); wrapperDefParms.addAll(methodDefParms); Annotation[] annotations = NO_ANNOTATIONS; for (MetaParameter p : erasedMethod.getParameters()) { if (p.getType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } } if (erasedMethod.getReturnType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } classBuilder.publicMethod(erasedMethod.getReturnType(), PrivateAccessUtil.getPrivateMethodName(method)) .annotatedWith(annotations) .parameters(DefParameters.fromParameters(wrapperDefParms)) .modifiers(appendJsni(modifiers)) .body() ._(StringStatement.of(JSNIUtil.methodAccess(erasedMethod))) .finish(); }