Skip to content

Commit

Permalink
Updates method signature serialization for Nonull formal parameters (#…
Browse files Browse the repository at this point in the history
…213)

This PR fixes #212 by updating method signature serialization for nonnull formal parameters. It reuses the existing serialization methods for symbols that ensure the correct method signature is printed.
  • Loading branch information
nimakarimipour authored Nov 17, 2023
1 parent fbab7a5 commit e085b64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
19 changes: 19 additions & 0 deletions annotator-core/src/test/java/edu/ucr/cs/riple/core/CoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,23 @@ public void nestedParameters() {
.toDepth(1)
.start();
}

@Test
public void nonnullTypeUseAnnotationOnFormalParameterAcknowledgmentTest() {
coreTestHelper
.onTarget()
.withSourceLines(
"A.java",
"package test;",
"import org.jetbrains.annotations.NotNull;",
"public class A {",
" static void foo(@NotNull Object o) {}",
" static void bar() { foo(null); }",
"}")
.expectNoReport()
.toDepth(5)
.start();
// No annotation should be added even though it can reduce the number of errors.
Assert.assertEquals(coreTestHelper.getLog().getInjectedAnnotations().size(), 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ subprojects {

// to add @Initializer
compileOnly 'com.uber.nullaway:nullaway-annotations:0.10.10'
// to add jetbrains annotations (testing type use vs type declaration)
compileOnly 'org.jetbrains:annotations:24.0.0'
compileOnly "org.jspecify:jspecify:0.3.0"
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
errorprone "com.google.errorprone:error_prone_core:2.3.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.google.common.base.Preconditions;
import com.sun.tools.javac.code.Symbol;
import edu.ucr.cs.riple.scanner.Serializer;
import javax.lang.model.element.ElementKind;

/**
Expand Down Expand Up @@ -66,8 +67,8 @@ public String tabSeparatedToString() {
"\t",
type.toString(),
enclosingClass.flatName(),
enclosingMethod.toString(),
paramSymbol.toString(),
Serializer.serializeSymbol(enclosingMethod),
Serializer.serializeSymbol(paramSymbol),
String.valueOf(index),
path != null ? path.toString() : "null");
}
Expand Down

0 comments on commit e085b64

Please sign in to comment.