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.jdt;
17:
18: import com.google.gwt.core.ext.UnableToCompleteException;
19: import com.google.gwt.core.ext.typeinfo.CompilationUnitProvider;
20:
21: import org.eclipse.jdt.core.compiler.CharOperation;
22: import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
23:
24: /**
25: * Implements <code>ICompilationUnit</code> in terms of a
26: * {@link CompilationUnitProvider}.
27: */
28: public class ICompilationUnitAdapter implements ICompilationUnit {
29:
30: private final CompilationUnitProvider cup;
31:
32: public ICompilationUnitAdapter(CompilationUnitProvider cup) {
33: assert (cup != null);
34: this .cup = cup;
35: }
36:
37: public CompilationUnitProvider getCompilationUnitProvider() {
38: return cup;
39: }
40:
41: public char[] getContents() {
42: try {
43: return cup.getSource();
44: } catch (UnableToCompleteException e) {
45: return null;
46: }
47: }
48:
49: public char[] getFileName() {
50: return cup.getLocation().toCharArray();
51: }
52:
53: /**
54: * This method is supposed to return the simple class name for this
55: * compilation unit. Examples of simple class names would be "String", or
56: * "ArrayList". JDT allows this method to return null in the cases where this
57: * compilation unit is not a package-info class.
58: */
59: public char[] getMainTypeName() {
60: String typeName = cup.getMainTypeName();
61: if (typeName != null) {
62: return typeName.toCharArray();
63: }
64: return null;
65: }
66:
67: public char[][] getPackageName() {
68: final char[] pkg = cup.getPackageName().toCharArray();
69: final char[][] pkgParts = CharOperation.splitOn('.', pkg);
70: return pkgParts;
71: }
72: }
|