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

Mon, 02 May 2011 02:13:02 -0700

author
bpatel
date
Mon, 02 May 2011 02:13:02 -0700
changeset 995
62bc3775d5bb
parent 554
9d9f26857129
child 1357
c75be5bc5283
permissions
-rw-r--r--

6492694: @deprecated tag doesn't work in package-info files.
Reviewed-by: jjg

duke@1 1 /*
ohair@554 2 * Copyright (c) 1999, 2008, 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
duke@1 28 import com.sun.javadoc.*;
duke@1 29 import com.sun.tools.doclets.internal.toolkit.Configuration;
duke@1 30 import java.util.*;
duke@1 31
duke@1 32 /**
duke@1 33 * For a given class method, build an array of interface methods which it
duke@1 34 * implements.
duke@1 35 *
duke@1 36 * This code is not part of an API.
duke@1 37 * It is implementation that is subject to change.
duke@1 38 * Do not use it as an API
duke@1 39 *
duke@1 40 * @author Atul M Dambalkar
duke@1 41 */
duke@1 42 public class ImplementedMethods {
duke@1 43
jjg@74 44 private Map<MethodDoc,Type> interfaces = new HashMap<MethodDoc,Type>();
jjg@74 45 private List<MethodDoc> methlist = new ArrayList<MethodDoc>();
duke@1 46 private Configuration configuration;
duke@1 47 private final ClassDoc classdoc;
duke@1 48 private final MethodDoc method;
duke@1 49
duke@1 50 public ImplementedMethods(MethodDoc method, Configuration configuration) {
duke@1 51 this.method = method;
duke@1 52 this.configuration = configuration;
duke@1 53 classdoc = method.containingClass();
duke@1 54 }
duke@1 55
duke@1 56 /**
duke@1 57 * Return the array of interface methods which the method passed in the
duke@1 58 * constructor is implementing. The search/build order is as follows:
duke@1 59 * <pre>
duke@1 60 * 1. Search in all the immediate interfaces which this method's class is
duke@1 61 * implementing. Do it recursively for the superinterfaces as well.
duke@1 62 * 2. Traverse all the superclasses and search recursively in the
duke@1 63 * interfaces which those superclasses implement.
duke@1 64 *</pre>
duke@1 65 *
duke@1 66 * @return MethodDoc[] Array of implemented methods.
duke@1 67 */
duke@1 68 public MethodDoc[] build(boolean sort) {
duke@1 69 buildImplementedMethodList(sort);
jjg@74 70 return methlist.toArray(new MethodDoc[methlist.size()]);
duke@1 71 }
duke@1 72
duke@1 73 public MethodDoc[] build() {
duke@1 74 return build(true);
duke@1 75 }
duke@1 76
duke@1 77 public Type getMethodHolder(MethodDoc methodDoc) {
jjg@74 78 return interfaces.get(methodDoc);
duke@1 79 }
duke@1 80
duke@1 81 /**
duke@1 82 * Search for the method in the array of interfaces. If found check if it is
duke@1 83 * overridden by any other subinterface method which this class
duke@1 84 * implements. If it is not overidden, add it in the method list.
duke@1 85 * Do this recursively for all the extended interfaces for each interface
duke@1 86 * from the array passed.
duke@1 87 */
duke@1 88 private void buildImplementedMethodList(boolean sort) {
mcimadamore@184 89 List<Type> intfacs = Util.getAllInterfaces(classdoc, configuration, sort);
mcimadamore@184 90 for (Iterator<Type> iter = intfacs.iterator(); iter.hasNext(); ) {
mcimadamore@184 91 Type interfaceType = iter.next();
duke@1 92 MethodDoc found = Util.findMethod(interfaceType.asClassDoc(), method);
duke@1 93 if (found != null) {
duke@1 94 removeOverriddenMethod(found);
duke@1 95 if (!overridingMethodFound(found)) {
duke@1 96 methlist.add(found);
duke@1 97 interfaces.put(found, interfaceType);
duke@1 98 }
duke@1 99 }
duke@1 100 }
duke@1 101 }
duke@1 102
duke@1 103 /**
duke@1 104 * Search in the method list and check if it contains a method which
duke@1 105 * is overridden by the method as parameter. If found, remove the
duke@1 106 * overridden method from the method list.
duke@1 107 *
duke@1 108 * @param method Is this method overriding a method in the method list.
duke@1 109 */
duke@1 110 private void removeOverriddenMethod(MethodDoc method) {
duke@1 111 ClassDoc overriddenClass = method.overriddenClass();
duke@1 112 if (overriddenClass != null) {
duke@1 113 for (int i = 0; i < methlist.size(); i++) {
jjg@74 114 ClassDoc cd = methlist.get(i).containingClass();
duke@1 115 if (cd == overriddenClass || overriddenClass.subclassOf(cd)) {
duke@1 116 methlist.remove(i); // remove overridden method
duke@1 117 return;
duke@1 118 }
duke@1 119 }
duke@1 120 }
duke@1 121 }
duke@1 122
duke@1 123 /**
duke@1 124 * Search in the already found methods' list and check if it contains
duke@1 125 * a method which is overriding the method parameter or is the method
duke@1 126 * parameter itself.
duke@1 127 *
duke@1 128 * @param method MethodDoc Method to be searched in the Method List for
duke@1 129 * an overriding method.
duke@1 130 */
duke@1 131 private boolean overridingMethodFound(MethodDoc method) {
duke@1 132 ClassDoc containingClass = method.containingClass();
duke@1 133 for (int i = 0; i < methlist.size(); i++) {
jjg@74 134 MethodDoc listmethod = methlist.get(i);
duke@1 135 if (containingClass == listmethod.containingClass()) {
duke@1 136 // it's the same method.
duke@1 137 return true;
duke@1 138 }
duke@1 139 ClassDoc cd = listmethod.overriddenClass();
duke@1 140 if (cd == null) {
duke@1 141 continue;
duke@1 142 }
duke@1 143 if (cd == containingClass || cd.subclassOf(containingClass)) {
duke@1 144 return true;
duke@1 145 }
duke@1 146 }
duke@1 147 return false;
duke@1 148 }
duke@1 149 }

mercurial