Class MemberSelectorListMemberAccessPolicy

java.lang.Object
freemarker.ext.beans.MemberSelectorListMemberAccessPolicy
All Implemented Interfaces:
MemberAccessPolicy
Direct Known Subclasses:
BlacklistMemberAccessPolicy, WhitelistMemberAccessPolicy

public abstract class MemberSelectorListMemberAccessPolicy extends Object implements MemberAccessPolicy
Superclass for member-selector-list-based member access policies, like 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