本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST.getType方法的典型用法代码示例。如果您正苦于以下问题:Java DetailAST.getType方法的具体用法?Java DetailAST.getType怎么用?Java DetailAST.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.DetailAST
的用法示例。
在下文中一共展示了DetailAST.getType方法的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: getImportedTypeCanonicalName
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Gets imported type's
* <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.7">
* canonical name</a>.
* @param importAst {@link TokenTypes#IMPORT Import}
* @return Imported canonical type's name.
*/
private static String getImportedTypeCanonicalName(DetailAST importAst) {
final StringBuilder canonicalNameBuilder = new StringBuilder(256);
DetailAST toVisit = importAst;
while (toVisit != null) {
toVisit = getNextSubTreeNode(toVisit, importAst);
if (toVisit != null && toVisit.getType() == TokenTypes.IDENT) {
canonicalNameBuilder.append(toVisit.getText());
final DetailAST nextSubTreeNode = getNextSubTreeNode(toVisit, importAst);
if (nextSubTreeNode.getType() != TokenTypes.SEMI) {
canonicalNameBuilder.append('.');
}
}
}
return canonicalNameBuilder.toString();
}
示例4: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
final DetailAST parent = ast.getParent();
//we do not want to check colon for cases and defaults
if (ast.getType() != TokenTypes.COLON
|| parent.getType() != TokenTypes.LITERAL_DEFAULT
&& parent.getType() != TokenTypes.LITERAL_CASE) {
final String text = ast.getText();
final int colNo = ast.getColumnNo();
final int lineNo = ast.getLineNo();
final String currentLine = getLine(lineNo - 1);
// Check if rest of line is whitespace, and not just the operator
// by itself. This last bit is to handle the operator on a line by
// itself.
if (option == WrapOption.NL
&& !text.equals(currentLine.trim())
&& CommonUtils.isBlank(currentLine.substring(colNo + text.length()))) {
log(lineNo, colNo, MSG_LINE_NEW, text);
}
else if (option == WrapOption.EOL
&& CommonUtils.hasWhitespaceBefore(colNo - 1, currentLine)) {
log(lineNo, colNo, MSG_LINE_PREVIOUS, text);
}
}
}
示例5: isDocument
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* @see org.jaxen.DefaultNavigator#isDocument(java.lang.Object)
*/
public boolean isDocument(Object aObject)
{
if (aObject instanceof DetailAST) {
final DetailAST node = (DetailAST) aObject;
return (node.getType() == TokenTypes.EOF);
}
else {
return false;
}
}
示例6: hasBody
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Determines whether an AST is a method definition with a body, or is
* a constructor definition.
* @param aAST the AST to check.
* @return if AST has a body.
*/
private boolean hasBody(DetailAST aAST)
{
if (aAST.getType() == TokenTypes.METHOD_DEF) {
return aAST.branchContains(TokenTypes.SLIST);
}
else if (aAST.getType() == TokenTypes.CTOR_DEF) {
return true;
}
return false;
}
示例7: isLocal
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks if a given method is local, i.e. either static or private.
* @param aAST method def for check
* @return true if a given method is iether static or private.
*/
private boolean isLocal(DetailAST aAST)
{
if (aAST.getType() == TokenTypes.METHOD_DEF) {
final DetailAST modifiers =
aAST.findFirstToken(TokenTypes.MODIFIERS);
return (modifiers == null)
|| modifiers.branchContains(TokenTypes.LITERAL_STATIC)
|| modifiers.branchContains(TokenTypes.LITERAL_PRIVATE);
}
return true;
}
示例8: testGetValueAtDetailNode
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Test
public void testGetValueAtDetailNode() {
final DetailAST commentContentNode = tree.getFirstChild().getNextSibling().getFirstChild();
Assert.assertNotNull("Comment node cannot be null", commentContentNode);
final int nodeType = commentContentNode.getType();
Assert.assertTrue("Comment node should be a comment type",
TokenUtils.isCommentType(nodeType));
Assert.assertEquals("This should be a javadoc comment",
"/*", commentContentNode.getParent().getText());
final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS);
final Object child = parseTree.getChild(commentContentNode, 0);
Assert.assertFalse("Child has not to be leaf", parseTree.isLeaf(child));
Assert.assertTrue("Child has to be leaf", parseTree.isLeaf(tree.getFirstChild()));
final Object treeModel = parseTree.getValueAt(child, 0);
final String type = (String) parseTree.getValueAt(child, 1);
final int line = (Integer) parseTree.getValueAt(child, 2);
final int column = (Integer) parseTree.getValueAt(child, 3);
final String text = (String) parseTree.getValueAt(child, 4);
final String expectedText = "JAVADOC";
Assert.assertNull("Tree model must be null", treeModel);
Assert.assertEquals("Invalid type", "JAVADOC", type);
Assert.assertEquals("Invalid line", 1, line);
Assert.assertEquals("Invalid column", 3, column);
Assert.assertEquals("Invalid text", expectedText, text);
try {
parseTree.getValueAt(child, parseTree.getColumnCount());
Assert.fail("IllegalStateException expected");
}
catch (IllegalStateException ex) {
Assert.assertEquals("Invalid error message", "Unknown column", ex.getMessage());
}
}
示例9: checkAnnotationIndentation
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks line wrapping into annotations.
*
* @param atNode at-clause node.
* @param firstNodesOnLines map which contains
* first nodes as values and line numbers as keys.
* @param indentLevel line wrapping indentation.
*/
private void checkAnnotationIndentation(DetailAST atNode,
NavigableMap<Integer, DetailAST> firstNodesOnLines, int indentLevel) {
final int firstNodeIndent = getLineStart(atNode);
final int currentIndent = firstNodeIndent + indentLevel;
final Collection<DetailAST> values = firstNodesOnLines.values();
final DetailAST lastAnnotationNode = atNode.getParent().getLastChild();
final int lastAnnotationLine = lastAnnotationNode.getLineNo();
final Iterator<DetailAST> itr = values.iterator();
while (firstNodesOnLines.size() > 1) {
final DetailAST node = itr.next();
final DetailAST parentNode = node.getParent();
final boolean isCurrentNodeCloseAnnotationAloneInLine =
node.getLineNo() == lastAnnotationLine
&& isEndOfScope(lastAnnotationNode, node);
if (isCurrentNodeCloseAnnotationAloneInLine
|| node.getType() == TokenTypes.AT
&& (parentNode.getParent().getType() == TokenTypes.MODIFIERS
|| parentNode.getParent().getType() == TokenTypes.ANNOTATIONS)
|| node.getLineNo() == atNode.getLineNo()) {
logWarningMessage(node, firstNodeIndent);
}
else {
logWarningMessage(node, currentIndent);
}
itr.remove();
}
}
示例10: findFirstUpperNamedBlock
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Find the Class, Constructor, Enum, Method, or Field in which it is defined.
* @param ast Variable for which we want to find the scope in which it is defined
* @return ast The Class or Constructor or Method in which it is defined.
*/
private static DetailAST findFirstUpperNamedBlock(DetailAST ast) {
DetailAST astTraverse = ast;
while (astTraverse.getType() != TokenTypes.METHOD_DEF
&& astTraverse.getType() != TokenTypes.CLASS_DEF
&& astTraverse.getType() != TokenTypes.ENUM_DEF
&& astTraverse.getType() != TokenTypes.CTOR_DEF
&& !ScopeUtils.isClassFieldDef(astTraverse)) {
astTraverse = astTraverse.getParent();
}
return astTraverse;
}
示例11: checkOverloadMethodsGrouping
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks that if overload methods are grouped together they should not be
* separated from each other.
* @param objectBlock
* is a class, interface or enum object block.
*/
private void checkOverloadMethodsGrouping(DetailAST objectBlock) {
final int allowedDistance = 1;
DetailAST currentToken = objectBlock.getFirstChild();
final Map<String, Integer> methodIndexMap = new HashMap<String, Integer>();
final Map<String, Integer> methodLineNumberMap = new HashMap<String, Integer>();
int currentIndex = 0;
while (currentToken != null) {
if (currentToken.getType() == TokenTypes.METHOD_DEF) {
currentIndex++;
final String methodName =
currentToken.findFirstToken(TokenTypes.IDENT).getText();
if (methodIndexMap.containsKey(methodName)) {
final int previousIndex = methodIndexMap.get(methodName);
if (currentIndex - previousIndex > allowedDistance) {
final int previousLineWithOverloadMethod =
methodLineNumberMap.get(methodName);
log(currentToken.getLineNo(), MSG_KEY,
previousLineWithOverloadMethod);
}
}
methodIndexMap.put(methodName, currentIndex);
methodLineNumberMap.put(methodName, currentToken.getLineNo());
}
currentToken = currentToken.getNextSibling();
}
}
示例12: leaveToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void leaveToken(DetailAST ast) {
if (ast.getType() == TokenTypes.CLASS_DEF
|| ast.getType() == TokenTypes.ENUM_DEF
|| ast.getType() == TokenTypes.ENUM_CONSTANT_DEF) {
//pop
frame = frame.getParent();
}
}
示例13: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
final int currentType = ast.getType();
if (!isNotRelevantSituation(ast, currentType)) {
final String line = getLine(ast.getLineNo() - 1);
final int before = ast.getColumnNo() - 1;
final int after = ast.getColumnNo() + ast.getText().length();
if (before >= 0) {
final char prevChar = line.charAt(before);
if (shouldCheckSeparationFromPreviousToken(ast)
&& !Character.isWhitespace(prevChar)) {
log(ast.getLineNo(), ast.getColumnNo(),
MSG_WS_NOT_PRECEDED, ast.getText());
}
}
if (after < line.length()) {
final char nextChar = line.charAt(after);
if (shouldCheckSeparationFromNextToken(ast, nextChar)
&& !Character.isWhitespace(nextChar)) {
log(ast.getLineNo(), ast.getColumnNo() + ast.getText().length(),
MSG_WS_NOT_FOLLOWED, ast.getText());
}
}
}
}
示例14: isStarImport
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks if current import is star import. E.g.:
* <p>
* {@code
* import java.util.*;
* }
* </p>
* @param importAst {@link TokenTypes#IMPORT Import}
* @return true if it is star import
*/
private static boolean isStarImport(DetailAST importAst) {
boolean result = false;
DetailAST toVisit = importAst;
while (toVisit != null) {
toVisit = getNextSubTreeNode(toVisit, importAst);
if (toVisit != null && toVisit.getType() == TokenTypes.STAR) {
result = true;
break;
}
}
return result;
}
示例15: getNearestClassOrEnumDefinition
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Returns CLASS_DEF or ENUM_DEF token which is the nearest to the given ast node.
* Searches the tree towards the root until it finds a CLASS_DEF or ENUM_DEF node.
* @param ast the start node for searching.
* @return the CLASS_DEF or ENUM_DEF token.
*/
private static DetailAST getNearestClassOrEnumDefinition(DetailAST ast) {
DetailAST searchAST = ast;
while (searchAST.getType() != TokenTypes.CLASS_DEF
&& searchAST.getType() != TokenTypes.ENUM_DEF) {
searchAST = searchAST.getParent();
}
return searchAST;
}