KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > jdom > DOMImport


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.jdom;
12
13 import org.eclipse.jdt.core.Flags;
14 import org.eclipse.jdt.core.ICompilationUnit;
15 import org.eclipse.jdt.core.IJavaElement;
16 import org.eclipse.jdt.core.jdom.*;
17 import org.eclipse.jdt.internal.core.util.Messages;
18 import org.eclipse.jdt.internal.core.util.CharArrayBuffer;
19 import org.eclipse.jdt.internal.core.util.Util;
20
21 /**
22  * DOMImport provides an implementation of IDOMImport.
23  *
24  * @see IDOMImport
25  * @see DOMNode
26  * @deprecated The JDOM was made obsolete by the addition in 2.0 of the more
27  * powerful, fine-grained DOM/AST API found in the
28  * org.eclipse.jdt.core.dom package.
29  */

30 // TODO (jerome) - add implementation support for 1.5 features
31
class DOMImport extends DOMNode implements IDOMImport {
32     
33     /**
34      * Indicates if this import is an on demand type import
35      */

36     protected boolean fOnDemand;
37     
38     /**
39      * Modifiers for this import.
40      * @since 3.0
41      */

42     protected int fFlags = Flags.AccDefault;
43     
44 /**
45  * Creates a new empty IMPORT node.
46  */

47 DOMImport() {
48     fName = "java.lang.*"; //$NON-NLS-1$
49
setMask(MASK_DETAILED_SOURCE_INDEXES, true);
50 }
51 /**
52  * Creates a new detailed IMPORT document fragment on the given range of the document.
53  *
54  * @param document - the document containing this node's original contents
55  * @param sourceRange - a two element array of integers describing the
56  * entire inclusive source range of this node within its document.
57  * Contents start on and include the character at the first position.
58  * Contents end on and include the character at the last position.
59  * An array of -1's indicates this node's contents do not exist
60  * in the document.
61  * @param name - the identifier portion of the name of this node, or
62  * <code>null</code> if this node does not have a name
63  * @param nameRange - a two element array of integers describing the
64  * entire inclusive source range of this node's name within its document,
65  * including any array qualifiers that might immediately follow the name
66  * or -1's if this node does not have a name.
67  * @param onDemand - indicates if this import is an on demand style import
68  */

69 DOMImport(char[] document, int[] sourceRange, String JavaDoc name, int[] nameRange, boolean onDemand, int modifiers) {
70     super(document, sourceRange, name, nameRange);
71     fOnDemand = onDemand;
72     fFlags = modifiers;
73     setMask(MASK_DETAILED_SOURCE_INDEXES, true);
74 }
75 /**
76  * Creates a new simple IMPORT document fragment on the given range of the document.
77  *
78  * @param document - the document containing this node's original contents
79  * @param sourceRange - a two element array of integers describing the
80  * entire inclusive source range of this node within its document.
81  * Contents start on and include the character at the first position.
82  * Contents end on and include the character at the last position.
83  * An array of -1's indicates this node's contents do not exist
84  * in the document.
85  * @param name - the identifier portion of the name of this node, or
86  * <code>null</code> if this node does not have a name
87  * @param onDemand - indicates if this import is an on demand style import
88  */

89 DOMImport(char[] document, int[] sourceRange, String JavaDoc name, boolean onDemand, int modifiers) {
90     this(document, sourceRange, name, new int[] {-1, -1}, onDemand, modifiers);
91     fOnDemand = onDemand;
92     setMask(MASK_DETAILED_SOURCE_INDEXES, false);
93 }
94 /**
95  * @see DOMNode#appendFragmentedContents(CharArrayBuffer)
96  */

97 protected void appendFragmentedContents(CharArrayBuffer buffer) {
98     if (fNameRange[0] < 0) {
99         buffer
100             .append("import ") //$NON-NLS-1$
101
.append(fName)
102             .append(';')
103             .append(Util.getLineSeparator(buffer.toString(), null));
104     } else {
105         buffer.append(fDocument, fSourceRange[0], fNameRange[0] - fSourceRange[0]);
106         //buffer.append(fDocument, fNameRange[0], fNameRange[1] - fNameRange[0] + 1);
107
buffer.append(fName);
108         buffer.append(fDocument, fNameRange[1] + 1, fSourceRange[1] - fNameRange[1]);
109     }
110 }
111 /**
112  * @see IDOMNode#getContents()
113  */

114 public String JavaDoc getContents() {
115     if (fName == null) {
116         return null;
117     } else {
118         return super.getContents();
119     }
120 }
121 /**
122  * @see DOMNode#getDetailedNode()
123  */

124 protected DOMNode getDetailedNode() {
125     return (DOMNode)getFactory().createImport(getContents());
126 }
127 /**
128  * @see IDOMNode#getJavaElement
129  */

130 public IJavaElement getJavaElement(IJavaElement parent) throws IllegalArgumentException JavaDoc {
131     if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
132         return ((ICompilationUnit)parent).getImport(getName());
133     } else {
134         throw new IllegalArgumentException JavaDoc(Messages.element_illegalParent);
135     }
136 }
137 /**
138  * @see IDOMNode#getNodeType()
139  */

140 public int getNodeType() {
141     return IDOMNode.IMPORT;
142 }
143 /**
144  * @see IDOMImport#isOnDemand()
145  */

146 public boolean isOnDemand() {
147     return fOnDemand;
148 }
149 /**
150  * @see DOMNode
151  */

152 protected DOMNode newDOMNode() {
153     return new DOMImport();
154 }
155 /**
156  * @see IDOMNode#setName(String)
157  */

158 public void setName(String JavaDoc name) {
159     if (name == null) {
160         throw new IllegalArgumentException JavaDoc(Messages.element_nullName);
161     }
162     becomeDetailed();
163     super.setName(name);
164     fOnDemand = name.endsWith(".*"); //$NON-NLS-1$
165
}
166 /**
167  * @see IDOMNode#toString()
168  */

169 public String JavaDoc toString() {
170     return "IMPORT: " + getName(); //$NON-NLS-1$
171
}
172
173 /**
174  * @see IDOMImport#getFlags()
175  * @since 3.0
176  */

177 public int getFlags() {
178     return this.fFlags;
179 }
180
181 /**
182  * @see IDOMImport#setFlags(int)
183  * @since 3.0
184  */

185 public void setFlags(int flags) {
186     this.fFlags = flags;
187 }
188 }
189
Popular Tags