Skip to content

Commit

Permalink
Cleanup InputFile interface
Browse files Browse the repository at this point in the history
	Change on 2017/01/23 by zgao <zgao@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=145280475
  • Loading branch information
zhouyanggao authored and tomball committed Jan 24, 2017
1 parent 9faa3a3 commit 3f0de5f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 28 deletions.
Expand Up @@ -36,17 +36,20 @@ public interface InputFile {
Reader openReader(Charset charset) throws IOException;

/**
* Gets a full path of a sourcefile. The "path" might not be an actual file system path
* (for example, if it is a jar URL). Used in J2ObjC for progress messages, error messages,
* and output comments.
* Gets a full path of a Java or JAR file. The path must be an actual file system path that can be
* used to read the soure. For Java source files extracted from a JAR file, return the absolute
* path of the extracted Java source file. For non-extracted JAR files, return the absolute path
* of the JAR file.
*/
String getPath();
String getAbsolutePath();

/**
* Gets the relative path to the actual filesystem file.
* For example, this could be a .java file or a .jar file.
* Gets the original location of a Java source file.
* For Java source files directly from or extracted from a JAR file, return
* "jar:file:path/to/originalJarFile.jar!internal/path/to/SourceFile.java".
* Used in J2ObjC for progress messages, error messages, and output comments.
*/
String getContainingPath();
String getOriginalLocation();

/**
* The compilation unit name of this SourceFile.
Expand Down
Expand Up @@ -87,13 +87,13 @@ public Reader openReader(Charset charset) throws IOException {
}

@Override
public String getPath() {
return "jar:file:" + jarPath + "!" + internalPath;
public String getAbsolutePath() {
return jarPath;
}

@Override
public String getContainingPath() {
return jarPath;
public String getOriginalLocation() {
return "jar:file:" + jarPath + "!" + internalPath;
}

@Override
Expand All @@ -113,6 +113,6 @@ public long lastModified() {

@Override
public String toString() {
return getPath();
return getOriginalLocation();
}
}
Expand Up @@ -27,26 +27,26 @@
* @author Mike Thvedt
*/
public class RegularInputFile implements InputFile {
private final String path;
private final String absolutePath;
private final String unitPath;

public RegularInputFile(String unitPath) {
this(unitPath, unitPath);
}

public RegularInputFile(String fsPath, String unitPath) {
this.path = fsPath;
this.absolutePath = fsPath;
this.unitPath = unitPath;
}

@Override
public boolean exists() {
return new File(path).exists();
return new File(absolutePath).exists();
}

@Override
public InputStream getInputStream() throws IOException {
return new FileInputStream(new File(path));
return new FileInputStream(new File(absolutePath));
}

@Override
Expand All @@ -55,13 +55,13 @@ public Reader openReader(Charset charset) throws IOException {
}

@Override
public String getPath() {
return path;
public String getAbsolutePath() {
return absolutePath;
}

@Override
public String getContainingPath() {
return unitPath;
public String getOriginalLocation() {
return absolutePath;
}

@Override
Expand All @@ -76,11 +76,11 @@ public String getBasename() {

@Override
public long lastModified() {
return new File(path).lastModified();
return new File(absolutePath).lastModified();
}

@Override
public String toString() {
return getPath();
return getOriginalLocation();
}
}
Expand Up @@ -71,7 +71,7 @@ public GenerationUnit(String sourceName, int numUnits, Options options) {
}

public static GenerationUnit newSingleFileUnit(InputFile file, Options options) {
GenerationUnit unit = new GenerationUnit(file.getPath(), 1, options);
GenerationUnit unit = new GenerationUnit(file.getOriginalLocation(), 1, options);
if (options.getHeaderMap().useSourceDirectories()) {
String outputPath = file.getUnitName();
outputPath = outputPath.substring(0, outputPath.lastIndexOf(".java"));
Expand Down
Expand Up @@ -230,7 +230,7 @@ public ProcessingResult processAnnotations(Iterable<String> fileArgs,
if (serviceIterator.hasNext()) {
List<File> inputFiles = new ArrayList<>();
for (ProcessingContext input : inputs) {
inputFiles.add(new File(input.getFile().getPath()));
inputFiles.add(new File(input.getFile().getAbsolutePath()));
}
try {
JavacEnvironment env = createEnvironment(inputFiles, null, true);
Expand Down
Expand Up @@ -178,7 +178,8 @@ public void acceptAST(String sourceFilePath, CompilationUnit ast) {
env, ast, sourceFilePath, FileUtil.getMainTypeName(file), source);
handler.handleParsedUnit(sourceFilePath, unit);
} catch (IOException e) {
ErrorUtil.error("Error reading file " + file.getPath() + ": " + e.getMessage());
ErrorUtil.error(
"Error reading file " + file.getOriginalLocation() + ": " + e.getMessage());
}
}
}
Expand Down
Expand Up @@ -113,7 +113,7 @@ private void processInput(ProcessingContext input) {
}

protected boolean isBatchable(InputFile file) {
return doBatching && file.getContainingPath().endsWith(".java");
return doBatching && file.getAbsolutePath().endsWith(".java");
}

private void processBatch() {
Expand All @@ -124,7 +124,7 @@ private void processBatch() {
List<String> paths = Lists.newArrayListWithCapacity(batchInputs.size());
final Map<String, ProcessingContext> inputMap = new CanonicalPathMap(batchInputs.size());
for (ProcessingContext input : batchInputs) {
String path = input.getFile().getPath();
String path = input.getFile().getAbsolutePath();
paths.add(path);
inputMap.put(path, input);
}
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class ProcessingContext {
private final GenerationUnit generationUnit;

public ProcessingContext(InputFile file, GenerationUnit generationUnit) {
originalSourcePath = file.getPath();
originalSourcePath = file.getOriginalLocation();
this.file = file;
this.generationUnit = generationUnit;
}
Expand Down

0 comments on commit 3f0de5f

Please sign in to comment.