本文整理汇总了Java中org.eclipse.jdt.core.dom.ConditionalExpression类的典型用法代码示例。如果您正苦于以下问题:Java ConditionalExpression类的具体用法?Java ConditionalExpression怎么用?Java ConditionalExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConditionalExpression类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ConditionalExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStatementType
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
/**
* Method that check statement type.
* @author Mariana Azevedo
* @since 13/07/2014
* @param itStatement
*/
private void getStatementType(Object itStatement) {
if (itStatement instanceof CatchClause){
this.visitor.visit((CatchClause)itStatement);
}else if (itStatement instanceof ForStatement){
this.visitor.visit((ForStatement)itStatement);
}else if (itStatement instanceof IfStatement){
this.visitor.visit((IfStatement)itStatement);
}else if (itStatement instanceof WhileStatement){
this.visitor.visit((WhileStatement)itStatement);
}else if (itStatement instanceof TryStatement){
this.visitor.visit((TryStatement)itStatement);
}else if (itStatement instanceof ConditionalExpression){
this.visitor.visit((ConditionalExpression)itStatement);
}else if (itStatement instanceof SwitchCase){
this.visitor.visit((SwitchCase)itStatement);
}else if (itStatement instanceof DoStatement){
this.visitor.visit((DoStatement)itStatement);
}else if (itStatement instanceof ExpressionStatement){
this.visitor.visit((ExpressionStatement)itStatement);
}
}
示例2: resolveBinding
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
public static IBinding resolveBinding(Expression expression) {
if (expression instanceof Name) return ((Name) expression).resolveBinding();
if (expression instanceof ParenthesizedExpression)
return resolveBinding(((ParenthesizedExpression) expression).getExpression());
else if (expression instanceof Assignment)
return resolveBinding(((Assignment) expression).getLeftHandSide()); // TODO ???
else if (expression instanceof MethodInvocation)
return ((MethodInvocation) expression).resolveMethodBinding();
else if (expression instanceof SuperMethodInvocation)
return ((SuperMethodInvocation) expression).resolveMethodBinding();
else if (expression instanceof FieldAccess)
return ((FieldAccess) expression).resolveFieldBinding();
else if (expression instanceof SuperFieldAccess)
return ((SuperFieldAccess) expression).resolveFieldBinding();
else if (expression instanceof ConditionalExpression)
return resolveBinding(((ConditionalExpression) expression).getThenExpression());
return null;
}
示例3: create
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
@Override
public ITypeConstraint[] create(ConditionalExpression node) {
List<ITypeConstraint> result = new ArrayList<ITypeConstraint>();
Expression thenExpression = node.getThenExpression();
Expression elseExpression = node.getElseExpression();
ConstraintVariable whole =
fConstraintVariableFactory.makeExpressionOrTypeVariable(node, getContext());
ConstraintVariable ev1 =
fConstraintVariableFactory.makeExpressionOrTypeVariable(thenExpression, getContext());
ConstraintVariable ev2 =
fConstraintVariableFactory.makeExpressionOrTypeVariable(elseExpression, getContext());
ITypeConstraint[] constraints1 = fTypeConstraintFactory.createEqualsConstraint(ev1, ev2);
ITypeConstraint[] constraints2 = fTypeConstraintFactory.createSubtypeConstraint(ev1, whole);
ITypeConstraint[] constraints3 = fTypeConstraintFactory.createSubtypeConstraint(ev2, whole);
result.addAll(Arrays.asList(constraints1));
result.addAll(Arrays.asList(constraints2));
result.addAll(Arrays.asList(constraints3));
return result.toArray(new ITypeConstraint[result.size()]);
}
示例4: resolveBinding
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
public static IBinding resolveBinding(Expression expression){
if (expression instanceof Name)
return ((Name)expression).resolveBinding();
if (expression instanceof ParenthesizedExpression)
return resolveBinding(((ParenthesizedExpression)expression).getExpression());
else if (expression instanceof Assignment)
return resolveBinding(((Assignment)expression).getLeftHandSide());//TODO ???
else if (expression instanceof MethodInvocation)
return ((MethodInvocation)expression).resolveMethodBinding();
else if (expression instanceof SuperMethodInvocation)
return ((SuperMethodInvocation)expression).resolveMethodBinding();
else if (expression instanceof FieldAccess)
return ((FieldAccess)expression).resolveFieldBinding();
else if (expression instanceof SuperFieldAccess)
return ((SuperFieldAccess)expression).resolveFieldBinding();
else if (expression instanceof ConditionalExpression)
return resolveBinding(((ConditionalExpression)expression).getThenExpression());
return null;
}
示例5: create
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
@Override
public ITypeConstraint[] create(ConditionalExpression node) {
List<ITypeConstraint> result= new ArrayList<ITypeConstraint>();
Expression thenExpression= node.getThenExpression();
Expression elseExpression= node.getElseExpression();
ConstraintVariable whole= fConstraintVariableFactory.makeExpressionOrTypeVariable(node, getContext());
ConstraintVariable ev1= fConstraintVariableFactory.makeExpressionOrTypeVariable(thenExpression, getContext());
ConstraintVariable ev2= fConstraintVariableFactory.makeExpressionOrTypeVariable(elseExpression, getContext());
ITypeConstraint[] constraints1= fTypeConstraintFactory.createEqualsConstraint(ev1, ev2);
ITypeConstraint[] constraints2= fTypeConstraintFactory.createSubtypeConstraint(ev1, whole);
ITypeConstraint[] constraints3= fTypeConstraintFactory.createSubtypeConstraint(ev2, whole);
result.addAll(Arrays.asList(constraints1));
result.addAll(Arrays.asList(constraints2));
result.addAll(Arrays.asList(constraints3));
return result.toArray(new ITypeConstraint[result.size()]);
}
示例6: createAddQualifiedHashCode
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
private Statement createAddQualifiedHashCode(IVariableBinding binding) {
MethodInvocation invoc= fAst.newMethodInvocation();
invoc.setExpression(getThisAccessForHashCode(binding.getName()));
invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
InfixExpression expr= fAst.newInfixExpression();
expr.setOperator(Operator.EQUALS);
expr.setLeftOperand(getThisAccessForHashCode(binding.getName()));
expr.setRightOperand(fAst.newNullLiteral());
ConditionalExpression cexpr= fAst.newConditionalExpression();
cexpr.setThenExpression(fAst.newNumberLiteral("0")); //$NON-NLS-1$
cexpr.setElseExpression(invoc);
cexpr.setExpression(parenthesize(expr));
return prepareAssignment(parenthesize(cexpr));
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:GenerateHashCodeEqualsOperation.java
示例7: visit
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
@Override
public boolean visit(ConditionalExpression node) {
if (expressionToReplace != null) {
return false;
}
if (node.getExpression() instanceof InfixExpression) {
InfixExpression condExpr = (InfixExpression) node.getExpression();
boolean retVal = findFirstAndSecondFloat(node, condExpr);
if (condExpr.getOperator() == InfixExpression.Operator.GREATER) {
return retVal;
}
else if (condExpr.getOperator() == InfixExpression.Operator.LESS) {
swapFirstAndSecondFloat();
return retVal;
}
}
return true;
}
示例8: findFirstAndSecondFloat
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
private boolean findFirstAndSecondFloat(ConditionalExpression node, InfixExpression condExpr) {
if (!handleTwoSimpleNames(node, condExpr)) {
// this is a if diff > 0 case
try {
if (condExpr.getLeftOperand() instanceof SimpleName) {
findDiffAndFloats((SimpleName) condExpr.getLeftOperand());
} else if (condExpr.getRightOperand() instanceof SimpleName) {
findDiffAndFloats((SimpleName) condExpr.getRightOperand());
} else {
return true; // unexpected comparison
}
floatOrDouble = getFloatOrDouble(firstFloat, secondFloat);
expressionToReplace = node;
} catch (CouldntFindDiffException e) {
return true; // keep nesting if we have a problem
}
}
return false;
}
示例9: fillConditionalExpression
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
/**
* Fills conditional/ternary skeleton pieces.
* @param node The conditional/ternary part of the skeleton.
* @param curConstraint The constraint for the type of the
* expressions generated from this piece of the skeleton.
* @param parentsOfHoles All nodes that are parents of some hole.
* @return The synthesized expressions corresponding to this
* skeleton piece and the type constraint representing their types.
*/
private ExpressionsAndTypeConstraints fillConditionalExpression(Expression node, TypeConstraint curConstraint, Set<ASTNode> parentsOfHoles) {
ConditionalExpression cond = (ConditionalExpression)node;
// TODO: Do a better job of constraining left/right to be similar? E.g., if we have right but not left.
ExpressionsAndTypeConstraints condResult = fillSkeleton(cond.getExpression(), new SupertypeBound(booleanType), parentsOfHoles);
ExpressionsAndTypeConstraints thenResult = fillSkeleton(cond.getThenExpression(), curConstraint, parentsOfHoles);
ExpressionsAndTypeConstraints elseResult = fillSkeleton(cond.getElseExpression(), curConstraint, parentsOfHoles);
Map<String, ArrayList<codehint.ast.Expression>> resultExprs = new HashMap<String, ArrayList<codehint.ast.Expression>>(thenResult.getExprs().size());
for (codehint.ast.Expression condExpr: Utils.singleton(condResult.getExprs().values()))
for (Map.Entry<String, ArrayList<codehint.ast.Expression>> thenExprs: thenResult.getExprs().entrySet()) {
IJavaType thenType = "null".equals(thenExprs.getKey()) ? null : EclipseUtils.getFullyQualifiedType(thenExprs.getKey(), stack, target, typeCache);
for (Map.Entry<String, ArrayList<codehint.ast.Expression>> elseExprs: elseResult.getExprs().entrySet()) {
IJavaType elseType = "null".equals(elseExprs.getKey()) ? null : EclipseUtils.getFullyQualifiedType(elseExprs.getKey(), stack, target, typeCache);
if ((thenType == null && EclipseUtils.isObject(elseType)) || (elseType == null && EclipseUtils.isObject(thenType)) || subtypeChecker.isSubtypeOf(thenType, elseType) || subtypeChecker.isSubtypeOf(elseType, thenType))
for (codehint.ast.Expression thenExpr: thenExprs.getValue())
for (codehint.ast.Expression elseExpr: elseExprs.getValue())
Utils.addToListMap(resultExprs, thenExprs.getKey(), expressionMaker.makeConditional(condExpr, thenExpr, elseExpr, thenExpr.getStaticType()));
}
}
return new ExpressionsAndTypeConstraints(resultExprs, thenResult.getTypeConstraint());
}
示例10: visit
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
/**
* @see ASTVisitor#visit(ConditionalExpression)
*/
@Override
public boolean visit(ConditionalExpression node) {
cyclomaticComplexityIndex++;
sumCyclomaticComplexity++;
inspectExpression(node.getExpression());
return true;
}
示例11: endVisit
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
@Override
public void endVisit(ConditionalExpression node) {
if (skipNode(node)) {
return;
}
Expression thenPart = node.getThenExpression();
Expression elsePart = node.getElseExpression();
if ((thenPart != null && fSelection.coveredBy(thenPart)) || (elsePart != null && fSelection.coveredBy(elsePart))) {
GenericSequentialFlowInfo info = createSequential();
setFlowInfo(node, info);
endVisitConditional(info, node.getExpression(), new ASTNode[] { thenPart, elsePart });
} else {
super.endVisit(node);
}
}
示例12: endVisit
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
@Override
public void endVisit(ConditionalExpression node) {
if (skipNode(node)) {
return;
}
ConditionalFlowInfo info = createConditional();
setFlowInfo(node, info);
info.mergeCondition(getFlowInfo(node.getExpression()), fFlowContext);
info.merge(getFlowInfo(node.getThenExpression()), getFlowInfo(node.getElseExpression()), fFlowContext);
}
示例13: getExpressionPrecedence
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
/**
* Returns the precedence of the expression. Expression
* with higher precedence are executed before expressions
* with lower precedence.
* i.e. in:
* <br><code> int a= ++3--;</code></br>
*
* the precedence order is
* <ul>
* <li>3</li>
* <li>++</li>
* <li>--</li>
* <li>=</li>
* </ul>
* 1. 3 -(++)-> 4<br>
* 2. 4 -(--)-> 3<br>
* 3. 3 -(=)-> a<br>
*
* @param expression the expression to determine the precedence for
* @return the precedence the higher to stronger the binding to its operand(s)
*/
public static int getExpressionPrecedence(Expression expression) {
if (expression instanceof InfixExpression) {
return getOperatorPrecedence(((InfixExpression)expression).getOperator());
} else if (expression instanceof Assignment) {
return ASSIGNMENT;
} else if (expression instanceof ConditionalExpression) {
return CONDITIONAL;
} else if (expression instanceof InstanceofExpression) {
return RELATIONAL;
} else if (expression instanceof CastExpression) {
return TYPEGENERATION;
} else if (expression instanceof ClassInstanceCreation) {
return POSTFIX;
} else if (expression instanceof PrefixExpression) {
return PREFIX;
} else if (expression instanceof FieldAccess) {
return POSTFIX;
} else if (expression instanceof MethodInvocation) {
return POSTFIX;
} else if (expression instanceof ArrayAccess) {
return POSTFIX;
} else if (expression instanceof PostfixExpression) {
return POSTFIX;
}
return Integer.MAX_VALUE;
}
示例14: endVisit
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
@Override
public void endVisit(ConditionalExpression node) {
// for now, no support for passing generic types through conditional expressions
ImmutableTypeVariable2 boxed =
fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
setConstraintVariable(node, boxed);
}
示例15: returnsConditionalExpression
import org.eclipse.jdt.core.dom.ConditionalExpression; //导入依赖的package包/类
public boolean returnsConditionalExpression() {
ASTNode last = getLastStatement();
if (last instanceof ReturnStatement) {
return ((ReturnStatement) last).getExpression() instanceof ConditionalExpression;
}
return false;
}