KickJava   Java API By Example, From Geeks To Geeks.

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


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

29 class DOMPackage extends DOMNode implements IDOMPackage {
30
31 /**
32  * Creates an empty PACKAGE node.
33  */

34 DOMPackage() {
35     setMask(MASK_DETAILED_SOURCE_INDEXES, true);
36 }
37 /**
38  * Creates a new simple PACKAGE document fragment on the given range of the document.
39  *
40  * @param document - the document containing this node's original contents
41  * @param sourceRange - a two element array of integers describing the
42  * entire inclusive source range of this node within its document.
43  * Contents start on and include the character at the first position.
44  * Contents end on and include the character at the last position.
45  * An array of -1's indicates this node's contents do not exist
46  * in the document.
47  * @param name - the identifier portion of the name of this node, or
48  * <code>null</code> if this node does not have a name
49  */

50 DOMPackage(char[] document, int[] sourceRange, String JavaDoc name) {
51     super(document, sourceRange, name, new int[] {-1, -1});
52     setMask(MASK_DETAILED_SOURCE_INDEXES, false);
53 }
54 /**
55  * Creates a new detailed PACKAGE document fragment on the given range of the document.
56  *
57  * @param document - the document containing this node's original contents
58  * @param sourceRange - a two element array of integers describing the
59  * entire inclusive source range of this node within its document.
60  * Contents start on and include the character at the first position.
61  * Contents end on and include the character at the last position.
62  * An array of -1's indicates this node's contents do not exist
63  * in the document.
64  * @param name - the identifier portion of the name of this node, or
65  * <code>null</code> if this node does not have a name
66  * @param nameRange - a two element array of integers describing the
67  * entire inclusive source range of this node's name within its document,
68  * including any array qualifiers that might immediately follow the name
69  * or -1's if this node does not have a name.
70  */

71 DOMPackage(char[] document, int[] sourceRange, String JavaDoc name, int[] nameRange) {
72     super(document, sourceRange, name, nameRange);
73     setMask(MASK_DETAILED_SOURCE_INDEXES, true);
74 }
75 /**
76  * @see DOMNode#appendFragmentedContents(CharArrayBuffer)
77  */

78 protected void appendFragmentedContents(CharArrayBuffer buffer) {
79     if (fNameRange[0] < 0) {
80         String JavaDoc lineSeparator = Util.getLineSeparator(buffer.toString(), null);
81         buffer
82             .append("package ") //$NON-NLS-1$
83
.append(fName)
84             .append(';')
85             .append(lineSeparator)
86             .append(lineSeparator);
87     } else {
88         buffer
89             .append(fDocument, fSourceRange[0], fNameRange[0] - fSourceRange[0])
90             .append(fName)
91             .append(fDocument, fNameRange[1] + 1, fSourceRange[1] - fNameRange[1]);
92     }
93 }
94 /**
95  * @see IDOMNode#getContents()
96  */

97 public String JavaDoc getContents() {
98     if (fName == null) {
99         return null;
100     } else {
101         return super.getContents();
102     }
103 }
104 /**
105  * @see DOMNode#getDetailedNode()
106  */

107 protected DOMNode getDetailedNode() {
108     return (DOMNode)getFactory().createPackage(getContents());
109 }
110 /**
111  * @see IDOMNode#getJavaElement
112  */

113 public IJavaElement getJavaElement(IJavaElement parent) throws IllegalArgumentException JavaDoc {
114     if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
115         return ((ICompilationUnit)parent).getPackageDeclaration(getName());
116     } else {
117         throw new IllegalArgumentException JavaDoc(Messages.element_illegalParent);
118     }
119 }
120 /**
121  * @see IDOMNode#getNodeType()
122  */

123 public int getNodeType() {
124     return IDOMNode.PACKAGE;
125 }
126 /**
127  * @see DOMNode
128  */

129 protected DOMNode newDOMNode() {
130     return new DOMPackage();
131 }
132 /**
133  * @see IDOMNode#setName
134  */

135 public void setName(String JavaDoc name) {
136     becomeDetailed();
137     super.setName(name);
138 }
139 /**
140  * @see IDOMNode#toString()
141  */

142 public String JavaDoc toString() {
143     return "PACKAGE: " + getName(); //$NON-NLS-1$
144
}
145 }
146
Popular Tags