net.sourceforge.pmd.lang.rule.properties

## Class MethodProperty

- java.lang.Object
- - net.sourceforge.pmd.lang.rule.properties.AbstractProperty<T>
  - - net.sourceforge.pmd.lang.rule.properties.AbstractPackagedProperty<Method>
    - - net.sourceforge.pmd.lang.rule.properties.MethodProperty

All Implemented Interfaces:
  Comparable<PropertyDescriptor<?>>, PropertyDescriptor<Method>

    public class MethodProperty
    extends AbstractPackagedProperty<Method>

Defines a property type that can specify a single method to use as part of a rule. Rule developers can limit the rules to those within designated packages per the 'legalPackages' argument in the constructor which can be an array of partial package names, i.e., ["java.lang", "com.mycompany" ].

Author:
  Brian Remedios

### Field Summary

Fields
`static char` `CLASS_METHOD_DELIMITER`
`static PropertyDescriptorFactory` `FACTORY`
`static char` `METHOD_ARG_DELIMITER`
`static char[]` `METHOD_GROUP_DELIMITERS`

### Fields inherited from class net.sourceforge.pmd.lang.rule.properties.AbstractPackagedProperty

`packagedFieldTypesByKey`

### Constructor Summary

Constructors
Constructor and Description
`MethodProperty(String theName, String theDescription, Method theDefault, String[] legalPackageNames, float theUIOrder)` Constructor for MethodProperty.
`MethodProperty(String theName, String theDescription, String defaultMethodStr, Map<String,String> otherParams, float theUIOrder)` Constructor for MethodProperty.
`MethodProperty(String theName, String theDescription, String defaultMethodStr, String[] legalPackageNames, float theUIOrder)` Constructor for MethodProperty.

### Method Summary

Methods
`protected String` `asString(Object value)` Return the value as a string that can be easily recognized and parsed when we see it again.
`static String` `asStringFor(Method method)` Return the value of `method' as a string that can be easily recognized and parsed when we see it again.
`static void` `asStringOn(Method method, StringBuilder sb)` Serializes the method signature onto the specified buffer.
`protected String` `defaultAsString()`
`protected String` `itemTypeName()` Method itemTypeName.
`static Method` `methodFrom(String methodStr)`
`static Method` `methodFrom(String methodNameAndArgTypes, char classMethodDelimiter, char methodArgDelimiter)` Returns the method specified within the string argument after parsing out its source class and any optional arguments.
`protected String` `packageNameOf(Object item)`
`Class<Method>` `type()` Denotes the value datatype.
`Method` `valueFrom(String valueString)` If the property is multi-valued then return the separate values after parsing the propertyString provided.

### Methods inherited from class net.sourceforge.pmd.lang.rule.properties.AbstractPackagedProperty

`addAttributesTo, legalPackageNames, packageNamesIn, valueErrorFor`

### Methods inherited from class net.sourceforge.pmd.lang.rule.properties.AbstractProperty

`areEqual, asDelimitedString, asDelimitedString, attributeValuesById, choices, compareTo, defaultHasNullValue, defaultValue, description, equals, errorFor, hashCode, isArray, isMultiValue, isRequired, multiValueDelimiter, name, preferredRowCount, propertyErrorFor, toString, typeErrorFor, uiOrder, valuesErrorFor`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### CLASS_METHOD_DELIMITER

    public static final char CLASS_METHOD_DELIMITER

See Also:
  Constant Field Values

#### METHOD_ARG_DELIMITER

    public static final char METHOD_ARG_DELIMITER

See Also:
  Constant Field Values

#### METHOD_GROUP_DELIMITERS

    public static final char[] METHOD_GROUP_DELIMITERS

#### FACTORY

    public static final PropertyDescriptorFactory FACTORY

### Constructor Detail

#### MethodProperty

    public MethodProperty(String theName,
                  String theDescription,
                  Method theDefault,
                  String[] legalPackageNames,
                  float theUIOrder)

Constructor for MethodProperty.

Parameters:
  `theName` - String
  `theDescription` - String
  `theDefault` - Method
  `legalPackageNames` - String[]
  `theUIOrder` - float
Throws:
  `IllegalArgumentException`

#### MethodProperty

    public MethodProperty(String theName,
                  String theDescription,
                  String defaultMethodStr,
                  String[] legalPackageNames,
                  float theUIOrder)

Constructor for MethodProperty.

Parameters:
  `theName` - String
  `theDescription` - String
  `defaultMethodStr` - String
  `legalPackageNames` - String[]
  `theUIOrder` - float
Throws:
  `IllegalArgumentException`

#### MethodProperty

    public MethodProperty(String theName,
                  String theDescription,
                  String defaultMethodStr,
                  Map<String,String> otherParams,
                  float theUIOrder)

Constructor for MethodProperty.

Parameters:
  `theName` - String
  `theDescription` - String
  `defaultMethodStr` - String
  `otherParams` - Map<String, String>
  `theUIOrder` - float
Throws:
  `IllegalArgumentException`

### Method Detail

#### asStringFor

    public static String asStringFor(Method method)

Return the value of `method' as a string that can be easily recognized and parsed when we see it again.

Parameters:
  `method` - the method to convert
Returns:
  the string value

#### defaultAsString

    protected String defaultAsString()

Specified by:
  `defaultAsString` in class `AbstractProperty<Method>`
Returns:
  String

#### asStringOn

    public static void asStringOn(Method method,
                  StringBuilder sb)

Serializes the method signature onto the specified buffer.

Parameters:
  `method` - Method
  `sb` - StringBuilder

#### methodFrom

    public static Method methodFrom(String methodNameAndArgTypes,
                    char classMethodDelimiter,
                    char methodArgDelimiter)

Returns the method specified within the string argument after parsing out its source class and any optional arguments. Callers need to specify the delimiters expected between the various elements. I.e.: "String#isEmpty()" "String#indexOf(int)" "String#substring(int,int)" If a method isn't part of the specified class we will walk up any superclasses to Object to try and find it. If the classes are listed in the ClassUtil class within in Typemaps then you likely can avoid specifying fully-qualified class names per the above example. Returns null if a matching method cannot be found.

Parameters:
  `methodNameAndArgTypes` -
  `classMethodDelimiter` -
  `methodArgDelimiter` -
Returns:
  Method

#### methodFrom

    public static Method methodFrom(String methodStr)

Parameters:
  `methodStr` - String
Returns:
  Method

#### asString

    protected String asString(Object value)

Return the value as a string that can be easily recognized and parsed when we see it again.

Overrides:
  `asString` in class `AbstractProperty<Method>`
Parameters:
  `value` - Object
Returns:
  String

#### packageNameOf

    protected String packageNameOf(Object item)

Specified by:
  `packageNameOf` in class `AbstractPackagedProperty<Method>`
Parameters:
  `item` - Object
Returns:
  String

#### itemTypeName

    protected String itemTypeName()

Description copied from class: `AbstractPackagedProperty`
Method itemTypeName.

Specified by:
  `itemTypeName` in class `AbstractPackagedProperty<Method>`
Returns:
  String

#### type

    public Class<Method> type()

Description copied from interface: `PropertyDescriptor`
Denotes the value datatype.

Returns:
  Class
See Also:
  `PropertyDescriptor.type()`

#### valueFrom

    public Method valueFrom(String valueString)
                     throws IllegalArgumentException

Description copied from interface: `PropertyDescriptor`
If the property is multi-valued then return the separate values after parsing the propertyString provided. If it isn't a multi-valued property then the value will be returned within an array of size[1].

Parameters:
  `valueString` - String
Returns:
  Object
Throws:
  `IllegalArgumentException`
See Also:
  `PropertyDescriptor.valueFrom(String)`