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