src/share/classes/com/sun/tools/doclets/internal/toolkit/util/ImplementedMethods.java

Tue, 14 May 2013 10:14:55 -0700

author
jjg
date
Tue, 14 May 2013 10:14:55 -0700
changeset 1746
bd51ca92c013
parent 1359
25e14ad23cef
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8012178: Cleanup use of Util.escapeHtmlChars
Reviewed-by: darcy

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

mercurial