本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.MODIFIERS属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.MODIFIERS属性的具体用法?Java TokenTypes.MODIFIERS怎么用?Java TokenTypes.MODIFIERS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.MODIFIERS属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitToken
@Override
public void visitToken(DetailAST ast) {
final DetailAST defaultGroupAST = ast.getParent();
//default keywords used in annotations too - not what we're
//interested in
if (defaultGroupAST.getType() != TokenTypes.ANNOTATION_FIELD_DEF
&& defaultGroupAST.getType() != TokenTypes.MODIFIERS) {
if (skipIfLastAndSharedWithCase) {
if (Objects.nonNull(findNextSibling(ast, TokenTypes.LITERAL_CASE))) {
log(ast, MSG_KEY_SKIP_IF_LAST_AND_SHARED_WITH_CASE);
}
else if (ast.getPreviousSibling() == null
&& Objects.nonNull(findNextSibling(defaultGroupAST,
TokenTypes.CASE_GROUP))) {
log(ast, MSG_KEY);
}
}
else if (Objects.nonNull(findNextSibling(defaultGroupAST,
TokenTypes.CASE_GROUP))) {
log(ast, MSG_KEY);
}
}
}
示例2: getAccessModifierFromModifiersToken
/**
* Returns {@link AccessModifier} based on the information about access modifier
* taken from the given token of type {@link TokenTypes#MODIFIERS}.
* @param modifiersToken token of type {@link TokenTypes#MODIFIERS}.
* @return {@link AccessModifier}.
*/
public static AccessModifier getAccessModifierFromModifiersToken(DetailAST modifiersToken) {
if (modifiersToken == null || modifiersToken.getType() != TokenTypes.MODIFIERS) {
throw new IllegalArgumentException("expected non-null AST-token with type 'MODIFIERS'");
}
// default access modifier
AccessModifier accessModifier = AccessModifier.PACKAGE;
for (AST token = modifiersToken.getFirstChild(); token != null;
token = token.getNextSibling()) {
final int tokenType = token.getType();
if (tokenType == TokenTypes.LITERAL_PUBLIC) {
accessModifier = AccessModifier.PUBLIC;
}
else if (tokenType == TokenTypes.LITERAL_PROTECTED) {
accessModifier = AccessModifier.PROTECTED;
}
else if (tokenType == TokenTypes.LITERAL_PRIVATE) {
accessModifier = AccessModifier.PRIVATE;
}
}
return accessModifier;
}
示例3: testGetDefaultTokens
@Test
public void testGetDefaultTokens() {
final ModifierOrderCheck modifierOrderCheckObj = new ModifierOrderCheck();
final int[] actual = modifierOrderCheckObj.getDefaultTokens();
final int[] expected = {TokenTypes.MODIFIERS};
final int[] unexpectedArray = {
TokenTypes.MODIFIERS,
TokenTypes.OBJBLOCK,
};
assertArrayEquals("Default tokens are invalid", expected, actual);
final int[] unexpectedEmptyArray = CommonUtils.EMPTY_INT_ARRAY;
Assert.assertNotSame("Default tokens should not be empty array",
unexpectedEmptyArray, actual);
Assert.assertNotSame("Invalid default tokens", unexpectedArray, actual);
Assert.assertNotNull("Default tokens should not be null", actual);
}
示例4: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final ModifierOrderCheck modifierOrderCheckObj = new ModifierOrderCheck();
final int[] actual = modifierOrderCheckObj.getAcceptableTokens();
final int[] expected = {TokenTypes.MODIFIERS};
final int[] unexpectedArray = {
TokenTypes.MODIFIERS,
TokenTypes.OBJBLOCK,
};
assertArrayEquals("Default acceptable tokens are invalid", expected, actual);
final int[] unexpectedEmptyArray = CommonUtils.EMPTY_INT_ARRAY;
Assert.assertNotSame("Default tokens should not be empty array",
unexpectedEmptyArray, actual);
Assert.assertNotSame("Invalid acceptable tokens", unexpectedArray, actual);
Assert.assertNotNull("Acceptable tokens should not be null", actual);
}
示例5: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.MODIFIERS,
TokenTypes.OBJBLOCK,
TokenTypes.VARIABLE_DEF,
};
}
示例6: visitToken
@Override
public void visitToken(DetailAST ast) {
final int parentType = ast.getParent().getType();
switch (ast.getType()) {
case TokenTypes.OBJBLOCK:
scopeStates.push(new ScopeState());
break;
case TokenTypes.MODIFIERS:
if (parentType == TokenTypes.VARIABLE_DEF
&& ast.getParent().getParent().getType() == TokenTypes.OBJBLOCK) {
processModifiers(ast);
}
break;
case TokenTypes.CTOR_DEF:
if (parentType == TokenTypes.OBJBLOCK) {
processConstructor(ast);
}
break;
case TokenTypes.METHOD_DEF:
if (parentType == TokenTypes.OBJBLOCK) {
final ScopeState state = scopeStates.peek();
// nothing can be bigger than method's state
state.currentScopeState = STATE_METHOD_DEF;
}
break;
case TokenTypes.VARIABLE_DEF:
if (ScopeUtils.isClassFieldDef(ast)) {
final DetailAST fieldDef = ast.findFirstToken(TokenTypes.IDENT);
classFieldNames.add(fieldDef.getText());
}
break;
default:
break;
}
}
示例7: checkAnnotationIndentation
/**
* 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();
}
}
示例8: getAnnotationTarget
/**
* Get target of annotation.
* @param ast the AST node to get the child of
* @return get target of annotation
*/
private static DetailAST getAnnotationTarget(DetailAST ast) {
final DetailAST targetAST;
final DetailAST parentAST = ast.getParent();
switch (parentAST.getType()) {
case TokenTypes.MODIFIERS:
case TokenTypes.ANNOTATIONS:
targetAST = getAcceptableParent(parentAST);
break;
default:
// unexpected container type
throw new IllegalArgumentException("Unexpected container AST: " + parentAST);
}
return targetAST;
}
示例9: getParentType
/**
* 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;
}
示例10: isOnTokenWithModifiers
/**
* Checks that block comment is on specified token with modifiers.
* @param blockComment block comment start DetailAST
* @param tokenType parent token type
* @return true if block comment is on specified token with modifiers
*/
private static boolean isOnTokenWithModifiers(DetailAST blockComment, int tokenType) {
return blockComment.getParent() != null
&& blockComment.getParent().getType() == TokenTypes.MODIFIERS
&& blockComment.getParent().getParent().getType() == tokenType
&& getPrevSiblingSkipComments(blockComment) == null;
}
示例11: isOnTokenWithAnnotation
/**
* Checks that block comment is on specified token with annotation.
* @param blockComment block comment start DetailAST
* @param tokenType parent token type
* @return true if block comment is on specified token with annotation
*/
private static boolean isOnTokenWithAnnotation(DetailAST blockComment, int tokenType) {
return blockComment.getParent() != null
&& blockComment.getParent().getType() == TokenTypes.ANNOTATION
&& getPrevSiblingSkipComments(blockComment.getParent()) == null
&& blockComment.getParent().getParent().getType() == TokenTypes.MODIFIERS
&& blockComment.getParent().getParent().getParent().getType() == tokenType
&& getPrevSiblingSkipComments(blockComment) == null;
}
示例12: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final ModifierOrderCheck checkObj = new ModifierOrderCheck();
final int[] expected = {TokenTypes.MODIFIERS};
assertArrayEquals("Default required tokens are invalid",
expected, checkObj.getRequiredTokens());
}
示例13: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {TokenTypes.MODIFIERS};
}
示例14: isMethodModifier
/**
* Checks if given synchronized is modifier of method.
* @param ast synchronized(TokenTypes.LITERAL_SYNCHRONIZED) to check
* @return true if synchronized only modifies method
*/
private static boolean isMethodModifier(DetailAST ast) {
return ast.getParent().getType() == TokenTypes.MODIFIERS;
}