private void printMethods(PrintWriter out, ClassNode classNode, boolean isEnum) {
    if (!isEnum) printConstructors(out, classNode);

    @SuppressWarnings("unchecked")
    List<MethodNode> methods = (List) propertyMethods.clone();
    methods.addAll(classNode.getMethods());
    for (MethodNode method : methods) {
      if (isEnum && method.isSynthetic()) {
        // skip values() method and valueOf(String)
        String name = method.getName();
        Parameter[] params = method.getParameters();
        if (name.equals("values") && params.length == 0) continue;
        if (name.equals("valueOf")
            && params.length == 1
            && params[0].getType().equals(ClassHelper.STRING_TYPE)) {
          continue;
        }
      }
      printMethod(out, classNode, method);
    }
  }
  private void printMethod(PrintWriter out, ClassNode clazz, MethodNode methodNode) {
    if (methodNode.getName().equals("<clinit>")) return;
    if (methodNode.isPrivate() || !Utilities.isJavaIdentifier(methodNode.getName())) return;
    if (methodNode.isSynthetic() && methodNode.getName().equals("$getStaticMetaClass")) return;

    printAnnotations(out, methodNode);
    if (!clazz.isInterface()) printModifiers(out, methodNode.getModifiers());

    printGenericsBounds(out, methodNode.getGenericsTypes());
    out.print(" ");
    printType(out, methodNode.getReturnType());
    out.print(" ");
    out.print(methodNode.getName());

    printParams(out, methodNode);

    ClassNode[] exceptions = methodNode.getExceptions();
    for (int i = 0; i < exceptions.length; i++) {
      ClassNode exception = exceptions[i];
      if (i == 0) {
        out.print("throws ");
      } else {
        out.print(", ");
      }
      printType(out, exception);
    }

    if ((methodNode.getModifiers() & Opcodes.ACC_ABSTRACT) != 0) {
      out.println(";");
    } else {
      out.print(" { ");
      ClassNode retType = methodNode.getReturnType();
      printReturn(out, retType);
      out.println("}");
    }
  }
Пример #3
0
 private boolean isPublicInstanceMethod(MethodNode methodNode) {
   return !methodNode.isSynthetic() && !methodNode.isStatic() && methodNode.isPublic();
 }
Пример #4
0
 public static boolean isCandidateMethod(MethodNode declaredMethod) {
   return !declaredMethod.isSynthetic()
       && !declaredMethod.getName().contains("$")
       && Modifier.isPublic(declaredMethod.getModifiers())
       && !Modifier.isAbstract(declaredMethod.getModifiers());
 }