2012-09-04 22:56:05 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* 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 com.ibm.wala.classLoader;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.io.Reader;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import com.ibm.wala.util.io.FileSuffixes;
|
|
|
|
|
|
|
|
/**
|
2013-04-30 19:09:55 +00:00
|
|
|
* A {@link Module} which is a wrapper around a source file
|
2012-09-04 22:56:05 +00:00
|
|
|
*/
|
|
|
|
public class SourceFileModule extends FileModule implements Module, ModuleEntry, SourceModule {
|
|
|
|
|
|
|
|
private final String fileName;
|
2013-06-25 15:53:58 +00:00
|
|
|
public SourceFileModule(File f, String fileName, Module container) {
|
|
|
|
super(f, container);
|
2012-09-04 22:56:05 +00:00
|
|
|
this.fileName = fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SourceFileModule(File f, SourceFileModule clonedFrom) {
|
2013-06-25 15:53:58 +00:00
|
|
|
super(f, clonedFrom.getContainer());
|
2012-09-04 22:56:05 +00:00
|
|
|
this.fileName = clonedFrom.fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "SourceFileModule:" + getFile().toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @see com.ibm.wala.classLoader.ModuleEntry#isClassFile()
|
|
|
|
*/
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public boolean isClassFile() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @see com.ibm.wala.classLoader.ModuleEntry#getClassName()
|
|
|
|
*/
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public String getClassName() {
|
|
|
|
return FileSuffixes.stripSuffix(fileName).replace(File.separator.charAt(0), '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @see com.ibm.wala.classLoader.ModuleEntry#isSourceFile()
|
|
|
|
*/
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public boolean isSourceFile() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public Reader getInputReader() {
|
|
|
|
return new InputStreamReader(getInputStream());
|
|
|
|
}
|
|
|
|
|
2013-06-25 15:53:58 +00:00
|
|
|
@Override
|
2012-09-04 22:56:05 +00:00
|
|
|
public URL getURL() {
|
|
|
|
try {
|
|
|
|
return getFile().toURI().toURL();
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
throw new Error("error making URL for " + getFile());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|