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;
32 * Creates a new empty IMPORT node.
35 fName = "java.lang.*"; //$NON-NLS-1$
36 setMask(MASK_DETAILED_SOURCE_INDEXES, true);
40 * Creates a new detailed IMPORT document fragment on the given range of the
44 * the document containing this node's original contents
45 * @param sourceRange -
46 * a two element array of integers describing the entire
47 * inclusive source range of this node within its document.
48 * Contents start on and include the character at the first
49 * position. Contents end on and include the character at the
50 * last position. An array of -1's indicates this node's contents
51 * do not exist in the document.
53 * the identifier portion of the name of this node, or
54 * <code>null</code> if this node does not have a name
56 * a two element array of integers describing the entire
57 * inclusive source range of this node's name within its
58 * document, including any array qualifiers that might
59 * immediately follow the name or -1's if this node does not have
62 * indicates if this import is an on demand style import
64 DOMImport(char[] document, int[] sourceRange, String name, int[] nameRange,
66 super(document, sourceRange, name, nameRange);
68 setMask(MASK_DETAILED_SOURCE_INDEXES, true);
72 * Creates a new simple IMPORT document fragment on the given range of the
76 * the document containing this node's original contents
77 * @param sourceRange -
78 * a two element array of integers describing the entire
79 * inclusive source range of this node within its document.
80 * Contents start on and include the character at the first
81 * position. Contents end on and include the character at the
82 * last position. An array of -1's indicates this node's contents
83 * do not exist in the document.
85 * the identifier portion of the name of this node, or
86 * <code>null</code> if this node does not have a name
88 * indicates if this import is an on demand style import
90 DOMImport(char[] document, int[] sourceRange, String name, boolean onDemand) {
91 this(document, sourceRange, name, new int[] { -1, -1 }, onDemand);
93 setMask(MASK_DETAILED_SOURCE_INDEXES, false);
97 * @see DOMNode#appendFragmentedContents(CharArrayBuffer)
99 protected void appendFragmentedContents(CharArrayBuffer buffer) {
100 if (fNameRange[0] < 0) {
101 buffer.append("include ") //$NON-NLS-1$
102 .append(fName).append(';').append(Util.LINE_SEPARATOR);
104 buffer.append(fDocument, fSourceRange[0], fNameRange[0]
106 // buffer.append(fDocument, fNameRange[0], fNameRange[1] -
107 // fNameRange[0] + 1);
108 buffer.append(fName);
109 buffer.append(fDocument, fNameRange[1] + 1, fSourceRange[1]
115 * @see IDOMNode#getContents()
117 public String getContents() {
121 return super.getContents();
126 * @see DOMNode#getDetailedNode()
128 // protected DOMNode getDetailedNode() {
129 // return (DOMNode)getFactory().createImport(getContents());
132 * @see IDOMNode#getJavaElement
134 public IJavaElement getJavaElement(IJavaElement parent)
135 throws IllegalArgumentException {
136 // if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
137 // return ((ICompilationUnit)parent).getImport(getName());
139 throw new IllegalArgumentException(Util.bind("element.illegalParent")); //$NON-NLS-1$
144 * @see IDOMNode#getNodeType()
146 public int getNodeType() {
147 return IDOMNode.IMPORT;
151 * @see IDOMImport#isOnDemand()
153 public boolean isOnDemand() {
160 protected DOMNode newDOMNode() {
161 return new DOMImport();
165 * @see IDOMNode#setName(char[])
167 public void setName(String name) {
169 throw new IllegalArgumentException(Util.bind("element.nullName")); //$NON-NLS-1$
173 fOnDemand = name.endsWith(".*"); //$NON-NLS-1$
177 * @see IDOMNode#toString()
179 public String toString() {
180 return "IMPORT: " + getName(); //$NON-NLS-1$