Skip to main content
summaryrefslogtreecommitdiffstats
blob: 05dd886a189bd9f5c0e39f8dfbdc80c8de8a1bb8 (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
/*******************************************************************************
 * 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.initParser;
/*


 */

import java.io.StringWriter;
import java.lang.reflect.Array;
import java.util.*;
/**
 * This represents the arguments in a multi dimensional array with construction parameters, e.g.
 * new int[][] { { 2 ,3 } , { 4 ,5 }}
 * the arguments of the constructor will be instance of ArrayArguments 
 */
public class ArrayArguments extends Expression {
	
	Static fType;
	List arguments = new ArrayList(2);
	boolean argsClosed;
	boolean insideArgsOpenedParen;
	boolean insideArgsClosedParen;
	
public Expression push(char[] token, char tokenDelimiter) {
	
	// If the args are opened and a token was supplied then it must be an argument
	//if ( argsOpened && ( tokenDelimiter == DelimiterCloseParen || tokenDelimiter == DelimiterComma || 
	//tokenDelimiter == DelimiterSpace || tokenDelimiter == DelimiterQuote || tokenDelimiter == DelimiterPeriod)) {
	if (!argsClosed){	
		if ( arguments.size() > 0 ){
			Expression openArgument = (Expression)arguments.get(arguments.size()-1);
			if ( !openArgument.isComplete() ) {
				openArgument.push(token,tokenDelimiter);
				// If the argument is complete and we received a ) then the message is complete
				if ( openArgument.isComplete() && tokenDelimiter == DelimiterCloseElipse){
					argsClosed = true;
				}
				return this;
			}
		}	
		
		// We must have a new argument - process accordingly	
		Expression newArgument = null;
		if (!insideArgsOpenedParen && tokenDelimiter == DelimiterOpenParen){
			insideArgsOpenedParen = true;
			newArgument = new Statement(fClassLoader).push(token,tokenDelimiter);
			newArgument = new MessageArgument(newArgument);
			arguments.add(newArgument);

		}
		if ( token.length > 0 || tokenDelimiter == DelimiterQuote || tokenDelimiter == DelimiterSingleQuote || tokenDelimiter == OperMinus ) {
			newArgument = new Statement(fClassLoader).push(token,tokenDelimiter);
			newArgument = new MessageArgument(newArgument);
			arguments.add(newArgument);
		}
		// If the token after the argument is a ) then the message is being closed
		if ( !insideArgsOpenedParen  && tokenDelimiter == DelimiterCloseElipse ) {
			argsClosed = true;
			return this;
		}
		if ( insideArgsOpenedParen  && tokenDelimiter == DelimiterCloseElipse ) {
			insideArgsClosedParen  = true;
			argsClosed = true;
			return this;
		}
	}
	return this;
}
/**
 * In the case of the expression new int[][] { {2,3} , {4,5} } then we are the 2,3 or the 4,5
 * to evaluate we must return an array of ints based on our size.  The type we return is determined by the initial 
 * constructor who will have given this to us as our fType
 */	
public Object evaluate() throws Exception {

	Object result = Array.newInstance(fType.getPrimitiveTypeClass(),arguments.size());
	for (int i = 0; i < arguments.size(); i++) {
		Object argumentValue = ((Expression)arguments.get(i)).evaluate();
		Array.set(result,i,argumentValue);
	}
	return result;
}

public Class getTypeClass() throws Exception {
	return null;
}

public boolean isComplete() {
	return argsClosed;
}

public boolean isPrimitive() throws Exception {
	return false;
}
public void setType(Static type) {
	fType = type;
}
public void contributeArgumentNumber(List argumentNumberList){
	
	// Add the number of arguments we have to the list
	argumentNumberList.add(new Integer(arguments.size()));
	// If our arguments are themselves array arguments ( which will occur in an array of 3 or more dimensions )
	// then we should cascade this message to our argument so that the total array depth is known
	if ( arguments.size() > 0 ) {
		Object firstArgument = arguments.get(0);
		if ( firstArgument instanceof ArrayArguments ) {
//			((ArrayArguments)firstArgument)contributeArgumentNumber(argumentNumberList);
		}
	}
	
}
public String toString(){
	StringWriter writer = new StringWriter();
	writer.write("Args("); //$NON-NLS-1$
	writer.write(new Integer(arguments.size()).toString());
	writer.write(")-"); //$NON-NLS-1$
	writer.write(arguments.toString());
	return writer.toString();
}
	/* (non-Javadoc)
	 * @see org.eclipse.jem.internal.proxy.core.initParser.Expression#getTypeClassName()
	 */
	protected String getTypeClassName() {
		return "";	// Not applicable //$NON-NLS-1$
	}

}

Back to the top