Class MemberSelectorListMemberAccessPolicy
- java.lang.Object
-
- freemarker.ext.beans.MemberSelectorListMemberAccessPolicy
-
- All Implemented Interfaces:
MemberAccessPolicy
- Direct Known Subclasses:
BlacklistMemberAccessPolicy
,WhitelistMemberAccessPolicy
public abstract class MemberSelectorListMemberAccessPolicy extends java.lang.Object implements MemberAccessPolicy
Superclass for member-selector-list-based member access policies, likeWhitelistMemberAccessPolicy
.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, andB extends A
, thencom.example.B.B()
is still not matched by that list. If you want it to be matched, you have to addcom.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
Nested Classes Modifier and Type Class Description static class
MemberSelectorListMemberAccessPolicy.MemberSelector
A condition that matches some type members.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassMemberAccessPolicy
forClass(java.lang.Class<?> contextClass)
Returns 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 Detail
-
forClass
public final ClassMemberAccessPolicy forClass(java.lang.Class<?> contextClass)
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.
-
-