public boolean isPackageScope() { return !(this.isPrivate() || this.isProtected() || this.isPublic()); }
private void checkAbstractMethodVisibility(ClassNode node) { // we only do check abstract classes (including enums), no interfaces or non-abstract classes if (!isAbstract(node.getModifiers()) || isInterface(node.getModifiers())) return; List<MethodNode> abstractMethods = node.getAbstractMethods(); if (abstractMethods == null || abstractMethods.isEmpty()) return; for (MethodNode method : abstractMethods) { if (method.isPrivate()) { addError("Method '" + method.getName() + "' from " + getDescription(node) + " must not be private as it is declared as an abstract method.", method); } } }
if (mNode.getDeclaringClass() != origType && mNode.isPrivate()) {
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; } } }
if (methodNode.isPrivate() && !enclosingClassNode.equals(declaringClass)) { continue;
private Expression transformMethodCallOnThis(final MethodCallExpression call) { Expression method = call.getMethod(); Expression arguments = call.getArguments(); if (method instanceof ConstantExpression) { String methodName = method.getText(); List<MethodNode> methods = traitClass.getMethods(methodName); for (MethodNode methodNode : methods) { if (methodName.equals(methodNode.getName()) && methodNode.isPrivate()) { if (inClosure) { return transformPrivateMethodCallOnThisInClosure(call, arguments, methodName); } return transformPrivateMethodCallOnThis(call, arguments, methodName); } } } if (inClosure) { return transformMethodCallOnThisInClosure(call); } return transformMethodCallOnThisFallBack(call, method, arguments); }
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); } } }
private void printMethod(PrintWriter out, ClassNode clazz, MethodNode methodNode) { if (methodNode.getName().equals("<clinit>")) return; if (methodNode.isPrivate() || !Utilities.isJavaIdentifier(methodNode.getName())) return; if (methodNode.isSynthetic() && methodNode.getName().equals("$getStaticMetaClass")) 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); } }
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; }
if (methodNode.isPrivate() || methodNode.isStatic()) { nonPublicAPIMethods.add(methodNode);
if (oldMethod.isPrivate()) return null;
if (target.isStatic()) { opcode = INVOKESTATIC; } else if (target.isPrivate() || ((receiver instanceof VariableExpression && ((VariableExpression) receiver).isSuperExpression()))) { opcode = INVOKESPECIAL; } else if (declaringClass.isInterface()) {
if (target.isPrivate()) { if (tryPrivateMethod(target, implicitThis, receiver, args, classNode)) return true; } else if (target.isProtected()) {
private boolean isExceptionHandlingMethod(MethodNode methodNode) { boolean isExceptionHandler = false; if(!methodNode.isPrivate() && methodNode.getName().indexOf("$") == -1) { Parameter[] parameters = methodNode.getParameters(); if(parameters.length == 1) { ClassNode parameterTypeClassNode = parameters[0].getType(); isExceptionHandler = parameterTypeClassNode.isDerivedFrom(new ClassNode(Exception.class)); } } return isExceptionHandler; }
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 genMethod(ClassNode clazz, MethodNode methodNode, PrintWriter out) { if (methodNode.getName().equals("<clinit>")) return; if (methodNode.isPrivate() || !Utilities.isJavaIdentifier(methodNode.getName())) return; if (!clazz.isInterface()) printModifiers(out, methodNode.getModifiers()); writeGenericsBounds(out, methodNode.getGenericsTypes()); out.print(" "); printType(methodNode.getReturnType(), out); out.print(" "); out.print(methodNode.getName()); printParams(methodNode, out); ClassNode[] exceptions = methodNode.getExceptions(); for (int i=0; i<exceptions.length; i++) { ClassNode exception = exceptions[i]; if (i==0) { out.print("throws "); } else { out.print(", "); } printType(exception,out); } if ((methodNode.getModifiers() & Opcodes.ACC_ABSTRACT) != 0) { out.println(";"); } else { out.print(" { "); ClassNode retType = methodNode.getReturnType(); printReturn(out, retType); out.println("}"); } }
private void printMethod(PrintWriter out, ClassNode clazz, MethodNode methodNode) { if (methodNode.getName().equals("<clinit>")) return; if (methodNode.isPrivate() || !Utilities.isJavaIdentifier(methodNode.getName())) return; if (methodNode.isSynthetic() && methodNode.getName().equals("$getStaticMetaClass")) return;
private void printMethod(PrintWriter out, ClassNode clazz, MethodNode methodNode) { if (methodNode.getName().equals("<clinit>")) return; if (methodNode.isPrivate() || !Utilities.isJavaIdentifier(methodNode.getName())) return; if (methodNode.isSynthetic() && methodNode.getName().equals("$getStaticMetaClass")) return;
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); } } }