KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > ImportDeclaration


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core;
12
13 import org.eclipse.core.runtime.Assert;
14 import org.eclipse.jdt.core.*;
15
16 /**
17  * Handle for an import declaration. Info object is a ImportDeclarationElementInfo.
18  * @see IImportDeclaration
19  */

20
21 public class ImportDeclaration extends SourceRefElement implements IImportDeclaration {
22
23     protected String JavaDoc name;
24     protected boolean isOnDemand;
25     
26 /**
27  * Constructs an ImportDeclaration in the given import container
28  * with the given name.
29  */

30 protected ImportDeclaration(ImportContainer parent, String JavaDoc name, boolean isOnDemand) {
31     super(parent);
32     this.name = name;
33     this.isOnDemand = isOnDemand;
34 }
35 public boolean equals(Object JavaDoc o) {
36     if (!(o instanceof ImportDeclaration)) return false;
37     return super.equals(o);
38 }
39 public String JavaDoc getElementName() {
40     if (this.isOnDemand)
41         return this.name + ".*"; //$NON-NLS-1$
42
return this.name;
43 }
44 public String JavaDoc getNameWithoutStar() {
45     return this.name;
46 }
47 /**
48  * @see IJavaElement
49  */

50 public int getElementType() {
51     return IMPORT_DECLARATION;
52 }
53 /**
54  * @see org.eclipse.jdt.core.IImportDeclaration#getFlags()
55  */

56 public int getFlags() throws JavaModelException {
57     ImportDeclarationElementInfo info = (ImportDeclarationElementInfo)getElementInfo();
58     return info.getModifiers();
59 }
60 /**
61  * @see JavaElement#getHandleMemento(StringBuffer)
62  * For import declarations, the handle delimiter is associated to the import container already
63  */

64 protected void getHandleMemento(StringBuffer JavaDoc buff) {
65     ((JavaElement)getParent()).getHandleMemento(buff);
66     escapeMementoName(buff, getElementName());
67     if (this.occurrenceCount > 1) {
68         buff.append(JEM_COUNT);
69         buff.append(this.occurrenceCount);
70     }
71 }
72 /**
73  * @see JavaElement#getHandleMemento()
74  */

75 protected char getHandleMementoDelimiter() {
76     // For import declarations, the handle delimiter is associated to the import container already
77
Assert.isTrue(false, "Should not be called"); //$NON-NLS-1$
78
return 0;
79 }
80 /*
81  * @see JavaElement#getPrimaryElement(boolean)
82  */

83 public IJavaElement getPrimaryElement(boolean checkOwner) {
84     CompilationUnit cu = (CompilationUnit)this.parent.getParent();
85     if (checkOwner && cu.isPrimary()) return this;
86     return cu.getImport(getElementName());
87 }
88 /**
89  * Returns true if the import is on-demand (ends with ".*")
90  */

91 public boolean isOnDemand() {
92     return this.isOnDemand;
93 }
94 /**
95  */

96 public String JavaDoc readableName() {
97
98     return null;
99 }
100 /**
101  * @private Debugging purposes
102  */

103 protected void toStringInfo(int tab, StringBuffer JavaDoc buffer, Object JavaDoc info, boolean showResolvedInfo) {
104     buffer.append(this.tabString(tab));
105     buffer.append("import "); //$NON-NLS-1$
106
toStringName(buffer);
107     if (info == null) {
108         buffer.append(" (not open)"); //$NON-NLS-1$
109
}
110 }
111 }
112
Popular Tags