@Override public void visitToken(final DetailAST ast) { final boolean containsAnnotation = AnnotationUtil.containsAnnotation(ast); final boolean inPackageInfo = getFileContents().inPackageInfo(); if (containsAnnotation && !inPackageInfo) { log(ast.getLine(), MSG_KEY); } }
@Test public void testNotInPackageInfo() { final FileContents fileContents = new FileContents(new FileText( new File("filename.java"), Collections.singletonList(" // "))); assertFalse("Should return false when not in package info", fileContents.inPackageInfo()); }
@Test public void testInPackageInfo() { final FileContents fileContents = new FileContents(new FileText( new File("filename.package-info.java"), Collections.singletonList(" // "))); assertTrue("Should return true when in package info", fileContents.inPackageInfo()); }
if (getFileContents().inPackageInfo()) { log(ast.getLineNo(), MSG_JAVADOC_MISSING);
/** * Whether we should check this node. * @param ast a given node. * @return whether we should check a given node. */ private boolean shouldCheck(final DetailAST ast) { boolean check = false; if (ast.getType() == TokenTypes.PACKAGE_DEF) { check = getFileContents().inPackageInfo(); } else if (!ScopeUtil.isInCodeBlock(ast)) { final Scope customScope; if (ScopeUtil.isInInterfaceOrAnnotationBlock(ast) || ast.getType() == TokenTypes.ENUM_CONSTANT_DEF) { customScope = Scope.PUBLIC; } else { customScope = ScopeUtil.getScopeFromMods(ast.findFirstToken(TokenTypes.MODIFIERS)); } final Scope surroundingScope = ScopeUtil.getSurroundingScope(ast); check = customScope.isIn(scope) && (surroundingScope == null || surroundingScope.isIn(scope)) && (excludeScope == null || !customScope.isIn(excludeScope) || surroundingScope != null && !surroundingScope.isIn(excludeScope)); } return check; }
@Override public void visitToken(final DetailAST ast) { final boolean containsAnnotation = AnnotationUtil.containsAnnotation(ast); final boolean inPackageInfo = getFileContents().inPackageInfo(); if (containsAnnotation && !inPackageInfo) { log(ast.getLine(), MSG_KEY); } }
if (getFileContents().inPackageInfo()) { log(ast.getLineNo(), MSG_JAVADOC_MISSING);
/** * Whether we should check this node. * @param ast a given node. * @return whether we should check a given node. */ private boolean shouldCheck(final DetailAST ast) { boolean check = false; if (ast.getType() == TokenTypes.PACKAGE_DEF) { check = getFileContents().inPackageInfo(); } else if (!ScopeUtil.isInCodeBlock(ast)) { final Scope customScope; if (ScopeUtil.isInInterfaceOrAnnotationBlock(ast) || ast.getType() == TokenTypes.ENUM_CONSTANT_DEF) { customScope = Scope.PUBLIC; } else { customScope = ScopeUtil.getScopeFromMods(ast.findFirstToken(TokenTypes.MODIFIERS)); } final Scope surroundingScope = ScopeUtil.getSurroundingScope(ast); check = customScope.isIn(scope) && (surroundingScope == null || surroundingScope.isIn(scope)) && (excludeScope == null || !customScope.isIn(excludeScope) || surroundingScope != null && !surroundingScope.isIn(excludeScope)); } return check; }