001    /*
002     * The JastAdd Extensible Java Compiler (http://jastadd.org) is covered
003     * by the modified BSD License. You should have received a copy of the
004     * modified BSD license with this compiler.
005     * 
006     * Copyright (c) 2005-2008, Torbjorn Ekman
007     * All rights reserved.
008     */
009    
010    aspect Arrays {
011      syn lazy int TypeDecl.dimension() = 0;
012      eq ArrayDecl.dimension() = componentType().dimension() + 1;
013      
014      // TypeDecl.elementType() - the ground type that the array is based on
015      syn lazy TypeDecl TypeDecl.elementType() = this;
016      eq ArrayDecl.elementType() = componentType().elementType();
017    
018      // TypeDecl.componentType() -  the elements in an array has this type
019      eq Program.getChild().componentType() = unknownType();
020      eq TypeDecl.arrayType().componentType() = this;
021      inh lazy TypeDecl TypeDecl.componentType();
022    
023      syn nta TypeDecl TypeDecl.arrayType() {
024        String name = name() + "[]";
025        TypeDecl typeDecl =
026          new ArrayDecl(
027            new Modifiers(new List().add(new Modifier("public"))),
028            name,
029            new Opt(typeObject().createQualifiedAccess()), // [SuperClassAccess]
030            new List().add(typeCloneable().createQualifiedAccess()).add(typeSerializable().createQualifiedAccess()), // Implements*
031            new List().add( // BodyDecl*
032              new FieldDeclaration(
033                new Modifiers(new List().add(new Modifier("public")).add(new Modifier("final"))),
034                new PrimitiveTypeAccess("int"),
035                "length",
036                new Opt() // [Init:Expr]
037              )).add(
038              new MethodDecl(
039                new Modifiers(new List().add(new Modifier("public"))),
040                typeObject().createQualifiedAccess(),
041                "clone",
042                new List(),
043                new List(),
044                new Opt(new Block())
045              )
046            )
047          );
048        return typeDecl;
049      }
050      inh TypeDecl TypeDecl.typeCloneable();
051      inh TypeDecl TypeDecl.typeSerializable();
052      
053      eq ArrayDecl.name() = fullName();
054      eq ArrayDecl.fullName() = getID();
055    
056      syn lazy String ArrayTypeAccess.getPackage() = getAccess().type().packageName();
057      syn lazy String ArrayTypeAccess.getID() = getAccess().type().name();
058    
059      public Access ArrayDecl.createQualifiedAccess() {
060        return new ArrayTypeAccess(componentType().createQualifiedAccess());
061      }
062    }