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 * Descriptor for a child property of an AST node.
15 * A child property is one whose value is an
18 * @see org.eclipse.jdt.core.dom.ASTNode#getStructuralProperty(StructuralPropertyDescriptor)
19 * @see org.eclipse.jdt.core.dom.ASTNode#setStructuralProperty(StructuralPropertyDescriptor, Object)
21 * @noinstantiate This class is not intended to be instantiated by clients.
23 public final class ChildPropertyDescriptor extends StructuralPropertyDescriptor {
26 * Child type. For example, for a node type like
27 * CompilationUnit, the "package" property is PackageDeclaration.class
29 private final Class childClass;
32 * Indicates whether the child is mandatory. A child property is allowed
33 * to be <code>null</code> only if it is not mandatory.
35 private final boolean mandatory;
38 * Indicates whether a cycle is possible.
39 * Field is private, but marked package-visible for fast
40 * access from ASTNode.
42 final boolean cycleRisk;
45 * Creates a new child property descriptor 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
50 * @param nodeClass concrete AST node type that owns this property
51 * @param propertyId the property id
52 * @param childType the child type of this property
53 * @param mandatory <code>true</code> if the property is mandatory,
54 * and <code>false</code> if it is may be <code>null</code>
55 * @param cycleRisk <code>true</code> if this property is at
56 * risk of cycles, and <code>false</code> if there is no worry about cycles
58 ChildPropertyDescriptor(Class nodeClass, String propertyId, Class childType, boolean mandatory, boolean cycleRisk) {
59 super(nodeClass, propertyId);
60 if (childType == null || !ASTNode.class.isAssignableFrom(childType)) {
61 throw new IllegalArgumentException();
63 this.childClass = childType;
64 this.mandatory = mandatory;
65 this.cycleRisk = cycleRisk;
69 * Returns the child type of this property.
71 * For example, for a node type like CompilationUnit,
72 * the "package" property returns <code>PackageDeclaration.class</code>.
75 * @return the child type of the property
77 public final Class getChildType() {
78 return this.childClass;
82 * Returns whether this property is mandatory. A property value
83 * is not allowed to be <code>null</code> if it is mandatory.
85 * @return <code>true</code> if the property is mandatory,
86 * and <code>false</code> if it is may be <code>null</code>
88 public final boolean isMandatory() {
89 return this.mandatory;
93 * Returns whether this property is vulnerable to cycles.
95 * A property is vulnerable to cycles if a node of the owning
96 * type (that is, the type that owns this property) could legally
97 * appear in the AST subtree below this property. For example,
98 * the body property of a
99 * {@link MethodDeclaration} node
100 * admits a body which might include statement that embeds
101 * another {@link MethodDeclaration} node.
102 * On the other hand, the name property of a
103 * MethodDeclaration node admits only names, and thereby excludes
104 * another MethodDeclaration node.
107 * @return <code>true</code> if cycles are possible,
108 * and <code>false</code> if cycles are impossible
110 public final boolean cycleRisk() {
111 return this.cycleRisk;