本文整理汇总了Java中org.eclipse.jdt.core.dom.IfStatement.getElseStatement方法的典型用法代码示例。如果您正苦于以下问题:Java IfStatement.getElseStatement方法的具体用法?Java IfStatement.getElseStatement怎么用?Java IfStatement.getElseStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.IfStatement
的用法示例。
在下文中一共展示了IfStatement.getElseStatement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getAddElseProposals
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private static boolean getAddElseProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
if (!(node instanceof IfStatement)) {
return false;
}
IfStatement ifStatement= (IfStatement) node;
if (ifStatement.getElseStatement() != null) {
return false;
}
if (resultingCollections == null) {
return true;
}
AST ast= node.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
Block body= ast.newBlock();
rewrite.set(ifStatement, IfStatement.ELSE_STATEMENT_PROPERTY, body, null);
String label= CorrectionMessages.QuickAssistProcessor_addelseblock_description;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.ADD_ELSE_BLOCK, image);
resultingCollections.add(proposal);
return true;
}
示例6: getAddElseProposals
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
private static boolean getAddElseProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
if (!(node instanceof IfStatement)) {
return false;
}
IfStatement ifStatement= (IfStatement) node;
if (ifStatement.getElseStatement() != null) {
return false;
}
if (resultingCollections == null) {
return true;
}
AST ast= node.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
Block body= ast.newBlock();
rewrite.set(ifStatement, IfStatement.ELSE_STATEMENT_PROPERTY, body, null);
String label= CorrectionMessages.QuickAssistProcessor_addelseblock_description;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image);
resultingCollections.add(proposal);
return true;
}
示例7: visit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
/**
* 'if(' expression ') {' thenStatement '}' ['else {' elseStatement '}']
*/
@Override
public boolean visit(final IfStatement node)
{
final int lineNo = lineStart(node);
// dependence id
final LineKind kind = node.getElseStatement() == null ? LK_IF_THEN : LK_IF_THEN_ELSE;
// new dependence
final IResolvedLine rd = createDependence(kind, lineNo, mdg.parent());
// append control dependences
appendDependences(rd, node.getExpression(), null, false);
// recursively append "then" dependences
appendRecursive(lineNo, rd, node.getThenStatement());
// recursively append "else" dependences
if (node.getElseStatement() != null)
{
appendRecursive(lineNo, rd, node.getElseStatement());
}
// do not visit children
return false;
}
示例8: visit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
public boolean visit(IfStatement node) {
//System.out.println("Found: " + node.getClass());
print("if (");
node.getExpression().accept(this);
println(") {");
indent++;
node.getThenStatement().accept(this);
indent--;
if (node.getElseStatement() == null) {
println("}");
} else {
if (node.getElseStatement() instanceof IfStatement) {
print("} else ");
node.getElseStatement().accept(this);
} else {
println("} else {");
indent++;
node.getElseStatement().accept(this);
indent--;
println("}");
}
}
return false;
}
示例9: 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;
}
示例10: 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);
}
}
示例11: 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;
}
示例12: visit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
public boolean visit(IfStatement statement) {
handle(statement.getThenStatement(), IfStatement.THEN_STATEMENT_PROPERTY);
Statement elseStatement = statement.getElseStatement();
if (elseStatement != null && !(elseStatement instanceof IfStatement)) {
handle(elseStatement, IfStatement.ELSE_STATEMENT_PROPERTY);
}
return super.visit(statement);
}
示例13: 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);
}
}
示例14: 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);
}
}
示例15: visit
import org.eclipse.jdt.core.dom.IfStatement; //导入方法依赖的package包/类
@Override
public boolean visit(IfStatement statement) {
handle(statement.getThenStatement(), IfStatement.THEN_STATEMENT_PROPERTY);
Statement elseStatement= statement.getElseStatement();
if (elseStatement != null && !(elseStatement instanceof IfStatement)) {
handle(elseStatement, IfStatement.ELSE_STATEMENT_PROPERTY);
}
return super.visit(statement);
}