Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1bd80bb8ec4d783c164033aa2042f3e09bbab01c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**********************************************************************
 * This file is part of "Object Teams Development Tooling"-Software
 *
 * Copyright 2006 Fraunhofer Gesellschaft, Munich, Germany,
 * for its Fraunhofer Institute for Computer Architecture and Software
 * Technology (FIRST), Berlin, Germany and Technical University Berlin,
 * Germany.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * $Id: PrecedenceDeclaration.java 23417 2010-02-03 20:13:55Z stephan $
 *
 * Please visit http://www.eclipse.org/objectteams for updates and contact.
 *
 * Contributors:
 * Fraunhofer FIRST - Initial API and implementation
 * Technical University Berlin - Initial API and implementation
 **********************************************************************/
package org.eclipse.jdt.core.dom;

import java.util.ArrayList;
import java.util.List;

/**
 * This class represents a precedence declaration in OT/J (OTJLD §4.8).
 * A precedence declaration contains a list of names
 * referring either to classes or to callin bindings.
 *
 * @author stephan
 */
@SuppressWarnings("rawtypes")
public class PrecedenceDeclaration extends ASTNode {

	@SuppressWarnings("nls")
	public static final ChildListPropertyDescriptor ELEMENTS_PROPERTY =
		new ChildListPropertyDescriptor(PrecedenceDeclaration.class, "elements", Name.class, NO_CYCLE_RISK);

	/**
	 * The "after" structural property of this node type.
	 * @since 0.7.0
	 */
	@SuppressWarnings("nls")
	public static final SimplePropertyDescriptor AFTER_PROPERTY =
		new SimplePropertyDescriptor(PrecedenceDeclaration.class, "after", boolean.class, MANDATORY);

	private static final List PROPERTY_DESCRIPTORS_3_0;

	static {
		List propertyList = new ArrayList(3);
		createPropertyList(PrecedenceDeclaration.class, propertyList);
		addProperty(ELEMENTS_PROPERTY, propertyList);
		addProperty(AFTER_PROPERTY, propertyList);
		PROPERTY_DESCRIPTORS_3_0 = reapPropertyList(propertyList);
	}

	public static List propertyDescriptors(int apiLevel) {
		if (apiLevel == AST.JLS2_INTERNAL) {
			throw new UnsupportedOperationException("JLS2 not supported"); //$NON-NLS-1$
		} else {
			return PROPERTY_DESCRIPTORS_3_0;
		}
	}

	ASTNode.NodeList _elements = new ASTNode.NodeList(ELEMENTS_PROPERTY);

	/**
	 * <code>true</code> for <code>precedence after</code>, else <code>false</code>.
	 */
	boolean isAfter = false;

	PrecedenceDeclaration(AST ast)
	{
		super(ast);
	}

     @Override
	List internalGetChildListProperty(ChildListPropertyDescriptor property)
     {
    	 if (property == ELEMENTS_PROPERTY) {
    		 return this._elements;
    	 }
    	 // allow default implementation to flag the error
    	 return super.internalGetChildListProperty(property);
     }

     @Override
     boolean internalGetSetBooleanProperty(SimplePropertyDescriptor property, boolean get, boolean value) {
    	 if (property == AFTER_PROPERTY) {
    		 if (get) {
    			 return isAfter();
    		 } else {
    			 setAfter(value);
    			 return false;
    		 }
    	 }
    	 // allow default implementation to flag the error
    	 return super.internalGetSetBooleanProperty(property, get, value);
     }

	@Override
	void accept0(ASTVisitor visitor) {
		boolean visitChildren = visitor.visit(this);
		if (visitChildren) {
			// visit children in normal left to right reading order
			if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
				unsupportedIn2();
			}
			if (this.ast.apiLevel >= AST.JLS3_INTERNAL) {
				acceptChildren(visitor, this._elements);
			}
		}
		visitor.endVisit(this);
	}

	@Override
	boolean subtreeMatch0(ASTMatcher matcher, Object other) {
        // dispatch to correct overloaded match method
		return matcher.match(this, other);
	}

	@SuppressWarnings("unchecked")
	@Override
	ASTNode clone0(AST target) {
		if (this.ast.apiLevel == AST.JLS2_INTERNAL)
			unsupportedIn2();
		PrecedenceDeclaration result = new PrecedenceDeclaration(target);
		result.setSourceRange(this.getStartPosition(), this.getLength());
		result.elements().addAll(ASTNode.copySubtrees(target, elements()));
		result.setAfter(isAfter());
		return result;
	}

	@Override
	int getNodeType0() {
		return PRECEDENCE_DECLARATION;
	}

	@Override
	List internalStructuralPropertiesForType(int apiLevel) {
		return propertyDescriptors(apiLevel);
	}

	public List elements() {
		return this._elements;
	}

	/**
	 * Mark whether this is a <code>precedence after</code> declaration.
	 */
    public void setAfter(boolean isAfter) {
		preValueChange(AFTER_PROPERTY);
		this.isAfter = isAfter;
		postValueChange(AFTER_PROPERTY);
    }

	/**
	 * Answer whether this is a <code>precedence after</code> declaration.
	 */
    public boolean isAfter() {
		return this.isAfter;
    }

	@Override
	int memSize() {
		return BASE_NODE_SIZE + 1;
	}

	@Override
	int treeSize() {
		return memSize() + this._elements.listSize();
	}

}

Back to the top