spoon.reflect.code.CtWhile Java Examples

The following examples show how to use spoon.reflect.code.CtWhile. 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: VariableResolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public static List<CtVariableAccess> collectVariableReadIgnoringBlocks(CtElement element) {

		if (element instanceof CtIf) {
			return collectVariableRead(((CtIf) element).getCondition());
		}
		if (element instanceof CtWhile) {
			return collectVariableRead(((CtWhile) element).getLoopingExpression());
		}

		if (element instanceof CtFor) {
			return collectVariableRead(((CtFor) element).getExpression());
		}

		return collectVariableRead(element);

	}
 
Example #3
Source File: VariableResolver.java    From coming with MIT License 6 votes vote down vote up
public static List<CtVariableAccess> collectVariableAccessIgnoringBlocks(CtElement element) {

		if (element instanceof CtIf) {
			return collectVariableAccess(((CtIf) element).getCondition());
		}
		if (element instanceof CtWhile) {
			return collectVariableAccess(((CtWhile) element).getLoopingExpression());
		}

		if (element instanceof CtFor) {
			return collectVariableAccess(((CtFor) element).getExpression());
		}

		return collectVariableAccess(element);

	}
 
Example #4
Source File: VariableResolver.java    From coming with MIT License 6 votes vote down vote up
public static List<CtVariableAccess> collectVariableReadIgnoringBlocks(CtElement element) {

		if (element instanceof CtIf) {
			return collectVariableRead(((CtIf) element).getCondition());
		}
		if (element instanceof CtWhile) {
			return collectVariableRead(((CtWhile) element).getLoopingExpression());
		}

		if (element instanceof CtFor) {
			return collectVariableRead(((CtFor) element).getExpression());
		}

		return collectVariableRead(element);

	}
 
Example #5
Source File: CodeElementInfo.java    From coming with MIT License 6 votes vote down vote up
private CtElement retrieveElementToStudy(CtElement element) {

		if (element instanceof CtIf) {
			return (((CtIf) element).getCondition());
		} else if (element instanceof CtWhile) {
			return (((CtWhile) element).getLoopingExpression());
		} else if (element instanceof CtFor) {
			return (((CtFor) element).getExpression());
		} else if (element instanceof CtDo) {
			return (((CtDo) element).getLoopingExpression());
		} else if (element instanceof CtForEach) {
			return (((CtForEach) element).getExpression());
		} else if (element instanceof CtSwitch) {
			return (((CtSwitch) element).getSelector());
		} else
			return (element);
	}
 
Example #6
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public static List<CtVariableAccess> collectVariableAccessIgnoringBlocks(CtElement element) {

		if (element instanceof CtIf) {
			return collectVariableAccess(((CtIf) element).getCondition());
		}
		if (element instanceof CtWhile) {
			return collectVariableAccess(((CtWhile) element).getLoopingExpression());
		}

		if (element instanceof CtFor) {
			return collectVariableAccess(((CtFor) element).getExpression());
		}

		return collectVariableAccess(element);

	}
 
Example #7
Source File: AbstractCodeAnalyzer.java    From coming with MIT License 6 votes vote down vote up
public CtElement retrieveElementToStudy(CtElement element) {

		if (element instanceof CtIf) {
			return (((CtIf) element).getCondition());
		} else if (element instanceof CtWhile) {
			return (((CtWhile) element).getLoopingExpression());
		} else if (element instanceof CtFor) {
			return (((CtFor) element).getExpression());
		} else if (element instanceof CtDo) {
			return (((CtDo) element).getLoopingExpression());
		} else if (element instanceof CtForEach) {
			return (((CtForEach) element).getExpression());
		} else if (element instanceof CtSwitch) {
			return (((CtSwitch) element).getSelector());
		} else
			return (element);
	}
 
Example #8
Source File: TransformStrategy.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<String> transform () {
	CtStatement targetStmt = (CtStatement) this.modificationPoint.getCodeElement();
	if (targetStmt instanceof CtInvocation)
		this.visitCtInvocation((CtInvocation) targetStmt);
	else if (targetStmt instanceof CtConstructorCall)
		this.visitCtConstructorCall((CtConstructorCall) targetStmt);
	else if (targetStmt instanceof CtIf)
		this.visitCtIf ((CtIf)targetStmt);
	else if (targetStmt instanceof CtReturn)
		this.visitCtReturn((CtReturn) targetStmt);
	else if (targetStmt instanceof CtSwitch)
		this.visitCtSwitch((CtSwitch) targetStmt);
	else if (targetStmt instanceof CtCase)
		this.visitCtCase((CtCase) targetStmt);
	else if (targetStmt instanceof CtAssignment)
		this.visitCtAssignment((CtAssignment) targetStmt);
	else if (targetStmt instanceof CtAssert)
		this.visitCtAssert((CtAssert) targetStmt);
	else if (targetStmt instanceof CtFor)
		this.visitCtFor((CtFor) targetStmt);
	else if (targetStmt instanceof CtForEach)
		this.visitCtForEach((CtForEach) targetStmt);
	else if (targetStmt instanceof CtWhile)
		this.visitCtWhile((CtWhile) targetStmt);
	else if (targetStmt instanceof CtUnaryOperator)
		this.visitCtUnaryOperator((CtUnaryOperator) targetStmt);
	else if (targetStmt instanceof CtSynchronized)
		this.visitCtSynchronized((CtSynchronized) targetStmt);

	return list;
}
 
Example #9
Source File: TransformStrategy.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void visitCtWhile(CtWhile whileLoop) {
	super.visitCtWhile(whileLoop);
	
	@SuppressWarnings("rawtypes")
	CtExpression exper=whileLoop.getLoopingExpression();
	if (candidates.containsKey(exper)) {
		whileLoop.setLoopingExpression(candidates.get(exper));
		saveSketchAndSynthesize();
		whileLoop.setLoopingExpression(exper);
		resoreDiskFile();
	}
}
 
Example #10
Source File: ConditionRemoveTransform.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<String> transform() {
	CtStatement targetStmt = (CtStatement) this.modificationPoint.getCodeElement();
	if (targetStmt instanceof CtIf)
		this.visitCtIf ((CtIf)targetStmt);
	else if (targetStmt instanceof CtWhile)
		this.visitCtWhile((CtWhile) targetStmt);
	return list;
}
 
Example #11
Source File: ConditionMutationTransform.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<String> transform() {
	CtStatement targetStmt = (CtStatement) this.modificationPoint.getCodeElement();
	if (targetStmt instanceof CtIf)
		this.visitCtIf ((CtIf)targetStmt);
	else if (targetStmt instanceof CtWhile)
		this.visitCtWhile((CtWhile) targetStmt);
	return list;
}
 
Example #12
Source File: LoopExpressionFixSpaceProcessor.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(CtLoop element) {
	if(element instanceof CtFor){
		addExpressionAndSubexpressions(((CtFor)element).getExpression());
	}
	if(element instanceof CtWhile){
		addExpressionAndSubexpressions(((CtWhile)element).getLoopingExpression());
	}
	if(element instanceof CtDo){
		addExpressionAndSubexpressions(((CtDo)element).getLoopingExpression());
	}
	
}
 
Example #13
Source File: VariableAnalyzer.java    From coming with MIT License 5 votes vote down vote up
public CtElement retrieveExpressionToStudy(CtElement element) {

			if (element instanceof CtIf) {
				return (((CtIf) element).getCondition());
			} else if (element instanceof CtWhile) {
				return (((CtWhile) element).getLoopingExpression());
			} else if (element instanceof CtFor) {
				return (((CtFor) element).getExpression());
			} else if (element instanceof CtForEach) {
				return (((CtForEach) element).getExpression());
			}  else
				return (element);
		}
 
Example #14
Source File: VariableAnalyzer.java    From coming with MIT License 5 votes vote down vote up
private boolean whetherConditionalStat(CtElement input) {
	
	if(input instanceof CtIf || input instanceof CtWhile || input instanceof CtFor || input
			instanceof CtForEach)
		return true;
	else return false;	
}
 
Example #15
Source File: InfinitelTest.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
private Map<String, CtWhile> loopsByMethodIn(File[] sourceFiles, int numberOfLoops) {
	Factory model = SpoonModelLibrary.modelFor(sourceFiles);
	CtPackage root = model.Package().getRootPackage();
	Collection<CtWhile> elements = SpoonElementLibrary.allChildrenOf(root, CtWhile.class);
	assertEquals(numberOfLoops, elements.size());
	Map<String, CtWhile> byMethod = MetaMap.newHashMap();
	for (CtWhile loop : elements) {
		String methodName = loop.getParent(CtMethod.class).getSimpleName();
		byMethod.put(methodName, loop);
	}
	return byMethod;
}
 
Example #16
Source File: InfinitelTest.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void unbreakableLoops() {
	Infinitel infinitel = infinitel(1);
	ProjectMonitorImplanter implanter = new ProjectMonitorImplanter(0);
	Map<String, CtWhile> loops = loopsByMethodIn(infinitel.getNopolContext().getProjectSources(), 5);
	assertFalse(implanter.isUnbreakable(loops.get("loopResult")));
	assertFalse(implanter.isUnbreakable(loops.get("fixableInfiniteLoop")));
	assertFalse(implanter.isUnbreakable(loops.get("binomialTest")));
	assertTrue(implanter.isUnbreakable(loops.get("unfixableInfiniteLoop")));
	assertTrue(implanter.isUnbreakable(loops.get("otherUnfixableInfiniteLoop")));
}
 
Example #17
Source File: ProjectMonitorImplanter.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
protected While newLoop(CtWhile loopStatement) {
    While loop = new While(loopStatement);
    if (isUnbreakable(loopStatement)) {
        loop.setUnbreakable();
    }
    return loop;
}
 
Example #18
Source File: ProjectMonitorImplanter.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
public boolean isUnbreakable(CtWhile loopStatement) {
    CtMethod<?> correspondingMethod = loopStatement.getParent(CtMethod.class);
    if (SpoonStatementLibrary.isLastStatementOfMethod(loopStatement)) {
        return !SpoonReferenceLibrary.isVoidType(correspondingMethod.getType());
    }
    return false;
}
 
Example #19
Source File: ProjectMonitorImplanter.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(CtWhile loopStatement) {
    While loop = newLoop(loopStatement);
    LoopMonitor loopMonitor = LoopMonitor.newInstance(loop, threshold());
    RuntimeValues<Boolean> newRuntimeValues = RuntimeValues.newInstance();
    submonitors().put(loop, loopMonitor);
    runtimeValues().put(loop, newRuntimeValues);
    LoopInstrumenter.instrument(loopMonitor, newRuntimeValues);
}
 
Example #20
Source File: SpoonModelLibrary.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public static void setLoopBody(CtWhile loop, CtStatement loopBody) {
    loopBody = asBlock(loopBody, loop);
    loop.setBody(loopBody);
}
 
Example #21
Source File: LabelFinder.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
@Override
public void visitCtWhile(CtWhile e) {
	label = "while";
}
 
Example #22
Source File: ConditionRemoveTransform.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitCtWhile(CtWhile whileLoop) {
	super.visitCtWhile(whileLoop);
}
 
Example #23
Source File: ConditionMutationTransform.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitCtWhile(CtWhile whileLoop) {
	super.visitCtWhile(whileLoop);
	fetchCOND(whileLoop);
}
 
Example #24
Source File: BinaryOperatorAnalyzer.java    From coming with MIT License 4 votes vote down vote up
private void analyzeBinaryOperatorCompareInCondition (CtElement wholeoriginal, CtBinaryOperator operatorunderstudy, int operatorindex, Cntx<Object> context) {
	
	boolean whethercompareincondition = false; 
	
       if(wholeoriginal instanceof CtIf || wholeoriginal instanceof CtWhile || wholeoriginal instanceof CtFor 
       	|| wholeoriginal instanceof CtDo || wholeoriginal instanceof CtForEach || wholeoriginal instanceof CtSwitch) {
       	
   		BinaryOperatorKind operatorkind = operatorunderstudy.getKind();

   		if (compareOperator.contains(operatorkind))
   			whethercompareincondition = true;
       }
	
       writeGroupedInfo(context, Integer.toString(operatorindex)+"_"+operatorunderstudy, CodeFeatures.O4_COMPARE_IN_CONDITION, 
			whethercompareincondition, "FEATURES_BINARYOPERATOR");
}
 
Example #25
Source File: LogicalExpressionAnalyzer.java    From coming with MIT License 4 votes vote down vote up
@Override
public void visitCtWhile(CtWhile whileLoop) {
	toScan = whileLoop.getLoopingExpression();
}
 
Example #26
Source File: ProjectMonitorImplanter.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isToBeProcessed(CtWhile loopStatement) {
    return true;
}
 
Example #27
Source File: SpoonModelLibrary.java    From nopol with GNU General Public License v2.0 4 votes vote down vote up
public static void setLoopingCondition(CtWhile loop, CtExpression<Boolean> loopingCondition) {
    setParent(loop, loopingCondition);
    loop.setLoopingExpression(loopingCondition);
}