KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > jjs > ast > JNode


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.jjs.ast;
17
18 import com.google.gwt.dev.jjs.HasSourceInfo;
19 import com.google.gwt.dev.jjs.SourceInfo;
20 import com.google.gwt.dev.jjs.impl.SourceGenerationVisitor;
21 import com.google.gwt.dev.jjs.impl.ToStringGenerationVisitor;
22 import com.google.gwt.dev.util.DefaultTextOutput;
23
24 /**
25  * Base class for all visitable AST nodes.
26  */

27 public abstract class JNode implements JVisitable, HasSourceInfo {
28
29   protected final JProgram program;
30   private final SourceInfo info;
31
32   protected JNode(JProgram program, SourceInfo info) {
33     if (program == null) {
34       assert (this instanceof JProgram);
35       this.program = (JProgram) this;
36     } else {
37       this.program = program;
38     }
39     this.info = info;
40   }
41
42   public SourceInfo getSourceInfo() {
43     return info;
44   }
45
46   // Causes source generation to delegate to the one visitor
47
public final String JavaDoc toSource() {
48     DefaultTextOutput out = new DefaultTextOutput(false);
49     SourceGenerationVisitor v = new SourceGenerationVisitor(out);
50     v.accept(this);
51     return out.toString();
52   }
53
54   // Causes source generation to delegate to the one visitor
55
public final String JavaDoc toString() {
56     DefaultTextOutput out = new DefaultTextOutput(false);
57     ToStringGenerationVisitor v = new ToStringGenerationVisitor(out);
58     v.accept(this);
59     return out.toString();
60   }
61 }
62
Popular Tags