KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > StructuralPropertyDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.core.dom;
12
13 /**
14  * Abstract base class for property descriptors of AST nodes.
15  * There are three kinds of properties:
16  * <ul>
17  * <li>simple properties ({@link SimplePropertyDescriptor})
18  * - properties where the value is a primitive (int, boolean)
19  * or simple (String, InfixExprsssion.Operator) type other than an
20  * AST node; for example, the identifier of a {@link SimpleName}</li>
21  * <li>child properties ({@link ChildPropertyDescriptor})
22  * - properties whose value is another AST node;
23  * for example, the name of a {@link MethodDeclaration}</li>
24  * <li>child list properties ({@link ChildListPropertyDescriptor})
25  * - properties where the value is a list of AST nodes;
26  * for example, the statements of a {@link Block}</li>
27  * </ul>
28  *
29  * @since 3.0
30  */

31 public abstract class StructuralPropertyDescriptor {
32     
33     /**
34      * Property id.
35      */

36     private final String JavaDoc propertyId;
37     
38     /**
39      * The concrete AST node type that owns this property.
40      */

41     private final Class JavaDoc nodeClass;
42     
43     /**
44      * Creates a new property descriptor for the given node type
45      * with the given property id.
46      * Note that this constructor is declared package-private so that
47      * property descriptors can only be created by the AST
48      * implementation.
49      *
50      * @param nodeClass concrete AST node type that owns this property
51      * @param propertyId the property id
52      */

53     StructuralPropertyDescriptor(Class JavaDoc nodeClass, String JavaDoc propertyId) {
54         if (nodeClass == null || propertyId == null) {
55             throw new IllegalArgumentException JavaDoc();
56         }
57         this.propertyId = propertyId;
58         this.nodeClass = nodeClass;
59     }
60     
61     /**
62      * Returns the id of this property.
63      *
64      * @return the property id
65      */

66     public final String JavaDoc getId() {
67         return this.propertyId;
68     }
69     
70     /**
71      * Returns the AST node type that owns this property.
72      * <p>
73      * For example, for all properties of the node type
74      * TypeDeclaration, this method returns <code>TypeDeclaration.class</code>.
75      * </p>
76      *
77      * @return the node type that owns this property
78      */

79     public final Class JavaDoc getNodeClass() {
80         return this.nodeClass;
81     }
82     
83     /**
84      * Returns whether this property is a simple property
85      * (instance of {@link SimplePropertyDescriptor}.
86      *
87      * @return <code>true</code> if this is a simple property, and
88      * <code>false</code> otherwise
89      */

90     public final boolean isSimpleProperty(){
91         return (this instanceof SimplePropertyDescriptor);
92     }
93     
94     /**
95      * Returns whether this property is a child property
96      * (instance of {@link ChildPropertyDescriptor}.
97      *
98      * @return <code>true</code> if this is a child property, and
99      * <code>false</code> otherwise
100      */

101     public final boolean isChildProperty() {
102         return (this instanceof ChildPropertyDescriptor);
103     }
104     
105     /**
106      * Returns whether this property is a child list property
107      * (instance of {@link ChildListPropertyDescriptor}.
108      *
109      * @return <code>true</code> if this is a child list property, and
110      * <code>false</code> otherwise
111      */

112     public final boolean isChildListProperty() {
113         return (this instanceof ChildListPropertyDescriptor);
114     }
115
116     /**
117      * Returns a string suitable for debug purposes.
118      * @return {@inheritDoc}
119      */

120     public String JavaDoc toString() {
121         StringBuffer JavaDoc b = new StringBuffer JavaDoc();
122         if (isChildListProperty()) {
123             b.append("ChildList"); //$NON-NLS-1$
124
}
125         if (isChildProperty()) {
126             b.append("Child"); //$NON-NLS-1$
127
}
128         if (isSimpleProperty()) {
129             b.append("Simple"); //$NON-NLS-1$
130
}
131         b.append("Property["); //$NON-NLS-1$
132
if (this.nodeClass != null) {
133             b.append(this.nodeClass.getName());
134         }
135         b.append(","); //$NON-NLS-1$
136
if (this.propertyId != null) {
137             b.append(this.propertyId);
138         }
139         b.append("]"); //$NON-NLS-1$
140
return b.toString();
141     }
142 }
143
Popular Tags