001 /*
002 * Copyright 2004-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.tools.apt.mirror.declaration;
027
028
029 import java.util.ArrayList;
030 import java.util.Collection;
031
032 import com.sun.mirror.declaration.*;
033 import com.sun.mirror.util.*;
034 import com.sun.tools.apt.mirror.AptEnv;
035 import com.sun.tools.javac.code.*;
036 import com.sun.tools.javac.code.Symbol.*;
037
038
039 /**
040 * Implementation of PackageDeclaration.
041 */
042
043 public class PackageDeclarationImpl extends DeclarationImpl
044 implements PackageDeclaration {
045
046 private PackageSymbol sym;
047
048
049 public PackageDeclarationImpl(AptEnv env, PackageSymbol sym) {
050 super(env, sym);
051 this.sym = sym;
052 }
053
054
055 /**
056 * Returns the qualified name.
057 */
058 public String toString() {
059 return getQualifiedName();
060 }
061
062 /**
063 * {@inheritDoc}
064 */
065 public String getQualifiedName() {
066 return sym.getQualifiedName().toString();
067 }
068
069 /**
070 * {@inheritDoc}
071 */
072 public Collection<ClassDeclaration> getClasses() {
073 return identityFilter.filter(getAllTypes(),
074 ClassDeclaration.class);
075 }
076
077 /**
078 * {@inheritDoc}
079 */
080 public Collection<EnumDeclaration> getEnums() {
081 return identityFilter.filter(getAllTypes(),
082 EnumDeclaration.class);
083 }
084
085 /**
086 * {@inheritDoc}
087 */
088 public Collection<InterfaceDeclaration> getInterfaces() {
089 return identityFilter.filter(getAllTypes(),
090 InterfaceDeclaration.class);
091 }
092
093 /**
094 * {@inheritDoc}
095 */
096 public Collection<AnnotationTypeDeclaration> getAnnotationTypes() {
097 return identityFilter.filter(getAllTypes(),
098 AnnotationTypeDeclaration.class);
099 }
100
101 /**
102 * {@inheritDoc}
103 */
104 public void accept(DeclarationVisitor v) {
105 v.visitPackageDeclaration(this);
106 }
107
108
109 // Cache of all top-level type declarations in this package.
110 private Collection<TypeDeclaration> allTypes = null;
111
112 /**
113 * Caches and returns all top-level type declarations in this package.
114 * Omits synthetic types.
115 */
116 private Collection<TypeDeclaration> getAllTypes() {
117 if (allTypes != null) {
118 return allTypes;
119 }
120 allTypes = new ArrayList<TypeDeclaration>();
121 for (Symbol s : getMembers(false)) {
122 allTypes.add(env.declMaker.getTypeDeclaration((ClassSymbol) s));
123 }
124 return allTypes;
125 }
126 }