本文整理汇总了Java中spoon.reflect.code.CtLocalVariable类的典型用法代码示例。如果您正苦于以下问题:Java CtLocalVariable类的具体用法?Java CtLocalVariable怎么用?Java CtLocalVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtLocalVariable类属于spoon.reflect.code包,在下文中一共展示了CtLocalVariable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: apply
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
@Override
public List<CtMethod> apply(CtMethod method) {
List<CtLocalVariable<?>> existingObjects = getExistingObjects(method);
final Stream<? extends CtMethod<?>> gen_o1 = existingObjects.stream() // must use tmp variable because javac is confused
.flatMap(localVariable -> ConstructorCreator.generateAllConstructionOf(localVariable.getType()).stream())
.map(ctExpression -> {
final CtMethod<?> clone = AmplificationHelper.cloneMethodTest(method, "_sd");
clone.getBody().insertBegin(
clone.getFactory().createLocalVariable(
ctExpression.getType(), "__DSPOT_gen_o" + counterGenerateNewObject++, ctExpression
)
);
return clone;
}
);
return gen_o1.collect(Collectors.toList());
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:18,代码来源:ObjectGenerator.java
示例2: removeAssertion
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
public void removeAssertion(CtInvocation<?> invocation) {
final Factory factory = invocation.getFactory();
invocation.getArguments().forEach(argument -> {
CtExpression clone = ((CtExpression) argument).clone();
if (clone instanceof CtUnaryOperator) {
clone = ((CtUnaryOperator) clone).getOperand();
}
if (clone instanceof CtStatement) {
invocation.insertBefore((CtStatement) clone);
} else if (! (clone instanceof CtLiteral || clone instanceof CtVariableRead)) {
CtTypeReference<?> typeOfParameter = clone.getType();
if (clone.getType().equals(factory.Type().NULL_TYPE)) {
typeOfParameter = factory.Type().createReference(Object.class);
}
final CtLocalVariable localVariable = factory.createLocalVariable(
typeOfParameter,
typeOfParameter.getSimpleName() + "_" + counter[0]++,
clone
);
invocation.insertBefore(localVariable);
}
});
invocation.getParent(CtStatementList.class).removeStatement(invocation);
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:25,代码来源:AssertionRemover.java
示例3: process
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
@Override
public void process(CtStatement statement) {
String evaluationAccess = "runtimeAngelicValue";
// create the angelic value
String type = subprocessor.getType().getCanonicalName();
CtLocalVariable<?> evaluation = newLocalVariableDeclaration(
statement.getFactory(), subprocessor.getType(), evaluationAccess, "(" + type + ")"
+ this.getClass().getCanonicalName() + ".getValue("
+ subprocessor.getDefaultValue() + ")");
// insert angelic value before the statement
insertBeforeUnderSameParent(evaluation, statement);
// collect values of the statement
appendValueCollection(statement, evaluationAccess);
// insert angelic value in the condition
subprocessor.setValue("runtimeAngelicValue");
subprocessor().process(statement);
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:18,代码来源:LoggingInstrumenter.java
示例4: process
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
@Override
public void process(CtStatement ctStatement) {
if (!(ctStatement instanceof CtLocalVariable<?>) && !(ctStatement instanceof CtAssignment<?, ?>))
return;
Class<?> localVariableClass = ((CtTypedElement<?>) ctStatement).getType().getActualClass();
if (localVariableClass.equals(Integer.class) || localVariableClass.equals(int.class)) {
if (ctStatement instanceof CtAssignment<?, ?>) {
replaceInteger(((CtAssignment<?, ?>) ctStatement).getAssignment());
} else {
replaceInteger(((CtLocalVariable<?>) ctStatement).getDefaultExpression());
}
} else if (localVariableClass.equals(Double.class) || localVariableClass.equals(double.class)) {
if (ctStatement instanceof CtAssignment<?, ?>) {
replaceDouble(((CtAssignment<?, ?>) ctStatement).getAssignment());
} else {
replaceDouble(((CtLocalVariable<?>) ctStatement).getDefaultExpression());
}
} else if (localVariableClass.equals(Boolean.class) || localVariableClass.equals(boolean.class)) {
if (ctStatement instanceof CtAssignment<?, ?>) {
replaceBoolean(((CtAssignment<?, ?>) ctStatement).getAssignment());
} else {
replaceBoolean(((CtLocalVariable<?>) ctStatement).getDefaultExpression());
}
}
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:27,代码来源:LiteralReplacer.java
示例5: replaceDouble
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
private void replaceDouble(CtExpression ctElement) {
if (getValue() == null) {
CtLocalVariable<Double> evaluation = newLocalVariableDeclaration(
ctElement.getFactory(), double.class, "guess_fix",
Debug.class.getCanonicalName() + ".makeSymbolicReal(\"guess_fix\")");
CtStatement firstStatement = getFirstStatement(ctElement);
if (firstStatement == null) {
return;
}
SpoonStatementLibrary.insertBeforeUnderSameParent(evaluation, firstStatement);
// SpoonStatementLibrary.insertAfterUnderSameParent(getFactory().Code().createCodeSnippetStatement("System.out.println(\"guess_fix: \" + guess_fix)"),
// getFirstStatement(ctElement));
ctElement.replace(getFactory().Code().createCodeSnippetExpression("guess_fix"));
} else {
ctElement.replace(getFactory().Code().createCodeSnippetExpression(getValue()));
}
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:19,代码来源:LiteralReplacer.java
示例6: replaceInteger
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
private void replaceInteger(CtExpression ctElement) {
if (getValue() == null) {
CtLocalVariable<Integer> evaluation = newLocalVariableDeclaration(
ctElement.getFactory(), int.class, "guess_fix",
Debug.class.getCanonicalName()
+ ".makeSymbolicInteger(\"guess_fix\")");
CtStatement firstStatement = getFirstStatement(ctElement);
if (firstStatement == null) {
return;
}
SpoonStatementLibrary.insertBeforeUnderSameParent(evaluation, firstStatement);
// SpoonStatementLibrary.insertAfterUnderSameParent(getFactory().Code().createCodeSnippetStatement("System.out.println(\"guess_fix: \" + guess_fix)"),
// getFirstStatement(ctElement));
ctElement.replace(getFactory().Code().createCodeSnippetExpression("guess_fix"));
} else {
ctElement.replace(getFactory().Code().createCodeSnippetExpression(getValue()));
}
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:21,代码来源:LiteralReplacer.java
示例7: changeThisAccesses
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
/**
* The statements of the command may refer to the external listener through 'this'. In such a case, the 'this' has to be changed
* in a variable access.
*/
private void changeThisAccesses(final @NotNull List<CtElement> stats, final @NotNull CtAbstractInvocation<?> regInvok) {
final Filter<CtThisAccess<?>> filter = new ThisAccessFilter(false);
final CtExecutable<?> regMethod = regInvok.getParent(CtExecutable.class);
stats.stream().map(stat -> stat.getElements(filter)).flatMap(s -> s.stream()).forEach(th -> {
List<CtLocalVariable<?>> thisVar = regMethod.getElements(new BasicFilter<CtLocalVariable<?>>(CtLocalVariable.class) {
@Override
public boolean matches(final CtLocalVariable<?> element) {
final CtType<?> decl = element.getType().getDeclaration();
return decl!=null && decl.equals(th.getType().getDeclaration());
}
});
if(thisVar.isEmpty()) {
LOG.log(Level.SEVERE, "Cannot find a local variable for a 'this' access: " + thisVar);
}else {
th.replace(regInvok.getFactory().Code().createVariableRead(thisVar.get(0).getReference(), false));
}
});
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:24,代码来源:ListenerCommandRefactor.java
示例8: process
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
@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);
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:SpecialStatementFixSpaceProcessor.java
示例9: generateNullValue
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
@Deprecated
public static CtLocalVariable generateNullValue(CtTypeReference type) {
Factory factory = type.getFactory();
final CtLiteral<?> defaultExpression = factory.createLiteral(null);
defaultExpression.addTypeCast(type);
return factory.Code().createLocalVariable(type, "vc_" + count++, defaultExpression);
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:8,代码来源:ValueCreator.java
示例10: getExistingObjects
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
private List<CtLocalVariable<?>> getExistingObjects(CtMethod method) {
return method.getElements(new TypeFilter<CtLocalVariable<?>>(CtLocalVariable.class) {
@Override
public boolean matches(CtLocalVariable<?> element) {
return element.getType() != null &&
!element.getType().isPrimitive() &&
element.getType().getDeclaration() != null;
}
});
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:11,代码来源:ObjectGenerator.java
示例11: LiteralReplacer
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
public LiteralReplacer(Class<?> cl, CtStatement statement, StatementType statementType) {
super(statement, statementType);
if (statement instanceof CtAssignment<?, ?>) {
super.setDefaultValue(((CtAssignment<?, ?>) statement).getAssignment().toString());
} else if (statement instanceof CtLocalVariable<?>) {
super.setDefaultValue(((CtLocalVariable<?>) statement).getDefaultExpression().toString());
}
super.setType(cl);
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:10,代码来源:LiteralReplacer.java
示例12: replaceBoolean
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
private void replaceBoolean(CtExpression ctElement) {
if (getValue() == null) {
CtLocalVariable<Boolean> evaluation = newLocalVariableDeclaration(
ctElement.getFactory(), boolean.class, "guess_fix",
Debug.class.getCanonicalName() + ".makeSymbolicBoolean(\"guess_fix\")");
CtStatement firstStatement = getFirstStatement(ctElement);
if (firstStatement == null) {
return;
}
SpoonStatementLibrary.insertBeforeUnderSameParent(evaluation,
firstStatement);
ctElement.replace(getFactory().Code().createCodeSnippetExpression(
"guess_fix"));
} else {
switch (getValue()) {
case "1":
ctElement.replace(getFactory().Code().createCodeSnippetExpression("true"));
break;
case "0":
ctElement.replace(getFactory().Code().createCodeSnippetExpression("false"));
break;
default:
ctElement.replace(getFactory().Code().createCodeSnippetExpression(getValue()));
break;
}
}
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:28,代码来源:LiteralReplacer.java
示例13: getGetters
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
public static List<CtMethod> getGetters(CtLocalVariable localVariable) {
return ((Set<CtMethod<?>>) localVariable.getType().getDeclaration().getMethods()).stream()
.filter(method -> method.getParameters().isEmpty() &&
method.getType() != localVariable.getFactory().Type().VOID_PRIMITIVE &&
(method.getSimpleName().startsWith("get") ||
method.getSimpleName().startsWith("is"))
).collect(Collectors.toList());
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:9,代码来源:Util.java
示例14: collect
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
public void collect(Launcher launcher, CtMethod<?> testMethod, List<CtLocalVariable> localVariables) {
final CtClass testClass = testMethod.getParent(CtClass.class);
testClass.removeMethod(testMethod);
final CtMethod<?> clone = testMethod.clone();
instrument(clone, localVariables);
testClass.addMethod(clone);
System.out.println(clone);
run(launcher, testClass, clone);
testClass.removeMethod(clone);
testClass.addMethod(testMethod);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:12,代码来源:Collector.java
示例15: instrument
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
void instrument(CtMethod testMethod, CtLocalVariable localVariable) {
List<CtMethod> getters = getGetters(localVariable);
getters.forEach(getter -> {
CtInvocation invocationToGetter =
invok(getter, localVariable);
CtInvocation invocationToObserve =
createObserve(getter, invocationToGetter);
testMethod.getBody().insertEnd(invocationToObserve);
});
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:11,代码来源:Collector.java
示例16: analyze
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
List<CtLocalVariable> analyze(CtMethod testMethod) {
TypeFilter filterLocalVar =
new TypeFilter(CtLocalVariable.class) {
public boolean matches(CtLocalVariable localVariable) {
return !localVariable.getType().isPrimitive();
}
};
return testMethod.getElements(filterLocalVar);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:10,代码来源:Analyzer.java
示例17: addAssertion
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
void addAssertion(CtMethod testMethod, CtLocalVariable localVariable) {
List<CtMethod> getters =
getGetters(localVariable);
getters.forEach(getter -> {
String key = getKey(getter);
CtInvocation invocationToGetter =
invok(getter, localVariable);
CtInvocation invocationToAssert = createAssert("assertEquals",
factory.createLiteral(Logger.observations.get(key)), // expected
invocationToGetter); // actual
testMethod.getBody().insertEnd(invocationToAssert);
});
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:15,代码来源:AssertionAdder.java
示例18: test
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
@Test
public void test() {
Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
launcher.getEnvironment().setLevel(Level.ALL.toString());
launcher.addInputResource("src/test/resources/project/src/main/java/");
launcher.addInputResource("src/test/resources/project/src/test/java/");
launcher.addInputResource("src/main/java/fr/inria/gforge/spoon/assertgenerator/Logger.java");
launcher.getEnvironment().setSourceClasspath(getPathToJunit());
launcher.buildModel();
final Analyzer analyzer = new Analyzer();
final Collector collector = new Collector(launcher.getFactory());
final AssertionAdder assertionAdder = new AssertionAdder(launcher.getFactory());
launcher.getFactory().Class().getAll().forEach(ctClass -> {
// Analyze
Map<CtMethod, List<CtLocalVariable>> localVariablesPerTestMethod = analyzer.analyze(ctClass);
localVariablesPerTestMethod.keySet().stream().forEach(key -> System.out.println("{"+ key.getParent(CtClass.class).getSimpleName() + "#" + key.getSimpleName() + "=["+ localVariablesPerTestMethod.get(key) +"]"));
if (!localVariablesPerTestMethod.isEmpty()) {
// Collect
localVariablesPerTestMethod.keySet().forEach(ctMethod -> collector.collect(launcher, ctMethod, localVariablesPerTestMethod.get(ctMethod)));
// Generate
localVariablesPerTestMethod.keySet().forEach(ctMethod -> assertionAdder.addAssertion(ctMethod, localVariablesPerTestMethod.get(ctMethod)));
}
});
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:28,代码来源:AssertionGenerationTest.java
示例19: getAllLocalVarDeclaration
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
public @NotNull Set<CtLocalVariable<?>> getAllLocalVarDeclaration(final @Nullable CtElement elt) {
if(elt == null) {
return new HashSet<>();
}
return elt.getElements(new BasicFilter<>(CtLocalVariableReference.class)).stream().map(varRef -> {
final CtLocalVariable<?> varDecl = varRef.getDeclaration();
Set<CtLocalVariable<?>> localVars = getAllLocalVarDeclaration(varDecl);
if(varDecl != null) {
localVars.add(varDecl);
}
return localVars;
}).flatMap(s -> s.stream()).collect(Collectors.toSet());
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:15,代码来源:SpoonHelper.java
示例20: extractUsagesOfVar
import spoon.reflect.code.CtLocalVariable; //导入依赖的package包/类
public List<CtVariableAccess<?>> extractUsagesOfVar(final @NotNull CtVariable<?> var) {
CtElement parent;
if(var instanceof CtLocalVariable<?>) {
parent = var.getParent(CtBlock.class);
}else {
if(var.getVisibility() == null) {
parent = var.getParent(CtPackage.class);
if(parent == null) parent = var.getParent(CtClass.class);
}else {
switch(var.getVisibility()) {
case PRIVATE:
parent = var.getParent(CtClass.class);
break;
case PROTECTED:
parent = var.getParent(CtPackage.class);
if(parent == null) parent = var.getParent(CtClass.class);
break;
case PUBLIC:
parent = var.getFactory().Package().getRootPackage();
break;
default:
parent = null;
break;
}
}
}
if(parent != null) {
return parent.getElements(new MyVariableAccessFilter(var));
}
return Collections.emptyList();
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:35,代码来源:SpoonHelper.java
注:本文中的spoon.reflect.code.CtLocalVariable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论