author | ksrini |
Sun, 15 Jun 2014 08:41:57 -0700 | |
changeset 25454 | 376a52c9540c |
parent 22163 | 3651128c74eb |
permissions | -rw-r--r-- |
10 | 1 |
/* |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.doclets.internal.toolkit.util; |
|
27 |
||
14258 | 28 |
import java.util.*; |
29 |
||
10 | 30 |
import com.sun.javadoc.*; |
31 |
import com.sun.tools.doclets.internal.toolkit.Configuration; |
|
32 |
||
33 |
/** |
|
34 |
* For a given class method, build an array of interface methods which it |
|
35 |
* implements. |
|
36 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
37 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
38 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
39 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
40 |
* deletion without notice.</b> |
10 | 41 |
* |
42 |
* @author Atul M Dambalkar |
|
43 |
*/ |
|
44 |
public class ImplementedMethods { |
|
45 |
||
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
46 |
private final Map<MethodDoc,Type> interfaces = new HashMap<>(); |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
47 |
private final List<MethodDoc> methlist = new ArrayList<>(); |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
48 |
private final Configuration configuration; |
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
49 |
private final Utils utils; |
10 | 50 |
private final ClassDoc classdoc; |
51 |
private final MethodDoc method; |
|
52 |
||
53 |
public ImplementedMethods(MethodDoc method, Configuration configuration) { |
|
54 |
this.method = method; |
|
55 |
this.configuration = configuration; |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
56 |
this.utils = configuration.utils; |
10 | 57 |
classdoc = method.containingClass(); |
58 |
} |
|
59 |
||
60 |
/** |
|
61 |
* Return the array of interface methods which the method passed in the |
|
62 |
* constructor is implementing. The search/build order is as follows: |
|
63 |
* <pre> |
|
64 |
* 1. Search in all the immediate interfaces which this method's class is |
|
65 |
* implementing. Do it recursively for the superinterfaces as well. |
|
66 |
* 2. Traverse all the superclasses and search recursively in the |
|
67 |
* interfaces which those superclasses implement. |
|
68 |
*</pre> |
|
69 |
* |
|
70 |
* @return MethodDoc[] Array of implemented methods. |
|
71 |
*/ |
|
72 |
public MethodDoc[] build(boolean sort) { |
|
73 |
buildImplementedMethodList(sort); |
|
868 | 74 |
return methlist.toArray(new MethodDoc[methlist.size()]); |
10 | 75 |
} |
76 |
||
77 |
public MethodDoc[] build() { |
|
78 |
return build(true); |
|
79 |
} |
|
80 |
||
81 |
public Type getMethodHolder(MethodDoc methodDoc) { |
|
868 | 82 |
return interfaces.get(methodDoc); |
10 | 83 |
} |
84 |
||
85 |
/** |
|
86 |
* Search for the method in the array of interfaces. If found check if it is |
|
87 |
* overridden by any other subinterface method which this class |
|
88 |
* implements. If it is not overidden, add it in the method list. |
|
89 |
* Do this recursively for all the extended interfaces for each interface |
|
90 |
* from the array passed. |
|
91 |
*/ |
|
92 |
private void buildImplementedMethodList(boolean sort) { |
|
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
93 |
List<Type> intfacs = utils.getAllInterfaces(classdoc, configuration, sort); |
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
94 |
for (Type interfaceType : intfacs) { |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
95 |
MethodDoc found = utils.findMethod(interfaceType.asClassDoc(), method); |
10 | 96 |
if (found != null) { |
97 |
removeOverriddenMethod(found); |
|
98 |
if (!overridingMethodFound(found)) { |
|
99 |
methlist.add(found); |
|
100 |
interfaces.put(found, interfaceType); |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* Search in the method list and check if it contains a method which |
|
108 |
* is overridden by the method as parameter. If found, remove the |
|
109 |
* overridden method from the method list. |
|
110 |
* |
|
111 |
* @param method Is this method overriding a method in the method list. |
|
112 |
*/ |
|
113 |
private void removeOverriddenMethod(MethodDoc method) { |
|
114 |
ClassDoc overriddenClass = method.overriddenClass(); |
|
115 |
if (overriddenClass != null) { |
|
116 |
for (int i = 0; i < methlist.size(); i++) { |
|
868 | 117 |
ClassDoc cd = methlist.get(i).containingClass(); |
10 | 118 |
if (cd == overriddenClass || overriddenClass.subclassOf(cd)) { |
119 |
methlist.remove(i); // remove overridden method |
|
120 |
return; |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
/** |
|
127 |
* Search in the already found methods' list and check if it contains |
|
128 |
* a method which is overriding the method parameter or is the method |
|
129 |
* parameter itself. |
|
130 |
* |
|
131 |
* @param method MethodDoc Method to be searched in the Method List for |
|
132 |
* an overriding method. |
|
133 |
*/ |
|
134 |
private boolean overridingMethodFound(MethodDoc method) { |
|
135 |
ClassDoc containingClass = method.containingClass(); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
14260
diff
changeset
|
136 |
for (MethodDoc listmethod : methlist) { |
10 | 137 |
if (containingClass == listmethod.containingClass()) { |
138 |
// it's the same method. |
|
139 |
return true; |
|
140 |
} |
|
141 |
ClassDoc cd = listmethod.overriddenClass(); |
|
142 |
if (cd == null) { |
|
143 |
continue; |
|
144 |
} |
|
145 |
if (cd == containingClass || cd.subclassOf(containingClass)) { |
|
146 |
return true; |
|
147 |
} |
|
148 |
} |
|
149 |
return false; |
|
150 |
} |
|
151 |
} |