-
Notifications
You must be signed in to change notification settings - Fork 8
Fix link reference #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix link reference #129
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -37,7 +37,15 @@ final class BuilderUtil { | |||||
| private static final Pattern XREF_LINK_RESOLVE_PATTERN = Pattern.compile("(?<class>\\w+)\\#(?<member>\\w+)(\\((?<param>.*)\\))?"); | ||||||
| public final static String[] LANGS = {"java"}; | ||||||
|
|
||||||
| static String populateUidValues(String text, LookupContext lookupContext) { | ||||||
| /** | ||||||
| * Replaces all the references the link in the linkContent with the UID | ||||||
| * | ||||||
| * @param text Text that potentially contains a link reference | ||||||
| * @param packageName MetaFileItem's packageName | ||||||
| * @param lookupContext Lookup Context | ||||||
| * @return Text with a link reference to the full qualified link | ||||||
| */ | ||||||
| static String populateUidValues(String text, String packageName, LookupContext lookupContext) { | ||||||
| if (StringUtils.isBlank(text)) { | ||||||
| return text; | ||||||
| } | ||||||
|
|
@@ -51,21 +59,29 @@ static String populateUidValues(String text, LookupContext lookupContext) { | |||||
| } | ||||||
|
|
||||||
| String linkContent = linkContentMatcher.group(); | ||||||
| String uid = resolveUidFromLinkContent(linkContent, lookupContext); | ||||||
| String uid = resolveUidFromLinkContent(linkContent, packageName, lookupContext); | ||||||
| String updatedLink = linkContentMatcher.replaceAll(uid); | ||||||
| text = StringUtils.replace(text, link, updatedLink); | ||||||
| } | ||||||
| return text; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * | ||||||
| * The linkContent could be in following format | ||||||
| * #memeber | ||||||
| * Class#member | ||||||
| * Class#method() | ||||||
| * Class#method(params) | ||||||
| * 1. #member | ||||||
| * 2. Class#member | ||||||
| * 3. Class#method() | ||||||
| * 4. Class#method(params) | ||||||
| * 5. Package.Class# +{Any combination of above} | ||||||
| * All Possibilities listed: https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#link | ||||||
| * | ||||||
| * @param linkContent Text of the link | ||||||
| * @param packageName MetaFileItem's packageName | ||||||
| * @param lookupContext LookupContext | ||||||
| * @return Fully qualified link url | ||||||
| */ | ||||||
| static String resolveUidFromLinkContent(String linkContent, LookupContext lookupContext) { | ||||||
| static String resolveUidFromLinkContent(String linkContent, String packageName, LookupContext lookupContext) { | ||||||
| if (StringUtils.isBlank(linkContent)) { | ||||||
| return ""; | ||||||
| } | ||||||
|
|
@@ -74,19 +90,42 @@ static String resolveUidFromLinkContent(String linkContent, LookupContext lookup | |||||
|
|
||||||
| // complete class name for class internal link | ||||||
| if (linkContent.startsWith("#")) { | ||||||
| // Can't use packageName because it is missing the ClassName | ||||||
| String firstKey = lookupContext.getOwnerUid(); | ||||||
| linkContent = firstKey + linkContent; | ||||||
| } | ||||||
|
|
||||||
| // fuzzy resolve, target for items from project external references | ||||||
| String fuzzyResolvedUid = resolveUidFromReference(linkContent, lookupContext); | ||||||
|
|
||||||
| // exact resolve in lookupContext | ||||||
| linkContent = linkContent.replace("#", "."); | ||||||
| String exactResolveUid = resolveUidByLookup(linkContent, lookupContext); | ||||||
| String qualifiedLink = getFullyQualifiedLinkUrl(linkContent, packageName); | ||||||
|
|
||||||
| // First, prefer references inside local package | ||||||
| String exactResolveUid = resolveUidByLookup(qualifiedLink, lookupContext); | ||||||
| if (exactResolveUid.isEmpty()) { | ||||||
| // Resolve with original linkContent | ||||||
| exactResolveUid = resolveUidByLookup(linkContent, lookupContext); | ||||||
| } | ||||||
| // Resolve with fuzzyResolve / external references | ||||||
| return exactResolveUid.isEmpty() ? fuzzyResolvedUid : exactResolveUid; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Logic to ensure that resulting link is in the format Package.Class.Method(Params...) | ||||||
| * | ||||||
| * @param linkContent String of the Class#Method | ||||||
| * @param packageName Package Name that should go in front of the link | ||||||
| * @return Fully qualified link url | ||||||
| */ | ||||||
| private static String getFullyQualifiedLinkUrl(String linkContent, String packageName) { | ||||||
| // If packageName does not exist/error'd or is already at the beginning of the link | ||||||
| if (packageName == null || linkContent.indexOf(packageName) == 0) { | ||||||
| return linkContent; | ||||||
| } | ||||||
| return String.format("%s.%s", packageName, linkContent); | ||||||
| } | ||||||
|
|
||||||
| static List<String> splitUidWithGenericsIntoClassNames(String uid) { | ||||||
| uid = RegExUtils.removeAll(uid, "[>]+$"); | ||||||
| return Arrays.asList(StringUtils.split(uid, "<")); | ||||||
|
|
@@ -120,27 +159,43 @@ else if (uid != "") | |||||
| return specList; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Populate the links for references based on a UID. Looker generates mappings for local context | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * (file specific) and global context (all the UID references). Searching is done first in the | ||||||
| * local context and then in the global context if local context is not found. | ||||||
| * | ||||||
| * ex. {@link Lookup } would search all the references to find which Lookup file to use | ||||||
| * It would parse the text to search ("Lookup") | ||||||
| * | ||||||
| * Since packages (v1 and v1beta) may contain the same generated java file names, there may be some | ||||||
| * conflicts between which link it should be. | ||||||
|
Comment on lines
+170
to
+171
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add why Javac doesn't have the problem of ambiguity but this tool via javadoc has trouble finding the exact class? |
||||||
| * | ||||||
| * The Looker#consumer() function guarantees that the UID (+ other combinations) will be put into the LookupContext. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is Looker? |
||||||
| * As long as the link that we extract contains Package#Method, it will match in either local or global context | ||||||
| * | ||||||
| * @param packageMetadataFiles Package specific metadata files | ||||||
| * @param classMetadataFiles Class specific metadata files | ||||||
| */ | ||||||
| static void populateUidValues(List<MetadataFile> packageMetadataFiles, List<MetadataFile> classMetadataFiles) { | ||||||
| Lookup lookup = new Lookup(packageMetadataFiles, classMetadataFiles); | ||||||
|
|
||||||
| classMetadataFiles.forEach(classMetadataFile -> { | ||||||
| LookupContext lookupContext = lookup.buildContext(classMetadataFile); | ||||||
|
|
||||||
| for (MetadataFileItem item : classMetadataFile.getItems()) { | ||||||
| String packageName = item.getPackageName(); | ||||||
| item.setSummary(YamlUtil.cleanupHtml( | ||||||
| populateUidValues(item.getSummary(), lookupContext) | ||||||
| populateUidValues(item.getSummary(), packageName, lookupContext) | ||||||
| )); | ||||||
|
|
||||||
| Optional.ofNullable(item.getSyntax()).ifPresent(syntax -> { | ||||||
| Optional.ofNullable(syntax.getParameters()).ifPresent( | ||||||
| methodParams -> methodParams.forEach( | ||||||
| param -> { | ||||||
| param.setDescription(populateUidValues(param.getDescription(), lookupContext)); | ||||||
| }) | ||||||
| param -> param.setDescription(populateUidValues(param.getDescription(), packageName, lookupContext))) | ||||||
| ); | ||||||
| Optional.ofNullable(syntax.getReturnValue()).ifPresent(returnValue -> | ||||||
| returnValue.setReturnDescription( | ||||||
| populateUidValues(syntax.getReturnValue().getReturnDescription(), lookupContext) | ||||||
| populateUidValues(syntax.getReturnValue().getReturnDescription(), packageName, lookupContext) | ||||||
| ) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ items: | |
| fullName: "com.microsoft.samples.google.SpeechSettings" | ||
| type: "Class" | ||
| package: "com.microsoft.samples.google" | ||
| summary: "Settings class to configure an instance of <xref uid=\"com.microsoft.samples.google.v1p1alpha.SpeechClient\" data-throw-if-not-resolved=\"false\">SpeechClient</xref>.\n\n <p>The default instance has everything set to sensible defaults:\n\n <ul>\n <li>The default service address (speech.googleapis.com) and default port (443) are used.\n <li>Credentials are acquired automatically through Application Default Credentials.\n <li>Retries are configured for idempotent methods but not for non-idempotent methods.\n </ul>\n\n <p>The builder of this class is recursive, so contained classes are themselves builders. When\n build() is called, the tree of builders is called to create the complete settings object.\n\n <p>For example, to set the total timeout of recognize to 30 seconds:\n\n <pre class=\"prettyprint lang-java\"><code>\n SpeechSettings.Builder speechSettingsBuilder = SpeechSettings.newBuilder();\n speechSettingsBuilder\n .recognizeSettings()\n .setRetrySettings(\n speechSettingsBuilder\n .recognizeSettings()\n .getRetrySettings()\n .toBuilder()\n .setTotalTimeout(Duration.ofSeconds(30))\n .build());\n SpeechSettings speechSettings = speechSettingsBuilder.build();\n </code></pre>" | ||
| summary: "Settings class to configure an instance of <xref uid=\"com.microsoft.samples.google.SpeechClient\" data-throw-if-not-resolved=\"false\">SpeechClient</xref>.\n\n <p>The default instance has everything set to sensible defaults:\n\n <ul>\n <li>The default service address (speech.googleapis.com) and default port (443) are used.\n <li>Credentials are acquired automatically through Application Default Credentials.\n <li>Retries are configured for idempotent methods but not for non-idempotent methods.\n </ul>\n\n <p>The builder of this class is recursive, so contained classes are themselves builders. When\n build() is called, the tree of builders is called to create the complete settings object.\n\n <p>For example, to set the total timeout of recognize to 30 seconds:\n\n <pre class=\"prettyprint lang-java\"><code>\n SpeechSettings.Builder speechSettingsBuilder = SpeechSettings.newBuilder();\n speechSettingsBuilder\n .recognizeSettings()\n .setRetrySettings(\n speechSettingsBuilder\n .recognizeSettings()\n .getRetrySettings()\n .toBuilder()\n .setTotalTimeout(Duration.ofSeconds(30))\n .build());\n SpeechSettings speechSettings = speechSettingsBuilder.build();\n </code></pre>" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| syntax: | ||
| content: "public class SpeechSettings extends ClientSettings<SpeechSettings>" | ||
| inheritance: | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's possible not to add the additional parameter and leveraging
lookupContext? For me, right now, it seems that the bug comes from lookupContext. I see the variable holds the fully-qualified class name for symbols.