From 638658d4bdf460febd0d583797ba71affec04770 Mon Sep 17 00:00:00 2001
From: Pavel Vojtechovsky
Date: Wed, 22 Feb 2017 21:37:18 +0100
Subject: [PATCH] feature: AllTypeMembersFunction
---
.../filter/AllTypeMembersFunction.java | 85 ++++++++++++++++++
.../reflect/declaration/CtTypeImpl.java | 89 +++++--------------
2 files changed, 106 insertions(+), 68 deletions(-)
create mode 100644 src/main/java/spoon/reflect/visitor/filter/AllTypeMembersFunction.java
diff --git a/src/main/java/spoon/reflect/visitor/filter/AllTypeMembersFunction.java b/src/main/java/spoon/reflect/visitor/filter/AllTypeMembersFunction.java
new file mode 100644
index 00000000000..6ad1cc7469d
--- /dev/null
+++ b/src/main/java/spoon/reflect/visitor/filter/AllTypeMembersFunction.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright (C) 2006-2017 INRIA and contributors
+ * Spoon - http://spoon.gforge.inria.fr/
+ *
+ * This software is governed by the CeCILL-C License under French law and
+ * abiding by the rules of distribution of free software. You can use, modify
+ * and/or redistribute the software under the terms of the CeCILL-C license as
+ * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL-C license and that you accept its terms.
+ */
+package spoon.reflect.visitor.filter;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import spoon.reflect.declaration.CtType;
+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;
+
+/**
+ * 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>, CtQueryAware {
+
+ private CtQuery query;
+ private final Class> memberClass;
+ private Set distintSet;
+
+ /**
+ * returns all type members
+ */
+ public AllTypeMembersFunction() {
+ this.memberClass = null;
+ }
+
+ /**
+ * returns all type members which are instance of `memberClass`.
+ * Example:
+ *
+ * CtField allFields = ctType.map(new AllTypeMembersFunction(CtField.class)).list();
+ *
+ */
+ public AllTypeMembersFunction(Class> memberClass) {
+ this.memberClass = memberClass;
+ }
+
+ public AllTypeMembersFunction distinctSet(Set distintSet) {
+ this.distintSet = distintSet;
+ return this;
+ }
+
+ @Override
+ public void apply(CtType> input, final CtConsumer