Java Code Examples for spoon.reflect.code.CtWhile

The following examples show how to use spoon.reflect.code.CtWhile. These examples are extracted from open source projects. 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 Project: coming   Source File: AbstractCodeAnalyzer.java    License: 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 2
Source Project: coming   Source File: CodeElementInfo.java    License: 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 3
Source Project: coming   Source File: VariableResolver.java    License: 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 4
Source Project: coming   Source File: VariableResolver.java    License: 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 5
Source Project: astor   Source File: VariableResolver.java    License: 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 6
Source Project: astor   Source File: VariableResolver.java    License: 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
@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 8
@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 9
public boolean isUnbreakable(CtWhile loopStatement) {
    CtMethod<?> correspondingMethod = loopStatement.getParent(CtMethod.class);
    if (SpoonStatementLibrary.isLastStatementOfMethod(loopStatement)) {
        return !SpoonReferenceLibrary.isVoidType(correspondingMethod.getType());
    }
    return false;
}
 
Example 10
protected While newLoop(CtWhile loopStatement) {
    While loop = new While(loopStatement);
    if (isUnbreakable(loopStatement)) {
        loop.setUnbreakable();
    }
    return loop;
}
 
Example 11
Source Project: nopol   Source File: InfinitelTest.java    License: 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 12
Source Project: nopol   Source File: InfinitelTest.java    License: 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 13
Source Project: coming   Source File: VariableAnalyzer.java    License: 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 14
Source Project: coming   Source File: VariableAnalyzer.java    License: 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 15
@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 16
@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 17
Source Project: astor   Source File: TransformStrategy.java    License: 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 18
Source Project: astor   Source File: TransformStrategy.java    License: 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 19
@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 20
Source Project: nopol   Source File: SpoonModelLibrary.java    License: 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 Project: nopol   Source File: SpoonModelLibrary.java    License: 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);
}
 
Example 22
@Override
public boolean isToBeProcessed(CtWhile loopStatement) {
    return true;
}
 
Example 23
Source Project: coming   Source File: LogicalExpressionAnalyzer.java    License: MIT License 4 votes vote down vote up
@Override
public void visitCtWhile(CtWhile whileLoop) {
	toScan = whileLoop.getLoopingExpression();
}
 
Example 24
Source Project: coming   Source File: BinaryOperatorAnalyzer.java    License: 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
@Override
public void visitCtWhile(CtWhile whileLoop) {
	super.visitCtWhile(whileLoop);
	fetchCOND(whileLoop);
}
 
Example 26
@Override
public void visitCtWhile(CtWhile whileLoop) {
	super.visitCtWhile(whileLoop);
}
 
Example 27
Source Project: gumtree-spoon-ast-diff   Source File: LabelFinder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void visitCtWhile(CtWhile e) {
	label = "while";
}