private void introspectInterface(Class<?> interfaceClass) { this.interfaceClass = interfaceClass; methodSignatures = new ArrayList<>(); Class<?> superClass = interfaceClass.getSuperclass(); if (superClass != null) { superType = superClass.getName(); } interfaces = new ArrayList<>(); for (Method method : interfaceClass.getDeclaredMethods()) { Signature signature = new Signature(method); if (!methodSignatures.contains(signature)) { methodSignatures.add(signature); } } addInterfaces(interfaceClass, interfaces); }
public Set<Method> getInjectionMethods(Class<?> type, Collection<Service<ComponentType>> services) { Set<Signature> exclude = getOperations(services); Set<Method> methods = new HashSet<>(); while (type != null) { for (Method method : type.getDeclaredMethods()) { // check method accessibility int modifiers = method.getModifiers(); if (Modifier.isStatic(modifiers) || Modifier.isAbstract(modifiers)) { continue; } if (!(Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers))) { continue; } if (!isSetter(method)) { continue; } // exclude methods we have seen already (i.e. in a contract or overriden in a subclass) // we check using the signature as the method itself will have been declared on a different class Signature signature = new Signature(method); if (exclude.contains(signature)) { continue; } exclude.add(signature); methods.add(method); } type = type.getSuperclass(); } return methods; }
private Set<Signature> getOperations(Collection<Service<ComponentType>> services) { Set<Signature> operations = new HashSet<>(); for (Service<ComponentType> definition : services) { List<? extends Operation> ops = definition.getServiceContract().getOperations(); for (Operation operation : ops) { String name = operation.getName(); List<? extends DataType> inputTypes = operation.getInputTypes(); List<String> paramTypes = new ArrayList<>(inputTypes.size()); for (DataType inputType : inputTypes) { paramTypes.add(inputType.getType().getName()); } operations.add(new Signature(name, paramTypes)); } } return operations; }