jaxws/src/share/jaxws_classes/com/sun/codemodel/internal/JArrayClass.java
changeset 12009 4abb694f273a
child 22678 ac1ea46be942
equal deleted inserted replaced
11943:16ba58282d11 12009:4abb694f273a
       
     1 /*
       
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package com.sun.codemodel.internal;
       
    27 
       
    28 import java.util.Iterator;
       
    29 import java.util.Collections;
       
    30 import java.util.List;
       
    31 
       
    32 /**
       
    33  * Array class.
       
    34  *
       
    35  * @author
       
    36  *      Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
       
    37  */
       
    38 final class JArrayClass extends JClass {
       
    39 
       
    40     // array component type
       
    41     private final JType componentType;
       
    42 
       
    43 
       
    44     JArrayClass( JCodeModel owner, JType component ) {
       
    45         super(owner);
       
    46         this.componentType = component;
       
    47     }
       
    48 
       
    49 
       
    50     public String name() {
       
    51         return componentType.name()+"[]";
       
    52     }
       
    53 
       
    54     public String fullName() {
       
    55         return componentType.fullName()+"[]";
       
    56     }
       
    57 
       
    58     public String binaryName() {
       
    59         return componentType.binaryName()+"[]";
       
    60     }
       
    61 
       
    62     public void generate(JFormatter f) {
       
    63         f.g(componentType).p("[]");
       
    64     }
       
    65 
       
    66     public JPackage _package() {
       
    67         return owner().rootPackage();
       
    68     }
       
    69 
       
    70     public JClass _extends() {
       
    71         return owner().ref(Object.class);
       
    72     }
       
    73 
       
    74     public Iterator<JClass> _implements() {
       
    75         return Collections.<JClass>emptyList().iterator();
       
    76     }
       
    77 
       
    78     public boolean isInterface() {
       
    79         return false;
       
    80     }
       
    81 
       
    82     public boolean isAbstract() {
       
    83         return false;
       
    84     }
       
    85 
       
    86     public JType elementType() {
       
    87         return componentType;
       
    88     }
       
    89 
       
    90     public boolean isArray() {
       
    91         return true;
       
    92     }
       
    93 
       
    94 
       
    95     //
       
    96     // Equality is based on value
       
    97     //
       
    98 
       
    99     public boolean equals(Object obj) {
       
   100         if(!(obj instanceof JArrayClass))   return false;
       
   101 
       
   102         if( componentType.equals( ((JArrayClass)obj).componentType ) )
       
   103             return true;
       
   104 
       
   105         return false;
       
   106     }
       
   107 
       
   108     public int hashCode() {
       
   109         return componentType.hashCode();
       
   110     }
       
   111 
       
   112     protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings) {
       
   113         if( componentType.isPrimitive() )
       
   114             return this;
       
   115 
       
   116         JClass c = ((JClass)componentType).substituteParams(variables,bindings);
       
   117         if(c==componentType)
       
   118             return this;
       
   119 
       
   120         return new JArrayClass(owner(),c);
       
   121     }
       
   122 
       
   123 }