private MethodNode findValidGetter(ClassNode classNode, String name) { MethodNode getterMethod = classNode.getGetterMethod(name); if (getterMethod != null && (getterMethod.isPublic() || getterMethod.isProtected())) { return getterMethod; } return null; }
private void addWeakerAccessError(ClassNode cn, MethodNode method, Parameter[] parameters, MethodNode superMethod) { StringBuilder msg = new StringBuilder(); msg.append(method.getName()); appendParamsDescription(parameters, msg); msg.append(" in "); msg.append(cn.getName()); msg.append(" cannot override "); msg.append(superMethod.getName()); msg.append(" in "); msg.append(superMethod.getDeclaringClass().getName()); msg.append("; attempting to assign weaker access privileges; was "); msg.append(superMethod.isPublic() ? "public" : "protected"); addError(msg.toString(), method); }
public boolean isPackageScope() { return !(this.isPrivate() || this.isProtected() || this.isPublic()); }
private static MethodNode selectConstructor(ClassNode node, Parameter[] paraTypes) { List<ConstructorNode> cl = node.getDeclaredConstructors(); MethodNode res = null; for (ConstructorNode cn : cl) { if (ParameterUtils.parametersEqual(cn.getParameters(), paraTypes)) { res = cn; break; } } if (res !=null && res.isPublic()) return res; return null; }
MethodNode m = (MethodNode) methodsIterator.next(); abstractMethods.remove(m.getTypeDescriptor()); if (m.isStatic() || !(m.isPublic() || m.isProtected())) { methodsIterator.remove(); && !m.isPublic() && !m.isStaticConstructor()) { throw new RuntimeParserException("The method " + m.getName() + " should be public as it implements the corresponding method from interface " +
private void checkMethodForWeakerAccessPrivileges(MethodNode mn, ClassNode cn) { if (mn.isPublic()) return; Parameter[] params = mn.getParameters(); for (MethodNode superMethod : cn.getSuperClass().getMethods(mn.getName())) { Parameter[] superParams = superMethod.getParameters(); if (!hasEqualParameterTypes(params, superParams)) continue; if ((mn.isPrivate() && !superMethod.isPrivate()) || (mn.isProtected() && superMethod.isPublic())) { addWeakerAccessError(cn, mn, params, superMethod); return; } } }
private void checkOverloadingPrivateAndPublic(MethodNode node) { if (isConstructor(node)) return; boolean hasPrivate = node.isPrivate(); boolean hasPublic = node.isPublic(); for (MethodNode method : currentClass.getMethods(node.getName())) { if (method == node) continue; if (!method.getDeclaringClass().equals(node.getDeclaringClass())) continue; if (method.isPublic() || method.isProtected()) { hasPublic = true; } else { hasPrivate = true; } if (hasPrivate && hasPublic) break; } if (hasPrivate && hasPublic) { addError("Mixing private and public/protected methods of the same name causes multimethods to be disabled and is forbidden to avoid surprising behaviour. Renaming the private methods will solve the problem.", node); } }
for (MethodNode metaMethod : cn.getMethods()) { Parameter[] types = metaMethod.getParameters(); if (metaMethod.isStatic() && metaMethod.isPublic() && types.length > 0 && metaMethod.getAnnotations(Deprecated_TYPE).isEmpty()) { Parameter[] parameters = new Parameter[types.length - 1];
continue outer; } else { if (methodNode.isPublic() || methodNode.isProtected()) { result.add(methodNode); continue outer;
private void addDelegateMethod(DelegateDescription delegate, List<MethodNode> ownMethods, MethodNode candidate, boolean includeDeprecated, boolean allNames) { if (!candidate.isPublic() || candidate.isStatic() || 0 != (candidate.getModifiers () & ACC_SYNTHETIC)) return;
if (classNode.isDerivedFrom(ClassHelper.CLOSURE_TYPE) && controller.isInClosure() && !target.isPublic() && target.getDeclaringClass() != classNode) { if (!tryBridgeMethod(target, receiver, implicitThis, args, classNode)) { return true; } else if (target.isPublic() && receiver != null) { if (implicitThis && !classNode.isDerivedFrom(target.getDeclaringClass())
mv.visitTypeInsn(CHECKCAST, owner); } else if (target.isPublic() && (!Modifier.isPublic(declaringClass.getModifiers()) && !receiverType.equals(declaringClass))
private boolean isPublicInstanceMethod(MethodNode methodNode) { return !methodNode.isSynthetic() && !methodNode.isStatic() && methodNode.isPublic(); }
private void addWeakerAccessError(ClassNode cn, MethodNode method, Parameter[] parameters, MethodNode superMethod) { StringBuilder msg = new StringBuilder(); msg.append(method.getName()); msg.append("("); boolean needsComma = false; for (Parameter parameter : parameters) { if (needsComma) { msg.append(","); } else { needsComma = true; } msg.append(parameter.getType()); } msg.append(") in "); msg.append(cn.getName()); msg.append(" cannot override "); msg.append(superMethod.getName()); msg.append(" in "); msg.append(superMethod.getDeclaringClass().getName()); msg.append("; attempting to assign weaker access privileges; was "); msg.append(superMethod.isPublic() ? "public" : "protected"); addError(msg.toString(), method); }
/** * 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(); }
private static MethodNode selectConstructor(ClassNode node, Parameter[] paraTypes) { List<ConstructorNode> cl = node.getDeclaredConstructors(); MethodNode res = null; for (ConstructorNode cn : cl) { if (parametersEqual(cn.getParameters(), paraTypes)) { res = cn; break; } } if (res !=null && res.isPublic()) return res; return null; }
/** * Checks whether the given {@link MethodNode} could be a candidate for an arbitrary {@link org.gcontracts.annotations.meta.ContractElement} * annotation. * * @param type the current {@link org.codehaus.groovy.ast.ClassNode} * @param method the {@link org.codehaus.groovy.ast.MethodNode} to check for {@link org.gcontracts.annotations.meta.ContractElement} compliance * @return whether the given method node could be a candidate or not */ public static boolean couldBeContractElementMethodNode(final ClassNode type, final MethodNode method) { if (method.isSynthetic() || !method.isPublic()) return false; if (method.getDeclaringClass() != null && !method.getDeclaringClass().getName().equals(type.getName())) return false; return true; }
/** * 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; }
private void checkOverloadingPrivateAndPublic(MethodNode node) { if (isConstructor(node)) return; boolean hasPrivate = false; boolean hasPublic = false; for (MethodNode method : currentClass.getMethods(node.getName())) { if (method == node) continue; if (!method.getDeclaringClass().equals(node.getDeclaringClass())) continue; if (method.isPublic() || method.isProtected()) { hasPublic = true; } else { hasPrivate = true; } } if (hasPrivate && hasPublic) { addError("Mixing private and public/protected methods of the same name causes multimethods to be disabled and is forbidden to avoid surprising behaviour. Renaming the private methods will solve the problem.", node); } }
private void checkMethodForWeakerAccessPrivileges(MethodNode mn, ClassNode cn) { Parameter[] params = mn.getParameters(); for (MethodNode superMethod : cn.getSuperClass().getMethods(mn.getName())) { Parameter[] superParams = superMethod.getParameters(); if (!hasEqualParameterTypes(params, superParams)) continue; if ((mn.isPrivate() && !superMethod.isPrivate()) || (mn.isProtected() && superMethod.isPublic())) { addWeakerAccessError(cn, mn, params, superMethod); return; } } }