Class MemberSelectorListMemberAccessPolicy
- All Implemented Interfaces:
MemberAccessPolicy
- Direct Known Subclasses:
BlacklistMemberAccessPolicy
,WhitelistMemberAccessPolicy
WhitelistMemberAccessPolicy
.
There are two ways you can add members to the member selector list:
- Via a list of member selectors passed to the constructor
- Via annotation (concrete type depends on subclass)
Members are identified with the following data (with the example of
com.example.MyClass.myMethod(int, int)
):
- Upper bound class (
com.example.MyClass
in the example) - Member name (
myMethod
in the example), except for constructors where it's unused - Parameter types (
int, int
in the example), except for fields where it's unused
If a method or field is matched in the upper bound type, it will be automatically matched in all subtypes of that.
It's called "upper bound" type, because the member will only be matched in classes that are instanceof
the upper bound class. That restriction stands even if the member was inherited from another type (class or
interface), and it wasn't even overridden in the upper bound type; the member won't be matched in the
type where it was inherited from, if that type is more generic than the upper bound type.
The above inheritance rule doesn't apply to constructors. That's consistent with the fact constructors aren't
inherited in Java (or pretty much any other language). So for example, if you add com.example.A.A()
to
the member selector list, and B extends A
, then com.example.B.B()
is still not matched by that list.
If you want it to be matched, you have to add com.example.B.B()
to list explicitly.
Note that the return type of methods aren't used in any way. If myMethod(int, int)
has multiple variants
with different return types (which is possible on the bytecode level) but the same parameter types, then all
variants of it is matched, or none is. Similarly, the type of fields isn't used either, only the name of the field
matters.
- Since:
- 2.3.30
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A condition that matches some type members. -
Method Summary
Modifier and TypeMethodDescriptionReturns theClassMemberAccessPolicy
that encapsulates the member access policy for a given class.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface freemarker.ext.beans.MemberAccessPolicy
isToStringAlwaysExposed
-
Method Details
-
forClass
Description copied from interface:MemberAccessPolicy
Returns theClassMemberAccessPolicy
that encapsulates the member access policy for a given class.ClassMemberAccessPolicy
implementations need not be thread-safe. Because class introspection results are cached, and so this method is usually only called once for a given class, theClassMemberAccessPolicy
instances shouldn't be cached by the implementation of this method.- Specified by:
forClass
in interfaceMemberAccessPolicy
- Parameters:
contextClass
- The exact class of object from which members will be get in the templates.
-