Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOE Sync 2020-05-26 #1635

Merged
merged 3 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

123 changes: 0 additions & 123 deletions core/src/main/java/com/google/errorprone/ErrorProneCompiler.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private static int getPrecedence(JCTree leaf, Context context) {
return (typeCast.expr == leaf) ? TreeInfo.prefixPrec : TreeInfo.noPrec;
} else if (parent instanceof JCInstanceOf) {
JCInstanceOf instanceOf = (JCInstanceOf) parent;
return TreeInfo.ordPrec + ((instanceOf.clazz == leaf) ? 1 : 0);
return TreeInfo.ordPrec + ((instanceOf.getType() == leaf) ? 1 : 0);
} else if (parent instanceof JCArrayAccess) {
JCArrayAccess arrayAccess = (JCArrayAccess) parent;
return (arrayAccess.indexed == leaf) ? TreeInfo.postfixPrec : TreeInfo.noPrec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ private JCCompilationUnit doCompile(
throw new IllegalArgumentException("Exception during argument processing: " + e);
}
context.put(ErrorProneOptions.class, errorProneOptions);
fileManager.createAndInstallTempFolderForOutput();
JavacTaskImpl task =
(JavacTaskImpl)
tool.getTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private Result compile() {
if (checkWellFormed) {
checkWellFormed(sources, processedArgs);
}
createAndInstallTempFolderForOutput(fileManager);
fileManager.createAndInstallTempFolderForOutput();
return compiler
.getTask(
new PrintWriter(
Expand All @@ -353,30 +353,8 @@ private Result compile() {
: Result.ERROR;
}

private static void createAndInstallTempFolderForOutput(
ErrorProneInMemoryFileManager fileManager) {
Path tempDirectory;
try {
tempDirectory =
Files.createTempDirectory(
fileManager.fileSystem().getRootDirectories().iterator().next(), "");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Arrays.stream(StandardLocation.values())
.filter(StandardLocation::isOutputLocation)
.forEach(
outputLocation -> {
try {
fileManager.setLocationFromPaths(outputLocation, ImmutableList.of(tempDirectory));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}

private void checkWellFormed(Iterable<JavaFileObject> sources, List<String> args) {
createAndInstallTempFolderForOutput(fileManager);
fileManager.createAndInstallTempFolderForOutput();
JavaCompiler compiler = JavacTool.create();
OutputStream outputStream = new ByteArrayOutputStream();
List<String> remainingArgs = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;

/** An in-memory file manager for testing that uses {@link JavacFileManager} and {@link Jimfs}. */
public class ErrorProneInMemoryFileManager extends JavacFileManager {
Expand Down Expand Up @@ -168,4 +170,24 @@ public boolean exists(String fileName) {
public FileSystem fileSystem() {
return fileSystem;
}

void createAndInstallTempFolderForOutput() {
Path tempDirectory;
try {
tempDirectory =
Files.createTempDirectory(fileSystem().getRootDirectories().iterator().next(), "");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Arrays.stream(StandardLocation.values())
.filter(StandardLocation::isOutputLocation)
.forEach(
outputLocation -> {
try {
setLocationFromPaths(outputLocation, ImmutableList.of(tempDirectory));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
}