spoon.reflect.code.CtCFlowBreak Java Examples

The following examples show how to use spoon.reflect.code.CtCFlowBreak. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpecialStatementFixSpaceProcessor.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void process(CtStatement element) {

	if (element instanceof CtIf) {
		add(((CtIf) element).getCondition());
	} else if (element instanceof CtFor) {
		add(((CtFor) element).getExpression());
	} else if (element instanceof CtWhile) {
		add(((CtWhile) element).getLoopingExpression());
	} else if (element instanceof CtDo) {
		add(((CtDo) element).getLoopingExpression());
	} else if (element instanceof CtThrow) {
		add(((CtThrow) element).getThrownExpression());
	} else if (element instanceof CtInvocation && (element.getParent() instanceof CtBlock)) {
		add(element);
	} else if (element instanceof CtAssignment || element instanceof CtConstructorCall
			|| element instanceof CtCFlowBreak || element instanceof CtLocalVariable) {
		add(element);
	}

}
 
Example #2
Source File: LoopExpressionMetaMutator.java    From metamutator with GNU General Public License v3.0 5 votes vote down vote up
public String breakOrReturn(CtLoop candidate) {
	Filter<CtCFlowBreak> filter = new ReturnOrThrowFilter();
	if(candidate.getBody().getElements(filter).size() > 0) {
		return candidate.getBody().getElements(filter).get(0).toString() + ";";
	}else {
		return "break;";
	}
}
 
Example #3
Source File: StatementDeletionMetaMutator.java    From metamutator with GNU General Public License v3.0 4 votes vote down vote up
private void mutateOperator(final CtStatement expression) {
	
	
	/*if (alreadyInHotsSpot(expression)) {
		System.out
				.println(String
						.format("Expression '%s' ignored because it is included in previous hot spot",
								expression));
		return;
	}*/
	int thisIndex = ++selectorIndex;
	
	ACTIVABLE kind = ACTIVABLE.ENABLED;
	String expressionContent =  String.format("("+ PREFIX + "%s.is(%s))",
			thisIndex, kind.getClass().getCanonicalName()+"."+kind.name());
	
	//create IfChoice with right condition
	CtIf ifChoice = getFactory().Core().createIf();
	CtCodeSnippetExpression expIf = getFactory().Code().createCodeSnippetExpression(expressionContent);
	ifChoice.setCondition(expIf);
		
	
	
	//create block from a clone of expression
	CtStatement exp2 = getFactory().Core().clone(expression);
	CtBlock thenBlock = getFactory().Code().createCtBlock(exp2);
	
	//set if and replace the expression with the new if
	ifChoice.setThenStatement(thenBlock);
	expression.replace(ifChoice);
	
	//to be sure
	ifChoice.getParent().updateAllParentsBelow();
	
	//if there are return or throws, set else with value of return.
	Filter<CtCFlowBreak> filterReturn = new ReturnOrThrowFilter();
	if(!thenBlock.getElements(filterReturn).isEmpty()){
		SetElseStatementWithReturn(ifChoice);
	}

	
	//to avoid to delete assignement in statement, we assign a default value to all local variable.
	Filter<CtLocalVariable> filterLocalVariable =  new TypeFilter<CtLocalVariable>(CtLocalVariable.class);
	CtMethod method = ifChoice.getParent(CtMethod.class);
	if(method != null && !method.getElements(filterLocalVariable).isEmpty()){
		for(CtLocalVariable var : method.getElements(filterLocalVariable)){
			if(var.getAssignment() == null){
				//create right side expression from template.
				Class classOfAssignment = var.getType().getActualClass();
				CtLiteral rightHand = null;
				
				//Particular case of ForEach (int x : numbers) can't be (int x = 0 : numbers)
				if(var.getParent() instanceof CtForEach){
					continue;
				}
				if(PrimitiveTemplateExpressions.containsKey(classOfAssignment)){
					CtLiteral templateExpression = PrimitiveTemplateExpressions.get(classOfAssignment);
					rightHand = getFactory().Core().clone(templateExpression);
				}else{
					rightHand = getFactory().createLiteral().setValue(null);
				}
				var.setAssignment(rightHand);
			}
		}
	}
	
	Selector.generateSelector(expression, ACTIVABLE.ENABLED, thisIndex, ActivableSet, PREFIX);
	//hotSpots.add(expression);

}
 
Example #4
Source File: FlowBreakFixSpaceProcessor.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void process(CtCFlowBreak element) {
	
	super.add(element);
}