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


Java ModifierKind类代码示例

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


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

示例1: process

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
public void process(CtMethod element) {
    Factory factory = this.getFactory();
    CtTry ctTry = factory.Core().createTry();
    ctTry.setBody(element.getBody());
    String snippet;
    String testName;
    if(element.getModifiers().contains(ModifierKind.STATIC)) {
        testName = element.getPosition().getCompilationUnit().getMainType().getQualifiedName() + "." + element.getSimpleName();
        snippet = this.getLogName() + ".testIn(Thread.currentThread(), \"" + testName + "\")";
    } else {
        testName = element.getSimpleName();
        snippet = this.getLogName() + ".testIn(Thread.currentThread(),this, \"" + testName + "\")";
    }

    CtCodeSnippetStatement snippetStatement = factory.Code().createCodeSnippetStatement(snippet);
    element.getBody().insertBegin(snippetStatement);
    snippet = this.getLogName() + ".testOut(Thread.currentThread())";
    CtCodeSnippetStatement snippetFinish = factory.Code().createCodeSnippetStatement(snippet);
    CtBlock finalizerBlock = factory.Core().createBlock();
    finalizerBlock.addStatement(snippetFinish);
    ctTry.setFinalizer(finalizerBlock);
    CtBlock methodBlock = factory.Core().createBlock();
    methodBlock.addStatement(ctTry);
    element.setBody(methodBlock);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:26,代码来源:TestLogProcessor.java

示例2: run

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

示例3: isTest

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
protected boolean isTest(CtMethod candidate) {
    if(candidate.isImplicit()
            || !candidate.getModifiers().contains(ModifierKind.PUBLIC)
            || candidate.getBody() == null
            || candidate.getBody().getStatements().size() == 0) {
        return false;
    }
    if(!guavaTestlib) {
        return candidate.getSimpleName().contains("test")
                || candidate.getAnnotations().stream()
                .map(annotation -> annotation.toString())
                .anyMatch(annotation -> annotation.startsWith("@org.junit.Test"));
    } else {
        return  candidate.getDeclaringType().getSimpleName().endsWith("Tester")
                && (candidate.getSimpleName().contains("test")
                || candidate.getAnnotations().stream()
                .map(annotation -> annotation.toString())
                .anyMatch(annotation -> annotation.startsWith("@org.junit.Test")));
    }
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:21,代码来源:TestProcessor.java

示例4: compileAndRunTests

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
private TestListener compileAndRunTests(CtType classTest, List<CtMethod<?>> currentTestList) {
	CtType amplifiedTestClass = this.testSelector.buildClassForSelection(classTest, currentTestList);
	final TestListener result = TestCompiler.compileAndRun(
			amplifiedTestClass,
			this.compiler,
			currentTestList,
			this.configuration
	);
	final long numberOfSubClasses = classTest.getFactory().Class().getAll().stream()
			.filter(subClass -> classTest.getReference().equals(subClass.getSuperclass()))
			.count();
	if (result == null ||
			!result.getFailingTests().isEmpty() ||
			(!classTest.getModifiers().contains(ModifierKind.ABSTRACT) &&
					result.getRunningTests().size() != currentTestList.size()) ||
			(classTest.getModifiers().contains(ModifierKind.ABSTRACT) &&
					numberOfSubClasses != result.getRunningTests().size())) {
		return null;
	} else {
		LOGGER.info("update test testCriterion");
		testSelector.update();
		return result;
	}
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:25,代码来源:Amplification.java

示例5: replaceRegistrationParameter

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
private <T> void replaceRegistrationParameter(final @NotNull CtExpression<T> elt,
											  final @NotNull CtAbstractInvocation<?> regInvok,
											  final @NotNull Set<CtAbstractInvocation<?>> unregInvoks,
											  final int regPos, final String widgetName) {
	final Factory fac = regInvok.getFactory();

	if(asField && cmd.getExecutable() instanceof CtMethod<?> || !unregInvoks.isEmpty()) {
		final CtField<T> newField = fac.Core().createField();
		newField.setSimpleName(widgetName + "Cmd");
		newField.addModifier(ModifierKind.FINAL);
		newField.setVisibility(ModifierKind.PRIVATE);
		newField.setType(elt.getType().clone());
		newField.setAssignment(elt);
		cmd.getExecutable().getParent(CtClass.class).addFieldAtTop(newField);
		regInvok.getArguments().get(regPos).replace(SpoonHelper.INSTANCE.createField(fac, newField));
		unregInvoks.forEach(unreg -> getListenerRegPositionInInvok(unreg).ifPresent(pos ->
			unreg.getArguments().get(pos).replace(SpoonHelper.INSTANCE.createField(fac, newField))));
	}else {
		regInvok.getArguments().get(regPos).replace(elt);
	}

	collectRefactoredType(regInvok);
	unregInvoks.forEach(unreg -> collectRefactoredType(unreg));
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:25,代码来源:ListenerCommandRefactor.java

示例6: findCandidates

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

示例7: isTest

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
public static boolean isTest(CtMethod<?> candidate) {
    CtClass<?> parent = candidate.getParent(CtClass.class);
    if (candidate.getAnnotation(org.junit.Ignore.class) != null) {
        return false;
    }
    if (candidate.isImplicit()
            || candidate.getVisibility() == null
            || !candidate.getVisibility().equals(ModifierKind.PUBLIC)
            || candidate.getBody() == null
            || candidate.getBody().getStatements().size() == 0
            || !candidate.getParameters().isEmpty()) {
        return false;
    }


    List<CtInvocation> listOfAssertion =
            candidate.getBody().getElements(new TypeFilter<CtInvocation>(CtInvocation.class) {
        @Override
        public boolean matches(CtInvocation element) {
            return hasAssertCall.test(element);
        }
    });

    if (listOfAssertion.isEmpty()) {
        listOfAssertion.addAll(candidate.getBody().getElements(new HasAssertInvocationFilter(3)));
    }

    if (!listOfAssertion.isEmpty()) {
        return true;
    }

    return (candidate.getAnnotation(org.junit.Test.class) != null ||
                    ((candidate.getSimpleName().contains("test") ||
                            candidate.getSimpleName().contains("should")) && !isTestJUnit4(parent)));
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:36,代码来源:AmplificationChecker.java

示例8: generateConstructionOf

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

示例9: canGenerateConstructionOf

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
private static boolean canGenerateConstructionOf(CtTypeReference type) {
    CtType<?> typeDeclaration = type.getDeclaration() == null ? type.getTypeDeclaration() : type.getDeclaration();
    return typeDeclaration != null &&
            !type.getModifiers().contains(ModifierKind.ABSTRACT) &&
            !typeDeclaration.getElements(new TypeFilter<CtConstructor>(CtConstructor.class) {
                @Override
                public boolean matches(CtConstructor element) {
                    return element.hasModifier(ModifierKind.PUBLIC);
                }
            }).isEmpty();
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:12,代码来源:ValueCreatorHelper.java

示例10: amplifyAllTests

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
public List<CtType> amplifyAllTests() throws InterruptedException, IOException, ClassNotFoundException {
    final List<CtType> amplifiedTest = inputProgram.getFactory().Class().getAll().stream()
            .filter(ctClass -> !ctClass.getModifiers().contains(ModifierKind.ABSTRACT))
            .filter(ctClass ->
                    ctClass.getMethods().stream()
                            .anyMatch(AmplificationChecker::isTest))
            .map(this::amplifyTest)
            .collect(Collectors.toList());
    writeTimeJson();
    return amplifiedTest;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:12,代码来源:DSpot.java

示例11: ctTypeToFullQualifiedName

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
/**
 * Will convert a CtType into a list of test classes full qualified names
 * in case of abstract test classes, otherwise returns only the full qualified name
 **/
private String ctTypeToFullQualifiedName(CtType<?> testClass) {
	if (testClass.getModifiers().contains(ModifierKind.ABSTRACT)) {
		CtTypeReference<?> referenceOfSuperClass = testClass.getReference();
		return testClass.getFactory().Class().getAll()
				.stream()
				.filter(ctType -> referenceOfSuperClass.equals(ctType.getSuperclass()))
				.map(CtType::getQualifiedName)
				.collect(Collectors.joining(","));
	} else {
		return testClass.getQualifiedName();
	}
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:17,代码来源:MavenAutomaticBuilder.java

示例12: ctTypeToFullQualifiedName

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
private String ctTypeToFullQualifiedName(CtType<?> testClass) {
    if (testClass.getModifiers().contains(ModifierKind.ABSTRACT)) {
        CtTypeReference<?> referenceOfSuperClass = testClass.getReference();
        return testClass.getFactory().Class().getAll()
                .stream()
                .filter(ctType -> referenceOfSuperClass.equals(ctType.getSuperclass()))
                .map(CtType::getQualifiedName)
                .collect(Collectors.joining(","));
    } else {
        return testClass.getQualifiedName();
    }
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:13,代码来源:GradleAutomaticBuilder.java

示例13: getClass

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
private CtClass<?> getClass(Factory factory) {
    final CtClass<?> aClass = factory.Class().create("MyTestClass");
    final CtMethod<Void> method = factory.createMethod();
    method.setSimpleName("method");
    method.setType(factory.Type().VOID_PRIMITIVE);
    method.setBody(factory.createCodeSnippetStatement("System.out.println()"));
    method.addModifier(ModifierKind.PUBLIC);
    aClass.addMethod(method);
    return aClass;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:11,代码来源:DSpotCompilerTest.java

示例14: createMainTestClass

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
public static void createMainTestClass(SpoonedFile spooner,
                                       String className) {
    Factory factory = spooner.spoonFactory();
    CtClass<Object> executeTestClass = factory.Class().create(className);

    CtTypeReference<String[]> typedReference = factory.Class()
            .createReference(String[].class);
    CtTypeReference<Object> returnTypedReference = factory.Class()
            .createReference("void");

    Set<ModifierKind> modifiers = new LinkedHashSet<>(2);
    modifiers.add(ModifierKind.PUBLIC);
    modifiers.add(ModifierKind.STATIC);

    HashSet<CtTypeReference<? extends Throwable>> exceptions = new HashSet<>();
    exceptions.add(factory.Class().createReference(Exception.class));

    CtBlock<?> body = spooner.spoonFactory().Core().createBlock();

    body.addStatement(factory
            .Code()
            .createCodeSnippetStatement(
                    "for (String method : methods) {\n\t\t"
                            + "String[] split = method.split(\"\\\\.\");\n\t\t"
                            + "Class.forName(method.replace(\".\" + split[split.length - 1], \"\")).getMethod(\"runJPFTest\", String[].class).invoke(null, new Object[] { new String[] { split[split.length - 1] }});}"));

    CtMethod<?> method = spooner
            .spoonFactory()
            .Method()
            .create(executeTestClass, modifiers, returnTypedReference,
                    "main", new ArrayList<CtParameter<?>>(), exceptions,
                    body);
    spooner.spoonFactory().Method()
            .createParameter(method, typedReference, "methods");
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:36,代码来源:TestExecutorProcessor.java

示例15: process

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
public void process(CtElement element) {
	if (element instanceof CtNamedElement || element instanceof CtField || element instanceof CtExecutable) {
		if (((CtModifiable) element).getModifiers().contains(ModifierKind.PUBLIC) || ((CtModifiable) element).getModifiers().contains(ModifierKind.PROTECTED)) {
			if (element.getDocComment() == null || element.getDocComment().equals("")) {
				undocumentedElements.add(element);
			}
		}
	}
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:10,代码来源:DocProcessor.java


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