blob: 81401acb2fa1a669d877e95fb596a22072f352d2 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.core.util;
import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
/**
* An ICompilationUnit that retrieves its contents using an IFile
*/
public class ResourceCompilationUnit extends CompilationUnit {
private IFile file;
public ResourceCompilationUnit(IFile file) {
super(null/*no contents*/, file.getLocationURI() == null ? file.getFullPath().toString() : file.getLocationURI().getPath(), null/*encoding is used only when retrieving the contents*/);
this.file = file;
}
public char[] getContents() {
if (this.contents != null)
return this.contents; // answer the cached source
// otherwise retrieve it
try {
return Util.getResourceContentsAsCharArray(this.file);
} catch (JavaModelException e) {
return CharOperation.NO_CHAR;
}
}
}