本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes.LITERAL_VOID属性的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes.LITERAL_VOID属性的具体用法?Java TokenTypes.LITERAL_VOID怎么用?Java TokenTypes.LITERAL_VOID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.puppycrawl.tools.checkstyle.api.TokenTypes
的用法示例。
在下文中一共展示了TokenTypes.LITERAL_VOID属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAnnotationOnType
/**
* Checks whether annotation on type takes place.
* @param modifier modifier token.
* @return true if annotation on type takes place.
*/
private static boolean isAnnotationOnType(DetailAST modifier) {
boolean annotationOnType = false;
final DetailAST modifiers = modifier.getParent();
final DetailAST definition = modifiers.getParent();
final int definitionType = definition.getType();
if (definitionType == TokenTypes.VARIABLE_DEF
|| definitionType == TokenTypes.PARAMETER_DEF
|| definitionType == TokenTypes.CTOR_DEF) {
annotationOnType = true;
}
else if (definitionType == TokenTypes.METHOD_DEF) {
final DetailAST typeToken = definition.findFirstToken(TokenTypes.TYPE);
final int methodReturnType = typeToken.getLastChild().getType();
if (methodReturnType != TokenTypes.LITERAL_VOID) {
annotationOnType = true;
}
}
return annotationOnType;
}
示例2: isWriteObject
/**
* Checks if a given method is writeObject().
* @param aAST method def to check
* @return true if this is a writeObject() definition
*/
private boolean isWriteObject(DetailAST aAST)
{
// name is writeObject...
final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
if (!"writeObject".equals(ident.getText())) {
return false;
}
// returns void...
final DetailAST typeAST =
(DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
if (typeAST.getType() != TokenTypes.LITERAL_VOID) {
return false;
}
// should have one parameter...
final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
if (params == null || params.getChildCount() != 1) {
return false;
}
// and paramter's type should be java.io.ObjectOutputStream
final DetailAST type =
(DetailAST) ((DetailAST) params.getFirstChild())
.findFirstToken(TokenTypes.TYPE).getFirstChild();
final String typeName = FullIdent.createFullIdent(type).getText();
if (!"java.io.ObjectOutputStream".equals(typeName)
&& !"ObjectOutputStream".equals(typeName))
{
return false;
}
// and, finally, it should throws java.io.IOException
final DetailAST throwsAST =
aAST.findFirstToken(TokenTypes.LITERAL_THROWS);
if (throwsAST == null || throwsAST.getChildCount() != 1) {
return false;
}
final DetailAST expt = (DetailAST) throwsAST.getFirstChild();
final String exceptionName = FullIdent.createFullIdent(expt).getText();
if (!"java.io.IOException".equals(exceptionName)
&& !"IOException".equals(exceptionName))
{
return false;
}
return true;
}
示例3: isReadObject
/**
* Checks if a given method is readObject().
* @param aAST method def to check
* @return true if this is a readObject() definition
*/
private boolean isReadObject(DetailAST aAST)
{
// name is readObject...
final DetailAST ident = aAST.findFirstToken(TokenTypes.IDENT);
if (!"readObject".equals(ident.getText())) {
return false;
}
// returns void...
final DetailAST typeAST =
(DetailAST) aAST.findFirstToken(TokenTypes.TYPE).getFirstChild();
if (typeAST.getType() != TokenTypes.LITERAL_VOID) {
return false;
}
// should have one parameter...
final DetailAST params = aAST.findFirstToken(TokenTypes.PARAMETERS);
if (params == null || params.getChildCount() != 1) {
return false;
}
// and paramter's type should be java.io.ObjectInputStream
final DetailAST type =
(DetailAST) ((DetailAST) params.getFirstChild())
.findFirstToken(TokenTypes.TYPE).getFirstChild();
final String typeName = FullIdent.createFullIdent(type).getText();
if (!"java.io.ObjectInputStream".equals(typeName)
&& !"ObjectInputStream".equals(typeName))
{
return false;
}
// and, finally, it should throws java.io.IOException
// and java.lang.ClassNotFoundException
final DetailAST throwsAST =
aAST.findFirstToken(TokenTypes.LITERAL_THROWS);
if (throwsAST == null || throwsAST.getChildCount() != 3) {
return false;
}
final DetailAST excpt1 = (DetailAST) throwsAST.getFirstChild();
final String exception1 = FullIdent.createFullIdent(excpt1).getText();
final String exception2 =
FullIdent.createFullIdent(throwsAST.getLastChild()).getText();
if (!"java.io.IOException".equals(exception1)
&& !"IOException".equals(exception1)
&& !"java.io.IOException".equals(exception2)
&& !"IOException".equals(exception2)
|| !"java.lang.ClassNotFoundException".equals(exception1)
&& !"ClassNotFoundException".equals(exception1)
&& !"java.lang.ClassNotFoundException".equals(exception2)
&& !"ClassNotFoundException".equals(exception2))
{
return false;
}
return true;
}
示例4: checkType
/**
* Checks that return type is {@code void}.
* @param method the METHOD_DEF node
* @return true if check passed, false otherwise
*/
private static boolean checkType(DetailAST method) {
final DetailAST type =
method.findFirstToken(TokenTypes.TYPE).getFirstChild();
return type.getType() == TokenTypes.LITERAL_VOID;
}