当前位置: 首页>>代码示例>>Java>>正文


Java ConditionalExpression.setElseExpression方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.ConditionalExpression.setElseExpression方法的典型用法代码示例。如果您正苦于以下问题:Java ConditionalExpression.setElseExpression方法的具体用法?Java ConditionalExpression.setElseExpression怎么用?Java ConditionalExpression.setElseExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.ConditionalExpression的用法示例。


在下文中一共展示了ConditionalExpression.setElseExpression方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: addMemberCheckNull

import org.eclipse.jdt.core.dom.ConditionalExpression; //导入方法依赖的package包/类
@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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:StringConcatenationGenerator.java

示例3: getInverseConditionalExpressionProposals

import org.eclipse.jdt.core.dom.ConditionalExpression; //导入方法依赖的package包/类
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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:33,代码来源:AdvancedQuickAssistProcessor.java

示例4: getInverseConditionalExpressionProposals

import org.eclipse.jdt.core.dom.ConditionalExpression; //导入方法依赖的package包/类
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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:33,代码来源:AdvancedQuickAssistProcessor.java

示例5: repairBug

import org.eclipse.jdt.core.dom.ConditionalExpression; //导入方法依赖的package包/类
@Override
protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException {
    Assert.isNotNull(rewrite);
    Assert.isNotNull(workingUnit);
    Assert.isNotNull(bug);

    TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
    MethodDeclaration method = getMethodDeclaration(type, bug.getPrimaryMethod());

    String fieldName = bug.getPrimaryField().getFieldName();
    SimpleName original = null;

    for (Statement stmt : (List<Statement>) method.getBody().statements()) {
        if (stmt instanceof ReturnStatement) {
            Expression retEx = ((ReturnStatement) stmt).getExpression();

            if (retEx instanceof SimpleName && ((SimpleName) retEx).getIdentifier().equals(fieldName)) {
                original = (SimpleName) retEx;
                break;
            } else if (retEx instanceof FieldAccess && isThisFieldAccess((FieldAccess) retEx, fieldName)) {
                original = ((FieldAccess) retEx).getName();
                break;
            }
        }
    }

    if (original == null) {
        throw new BugResolutionException("No original field found.");
    }

    // set up the clone part
    MethodInvocation cloneInvoke = invokeClone(workingUnit, original);



    // cast the result to the right type
    CastExpression castRet = workingUnit.getAST().newCastExpression();
    castRet.setExpression(cloneInvoke);
    Type retType = (Type) ASTNode.copySubtree(castRet.getAST(), method.getReturnType2());
    castRet.setType(retType);


    ConditionalExpression conditionalExpression = workingUnit.getAST().newConditionalExpression();
    conditionalExpression.setElseExpression(castRet);
    conditionalExpression.setThenExpression(workingUnit.getAST().newNullLiteral() );

    InfixExpression nullTest = workingUnit.getAST().newInfixExpression();
    nullTest.setOperator(InfixExpression.Operator.EQUALS);
    nullTest.setRightOperand(workingUnit.getAST().newNullLiteral());
    Expression initialLoad = (SimpleName) ASTNode.copySubtree(cloneInvoke.getAST(), original);
    nullTest.setLeftOperand(initialLoad);

    conditionalExpression.setExpression(nullTest);

    rewrite.replace(original, conditionalExpression, null);

}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:58,代码来源:CreateMutableCloneResolution.java


注:本文中的org.eclipse.jdt.core.dom.ConditionalExpression.setElseExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。