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.shell;
17:
18: import com.google.gwt.core.ext.TreeLogger;
19: import com.google.gwt.core.ext.UnableToCompleteException;
20: import com.google.gwt.core.ext.typeinfo.CompilationUnitProvider;
21: import com.google.gwt.core.ext.typeinfo.TypeOracle;
22: import com.google.gwt.dev.jdt.StandardSourceOracle;
23: import com.google.gwt.dev.jdt.StaticCompilationUnitProvider;
24: import com.google.gwt.util.tools.Utility;
25:
26: import java.io.File;
27: import java.io.IOException;
28:
29: /**
30: * Does a little extra magic to handle hosted mode JSNI and
31: * <code>GWT.create()</code>.
32: */
33: public class HostedModeSourceOracle extends StandardSourceOracle {
34:
35: private final JsniInjector injector;
36: private final File jsniSaveDirectory;
37:
38: public HostedModeSourceOracle(TypeOracle typeOracle,
39: File jsniSaveDirectory) {
40: super (typeOracle);
41: this .injector = new JsniInjector(typeOracle);
42: this .jsniSaveDirectory = jsniSaveDirectory;
43: }
44:
45: @Override
46: protected CompilationUnitProvider doFilterCompilationUnit(
47: TreeLogger logger, String typeName,
48: CompilationUnitProvider existing)
49: throws UnableToCompleteException {
50:
51: /*
52: * MAGIC: The implementation of GWT can be very different between hosted
53: * mode and web mode. The compiler has special knowledge of GWT for web
54: * mode. The source for hosted mode is in GWT.java-hosted.
55: */
56: if (typeName.equals("com.google.gwt.core.client.GWT")) {
57: try {
58: String source = Utility
59: .getFileFromClassPath("com/google/gwt/core/client/GWT.java-hosted");
60: return new StaticCompilationUnitProvider(
61: "com.google.gwt.core.client", "GWT", source
62: .toCharArray());
63: } catch (IOException e) {
64: logger
65: .log(
66: TreeLogger.ERROR,
67: "Unable to load 'com/google/gwt/core/client/GWT.java-hosted' from class path; is your installation corrupt?",
68: e);
69: throw new UnableToCompleteException();
70: }
71: }
72:
73: // Otherwise, it's a regular translatable type, but we want to make sure
74: // its JSNI stuff, if any, gets handled.
75: //
76: CompilationUnitProvider jsnified = injector.inject(logger,
77: existing, jsniSaveDirectory);
78: return jsnified;
79: }
80: }
|