KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > internal > declaration > PackageDeclarationImplNoBinding


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * tyeung@bea.com - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.apt.core.internal.declaration;
12
13 import java.lang.annotation.Annotation JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.Collections JavaDoc;
16
17 import org.eclipse.jdt.core.IPackageFragment;
18
19 import com.sun.mirror.declaration.AnnotationMirror;
20 import com.sun.mirror.declaration.AnnotationTypeDeclaration;
21 import com.sun.mirror.declaration.ClassDeclaration;
22 import com.sun.mirror.declaration.EnumDeclaration;
23 import com.sun.mirror.declaration.InterfaceDeclaration;
24 import com.sun.mirror.declaration.Modifier;
25 import com.sun.mirror.declaration.PackageDeclaration;
26 import com.sun.mirror.util.DeclarationVisitor;
27 import com.sun.mirror.util.SourcePosition;
28
29 /**
30  * For packages that have no binding. E.g. Packages with no
31  * classes, like "java.lang", or possibly "" (the default package).
32  */

33 public class PackageDeclarationImplNoBinding implements PackageDeclaration {
34     
35     private final IPackageFragment[] fragments;
36     
37     public PackageDeclarationImplNoBinding(final IPackageFragment[] fragments) {
38         this.fragments = fragments;
39     }
40
41     public String JavaDoc getQualifiedName() {
42         return fragments[0].getElementName();
43     }
44
45     public Collection JavaDoc<ClassDeclaration> getClasses() {
46         return Collections.emptyList();
47     }
48
49     public Collection JavaDoc<EnumDeclaration> getEnums() {
50         return Collections.emptyList();
51     }
52
53     public Collection JavaDoc<InterfaceDeclaration> getInterfaces() {
54         return Collections.emptyList();
55     }
56
57     public Collection JavaDoc<AnnotationTypeDeclaration> getAnnotationTypes() {
58         return Collections.emptyList();
59     }
60
61     public String JavaDoc getDocComment() {
62         // Packages have no comments
63
return null;
64     }
65
66     public Collection JavaDoc<AnnotationMirror> getAnnotationMirrors() {
67         return Collections.emptyList();
68     }
69
70     public <A extends Annotation JavaDoc> A getAnnotation(Class JavaDoc<A> arg0) {
71         return null;
72     }
73
74     public Collection JavaDoc<Modifier> getModifiers() {
75         // Packages do not have modifiers
76
return Collections.emptyList();
77     }
78
79     public String JavaDoc getSimpleName() {
80         String JavaDoc components = getQualifiedName();
81         int dotIndex = components.indexOf("."); //$NON-NLS-1$
82
if (dotIndex < 0)
83             return components;
84         return components.substring(dotIndex + 1);
85     }
86
87     public SourcePosition getPosition() {
88         // non-source, we do not have a source position
89
return null;
90     }
91
92     public void accept(final DeclarationVisitor visitor) {
93         visitor.visitDeclaration(this);
94         visitor.visitPackageDeclaration(this);
95     }
96
97 }
98
Popular Tags