|
19 | 19 | import java.nio.file.Path; |
20 | 20 | import java.nio.file.Paths; |
21 | 21 | import java.security.NoSuchAlgorithmException; |
22 | | -import java.util.ArrayList; |
23 | | -import java.util.Iterator; |
24 | | -import java.util.List; |
25 | | -import java.util.Optional; |
| 22 | +import java.util.*; |
26 | 23 | import java.util.stream.Collectors; |
27 | 24 |
|
28 | 25 | import static com.sourcegraph.semanticdb_javac.SemanticdbTypeVisitor.ARRAY_SYMBOL; |
@@ -469,7 +466,9 @@ private Semanticdb.Tree.Builder semanticdbAnnotationParameter(JCTree.JCExpressio |
469 | 466 | break; |
470 | 467 | case CHAR: |
471 | 468 | constantBuilder.setCharConstant( |
472 | | - Semanticdb.CharConstant.newBuilder().setValue((Character) rhs.value).build()); |
| 469 | + Semanticdb.CharConstant.newBuilder() |
| 470 | + .setValue(Character.forDigit((Integer) rhs.value, 10)) |
| 471 | + .build()); |
473 | 472 | break; |
474 | 473 | case FLOAT: |
475 | 474 | constantBuilder.setFloatConstant( |
@@ -516,6 +515,13 @@ private Semanticdb.Tree.Builder semanticdbAnnotationParameter(JCTree.JCExpressio |
516 | 515 | Semanticdb.IdTree.newBuilder() |
517 | 516 | .setSymbol(globals.semanticdbSymbol(((JCTree.JCIdent) expr).sym, locals)) |
518 | 517 | .build()); |
| 518 | + } else if (expr instanceof JCTree.JCBinary) { |
| 519 | + Semanticdb.BinaryOperatorTree.Builder binOp = Semanticdb.BinaryOperatorTree.newBuilder(); |
| 520 | + JCTree.JCBinary binExpr = (JCTree.JCBinary) expr; |
| 521 | + binOp.setLhs(semanticdbAnnotationParameter(binExpr.lhs)); |
| 522 | + binOp.setOp(semanticdbBinaryOperator(expr.getKind())); |
| 523 | + binOp.setRhs(semanticdbAnnotationParameter(binExpr.rhs)); |
| 524 | + return Semanticdb.Tree.newBuilder().setBinopTree(binOp.build()); |
519 | 525 | } |
520 | 526 |
|
521 | 527 | throw new IllegalArgumentException( |
@@ -559,6 +565,52 @@ private Semanticdb.Access semanticdbAccess(Symbol sym) { |
559 | 565 | } |
560 | 566 | } |
561 | 567 |
|
| 568 | + private Semanticdb.BinaryOperator semanticdbBinaryOperator(Tree.Kind kind) { |
| 569 | + switch (kind) { |
| 570 | + case PLUS: |
| 571 | + return Semanticdb.BinaryOperator.PLUS; |
| 572 | + case MINUS: |
| 573 | + return Semanticdb.BinaryOperator.MINUS; |
| 574 | + case MULTIPLY: |
| 575 | + return Semanticdb.BinaryOperator.MULTIPLY; |
| 576 | + case DIVIDE: |
| 577 | + return Semanticdb.BinaryOperator.DIVIDE; |
| 578 | + case REMAINDER: |
| 579 | + return Semanticdb.BinaryOperator.REMAINDER; |
| 580 | + case LESS_THAN: |
| 581 | + return Semanticdb.BinaryOperator.LESS_THAN; |
| 582 | + case GREATER_THAN: |
| 583 | + return Semanticdb.BinaryOperator.GREATER_THAN; |
| 584 | + case LEFT_SHIFT: |
| 585 | + return Semanticdb.BinaryOperator.SHIFT_LEFT; |
| 586 | + case RIGHT_SHIFT: |
| 587 | + return Semanticdb.BinaryOperator.SHIFT_RIGHT; |
| 588 | + case UNSIGNED_RIGHT_SHIFT: |
| 589 | + return Semanticdb.BinaryOperator.SHIFT_RIGHT_UNSIGNED; |
| 590 | + case EQUAL_TO: |
| 591 | + return Semanticdb.BinaryOperator.EQUAL_TO; |
| 592 | + case NOT_EQUAL_TO: |
| 593 | + return Semanticdb.BinaryOperator.NOT_EQUAL_TO; |
| 594 | + case LESS_THAN_EQUAL: |
| 595 | + return Semanticdb.BinaryOperator.LESS_THAN_EQUAL; |
| 596 | + case GREATER_THAN_EQUAL: |
| 597 | + return Semanticdb.BinaryOperator.GREATER_THAN_EQUAL; |
| 598 | + case CONDITIONAL_AND: |
| 599 | + return Semanticdb.BinaryOperator.CONDITIONAL_AND; |
| 600 | + case CONDITIONAL_OR: |
| 601 | + return Semanticdb.BinaryOperator.CONDITIONAL_OR; |
| 602 | + case AND: |
| 603 | + return Semanticdb.BinaryOperator.AND; |
| 604 | + case OR: |
| 605 | + return Semanticdb.BinaryOperator.OR; |
| 606 | + case XOR: |
| 607 | + return Semanticdb.BinaryOperator.XOR; |
| 608 | + default: |
| 609 | + throw new IllegalStateException( |
| 610 | + semanticdbUri() + ": unexpected binary expression operator kind " + kind); |
| 611 | + } |
| 612 | + } |
| 613 | + |
562 | 614 | private String semanticdbUri() { |
563 | 615 | Path absolutePath = Paths.get(event.getSourceFile().toUri()); |
564 | 616 | Path relativePath = options.sourceroot.relativize(absolutePath); |
|
0 commit comments