removed unused private methods.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / dom / StructuralPropertyDescriptor.java
1 /*******************************************************************************
2  * Copyright (c) 2004, 2008 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 net.sourceforge.phpdt.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  * @noextend This class is not intended to be subclassed by clients.
31  */
32 public abstract class StructuralPropertyDescriptor {
33         
34         /**
35          * Property id.
36          */
37         private final String propertyId;
38         
39         /**
40          * The concrete AST node type that owns this property.
41          */
42         private final Class nodeClass;
43         
44         /**
45          * Creates a new property descriptor for the given node type
46          * with the given property id.
47          * Note that this constructor is declared package-private so that
48          * property descriptors can only be created by the AST
49          * implementation.
50          * 
51          * @param nodeClass concrete AST node type that owns this property
52          * @param propertyId the property id
53          */
54         StructuralPropertyDescriptor(Class nodeClass, String propertyId) {
55                 if (nodeClass == null || propertyId == null) {
56                         throw new IllegalArgumentException();
57                 }
58                 this.propertyId = propertyId;
59                 this.nodeClass = nodeClass;
60         }
61         
62         /**
63          * Returns the id of this property.
64          * 
65          * @return the property id
66          */
67         public final String getId() {
68                 return this.propertyId;
69         }
70         
71         /**
72          * Returns the AST node type that owns this property.
73          * <p>
74          * For example, for all properties of the node type
75          * TypeDeclaration, this method returns <code>TypeDeclaration.class</code>.
76          * </p>
77          * 
78          * @return the node type that owns this property
79          */
80         public final Class getNodeClass() {
81                 return this.nodeClass;
82         }
83         
84         /**
85          * Returns whether this property is a simple property
86          * (instance of {@link SimplePropertyDescriptor}.
87          * 
88          * @return <code>true</code> if this is a simple property, and 
89          * <code>false</code> otherwise
90          */
91         public final boolean isSimpleProperty(){
92                 return (this instanceof SimplePropertyDescriptor);
93         }
94         
95         /**
96          * Returns whether this property is a child property
97          * (instance of {@link ChildPropertyDescriptor}.
98          * 
99          * @return <code>true</code> if this is a child property, and 
100          * <code>false</code> otherwise
101          */
102         public final boolean isChildProperty() {
103                 return (this instanceof ChildPropertyDescriptor);
104         }
105         
106         /**
107          * Returns whether this property is a child list property
108          * (instance of {@link ChildListPropertyDescriptor}.
109          * 
110          * @return <code>true</code> if this is a child list property, and 
111          * <code>false</code> otherwise
112          */
113         public final boolean isChildListProperty() { 
114                 return (this instanceof ChildListPropertyDescriptor);
115         }
116
117         /**
118          * Returns a string suitable for debug purposes.
119          * @return {@inheritDoc}
120          */
121         public String toString() {
122                 StringBuffer b = new StringBuffer();
123                 if (isChildListProperty()) {
124                         b.append("ChildList"); //$NON-NLS-1$
125                 }
126                 if (isChildProperty()) {
127                         b.append("Child"); //$NON-NLS-1$
128                 }
129                 if (isSimpleProperty()) {
130                         b.append("Simple"); //$NON-NLS-1$
131                 }
132                 b.append("Property["); //$NON-NLS-1$
133                 if (this.nodeClass != null) {
134                         b.append(this.nodeClass.getName());
135                 }
136                 b.append(","); //$NON-NLS-1$
137                 if (this.propertyId != null) {
138                         b.append(this.propertyId);
139                 }
140                 b.append("]"); //$NON-NLS-1$
141                 return b.toString();
142         }
143 }