本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.CTOR_DEF属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.CTOR_DEF属性的具体用法?Java TokenTypes.CTOR_DEF怎么用?Java TokenTypes.CTOR_DEF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.CTOR_DEF属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParam
@Test
public void testParam() {
final DetailAST ast = new DetailAST();
final int[] validTypes = {
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
};
for (int type: validTypes) {
ast.setType(type);
assertTrue("Invalid ast type for current tag: " + ast.getType(),
JavadocTagInfo.PARAM.isValidOn(ast));
}
ast.setType(TokenTypes.LAMBDA);
assertFalse("Should return false when ast type is invalid for current tag",
JavadocTagInfo.PARAM.isValidOn(ast));
}
示例2: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final NPathComplexityCheck npathComplexityCheckObj = new NPathComplexityCheck();
final int[] actual = npathComplexityCheckObj.getRequiredTokens();
final int[] expected = {
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.STATIC_INIT,
TokenTypes.INSTANCE_INIT,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.LITERAL_SWITCH,
TokenTypes.CASE_GROUP,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.QUESTION,
TokenTypes.LITERAL_RETURN,
TokenTypes.LITERAL_DEFAULT,
};
Assert.assertNotNull("Required tokens should not be null", actual);
Assert.assertArrayEquals("Invalid required tokens", expected, actual);
}
示例3: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final UnusedImportsCheck testCheckObject =
new UnusedImportsCheck();
final int[] actual = testCheckObject.getRequiredTokens();
final int[] expected = {
TokenTypes.IDENT,
TokenTypes.IMPORT,
TokenTypes.STATIC_IMPORT,
// Definitions that may contain Javadoc...
TokenTypes.PACKAGE_DEF,
TokenTypes.ANNOTATION_DEF,
TokenTypes.ANNOTATION_FIELD_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.VARIABLE_DEF,
};
assertArrayEquals("Default required tokens are invalid", expected, actual);
}
示例4: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.VARIABLE_DEF,
TokenTypes.PARAMETER_DEF,
TokenTypes.ANNOTATION_DEF,
TokenTypes.TYPECAST,
TokenTypes.LITERAL_THROWS,
TokenTypes.IMPLEMENTS_CLAUSE,
TokenTypes.TYPE_ARGUMENT,
TokenTypes.LITERAL_NEW,
TokenTypes.DOT,
TokenTypes.ANNOTATION_FIELD_DEF,
};
}
示例5: testException
@Test
public void testException() {
final DetailAST ast = new DetailAST();
final int[] validTypes = {
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
};
for (int type: validTypes) {
ast.setType(type);
assertTrue("Invalid ast type for current tag: " + ast.getType(),
JavadocTagInfo.EXCEPTION.isValidOn(ast));
}
ast.setType(TokenTypes.LAMBDA);
assertFalse("Should return false when ast type is invalid for current tag",
JavadocTagInfo.EXCEPTION.isValidOn(ast));
}
示例6: hasDefaultOrExplicitNonPrivateCtor
/**
* Checks whether a class has default or explicit non-private constructor.
* @param classDef class ast token.
* @return true if a class has default or explicit non-private constructor.
*/
private static boolean hasDefaultOrExplicitNonPrivateCtor(DetailAST classDef) {
// check if subclassing is prevented by having only private ctors
final DetailAST objBlock = classDef.findFirstToken(TokenTypes.OBJBLOCK);
boolean hasDefaultConstructor = true;
boolean hasExplicitNonPrivateCtor = false;
DetailAST candidate = objBlock.getFirstChild();
while (candidate != null) {
if (candidate.getType() == TokenTypes.CTOR_DEF) {
hasDefaultConstructor = false;
final DetailAST ctorMods =
candidate.findFirstToken(TokenTypes.MODIFIERS);
if (ctorMods.findFirstToken(TokenTypes.LITERAL_PRIVATE) == null) {
hasExplicitNonPrivateCtor = true;
break;
}
}
candidate = candidate.getNextSibling();
}
return hasDefaultConstructor || hasExplicitNonPrivateCtor;
}
示例7: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final UnusedImportsCheck testCheckObject =
new UnusedImportsCheck();
final int[] actual = testCheckObject.getAcceptableTokens();
final int[] expected = {
TokenTypes.IDENT,
TokenTypes.IMPORT,
TokenTypes.STATIC_IMPORT,
// Definitions that may contain Javadoc...
TokenTypes.PACKAGE_DEF,
TokenTypes.ANNOTATION_DEF,
TokenTypes.ANNOTATION_FIELD_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.VARIABLE_DEF,
};
assertArrayEquals("Default acceptable tokens are invalid", expected, actual);
}
示例8: isInCodeBlock
/**
* Returns whether the scope of a node is restricted to a code block.
* A code block is a method or constructor body, an initializer block, or lambda body.
*
* @param node the node to check
* @return a {@code boolean} value
*/
public static boolean isInCodeBlock(DetailAST node) {
boolean returnValue = false;
// Loop up looking for a containing code block
for (DetailAST token = node.getParent();
token != null;
token = token.getParent()) {
final int type = token.getType();
if (type == TokenTypes.METHOD_DEF
|| type == TokenTypes.CTOR_DEF
|| type == TokenTypes.INSTANCE_INIT
|| type == TokenTypes.STATIC_INIT
|| type == TokenTypes.LAMBDA) {
returnValue = true;
break;
}
}
return returnValue;
}
示例9: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.METHOD_CALL,
TokenTypes.CLASS_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_TRY,
TokenTypes.VARIABLE_DEF,
TokenTypes.PARAMETER_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.SLIST,
TokenTypes.ENUM_DEF,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.LITERAL_NEW,
};
}
示例10: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CATCH,
TokenTypes.LITERAL_FINALLY,
TokenTypes.LITERAL_IF,
TokenTypes.LITERAL_ELSE,
TokenTypes.CLASS_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.LITERAL_FOR,
TokenTypes.LITERAL_WHILE,
TokenTypes.LITERAL_DO,
TokenTypes.STATIC_INIT,
TokenTypes.INSTANCE_INIT,
TokenTypes.LAMBDA,
};
}
示例11: hasBody
/**
* 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;
}
示例12: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.IDENT,
TokenTypes.CTOR_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.SLIST,
TokenTypes.OBJBLOCK,
TokenTypes.LITERAL_BREAK,
};
}
示例13: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final MethodParamPadCheck methodParamPadCheckObj = new MethodParamPadCheck();
final int[] actual = methodParamPadCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.CTOR_DEF,
TokenTypes.LITERAL_NEW,
TokenTypes.METHOD_CALL,
TokenTypes.METHOD_DEF,
TokenTypes.SUPER_CTOR_CALL,
TokenTypes.ENUM_CONSTANT_DEF,
};
assertArrayEquals("Default acceptable tokens are invalid", expected, actual);
}
示例14: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.PACKAGE_DEF,
TokenTypes.IMPORT,
TokenTypes.CLASS_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.ANNOTATION_FIELD_DEF,
};
}
示例15: leaveToken
@Override
public void leaveToken(DetailAST ast) {
Map<String, FinalVariableCandidate> scope = null;
switch (ast.getType()) {
case TokenTypes.OBJBLOCK:
case TokenTypes.CTOR_DEF:
case TokenTypes.METHOD_DEF:
scope = scopeStack.pop().scope;
break;
case TokenTypes.SLIST:
// [email protected][MoveVariableInsideIf] assignment value is modified later so it can't be
// moved
final Deque<DetailAST> prevScopeUninitializedVariableData =
prevScopeUninitializedVariables.peek();
boolean containsBreak = false;
if (ast.getParent().getType() != TokenTypes.CASE_GROUP
|| findLastChildWhichContainsSpecifiedToken(ast.getParent().getParent(),
TokenTypes.CASE_GROUP, TokenTypes.SLIST) == ast.getParent()) {
containsBreak = scopeStack.peek().containsBreak;
scope = scopeStack.pop().scope;
prevScopeUninitializedVariables.pop();
}
final DetailAST parent = ast.getParent();
if (containsBreak || shouldUpdateUninitializedVariables(parent)) {
updateAllUninitializedVariables(prevScopeUninitializedVariableData);
}
updateCurrentScopeAssignedVariables();
break;
default:
// do nothing
}
if (scope != null) {
for (FinalVariableCandidate candidate : scope.values()) {
final DetailAST ident = candidate.variableIdent;
log(ident.getLineNo(), ident.getColumnNo(), MSG_KEY, ident.getText());
}
}
}