本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST类的典型用法代码示例。如果您正苦于以下问题:Java DetailAST类的具体用法?Java DetailAST怎么用?Java DetailAST使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DetailAST类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了DetailAST类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getParentAxisIterator
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/**
* Get a (single-member) iterator over this node's parent.
*
* @param aObject the context node for the parent axis.
* @return A possibly-empty iterator (not null).
*/
public Iterator getParentAxisIterator(Object aObject)
{
if (isAttribute(aObject)) {
return new SingleObjectIterator(((Attribute) aObject).getParent());
}
else {
DetailAST parent = ((DetailAST) aObject).getParent();
if (parent != null) {
return new SingleObjectIterator(parent);
}
else {
return EMPTY_ITERATOR;
}
}
}
示例2: 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;
}
示例3: finishTree
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void finishTree(DetailAST aAST)
{
if (aAST == null) {
// we have nothing to check
return;
}
try {
final Set nodes = getASTManager().getCheckNodes(this);
if (nodes != null) {
applyTo(nodes);
}
}
catch (SymbolTableException ste) {
logError(ste);
}
getASTManager().removeCheck(this);
}
示例4: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
final String line = getLine(ast.getLineNo() - 1);
final int before = ast.getColumnNo() - 1;
if ((before == -1 || Character.isWhitespace(line.charAt(before)))
&& !isInEmptyForInitializerOrCondition(ast)) {
boolean flag = !allowLineBreaks;
// verify all characters before '.' are whitespace
for (int i = 0; !flag && i <= before - 1; i++) {
if (!Character.isWhitespace(line.charAt(i))) {
flag = true;
break;
}
}
if (flag) {
log(ast.getLineNo(), before, MSG_KEY, ast.getText());
}
}
}
示例5: shouldCheck
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/**
* 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 Scope customScope;
if (ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
customScope = Scope.PUBLIC;
}
else {
final DetailAST mods = ast.findFirstToken(TokenTypes.MODIFIERS);
customScope = ScopeUtils.getScopeFromMods(mods);
}
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));
}
示例6: leaveToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
@Override
public void leaveToken(DetailAST ast) {
final int astType = ast.getType();
if (astType != TokenTypes.VARIABLE_DEF
&& astType != TokenTypes.PARAMETER_DEF
&& astType != TokenTypes.METHOD_CALL
&& astType != TokenTypes.SLIST
&& astType != TokenTypes.LITERAL_NEW
|| astType == TokenTypes.LITERAL_NEW
&& ast.findFirstToken(TokenTypes.OBJBLOCK) != null) {
currentFrame = currentFrame.getParent();
}
else if (astType == TokenTypes.SLIST) {
leaveSlist(ast);
}
}
示例7: 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);
}
示例8: createSlCommentNode
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/**
* Create single-line comment from token.
* @param token
* Token object.
* @return DetailAST with SINGLE_LINE_COMMENT type.
*/
private static DetailAST createSlCommentNode(Token token) {
final DetailAST slComment = new DetailAST();
slComment.setType(TokenTypes.SINGLE_LINE_COMMENT);
slComment.setText("//");
// column counting begins from 0
slComment.setColumnNo(token.getColumn() - 1);
slComment.setLineNo(token.getLine());
final DetailAST slCommentContent = new DetailAST();
slCommentContent.setType(TokenTypes.COMMENT_CONTENT);
// column counting begins from 0
// plus length of '//'
slCommentContent.setColumnNo(token.getColumn() - 1 + 2);
slCommentContent.setLineNo(token.getLine());
slCommentContent.setText(token.getText());
slComment.addChild(slCommentContent);
return slComment;
}
示例9: shouldRemoveFinalVariableCandidate
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/**
* Whether the final variable candidate should be removed from the list of final local variable
* candidates.
* @param scopeData the scope data of the variable.
* @param ast the variable ast.
* @return true, if the variable should be removed.
*/
private static boolean shouldRemoveFinalVariableCandidate(ScopeData scopeData, DetailAST ast) {
boolean shouldRemove = true;
for (DetailAST variable : scopeData.uninitializedVariables) {
if (variable.getText().equals(ast.getText())) {
// if the variable is declared outside the loop and initialized inside
// the loop, then it cannot be declared final, as it can be initialized
// more than once in this case
if (isInTheSameLoop(variable, ast) || !isUseOfExternalVariableInsideLoop(ast)) {
final FinalVariableCandidate candidate = scopeData.scope.get(ast.getText());
shouldRemove = candidate.alreadyAssigned;
}
scopeData.uninitializedVariables.remove(variable);
break;
}
}
return shouldRemove;
}
示例10: isNotRelevantSituation
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/**
* Is ast not a target of Check.
* @param ast ast
* @param currentType type of ast
* @return true is ok to skip validation
*/
private boolean isNotRelevantSituation(DetailAST ast, int currentType) {
final int parentType = ast.getParent().getType();
final boolean starImport = currentType == TokenTypes.STAR
&& parentType == TokenTypes.DOT;
final boolean slistInsideCaseGroup = currentType == TokenTypes.SLIST
&& parentType == TokenTypes.CASE_GROUP;
final boolean starImportOrSlistInsideCaseGroup = starImport || slistInsideCaseGroup;
final boolean colonOfCaseOrDefaultOrForEach =
isColonOfCaseOrDefault(currentType, parentType)
|| isColonOfForEach(currentType, parentType);
final boolean emptyBlockOrType =
isEmptyBlock(ast, parentType)
|| allowEmptyTypes && isEmptyType(ast);
return starImportOrSlistInsideCaseGroup
|| colonOfCaseOrDefaultOrForEach
|| emptyBlockOrType
|| isArrayInitialization(currentType, parentType);
}
示例11: testContainsAnnotation
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
@Test
public void testContainsAnnotation() {
final DetailAST astForTest = new DetailAST();
astForTest.setType(TokenTypes.PACKAGE_DEF);
final DetailAST child = new DetailAST();
final DetailAST annotations = new DetailAST();
final DetailAST annotation = new DetailAST();
final DetailAST annotationNameHolder = new DetailAST();
final DetailAST annotationName = new DetailAST();
annotations.setType(TokenTypes.ANNOTATIONS);
annotation.setType(TokenTypes.ANNOTATION);
annotationNameHolder.setType(TokenTypes.AT);
annotationName.setText("Annotation");
annotationNameHolder.setNextSibling(annotationName);
annotation.setFirstChild(annotationNameHolder);
annotations.setFirstChild(annotation);
child.setNextSibling(annotations);
astForTest.setFirstChild(child);
assertTrue("Annotation should contain " + astForTest,
AnnotationUtility.containsAnnotation(astForTest, "Annotation"));
}
示例12: checkTrailingComma
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/**
* Checks to see if the trailing comma is present if required or
* prohibited.
*
* @param annotation the annotation token
*/
private void checkTrailingComma(final DetailAST annotation) {
if (trailingArrayComma != TrailingArrayComma.IGNORE) {
DetailAST child = annotation.getFirstChild();
while (child != null) {
DetailAST arrayInit = null;
if (child.getType() == TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR) {
arrayInit = child.findFirstToken(TokenTypes.ANNOTATION_ARRAY_INIT);
}
else if (child.getType() == TokenTypes.ANNOTATION_ARRAY_INIT) {
arrayInit = child;
}
if (arrayInit != null) {
logCommaViolation(arrayInit);
}
child = child.getNextSibling();
}
}
}
示例13: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
// LITERAL_IF has the following four or five children:
// '('
// condition
// ')'
// thenStatement
// [ LITERAL_ELSE (with the elseStatement as a child) ]
// don't bother if this is not if then else
final AST elseLiteral =
ast.findFirstToken(TokenTypes.LITERAL_ELSE);
if (elseLiteral != null) {
final AST elseStatement = elseLiteral.getFirstChild();
// skip '(' and ')'
final AST condition = ast.getFirstChild().getNextSibling();
final AST thenStatement = condition.getNextSibling().getNextSibling();
if (canReturnOnlyBooleanLiteral(thenStatement)
&& canReturnOnlyBooleanLiteral(elseStatement)) {
log(ast.getLineNo(), ast.getColumnNo(), MSG_KEY);
}
}
}
示例14: getFilteredMessages
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/**
* Returns filtered set of {@link LocalizedMessage}.
* @param fileName path to the file
* @param fileContents the contents of the file
* @param rootAST root AST element {@link DetailAST} of the file
* @return filtered set of messages
*/
private SortedSet<LocalizedMessage> getFilteredMessages(
String fileName, FileContents fileContents, DetailAST rootAST) {
final SortedSet<LocalizedMessage> result = new TreeSet<LocalizedMessage>(messages);
for (LocalizedMessage element : messages) {
final TreeWalkerAuditEvent event =
new TreeWalkerAuditEvent(fileContents, fileName, element, rootAST);
for (TreeWalkerFilter filter : filters) {
if (!filter.accept(event)) {
result.remove(element);
break;
}
}
}
return result;
}
示例15: checkRightParen
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入依赖的package包/类
/**
* Check the indentation of the right parenthesis.
* @param rparen parenthesis to check
* @param lparen left parenthesis associated with aRparen
*/
protected final void checkRightParen(DetailAST lparen, DetailAST rparen) {
if (rparen != null) {
// the rcurly can either be at the correct indentation,
// or not first on the line
final int rparenLevel = expandedTabsColumnNo(rparen);
// or has <lparen level> + 1 indentation
final int lparenLevel = expandedTabsColumnNo(lparen);
if (rparenLevel != lparenLevel + 1
&& !getIndent().isAcceptable(rparenLevel)
&& isOnStartOfLine(rparen)) {
logError(rparen, "rparen", rparenLevel);
}
}
}