• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ModifierKind类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: contributeField

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
private void contributeField(ClassWriter classWriter, CtTypeReference<?> parentType, Property property) {
    if (property.isLeastSpecificType()) {
        CtField<?> field = getField(parentType, property.getName());
        if (field == null || EventImplGenTask.getAnnotation(field, "org.spongepowered.api.util.annotation.eventgen.UseField") == null) {
            generateField(classWriter, property);
        } else if (field.getModifiers().contains(ModifierKind.PRIVATE)) {
            throw new RuntimeException("You've annotated the field " + property.getName() + " with @SetField, "
                    + "but it's private. This just won't work.");
        } else if (!property.getType().isSubtypeOf(field.getType())) {
            throw new RuntimeException(String.format("In event %s with parent %s - you've specified field '%s' of type %s"
                    + " but the property has the type of %s", property.getAccessor().getDeclaringType().getQualifiedName(), parentType.getQualifiedName(), field.getSimpleName(), field.getType().getQualifiedName(), property.getType().getQualifiedName()));
        }
    }
}
 
开发者ID:SpongePowered,项目名称:event-impl-gen,代码行数:15,代码来源:ClassGenerator.java


示例17: removeActionCommandStatements

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
private void removeActionCommandStatements() {
	usages.forEach(usage -> {
		Filter<CtInvocation<?>> filter = new BasicFilter<CtInvocation<?>>(CtInvocation.class) {
			@Override
			public boolean matches(final CtInvocation<?> element) {
				return WidgetHelper.INSTANCE.ACTION_CMD_METHOD_NAMES.stream().anyMatch(elt -> element.getExecutable().getSimpleName().equals(elt));
			}
		};

		// Getting all the set action command and co statements.
		List<CtStatement> actionCmds = usage.accesses.stream().map(access -> access.getParent(CtStatement.class)).
			filter(stat -> stat != null && !stat.getElements(filter).isEmpty()).collect(Collectors.toList());

		// Deleting each set action command and co statement.
		actionCmds.forEach(stat -> {
			LOG.log(Level.INFO, () -> cmd + ": removing setActionCmd: " + stat);
			stat.delete();
			collectRefactoredType(stat);
		});

		// Deleting the unused private/protected/package action command names defined as constants or variables (analysing the
		// usage of public variables is time-consuming).
		actionCmds.stream().filter(cmds -> cmds instanceof CtInvocation<?>).
			// Considering the arguments of the invocation only.
			map(invok -> ((CtInvocation<?>)invok).getArguments()).flatMap(s -> s.stream()).
			map(arg -> arg.getElements(new VariableAccessFilter())).flatMap(s -> s.stream()).
			map(access -> access.getVariable().getDeclaration()).distinct().
			filter(var -> var!=null && (var.getVisibility()==ModifierKind.PRIVATE || var.getVisibility()==ModifierKind.PROTECTED ||
				var.getVisibility()==null) && SpoonHelper.INSTANCE.extractUsagesOfVar(var).size()<2).
			forEach(var -> {
				LOG.log(Level.INFO, () -> cmd + ": removing action cmd names: " + var);
				var.delete();
				collectRefactoredType(var);
			});
	});
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:37,代码来源:ListenerCommandRefactor.java


示例18: isToBeProcessed

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
@Override
public boolean isToBeProcessed(final @NotNull CtMethod<?> method) {
	final CtClass<?> parentClass = method.getParent(CtClass.class);

	return parentClass != null && method.getVisibility() != ModifierKind.ABSTRACT &&
		method.getAnnotations().stream().anyMatch(anot -> "Test".equals(anot.getAnnotationType().getSimpleName())) &&
		parentClass.isSubtypeOf(getFactory().Type().createReference(ApplicationTest.class));
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:9,代码来源:TestFXProcessor.java


示例19: isStaticAndInit

import spoon.reflect.declaration.ModifierKind; //导入依赖的package包/类
protected boolean isStaticAndInit(CtFieldAccess fieldAccess) {
    CtField field = fieldAccess.getVariable().getDeclaration();
    try {
        if (field != null) {
            return field.getModifiers().contains(ModifierKind.STATIC) && field.getAssignment() != null;
        } else {
            return Modifier.isStatic(fieldAccess.getVariable().getActualField().getModifiers());
        }
    } catch (Exception e) {
        return false;
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:FieldUsedInstrumenter.java


示例20: 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;
    }

    return candidate.getSimpleName().contains("test")
            || candidate.getAnnotations().stream()
            .map(annotation -> annotation.toString())
            .anyMatch(annotation -> annotation.startsWith("@org.junit.Test"));
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:14,代码来源:TestProcessor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EnumComboBoxModel类代码示例发布时间:2022-05-22
下一篇:
Java Reference类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap