Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.jdt.internal.core.jdom;
 
 
DOMField provides an implementation of IDOMField.

Deprecated:
The JDOM was made obsolete by the addition in 2.0 of the more powerful, fine-grained DOM/AST API found in the org.eclipse.jdt.core.dom package.
See also:
org.eclipse.jdt.core.jdom.IDOMField
DOMNode
 
 class DOMField extends DOMMember implements IDOMField {

Contains the type of the field when the type has been altered from the contents in the document, otherwise null.
 
 	protected String fType;

The original inclusive source range of the field's type in the document.
 
 	protected int[] fTypeRange;

The contents of the initializer when the initializer has been altered from the original state in the document, otherwise null.
 
 	protected String fInitializer;

The original inclusive source range of the initializer in the document.
 
 	protected int[] fInitializerRange;

Constructs an empty field node.
 
 DOMField() {
 	// Constructs an empty field node
 }
Creates a new detailed FIELD document fragment on the given range of the document.

Parameters:
document - the document containing this node's original contents
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.
name - the identifier portion of the name of this field, corresponding to VariableDeclaratorId (JLS 8.3).
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 follow the name.
commentRange - a two element array describing the comments that precede the member declaration. The first matches the start of this node's sourceRange, and the second is the new-line or first non-whitespace character following the last comment. If no comments are present, this array contains two -1's.
flags - an integer representing the modifiers for this member. The integer can be analyzed with org.eclipse.jdt.core.Flags
modifierRange - a two element array describing the location of modifiers for this member within its source range. The first integer is the first character of the first modifier for this member, and the second integer is the last whitespace character preceeding the next part of this member declaration. If there are no modifiers present in this node's source code (that is, package default visibility), this array contains two -1's.
typeRange - a two element array describing the location of the typeName in the document - the positions of the first and last characters of the typeName.
type - the type of the field, in normalized form, as defined in Type in Field Declaration (JLS 8.3)
hasInitializer - true if this field declaration includes an initializer, otherwise false
initRange - a two element array describing the location of the initializer in the declaration. The first integer is the position of the character following the equals sign, and the position of the last character is the last in the initializer. If this field has no initializer, this array contains two -1's.
isVariableDeclarator - true if the field is a seconday variable declarator for a previous field declaration.
DOMField(char[] documentint[] sourceRangeString nameint[] nameRangeint[] commentRangeint flagsint[] modifierRangeint[] typeRangeString typeboolean hasInitializerint[] initRangeboolean isVariableDeclarator) {
	super(documentsourceRangenamenameRangecommentRangeflagsmodifierRange);
	this.type;
	this.typeRange;
	setHasInitializer(hasInitializer);
	this.initRange;
	setIsVariableDeclarator(isVariableDeclarator);
Creates a new simple FIELD document fragment on the given range of the document.

Parameters:
document - the document containing this node's original contents
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.
name - the identifier portion of the name of this field, corresponding to VariableDeclaratorId (JLS 8.3).
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 follow the name.
flags - an integer representing the modifiers for this member. The integer can be analyzed with org.eclipse.jdt.core.Flags
type - the type of the field, in normalized form, as defined in Type in Field Declaration (JLS 8.3)
isVariableDeclarator - true if the field is a seconday variable declarator for a previous field declaration.
DOMField(char[] documentint[] sourceRangeString nameint[] nameRangeint flagsString typeboolean isVariableDeclarator) {
	this(documentsourceRangenamenameRangenew int[] {-1, -1}, flagsnew int[] {-1, -1}, new int[] {-1, -1}, typefalsenew int[] {-1, -1}, isVariableDeclarator);
Appends this member's body contents to the given CharArrayBuffer. Body contents include the member body and any trailing whitespace.

A field does not have a body.

protected void appendMemberBodyContents(CharArrayBuffer buffer) {
	// nothing to do
		buffer.append(this.this.[0], this.[0] - this.[0]);
else {
		buffer
			.append(this.this.[1] + 1, this.[0] - this.[1] - 1);
	}
	if (hasInitializer()) {
		if (this.[0] < 0) {
			buffer
				.append('=')
				.append(this.this.[1] + 1, this.[1] - this.[1]);
else {
			buffer
				.append(this.this.[1] + 1, this.[0] - this.[1] - 1)
				.append(this.this.[1] + 1, this.[1] - this.[1]);
		}
else {
		if (this.[0] < 0) {
			buffer.append(this.this.[1] + 1, this.[1] - this.[1]);
else {
			buffer.append(this.this.[1] + 1, this.[1] - this.[1]);
		}
	}
Appends this member's header contents to the given CharArrayBuffer. Header contents include any preceding comments and modifiers.

If this field is a secondary variable declarator, there is no header.

protected void appendMemberHeaderFragment(CharArrayBuffer buffer) {
		return;
else {
	}
protected void appendSimpleContents(CharArrayBuffer buffer) {
	// append eveything before my name
	buffer.append(this.this.[0], this.[0] - this.[0]);
	// append my name
	buffer.append(this.);
	// append everything after my name
	buffer.append(this.this.[1] + 1, this.[1] - this.[1]);
Generates detailed source indexes for this node if possible.

Throws:
org.eclipse.jdt.core.jdom.DOMException if unable to generate detailed source indexes for this node
protected void becomeDetailed() throws DOMException {
	if (!isDetailed()) {
			DOMNode nodefirst;
			String sourcefirst.getContents();
			while (node != last) {
				nodenode.fNextNode;
				source+=node.getContents();
			}
			DOMBuilder builder = new DOMBuilder();
			IDOMField[] detailsbuilder.createFields(source.toCharArray());
			if (details.length == 0) {
else {
				nodethis;
				for (int i= 0; i < details.lengthi++) {
					node.shareContents((DOMNode)details[i]);
					nodenode.fNextNode;
				}
			}
else {
		}
	}
public Object clone() {
else {
		return super.clone();
	}
Expands all variable declarators in this field declaration into stand-alone field declarations.
protected void expand() {
		DOMField field= (DOMField)siblings.nextElement();
		DOMNode nextfield.fNextNode;
		while (siblings.hasMoreElements() && (next instanceof DOMField) && (((DOMField)next).isVariableDeclarator())) {
			if (field.fParent != null) {
				field.fParent.fragment();
			}
			field= (DOMField)siblings.nextElement();
			nextfield.fNextNode;
		}
	}
protected DOMNode getDetailedNode() {
else {
	}
Returns the first field document fragment that defines the type for this variable declarator.
else {
		return this;
	}
	if (hasInitializer()) {
		if (this. != null) {
			return this.;
else {
			return new String(this.this.[0], this.[1] + 1 - this.[0]);
		}
else {
		return null;
	}
	if (parent.getElementType() == .) {
		return ((IType)parent).getField(getName());
else {
	}
Returns the last field document fragment in this muli-declarator statement.
	DOMField field = this;
		if (field.fNextNode instanceof DOMField && ((DOMField)field.fNextNode).isVariableDeclarator()) {
			field= (DOMField)field.fNextNode;
else {
			break;
		}
	}
	return field;
	return this.[0];
public int getNodeType() {
	return .;
Returns a String representing this field declaration as a field declaration with one variable declarator.
	if (first.isDetailed()) {
		buffer.append(getType());
			buffer.append(' ');
else {
			buffer.append(this.this.[1] + 1, this.[0] - this.[1] - 1);
		}
else {
		buffer.append(first.fDocumentfirst.fSourceRange[0], first.fNameRange[0] - first.fSourceRange[0]);
	}
	buffer.append(getName());
	if (hasInitializer()) {
		if (this.[0] < 0) {
			buffer
				.append('=')
				.append(';')
				.append(Util.getLineSeparator(buffer.toString(), null));
else {
			buffer
				.append(this.this.[1] + 1, this.[0] - this.[1] - 1)
				.append(';')
				.append(Util.getLineSeparator(buffer.toString(), null));
		}
else {
		buffer.append(';').append(Util.getLineSeparator(buffer.toString(), null));
	}
	return buffer.getContents();
public String getType() {
	return this.;
Returns the souce code to be used for this field's type.
protected char[] getTypeContents() {
	if (isTypeAltered()) {
		return this..toCharArray();
else {
		return CharOperation.subarray(this.this.[0], this.[1] + 1);
	}
Returns true if this field has an initializer expression, otherwise false.
protected boolean hasInitializer() {
Returns true is this field declarations has more than one variable declarator, otherwise false;
protected boolean hasMultipleVariableDeclarators() {
	return this. != null && (this. instanceof DOMField) &&
Inserts the given un-parented node as a sibling of this node, immediately before this node. Once inserted, the sibling is only dependent on this document fragment.

When a sibling is inserted before a variable declarator, it must first be expanded.

public void insertSibling(IDOMNode siblingthrows IllegalArgumentExceptionDOMException {
	}
	super.insertSibling(sibling);
Returns true if this field's type has been altered from the original document contents.
protected boolean isTypeAltered() {
Returns true if this field is declared as a secondary variable declarator for a previous field declaration.
protected boolean isVariableDeclarator() {

See also:
DOMNode
protected DOMNode newDOMNode() {
	return new DOMField();
Normalizes this DOMNode's end position.
	if (next == null) {
		// this node's end position includes all of the characters up
		// to the end of the enclosing node
		DOMNode parent = (DOMNodegetParent();
		if (parent == null || parent instanceof DOMCompilationUnit) {
			setSourceRangeEnd(this..length - 1);
else {
			// parent is a type
			int temp = ((DOMType)parent).getCloseBodyPosition() - 1;
			this. = Math.max(finder.getLineStart(temp + 1), getEndPosition());
		}
else {
		// this node's end position is just before the start of the next node
		// unless the next node is a field that is declared along with this one
		int temp = next.getStartPosition() - 1;
		this. = Math.max(finder.getLineStart(temp + 1), getEndPosition());
		if (next instanceof DOMField) {
			DOMField field = (DOMFieldnext;
			if (field.isVariableDeclarator() && this.[0] == field.fTypeRange[0])
				return;
		}
	}
Normalizes this DOMNode's start position.
void normalizeStartPosition(int endPositionILineStartFinder finder) {
		// start position is end of last element
else {
		super.normalizeStartPosition(endPositionfinder);
	}
Offsets all the source indexes in this node by the given amount.
protected void offset(int offset) {
	super.offset(offset);
	offsetRange(this.offset);
Separates this node from its parent and siblings, maintaining any ties that this node has to the underlying document fragment.

When a field with multiple declarators is removed, its declaration must first be expanded.

public void remove() {
	super.remove();
public void setComment(String comment) {
	super.setComment(comment);
public void setFlags(int flags) {
	super.setFlags(flags);
Sets the state of this field declaration as having an initializer expression.
protected void setHasInitializer(boolean hasInitializer) {
public void setInitializer(String initializer) {
	setHasInitializer(initializer != null);
	this.initializer;
Sets the initializer range.
void setInitializerRange(int startint end) {
	this.[0] = start;
	this.[1] = end;
Sets the state of this field declaration as being a secondary variable declarator for a previous field declaration.
protected void setIsVariableDeclarator(boolean isVariableDeclarator) {
public void setName(String namethrows IllegalArgumentException {
	if (name == null) {
else {
		super.setName(name);
	}
public void setType(String typeNamethrows IllegalArgumentException {
	if (typeName == null) {
	}
	this.typeName;
Sets the state of this field declaration as having the field type altered from the original document.
protected void setTypeAltered(boolean typeAltered) {
protected void shareContents(DOMNode node) {
	super.shareContents(node);
	DOMField field= (DOMField)node;
	this.field.fInitializer;
	this.rangeCopy(field.fInitializerRange);
	this.field.fType;
	this.rangeCopy(field.fTypeRange);
public String toString() {
	return "FIELD: " + getName(); //$NON-NLS-1$
New to GrepCode? Check out our FAQ X