From 60f660f3cd42bacc49cbcf2e45cf580ba6cf84fd Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Tue, 29 Oct 2024 12:02:42 +0000 Subject: [PATCH] Fix cast tree --- .../scip_semanticdb/SignatureFormatter.java | 2 ++ .../semanticdb_javac/SemanticdbBuilders.java | 5 +++++ .../semanticdb_javac/SemanticdbTrees.java | 13 ++++++++----- .../main/java/minimized/AnnotationParameters.java | 2 +- .../main/java/minimized/AnnotationParameters.java | 8 ++++++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/scip-semanticdb/src/main/java/com/sourcegraph/scip_semanticdb/SignatureFormatter.java b/scip-semanticdb/src/main/java/com/sourcegraph/scip_semanticdb/SignatureFormatter.java index aec78d52..b4972416 100644 --- a/scip-semanticdb/src/main/java/com/sourcegraph/scip_semanticdb/SignatureFormatter.java +++ b/scip-semanticdb/src/main/java/com/sourcegraph/scip_semanticdb/SignatureFormatter.java @@ -470,6 +470,8 @@ private String formatTree(Tree tree) { + formatTree(tree.getAssignTree().getRhs()); } else if (tree.hasUnaryopTree()) { return formatUnaryOperation(tree.getUnaryopTree()); + } else if (tree.hasCastTree()) { + return "FIX ME"; } throw new IllegalArgumentException("tree was of unexpected type " + tree); diff --git a/semanticdb-java/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbBuilders.java b/semanticdb-java/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbBuilders.java index d22aec4b..024f9781 100644 --- a/semanticdb-java/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbBuilders.java +++ b/semanticdb-java/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbBuilders.java @@ -150,6 +150,11 @@ public static Semanticdb.Tree tree(Semanticdb.UnaryOperatorTree unaryOperatorTre return Semanticdb.Tree.newBuilder().setUnaryopTree(unaryOperatorTree).build(); } + public static Semanticdb.Tree tree(Semanticdb.CastTree castTree) { + return Semanticdb.Tree.newBuilder().setCastTree(castTree).build(); + } + + public static Semanticdb.UnaryOperatorTree unaryOpTree( Semanticdb.UnaryOperator operator, Semanticdb.Tree rhs) { return Semanticdb.UnaryOperatorTree.newBuilder().setOp(operator).setTree(rhs).build(); diff --git a/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTrees.java b/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTrees.java index 5511719d..2a150a00 100644 --- a/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTrees.java +++ b/semanticdb-javac/src/main/java/com/sourcegraph/semanticdb_javac/SemanticdbTrees.java @@ -96,10 +96,11 @@ public Semanticdb.AnnotationTree annotationBuilder(AnnotationTree annotation) { private TypeMirror getTreeType(Tree tree) { TreePath path = nodes.get(tree); - System.out.println("Path: " + path); - Element sym = trees.getElement(path); - System.out.println("SYM: " + sym); - return sym.asType(); + System.out.println("Path: " + path.getLeaf()); + // System.out.println("TM:" + trees.getTypeMirror(path)); + // Element sym = trees.getElement(path); + // System.out.println("SYM: " + sym); + return trees.getTypeMirror(path); } private Semanticdb.Tree annotationParameter(ExpressionTree expr) { @@ -164,14 +165,16 @@ private Semanticdb.Tree annotationParameter(ExpressionTree expr) { } else if (expr instanceof TypeCastTree) { TypeCastTree tree = (TypeCastTree) expr; System.out.println(typeVisitor.semanticdbType(getTreeType(tree.getType()))); + return tree(castTree(typeVisitor.semanticdbType(getTreeType(tree.getType())), annotationParameter(tree.getExpression()))); // tree.getType() - } + } else { throw new IllegalArgumentException( semanticdbUri + ": annotation parameter rhs was of unexpected tree node type " + expr.getClass() + "\n" + expr); + } } private Semanticdb.BinaryOperator semanticdbBinaryOperator(Tree.Kind kind) { diff --git a/tests/minimized/src/main/java/minimized/AnnotationParameters.java b/tests/minimized/src/main/java/minimized/AnnotationParameters.java index c4ec2229..aab18e84 100644 --- a/tests/minimized/src/main/java/minimized/AnnotationParameters.java +++ b/tests/minimized/src/main/java/minimized/AnnotationParameters.java @@ -27,5 +27,5 @@ interface Foo { Foo test4(); @Bar((double) -1) - double test(); + double testCast(); } diff --git a/tests/snapshots/src/main/generated/tests/minimized/src/main/java/minimized/AnnotationParameters.java b/tests/snapshots/src/main/generated/tests/minimized/src/main/java/minimized/AnnotationParameters.java index d2c068fa..efc0f49e 100644 --- a/tests/snapshots/src/main/generated/tests/minimized/src/main/java/minimized/AnnotationParameters.java +++ b/tests/snapshots/src/main/generated/tests/minimized/src/main/java/minimized/AnnotationParameters.java @@ -80,4 +80,12 @@ interface Foo { // display_name test4 // signature_documentation java @Nullable("what")\npublic abstract Foo test4() // kind AbstractMethod + +→@Bar((double) -1) +//^^^ reference semanticdb maven . . minimized/Bar# +→double testCast(); +// ^^^^^^^^ definition semanticdb maven . . minimized/Foo#testCast(). +// display_name testCast +// signature_documentation java @Bar(FIX ME)\npublic abstract double testCast() +// kind AbstractMethod }