private MethodInfo filterAnnotationsFor(MethodInfo method) { return new MethodInfo( method.getClassName(), method.getMethodName(), method.getAnnotationInfo() .stream() .filter(this::isVisibleAnnotation) .sorted() .collect(toList()), method.getModifiers(), method.getTypeDescriptorStr(), method.getTypeSignatureStr(), method.getParameterNames(), method.getParameterModifiers(), method.getParameterAnnotationInfo() ); }
private void writeMethods(ApiPrintWriter writer, List<MethodInfo> methods) { sort(methods); for (MethodInfo method : methods) { if (isVisible(method.getModifiers()) // Only public and protected methods && isValid(method.getModifiers(), METHOD_MASK) // Excludes bridge and synthetic methods && !hasInternalAnnotation(method.getAnnotationNames()) // Excludes methods annotated as @CordaInternal && !isKotlinInternalScope(method)) { writer.println(filterAnnotationsFor(method), " "); } } }
for (ClassInfo classInfo : classInfos.values()){ for (MethodInfo methodInfo : classInfo.getMethodAndConstructorInfo()) { if (methodInfo.isConstructor()) { AnnotationInfo[][] parametersAnnotationInfo = methodInfo.getParameterAnnotationInfo(); if (parametersAnnotationInfo != null) for (AnnotationInfo[] oneParametersAnnotationInfo: parametersAnnotationInfo) { for (AnnotationInfo ai : oneParametersAnnotationInfo) { if (ai.getAnnotationType() == clazz) { methodIdentifiers.add(new MethodIdentifier(methodInfo.getClassName(), methodInfo.getMethodName(), methodInfo.getParameterTypeSignatures()));
public void println(MethodInfo method, String indentation) { append(asAnnotations(method.getAnnotationNames(), indentation)); append(indentation); if (method.getModifiersStr() != null) { append(method.getModifiersStr()).append(' '); } if (!method.isConstructor()) { append(removeQualifierFromBaseTypes(method.getResultTypeStr())).append(' '); } append(method.getMethodName()).append('('); LinkedList<String> paramTypes = method .getTypeSignature() .getParameterTypeSignatures() .stream() .map(ApiPrintWriter::removeQualifierFromBaseTypes) .collect(toCollection(LinkedList::new)); //if parameter is varargs, remove the array [] qualifier and replace with ellipsis if (method.isVarArgs() && !paramTypes.isEmpty()) { String vararg = paramTypes.removeLast(); paramTypes.add(vararg.substring(0, vararg.length() - 2) + "..."); } append(paramTypes.stream().collect(joining(", "))); println(')'); }
for (final MethodInfo mi : methodInfoSorted) { if (!mi.getMethodName().equals("<clinit>")) { buf.append("<tr>"); for (final AnnotationInfo ai : mi.getAnnotationInfo()) { if (buf.charAt(buf.length() - 1) != ' ') { buf.append(' '); buf.append(mi.getModifiersStr()); if (!mi.getMethodName().equals("<init>")) { GraphvizUtils.htmlEncode(mi.getResultType().toString(), buf); } else { buf.append("<b><constructor></b>"); if (mi.getMethodName().equals("<init>")) { mi.getClassName().substring(mi.getClassName().lastIndexOf('.') + 1), buf); } else { GraphvizUtils.htmlEncode(mi.getMethodName(), buf); if (mi.getNumParameters() != 0) { final MethodParameterInfo[] paramInfo = mi.getParameterInfo(); for (int i = 0, wrapPos = 0; i < paramInfo.length; i++) { if (i > 0) {
final MethodTypeSignature methodType = getTypeSignatureOrTypeDescriptor(); if (!isConstructor()) { if (buf.length() > 0) { buf.append(' '); final MethodParameterInfo[] allParamInfo = getParameterInfo(); boolean hasParamNames = false; for (int i = 0, numParams = allParamInfo.length; i < numParams; i++) { if (isVarArgs() && i == numParams - 1) {
@Override public int compare(final MethodInfo f1, final MethodInfo f2) { return f1.getMethodName().compareTo(f2.getMethodName()); } });
/** * Returns the unique annotation names for annotations on each method parameter, if any parameters have * annotations, else returns null. * * Note that it is always faster to call {@link #getParameterInfo()} and get the parameter information from the * returned list of {@link MethodParameterInfo} objects, since this method calls that to compile its results. * * @return The method parameter annotation names, as an array of Strings, or null if no parameter annotations * are presest. */ public String[][] getParameterAnnotationNames() { final AnnotationInfo[][] paramAnnotationInfo = getParameterAnnotationInfo(); if (paramAnnotationInfo == null) { return null; } final String[][] paramAnnotationNames = new String[paramAnnotationInfo.length][]; for (int i = 0; i < paramAnnotationInfo.length; i++) { paramAnnotationNames[i] = AnnotationInfo.getUniqueAnnotationNamesSorted(paramAnnotationInfo[i]); } return paramAnnotationNames; }
/** * Get the method modifiers as a String, e.g. "public static final". For the modifier bits, call * {@link #getModifiers()}. * * @return The modifiers for the method, as a String. */ public String getModifiersStr() { return TypeUtils.modifiersToString(getModifiers(), /* isMethod = */ true); }
/** * Returns a list of {@code Class<?>} references for the annotations on this method. Note that this calls * Class.forName() on the annotation types, which will cause each annotation class to be loaded. * * @return a list of {@code Class<?>} references for the annotations on this method, or the empty list if none. * @throws IllegalArgumentException * if the annotation type could not be loaded. */ public List<Class<?>> getAnnotationTypes() throws IllegalArgumentException { if (annotationInfo == null || annotationInfo.isEmpty()) { return Collections.<Class<?>> emptyList(); } else { final List<Class<?>> annotationClassRefs = new ArrayList<>(); for (final String annotationName : getAnnotationNames()) { annotationClassRefs.add(scanResult.classNameToClassRef(annotationName)); } return annotationClassRefs; } }
/** * Returns the parameter modifiers as a string (e.g. ["final", ""], if available (only available in classfiles * compiled in JDK8 or above using the -parameters commandline switch), otherwise returns null if the parameter * modifiers are not known. * * Note that it is always faster to call {@link #getParameterInfo()} and get the parameter information from the * returned list of {@link MethodParameterInfo} objects, since this method calls that to compile its results. * * @return The method parameter modifiers, in string representation, as an array of Strings, or null if the * parameter modifiers are not available. */ public String[] getParameterModifierStrs() { final int[] paramModifiers = getParameterModifiers(); if (paramModifiers == null) { return null; } final String[] paramModifierStrs = new String[paramModifiers.length]; for (int i = 0; i < paramModifiers.length; i++) { paramModifierStrs[i] = TypeUtils.modifiersToString(paramModifiers[i], /* isMethod = */ false); } return paramModifierStrs; }
classInfoUnlinked.addMethodInfo(new MethodInfo(className, methodName, methodAnnotationInfo, methodModifierFlags, methodTypeDescriptor, methodTypeSignature, methodParameterNames, methodParameterModifiers, methodParameterAnnotations));
@Override public Set<Method> getMethodsWithAnyParamAnnotated(Class clazz) { Map<String, ClassInfo> classInfos = scanResult.getClassNameToClassInfo(); Set<MethodIdentifier> methodIdentifiers = new HashSet<>(); for (ClassInfo classInfo : classInfos.values()){ for (MethodInfo methodInfo : classInfo.getMethodAndConstructorInfo()) { AnnotationInfo[][] parametersAnnotationInfo = methodInfo.getParameterAnnotationInfo(); if (parametersAnnotationInfo != null) for (AnnotationInfo[] oneParametersAnnotationInfo: parametersAnnotationInfo) { for (AnnotationInfo ai : oneParametersAnnotationInfo) { if (ai.getAnnotationType() == clazz) { methodIdentifiers.add(new MethodIdentifier(methodInfo.getClassName(), methodInfo.getMethodName(), methodInfo.getParameterTypeSignatures())); } } } } } Set<Method> methods = new HashSet<>(methodIdentifiers.size()); for (MethodIdentifier methodIdentifier : methodIdentifiers) { Class<?> classe = scanResult.classNameToClassRef(methodIdentifier.getClassName()); for (Method method : classe.getDeclaredMethods()) { if (methodIdentifier.matchesMethod(classe, method, scanResult)){ methods.add(method); } } } return methods; }
private static boolean isKotlinInternalScope(MethodInfo method) { return method.getMethodName().indexOf('$') >= 0; }
final List<MethodInfo> nonConstructorMethods = new ArrayList<>(); for (final MethodInfo mi : methodInfo) { final String methodName = mi.getMethodName(); if (methodName.equals("<init>")) { nonConstructorMethods.add(mi);
final List<MethodInfo> nonConstructorMethods = new ArrayList<>(); for (final MethodInfo mi : methodInfo) { final String methodName = mi.getMethodName(); if (!methodName.equals("<init>") && !methodName.equals("<clinit>")) { nonConstructorMethods.add(mi);
methodNameToMethodInfo.put(f.getMethodName(), f);