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);
35 * Creates a new simple PACKAGE document fragment on the given range of the document.
37 * @param document - the document containing this node's original contents
38 * @param sourceRange - a two element array of integers describing the
39 * entire inclusive source range of this node within its document.
40 * Contents start on and include the character at the first position.
41 * Contents end on and include the character at the last position.
42 * An array of -1's indicates this node's contents do not exist
44 * @param name - the identifier portion of the name of this node, or
45 * <code>null</code> if this node does not have a name
47 DOMPackage(char[] document, int[] sourceRange, String name) {
48 super(document, sourceRange, name, new int[] {-1, -1});
49 setMask(MASK_DETAILED_SOURCE_INDEXES, false);
52 * Creates a new detailed PACKAGE document fragment on the given range of the document.
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
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.
68 DOMPackage(char[] document, int[] sourceRange, String name, int[] nameRange) {
69 super(document, sourceRange, name, nameRange);
70 setMask(MASK_DETAILED_SOURCE_INDEXES, true);
73 * @see DOMNode#appendFragmentedContents(CharArrayBuffer)
75 protected void appendFragmentedContents(CharArrayBuffer buffer) {
76 if (fNameRange[0] < 0) {
78 .append("package ") //$NON-NLS-1$
81 .append(Util.LINE_SEPARATOR)
82 .append(Util.LINE_SEPARATOR);
85 .append(fDocument, fSourceRange[0], fNameRange[0] - fSourceRange[0])
87 .append(fDocument, fNameRange[1] + 1, fSourceRange[1] - fNameRange[1]);
91 * @see IDOMNode#getContents()
93 public String getContents() {
97 return super.getContents();
101 * @see DOMNode#getDetailedNode()
103 //protected DOMNode getDetailedNode() {
104 // return (DOMNode)getFactory().createPackage(getContents());
107 * @see IDOMNode#getJavaElement
109 public IJavaElement getJavaElement(IJavaElement parent) throws IllegalArgumentException {
110 if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
111 return ((ICompilationUnit)parent).getPackageDeclaration(getName());
113 throw new IllegalArgumentException(Util.bind("element.illegalParent")); //$NON-NLS-1$
117 * @see IDOMNode#getNodeType()
119 public int getNodeType() {
120 return IDOMNode.PACKAGE;
125 protected DOMNode newDOMNode() {
126 return new DOMPackage();
129 * @see IDOMNode#setName
131 public void setName(String name) {
136 * @see IDOMNode#toString()
138 public String toString() {
139 return "PACKAGE: " + getName(); //$NON-NLS-1$