Java 类org.eclipse.jdt.core.dom.ConditionalExpression 实例源码

项目:o3smeasures-tool    文件:WeightMethodsPerClassVisitor.java   
/**
 * 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);
    }
}
项目:che    文件:ExpressionVariable.java   
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;
}
项目:che    文件:FullConstraintCreator.java   
@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()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:ExpressionVariable.java   
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;
}
项目:Eclipse-Postfix-Code-Completion    文件:FullConstraintCreator.java   
@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()]);
}
项目:Eclipse-Postfix-Code-Completion    文件:GenerateHashCodeEqualsOperation.java   
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));
    }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ExpressionVariable.java   
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;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:FullConstraintCreator.java   
@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()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:GenerateHashCodeEqualsOperation.java   
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));
    }
项目:fb-contrib-eclipse-quick-fixes    文件:CompareFloatResolution.java   
@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;
}
项目:fb-contrib-eclipse-quick-fixes    文件:CompareFloatResolution.java   
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;
}
项目:codehint    文件:ExpressionSkeleton.java   
/**
 * 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());
}
项目:o3smeasures-tool    文件:CyclomaticComplexityVisitor.java   
/**
 * @see ASTVisitor#visit(ConditionalExpression)
 */
@Override
public boolean visit(ConditionalExpression node) {
    cyclomaticComplexityIndex++;
    sumCyclomaticComplexity++;
    inspectExpression(node.getExpression());
    return true;
}
项目:eclipse.jdt.ls    文件:InputFlowAnalyzer.java   
@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);
    }
}
项目:eclipse.jdt.ls    文件:FlowAnalyzer.java   
@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);
}
项目:eclipse.jdt.ls    文件:OperatorPrecedence.java   
/**
 * 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;
}
项目:che    文件:InferTypeArgumentsConstraintCreator.java   
@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);
}
项目:che    文件:SourceProvider.java   
public boolean returnsConditionalExpression() {
  ASTNode last = getLastStatement();
  if (last instanceof ReturnStatement) {
    return ((ReturnStatement) last).getExpression() instanceof ConditionalExpression;
  }
  return false;
}
项目:che    文件:InputFlowAnalyzer.java   
@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);
  }
}
项目:che    文件:OperatorPrecedence.java   
/**
 * 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>
 *
 * <p>the precedence order is
 *
 * <ul>
 *   <li>3
 *   <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;
}
项目:evosuite    文件:TestExtractingVisitor.java   
/** {@inheritDoc} */
@Override
public void endVisit(ConditionalExpression node) {
    // TODO-JRO Implement method endVisit
    logger.warn("Method endVisit not implemented!");
    super.endVisit(node);
}
项目:Eclipse-Postfix-Code-Completion    文件:SourceProvider.java   
public boolean returnsConditionalExpression() {
    ASTNode last= getLastStatement();
    if (last instanceof ReturnStatement) {
        return ((ReturnStatement)last).getExpression() instanceof ConditionalExpression;
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:InputFlowAnalyzer.java   
@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);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:FlowAnalyzer.java   
@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);
}
项目:Eclipse-Postfix-Code-Completion    文件:OperatorPrecedence.java   
/**
 * 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;
}
项目:Eclipse-Postfix-Code-Completion    文件:StringConcatenationGenerator.java   
private void addElement(Object element, SumExpressionBuilder builder) {
    if (element instanceof String) {
        builder.addString((String)element);
    }
    if (element instanceof Expression) {
        Expression expr= (Expression)element;
        if (expr instanceof ConditionalExpression) {
            ParenthesizedExpression expr2= fAst.newParenthesizedExpression();
            expr2.setExpression(expr);
            expr= expr2;
        }
        builder.addExpression(expr);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:StringConcatenationGenerator.java   
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
    ConditionalExpression cExpression= fAst.newConditionalExpression();

    // member != null ?
    InfixExpression infExpression= fAst.newInfixExpression();
    infExpression.setLeftOperand(createMemberAccessExpression(member, true, true));
    infExpression.setRightOperand(fAst.newNullLiteral());
    infExpression.setOperator(Operator.NOT_EQUALS);
    cExpression.setExpression(infExpression);

    SumExpressionBuilder builder= new SumExpressionBuilder(null);
    String[] arrayString= getContext().getTemplateParser().getBody();
    for (int i= 0; i < arrayString.length; i++) {
        addElement(processElement(arrayString[i], member), builder);
    }
    if (addSeparator)
        addElement(getContext().getTemplateParser().getSeparator(), builder);
    cExpression.setThenExpression(builder.getExpression());

    StringLiteral literal= fAst.newStringLiteral();
    literal.setLiteralValue(getContext().isSkipNulls() ? "" : "null"); //$NON-NLS-1$ //$NON-NLS-2$
    cExpression.setElseExpression(literal);

    ParenthesizedExpression pExpression= fAst.newParenthesizedExpression();
    pExpression.setExpression(cExpression);
    toStringExpressionBuilder.addExpression(pExpression);
}
项目:Eclipse-Postfix-Code-Completion    文件:AdvancedQuickAssistProcessor.java   
private static boolean getInverseConditionalExpressionProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
    // try to find conditional expression as parent
    while (covering instanceof Expression) {
        if (covering instanceof ConditionalExpression)
            break;
        covering= covering.getParent();
    }
    if (!(covering instanceof ConditionalExpression)) {
        return false;
    }
    ConditionalExpression expression= (ConditionalExpression) covering;
    //  we could produce quick assist
    if (resultingCollections == null) {
        return true;
    }
    //
    AST ast= covering.getAST();
    ASTRewrite rewrite= ASTRewrite.create(ast);
    // prepare new conditional expression
    ConditionalExpression newExpression= ast.newConditionalExpression();
    newExpression.setExpression(getInversedExpression(rewrite, expression.getExpression()));
    newExpression.setThenExpression((Expression) rewrite.createCopyTarget(expression.getElseExpression()));
    newExpression.setElseExpression((Expression) rewrite.createCopyTarget(expression.getThenExpression()));
    // replace old expression with new
    rewrite.replace(expression, newExpression, null);
    // add correction proposal
    String label= CorrectionMessages.AdvancedQuickAssistProcessor_inverseConditionalExpression_description;
    Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INVERSE_CONDITIONAL_EXPRESSION, image);
    resultingCollections.add(proposal);
    return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:AdvancedQuickAssistProcessor.java   
private static Expression getBooleanExpression(ASTNode node) {
    if (!(node instanceof Expression)) {
        return null;
    }

    // check if the node is a location where it can be negated
    StructuralPropertyDescriptor locationInParent= node.getLocationInParent();
    if (locationInParent == QualifiedName.NAME_PROPERTY) {
        node= node.getParent();
        locationInParent= node.getLocationInParent();
    }
    while (locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
        node= node.getParent();
        locationInParent= node.getLocationInParent();
    }
    Expression expression= (Expression) node;
    if (!isBoolean(expression)) {
        return null;
    }
    if (expression.getParent() instanceof InfixExpression) {
        return expression;
    }
    if (locationInParent == Assignment.RIGHT_HAND_SIDE_PROPERTY || locationInParent == IfStatement.EXPRESSION_PROPERTY
            || locationInParent == WhileStatement.EXPRESSION_PROPERTY || locationInParent == DoStatement.EXPRESSION_PROPERTY
            || locationInParent == ReturnStatement.EXPRESSION_PROPERTY || locationInParent == ForStatement.EXPRESSION_PROPERTY
            || locationInParent == AssertStatement.EXPRESSION_PROPERTY || locationInParent == MethodInvocation.ARGUMENTS_PROPERTY
            || locationInParent == ConstructorInvocation.ARGUMENTS_PROPERTY || locationInParent == SuperMethodInvocation.ARGUMENTS_PROPERTY
            || locationInParent == EnumConstantDeclaration.ARGUMENTS_PROPERTY || locationInParent == SuperConstructorInvocation.ARGUMENTS_PROPERTY
            || locationInParent == ClassInstanceCreation.ARGUMENTS_PROPERTY || locationInParent == ConditionalExpression.EXPRESSION_PROPERTY
            || locationInParent == PrefixExpression.OPERAND_PROPERTY) {
        return expression;
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:AdvancedQuickAssistProcessor.java   
private static boolean getPullNegationUpProposals(IInvocationContext context, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) {
    if (coveredNodes.size() != 1) {
        return false;
    }
    //
    ASTNode fullyCoveredNode= coveredNodes.get(0);

    Expression expression= getBooleanExpression(fullyCoveredNode);
    if (expression == null || (!(expression instanceof InfixExpression) && !(expression instanceof ConditionalExpression))) {
        return false;
    }
    //  we could produce quick assist
    if (resultingCollections == null) {
        return true;
    }
    //
    AST ast= expression.getAST();
    final ASTRewrite rewrite= ASTRewrite.create(ast);
    // prepared inverted expression
    Expression inversedExpression= getInversedExpression(rewrite, expression);
    // prepare ParenthesizedExpression
    ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression();
    parenthesizedExpression.setExpression(inversedExpression);
    // prepare NOT prefix expression
    PrefixExpression prefixExpression= ast.newPrefixExpression();
    prefixExpression.setOperator(PrefixExpression.Operator.NOT);
    prefixExpression.setOperand(parenthesizedExpression);
    // replace old expression
    rewrite.replace(expression, prefixExpression, null);
    // add correction proposal
    String label= CorrectionMessages.AdvancedQuickAssistProcessor_pullNegationUp;
    Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.PULL_NEGATION_UP, image);
    resultingCollections.add(proposal);
    return true;
}
项目:ChangeScribe    文件:MethodAnalyzer.java   
public boolean visit(final ConditionalExpression node) {
    ++this.inCondition;
    node.getExpression().accept((ASTVisitor)this);
    --this.inCondition;
    node.getThenExpression().accept((ASTVisitor)this);
    node.getElseExpression().accept((ASTVisitor)this);
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SourceProvider.java   
public boolean returnsConditionalExpression() {
    ASTNode last= getLastStatement();
    if (last instanceof ReturnStatement) {
        return ((ReturnStatement)last).getExpression() instanceof ConditionalExpression;
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:InputFlowAnalyzer.java   
@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);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:FlowAnalyzer.java   
@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);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:OperatorPrecedence.java   
/**
 * 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;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ASTFlattener.java   
@Override
public boolean visit(ConditionalExpression node) {
    node.getExpression().accept(this);
    this.fBuffer.append("?");//$NON-NLS-1$
    node.getThenExpression().accept(this);
    this.fBuffer.append(":");//$NON-NLS-1$
    node.getElseExpression().accept(this);
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NecessaryParenthesesChecker.java   
/**
 * Does the <code>expression</code> need parentheses when inserted into <code>parent</code> at
 * <code>locationInParent</code> ?
 * 
 * <p>
 * <b>Note:</b> The expression can be an unparented node.
 * </p>
 * 
 * @param expression the expression
 * @param parent the parent node
 * @param locationInParent location of expression in the parent
 * @return <code>true</code> if the expression needs parentheses, <code>false</code> otherwise.
 */
public static boolean needsParentheses(Expression expression, ASTNode parent, StructuralPropertyDescriptor locationInParent) {
    if (!expressionTypeNeedsParentheses(expression))
        return false;

    if (!locationNeedsParentheses(locationInParent)) {
        return false;
    }

    if (parent instanceof Expression) {
        Expression parentExpression= (Expression)parent;

        int expressionPrecedence= OperatorPrecedence.getExpressionPrecedence(expression);
        int parentPrecedence= OperatorPrecedence.getExpressionPrecedence(parentExpression);

        if (expressionPrecedence > parentPrecedence)
            //(opEx) opParent and opEx binds more -> parentheses not needed
            return false;

        if (expressionPrecedence < parentPrecedence)
            //(opEx) opParent and opEx binds less -> parentheses needed
            return true;

        //(opEx) opParent binds equal

        if (parentExpression instanceof InfixExpression) {
            return needsParenthesesInInfixExpression(expression, (InfixExpression)parentExpression, locationInParent);
        }

        if (parentExpression instanceof ConditionalExpression && locationInParent == ConditionalExpression.EXPRESSION_PROPERTY) {
            return true;
        }

        return false;
    }

    return true;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:StringConcatenationGenerator.java   
private void addElement(Object element, SumExpressionBuilder builder) {
    if (element instanceof String) {
        builder.addString((String)element);
    }
    if (element instanceof Expression) {
        Expression expr= (Expression)element;
        if (expr instanceof ConditionalExpression) {
            ParenthesizedExpression expr2= fAst.newParenthesizedExpression();
            expr2.setExpression(expr);
            expr= expr2;
        }
        builder.addExpression(expr);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:StringConcatenationGenerator.java   
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
    ConditionalExpression cExpression= fAst.newConditionalExpression();

    // member != null ?
    InfixExpression infExpression= fAst.newInfixExpression();
    infExpression.setLeftOperand(createMemberAccessExpression(member, true, true));
    infExpression.setRightOperand(fAst.newNullLiteral());
    infExpression.setOperator(Operator.NOT_EQUALS);
    cExpression.setExpression(infExpression);

    SumExpressionBuilder builder= new SumExpressionBuilder(null);
    String[] arrayString= getContext().getTemplateParser().getBody();
    for (int i= 0; i < arrayString.length; i++) {
        addElement(processElement(arrayString[i], member), builder);
    }
    if (addSeparator)
        addElement(getContext().getTemplateParser().getSeparator(), builder);
    cExpression.setThenExpression(builder.getExpression());

    StringLiteral literal= fAst.newStringLiteral();
    literal.setLiteralValue(getContext().isSkipNulls() ? "" : "null"); //$NON-NLS-1$ //$NON-NLS-2$
    cExpression.setElseExpression(literal);

    ParenthesizedExpression pExpression= fAst.newParenthesizedExpression();
    pExpression.setExpression(cExpression);
    toStringExpressionBuilder.addExpression(pExpression);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AdvancedQuickAssistProcessor.java   
private static boolean getInverseConditionalExpressionProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
    // try to find conditional expression as parent
    while (covering instanceof Expression) {
        if (covering instanceof ConditionalExpression)
            break;
        covering= covering.getParent();
    }
    if (!(covering instanceof ConditionalExpression)) {
        return false;
    }
    ConditionalExpression expression= (ConditionalExpression) covering;
    //  we could produce quick assist
    if (resultingCollections == null) {
        return true;
    }
    //
    AST ast= covering.getAST();
    ASTRewrite rewrite= ASTRewrite.create(ast);
    // prepare new conditional expression
    ConditionalExpression newExpression= ast.newConditionalExpression();
    newExpression.setExpression(getInversedExpression(rewrite, expression.getExpression()));
    newExpression.setThenExpression((Expression) rewrite.createCopyTarget(expression.getElseExpression()));
    newExpression.setElseExpression((Expression) rewrite.createCopyTarget(expression.getThenExpression()));
    // replace old expression with new
    rewrite.replace(expression, newExpression, null);
    // add correction proposal
    String label= CorrectionMessages.AdvancedQuickAssistProcessor_inverseConditionalExpression_description;
    Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image);
    resultingCollections.add(proposal);
    return true;
}