01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.generator.ast;
17:
18: import java.util.List;
19: import java.util.Arrays;
20:
21: /**
22: * A {@link Node} that represents a single Java statement.
23: */
24: public class Statement extends BaseNode implements Statements {
25:
26: private String code;
27:
28: private Expression expression;
29:
30: private final List<Statements> list;
31:
32: /**
33: * Creates a new <code>Statement</code> from a {@link String} of code
34: * representing an {@link Expression}. Automatically appends a semicolon to
35: * <code>code</code>.
36: *
37: * @param code A textual {@link Expression}. Should not end with a semicolon.
38: */
39: public Statement(String code) {
40: this .code = code;
41: this .list = Arrays.asList((Statements) this );
42: }
43:
44: /**
45: * Creates a new <code>Statement</code> from an {@link Expression}.
46: *
47: * @param expression A non <code>null</code> {@link Expression}.
48: */
49: public Statement(Expression expression) {
50: this .expression = expression;
51: this .list = Arrays.asList((Statements) this );
52: }
53:
54: /**
55: * Returns this single <code>Statement</code> as a {@link java.util.List} of
56: * {@link Statement}s of size, one.
57: */
58: public List<Statements> getStatements() {
59: return list;
60: }
61:
62: @Override
63: public String toCode() {
64: if (expression != null) {
65: return expression.toCode() + ";";
66: } else {
67: return code + ";";
68: }
69: }
70: }
|