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.IJavaElement;
14 import net.sourceforge.phpdt.core.jdom.IDOMImport;
15 import net.sourceforge.phpdt.core.jdom.IDOMNode;
16 import net.sourceforge.phpdt.internal.compiler.util.Util;
17 import net.sourceforge.phpdt.internal.core.util.CharArrayBuffer;
20 * DOMImport provides an implementation of IDOMImport.
25 class DOMImport extends DOMNode implements IDOMImport {
27 * Indicates if this import is an on demand type import
29 protected boolean fOnDemand;
31 * Creates a new empty IMPORT node.
34 fName = "java.lang.*"; //$NON-NLS-1$
35 setMask(MASK_DETAILED_SOURCE_INDEXES, true);
38 * Creates a new detailed IMPORT document fragment on the given range of the document.
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
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 * @param nameRange - a two element array of integers describing the
50 * entire inclusive source range of this node's name within its document,
51 * including any array qualifiers that might immediately follow the name
52 * or -1's if this node does not have a name.
53 * @param onDemand - indicates if this import is an on demand style import
55 DOMImport(char[] document, int[] sourceRange, String name, int[] nameRange, boolean onDemand) {
56 super(document, sourceRange, name, nameRange);
58 setMask(MASK_DETAILED_SOURCE_INDEXES, true);
61 * Creates a new simple IMPORT document fragment on the given range of the document.
63 * @param document - the document containing this node's original contents
64 * @param sourceRange - a two element array of integers describing the
65 * entire inclusive source range of this node within its document.
66 * Contents start on and include the character at the first position.
67 * Contents end on and include the character at the last position.
68 * An array of -1's indicates this node's contents do not exist
70 * @param name - the identifier portion of the name of this node, or
71 * <code>null</code> if this node does not have a name
72 * @param onDemand - indicates if this import is an on demand style import
74 DOMImport(char[] document, int[] sourceRange, String name, boolean onDemand) {
75 this(document, sourceRange, name, new int[] {-1, -1}, onDemand);
77 setMask(MASK_DETAILED_SOURCE_INDEXES, false);
80 * @see DOMNode#appendFragmentedContents(CharArrayBuffer)
82 protected void appendFragmentedContents(CharArrayBuffer buffer) {
83 if (fNameRange[0] < 0) {
85 .append("include ") //$NON-NLS-1$
88 .append(Util.LINE_SEPARATOR);
90 buffer.append(fDocument, fSourceRange[0], fNameRange[0] - fSourceRange[0]);
91 //buffer.append(fDocument, fNameRange[0], fNameRange[1] - fNameRange[0] + 1);
93 buffer.append(fDocument, fNameRange[1] + 1, fSourceRange[1] - fNameRange[1]);
97 * @see IDOMNode#getContents()
99 public String getContents() {
103 return super.getContents();
107 * @see DOMNode#getDetailedNode()
109 //protected DOMNode getDetailedNode() {
110 // return (DOMNode)getFactory().createImport(getContents());
113 * @see IDOMNode#getJavaElement
115 public IJavaElement getJavaElement(IJavaElement parent) throws IllegalArgumentException {
116 // if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
117 // return ((ICompilationUnit)parent).getImport(getName());
119 throw new IllegalArgumentException(Util.bind("element.illegalParent")); //$NON-NLS-1$
123 * @see IDOMNode#getNodeType()
125 public int getNodeType() {
126 return IDOMNode.IMPORT;
129 * @see IDOMImport#isOnDemand()
131 public boolean isOnDemand() {
137 protected DOMNode newDOMNode() {
138 return new DOMImport();
141 * @see IDOMNode#setName(char[])
143 public void setName(String name) {
145 throw new IllegalArgumentException(Util.bind("element.nullName")); //$NON-NLS-1$
149 fOnDemand = name.endsWith(".*"); //$NON-NLS-1$
152 * @see IDOMNode#toString()
154 public String toString() {
155 return "IMPORT: " + getName(); //$NON-NLS-1$