private void checkForBadPrivateInterfaceMethod(ASTMethodDeclaration node) { if (jdkVersion < 9 && inInterface && node.isPrivate()) { throwParseException("Cannot use private interface methods when running in JDK inferior to 9 mode!"); } } private void checkForBadIdentifier(String image) {
/** * Returns true if this method has public visibility. * Non-private interface members are implicitly public, * whether they declare the {@code public} modifier or * not. */ @Override public boolean isPublic() { // interface methods are public by default, but could be private since java9 return isInterfaceMember() && !isPrivate() || super.isPublic(); }
private boolean isSerializationMethod(ASTMethodDeclaration node) { ASTMethodDeclarator declarator = node.getFirstDescendantOfType(ASTMethodDeclarator.class); List<ASTFormalParameter> parameters = declarator.findDescendantsOfType(ASTFormalParameter.class); if (node.isPrivate() && "readObject".equals(node.getMethodName()) && parameters.size() == 1 && throwsOneException(node, InvalidObjectException.class)) { ASTType type = parameters.get(0).getTypeNode(); if (type.getType() == ObjectInputStream.class || ObjectInputStream.class.getSimpleName().equals(type.getTypeImage()) || ObjectInputStream.class.getName().equals(type.getTypeImage())) { return true; } } return false; }
@Override public Object visit(ASTMethodDeclaration node, Object data) { if (!node.isPrivate() && !getProperty(CHECKALL_DESCRIPTOR)) { return data; } if (!node.isNative() && !node.isAbstract() && !isSerializationMethod(node) && !hasOverrideAnnotation(node)) { check(node, data); } return data; }
@Override public Object visit(final ASTMethodDeclaration node, Object data) { Set<Modifier> unnecessary = EnumSet.noneOf(Modifier.class); if (node.isSyntacticallyPublic()) { unnecessary.add(Modifier.PUBLIC); } if (node.isSyntacticallyAbstract()) { unnecessary.add(Modifier.ABSTRACT); } checkDeclarationInInterfaceType(data, node, unnecessary); if (node.isFinal()) { // If the method is annotated by @SafeVarargs then it's ok if (!isSafeVarargs(node)) { if (node.isPrivate()) { reportUnnecessaryModifiers(data, node, Modifier.FINAL, "private methods cannot be overridden"); } else { final Node n = node.getNthParent(3); // A final method of an anonymous class / enum constant. Neither can be extended / overridden if (n instanceof ASTAllocationExpression || n instanceof ASTEnumConstant) { reportUnnecessaryModifiers(data, node, Modifier.FINAL, "an anonymous class cannot be extended"); } else if (n instanceof ASTClassOrInterfaceDeclaration && ((AccessNode) n).isFinal()) { reportUnnecessaryModifiers(data, node, Modifier.FINAL, "the method is already in a final class"); } } } } return data; }
@Override public Object visit(ASTMethodDeclaration method, Object data) { if (!method.getResultType().returnsArray() || method.isPrivate()) { return data;
if (!m.isPrivate()) { methodCount++;
private void checkForBadPrivateInterfaceMethod(ASTMethodDeclaration node) { if (jdkVersion < 9 && inInterface && node.isPrivate()) { throwParseException("Cannot use private interface methods when running in JDK inferior to 9 mode!"); } } private void checkForBadIdentifier(String image) {
/** * Returns true if this method has public visibility. * Non-private interface members are implicitly public, * whether they declare the {@code public} modifier or * not. */ @Override public boolean isPublic() { // interface methods are public by default, but could be private since java9 return isInterfaceMember() && !isPrivate() || super.isPublic(); }
private boolean isSerializationMethod(ASTMethodDeclaration node) { ASTMethodDeclarator declarator = node.getFirstDescendantOfType(ASTMethodDeclarator.class); List<ASTFormalParameter> parameters = declarator.findDescendantsOfType(ASTFormalParameter.class); if (node.isPrivate() && "readObject".equals(node.getMethodName()) && parameters.size() == 1 && throwsOneException(node, InvalidObjectException.class)) { ASTType type = parameters.get(0).getTypeNode(); if (type.getType() == ObjectInputStream.class || ObjectInputStream.class.getSimpleName().equals(type.getTypeImage()) || ObjectInputStream.class.getName().equals(type.getTypeImage())) { return true; } } return false; }
private boolean isInPrimaryOrProtectedMethod(ASTAllocationExpression node) { ASTMethodDeclaration methodDeclaration = node.getFirstParentOfType(ASTMethodDeclaration.class); return methodDeclaration != null && returnThread(methodDeclaration) && (methodDeclaration.isPrivate() || methodDeclaration.isProtected()); }
@Override public Object visit(ASTMethodDeclaration node, Object data) { if (!node.isPrivate() && !getProperty(CHECKALL_DESCRIPTOR)) { return data; } if (!node.isNative() && !node.isAbstract() && !isSerializationMethod(node) && !hasOverrideAnnotation(node)) { check(node, data); } return data; }
@Override public Object visit(final ASTMethodDeclaration node, Object data) { Set<Modifier> unnecessary = EnumSet.noneOf(Modifier.class); if (node.isSyntacticallyPublic()) { unnecessary.add(Modifier.PUBLIC); } if (node.isSyntacticallyAbstract()) { unnecessary.add(Modifier.ABSTRACT); } checkDeclarationInInterfaceType(data, node, unnecessary); if (node.isFinal()) { // If the method is annotated by @SafeVarargs then it's ok if (!isSafeVarargs(node)) { if (node.isPrivate()) { reportUnnecessaryModifiers(data, node, Modifier.FINAL, "private methods cannot be overridden"); } else { final Node n = node.getNthParent(3); // A final method of an anonymous class / enum constant. Neither can be extended / overridden if (n instanceof ASTAllocationExpression || n instanceof ASTEnumConstant) { reportUnnecessaryModifiers(data, node, Modifier.FINAL, "an anonymous class cannot be extended"); } else if (n instanceof ASTClassOrInterfaceDeclaration && ((AccessNode) n).isFinal()) { reportUnnecessaryModifiers(data, node, Modifier.FINAL, "the method is already in a final class"); } } } } return data; }
@Override public Object visit(ASTMethodDeclaration method, Object data) { if (!method.getResultType().returnsArray() || method.isPrivate()) { return data;
if (!m.isPrivate()) { methodCount++;