1 | /******************************************************************************* |
---|---|
2 | * Copyright (c) 2004, 2013 IBM Corporation and others. |
3 | * |
4 | * This program and the accompanying materials |
5 | * are made available under the terms of the Eclipse Public License 2.0 |
6 | * which accompanies this distribution, and is available at |
7 | * https://www.eclipse.org/legal/epl-2.0/ |
8 | * |
9 | * SPDX-License-Identifier: EPL-2.0 |
10 | * |
11 | * Contributors: |
12 | * IBM Corporation - initial API and implementation |
13 | *******************************************************************************/ |
14 | package org.eclipse.jdt.core.dom; |
15 | |
16 | /** |
17 | * Descriptor for a simple property of an AST node. |
18 | * A simple property is one whose value is a |
19 | * primitive type (such as <code>int</code> or <code>boolean</code>) |
20 | * or some simple value type (such as <code>String</code> or |
21 | * <code>InfixExpression.Operator</code>). |
22 | * |
23 | * @see org.eclipse.jdt.core.dom.ASTNode#getStructuralProperty(StructuralPropertyDescriptor) |
24 | * @see org.eclipse.jdt.core.dom.ASTNode#setStructuralProperty(StructuralPropertyDescriptor, Object) |
25 | * @since 3.0 |
26 | * @noinstantiate This class is not intended to be instantiated by clients. |
27 | */ |
28 | @SuppressWarnings("rawtypes") |
29 | public final class SimplePropertyDescriptor extends StructuralPropertyDescriptor { |
30 | |
31 | /** |
32 | * Value type. For example, for a node type like |
33 | * SingleVariableDeclaration, the modifiers property is int.class |
34 | */ |
35 | private final Class valueType; |
36 | |
37 | /** |
38 | * Indicates whether a value is mandatory. A property value is allowed |
39 | * to be <code>null</code> only if it is not mandatory. |
40 | */ |
41 | private final boolean mandatory; |
42 | |
43 | /** |
44 | * Creates a new simple 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 valueType the value 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 | */ |
55 | SimplePropertyDescriptor(Class nodeClass, String propertyId, Class valueType, boolean mandatory) { |
56 | super(nodeClass, propertyId); |
57 | if (valueType == null || ASTNode.class.isAssignableFrom(valueType)) { |
58 | throw new IllegalArgumentException(); |
59 | } |
60 | this.valueType = valueType; |
61 | this.mandatory = mandatory; |
62 | } |
63 | |
64 | /** |
65 | * Returns the value type of this property. |
66 | * <p> |
67 | * For example, for a node type like SingleVariableDeclaration, |
68 | * the "modifiers" property returns <code>int.class</code>. |
69 | * </p> |
70 | * |
71 | * @return the value type of the property |
72 | */ |
73 | public Class getValueType() { |
74 | return this.valueType; |
75 | } |
76 | |
77 | /** |
78 | * Returns whether this property is mandatory. A property value |
79 | * is not allowed to be <code>null</code> if it is mandatory. |
80 | * |
81 | * @return <code>true</code> if the property is mandatory, |
82 | * and <code>false</code> if it is may be <code>null</code> |
83 | */ |
84 | public boolean isMandatory() { |
85 | return this.mandatory; |
86 | } |
87 | } |
88 |
Members