Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

review: refactor AllTypeMembersFunction #1285

Merged
merged 1 commit into from
May 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@
import java.util.Set;

import spoon.reflect.declaration.CtType;
import spoon.reflect.declaration.CtTypeInformation;
import spoon.reflect.declaration.CtTypeMember;
import spoon.reflect.visitor.chain.CtConsumableFunction;
import spoon.reflect.visitor.chain.CtConsumer;
import spoon.reflect.visitor.chain.CtQuery;
import spoon.reflect.visitor.chain.CtQueryAware;
import spoon.reflect.visitor.chain.CtQueryable;

/**
* Expects {@link CtType} as input
* and produces all {@link CtTypeMember}s declared in input class
* or any super class or super interface
*/
public class AllTypeMembersFunction implements CtConsumableFunction<CtType<?>>, CtQueryAware {
public class AllTypeMembersFunction implements CtConsumableFunction<CtTypeInformation>, CtQueryAware {

private CtQuery query;
private final Class<?> memberClass;
private Set<String> distintSet;
private Set<String> distinctSet;

/**
* returns all type members
Expand All @@ -55,14 +57,19 @@ public AllTypeMembersFunction(Class<?> memberClass) {
this.memberClass = memberClass;
}

public AllTypeMembersFunction distinctSet(Set<String> distintSet) {
this.distintSet = distintSet;
/**
* The types whose qualified name is in distinctSet are not visited.
* The qualified name of each type visited by this mapping function is added to `distinctSet`
* @param distinctSet - Set of qualified names of types, which has to be ignored, because they were already processed
*/
public AllTypeMembersFunction distinctSet(Set<String> distinctSet) {
this.distinctSet = distinctSet;
return this;
}

@Override
public void apply(CtType<?> input, final CtConsumer<Object> outputConsumer) {
final CtQuery q = input.map(new SuperInheritanceHierarchyFunction(distintSet == null ? new HashSet<String>() : distintSet).includingSelf(true));
public void apply(CtTypeInformation input, final CtConsumer<Object> outputConsumer) {
final CtQuery q = ((CtQueryable) input).map(new SuperInheritanceHierarchyFunction(distinctSet == null ? new HashSet<String>() : distinctSet).includingSelf(true));
q.forEach(new CtConsumer<CtType<?>>() {
@Override
public void accept(CtType<?> type) {
Expand Down