KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > generator > ast > Statement


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.Arrays JavaDoc;
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 JavaDoc code;
27
28   private Expression expression;
29
30   private final List JavaDoc 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 JavaDoc code) {
40     this.code = code;
41     this.list = Arrays.asList(new Statement[]{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(new Statement[]{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 JavaDoc getStatements() {
59     return list;
60   }
61
62   public String JavaDoc toCode() {
63     if (expression != null) {
64       return expression.toCode() + ";";
65     } else {
66       return code + ";";
67     }
68   }
69 }
70
Popular Tags