/** * @return the list of abstract methods associated with this * ClassNode or null if there are no such methods */ public List<MethodNode> getAbstractMethods() { List<MethodNode> result = new ArrayList<MethodNode>(3); for (MethodNode method : getDeclaredMethodsMap().values()) { if (method.isAbstract()) { result.add(method); } } if (result.isEmpty()) { return null; } else { return result; } }
private static List<ClassNode[]> extractSignaturesFromMethods(final ClassNode cn) { List<MethodNode> methods = cn.getAllDeclaredMethods(); List<ClassNode[]> signatures = new LinkedList<ClassNode[]>(); for (MethodNode method : methods) { if (!method.isSynthetic() && method.isAbstract()) { extractParametersFromMethod(signatures, method); } } return signatures; }
private void checkAbstractDeclaration(MethodNode methodNode) { if (!methodNode.isAbstract()) return; if (isAbstract(currentClass.getModifiers())) return; addError("Can't have an abstract method in a non-abstract class." + " The " + getDescription(currentClass) + " must be declared abstract or the method '" + methodNode.getTypeDescriptor() + "' must not be abstract.", methodNode); }
private static void checkForAbstractMethods(ClassNode enumClass) { List<MethodNode> methods = enumClass.getMethods(); for (MethodNode m : methods) { if (m.isAbstract()) { // make the class abstract also see Effective Java p.152 enumClass.setModifiers(enumClass.getModifiers() | Opcodes.ACC_ABSTRACT); break; } } }
if (found != null) { String td = methodDescriptorWithoutReturnType(found); if (result.containsKey(td) && !result.get(td).isAbstract()) { continue; if (found != null) { String td = methodDescriptorWithoutReturnType(found); if (result.containsKey(td) && !result.get(td).isAbstract()) { continue;
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())); } } }
MethodNode mn = result.get(methodNode.getTypeDescriptor()); if (mn != null && (mn.isStatic() ^ methodNode.isStatic()) && !methodNode.isStaticConstructor()) { if (!mn.isAbstract()) continue; ClassNode declaringClass = mn.getDeclaringClass(); ClassNode cn = declaringClass.getOuterClass();
} else if (!node.isAbstract()) { Statement code = node.getCode(); mv.visitCode();
if (method==null && !traitMethod.isAbstract()) { printMethod(out, classNode, traitMethod);
public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source); AnnotatedNode parent = (AnnotatedNode) nodes[1]; AnnotationNode node = (AnnotationNode) nodes[0]; if (!MY_TYPE.equals(node.getClassNode())) return; String value = getMemberStringValue(node, "value"); if (parent instanceof MethodNode) { MethodNode mNode = (MethodNode) parent; if (mNode.isAbstract()) { addError("Error during " + MY_TYPE_NAME + " processing: annotation not allowed on abstract method '" + mNode.getName() + "'", mNode); return; } ClassNode cNode = mNode.getDeclaringClass(); String lockExpr = determineLock(value, cNode, mNode); if (lockExpr == null) return; Statement origCode = mNode.getCode(); Statement newCode = new SynchronizedStatement(varX(lockExpr), origCode); mNode.setCode(newCode); } }
return null; if (!methodNode.isAbstract()) { MethodNode newMethod = processMethod(cNode, helper, methodNode, fieldHelper, fieldNames); if (methodNode.getName().equals("<clinit>")) {
String name = methodNode.getName(); Parameter[] helperMethodParams = methodNode.getParameters(); boolean isAbstract = methodNode.isAbstract(); if (!isAbstract && helperMethodParams.length > 0 && ((methodNode.getModifiers() & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) && (!name.contains("$") || (methodNode.getModifiers() & Opcodes.ACC_SYNTHETIC) == 0)) { ArgumentListExpression argList = new ArgumentListExpression();
if (mn.getTypeDescriptor().equals(candidate.getTypeDescriptor()) && !mn.isAbstract() && !mn.isStatic()) { existingNode = mn; break;
private MethodNode processMethod(ClassNode traitClass, ClassNode traitHelperClass, MethodNode methodNode, ClassNode fieldHelper, Collection<String> knownFields) { Parameter[] initialParams = methodNode.getParameters(); Parameter[] newParams = new Parameter[initialParams.length + 1]; newParams[0] = createSelfParameter(traitClass, methodNode.isStatic()); System.arraycopy(initialParams, 0, newParams, 1, initialParams.length); final int mod = methodNode.isPrivate() ? ACC_PRIVATE : ACC_PUBLIC | (methodNode.isFinal() ? ACC_FINAL : 0); MethodNode mNode = new MethodNode( methodNode.getName(), mod | ACC_STATIC, methodNode.getReturnType(), newParams, methodNode.getExceptions(), processBody(new VariableExpression(newParams[0]), methodNode.getCode(), traitClass, traitHelperClass, fieldHelper, knownFields) ); mNode.setSourcePosition(methodNode); mNode.addAnnotations(filterAnnotations(methodNode.getAnnotations())); mNode.setGenericsTypes(methodNode.getGenericsTypes()); if (methodNode.isAbstract()) { mNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT); } else { methodNode.addAnnotation(new AnnotationNode(Traits.IMPLEMENTED_CLASSNODE)); } methodNode.setCode(null); if (!methodNode.isPrivate() && !methodNode.isStatic()) { methodNode.setModifiers(ACC_PUBLIC | ACC_ABSTRACT); } return mNode; }
public void visitMethod(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods { final Statement code = addReturnsIfNeeded(statement, node.getVariableScope()); if (doAdd) node.setCode(code); } } else if (!node.isAbstract() && node.getReturnType().redirect()!=ClassHelper.VOID_TYPE) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); Statement code = node.getCode(); if (code instanceof BlockStatement) { newBlock.setVariableScope(((BlockStatement) code).getVariableScope()); } if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } final ReturnStatement returnStatement = ReturnStatement.RETURN_NULL_OR_VOID; listener.returnStatementAdded(returnStatement); newBlock.addStatement(returnStatement); newBlock.setSourcePosition(statement); if (doAdd) node.setCode(newBlock); } } }
List<MethodNode> baseMethods = enumBase.getMethods(); for (MethodNode methodNode : baseMethods) { if (!methodNode.isAbstract()) continue; MethodNode enumConstMethod = inner.getMethod(methodNode.getName(), methodNode.getParameters()); if (enumConstMethod == null || (enumConstMethod.getModifiers() & Opcodes.ACC_ABSTRACT) != 0) {
if (MY_TYPE.equals(annotationNode.getClassNode()) && annotatedNode instanceof MethodNode) { MethodNode methodNode = (MethodNode) annotatedNode; if (methodNode.isAbstract()) { addError("Annotation " + MY_TYPE_NAME + " cannot be used for abstract methods.", methodNode); return;
/** * Should this method be transformed? */ protected boolean shouldBeTransformed(MethodNode node) { return !node.isSynthetic() && !hasAnnotation(node, NonCPS.class) && !hasAnnotation(node, WorkflowTransformed.class) && !node.isAbstract(); }
/** * 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(); }
/** * Decides whether the given <tt>method</tt> is a candidate for class invariants. * * @param type the current {@link org.codehaus.groovy.ast.ClassNode} * @param method the {@link org.codehaus.groovy.ast.MethodNode} to check for class invariant compliance * @return whether the given {@link org.codehaus.groovy.ast.MethodNode} is a candidate for class invariants */ public static boolean isClassInvariantCandidate(final ClassNode type, final MethodNode method) { if (method.isSynthetic() || method.isAbstract() || method.isStatic() || !method.isPublic()) return false; if (method.getDeclaringClass() != type) return false; return true; }