Skip to content

Commit 0eec539

Browse files
minor refactoring
1 parent 81a684b commit 0eec539

File tree

6 files changed

+37
-28
lines changed

6 files changed

+37
-28
lines changed

annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public void fieldAssignNullableNonNullArrayContent() {
599599
== found.getOverallEffect(coreTestHelper.getConfig()))
600600
.disableBailOut()
601601
.checkExpectedOutput("fieldAssignNullableNonNullArrayContent/expected")
602-
.enableJSpecify()
602+
.enableJSpecifyMode()
603603
.start();
604604
}
605605
}

annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/CoreTestHelper.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,19 @@ public class CoreTestHelper {
109109

110110
private ParserConfiguration.LanguageLevel languageLevel;
111111

112-
private boolean jSpecifyEnabled = false;
112+
/**
113+
* JSpecify mode activation. Deactivated by default. If activated, the test will enable {<a
114+
* href="https://jspecify.dev">JSpecify</a>} mode on NullAway.
115+
*/
116+
private boolean jSpecifyModeEnabled;
113117

114118
public CoreTestHelper(Path projectPath, Path outDirPath) {
115119
this.projectPath = projectPath;
116120
this.outDirPath = outDirPath;
117121
this.expectedReports = new HashSet<>();
118122
this.projectBuilder = new ProjectBuilder(this, projectPath);
119123
this.languageLevel = ParserConfiguration.LanguageLevel.JAVA_17;
120-
this.jSpecifyEnabled = false;
124+
this.jSpecifyModeEnabled = false;
121125
}
122126

123127
public Module onTarget() {
@@ -245,11 +249,12 @@ public CoreTestHelper withLanguageLevel(ParserConfiguration.LanguageLevel langua
245249
}
246250

247251
/**
248-
* Enables JSpecify.
252+
* Enables JSpecify mode.
253+
*
249254
* @return This instance of {@link CoreTestHelper}.
250255
*/
251-
public CoreTestHelper enableJSpecify() {
252-
this.jSpecifyEnabled = true;
256+
public CoreTestHelper enableJSpecifyMode() {
257+
this.jSpecifyModeEnabled = true;
253258
return this;
254259
}
255260

@@ -442,8 +447,9 @@ public void makeAnnotatorConfigFile(Path configPath) {
442447
outDirPath.resolve(name + "-scanner.xml")))
443448
.collect(Collectors.toList());
444449
builder.checker = NullAway.NAME;
450+
// Set annotation name based on JSpecify mode activation.
445451
builder.nullableAnnotation =
446-
jSpecifyEnabled ? "org.jspecify.annotations" : "javax.annotation.Nullable";
452+
jSpecifyModeEnabled ? "org.jspecify.annotations.Nullable" : "javax.annotation.Nullable";
447453
// In tests, we use NullAway @Initializer annotation.
448454
builder.initializerAnnotation = "com.uber.nullaway.annotations.Initializer";
449455
builder.outputDir = outDirPath.toString();
@@ -466,17 +472,19 @@ public void makeAnnotatorConfigFile(Path configPath) {
466472
!getEnvironmentVariable("ANNOTATOR_TEST_DISABLE_PARALLEL_PROCESSING");
467473
if (downstreamDependencyAnalysisActivated) {
468474
builder.buildCommand =
469-
projectBuilder.computeTargetBuildCommandWithLibraryModelLoaderDependency(this.outDirPath, jSpecifyEnabled);
475+
projectBuilder.computeTargetBuildCommandWithLibraryModelLoaderDependency(
476+
this.outDirPath, jSpecifyModeEnabled);
470477
builder.downstreamBuildCommand =
471478
projectBuilder.computeDownstreamDependencyBuildCommandWithLibraryModelLoaderDependency(
472-
this.outDirPath, jSpecifyEnabled);
479+
this.outDirPath, jSpecifyModeEnabled);
473480
builder.nullawayLibraryModelLoaderPath =
474481
Utility.getPathToLibraryModel(outDirPath)
475482
.resolve(
476483
Paths.get(
477484
"src", "main", "resources", "edu", "ucr", "cs", "riple", "librarymodel"));
478485
} else {
479-
builder.buildCommand = projectBuilder.computeTargetBuildCommand(this.outDirPath, jSpecifyEnabled);
486+
builder.buildCommand =
487+
projectBuilder.computeTargetBuildCommand(this.outDirPath, jSpecifyModeEnabled);
480488
}
481489
builder.write(configPath);
482490
}

annotator-core/src/test/java/edu/ucr/cs/riple/core/tools/ProjectBuilder.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,20 @@ CoreTestHelper exitProjectConstruction() {
103103
* root to project root dir, command to compile the project and the computed paths to config files
104104
* which will be passed through gradle command line arguments.
105105
*
106-
* @param outDirPath Path to serialization output directory,
107-
* @param jSpecifyEnabled Flag to enable jSpecify
106+
* @param outDirPath Path to serialization output directory,
107+
* @param jSpecifyModeEnabled Flag to enable jSpecify mode when running NullAway.
108108
* @return The command to build the project including the command line arguments, this command can
109-
* * be executed from any directory.
109+
* * be executed from any directory.
110110
*/
111-
public String computeTargetBuildCommand(Path outDirPath, boolean jSpecifyEnabled) {
111+
public String computeTargetBuildCommand(Path outDirPath, boolean jSpecifyModeEnabled) {
112112
return String.format(
113113
"%s && ./gradlew %s %s -Plibrary-model-loader-path=%s -Pjspecify=%s --rerun-tasks",
114114
Utility.changeDirCommand(pathToProject),
115115
computeCompileGradleCommandForModules(modules.subList(0, 1)),
116116
String.join(" ", Utility.computeConfigPathsWithGradleArguments(outDirPath, modules)),
117117
Utility.getPathToLibraryModel(outDirPath)
118118
.resolve(Paths.get("build", "libs", "librarymodel.jar")),
119-
jSpecifyEnabled
120-
);
119+
jSpecifyModeEnabled);
121120
}
122121

123122
/**
@@ -126,12 +125,13 @@ public String computeTargetBuildCommand(Path outDirPath, boolean jSpecifyEnabled
126125
* loader jar and the computed paths to config files which will be passed through gradle command
127126
* line arguments.
128127
*
129-
* @param outDirPath Path to serialization output directory,
130-
* @param jSpecifyEnabled Flag to enable jSpecify
128+
* @param outDirPath Path to serialization output directory,
129+
* @param jSpecifyModeEnabled Flag to enable jSpecify mode when running NullAway.
131130
* @return The command to build the project including the command line arguments, this command can
132-
* * be executed from any directory.
131+
* * be executed from any directory.
133132
*/
134-
public String computeTargetBuildCommandWithLibraryModelLoaderDependency(Path outDirPath, boolean jSpecifyEnabled) {
133+
public String computeTargetBuildCommandWithLibraryModelLoaderDependency(
134+
Path outDirPath, boolean jSpecifyModeEnabled) {
135135
return String.format(
136136
"%s && ./gradlew library-model-loader:jar --rerun-tasks && %s && ./gradlew %s %s -Plibrary-model-loader-path=%s -Pjspecify=%s --rerun-tasks",
137137
Utility.changeDirCommand(outDirPath.resolve("Annotator")),
@@ -140,7 +140,7 @@ public String computeTargetBuildCommandWithLibraryModelLoaderDependency(Path out
140140
String.join(" ", Utility.computeConfigPathsWithGradleArguments(outDirPath, modules)),
141141
Utility.getPathToLibraryModel(outDirPath)
142142
.resolve(Paths.get("build", "libs", "librarymodel.jar")),
143-
jSpecifyEnabled);
143+
jSpecifyModeEnabled);
144144
}
145145

146146
/**
@@ -149,13 +149,13 @@ public String computeTargetBuildCommandWithLibraryModelLoaderDependency(Path out
149149
* loader jar and the computed paths to config files which will be passed through gradle command
150150
* line arguments.
151151
*
152-
* @param outDirPath Path to serialization output directory,
153-
* @param jSpecifyEnabled Flag to enable jSpecify
152+
* @param outDirPath Path to serialization output directory,
153+
* @param jSpecifyModeEnabled Flag to enable jSpecify mode when running NullAway.
154154
* @return The command to build the project including the command line arguments, this command can
155-
* * be executed from any directory.
155+
* * be executed from any directory.
156156
*/
157157
public String computeDownstreamDependencyBuildCommandWithLibraryModelLoaderDependency(
158-
Path outDirPath, boolean jSpecifyEnabled) {
158+
Path outDirPath, boolean jSpecifyModeEnabled) {
159159
return String.format(
160160
"%s && ./gradlew library-model-loader:jar --rerun-tasks && %s && ./gradlew %s %s -Plibrary-model-loader-path=%s -Pjspecify=%s --rerun-tasks",
161161
Utility.changeDirCommand(outDirPath.resolve("Annotator")),
@@ -164,8 +164,7 @@ public String computeDownstreamDependencyBuildCommandWithLibraryModelLoaderDepen
164164
String.join(" ", Utility.computeConfigPathsWithGradleArguments(outDirPath, modules)),
165165
Utility.getPathToLibraryModel(outDirPath)
166166
.resolve(Paths.get("build", "libs", "librarymodel.jar")),
167-
jSpecifyEnabled
168-
);
167+
jSpecifyModeEnabled);
169168
}
170169

171170
/**

annotator-core/src/test/resources/templates/java-17/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ subprojects {
7373
option("NullAway:SerializeFixMetadata", "true")
7474
option("NullAway:FixSerializationConfigPath", project.getProperty(project.name + "-nullaway-config-path"))
7575
option("NullAway:AcknowledgeLibraryModelsOfAnnotatedCode", "true")
76+
option("NullAway:JSpecifyMode", project.getProperty("jspecify"))
7677
option("AnnotatorScanner:ConfigPath", project.getProperty(project.name + "-scanner-config-path"))
7778
}
7879
}

annotator-core/src/test/resources/templates/lombok/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ subprojects {
7575
option("NullAway:SerializeFixMetadata", "true")
7676
option("NullAway:FixSerializationConfigPath", project.getProperty(project.name + "-nullaway-config-path"))
7777
option("NullAway:AcknowledgeLibraryModelsOfAnnotatedCode", "true")
78+
option("NullAway:JSpecifyMode", project.getProperty("jspecify"))
7879
option("AnnotatorScanner:ConfigPath", project.getProperty(project.name + "-scanner-config-path"))
7980
}
8081
}

annotator-core/src/test/resources/templates/nullable-multi-modular/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ subprojects {
7373
option("NullAway:SerializeFixMetadata", "true")
7474
option("NullAway:FixSerializationConfigPath", project.getProperty(project.name + "-nullaway-config-path"))
7575
option("NullAway:AcknowledgeLibraryModelsOfAnnotatedCode", "true")
76-
option("NullAway:JSpecifyMode", project.getProperty(project.name + "-jspecify"))
76+
option("NullAway:JSpecifyMode", project.getProperty("jspecify"))
7777
option("AnnotatorScanner:ConfigPath", project.getProperty(project.name + "-scanner-config-path"))
7878
}
7979
}

0 commit comments

Comments
 (0)