KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Descriptor for a child property of an AST node.
15  * A child property is one whose value is an
16  * {@link ASTNode}.
17  *
18  * @see org.eclipse.jdt.core.dom.ASTNode#getStructuralProperty(StructuralPropertyDescriptor)
19  * @see org.eclipse.jdt.core.dom.ASTNode#setStructuralProperty(StructuralPropertyDescriptor, Object)
20  * @since 3.0
21  */

22 public final class ChildPropertyDescriptor extends StructuralPropertyDescriptor {
23     
24     /**
25      * Child type. For example, for a node type like
26      * CompilationUnit, the "package" property is PackageDeclaration.class
27      */

28     private final Class JavaDoc childClass;
29     
30     /**
31      * Indicates whether the child is mandatory. A child property is allowed
32      * to be <code>null</code> only if it is not mandatory.
33      */

34     private final boolean mandatory;
35     
36     /**
37      * Indicates whether a cycle is possible.
38      * Field is private, but marked package-visible for fast
39      * access from ASTNode.
40      */

41     final boolean cycleRisk;
42     
43     /**
44      * Creates a new child property descriptor with the given property id.
45      * Note that this constructor is declared package-private so that
46      * property descriptors can only be created by the AST
47      * implementation.
48      *
49      * @param nodeClass concrete AST node type that owns this property
50      * @param propertyId the property id
51      * @param childType the child type of this property
52      * @param mandatory <code>true</code> if the property is mandatory,
53      * and <code>false</code> if it is may be <code>null</code>
54      * @param cycleRisk <code>true</code> if this property is at
55      * risk of cycles, and <code>false</code> if there is no worry about cycles
56      */

57     ChildPropertyDescriptor(Class JavaDoc nodeClass, String JavaDoc propertyId, Class JavaDoc childType, boolean mandatory, boolean cycleRisk) {
58         super(nodeClass, propertyId);
59         if (childType == null || !ASTNode.class.isAssignableFrom(childType)) {
60             throw new IllegalArgumentException JavaDoc();
61         }
62         this.childClass = childType;
63         this.mandatory = mandatory;
64         this.cycleRisk = cycleRisk;
65     }
66     
67     /**
68      * Returns the child type of this property.
69      * <p>
70      * For example, for a node type like CompilationUnit,
71      * the "package" property returns <code>PackageDeclaration.class</code>.
72      * </p>
73      *
74      * @return the child type of the property
75      */

76     public final Class JavaDoc getChildType() {
77         return this.childClass;
78     }
79     
80     /**
81      * Returns whether this property is mandatory. A property value
82      * is not allowed to be <code>null</code> if it is mandatory.
83      *
84      * @return <code>true</code> if the property is mandatory,
85      * and <code>false</code> if it is may be <code>null</code>
86      */

87     public final boolean isMandatory() {
88         return this.mandatory;
89     }
90     
91     /**
92      * Returns whether this property is vulnerable to cycles.
93      * <p>
94      * A property is vulnerable to cycles if a node of the owning
95      * type (that is, the type that owns this property) could legally
96      * appear in the AST subtree below this property. For example,
97      * the body property of a
98      * {@link MethodDeclaration} node
99      * admits a body which might include statement that embeds
100      * another {@link MethodDeclaration} node.
101      * On the other hand, the name property of a
102      * MethodDeclaration node admits only names, and thereby excludes
103      * another MethodDeclaration node.
104      * </p>
105      *
106      * @return <code>true</code> if cycles are possible,
107      * and <code>false</code> if cycles are impossible
108      */

109     public final boolean cycleRisk() {
110         return this.cycleRisk;
111     }
112 }
113
Popular Tags