@Override public ClassNode getReturnType() { try { return returnType.call(); } catch (Exception e) { return super.getReturnType(); } } };
@Override public void visitMethod(final MethodNode node) { result.set(node.getReturnType()); }
private ClassNode inferTraitMethodReturnType(ClassNode nextTrait, String methodName, ClassNode[] paramTypes) { ClassNode result = ClassHelper.OBJECT_TYPE; if (nextTrait != null) { List<MethodNode> candidates = typeCheckingVisitor.findMethod(nextTrait, methodName, paramTypes); if (candidates.size() == 1) { result = candidates.get(0).getReturnType(); } } return result; }
private static void removeMethodWithSuperReturnType(List<MethodNode> toBeRemoved, MethodNode one, MethodNode two) { ClassNode oneRT = one.getReturnType(); ClassNode twoRT = two.getReturnType(); if (isCovariant(oneRT, twoRT)) { toBeRemoved.add(two); } else if (isCovariant(twoRT, oneRT)) { toBeRemoved.add(one); } }
@Override protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor) { if (!inAnnotationDef) return; visitStatement(node.getFirstStatement(), node.getReturnType()); }
public ClassNode getReturnType() { if (methodNode != null) { return methodNode.getReturnType(); } else if (constructorNode != null) { return constructorNode.getReturnType(); } else { throw new GroovyBugError("I spotted a return that is neither in a method nor in a constructor... I can not handle that"); } }
/** * Returns a method descriptor for the given {@link org.codehaus.groovy.ast.MethodNode}. * * @param methodNode the method node for which to create the descriptor * @return a method descriptor as defined in section JVMS section 4.3.3 */ public static String getMethodDescriptor(MethodNode methodNode) { return getMethodDescriptor(methodNode.getReturnType(), methodNode.getParameters()); }
private ClassNode getAttributeType(AnnotationNode node, String attrName) { ClassNode classNode = node.getClassNode(); List methods = classNode.getMethods(attrName); // if size is >1, then the method was overwritten or something, we ignore that // if it is an error, we have to test it at another place. But size==0 is // an error, because it means that no such attribute exists. if (methods.isEmpty()) { addError("'" + attrName + "'is not part of the annotation " + classNode, node); return ClassHelper.OBJECT_TYPE; } MethodNode method = (MethodNode) methods.get(0); return method.getReturnType(); }
private void createMethods(ClassNode cNode, ClassNode exception, String message, ClosureExpression code) { for (MethodNode candidate : getAllCorrectedMethodsMap(cNode).values()) { if (candidate.isAbstract()) { addGeneratedMethod(cNode, candidate.getName(), Opcodes.ACC_PUBLIC, candidate.getReturnType(), candidate.getParameters(), candidate.getExceptions(), methodBody(exception, message, code, candidate.getReturnType())); } } }
public MethodNode getSetterMethod(String setterName, boolean voidOnly) { for (MethodNode method : getDeclaredMethods(setterName)) { if (setterName.equals(method.getName()) && (!voidOnly || ClassHelper.VOID_TYPE==method.getReturnType()) && method.getParameters().length == 1) { return method; } } ClassNode parent = getSuperClass(); if (parent!=null) return parent.getSetterMethod(setterName, voidOnly); return null; }
private void addErrorIfParamsAndReturnTypeEqual(Parameter[] p2, Parameter[] p1, MethodNode node, MethodNode element) { boolean isEqual = true; for (int i = 0; i < p2.length; i++) { isEqual &= p1[i].getType().equals(p2[i].getType()); if (!isEqual) break; } isEqual &= node.getReturnType().equals(element.getReturnType()); if (isEqual) { addError("Repetitive method name/signature for " + getDescription(node) + " in " + getDescription(currentClass) + ".", node); } }
private void visitAnnotationDefault(MethodNode node, MethodVisitor mv) { if (!node.hasAnnotationDefault()) return; Expression exp = ((ReturnStatement) node.getCode()).getExpression(); AnnotationVisitor av = mv.visitAnnotationDefault(); visitAnnotationDefaultExpression(av,node.getReturnType(),exp); }
private static void renameMethod(ClassNode buildee, MethodNode mNode, String newName) { buildee.addMethod(newName, mNode.getModifiers(), mNode.getReturnType(), mNode.getParameters(), mNode.getExceptions(), mNode.getCode()); buildee.removeMethod(mNode); }
private static void createBuildeeMethods(ClassNode buildee, MethodNode mNode, ClassNode builder, List<FieldNode> fields) { ClassNode paramType = makeClassSafeWithGenerics(builder, setGenTypes(fields.size())); List<Expression> argsList = new ArrayList<Expression>(); Parameter initParam = param(paramType, "initializer"); for (FieldNode fieldNode : fields) { argsList.add(propX(varX(initParam), fieldNode.getName())); } String newName = "$" + mNode.getName(); // can't have private and public methods of the same name, so rename original buildee.addMethod(mNode.getName(), PUBLIC_STATIC, mNode.getReturnType(), params(param(paramType, "initializer")), NO_EXCEPTIONS, block(stmt(callX(buildee, newName, args(argsList))))); renameMethod(buildee, mNode, newName); }
@Override public void visitMethod(MethodNode node) { Parameter[] parameters = node.getParameters(); for (Parameter param : parameters) { ClassNode paramType = param.getType(); checkGenericsUsage(paramType, paramType.redirect()); } ClassNode returnType = node.getReturnType(); checkGenericsUsage(returnType, returnType.redirect()); super.visitMethod(node); }
@Override public void visitMethod(MethodNode node) { for (Parameter p : node.getParameters()) { addToCache(p.getType()); } addToCache(node.getReturnType()); addToCache(node.getExceptions()); super.visitMethod(node); } @Override
private void analyseMethodHead(MethodNode node) { visitNode(node.getReturnType()); analyseParameters(node.getParameters()); visitNodes(node.getExceptions()); }
public static MethodNode correctToGenericsSpec(Map<String, ClassNode> genericsSpec, MethodNode mn) { ClassNode correctedType = correctToGenericsSpecRecurse(genericsSpec, mn.getReturnType()); Parameter[] origParameters = mn.getParameters(); Parameter[] newParameters = new Parameter[origParameters.length]; for (int i = 0; i < origParameters.length; i++) { Parameter origParameter = origParameters[i]; newParameters[i] = new Parameter(correctToGenericsSpecRecurse(genericsSpec, origParameter.getType()), origParameter.getName(), origParameter.getInitialExpression()); } return new MethodNode(mn.getName(), mn.getModifiers(), correctedType, newParameters, mn.getExceptions(), mn.getCode()); }
public void visitMethod(MethodNode node) { visitParameters(node, node.getParameters()); String methodType = BytecodeHelper.getMethodDescriptor(node.getReturnType(), node.getParameters()); mv = cv.visitMethod(node.getModifiers(), node.getName(), methodType, null, null); mv.visitTypeInsn(NEW, "java/lang/RuntimeException"); mv.visitInsn(DUP); mv.visitLdcInsn("not intended for execution"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false); mv.visitInsn(ATHROW); mv.visitMaxs(0, 0); }
private static MethodNode createBuildMethodForMethod(AnnotationNode anno, ClassNode buildee, MethodNode mNode, Parameter[] params) { String buildMethodName = getMemberStringValue(anno, "buildMethodName", "build"); final BlockStatement body = new BlockStatement(); ClassNode returnType; if (mNode instanceof ConstructorNode) { returnType = newClass(buildee); body.addStatement(returnS(ctorX(newClass(mNode.getDeclaringClass()), args(params)))); } else { body.addStatement(returnS(callX(newClass(mNode.getDeclaringClass()), mNode.getName(), args(params)))); returnType = newClass(mNode.getReturnType()); } return new MethodNode(buildMethodName, ACC_PUBLIC, returnType, NO_PARAMS, NO_EXCEPTIONS, body); }