本文整理汇总了Java中com.sun.source.tree.ConditionalExpressionTree类的典型用法代码示例。如果您正苦于以下问题:Java ConditionalExpressionTree类的具体用法?Java ConditionalExpressionTree怎么用?Java ConditionalExpressionTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConditionalExpressionTree类属于com.sun.source.tree包,在下文中一共展示了ConditionalExpressionTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
public Boolean visitConditionalExpression(ConditionalExpressionTree node, TreePath p) {
if (p == null) {
super.visitConditionalExpression(node, p);
return false;
}
ConditionalExpressionTree t = (ConditionalExpressionTree) p.getLeaf();
if (!scan(node.getCondition(), t.getCondition(), p))
return false;
if (!scan(node.getFalseExpression(), t.getFalseExpression(), p))
return false;
return scan(node.getTrueExpression(), t.getTrueExpression(), p);
}
示例2: computeConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
private static List<? extends TypeMirror> computeConditionalExpression(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
ConditionalExpressionTree cet = (ConditionalExpressionTree) parent.getLeaf();
if (cet.getCondition() == error) {
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.BOOLEAN));
}
if (cet.getTrueExpression() == error || cet.getFalseExpression() == error) {
types.add(ElementKind.PARAMETER);
types.add(ElementKind.LOCAL_VARIABLE);
types.add(ElementKind.FIELD);
return resolveType(types, info, parent.getParentPath(), cet, offset, null, null);
}
return null;
}
示例3: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public Object visitConditionalExpression(ConditionalExpressionTree node, Void p) {
Object condition = scan(node.getCondition(), p);
if (condition == Boolean.TRUE) {
return scan(node.getTrueExpression(), p);
} else if (condition == Boolean.FALSE) {
return scan(node.getFalseExpression(), p);
}
if (enhanceProcessing) {
Object first = scan(node.getTrueExpression(), p);
Object second = scan(node.getFalseExpression(), p);
if (first == NULL && second == NULL) {
return NULL;
} else if (first != null && second != null) {
return NOT_NULL;
}
}
// indeterminate
return null;
}
示例4: performRewrite
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
TypeMirror resolvedTargetType = targetType.resolve(ctx.getWorkingCopy());
if (resolvedTargetType == null) {
//cannot resolve anymore:
return;
}
TreePath resolvedIdealTypeTree = idealTypeTree != null ? idealTypeTree.resolve(ctx.getWorkingCopy()) : null;
TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
ExpressionTree toCast = (ExpressionTree) ctx.getPath().getLeaf();
Class interf = toCast.getKind().asInterface();
boolean wrapWithBrackets = interf == BinaryTree.class || interf == ConditionalExpressionTree.class;
if (/*TODO: replace with JavaFixUtilities.requiresparenthesis*/wrapWithBrackets) {
toCast = make.Parenthesized(toCast);
}
ExpressionTree cast = make.TypeCast(resolvedIdealTypeTree != null ? resolvedIdealTypeTree.getLeaf() : make.Type(resolvedTargetType), toCast);
ctx.getWorkingCopy().rewrite(ctx.getPath().getLeaf(), cast);
}
示例5: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public Void visitConditionalExpression(ConditionalExpressionTree node, Void unused) {
sync(node);
builder.open(plusFour);
scan(node.getCondition(), null);
builder.breakOp(" ");
token("?");
builder.space();
scan(node.getTrueExpression(), null);
builder.breakOp(" ");
token(":");
builder.space();
scan(node.getFalseExpression(), null);
builder.close();
return null;
}
示例6: matches
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public boolean matches(ExpressionTree t, VisitorState state) {
return firstNonNull(
t.accept(
new SimpleTreeVisitor<Boolean, Void>() {
@Override
public Boolean visitConditionalExpression(
ConditionalExpressionTree tree, Void unused) {
return reduce(
tree.getTrueExpression().accept(this, null),
tree.getFalseExpression().accept(this, null));
}
@Override
protected Boolean defaultAction(Tree node, Void aVoid) {
Object constValue = ASTHelpers.constValue(node);
return constValue != null;
}
public Boolean reduce(Boolean lhs, Boolean rhs) {
return firstNonNull(lhs, false) && firstNonNull(rhs, false);
}
},
null),
false);
}
示例7: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
/**
* If the computation of the type of the ConditionalExpressionTree in
* org.checkerframework.framework.type.TypeFromTree.TypeFromExpression.visitConditionalExpression(ConditionalExpressionTree, AnnotatedTypeFactory)
* is correct, the following checks are redundant.
* However, let's add another failsafe guard and do the checks.
*/
@Override
public Void visitConditionalExpression(ConditionalExpressionTree node, Void p) {
AnnotatedTypeMirror cond = atypeFactory.getAnnotatedType(node);
Pair<Tree, AnnotatedTypeMirror> ctx = visitorState.getAssignmentContext();
Tree assignmentContext = ctx == null ? null : ctx.first;
boolean isLocalVariableAssignment = false;
if (assignmentContext != null) {
if (assignmentContext instanceof VariableTree) {
isLocalVariableAssignment = assignmentContext instanceof IdentifierTree
&& !TreeUtils.isFieldAccess(assignmentContext);
}
if (assignmentContext instanceof VariableTree) {
isLocalVariableAssignment = TreeUtils
.enclosingMethod(getCurrentPath()) != null;
}
}
this.commonAssignmentCheck(cond, node.getTrueExpression(),
"conditional.type.incompatible", isLocalVariableAssignment);
this.commonAssignmentCheck(cond, node.getFalseExpression(),
"conditional.type.incompatible", isLocalVariableAssignment);
return super.visitConditionalExpression(node, p);
}
示例8: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public Tree visitConditionalExpression(ConditionalExpressionTree tree, Void p) {
ConditionalExpressionTree n = make.ConditionalExpression(tree.getCondition(), tree.getTrueExpression(), tree.getFalseExpression());
model.setType(n, model.getType(tree));
comments.copyComments(tree, n);
model.setPos(n, model.getPos(tree));
return n;
}
示例9: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public Object visitConditionalExpression(ConditionalExpressionTree node, Object p) {
depth++;
Object o = super.visitConditionalExpression(node, p);
depth--;
return o;
}
示例10: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public Void visitConditionalExpression(ConditionalExpressionTree tree, List<Node> d) {
List<Node> below = new ArrayList<Node>();
addCorrespondingType(below);
addCorrespondingComments(below);
super.visitConditionalExpression(tree, below);
d.add(new TreeNode(info, getCurrentPath(), below));
return null;
}
示例11: makeParenthesis
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
private ExpressionTree makeParenthesis(ExpressionTree arg) {
Class c = arg.getKind().asInterface();
// if the original append argument was an expression, surround it in parenthesis, to get the same toString effect
if (c == BinaryTree.class || c == UnaryTree.class || c == CompoundAssignmentTree.class || c == AssignmentTree.class ||
c == ConditionalExpressionTree.class) {
return mk.Parenthesized(arg);
} else {
return arg;
}
}
示例12: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public Boolean visitConditionalExpression(ConditionalExpressionTree node, ConstructorData p) {
Boolean result = scan(node.getCondition(), p);
if (result != null) {
if (result) {
scan(node.getTrueExpression(), null);
} else {
scan(node.getFalseExpression(), null);
}
return null;
}
Map<Element, State> oldVariable2State = variable2State;
variable2State = new HashMap<Element, Flow.State>(oldVariable2State);
scan(node.getTrueExpression(), null);
if (node.getFalseExpression() != null) {
Map<Element, State> variableStatesAfterThen = new HashMap<Element, Flow.State>(variable2State);
variable2State = new HashMap<Element, Flow.State>(oldVariable2State);
scan(node.getFalseExpression(), null);
variable2State = mergeOr(variable2State, variableStatesAfterThen);
} else {
variable2State = mergeOr(variable2State, oldVariable2State);
}
return null;
}
示例13: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public List<Tree> visitConditionalExpression(ConditionalExpressionTree node, ExpressionScanner.ExpressionsInfo p) {
ExpressionTree condition = node.getCondition();
List<Tree> cond = scan(condition, p);
Tree lastCond = null;
Boolean resolvedCondition = null;
if (cond != null) {
lastCond = cond.get(cond.size() - 1);
} else {
if (condition.getKind() == Tree.Kind.BOOLEAN_LITERAL) {
resolvedCondition = Boolean.parseBoolean(condition.toString());
}
}
List<Tree> rT;
List<Tree> rF;
if (resolvedCondition != null) {
if (resolvedCondition) {
rT = scan(node.getTrueExpression(), p);
rF = null;
} else {
rT = null;
rF = scan(node.getFalseExpression(), p);
}
} else {
rT = scan(node.getTrueExpression(), p);
rF = scan(node.getFalseExpression(), p);
}
if (lastCond != null) {
if (rT != null) {
p.addNextExpression(lastCond, rT.get(0));
}
if (rF != null) {
p.addNextExpression(lastCond, rF.get(0));
}
}
return reduce(reduce(cond, rT), rF);
}
示例14: visitConditionalExpression
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
@Override
public Mirror visitConditionalExpression(ConditionalExpressionTree arg0, EvaluationContext evaluationContext) {
boolean isTrue = evaluateCondition(arg0, evaluationContext, arg0.getCondition());
if (isTrue) {
return arg0.getTrueExpression().accept(this, evaluationContext);
} else {
return arg0.getFalseExpression().accept(this, evaluationContext);
}
}
示例15: pathToType
import com.sun.source.tree.ConditionalExpressionTree; //导入依赖的package包/类
private Type pathToType(TreePath tp, Tree tree) {
if (tree instanceof ConditionalExpressionTree) {
// Conditionals always wind up as Object -- this corrects
ConditionalExpressionTree cet = (ConditionalExpressionTree) tree;
Type tmt = pathToType(new TreePath(tp, cet.getTrueExpression()));
Type tmf = pathToType(new TreePath(tp, cet.getFalseExpression()));
if (!tmt.isPrimitive() && !tmf.isPrimitive()) {
Type lub = types.lub(tmt, tmf);
// System.err.printf("cond ? %s : %s -- lub = %s\n",
// varTypeName(tmt), varTypeName(tmf), varTypeName(lub));
return lub;
}
}
return pathToType(tp);
}