View Javadoc

1   package net.sourceforge.pmd.properties;
2   
3   import java.lang.reflect.Method;
4   
5   import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
6   import net.sourceforge.pmd.lang.rule.properties.BooleanMultiProperty;
7   import net.sourceforge.pmd.lang.rule.properties.BooleanProperty;
8   import net.sourceforge.pmd.lang.rule.properties.CharacterMultiProperty;
9   import net.sourceforge.pmd.lang.rule.properties.CharacterProperty;
10  import net.sourceforge.pmd.lang.rule.properties.EnumeratedMultiProperty;
11  import net.sourceforge.pmd.lang.rule.properties.EnumeratedProperty;
12  import net.sourceforge.pmd.lang.rule.properties.FloatMultiProperty;
13  import net.sourceforge.pmd.lang.rule.properties.FloatProperty;
14  import net.sourceforge.pmd.lang.rule.properties.IntegerMultiProperty;
15  import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
16  import net.sourceforge.pmd.lang.rule.properties.LongMultiProperty;
17  import net.sourceforge.pmd.lang.rule.properties.LongProperty;
18  import net.sourceforge.pmd.lang.rule.properties.MethodMultiProperty;
19  import net.sourceforge.pmd.lang.rule.properties.MethodProperty;
20  import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty;
21  import net.sourceforge.pmd.lang.rule.properties.StringProperty;
22  import net.sourceforge.pmd.lang.rule.properties.TypeMultiProperty;
23  import net.sourceforge.pmd.lang.rule.properties.TypeProperty;
24  import net.sourceforge.pmd.util.ClassUtil;
25  
26  /**
27   * A non-functional rule containing all property types. Used for testing UIs.
28   * 
29   * Steps required to use with Eclipse Plugin:
30   * 
31   *  update your chosen ruleset xml file to include this 'rule'
32   *  compile new PMD jars
33   *  copy both the pmd5.0.jar and pmd-test-5.0.jar to the eclipse-plugin/lib directory
34   *  update the /manifest.mf file to ensure it includes the pmd-test-5.0.jar
35   * 
36   * @author Brian Remedios
37   */
38  public class NonRuleWithAllPropertyTypes extends AbstractJavaRule {
39  
40      private static final Method stringLength = ClassUtil.methodFor(String.class, "length", ClassUtil.EMPTY_CLASS_ARRAY);
41      private static final Method stringToLowerCase = ClassUtil.methodFor(String.class, "toLowerCase", ClassUtil.EMPTY_CLASS_ARRAY);
42       
43  	// descriptors are public to enable us to write external tests
44  	public static final StringProperty singleStr	  = new StringProperty("singleStr", "String value", "hello world" , 3.0f);
45  	public static final StringMultiProperty multiStr  = new StringMultiProperty("multiStr", "Multiple string values", new String[] {"hello", "world"}, 5.0f, '|');
46  	
47  	public static final IntegerProperty singleInt	  = new IntegerProperty("singleInt", "Single integer value", 1, 10, 8 , 3.0f);
48  	public static final IntegerMultiProperty multiInt = new IntegerMultiProperty("multiInt", "Multiple integer values", 0, 10, new Integer[] {1, 2, 3, 4}, 5.0f);
49   
50  	public static final LongProperty singleLong       = new LongProperty("singleLong", "Single long value", 1L, 10L, 8L , 3.0f);
51      public static final LongMultiProperty multiLong   = new LongMultiProperty("multiLong", "Multiple long values", 0L, 10L, new Long[] {1L, 2L, 3L, 4L}, 5.0f);
52  	
53  	public static final BooleanProperty singleBool	   = new BooleanProperty("singleBool", "Single boolean value", true, 6.0f);
54  	public static final BooleanMultiProperty multiBool = new BooleanMultiProperty("multiBool", "Multiple boolean values", new Boolean[] { true, false}, 5.0f);
55  	
56  	public static final CharacterProperty singleChar	 = new CharacterProperty("singleChar", "Single character", 'a', 5.0f);
57  	public static final CharacterMultiProperty multiChar = new CharacterMultiProperty("multiChar", "Multiple characters", new Character[] {'a', 'e', 'i', 'o', 'u'}, 6.0f, '|');
58  	
59  	public static final FloatProperty singleFloat	     = new FloatProperty("singleFloat", "Single float value", 9f, 10f, .9f, 5.0f);
60  	public static final FloatMultiProperty multiFloat    = new FloatMultiProperty("multiFloat", "Multiple float values", 0f, 5f, new Float[] {1f, 2f, 3f}, 6.0f);
61  	
62  	public static final TypeProperty singleType	         = new TypeProperty("singleType", "Single type", String.class, new String[] { "java.lang" }, 5.0f);
63  	public static final TypeMultiProperty multiType	     = new TypeMultiProperty("multiType", "Multiple types", new Class[] {Integer.class, Object.class}, new String[] { "java.lang" }, 6.0f);
64  
65      public static final MethodProperty singleMethod      = new MethodProperty("singleMethod", "Single method", stringLength, new String[] { "java.lang" }, 5.0f);
66      public static final MethodMultiProperty multiMethod  = new MethodMultiProperty("multiMethod", "Multiple methods", new Method[] {stringLength, stringToLowerCase}, new String[] { "java.lang" }, 6.0f);
67  
68  	public static final EnumeratedProperty<Class> enumType			 = new EnumeratedProperty<Class>("enumType", "Enumerated choices", new String[] {"String", "Object"}, new Class[] {String.class, Object.class}, 1, 5.0f);
69  	public static final EnumeratedMultiProperty<Class> multiEnumType = new EnumeratedMultiProperty<Class>("multiEnumType", "Multiple enumerated choices", new String[] {"String", "Object"}, new Class[] {String.class, Object.class}, new int[] {0,1}, 5.0f);
70  	
71  	
72  	public NonRuleWithAllPropertyTypes() {
73  		super();
74  		definePropertyDescriptor(singleStr);
75  		definePropertyDescriptor(multiStr);
76  		definePropertyDescriptor(singleInt);
77  		definePropertyDescriptor(multiInt);
78  	    definePropertyDescriptor(singleLong);
79  	    definePropertyDescriptor(multiLong);
80  		definePropertyDescriptor(singleBool);
81  		definePropertyDescriptor(multiBool);
82  		definePropertyDescriptor(singleChar);
83  		definePropertyDescriptor(multiChar);
84  		definePropertyDescriptor(singleFloat);
85  		definePropertyDescriptor(multiFloat);
86  		definePropertyDescriptor(singleType);
87  		definePropertyDescriptor(multiType);
88  		definePropertyDescriptor(enumType);
89  		definePropertyDescriptor(singleMethod);
90          definePropertyDescriptor(multiMethod);
91  		definePropertyDescriptor(multiEnumType);
92  	}
93  }