Skip to content

Commit 6d6a27c

Browse files
committed
add 'throws' field to MethodSignature and implement pretty-printing
1 parent 0bbdd1e commit 6d6a27c

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/SignatureFormatter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ private void formatMethodSignature(MethodSignature methodSignature) {
178178
+ " "
179179
+ symInfo.getDisplayName())
180180
.collect(Collectors.joining(", ", "(", ")")));
181+
182+
if (!methodSignature.getThrowsList().isEmpty()) {
183+
printKeyword(" throws");
184+
s.append(
185+
methodSignature.getThrowsList().stream()
186+
.map(this::formatType)
187+
.collect(Collectors.joining(", ")));
188+
}
181189
}
182190

183191
private void formatValueSignature(ValueSignature valueSignature) {

semanticdb-java/src/main/protobuf/semanticdb.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ message MethodSignature {
6060
Scope type_parameters = 1;
6161
repeated Scope parameter_lists = 2;
6262
Type return_type = 3;
63+
repeated Type throws = 4;
6364
}
6465

6566
message TypeSignature {

semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbSignatures.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.lang.model.element.Element;
88
import javax.lang.model.type.*;
99
import java.util.List;
10+
import java.util.stream.Collectors;
1011

1112
import static com.sourcegraph.semanticdb_javac.SemanticdbTypeVisitor.UNRESOLVED_TYPE_REF;
1213

@@ -73,6 +74,10 @@ private Signature generateMethodSignature(Symbol.MethodSymbol sym) {
7374
builder.setReturnType(returnType);
7475
}
7576

77+
List<Semanticdb.Type> thrownTypes =
78+
sym.getThrownTypes().stream().map(this::generateType).collect(Collectors.toList());
79+
builder.addAllThrows(thrownTypes);
80+
7681
return Signature.newBuilder().setMethodSignature(builder).build();
7782
}
7883

tests/minimized/src/main/java/minimized/Methods.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private static String staticOverload(String value) {
1717
return value + "1";
1818
}
1919

20-
public static String app(int n, String m) {
20+
public static String app(int n, String m) throws RuntimeException, IndexOutOfBoundsException {
2121
Methods methods = new Methods();
2222
int a = staticOverload(n);
2323
String b = staticOverload(m);

tests/snapshots/src/main/generated/minimized/Methods.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ private static String staticOverload(String value) {
3535
// ^^^^^ reference local3
3636
}
3737

38-
public static String app(int n, String m) {
38+
public static String app(int n, String m) throws RuntimeException, IndexOutOfBoundsException {
3939
// ^^^^^^ reference java/lang/String#
40-
// ^^^ definition minimized/Methods#app(). public static String app(int n, String m)
40+
// ^^^ definition minimized/Methods#app(). public static String app(int n, String m) throws RuntimeException, IndexOutOfBoundsException
4141
// ^ definition local4 int n
4242
// ^^^^^^ reference java/lang/String#
4343
// ^ definition local5 String m
44+
// ^^^^^^^^^^^^^^^^ reference java/lang/RuntimeException#
45+
// ^^^^^^^^^^^^^^^^^^^^^^^^^ reference java/lang/IndexOutOfBoundsException#
4446
Methods methods = new Methods();
4547
// ^^^^^^^ reference minimized/Methods#
4648
// ^^^^^^^ definition local6 Methods methods

0 commit comments

Comments
 (0)