Skip to main content
summaryrefslogtreecommitdiffstats
blob: dec2d57e078053c6f461b3a4485f1d37f6776da2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package org.eclipse.jdt.internal.core.jdom;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.jdom.IDOMNode;
import org.eclipse.jdt.core.jdom.IDOMPackage;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.Util;
import org.eclipse.jdt.internal.core.util.CharArrayBuffer;

/**
 * DOMPackage provides an implementation of IDOMPackage.
 *
 * @see IDOMPackage
 * @see DOMNode
 */
class DOMPackage extends DOMNode implements IDOMPackage {

/**
 * Creates an empty PACKAGE node.
 */
DOMPackage() {
	setMask(MASK_DETAILED_SOURCE_INDEXES, true);
}
/**
 * Creates a new simple PACKAGE document fragment on the given range of the document.
 *
 * @param document - the document containing this node's original contents
 * @param sourceRange - a two element array of integers describing the
 *		entire inclusive source range of this node within its document.
 * 		Contents start on and include the character at the first position.
 *		Contents end on and include the character at the last position.
 *		An array of -1's indicates this node's contents do not exist
 *		in the document.
 * @param name - the identifier portion of the name of this node, or
 *		<code>null</code> if this node does not have a name
 */
DOMPackage(char[] document, int[] sourceRange, String name) {
	super(document, sourceRange, name, new int[] {-1, -1});
	setMask(MASK_DETAILED_SOURCE_INDEXES, false);
}
/**
 * Creates a new detailed PACKAGE document fragment on the given range of the document.
 *
 * @param document - the document containing this node's original contents
 * @param sourceRange - a two element array of integers describing the
 *		entire inclusive source range of this node within its document.
 * 		Contents start on and include the character at the first position.
 *		Contents end on and include the character at the last position.
 *		An array of -1's indicates this node's contents do not exist
 *		in the document.
 * @param name - the identifier portion of the name of this node, or
 *		<code>null</code> if this node does not have a name
 * @param nameRange - a two element array of integers describing the
 *		entire inclusive source range of this node's name within its document,
 *		including any array qualifiers that might immediately follow the name
 *		or -1's if this node does not have a name.
 */
DOMPackage(char[] document, int[] sourceRange, String name, int[] nameRange) {
	super(document, sourceRange, name, nameRange);
	setMask(MASK_DETAILED_SOURCE_INDEXES, true);
}
/**
 * @see DOMNode#appendFragmentedContents(CharArrayBuffer)
 */
protected void appendFragmentedContents(CharArrayBuffer buffer) {
	if (fNameRange[0] < 0) {
		buffer
			.append("package "/*nonNLS*/)
			.append(fName)
			.append(';')
			.append(JavaModelManager.LINE_SEPARATOR);
	} else {
		buffer
			.append(fDocument, fSourceRange[0], fNameRange[0] - fSourceRange[0])
			.append(fName)
			.append(fDocument, fNameRange[1] + 1, fSourceRange[1] - fNameRange[1]);
	}
}
/**
 * @see IDOMNode#getContents()
 */
public String getContents() {
	if (fName == null) {
		return null;
	} else {
		return super.getContents();
	}
}
/**
 * @see DOMNode#getDetailedNode()
 */
protected DOMNode getDetailedNode() {
	return (DOMNode)getFactory().createPackage(getContents());
}
/**
 * @see IDOMNode#getJavaElement
 */
public IJavaElement getJavaElement(IJavaElement parent) throws IllegalArgumentException {
	if (parent.getElementType() == IJavaElement.COMPILATION_UNIT) {
		return ((ICompilationUnit)parent).getPackageDeclaration(getName());
	} else {
		throw new IllegalArgumentException(Util.bind("element.illegalParent"/*nonNLS*/));
	}
}
/**
 * @see IDOMNode#getNodeType()
 */
public int getNodeType() {
	return IDOMNode.PACKAGE;
}
/**
 * @see DOMNode
 */
protected DOMNode newDOMNode() {
	return new DOMPackage();
}
/**
 * @see IDOMNode#setName
 */
public void setName(String name) {
	becomeDetailed();
	super.setName(name);
}
/**
 * @see IDOMNode#toString()
 */
public String toString() {
	return "PACKAGE: "/*nonNLS*/ + getName();
}
}

Back to the top