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


Java CtIf.getElseStatement方法代码示例

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


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

示例1: elementCoverage

import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
public double elementCoverage(CtElement elem) {
    if(elem instanceof CtIf) {
        CtIf ctIf = (CtIf) elem;
        if(ctIf.getElseStatement() != null) {
            return (coverage(ctIf.getThenStatement()) + coverage(ctIf.getElseStatement())) / 2d;
        } else {
            return coverage(ctIf.getThenStatement());
        }
    }

    if(elem instanceof CtLoop) {
        CtLoop loop = (CtLoop) elem;
        if(loop.getBody() != null) {
            return coverage(loop.getBody());
        } else {
            return coverage(loop);
        }
    }

    return coverage(elem);
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:22,代码来源:CoverageReport.java

示例2: process

import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
/**
 * Build a control flow graph from a If statement
 */
private SubGraph process(CtIf ifConditional) {
	// Get data
	CtExpression<Boolean> condition = ifConditional.getCondition();
	CtUnaryOperator<Boolean> negCondition = factory.Core().createUnaryOperator();
	negCondition.setOperand(condition);
	negCondition.setKind(UnaryOperatorKind.NOT);
	// negCondition.setParent(condition);
	CtStatement thenPart = ifConditional.getThenStatement();
	CtStatement elsePart = ifConditional.getElseStatement();

	// Build the sub-graph
	SubGraph thenBlock = process(thenPart);
	ConditionalSolution thenCondition = Solver.solve(condition.toString());

	SubGraph res = new SubGraph(cfg);
	res.getEntry().addChild(thenBlock.getEntry(), condition);
	thenBlock.getExit().addChild(res.getExit(), null);

	// Do the same for else block
	if (elsePart != null) {
		SubGraph elseBlock = process(elsePart);
		ConditionalSolution elseCondition = Solver.solve("!(" + condition.toString() + ")");
		res.getEntry().addChild(elseBlock.getEntry(), negCondition);
		elseBlock.getExit().addChild(res.getExit(), null);
	} else {
		res.getEntry().addChild(res.getExit(), negCondition);
	}

	return res;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:34,代码来源:CfgBuilder.java

示例3: isEmptyIfStatement

import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
public boolean isEmptyIfStatement(final @Nullable CtIf iff) {
	if(iff == null) return false;
	final BasicFilter<CtStatement> filter = new BasicFilter<CtStatement>(CtStatement.class) {
		@Override
		public boolean matches(final CtStatement element) {
			return !(element instanceof CtBlock) && !(element instanceof CtCFlowBreak) && !(element instanceof CtSynchronized) && !(element instanceof CtAssert);
		}
	};

	return iff.getThenStatement() == null || iff.getThenStatement().getElements(filter).isEmpty() &&
		(iff.getElseStatement() == null || iff.getElseStatement().getElements(filter).isEmpty());
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:13,代码来源:SpoonHelper.java

示例4: getReplaceStmt

import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
protected CtIf getReplaceStmt(CtIf stmt) {
    Factory factory = getInputProgram().getFactory();
    CtIf clone = factory.Core().clone(stmt);

    if(stmt.getElseStatement() == null) {
        clone.setCondition(factory.Code().createLiteral(false));
    } else {
        if(containsOnlyReturn(stmt.getThenStatement())) {
            clone.setCondition(factory.Code().createLiteral(false));
        } else {
            clone.setCondition(factory.Code().createLiteral(true));
        }
    }
    return clone;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:16,代码来源:JsonRemoveParameterConditionInput.java

示例5: exploreConditionals

import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
public List<CtExpression<?>> exploreConditionals(CtCodeElement action, CtCodeElement parent) {

		CtUnaryOperator<Boolean> negCondition = factory.Core().createUnaryOperator();
		List<CtExpression<?>> res = new ArrayList<>();
		if (parent instanceof CtIf) {
			CtIf ctif = (CtIf) parent;
			CtStatement thenpart = ctif.getThenStatement();

			if (isContainedBy(action, thenpart)) {
				res.add(ctif.getCondition());
				return res;
			}
			List<CtExpression<?>> childCond = exploreConditionals(action, thenpart);
			if (!childCond.isEmpty()) {
				res.add(ctif.getCondition());
				res.addAll(exploreConditionals(action, thenpart));
			}
			CtStatement elsepart = ctif.getElseStatement();
			if (isContainedBy(action, elsepart)) {
				negCondition.setOperand(ctif.getCondition());
				negCondition.setKind(UnaryOperatorKind.NOT);
				res.add(negCondition);
				return res;
			}
			childCond = exploreConditionals(action, elsepart);
			if (!childCond.isEmpty()) {
				res.add(ctif.getCondition());
				res.addAll(exploreConditionals(action, elsepart));
			}
		} else if (parent instanceof CtWhile) {
			CtWhile while_ = (CtWhile) parent;
			res.add(while_.getLoopingExpression());
		} else if (parent instanceof CtFor) {
			CtFor for_ = (CtFor) parent;
			res.add(for_.getExpression());
		} else if (parent instanceof CtCase) {
			CtCase<?> case_ = (CtCase<?>) parent;
			res.add(case_.getCaseExpression());
		} else if (parent instanceof CtConditional) {// TODO: get the negation
														// too
			CtConditional<?> cond = (CtConditional<?>) parent;
			res.add(cond.getCondition());
		} else if (parent instanceof CtDo) {
			CtDo do_ = (CtDo) parent;
			res.add(do_.getLoopingExpression());
		} else if (parent instanceof CtSwitch) {
			CtSwitch<?> switch_ = (CtSwitch<?>) parent;
			res.add(switch_.getSelector());
		}

		return res;
	}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:53,代码来源:Command.java

示例6: getSurroundedBlock

import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
private List<CtCodeElement> getSurroundedBlock(Action cmd, CtExpression<?> cond) {
	List<CtCodeElement> res = new ArrayList<>();
	CtUnaryOperator<Boolean> negation = factory.Core().createUnaryOperator();

	List<CtCodeElement> stmts = cmd.getStatements();
	CtCodeElement stmt1 = stmts.get(0);
	CtElement parent = stmt1;
	if (stmt1 != null) {
		try {
			parent = stmt1.getParent();
			while (parent != null && parent != cmd.getSource()) {
				if (parent instanceof CtIf) {
					CtIf if_ = (CtIf) parent;
					negation.setOperand(if_.getCondition());
					negation.setKind(UnaryOperatorKind.NOT);
					if (if_.getCondition() == cond) {
						CtStatement thenPart = if_.getThenStatement();
						res.add(thenPart);
						return res;
					} else if (negation.toString().equals(cond.toString())) {// Handle
																				// the
																				// else
																				// part
																				// as
																				// a
																				// command
						CtStatement elsePart = if_.getElseStatement();
						res.add(elsePart);
						return res;
					}
				} else if (parent instanceof CtWhile) {
					CtWhile while_ = (CtWhile) parent;
					if (while_.getLoopingExpression() == cond) {
						res.add(while_.getBody());
						return res;
					}
				} else if (parent instanceof CtFor) {
					CtFor for_ = (CtFor) parent;
					if (for_.getExpression() == cond) {
						res.add(for_.getBody());
						return res;
					}
				} else if (parent instanceof CtCase) {
					CtCase<?> case_ = (CtCase<?>) parent;
					if (case_.getCaseExpression() == cond) {
						res.addAll(case_.getStatements());
						return res;
					}
				} else if (parent instanceof CtConditional) {
					CtConditional<?> conditional = (CtConditional<?>) parent;
					if (conditional.getCondition() == cond) {
						res.add(conditional.getThenExpression());
						return res;
					}
				} else if (parent instanceof CtDo) {
					CtDo do_ = (CtDo) parent;
					if (do_.getLoopingExpression() == cond) {
						res.add(do_.getBody());
						return res;
					}
				} else if (parent instanceof CtSwitch) {
					CtSwitch<?> switch_ = (CtSwitch<?>) parent;
					if (switch_.getSelector() == cond) {
						res.addAll(switch_.getCases());
						return res;
					}
				}
				parent = parent.getParent();
			}
		} catch (ParentNotInitializedException e) {
			System.out.println("Parent init exeption: " + parent);
		}
	}
	return null;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:76,代码来源:Command.java

示例7: getsuperConditionalStatements

import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
/**
 * Explores the parent of the given statement up to the method definition to identify all the conditional statements that
 * lead to the given one.
 * @param condStat The conditional statement to use.
 * @return The list of all the conditional statements.
 */
private List<CommandConditionEntry> getsuperConditionalStatements(final @NotNull CtElement condStat) {
	CtElement currElt = condStat;
	CtElement parent = currElt.getParent();
	List<CommandConditionEntry> conds = new ArrayList<>();

	// Exploring the parents to identify the conditional statements
	while(parent!=null) {
		if(parent instanceof CtIf) {
			CtIf ctif = (CtIf) parent;
			CtExpression<Boolean> condition = ctif.getCondition();

			// Identifying the block of the if used and adding a condition.
			if(ctif.getThenStatement()==currElt) {
				conds.add(new CommandConditionEntry(condition));
			}else {
				if(ctif.getElseStatement() == currElt) {
					conds.add(new CommandConditionEntry(condition, SpoonHelper.INSTANCE.negBoolExpression(condition)));
				}else {
					LOG.log(Level.SEVERE, "Cannot find the origin of the statement in the if statement " +
						SpoonHelper.INSTANCE.formatPosition(parent.getPosition()) + " + : " + parent);
				}
			}
		}else if(parent instanceof CtSwitch<?>) {
			final CtElement elt = currElt;
			CtSwitch<?> ctswitch = (CtSwitch<?>) parent;
			// Identifying the case statement used and creating a condition.
			// The use of orElse(null) is mandatory here (berk!) to avoid a strange compilation bug with generics and casting.
			CtCase<?> caz = ctswitch.getCases().stream().filter(cas -> cas == elt).findFirst().orElse(null);

			if(caz==null) {
				LOG.log(Level.SEVERE, "Cannot find the origin of the statement " + elt + " in the switch statement " +
						SpoonHelper.INSTANCE.formatPosition(parent.getPosition()) +  " + : " + parent);
			}else {
				conds.add(new CommandConditionEntry(caz.getCaseExpression(),
													SpoonHelper.INSTANCE.createEqExpressionFromSwitchCase(ctswitch, caz)));
			}
		}

		currElt = parent;
		parent = parent.getParent();
	}

	return conds;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:51,代码来源:CommandAnalyser.java


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