From 31275209ebedc4a38d344a41317219d1274bb854 Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Tue, 24 Oct 2023 21:12:43 +0300 Subject: [PATCH] @links to Java methods annotated with @JsProperty do not resolve correctly in Typescript (#90) Fix #87 (cherry picked from commit 710aed239b039d6ad160b93df50f79f005dbd8b5) --- .../tsdefs/doclet/TsDocTreeVisitor.java | 12 ++++++--- .../tsdocs/doclet/links/methods/MyClass.java | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/links/methods/MyClass.java diff --git a/jsinterop-ts-defs-doclet/src/main/java/com/vertispan/tsdefs/doclet/TsDocTreeVisitor.java b/jsinterop-ts-defs-doclet/src/main/java/com/vertispan/tsdefs/doclet/TsDocTreeVisitor.java index de8c21b..34757ea 100644 --- a/jsinterop-ts-defs-doclet/src/main/java/com/vertispan/tsdefs/doclet/TsDocTreeVisitor.java +++ b/jsinterop-ts-defs-doclet/src/main/java/com/vertispan/tsdefs/doclet/TsDocTreeVisitor.java @@ -21,6 +21,7 @@ import com.sun.source.util.DocTreePath; import com.sun.source.util.DocTrees; import com.sun.source.util.SimpleDocTreeVisitor; +import com.vertispan.tsdefs.impl.Formatting; import com.vertispan.tsdefs.impl.HasProcessorEnv; import com.vertispan.tsdefs.impl.builders.TsElement; import java.util.Optional; @@ -67,7 +68,12 @@ public String visitReference(ReferenceTree node, Element element) { String refNamespace = refTsElement.getNamespace(); String parentNamespace = parentTsElement.getNamespace(); - String name = refTsElement.getName(); + boolean isSetterOrGetter = refTsElement.isSetter() || refTsElement.isGetter(); + + String name = + isSetterOrGetter + ? Formatting.nonGetSetName(refTsElement.getName()) + : refTsElement.getName(); String parentName = parentTsElement.getName(); if (refNamespace.equals(parentNamespace)) { String fullName = refNamespace + "." + parentName + "." + name; @@ -127,7 +133,7 @@ public String visitDocComment(DocCommentTree node, Element element) { node.getBlockTags().stream() .map(tag -> " " + tag.accept(this, element)) .collect(Collectors.joining("\n")); - return body + "\n" + tags; + return " " + body + "\n" + tags; } @Override @@ -145,6 +151,6 @@ public String visitLiteral(LiteralTree node, Element element) { @Override public String visitText(TextTree node, Element element) { - return " " + node.getBody(); + return "" + node.getBody(); } } diff --git a/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/links/methods/MyClass.java b/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/links/methods/MyClass.java new file mode 100644 index 0000000..e07939f --- /dev/null +++ b/jsinterop-ts-defs-doclet/src/test/java/com/vertispan/tsdefs/tests/tsdocs/doclet/links/methods/MyClass.java @@ -0,0 +1,26 @@ +/* + * Copyright © 2023 Vertispan + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.vertispan.tsdefs.tests.tsdocs.doclet.links.methods; + +import jsinterop.annotations.JsProperty; + +/** The entire point of this class is to let you use {@link #getSomethingImportant()}. */ +public class MyClass { + @JsProperty + public String getSomethingImportant() { + return null; + } +}