This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 195649
Collapse All | Expand All

(-)a/java.editor/nbproject/project.xml (-1 / +1 lines)
Lines 236-242 Link Here
236
                    <compile-dependency/>
236
                    <compile-dependency/>
237
                    <run-dependency>
237
                    <run-dependency>
238
                        <release-version>1</release-version>
238
                        <release-version>1</release-version>
239
                        <specification-version>1.15</specification-version>
239
                        <specification-version>1.19</specification-version>
240
                    </run-dependency>
240
                    </run-dependency>
241
                </dependency>
241
                </dependency>
242
                <dependency>
242
                <dependency>
(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionDoc.java (+5 lines)
Lines 46-51 Link Here
46
46
47
import java.net.URL;
47
import java.net.URL;
48
import java.util.concurrent.Callable;
48
import java.util.concurrent.Callable;
49
import java.util.concurrent.Future;
49
import javax.lang.model.element.Element;
50
import javax.lang.model.element.Element;
50
import javax.swing.Action;
51
import javax.swing.Action;
51
import org.netbeans.api.java.source.CompilationController;
52
import org.netbeans.api.java.source.CompilationController;
Lines 77-82 Link Here
77
        return elementJavadoc.getText();
78
        return elementJavadoc.getText();
78
    }
79
    }
79
80
81
    public Future<String> getFutureText() {
82
        return elementJavadoc.getTextAsync();
83
    }
84
80
    public Action getGotoSourceAction() {
85
    public Action getGotoSourceAction() {
81
        return elementJavadoc.getGotoSourceAction();
86
        return elementJavadoc.getGotoSourceAction();
82
    }
87
    }
(-)a/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionProvider.java (-1 / +13 lines)
Lines 51-56 Link Here
51
import java.util.*;
51
import java.util.*;
52
import java.util.concurrent.Callable;
52
import java.util.concurrent.Callable;
53
import java.util.concurrent.Future;
53
import java.util.concurrent.Future;
54
import java.util.concurrent.TimeUnit;
55
import java.util.concurrent.TimeoutException;
54
import java.util.logging.Logger;
56
import java.util.logging.Logger;
55
import java.util.logging.Level;
57
import java.util.logging.Level;
56
import javax.lang.model.SourceVersion;
58
import javax.lang.model.SourceVersion;
Lines 303-310 Link Here
303
                            if (toolTip != null && toolTip.hasData())
305
                            if (toolTip != null && toolTip.hasData())
304
                                resultSet.setToolTip(toolTip);
306
                                resultSet.setToolTip(toolTip);
305
                        } else if (queryType == DOCUMENTATION_QUERY_TYPE) {
307
                        } else if (queryType == DOCUMENTATION_QUERY_TYPE) {
306
                            if (documentation != null)
308
                            if (documentation instanceof JavaCompletionDoc) {
309
                                while (!isTaskCancelled()) {
310
                                    try {
311
                                        ((JavaCompletionDoc)documentation).getFutureText().get(250, TimeUnit.MILLISECONDS);
312
                                        resultSet.setDocumentation(documentation);
313
                                        break;
314
                                    } catch (TimeoutException timeOut) {/*retry*/}
315
                                }
316
                                
317
                            } else if (documentation != null) {
307
                                resultSet.setDocumentation(documentation);
318
                                resultSet.setDocumentation(documentation);
319
                            }
308
                        }
320
                        }
309
                        if (anchorOffset > -1)
321
                        if (anchorOffset > -1)
310
                            resultSet.setAnchorOffset(anchorOffset);
322
                            resultSet.setAnchorOffset(anchorOffset);
(-)a/java.sourceui/apichanges.xml (-1 / +14 lines)
Lines 109-115 Link Here
109
109
110
    <changes>
110
    <changes>
111
111
112
112
        <change id="ElementJavadoc-getTextAsync">
113
            <api name="general"/>
114
            <summary>Added asynchronous version of getText method into ElementJavadoc </summary>
115
            <version major="1" minor="19"/>
116
            <date day="21" month="2" year="2011"/>
117
            <author login="tzezula"/>
118
            <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
119
            <description>
120
                Added asynchronous version of <code>getText</code> into <code>ElementJavadoc</code>.
121
                The <code>getTextAsync</code> returns a <code>Future</code> which blocks until the javadoc is downloaded.
122
            </description>
123
            <class package="org.netbeans.api.java.source.ui" name="ElementJavadoc"/>
124
            <issue number="194969"/>
125
        </change>
113
        <change id="ElementJavadoc-create">
126
        <change id="ElementJavadoc-create">
114
            <api name="general"/>
127
            <api name="general"/>
115
            <summary>Adding cancelable version of ElementJavadoc.create</summary>
128
            <summary>Adding cancelable version of ElementJavadoc.create</summary>
(-)a/java.sourceui/nbproject/project.properties (-1 / +1 lines)
Lines 2-5 Link Here
2
javac.compilerargs=-Xlint -Xlint:-serial
2
javac.compilerargs=-Xlint -Xlint:-serial
3
javac.source=1.6
3
javac.source=1.6
4
javadoc.arch=${basedir}/arch.xml
4
javadoc.arch=${basedir}/arch.xml
5
spec.version.base=1.18.0
5
spec.version.base=1.19.0
(-)a/java.sourceui/src/org/netbeans/api/java/source/ui/Bundle.properties (+1 lines)
Lines 54-59 Link Here
54
array_length_field_javadoc=Length of array.
54
array_length_field_javadoc=Length of array.
55
class_constant_javadoc=java.lang.Class constant.
55
class_constant_javadoc=java.lang.Class constant.
56
javadoc_content_not_found=<font color=\"#7c0000\">Javadoc not found.</font> Either Javadoc documentation for this item does not exist or you have not added specified Javadoc in the Java Platform Manager or the Library Manager.
56
javadoc_content_not_found=<font color=\"#7c0000\">Javadoc not found.</font> Either Javadoc documentation for this item does not exist or you have not added specified Javadoc in the Java Platform Manager or the Library Manager.
57
LBL_HTTPJavadocDownload=Downloading HTTP Javadoc
57
58
58
LBL_CancelAction=Cancel {0}
59
LBL_CancelAction=Cancel {0}
59
MSG_WaitScan=Please wait, classpath scanning in progress...
60
MSG_WaitScan=Please wait, classpath scanning in progress...
(-)a/java.sourceui/src/org/netbeans/api/java/source/ui/ElementJavadoc.java (-102 / +227 lines)
Lines 30-41 Link Here
30
 */
30
 */
31
package org.netbeans.api.java.source.ui;
31
package org.netbeans.api.java.source.ui;
32
32
33
import com.sun.source.util.Trees;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionEvent;
34
import java.io.IOException;
35
import java.io.IOException;
35
import java.lang.reflect.Modifier;
36
import java.lang.reflect.Modifier;
36
import java.net.URI;
37
import java.net.URI;
37
import java.net.URL;
38
import java.net.URL;
38
import java.util.*;
39
import java.util.*;
40
import java.util.concurrent.ExecutionException;
41
import java.util.concurrent.Future;
42
import java.util.concurrent.TimeUnit;
43
import java.util.concurrent.TimeoutException;
39
import javax.lang.model.element.Element;
44
import javax.lang.model.element.Element;
40
import javax.lang.model.element.ElementKind;
45
import javax.lang.model.element.ElementKind;
41
import javax.lang.model.element.ExecutableElement;
46
import javax.lang.model.element.ExecutableElement;
Lines 50-59 Link Here
50
import javax.swing.Action;
55
import javax.swing.Action;
51
import com.sun.javadoc.*;
56
import com.sun.javadoc.*;
52
import com.sun.javadoc.AnnotationDesc.ElementValuePair;
57
import com.sun.javadoc.AnnotationDesc.ElementValuePair;
53
import com.sun.source.util.Trees;
54
import java.net.MalformedURLException;
58
import java.net.MalformedURLException;
55
import java.util.ArrayList;
59
import java.util.ArrayList;
56
import java.util.concurrent.Callable;
60
import java.util.concurrent.Callable;
61
import java.util.concurrent.FutureTask;
57
import org.netbeans.api.java.source.ClasspathInfo;
62
import org.netbeans.api.java.source.ClasspathInfo;
58
import org.netbeans.api.java.source.CompilationController;
63
import org.netbeans.api.java.source.CompilationController;
59
import org.netbeans.api.java.source.CompilationInfo;
64
import org.netbeans.api.java.source.CompilationInfo;
Lines 63-73 Link Here
63
import org.netbeans.api.java.source.JavaSource.Phase;
68
import org.netbeans.api.java.source.JavaSource.Phase;
64
import org.netbeans.api.java.source.SourceUtils;
69
import org.netbeans.api.java.source.SourceUtils;
65
import org.netbeans.api.java.source.Task;
70
import org.netbeans.api.java.source.Task;
71
import org.netbeans.api.progress.ProgressHandle;
72
import org.netbeans.api.progress.ProgressHandleFactory;
73
import org.netbeans.modules.java.preprocessorbridge.api.JavaSourceUtil;
66
import org.netbeans.modules.java.source.JavadocHelper;
74
import org.netbeans.modules.java.source.JavadocHelper;
75
import org.netbeans.modules.java.source.usages.Pair;
67
import org.openide.filesystems.FileObject;
76
import org.openide.filesystems.FileObject;
68
import org.openide.filesystems.FileStateInvalidException;
77
import org.openide.filesystems.FileStateInvalidException;
69
import org.openide.util.Exceptions;
78
import org.openide.util.Exceptions;
70
import org.openide.util.NbBundle;
79
import org.openide.util.NbBundle;
80
import org.openide.util.RequestProcessor;
71
import org.openide.xml.XMLUtil;
81
import org.openide.xml.XMLUtil;
72
82
73
/** Utility class for viewing Javadoc comments as HTML.
83
/** Utility class for viewing Javadoc comments as HTML.
Lines 78-83 Link Here
78
    
88
    
79
    private static final String API = "/api";                                   //NOI18N
89
    private static final String API = "/api";                                   //NOI18N
80
    private static final Set<String> LANGS;
90
    private static final Set<String> LANGS;
91
92
    private static final RequestProcessor RP = new RequestProcessor(ElementJavadoc.class);
81
    
93
    
82
    static {
94
    static {
83
        Locale[] availableLocales = Locale.getAvailableLocales();
95
        Locale[] availableLocales = Locale.getAvailableLocales();
Lines 92-101 Link Here
92
    }
104
    }
93
105
94
    private ClasspathInfo cpInfo;
106
    private ClasspathInfo cpInfo;
95
    private ElementUtilities eu;
96
    private Trees trees;
97
    //private Doc doc;
107
    //private Doc doc;
98
    private String content = null;
108
    private Future<String> content;
99
    private Hashtable<String, ElementHandle<? extends Element>> links = new Hashtable<String, ElementHandle<? extends Element>>();
109
    private Hashtable<String, ElementHandle<? extends Element>> links = new Hashtable<String, ElementHandle<? extends Element>>();
100
    private int linkCounter = 0;
110
    private int linkCounter = 0;
101
    private URL docURL = null;
111
    private URL docURL = null;
Lines 143-148 Link Here
143
     * @return HTML text of the javadoc
153
     * @return HTML text of the javadoc
144
     */
154
     */
145
    public String getText() {
155
    public String getText() {
156
        try {
157
            return content.get();
158
        } catch (InterruptedException ex) {
159
            return null;
160
        } catch (ExecutionException ex) {
161
            return null;
162
        }
163
    }
164
165
    /** Gets the javadoc comment formated as HTML.
166
     * @return {@link Future} of HTML text of the javadoc
167
     * @since 1.19
168
     */
169
    public Future<String> getTextAsync() {
146
        return content;
170
        return content;
147
    }
171
    }
148
172
Lines 246-255 Link Here
246
    }
270
    }
247
    
271
    
248
    private ElementJavadoc(CompilationInfo compilationInfo, Element element, URL url, final Callable<Boolean> cancel) {
272
    private ElementJavadoc(CompilationInfo compilationInfo, Element element, URL url, final Callable<Boolean> cancel) {
249
        this.trees = compilationInfo.getTrees();
273
        Pair<Trees,ElementUtilities> context = Pair.of(compilationInfo.getTrees(), compilationInfo.getElementUtilities());
250
        this.eu = compilationInfo.getElementUtilities();
251
        this.cpInfo = compilationInfo.getClasspathInfo();
274
        this.cpInfo = compilationInfo.getClasspathInfo();
252
        Doc doc = eu.javaDocFor(element);
275
        Doc doc = context.second.javaDocFor(element);
253
        boolean localized = false;
276
        boolean localized = false;
254
        StringBuilder content = new StringBuilder();
277
        StringBuilder content = new StringBuilder();
255
        JavadocHelper.TextStream page = null;
278
        JavadocHelper.TextStream page = null;
Lines 282-288 Link Here
282
                }
305
                }
283
            }
306
            }
284
        }
307
        }
285
        this.content = content.append(prepareContent(doc, localized, page, cancel)).toString();
308
        try {
309
            //Optimisitic no http
310
            this.content = prepareContent(content, doc,localized, page, cancel, true, context);
311
        } catch (RemoteJavadocException re) {
312
            final FileObject fo = compilationInfo.getFileObject();
313
            final ElementHandle<? extends Element> handle = ElementHandle.create(element);
314
            final StringBuilder contentFin = content;
315
            final boolean localizedFin = localized;
316
            this.content = new FutureTask<String>(new Callable<String>(){
317
                @Override
318
                public String call() throws Exception {
319
                    final JavaSourceUtil.Handle ch = JavaSourceUtil.createControllerHandle(fo, null);
320
                    final CompilationController c = (CompilationController) ch.getCompilationController();
321
                    c.toPhase(Phase.RESOLVED);
322
                    final Element element = handle.resolve(c);
323
                    Pair<Trees,ElementUtilities> context = Pair.of(c.getTrees(), c.getElementUtilities());
324
                    Doc doc = context.second.javaDocFor(element);
325
                    JavadocHelper.TextStream page = JavadocHelper.getJavadoc(element, cancel);
326
                    return prepareContent(contentFin, doc,localizedFin, page, cancel, false, context).get();
327
                }
328
            });
329
            RP.post(new Runnable() {
330
                @Override
331
                public void run() {
332
                    final ProgressHandle progress = ProgressHandleFactory.createHandle(NbBundle.getMessage(ElementJavadoc.class, "LBL_HTTPJavadocDownload"));
333
                    progress.start();
334
                    try {
335
                        ((Runnable)ElementJavadoc.this.content).run();
336
                    } finally {
337
                        progress.finish();
338
                    }
339
                }
340
            });
341
        }
286
    }
342
    }
287
    
343
    
288
    private ElementJavadoc(URL url) {
344
    private ElementJavadoc(URL url) {
Lines 329-353 Link Here
329
           
385
           
330
    /**
386
    /**
331
     * Creates javadoc content
387
     * Creates javadoc content
388
     * @header header of the generated HTML
332
     * @param eu element utilities to find out elements
389
     * @param eu element utilities to find out elements
333
     * @param doc javac javadoc model
390
     * @param doc javac javadoc model
334
     * @param useJavadoc preffer javadoc to sources
391
     * @param useJavadoc preffer javadoc to sources
335
     * @return Javadoc content
392
     * @return Javadoc content
336
     */
393
     */
337
    private StringBuilder prepareContent(Doc doc, final boolean useJavadoc, JavadocHelper.TextStream page, Callable<Boolean> cancel) {
394
    private Future<String> prepareContent(
338
        StringBuilder sb = new StringBuilder();
395
            final StringBuilder header,
396
            final Doc doc,
397
            final boolean useJavadoc,
398
            final JavadocHelper.TextStream page,
399
            final Callable<Boolean> cancel,
400
            final boolean sync, Pair<Trees,ElementUtilities> ctx) throws RemoteJavadocException {
401
402
403
        final StringBuilder sb = new StringBuilder(header);
339
        if (doc != null) {
404
        if (doc != null) {
340
            if (doc instanceof ProgramElementDoc) {
405
            if (doc instanceof ProgramElementDoc) {
341
                sb.append(getContainingClassOrPackageHeader((ProgramElementDoc)doc));
406
                sb.append(getContainingClassOrPackageHeader((ProgramElementDoc)doc, ctx));
342
            }
407
            }
343
            if (doc.isMethod() || doc.isConstructor() || doc.isAnnotationTypeElement()) {
408
            if (doc.isMethod() || doc.isConstructor() || doc.isAnnotationTypeElement()) {
344
                sb.append(getMethodHeader((ExecutableMemberDoc)doc));
409
                sb.append(getMethodHeader((ExecutableMemberDoc)doc, ctx));
345
            } else if (doc.isField() || doc.isEnumConstant()) {
410
            } else if (doc.isField() || doc.isEnumConstant()) {
346
                sb.append(getFieldHeader((FieldDoc)doc));
411
                sb.append(getFieldHeader((FieldDoc)doc, ctx));
347
            } else if (doc.isClass() || doc.isInterface() || doc.isAnnotationType()) {
412
            } else if (doc.isClass() || doc.isInterface() || doc.isAnnotationType()) {
348
                sb.append(getClassHeader((ClassDoc)doc));
413
                sb.append(getClassHeader((ClassDoc)doc, ctx));
349
            } else if (doc instanceof PackageDoc) {
414
            } else if (doc instanceof PackageDoc) {
350
                sb.append(getPackageHeader((PackageDoc)doc));
415
                sb.append(getPackageHeader((PackageDoc)doc, ctx));
351
            }
416
            }
352
            sb.append("<p>"); //NOI18N
417
            sb.append("<p>"); //NOI18N
353
            if (!useJavadoc) {
418
            if (!useJavadoc) {
Lines 454-467 Link Here
454
                            inheritedReturnTags != null && inheritedReturnTags.isEmpty() ||
519
                            inheritedReturnTags != null && inheritedReturnTags.isEmpty() ||
455
                            paramPos != null && !paramPos.isEmpty() ||
520
                            paramPos != null && !paramPos.isEmpty() ||
456
                            throwsTypes != null && !throwsTypes.isEmpty()) {
521
                            throwsTypes != null && !throwsTypes.isEmpty()) {
457
                        String s = inheritedDocFor(mdoc, mdoc.containingClass(), inheritedTags, inheritedReturnTags,
522
                            String s = inheritedDocFor(mdoc, mdoc.containingClass(), inheritedTags, inheritedReturnTags,
458
                                paramPos, inheritedParamTags, inheritedParamInlineTags,
523
                            paramPos, inheritedParamTags, inheritedParamInlineTags,
459
                                throwsTypes, inheritedThrowsTags, inheritedThrowsInlineTags, cancel);
524
                            throwsTypes, inheritedThrowsTags, inheritedThrowsInlineTags, cancel, sync, ctx);
460
                        if (s != null) {
525
                            if (s != null) {
461
                            sb.append(s);
526
                                sb.append(s);
462
                            sb.append("</p>"); //NOI18N
527
                                sb.append("</p>"); //NOI18N
463
                            return sb;
528
                                return new Now(sb.toString());
464
                        }
529
                            }
465
                    }
530
                    }
466
                    if (inheritedTags != null && !inheritedTags.isEmpty()) {
531
                    if (inheritedTags != null && !inheritedTags.isEmpty()) {
467
                        if (inlineTags.length == 0) {
532
                        if (inlineTags.length == 0) {
Lines 542-583 Link Here
542
                        }
607
                        }
543
                    }
608
                    }
544
                    if (inlineTags.length > 0 || doc.tags().length > 0) {
609
                    if (inlineTags.length > 0 || doc.tags().length > 0) {
545
                        sb.append(getDeprecatedTag(doc));
610
                        sb.append(getDeprecatedTag(doc, ctx));
546
                        sb.append(inlineTags(doc, inlineTags));
611
                        sb.append(inlineTags(doc, inlineTags, ctx));
547
                        sb.append("</p><p>"); //NOI18N
612
                        sb.append("</p><p>"); //NOI18N
548
                        sb.append(getMethodTags(mdoc, returnTags, paramTags,
613
                        sb.append(getMethodTags(mdoc, returnTags, paramTags,
549
                                throwsTags, throwsInlineTags));
614
                                throwsTags, throwsInlineTags, ctx));
550
                        sb.append("</p>"); //NOI18N
615
                        sb.append("</p>"); //NOI18N
551
                        return sb;
616
                        return new Now(sb.toString());
552
                    }
617
                    }
553
                } else {
618
                } else {
554
                    if (inlineTags.length > 0 || doc.tags().length > 0) {
619
                    if (inlineTags.length > 0 || doc.tags().length > 0) {
555
                        sb.append(getDeprecatedTag(doc));
620
                        sb.append(getDeprecatedTag(doc, ctx));
556
                        sb.append(inlineTags(doc, inlineTags));
621
                        sb.append(inlineTags(doc, inlineTags, ctx));
557
                        sb.append("</p><p>"); //NOI18N
622
                        sb.append("</p><p>"); //NOI18N
558
                        sb.append(getTags(doc));
623
                        sb.append(getTags(doc, ctx));
559
                        sb.append("</p>"); //NOI18N
624
                        sb.append("</p>"); //NOI18N
560
                        return sb;
625
                        return new Now(sb.toString());
561
                    }
626
                    }
562
                }
627
                }
563
            }
628
            }
564
            String jdText = page != null ? HTMLJavadocParser.getJavadocText(page, false) : docURL != null ? HTMLJavadocParser.getJavadocText(docURL, false) : null;
629
565
            if (jdText != null)
630
            final Callable<String> call = new Callable<String>() {
566
                sb.append(jdText);
631
                @Override
567
            else
632
                public String call() throws Exception {
568
                sb.append(NbBundle.getMessage(ElementJavadoc.class, "javadoc_content_not_found")); //NOI18N
633
                    String jdText = page != null ? HTMLJavadocParser.getJavadocText(page, false) : docURL != null ? HTMLJavadocParser.getJavadocText(docURL, false) : null;
569
            sb.append("</p>"); //NOI18N
634
                    if (jdText != null)
570
            return sb;
635
                        sb.append(jdText);
636
                    else
637
                        sb.append(NbBundle.getMessage(ElementJavadoc.class, "javadoc_content_not_found")); //NOI18N
638
                    sb.append("</p>"); //NOI18N
639
                    return sb.toString();
640
                }
641
            };
642
            final FutureTask<String> task = new FutureTask<String>(call);
643
            if (sync) {
644
                RP.post(task);
645
            } else {
646
                task.run();
647
            }
648
            return task;
571
        }
649
        }
572
        sb.append(NbBundle.getMessage(ElementJavadoc.class, "javadoc_content_not_found")); //NOI18N
650
        sb.append(NbBundle.getMessage(ElementJavadoc.class, "javadoc_content_not_found")); //NOI18N
573
        return sb;
651
        return new Now (sb.toString());
574
    }
652
    }
575
    
653
    
576
    private CharSequence getContainingClassOrPackageHeader(ProgramElementDoc peDoc) {
654
    private CharSequence getContainingClassOrPackageHeader(ProgramElementDoc peDoc, Pair<Trees,ElementUtilities> ctx) {
577
        StringBuilder sb = new StringBuilder();
655
        StringBuilder sb = new StringBuilder();
578
        ClassDoc cls = peDoc.containingClass();
656
        ClassDoc cls = peDoc.containingClass();
579
        if (cls != null) {
657
        if (cls != null) {
580
            Element e = eu.elementFor(cls);
658
            Element e = ctx.second.elementFor(cls);
581
            if (e != null) {
659
            if (e != null) {
582
                switch(e.getEnclosingElement().getKind()) {
660
                switch(e.getEnclosingElement().getKind()) {
583
                    case ANNOTATION_TYPE:
661
                    case ANNOTATION_TYPE:
Lines 596-602 Link Here
596
            PackageDoc pkg = peDoc.containingPackage();
674
            PackageDoc pkg = peDoc.containingPackage();
597
            if (pkg != null) {
675
            if (pkg != null) {
598
                sb.append("<font size='+0'><b>"); //NOI18N
676
                sb.append("<font size='+0'><b>"); //NOI18N
599
                createLink(sb, eu.elementFor(pkg), makeNameLineBreakable(pkg.name()));
677
                createLink(sb, ctx.second.elementFor(pkg), makeNameLineBreakable(pkg.name()));
600
                sb.append("</b></font>"); //NOI18N)
678
                sb.append("</b></font>"); //NOI18N)
601
            }
679
            }
602
        }
680
        }
Lines 606-615 Link Here
606
        return name.replace(".", /* ZERO WIDTH SPACE */".&#x200B;");
684
        return name.replace(".", /* ZERO WIDTH SPACE */".&#x200B;");
607
    }
685
    }
608
    
686
    
609
    private CharSequence getMethodHeader(ExecutableMemberDoc mdoc) {
687
    private CharSequence getMethodHeader(ExecutableMemberDoc mdoc, Pair<Trees,ElementUtilities> ctx) {
610
        StringBuilder sb = new StringBuilder();
688
        StringBuilder sb = new StringBuilder();
611
        sb.append("<p><tt>"); //NOI18N
689
        sb.append("<p><tt>"); //NOI18N
612
        sb.append(getAnnotations(mdoc.annotations()));
690
        sb.append(getAnnotations(mdoc.annotations(), ctx));
613
        int len = sb.length();
691
        int len = sb.length();
614
        sb.append(Modifier.toString(mdoc.modifierSpecifier() &~ Modifier.NATIVE));
692
        sb.append(Modifier.toString(mdoc.modifierSpecifier() &~ Modifier.NATIVE));
615
        len = sb.length() - len;
693
        len = sb.length() - len;
Lines 621-627 Link Here
621
            }
699
            }
622
            sb.append("&lt;"); //NOI18N
700
            sb.append("&lt;"); //NOI18N
623
            for (int i = 0; i < tvars.length; i++) {
701
            for (int i = 0; i < tvars.length; i++) {
624
                len += appendType(sb, tvars[i], false, true, false);
702
                len += appendType(sb, tvars[i], false, true, false, ctx);
625
                if (i < tvars.length - 1) {
703
                if (i < tvars.length - 1) {
626
                    sb.append(","); //NOI18N
704
                    sb.append(","); //NOI18N
627
                    len++;
705
                    len++;
Lines 635-641 Link Here
635
                sb.append(' '); //NOI18N
713
                sb.append(' '); //NOI18N
636
                len++;
714
                len++;
637
            }
715
            }
638
            len += appendType(sb, ((MethodDoc)mdoc).returnType(), false, false, false);
716
            len += appendType(sb, ((MethodDoc)mdoc).returnType(), false, false, false, ctx);
639
        }
717
        }
640
        String name = mdoc.name();
718
        String name = mdoc.name();
641
        len += name.length();
719
        len += name.length();
Lines 645-653 Link Here
645
            len++;
723
            len++;
646
            Parameter[] params = mdoc.parameters();
724
            Parameter[] params = mdoc.parameters();
647
            for(int i = 0; i < params.length; i++) {
725
            for(int i = 0; i < params.length; i++) {
648
                sb.append(getAnnotations(params[i].annotations()));
726
                sb.append(getAnnotations(params[i].annotations(), ctx));
649
                boolean varArg = i == params.length - 1 && mdoc.isVarArgs();
727
                boolean varArg = i == params.length - 1 && mdoc.isVarArgs();
650
                appendType(sb, params[i].type(), varArg, false, false);
728
                appendType(sb, params[i].type(), varArg, false, false, ctx);
651
                sb.append(' ').append(params[i].name()); //NOI18N
729
                sb.append(' ').append(params[i].name()); //NOI18N
652
                String dim = params[i].type().dimension();
730
                String dim = params[i].type().dimension();
653
                if (dim.length() > 0) {
731
                if (dim.length() > 0) {
Lines 665-671 Link Here
665
        if (exs.length > 0) {
743
        if (exs.length > 0) {
666
            sb.append(" throws "); //NOI18N
744
            sb.append(" throws "); //NOI18N
667
            for (int i = 0; i < exs.length; i++) {
745
            for (int i = 0; i < exs.length; i++) {
668
                appendType(sb, exs[i], false, false, false);
746
                appendType(sb, exs[i], false, false, false, ctx);
669
                if (i < exs.length - 1)
747
                if (i < exs.length - 1)
670
                    sb.append(", "); //NOI18N
748
                    sb.append(", "); //NOI18N
671
            }
749
            }
Lines 674-698 Link Here
674
        return sb;
752
        return sb;
675
    }
753
    }
676
    
754
    
677
    private CharSequence getFieldHeader(FieldDoc fdoc) {
755
    private CharSequence getFieldHeader(FieldDoc fdoc, Pair<Trees,ElementUtilities> ctx) {
678
        StringBuilder sb = new StringBuilder();
756
        StringBuilder sb = new StringBuilder();
679
        sb.append("<p><tt>"); //NOI18N
757
        sb.append("<p><tt>"); //NOI18N
680
        sb.append(getAnnotations(fdoc.annotations()));
758
        sb.append(getAnnotations(fdoc.annotations(), ctx));
681
        int len = sb.length();
759
        int len = sb.length();
682
        sb.append(fdoc.modifiers());
760
        sb.append(fdoc.modifiers());
683
        len = sb.length() - len;
761
        len = sb.length() - len;
684
        if (len > 0)
762
        if (len > 0)
685
            sb.append(' '); //NOI18N
763
            sb.append(' '); //NOI18N
686
        appendType(sb, fdoc.type(), false, false, false);
764
        appendType(sb, fdoc.type(), false, false, false, ctx);
687
        sb.append(" <b>").append(fdoc.name()).append("</b>"); //NOI18N
765
        sb.append(" <b>").append(fdoc.name()).append("</b>"); //NOI18N
688
        sb.append("</tt></p>"); //NOI18N
766
        sb.append("</tt></p>"); //NOI18N
689
        return sb;
767
        return sb;
690
    }
768
    }
691
    
769
    
692
    private CharSequence getClassHeader(ClassDoc cdoc) {
770
    private CharSequence getClassHeader(ClassDoc cdoc, Pair<Trees,ElementUtilities> ctx) {
693
        StringBuilder sb = new StringBuilder();
771
        StringBuilder sb = new StringBuilder();
694
        sb.append("<p><tt>"); //NOI18N
772
        sb.append("<p><tt>"); //NOI18N
695
        sb.append(getAnnotations(cdoc.annotations()));
773
        sb.append(getAnnotations(cdoc.annotations(), ctx));
696
        int mods = cdoc.modifierSpecifier() & ~Modifier.INTERFACE;
774
        int mods = cdoc.modifierSpecifier() & ~Modifier.INTERFACE;
697
        if (cdoc.isEnum())
775
        if (cdoc.isEnum())
698
            mods &= ~Modifier.FINAL;
776
            mods &= ~Modifier.FINAL;
Lines 712-718 Link Here
712
        if (tvars.length > 0) {
790
        if (tvars.length > 0) {
713
            sb.append("&lt;"); //NOI18N
791
            sb.append("&lt;"); //NOI18N
714
            for (int i = 0; i < tvars.length; i++) {
792
            for (int i = 0; i < tvars.length; i++) {
715
                appendType(sb, tvars[i], false, true, false);
793
                appendType(sb, tvars[i], false, true, false, ctx);
716
                if (i < tvars.length - 1)
794
                if (i < tvars.length - 1)
717
                    sb.append(","); //NOI18N
795
                    sb.append(","); //NOI18N
718
            }
796
            }
Lines 724-737 Link Here
724
                Type supercls = cdoc.superclassType();
802
                Type supercls = cdoc.superclassType();
725
                if (supercls != null) {
803
                if (supercls != null) {
726
                    sb.append(" extends "); //NOI18N
804
                    sb.append(" extends "); //NOI18N
727
                    appendType(sb, supercls, false, false, false);
805
                    appendType(sb, supercls, false, false, false, ctx);
728
                }
806
                }
729
            }
807
            }
730
            Type[] ifaces = cdoc.interfaceTypes();
808
            Type[] ifaces = cdoc.interfaceTypes();
731
            if (ifaces.length > 0) {
809
            if (ifaces.length > 0) {
732
                sb.append(cdoc.isInterface() ? " extends " : " implements "); //NOI18N
810
                sb.append(cdoc.isInterface() ? " extends " : " implements "); //NOI18N
733
                for (int i = 0; i < ifaces.length; i++) {
811
                for (int i = 0; i < ifaces.length; i++) {
734
                    appendType(sb, ifaces[i], false, false, false);
812
                    appendType(sb, ifaces[i], false, false, false, ctx);
735
                    if (i < ifaces.length - 1)
813
                    if (i < ifaces.length - 1)
736
                        sb.append(", "); //NOI18N
814
                        sb.append(", "); //NOI18N
737
                }
815
                }
Lines 741-769 Link Here
741
        return sb;
819
        return sb;
742
    }
820
    }
743
    
821
    
744
    private CharSequence getPackageHeader(PackageDoc pdoc) {
822
    private CharSequence getPackageHeader(PackageDoc pdoc, Pair<Trees,ElementUtilities> ctx) {
745
        StringBuilder sb = new StringBuilder();
823
        StringBuilder sb = new StringBuilder();
746
        sb.append("<p><tt>"); //NOI18N
824
        sb.append("<p><tt>"); //NOI18N
747
        sb.append(getAnnotations(pdoc.annotations()));
825
        sb.append(getAnnotations(pdoc.annotations(), ctx));
748
        sb.append("package <b>").append(pdoc.name()).append("</b>"); //NOI18N
826
        sb.append("package <b>").append(pdoc.name()).append("</b>"); //NOI18N
749
        sb.append("</tt></p>"); //NOI18N
827
        sb.append("</tt></p>"); //NOI18N
750
        return sb;
828
        return sb;
751
    }
829
    }
752
    
830
    
753
    private CharSequence getAnnotations(AnnotationDesc[] annotations) {
831
    private CharSequence getAnnotations(AnnotationDesc[] annotations, Pair<Trees,ElementUtilities> ctx) {
754
        StringBuilder sb = new StringBuilder();
832
        StringBuilder sb = new StringBuilder();
755
        for (AnnotationDesc annotationDesc : annotations) {
833
        for (AnnotationDesc annotationDesc : annotations) {
756
            AnnotationTypeDoc annotationType = annotationDesc.annotationType();
834
            AnnotationTypeDoc annotationType = annotationDesc.annotationType();
757
            if (annotationType != null && isDocumented(annotationType)) {
835
            if (annotationType != null && isDocumented(annotationType)) {
758
                appendType(sb, annotationType, false, false, true);
836
                appendType(sb, annotationType, false, false, true, ctx);
759
                ElementValuePair[] pairs = annotationDesc.elementValues();
837
                ElementValuePair[] pairs = annotationDesc.elementValues();
760
                if (pairs.length > 0) {
838
                if (pairs.length > 0) {
761
                    sb.append('('); //NOI18N
839
                    sb.append('('); //NOI18N
762
                    for (int i = 0; i < pairs.length; i++) {
840
                    for (int i = 0; i < pairs.length; i++) {
763
                        AnnotationTypeElementDoc ated = pairs[i].element();
841
                        AnnotationTypeElementDoc ated = pairs[i].element();
764
                        createLink(sb, eu.elementFor(ated), ated.name());
842
                        createLink(sb, ctx.second.elementFor(ated), ated.name());
765
                        sb.append('='); //NOI18N
843
                        sb.append('='); //NOI18N
766
                        appendAnnotationValue(sb, pairs[i].value());
844
                        appendAnnotationValue(sb, pairs[i].value(), ctx);
767
                        if (i < pairs.length - 1)
845
                        if (i < pairs.length - 1)
768
                            sb.append(","); //NOI18N
846
                            sb.append(","); //NOI18N
769
                    }
847
                    }
Lines 783-813 Link Here
783
        return false;
861
        return false;
784
    }
862
    }
785
    
863
    
786
    private void appendAnnotationValue(StringBuilder sb, AnnotationValue av) {
864
    private void appendAnnotationValue(StringBuilder sb, AnnotationValue av, Pair<Trees,ElementUtilities> ctx) {
787
        Object value = av.value();
865
        Object value = av.value();
788
        if (value instanceof AnnotationValue[]) {
866
        if (value instanceof AnnotationValue[]) {
789
            int length = ((AnnotationValue[])value).length;
867
            int length = ((AnnotationValue[])value).length;
790
            if (length > 1)
868
            if (length > 1)
791
                sb.append('{'); //NOI18N
869
                sb.append('{'); //NOI18N
792
            for(int i = 0; i < ((AnnotationValue[])value).length; i++) {
870
            for(int i = 0; i < ((AnnotationValue[])value).length; i++) {
793
                appendAnnotationValue(sb, ((AnnotationValue[])value)[i]);
871
                appendAnnotationValue(sb, ((AnnotationValue[])value)[i], ctx);
794
                if (i < ((AnnotationValue[])value).length - 1)
872
                if (i < ((AnnotationValue[])value).length - 1)
795
                    sb.append(","); //NOI18N
873
                    sb.append(","); //NOI18N
796
            }
874
            }
797
            if (length > 1)
875
            if (length > 1)
798
                sb.append('}'); //NOI18N
876
                sb.append('}'); //NOI18N
799
        } else if (value instanceof Doc) {
877
        } else if (value instanceof Doc) {
800
            createLink(sb, eu.elementFor((Doc)value), ((Doc)value).name());
878
            createLink(sb, ctx.second.elementFor((Doc)value), ((Doc)value).name());
801
        } else {
879
        } else {
802
            sb.append(value.toString());
880
            sb.append(value.toString());
803
        }
881
        }
804
    } 
882
    } 
805
    
883
    
806
    private CharSequence getMethodTags(MethodDoc doc, Tag[] returnTags, Map<Integer, List<Tag>> paramInlineTags,
884
    private CharSequence getMethodTags(MethodDoc doc, Tag[] returnTags, Map<Integer, List<Tag>> paramInlineTags,
807
            List<ThrowsTag> throwsTags, Map<String, List<Tag>> throwsInlineTags) {
885
            List<ThrowsTag> throwsTags, Map<String, List<Tag>> throwsInlineTags, Pair<Trees,ElementUtilities> ctx) {
808
        StringBuilder ret = new StringBuilder();
886
        StringBuilder ret = new StringBuilder();
809
        if (returnTags.length > 0) {
887
        if (returnTags.length > 0) {
810
            ret.append(inlineTags(doc, returnTags));
888
            ret.append(inlineTags(doc, returnTags, ctx));
811
            ret.append("<br>"); //NOI18N
889
            ret.append("<br>"); //NOI18N
812
        }
890
        }
813
        StringBuilder par = new StringBuilder();
891
        StringBuilder par = new StringBuilder();
Lines 818-824 Link Here
818
                List<Tag> tags = paramInlineTags.get(pos);
896
                List<Tag> tags = paramInlineTags.get(pos);
819
                Tag[] its = tags.toArray(new Tag[tags.size()]);                
897
                Tag[] its = tags.toArray(new Tag[tags.size()]);                
820
                if (its.length > 0) {
898
                if (its.length > 0) {
821
                    CharSequence cs = inlineTags(doc, its);
899
                    CharSequence cs = inlineTags(doc, its, ctx);
822
                    if (cs.length() > 0) {
900
                    if (cs.length() > 0) {
823
                        par.append(" - "); //NOI18N
901
                        par.append(" - "); //NOI18N
824
                        par.append(cs);
902
                        par.append(cs);
Lines 834-840 Link Here
834
                tpar.append("<code>").append(pTag.parameterName()).append("</code>"); //NOI18N
912
                tpar.append("<code>").append(pTag.parameterName()).append("</code>"); //NOI18N
835
                Tag[] its = pTag.inlineTags();
913
                Tag[] its = pTag.inlineTags();
836
                if (its.length > 0) {
914
                if (its.length > 0) {
837
                    CharSequence cs = inlineTags(doc, its);
915
                    CharSequence cs = inlineTags(doc, its, ctx);
838
                    if (cs.length() > 0) {
916
                    if (cs.length() > 0) {
839
                        tpar.append(" - "); //NOI18N
917
                        tpar.append(" - "); //NOI18N
840
                        tpar.append(cs);
918
                        tpar.append(cs);
Lines 849-855 Link Here
849
                thr.append("<code>"); //NOI18N
927
                thr.append("<code>"); //NOI18N
850
                Type exType = throwsTag.exceptionType();
928
                Type exType = throwsTag.exceptionType();
851
                if (exType != null) {
929
                if (exType != null) {
852
                    createLink(thr, eu.elementFor(exType.asClassDoc()), exType.simpleTypeName());
930
                    createLink(thr, ctx.second.elementFor(exType.asClassDoc()), exType.simpleTypeName());
853
                } else {
931
                } else {
854
                    thr.append(throwsTag.exceptionName());
932
                    thr.append(throwsTag.exceptionName());
855
                }
933
                }
Lines 857-863 Link Here
857
                List<Tag> tags = throwsInlineTags.get(exType != null ? exType.qualifiedTypeName() : throwsTag.exceptionName());
935
                List<Tag> tags = throwsInlineTags.get(exType != null ? exType.qualifiedTypeName() : throwsTag.exceptionName());
858
                Tag[] its = tags == null ? throwsTag.inlineTags() : tags.toArray(new Tag[tags.size()]);                
936
                Tag[] its = tags == null ? throwsTag.inlineTags() : tags.toArray(new Tag[tags.size()]);                
859
                if (its.length > 0) {
937
                if (its.length > 0) {
860
                    CharSequence cs = inlineTags(doc, its);
938
                    CharSequence cs = inlineTags(doc, its, ctx);
861
                    if (cs.length() > 0) {
939
                    if (cs.length() > 0) {
862
                        thr.append(" - "); //NOI18N
940
                        thr.append(" - "); //NOI18N
863
                        thr.append(cs);
941
                        thr.append(cs);
Lines 877-883 Link Here
877
                String label = stag.label();
955
                String label = stag.label();
878
                if (memberName != null) {
956
                if (memberName != null) {
879
                    if (refClass != null) {
957
                    if (refClass != null) {
880
                        createLink(see, eu.elementFor(stag.referencedMember()), "<code>" + (label != null && label.length() > 0 ? label : (refClass.simpleTypeName() + "." + memberName)) + "</code>"); //NOI18N
958
                        createLink(see, ctx.second.elementFor(stag.referencedMember()), "<code>" + (label != null && label.length() > 0 ? label : (refClass.simpleTypeName() + "." + memberName)) + "</code>"); //NOI18N
881
                    } else {
959
                    } else {
882
                        see.append(className);
960
                        see.append(className);
883
                        see.append('.'); //NOI18N
961
                        see.append('.'); //NOI18N
Lines 886-892 Link Here
886
                    see.append(", "); //NOI18N
964
                    see.append(", "); //NOI18N
887
                } else if (className != null) {
965
                } else if (className != null) {
888
                    if (refClass != null) {
966
                    if (refClass != null) {
889
                        createLink(see, eu.elementFor(refClass), "<code>" + (label != null && label.length() > 0 ? label : refClass.simpleTypeName()) + "</code>"); //NOI18N
967
                        createLink(see, ctx.second.elementFor(refClass), "<code>" + (label != null && label.length() > 0 ? label : refClass.simpleTypeName()) + "</code>"); //NOI18N
890
                    } else {
968
                    } else {
891
                        see.append(className);
969
                        see.append(className);
892
                    }
970
                    }
Lines 921-927 Link Here
921
        return sb;
999
        return sb;
922
    }
1000
    }
923
    
1001
    
924
    private CharSequence getTags(Doc doc) {
1002
    private CharSequence getTags(Doc doc, Pair<Trees,ElementUtilities> ctx) {
925
        StringBuilder see = new StringBuilder();
1003
        StringBuilder see = new StringBuilder();
926
        StringBuilder par = new StringBuilder();
1004
        StringBuilder par = new StringBuilder();
927
        StringBuilder thr = new StringBuilder();
1005
        StringBuilder thr = new StringBuilder();
Lines 933-957 Link Here
933
                Tag[] its = tag.inlineTags();
1011
                Tag[] its = tag.inlineTags();
934
                if (its.length > 0) {
1012
                if (its.length > 0) {
935
                    par.append(" - "); //NOI18N
1013
                    par.append(" - "); //NOI18N
936
                    par.append(inlineTags(doc, its));
1014
                    par.append(inlineTags(doc, its, ctx));
937
                }
1015
                }
938
                par.append("<br>"); //NOI18N
1016
                par.append("<br>"); //NOI18N
939
            } else if (THROWS_TAG.equals(tag.kind()) && !doc.isMethod()) {
1017
            } else if (THROWS_TAG.equals(tag.kind()) && !doc.isMethod()) {
940
                thr.append("<code>"); //NOI18N
1018
                thr.append("<code>"); //NOI18N
941
                Type exType = ((ThrowsTag)tag).exceptionType();
1019
                Type exType = ((ThrowsTag)tag).exceptionType();
942
                if (exType != null)
1020
                if (exType != null)
943
                    createLink(thr, eu.elementFor(exType.asClassDoc()), exType.simpleTypeName());
1021
                    createLink(thr, ctx.second.elementFor(exType.asClassDoc()), exType.simpleTypeName());
944
                else
1022
                else
945
                    thr.append(((ThrowsTag)tag).exceptionName());
1023
                    thr.append(((ThrowsTag)tag).exceptionName());
946
                thr.append("</code>"); //NOI18N
1024
                thr.append("</code>"); //NOI18N
947
                Tag[] its = tag.inlineTags();
1025
                Tag[] its = tag.inlineTags();
948
                if (its.length > 0) {
1026
                if (its.length > 0) {
949
                    thr.append(" - "); //NOI18N
1027
                    thr.append(" - "); //NOI18N
950
                    thr.append(inlineTags(doc, its));
1028
                    thr.append(inlineTags(doc, its, ctx));
951
                }
1029
                }
952
                thr.append("<br>"); //NOI18N
1030
                thr.append("<br>"); //NOI18N
953
            } else if (RETURN_TAG.equals(tag.kind()) && !doc.isMethod()) {
1031
            } else if (RETURN_TAG.equals(tag.kind()) && !doc.isMethod()) {
954
                ret.append(inlineTags(doc, tag.inlineTags()));
1032
                ret.append(inlineTags(doc, tag.inlineTags(), ctx));
955
                ret.append("<br>"); //NOI18N
1033
                ret.append("<br>"); //NOI18N
956
            } else if (SEE_TAG.equals(tag.kind())) {
1034
            } else if (SEE_TAG.equals(tag.kind())) {
957
                SeeTag stag = (SeeTag)tag;
1035
                SeeTag stag = (SeeTag)tag;
Lines 961-967 Link Here
961
                String label = stag.label();
1039
                String label = stag.label();
962
                if (memberName != null) {
1040
                if (memberName != null) {
963
                    if (refClass != null) {
1041
                    if (refClass != null) {
964
                        createLink(see, eu.elementFor(stag.referencedMember()), "<code>" + (label != null && label.length() > 0 ? label : (refClass.simpleTypeName() + "." + memberName)) + "</code>"); //NOI18N
1042
                        createLink(see, ctx.second.elementFor(stag.referencedMember()), "<code>" + (label != null && label.length() > 0 ? label : (refClass.simpleTypeName() + "." + memberName)) + "</code>"); //NOI18N
965
                    } else {
1043
                    } else {
966
                        see.append(className);
1044
                        see.append(className);
967
                        see.append('.'); //NOI18N
1045
                        see.append('.'); //NOI18N
Lines 970-976 Link Here
970
                    see.append(", "); //NOI18N
1048
                    see.append(", "); //NOI18N
971
                } else if (className != null) {
1049
                } else if (className != null) {
972
                    if (refClass != null) {
1050
                    if (refClass != null) {
973
                        createLink(see, eu.elementFor(refClass), "<code>" + (label != null && label.length() > 0 ? label : refClass.simpleTypeName()) + "</code>"); //NOI18N
1051
                        createLink(see, ctx.second.elementFor(refClass), "<code>" + (label != null && label.length() > 0 ? label : refClass.simpleTypeName()) + "</code>"); //NOI18N
974
                    } else {
1052
                    } else {
975
                        see.append(className);
1053
                        see.append(className);
976
                    }
1054
                    }
Lines 1002-1019 Link Here
1002
        return sb;
1080
        return sb;
1003
    }
1081
    }
1004
    
1082
    
1005
    private CharSequence getDeprecatedTag(Doc doc) {
1083
    private CharSequence getDeprecatedTag(Doc doc, Pair<Trees,ElementUtilities> ctx) {
1006
        StringBuilder sb = new StringBuilder();
1084
        StringBuilder sb = new StringBuilder();
1007
        for (Tag tag : doc.tags()) {
1085
        for (Tag tag : doc.tags()) {
1008
            if (DEPRECATED_TAG.equals(tag.kind())) {
1086
            if (DEPRECATED_TAG.equals(tag.kind())) {
1009
                sb.append("<b>").append(NbBundle.getMessage(ElementJavadoc.class, "JCD-deprecated")).append("</b> <i>").append(inlineTags(doc, tag.inlineTags())).append("</i></p><p>"); //NOI18N
1087
                sb.append("<b>").append(NbBundle.getMessage(ElementJavadoc.class, "JCD-deprecated")).append("</b> <i>").append(inlineTags(doc, tag.inlineTags(),ctx)).append("</i></p><p>"); //NOI18N
1010
                break;
1088
                break;
1011
            }
1089
            }
1012
        }
1090
        }
1013
        return sb;
1091
        return sb;
1014
    }
1092
    }
1015
    
1093
    
1016
    private CharSequence inlineTags(Doc doc, Tag[] tags) {
1094
    private CharSequence inlineTags(Doc doc, Tag[] tags, Pair<Trees,ElementUtilities> ctx) {
1017
        StringBuilder sb = new StringBuilder();
1095
        StringBuilder sb = new StringBuilder();
1018
        for (Tag tag : tags) {
1096
        for (Tag tag : tags) {
1019
            if (SEE_TAG.equals(tag.kind())) {
1097
            if (SEE_TAG.equals(tag.kind())) {
Lines 1035-1041 Link Here
1035
                    boolean plain = LINKPLAIN_TAG.equals(stag.name());
1113
                    boolean plain = LINKPLAIN_TAG.equals(stag.name());
1036
                    if (memberName != null) {
1114
                    if (memberName != null) {
1037
                        if (refClass != null) {
1115
                        if (refClass != null) {
1038
                            createLink(sb, eu.elementFor(stag.referencedMember()), (plain ? "" : "<code>") + (label != null && label.length() > 0 ? label : (refClass.simpleTypeName() + "." + memberName)) + (plain ? "" : "</code>")); //NOI18N
1116
                            createLink(sb, ctx.second.elementFor(stag.referencedMember()), (plain ? "" : "<code>") + (label != null && label.length() > 0 ? label : (refClass.simpleTypeName() + "." + memberName)) + (plain ? "" : "</code>")); //NOI18N
1039
                        } else {
1117
                        } else {
1040
                            sb.append(stag.referencedClassName());
1118
                            sb.append(stag.referencedClassName());
1041
                            sb.append('.'); //NOI18N
1119
                            sb.append('.'); //NOI18N
Lines 1043-1049 Link Here
1043
                        }
1121
                        }
1044
                    } else {
1122
                    } else {
1045
                        if (refClass != null) {
1123
                        if (refClass != null) {
1046
                            createLink(sb, eu.elementFor(refClass), (plain ? "" : "<code>") + (label != null && label.length() > 0 ? label : refClass.simpleTypeName()) + (plain ? "" : "</code>")); //NOI18N
1124
                            createLink(sb, ctx.second.elementFor(refClass), (plain ? "" : "<code>") + (label != null && label.length() > 0 ? label : refClass.simpleTypeName()) + (plain ? "" : "</code>")); //NOI18N
1047
                        } else {
1125
                        } else {
1048
                            String className = stag.referencedClassName();
1126
                            String className = stag.referencedClassName();
1049
                            sb.append(className != null ? className : stag.text());
1127
                            sb.append(className != null ? className : stag.text());
Lines 1054-1060 Link Here
1054
                if (doc.isMethod()) {
1132
                if (doc.isMethod()) {
1055
                    MethodDoc mdoc = ((MethodDoc)doc).overriddenMethod();
1133
                    MethodDoc mdoc = ((MethodDoc)doc).overriddenMethod();
1056
                    if (mdoc != null)
1134
                    if (mdoc != null)
1057
                        sb.append(inlineTags(mdoc, mdoc.inlineTags()));
1135
                        sb.append(inlineTags(mdoc, mdoc.inlineTags(),ctx));
1058
                }
1136
                }
1059
            } else if (LITERAL_TAG.equals(tag.kind())) {
1137
            } else if (LITERAL_TAG.equals(tag.kind())) {
1060
                try {
1138
                try {
Lines 1115-1121 Link Here
1115
            sb.append(' '); //NOI18N            
1193
            sb.append(' '); //NOI18N            
1116
    }
1194
    }
1117
    
1195
    
1118
    private int appendType(StringBuilder sb, Type type, boolean varArg, boolean typeVar, boolean annotation) {
1196
    private int appendType(StringBuilder sb, Type type, boolean varArg, boolean typeVar, boolean annotation, Pair<Trees,ElementUtilities> ctx) {
1119
        int len = 0;
1197
        int len = 0;
1120
        WildcardType wt = type.asWildcardType();
1198
        WildcardType wt = type.asWildcardType();
1121
        if (wt != null) {
1199
        if (wt != null) {
Lines 1125-1137 Link Here
1125
            if (bounds != null && bounds.length > 0) {
1203
            if (bounds != null && bounds.length > 0) {
1126
                sb.append(" extends "); //NOI18N
1204
                sb.append(" extends "); //NOI18N
1127
                len += 9;
1205
                len += 9;
1128
                len += appendType(sb, bounds[0], false, false, false);
1206
                len += appendType(sb, bounds[0], false, false, false, ctx);
1129
            }
1207
            }
1130
            bounds = wt.superBounds();
1208
            bounds = wt.superBounds();
1131
            if (bounds != null && bounds.length > 0) {
1209
            if (bounds != null && bounds.length > 0) {
1132
                sb.append(" super "); //NOI18N
1210
                sb.append(" super "); //NOI18N
1133
                len += 7;
1211
                len += 7;
1134
                len += appendType(sb, bounds[0], false, false, false);
1212
                len += appendType(sb, bounds[0], false, false, false, ctx);
1135
            }
1213
            }
1136
        } else {
1214
        } else {
1137
            TypeVariable tv = type.asTypeVariable();
1215
            TypeVariable tv = type.asTypeVariable();
Lines 1142-1148 Link Here
1142
                    sb.append(" extends "); //NOI18N
1220
                    sb.append(" extends "); //NOI18N
1143
                    len += 9;
1221
                    len += 9;
1144
                    for (int i = 0; i < bounds.length; i++) {
1222
                    for (int i = 0; i < bounds.length; i++) {
1145
                        len += appendType(sb, bounds[i], false, false, false);
1223
                        len += appendType(sb, bounds[i], false, false, false, ctx);
1146
                        if (i < bounds.length - 1) {
1224
                        if (i < bounds.length - 1) {
1147
                            sb.append(" & "); //NOI18N
1225
                            sb.append(" & "); //NOI18N
1148
                            len += 3;
1226
                            len += 3;
Lines 1154-1167 Link Here
1154
                String tName = cd != null ? cd.name() : type.simpleTypeName();
1232
                String tName = cd != null ? cd.name() : type.simpleTypeName();
1155
                if (cd != null && cd.isAnnotationType() && annotation)
1233
                if (cd != null && cd.isAnnotationType() && annotation)
1156
                    tName = "@" + tName; //NOI18N
1234
                    tName = "@" + tName; //NOI18N
1157
                len += createLink(sb, eu.elementFor(type.asClassDoc()), tName);
1235
                len += createLink(sb, ctx.second.elementFor(type.asClassDoc()), tName);
1158
                ParameterizedType pt = type.asParameterizedType();
1236
                ParameterizedType pt = type.asParameterizedType();
1159
                if (pt != null) {
1237
                if (pt != null) {
1160
                    Type[] targs = pt.typeArguments();
1238
                    Type[] targs = pt.typeArguments();
1161
                    if (targs.length > 0) {
1239
                    if (targs.length > 0) {
1162
                        sb.append("&lt;"); //NOI18N
1240
                        sb.append("&lt;"); //NOI18N
1163
                        for (int j = 0; j < targs.length; j++) {
1241
                        for (int j = 0; j < targs.length; j++) {
1164
                            len += appendType(sb, targs[j], false, false, false);
1242
                            len += appendType(sb, targs[j], false, false, false, ctx);
1165
                            if (j < targs.length - 1) {
1243
                            if (j < targs.length - 1) {
1166
                                sb.append(","); //NOI18N
1244
                                sb.append(","); //NOI18N
1167
                                len++;
1245
                                len++;
Lines 1198-1209 Link Here
1198
    private String inheritedDocFor(MethodDoc mdoc, ClassDoc cdoc, List<Tag> inlineTags, List<Tag> returnTags,
1276
    private String inheritedDocFor(MethodDoc mdoc, ClassDoc cdoc, List<Tag> inlineTags, List<Tag> returnTags,
1199
            Set<Integer> paramPos, Map<Integer, ParamTag> paramTags, Map<Integer, List<Tag>> paramInlineTags,
1277
            Set<Integer> paramPos, Map<Integer, ParamTag> paramTags, Map<Integer, List<Tag>> paramInlineTags,
1200
            Set<String> throwsTypes, Map<String, ThrowsTag> throwsTags, Map<String, List<Tag>> throwsInlineTags,
1278
            Set<String> throwsTypes, Map<String, ThrowsTag> throwsTags, Map<String, List<Tag>> throwsInlineTags,
1201
            Callable<Boolean> cancel) {
1279
            Callable<Boolean> cancel, boolean stopByRemoteJdoc, Pair<Trees,ElementUtilities> ctx) throws RemoteJavadocException {
1202
        JavadocHelper.TextStream inheritedPage = null;
1280
        JavadocHelper.TextStream inheritedPage = null;
1203
        for (ClassDoc ifaceDoc : cdoc.interfaces()) {
1281
        for (ClassDoc ifaceDoc : cdoc.interfaces()) {
1204
            for (MethodDoc methodDoc : ifaceDoc.methods(false)) {
1282
            for (MethodDoc methodDoc : ifaceDoc.methods(false)) {
1205
                if (mdoc.overrides(methodDoc)) {
1283
                if (mdoc.overrides(methodDoc)) {
1206
                    Element e = eu.elementFor(methodDoc);
1284
                    Element e = ctx.second.elementFor(methodDoc);
1207
                    boolean isLocalized = false;
1285
                    boolean isLocalized = false;
1208
                    if (e != null) {
1286
                    if (e != null) {
1209
                        inheritedPage = JavadocHelper.getJavadoc(e, cancel);
1287
                        inheritedPage = JavadocHelper.getJavadoc(e, cancel);
Lines 1211-1217 Link Here
1211
                            docURL = inheritedPage.getLocation();
1289
                            docURL = inheritedPage.getLocation();
1212
                        }
1290
                        }
1213
                        if (!(isLocalized = isLocalized(docURL, e)))
1291
                        if (!(isLocalized = isLocalized(docURL, e)))
1214
                            trees.getTree(e);
1292
                            ctx.first.getTree(e);
1215
                    }
1293
                    }
1216
                    if (!isLocalized) {
1294
                    if (!isLocalized) {
1217
                        List<Tag> inheritedInlineTags = null;
1295
                        List<Tag> inheritedInlineTags = null;
Lines 1295-1301 Link Here
1295
                                inheritedParamPos != null && inheritedParamTags != null)
1373
                                inheritedParamPos != null && inheritedParamTags != null)
1296
                            inheritedDocFor(mdoc, ifaceDoc, inheritedInlineTags, inheritedReturnTags,
1374
                            inheritedDocFor(mdoc, ifaceDoc, inheritedInlineTags, inheritedReturnTags,
1297
                                    inheritedParamPos, inheritedParamTags, inheritedParamInlineTags,
1375
                                    inheritedParamPos, inheritedParamTags, inheritedParamInlineTags,
1298
                                    inheritedThrowsTypes, inheritedThrowsTags, inheritedThrowsInlineTags, cancel);
1376
                                    inheritedThrowsTypes, inheritedThrowsTags, inheritedThrowsInlineTags, cancel, stopByRemoteJdoc, ctx);
1299
                        if (inheritedInlineTags != null && !inheritedInlineTags.isEmpty()) {
1377
                        if (inheritedInlineTags != null && !inheritedInlineTags.isEmpty()) {
1300
                            inlineTags.clear();
1378
                            inlineTags.clear();
1301
                            for (Tag tag : methodDoc.inlineTags()) {
1379
                            for (Tag tag : methodDoc.inlineTags()) {
Lines 1350-1362 Link Here
1350
                    (throwsTypes == null || throwsTypes.isEmpty()))
1428
                    (throwsTypes == null || throwsTypes.isEmpty()))
1351
                return null;
1429
                return null;
1352
        }
1430
        }
1431
        if (stopByRemoteJdoc && isRemote(inheritedPage, docURL)) {
1432
            throw new RemoteJavadocException();
1433
        }
1353
        String jdText = inheritedPage != null ? HTMLJavadocParser.getJavadocText(inheritedPage, false) : docURL != null ? HTMLJavadocParser.getJavadocText(docURL, false) : null;
1434
        String jdText = inheritedPage != null ? HTMLJavadocParser.getJavadocText(inheritedPage, false) : docURL != null ? HTMLJavadocParser.getJavadocText(docURL, false) : null;
1354
        if (jdText != null)
1435
        if (jdText != null)
1355
            return jdText;
1436
            return jdText;
1356
        for (ClassDoc ifaceDoc : cdoc.interfaces()) {
1437
        for (ClassDoc ifaceDoc : cdoc.interfaces()) {
1357
            jdText = inheritedDocFor(mdoc, ifaceDoc, inlineTags, returnTags,
1438
            jdText = inheritedDocFor(mdoc, ifaceDoc, inlineTags, returnTags,
1358
                    paramPos, paramTags, paramInlineTags,
1439
                    paramPos, paramTags, paramInlineTags,
1359
                    throwsTypes, throwsTags, throwsInlineTags, cancel);
1440
                    throwsTypes, throwsTags, throwsInlineTags, cancel, stopByRemoteJdoc, ctx);
1360
            if (jdText != null)
1441
            if (jdText != null)
1361
                return jdText;
1442
                return jdText;
1362
            if ((inlineTags == null || !inlineTags.isEmpty()) &&
1443
            if ((inlineTags == null || !inlineTags.isEmpty()) &&
Lines 1370-1376 Link Here
1370
        if (superclass != null) { //NOI18N
1451
        if (superclass != null) { //NOI18N
1371
            for (MethodDoc methodDoc : superclass.methods(false)) {
1452
            for (MethodDoc methodDoc : superclass.methods(false)) {
1372
                if (mdoc.overrides(methodDoc)) {
1453
                if (mdoc.overrides(methodDoc)) {
1373
                    Element e = eu.elementFor(methodDoc);
1454
                    Element e = ctx.second.elementFor(methodDoc);
1374
                    boolean isLocalized = false;
1455
                    boolean isLocalized = false;
1375
                    if (e != null) {
1456
                    if (e != null) {
1376
                        inheritedPage = JavadocHelper.getJavadoc(e, cancel);
1457
                        inheritedPage = JavadocHelper.getJavadoc(e, cancel);
Lines 1378-1384 Link Here
1378
                            docURL = inheritedPage.getLocation();
1459
                            docURL = inheritedPage.getLocation();
1379
                        }
1460
                        }
1380
                        if (!(isLocalized = isLocalized(docURL, e)))
1461
                        if (!(isLocalized = isLocalized(docURL, e)))
1381
                            trees.getTree(e);
1462
                            ctx.first.getTree(e);
1382
                    }
1463
                    }
1383
                    if (!isLocalized) {
1464
                    if (!isLocalized) {
1384
                        List<Tag> inheritedInlineTags = null;
1465
                        List<Tag> inheritedInlineTags = null;
Lines 1463-1469 Link Here
1463
                            inheritedDocFor(mdoc, superclass, inheritedInlineTags,
1544
                            inheritedDocFor(mdoc, superclass, inheritedInlineTags,
1464
                                    inheritedReturnTags, inheritedParamNames, inheritedParamTags,
1545
                                    inheritedReturnTags, inheritedParamNames, inheritedParamTags,
1465
                                    inheritedParamInlineTags, inheritedThrowsTypes,
1546
                                    inheritedParamInlineTags, inheritedThrowsTypes,
1466
                                    inheritedThrowsTags, inheritedThrowsInlineTags, cancel);
1547
                                    inheritedThrowsTags, inheritedThrowsInlineTags, cancel, stopByRemoteJdoc, ctx);
1467
                        if (inheritedInlineTags != null && !inheritedInlineTags.isEmpty()) {
1548
                        if (inheritedInlineTags != null && !inheritedInlineTags.isEmpty()) {
1468
                            inlineTags.clear();
1549
                            inlineTags.clear();
1469
                            for (Tag tag : methodDoc.inlineTags()) {
1550
                            for (Tag tag : methodDoc.inlineTags()) {
Lines 1516-1526 Link Here
1516
                    returnTags != null && returnTags.isEmpty() ||
1597
                    returnTags != null && returnTags.isEmpty() ||
1517
                    paramPos != null && !paramPos.isEmpty() ||
1598
                    paramPos != null && !paramPos.isEmpty() ||
1518
                    throwsTypes != null && !throwsTypes.isEmpty()) {
1599
                    throwsTypes != null && !throwsTypes.isEmpty()) {
1600
                if (stopByRemoteJdoc && isRemote(inheritedPage,docURL)) {
1601
                    throw new RemoteJavadocException();
1602
                }
1519
                jdText = inheritedPage != null ? HTMLJavadocParser.getJavadocText(inheritedPage, false) : docURL != null ? HTMLJavadocParser.getJavadocText(docURL, false) : null;
1603
                jdText = inheritedPage != null ? HTMLJavadocParser.getJavadocText(inheritedPage, false) : docURL != null ? HTMLJavadocParser.getJavadocText(docURL, false) : null;
1520
                return jdText != null ? jdText : inheritedDocFor(mdoc, superclass, inlineTags,
1604
                return jdText != null ? jdText : inheritedDocFor(mdoc, superclass, inlineTags,
1521
                        returnTags, paramPos, paramTags,
1605
                        returnTags, paramPos, paramTags,
1522
                        paramInlineTags, throwsTypes,
1606
                        paramInlineTags, throwsTypes,
1523
                        throwsTags, throwsInlineTags, cancel);
1607
                        throwsTags, throwsInlineTags, cancel, stopByRemoteJdoc, ctx);
1524
            }
1608
            }
1525
        }
1609
        }
1526
        return null;
1610
        return null;
Lines 1536-1539 Link Here
1536
        return -1;
1620
        return -1;
1537
1621
1538
    }
1622
    }
1623
1624
    private static boolean isRemote(final JavadocHelper.TextStream page, final URL url) {
1625
        return page != null ? page.getLocation().toString().startsWith("http") : url != null ? url.toString().startsWith("http") : false;
1626
    }
1627
1628
    private static final class Now implements Future<String> {
1629
1630
        private final String value;
1631
1632
        Now(final String value) {
1633
            this.value = value;
1634
        }
1635
1636
        @Override
1637
        public boolean cancel(boolean mayInterruptIfRunning) {
1638
            return false;
1639
        }
1640
1641
        @Override
1642
        public boolean isCancelled() {
1643
            return false;
1644
        }
1645
1646
        @Override
1647
        public boolean isDone() {
1648
            return true;
1649
        }
1650
1651
        @Override
1652
        public String get() throws InterruptedException, ExecutionException {
1653
            return value;
1654
        }
1655
1656
        @Override
1657
        public String get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
1658
            return value;
1659
        }
1660
    }
1661
1662
    private static class RemoteJavadocException extends Exception {        
1663
    }
1539
}
1664
}

Return to bug 195649