1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core.jdom;
13 import net.sourceforge.phpdt.core.ICompilationUnit;
14 import net.sourceforge.phpdt.core.IJavaElement;
15 import net.sourceforge.phpdt.core.jdom.IDOMNode;
16 import net.sourceforge.phpdt.core.jdom.IDOMPackage;
17 import net.sourceforge.phpdt.internal.compiler.util.Util;
18 import net.sourceforge.phpdt.internal.core.util.CharArrayBuffer;
21 * DOMPackage provides an implementation of IDOMPackage.
26 class DOMPackage extends DOMNode implements IDOMPackage {
29 * Creates an empty PACKAGE node.
32 setMask(MASK_DETAILED_SOURCE_INDEXES, true);
36 * Creates a new simple PACKAGE document fragment on the given range of the
40 * the document containing this node's original contents
41 * @param sourceRange -
42 * a two element array of integers describing the entire
43 * inclusive source range of this node within its document.
44 * Contents start on and include the character at the first
45 * position. Contents end on and include the character at the
46 * last position. An array of -1's indicates this node's contents
47 * do not exist in the document.
49 * the identifier portion of the name of this node, or
50 * <code>null</code> if this node does not have a name
52 DOMPackage(char[] document, int[] sourceRange, String name) {
53 super(document, sourceRange, name, new int[] { -1, -1 });
54 setMask(MASK_DETAILED_SOURCE_INDEXES, false);
58 * Creates a new detailed PACKAGE document fragment on the given range of
62 * the document containing this node's original contents
63 * @param sourceRange -
64 * a two element array of integers describing the entire
65 * inclusive source range of this node within its document.
66 * Contents start on and include the character at the first
67 * position. Contents end on and include the character at the
68 * last position. An array of -1's indicates this node's contents
69 * do not exist in the document.
71 * the identifier portion of the name of this node, or
72 * <code>null</code> if this node does not have a name
74 * a two element array of integers describing the entire
75 * inclusive source range of this node's name within its
76 * document, including any array qualifiers that might
77 * immediately follow the name or -1's if this node does not have
80 DOMPackage(char[] document, int[] sourceRange, String name, int[] nameRange) {
81 super(document, sourceRange, name, nameRange);
82 setMask(MASK_DETAILED_SOURCE_INDEXES, true);
86 * @see DOMNode#appendFragmentedContents(CharArrayBuffer)
88 protected void appendFragmentedContents(CharArrayBuffer buffer) {
89 if (fNameRange[0] < 0) {
90 buffer.append("package ") //$NON-NLS-1$
91 .append(fName).append(';').append(Util.LINE_SEPARATOR)
92 .append(Util.LINE_SEPARATOR);
94 buffer.append(fDocument, fSourceRange[0],
95 fNameRange[0] - fSourceRange[0]).append(fName).append(
96 fDocument, fNameRange[1] + 1,
97 fSourceRange[1] - fNameRange[1]);
102 * @see IDOMNode#getContents()
104 public String getContents() {
108 return super.getContents();
113 * @see DOMNode#getDetailedNode()
115 // protected DOMNode getDetailedNode() {
116 // return (DOMNode)getFactory().createPackage(getContents());
119 * @see IDOMNode#getJavaElement
121 public IJavaElement getJavaElement(IJavaElement parent)
122 throws IllegalArgumentException {
123 if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
124 return ((ICompilationUnit) parent).getPackageDeclaration(getName());
126 throw new IllegalArgumentException(Util
127 .bind("element.illegalParent")); //$NON-NLS-1$
132 * @see IDOMNode#getNodeType()
134 public int getNodeType() {
135 return IDOMNode.PACKAGE;
141 protected DOMNode newDOMNode() {
142 return new DOMPackage();
146 * @see IDOMNode#setName
148 public void setName(String name) {
154 * @see IDOMNode#toString()
156 public String toString() {
157 return "PACKAGE: " + getName(); //$NON-NLS-1$