0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.rmi.rmic.newrmic.jrmp;
0N/A
0N/Aimport com.sun.javadoc.ClassDoc;
0N/Aimport com.sun.javadoc.MethodDoc;
0N/Aimport com.sun.javadoc.Parameter;
0N/Aimport com.sun.javadoc.Type;
0N/A
0N/A/**
0N/A * Provides static utility methods.
0N/A *
0N/A * WARNING: The contents of this source file are not part of any
0N/A * supported API. Code that depends on them does so at its own risk:
0N/A * they are subject to change or removal without notice.
0N/A *
0N/A * @author Peter Jones
0N/A **/
0N/Afinal class Util {
0N/A
0N/A private Util() { throw new AssertionError(); }
0N/A
0N/A /**
0N/A * Returns the binary name of the class or interface represented
0N/A * by the specified ClassDoc.
0N/A **/
0N/A static String binaryNameOf(ClassDoc cl) {
0N/A String flat = cl.name().replace('.', '$');
0N/A String packageName = cl.containingPackage().name();
0N/A return packageName.equals("") ? flat : packageName + "." + flat;
0N/A }
0N/A
0N/A /**
0N/A * Returns the method descriptor for the specified method.
0N/A *
0N/A * See section 4.3.3 of The Java Virtual Machine Specification
0N/A * Second Edition for the definition of a "method descriptor".
0N/A **/
0N/A static String methodDescriptorOf(MethodDoc method) {
0N/A String desc = "(";
0N/A Parameter[] parameters = method.parameters();
0N/A for (int i = 0; i < parameters.length; i++) {
0N/A desc += typeDescriptorOf(parameters[i].type());
0N/A }
0N/A desc += ")" + typeDescriptorOf(method.returnType());
0N/A return desc;
0N/A }
0N/A
0N/A /**
0N/A * Returns the descriptor for the specified type, as appropriate
0N/A * for either a parameter or return type in a method descriptor.
0N/A **/
0N/A private static String typeDescriptorOf(Type type) {
0N/A String desc;
0N/A ClassDoc classDoc = type.asClassDoc();
0N/A if (classDoc == null) {
0N/A /*
0N/A * Handle primitive types.
0N/A */
0N/A String name = type.typeName();
0N/A if (name.equals("boolean")) {
0N/A desc = "Z";
0N/A } else if (name.equals("byte")) {
0N/A desc = "B";
0N/A } else if (name.equals("char")) {
0N/A desc = "C";
0N/A } else if (name.equals("short")) {
0N/A desc = "S";
0N/A } else if (name.equals("int")) {
0N/A desc = "I";
0N/A } else if (name.equals("long")) {
0N/A desc = "J";
0N/A } else if (name.equals("float")) {
0N/A desc = "F";
0N/A } else if (name.equals("double")) {
0N/A desc = "D";
0N/A } else if (name.equals("void")) {
0N/A desc = "V";
0N/A } else {
0N/A throw new AssertionError(
0N/A "unrecognized primitive type: " + name);
0N/A }
0N/A } else {
0N/A /*
0N/A * Handle non-array reference types.
0N/A */
0N/A desc = "L" + binaryNameOf(classDoc).replace('.', '/') + ";";
0N/A }
0N/A
0N/A /*
0N/A * Handle array types.
0N/A */
0N/A int dimensions = type.dimension().length() / 2;
0N/A for (int i = 0; i < dimensions; i++) {
0N/A desc = "[" + desc;
0N/A }
0N/A
0N/A return desc;
0N/A }
0N/A
0N/A /**
0N/A * Returns a reader-friendly string representation of the
0N/A * specified method's signature. Names of reference types are not
0N/A * package-qualified.
0N/A **/
0N/A static String getFriendlyUnqualifiedSignature(MethodDoc method) {
0N/A String sig = method.name() + "(";
0N/A Parameter[] parameters = method.parameters();
0N/A for (int i = 0; i < parameters.length; i++) {
0N/A if (i > 0) {
0N/A sig += ", ";
0N/A }
0N/A Type paramType = parameters[i].type();
0N/A sig += paramType.typeName() + paramType.dimension();
0N/A }
0N/A sig += ")";
0N/A return sig;
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the specified type is void.
0N/A **/
0N/A static boolean isVoid(Type type) {
0N/A return type.asClassDoc() == null && type.typeName().equals("void");
0N/A }
0N/A}