jaxws/src/share/classes/com/sun/codemodel/internal/JNarrowedClass.java
author tonyp
Wed, 19 Aug 2009 12:53:25 -0400
changeset 3691 c84b8483cd2c
parent 2678 57cf2a1c1a05
permissions -rw-r--r--
6871111: G1: remove the concurrent overhead tracker Summary: Removing the concurrent overhead tracker from G1, along with the GC overhead reporter and the G1AccountConcurrentOverhead (both of which rely on the the concurrent overhead tracker). Reviewed-by: iveresov, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
474761f14bca Initial load
duke
parents:
diff changeset
     1
/*
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
8
474761f14bca Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
474761f14bca Initial load
duke
parents:
diff changeset
     4
 *
474761f14bca Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
474761f14bca Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
474761f14bca Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
474761f14bca Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
474761f14bca Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
474761f14bca Initial load
duke
parents:
diff changeset
    10
 *
474761f14bca Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
474761f14bca Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
474761f14bca Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
474761f14bca Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
474761f14bca Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
474761f14bca Initial load
duke
parents:
diff changeset
    16
 *
474761f14bca Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
474761f14bca Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
474761f14bca Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
474761f14bca Initial load
duke
parents:
diff changeset
    20
 *
474761f14bca Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
474761f14bca Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
474761f14bca Initial load
duke
parents:
diff changeset
    23
 * have any questions.
474761f14bca Initial load
duke
parents:
diff changeset
    24
 */
474761f14bca Initial load
duke
parents:
diff changeset
    25
package com.sun.codemodel.internal;
474761f14bca Initial load
duke
parents:
diff changeset
    26
474761f14bca Initial load
duke
parents:
diff changeset
    27
import java.util.Iterator;
474761f14bca Initial load
duke
parents:
diff changeset
    28
import java.util.List;
474761f14bca Initial load
duke
parents:
diff changeset
    29
import java.util.Collections;
474761f14bca Initial load
duke
parents:
diff changeset
    30
import java.util.ArrayList;
474761f14bca Initial load
duke
parents:
diff changeset
    31
474761f14bca Initial load
duke
parents:
diff changeset
    32
/**
474761f14bca Initial load
duke
parents:
diff changeset
    33
 * Represents X<Y>.
474761f14bca Initial load
duke
parents:
diff changeset
    34
 *
474761f14bca Initial load
duke
parents:
diff changeset
    35
 * TODO: consider separating the decl and the use.
474761f14bca Initial load
duke
parents:
diff changeset
    36
 *
474761f14bca Initial load
duke
parents:
diff changeset
    37
 * @author
474761f14bca Initial load
duke
parents:
diff changeset
    38
 *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
474761f14bca Initial load
duke
parents:
diff changeset
    39
 */
474761f14bca Initial load
duke
parents:
diff changeset
    40
class JNarrowedClass extends JClass {
474761f14bca Initial load
duke
parents:
diff changeset
    41
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    42
     * A generic class with type parameters.
474761f14bca Initial load
duke
parents:
diff changeset
    43
     */
474761f14bca Initial load
duke
parents:
diff changeset
    44
    final JClass basis;
474761f14bca Initial load
duke
parents:
diff changeset
    45
    /**
474761f14bca Initial load
duke
parents:
diff changeset
    46
     * Arguments to those parameters.
474761f14bca Initial load
duke
parents:
diff changeset
    47
     */
474761f14bca Initial load
duke
parents:
diff changeset
    48
    private final List<JClass> args;
474761f14bca Initial load
duke
parents:
diff changeset
    49
474761f14bca Initial load
duke
parents:
diff changeset
    50
    JNarrowedClass(JClass basis, JClass arg) {
474761f14bca Initial load
duke
parents:
diff changeset
    51
        this(basis,Collections.singletonList(arg));
474761f14bca Initial load
duke
parents:
diff changeset
    52
    }
474761f14bca Initial load
duke
parents:
diff changeset
    53
474761f14bca Initial load
duke
parents:
diff changeset
    54
    JNarrowedClass(JClass basis, List<JClass> args) {
474761f14bca Initial load
duke
parents:
diff changeset
    55
        super(basis.owner());
474761f14bca Initial load
duke
parents:
diff changeset
    56
        this.basis = basis;
474761f14bca Initial load
duke
parents:
diff changeset
    57
        assert !(basis instanceof JNarrowedClass);
474761f14bca Initial load
duke
parents:
diff changeset
    58
        this.args = args;
474761f14bca Initial load
duke
parents:
diff changeset
    59
    }
474761f14bca Initial load
duke
parents:
diff changeset
    60
474761f14bca Initial load
duke
parents:
diff changeset
    61
    public JClass narrow( JClass clazz ) {
474761f14bca Initial load
duke
parents:
diff changeset
    62
        List<JClass> newArgs = new ArrayList<JClass>(args);
474761f14bca Initial load
duke
parents:
diff changeset
    63
        newArgs.add(clazz);
474761f14bca Initial load
duke
parents:
diff changeset
    64
        return new JNarrowedClass(basis,newArgs);
474761f14bca Initial load
duke
parents:
diff changeset
    65
    }
474761f14bca Initial load
duke
parents:
diff changeset
    66
474761f14bca Initial load
duke
parents:
diff changeset
    67
    public JClass narrow( JClass... clazz ) {
474761f14bca Initial load
duke
parents:
diff changeset
    68
        List<JClass> newArgs = new ArrayList<JClass>(args);
474761f14bca Initial load
duke
parents:
diff changeset
    69
        for (JClass c : clazz)
474761f14bca Initial load
duke
parents:
diff changeset
    70
            newArgs.add(c);
474761f14bca Initial load
duke
parents:
diff changeset
    71
        return new JNarrowedClass(basis,newArgs);
474761f14bca Initial load
duke
parents:
diff changeset
    72
    }
474761f14bca Initial load
duke
parents:
diff changeset
    73
474761f14bca Initial load
duke
parents:
diff changeset
    74
    public String name() {
474761f14bca Initial load
duke
parents:
diff changeset
    75
        StringBuffer buf = new StringBuffer();
474761f14bca Initial load
duke
parents:
diff changeset
    76
        buf.append(basis.name());
474761f14bca Initial load
duke
parents:
diff changeset
    77
        buf.append('<');
474761f14bca Initial load
duke
parents:
diff changeset
    78
        boolean first = true;
474761f14bca Initial load
duke
parents:
diff changeset
    79
        for (JClass c : args) {
474761f14bca Initial load
duke
parents:
diff changeset
    80
            if(first)
474761f14bca Initial load
duke
parents:
diff changeset
    81
                first = false;
474761f14bca Initial load
duke
parents:
diff changeset
    82
            else
474761f14bca Initial load
duke
parents:
diff changeset
    83
                buf.append(',');
474761f14bca Initial load
duke
parents:
diff changeset
    84
            buf.append(c.name());
474761f14bca Initial load
duke
parents:
diff changeset
    85
        }
474761f14bca Initial load
duke
parents:
diff changeset
    86
        buf.append('>');
474761f14bca Initial load
duke
parents:
diff changeset
    87
        return buf.toString();
474761f14bca Initial load
duke
parents:
diff changeset
    88
    }
474761f14bca Initial load
duke
parents:
diff changeset
    89
474761f14bca Initial load
duke
parents:
diff changeset
    90
    public String fullName() {
474761f14bca Initial load
duke
parents:
diff changeset
    91
        StringBuilder buf = new StringBuilder();
474761f14bca Initial load
duke
parents:
diff changeset
    92
        buf.append(basis.fullName());
474761f14bca Initial load
duke
parents:
diff changeset
    93
        buf.append('<');
474761f14bca Initial load
duke
parents:
diff changeset
    94
        boolean first = true;
474761f14bca Initial load
duke
parents:
diff changeset
    95
        for (JClass c : args) {
474761f14bca Initial load
duke
parents:
diff changeset
    96
            if(first)
474761f14bca Initial load
duke
parents:
diff changeset
    97
                first = false;
474761f14bca Initial load
duke
parents:
diff changeset
    98
            else
474761f14bca Initial load
duke
parents:
diff changeset
    99
                buf.append(',');
474761f14bca Initial load
duke
parents:
diff changeset
   100
            buf.append(c.fullName());
474761f14bca Initial load
duke
parents:
diff changeset
   101
        }
474761f14bca Initial load
duke
parents:
diff changeset
   102
        buf.append('>');
474761f14bca Initial load
duke
parents:
diff changeset
   103
        return buf.toString();
474761f14bca Initial load
duke
parents:
diff changeset
   104
    }
474761f14bca Initial load
duke
parents:
diff changeset
   105
474761f14bca Initial load
duke
parents:
diff changeset
   106
    public String binaryName() {
474761f14bca Initial load
duke
parents:
diff changeset
   107
        StringBuilder buf = new StringBuilder();
474761f14bca Initial load
duke
parents:
diff changeset
   108
        buf.append(basis.binaryName());
474761f14bca Initial load
duke
parents:
diff changeset
   109
        buf.append('<');
474761f14bca Initial load
duke
parents:
diff changeset
   110
        boolean first = true;
474761f14bca Initial load
duke
parents:
diff changeset
   111
        for (JClass c : args) {
474761f14bca Initial load
duke
parents:
diff changeset
   112
            if(first)
474761f14bca Initial load
duke
parents:
diff changeset
   113
                first = false;
474761f14bca Initial load
duke
parents:
diff changeset
   114
            else
474761f14bca Initial load
duke
parents:
diff changeset
   115
                buf.append(',');
474761f14bca Initial load
duke
parents:
diff changeset
   116
            buf.append(c.binaryName());
474761f14bca Initial load
duke
parents:
diff changeset
   117
        }
474761f14bca Initial load
duke
parents:
diff changeset
   118
        buf.append('>');
474761f14bca Initial load
duke
parents:
diff changeset
   119
        return buf.toString();
474761f14bca Initial load
duke
parents:
diff changeset
   120
    }
474761f14bca Initial load
duke
parents:
diff changeset
   121
474761f14bca Initial load
duke
parents:
diff changeset
   122
    public void generate(JFormatter f) {
474761f14bca Initial load
duke
parents:
diff changeset
   123
        f.t(basis).p('<').g(args).p(JFormatter.CLOSE_TYPE_ARGS);
474761f14bca Initial load
duke
parents:
diff changeset
   124
    }
474761f14bca Initial load
duke
parents:
diff changeset
   125
474761f14bca Initial load
duke
parents:
diff changeset
   126
    @Override
474761f14bca Initial load
duke
parents:
diff changeset
   127
    void printLink(JFormatter f) {
474761f14bca Initial load
duke
parents:
diff changeset
   128
        basis.printLink(f);
474761f14bca Initial load
duke
parents:
diff changeset
   129
        f.p("{@code <}");
474761f14bca Initial load
duke
parents:
diff changeset
   130
        boolean first = true;
474761f14bca Initial load
duke
parents:
diff changeset
   131
        for( JClass c : args ) {
474761f14bca Initial load
duke
parents:
diff changeset
   132
            if(first)
474761f14bca Initial load
duke
parents:
diff changeset
   133
                first = false;
474761f14bca Initial load
duke
parents:
diff changeset
   134
            else
474761f14bca Initial load
duke
parents:
diff changeset
   135
                f.p(',');
474761f14bca Initial load
duke
parents:
diff changeset
   136
            c.printLink(f);
474761f14bca Initial load
duke
parents:
diff changeset
   137
        }
474761f14bca Initial load
duke
parents:
diff changeset
   138
        f.p("{@code >}");
474761f14bca Initial load
duke
parents:
diff changeset
   139
    }
474761f14bca Initial load
duke
parents:
diff changeset
   140
474761f14bca Initial load
duke
parents:
diff changeset
   141
    public JPackage _package() {
474761f14bca Initial load
duke
parents:
diff changeset
   142
        return basis._package();
474761f14bca Initial load
duke
parents:
diff changeset
   143
    }
474761f14bca Initial load
duke
parents:
diff changeset
   144
474761f14bca Initial load
duke
parents:
diff changeset
   145
    public JClass _extends() {
474761f14bca Initial load
duke
parents:
diff changeset
   146
        JClass base = basis._extends();
474761f14bca Initial load
duke
parents:
diff changeset
   147
        if(base==null)  return base;
474761f14bca Initial load
duke
parents:
diff changeset
   148
        return base.substituteParams(basis.typeParams(),args);
474761f14bca Initial load
duke
parents:
diff changeset
   149
    }
474761f14bca Initial load
duke
parents:
diff changeset
   150
474761f14bca Initial load
duke
parents:
diff changeset
   151
    public Iterator<JClass> _implements() {
474761f14bca Initial load
duke
parents:
diff changeset
   152
        return new Iterator<JClass>() {
474761f14bca Initial load
duke
parents:
diff changeset
   153
            private final Iterator<JClass> core = basis._implements();
474761f14bca Initial load
duke
parents:
diff changeset
   154
            public void remove() {
474761f14bca Initial load
duke
parents:
diff changeset
   155
                core.remove();
474761f14bca Initial load
duke
parents:
diff changeset
   156
            }
474761f14bca Initial load
duke
parents:
diff changeset
   157
            public JClass next() {
474761f14bca Initial load
duke
parents:
diff changeset
   158
                return core.next().substituteParams(basis.typeParams(),args);
474761f14bca Initial load
duke
parents:
diff changeset
   159
            }
474761f14bca Initial load
duke
parents:
diff changeset
   160
            public boolean hasNext() {
474761f14bca Initial load
duke
parents:
diff changeset
   161
                return core.hasNext();
474761f14bca Initial load
duke
parents:
diff changeset
   162
            }
474761f14bca Initial load
duke
parents:
diff changeset
   163
        };
474761f14bca Initial load
duke
parents:
diff changeset
   164
    }
474761f14bca Initial load
duke
parents:
diff changeset
   165
474761f14bca Initial load
duke
parents:
diff changeset
   166
    public JClass erasure() {
474761f14bca Initial load
duke
parents:
diff changeset
   167
        return basis;
474761f14bca Initial load
duke
parents:
diff changeset
   168
    }
474761f14bca Initial load
duke
parents:
diff changeset
   169
474761f14bca Initial load
duke
parents:
diff changeset
   170
    public boolean isInterface() {
474761f14bca Initial load
duke
parents:
diff changeset
   171
        return basis.isInterface();
474761f14bca Initial load
duke
parents:
diff changeset
   172
    }
474761f14bca Initial load
duke
parents:
diff changeset
   173
474761f14bca Initial load
duke
parents:
diff changeset
   174
    public boolean isAbstract() {
474761f14bca Initial load
duke
parents:
diff changeset
   175
        return basis.isAbstract();
474761f14bca Initial load
duke
parents:
diff changeset
   176
    }
474761f14bca Initial load
duke
parents:
diff changeset
   177
474761f14bca Initial load
duke
parents:
diff changeset
   178
    public boolean isArray() {
474761f14bca Initial load
duke
parents:
diff changeset
   179
        return false;
474761f14bca Initial load
duke
parents:
diff changeset
   180
    }
474761f14bca Initial load
duke
parents:
diff changeset
   181
474761f14bca Initial load
duke
parents:
diff changeset
   182
474761f14bca Initial load
duke
parents:
diff changeset
   183
    //
474761f14bca Initial load
duke
parents:
diff changeset
   184
    // Equality is based on value
474761f14bca Initial load
duke
parents:
diff changeset
   185
    //
474761f14bca Initial load
duke
parents:
diff changeset
   186
474761f14bca Initial load
duke
parents:
diff changeset
   187
    public boolean equals(Object obj) {
474761f14bca Initial load
duke
parents:
diff changeset
   188
        if(!(obj instanceof JNarrowedClass))   return false;
474761f14bca Initial load
duke
parents:
diff changeset
   189
        return fullName().equals(((JClass)obj).fullName());
474761f14bca Initial load
duke
parents:
diff changeset
   190
    }
474761f14bca Initial load
duke
parents:
diff changeset
   191
474761f14bca Initial load
duke
parents:
diff changeset
   192
    public int hashCode() {
474761f14bca Initial load
duke
parents:
diff changeset
   193
        return fullName().hashCode();
474761f14bca Initial load
duke
parents:
diff changeset
   194
    }
474761f14bca Initial load
duke
parents:
diff changeset
   195
474761f14bca Initial load
duke
parents:
diff changeset
   196
    protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings) {
474761f14bca Initial load
duke
parents:
diff changeset
   197
        JClass b = basis.substituteParams(variables,bindings);
474761f14bca Initial load
duke
parents:
diff changeset
   198
        boolean different = b!=basis;
474761f14bca Initial load
duke
parents:
diff changeset
   199
474761f14bca Initial load
duke
parents:
diff changeset
   200
        List<JClass> clazz = new ArrayList<JClass>(args.size());
474761f14bca Initial load
duke
parents:
diff changeset
   201
        for( int i=0; i<clazz.size(); i++ ) {
474761f14bca Initial load
duke
parents:
diff changeset
   202
            JClass c = args.get(i).substituteParams(variables,bindings);
474761f14bca Initial load
duke
parents:
diff changeset
   203
            clazz.set(i,c);
474761f14bca Initial load
duke
parents:
diff changeset
   204
            different |= c != args.get(i);
474761f14bca Initial load
duke
parents:
diff changeset
   205
        }
474761f14bca Initial load
duke
parents:
diff changeset
   206
474761f14bca Initial load
duke
parents:
diff changeset
   207
        if(different)
474761f14bca Initial load
duke
parents:
diff changeset
   208
            return new JNarrowedClass(b,clazz);
474761f14bca Initial load
duke
parents:
diff changeset
   209
        else
474761f14bca Initial load
duke
parents:
diff changeset
   210
            return this;
474761f14bca Initial load
duke
parents:
diff changeset
   211
    }
474761f14bca Initial load
duke
parents:
diff changeset
   212
474761f14bca Initial load
duke
parents:
diff changeset
   213
    public List<JClass> getTypeParameters() {
474761f14bca Initial load
duke
parents:
diff changeset
   214
        return args;
474761f14bca Initial load
duke
parents:
diff changeset
   215
    }
474761f14bca Initial load
duke
parents:
diff changeset
   216
}