langtools/src/share/classes/com/sun/tools/javah/TypeSignature.java
author briangoetz
Wed, 18 Dec 2013 16:05:18 -0500
changeset 22163 3651128c74eb
parent 22159 682da512ec17
child 25690 b1dac768ab79
permissions -rw-r--r--
8030244: Update langtools to use Diamond Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
10192
378321489bea 7025809: Provided new utility visitors supporting SourceVersion.RELEASE_8
darcy
parents: 7681
diff changeset
     2
 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3996
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3996
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3996
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3996
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3996
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
package com.sun.tools.javah;
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.*;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    30
import javax.lang.model.element.Name;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    31
import javax.lang.model.element.TypeElement;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    32
import javax.lang.model.type.ArrayType;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    33
import javax.lang.model.type.DeclaredType;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    34
import javax.lang.model.type.NoType;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    35
import javax.lang.model.type.PrimitiveType;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    36
import javax.lang.model.type.TypeKind;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    37
import javax.lang.model.type.TypeMirror;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    38
import javax.lang.model.type.TypeVariable;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    39
import javax.lang.model.type.TypeVisitor;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    40
import javax.lang.model.util.Elements;
10192
378321489bea 7025809: Provided new utility visitors supporting SourceVersion.RELEASE_8
darcy
parents: 7681
diff changeset
    41
import javax.lang.model.util.SimpleTypeVisitor8;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * Returns internal type signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5841
diff changeset
    46
 * <p><b>This is NOT part of any supported API.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    47
 * If you write code that depends on this, you do so at your own
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    48
 * risk.  This code and its internal interfaces are subject to change
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    49
 * or deletion without notice.</b></p>
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    50
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * @author Sucheta Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    54
public class TypeSignature {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    55
    static class SignatureException extends Exception {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    56
        private static final long serialVersionUID = 1L;
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    57
        SignatureException(String reason) {
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    58
            super(reason);
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    59
        }
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    60
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    62
    Elements elems;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    /* Signature Characters */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    private static final String SIG_VOID                   = "V";
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    private static final String SIG_BOOLEAN                = "Z";
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    private static final String SIG_BYTE                   = "B";
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    private static final String SIG_CHAR                   = "C";
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    private static final String SIG_SHORT                  = "S";
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    private static final String SIG_INT                    = "I";
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    private static final String SIG_LONG                   = "J";
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    private static final String SIG_FLOAT                  = "F";
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    private static final String SIG_DOUBLE                 = "D";
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    private static final String SIG_ARRAY                  = "[";
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    private static final String SIG_CLASS                  = "L";
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    80
    public TypeSignature(Elements elems){
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
    81
        this.elems = elems;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * Returns the type signature of a field according to JVM specs
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    87
    public String getTypeSignature(String javasignature) throws SignatureException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        return getParamJVMSignature(javasignature);
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * Returns the type signature of a method according to JVM specs
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     */
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    94
    public String getTypeSignature(String javasignature, TypeMirror returnType)
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
    95
            throws SignatureException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        String signature = null; //Java type signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        String typeSignature = null; //Internal type signature.
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
    98
        List<String> params = new ArrayList<>(); //List of parameters.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        String paramsig = null; //Java parameter signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
        String paramJVMSig = null; //Internal parameter signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        String returnSig = null; //Java return type signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        String returnJVMType = null; //Internal return type signature.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   103
        int dimensions = 0; //Array dimension.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        int startIndex = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        int endIndex = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        StringTokenizer st = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        int i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
        // Gets the actual java signature without parentheses.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   111
        if (javasignature != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
            startIndex = javasignature.indexOf("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
            endIndex = javasignature.indexOf(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   116
        if (((startIndex != -1) && (endIndex != -1))
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   117
            &&(startIndex+1 < javasignature.length())
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   118
            &&(endIndex < javasignature.length())) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            signature = javasignature.substring(startIndex+1, endIndex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        // Separates parameters.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   123
        if (signature != null) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   124
            if (signature.contains(",")) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                st = new StringTokenizer(signature, ",");
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   126
                if (st != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                    while (st.hasMoreTokens()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                        params.add(st.nextToken());
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                }
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   131
            } else {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                params.add(signature);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
        /* JVM type signature. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        typeSignature = "(";
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        // Gets indivisual internal parameter signature.
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   140
        while (params.isEmpty() != true) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   141
            paramsig = params.remove(i).trim();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
            paramJVMSig  = getParamJVMSignature(paramsig);
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   143
            if (paramJVMSig != null) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                typeSignature += paramJVMSig;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        typeSignature += ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
        // Get internal return type signature.
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
        returnJVMType = "";
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   153
        if (returnType != null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   154
            dimensions = dimensions(returnType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   157
        //Gets array dimension of return type.
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   158
        while (dimensions-- > 0) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   159
            returnJVMType += "[";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        }
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   161
        if (returnType != null) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   162
            returnSig = qualifiedTypeName(returnType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
            returnJVMType += getComponentType(returnSig);
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   164
        } else {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            System.out.println("Invalid return type.");
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        typeSignature += returnJVMType;
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   169
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        return typeSignature;
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * Returns internal signature of a parameter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     */
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
   176
    private String getParamJVMSignature(String paramsig) throws SignatureException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        String paramJVMSig = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        String componentType ="";
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        if(paramsig != null){
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   182
            if(paramsig.contains("[]")) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                // Gets array dimension.
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                int endindex = paramsig.indexOf("[]");
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
                componentType = paramsig.substring(0, endindex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
                String dimensionString =  paramsig.substring(endindex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
                if(dimensionString != null){
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   188
                    while(dimensionString.contains("[]")){
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
                        paramJVMSig += "[";
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
                        int beginindex = dimensionString.indexOf("]") + 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
                        if(beginindex < dimensionString.length()){
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
                            dimensionString = dimensionString.substring(beginindex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
                        }else
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                            dimensionString = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            } else componentType = paramsig;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
            paramJVMSig += getComponentType(componentType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        return paramJVMSig;
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     * Returns internal signature of a component.
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     */
6930
b6fea484cbb2 4942232: missing param class processes without error
jjg
parents: 5847
diff changeset
   207
    private String getComponentType(String componentType) throws SignatureException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        String JVMSig = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
        if(componentType != null){
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   212
            switch (componentType) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   213
                case "void":    JVMSig += SIG_VOID;    break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   214
                case "boolean": JVMSig += SIG_BOOLEAN; break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   215
                case "byte":    JVMSig += SIG_BYTE;    break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   216
                case "char":    JVMSig += SIG_CHAR;    break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   217
                case "short":   JVMSig += SIG_SHORT;   break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   218
                case "int":     JVMSig += SIG_INT;     break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   219
                case "long":    JVMSig += SIG_LONG;    break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   220
                case "float":   JVMSig += SIG_FLOAT;   break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   221
                case "double":  JVMSig += SIG_DOUBLE;  break;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   222
                default:
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   223
                    if (!componentType.equals("")) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   224
                        TypeElement classNameDoc = elems.getTypeElement(componentType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   226
                        if (classNameDoc == null) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   227
                            throw new SignatureException(componentType);
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   228
                        }
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   229
                        else {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   230
                            String classname = classNameDoc.getQualifiedName().toString();
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   231
                            String newclassname = classname.replace('.', '/');
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   232
                            JVMSig += "L";
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   233
                            JVMSig += newclassname;
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   234
                            JVMSig += ";";
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   235
                        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                    }
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 10192
diff changeset
   237
                    break;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        return JVMSig;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    }
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   242
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   243
    int dimensions(TypeMirror t) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   244
        if (t.getKind() != TypeKind.ARRAY)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   245
            return 0;
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   246
        return 1 + dimensions(((ArrayType) t).getComponentType());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   247
    }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   248
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   249
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   250
    String qualifiedTypeName(TypeMirror type) {
10192
378321489bea 7025809: Provided new utility visitors supporting SourceVersion.RELEASE_8
darcy
parents: 7681
diff changeset
   251
        TypeVisitor<Name, Void> v = new SimpleTypeVisitor8<Name, Void>() {
3996
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   252
            @Override
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   253
            public Name visitArray(ArrayType t, Void p) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   254
                return t.getComponentType().accept(this, p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   255
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   256
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   257
            @Override
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   258
            public Name visitDeclared(DeclaredType t, Void p) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   259
                return ((TypeElement) t.asElement()).getQualifiedName();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   260
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   261
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   262
            @Override
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   263
            public Name visitPrimitive(PrimitiveType t, Void p) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   264
                return elems.getName(t.toString());
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   265
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   266
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   267
            @Override
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   268
            public Name visitNoType(NoType t, Void p) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   269
                if (t.getKind() == TypeKind.VOID)
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   270
                    return elems.getName("void");
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   271
                return defaultAction(t, p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   272
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   273
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   274
            @Override
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   275
            public Name visitTypeVariable(TypeVariable t, Void p) {
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   276
                return t.getUpperBound().accept(this, p);
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   277
            }
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   278
        };
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   279
        return v.visit(type).toString();
dc676a9093b3 6572945: javah should be written as an annotation processor, not a doclet
jjg
parents: 1789
diff changeset
   280
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
}