KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > util > ResourceCompilationUnit


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core.util;
12
13 import java.net.URI JavaDoc;
14
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jdt.core.compiler.CharOperation;
18 import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
19
20 /**
21  * An ICompilationUnit that retrieves its contents using an IFile
22  */

23 public class ResourceCompilationUnit extends CompilationUnit {
24     
25     private IFile file;
26     
27     public ResourceCompilationUnit(IFile file, URI JavaDoc location) {
28         super(null/*no contents*/, location == null ? file.getFullPath().toString() : location.getPath(), null/*encoding is used only when retrieving the contents*/);
29         this.file = file;
30     }
31
32     public char[] getContents() {
33         if (this.contents != null)
34             return this.contents; // answer the cached source
35

36         // otherwise retrieve it
37
try {
38             return Util.getResourceContentsAsCharArray(this.file);
39         } catch (CoreException e) {
40             return CharOperation.NO_CHAR;
41         }
42     }
43 }
44
Popular Tags