Skip to main content
summaryrefslogtreecommitdiffstats
blob: 88ad26c39327446b0c7e987a41a507389bbfb054 (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
/*******************************************************************************
 * 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.text.MessageFormat;



public class CharLiteral extends Expression {
	protected boolean isComplete;
	public char value;
	public StringBuffer valueBuffer = new StringBuffer();
	protected boolean isEscaped = false;

/**
 * constructor
 */
public CharLiteral(){
}
	
/**
 * evaluate method comment.
 */
public Object evaluate() throws Exception {
	if (valueBuffer.length() == 1)
		return new Character(valueBuffer.charAt(0));
	else
		throw new EvaluationException(
			new IllegalArgumentException(MessageFormat.format(ProxyInitParserMessages.getString("CharTooComplicated_EXC_"), //$NON-NLS-1$
				new Object[] {valueBuffer.toString()})));
}

public boolean isComplete(){
	return isComplete;
}
/**
 * We must evaluate ourself and return the type of the result
 */
 
public Class getTypeClass() {
	return Character.TYPE;
}

protected String getTypeClassName() {
	return Character.TYPE.getName();
}
/**
 *This string might be broken into a few tokens
 *so we need a StringBuffer 
 */
public Expression push(char[] token , char delimiter){
	
	if (isEscaped) {
		isEscaped = false;
		if (token.length != 0) {
			// Had an escape followed by stuff, so not a true esc for our current definition
			valueBuffer.append(DelimiterEscape);
		} else {
			if (delimiter == DelimiterSingleQuote || delimiter == DelimiterEscape)
				valueBuffer.append(delimiter);	// It was a true escape.
			else {
				valueBuffer.append(DelimiterEscape);	// If wasn't a true escape
				valueBuffer.append(delimiter);
			}
			return this;
		}
	}
	
	valueBuffer.append(token);
	
	if (delimiter == DelimiterSingleQuote){		
		isComplete =true;
		return this;
	}
	
	// If the delimiter is an escape character remember it so we can escape
	// the next token, otherwise treat it as a literal
	if (delimiter == DelimiterEscape ){
		isEscaped = true;
	} else {
		valueBuffer.append(delimiter);
	}
	return this;
}

/**
 * chars are primitives.
 */
public boolean isPrimitive() {
	return true;
}
public String toString(){
	StringBuffer buffer = new StringBuffer();
	buffer.append("Char('"); //$NON-NLS-1$
	if ( valueBuffer != null ) {
		buffer.append(valueBuffer.toString());
	}
	buffer.append(')');
	return buffer.toString();
}

}

Back to the top