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;
     }
   }
 }
 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 checkInterfaceMethodVisibility(ClassNode node) {
   if (!node.isInterface()) return;
   for (MethodNode method : node.getMethods()) {
     if (method.isPrivate()) {
       addError(
           "Method '"
               + method.getName()
               + "' is private but should be public in "
               + getDescription(currentClass)
               + ".",
           method);
     } else if (method.isProtected()) {
       addError(
           "Method '"
               + method.getName()
               + "' is protected but should be public in "
               + getDescription(currentClass)
               + ".",
           method);
     }
   }
 }
Пример #4
0
 /**
  * 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, Parameter.EMPTY_ARRAY);
   return method != null && (method.isPublic() || method.isProtected()) && !method.isAbstract();
 }