Class MethodDescription.AbstractBase

    • Field Detail

      • SOURCE_MODIFIERS

        private static final int SOURCE_MODIFIERS
        A merger of all method modifiers that are visible in the Java source code.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractBase

        public AbstractBase()
    • Method Detail

      • getStackSize

        public int getStackSize()
        Returns the size of the local variable array that is required for this method, i.e. the size of all parameters if they were loaded on the stack including a reference to this if this method represented a non-static method.
        Specified by:
        getStackSize in interface MethodDescription
        Returns:
        The size of this method on the operand stack.
      • isMethod

        public boolean isMethod()
        Checks if this method description represents a method, i.e. not a constructor or a type initializer.
        Specified by:
        isMethod in interface MethodDescription
        Returns:
        true if this method description represents a Java method.
      • isConstructor

        public boolean isConstructor()
        Checks if this method description represents a constructor.
        Specified by:
        isConstructor in interface MethodDescription
        Returns:
        true if this method description represents a constructor.
      • isTypeInitializer

        public boolean isTypeInitializer()
        Checks if this method is a type initializer.
        Specified by:
        isTypeInitializer in interface MethodDescription
        Returns:
        true if this method description represents a type initializer.
      • represents

        public boolean represents​(java.lang.reflect.Method method)
        Verifies if a method description represents a given loaded method.
        Specified by:
        represents in interface MethodDescription
        Parameters:
        method - The method to be checked.
        Returns:
        true if this method description represents the given loaded method.
      • represents

        public boolean represents​(java.lang.reflect.Constructor<?> constructor)
        Verifies if a method description represents a given loaded constructor.
        Specified by:
        represents in interface MethodDescription
        Parameters:
        constructor - The constructor to be checked.
        Returns:
        true if this method description represents the given loaded constructor.
      • getName

        public java.lang.String getName()
        Returns the internalName of this byte code element.
        Specified by:
        getName in interface NamedElement.WithRuntimeName
        Returns:
        The internalName of this byte code element as visible from within a running Java application.
      • getActualName

        public java.lang.String getActualName()
        Returns the name of this element as it is found in the source code. If no such name exists, an empty string is returned.
        Specified by:
        getActualName in interface NamedElement
        Returns:
        The name of this element as given in a Java program's source code.
      • getDescriptor

        public java.lang.String getDescriptor()
        Returns the descriptor of this byte code element.
        Specified by:
        getDescriptor in interface NamedElement.WithDescriptor
        Returns:
        The descriptor of this byte code element.
      • getGenericSignature

        public java.lang.String getGenericSignature()
        Returns the generic signature of this byte code element. If this element does not reference generic types or references malformed generic types, null is returned as a signature.
        Specified by:
        getGenericSignature in interface NamedElement.WithDescriptor
        Returns:
        The generic signature or null if this element is not generic.
      • getActualModifiers

        public int getActualModifiers()
        Returns this method's actual modifiers as it is present in a class file, i.e. includes a flag if this method is marked Deprecated.
        Specified by:
        getActualModifiers in interface MethodDescription
        Returns:
        The method's actual modifiers.
      • getActualModifiers

        public int getActualModifiers​(boolean manifest)
        Returns this method's actual modifiers as it is present in a class file, i.e. includes a flag if this method is marked Deprecated and adjusts the modifiers for being abstract or not.
        Specified by:
        getActualModifiers in interface MethodDescription
        Parameters:
        manifest - true if the method should be treated as non-abstract.
        Returns:
        The method's actual modifiers.
      • getActualModifiers

        public int getActualModifiers​(boolean manifest,
                                      Visibility visibility)
        Returns this method's actual modifiers as it is present in a class file, i.e. includes a flag if this method is marked Deprecated and adjusts the modifiers for being abstract or not. Additionally, this method resolves a required minimal visibility.
        Specified by:
        getActualModifiers in interface MethodDescription
        Parameters:
        manifest - true if the method should be treated as non-abstract.
        visibility - The minimal visibility to enforce for this method.
        Returns:
        The method's actual modifiers.
      • isVisibleTo

        public boolean isVisibleTo​(TypeDescription typeDescription)

        Checks if this element is visible from a given type. Visibility is a wider criteria then accessibility which can be checked by ByteCodeElement.isAccessibleTo(TypeDescription). Visibility allows the invocation of a method on itself or on external instances.

        Note: A method or field might define a signature that includes types that are not visible to a type. Such methods can be legally invoked from this type and can even be implemented as bridge methods by this type. It is however not legal to declare a method with invisible types in its signature that are not bridges what might require additional validation.

        Important: Virtual byte code elements, i.e. virtual methods, are only considered visible if the type they are invoked upon is visible to a given type. The visibility of such virtual members can therefore not be determined by only investigating the invoked method but requires an additional check of the target type.

        Specified by:
        isVisibleTo in interface ByteCodeElement
        Parameters:
        typeDescription - The type which is checked for its visibility of this element.
        Returns:
        true if this element is visible for typeDescription.
      • isAccessibleTo

        public boolean isAccessibleTo​(TypeDescription typeDescription)

        Checks if this element is accessible from a given type. Accessibility is a more narrow criteria then visibility which can be checked by ByteCodeElement.isVisibleTo(TypeDescription). Accessibility allows the invocation of a method on external instances or on itself. Methods that can be invoked from within an instance might however not be considered accessible.

        Note: A method or field might define a signature that includes types that are not visible to a type. Such methods can be legally invoked from this type and can even be implemented as bridge methods by this type. It is however not legal to declare a method with invisible types in its signature that are not bridges what might require additional validation.

        Important: Virtual byte code elements, i.e. virtual methods, are only considered visible if the type they are invoked upon is visible to a given type. The visibility of such virtual members can therefore not be determined by only investigating the invoked method but requires an additional check of the target type.

        Specified by:
        isAccessibleTo in interface ByteCodeElement
        Parameters:
        typeDescription - The type which is checked for its accessibility of this element.
        Returns:
        true if this element is accessible for typeDescription.
      • isVirtual

        public boolean isVirtual()
        Verifies if this method describes a virtual method, i.e. a method that is inherited by a sub type of this type.
        Specified by:
        isVirtual in interface MethodDescription
        Returns:
        true if this method is virtual.
      • isDefaultMethod

        public boolean isDefaultMethod()
        Checks if this method represents a default (defender) method.
        Specified by:
        isDefaultMethod in interface MethodDescription
        Returns:
        true if this method is a default method.
      • isSpecializableFor

        public boolean isSpecializableFor​(TypeDescription targetType)
        Checks if this method can be called using the INVOKESPECIAL for a given type.
        Specified by:
        isSpecializableFor in interface MethodDescription
        Parameters:
        targetType - The type o
        Returns:
        true if this method can be called using the INVOKESPECIAL instruction using the given type.
      • getDefaultValue

        public <T> T getDefaultValue​(java.lang.Class<T> type)
        Returns the default value but casts it to the given type. If the type differs from the value, a ClassCastException is thrown.
        Specified by:
        getDefaultValue in interface MethodDescription
        Type Parameters:
        T - The type to cast the default value to.
        Parameters:
        type - The type to cast the default value to.
        Returns:
        The casted default value.
      • isInvokableOn

        public boolean isInvokableOn​(TypeDescription typeDescription)
        Asserts if this method is invokable on an instance of the given type, i.e. the method is an instance method or a constructor and the method is visible to the type and can be invoked on the given instance.
        Specified by:
        isInvokableOn in interface MethodDescription
        Parameters:
        typeDescription - The type to check.
        Returns:
        true if this method is invokable on an instance of the given type.
      • isBootstrap

        private boolean isBootstrap​(TypeDescription selfType)
        Checks if this method is a bootstrap method while expecting the supplied type as a type representation.
        Parameters:
        selfType - The type of the bootstrap method's type representation.
        Returns:
        true if this method is a bootstrap method assuming the supplied type representation.
      • isBootstrap

        private boolean isBootstrap​(java.util.List<? extends TypeDefinition> types)
        Checks if this method is a bootstrap method given the supplied arguments. This method does not implement a full check but assumes that isBootstrap(TypeDescription) is invoked, as well.
        Parameters:
        types - The types of the explicit arguments that are supplied to the bootstrap method.
        Returns:
        true if this method is a bootstrap method for the supplied arguments.
      • isInvokeBootstrap

        public boolean isInvokeBootstrap()
        Checks if this method is a valid bootstrap method for an invokedynamic call.
        Specified by:
        isInvokeBootstrap in interface MethodDescription
        Returns:
        true if this method is a valid bootstrap method for an invokedynamic call.
      • isInvokeBootstrap

        public boolean isInvokeBootstrap​(java.util.List<? extends TypeDefinition> arguments)
        Checks if this method is a valid bootstrap method for an invokedynamic call.
        Specified by:
        isInvokeBootstrap in interface MethodDescription
        Parameters:
        arguments - The types of the explicit arguments that are supplied to the bootstrap method.
        Returns:
        true if this method is a valid bootstrap method for an invokedynamic call.
      • isConstantBootstrap

        public boolean isConstantBootstrap()
        Checks if this method is a valid bootstrap method for an constantdynamic call.
        Specified by:
        isConstantBootstrap in interface MethodDescription
        Returns:
        true if this method is a valid bootstrap method for an constantdynamic call.
      • isConstantBootstrap

        public boolean isConstantBootstrap​(java.util.List<? extends TypeDefinition> arguments)
        Checks if this method is a valid bootstrap method for an constantdynamic call.
        Specified by:
        isConstantBootstrap in interface MethodDescription
        Parameters:
        arguments - The types of the explicit arguments that are supplied to the bootstrap method.
        Returns:
        true if this method is a valid bootstrap method for an constantdynamic call.
      • isDefaultValue

        public boolean isDefaultValue()
        Checks if this method is capable of defining a default annotation value.
        Specified by:
        isDefaultValue in interface MethodDescription
        Returns:
        true if it is possible to define a default annotation value for this method.
      • isDefaultValue

        public boolean isDefaultValue​(AnnotationValue<?,​?> annotationValue)
        Checks if the given value can describe a default annotation value for this method.
        Specified by:
        isDefaultValue in interface MethodDescription
        Parameters:
        annotationValue - The value that describes the default annotation value for this method.
        Returns:
        true if the given value can describe a default annotation value for this method.
      • isEnumerationType

        private static boolean isEnumerationType​(TypeDescription enumerationType,
                                                 EnumerationDescription... enumerationDescription)
        Checks if the supplied enumeration descriptions describe the correct enumeration type.
        Parameters:
        enumerationType - The enumeration type to check for.
        enumerationDescription - The enumeration descriptions to check.
        Returns:
        true if all enumeration descriptions represent the enumeration type in question.
      • isAnnotationType

        private static boolean isAnnotationType​(TypeDescription annotationType,
                                                AnnotationDescription... annotationDescription)
        Checks if the supplied enumeration descriptions describe the correct annotation type.
        Parameters:
        annotationType - The annotation type to check for.
        annotationDescription - The annotation descriptions to check.
        Returns:
        true if all annotation descriptions represent the annotation type in question.
      • getEnclosingSource

        public TypeVariableSource getEnclosingSource()
        Returns the enclosing source of type variables that are valid in the scope of this type variable source.
        Specified by:
        getEnclosingSource in interface TypeVariableSource
        Returns:
        The enclosing source or null if no such source exists.
      • isInferrable

        public boolean isInferrable()
        Returns true if type variables declared by this type variable source allow dynamic type inference.
        Specified by:
        isInferrable in interface TypeVariableSource
        Returns:
        true if type variables declared by this type variable source allow dynamic type inference.
      • accept

        public <T> T accept​(TypeVariableSource.Visitor<T> visitor)
        Applies a visitor on this type variable source.
        Specified by:
        accept in interface TypeVariableSource
        Type Parameters:
        T - The visitor's return type.
        Parameters:
        visitor - The visitor to apply.
        Returns:
        The visitor's return value.
      • isGenerified

        public boolean isGenerified()
        Checks if this type variable source has a generic declaration. This means:
        • A type declares type variables or is an inner class of a type with a generic declaration.
        • A method declares at least one type variable.
        Specified by:
        isGenerified in interface TypeVariableSource
        Returns:
        true if this type code element has a generic declaration.
      • asTypeToken

        public MethodDescription.TypeToken asTypeToken()
        Returns a type token that represents this method's raw return and parameter types.
        Specified by:
        asTypeToken in interface MethodDescription
        Returns:
        A type token that represents this method's raw return and parameter types.
      • isBridgeCompatible

        public boolean isBridgeCompatible​(MethodDescription.TypeToken typeToken)
        Validates that the supplied type token can implement a bridge method to this method.
        Specified by:
        isBridgeCompatible in interface MethodDescription
        Parameters:
        typeToken - A type token representing a potential bridge method to this method.
        Returns:
        true if the supplied type token can represent a bridge method to this method.
      • hashCode

        @Enhance("hashCode")
        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • toGenericString

        public java.lang.String toGenericString()
        Returns a generic string of this byte code element.
        Specified by:
        toGenericString in interface NamedElement.WithGenericName
        Returns:
        A generic string of this byte code element.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object