File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\tools\PropertyDescriptor.java.html

1 package hudson.tools;
2
3 import hudson.Functions;
4 import hudson.model.Describable;
5 import hudson.model.Descriptor;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 /**
11 * Base {@link Descriptor} type used for {@code XyzProperty} classes.
12 *
13 * @param <P>
14 * Type of the {@code XyzProperty}. Called 'property type'
15 * @param <T>
16 * Type of the {@code Xyz}, that the property attaches to. Called 'target type'
17 * @author Kohsuke Kawaguchi
18 * @since 1.305
19 */
20 public abstract class PropertyDescriptor<P extends Describable<P>,T> extends Descriptor<P> {
21 protected PropertyDescriptor(Class<? extends P> clazz) {
22 super(clazz);
23 }
24
25 protected PropertyDescriptor() {
26 }
27
28 /**
29 * Infer the type parameterization 'P'
30 */
31 private Class<P> getP() {
32 return Functions.getTypeParameter(getClass(),Descriptor.class,0);
33 }
34
35 /**
36 * Returns true if this property type is applicable to the
37 * given target type.
38 *
39 * <p>
40 * The default implementation of this method checks if the given node type is assignable
41 * according to the parameterization, but subtypes can extend this to change this behavior.
42 *
43 * @return
44 * true to indicate applicable, in which case the property will be
45 * displayed in the configuration screen of the target, for example.
46 */
47 public boolean isApplicable(Class<? extends T> targetType) {
48 Class<? extends T> applicable = Functions.getTypeParameter(clazz,getP(),0);
49 return applicable.isAssignableFrom(targetType);
50 }
51
52 public static <D extends PropertyDescriptor<?,T>,T> List<D> for_(List<D> all, Class<? extends T> target) {
53 List<D> result = new ArrayList<D>();
54 for (D d : all)
55 if (d.isApplicable(target))
56 result.add(d);
57 return result;
58 }
59
60 public static <D extends PropertyDescriptor<?,T>,T> List<D> for_(List<D> all, T target) {
61 return for_(all,(Class)target.getClass());
62 }
63 }
64