本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java DetailAST.getParent方法的具体用法?Java DetailAST.getParent怎么用?Java DetailAST.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.DetailAST
的用法示例。
在下文中一共展示了DetailAST.getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mustCheckReferenceCount
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public boolean mustCheckReferenceCount(DetailAST aAST)
{
boolean result = false;
final DetailAST parent = aAST.getParent();
if (parent != null) {
if (parent.getType() == TokenTypes.PARAMETERS) {
final DetailAST grandparent = parent.getParent();
if (grandparent != null) {
result = hasBody(grandparent)
&& (!mIgnoreNonLocal || isLocal(grandparent));
}
}
else if (parent.getType() == TokenTypes.LITERAL_CATCH) {
result = !mIgnoreCatch;
}
}
return result;
}
示例2: visitSlist
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Process the end of a statement list.
*
* @param ast the token representing the statement list.
*/
private void visitSlist(DetailAST ast) {
if (context.getAST() != null) {
// find member AST for the statement list
final DetailAST contextAST = context.getAST();
DetailAST parent = ast.getParent();
int type = parent.getType();
while (type != TokenTypes.CTOR_DEF
&& type != TokenTypes.METHOD_DEF
&& type != TokenTypes.INSTANCE_INIT
&& type != TokenTypes.STATIC_INIT) {
parent = parent.getParent();
type = parent.getType();
}
if (parent == contextAST) {
context.addCount(ast.getChildCount() / 2);
}
}
}
示例3: getAccessModifier
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Returns the access modifier of the method/constructor at the specified AST. If
* the method is in an interface or annotation block, the access modifier is assumed
* to be public.
*
* @param ast the token of the method/constructor.
* @return the access modifier of the method/constructor.
*/
private static AccessModifier getAccessModifier(final DetailAST ast) {
final DetailAST params = ast.getParent();
final DetailAST meth = params.getParent();
AccessModifier accessModifier = AccessModifier.PRIVATE;
if (meth.getType() == TokenTypes.METHOD_DEF
|| meth.getType() == TokenTypes.CTOR_DEF) {
if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
accessModifier = AccessModifier.PUBLIC;
}
else {
final DetailAST modsToken = meth.findFirstToken(TokenTypes.MODIFIERS);
accessModifier = CheckUtils.getAccessModifierFromModifiersToken(modsToken);
}
}
return accessModifier;
}
示例4: isOverlappingByArgument
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks whether an overlapping by method or constructor argument takes place.
* @param ast an identifier.
* @return true if an overlapping by method or constructor argument takes place.
*/
private boolean isOverlappingByArgument(DetailAST ast) {
boolean overlapping = false;
final DetailAST parent = ast.getParent();
final DetailAST sibling = ast.getNextSibling();
if (sibling != null && isAssignToken(parent.getType())) {
if (isCompoundAssignToken(parent.getType())) {
overlapping = true;
}
else {
final ClassFrame classFrame = (ClassFrame) findFrame(ast, true);
final Set<DetailAST> exprIdents = getAllTokensOfType(sibling, TokenTypes.IDENT);
overlapping = classFrame.containsFieldOrVariableDef(exprIdents, ast);
}
}
return overlapping;
}
示例5: isInStatic
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Determines whether an AST node is in a static method or static
* initializer.
* @param ast the node to check.
* @return true if ast is in a static method or a static block;
*/
private static boolean isInStatic(DetailAST ast) {
DetailAST parent = ast.getParent();
boolean inStatic = false;
while (parent != null && !inStatic) {
if (parent.getType() == TokenTypes.STATIC_INIT) {
inStatic = true;
}
else if (parent.getType() == TokenTypes.METHOD_DEF
&& !ScopeUtils.isInScope(parent, Scope.ANONINNER)
|| parent.getType() == TokenTypes.VARIABLE_DEF) {
final DetailAST mods =
parent.findFirstToken(TokenTypes.MODIFIERS);
inStatic = mods.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
break;
}
else {
parent = parent.getParent();
}
}
return inStatic;
}
示例6: getMatchingAstElements
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Returns list of nodes matching defined line and column number.
* @return list of nodes matching defined line and column number
*/
private List<DetailAST> getMatchingAstElements() {
final List<DetailAST> result = new ArrayList<DetailAST>();
DetailAST curNode = rootAst;
while (curNode != null && curNode.getLineNo() <= lineNumber) {
if (isMatchingByLineAndColumnAndNotIdent(curNode)) {
result.add(curNode);
}
DetailAST toVisit = curNode.getFirstChild();
while (curNode != null && toVisit == null) {
toVisit = curNode.getNextSibling();
if (toVisit == null) {
curNode = curNode.getParent();
}
}
curNode = toVisit;
}
return result;
}
示例7: getBlockEndToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Returns the token which ends the code block.
* @param blockNameIdent block name identifier.
* @param blockStartToken token which starts the block.
* @return the token which ends the code block.
*/
private static DetailAST getBlockEndToken(DetailAST blockNameIdent, DetailAST blockStartToken) {
DetailAST blockEndToken = null;
final DetailAST blockNameIdentParent = blockNameIdent.getParent();
if (blockNameIdentParent.getType() == TokenTypes.CASE_GROUP) {
blockEndToken = blockNameIdentParent.getNextSibling();
}
else {
final Set<DetailAST> rcurlyTokens = getAllTokensOfType(blockNameIdent,
TokenTypes.RCURLY);
for (DetailAST currentRcurly : rcurlyTokens) {
final DetailAST parent = currentRcurly.getParent();
if (blockStartToken.getLineNo() == parent.getLineNo()) {
blockEndToken = currentRcurly;
}
}
}
return blockEndToken;
}
示例8: isUserDefinedArrangementOfThis
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks whether user arranges 'this' for variable in method, constructor, or block on his own.
* @param currentFrame current frame.
* @param ident ident token.
* @return true if user arranges 'this' for variable in method, constructor,
* or block on his own.
*/
private static boolean isUserDefinedArrangementOfThis(AbstractFrame currentFrame,
DetailAST ident) {
final DetailAST blockFrameNameIdent = currentFrame.getFrameNameIdent();
final DetailAST definitionToken = blockFrameNameIdent.getParent();
final DetailAST blockStartToken = definitionToken.findFirstToken(TokenTypes.SLIST);
final DetailAST blockEndToken = getBlockEndToken(blockFrameNameIdent, blockStartToken);
boolean userDefinedArrangementOfThis = false;
final Set<DetailAST> variableUsagesInsideBlock =
getAllTokensWhichAreEqualToCurrent(definitionToken, ident,
blockEndToken.getLineNo());
for (DetailAST variableUsage : variableUsagesInsideBlock) {
final DetailAST prevSibling = variableUsage.getPreviousSibling();
if (prevSibling != null
&& prevSibling.getType() == TokenTypes.LITERAL_THIS) {
userDefinedArrangementOfThis = true;
break;
}
}
return userDefinedArrangementOfThis;
}
示例9: isOuterMostType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Returns whether a node is contained in the outer most type block.
*
* @param node the node to check
* @return a {@code boolean} value
*/
public static boolean isOuterMostType(DetailAST node) {
boolean returnValue = true;
for (DetailAST parent = node.getParent();
parent != null;
parent = parent.getParent()) {
if (parent.getType() == TokenTypes.CLASS_DEF
|| parent.getType() == TokenTypes.INTERFACE_DEF
|| parent.getType() == TokenTypes.ANNOTATION_DEF
|| parent.getType() == TokenTypes.ENUM_DEF) {
returnValue = false;
break;
}
}
return returnValue;
}
示例10: reportMagicNumber
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Reports aAST as a magic number, includes unary operators as needed.
* @param ast the AST node that contains the number to report
*/
private void reportMagicNumber(DetailAST ast) {
String text = ast.getText();
final DetailAST parent = ast.getParent();
DetailAST reportAST = ast;
if (parent.getType() == TokenTypes.UNARY_MINUS) {
reportAST = parent;
text = "-" + text;
}
else if (parent.getType() == TokenTypes.UNARY_PLUS) {
reportAST = parent;
text = "+" + text;
}
log(reportAST.getLineNo(),
reportAST.getColumnNo(),
MSG_KEY,
text);
}
示例11: hasAtLeastOneSiblingWithSameTokenType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks if the given ast element has unique {@code TokenTypes} among siblings.
* @param ast {@code DetailAST} ast element
* @return if the given ast element has unique {@code TokenTypes} among siblings
*/
private static boolean hasAtLeastOneSiblingWithSameTokenType(DetailAST ast) {
boolean result = false;
if (ast.getParent() == null) {
DetailAST prev = ast.getPreviousSibling();
while (prev != null) {
if (prev.getType() == ast.getType()) {
result = true;
break;
}
prev = prev.getPreviousSibling();
}
if (!result) {
DetailAST next = ast.getNextSibling();
while (next != null) {
if (next.getType() == ast.getType()) {
result = true;
break;
}
next = next.getNextSibling();
}
}
}
else {
result = ast.getParent().getChildCount(ast.getType()) > 1;
}
return result;
}
示例12: getParentType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Returns type of parent node.
* @param commentBlock child node.
* @return parent type.
*/
private static int getParentType(DetailAST commentBlock) {
final DetailAST parentNode = commentBlock.getParent();
int type = parentNode.getType();
if (type == TokenTypes.TYPE || type == TokenTypes.MODIFIERS) {
type = parentNode.getParent().getType();
}
return type;
}
示例13: isDistributedExpression
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks whether the previous statement of a comment is a method call chain or
* string concatenation statement distributed over two ore more lines.
* @param comment comment to check.
* @return true if the previous statement is a distributed expression.
*/
private boolean isDistributedExpression(DetailAST comment) {
DetailAST previousSibling = comment.getPreviousSibling();
while (previousSibling != null && isComment(previousSibling)) {
previousSibling = previousSibling.getPreviousSibling();
}
boolean isDistributed = false;
if (previousSibling != null) {
if (previousSibling.getType() == TokenTypes.SEMI
&& isOnPreviousLineIgnoringComments(comment, previousSibling)) {
DetailAST currentToken = previousSibling.getPreviousSibling();
while (currentToken.getFirstChild() != null) {
currentToken = currentToken.getFirstChild();
}
if (currentToken.getType() == TokenTypes.COMMENT_CONTENT) {
currentToken = currentToken.getParent();
while (isComment(currentToken)) {
currentToken = currentToken.getNextSibling();
}
}
if (previousSibling.getLineNo() != currentToken.getLineNo()) {
isDistributed = true;
}
}
else {
isDistributed = isStatementWithPossibleCurlies(previousSibling);
}
}
return isDistributed;
}
示例14: isOverlappingByLocalVariable
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks whether an overlapping by local variable takes place.
* @param ast an identifier.
* @return true if an overlapping by local variable takes place.
*/
private boolean isOverlappingByLocalVariable(DetailAST ast) {
boolean overlapping = false;
final DetailAST parent = ast.getParent();
final DetailAST sibling = ast.getNextSibling();
if (sibling != null && isAssignToken(parent.getType())) {
final ClassFrame classFrame = (ClassFrame) findFrame(ast, true);
final Set<DetailAST> exprIdents = getAllTokensOfType(sibling, TokenTypes.IDENT);
overlapping = classFrame.containsFieldOrVariableDef(exprIdents, ast);
}
return overlapping;
}
示例15: leaveToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void leaveToken(DetailAST ast) {
Map<String, FinalVariableCandidate> scope = null;
switch (ast.getType()) {
case TokenTypes.OBJBLOCK:
case TokenTypes.CTOR_DEF:
case TokenTypes.METHOD_DEF:
scope = scopeStack.pop().scope;
break;
case TokenTypes.SLIST:
// [email protected][MoveVariableInsideIf] assignment value is modified later so it can't be
// moved
final Deque<DetailAST> prevScopeUninitializedVariableData =
prevScopeUninitializedVariables.peek();
boolean containsBreak = false;
if (ast.getParent().getType() != TokenTypes.CASE_GROUP
|| findLastChildWhichContainsSpecifiedToken(ast.getParent().getParent(),
TokenTypes.CASE_GROUP, TokenTypes.SLIST) == ast.getParent()) {
containsBreak = scopeStack.peek().containsBreak;
scope = scopeStack.pop().scope;
prevScopeUninitializedVariables.pop();
}
final DetailAST parent = ast.getParent();
if (containsBreak || shouldUpdateUninitializedVariables(parent)) {
updateAllUninitializedVariables(prevScopeUninitializedVariableData);
}
updateCurrentScopeAssignedVariables();
break;
default:
// do nothing
}
if (scope != null) {
for (FinalVariableCandidate candidate : scope.values()) {
final DetailAST ident = candidate.variableIdent;
log(ident.getLineNo(), ident.getColumnNo(), MSG_KEY, ident.getText());
}
}
}