001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: package com.sun.codemodel;
021:
022: import java.util.Iterator;
023: import java.util.Collections;
024: import java.util.List;
025:
026: /**
027: * Array class.
028: *
029: * @author
030: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
031: */
032: final class JArrayClass extends JClass {
033:
034: // array component type
035: private final JType componentType;
036:
037: JArrayClass(JCodeModel owner, JType component) {
038: super (owner);
039: this .componentType = component;
040: }
041:
042: public String name() {
043: return componentType.name() + "[]";
044: }
045:
046: public String fullName() {
047: return componentType.fullName() + "[]";
048: }
049:
050: public String binaryName() {
051: return componentType.binaryName() + "[]";
052: }
053:
054: public void generate(JFormatter f) {
055: f.g(componentType).p("[]");
056: }
057:
058: public JPackage _package() {
059: return owner().rootPackage();
060: }
061:
062: public JClass _extends() {
063: return owner().ref(Object.class);
064: }
065:
066: public Iterator<JClass> _implements () {
067: return Collections.<JClass> emptyList().iterator();
068: }
069:
070: public boolean isInterface() {
071: return false;
072: }
073:
074: public boolean isAbstract() {
075: return false;
076: }
077:
078: public JType elementType() {
079: return componentType;
080: }
081:
082: public boolean isArray() {
083: return true;
084: }
085:
086: //
087: // Equality is based on value
088: //
089:
090: public boolean equals(Object obj) {
091: if (!(obj instanceof JArrayClass))
092: return false;
093:
094: if (componentType.equals(((JArrayClass) obj).componentType))
095: return true;
096:
097: return false;
098: }
099:
100: public int hashCode() {
101: return componentType.hashCode();
102: }
103:
104: protected JClass substituteParams(JTypeVar[] variables,
105: List<JClass> bindings) {
106: if (componentType.isPrimitive())
107: return this ;
108:
109: JClass c = ((JClass) componentType).substituteParams(variables,
110: bindings);
111: if (c == componentType)
112: return this ;
113:
114: return new JArrayClass(owner(), c);
115: }
116:
117: }
|