Skip to content

Commit

Permalink
Fix cast tree
Browse files Browse the repository at this point in the history
  • Loading branch information
antonsviridov-src committed Oct 29, 2024
1 parent 34e2f61 commit 60f660f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ interface Foo {
Foo test4();

@Bar((double) -1)
double test();
double testCast();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 60f660f

Please sign in to comment.