author | prr |
Thu, 11 Aug 2016 10:38:13 -0700 | |
changeset 40489 | 4572e3dce7ba |
parent 35426 | 374342e56a56 |
child 45417 | f7479ee8de69 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
2 |
* Copyright (c) 1999, 2015, 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 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.toolkit.util; |
10 | 27 |
|
14258 | 28 |
import java.util.*; |
29 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
30 |
import javax.lang.model.element.ExecutableElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
31 |
import javax.lang.model.element.TypeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
32 |
import javax.lang.model.type.TypeMirror; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
33 |
|
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
34 |
import jdk.javadoc.internal.doclets.toolkit.Configuration; |
10 | 35 |
|
36 |
/** |
|
37 |
* For a given class method, build an array of interface methods which it |
|
38 |
* implements. |
|
39 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
40 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
41 |
* 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
|
42 |
* 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
|
43 |
* deletion without notice.</b> |
10 | 44 |
* |
45 |
* @author Atul M Dambalkar |
|
46 |
*/ |
|
47 |
public class ImplementedMethods { |
|
48 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
49 |
private final Map<ExecutableElement, TypeMirror> interfaces = new HashMap<>(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
50 |
private final List<ExecutableElement> methlist = new ArrayList<>(); |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
51 |
private final Utils utils; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
52 |
private final TypeElement typeElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
53 |
private final ExecutableElement method; |
10 | 54 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
55 |
public ImplementedMethods(ExecutableElement method, Configuration configuration) { |
10 | 56 |
this.method = method; |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
22163
diff
changeset
|
57 |
this.utils = configuration.utils; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
58 |
typeElement = utils.getEnclosingTypeElement(method); |
10 | 59 |
} |
60 |
||
61 |
/** |
|
62 |
* Return the array of interface methods which the method passed in the |
|
63 |
* constructor is implementing. The search/build order is as follows: |
|
64 |
* <pre> |
|
65 |
* 1. Search in all the immediate interfaces which this method's class is |
|
66 |
* implementing. Do it recursively for the superinterfaces as well. |
|
67 |
* 2. Traverse all the superclasses and search recursively in the |
|
68 |
* interfaces which those superclasses implement. |
|
69 |
*</pre> |
|
70 |
* |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
71 |
* @return SortedSet<ExecutableElement> of implemented methods. |
10 | 72 |
*/ |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
73 |
public List<ExecutableElement> build() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
74 |
buildImplementedMethodList(); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
75 |
return methlist; |
10 | 76 |
} |
77 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
78 |
public TypeMirror getMethodHolder(ExecutableElement ee) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
79 |
return interfaces.get(ee); |
10 | 80 |
} |
81 |
||
82 |
/** |
|
83 |
* Search for the method in the array of interfaces. If found check if it is |
|
84 |
* overridden by any other subinterface method which this class |
|
85 |
* implements. If it is not overidden, add it in the method list. |
|
86 |
* Do this recursively for all the extended interfaces for each interface |
|
87 |
* from the array passed. |
|
88 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
89 |
private void buildImplementedMethodList() { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
90 |
Set<TypeMirror> intfacs = utils.getAllInterfaces(typeElement); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
91 |
for (TypeMirror interfaceType : intfacs) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
92 |
ExecutableElement found = utils.findMethod(utils.asTypeElement(interfaceType), method); |
10 | 93 |
if (found != null) { |
94 |
removeOverriddenMethod(found); |
|
95 |
if (!overridingMethodFound(found)) { |
|
96 |
methlist.add(found); |
|
97 |
interfaces.put(found, interfaceType); |
|
98 |
} |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
/** |
|
104 |
* Search in the method list and check if it contains a method which |
|
105 |
* is overridden by the method as parameter. If found, remove the |
|
106 |
* overridden method from the method list. |
|
107 |
* |
|
108 |
* @param method Is this method overriding a method in the method list. |
|
109 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
110 |
private void removeOverriddenMethod(ExecutableElement method) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
111 |
TypeElement overriddenClass = utils.overriddenClass(method); |
10 | 112 |
if (overriddenClass != null) { |
113 |
for (int i = 0; i < methlist.size(); i++) { |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
114 |
TypeElement te = utils.getEnclosingTypeElement(methlist.get(i)); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
115 |
if (te == overriddenClass || utils.isSubclassOf(overriddenClass, te)) { |
10 | 116 |
methlist.remove(i); // remove overridden method |
117 |
return; |
|
118 |
} |
|
119 |
} |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* Search in the already found methods' list and check if it contains |
|
125 |
* a method which is overriding the method parameter or is the method |
|
126 |
* parameter itself. |
|
127 |
* |
|
128 |
* @param method MethodDoc Method to be searched in the Method List for |
|
129 |
* an overriding method. |
|
130 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
131 |
private boolean overridingMethodFound(ExecutableElement method) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
132 |
TypeElement containingClass = utils.getEnclosingTypeElement(method); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
133 |
for (ExecutableElement listmethod : methlist) { |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
134 |
if (containingClass == utils.getEnclosingTypeElement(listmethod)) { |
10 | 135 |
// it's the same method. |
136 |
return true; |
|
137 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
138 |
TypeElement te = utils.overriddenClass(listmethod); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
139 |
if (te == null) { |
10 | 140 |
continue; |
141 |
} |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
25874
diff
changeset
|
142 |
if (te == containingClass || utils.isSubclassOf(te, containingClass)) { |
10 | 143 |
return true; |
144 |
} |
|
145 |
} |
|
146 |
return false; |
|
147 |
} |
|
148 |
} |