当前位置: 首页>>代码示例>>Java>>正文


Java CtTypeReference类代码示例

本文整理汇总了Java中spoon.reflect.reference.CtTypeReference的典型用法代码示例。如果您正苦于以下问题:Java CtTypeReference类的具体用法?Java CtTypeReference怎么用?Java CtTypeReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CtTypeReference类属于spoon.reflect.reference包,在下文中一共展示了CtTypeReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import spoon.reflect.reference.CtTypeReference; //导入依赖的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: inheritsFrom

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
public boolean inheritsFrom(CtType testType) {
    CtTypeReference testReference = testType.getReference();
    CtTypeReference ctTypeReference = ctType.getReference();

    while ((ctTypeReference = ctTypeReference.getSuperclass()) != null) {
        if (ctTypeReference.equals(testReference)) {
            return true;
        }
    }

    for (CtTypeReference<?> ctInterface : ctType.getReference().getSuperInterfaces()) {
        if (ctInterface.equals(testReference)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:slipperyseal,项目名称:trebuchet,代码行数:18,代码来源:ClassShovel.java

示例3: addClassSignature

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
private void addClassSignature(CtType ctType) {
    headerWriter.print("class ");
    headerWriter.print(name);

    FirstPrintOptions firstPrintOptions = new FirstPrintOptions(headerWriter, ":", ",");
    CtTypeReference ctTypeReferenceSuper = ctType.getSuperclass();
    if (ctTypeReferenceSuper != null) {
        firstPrintOptions.print();
        headerWriter.print(" public ");
        headerWriter.print(typeMapper.getTypeName(ctTypeReferenceSuper));
    }
    for (CtTypeReference ctTypeReference : ctType.getSuperInterfaces()) {
        firstPrintOptions.print();
        headerWriter.print(" public ");
        headerWriter.print(typeMapper.getTypeName(ctTypeReference));
    }
}
 
开发者ID:slipperyseal,项目名称:trebuchet,代码行数:18,代码来源:ClassShovel.java

示例4: run

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
public static TestListener run(InputConfiguration configuration,
							   URLClassLoader classLoader,
							   CtType<?> testClass,
							   Collection<String> testMethodNames,
                                  RunListener... listeners) {
	Logger.reset();
	Logger.setLogDir(new File(configuration.getInputProgram().getProgramDir() + "/log"));
	if (testClass.getModifiers().contains(ModifierKind.ABSTRACT)) {
		final CtTypeReference<?> referenceToAbstractClass = testClass.getReference();
		return testClass.getFactory().Class().getAll().stream()
				.filter(ctType -> ctType.getSuperclass() != null)
				.filter(ctType ->
						ctType.getSuperclass().equals(referenceToAbstractClass)
				)
				.map(ctType -> run(configuration, classLoader, ctType, testMethodNames, listeners))
				.reduce(new TestListener(), TestListener::aggregate);
	}
	return TestRunnerFactory.createRunner(testClass, classLoader).run(testClass.getQualifiedName(), testMethodNames, listeners);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:20,代码来源:TestLauncher.java

示例5: createAmplifiedTest

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
public static CtType createAmplifiedTest(List<CtMethod<?>> ampTest, CtType<?> classTest) {
    CtType amplifiedTest = classTest.clone();
    final String amplifiedName = classTest.getSimpleName().startsWith("Test") ?
            classTest.getSimpleName() + "Ampl" :
            "Ampl" + classTest.getSimpleName();
    amplifiedTest.setSimpleName(amplifiedName);
    classTest.getMethods().stream().filter(AmplificationChecker::isTest).forEach(amplifiedTest::removeMethod);
    ampTest.forEach(amplifiedTest::addMethod);
    final CtTypeReference classTestReference = classTest.getReference();
    amplifiedTest.getElements(new TypeFilter<CtTypeReference>(CtTypeReference.class) {
        @Override
        public boolean matches(CtTypeReference element) {
            return element.equals(classTestReference) && super.matches(element);
        }
    }).forEach(ctTypeReference -> ctTypeReference.setSimpleName(amplifiedName));
    classTest.getPackage().addType(amplifiedTest);
    return amplifiedTest;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:19,代码来源:AmplificationHelper.java

示例6: generateSingletonList

import spoon.reflect.reference.CtTypeReference; //导入依赖的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

示例7: generateRandomValue

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
static CtExpression<?> generateRandomValue(CtTypeReference type) {
        if (AmplificationChecker.isPrimitive(type)) {
            return generatePrimitiveRandomValue(type);
        } else {
            try {
                if (AmplificationChecker.isArray(type)) {
                    return generateArray(type);
                } else if (type.getActualClass() == String.class) {
                    return type.getFactory().createLiteral(AmplificationHelper.getRandomString(20));
                } else if (type.getActualClass() == Collection.class ||
                        type.getActualClass() == List.class ||
                        type.getSuperInterfaces().contains(type.getFactory().Type().get(List.class).getReference())) {
                    return CollectionCreator.generateCollection(type, "List", List.class);
                } else if (type.getActualClass() == Set.class) {
                    return CollectionCreator.generateCollection(type, "Set", Set.class);
                } else if (type.getActualClass() == Map.class) {
                    return CollectionCreator.generateCollection(type, "Map", Map.class);
                }
            } catch (SpoonException exception) {
                // couldn't load the definition of the class, it may be a client class
                return ConstructorCreator.generateConstructionOf(type);
            }
        }
        return ConstructorCreator.generateConstructionOf(type);
//		throw new RuntimeException();
    }
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:27,代码来源:ValueCreator.java

示例8: canGenerateAValueForType

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
public static boolean canGenerateAValueForType(CtTypeReference type) {
    try {
        if (AmplificationChecker.isPrimitive(type)) {
            return true;
        } else {
            try {
                if (AmplificationChecker.isArray(type) ||
                        type.getActualClass() == String.class ||
                        type.getActualClass() == Collection.class ||
                        type.getActualClass() == List.class ||
                        type.getActualClass() == Set.class ||
                        type.getActualClass() == Map.class) {
                    return true;
                }
            } catch (SpoonClassNotFoundException exception) {
                // couldn't load the definition of the class, it may be a client class
                return canGenerateConstructionOf(type);
            }
        }
        return canGenerateConstructionOf(type);
    } catch (Exception e) {
        return false;
    }
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:25,代码来源:ValueCreatorHelper.java

示例9: findMethodsWithTargetType

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
private List<CtMethod<?>> findMethodsWithTargetType(CtTypeReference<?> type) {
    if (type == null) {
        return Collections.emptyList();
    } else {
        return type.getTypeDeclaration().getMethods().stream()
                .filter(method -> method.getModifiers().contains(ModifierKind.PUBLIC)) // TODO checks this predicate
                // TODO we could also access to method with default or protected modifiers
                .filter(method -> !method.getModifiers().contains(ModifierKind.STATIC)) // TODO checks this predicate
                // TODO we can't amplify test on full static classes with this predicate
                .filter(method -> !method.getModifiers().contains(ModifierKind.ABSTRACT)) // TODO checks this predicate
                // TODO maybe we would like to call of abstract method, since the abstract would be implemented
                // TODO inherited classes. However, the semantic of the test to be amplified may be to test the abstract class
                .filter(method -> method.getParameters()
                        .stream()
                        .map(CtParameter::getType)
                        .allMatch(ValueCreatorHelper::canGenerateAValueForType)
                ).collect(Collectors.toList());
    }
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:20,代码来源:StatementAdd.java

示例10: removeAssertion

import spoon.reflect.reference.CtTypeReference; //导入依赖的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

示例11: findFromStatement

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
protected void findFromStatement(CtStatement statement) {
    CtType parentType;
    try {
        parentType = parentOfType(CtType.class, statement);
    } catch (ParentNotInitializedException e) {
        return;
    }
    if (parentType == null) {
        return;
    }
    ReachableVariableVisitor variableVisitor = new ReachableVariableVisitor(statement);
    Collection<CtVariable<?>> reachedVariables = variablesInitializedBefore(statement, variableVisitor.reachedVariables());
    addVariableNames(reachedVariables);
    CtTypeReference<?> typeReference = parentType.getReference();
    addVisibleFieldsOfParameters(reachedVariables, typeReference);
    addGettersOfFields(reachedVariables, typeReference);
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:18,代码来源:CollectableValueFinder.java

示例12: isVisibleFrom

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
private static boolean isVisibleFrom(CtTypeReference<?> accessingClass, CtModifiable modifiable, CtTypeReference<?> declaringClass, CtTypeReference<?> actualClass) {
    if (hasPublicModifier(modifiable)) {
        return true;
    }
    if ((isNestedIn(accessingClass, actualClass) || isNestedIn(actualClass, accessingClass)) && areSameClass(declaringClass, actualClass)) {
        return true;
    }
    if (hasNoVisibilityModifier(modifiable) && areFromSamePackage(declaringClass, actualClass) && areFromSamePackage(actualClass, accessingClass)) {
        return true;
    }
    if (hasPrivateModifier(modifiable) && areSameClass(declaringClass, accessingClass)) {
        return true;
    }
    if (hasProtectedModifier(modifiable) && areFromSamePackage(declaringClass, accessingClass)) {
        return true;
    }
    if (hasProtectedModifier(modifiable) && isSubclassOf(declaringClass, accessingClass) && areSameClass(actualClass, accessingClass)) {
        return true;
    }
    return false;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:22,代码来源:SpoonReferenceLibrary.java

示例13: getDependencies

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
/**
 * get all dependencies added by a CtTypedElement
 *
 * @param element
 * @return all dependencies added by element
 */
private List<CtTypeReference<?>> getDependencies(CtTypedElement<?> element) {
    List<CtTypeReference<?>> listDependencies = new ArrayList<>();
    // Literal
    if (element instanceof CtAnnotation) {
        return listDependencies;
    }
    if (element instanceof CtLiteral<?>) {
        CtLiteral<?> literal = (CtLiteral<?>) element;
        literal.getValue();
        if (literal.getValue() instanceof CtTypeReference<?>) {
            listDependencies.add((CtTypeReference<?>) literal.getValue());
        } else if (literal.getValue() instanceof CtTypedElement<?>) {
            listDependencies.add(((CtTypedElement<?>) literal.getValue())
                    .getType());
        }
    }
    // method invocation
    if (element instanceof CtInvocation<?>) {
        CtInvocation<?> invocation = (CtInvocation<?>) element;
        // the class of the method
        listDependencies.add(invocation.getExecutable().getDeclaringType());
    }
    listDependencies.add(element.getType());
    return listDependencies;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:32,代码来源:VariablesInSuspiciousCollector.java

示例14: process

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
public void process(CtPackage element) {
	CtPackageReference pack = element.getReference();
	Set<CtPackageReference> refs = new HashSet<CtPackageReference>();
	for (CtType t : element.getTypes()) {
		List<CtTypeReference<?>> listReferences = Query.getReferences(t, new ReferenceTypeFilter<CtTypeReference<?>>(CtTypeReference.class));

		for (CtTypeReference<?> tref : listReferences) {
			if (tref.getPackage() != null && !tref.getPackage().equals(pack)) {
				if (ignoredTypes.contains(tref))
					continue;
				refs.add(tref.getPackage());
			}
		}
	}
	if (refs.size() > 0) {
		packRefs.put(pack, refs);
	}
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:19,代码来源:ReferenceProcessor.java

示例15: getVarWidgetUsedInCmdConditions

import spoon.reflect.reference.CtTypeReference; //导入依赖的package包/类
/**
 * Identifies the widgetUsages used the conditions of the given command.
 * @param cmd The comand to analyse
 * @return The list of the references to the widgetUsages used in the conditions.
 */
private @NotNull Set<WidgetProcessor.WidgetUsage> getVarWidgetUsedInCmdConditions(final @NotNull Command cmd) {
	final TypeRefFilter filter = new TypeRefFilter(WidgetHelper.INSTANCE.getWidgetTypes(cmd.getExecutable().getFactory()));
	// Getting the widget types used in the conditions.
	final List<CtTypeReference<?>> types = cmd.getConditions().stream().
		// We do not keep the conditional statements that come from of if else if else.
		filter(cond -> cond.isSameCondition()).
		map(cond -> cond.realStatmt.getElements(filter)).
		flatMap(s -> s.stream()).distinct().collect(Collectors.toList());

	// Getting the widget usages which variable is used in the conditions.
	return widgetUsages.parallelStream().filter(u -> types.stream().anyMatch(w -> {
		try {
			final CtVariableReference<?> parent = w.getParent(CtVariableReference.class);
			return parent != null && u.widgetVar == parent.getDeclaration();
		}catch(ParentNotInitializedException ex) {
			return false;
		}
	})).collect(Collectors.toSet());
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:25,代码来源:CommandWidgetFinder.java


注:本文中的spoon.reflect.reference.CtTypeReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。