/** * @see #getDeclaredMethod(String, Parameter[]) */ public boolean hasDeclaredMethod(String name, Parameter[] parameters) { MethodNode other = getDeclaredMethod(name, parameters); return other != null; }
@Override public MethodNode getDeclaredMethod(final String name, final Parameter[] parameters) { for (ClassNode delegate : delegates) { MethodNode node = delegate.getDeclaredMethod(name, parameters); if (node != null) return node; } return null; }
private static MethodNode findExistingMethod(final ClassNode cNode, final String name, final Parameter[] params) { return cNode.getDeclaredMethod(name, params); }
/** * If a method with the given name and parameters is already defined then it is returned * otherwise the given method is added to this node. This method is useful for * default method adding like getProperty() or invokeMethod() where there may already * be a method defined in a class and so the default implementations should not be added * if already present. */ public MethodNode addMethod(String name, int modifiers, ClassNode returnType, Parameter[] parameters, ClassNode[] exceptions, Statement code) { MethodNode other = getDeclaredMethod(name, parameters); // let's not add duplicate methods if (other != null) { return other; } MethodNode node = new MethodNode(name, modifiers, returnType, parameters, exceptions, code); addMethod(node); return node; }
/** * Creates, if necessary, a super forwarder method, for stackable traits. * @param forwarder a forwarder method * @param genericsSpec */ private static void createSuperForwarder(ClassNode targetNode, MethodNode forwarder, final Map<String,ClassNode> genericsSpec) { List<ClassNode> interfaces = new ArrayList<ClassNode>(Traits.collectAllInterfacesReverseOrder(targetNode, new LinkedHashSet<ClassNode>())); String name = forwarder.getName(); Parameter[] forwarderParameters = forwarder.getParameters(); LinkedHashSet<ClassNode> traits = new LinkedHashSet<ClassNode>(); List<MethodNode> superForwarders = new LinkedList<MethodNode>(); for (ClassNode node : interfaces) { if (Traits.isTrait(node)) { MethodNode method = node.getDeclaredMethod(name, forwarderParameters); if (method!=null) { // a similar method exists, we need a super bridge // trait$super$foo(Class currentTrait, ...) traits.add(node); superForwarders.add(method); } } } for (MethodNode superForwarder : superForwarders) { doCreateSuperForwarder(targetNode, superForwarder, traits.toArray(ClassNode.EMPTY_ARRAY), genericsSpec); } }
private void transformRunMethod(final ClassNode classNode, final SourceUnit source) { MethodNode runMethod = classNode.getDeclaredMethod("run", Parameter.EMPTY_ARRAY); Statement code = runMethod.getCode(); MarkupBuilderCodeTransformer transformer = new MarkupBuilderCodeTransformer(source, classNode, config.isAutoEscape()); code.visit(transformer); }
@Override protected boolean makeDirectCall(final Expression origin, final Expression receiver, final Expression message, final Expression arguments, final MethodCallerMultiAdapter adapter, final boolean implicitThis, final boolean containsSpreadExpression) { if (origin instanceof MethodCallExpression && receiver instanceof VariableExpression && ((VariableExpression) receiver).isSuperExpression()) { ClassNode superClass = receiver.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER); if (superClass!=null && !controller.getCompileStack().isLHS()) { // GROOVY-7300 MethodCallExpression mce = (MethodCallExpression) origin; MethodNode node = superClass.getDeclaredMethod(mce.getMethodAsString(), Parameter.EMPTY_ARRAY); mce.setMethodTarget(node); } } return super.makeDirectCall(origin, receiver, message, arguments, adapter, implicitThis, containsSpreadExpression); }
private static boolean hasUsableImplementation(ClassNode c, MethodNode m) { if (c == m.getDeclaringClass()) return false; MethodNode found = c.getDeclaredMethod(m.getName(), m.getParameters()); if (found == null) return false; int asp = found.getModifiers() & ABSTRACT_STATIC_PRIVATE; int visible = found.getModifiers() & VISIBILITY; if (visible != 0 && asp == 0) return true; if (c.equals(OBJECT_TYPE)) return false; return hasUsableImplementation(c.getSuperClass(), m); }
MethodNode getAtNode = null; while (current!=null && getAtNode==null) { getAtNode = current.getDeclaredMethod("getAt", new Parameter[]{new Parameter(aType, "index")}); if (getAtNode == null) { getAtNode = getCompatibleMethod(current, "getAt", aType); getAtNode = current.getDeclaredMethod("getAt", new Parameter[]{new Parameter(getWrapper(aType), "index")}); if (getAtNode == null) { getAtNode = getCompatibleMethod(current, "getAt", getWrapper(aType)); getAtNode = current.getDeclaredMethod("getAt", new Parameter[]{new Parameter(getUnwrapper(aType), "index")}); if (getAtNode == null) { getAtNode = getCompatibleMethod(current, "getAt", getUnwrapper(aType));
if (OBJECT_TYPE.getDeclaredMethod(mi.getName(), mi.getParameters()) != null) continue;
params[i] = new Parameter(argumentTypes[i-1], "p" + i); MethodNode method = helper.getDeclaredMethod(name, params); if (method != null) { return Collections.singletonList(makeDynamic(call, method.getReturnType()));
final ClassNode next = i < interfacesToGenerateForwarderFor.length - 1 ? interfacesToGenerateForwarderFor[i + 1] : null; String forwarderName = Traits.getSuperTraitMethodName(current, forwarderMethod.getName()); if (targetNode.getDeclaredMethod(forwarderName, superForwarderParams) == null) { ClassNode returnType = correctToGenericsSpecRecurse(genericsSpec, forwarderMethod.getReturnType()); Statement delegate = next == null ? createSuperFallback(forwarderMethod, returnType) : createDelegatingForwarder(forwarderMethod, next);
MethodNode clinit = annotatedClass.getDeclaredMethod("<clinit>", noparams); if (clinit == null) { clinit = annotatedClass.addMethod("<clinit>", ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC, ClassHelper.VOID_TYPE, noparams, null, new BlockStatement());
MethodNode defaultMethod = cNode.getDeclaredMethod("run", Parameter.EMPTY_ARRAY);
MethodNode defaultMethod = cNode.getDeclaredMethod("run", Parameter.EMPTY_ARRAY);
newMethod.addAnnotations(annotations); MethodNode oldMethod = node.getDeclaredMethod(method.getName(), newParams); if (oldMethod != null) { throw new RuntimeParserException(
/** * @param classNode the {@link org.codehaus.groovy.ast.ClassNode} used to look up the invariant closure field * * @return the {@link org.codehaus.groovy.ast.MethodNode} which contains the invariant of the given <tt>classNode</tt> */ public static MethodNode getInvariantMethodNode(final ClassNode classNode) { return classNode.getDeclaredMethod(getInvariantMethodName(classNode), Parameter.EMPTY_ARRAY); }
protected void autoAnnotateSetupTeardown(ClassNode classNode) { MethodNode setupMethod = classNode.getDeclaredMethod(SET_UP_METHOD, GrailsArtefactClassInjector.ZERO_PARAMETERS); if ( setupMethod != null && setupMethod.getAnnotations(TestForTransformation.BEFORE_CLASS_NODE).size() == 0) { setupMethod.addAnnotation(TestForTransformation.BEFORE_ANNOTATION); } MethodNode tearDown = classNode.getDeclaredMethod(TEAR_DOWN_METHOD, GrailsArtefactClassInjector.ZERO_PARAMETERS); if ( tearDown != null && tearDown.getAnnotations(TestForTransformation.AFTER_CLASS_NODE).size() == 0) { tearDown.addAnnotation(TestForTransformation.AFTER_ANNOTATION); } } }
/** * Tests whether the ClasNode implements the specified method name. * * @param classNode The ClassNode * @param methodName The method name * * @return True if it does implement the method */ public static boolean implementsZeroArgMethod(ClassNode classNode, String methodName) { MethodNode method = classNode.getDeclaredMethod(methodName, new Parameter[]{}); return method != null && (method.isPublic() || method.isProtected()) && !method.isAbstract(); }
private void transformRunMethod(final ClassNode classNode, final SourceUnit source) { MethodNode runMethod = classNode.getDeclaredMethod("run", Parameter.EMPTY_ARRAY); Statement code = runMethod.getCode(); MarkupBuilderCodeTransformer transformer = new MarkupBuilderCodeTransformer(source, classNode, config.isAutoEscape()); code.visit(transformer); }