01: /*
02: * Copyright 2006 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.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
24: CompilationUnitProvider {
25:
26: private final String packageName;
27:
28: private final String simpleTypeName;
29:
30: private final char[] source;
31:
32: /**
33: * @param source if <code>null</code>, override this class and return
34: * source from {@link #getSource()}
35: */
36: public StaticCompilationUnitProvider(String packageName,
37: String simpleTypeName, char[] source) {
38: this .packageName = packageName;
39: this .simpleTypeName = simpleTypeName;
40: this .source = source;
41: }
42:
43: /**
44: * Stubbed to return the same value every time.
45: */
46: public long getLastModified() {
47: return 0;
48: }
49:
50: /**
51: * Creates a stable name for this compilation unit.
52: */
53: public final String getLocation() {
54: return "transient source for " + packageName + "."
55: + simpleTypeName;
56: }
57:
58: public String getMainTypeName() {
59: return getTypeName();
60: }
61:
62: public String getPackageName() {
63: return packageName;
64: }
65:
66: public char[] getSource() {
67: return source;
68: }
69:
70: public String getTypeName() {
71: return simpleTypeName;
72: }
73:
74: public boolean isTransient() {
75: return true;
76: }
77:
78: public String toString() {
79: return getLocation();
80: }
81: }
|