Class MethodSpec


  • public final class MethodSpec
    extends java.lang.Object
    A generated constructor or method declaration.
    • Field Detail

      • name

        public final java.lang.String name
      • annotations

        public final java.util.List<AnnotationSpec> annotations
      • modifiers

        public final java.util.Set<javax.lang.model.element.Modifier> modifiers
      • returnType

        public final TypeName returnType
      • parameters

        public final java.util.List<ParameterSpec> parameters
      • varargs

        public final boolean varargs
      • exceptions

        public final java.util.List<TypeName> exceptions
      • defaultValue

        public final CodeBlock defaultValue
    • Method Detail

      • lastParameterIsArray

        private boolean lastParameterIsArray​(java.util.List<ParameterSpec> parameters)
      • emit

        void emit​(CodeWriter codeWriter,
                  java.lang.String enclosingName,
                  java.util.Set<javax.lang.model.element.Modifier> implicitModifiers)
           throws java.io.IOException
        Throws:
        java.io.IOException
      • javadocWithParameters

        private CodeBlock javadocWithParameters()
      • hasModifier

        public boolean hasModifier​(javax.lang.model.element.Modifier modifier)
      • isConstructor

        public boolean isConstructor()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

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

        public static MethodSpec.Builder methodBuilder​(java.lang.String name)
      • overriding

        public static MethodSpec.Builder overriding​(javax.lang.model.element.ExecutableElement method)
        Returns a new method spec builder that overrides method.

        This will copy its visibility modifiers, type parameters, return type, name, parameters, and throws declarations. An Override annotation will be added.

        Note that in JavaPoet 1.2 through 1.7 this method retained annotations from the method and parameters of the overridden method. Since JavaPoet 1.8 annotations must be added separately.

      • overriding

        public static MethodSpec.Builder overriding​(javax.lang.model.element.ExecutableElement method,
                                                    javax.lang.model.type.DeclaredType enclosing,
                                                    javax.lang.model.util.Types types)
        Returns a new method spec builder that overrides method as a member of enclosing. This will resolve type parameters: for example overriding Comparable.compareTo(T) in a type that implements Comparable<Movie>, the T parameter will be resolved to Movie.

        This will copy its visibility modifiers, type parameters, return type, name, parameters, and throws declarations. An Override annotation will be added.

        Note that in JavaPoet 1.2 through 1.7 this method retained annotations from the method and parameters of the overridden method. Since JavaPoet 1.8 annotations must be added separately.