@Override public void visitConstructor(ConstructorNode node) { addNode(constructors, node.getDeclaringClass().getNameWithoutPackage(), node); super.visitConstructor(node); }
protected String prepareConstructorCall(ConstructorNode cn) { String owner = BytecodeHelper.getClassInternalName(cn.getDeclaringClass()); MethodVisitor mv = controller.getMethodVisitor(); mv.visitTypeInsn(NEW, owner); mv.visitInsn(DUP); return owner; }
MapExpression map = (MapExpression) expression; ClassNode declaringClass = node.getDeclaringClass(); for (ConstructorNode constructorNode : declaringClass.getDeclaredConstructors()) { if (constructorNode == node) {
protected void finnishConstructorCall(ConstructorNode cn, String ownerDescriptor, int argsToRemove) { String desc = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, cn.getParameters()); MethodVisitor mv = controller.getMethodVisitor(); mv.visitMethodInsn(INVOKESPECIAL, ownerDescriptor, "<init>", desc, false); controller.getOperandStack().remove(argsToRemove); controller.getOperandStack().push(cn.getDeclaringClass()); }
private static Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) { ClassNode type = node.getDeclaringClass(); ClassNode superType = type.getUnresolvedSuperClass(); Parameter[] bestMatch = null; for (ConstructorNode c : superType.getDeclaredConstructors()) { // Only look at things we can actually call if (!c.isPublic() && !c.isProtected()) continue; Parameter[] parameters = c.getParameters(); // workaround for GROOVY-5859: remove generic type info Parameter[] copy = new Parameter[parameters.length]; for (int i = 0; i < copy.length; i++) { Parameter orig = parameters[i]; copy[i] = new Parameter(orig.getOriginType().getPlainNodeReference(), orig.getName()); } if (noExceptionToAvoid(node,c)) return copy; if (bestMatch==null) bestMatch = copy; } if (bestMatch!=null) return bestMatch; // fall back for parameterless constructor if (superType.isPrimaryClassNode()) { return Parameter.EMPTY_ARRAY; } return null; }
@Override public void writeSpecialConstructorCall(final ConstructorCallExpression call) { MethodNode mn = call.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET); if (mn==null) { super.writeSpecialConstructorCall(call); return; } controller.getCompileStack().pushInSpecialConstructorCall(); ConstructorNode cn; if (mn instanceof ConstructorNode) { cn = (ConstructorNode) mn; } else { cn = new ConstructorNode(mn.getModifiers(), mn.getParameters(), mn.getExceptions(), mn.getCode()); cn.setDeclaringClass(mn.getDeclaringClass()); } // load "this" controller.getMethodVisitor().visitVarInsn(ALOAD, 0); String ownerDescriptor = BytecodeHelper.getClassInternalName(cn.getDeclaringClass()); TupleExpression args = makeArgumentList(call.getArguments()); int before = controller.getOperandStack().getStackLength(); loadArguments(args.getExpressions(), cn.getParameters()); finnishConstructorCall(cn, ownerDescriptor, controller.getOperandStack().getStackLength() - before); // on a special call, there's no object on stack controller.getOperandStack().remove(1); controller.getCompileStack().pop(); }
if (cn.isPrivate()) { ClassNode classNode = controller.getClassNode(); ClassNode declaringClass = cn.getDeclaringClass(); if (declaringClass != classNode) { MethodNode bridge = null;
@Override public String getName() { if (name == null) { if (node instanceof ConstructorNode) { name = ((ConstructorNode) node).getDeclaringClass().getNameWithoutPackage(); } else if (node instanceof MethodNode) { name = ((MethodNode) node).getName(); } if (name == null) { name = node.toString(); } } return name; }
private Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) { ClassNode type = node.getDeclaringClass(); ClassNode superType = type.getSuperClass(); boolean hadPrivateConstructor = false; for (Iterator iter = superType.getDeclaredConstructors().iterator(); iter.hasNext();) { ConstructorNode c = (ConstructorNode)iter.next(); // Only look at things we can actually call if (c.isPublic() || c.isProtected()) { return c.getParameters(); } } // fall back for parameterless constructor if (superType.isPrimaryClassNode()) { return Parameter.EMPTY_ARRAY; } return null; }
private Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) { ClassNode type = node.getDeclaringClass(); ClassNode superType = type.getSuperClass(); boolean hadPrivateConstructor = false; for (Iterator iter = superType.getDeclaredConstructors().iterator(); iter.hasNext();) { ConstructorNode c = (ConstructorNode)iter.next(); // Only look at things we can actually call if (c.isPublic() || c.isProtected()) { return c.getParameters(); } } // fall back for parameterless constructor if (superType.isPrimaryClassNode()) { return Parameter.EMPTY_ARRAY; } return null; }
private Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) { ClassNode type = node.getDeclaringClass(); ClassNode superType = type.getSuperClass(); boolean hadPrivateConstructor = false; for (Iterator iter = superType.getDeclaredConstructors().iterator(); iter.hasNext();) { ConstructorNode c = (ConstructorNode)iter.next(); // Only look at things we can actually call if (c.isPublic() || c.isProtected()) { return c.getParameters(); } } // fall back for parameterless constructor if (superType.isPrimaryClassNode()) { return Parameter.EMPTY_ARRAY; } return null; }
private Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) { ClassNode type = node.getDeclaringClass(); ClassNode superType = type.getSuperClass(); boolean hadPrivateConstructor = false; for (Iterator iter = superType.getDeclaredConstructors().iterator(); iter.hasNext();) { ConstructorNode c = (ConstructorNode) iter.next(); // Only look at things we can actually call if (c.isPublic() || c.isProtected()) { return c.getParameters(); } } // fall back for parameterless constructor if (superType.isPrimaryClassNode()) { return Parameter.EMPTY_ARRAY; } return null; }
public static boolean isSameConstructor(ConstructorNode constructor, ConstructorCallExpression call) { if (constructor.getDeclaringClass().getNameWithoutPackage().equals(call.getType().getNameWithoutPackage())) { // not comparing parameter types for now, only their count // is it even possible to make some check for parameter types? if (getParameterCount(call) == constructor.getParameters().length) { return true; } } return false; }
private String prepareConstructorCall(ConstructorNode cn) { String owner = BytecodeHelper.getClassInternalName(cn.getDeclaringClass()); MethodVisitor mv = controller.getMethodVisitor(); mv.visitTypeInsn(NEW, owner); mv.visitInsn(DUP); return owner; }
private Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) { ClassNode type = node.getDeclaringClass(); ClassNode superType = type.getSuperClass(); for (ConstructorNode c : superType.getDeclaredConstructors()) { // Only look at things we can actually call if (c.isPublic() || c.isProtected()) { return c.getParameters(); } } // fall back for parameterless constructor if (superType.isPrimaryClassNode()) { return Parameter.EMPTY_ARRAY; } return null; }
private Parameter[] selectAccessibleConstructorFromSuper(ConstructorNode node) { ClassNode type = node.getDeclaringClass(); ClassNode superType = type.getSuperClass(); for (ConstructorNode c : superType.getDeclaredConstructors()) { // Only look at things we can actually call if (c.isPublic() || c.isProtected()) { return c.getParameters(); } } // fall back for parameterless constructor if (superType.isPrimaryClassNode()) { return Parameter.EMPTY_ARRAY; } return null; }
private void finnishConstructorCall(ConstructorNode cn, String ownerDescriptor, int argsToRemove) { String desc = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, cn.getParameters()); MethodVisitor mv = controller.getMethodVisitor(); mv.visitMethodInsn(INVOKESPECIAL, ownerDescriptor, "<init>", desc); controller.getOperandStack().remove(argsToRemove); controller.getOperandStack().push(cn.getDeclaringClass()); }
int start = getOffset(doc, lineNumber, columnNumber); ConstructorNode constructorNode = (ConstructorNode) node; return getNextIdentifierByName(doc, constructorNode.getDeclaringClass().getNameWithoutPackage(), start); } else if (node instanceof MethodNode) { int start = getOffset(doc, lineNumber, columnNumber);