FieldNode field = node.getField(); String getterName = "get" + capitalize(name); String setterName = "set" + capitalize(name); MethodNode getter = classNode.getGetterMethod(getterName, !node.isStatic()); if (getter == null && ClassHelper.boolean_TYPE == node.getType()) { String secondGetterName = "is" + capitalize(name); getter = classNode.getGetterMethod(secondGetterName); if (!node.isPrivate() && methodNeedsReplacement(getter)) { getterBlock = createGetterBlock(node, field); if (!node.isPrivate() && !isFinal(accessorModifiers) && methodNeedsReplacement(setter)) { setterBlock = createSetterBlock(node, field); visitGetter(node, getterBlock, getterModifiers, getterName); String secondGetterName = "is" + capitalize(name); visitGetter(node, getterBlock, getterModifiers, secondGetterName); new MethodNode(setterName, accessorModifiers, ClassHelper.VOID_TYPE, setterParameterTypes, ClassNode.EMPTY_ARRAY, setterBlock); setter.setSynthetic(true); addPropertyMethod(setter); visitMethod(setter);
verifier.visitClass(classNode);
/** * Creates a new helper method for each combination of default parameter expressions */ protected void addDefaultParameters(List methods, DefaultArgsAction action) { for (Object next : methods) { MethodNode method = (MethodNode) next; if (method.hasDefaultValue()) { addDefaultParameters(action, method); } } }
protected void addInitialization(final ClassNode node) { boolean addSwapInit = moveOptimizedConstantsInitialization(node); for (ConstructorNode cn : node.getDeclaredConstructors()) { addInitialization(node, cn); } if (addSwapInit) { BytecodeSequence seq = new BytecodeSequence( new BytecodeInstruction() { @Override public void visit(MethodVisitor mv) { mv.visitMethodInsn(INVOKESTATIC, BytecodeHelper.getClassInternalName(node), SWAP_INIT, "()V", false); } }); List<Statement> swapCall = new ArrayList<Statement>(1); swapCall.add(seq); node.addStaticInitializerStatements(swapCall, true); } }
@Override public void visitClass(final ClassNode node) { List<Statement> savedStatements = new ArrayList<Statement>(node.getObjectInitializerStatements()); super.visitClass(node); node.getObjectInitializerStatements().addAll(savedStatements); for (ClassNode inode : node.getAllInterfaces()) { if (Traits.isTrait(inode)) { List<PropertyNode> traitProps = inode.getProperties(); for (PropertyNode pn : traitProps) { super.visitProperty(pn); } } } }
private void addCovariantMethods(ClassNode classNode, List declaredMethods, Map abstractMethods, Map methodsToAdd, Map oldGenericsSpec) { ClassNode sn = classNode.getUnresolvedSuperClass(false); if (sn != null) { Map genericsSpec = createGenericsSpec(sn, oldGenericsSpec); List<MethodNode> classMethods = sn.getMethods(); // original class causing bridge methods for methods in super class storeMissingCovariantMethods(declaredMethods, methodsToAdd, genericsSpec, classMethods); // super class causing bridge methods for abstract methods in original class if (!abstractMethods.isEmpty()) { for (Object classMethod : classMethods) { MethodNode method = (MethodNode) classMethod; if (method.isStatic()) continue; storeMissingCovariantMethods(abstractMethods.values(), method, methodsToAdd, Collections.EMPTY_MAP, true); } } addCovariantMethods(sn.redirect(), declaredMethods, abstractMethods, methodsToAdd, genericsSpec); } ClassNode[] interfaces = classNode.getInterfaces(); for (ClassNode anInterface : interfaces) { List interfacesMethods = anInterface.getMethods(); Map genericsSpec = createGenericsSpec(anInterface, oldGenericsSpec); storeMissingCovariantMethods(declaredMethods, methodsToAdd, genericsSpec, interfacesMethods); addCovariantMethods(anInterface, declaredMethods, abstractMethods, methodsToAdd, genericsSpec); } }
addInitialization(node, dummy); node.visitContents(this); return; addDefaultParameterMethods(node); addDefaultParameterConstructors(node); FieldNode metaClassField = getMetaClassField(node); metaClassField = setMetaClassFieldIfNotExists(node, metaClassField); addMethod(node,!Modifier.isAbstract(node.getModifiers()), "getMetaClass", ACC_PUBLIC, metaClassField=setMetaClassFieldIfNotExists(node,metaClassField); Statement setMetaClassCode; if (Modifier.isFinal(metaClassField.getModifiers())) { addMethod(node,!Modifier.isAbstract(node.getModifiers()), "setMetaClass", ACC_PUBLIC, addMethod(node,!Modifier.isAbstract(node.getModifiers()), "invokeMethod", ACC_PUBLIC, addMethod(node,!Modifier.isAbstract(node.getModifiers()), "getProperty", ACC_PUBLIC,
addInitialization(node, dummy); node.visitContents(this); if (classNode.getNodeMetaData(ClassNodeSkip.class) == null) { addDefaultParameterMethods(node); addDefaultParameterConstructors(node); addStaticMetaClassField(node, classInternalName); || node.isDerivedFrom(ClassHelper.GROOVY_OBJECT_SUPPORT_TYPE); addFastPathHelperFieldsAndHelperMethod(node, classInternalName, knownSpecialCase); if (!knownSpecialCase) addGroovyObjectInterfaceAndMethods(node, classInternalName); addDefaultConstructor(node); addInitialization(node); checkReturnInObjectInitializer(node.getObjectInitializerStatements()); node.getObjectInitializerStatements().clear(); node.visitContents(this); checkForDuplicateMethods(node); addCovariantMethods(node); checkFinalVariables(node);
addInitialization(node, dummy); node.visitContents(this); if (classNode.getNodeMetaData(ClassNodeSkip.class)==null) { addDefaultParameterMethods(node); addDefaultParameterConstructors(node); addStaticMetaClassField(node, classInternalName); || node.isDerivedFrom(ClassHelper.GROOVY_OBJECT_SUPPORT_TYPE); addFastPathHelperFieldsAndHelperMethod(node, classInternalName, knownSpecialCase); if (!knownSpecialCase) addGroovyObjectInterfaceAndMethods(node, classInternalName); addDefaultConstructor(node); if (!(node instanceof InnerClassNode)) addTimeStamp(node); addInitialization(node); checkReturnInObjectInitializer(node.getObjectInitializerStatements()); node.getObjectInitializerStatements().clear(); node.visitContents(this); addCovariantMethods(node);
private static String getSetterName(String name) { return "set" + Verifier.capitalize(name); } }
Map genericsSpec = createGenericsSpec(sn,oldGenericsSpec); List classMethods = sn.getMethods(); MethodNode method = (MethodNode) it.next(); if (method.isStatic()) continue; storeMissingCovariantMethods(classMethods,method,methodsToAdd,genericsSpec); MethodNode method = (MethodNode) it.next(); if (method.isStatic()) continue; storeMissingCovariantMethods(abstractMethods.values(),method,methodsToAdd,Collections.EMPTY_MAP); addCovariantMethods(sn.redirect(),declaredMethods,abstractMethods,methodsToAdd,genericsSpec); for (int i=0; i<interfaces.length; i++) { List interfacesMethods = interfaces[i].getMethods(); Map genericsSpec = createGenericsSpec(interfaces[i],oldGenericsSpec); for (Iterator it = declaredMethods.iterator(); it.hasNext();) { MethodNode method = (MethodNode) it.next(); if (method.isStatic()) continue; storeMissingCovariantMethods(interfacesMethods,method,methodsToAdd,genericsSpec); addCovariantMethods(interfaces[i],declaredMethods,abstractMethods,methodsToAdd,genericsSpec);
/** * gets the time stamp of a given class. For groovy * generated classes this usually means to return the value * of the static field __timeStamp. If the parameter doesn't * have such a field, then Long.MAX_VALUE is returned * * @param cls the class * @return the time stamp */ protected long getTimeStamp(Class cls) { return Verifier.getTimestamp(cls); }
return; ConstructorCallExpression first = getFirstIfSpecialConstructorCall(firstStatement); addFieldInitialization(statements, staticStatements, fn, isEnum, initStmtsAfterEnumValuesInit, explicitStaticPropsInEnum); statements.add(0, firstStatement); Statement stmtThis$0 = getImplicitThis$0StmtIfInnerClass(otherStatements); if (stmtThis$0 != null) {
protected void addInitialization(ClassNode node, ConstructorNode constructorNode) { Statement firstStatement = constructorNode.getFirstStatement(); ConstructorCallExpression first = getFirstIfSpecialConstructorCall(firstStatement); final boolean isEnumClassNode = isEnum(node); List initStmtsAfterEnumValuesInit = new ArrayList(); Set explicitStaticPropsInEnum = new HashSet(); addFieldInitialization(statements, staticStatements, (FieldNode) iter.next(), isEnumClassNode, initStmtsAfterEnumValuesInit, explicitStaticPropsInEnum);
addCovariantMethods(classNode, declaredMethods, abstractMethods, methodsToAdd, genericsSpec); addPropertyMethod(method);
this.generatedClasses = new ArrayList<GroovyClass>(); this.verifier = new Verifier(); this.resolveVisitor = new ResolveVisitor(this); this.staticImportVisitor = new StaticImportVisitor();
collectSuperInterfaceMethods(classNode, allInterfaceMethods); addCovariantMethods(classNode, declaredMethods, abstractMethods, methodsToAdd, genericsSpec); addPropertyMethod(method);
protected void addInitialization(ClassNode node, ConstructorNode constructorNode) { Statement firstStatement = constructorNode.getFirstStatement(); ConstructorCallExpression first = getFirstIfSpecialConstructorCall(firstStatement); addFieldInitialization(statements, staticStatements, (FieldNode) iter.next(), isEnum, initStmtsAfterEnumValuesInit, explicitStaticPropsInEnum);
protected void addInitialization(ClassNode node) { for (Iterator iter = node.getDeclaredConstructors().iterator(); iter.hasNext();) { addInitialization(node, (ConstructorNode) iter.next()); } }
addCovariantMethods(classNode, declaredMethods, abstractMethods, methodsToAdd, genericsSpec);