-
Notifications
You must be signed in to change notification settings - Fork 293
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
External Library Models Integration #922
Changes from 11 commits
1d48e6e
b0631cb
e5353d1
ea7d117
e9a06dc
19b020b
31f569c
a26f856
a863363
ee56362
3806c80
32f0990
3dedc77
07586ae
4b7891e
10c36e3
36b5a21
a6c8204
0c2cd44
ac14c99
2dbc283
32e80d5
2b637f1
888c1b2
fb81869
e889dc3
26efa96
cbe7bf5
600164c
d1fed93
db993b8
09c0f4c
161c6ac
27ebcc9
5ee2428
8c442f7
609f2e5
fb83aff
629ec5b
5190597
fd7d546
f213d82
1137aa9
6e0ef33
41bc90f
26c4907
dc0618a
5fa73da
14e39b6
f390cd1
ad44788
2a1c2da
8f86b36
35b988c
c1fe36b
d301e28
439ca14
e2a9c60
a072bbd
75785fa
80be0d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,4 +73,54 @@ public void libraryModelNullableReturnsArrayTest() { | |
"}") | ||
.doTest(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test case without the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, may I suggest a case with a model adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lazaroclapp We have not added the functionality for processing the annotations on method parameters in this PR so a test case with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also @lazaroclapp I don't think supporting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't a chance that specific classes will be |
||
|
||
@Test | ||
public void libraryModelWithoutJarInferEnabledTest() { | ||
compilationHelper | ||
.setArgs( | ||
Arrays.asList( | ||
"-d", | ||
temporaryFolder.getRoot().getAbsolutePath(), | ||
"-XepOpt:NullAway:AnnotatedPackages=com.uber")) | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import com.uber.nullaway.libmodel.AnnotationExample;", | ||
"class Test {", | ||
" static AnnotationExample annotationExample = new AnnotationExample();", | ||
" static void test(String value){", | ||
" }", | ||
" static void testNegative() {", | ||
" // Since the JarInferEnabled and JarInferUseReturnAnnotations flags are not set, we don't get an error here", | ||
" test(annotationExample.makeUpperCase(\"nullaway\"));", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
public void libraryModelInnerClassNullableReturnsTest() { | ||
compilationHelper | ||
.setArgs( | ||
Arrays.asList( | ||
"-d", | ||
temporaryFolder.getRoot().getAbsolutePath(), | ||
"-XepOpt:NullAway:AnnotatedPackages=com.uber", | ||
"-XepOpt:NullAway:JarInferEnabled=true", | ||
"-XepOpt:NullAway:JarInferUseReturnAnnotations=true")) | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import com.uber.nullaway.libmodel.AnnotationExample;", | ||
"class Test {", | ||
" static AnnotationExample.InnerExample innerExample = new AnnotationExample.InnerExample();", | ||
" static void test(String value){", | ||
" }", | ||
" static void testPositive() {", | ||
" // BUG: Diagnostic contains: passing @Nullable parameter 'innerExample.returnNull()'", | ||
" test(innerExample.returnNull());", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,10 +26,8 @@ | |
import com.github.javaparser.ParserConfiguration.LanguageLevel; | ||
import com.github.javaparser.ast.CompilationUnit; | ||
import com.github.javaparser.ast.ImportDeclaration; | ||
import com.github.javaparser.ast.Node; | ||
import com.github.javaparser.ast.PackageDeclaration; | ||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; | ||
import com.github.javaparser.ast.body.EnumDeclaration; | ||
import com.github.javaparser.ast.body.MethodDeclaration; | ||
import com.github.javaparser.ast.expr.AnnotationExpr; | ||
import com.github.javaparser.ast.type.ArrayType; | ||
|
@@ -59,12 +57,12 @@ | |
* directory. It processes the annotated Java source code to generate an astubx file that contains | ||
* the required annotation information to be able to generate library models. | ||
*/ | ||
public class LibraryModelGenerator { | ||
Check warning on line 60 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L60
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going to assume these codecov warnings are because it doesn't properly count the coverage from running this as part of the build for the integration tests? (cc: @msridhar ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is true. At the same time, we don't have any unit tests like those in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brief update is that the stubx writing code gets covered as part of the |
||
|
||
public void generateAstubxForLibraryModels(String inputSourceDirectory, String outputDirectory) { | ||
Map<String, MethodAnnotationsRecord> methodRecords = processDirectory(inputSourceDirectory); | ||
writeToAstubx(outputDirectory, methodRecords); | ||
} | ||
Check warning on line 65 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L63-L65
|
||
|
||
/** | ||
* Parses all the source files within the directory using javaparser. | ||
|
@@ -73,26 +71,26 @@ | |
* @return a Map containing the Nullability annotation information from the source files. | ||
*/ | ||
private Map<String, MethodAnnotationsRecord> processDirectory(String sourceDirectoryRoot) { | ||
Map<String, MethodAnnotationsRecord> methodRecords = new LinkedHashMap<>(); | ||
Path root = dirnameToPath(sourceDirectoryRoot); | ||
AnnotationCollectorCallback ac = new AnnotationCollectorCallback(methodRecords); | ||
CollectionStrategy strategy = new ParserCollectionStrategy(); | ||
Check warning on line 77 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L74-L77
|
||
// Required to include directories that contain a module-info.java, which don't parse by | ||
// default. | ||
strategy.getParserConfiguration().setLanguageLevel(LanguageLevel.JAVA_17); | ||
ProjectRoot projectRoot = strategy.collect(root); | ||
Check warning on line 81 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L80-L81
|
||
|
||
projectRoot | ||
.getSourceRoots() | ||
.forEach( | ||
Check warning on line 85 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L83-L85
|
||
sourceRoot -> { | ||
try { | ||
sourceRoot.parse("", ac); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
return methodRecords; | ||
Check warning on line 93 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L88-L93
|
||
} | ||
|
||
/** | ||
|
@@ -104,124 +102,115 @@ | |
private void writeToAstubx( | ||
String outputPath, Map<String, MethodAnnotationsRecord> methodRecords) { | ||
if (methodRecords.isEmpty()) { | ||
return; | ||
Check warning on line 105 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L105
|
||
} | ||
Map<String, String> importedAnnotations = | ||
ImmutableMap.of( | ||
Check warning on line 108 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L107-L108
|
||
"Nonnull", "javax.annotation.Nonnull", | ||
"Nullable", "javax.annotation.Nullable"); | ||
"NonNull", "org.jspecify.annotations.NonNull", | ||
"Nullable", "org.jspecify.annotations.Nullable"); | ||
Path outputPathInstance = Paths.get(outputPath); | ||
Check warning on line 111 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L111
|
||
try { | ||
Files.createDirectories(outputPathInstance.getParent()); | ||
try (DataOutputStream dos = new DataOutputStream(Files.newOutputStream(outputPathInstance))) { | ||
StubxWriter.write( | ||
Check warning on line 115 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L113-L115
|
||
dos, | ||
importedAnnotations, | ||
Collections.emptyMap(), | ||
Collections.emptyMap(), | ||
Check warning on line 119 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L118-L119
|
||
methodRecords); | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
Check warning on line 125 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L122-L125
|
||
|
||
public Path dirnameToPath(String dir) { | ||
File f = new File(dir); | ||
String absoluteDir = f.getAbsolutePath(); | ||
Check warning on line 129 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L128-L129
|
||
if (absoluteDir.endsWith("/.")) { | ||
absoluteDir = absoluteDir.substring(0, absoluteDir.length() - 2); | ||
Check warning on line 131 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L131
|
||
} | ||
return Paths.get(absoluteDir); | ||
Check warning on line 133 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L133
|
||
} | ||
|
||
private static class AnnotationCollectorCallback implements SourceRoot.Callback { | ||
|
||
private final AnnotationCollectionVisitor annotationCollectionVisitor; | ||
|
||
public AnnotationCollectorCallback(Map<String, MethodAnnotationsRecord> methodRecords) { | ||
this.annotationCollectionVisitor = new AnnotationCollectionVisitor(methodRecords); | ||
} | ||
Check warning on line 142 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L140-L142
|
||
|
||
@Override | ||
public Result process(Path localPath, Path absolutePath, ParseResult<CompilationUnit> result) { | ||
Result res = Result.SAVE; | ||
Optional<CompilationUnit> opt = result.getResult(); | ||
Check warning on line 147 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L146-L147
|
||
if (opt.isPresent()) { | ||
CompilationUnit cu = opt.get(); | ||
cu.accept(annotationCollectionVisitor, null); | ||
Check warning on line 150 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L149-L150
|
||
} | ||
return res; | ||
Check warning on line 152 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L152
|
||
} | ||
} | ||
|
||
private static class AnnotationCollectionVisitor extends VoidVisitorAdapter<Void> { | ||
|
||
private String packageName = ""; | ||
private StringBuilder parentName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably better to just make this a |
||
private boolean isJspecifyNullableImportPresent = false; | ||
private boolean isNullMarked = false; | ||
Check warning on line 160 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L159-L160
|
||
private Map<String, MethodAnnotationsRecord> methodRecords; | ||
private static final String ARRAY_RETURN_TYPE_STRING = "Array"; | ||
private static final String NULL_MARKED = "NullMarked"; | ||
private static final String NULLABLE = "Nullable"; | ||
private static final String JSPECIFY_NULLABLE_IMPORT = "org.jspecify.annotations.Nullable"; | ||
|
||
public AnnotationCollectionVisitor(Map<String, MethodAnnotationsRecord> methodRecords) { | ||
this.methodRecords = methodRecords; | ||
} | ||
Check warning on line 169 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L167-L169
|
||
|
||
@Override | ||
public void visit(PackageDeclaration pd, Void arg) { | ||
this.packageName = pd.getNameAsString(); | ||
this.parentName = new StringBuilder(pd.getNameAsString()); | ||
super.visit(pd, null); | ||
} | ||
Check warning on line 175 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L173-L175
|
||
|
||
@Override | ||
public void visit(ImportDeclaration id, Void arg) { | ||
if (id.getName().toString().contains(JSPECIFY_NULLABLE_IMPORT)) { | ||
this.isJspecifyNullableImportPresent = true; | ||
Check warning on line 180 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L180
|
||
} | ||
super.visit(id, null); | ||
} | ||
Check warning on line 183 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L182-L183
|
||
|
||
@Override | ||
public void visit(ClassOrInterfaceDeclaration cid, Void arg) { | ||
/*Currently, this logic only supports @NullMarked annotations on top-level classes and | ||
does not handle cases where @NullMarked appears on some nested classes but not others*/ | ||
/*This logic assumes an explicit @NullMarked annotation on the top-level class within a | ||
source file, and it's expected that each source file contains only one top-level class. The | ||
logic does not currently handle cases where @NullMarked annotations appear on some nested | ||
classes but not others. It also does not consider annotations within package-info.java or | ||
module-info.java files.*/ | ||
parentName.append(".").append(cid.getNameAsString()); | ||
cid.getAnnotations() | ||
.forEach( | ||
Check warning on line 194 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L192-L194
|
||
a -> { | ||
if (a.getNameAsString().equalsIgnoreCase(NULL_MARKED)) { | ||
this.isNullMarked = true; | ||
Check warning on line 197 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L197
|
||
} | ||
}); | ||
super.visit(cid, null); | ||
Check warning on line 200 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L199-L200
|
||
// We reset the variable that constructs the parent name after visiting all the children. | ||
parentName.delete(parentName.lastIndexOf("." + cid.getNameAsString()), parentName.length()); | ||
} | ||
Check warning on line 203 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L202-L203
|
||
|
||
@Override | ||
public void visit(MethodDeclaration md, Void arg) { | ||
Optional<Node> parentClassNode = md.getParentNode(); | ||
String parentClassName = ""; | ||
if (parentClassNode.isPresent()) { | ||
if (parentClassNode.get() instanceof ClassOrInterfaceDeclaration) { | ||
parentClassName = ((ClassOrInterfaceDeclaration) parentClassNode.get()).getNameAsString(); | ||
} else if (parentClassNode.get() instanceof EnumDeclaration) { | ||
parentClassName = ((EnumDeclaration) parentClassNode.get()).getNameAsString(); | ||
} | ||
} | ||
if (this.isNullMarked && hasNullableReturn(md)) { | ||
methodRecords.put( | ||
packageName | ||
+ "." | ||
+ parentClassName | ||
+ ":" | ||
+ getMethodReturnTypeString(md) | ||
+ " " | ||
+ md.getSignature().toString(), | ||
parentName + ":" + getMethodReturnTypeString(md) + " " + md.getSignature().toString(), | ||
MethodAnnotationsRecord.create(ImmutableSet.of("Nullable"), ImmutableMap.of())); | ||
Check warning on line 210 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L208-L210
|
||
} | ||
super.visit(md, null); | ||
} | ||
Check warning on line 213 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L212-L213
|
||
|
||
/** | ||
* Determines if a MethodDeclaration can return null. | ||
|
@@ -236,17 +225,17 @@ | |
Nullable(@Nullable Object []) */ | ||
for (AnnotationExpr annotation : md.getType().getAnnotations()) { | ||
if (isAnnotationNullable(annotation)) { | ||
return true; | ||
Check warning on line 228 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L228
|
||
} | ||
} | ||
Check warning on line 230 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L230
|
||
} else { | ||
for (AnnotationExpr annotation : md.getAnnotations()) { | ||
if (isAnnotationNullable(annotation)) { | ||
return true; | ||
Check warning on line 234 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L234
|
||
} | ||
} | ||
Check warning on line 236 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L236
|
||
} | ||
return false; | ||
Check warning on line 238 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L238
|
||
} | ||
|
||
/** | ||
|
@@ -258,16 +247,16 @@ | |
*/ | ||
private String getMethodReturnTypeString(MethodDeclaration md) { | ||
if (md.getType() instanceof ClassOrInterfaceType) { | ||
return md.getType().getChildNodes().get(0).toString(); | ||
Check warning on line 250 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L250
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that using simple names is something we inherited from the CF |
||
} else if (md.getType() instanceof ArrayType) { | ||
return ARRAY_RETURN_TYPE_STRING; | ||
Check warning on line 252 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L252
|
||
} else { | ||
return md.getType().toString(); | ||
Check warning on line 254 in library-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java Codecov / codecov/patchlibrary-model/library-model-generator/src/main/java/com/uber/nullaway/libmodel/LibraryModelGenerator.java#L254
|
||
} | ||
} | ||
|
||
private boolean isAnnotationNullable(AnnotationExpr annotation) { | ||
// Since we only want to consider jspecify Nullable annotations. | ||
// We only consider jspecify Nullable annotations(star imports are not supported). | ||
return (annotation.getNameAsString().equalsIgnoreCase(NULLABLE) | ||
&& this.isJspecifyNullableImportPresent) | ||
|| annotation.getNameAsString().equalsIgnoreCase(JSPECIFY_NULLABLE_IMPORT); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,19 @@ public String makeUpperCase(String inputString) { | |
/** | ||
* This method exists to test that | ||
* we do not process this annotation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Why not? I assume we currently only acknowledge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As to reasoning, I wanted to narrow the focus because when declaration annotations get mixed in, things start getting very confusing (e.g., how to interpret them on array types). Since only JSpecify annotations are used in jspecify/jdk I thought we'd just focus on that for now |
||
* Since for the purposes of this tool, | ||
* we are only considering the jspecify annotation. | ||
*/ | ||
@javax.annotation.Nullable | ||
public String nullReturn() { | ||
return null; | ||
} | ||
|
||
public static class InnerExample { | ||
|
||
@Nullable | ||
public String returnNull() { | ||
return null; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the number of args and print a basic usage message? (Not sure if we do that for JarInfer, and I don't think we need a full argument parser here yet, a check on the length of
args
would suffice for now)