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 simple property of an AST node.
15 * A simple property is one whose value is a
16 * primitive type (such as <code>int</code> or <code>boolean</code>)
17 * or some simple value type (such as <code>String</code> or
18 * <code>InfixExpression.Operator</code>).
20 * @see org.eclipse.jdt.core.dom.ASTNode#getStructuralProperty(StructuralPropertyDescriptor)
21 * @see org.eclipse.jdt.core.dom.ASTNode#setStructuralProperty(StructuralPropertyDescriptor, Object)
23 * @noinstantiate This class is not intended to be instantiated by clients.
25 public final class SimplePropertyDescriptor extends StructuralPropertyDescriptor {
28 * Value type. For example, for a node type like
29 * SingleVariableDeclaration, the modifiers property is int.class
31 private final Class valueType;
34 * Indicates whether a value is mandatory. A property value is allowed
35 * to be <code>null</code> only if it is not mandatory.
37 private final boolean mandatory;
40 * Creates a new simple property descriptor with the given property id.
41 * Note that this constructor is declared package-private so that
42 * property descriptors can only be created by the AST
45 * @param nodeClass concrete AST node type that owns this property
46 * @param propertyId the property id
47 * @param valueType the value type of this property
48 * @param mandatory <code>true</code> if the property is mandatory,
49 * and <code>false</code> if it is may be <code>null</code>
51 SimplePropertyDescriptor(Class nodeClass, String propertyId, Class valueType, boolean mandatory) {
52 super(nodeClass, propertyId);
53 if (valueType == null || ASTNode.class.isAssignableFrom(valueType)) {
54 throw new IllegalArgumentException();
56 this.valueType = valueType;
57 this.mandatory = mandatory;
61 * Returns the value type of this property.
63 * For example, for a node type like SingleVariableDeclaration,
64 * the "modifiers" property returns <code>int.class</code>.
67 * @return the value type of the property
69 public Class getValueType() {
70 return this.valueType;
74 * Returns whether this property is mandatory. A property value
75 * is not allowed to be <code>null</code> if it is mandatory.
77 * @return <code>true</code> if the property is mandatory,
78 * and <code>false</code> if it is may be <code>null</code>
80 public boolean isMandatory() {
81 return this.mandatory;