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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core.dom;
14 * Abstract base class for property descriptors of AST nodes.
15 * There are three kinds of properties:
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>
30 * @noextend This class is not intended to be subclassed by clients.
32 public abstract class StructuralPropertyDescriptor {
37 private final String propertyId;
40 * The concrete AST node type that owns this property.
42 private final Class nodeClass;
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
51 * @param nodeClass concrete AST node type that owns this property
52 * @param propertyId the property id
54 StructuralPropertyDescriptor(Class nodeClass, String propertyId) {
55 if (nodeClass == null || propertyId == null) {
56 throw new IllegalArgumentException();
58 this.propertyId = propertyId;
59 this.nodeClass = nodeClass;
63 * Returns the id of this property.
65 * @return the property id
67 public final String getId() {
68 return this.propertyId;
72 * Returns the AST node type that owns this property.
74 * For example, for all properties of the node type
75 * TypeDeclaration, this method returns <code>TypeDeclaration.class</code>.
78 * @return the node type that owns this property
80 public final Class getNodeClass() {
81 return this.nodeClass;
85 * Returns whether this property is a simple property
86 * (instance of {@link SimplePropertyDescriptor}.
88 * @return <code>true</code> if this is a simple property, and
89 * <code>false</code> otherwise
91 public final boolean isSimpleProperty(){
92 return (this instanceof SimplePropertyDescriptor);
96 * Returns whether this property is a child property
97 * (instance of {@link ChildPropertyDescriptor}.
99 * @return <code>true</code> if this is a child property, and
100 * <code>false</code> otherwise
102 public final boolean isChildProperty() {
103 return (this instanceof ChildPropertyDescriptor);
107 * Returns whether this property is a child list property
108 * (instance of {@link ChildListPropertyDescriptor}.
110 * @return <code>true</code> if this is a child list property, and
111 * <code>false</code> otherwise
113 public final boolean isChildListProperty() {
114 return (this instanceof ChildListPropertyDescriptor);
118 * Returns a string suitable for debug purposes.
119 * @return {@inheritDoc}
121 public String toString() {
122 StringBuffer b = new StringBuffer();
123 if (isChildListProperty()) {
124 b.append("ChildList"); //$NON-NLS-1$
126 if (isChildProperty()) {
127 b.append("Child"); //$NON-NLS-1$
129 if (isSimpleProperty()) {
130 b.append("Simple"); //$NON-NLS-1$
132 b.append("Property["); //$NON-NLS-1$
133 if (this.nodeClass != null) {
134 b.append(this.nodeClass.getName());
136 b.append(","); //$NON-NLS-1$
137 if (this.propertyId != null) {
138 b.append(this.propertyId);
140 b.append("]"); //$NON-NLS-1$