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


Java IfStatement.setThenStatement方法代码示例

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


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

示例1: addMemberCheckNull

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
	IfStatement ifStatement= fAst.newIfStatement();
	ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
	Block thenBlock= fAst.newBlock();
	flushBuffer(null);
	String[] arrayString= getContext().getTemplateParser().getBody();
	for (int i= 0; i < arrayString.length; i++) {
		addElement(processElement(arrayString[i], member), thenBlock);
	}
	if (addSeparator)
		addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
	flushBuffer(thenBlock);

	if (thenBlock.statements().size() == 1 && !getContext().isForceBlocks()) {
		ifStatement.setThenStatement((Statement)ASTNode.copySubtree(fAst, (ASTNode)thenBlock.statements().get(0)));
	} else {
		ifStatement.setThenStatement(thenBlock);
	}
	toStringMethod.getBody().statements().add(ifStatement);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:StringBuilderGenerator.java

示例2: addMemberCheckNull

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
protected void addMemberCheckNull(Object member, boolean addSeparator) {
	IfStatement ifStatement= fAst.newIfStatement();
	ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(member, true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
	Block thenBlock= fAst.newBlock();
	flushTemporaryExpression();
	String[] arrayString= getContext().getTemplateParser().getBody();
	for (int i= 0; i < arrayString.length; i++) {
		addElement(processElement(arrayString[i], member), thenBlock);
	}
	if (addSeparator)
		addElement(getContext().getTemplateParser().getSeparator(), thenBlock);
	flushTemporaryExpression();

	if (thenBlock.statements().size() == 1 && !getContext().isForceBlocks()) {
		ifStatement.setThenStatement((Statement)ASTNode.copySubtree(fAst, (ASTNode)thenBlock.statements().get(0)));
	} else {
		ifStatement.setThenStatement(thenBlock);
	}
	toStringMethod.getBody().statements().add(ifStatement);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:StringBuilderChainGenerator.java

示例3: createOuterComparison

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private Statement createOuterComparison() {
	MethodInvocation outer1= fAst.newMethodInvocation();
	outer1.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE));

	MethodInvocation outer2= fAst.newMethodInvocation();
	outer2.setName(fAst.newSimpleName(METHODNAME_OUTER_TYPE));
	outer2.setExpression(fAst.newSimpleName(VARIABLE_NAME_EQUALS_CASTED));

	MethodInvocation outerEql= fAst.newMethodInvocation();
	outerEql.setName(fAst.newSimpleName(METHODNAME_EQUALS));
	outerEql.setExpression(outer1);
	outerEql.arguments().add(outer2);

	PrefixExpression not= fAst.newPrefixExpression();
	not.setOperand(outerEql);
	not.setOperator(PrefixExpression.Operator.NOT);

	IfStatement notEqNull= fAst.newIfStatement();
	notEqNull.setExpression(not);
	notEqNull.setThenStatement(getThenStatement(getReturnFalse()));
	return notEqNull;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:GenerateHashCodeEqualsOperation.java

示例4: createArrayComparison

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private Statement createArrayComparison(String name) {
	MethodInvocation invoc= fAst.newMethodInvocation();
	invoc.setName(fAst.newSimpleName(METHODNAME_EQUALS));
	invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
	invoc.arguments().add(getThisAccessForEquals(name));
	invoc.arguments().add(getOtherAccess(name));

	PrefixExpression pe= fAst.newPrefixExpression();
	pe.setOperator(PrefixExpression.Operator.NOT);
	pe.setOperand(invoc);

	IfStatement ifSt= fAst.newIfStatement();
	ifSt.setExpression(pe);
	ifSt.setThenStatement(getThenStatement(getReturnFalse()));

	return ifSt;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:GenerateHashCodeEqualsOperation.java

示例5: createMultiArrayComparison

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private Statement createMultiArrayComparison(String name) {
	MethodInvocation invoc= fAst.newMethodInvocation();
	invoc.setName(fAst.newSimpleName(METHODNAME_DEEP_EQUALS));
	invoc.setExpression(getQualifiedName(JAVA_UTIL_ARRAYS));
	invoc.arguments().add(getThisAccessForEquals(name));
	invoc.arguments().add(getOtherAccess(name));

	PrefixExpression pe= fAst.newPrefixExpression();
	pe.setOperator(PrefixExpression.Operator.NOT);
	pe.setOperand(invoc);

	IfStatement ifSt= fAst.newIfStatement();
	ifSt.setExpression(pe);
	ifSt.setThenStatement(getThenStatement(getReturnFalse()));

	return ifSt;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:GenerateHashCodeEqualsOperation.java

示例6: makeIfStatement

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Statement makeIfStatement(ASTRewrite rewrite, ReturnValueResolutionVisitor rvrFinder, boolean b) {
    AST rootNode = rewrite.getAST();
    IfStatement ifStatement = rootNode.newIfStatement();

    Expression expression = makeIfExpression(rewrite, rvrFinder, b);
    ifStatement.setExpression(expression);

    // the block surrounds the inner statement with {}
    Block thenBlock = rootNode.newBlock();
    Statement thenStatement = makeExceptionalStatement(rootNode);
    thenBlock.statements().add(thenStatement);
    ifStatement.setThenStatement(thenBlock);

    return ifStatement;
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:17,代码来源:ReturnValueIgnoreResolution.java

示例7: visit

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean visit(QJump statement) {

	Block block = blocks.peek();

	// dummy break
	if (isParentFor(statement)) {
		IfStatement ifSt = ast.newIfStatement();
		ifSt.setExpression(ast.newBooleanLiteral(false));
		ifSt.setThenStatement(ast.newBreakStatement());
		block.statements().add(ifSt);
	}

	MethodInvocation methodInvocation = ast.newMethodInvocation();
	methodInvocation.setExpression(ast.newSimpleName("qRPJ"));
	methodInvocation.setName(ast.newSimpleName("qJump"));

	Name labelName = ast.newName(new String[] { "TAG", statement.getLabel() });
	methodInvocation.arguments().add(0, labelName);

	ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
	block.statements().add(expressionStatement);

	return super.visit(statement);
}
 
开发者ID:asupdev,项目名称:asup,代码行数:27,代码来源:JDTStatementWriter.java

示例8: generateToStringMethod

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
public MethodDeclaration generateToStringMethod() throws CoreException {
	initialize();

	//ToStringBuilder builder= new ToStringBuilder(this);
	String builderVariableName= createNameSuggestion(getContext().getCustomBuilderVariableName(), NamingConventions.VK_LOCAL);
	VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment();
	fragment.setName(fAst.newSimpleName(builderVariableName));
	ClassInstanceCreation classInstance= fAst.newClassInstanceCreation();
	Name typeName= addImport(getContext().getCustomBuilderClass());
	classInstance.setType(fAst.newSimpleType(typeName));
	classInstance.arguments().add(fAst.newThisExpression());
	fragment.setInitializer(classInstance);
	VariableDeclarationStatement vStatement= fAst.newVariableDeclarationStatement(fragment);
	vStatement.setType(fAst.newSimpleType((Name)ASTNode.copySubtree(fAst, typeName)));
	toStringMethod.getBody().statements().add(vStatement);

	/* expression for accumulating chained calls */
	Expression expression= null;

	for (int i= 0; i < getContext().getSelectedMembers().length; i++) {
		//builder.append("member", member);
		MethodInvocation appendInvocation= createAppendMethodForMember(getContext().getSelectedMembers()[i]);
		if (getContext().isSkipNulls() && !getMemberType(getContext().getSelectedMembers()[i]).isPrimitive()) {
			if (expression != null) {
				toStringMethod.getBody().statements().add(fAst.newExpressionStatement(expression));
				expression= null;
			}
			appendInvocation.setExpression(fAst.newSimpleName(builderVariableName));
			IfStatement ifStatement= fAst.newIfStatement();
			ifStatement.setExpression(createInfixExpression(createMemberAccessExpression(getContext().getSelectedMembers()[i], true, true), Operator.NOT_EQUALS, fAst.newNullLiteral()));
			ifStatement.setThenStatement(createOneStatementBlock(appendInvocation));
			toStringMethod.getBody().statements().add(ifStatement);
		} else {
			if (expression != null) {
				appendInvocation.setExpression(expression);
			} else {
				appendInvocation.setExpression(fAst.newSimpleName(builderVariableName));
			}
			if (getContext().isCustomBuilderChainedCalls() && canChainLastAppendCall) {
				expression= appendInvocation;
			} else {
				expression= null;
				toStringMethod.getBody().statements().add(fAst.newExpressionStatement(appendInvocation));
			}
		}
	}

	if (expression != null) {
		toStringMethod.getBody().statements().add(fAst.newExpressionStatement(expression));
	}
	// return builder.toString();
	ReturnStatement rStatement= fAst.newReturnStatement();
	rStatement.setExpression(createMethodInvocation(builderVariableName, getContext().getCustomBuilderResultMethod(), null));
	toStringMethod.getBody().statements().add(rStatement);

	complete();

	return toStringMethod;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:61,代码来源:CustomBuilderGenerator.java

示例9: createReturningIfStatement

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private Statement createReturningIfStatement(boolean result, Expression condition) {
	IfStatement firstIf= fAst.newIfStatement();
	firstIf.setExpression(condition);

	ReturnStatement returner= fAst.newReturnStatement();
	returner.setExpression(fAst.newBooleanLiteral(result));
	firstIf.setThenStatement(getThenStatement(returner));
	return firstIf;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:GenerateHashCodeEqualsOperation.java

示例10: addConstructorInvocations

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
/**
 * adds calls to the appropriate DomainObject subclass constructors
 * depending on the existing local string variable @className
 * 
 * has @SuppressWarnings("unchecked") annotation, because we need to add elements to
 * the untyped list returned org.eclipse.jdt.core.dom.MethodInvocation.arguments()
 * which is part of the imported jdt ast library, which would be unreasonable to adapt.
 * 
 * @param currentClass
 * @param ast
 * @param listRewrite
 */
@SuppressWarnings("unchecked")
private static void addConstructorInvocations(DomainClass currentClass, AST ast, ListRewrite listRewrite) {
	if(!currentClass.getIsAbstract() && currentClass.getHasPublicEmptyConstructor()) {
		IfStatement ifClass = ast.newIfStatement();
		SimpleName simpleName = ast.newSimpleName("className");
		MethodInvocation equals = ast.newMethodInvocation();
		equals.setName(ast.newSimpleName("equals"));
		StringLiteral stringLiteral = ast.newStringLiteral();
		stringLiteral.setLiteralValue(currentClass.getName());
		equals.setExpression(stringLiteral);
		equals.arguments().add(simpleName);
		
		ReturnStatement returnStatement = ast.newReturnStatement();
		ClassInstanceCreation classInstanceCreation = ast.newClassInstanceCreation();
		Name name = ast.newName(currentClass.getName());
		SimpleType atomExceptionType = ast.newSimpleType(name);
		classInstanceCreation.setType(atomExceptionType);
		returnStatement.setExpression(classInstanceCreation);
		
		ifClass.setThenStatement(returnStatement);		
		
		listRewrite.insertLast(ifClass, null);
		
		ifClass.setExpression(equals);
	}
	
	for(DomainClass subClass : currentClass.getSubClasses()) {
		addConstructorInvocations(subClass, ast, listRewrite);
	}
}
 
开发者ID:fhcampuswien,项目名称:atom,代码行数:43,代码来源:ReflectionEmulatorGenerator.java

示例11: createInitPython

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
/**
 * Creates initPython() method.
 */
private void createInitPython() {
    // create a new method
    MethodDeclaration md = ast.newMethodDeclaration();
    md.setName(ast.newSimpleName("initPython"));
    // add to the TD body declarations
    td.bodyDeclarations().add(1, md);
    // set private modifier
    setPrivate(md);
    // create block with IF statement
    md.setBody(ast.newBlock());
    IfStatement ifSt = ast.newIfStatement();
    Block ifBlock = ast.newBlock();
    ifSt.setThenStatement(ifBlock);
    md.getBody().statements().add(ifSt);
    // create pexec == null expression
    InfixExpression infix = ast.newInfixExpression();
    infix.setLeftOperand(ast.newSimpleName("pexec"));
    infix.setOperator(InfixExpression.Operator.EQUALS);
    infix.setRightOperand(ast.newNullLiteral());
    ifSt.setExpression(infix);
    // create pexec = new PythonExecutor(this) statement
    Assignment assignment = ast.newAssignment();
    assignment.setLeftHandSide(ast.newSimpleName("pexec"));
    assignment.setOperator(Assignment.Operator.ASSIGN);
    ClassInstanceCreation cic = ast.newClassInstanceCreation();
    cic.setType(ast.newSimpleType(ast.newSimpleName("PythonExecutor")));
    cic.arguments().add(ast.newThisExpression());
    assignment.setRightHandSide(cic);
    ifBlock.statements().add(ast.newExpressionStatement(assignment));
    createCheckAbstract(ifBlock);
    createRegisterFunc(ifBlock);
}
 
开发者ID:conyx,项目名称:jenkins.py,代码行数:36,代码来源:MethodMaker.java

示例12: createMethWrappers

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
/**
 * Creates wrappers for non-abstract methods.
 */
private void createMethWrappers() {
    for (int i = 0; i < nonabstractMethods.size(); i++) {
        MethodDeclaration md = (MethodDeclaration)ASTNode.copySubtree(ast, nonabstractMethods.get(i));
        // set public modifier
        setPublic(md);
        // add to the TD body declarations
        td.bodyDeclarations().add(md);
        // add @Override annotation
        addOverride(md);
        // add initPython() call
        MethodInvocation mi = ast.newMethodInvocation();
        mi.setName(ast.newSimpleName("initPython"));
        md.getBody().statements().add(ast.newExpressionStatement(mi));
        // get pexec.execPython() statement
        Statement pexec = getExecStatement(md);
        // get pexec.isImplemented(id) expression
        Expression impl = getIsImplementedExpr(i);
        // get "return super.method(args)" statement
        Statement superSt = getSuperMethCall(md);
        // create if-else statement
        IfStatement ifSt = ast.newIfStatement();
        ifSt.setExpression(impl);
        Block ifBlock = ast.newBlock();
        ifBlock.statements().add(pexec);
        ifSt.setThenStatement(ifBlock);
        Block elseBlock = ast.newBlock();
        elseBlock.statements().add(superSt);
        ifSt.setElseStatement(elseBlock);
        md.getBody().statements().add(ifSt);
    }
}
 
开发者ID:conyx,项目名称:jenkins.py,代码行数:35,代码来源:MethodMaker.java

示例13: createQualifiedComparison

import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
/**
 * Creates a comparison of reference types.
 *
 * <pre>
 * if (this.a == null) {
 * 	if (other.a != null)
 * 		return false;
 * } else {
 * 	if (!this.a.equals(other.a))
 * 		return false;
 * }
 * </pre>
 * @param name the field name
 * @return the comparison statement
 */
private Statement createQualifiedComparison(String name) {
	InfixExpression newCondition= fAst.newInfixExpression();
	newCondition.setOperator(Operator.EQUALS);
	newCondition.setLeftOperand(getThisAccessForEquals(name));
	newCondition.setRightOperand(fAst.newNullLiteral());

	// THEN
	InfixExpression notEqNull= fAst.newInfixExpression();
	notEqNull.setOperator(Operator.NOT_EQUALS);
	notEqNull.setLeftOperand(getOtherAccess(name));
	notEqNull.setRightOperand(fAst.newNullLiteral());

	IfStatement thenPart= fAst.newIfStatement();
	thenPart.setExpression(notEqNull);
	thenPart.setThenStatement(getThenStatement(getReturnFalse()));

	Block thenPart2= fAst.newBlock();
	thenPart2.statements().add(thenPart);

	// ELSE
	MethodInvocation invoc= fAst.newMethodInvocation();
	invoc.setName(fAst.newSimpleName(METHODNAME_EQUALS));
	invoc.setExpression(getThisAccessForEquals(name));
	invoc.arguments().add(getOtherAccess(name));

	PrefixExpression pe= fAst.newPrefixExpression();
	pe.setOperator(PrefixExpression.Operator.NOT);
	pe.setOperand(invoc);

	IfStatement elsePart= fAst.newIfStatement();
	elsePart.setExpression(pe);
	elsePart.setThenStatement(getThenStatement(getReturnFalse()));

	// ALL
	IfStatement isNull= fAst.newIfStatement();
	isNull.setExpression(newCondition);
	isNull.setThenStatement(thenPart2);
	isNull.setElseStatement(elsePart);

	return isNull;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:57,代码来源:GenerateHashCodeEqualsOperation.java


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