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

Java Filter类代码示例

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

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



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

示例1: processOverridden

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
private static <T> void processOverridden(CtClass<?> mergeInto, CtClass<?> toMerge,
                                          final CtMethod<T> methodToMerge) {
    List<CtInvocation<T>> superInvocations = mergeInto.getElements(
            new Filter<CtInvocation<T>>() {
                @Override
                public boolean matches(CtInvocation<T> invocation) {
                    if (!(invocation.getTarget() instanceof CtSuperAccess))
                        return false;
                    CtExecutable<?> m = invocation.getExecutable().getDeclaration();
                    return m != null && MethodNode.overrides((CtMethod<?>) m, methodToMerge);
                }
            });
    
    methodToMerge.setSimpleName(classPrefixedName(toMerge, methodToMerge));
    methodToMerge.setVisibility(PRIVATE);
    removeAnnotation(methodToMerge, Override.class);
    
    for (CtInvocation<T> superInvocation : superInvocations) {
        superInvocation.setTarget(null);
        superInvocation.setExecutable(methodToMerge.getReference());
    }
    add(mergeInto, methodToMerge, mergeInto::addMethod);
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:24,代码来源:ExtensionChains.java


示例2: findWidgetRegistrations

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
private @NotNull Set<CtAbstractInvocation<?>> findWidgetRegistrations(final @NotNull WidgetProcessor.WidgetUsage usage) {
	final CtExecutable<?> cmdExec = cmd.getExecutable();
	final Filter<CtAbstractInvocation<?>> filter = new BasicFilter<CtAbstractInvocation<?>>(CtAbstractInvocation.class) {
		@Override
		public boolean matches(final CtAbstractInvocation<?> exec) {
			final OptionalInt pos = getListenerRegPositionInInvok(exec);
			return pos.isPresent() && WidgetHelper.INSTANCE.isListenerClass(exec.getExecutable().getParameters().get(pos.getAsInt()),
				exec.getFactory(), WidgetHelper.INSTANCE.getListenerInterface(cmdExec).orElse(null));
		}
	};

	return usage.getUsagesWithCons().stream().
		// gathering their parent statement.
			map(acc -> SpoonHelper.INSTANCE.getStatement(acc)).filter(stat -> stat.isPresent()).map(stat -> stat.get()).
		// Gathering the method call that matches listener registration: single parameter that is a listener type.
			map(stat -> stat.getElements(filter)).flatMap(s -> s.stream()).collect(Collectors.toSet());
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:18,代码来源:ListenerCommandRefactor.java


示例3: changeThisAccesses

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
/**
 * The statements of the command may refer to the external listener through 'this'. In such a case, the 'this' has to be changed
 * in a variable access.
 */
private void changeThisAccesses(final @NotNull List<CtElement> stats, final @NotNull CtAbstractInvocation<?> regInvok) {
	final Filter<CtThisAccess<?>> filter = new ThisAccessFilter(false);
	final CtExecutable<?> regMethod = regInvok.getParent(CtExecutable.class);

	stats.stream().map(stat -> stat.getElements(filter)).flatMap(s -> s.stream()).forEach(th -> {
		List<CtLocalVariable<?>> thisVar = regMethod.getElements(new BasicFilter<CtLocalVariable<?>>(CtLocalVariable.class) {
			@Override
			public boolean matches(final CtLocalVariable<?> element) {
				final CtType<?> decl = element.getType().getDeclaration();
				return decl!=null && decl.equals(th.getType().getDeclaration());
			}
		});
		if(thisVar.isEmpty()) {
			LOG.log(Level.SEVERE, "Cannot find a local variable for a 'this' access: " + thisVar);
		}else {
			th.replace(regInvok.getFactory().Code().createVariableRead(thisVar.get(0).getReference(), false));
		}
	});
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:24,代码来源:ListenerCommandRefactor.java


示例4: getFieldInitializer

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
public List<CtLiteral> getFieldInitializer(CtField ctField) {
    List<CtLiteral> ctLiterals = new ArrayList<CtLiteral>();
    for (CtElement ctElement : ctField.getElements(new Filter<CtLiteral>() {
        @Override
        public boolean matches(CtLiteral ctLiteral) {
            return true;
        }
    })) {
        ctLiterals.add((CtLiteral)ctElement);
    }
    return ctLiterals;
}
 
开发者ID:slipperyseal,项目名称:trebuchet,代码行数:13,代码来源:FieldGroups.java


示例5: wasInitializedBefore

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
private boolean wasInitializedBefore(CtStatement statement, CtVariable<?> variable) {
    if (variable.getDefaultExpression() == null) {
        CtBlock<?> block = variable.getParent(CtBlock.class);
        Filter<CtAssignment<?, ?>> filter = initializationAssignmentsFilterFor(variable, statement);
        return !block.getElements(filter).isEmpty();
    }
    return true;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:9,代码来源:CollectableValueFinder.java


示例6: initializationAssignmentsFilterFor

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
private Filter<CtAssignment<?, ?>> initializationAssignmentsFilterFor(CtVariable<?> variable, CtStatement statement) {
    VariableAssignmentFilter variableAssignment = new VariableAssignmentFilter(variable);
    BeforeLocationFilter<CtAssignment<?, ?>> beforeLocation = new BeforeLocationFilter(CtAssignment.class, statement.getPosition());
    InBlockFilter<CtAssignment<?, ?>> inVariableDeclarationBlock = new InBlockFilter(CtAssignment.class, asList(variable.getParent(CtBlock.class)));
    InBlockFilter<CtAssignment<?, ?>> inStatementBlock = new InBlockFilter(CtAssignment.class, asList(statement.getParent(CtBlock.class)));
    Filter<CtAssignment<?, ?>> inBlockFilter = new CompositeFilter(FilteringOperator.UNION, inStatementBlock, inVariableDeclarationBlock);
    return new CompositeFilter(FilteringOperator.INTERSECTION, variableAssignment, beforeLocation, inBlockFilter);
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:9,代码来源:CollectableValueFinder.java


示例7: process

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
@Override
public void process(final CtMethod<?> method) {
    if (method != null) {
        if (isTestCase(method)) {
            instrumentMethod(method);
        } else {
            if (method.getBody() != null) {
                List<CtIf> ifList = method.getBody().getElements(
                        new Filter<CtIf>() {

                            @Override
                            public boolean matches(CtIf arg0) {
                                if (!(arg0 instanceof CtIf)) {
                                    return false;
                                }

                                return true;
                            }
                        });
                for (CtIf tmp : ifList) {
                    instrumentIfInsideMethod(tmp);
                }
            }
        }

        String s = method.getDeclaringType().getQualifiedName();
        if (this.ifMetric != null && !this.ifMetric.modifyClass.contains(s)) {
            this.ifMetric.modifyClass.add(s);
        }


    }

}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:35,代码来源:IfCountingInstrumentingProcessor.java


示例8: elementFromSnippet

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private CtElement elementFromSnippet(File sourceFile, String codeSnippet) {
	Factory model = SpoonModelLibrary.modelFor(new File[]{sourceFile});
	Filter filter = new CodeSnippetFilter(sourceFile, codeSnippet);
	List<CtElement> elements = SpoonElementLibrary.filteredElements(model, filter);
	assertEquals(1, elements.size());
	return elements.get(0);
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:9,代码来源:ValuesCollectorTest.java


示例9: filterBlocksForBuildingDeps

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
@Override
public <E extends CtElement> List<E> filterBlocksForBuildingDeps(Filter<E> filter) {
    Stream<CtMethod<?>> depsBuildingMethods =
            concat(initStageMethods.stream(), stageMethods.keySet().stream());
    Stream<CtMethod<Void>> closeMethods =
            Stream.of(getCloseMethod().get(), getDoCloseMethod());
    depsBuildingMethods = concat(depsBuildingMethods, closeMethods);
    return depsBuildingMethods.flatMap(initMethod -> initMethod.getElements(filter).stream())
            .collect(toList());
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:11,代码来源:StageModel.java


示例10: checkListenerMatching

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
/**
 * Checks that the matchings correspond to the listener that contains the command:
 * a reference of the listener is searched in the usages of the identified widgets and is compared
 * to the listener of the command to determine whether this widget really matches the command.
 * This analysis does not work with toolkit that does not require listener registration such as
 * with JavaFX where a listener method can be associated with the widget directly in the FXML.
 * @param listenerClass The listener class of the command.
 * @param cmdWidgetMatches The list of the widgets that may correspond to the command.
 * @param <T> The type of the matching.
 * @return The filtered list of widgets.
 */
private @NotNull <T extends CmdWidgetMatch> List<T> checkListenerMatching(final @Nullable CtClass<?> listenerClass, final @NotNull List<T> cmdWidgetMatches) {
	if(listenerClass == null) return cmdWidgetMatches;

	final CtTypeReference<?> listRef = listenerClass.getReference();
	final Filter<CtTypedElement<?>> filt = new BasicFilter<>(CtTypedElement.class);

	cmdWidgetMatches.removeIf(m ->
		// Removing if in the statement of the access there is a reference to the current listener class.
		m.usage.getUsagesWithCons().stream().noneMatch(a -> a.getParent(CtStatement.class).getElements(filt).stream().
			map(var -> var.getType()).anyMatch(ty -> ty != null && ty.equals(listRef))));
	return cmdWidgetMatches;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:24,代码来源:CommandWidgetFinder.java


示例11: removeActionCommandStatements

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


示例12: changeNonLocalFieldAccesses

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
private void changeNonLocalFieldAccesses(final @NotNull List<CtElement> stats, final @NotNull CtAbstractInvocation<?> regInvok) {
	final Filter<CtFieldRead<?>> filter = new BasicFilter<>(CtFieldRead.class);
	// Getting the class where the listener is registered.
	final CtType<?> listenerRegClass = regInvok.getParent(CtType.class);
	final List<CtFieldRead<?>> nonLocalFieldAccesses =
		// Getting all the invocations used in the statements.
		stats.stream().map(stat -> stat.getElements(filter)).flatMap(s -> s.stream()).
			// Keeping the invocations that are on fields
				filter(f -> f.getVariable().getDeclaration()!=null &&
				// Keeping the invocations that calling fields are not part of the class that registers the listener.
				f.getVariable().getDeclaration().getParent(CtType.class) != listenerRegClass).
			collect(Collectors.toList());

	// The invocation may refer to a method that is defined in the class where the registration occurs.
	nonLocalFieldAccesses.stream().filter(field -> {
		try {
			return field.getType().getDeclaration() == listenerRegClass;
		}catch(final ParentNotInitializedException ex) {
			return false;
		}
	}).
		// In this case, the target of the invocation (the field read) is removed since the invocation will be moved to
		// the registration class.
		forEach(f -> {
			LOG.log(Level.INFO, () -> cmd + ": removing a field access by its target: " + f);
			f.replace(f.getTarget());
		});
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:29,代码来源:ListenerCommandRefactor.java


示例13: filteredElements

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
public static <T extends CtElement> List<T> filteredElements(Factory factory, Filter<T> filter) {
    return Query.getElements(factory, filter);
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:4,代码来源:SpoonElementLibrary.java


示例14: generateMutants

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
/** returns a list of mutant classes */
public void generateMutants() {
	Launcher l = new Launcher();
	l.addInputResource(sourceCodeToBeMutated);
	l.buildModel();

	CtClass origClass = (CtClass) l.getFactory().Package().getRootPackage()
			.getElements(new TypeFilter(CtClass.class)).get(0);

	// now we apply a transformation
	// we replace "+" and "*" by "-"
	List<CtElement> elementsToBeMutated = origClass.getElements(new Filter<CtElement>() {

		@Override
		public boolean matches(CtElement arg0) {
			return mutator.isToBeProcessed(arg0);
		}
	});
	
	for (CtElement e : elementsToBeMutated) {
		// this loop is the trickiest part
		// because we want one mutation after the other
		
		// cloning the AST element
		CtElement op = l.getFactory().Core().clone(e);
		
		// mutate the element
		mutator.process(op);
		
		// temporarily replacing the original AST node with the mutated element 
		replace(e,op);

		// creating a new class containing the mutating code
		CtClass klass = l.getFactory().Core()
				.clone(op.getParent(CtClass.class));
		// setting the package
		klass.setParent(origClass.getParent());

		// adding the new mutant to the list
		mutants.add(klass);

		// restoring the original code
		replace(op, e);
	}
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:46,代码来源:MutationTester.java


示例15: example

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
@Test
public void example() throws Exception {
 Launcher l = new Launcher();
 
 // required for having IFoo.class in the classpath in Maven
 l.setArgs(new String[] {"--source-classpath","target/test-classes"});
 
 l.addInputResource("src/test/resources/transformation/");
 l.buildModel();
 
 CtClass foo = l.getFactory().Package().getRootPackage().getElements(new NamedElementFilter<>(CtClass.class, "Foo1")).get(0);

 // compiling and testing the initial class
 Class<?> fooClass = InMemoryJavaCompiler.newInstance().compile(foo.getQualifiedName(), "package "+foo.getPackage().getQualifiedName()+";"+foo.toString());
 IFoo x = (IFoo) fooClass.newInstance();
 // testing its behavior
 assertEquals(5, x.m());

 // now we apply a transformation
 // we replace "+" by "-"
 for(Object e : foo.getElements(new TypeFilter(CtBinaryOperator.class))) {
  CtBinaryOperator op = (CtBinaryOperator)e;
  if (op.getKind()==BinaryOperatorKind.PLUS) {
	  op.setKind(BinaryOperatorKind.MINUS);
  }
 }
 
 // first assertion on the results of the transfo
 
 // there are no more additions in the code
 assertEquals(0, foo.getElements(new Filter<CtBinaryOperator<?>>() {
@Override
public boolean matches(CtBinaryOperator<?> arg0) {
	return arg0.getKind()==BinaryOperatorKind.PLUS;
}		  
 }).size());

 // second assertions on the behavior of the transformed code
 
 // compiling and testing the transformed class
 fooClass = InMemoryJavaCompiler.newInstance().compile(foo.getQualifiedName(), "package "+foo.getPackage().getQualifiedName()+";"+foo.toString());
 IFoo y = (IFoo) fooClass.newInstance();
 // testing its behavior with subtraction
 assertEquals(1, y.m());
 
 System.out.println("yes y.m()="+y.m());
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:48,代码来源:OnTheFlyTransfoTest.java


示例16: filterBlocksForBuildingDeps

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
@Override
public <E extends CtElement> List<E> filterBlocksForBuildingDeps(Filter<E> filter) {
    return methods.stream().flatMap(m -> m.getElements(filter).stream()).collect(toList());
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:5,代码来源:MethodNode.java


示例17: consumerToFilter

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
private static <E extends CtElement> Filter<E> consumerToFilter(Consumer<E> action) {
    return e -> {
        action.accept(e);
        return false;
    };
}
 
开发者ID:OpenHFT,项目名称:Stage-Compiler,代码行数:7,代码来源:DependencyNode.java


示例18: setOutputFilter

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
@Override
public void setOutputFilter(final Filter<CtType<?>> typeFilter) {
	cmdAnalyser.setOutputFilter(typeFilter);
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:5,代码来源:BlobListenerAnalyser.java


示例19: changeNonLocalMethodInvocations

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
private void changeNonLocalMethodInvocations(final @NotNull List<CtElement> stats, final @NotNull CtAbstractInvocation<?> regInvok) {
	final Filter<CtInvocation<?>> filter = new BasicFilter<>(CtInvocation.class);
	// Getting the class where the listener is registered.
	final CtType<?> listenerRegClass = regInvok.getParent(CtType.class);
	final List<CtInvocation<?>> nonLocalInvoks =
		// Getting all the invocations used in the statements.
		stats.stream().map(stat -> stat.getElements(filter)).flatMap(s -> s.stream()).
		// Keeping the invocations that are on fields
		filter(invok -> invok.getTarget() instanceof CtFieldRead &&
			((CtFieldRead<?>) invok.getTarget()).getVariable().getDeclaration()!=null &&
		// Keeping the invocations that calling fields are not part of the class that registers the listener.
			((CtFieldRead<?>) invok.getTarget()).getVariable().getDeclaration().getParent(CtType.class) != listenerRegClass).
		collect(Collectors.toList());

	// The invocation may refer to a method that is defined in the class where the registration occurs.
	nonLocalInvoks.stream().filter(invok -> invok.getTarget().getType().getDeclaration()==listenerRegClass).
		// In this case, the target of the invocation (the field read) is removed since the invocation will be moved to
		// the registration class.
		forEach(invok -> {
			LOG.log(Level.INFO, () -> cmd + ": removing the target of the invocation: " + invok);
			invok.setTarget(null);
		});

	// The invocation may refer to a attribute that is defined in the listener class but no where the registration occurs.
	nonLocalInvoks.stream().filter(invok -> invok.getTarget() instanceof CtFieldRead<?>).
		// Getting such fields.
		map(invok -> ((CtFieldRead<?>)invok.getTarget()).getVariable().getDeclaration()).
		filter(f -> f!=null).distinct().forEach(field -> {
			// Extracting the local usages of these fields
			field.getParent(CtClass.class).getElements(new MyVariableAccessFilter(field)).stream().
				map(u -> u instanceof CtStatement ? (CtStatement)u : u.getParent(CtStatement.class)).
				// Only considering the initialisation of these fields for the moment.
				filter(stat -> stat.getParent(CtConstructor.class)!=null).
				forEach(u -> {
					LOG.log(Level.INFO, () -> cmd + ": moving a listener attribute: " + u + " before " + regInvok);
					if(regInvok.getParent(CtBlock.class).getStatements().parallelStream().noneMatch(s -> s.equals(u))) {
						if(regInvok instanceof CtStatement) {
							((CtStatement)regInvok).insertBefore(u.clone()); // and moving it where the initialisation occurs.
						}
					}
				});

			LOG.log(Level.INFO, () -> cmd + ": moving a listener attribute: " + field + " from " + field.getParent(CtType.class).getSimpleName() + " to " + listenerRegClass.getSimpleName());
			if(listenerRegClass.getField(field.getSimpleName())==null) {
				listenerRegClass.addField(field.clone());
			}
	});
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:49,代码来源:ListenerCommandRefactor.java


示例20: setOutputFilter

import spoon.reflect.visitor.Filter; //导入依赖的package包/类
@Override
public void setOutputFilter(Filter<CtType<?>> typeFilter) {

}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:5,代码来源:InspectorGuidetAnalyser.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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