本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST.getFirstChild方法的典型用法代码示例。如果您正苦于以下问题:Java DetailAST.getFirstChild方法的具体用法?Java DetailAST.getFirstChild怎么用?Java DetailAST.getFirstChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.DetailAST
的用法示例。
在下文中一共展示了DetailAST.getFirstChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFirstNode
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Finds sub-node for given node minimal (line, column) pair.
* @param node the root of tree for search.
* @return sub-node with minimal (line, column) pair.
*/
public static DetailAST getFirstNode(final DetailAST node) {
DetailAST currentNode = node;
DetailAST child = node.getFirstChild();
while (child != null) {
final DetailAST newNode = getFirstNode(child);
if (newNode.getLineNo() < currentNode.getLineNo()
|| newNode.getLineNo() == currentNode.getLineNo()
&& newNode.getColumnNo() < currentNode.getColumnNo()) {
currentNode = newNode;
}
child = child.getNextSibling();
}
return currentNode;
}
示例2: getChildAtDetailAst
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Gets child of DetailAST node at specified index.
* @param parent DetailAST node
* @param index child index
* @return child DetailsAST or DetailNode if child is Javadoc node
* and parseMode is JAVA_WITH_JAVADOC_AND_COMMENTS.
*/
private Object getChildAtDetailAst(DetailAST parent, int index) {
final Object result;
if (parseMode == ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS
&& parent.getType() == TokenTypes.COMMENT_CONTENT
&& JavadocUtils.isJavadocComment(parent.getParent())) {
result = getJavadocTree(parent.getParent());
}
else {
int currentIndex = 0;
DetailAST child = parent.getFirstChild();
while (currentIndex < index) {
child = child.getNextSibling();
currentIndex++;
}
result = child;
}
return result;
}
示例3: getAllExceptionTypes
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Finds all exception types in current catch.
* We need it till we can have few different exception types into one catch.
* @param parentToken - parent node for types (TYPE or BOR)
* @return list, that contains all exception types in current catch
*/
private static List<DetailAST> getAllExceptionTypes(DetailAST parentToken) {
DetailAST currentNode = parentToken.getFirstChild();
final List<DetailAST> exceptionTypes = new LinkedList<DetailAST>();
if (currentNode.getType() == TokenTypes.BOR) {
exceptionTypes.addAll(getAllExceptionTypes(currentNode));
currentNode = currentNode.getNextSibling();
if (currentNode != null) {
exceptionTypes.add(currentNode);
}
}
else {
exceptionTypes.add(currentNode);
currentNode = currentNode.getNextSibling();
while (currentNode != null) {
exceptionTypes.add(currentNode);
currentNode = currentNode.getNextSibling();
}
}
return exceptionTypes;
}
示例4: getStringExpr
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Returns the literal string expression represented by an AST.
* @param ast an AST node for an EXPR
* @return the Java string represented by the given AST expression
* or empty string if expression is too complex
* @throws IllegalArgumentException if the AST is invalid
*/
private static String getStringExpr(DetailAST ast) {
final DetailAST firstChild = ast.getFirstChild();
String expr = "";
switch (firstChild.getType()) {
case TokenTypes.STRING_LITERAL:
// NOTE: escaped characters are not unescaped
final String quotedText = firstChild.getText();
expr = quotedText.substring(1, quotedText.length() - 1);
break;
case TokenTypes.IDENT:
expr = firstChild.getText();
break;
case TokenTypes.DOT:
expr = firstChild.getLastChild().getText();
break;
default:
// annotations with complex expressions cannot suppress warnings
}
return expr;
}
示例5: isSingleLineCase
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks if current case statement is single-line statement, e.g.:
* <p>
* {@code
* case 1: doSomeStuff(); break;
* case 2: doSomeStuff(); break;
* case 3: ;
* }
* </p>
* @param literalCase {@link TokenTypes#LITERAL_CASE case statement}.
* @return true if current case statement is single-line statement.
*/
private static boolean isSingleLineCase(DetailAST literalCase) {
boolean result = false;
final DetailAST slist = literalCase.getNextSibling();
if (slist == null) {
result = true;
}
else {
final DetailAST block = slist.getFirstChild();
if (block.getType() != TokenTypes.SLIST) {
final DetailAST caseBreak = slist.findFirstToken(TokenTypes.LITERAL_BREAK);
if (caseBreak != null) {
final boolean atOneLine = literalCase.getLineNo() == block.getLineNo();
result = atOneLine && block.getLineNo() == caseBreak.getLineNo();
}
}
}
return result;
}
示例6: isChainedMethodCallWrapped
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* If this is the first chained method call which was moved to the next line.
* @return true if chained class are wrapped
*/
private boolean isChainedMethodCallWrapped() {
boolean result = false;
final DetailAST main = getMainAst();
final DetailAST dot = main.getFirstChild();
final DetailAST target = dot.getFirstChild();
final DetailAST dot1 = target.getFirstChild();
final DetailAST target1 = dot1.getFirstChild();
if (dot1.getType() == TokenTypes.DOT
&& target1.getType() == TokenTypes.METHOD_CALL) {
result = true;
}
return result;
}
示例7: getAllTokensOfType
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Collects all tokens of specific type starting with the current ast node.
* @param ast ast node.
* @param tokenType token type.
* @return a set of all tokens of specific type starting with the current ast node.
*/
private static Set<DetailAST> getAllTokensOfType(DetailAST ast, int tokenType) {
DetailAST vertex = ast;
final Set<DetailAST> result = new HashSet<DetailAST>();
final Deque<DetailAST> stack = new ArrayDeque<DetailAST>();
while (vertex != null || !stack.isEmpty()) {
if (!stack.isEmpty()) {
vertex = stack.pop();
}
while (vertex != null) {
if (vertex.getType() == tokenType && !vertex.equals(ast)) {
result.add(vertex);
}
if (vertex.getNextSibling() != null) {
stack.push(vertex.getNextSibling());
}
vertex = vertex.getFirstChild();
}
}
return result;
}
示例8: containsAllSafeTokens
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Looks for all "safe" Token combinations in the argument
* expression branch.
* @param expr the argument expression
* @return - true if any child matches the set of tokens, false if not
*/
private static boolean containsAllSafeTokens(final DetailAST expr) {
DetailAST arg = expr.getFirstChild();
arg = skipVariableAssign(arg);
boolean argIsNotNull = false;
if (arg.getType() == TokenTypes.PLUS) {
DetailAST child = arg.getFirstChild();
while (child != null
&& !argIsNotNull) {
argIsNotNull = child.getType() == TokenTypes.STRING_LITERAL
|| child.getType() == TokenTypes.IDENT;
child = child.getNextSibling();
}
}
return argIsNotNull
|| !arg.branchContains(TokenTypes.IDENT)
&& !arg.branchContains(TokenTypes.LITERAL_NULL);
}
示例9: beginTree
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void beginTree(DetailAST rootAST) {
frames = new HashMap<DetailAST, AbstractFrame>();
current.clear();
final Deque<AbstractFrame> frameStack = new LinkedList<AbstractFrame>();
DetailAST curNode = rootAST;
while (curNode != null) {
collectDeclarations(frameStack, curNode);
DetailAST toVisit = curNode.getFirstChild();
while (curNode != null && toVisit == null) {
endCollectingDeclarations(frameStack, curNode);
toVisit = curNode.getNextSibling();
if (toVisit == null) {
curNode = curNode.getParent();
}
}
curNode = toVisit;
}
}
示例10: testCreationOfFakeCommentBlock
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testCreationOfFakeCommentBlock() {
final DetailAST testCommentBlock =
CommonUtils.createBlockCommentNode("test_comment");
assertEquals("Invalid token type",
TokenTypes.BLOCK_COMMENT_BEGIN, testCommentBlock.getType());
assertEquals("Invalid text", "/*", testCommentBlock.getText());
assertEquals("Invalid line number", 0, testCommentBlock.getLineNo());
final DetailAST contentCommentBlock = testCommentBlock.getFirstChild();
assertEquals("Invalid token type",
TokenTypes.COMMENT_CONTENT, contentCommentBlock.getType());
assertEquals("Invalid text", "*test_comment", contentCommentBlock.getText());
assertEquals("Invalid line number", 0, contentCommentBlock.getLineNo());
assertEquals("Invalid column number", -1, contentCommentBlock.getColumnNo());
final DetailAST endCommentBlock = contentCommentBlock.getNextSibling();
assertEquals("Invalid token type", TokenTypes.BLOCK_COMMENT_END, endCommentBlock.getType());
assertEquals("Invalid text", "*/", endCommentBlock.getText());
}
示例11: getNextToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Get the token to start counting the number of lines to add to the distance aim from.
* @param checkedStatement the checked statement.
* @return the token to start counting the number of lines to add to the distance aim from.
*/
private DetailAST getNextToken(DetailAST checkedStatement) {
DetailAST nextToken;
if (checkedStatement.getType() == TokenTypes.SLIST
|| checkedStatement.getType() == TokenTypes.ARRAY_INIT
|| checkedStatement.getType() == TokenTypes.CASE_GROUP) {
nextToken = checkedStatement.getFirstChild();
}
else {
nextToken = checkedStatement.getNextSibling();
}
if (nextToken != null && isComment(nextToken) && isTrailingComment(nextToken)) {
nextToken = nextToken.getNextSibling();
}
return nextToken;
}
示例12: isEqualsMethod
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Determines if an AST is a valid Equals method implementation.
*
* @param ast the AST to check
* @return true if the {code ast} is a Equals method.
*/
public static Boolean isEqualsMethod(DetailAST ast) {
DetailAST modifiers = ast.getFirstChild();
DetailAST parameters = ast.findFirstToken(TokenTypes.PARAMETERS);
return CheckUtils.isEqualsMethod(ast)
&& modifiers.branchContains(TokenTypes.LITERAL_PUBLIC)
&& isObjectParam(parameters.getFirstChild())
&& (ast.branchContains(TokenTypes.SLIST)
|| modifiers.branchContains(TokenTypes.LITERAL_NATIVE));
}
示例13: getTypeLastNode
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Searches parameter node for a type node.
* Returns it or its last node if it has an extended structure.
* @param ast
* , subject node.
* @return type node.
*/
private static DetailAST getTypeLastNode(DetailAST ast) {
DetailAST result = ast.findFirstToken(TokenTypes.TYPE_ARGUMENTS);
if (result == null) {
result = getIdentLastToken(ast);
if (result == null) {
//primitive literal expected
result = ast.getFirstChild();
}
}
else {
result = result.findFirstToken(TokenTypes.GENERIC_END);
}
return result;
}
示例14: calculateDistanceInSingleScope
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Calculates distance between declaration of variable and its first usage
* in single scope.
* @param semicolonAst
* Regular node of Ast which is checked for content of checking
* variable.
* @param variableIdentAst
* Variable which distance is calculated for.
* @return entry which contains expression with variable usage and distance.
*/
private static Entry<DetailAST, Integer> calculateDistanceInSingleScope(
DetailAST semicolonAst, DetailAST variableIdentAst) {
int dist = 0;
boolean firstUsageFound = false;
DetailAST currentAst = semicolonAst;
DetailAST variableUsageAst = null;
while (!firstUsageFound && currentAst != null
&& currentAst.getType() != TokenTypes.RCURLY) {
if (currentAst.getFirstChild() != null) {
if (isChild(currentAst, variableIdentAst)) {
dist = getDistToVariableUsageInChildNode(currentAst, variableIdentAst, dist);
variableUsageAst = currentAst;
firstUsageFound = true;
}
else if (currentAst.getType() != TokenTypes.VARIABLE_DEF) {
dist++;
}
}
currentAst = currentAst.getNextSibling();
}
// If variable wasn't used after its declaration, distance is 0.
if (!firstUsageFound) {
dist = 0;
}
return new SimpleEntry<DetailAST, Integer>(variableUsageAst, dist);
}
示例15: processAbstractMethodParameters
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Process validation of parameters for Methods with no definition.
* @param ast method AST
*/
private void processAbstractMethodParameters(DetailAST ast) {
final DetailAST parameters = ast.findFirstToken(TokenTypes.PARAMETERS);
for (DetailAST child = parameters.getFirstChild(); child != null; child = child
.getNextSibling()) {
if (child.getType() == TokenTypes.PARAMETER_DEF) {
checkForRedundantModifier(child, TokenTypes.FINAL);
}
}
}