Skip to content

Commit

Permalink
Add -AparseAllJdk option (#3279)
Browse files Browse the repository at this point in the history
Also, add a tests that used that option.
  • Loading branch information
smillst authored May 1, 2020
1 parent e38f895 commit ccdcaf8
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
21 changes: 21 additions & 0 deletions checker/src/test/java/tests/ParseAllJdkTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tests;

import java.io.File;
import java.util.List;
import org.checkerframework.checker.nullness.NullnessChecker;
import org.checkerframework.framework.test.CheckerFrameworkPerDirectoryTest;
import org.junit.runners.Parameterized.Parameters;

/** Tests -AparseAllJdk option. */
public class ParseAllJdkTest extends CheckerFrameworkPerDirectoryTest {

/** @param testFiles the files containing test code, which will be type-checked */
public ParseAllJdkTest(List<File> testFiles) {
super(testFiles, NullnessChecker.class, "parse-all-jdk", "-AparseAllJdk");
}

@Parameters
public static String[] getTestDirs() {
return new String[] {"parse-all-jdk"};
}
}
2 changes: 2 additions & 0 deletions checker/tests/parse-all-jdk/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** This class doesn't need a body because it is only used to test parsing all the JDK files. */
public class Test {}
3 changes: 3 additions & 0 deletions docs/manual/creating-a-checker.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,9 @@
\item \code{-ApermitMissingJdk}:
don't issue an error if no annotated JDK can be found.

\item \code{-AparseAllJdk}:
parse all JDK files at startup rather than as needed.

\item \code{-AstubDebug}:
Print debugging messages while processing stub files.

Expand Down
1 change: 1 addition & 0 deletions docs/manual/introduction.tex
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@
\item
\<-Aignorejdkastub>,
\<-ApermitMissingJdk>,
\<-AparseAllJdk>,
\<-AstubDebug>
Stub and JDK libraries; see Section~\ref{creating-debugging-options-libraries}.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@
"permitMissingJdk",
"nocheckjdk", // temporary, for backward compatibility

// Parse all JDK files at startup rather than as needed.
// org.checkerframework.framework.stub.StubTypes.StubTypes
"parseAllJdk",

// Whether to print debugging messages while processing the stub files
// org.checkerframework.framework.stub.StubParser.debugStubParser
"stubDebug",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ private void stubWarnOverwritesBytecode(String warning) {
*/
private void stubWarn(String warning, Object... args) {
warning = String.format(warning, args);
if (warnings.add(warning)) {
if (warnings.add(warning) && !isJdkAsStub) {
processingEnv
.getMessager()
.printMessage(javax.tools.Diagnostic.Kind.WARNING, "StubParser: " + warning);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ public class StubTypes {
/** Should the JDK be parsed? */
private final boolean shouldParseJdk;

/** Creates a stub type. */
/** Parse all JDK files at startup rather than as needed. */
private final boolean parseAllJdkFiles;

/**
* Creates a stub type.
*
* @param factory AnnotatedTypeFactory
*/
public StubTypes(AnnotatedTypeFactory factory) {
this.factory = factory;
this.typesFromStubFiles = new HashMap<>();
Expand All @@ -86,6 +93,7 @@ public StubTypes(AnnotatedTypeFactory factory) {
!factory.getContext().getChecker().hasOption("ignorejdkastub")
&& SystemUtil.getJreVersion() != 8
&& annotatedJdkVersion.equals("11");
this.parseAllJdkFiles = factory.getContext().getChecker().hasOption("parseAllJdk");
}

/** @return true if stub files are currently being parsed; otherwise, false. */
Expand Down Expand Up @@ -480,6 +488,10 @@ private void prepJdkFromFile(URL resourceURL) {
parseStubFile(path);
continue;
}
if (parseAllJdkFiles) {
parseStubFile(path);
continue;
}
Path relativePath = root.relativize(path);
// 4: /src/<module>/share/classes
Path savepath = relativePath.subpath(4, relativePath.getNameCount());
Expand Down Expand Up @@ -507,15 +519,20 @@ private void prepJdkFromJar(URL resourceURL) {
if (!jarEntry.isDirectory()
&& jarEntry.getName().endsWith(".java")
&& jarEntry.getName().startsWith("annotated-jdk")) {
String jeNAme = jarEntry.getName();
String jarEntryName = jarEntry.getName();
int index = jarEntry.getName().indexOf("/share/classes/");
String shortName =
jeNAme.substring(index + "/share/classes/".length())
jarEntryName
.substring(index + "/share/classes/".length())
.replace(".java", "")
.replace('/', '.');
jdkStubFilesJar.put(shortName, jeNAme);
if (jeNAme.endsWith("package-info.java")) {
parseJarEntry(jeNAme);
jdkStubFilesJar.put(shortName, jarEntryName);
if (jarEntryName.endsWith("package-info.java")) {
parseJarEntry(jarEntryName);
}
if (parseAllJdkFiles) {
parseJarEntry(jarEntryName);
continue;
}
}
}
Expand Down

0 comments on commit ccdcaf8

Please sign in to comment.