本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.CLASS_DEF属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.CLASS_DEF属性的具体用法?Java TokenTypes.CLASS_DEF怎么用?Java TokenTypes.CLASS_DEF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.CLASS_DEF属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSuperclass
/**
*
* If the class has a super class a reference to this super class
* is added to this class.
* @return <code>void</code>
* @see net.sourceforge.transmogrify.symtab.ClassDef
*/
private void setSuperclass() {
if (_def.getTreeNode().getType() == TokenTypes.CLASS_DEF) {
SymTabAST extendsNode = getExtendsNode(_def);
if ( extendsNode != null ) {
String superclassName = ASTUtil.constructDottedName(extendsNode);
IClass superclass = _def.getClassDefinition(superclassName);
if ( superclass != null ) {
_def.setSuperclass( superclass );
superclass.addSubclass( _def );
}
}
else {
_def.setSuperclass(new ExternalClass(Object.class));
}
}
else {
_def.setSuperclass(new ExternalClass(Object.class));
}
}
示例2: addInterfaces
/**
*
* If the class implements an interface a reference to this interface
* is added to this class.
* @return <code>void</code>
* @see net.sourceforge.transmogrify.symtab.ClassDef
*/
private void addInterfaces() {
SymTabAST implementsClause = null;
if (_def.getTreeNode().getType() == TokenTypes.CLASS_DEF) {
implementsClause
= _node.findFirstToken(TokenTypes.IMPLEMENTS_CLAUSE);
}
else {
implementsClause
= _node.findFirstToken(TokenTypes.EXTENDS_CLAUSE);
}
if ( implementsClause != null ) {
SymTabAST interfaceNode = (SymTabAST)implementsClause.getFirstChild();
while ( interfaceNode != null ) {
IClass implemented =
_def.getClassDefinition(interfaceNode.getText());
if ( implemented != null ) {
_def.addInterface( implemented );
implemented.addImplementor( _def );
}
interfaceNode = (SymTabAST)(interfaceNode.getNextSibling());
}
}
}
示例3: testGetAcceptableTokens
@Test
public void testGetAcceptableTokens() {
final ClassFanOutComplexityCheck classFanOutComplexityCheckObj =
new ClassFanOutComplexityCheck();
final int[] actual = classFanOutComplexityCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.PACKAGE_DEF,
TokenTypes.IMPORT,
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.TYPE,
TokenTypes.LITERAL_NEW,
TokenTypes.LITERAL_THROWS,
TokenTypes.ANNOTATION_DEF,
};
Assert.assertNotNull("Acceptable tokens should not be null", actual);
Assert.assertArrayEquals("Invalid acceptable tokens", expected, actual);
}
示例4: testAcceptThrowsIllegalStateExceptionAsFileNotFound
@Test
public void testAcceptThrowsIllegalStateExceptionAsFileNotFound() {
final LocalizedMessage message = new LocalizedMessage(1, 1, 1, TokenTypes.CLASS_DEF,
"messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final String fileName = "nonexisting_file";
final AuditEvent auditEvent = new AuditEvent(this, fileName, message);
final SuppressWithPlainTextCommentFilter filter = new SuppressWithPlainTextCommentFilter();
try {
filter.accept(auditEvent);
fail(IllegalStateException.class.getSimpleName() + " is expected");
}
catch (IllegalStateException ex) {
assertEquals("Invalid exception message",
"Cannot read source file: " + fileName, ex.getMessage());
final Throwable cause = ex.getCause();
assertTrue("Exception cause has invalid type",
cause instanceof FileNotFoundException);
assertEquals("Invalid exception message",
fileName + " (No such file or directory)", cause.getMessage());
}
}
开发者ID:rnveach,项目名称:checkstyle-backport-jre6,代码行数:24,代码来源:SuppressWithPlainTextCommentFilterTest.java
示例5: 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,
};
}
示例6: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final OuterTypeNumberCheck checkObj = new OuterTypeNumberCheck();
final int[] expected = {
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.ANNOTATION_DEF,
};
assertArrayEquals("Default required tokens are invalid",
expected, checkObj.getRequiredTokens());
}
示例7: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.CLASS_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.ENUM_CONSTANT_DEF,
};
}
示例8: testDeprecated
@Test
public void testDeprecated() throws Exception {
final DetailAST ast = new DetailAST();
final DetailAST astParent = new DetailAST();
astParent.setType(TokenTypes.LITERAL_CATCH);
final Method setParent = ast.getClass().getDeclaredMethod("setParent", DetailAST.class);
setParent.setAccessible(true);
setParent.invoke(ast, astParent);
final int[] validTypes = {
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.ANNOTATION_DEF,
TokenTypes.METHOD_DEF,
TokenTypes.CTOR_DEF,
TokenTypes.ENUM_CONSTANT_DEF,
TokenTypes.ANNOTATION_FIELD_DEF,
TokenTypes.VARIABLE_DEF,
};
for (int type: validTypes) {
ast.setType(type);
assertTrue("Invalid ast type for current tag: " + ast.getType(),
JavadocTagInfo.DEPRECATED.isValidOn(ast));
}
astParent.setType(TokenTypes.SLIST);
ast.setType(TokenTypes.VARIABLE_DEF);
assertFalse("Should return false when ast type is invalid for current tag",
JavadocTagInfo.DEPRECATED.isValidOn(ast));
ast.setType(TokenTypes.PARAMETER_DEF);
assertFalse("Should return false when ast type is invalid for current tag",
JavadocTagInfo.DEPRECATED.isValidOn(ast));
}
示例9: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.CLASS_DEF,
TokenTypes.INTERFACE_DEF,
TokenTypes.ENUM_DEF,
TokenTypes.ANNOTATION_DEF,
};
}
示例10: visitToken
@Override
public void visitToken(DetailAST ast) {
switch (ast.getType()) {
case TokenTypes.CLASS_DEF:
visitClassDef(ast);
break;
case TokenTypes.VARIABLE_DEF:
visitVariableDef(ast);
break;
default:
throw new IllegalStateException(ast.toString());
}
}
示例11: testGetRequiredTokens
@Test
public void testGetRequiredTokens() {
final AbstractClassNameCheck classNameCheckObj = new AbstractClassNameCheck();
final int[] actual = classNameCheckObj.getRequiredTokens();
final int[] expected = {
TokenTypes.CLASS_DEF,
};
Assert.assertArrayEquals("Invalid required tokens", expected, actual);
}
示例12: getRequiredTokens
@Override
public int[] getRequiredTokens() {
return new int[] {
TokenTypes.METHOD_DEF,
TokenTypes.CLASS_DEF,
TokenTypes.PACKAGE_DEF,
};
}
示例13: visitToken
@Override
public void visitToken(DetailAST ast) {
final DetailAST modifiers = ast.findFirstToken(TokenTypes.MODIFIERS);
switch (ast.getType()) {
case TokenTypes.PACKAGE_DEF:
packageName = extractQualifiedName(ast);
break;
case TokenTypes.CLASS_DEF:
registerNestedSubclassToOuterSuperClasses(ast);
final boolean isFinal = modifiers.findFirstToken(TokenTypes.FINAL) != null;
final boolean isAbstract = modifiers.findFirstToken(TokenTypes.ABSTRACT) != null;
final String qualifiedClassName = getQualifiedClassName(ast);
classes.push(new ClassDesc(qualifiedClassName, isFinal, isAbstract));
break;
case TokenTypes.CTOR_DEF:
if (!ScopeUtils.isInEnumBlock(ast)) {
final ClassDesc desc = classes.peek();
if (modifiers.findFirstToken(TokenTypes.LITERAL_PRIVATE) == null) {
desc.registerNonPrivateCtor();
}
else {
desc.registerPrivateCtor();
}
}
break;
default:
throw new IllegalStateException(ast.toString());
}
}
示例14: applyTo
/** @see com.puppycrawl.tools.checkstyle.checks.usage.AbstractUsageCheck */
public void applyTo(Set aNodes)
{
// apply the check to each private field
final Set methods = new HashSet();
final Iterator it = aNodes.iterator();
while (it.hasNext()) {
methods.clear();
final DetailAST nameAST = (DetailAST) it.next();
// find methods using the field
final Iterator refIt = getReferences(nameAST);
while (refIt.hasNext()) {
final Reference ref = (Reference) refIt.next();
final SymTabAST refNode = ref.getTreeNode();
final DetailAST refDetail = refNode.getDetailNode();
// don't need to check a self-reference
if (refDetail == nameAST) {
continue;
}
DetailAST parent = refDetail.getParent();
while (parent != null) {
final int type = parent.getType();
if ((type == TokenTypes.METHOD_DEF)
|| (type == TokenTypes.CTOR_DEF)
|| (type == TokenTypes.INSTANCE_INIT)
|| (type == TokenTypes.STATIC_INIT))
{
methods.add(parent);
break;
}
// initializer for inner class?
else if (type == TokenTypes.CLASS_DEF) {
break;
}
parent = parent.getParent();
}
}
if (methods.size() == 1) {
log(
nameAST.getLineNo(),
nameAST.getColumnNo(),
getErrorKey(),
nameAST.getText());
}
}
}
示例15: getAcceptableTokens
@Override
public int[] getAcceptableTokens() {
return new int[] {TokenTypes.CLASS_DEF};
}