本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.DetailAST.findFirstToken方法的典型用法代码示例。如果您正苦于以下问题:Java DetailAST.findFirstToken方法的具体用法?Java DetailAST.findFirstToken怎么用?Java DetailAST.findFirstToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.puppycrawl.tools.checkstyle.api.DetailAST
的用法示例。
在下文中一共展示了DetailAST.findFirstToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
}
}
示例3: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
final DetailAST slistAST = ast.findFirstToken(TokenTypes.SLIST);
boolean isElseIf = false;
if (ast.getType() == TokenTypes.LITERAL_ELSE
&& ast.findFirstToken(TokenTypes.LITERAL_IF) != null) {
isElseIf = true;
}
final boolean isDefaultInAnnotation = isDefaultInAnnotation(ast);
final boolean skipStatement = isSkipStatement(ast);
final boolean skipEmptyLoopBody = allowEmptyLoopBody && isEmptyLoopBody(ast);
if (slistAST == null && !isElseIf && !isDefaultInAnnotation
&& !skipStatement && !skipEmptyLoopBody) {
log(ast.getLineNo(), MSG_KEY_NEED_BRACES, ast.getText());
}
}
示例4: isSkipCase
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks for cases that should be skipped: no assignment, local variable, final variables.
* @param ast Variable def AST
* @return true is that is a case that need to be skipped.
*/
private static boolean isSkipCase(DetailAST ast) {
boolean skipCase = true;
// do not check local variables and
// fields declared in interface/annotations
if (!ScopeUtils.isLocalVariableDef(ast)
&& !ScopeUtils.isInInterfaceOrAnnotationBlock(ast)) {
final DetailAST assign = ast.findFirstToken(TokenTypes.ASSIGN);
if (assign != null) {
final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
skipCase = modifiers.findFirstToken(TokenTypes.FINAL) != null;
}
}
return skipCase;
}
示例5: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
public void visitToken(DetailAST ast) {
if (!isSkipCase(ast)) {
final DetailAST assign = ast.findFirstToken(TokenTypes.ASSIGN);
final DetailAST exprStart =
assign.getFirstChild().getFirstChild();
final DetailAST type = ast.findFirstToken(TokenTypes.TYPE);
if (isObjectType(type)
&& exprStart.getType() == TokenTypes.LITERAL_NULL) {
final DetailAST ident = ast.findFirstToken(TokenTypes.IDENT);
log(ident, MSG_KEY, ident.getText(), "null");
}
if (!onlyObjectReferences) {
validateNonObjects(ast);
}
}
}
示例6: mustCheckName
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
protected final boolean mustCheckName(DetailAST ast) {
boolean returnValue = false;
final DetailAST modifiersAST =
ast.findFirstToken(TokenTypes.MODIFIERS);
final boolean isStatic = modifiersAST.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
final boolean isFinal = modifiersAST.findFirstToken(TokenTypes.FINAL) != null;
if (isStatic && isFinal && shouldCheckInScope(modifiersAST)
|| ScopeUtils.isInAnnotationBlock(ast)
|| ScopeUtils.isInInterfaceOrAnnotationBlock(ast)
&& !ScopeUtils.isInCodeBlock(ast)) {
// Handle the serialVersionUID and serialPersistentFields constants
// which are used for Serialization. Cannot enforce rules on it. :-)
final DetailAST nameAST = ast.findFirstToken(TokenTypes.IDENT);
if (!"serialVersionUID".equals(nameAST.getText())
&& !"serialPersistentFields".equals(nameAST.getText())) {
returnValue = true;
}
}
return returnValue;
}
示例7: mustCheckReferenceCount
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public boolean mustCheckReferenceCount(DetailAST aAST)
{
final DetailAST mods = aAST.findFirstToken(TokenTypes.MODIFIERS);
return ((mods != null)
&& (ScopeUtils.getScopeFromMods(mods) == Scope.PRIVATE));
}
示例8: 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;
}
示例9: visitToken
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.api.Check */
public void visitToken(DetailAST aAST)
{
if (mustCheckReferenceCount(aAST)) {
final DetailAST nameAST = aAST.findFirstToken(TokenTypes.IDENT);
Pattern regexp = getRegexp();
if ((regexp == null)
|| !regexp.matcher(nameAST.getText()).find())
{
getASTManager().registerCheckNode(this, nameAST);
}
}
}
示例10: mustCheckReferenceCount
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public boolean mustCheckReferenceCount(DetailAST aAST)
{
final DetailAST mods = aAST.findFirstToken(TokenTypes.MODIFIERS);
if ((mods == null)
|| (ScopeUtils.getScopeFromMods(mods) != Scope.PRIVATE))
{
return false;
}
return !mAllowSerializationMethods
|| !(isWriteObject(aAST) || isReadObject(aAST)
|| isWriteReplaceOrReadResolve(aAST));
}
示例11: visitResourceSpecification
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks parens in {@link TokenTypes#RESOURCE_SPECIFICATION}.
* @param ast the token to check.
*/
private void visitResourceSpecification(DetailAST ast) {
processLeft(ast.findFirstToken(TokenTypes.LPAREN));
final DetailAST rparen = ast.findFirstToken(TokenTypes.RPAREN);
if (!hasPrecedingSemiColon(rparen)) {
processRight(rparen);
}
}
示例12: skipAnnotationOnlyLines
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Skip lines that only contain {@code TokenTypes.ANNOTATION}s.
* If the received {@code DetailAST}
* has annotations within its modifiers then first token on the line
* of the first token after all annotations is return. This might be
* an annotation.
* Otherwise, the received {@code DetailAST} is returned.
* @param ast {@code DetailAST}.
* @return {@code DetailAST}.
*/
private static DetailAST skipAnnotationOnlyLines(DetailAST ast) {
DetailAST resultNode = ast;
final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
if (modifiers != null) {
final DetailAST lastAnnotation = findLastAnnotation(modifiers);
if (lastAnnotation != null) {
final DetailAST tokenAfterLast;
if (lastAnnotation.getNextSibling() == null) {
tokenAfterLast = modifiers.getNextSibling();
}
else {
tokenAfterLast = lastAnnotation.getNextSibling();
}
if (tokenAfterLast.getLineNo() > lastAnnotation.getLineNo()) {
resultNode = tokenAfterLast;
}
else {
resultNode = getFirstAnnotationOnSameLine(lastAnnotation);
}
}
}
return resultNode;
}
示例13: raiseCounter
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* 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);
}
示例14: mustCheckName
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
@Override
protected final boolean mustCheckName(DetailAST ast) {
final DetailAST modifiersAST =
ast.findFirstToken(TokenTypes.MODIFIERS);
final boolean isStatic = modifiersAST.findFirstToken(TokenTypes.LITERAL_STATIC) != null;
final boolean isFinal = modifiersAST.findFirstToken(TokenTypes.FINAL) != null;
return isStatic
&& !isFinal
&& shouldCheckInScope(modifiersAST)
&& !ScopeUtils.isInInterfaceOrAnnotationBlock(ast);
}
示例15: checkCompactNoArrayStyle
import com.puppycrawl.tools.checkstyle.api.DetailAST; //导入方法依赖的package包/类
/**
* Checks for compact no array style type violations.
*
* @param annotation the annotation token
*/
private void checkCompactNoArrayStyle(final DetailAST annotation) {
final DetailAST arrayInit =
annotation.findFirstToken(TokenTypes.ANNOTATION_ARRAY_INIT);
final int valuePairCount =
annotation.getChildCount(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
//in compact style with one value
if (arrayInit != null
&& arrayInit.getChildCount(TokenTypes.EXPR) == 1) {
log(annotation.getLineNo(), MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.COMPACT_NO_ARRAY);
}
//in expanded style with one value and the correct element name
else if (valuePairCount == 1) {
final DetailAST valuePair =
annotation.findFirstToken(TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR);
final DetailAST nestedArrayInit =
valuePair.findFirstToken(TokenTypes.ANNOTATION_ARRAY_INIT);
if (nestedArrayInit != null
&& ANNOTATION_ELEMENT_SINGLE_NAME.equals(
valuePair.getFirstChild().getText())
&& nestedArrayInit.getChildCount(TokenTypes.EXPR) == 1) {
log(annotation.getLineNo(), MSG_KEY_ANNOTATION_INCORRECT_STYLE,
ElementStyle.COMPACT_NO_ARRAY);
}
}
}