1 /* gnu.classpath.tools.gjdoc.expr.IdentifierExpression
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 package gnu.classpath.tools.gjdoc.expr;
23 class IdentifierExpression
26 private String identifier;
28 public IdentifierExpression(String identifier)
30 this.identifier = identifier;
33 public ConstantExpression evaluate(Context context)
34 throws IllegalExpressionException
36 Object value = context.getEvaluatorEnvironment().getValue(identifier, context.getVisitedFields());
38 if (value instanceof Byte) {
39 return new ConstantByte(((Byte)value).byteValue());
41 else if (value instanceof Short) {
42 return new ConstantShort(((Short)value).shortValue());
44 else if (value instanceof Integer) {
45 return new ConstantInteger(((Integer)value).intValue());
47 else if (value instanceof Long) {
48 return new ConstantLong(((Long)value).longValue());
50 else if (value instanceof Float) {
51 return new ConstantFloat(((Float)value).floatValue());
53 else if (value instanceof Double) {
54 return new ConstantDouble(((Double)value).doubleValue());
56 else if (value instanceof Boolean) {
57 return new ConstantBoolean(((Boolean)value).booleanValue());
59 else if (value instanceof Character) {
60 return new ConstantChar(((Character)value).charValue());
62 else if (value instanceof String) {
63 return new ConstantString((String)value);
65 else if (null != value) {
66 throw new IllegalExpressionException("Unsupported type " + value.getClass().getName() + " for identifier " + identifier);
69 throw new IllegalExpressionException("Cannot resolve identifier " + identifier);