(
doc: spec.Documentable,
apiLoc: ApiLocation,
unionHint?: {
returnsUnion?: spec.TypeReference;
},
)
| 2842 | |
| 2843 | // eslint-disable-next-line complexity |
| 2844 | private addJavaDocs( |
| 2845 | doc: spec.Documentable, |
| 2846 | apiLoc: ApiLocation, |
| 2847 | unionHint?: { |
| 2848 | returnsUnion?: spec.TypeReference; |
| 2849 | }, |
| 2850 | ) { |
| 2851 | const returnsUnion = |
| 2852 | unionHint?.returnsUnion && containsUnionType(unionHint.returnsUnion) |
| 2853 | ? this.renderTypeReference(unionHint.returnsUnion) |
| 2854 | : undefined; |
| 2855 | |
| 2856 | if ( |
| 2857 | !returnsUnion && |
| 2858 | Object.keys(doc.docs ?? {}).length === 0 && |
| 2859 | !((doc as spec.Method).parameters ?? []).some( |
| 2860 | (p) => Object.keys(p.docs ?? {}).length !== 0, |
| 2861 | ) |
| 2862 | ) { |
| 2863 | return; |
| 2864 | } |
| 2865 | |
| 2866 | const docs = (doc.docs = doc.docs ?? {}); |
| 2867 | |
| 2868 | const paras = []; |
| 2869 | |
| 2870 | if (docs.summary) { |
| 2871 | paras.push(stripNewLines(myMarkDownToJavaDoc(renderSummary(docs)))); |
| 2872 | } |
| 2873 | |
| 2874 | if (docs.remarks) { |
| 2875 | paras.push( |
| 2876 | myMarkDownToJavaDoc( |
| 2877 | this.convertSamplesInMarkdown(docs.remarks, apiLoc), |
| 2878 | ).trimRight(), |
| 2879 | ); |
| 2880 | } |
| 2881 | |
| 2882 | if (returnsUnion) { |
| 2883 | paras.push(`Returns union: ${returnsUnion}`); |
| 2884 | } |
| 2885 | |
| 2886 | if (docs.default) { |
| 2887 | paras.push(`Default: ${docs.default}`); // NOTE: there is no annotation in JavaDoc for this |
| 2888 | } |
| 2889 | |
| 2890 | if (docs.example) { |
| 2891 | paras.push('Example:'); |
| 2892 | |
| 2893 | const convertedExample = this.convertExample(docs.example, apiLoc); |
| 2894 | |
| 2895 | // We used to use the slightly nicer `<pre>{@code ...}</pre>`, which doesn't |
| 2896 | // require (and therefore also doesn't allow) escaping special characters. |
| 2897 | // |
| 2898 | // However, code samples may contain block quotes of their own ('*/') that |
| 2899 | // would terminate the block comment from the PoV of the Java tokenizer, and |
| 2900 | // since `{@code ... }` doesn't allow any escaping, there's also no way to encode |
| 2901 | // '*/' in a way that would (a) hide it from the tokenizer and (b) give '*/' back |
no test coverage detected