@Override public List<MethodNode> getMethods() { List<MethodNode> nodes = new LinkedList<MethodNode>(); for (ClassNode delegate : delegates) { List<MethodNode> methods = delegate.getMethods(); if (methods != null) nodes.addAll(methods); } return nodes; }
public static List<MethodNode> getAllMethods(ClassNode type) { ClassNode node = type; List<MethodNode> result = new ArrayList<MethodNode>(); while (node != null) { result.addAll(node.getMethods()); node = node.getSuperClass(); } return result; }
private void checkMethodsForWeakerAccess(ClassNode cn) { for (MethodNode method : cn.getMethods()) { checkMethodForWeakerAccessPrivileges(method, cn); } }
private boolean anyMethodSkip(final ClassNode node) { for (MethodNode methodNode : node.getMethods()) { if (isSkipMode(methodNode)) return true; } return false; }
@Override public List<MethodNode> getMethods() { lazyInitMembers(); return super.getMethods(); }
public static void deleteMethod(ClassNode clazz, MethodNode method) { // as of 1.8.6, this is the best possible implementation clazz.getMethods().remove(method); clazz.getDeclaredMethods(method.getName()).remove(method); }
public int compare(final ClassNode o1, final ClassNode o2) { int interfaceCountForO1 = o1.getInterfaces().length; int interfaceCountForO2 = o2.getInterfaces().length; if (interfaceCountForO1 > interfaceCountForO2) return -1; if (interfaceCountForO1 < interfaceCountForO2) return 1; int methodCountForO1 = o1.getMethods().size(); int methodCountForO2 = o2.getMethods().size(); if (methodCountForO1 > methodCountForO2) return -1; if (methodCountForO1 < methodCountForO2) return 1; return o1.getName().compareTo(o2.getName()); } };
private static String scriptBodySignatureWithoutReturnType(ClassNode cn) { for (MethodNode mn : cn.getMethods()) { if (mn.isScriptBody()) return methodDescriptorWithoutReturnType(mn); } return null; }
/** * @return the list of methods associated with this ClassNode */ public List<MethodNode> getMethods() { if (redirect!=null) return redirect().getMethods(); lazyClassInit(); return methodsList; }
public Map<String, MethodNode> getDeclaredMethodsMap() { Map<String, MethodNode> result = ClassNodeUtils.getDeclaredMethodsFromSuper(this); ClassNodeUtils.addDeclaredMethodsFromInterfaces(this, result); // And add in the methods implemented in this class. for (MethodNode method : getMethods()) { String sig = method.getTypeDescriptor(); result.put(sig, method); } return result; }
private static List<MethodNode> filterMethods(ClassNode owner) { List<MethodNode> result = new LinkedList<MethodNode>(); List<MethodNode> methods = owner.getMethods(); for (MethodNode method : methods) { if (method.getDeclaringClass() == owner && !method.isSynthetic()) { if ("main".equals(method.getName()) || "run".equals(method.getName()) && owner.isScriptBody()) continue; result.add(method); } } return result; }
protected void collectAllInterfaceMethodsByName(final ClassNode receiver, final String name, final List<MethodNode> methods) { ClassNode cNode = receiver; while (cNode != null) { ClassNode[] interfaces = cNode.getInterfaces(); if (interfaces != null && interfaces.length > 0) { for (ClassNode node : interfaces) { List<MethodNode> intfMethods = node.getMethods(name); methods.addAll(intfMethods); collectAllInterfaceMethodsByName(node, name, methods); } } cNode = cNode.getSuperClass(); } }
private static void checkForAbstractMethods(ClassNode enumClass) { List<MethodNode> methods = enumClass.getMethods(); for (MethodNode m : methods) { if (m.isAbstract()) { // make the class abstract also see Effective Java p.152 enumClass.setModifiers(enumClass.getModifiers() | Opcodes.ACC_ABSTRACT); break; } } }
private static boolean checkIsConditionBlock(MethodCallExpression methodCallExpr) { ClassNode targetType = methodCallExpr.getObjectExpression().getType(); String methodName = methodCallExpr.getMethodAsString(); List<MethodNode> methods = targetType.getMethods(methodName); for (MethodNode method : methods) { for (AnnotationNode annotation : method.getAnnotations()) { if (annotation.getClassNode().getName().equals(ConditionBlock.class.getName())) return true; } } return false; } }
private void checkMethodsForOverridingFinal(ClassNode cn) { for (MethodNode method : cn.getMethods()) { Parameter[] params = method.getParameters(); for (MethodNode superMethod : cn.getSuperClass().getMethods(method.getName())) { Parameter[] superParams = superMethod.getParameters(); if (!hasEqualParameterTypes(params, superParams)) continue; if (!superMethod.isFinal()) break; addInvalidUseOfFinalError(method, params, superMethod.getDeclaringClass()); return; } } }
public void createMopMethods() { ClassNode classNode = controller.getClassNode(); if (classNode.declaresInterface(ClassHelper.GENERATED_CLOSURE_Type)) { return; } Set<MopKey> currentClassSignatures = buildCurrentClassSignatureSet(classNode.getMethods()); visitMopMethodList(classNode.getMethods(), true, Collections.EMPTY_SET, Collections.EMPTY_LIST); visitMopMethodList(classNode.getSuperClass().getAllDeclaredMethods(), false, currentClassSignatures, controller.getSuperMethodNames()); }
private void createListenerSetter(ClassNode classNode, PropertyNode propertyNode) { String setterName = "set" + MetaClassHelper.capitalize(propertyNode.getName()); if (classNode.getMethods(setterName).isEmpty()) { Statement setterBlock = createBindableStatement(propertyNode, fieldX(propertyNode.getField())); // create method void <setter>(<type> fieldName) createSetterMethod(classNode, propertyNode, setterName, setterBlock); } else { wrapSetterMethod(classNode, propertyNode.getName()); } }
private void checkRepetitiveMethod(MethodNode node) { if (isConstructor(node)) return; for (MethodNode method : currentClass.getMethods(node.getName())) { if (method == node) continue; if (!method.getDeclaringClass().equals(node.getDeclaringClass())) continue; Parameter[] p1 = node.getParameters(); Parameter[] p2 = method.getParameters(); if (p1.length != p2.length) continue; addErrorIfParamsAndReturnTypeEqual(p2, p1, node, method); } }
private void checkInterfaceMethodVisibility(ClassNode node) { if (!node.isInterface()) return; for (MethodNode method : node.getMethods()) { if (method.isPrivate()) { addError("Method '" + method.getName() + "' is private but should be public in " + getDescription(currentClass) + ".", method); } else if (method.isProtected()) { addError("Method '" + method.getName() + "' is protected but should be public in " + getDescription(currentClass) + ".", method); } } }
private void checkMethodForWeakerAccessPrivileges(MethodNode mn, ClassNode cn) { if (mn.isPublic()) return; Parameter[] params = mn.getParameters(); for (MethodNode superMethod : cn.getSuperClass().getMethods(mn.getName())) { Parameter[] superParams = superMethod.getParameters(); if (!hasEqualParameterTypes(params, superParams)) continue; if ((mn.isPrivate() && !superMethod.isPrivate()) || (mn.isProtected() && superMethod.isPublic())) { addWeakerAccessError(cn, mn, params, superMethod); return; } } }