001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.codemodel.internal;
027:
028: import java.util.Iterator;
029: import java.util.Collections;
030: import java.util.List;
031:
032: /**
033: * Array class.
034: *
035: * @author
036: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
037: */
038: final class JArrayClass extends JClass {
039:
040: // array component type
041: private final JType componentType;
042:
043: JArrayClass(JCodeModel owner, JType component) {
044: super (owner);
045: this .componentType = component;
046: }
047:
048: public String name() {
049: return componentType.name() + "[]";
050: }
051:
052: public String fullName() {
053: return componentType.fullName() + "[]";
054: }
055:
056: public String binaryName() {
057: return componentType.binaryName() + "[]";
058: }
059:
060: public void generate(JFormatter f) {
061: f.g(componentType).p("[]");
062: }
063:
064: public JPackage _package() {
065: return owner().rootPackage();
066: }
067:
068: public JClass _extends() {
069: return owner().ref(Object.class);
070: }
071:
072: public Iterator<JClass> _implements () {
073: return Collections.<JClass> emptyList().iterator();
074: }
075:
076: public boolean isInterface() {
077: return false;
078: }
079:
080: public boolean isAbstract() {
081: return false;
082: }
083:
084: public JType elementType() {
085: return componentType;
086: }
087:
088: public boolean isArray() {
089: return true;
090: }
091:
092: //
093: // Equality is based on value
094: //
095:
096: public boolean equals(Object obj) {
097: if (!(obj instanceof JArrayClass))
098: return false;
099:
100: if (componentType.equals(((JArrayClass) obj).componentType))
101: return true;
102:
103: return false;
104: }
105:
106: public int hashCode() {
107: return componentType.hashCode();
108: }
109:
110: protected JClass substituteParams(JTypeVar[] variables,
111: List<JClass> bindings) {
112: if (componentType.isPrimitive())
113: return this ;
114:
115: JClass c = ((JClass) componentType).substituteParams(variables,
116: bindings);
117: if (c == componentType)
118: return this ;
119:
120: return new JArrayClass(owner(), c);
121: }
122:
123: }
|