Interface ExprMirror.CtorInvocationMirror

    • Method Detail

      • getNewType

        @NonNull JTypeMirror getNewType()
        Return the type name being instantiated. If the constructor call is a diamond invocation (or no type args), returns the generic type declaration. Otherwise returns the parameterised type. If the call declares an anonymous class, then this does *not* return the anonymous type, but its explicit supertype.
        • e.g. for new ArrayList<>(), returns ArrayList<T>.
        • e.g. for new ArrayList(), returns ArrayList.
        • e.g. for new ArrayList<String>(), returns ArrayList<String>.
        • e.g. for new Runnable() {} (anonymous), returns Runnable.

        Note that this returns a JClassType in valid code. Other return values may be eg TypeSystem.UNKNOWN, or a JTypeVar, but indicate malformed code.

      • isAnonymous

        boolean isAnonymous()
        True if this creates an anonymous class. Since java 9 those can also be diamond-inferred.
      • isDiamond

        boolean isDiamond()
        Return true if this is a diamond constructor call. In that case the type parameters of the created instance must be inferred. Returns false if the constructor call mentions no type arguments.
        • e.g. for new ArrayList<>(), returns true.
        • e.g. for new ArrayList(), returns false.
        • e.g. for new ArrayList<String>(), returns false.
      • getAccessibleCandidates

        default Iterable<JMethodSig> getAccessibleCandidates()
        Enumerates *accessible* method (or ctor) signatures with *the same name* as this invocation. Name and accessibility will not be checked later. The details on how to determine this are here: https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.12.1

        Returns the constructor of the getNewType(). If this is an anonymous class declaration implementing an interface, then returns the constructors of class Object.

        This default implementation uses getAccessibleCandidates(JTypeMirror), which should be implemented instead.

        Specified by:
        getAccessibleCandidates in interface ExprMirror.InvocationMirror
      • getAccessibleCandidates

        Iterable<JMethodSig> getAccessibleCandidates​(JTypeMirror newType)
        Returns the accessible candidates for this node, as if getNewType() returned the type passed as parameter. Since candidates depend on the new type, this allows us to write simple "spy" wrappers to redo an invocation in different conditions (ie, pretending the newtype is the parameter)
        Parameters:
        newType - Assumed value of getNewType()