001 /* Copyright (c) 2005-2008, Torbjorn Ekman 002 * All rights reserved. 003 * 004 * Redistribution and use in source and binary forms, with or without 005 * modification, are permitted provided that the following conditions are met: 006 * 007 * 1. Redistributions of source code must retain the above copyright notice, 008 * this list of conditions and the following disclaimer. 009 * 010 * 2. Redistributions in binary form must reproduce the above copyright notice, 011 * this list of conditions and the following disclaimer in the documentation 012 * and/or other materials provided with the distribution. 013 * 014 * 3. Neither the name of the copyright holder nor the names of its 015 * contributors may be used to endorse or promote products derived from this 016 * software without specific prior written permission. 017 * 018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 028 * POSSIBILITY OF SUCH DAMAGE. 029 */ 030 031 aspect Arrays { 032 syn lazy int TypeDecl.dimension() = 0; 033 eq ArrayDecl.dimension() = componentType().dimension() + 1; 034 035 // TypeDecl.elementType() - the ground type that the array is based on 036 syn lazy TypeDecl TypeDecl.elementType() = this; 037 eq ArrayDecl.elementType() = componentType().elementType(); 038 039 // TypeDecl.componentType() - the elements in an array has this type 040 eq Program.getChild().componentType() = unknownType(); 041 eq TypeDecl.arrayType().componentType() = this; 042 inh lazy TypeDecl TypeDecl.componentType(); 043 044 syn nta TypeDecl TypeDecl.arrayType() { 045 String name = name() + "[]"; 046 TypeDecl typeDecl = new ArrayDecl( 047 new Modifiers(new List().add(new Modifier("public"))), 048 name, 049 new Opt(typeObject().createQualifiedAccess()), // [SuperClass] 050 new List().add(typeCloneable().createQualifiedAccess()).add(typeSerializable().createQualifiedAccess()), // Implements* 051 new List().add( // BodyDecl* 052 new FieldDeclaration( 053 new Modifiers(new List().add(new Modifier("public")).add(new Modifier("final"))), 054 new PrimitiveTypeAccess("int"), 055 "length", 056 new Opt() // [Init:Expr] 057 )).add( 058 new MethodDecl( 059 new Modifiers(new List().add(new Modifier("public"))), 060 typeObject().createQualifiedAccess(), 061 "clone", 062 new List(), 063 new List(), 064 new Opt(new Block()) 065 ) 066 ) 067 ); 068 return typeDecl; 069 } 070 inh TypeDecl TypeDecl.typeCloneable(); 071 inh TypeDecl TypeDecl.typeSerializable(); 072 073 eq ArrayDecl.name() = fullName(); 074 eq ArrayDecl.fullName() = getID(); 075 076 syn lazy String ArrayTypeAccess.getPackage() = getAccess().type().packageName(); 077 syn lazy String ArrayTypeAccess.getID() = getAccess().type().name(); 078 079 public Access ArrayDecl.createQualifiedAccess() { 080 return new ArrayTypeAccess(componentType().createQualifiedAccess()); 081 } 082 }