本文整理汇总了Java中org.eclipse.jdt.core.dom.IfStatement.getThenStatement方法的典型用法代码示例。如果您正苦于以下问题:Java IfStatement.getThenStatement方法的具体用法?Java IfStatement.getThenStatement怎么用?Java IfStatement.getThenStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.IfStatement
的用法示例。
在下文中一共展示了IfStatement.getThenStatement方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSingleControlStatementWithoutBlock
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private boolean isSingleControlStatementWithoutBlock() {
List<Statement> statements = fDeclaration.getBody().statements();
int size = statements.size();
if (size != 1) return false;
Statement statement = statements.get(size - 1);
int nodeType = statement.getNodeType();
if (nodeType == ASTNode.IF_STATEMENT) {
IfStatement ifStatement = (IfStatement) statement;
return !(ifStatement.getThenStatement() instanceof Block)
&& !(ifStatement.getElseStatement() instanceof Block);
} else if (nodeType == ASTNode.FOR_STATEMENT) {
return !(((ForStatement) statement).getBody() instanceof Block);
} else if (nodeType == ASTNode.WHILE_STATEMENT) {
return !(((WhileStatement) statement).getBody() instanceof Block);
}
return false;
}
示例2: preNext
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
public boolean preNext(IfStatement curElement) {
Statement thenStatement = curElement.getThenStatement();
Statement elseStatement = curElement.getElseStatement();
Expression condition = curElement.getExpression();
if (elseStatement == null) {
compiler.println("opt " + condition.toString());
return true;
} else {
compiler.println("alt " + condition.toString());
thenStatement.accept(compiler);
if (elseStatement instanceof IfStatement) {
processAltStatement((IfStatement) elseStatement);
} else {
compiler.println("else");
elseStatement.accept(compiler);
}
return false;
}
}
示例3: processAltStatement
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private void processAltStatement(IfStatement statement) {
Statement thenStatement = statement.getThenStatement();
Statement elseStatement = statement.getElseStatement();
Expression condition = statement.getExpression();
compiler.println("else " + condition.toString());
thenStatement.accept(compiler);
if (elseStatement != null) {
if (elseStatement instanceof IfStatement) {
processAltStatement((IfStatement) elseStatement);
} else {
compiler.println("else");
elseStatement.accept(compiler);
}
}
}
示例4: isSingleControlStatementWithoutBlock
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private boolean isSingleControlStatementWithoutBlock() {
List<Statement> statements= fDeclaration.getBody().statements();
int size= statements.size();
if (size != 1)
return false;
Statement statement= statements.get(size - 1);
int nodeType= statement.getNodeType();
if (nodeType == ASTNode.IF_STATEMENT) {
IfStatement ifStatement= (IfStatement) statement;
return !(ifStatement.getThenStatement() instanceof Block)
&& !(ifStatement.getElseStatement() instanceof Block);
} else if (nodeType == ASTNode.FOR_STATEMENT) {
return !(((ForStatement)statement).getBody() instanceof Block);
} else if (nodeType == ASTNode.WHILE_STATEMENT) {
return !(((WhileStatement)statement).getBody() instanceof Block);
}
return false;
}
示例5: visit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
public boolean visit(IfStatement node) {
Statement thenStmt = node.getThenStatement();
Statement elseStmt = node.getElseStatement();
Expression condExpr = node.getExpression();
String thenStr = (thenStmt.toString()).replace('\n', ' ');
String elseStr = "";
if (elseStmt != null) {
elseStr = (elseStmt.toString()).replace('\n', ' ');
}
if (mtbStack.isEmpty()) // not part of a method
return true;
IMethodBinding mtb = mtbStack.peek();
String methodStr = getQualifiedName(mtb);
String condStr = condExpr.toString();
condStr = edit_str(condStr);
thenStr = edit_str(thenStr);
elseStr = edit_str(elseStr);
// make conditional fact
try {
facts.add(Fact.makeConditionalFact(condStr, thenStr, elseStr,
methodStr));
} catch (Exception e) {
System.err.println("Cannot resolve conditional \""
+ condExpr.toString() + "\"");
System.out.println("ifStmt: " + thenStr);
System.out.println("elseStmt: " + elseStr);
System.err.println(e.getMessage());
}
return true;
}
示例6: endVisit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
public void endVisit(IfStatement node) {
if (skipNode(node)) {
return;
}
Statement thenPart = node.getThenStatement();
Statement elsePart = node.getElseStatement();
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);
}
}
示例7: visit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
public boolean visit(IfStatement node)
{
Statement thenStmt = node.getThenStatement();
Statement elseStmt = node.getElseStatement();
Expression condExpr = node.getExpression();
String thenStr = thenStmt.toString().replace('\n', ' ');
String elseStr = "";
if (elseStmt != null) {
elseStr = elseStmt.toString().replace('\n', ' ');
}
if (this.mtbStack.isEmpty()) {
return true;
}
IMethodBinding mtb = (IMethodBinding)this.mtbStack.peek();
String methodStr = getQualifiedName(mtb);
String condStr = condExpr.toString();
condStr = edit_str(condStr);
thenStr = edit_str(thenStr);
elseStr = edit_str(elseStr);
try
{
this.facts.add(Fact.makeConditionalFact(condStr, thenStr, elseStr,
methodStr));
}
catch (Exception e)
{
System.err.println("Cannot resolve conditional \"" +
condExpr.toString() + "\"");
System.out.println("ifStmt: " + thenStr);
System.out.println("elseStmt: " + elseStr);
System.err.println(e.getMessage());
}
return true;
}
示例8: endVisit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
public void endVisit(IfStatement node) {
if (skipNode(node)) return;
Statement thenPart = node.getThenStatement();
Statement elsePart = node.getElseStatement();
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);
}
}
示例9: endVisit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
public void endVisit(IfStatement node) {
if (skipNode(node))
return;
Statement thenPart= node.getThenStatement();
Statement elsePart= node.getElseStatement();
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);
}
}
示例10: getInverseIfProposals
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private static boolean getInverseIfProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
if (!(covering instanceof IfStatement)) {
return false;
}
IfStatement ifStatement= (IfStatement) covering;
if (ifStatement.getElseStatement() == null) {
return false;
}
// we could produce quick assist
if (resultingCollections == null) {
return true;
}
//
AST ast= covering.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
Statement thenStatement= ifStatement.getThenStatement();
Statement elseStatement= ifStatement.getElseStatement();
// prepare original nodes
Expression inversedExpression= getInversedExpression(rewrite, ifStatement.getExpression());
Statement newElseStatement= (Statement) rewrite.createMoveTarget(thenStatement);
Statement newThenStatement= (Statement) rewrite.createMoveTarget(elseStatement);
// set new nodes
rewrite.set(ifStatement, IfStatement.EXPRESSION_PROPERTY, inversedExpression, null);
if (elseStatement instanceof IfStatement) {// bug 79507 && bug 74580
Block elseBlock= ast.newBlock();
elseBlock.statements().add(newThenStatement);
newThenStatement= elseBlock;
}
rewrite.set(ifStatement, IfStatement.THEN_STATEMENT_PROPERTY, newThenStatement, null);
rewrite.set(ifStatement, IfStatement.ELSE_STATEMENT_PROPERTY, newElseStatement, null);
// add correction proposal
String label= CorrectionMessages.AdvancedQuickAssistProcessor_inverseIf_description;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.INVERSE_IF_STATEMENT, image);
resultingCollections.add(proposal);
return true;
}
示例11: getInverseIfProposals
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private static boolean getInverseIfProposals(IInvocationContext context, ASTNode covering, Collection<ICommandAccess> resultingCollections) {
if (!(covering instanceof IfStatement)) {
return false;
}
IfStatement ifStatement= (IfStatement) covering;
if (ifStatement.getElseStatement() == null) {
return false;
}
// we could produce quick assist
if (resultingCollections == null) {
return true;
}
//
AST ast= covering.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
Statement thenStatement= ifStatement.getThenStatement();
Statement elseStatement= ifStatement.getElseStatement();
// prepare original nodes
Expression inversedExpression= getInversedExpression(rewrite, ifStatement.getExpression());
Statement newElseStatement= (Statement) rewrite.createMoveTarget(thenStatement);
Statement newThenStatement= (Statement) rewrite.createMoveTarget(elseStatement);
// set new nodes
rewrite.set(ifStatement, IfStatement.EXPRESSION_PROPERTY, inversedExpression, null);
if (elseStatement instanceof IfStatement) {// bug 79507 && bug 74580
Block elseBlock= ast.newBlock();
elseBlock.statements().add(newThenStatement);
newThenStatement= elseBlock;
}
rewrite.set(ifStatement, IfStatement.THEN_STATEMENT_PROPERTY, newThenStatement, null);
rewrite.set(ifStatement, IfStatement.ELSE_STATEMENT_PROPERTY, newElseStatement, null);
// add correction proposal
String label= CorrectionMessages.AdvancedQuickAssistProcessor_inverseIf_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,代码行数:41,代码来源:AdvancedQuickAssistProcessor.java
示例12: visit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public boolean visit(QIf statement) {
Block block = blocks.peek();
IfStatement ifSt = ast.newIfStatement();
QPredicateExpression condition = expressionParser.parsePredicate(statement.getCondition());
Expression expression = null;
if (CompilationContextHelper.isPrimitive(compilationUnit, condition))
expression = buildExpression(ast, condition, Boolean.class);
else {
expression = buildExpression(ast, condition, Boolean.class);
}
// expression = buildExpression(ast, condition, null);
ifSt.setExpression(expression);
block.statements().add(ifSt);
// then
if (statement.getThen() != null) {
Block thenBlock = null;
if (ifSt.getThenStatement() instanceof Block)
thenBlock = (Block) ifSt.getThenStatement();
else {
thenBlock = ast.newBlock();
ifSt.setThenStatement(thenBlock);
}
blocks.push(thenBlock);
statement.getThen().accept(this);
blocks.pop();
}
// else
if (statement.getElse() != null) {
Block elseBlock = null;
if (ifSt.getElseStatement() instanceof Block)
elseBlock = (Block) ifSt.getElseStatement();
else {
elseBlock = ast.newBlock();
ifSt.setElseStatement(elseBlock);
}
// walk else
blocks.push(elseBlock);
statement.getElse().accept(this);
blocks.pop();
}
// interrupt navigation
return false;
}