Skip to content

Commit 5750340

Browse files
authored
Merge pull request #160 from sourcegraph/nsc/method-throws-formatter
2 parents 44e9993 + 6d6a27c commit 5750340

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
@@ -179,6 +179,14 @@ private void formatMethodSignature(MethodSignature methodSignature) {
179179
+ " "
180180
+ symInfo.getDisplayName())
181181
.collect(Collectors.joining(", ", "(", ")")));
182+
183+
if (!methodSignature.getThrowsList().isEmpty()) {
184+
printKeyword(" throws");
185+
s.append(
186+
methodSignature.getThrowsList().stream()
187+
.map(this::formatType)
188+
.collect(Collectors.joining(", ")));
189+
}
182190
}
183191

184192
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)