Skip to main content
summaryrefslogtreecommitdiffstats
blob: ba1e81203fce1df78b4c0a39abf701f463e19484 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*******************************************************************************
 * Copyright (c) 2001, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jem.internal.proxy.ide;

/*
 *  $RCSfile: IDEArrayBeanTypeProxy.java,v $
 *  $Revision: 1.4 $  $Date: 2005/08/24 20:39:06 $ 
 */

import org.eclipse.jem.internal.proxy.core.*;

import java.lang.reflect.*;

/**
 * Array Type Proxy for the IDE VM.
 * 
 * The class is final because array's are special and shouldn't have any subclasses since the factory would never call it.
 */

public final class IDEArrayBeanTypeProxy extends IDEBeanTypeProxy implements IArrayBeanTypeProxy {

	IBeanTypeProxy fFinalComponentType;

	IBeanTypeProxy fComponentType;

	String fTypeName;

	/**
	 * Create with a registry and a class. It is package so that only the factory with this IDE package can call it.
	 */
	IDEArrayBeanTypeProxy(IDEProxyFactoryRegistry aRegistry, String aTypeName, Class aClass) {
		// The class of an Array is always Object
		super(aRegistry, aClass);
		fTypeName = aTypeName;
	}

	/**
	 * This is an array type!
	 */
	public boolean isArray() {
		return true;
	}

	public String getTypeName() {
		return fTypeName;
	}

	/**
	 * Return the final component type.
	 */
	public IBeanTypeProxy getFinalComponentType() {
		if (fFinalComponentType == null) {
			// Component type is strip off all '[' and return class name (if we ever add classLoader support, this won't work).
			// However, if the type is a primitive we need to go through the change table).
			int typeStart = getTypeName().lastIndexOf('[') + 1;
			if (getTypeName().charAt(typeStart) == 'L') {
				// It is a class.
				// Strip off up to the 'L', and the trailing ';'. That is the class name.
				fFinalComponentType = fProxyFactoryRegistry.getBeanTypeProxyFactory().getBeanTypeProxy(
						getTypeName().substring(typeStart + 1, getTypeName().length() - 1));
			} else {
				// It is a type. Need to map it.
				Class aType = (Class) IDEStandardBeanTypeProxyFactory.MAP_SHORTSIG_TO_TYPE.get(getTypeName().substring(typeStart, typeStart + 1));
				fFinalComponentType = aType != null ? fProxyFactoryRegistry.getBeanTypeProxyFactory().getBeanTypeProxy(aType.getName()) : null;
			}
		}
		return fFinalComponentType;
	}

	/**
	 * Return the component type.
	 */
	public IBeanTypeProxy getComponentType() {
		if (fComponentType == null) {
			// Component type is strip off first '[' and return class name (if we ever add classLoader support, this won't work).
			// However, if the type is a primitive we need to go through the change table).
			if (getTypeName().charAt(1) != '[') {
				// It is a one dimensional array, just send to getFinalComponentType to figure out the type.
				fComponentType = getFinalComponentType();
			} else {
				// It is a multi-dimensional array. Just strip off one '[' and send that to the bean type factory.
				fComponentType = fProxyFactoryRegistry.getBeanTypeProxyFactory().getBeanTypeProxy(getTypeName().substring(1));
			}
		}
		return fComponentType;
	}

	/**
	 * Return the number of dimensions.
	 */
	public int getDimensions() {
		return getTypeName().lastIndexOf('[') + 1;
	}

	/**
	 * Return the null ctor proxy for this method with these arguments. For all of the array types, this is an invalid operation.
	 */
	public IConstructorProxy getNullConstructorProxy() {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return a proxy to the constructor for the target VM being the same as the REM For all of the array types, this is an invalid operation.
	 */
	public IConstructorProxy getConstructorProxy(String[] argumentClassNames) {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return a proxy to the constructor for the target VM being the same as the REM For all of the array types, this is an invalid operation.
	 */
	public IConstructorProxy getConstructorProxy(IBeanTypeProxy[] argumentTypes) {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getConstructors() For all of the array types, this is an invalid operation.
	 */
	public IConstructorProxy[] getConstructors() {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return a proxy to the constructor for the target VM being the same as the REM For all of the array types, this is an invalid operation.
	 */
	public IConstructorProxy getDeclaredConstructorProxy(String[] argumentClassNames) {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return a proxy to the constructor for the target VM being the same as the REM For all of the array types, this is an invalid operation.
	 */
	public IConstructorProxy getDeclaredConstructorProxy(IBeanTypeProxy[] argumentTypes) {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getConstructors() For all of the array types, this is an invalid operation.
	 */
	public IConstructorProxy[] getDeclaredConstructors() {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getConstructors() For all of the array types, this is an invalid operation.
	 */
	public IFieldProxy[] getFields() {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getCompatibleConstructor(org.eclipse.jem.internal.proxy.core.IBeanTypeProxy[])
	 */
	public IConstructorProxy getCompatibleConstructor(IBeanTypeProxy[] argumentTypes) {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getCompatibleMethod(java.lang.String,
	 *      org.eclipse.jem.internal.proxy.core.IBeanTypeProxy[])
	 */
	public IMethodProxy getCompatibleMethod(String methodName, IBeanTypeProxy[] argumentTypes) {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getConstructors() For all of the array types, this is an invalid operation.
	 */
	public IFieldProxy[] getDeclaredFields() {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return a proxy to the field for the target VM being the same as the REM For all of the array types, this is an invalid operation.
	 */
	public IFieldProxy getFieldProxy(String fieldName) {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return the method proxy for this method with these arguments. For all of the array types, this is an invalid operation.
	 */
	public IMethodProxy getMethodProxy(String methodName, IBeanTypeProxy[] argumentTypes) {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return the method proxy for this method with these arguments. For all of the array types, this is an invalid operation.
	 */
	public IMethodProxy getMethodProxy(String methodName, String[] argumentClassNames) {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return the method proxy for this method with these arguments. For all of the array types, this is an invalid operation.
	 */
	public IMethodProxy getMethodProxy(String methodName, String argumentQualifiedTypeName) {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return the method proxy for this method with these arguments. For all of the array types, this is an invalid operation.
	 */
	public IMethodProxy getMethodProxy(String methodName) {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getConstructors() For all of the array types, this is an invalid operation.
	 */
	public IMethodProxy[] getMethods() {
		throw new UnsupportedOperationException();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getConstructors() For all of the array types, this is an invalid operation.
	 */
	public IMethodProxy[] getDeclaredMethods() {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return the method proxy for this method with these arguments. For all of the array types, this is an invalid operation.
	 */
	public IMethodProxy getDeclaredMethodProxy(String methodName, IBeanTypeProxy[] argumentTypes) {
		throw new UnsupportedOperationException();
	}

	/**
	 * Return the method proxy for this method with these arguments. For all of the array types, this is an invalid operation.
	 */
	public IMethodProxy getDeclaredMethodProxy(String methodName, String[] argumentClassNames) {
		throw new UnsupportedOperationException();
	}

	/**
	 * Create an array bean proxy.
	 *  - (int, new int[2] {3, 4}) will create: int [3] [4]
	 *  - (int[], new int[1] {1}) int [1]
	 *  - (int[], new int[2] {2,3}) int [2] [3]
	 * 
	 *  - (int[], null) or (int[], new int[0]) or (int, null) or (int, new int[0]) int [0] (int[][], null) or (int[][], new int[0]) int[0][] This is
	 * because an array instance with no dimensions specified is not valid.
	 *  - (int[][], new int[1] {3}) int[3][]
	 * 
	 * It is package protected so that only the REM Factory can call it.
	 */
	IDEArrayBeanProxy createBeanProxyWith(int[] dimensions) throws ThrowableProxy {
		// If the dimensions is null or zero length, then create the
		// array as a 0 sized array one dimensional array.
		if (dimensions == null || dimensions.length == 0)
			return createBeanProxyWith(new int[] { 0});

		// Remove from this type the number of dimensions specified
		// coming in, up to but no further than the final component.
		// From here we can then use the appropriate java.lang.reflect.Array
		// method to create the array.
		IBeanTypeProxy compType = null; // The type of array to create (it may be different number of dimensions).
		int numDims = getDimensions();
		if (numDims <= dimensions.length)
			compType = getFinalComponentType(); // There are the same or more requested dimensions, so use final component type
		else {
			// There are fewer requested dimensions, so strip off that many
			String compClass = getTypeName().substring(dimensions.length);
			compType = fProxyFactoryRegistry.getBeanTypeProxyFactory().getBeanTypeProxy(compClass);
		}

		if (dimensions.length == 1) {
			// Use the one dimension call
			Object array = Array.newInstance(((IDEBeanTypeProxy) compType).fClass, dimensions[0]);
			return new IDEArrayBeanProxy(fProxyFactoryRegistry, array, null);
		} else {
			// Use the multi dimension call
			Object array = Array.newInstance(((IDEBeanTypeProxy) compType).fClass, dimensions);
			return new IDEArrayBeanProxy(fProxyFactoryRegistry, array, null);
		}
	}

	/**
	 * Create a new bean proxy with the specified object
	 */
	protected IIDEBeanProxy newBeanProxy(Object anObject) {

		return new IDEArrayBeanProxy(fProxyFactoryRegistry, anObject, this);

	}

	/**
	 * @see IBeanTypeProxy#getFormalTypeName()
	 */
	public String getFormalTypeName() {
		String name = getTypeName();
		int dims = name.lastIndexOf('[') + 1;
		String type = getFinalComponentType().getTypeName();
		StringBuffer formalType = new StringBuffer(type.length() + ("[]".length() * dims)); //$NON-NLS-1$
		formalType.append(type);
		for (int i = 0; i < dims; i++)
			formalType.append("[]"); //$NON-NLS-1$
		return formalType.toString();
	}

}

Back to the top