本文整理汇总了Java中com.puppycrawl.tools.checkstyle.api.TokenTypes类的典型用法代码示例。如果您正苦于以下问题:Java TokenTypes类的具体用法?Java TokenTypes怎么用?Java TokenTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TokenTypes类属于com.puppycrawl.tools.checkstyle.api包,在下文中一共展示了TokenTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getColumn
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* gets a column number for the tree; if the current SymTabAST node does not have one associated
* with it, traverse its children until a column number is found. Failure results in column
* number value of 0.
*
* @param tree the SymTabAST to process
*
* @return int the resulting line number (0 if none is found)
*/
public static int getColumn(SymTabAST tree) {
SymTabAST indexedNode = tree;
// find a node that actually has line number info
// REDTAG -- a label's ':' is a real token and has (the wrong) column info
// because it is the parent of the ident node that people will want
if (indexedNode.getColumnNo() == 0
|| indexedNode.getType() == TokenTypes.LABELED_STAT) {
indexedNode = (SymTabAST) indexedNode.getFirstChild();
while (indexedNode != null && indexedNode.getColumnNo() == 0) {
indexedNode = (SymTabAST) indexedNode.getNextSibling();
}
if (indexedNode == null) {
// we're screwed
indexedNode = tree;
}
}
return indexedNode.getColumnNo();
}
示例2: getVisibility
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
public int getVisibility() {
int result = DEFAULT_VISIBILITY;
SymTabAST visibilityNode = getVisibilityNode();
if (visibilityNode != null) {
if (visibilityNode.getType() == TokenTypes.LITERAL_PRIVATE) {
result = PRIVATE_VISIBILITY;
}
else if (
visibilityNode.getType() == TokenTypes.LITERAL_PROTECTED) {
result = PROTECTED_VISIBILITY;
}
else if (visibilityNode.getType() == TokenTypes.LITERAL_PUBLIC) {
result = PUBLIC_VISIBILITY;
}
}
return result;
}
示例3: getVisibilityNode
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
private SymTabAST getVisibilityNode() {
SymTabAST result = null;
SymTabAST modifiersNode =
getTreeNode().findFirstToken(TokenTypes.MODIFIERS);
SymTabAST modifier = (SymTabAST) modifiersNode.getFirstChild();
while (modifier != null) {
if (isVisibilityNode(modifier)) {
result = modifier;
break;
}
modifier = (SymTabAST) modifier.getNextSibling();
}
return result;
}
示例4: handleAssert
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* @param block
*/
private void handleAssert(BlockDef block) {
SymTabAST node = block.getTreeNode();
SymTabAST conditional =
(node.findFirstToken(TokenTypes.EXPR));
resolveExpression(conditional, block, null, true);
SymTabAST message = (SymTabAST) conditional.getNextSibling();
while ((message != null) && (message.getType() != TokenTypes.EXPR)) {
message = (SymTabAST) message.getNextSibling();
}
if (message != null) {
resolveExpression(message, block, null, true);
}
}
示例5: handleVariable
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* processes a variable definition and resolves references in it
*
* @param variable the <code>VariableDef</code> to process
*/
protected void handleVariable(VariableDef variable) {
SymTabAST node = variable.getTreeNode();
Scope location = variable.getParentScope();
SymTabAST nameNode = node.findFirstToken(TokenTypes.IDENT);
nameNode.setDefinition(variable, location, true);
SymTabAST typeNode = node.findFirstToken(TokenTypes.TYPE);
resolveType(typeNode, location, null, true);
SymTabAST assignmentNode = node.findFirstToken(TokenTypes.ASSIGN);
if (assignmentNode != null) {
resolveExpression(
(SymTabAST) (assignmentNode.getFirstChild()),
variable.getParentScope(),
null,
true);
}
}
示例6: resolveArrayAccess
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
private IClass resolveArrayAccess(
SymTabAST node,
Scope location,
IClass context,
boolean referencePhase) {
SymTabAST arrayNode = (SymTabAST) (node.getFirstChild());
SymTabAST exprNode = (SymTabAST) (arrayNode.getNextSibling());
//resolve index expressions
while (arrayNode.getType() == TokenTypes.INDEX_OP) {
resolveExpression(exprNode, location, context, referencePhase);
arrayNode = (SymTabAST) (arrayNode.getFirstChild());
exprNode = (SymTabAST) (arrayNode.getNextSibling());
}
ArrayDef array =
(ArrayDef) resolveExpression(arrayNode,
location,
context,
referencePhase);
resolveExpression(exprNode, location, context, referencePhase);
return array.getType();
}
示例7: resolveType
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* resolves and expression of type TokenTypes.TYPE
*
* @param expression the <code>SymTabAST</code> of the expression
* @param location the <code>Scope</code> where the expression occurs
* @param context the <code>Scope</code> in which the expression occurs
* (where the search for a defintion begins)
* @param referencePhase whether or not this is the reference phase of
* table construction
* @return the resulting scope of the expression (the type to which it evaluates)
* @see #resolveDottedName(SymTabAST, Scope, IClass, boolean)
* @see #resolveClassIdent(SymTabAST, Scope, IClass, boolean)
*/
public IClass resolveType(
SymTabAST expr,
Scope location,
IClass context,
boolean referencePhase) {
IClass result = null;
SymTabAST nameNode = (SymTabAST) expr.getFirstChild();
// TODO: Checkstyle change.
// Do not create references from typecast.
// Original transmogrify code is equivalent to
// final boolean createReference = referencePhase;
// which creates non-existant references for variables.
final boolean createReference = false;
if (nameNode.getType() == TokenTypes.DOT) {
result =
resolveDottedName(nameNode, location, context, createReference);
}
else {
result =
resolveClassIdent(nameNode, location, context, createReference);
}
return result;
}
示例8: resolveParameters
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* Resolves the types found in a method call. Any references found
* in the process are created. Returns a <code>MethodSignature</code> for
* the types of the parameters.
*
* @param elist The <code>SymTabAST</code> for the list of parameters
* @return the signature of the parameters
*/
private MethodSignature resolveParameters(
SymTabAST elist,
Scope location,
IClass context,
boolean referencePhase) {
Vector parameters = new Vector();
SymTabAST expr = (SymTabAST) (elist.getFirstChild());
while (expr != null) {
if (expr.getType() != TokenTypes.COMMA) {
IClass parameter =
resolveExpression((SymTabAST) (expr
.getFirstChild()),
location,
context,
referencePhase);
parameters.add(parameter);
}
expr = (SymTabAST) (expr.getNextSibling());
}
return new MethodSignature(parameters);
}
示例9: resolveBooleanExpression
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* Resolves a (binary) boolean expression. The left and right sides of the
* expression
* are resolved in the process.
*
* @param expression the <code>SymTabAST</code> representing the boolean
* expression.
* @return the <code>Scope</code> for the boolean primitive type.
*/
private IClass resolveBooleanExpression(
SymTabAST expression,
Scope location,
IClass context,
boolean referencePhase) {
IClass result = null;
SymTabAST leftChild = findLeftChild(expression);
resolveExpression(leftChild, location, context, referencePhase);
SymTabAST rightChild = findRightSibling(leftChild);
resolveExpression(rightChild, location, context, referencePhase);
result = LiteralResolver.getDefinition(TokenTypes.LITERAL_BOOLEAN);
return result;
}
示例10: resolveInstanceOf
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* resolves references in an instanceof expression
*
* @param expression the <code>SymTabAST</code> of the expression
* @param location the <code>Scope</code> where the expression occurs
* @param context the <code>Scope</code> in which the expression occurs
* (where the search for a defintion begins)
*
* @return the resulting scope of the expression (the type to which it evaluates)
*/
private IClass resolveInstanceOf(
SymTabAST expression,
Scope location,
IClass context,
boolean referencePhase) {
SymTabAST leftNode = (SymTabAST) (expression.getFirstChild());
SymTabAST rightNode = (SymTabAST) (leftNode.getNextSibling());
resolveExpression(leftNode, location, context, referencePhase);
SymTabAST classNameNode = (SymTabAST) (rightNode.getFirstChild());
resolveClass(classNameNode, location, context, referencePhase);
return LiteralResolver.getDefinition(TokenTypes.LITERAL_BOOLEAN);
}
示例11: resolveGoto
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* resolves references in a a break statement
*
* @param expression the <code>SymTabAST</code> for the expression
* @param location the <code>Scope</code> where the expression occurs
* @param context the <code>Scope</code> in which the expression occurs
* (where the search for a defintion begins)
*
* @return the <code>Scope</code> for the int primitive type
*/
private IClass resolveGoto(
SymTabAST expression,
Scope location,
IClass context,
boolean referencePhase) {
SymTabAST label = (SymTabAST) (expression.getFirstChild());
// handle Checkstyle grammar
if (label != null && (label.getType() != TokenTypes.SEMI)) {
LabelDef def = location.getLabelDefinition(label.getText());
if (def != null) {
label.setDefinition(def, location, referencePhase);
}
}
return null;
}
示例12: prefixString
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
public String prefixString(boolean verboseStringConversion) {
StringBuffer b = new StringBuffer();
try {
final String name = TokenTypes.getTokenName(getType());
// if verbose and type name not same as text (keyword probably)
if (verboseStringConversion && !getText().equalsIgnoreCase(name)) {
b.append('[');
b.append(getText());
b.append(",<");
b.append(name);
b.append(">]");
return b.toString();
}
}
catch (Exception ex) {
;
}
return getText();
}
示例13: processAssert
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* @param tree
*/
public void processAssert(SymTabAST tree) {
BlockDef block = makeBlock(tree);
SymTabAST expr = tree.findFirstToken(TokenTypes.EXPR);
SymTabAST message = (SymTabAST)expr.getNextSibling();
while ((message != null) && (message.getType() != TokenTypes.EXPR)) {
message = (SymTabAST) message.getNextSibling();
}
symbolTable.pushScope( block );
walkTree(expr, false);
if (message != null) {
walkTree(message, false);
}
symbolTable.popScope();
}
示例14: createPackage
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* gets the package represented by the tree. The method
* analyzes the tree, constructs an appropriate package name
* and fetches it from the internal package list. If the package does not
* exist it is created.
*
* @param tree <code>SymTabAST</code> to consider
*
* @return <code>PackageDef</code> the resulting package definition
* @see #getPackage(Scope, SymTabAST)
*/
private PackageDef createPackage( SymTabAST tree ) {
PackageDef result = null;
if (tree.getType() == TokenTypes.DOT) {
// find the package result of left child
SymTabAST leftChild = (SymTabAST)tree.getFirstChild();
SymTabAST rightChild = (SymTabAST)leftChild.getNextSibling();
PackageDef context = createPackage(leftChild);
result = getPackage( context, rightChild );
}
else {
result = getPackage(symbolTable.getBaseScope(), tree);
}
return result;
}
示例15: processClass
import com.puppycrawl.tools.checkstyle.api.TokenTypes; //导入依赖的package包/类
/**
* process the given <code>SymTabAST</code> as a class definition
*
* @param tree the <code>SymTabAST</code> to process
* @return <code>void</code>
* @see #makeClass(String, SymTabAST)
* @see #walkSiblings(SymTabAST, boolean)
* @see net.sourceforge.transmogrify.symtab.antlr.SymTabAST
*/
public void processClass(SymTabAST tree) {
String name = tree.findFirstToken(TokenTypes.IDENT).getText();
makeClass(name, tree);
final SymTabAST objblock =
tree.findFirstToken(TokenTypes.OBJBLOCK);
SymTabAST start = (SymTabAST)objblock.getFirstChild();
if (start != null) {
//skip LPAREN
if (start.getType() == TokenTypes.LPAREN) {
start = (SymTabAST)start.getNextSibling();
}
walkSiblings(start, false);
}
symbolTable.popScope();
}