use of com.puppycrawl.tools.checkstyle.api.Scope in project checkstyle by checkstyle.
the class JavadocMethodCheck method calculateScope.
/**
* Returns the scope for the method/constructor at the specified AST. If
* the method is in an interface or annotation block, the scope is assumed
* to be public.
*
* @param ast the token of the method/constructor
* @return the scope of the method/constructor
*/
private static Scope calculateScope(final DetailAST ast) {
final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
return Scope.PUBLIC;
} else {
return declaredScope;
}
}
use of com.puppycrawl.tools.checkstyle.api.Scope in project checkstyle by checkstyle.
the class JavadocTypeCheck method shouldCheck.
/**
* 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) {
final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
final Scope customScope;
if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
customScope = Scope.PUBLIC;
} else {
customScope = declaredScope;
}
final Scope surroundingScope = ScopeUtils.getSurroundingScope(ast);
return customScope.isIn(scope) && (surroundingScope == null || surroundingScope.isIn(scope)) && (excludeScope == null || !customScope.isIn(excludeScope) || surroundingScope != null && !surroundingScope.isIn(excludeScope));
}
use of com.puppycrawl.tools.checkstyle.api.Scope in project checkstyle by checkstyle.
the class JavadocVariableCheck method shouldCheck.
/**
* 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) {
if (ScopeUtils.isInCodeBlock(ast) || isIgnored(ast)) {
return false;
}
final Scope customScope;
if (ast.getType() == TokenTypes.ENUM_CONSTANT_DEF) {
customScope = Scope.PUBLIC;
} else {
final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
final Scope declaredScope = ScopeUtils.getScopeFromMods(mods);
if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
customScope = Scope.PUBLIC;
} else {
customScope = declaredScope;
}
}
final Scope surroundingScope = ScopeUtils.getSurroundingScope(ast);
return customScope.isIn(scope) && surroundingScope.isIn(scope) && (excludeScope == null || !customScope.isIn(excludeScope) || !surroundingScope.isIn(excludeScope));
}
use of com.puppycrawl.tools.checkstyle.api.Scope in project checkstyle by checkstyle.
the class MethodCountCheck method raiseCounter.
/**
* Determine the visibility modifier and raise the corresponding counter.
* @param method
* The method-subtree from the AbstractSyntaxTree.
*/
private void raiseCounter(DetailAST method) {
final MethodCounter actualCounter = counters.peek();
final DetailAST temp = method.findFirstToken(TokenTypes.MODIFIERS);
final Scope scope = ScopeUtils.getScopeFromMods(temp);
actualCounter.increment(scope);
}
use of com.puppycrawl.tools.checkstyle.api.Scope in project checkstyle by checkstyle.
the class ScopeUtils method getSurroundingScope.
/**
* Returns the scope of the surrounding "block".
* @param node the node to return the scope for
* @return the Scope of the surrounding block
*/
public static Scope getSurroundingScope(DetailAST node) {
Scope returnValue = null;
for (DetailAST token = node.getParent(); token != null; token = token.getParent()) {
final int type = token.getType();
if (type == TokenTypes.CLASS_DEF || type == TokenTypes.INTERFACE_DEF || type == TokenTypes.ANNOTATION_DEF || type == TokenTypes.ENUM_DEF) {
final DetailAST mods = token.findFirstToken(TokenTypes.MODIFIERS);
final Scope modScope = getScopeFromMods(mods);
if (returnValue == null || returnValue.isIn(modScope)) {
returnValue = modScope;
}
} else if (type == TokenTypes.LITERAL_NEW) {
returnValue = Scope.ANONINNER;
// because Scope.ANONINNER is not in any other Scope
break;
}
}
return returnValue;
}
Aggregations