本文整理汇总了Java中spoon.reflect.code.CtConstructorCall类的典型用法代码示例。如果您正苦于以下问题:Java CtConstructorCall类的具体用法?Java CtConstructorCall怎么用?Java CtConstructorCall使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtConstructorCall类属于spoon.reflect.code包,在下文中一共展示了CtConstructorCall类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testReferenceProcessor
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
@Test
public void testReferenceProcessor() throws Exception {
final String[] args = {
"-i", "src/test/resources/factory/",
"-o", "target/spooned/"
};
final Launcher launcher = new Launcher();
launcher.setArgs(args);
launcher.run();
final Factory factory = launcher.getFactory();
final ProcessingManager processingManager = new QueueProcessingManager(factory);
List<CtInterface> listFactoryItf = factory.getModel().getElements(new NamedElementFilter<>(CtInterface.class, "Factory"));
assertThat(listFactoryItf.size(), is(1));
final FactoryProcessor processor = new FactoryProcessor(listFactoryItf.get(0).getReference());
processingManager.addProcessor(processor);
List<CtConstructorCall> ctNewClasses = factory.getModel().getElements(new TypeFilter<CtConstructorCall>(CtConstructorCall.class));
processingManager.process(ctNewClasses);
// implicit constructor is also counted
assertThat(processor.listWrongUses.size(), is(2));
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:26,代码来源:FactoryProcessorTest.java
示例2: findCandidates
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
private void findCandidates() {
candidates = new ArrayList<>();
System.out.println(" --- Search for for Candidates --- ");
Collection<CtConstructorCall> calls = getInputProgram().getAllElement(CtConstructorCall.class);
int collections = 0;
int skipped = 0;
List<CtConstructorCall> colCalls = new ArrayList<>();
List<CtConstructorCall> skippedCalls = new ArrayList<>();
for(CtConstructorCall call : calls) {
Factory f = call.getFactory();
//System.out.println("c: " + call + " in " + ((CtClass) call.getParent(CtClass.class)).getSimpleName());
CtTypedElement parent = call.getParent(CtTypedElement.class);
skipped++;
skippedCalls.add(call);
if(parent.getType().getModifiers().contains(ModifierKind.STATIC)) continue;
if(call.getType().getModifiers().contains(ModifierKind.STATIC)) continue;
if(call.getType().getQualifiedName() == parent.getType().getQualifiedName()) continue;
skipped--;
skippedCalls.remove(call);
}
System.out.println(" --- Done (" + candidates.size() + " coll: " + collections + " skipped: " + skipped + ") --- ");
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:27,代码来源:SwapInterfaceImplQuery.java
示例3: query
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
@Override
public Transformation query() throws QueryException {
Random random = new Random();
while (true) {
int index = random.nextInt(staticTypes.size());
List<CtConstructorCall> constructorCallDynamicType = findAllConstructorCallWithDynamicType(getConstructorCall(), originalDynamicTypes.get(index));
List<CtConstructorCall> constructorCallStaticType = findAllConstructorCallWithStaticType(constructorCallDynamicType, staticTypes.get(index));
if (!constructorCallStaticType.isEmpty()) {
CtConstructorCall candidate = constructorCallStaticType.get(random.nextInt(constructorCallStaticType.size()));
List<Constructor> newConstructor = findAllNewConstructors(candidate, newDynamicTypes.get(index));
if (!newConstructor.isEmpty()) {
InstanceTransformation transformation = new InstanceTransformation();
transformation.setWithSwitch(withSwitch);
if (all) {
buildMultiPointTransformation(transformation, constructorCallStaticType, candidate, newConstructor.get(random.nextInt(newConstructor.size())));
} else {
buildSinglePointTransformation(transformation, candidate, newConstructor.get(random.nextInt(newConstructor.size())));
}
return transformation;
}
}
}
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:27,代码来源:InstanceTransformationQuery.java
示例4: findAllNewConstructors
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
protected List<Constructor> findAllNewConstructors(CtConstructorCall constructorCall, Set<Class> newDynamicType) {
Class staticType = findStaticType(constructorCall);
Set<Class> subTypes = findAssignableTypeFor(staticType).stream()
.filter(type -> newDynamicType.contains(type))
.collect(Collectors.toSet());
List<Constructor> candidate = findCandidate(constructorCall, subTypes);
candidate.remove(constructorCall.getExecutable().getActualConstructor());
return candidate.stream()
.filter(c -> !Modifier.isAbstract(c.getDeclaringClass().getModifiers()))
.filter(c -> newDynamicType.stream()
.anyMatch(dt -> dt == c.getDeclaringClass() || dt.isAssignableFrom(c.getDeclaringClass())))
.collect(Collectors.toList());
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:17,代码来源:InstanceTransformationQuery.java
示例5: process
import spoon.reflect.code.CtConstructorCall; //导入依赖的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
示例6: generateAllConstructionOf
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
public static List<CtExpression> generateAllConstructionOf(CtTypeReference type) {
CtConstructorCall<?> constructorCall = type.getFactory().createConstructorCall();
constructorCall.setType(type);
if (type.getDeclaration() != null) {
final List<CtConstructor<?>> constructors = type.getDeclaration()
.getElements(new TypeFilter<CtConstructor<?>>(CtConstructor.class) {
@Override
public boolean matches(CtConstructor<?> element) {
return element.getParameters().stream()
.map(CtParameter::getType)
.allMatch(ValueCreatorHelper::canGenerateAValueForType);
}
});
if (!constructors.isEmpty()) {
final List<CtExpression> generatedConstructors = constructors.stream().map(ctConstructor -> {
final CtConstructorCall<?> clone = constructorCall.clone();
ctConstructor.getParameters().forEach(parameter ->
clone.addArgument(ValueCreator.generateRandomValue(parameter.getType()))
);
return clone;
}
).collect(Collectors.toList());
//add a null value
final CtExpression<?> literalNull = type.getFactory().createLiteral(null);
literalNull.setType(type);
generatedConstructors.add(literalNull);
return generatedConstructors;
}
}
return Collections.singletonList(constructorCall);
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:32,代码来源:ConstructorCreator.java
示例7: generateConstructionOf
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
static CtExpression generateConstructionOf(CtTypeReference type) {
CtType<?> typeDeclaration = type.getDeclaration() == null ? type.getTypeDeclaration() : type.getDeclaration();
if (typeDeclaration != null) {
final List<CtConstructor<?>> constructors = typeDeclaration.getElements(new TypeFilter<CtConstructor<?>>(CtConstructor.class) {
@Override
public boolean matches(CtConstructor<?> element) {
return element.hasModifier(ModifierKind.PUBLIC) &&
element.getParameters().stream()
.map(CtParameter::getType)
.allMatch(ValueCreatorHelper::canGenerateAValueForType);
}
});
if (!constructors.isEmpty()) {
CtConstructorCall<?> constructorCall = type.getFactory().createConstructorCall();
constructorCall.setType(type);
final CtConstructor<?> selectedConstructor = constructors.get(AmplificationHelper.getRandom().nextInt(constructors.size()));
selectedConstructor.getParameters().forEach(parameter -> {
// if (!type.getActualTypeArguments().isEmpty()) {
// type.getActualTypeArguments().forEach(ctTypeReference -> {
// if (!parameter.getType().getActualTypeArguments().contains(ctTypeReference)) {
// parameter.getType().setActualTypeArguments(ctTypeReference);
// }
// }
// );
// }
constructorCall.addArgument(ValueCreator.generateRandomValue(parameter.getType()));
}
);
return constructorCall;
}
}
return null;
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:34,代码来源:ConstructorCreator.java
示例8: process
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
public void process(CtConstructorCall<?> newClass) {
// skip factory creation
if (newClass.getExecutable().getDeclaringType().isSubtypeOf(getFactoryType()))
return;
// skip creations in factories
if (((CtClass<?>) newClass.getParent(CtClass.class)).isSubtypeOf(getFactoryType()))
return;
// only report for types created by the factory
for (CtTypeReference<?> t : getCreatedTypes()) {
if (newClass.getType().isSubtypeOf(t)) {
this.listWrongUses.add(newClass);
}
}
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:16,代码来源:FactoryProcessor.java
示例9: getGUICommands
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
private @NotNull List<Cmd<?>> getGUICommands(final @NotNull CtStatement stat) {
//TODO analyse setUp
if(stat instanceof CtConstructorCall<?> && ((CtConstructorCall<?>) stat).getExecutable().getType().getSimpleName().equals("CompositeGUIVoidCommand")) {
return ((CtConstructorCall<?>) stat).getArguments().stream().map(arg -> new GUICmd(arg)).collect(Collectors.toList());
}
if(stat instanceof CtInvocation<?> && isCmd(((CtInvocation<?>) stat).getExecutable().getDeclaringType())) {
return Collections.singletonList(new GUICmd((CtExpression<?>)stat));
}
return Collections.emptyList();
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:13,代码来源:TestFXProcessor.java
示例10: parametersMatch
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
private boolean parametersMatch(CtConstructorCall curCall, CtExecutableReference candidate) {
if(curCall.getArguments().size() != candidate.getParameters().size()) return false;
List<CtExpression> args = curCall.getArguments();
List<CtTypeReference> params = candidate.getParameters();
for(int i = 0; i < args.size(); i++) {
if(!args.get(i).getType().equals(params.get(i))) return false;
}
return true;
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:10,代码来源:SwapInterfaceImplQuery.java
示例11: buildConstructorCall
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
public List<CtConstructorCall> buildConstructorCall(CtConstructorCall call, Set<String> l, String type, String param) {
Factory f = call.getFactory();
List<CtConstructorCall> res = new ArrayList<>();
for(String c : l) {
if(!call.getType().getQualifiedName().equals(c)) {
try {
res.add((CtConstructorCall) f.Code().createCodeSnippetExpression("new " + c + "<" + type + ">("+ param + ")").compile());
} catch (Exception ex) {}
}
}
return res;
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:SwapInterfaceImplQuery.java
示例12: query
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
@Override
public Transformation query() throws QueryException {
//try {
Map.Entry<CtConstructorCall, CtConstructorCall> cur = candidateIt.next();
CtConstructorCall tp = cur.getKey();
CtConstructorCall c = cur.getValue();
return new SwapSubType(tp, c);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:9,代码来源:SwapInterfaceImplQuery.java
示例13: buildMultiPointTransformation
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
protected void buildMultiPointTransformation(InstanceTransformation transformation, List<CtConstructorCall> constructorCalls,
CtConstructorCall candidate, Constructor newConstructor) {
StaticTypeFinder staticTypeFinder = new StaticTypeFinder();
Constructor model = candidate.getExecutable().getActualConstructor();
constructorCalls.stream()
.filter(constructorCall -> constructorCall.getExecutable() != null
&& constructorCall.getExecutable().getActualConstructor() != null)
.filter(constructorCall -> model.equals(constructorCall.getExecutable().getActualConstructor()))
.filter(constructorCall -> staticTypeFinder.findStaticType(constructorCall).isAssignableFrom(newConstructor.getDeclaringClass()))
.forEach(constructorCall -> transformation.add(constructorCall, newConstructor));
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:InstanceTransformationQuery.java
示例14: findAllConstructorCallWithStaticType
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
protected List<CtConstructorCall> findAllConstructorCallWithStaticType(List<CtConstructorCall> constructorCalls, Set<Class> staticType) {
return constructorCalls.stream()
.filter(constructorCall -> {
Class type = findStaticType(constructorCall);
return type != null
&& staticType.stream()
.anyMatch(st -> st.isAssignableFrom(type));
})
.collect(Collectors.toList());
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:11,代码来源:InstanceTransformationQuery.java
示例15: findAllConstructorCallWithDynamicType
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
protected List<CtConstructorCall> findAllConstructorCallWithDynamicType(List<CtConstructorCall> constructorCalls, Set<Class> dynamicType) {
return constructorCalls.parallelStream()
.filter(constructorCall -> {
try {
CtTypeReference typeRef = constructorCall.getType();
if (typeRef != null) {
Class cl = typeRef.getActualClass();
return dynamicType.stream()
.anyMatch(dt -> dt.isAssignableFrom(cl));
}
} catch (Exception e) {}
return false;
})
.collect(Collectors.toList());
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:16,代码来源:InstanceTransformationQuery.java
示例16: findEquivalentConstructor
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
protected Constructor findEquivalentConstructor(CtConstructorCall constructorCall, Class cl) {
try {
Class[] types = constructorCall.getExecutable().getActualConstructor().getParameterTypes();
return cl.getConstructor(types);
} catch (Exception e) {
return null;
}
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:9,代码来源:InstanceTransformationQuery.java
示例17: getConstructorCall
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
protected List<CtConstructorCall> getConstructorCall() {
if (constructorCalls == null) {
List<CtConstructorCall> allConstructorCall = getInputProgram().getAllElement(CtConstructorCall.class);
constructorCalls = allConstructorCall.parallelStream()
.filter(elem -> elem.getPosition() != null)
.filter(elem -> getInputProgram().getCoverageReport().elementCoverage(elem) != 0)
.filter(elem -> elem.getPosition().toString().contains(inputProgram.getRelativeSourceCodeDir()))
.collect(Collectors.toList());
}
return constructorCalls;
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:12,代码来源:InstanceTransformationQuery.java
示例18: canBeAppliedToPoint
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
@Override
public boolean canBeAppliedToPoint(ModificationPoint point) {
boolean apply = super.canBeAppliedToPoint(point);
if (!apply)
return apply;
// do not insert after a return
if (point.getCodeElement() instanceof CtConstructorCall) {
return false;
}
// Otherwise, accept the element
return true;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:InsertBeforeOp.java
示例19: test_t_211903
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
@Test
public void test_t_211903() throws Exception{
AstComparator diff = new AstComparator();
// meld src/test/resources/examples/t_211903/left_MemberFilePersister_1.4.java src/test/resources/examples/t_211903/right_MemberFilePersister_1.5.java
File fl = new File("src/test/resources/examples/t_211903/left_MemberFilePersister_1.4.java");
File fr = new File("src/test/resources/examples/t_211903/right_MemberFilePersister_1.5.java");
Diff result = diff.compare(fl,fr);
//result.debugInformation();
CtElement ancestor = result.commonAncestor();
assertTrue(ancestor instanceof CtConstructorCall);
assertEquals(88,ancestor.getPosition().getLine());
List<Operation> actions = result.getRootOperations();
//result.debugInformation();
assertTrue(result.containsOperation(OperationKind.Update, "ConstructorCall", "java.io.FileReader(java.io.File)"));
assertTrue(result.containsOperation(OperationKind.Insert, "ConstructorCall", "java.io.InputStreamReader(java.io.InputStream,java.lang.String)"));
// additional checks on low-level actions
assertTrue(result.containsOperations(result.getAllOperations(), OperationKind.Insert, "Literal", "\"UTF-8\""));
// the change is in the local variable declaration
CtElement elem = actions.get(0).getNode();
assertNotNull(elem);
assertNotNull(elem.getParent(CtLocalVariable.class));
}
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:30,代码来源:AstComparatorTest.java
示例20: buildSinglePointTransformation
import spoon.reflect.code.CtConstructorCall; //导入依赖的package包/类
protected void buildSinglePointTransformation(InstanceTransformation transformation, CtConstructorCall candidate, Constructor newConstructor) {
transformation.add(candidate, newConstructor);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:4,代码来源:InstanceTransformationQuery.java
注:本文中的spoon.reflect.code.CtConstructorCall类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论