本文整理汇总了Java中com.sun.source.tree.Tree.Kind方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.Kind方法的具体用法?Java Tree.Kind怎么用?Java Tree.Kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.tree.Tree
的用法示例。
在下文中一共展示了Tree.Kind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findBinaryParent
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
/**
* Checks that the same type cast removal is not suggested in the left operand
* of a binary op: both casts cannot be removed, otherwise the operation
* could change semantic.
* @param path
* @param useless
* @return
*/
private static TreePath findBinaryParent(TreePath path) {
O: while (path != null) {
Tree l = path.getLeaf();
Tree.Kind k = l.getKind();
if (k.asInterface().isAssignableFrom(StatementTree.class)) {
return null;
}
switch (k) {
case PLUS: case MINUS: case MULTIPLY: case DIVIDE: case REMAINDER:
case CONDITIONAL_EXPRESSION:
break O;
case PARENTHESIZED:
break;
default:
return null;
}
path = path.getParentPath();
}
return path;
}
示例2: visitMemberSelect
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
@Override
public Object visitMemberSelect(MemberSelectTree node, Object p) {
if (wc.getTrees().getElement(new TreePath(getCurrentPath(), node.getExpression())) != varElement) {
return super.visitMemberSelect(node, p);
}
Element target = wc.getTrees().getElement(getCurrentPath());
if (target != null && target.getKind() == ElementKind.METHOD) {
Tree x = getCurrentPath().getParentPath().getLeaf();
Tree.Kind k = x.getKind();
if (k == Tree.Kind.METHOD_INVOCATION) {
if (node.getIdentifier().contentEquals("toString")) { // NOI18N
// rewrite the node to just the variable, which is going to change the type
gu.copyComments(x, node.getExpression(), true);
gu.copyComments(x, node.getExpression(), false);
wc.rewrite(x, node.getExpression());
}
}
}
return super.visitMemberSelect(node, p);
}
示例3: getSuitableOperator
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private Tree.Kind getSuitableOperator(Tree.Kind kind) {
if (Tree.Kind.AND_ASSIGNMENT == kind) {
return Tree.Kind.AND;
}
if (Tree.Kind.OR_ASSIGNMENT == kind) {
return Tree.Kind.OR;
}
if (Tree.Kind.PLUS_ASSIGNMENT == kind) {
return Tree.Kind.PLUS;
}
if (Tree.Kind.MINUS_ASSIGNMENT == kind) {
return Tree.Kind.MINUS;
}
if (Tree.Kind.DIVIDE_ASSIGNMENT == kind) {
return Tree.Kind.DIVIDE;
}
if (Tree.Kind.MULTIPLY_ASSIGNMENT == kind) {
return Tree.Kind.MULTIPLY;
}
if (Tree.Kind.REMAINDER_ASSIGNMENT == kind) {
return Tree.Kind.REMAINDER;
}
if (Tree.Kind.LEFT_SHIFT_ASSIGNMENT == kind) {
return Tree.Kind.LEFT_SHIFT;
}
if (Tree.Kind.RIGHT_SHIFT_ASSIGNMENT == kind) {
return Tree.Kind.RIGHT_SHIFT;
}
if (Tree.Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT == kind) {
return Tree.Kind.UNSIGNED_RIGHT_SHIFT;
}
return null;
}
示例4: isBreakable
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private static boolean isBreakable(TreePath path) {
Tree tree = path.getLeaf();
switch (tree.getKind()) {
case BLOCK:
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
case COMPILATION_UNIT:
case IMPORT:
case MODIFIERS:
case EMPTY_STATEMENT:
return false;
}
while (path != null) {
tree = path.getLeaf();
Tree.Kind kind = tree.getKind();
if (kind == Tree.Kind.IMPORT) return false;
if (kind == Tree.Kind.VARIABLE) {
VariableTree varTree = (VariableTree)tree;
if (varTree.getInitializer() == null) {
return false;
}
}
path = path.getParentPath();
}
return true;
}
示例5: getTemplateContexts
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private void getTemplateContexts(CodeTemplate template, EnumSet<Tree.Kind> treeKindContexts, HashSet<String> stringContexts) {
List<String> contexts = template.getContexts();
if (contexts != null) {
for(String context : contexts) {
try {
treeKindContexts.add(Tree.Kind.valueOf(context));
} catch (IllegalArgumentException iae) {
stringContexts.add(context);
}
}
}
}
示例6: visitBlock
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
@Override public Object visitBlock(BlockTree node, Object p) {
Tree parent = getCurrentPath().getParentPath().getLeaf();
Tree.Kind k = parent.getKind();
if (k == Tree.Kind.CLASS || k == Tree.Kind.INTERFACE || k == Tree.Kind.ENUM) {
member = node;
return super.visitBlock(node, p);
}
return p;
}
示例7: isNumericLiteral
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private boolean isNumericLiteral(Tree currentTree) {
Tree.Kind kind = currentTree.getKind();
return kind == Tree.Kind.INT_LITERAL
|| kind == Tree.Kind.CHAR_LITERAL
|| kind == Tree.Kind.DOUBLE_LITERAL
|| kind == Tree.Kind.FLOAT_LITERAL
|| kind == Tree.Kind.LONG_LITERAL;
}
示例8: isEvil
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private boolean isEvil(Tree tree) {
Tree.Kind kind = tree.getKind();
switch (kind) {
case COMPILATION_UNIT:
CompilationUnitTree cut = (CompilationUnitTree) tree;
return cut.getPackageName() == null;
// case MODIFIERS:
case PRIMITIVE_TYPE:
return true;
default: return false;
}
}
示例9: run
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
/**
*/
public void run(CompilationController controller) throws IOException {
controller.toPhase(Phase.RESOLVED); //cursor position needed
if (cancelled) {
return;
}
TreePath treePath = controller.getTreeUtilities()
.pathFor(caretPosition);
if (treePath != null) {
if (cancelled) {
return;
}
TreePath parent = treePath.getParentPath();
while (parent != null) {
Tree.Kind parentKind = parent.getLeaf().getKind();
if ((TreeUtilities.CLASS_TREE_KINDS.contains(parentKind))
|| (parentKind == Tree.Kind.COMPILATION_UNIT)) {
break;
}
treePath = parent;
parent = treePath.getParentPath();
}
}
if (treePath != null) {
if (cancelled) {
return;
}
try {
element = controller.getTrees().getElement(treePath);
} catch (IllegalArgumentException ex) {
Logger.getLogger("global").log(Level.WARNING, null, ex);
}
}
}
示例10: makeSimpleExplicitReducer
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private ExpressionTree makeSimpleExplicitReducer(Tree.Kind opKind, VariableTree var, VariableTree var1) {
Tree lambdaBody;
ExpressionTree lambda;
lambdaBody = this.treeMaker.Binary(this.getSuitableOperator(opKind), this.treeMaker.Identifier("accumulator"), this.treeMaker.Identifier(UNKNOWN_NAME));
lambda = treeMaker.LambdaExpression(Arrays.asList(var, var1), lambdaBody);
return lambda;
}
示例11: getPathElementOfKind
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
public static TreePath getPathElementOfKind(Set<Tree.Kind> kinds, TreePath path) {
while (path != null) {
if (kinds.contains(path.getLeaf().getKind())) {
return path;
}
path = path.getParentPath();
}
return null;
}
示例12: getPathElementOfKind
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
public static TreePath getPathElementOfKind(Tree.Kind kind, TreePath path) {
return getPathElementOfKind(EnumSet.of(kind), path);
}
示例13: operatorToString
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
private static String operatorToString(Tree.Kind kind) {
switch (kind) {
case AND:
return "&"; // NOI18N
case AND_ASSIGNMENT:
return "&="; // NOI18N
case CONDITIONAL_AND:
return "&&"; // NOI18N
case CONDITIONAL_OR:
return "||"; // NOI18N
case LEFT_SHIFT:
return "<<"; // NOI18N
case LEFT_SHIFT_ASSIGNMENT:
return "<<="; // NOI18N
case LOGICAL_COMPLEMENT:
return "!"; // NOI18N
case MINUS:
return "-"; // NOI18N
case MINUS_ASSIGNMENT:
return "-="; // NOI18N
case MULTIPLY:
return "*"; // NOI18N
case MULTIPLY_ASSIGNMENT:
return "*="; // NOI18N
case OR:
return "|"; // NOI18N
case OR_ASSIGNMENT:
return "|="; // NOI18N
case PLUS:
return "+"; // NOI18N
case PLUS_ASSIGNMENT:
return "+="; // NOI18N
case PREFIX_DECREMENT:
return "--"; // NOI18N
case PREFIX_INCREMENT:
return "++"; // NOI18N
case REMAINDER:
return "%"; // NOI18N
case REMAINDER_ASSIGNMENT:
return "%="; // NOI18N
case RIGHT_SHIFT:
return ">>"; // NOI18N
case RIGHT_SHIFT_ASSIGNMENT:
return ">>="; // NOI18N
case UNARY_MINUS:
return "-"; // NOI18N
case UNARY_PLUS:
return "+"; // NOI18N
case UNSIGNED_RIGHT_SHIFT:
return ">>>"; // NOI18N
case UNSIGNED_RIGHT_SHIFT_ASSIGNMENT:
return ">>>="; // NOI18N
case XOR:
return "^"; // NOI18N
case XOR_ASSIGNMENT:
return "^="; // NOI18N
default:
return kind.toString();
}
}
示例14: getTreeKinds
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
public Set<Tree.Kind> getTreeKinds() {
return treeKinds;
}
示例15: okToReadBeforeInitialized
import com.sun.source.tree.Tree; //导入方法依赖的package包/类
/**
* @param path tree path to read operation
* @return true if it is permissible to perform this read before the field has been initialized,
* false otherwise
*/
private boolean okToReadBeforeInitialized(TreePath path) {
TreePath parentPath = path.getParentPath();
Tree leaf = path.getLeaf();
Tree parent = parentPath.getLeaf();
if (parent instanceof AssignmentTree) {
// ok if it's actually a write
AssignmentTree assignment = (AssignmentTree) parent;
return assignment.getVariable().equals(leaf);
} else if (parent instanceof BinaryTree) {
// ok if we're comparing to null
BinaryTree binaryTree = (BinaryTree) parent;
Tree.Kind kind = binaryTree.getKind();
if (kind.equals(Tree.Kind.EQUAL_TO) || kind.equals(Tree.Kind.NOT_EQUAL_TO)) {
ExpressionTree left = binaryTree.getLeftOperand();
ExpressionTree right = binaryTree.getRightOperand();
return (left.equals(leaf) && right.getKind().equals(Tree.Kind.NULL_LITERAL))
|| (right.equals(leaf) && left.getKind().equals(Tree.Kind.NULL_LITERAL));
}
} else if (parent instanceof MethodInvocationTree) {
// ok if it's invoking castToNonNull and the read is the argument
MethodInvocationTree methodInvoke = (MethodInvocationTree) parent;
Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(methodInvoke);
String qualifiedName =
ASTHelpers.enclosingClass(methodSymbol) + "." + methodSymbol.getSimpleName().toString();
if (qualifiedName.equals(config.getCastToNonNullMethod())) {
List<? extends ExpressionTree> arguments = methodInvoke.getArguments();
return arguments.size() == 1 && leaf.equals(arguments.get(0));
}
}
return false;
}