001    /*
002     * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    
027    package com.sun.tools.doclets.formats.html;
028    
029    import com.sun.javadoc.*;
030    import com.sun.tools.doclets.internal.toolkit.util.*;
031    import com.sun.tools.doclets.internal.toolkit.util.links.*;
032    
033    public class LinkInfoImpl extends LinkInfo {
034    
035        /**
036         * Indicate that the link appears in a class list.
037         */
038        public static final int ALL_CLASSES_FRAME = 1;
039    
040        /**
041         * Indicate that the link appears in a class documentation.
042         */
043        public static final int CONTEXT_CLASS = 2;
044    
045        /**
046         * Indicate that the link appears in member documentation.
047         */
048        public static final int CONTEXT_MEMBER = 3;
049    
050        /**
051         * Indicate that the link appears in class use documentation.
052         */
053        public static final int CONTEXT_CLASS_USE = 4;
054    
055        /**
056         * Indicate that the link appears in index documentation.
057         */
058        public static final int CONTEXT_INDEX = 5;
059    
060        /**
061         * Indicate that the link appears in constant value summary.
062         */
063        public static final int CONTEXT_CONSTANT_SUMMARY = 6;
064    
065        /**
066         * Indicate that the link appears in serialized form documentation.
067         */
068        public static final int CONTEXT_SERIALIZED_FORM = 7;
069    
070        /**
071         * Indicate that the link appears in serial member documentation.
072         */
073        public static final int CONTEXT_SERIAL_MEMBER = 8;
074    
075        /**
076         * Indicate that the link appears in package documentation.
077         */
078        public static final int CONTEXT_PACKAGE = 9;
079    
080        /**
081         * Indicate that the link appears in see tag documentation.
082         */
083        public static final int CONTEXT_SEE_TAG = 10;
084    
085        /**
086         * Indicate that the link appears in value tag documentation.
087         */
088        public static final int CONTEXT_VALUE_TAG = 11;
089    
090        /**
091         * Indicate that the link appears in tree documentation.
092         */
093        public static final int CONTEXT_TREE = 12;
094    
095        /**
096         * Indicate that the link appears in a class list.
097         */
098        public static final int PACKAGE_FRAME = 13;
099    
100        /**
101         * The header in the class documentation.
102         */
103        public static final int CONTEXT_CLASS_HEADER = 14;
104    
105        /**
106         * The signature in the class documentation.
107         */
108        public static final int CONTEXT_CLASS_SIGNATURE = 15;
109    
110        /**
111         * The return type of a method.
112         */
113        public static final int CONTEXT_RETURN_TYPE = 16;
114    
115        /**
116         * The return type of a method in a member summary.
117         */
118        public static final int CONTEXT_SUMMARY_RETURN_TYPE = 17;
119    
120        /**
121         * The type of a method/constructor parameter.
122         */
123        public static final int CONTEXT_EXECUTABLE_MEMBER_PARAM = 18;
124    
125        /**
126         * Super interface links.
127         */
128        public static final int CONTEXT_SUPER_INTERFACES = 19;
129    
130        /**
131         * Implemented interface links.
132         */
133        public static final int CONTEXT_IMPLEMENTED_INTERFACES = 20;
134    
135        /**
136         * Implemented class links.
137         */
138        public static final int CONTEXT_IMPLEMENTED_CLASSES = 21;
139    
140        /**
141         * Subinterface links.
142         */
143        public static final int CONTEXT_SUBINTERFACES = 22;
144    
145        /**
146         * Subclasses links.
147         */
148        public static final int CONTEXT_SUBCLASSES = 23;
149    
150        /**
151         * The signature in the class documentation (implements/extends portion).
152         */
153        public static final int CONTEXT_CLASS_SIGNATURE_PARENT_NAME = 24;
154    
155        /**
156         * The header for method documentation copied from parent.
157         */
158        public static final int CONTEXT_METHOD_DOC_COPY = 26;
159    
160        /**
161         * Method "specified by" link.
162         */
163        public static final int CONTEXT_METHOD_SPECIFIED_BY = 27;
164    
165        /**
166         * Method "overrides" link.
167         */
168        public static final int CONTEXT_METHOD_OVERRIDES = 28;
169    
170        /**
171         * Annotation link.
172         */
173        public static final int CONTEXT_ANNOTATION = 29;
174    
175        /**
176         * The header for field documentation copied from parent.
177         */
178        public static final int CONTEXT_FIELD_DOC_COPY = 30;
179    
180        /**
181         * The parent nodes int the class tree.
182         */
183        public static final int CONTEXT_CLASS_TREE_PARENT = 31;
184    
185        /**
186         * The type parameters of a method or constructor.
187         */
188        public static final int CONTEXT_MEMBER_TYPE_PARAMS = 32;
189    
190        /**
191         * Indicate that the link appears in class use documentation.
192         */
193        public static final int CONTEXT_CLASS_USE_HEADER = 33;
194    
195        /**
196         * The integer indicating the location of the link.
197         */
198        public int context;
199    
200        /**
201         * The value of the marker #.
202         */
203        public String where = "";
204    
205        /**
206         * String style of text defined in style sheet.
207         */
208        public String styleName ="";
209    
210        /**
211         * The valueof the target.
212         */
213        public String target = "";
214    
215        /**
216         * Construct a LinkInfo object.
217         *
218         * @param context    the context of the link.
219         * @param classDoc   the class to link to.
220         * @param label      the label for the link.
221         * @param target     the value of the target attribute.
222         */
223        public LinkInfoImpl (int context, ClassDoc classDoc, String label,
224                String target){
225            this.classDoc = classDoc;
226            this.label = label;
227            this.target = target;
228            setContext(context);
229        }
230    
231        /**
232         * Construct a LinkInfo object.
233         *
234         * @param context    the context of the link.
235         * @param classDoc   the class to link to.
236         * @param where      the value of the marker #.
237         * @param label      the label for the link.
238         * @param isStrong       true if the link should be strong.
239         * @param styleName  String style of text defined in style sheet.
240         */
241        public LinkInfoImpl (int context, ClassDoc classDoc, String where, String label,
242                boolean isStrong, String styleName){
243            this.classDoc = classDoc;
244            this.where = where;
245            this.label = label;
246            this.isStrong = isStrong;
247            this.styleName = styleName;
248            setContext(context);
249        }
250    
251        /**
252         * Construct a LinkInfo object.
253         *
254         * @param context    the context of the link.
255         * @param classDoc   the class to link to.
256         * @param where      the value of the marker #.
257         * @param label      the label for the link.
258         * @param isStrong       true if the link should be strong.
259         */
260        public LinkInfoImpl (int context, ClassDoc classDoc, String where, String label,
261                boolean isStrong){
262            this.classDoc = classDoc;
263            this.where = where;
264            this.label = label;
265            this.isStrong = isStrong;
266            setContext(context);
267        }
268    
269        /**
270         * Construct a LinkInfo object.
271         *
272         * @param classDoc   the class to link to.
273         * @param label      the label for the link.
274         */
275        public LinkInfoImpl (ClassDoc classDoc, String label){
276            this.classDoc = classDoc;
277            this.label = label;
278            setContext(context);
279        }
280    
281        /**
282         * Construct a LinkInfo object.
283         *
284         * @param context               the context of the link.
285         * @param executableMemberDoc   the member to link to.
286         * @param isStrong                true if the link should be strong.
287         */
288        public LinkInfoImpl (int context, ExecutableMemberDoc executableMemberDoc,
289                boolean isStrong){
290            this.executableMemberDoc = executableMemberDoc;
291            this.isStrong = isStrong;
292            setContext(context);
293        }
294    
295        /**
296         * Construct a LinkInfo object.
297         *
298         * @param context    the context of the link.
299         * @param classDoc   the class to link to.
300         * @param isStrong       true if the link should be strong.
301         */
302        public LinkInfoImpl (int context, ClassDoc classDoc,  boolean isStrong){
303            this.classDoc = classDoc;
304            this.isStrong = isStrong;
305            setContext(context);
306        }
307    
308        /**
309         * Construct a LinkInfo object.
310         *
311         * @param context    the context of the link.
312         * @param type       the class to link to.
313         */
314        public LinkInfoImpl (int context, Type type){
315            this.type = type;
316            setContext(context);
317        }
318    
319        /**
320         * Construct a LinkInfo object.
321         *
322         * @param context    the context of the link.
323         * @param type       the class to link to.
324         * @param isVarArg   true if this is a link to a var arg.
325         */
326        public LinkInfoImpl (int context, Type type, boolean isVarArg){
327            this.type = type;
328            this.isVarArg = isVarArg;
329            setContext(context);
330        }
331    
332        /**
333         * Construct a LinkInfo object.
334         *
335         * @param context    the context of the link.
336         * @param type       the class to link to.
337         * @param label      the label for the link.
338         * @param isStrong     true if the link should be strong.
339         */
340        public LinkInfoImpl (int context, Type type, String label,
341                boolean isStrong){
342            this.type = type;
343            this.label = label;
344            this.isStrong = isStrong;
345            setContext(context);
346        }
347    
348        /**
349         * Construct a LinkInfo object.
350         *
351         * @param context    the context of the link.
352         * @param classDoc   the class to link to.
353         * @param label      the label for the link.
354         * @param isStrong       true if the link should be strong.
355         */
356        public LinkInfoImpl (int context, ClassDoc classDoc, String label,
357                boolean isStrong){
358            this.classDoc = classDoc;
359            this.label = label;
360            this.isStrong = isStrong;
361            setContext(context);
362        }
363    
364        /**
365         * {@inheritDoc}
366         */
367        public int getContext() {
368            return context;
369        }
370    
371        /**
372         * {@inheritDoc}
373         *
374         * This method sets the link attributes to the appropriate values
375         * based on the context.
376         *
377         * @param c the context id to set.
378         */
379        public void setContext(int c) {
380            //NOTE:  Put context specific link code here.
381            switch (c) {
382                case ALL_CLASSES_FRAME:
383                case PACKAGE_FRAME:
384                case CONTEXT_IMPLEMENTED_CLASSES:
385                case CONTEXT_SUBCLASSES:
386                case CONTEXT_METHOD_DOC_COPY:
387                case CONTEXT_FIELD_DOC_COPY:
388                case CONTEXT_CLASS_USE_HEADER:
389                    includeTypeInClassLinkLabel = false;
390                    break;
391    
392                case CONTEXT_ANNOTATION:
393                    excludeTypeParameterLinks = true;
394                    excludeTypeBounds = true;
395                    break;
396    
397                case CONTEXT_IMPLEMENTED_INTERFACES:
398                case CONTEXT_SUPER_INTERFACES:
399                case CONTEXT_SUBINTERFACES:
400                case CONTEXT_CLASS_TREE_PARENT:
401                case CONTEXT_TREE:
402                case CONTEXT_CLASS_SIGNATURE_PARENT_NAME:
403                    excludeTypeParameterLinks = true;
404                    excludeTypeBounds = true;
405                    includeTypeInClassLinkLabel = false;
406                    includeTypeAsSepLink = true;
407                    break;
408    
409                case CONTEXT_PACKAGE:
410                case CONTEXT_CLASS_USE:
411                    excludeTypeBoundsLinks = true;
412                    excludeTypeParameterLinks = true;
413                    break;
414    
415                case CONTEXT_CLASS_HEADER:
416                case CONTEXT_CLASS_SIGNATURE:
417                    excludeTypeParameterLinks = true;
418                    includeTypeAsSepLink = true;
419                    includeTypeInClassLinkLabel = false;
420                    break;
421    
422                case CONTEXT_MEMBER_TYPE_PARAMS:
423                    includeTypeAsSepLink = true;
424                    includeTypeInClassLinkLabel = false;
425                    break;
426    
427                case CONTEXT_RETURN_TYPE:
428                case CONTEXT_SUMMARY_RETURN_TYPE:
429                case CONTEXT_EXECUTABLE_MEMBER_PARAM:
430                    excludeTypeBounds = true;
431                    break;
432            }
433            context = c;
434            if (type != null &&
435                type.asTypeVariable()!= null &&
436                type.asTypeVariable().owner() instanceof ExecutableMemberDoc){
437                excludeTypeParameterLinks = true;
438            }
439        }
440    
441        /**
442         * Return true if this link is linkable and false if we can't link to the
443         * desired place.
444         *
445         * @return true if this link is linkable and false if we can't link to the
446         * desired place.
447         */
448        public boolean isLinkable() {
449            return Util.isLinkable(classDoc, ConfigurationImpl.getInstance());
450        }
451    }