本文整理汇总了Java中spoon.reflect.reference.CtExecutableReference类的典型用法代码示例。如果您正苦于以下问题:Java CtExecutableReference类的具体用法?Java CtExecutableReference怎么用?Java CtExecutableReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtExecutableReference类属于spoon.reflect.reference包,在下文中一共展示了CtExecutableReference类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: process
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
@Override
public void process(CtInvocation ctElement) {
CtExecutableReference executable = ctElement.getExecutable();
if (executable.isConstructor()) {
return;
}
String key = executable.toString();
CtTypeReference declaringType = executable.getDeclaringType();
if (declaringType.getPackage() != null) {
key = declaringType.getPackage().getSimpleName() + "." + executable.getSimpleName();
}
if (!statMethod.containsKey(key)) {
statMethod.put(key, 1);
} else {
statMethod.put(key, statMethod.get(key) + 1);
}
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:18,代码来源:MethodCollector.java
示例2: generateSingletonList
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static CtExpression<?> generateSingletonList(CtTypeReference type, String nameMethod, Class<?> typeOfCollection) {
final Factory factory = type.getFactory();
final CtType<?> collectionsType = factory.Type().get(Collections.class);
final CtTypeAccess<?> accessToCollections = factory.createTypeAccess(collectionsType.getReference());
final CtMethod<?> singletonListMethod = collectionsType.getMethodsByName(nameMethod).get(0);
final CtExecutableReference executableReference = factory.Core().createExecutableReference();
executableReference.setStatic(true);
executableReference.setSimpleName(singletonListMethod.getSimpleName());
executableReference.setDeclaringType(collectionsType.getReference());
executableReference.setType(factory.createCtTypeReference(typeOfCollection));
if (!type.getActualTypeArguments().isEmpty() &&
type.getActualTypeArguments().stream().allMatch(ValueCreatorHelper::canGenerateAValueForType)) {
executableReference.setParameters(type.getActualTypeArguments());
List<CtExpression<?>> parameters = type.getActualTypeArguments().stream()
.map(ValueCreator::generateRandomValue).collect(Collectors.toList());
return factory.createInvocation(accessToCollections, executableReference, parameters);
} else {
return factory.createInvocation(accessToCollections, executableReference,
factory.createConstructorCall(factory.Type().createReference(Object.class))
);
}
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:24,代码来源:CollectionCreator.java
示例3: buildSnippetAssertCollection
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static List<CtStatement> buildSnippetAssertCollection(Factory factory, String expression, Collection value) {
final CtVariableAccess variableRead = factory.createVariableRead(
factory.createLocalVariableReference().setSimpleName(expression),
false
);
final CtExecutableReference contains = factory.Type().get(Collection.class).getMethodsByName("contains").get(0).getReference();
return (List<CtStatement>) value.stream().map(factory::createLiteral)
.map(o ->
buildInvocation(factory, "assertTrue",
Collections.singletonList(factory.createInvocation(variableRead,
contains, (CtLiteral) o
)
)
)
)
.collect(Collectors.toList());
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:19,代码来源:AssertBuilder.java
示例4: collectStaticMethods
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
/**
* Call static methods on imported class
* @param ctExecutableReferences
* @param threadRef
* @param argsCandidates
*/
private Candidates collectStaticMethods(Set<CtExecutableReference> ctExecutableReferences, ThreadReference threadRef, Candidates argsCandidates) {
Candidates results = new Candidates();
Iterator<CtExecutableReference> it = ctExecutableReferences.iterator();
while (it.hasNext()) {
CtExecutableReference next = it.next();
List<ReferenceType> refs = threadRef.virtualMachine().classesByName(next.getDeclaringType().getQualifiedName());
if (refs.size() == 0) {
continue;
}
ReferenceType ref = refs.get(0);
Expression exp = AccessFactory.variable(next.getDeclaringType().getQualifiedName(), ref, nopolContext);
List<Method> methods = getMethods(exp, ref, true, threadRef, next.getSimpleName());
results.addAll(callMethods(exp, threadRef, methods, argsCandidates));
}
return results;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:24,代码来源:DataCollector.java
示例5: createInvocation
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
private CtStatement createInvocation(CtVariable target, CtMethod method, List<CtVariable> vars, boolean staticParam) {
Factory f = method.getFactory();
CtStatement res = null;
List<CtExpression> params = new LinkedList<>();
if (VarFinder.fillParameter(params, method, vars, staticParam)) {
CtExpression ttarget = null;
if(target != null) {
ttarget = f.Code().createVariableRead(VarFinder.createRef(target), target.getModifiers().contains(ModifierKind.STATIC));
}
CtExecutableReference exeRef = method.getReference();
CtExpression[] array = params.toArray(new CtExpression[params.size()]);
res = f.Code().createInvocation(ttarget, exeRef, array);
toRemove.add(method);
}
return res;
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:17,代码来源:AddMethodInvocationQuery.java
示例6: generateEmptyCollection
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
static CtExpression<?> generateEmptyCollection(CtTypeReference type, String nameMethod, Class<?> typeOfCollection) {
final Factory factory = type.getFactory();
final CtType<?> collectionsType = factory.Type().get(Collections.class);
final CtTypeAccess<?> accessToCollections = factory.createTypeAccess(collectionsType.getReference());
final CtMethod<?> singletonListMethod = collectionsType.getMethodsByName(nameMethod).get(0);
final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference();
executableReference.setStatic(true);
executableReference.setSimpleName(singletonListMethod.getSimpleName());
executableReference.setDeclaringType(collectionsType.getReference());
executableReference.setType(factory.createCtTypeReference(typeOfCollection));
return factory.createInvocation(accessToCollections, executableReference);
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:13,代码来源:CollectionCreator.java
示例7: buildInvocation
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
private static CtInvocation buildInvocation(Factory factory, String methodName, List<CtExpression> arguments) {
final CtInvocation invocation = factory.createInvocation();
final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference();
executableReference.setStatic(true);
executableReference.setSimpleName(methodName);
executableReference.setDeclaringType(factory.createCtTypeReference(org.junit.Assert.class));
invocation.setExecutable(executableReference);
invocation.setArguments(arguments); // TODO
invocation.setType(factory.Type().voidPrimitiveType());
invocation.setTarget(factory.createTypeAccess(factory.createCtTypeReference(org.junit.Assert.class)));
return invocation;
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:13,代码来源:AssertBuilder.java
示例8: isToBeProcessed
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
@Override
public boolean isToBeProcessed(CtInvocation<?> candidate) {
if (!candidate.getExecutable().getSimpleName().contains("assert")) {
return false;
}
CtExecutableReference<?> executable = candidate.getExecutable();
CtPackageReference executablePackage = executable.getDeclaringType()
.getPackage();
if (executablePackage == null
|| !executablePackage.getSimpleName().contains("junit")) {
return false;
}
CtMethod<?> parentMethod = candidate.getParent(CtMethod.class);
if (parentMethod == null) {
return false;
}
createExecutionMethod(candidate);
return super.isToBeProcessed(candidate);
/*
* boolean found = false; for (TestCase testCase : faillingTest) { if
* (testCase.className().equals(parentClass.getQualifiedName())) { if
* (testCase.testName().equals(parentMethod.getSimpleName())) { found =
* true; break; } } }
*
* return found;
*/
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:28,代码来源:AssertReplacer.java
示例9: createObserve
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
CtInvocation createObserve(CtMethod getter, CtInvocation invocationToGetter) {
CtTypeAccess accessToLogger =
factory.createTypeAccess(factory.createCtTypeReference(Logger.class));
CtExecutableReference refObserve = factory.Type().get(Logger.class)
.getMethodsByName("observe").get(0).getReference();
return factory.createInvocation(
accessToLogger,
refObserve,
factory.createLiteral(getKey(getter)),
invocationToGetter
);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:13,代码来源:Collector.java
示例10: createAssert
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
public static CtInvocation createAssert(String name, CtExpression... parameters) {
final Factory factory = parameters[0].getFactory();
CtTypeAccess accessToAssert =
factory.createTypeAccess(factory.createCtTypeReference(Assert.class));
CtExecutableReference assertEquals = factory.Type().get(Assert.class)
.getMethodsByName(name).get(0).getReference();
return factory.createInvocation(
accessToAssert,
assertEquals,
parameters[0],
parameters[1]
);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:14,代码来源:AssertionAdder.java
示例11: getCreatedTypes
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
private List<CtTypeReference<?>> getCreatedTypes() {
if (createdTypes == null) {
createdTypes = new ArrayList<CtTypeReference<?>>();
for (CtExecutableReference<?> m : getFactoryType().getDeclaredExecutables()) {
createdTypes.add(m.getType());
}
}
return createdTypes;
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:10,代码来源:FactoryProcessor.java
示例12: isTypeChecking
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
private boolean isTypeChecking(CtExecutableReference exe) {
List<CtTypeReference> params = exe.getParameters();
for(CtTypeReference p : params) {
if (p.getSimpleName().equals("Type")) return true;
}
return false;
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:8,代码来源:RemoveTypeFormatingQuery.java
示例13: getTypeParam
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
private CtExpression getTypeParam(CtInvocation invocation) {
CtExecutableReference exe = invocation.getExecutable();
List<CtTypeReference> params = exe.getParameters();
for(CtTypeReference p : params) {
if (p.getSimpleName().equals("Type")) return (CtExpression) invocation.getArguments().get(params.indexOf(p));
}
return null;
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:9,代码来源:RemoveTypeFormatingQuery.java
示例14: parametersMatch
import spoon.reflect.reference.CtExecutableReference; //导入依赖的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,代码来源:SwapSubTypeQuery.java
示例15: getStatMethod
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
public Map<CtExecutableReference, Integer> getStatMethod() {
return statMethod;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:4,代码来源:StatCollector.java
示例16: invok
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
public static CtInvocation invok(CtMethod method, CtLocalVariable localVariable) {
final CtExecutableReference reference = method.getReference();
final CtVariableAccess variableRead = method.getFactory().createVariableRead(localVariable.getReference(), false);
return method.getFactory().createInvocation(variableRead, reference);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:6,代码来源:Util.java
示例17: process
import spoon.reflect.reference.CtExecutableReference; //导入依赖的package包/类
@Override
public void process(final @NotNull CtTypeReference<?> element) {
final CtElement parent = element.getParent();
LOG.log(Level.INFO, () -> "PROCESSING " + element + " " + parent.getClass());
if(parent instanceof CtField<?> || parent instanceof CtLocalVariable<?>) {
onWidgetVar((CtVariable<?>) parent);
return;
}
if(parent instanceof CtExecutableReference<?> && parent.getParent() instanceof CtConstructorCall<?>) {
analyseWidgetConstructorCall((CtConstructorCall<?>) parent.getParent());
return;
}
if(parent instanceof CtAssignment<?,?>) {
analyseWidgetAssignment((CtAssignment<?, ?>) parent);
return;
}
if(parent instanceof CtFieldReference<?>) {
CtField<?> decl = ((CtFieldReference<?>) parent).getDeclaration();
if(decl!=null && WidgetHelper.INSTANCE.isTypeRefAWidget(decl.getType())) {
onWidgetVar(decl);
}
return;
}
if(parent instanceof CtMethod<?>) {
analyseMethodUse((CtMethod<?>) parent);
return;
}
if(parent instanceof CtExecutableReference<?>) {
// A method is called on a widget, so ignored.
return;
}
if(parent instanceof CtTypeAccess<?>) {
// A static method / attribute is used on a widget class.
return;
}
if(parent instanceof CtClass<?>) {
// A widget class is used.
return;
}
if(parent instanceof CtLocalVariableReference<?> || parent instanceof CtVariableRead<?>) {
// A widget var assigned to a local var; or simply used.
return;
}
if(parent instanceof CtThisAccess<?>) {
// Use of this on a widget object.
return;
}
LOG.log(Level.WARNING, "CTypeReference parent not supported or ignored: " + parent.getClass() + " " + parent);
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:56,代码来源:WidgetProcessor.java
注:本文中的spoon.reflect.reference.CtExecutableReference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论