@Override public Collection<MetaClass> provideTypesToExpose() { final Set<MetaClass> types = new HashSet<MetaClass>(); for (final MetaClass metaClass : ClassScanner.getTypesAnnotatedWith(Remote.class)) { for (final MetaMethod method : metaClass.getDeclaredMethods()) { if (!method.getReturnType().isVoid()) { types.add(method.getReturnType().getErased()); } for (final MetaParameter parameter : method.getParameters()) { final MetaClass type = parameter.getType(); types.add(type.getErased()); final MetaParameterizedType parameterizedType = type.getParameterizedType(); if (parameterizedType != null) { for (final MetaType tp : parameterizedType.getTypeParameters()) { if (tp instanceof MetaClass) { types.add(((MetaClass) tp).getErased()); } } } } } } return types; } }
private static MetaMethod _findGetterMethod(final String prefix, final MetaClass cls, String key) { key = (prefix + key).toUpperCase(); for (final MetaMethod m : cls.getDeclaredMethods()) { if (m.getName().toUpperCase().equals(key) && m.getParameters().length == 0) { return m; } } return null; }
private static MetaMethod _findGetterMethod(final String prefix, final MetaClass cls, String key) { key = (prefix + key).toUpperCase(); for (final MetaMethod m : cls.getDeclaredMethods()) { if (m.getName().toUpperCase().equals(key) && m.getParameters().length == 0) { return m; } } return null; }
@Override public List<MetaMethod> getMethodsWithMetaAnnotations(final Class<? extends Annotation> annotation) { final List<MetaMethod> methods = new ArrayList<>(); MetaClass scanTarget = this; while (scanTarget != null) { for (final MetaMethod m : scanTarget.getDeclaredMethods()) { for (final Annotation a : m.getAnnotations()) { if (_findMetaAnnotation(a.annotationType(), annotation)) { methods.add(m); } } } scanTarget = scanTarget.getSuperClass(); } return methods; }
@Override public final List<MetaMethod> getMethodsAnnotatedWith(final Class<? extends Annotation> annotation) { final Map<String, List<MetaMethod>> methodsByName = new HashMap<>(); MetaClass scanTarget = this; while (scanTarget != null) { for (final MetaMethod m : scanTarget.getDeclaredMethods()) { if (m.isAnnotationPresent(annotation)) { final List<MetaMethod> methods = methodsByName.computeIfAbsent(m.getName(), k -> new ArrayList<>()); if (isNotOverriden(m, methods)) { methods.add(m); } } } scanTarget = scanTarget.getSuperClass(); } return Collections .unmodifiableList(methodsByName .values() .stream() .flatMap(list -> list.stream()) .collect(Collectors.toList())); }
@Override public List<MetaMethod> getMethodsWithMetaAnnotations(final Class<? extends Annotation> annotation) { final List<MetaMethod> methods = new ArrayList<>(); MetaClass scanTarget = this; while (scanTarget != null) { for (final MetaMethod m : scanTarget.getDeclaredMethods()) { for (final Annotation a : m.getAnnotations()) { if (_findMetaAnnotation(a.annotationType(), annotation)) { methods.add(m); } } } scanTarget = scanTarget.getSuperClass(); } return methods; }
@Override public final List<MetaMethod> getMethodsAnnotatedWith(final Class<? extends Annotation> annotation) { final Map<String, List<MetaMethod>> methodsByName = new HashMap<>(); MetaClass scanTarget = this; while (scanTarget != null) { for (final MetaMethod m : scanTarget.getDeclaredMethods()) { if (m.isAnnotationPresent(annotation)) { final List<MetaMethod> methods = methodsByName.computeIfAbsent(m.getName(), k -> new ArrayList<>()); if (isNotOverriden(m, methods)) { methods.add(m); } } } scanTarget = scanTarget.getSuperClass(); } return Collections .unmodifiableList(methodsByName .values() .stream() .flatMap(list -> list.stream()) .collect(Collectors.toList())); }
@Override public List<MetaParameter> getParametersAnnotatedWith(final Class<? extends Annotation> annotation) { final List<MetaParameter> methods = new ArrayList<>(); MetaClass scanTarget = this; while (scanTarget != null) { for (final MetaConstructor m : scanTarget.getDeclaredConstructors()) { methods.addAll(m.getParametersAnnotatedWith(annotation)); } for (final MetaMethod m : scanTarget.getDeclaredMethods()) { methods.addAll(m.getParametersAnnotatedWith(annotation)); } scanTarget = scanTarget.getSuperClass(); } return methods; }
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> 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")); }
@Override public List<MetaParameter> getParametersAnnotatedWith(final Class<? extends Annotation> annotation) { final List<MetaParameter> methods = new ArrayList<>(); MetaClass scanTarget = this; while (scanTarget != null) { for (final MetaConstructor m : scanTarget.getDeclaredConstructors()) { methods.addAll(m.getParametersAnnotatedWith(annotation)); } for (final MetaMethod m : scanTarget.getDeclaredMethods()) { methods.addAll(m.getParametersAnnotatedWith(annotation)); } scanTarget = scanTarget.getSuperClass(); } return methods; }
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")); }
/** * Checks is the given {@link MetaMethod} is in scope (part of the attached class contexts). * * @param method * the method to check. * * @return true if in scope, otherwise false. */ public boolean isInScope(final MetaMethod method) { checkThread(); Context c = this; do { for (final MetaClass clazz : c.classContexts) { for (final MetaMethod m : clazz.getDeclaredMethods()) { if (m.equals(method)) return true; } } } while ((c = c.parent) != null); return false; }
/** * Checks is the given {@link MetaMethod} is in scope (part of the attached class contexts). * * @param method * the method to check. * * @return true if in scope, otherwise false. */ public boolean isInScope(final MetaMethod method) { checkThread(); Context c = this; do { for (final MetaClass clazz : c.classContexts) { for (final MetaMethod m : clazz.getDeclaredMethods()) { if (m.equals(method)) return true; } } } while ((c = c.parent) != null); return false; }
for (final MetaMethod metaMethod : metaClass.getDeclaredMethods()) { if (metaMethod.isAnnotationPresent(annotation)) { result.add(metaMethod); for (final MetaMethod metaMethod : metaClass.getDeclaredMethods()) { if (metaMethod.isAnnotationPresent(annotation)) { result.add(metaMethod);
@Override public Collection<MetaClass> provideTypesToExpose() { final Set<MetaClass> types = new HashSet<MetaClass>(); for (final MetaClass metaClass : ClassScanner.getTypesAnnotatedWith(Remote.class)) { for (final MetaMethod method : metaClass.getDeclaredMethods()) { if (!method.getReturnType().isVoid()) { types.add(method.getReturnType().getErased()); } for (final MetaParameter parameter : method.getParameters()) { final MetaClass type = parameter.getType(); types.add(type.getErased()); final MetaParameterizedType parameterizedType = type.getParameterizedType(); if (parameterizedType != null) { for (final MetaType tp : parameterizedType.getTypeParameters()) { if (tp instanceof MetaClass) { types.add(((MetaClass) tp).getErased()); } } } } } } return types; } }
public static MetaMethod findCaseInsensitiveMatch(final MetaClass retType, final MetaClass clazz, final String name, final MetaClass... parms) { MetaClass c = clazz; do { Outer: for (final MetaMethod method : c.getDeclaredMethods()) { if (name.equalsIgnoreCase(method.getName())) { if (parms.length != method.getParameters().length) continue; final MetaParameter[] mps = method.getParameters(); for (int i = 0; i < parms.length; i++) { if (!parms[i].getFullyQualifiedName().equals(mps[i].getType().getFullyQualifiedName())) { continue Outer; } } if (retType != null && !retType.getFullyQualifiedName().equals(method.getReturnType().getFullyQualifiedName())) { continue; } return method; } } } while ((c = c.getSuperClass()) != null); return null; }
public static MetaMethod findCaseInsensitiveMatch(final MetaClass retType, final MetaClass clazz, final String name, final MetaClass... parms) { MetaClass c = clazz; do { Outer: for (final MetaMethod method : c.getDeclaredMethods()) { if (name.equalsIgnoreCase(method.getName())) { if (parms.length != method.getParameters().length) continue; final MetaParameter[] mps = method.getParameters(); for (int i = 0; i < parms.length; i++) { if (!parms[i].getFullyQualifiedName().equals(mps[i].getType().getFullyQualifiedName())) { continue Outer; } } if (retType != null && !retType.getFullyQualifiedName().equals(method.getReturnType().getFullyQualifiedName())) { continue; } return method; } } } while ((c = c.getSuperClass()) != null); return null; }
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(); }