KickJava   Java API By Example, From Geeks To Geeks.

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


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.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   public char[] getMainTypeName() {
54     // seems to work just returning null
55
return null;
56   }
57
58   public char[][] getPackageName() {
59     final char[] pkg = cup.getPackageName().toCharArray();
60     final char[][] pkgParts = CharOperation.splitOn('.', pkg);
61     return pkgParts;
62   }
63 }
64
Popular Tags