public List<MethodNode> getAllDeclaredMethods() { return new ArrayList<MethodNode>(getDeclaredMethodsMap().values()); }
/** * Add methods from the super class. * * @param cNode The ClassNode * @return A map of methods */ public static Map<String, MethodNode> getDeclaredMethodsFromSuper(ClassNode cNode) { ClassNode parent = cNode.getSuperClass(); if (parent == null) { return new HashMap<String, MethodNode>(); } return parent.getDeclaredMethodsMap(); }
/** * Get methods from all interfaces. * Methods from interfaces visited early will be overwritten by later ones. * * @param cNode The ClassNode * @return A map of methods */ public static Map<String, MethodNode> getDeclaredMethodsFromInterfaces(ClassNode cNode) { Map<String, MethodNode> result = new HashMap<String, MethodNode>(); ClassNode[] interfaces = cNode.getInterfaces(); for (ClassNode iface : interfaces) { result.putAll(iface.getDeclaredMethodsMap()); } return result; }
/** * @return the list of abstract methods associated with this * ClassNode or null if there are no such methods */ public List<MethodNode> getAbstractMethods() { List<MethodNode> result = new ArrayList<MethodNode>(3); for (MethodNode method : getDeclaredMethodsMap().values()) { if (method.isAbstract()) { result.add(method); } } if (result.isEmpty()) { return null; } else { return result; } }
/** * Add in methods from all interfaces. Existing entries in the methods map take precedence. * Methods from interfaces visited early take precedence over later ones. * * @param cNode The ClassNode * @param methodsMap A map of existing methods to alter */ public static void addDeclaredMethodsFromInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) { // add in unimplemented abstract methods from the interfaces for (ClassNode iface : cNode.getInterfaces()) { Map<String, MethodNode> ifaceMethodsMap = iface.getDeclaredMethodsMap(); for (Map.Entry<String, MethodNode> entry : ifaceMethodsMap.entrySet()) { String methSig = entry.getKey(); if (!methodsMap.containsKey(methSig)) { methodsMap.put(methSig, entry.getValue()); } } } }
/** * Adds methods from interfaces and parent interfaces. Existing entries in the methods map take precedence. * Methods from interfaces visited early take precedence over later ones. * * @param cNode The ClassNode * @param methodsMap A map of existing methods to alter */ public static void addDeclaredMethodsFromAllInterfaces(ClassNode cNode, Map<String, MethodNode> methodsMap) { List cnInterfaces = Arrays.asList(cNode.getInterfaces()); ClassNode parent = cNode.getSuperClass(); while (parent != null && !parent.equals(ClassHelper.OBJECT_TYPE)) { ClassNode[] interfaces = parent.getInterfaces(); for (ClassNode iface : interfaces) { if (!cnInterfaces.contains(iface)) { methodsMap.putAll(iface.getDeclaredMethodsMap()); } } parent = parent.getSuperClass(); } }
result = parent.getDeclaredMethodsMap(); } else { result = new HashMap<String, MethodNode>();
public List getAllDeclaredMethods() { return new ArrayList(getDeclaredMethodsMap().values()); }
public List getAllDeclaredMethods() { return new ArrayList(getDeclaredMethodsMap().values()); }
public List getAllDeclaredMethods() { return new ArrayList(getDeclaredMethodsMap().values()); }
public List<MethodNode> getAllDeclaredMethods() { return new ArrayList<MethodNode>(getDeclaredMethodsMap().values()); }
/** * @return the list of abstract methods associated with this * ClassNode or null if there are no such methods */ public List<MethodNode> getAbstractMethods() { List<MethodNode> result = new ArrayList<MethodNode>(3); for (MethodNode method : getDeclaredMethodsMap().values()) { if (method.isAbstract()) { result.add(method); } } if (result.isEmpty()) { return null; } else { return result; } }
/** * Returns a list containing MethodNode objects for * each abstract method in the class represented by * this ClassNode */ public List getAbstractMethods() { List result = new ArrayList(3); Map declaredMethods = getDeclaredMethodsMap(); for (Iterator it = declaredMethods.values().iterator(); it.hasNext();) { MethodNode method = (MethodNode) it.next(); if (method.isAbstract()) { result.add(method); } } if (result.isEmpty()) { return null; } else { return result; } }
/** * Returns a list containing MethodNode objects for * each abstract method in the class represented by * this ClassNode */ public List getAbstractMethods() { List result = new ArrayList(3); Map declaredMethods = getDeclaredMethodsMap(); for (Iterator it = declaredMethods.values().iterator(); it.hasNext();) { MethodNode method = (MethodNode) it.next(); if (method.isAbstract()) { result.add(method); } } if (result.isEmpty()) { return null; } else { return result; } }
/** * Returns a list containing MethodNode objects for * each abstract method in the class represented by * this ClassNode */ public List getAbstractMethods() { List result = new ArrayList(3); Map declaredMethods = getDeclaredMethodsMap(); for (Iterator it = declaredMethods.values().iterator(); it.hasNext();) { MethodNode method = (MethodNode) it.next(); if (method.isAbstract()) { result.add(method); } } if (result.isEmpty()) { return null; } else { return result; } }
protected Statement getExistingJUnit4BeforeMethod(ClassNode classNode) { Statement code = null; Map<String, MethodNode> declaredMethodsMap = classNode.getDeclaredMethodsMap(); for (MethodNode methodNode : declaredMethodsMap.values()) { if (isDeclaredBeforeMethod(methodNode)) { code = getMethodBody(methodNode); } } return code; }
public Map<String, MethodNode> getDeclaredMethodsMap() { // Start off with the methods from the superclass. ClassNode parent = getSuperClass(); Map<String, MethodNode> result = null; if (parent != null) { result = parent.getDeclaredMethodsMap(); } else { result = new HashMap<String, MethodNode>(); } // add in unimplemented abstract methods from the interfaces for (ClassNode iface : getInterfaces()) { Map<String, MethodNode> ifaceMethodsMap = iface.getDeclaredMethodsMap(); for (String methSig : ifaceMethodsMap.keySet()) { if (!result.containsKey(methSig)) { MethodNode methNode = ifaceMethodsMap.get(methSig); result.put(methSig, methNode); } } } // And add in the methods implemented in this class. for (MethodNode method : getMethods()) { String sig = method.getTypeDescriptor(); result.put(sig, method); } return result; }
public Map getDeclaredMethodsMap() { // Start off with the methods from the superclass. ClassNode parent = getSuperClass(); Map result = null; if (parent != null) { result = parent.getDeclaredMethodsMap(); } else { result = new HashMap(); } // add in unimplemented abstract methods from the interfaces ClassNode[] interfaces = getInterfaces(); for (int i = 0; i < interfaces.length; i++) { ClassNode iface = interfaces[i]; Map ifaceMethodsMap = iface.getDeclaredMethodsMap(); for (Object o : ifaceMethodsMap.keySet()) { String methSig = (String) o; if (!result.containsKey(methSig)) { MethodNode methNode = (MethodNode) ifaceMethodsMap.get(methSig); result.put(methSig, methNode); } } } // And add in the methods implemented in this class. for (Object o : getMethods()) { MethodNode method = (MethodNode) o; String sig = method.getTypeDescriptor(); result.put(sig, method); } return result; }
private void collectSuperInterfaceMethods(ClassNode cn, Map<String, MethodNode> allInterfaceMethods) { List cnInterfaces = Arrays.asList(cn.getInterfaces()); ClassNode sn = cn.getSuperClass(); while (sn != null && !sn.equals(ClassHelper.OBJECT_TYPE)) { ClassNode[] interfaces = sn.getInterfaces(); for (ClassNode iface : interfaces) { if (!cnInterfaces.contains(iface)) { Map<String, MethodNode> ifaceMethodsMap = iface.getDeclaredMethodsMap(); allInterfaceMethods.putAll(ifaceMethodsMap); } } sn = sn.getSuperClass(); } }
private void autoAddTestAnnotation(ClassNode classNode) { if(isSpockTest(classNode)) return; Map<String, MethodNode> declaredMethodsMap = classNode.getDeclaredMethodsMap(); for (String methodName : declaredMethodsMap.keySet()) { MethodNode methodNode = declaredMethodsMap.get(methodName); ClassNode testAnnotationClassNode = TEST_ANNOTATION.getClassNode(); List<AnnotationNode> existingTestAnnotations = methodNode.getAnnotations(testAnnotationClassNode); if (isCandidateMethod(methodNode) && (methodNode.getName().startsWith("test") || existingTestAnnotations.size()>0)) { if (existingTestAnnotations.size()==0) { ClassNode returnType = methodNode.getReturnType(); if (returnType.getName().equals(VOID_TYPE)) { methodNode.addAnnotation(TEST_ANNOTATION); } } } } }