public List<MethodNode> handleMissingMethod(final ClassNode receiver, final String name, final ArgumentListExpression argumentList, final ClassNode[] argumentTypes, final MethodCall call) { List<MethodNode> result = new LinkedList<MethodNode>(); for (TypeCheckingExtension handler : handlers) { List<MethodNode> handlerResult = handler.handleMissingMethod(receiver, name, argumentList, argumentTypes, call); for (MethodNode mn : handlerResult) { if (mn.getDeclaringClass()==null) { mn.setDeclaringClass(ClassHelper.OBJECT_TYPE); } } result.addAll(handlerResult); } return result; }
public void addMethod(MethodNode node) { node.setDeclaringClass(this); ClassNode base = redirect(); if (base.methodsList.isEmpty()) { base.methodsList = new ArrayList<MethodNode>(); } base.methodsList.add(node); base.methods.put(node.getName(), node); }
protected MethodNode typeCheckMapConstructor(final ConstructorCallExpression call, final ClassNode receiver, final Expression arguments) { MethodNode node = null; if (arguments instanceof TupleExpression) { TupleExpression texp = (TupleExpression) arguments; List<Expression> expressions = texp.getExpressions(); // should only get here with size = 2 when inner class constructor if (expressions.size() == 1 || expressions.size() == 2) { Expression expression = expressions.get(expressions.size() - 1); if (expression instanceof MapExpression) { MapExpression argList = (MapExpression) expression; checkGroovyConstructorMap(call, receiver, argList); Parameter[] params = expressions.size() == 1 ? new Parameter[]{new Parameter(MAP_TYPE, "map")} : new Parameter[]{new Parameter(receiver.redirect().getOuterClass(), "$p$"), new Parameter(MAP_TYPE, "map")}; node = new ConstructorNode(Opcodes.ACC_PUBLIC, params, ClassNode.EMPTY_ARRAY, GENERATED_EMPTY_STATEMENT); node.setDeclaringClass(receiver); } } } return node; }
/** * add various getAt and setAt methods for primitive arrays * * @param receiver the receiver class * @param name the name of the method * @param args the argument classes */ private static void addArrayMethods(List<MethodNode> methods, ClassNode receiver, String name, ClassNode[] args) { if (args.length != 1) return; if (!receiver.isArray()) return; if (!isIntCategory(getUnwrapper(args[0]))) return; if ("getAt".equals(name)) { MethodNode node = new MethodNode(name, Opcodes.ACC_PUBLIC, receiver.getComponentType(), new Parameter[]{new Parameter(args[0], "arg")}, null, null); node.setDeclaringClass(receiver.redirect()); methods.add(node); } else if ("setAt".equals(name)) { MethodNode node = new MethodNode(name, Opcodes.ACC_PUBLIC, VOID_TYPE, new Parameter[]{new Parameter(args[0], "arg")}, null, null); node.setDeclaringClass(receiver.redirect()); methods.add(node); } }
for (MethodNode methodNode : anInterface.getMethods()) { MethodNode method = addMethod(methodNode.getName(), methodNode.getModifiers(), methodNode.getReturnType(), methodNode.getParameters(), methodNode.getExceptions(), methodNode.getCode()); method.setDeclaringClass(anInterface); // important for static compilation!
stubbed.setGenericsTypes(method.getGenericsTypes()); stubbed.setDeclaringClass(method.getDeclaringClass()); result.add(stubbed);
if (methods.isEmpty()) { MethodNode node = new ConstructorNode(Opcodes.ACC_PUBLIC, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, GENERATED_EMPTY_STATEMENT); node.setDeclaringClass(receiver); methods = Collections.singletonList(node); if (receiver.isArray()) { node.setModifiers(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC); node.setDeclaringClass(receiver); return Collections.singletonList( node); node.setModifiers(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC); node.setDeclaringClass(receiver); return Collections.singletonList(node);
private MethodNode copyMethod(MethodNode method, String newName) { // can't hurt to set return type to void MethodNode newMethod = new MethodNode(newName, method.getModifiers(), ClassHelper.VOID_TYPE, method.getParameters(), method.getExceptions(), method.getCode()); newMethod.addAnnotations(method.getAnnotations()); newMethod.setSynthetic(method.isSynthetic()); newMethod.setDeclaringClass(method.getDeclaringClass()); newMethod.setSourcePosition(method); newMethod.setVariableScope(method.getVariableScope()); newMethod.setGenericsTypes(method.getGenericsTypes()); newMethod.setAnnotationDefault(method.hasAnnotationDefault()); return newMethod; }
EmptyStatement.INSTANCE ); dummyMN.setDeclaringClass(selectedMethod.getDeclaringClass()); dummyMN.setGenericsTypes(selectedMethod.getGenericsTypes()); if (selectedMethod instanceof ExtensionMethodNode) { orig.isStaticExtension() ); dummyMN.setDeclaringClass(orig.getDeclaringClass()); dummyMN.setGenericsTypes(orig.getGenericsTypes());
private static MethodCallExpression transformToMopSuperCall(final ClassNode superCallReceiver, final MethodCallExpression expr) { MethodNode mn = expr.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); String mopName = MopWriter.getMopMethodName(mn, false); MethodNode direct = new MethodNode( mopName, ACC_PUBLIC | ACC_SYNTHETIC, mn.getReturnType(), mn.getParameters(), mn.getExceptions(), EmptyStatement.INSTANCE ); direct.setDeclaringClass(superCallReceiver); MethodCallExpression result = new MethodCallExpression( new VariableExpression("this"), mopName, expr.getArguments() ); result.setImplicitThis(true); result.setSpreadSafe(false); result.setSafe(false); result.setSourcePosition(expr); result.setMethodTarget(direct); return result; }
Traits.STATIC_INIT_METHOD, Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, ClassHelper.VOID_TYPE, new Parameter[] {new Parameter(ClassHelper.CLASS_Type,"clazz")}, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE); staticInitMethod.setDeclaringClass(helperClassNode); staticInitCall.setMethodTarget(staticInitMethod); cNode.addStaticInitializerStatements(Collections.<Statement>singletonList(new ExpressionStatement(
EmptyStatement.INSTANCE ); setterMethod.setDeclaringClass(receiverType);
ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE); getterNode.setDeclaringClass(receiverType); if (propertyNode.isStatic()) getterNode.setModifiers(ACC_PUBLIC + ACC_STATIC);
public void addMethod(MethodNode node) { node.setDeclaringClass(this); redirect().methodsList.add(node); redirect().methods.put(node.getName(), node); }
public void addMethod(MethodNode node) { node.setDeclaringClass(this); redirect().methodsList.add(node); redirect().methods.put(node.getName(), node); }
public void addMethod(MethodNode node) { node.setDeclaringClass(this); redirect().getMethodsListLazy().add(node); redirect().getMethodsLazy().put(node.getName(), node); }
public void addMethod(MethodNode node) { node.setDeclaringClass(this); redirect().getMethodsListLazy().add(node); redirect().getMethodsLazy().put(node.getName(), node); }