Wed, 13 Apr 2011 11:35:43 -0700
7032975: API files in javax.annotation.processing need to be updated for references to JLS
7032972: API files in javax.tools need to updated for references to JVM Spec with editions/hyperlinks
7032978: API files in javax.tools need to be updated for references to JLS with editions/hyperlinks
Summary: Removed URLs and 'edition' references
Reviewed-by: jjg, darcy
1 /*
2 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
26 package com.sun.tools.doclets.internal.toolkit.util;
28 import com.sun.javadoc.*;
29 import com.sun.tools.doclets.internal.toolkit.Configuration;
30 import java.util.*;
32 /**
33 * For a given class method, build an array of interface methods which it
34 * implements.
35 *
36 * This code is not part of an API.
37 * It is implementation that is subject to change.
38 * Do not use it as an API
39 *
40 * @author Atul M Dambalkar
41 */
42 public class ImplementedMethods {
44 private Map<MethodDoc,Type> interfaces = new HashMap<MethodDoc,Type>();
45 private List<MethodDoc> methlist = new ArrayList<MethodDoc>();
46 private Configuration configuration;
47 private final ClassDoc classdoc;
48 private final MethodDoc method;
50 public ImplementedMethods(MethodDoc method, Configuration configuration) {
51 this.method = method;
52 this.configuration = configuration;
53 classdoc = method.containingClass();
54 }
56 /**
57 * Return the array of interface methods which the method passed in the
58 * constructor is implementing. The search/build order is as follows:
59 * <pre>
60 * 1. Search in all the immediate interfaces which this method's class is
61 * implementing. Do it recursively for the superinterfaces as well.
62 * 2. Traverse all the superclasses and search recursively in the
63 * interfaces which those superclasses implement.
64 *</pre>
65 *
66 * @return MethodDoc[] Array of implemented methods.
67 */
68 public MethodDoc[] build(boolean sort) {
69 buildImplementedMethodList(sort);
70 return methlist.toArray(new MethodDoc[methlist.size()]);
71 }
73 public MethodDoc[] build() {
74 return build(true);
75 }
77 public Type getMethodHolder(MethodDoc methodDoc) {
78 return interfaces.get(methodDoc);
79 }
81 /**
82 * Search for the method in the array of interfaces. If found check if it is
83 * overridden by any other subinterface method which this class
84 * implements. If it is not overidden, add it in the method list.
85 * Do this recursively for all the extended interfaces for each interface
86 * from the array passed.
87 */
88 private void buildImplementedMethodList(boolean sort) {
89 List<Type> intfacs = Util.getAllInterfaces(classdoc, configuration, sort);
90 for (Iterator<Type> iter = intfacs.iterator(); iter.hasNext(); ) {
91 Type interfaceType = iter.next();
92 MethodDoc found = Util.findMethod(interfaceType.asClassDoc(), method);
93 if (found != null) {
94 removeOverriddenMethod(found);
95 if (!overridingMethodFound(found)) {
96 methlist.add(found);
97 interfaces.put(found, interfaceType);
98 }
99 }
100 }
101 }
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 */
110 private void removeOverriddenMethod(MethodDoc method) {
111 ClassDoc overriddenClass = method.overriddenClass();
112 if (overriddenClass != null) {
113 for (int i = 0; i < methlist.size(); i++) {
114 ClassDoc cd = methlist.get(i).containingClass();
115 if (cd == overriddenClass || overriddenClass.subclassOf(cd)) {
116 methlist.remove(i); // remove overridden method
117 return;
118 }
119 }
120 }
121 }
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 */
131 private boolean overridingMethodFound(MethodDoc method) {
132 ClassDoc containingClass = method.containingClass();
133 for (int i = 0; i < methlist.size(); i++) {
134 MethodDoc listmethod = methlist.get(i);
135 if (containingClass == listmethod.containingClass()) {
136 // it's the same method.
137 return true;
138 }
139 ClassDoc cd = listmethod.overriddenClass();
140 if (cd == null) {
141 continue;
142 }
143 if (cd == containingClass || cd.subclassOf(containingClass)) {
144 return true;
145 }
146 }
147 return false;
148 }
149 }