KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > jdt > StaticCompilationUnitProvider


1 /*
2  * Copyright 2006 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.jdt;
17
18 import com.google.gwt.core.ext.typeinfo.CompilationUnitProvider;
19
20 /**
21  * Implements a {@link CompilationUnitProvider} as transient (in-memory) source.
22  */

23 public class StaticCompilationUnitProvider implements CompilationUnitProvider {
24
25   private final String JavaDoc packageName;
26
27   private final String JavaDoc simpleTypeName;
28
29   private final char[] source;
30
31   /**
32    * @param source if <code>null</code>, override this class and return
33    * source from {@link #getSource()}
34    */

35   public StaticCompilationUnitProvider(String JavaDoc packageName,
36       String JavaDoc simpleTypeName, char[] source) {
37     this.packageName = packageName;
38     this.simpleTypeName = simpleTypeName;
39     this.source = source;
40   }
41
42   /**
43    * Stubbed to return the same value every time.
44    */

45   public long getLastModified() {
46     return 0;
47   }
48
49   /**
50    * Creates a stable name for this compilation unit.
51    */

52   public final String JavaDoc getLocation() {
53     return "transient source for " + packageName + "." + simpleTypeName;
54   }
55
56   public String JavaDoc getPackageName() {
57     return packageName;
58   }
59
60   public char[] getSource() {
61     return source;
62   }
63
64   public String JavaDoc getTypeName() {
65     return simpleTypeName;
66   }
67
68   public boolean isTransient() {
69     return true;
70   }
71
72   public String JavaDoc toString() {
73     return getLocation();
74   }
75 }
76
Popular Tags