1 
2 module witchcraft.members;
3 
4 import witchcraft;
5 
6 import std.algorithm;
7 import std.array;
8 
9 /++
10  + Represents a set of behaviours common to reflective elements.
11  ++/
12 interface Member
13 {
14     /++
15      + Returns an array of attributes that are attached to this element.
16      +
17      + Returns:
18      +   An array of attributes.
19      ++/
20     const(Attribute)[] getAttributes() const;
21 
22     /++
23      + Returns an array of attributes of the given type that are attched to
24      + this element. If no such attributes exist, an empty array is returned.
25      +
26      + Params:
27      +   attributeType = The type of attribute to filter by.
28      +
29      + Returns:
30      +   An array of attributes.
31      ++/
32     final const(Attribute)[] getAttributes(Type attributeType) const
33     {
34         return getAttributes
35             .filter!(a => a.getAttributeType == attributeType)
36             .array;
37     }
38 
39     /++
40      + Returns an array of attributes of the given type that are attched to
41      + this element. If no such attributes exist, an empty array is returned.
42      +
43      + Params:
44      +   attributeTypeInfo = The type of attribute to filter by.
45      +
46      + Returns:
47      +   An array of attributes.
48      ++/
49     final const(Attribute)[] getAttributes(TypeInfo attributeTypeInfo) const
50     {
51         return getAttributes
52             .filter!(a => a.getAttributeTypeInfo == attributeTypeInfo)
53             .array;
54     }
55 
56     /++
57      + Ditto, but the type is given by template parameter.
58      +
59      + Params:
60      +   T = The type of attribute to filter by.
61      +
62      + Returns:
63      +   An array of attributes.
64      ++/
65     final const(Attribute)[] getAttributes(T)() const
66     {
67         return getAttributes(typeid(T));
68     }
69 
70     /++
71      + Returns the type that encapsulates this one. Null is returned if this
72      + is the topmost element, or if the outer type lacks reflective meta
73      + information.
74      +
75      + Returns:
76      +   The declaring element's type.
77      ++/
78     const(Type) getDeclaringType() const;
79 
80     /++
81      + Returns a `TypeInfo` object for the declaring element.
82      +
83      + Returns:
84      +   The type of the declaring element.
85      +
86      + See_Also:
87      +   getDeclaringType
88      ++/
89     const(TypeInfo) getDeclaringTypeInfo() const;
90 
91     /++
92      + The name of the element.
93      +
94      + Returns:
95      +   The name of this element.
96      ++/
97     string getName() const;
98 
99     /++
100      + Returns the fully-qualified name of the element, including the package
101      + and module name, and any types that might enclose it.
102      +
103      + Returns:
104      +   The fully-qualified name of this element.
105      ++/
106     string getFullName() const;
107 
108     /++
109      + Returns a string that represents this element's declared protection.
110      +
111      + Returns:
112      +   This element's protection.
113      ++/
114     string getProtection() const;
115 
116     @property
117     bool isAccessible() const;
118 }