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.env.ICompilationUnit;
 
  17 import net.sourceforge.phpdt.internal.compiler.util.Util;
 
  18 import net.sourceforge.phpdt.internal.core.util.CharArrayBuffer;
 
  21  * DOMImport provides an implementation of IDOMImport.
 
  26 class DOMImport extends DOMNode implements IDOMImport {
 
  28          * Indicates if this import is an on demand type import
 
  30         protected boolean fOnDemand;
 
  32  * Creates a new empty IMPORT node.
 
  35         fName = "java.lang.*"; //$NON-NLS-1$
 
  36         setMask(MASK_DETAILED_SOURCE_INDEXES, true);
 
  39  * Creates a new detailed IMPORT document fragment on the given range of the document.
 
  41  * @param document - the document containing this node's original contents
 
  42  * @param sourceRange - a two element array of integers describing the
 
  43  *              entire inclusive source range of this node within its document.
 
  44  *              Contents start on and include the character at the first position.
 
  45  *              Contents end on and include the character at the last position.
 
  46  *              An array of -1's indicates this node's contents do not exist
 
  48  * @param name - the identifier portion of the name of this node, or
 
  49  *              <code>null</code> if this node does not have a name
 
  50  * @param nameRange - a two element array of integers describing the
 
  51  *              entire inclusive source range of this node's name within its document,
 
  52  *              including any array qualifiers that might immediately follow the name
 
  53  *              or -1's if this node does not have a name.
 
  54  * @param onDemand - indicates if this import is an on demand style import
 
  56 DOMImport(char[] document, int[] sourceRange, String name, int[] nameRange, boolean onDemand) {
 
  57         super(document, sourceRange, name, nameRange);
 
  59         setMask(MASK_DETAILED_SOURCE_INDEXES, true);
 
  62  * Creates a new simple IMPORT document fragment on the given range of the document.
 
  64  * @param document - the document containing this node's original contents
 
  65  * @param sourceRange - a two element array of integers describing the
 
  66  *              entire inclusive source range of this node within its document.
 
  67  *              Contents start on and include the character at the first position.
 
  68  *              Contents end on and include the character at the last position.
 
  69  *              An array of -1's indicates this node's contents do not exist
 
  71  * @param name - the identifier portion of the name of this node, or
 
  72  *              <code>null</code> if this node does not have a name
 
  73  * @param onDemand - indicates if this import is an on demand style import
 
  75 DOMImport(char[] document, int[] sourceRange, String name, boolean onDemand) {
 
  76         this(document, sourceRange, name, new int[] {-1, -1}, onDemand);
 
  78         setMask(MASK_DETAILED_SOURCE_INDEXES, false);
 
  81  * @see DOMNode#appendFragmentedContents(CharArrayBuffer)
 
  83 protected void appendFragmentedContents(CharArrayBuffer buffer) {
 
  84         if (fNameRange[0] < 0) {
 
  86                         .append("import ") //$NON-NLS-1$
 
  89                         .append(Util.LINE_SEPARATOR);
 
  91                 buffer.append(fDocument, fSourceRange[0], fNameRange[0] - fSourceRange[0]);
 
  92                 //buffer.append(fDocument, fNameRange[0], fNameRange[1] - fNameRange[0] + 1);
 
  94                 buffer.append(fDocument, fNameRange[1] + 1, fSourceRange[1] - fNameRange[1]);
 
  98  * @see IDOMNode#getContents()
 
 100 public String getContents() {
 
 104                 return super.getContents();
 
 108  * @see DOMNode#getDetailedNode()
 
 110 //protected DOMNode getDetailedNode() {
 
 111 //      return (DOMNode)getFactory().createImport(getContents());
 
 114  * @see IDOMNode#getJavaElement
 
 116 public IJavaElement getJavaElement(IJavaElement parent) throws IllegalArgumentException {
 
 117 //      if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
 
 118 //              return ((ICompilationUnit)parent).getImport(getName());
 
 120                 throw new IllegalArgumentException(Util.bind("element.illegalParent")); //$NON-NLS-1$
 
 124  * @see IDOMNode#getNodeType()
 
 126 public int getNodeType() {
 
 127         return IDOMNode.IMPORT;
 
 130  * @see IDOMImport#isOnDemand()
 
 132 public boolean isOnDemand() {
 
 138 protected DOMNode newDOMNode() {
 
 139         return new DOMImport();
 
 142  * @see IDOMNode#setName(char[])
 
 144 public void setName(String name) {
 
 146                 throw new IllegalArgumentException(Util.bind("element.nullName")); //$NON-NLS-1$
 
 150         fOnDemand = name.endsWith(".*"); //$NON-NLS-1$
 
 153  * @see IDOMNode#toString()
 
 155 public String toString() {
 
 156         return "IMPORT: " + getName(); //$NON-NLS-1$