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;
 
DOMMethod provides an implementation of IDOMMethod.

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.IDOMMethod
DOMNode
 
 // TODO (jerome) - add implementation support for 1.5 features
 class DOMMethod extends DOMMember implements IDOMMethod {

Contains the return type of the method when the return type has been altered from the contents in the document, otherwise null.
 
 	protected String fReturnType;

The original inclusive source range of the method's return type in the document, or -1's if no return type is present in the document. If the return type of this method is qualified with '[]' following the parameter list, this array has four entries. In this case, the last two entries of the array are the inclusive source range of the array qualifiers.
 
 	protected int[]  fReturnTypeRange;

Contains the textual representation of the method's parameter list, including open and closing parentheses when the parameters had been altered from the contents in the document, otherwise null.
 
 	protected char[] fParameterList;

The original inclusive source range of the method's parameter list in the document.
 
 	protected int[]  fParameterRange;

Contains the textual representation of the method's exception list when the exceptions had been altered from the contents in the document, otherwise null. The exception list is a comment delimited list of exceptions, not including the "throws" keyword.
 
 	protected char[] fExceptionList;

The original inclusive source range of the method's exception list in the document.
 
 	protected int[]  fExceptionRange;

Contains the method's body when the body has been altered from the contents in the document, otherwise null. The body includes everything between and including the enclosing braces, and trailing whitespace.
 
 	protected String fBody;

The original inclusive source range of the method's body.
 
 	protected int[]  fBodyRange;


Names of parameters in the method parameter list, or null if the method has no parameters.
	protected String[] fParameterNames;

Types of parameters in the method parameter list, or null if the method has no parameters.
	protected String[] fParameterTypes;

The exceptions the method throws, or null if the method throws no exceptions.
	protected String[] fExceptions;

The formal type parameters.

Since:
3.0
Default value for this attotation type member (only), or null if none.

Since:
3.0
	protected String fDefaultValue = null;

Constructs an empty method node.
	// Constructs an empty method node
Creates a new detailed METHOD 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 node, or null if this node does not have a name
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.
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.
isConstructor - true if the method is a contructor, otherwise false
returnType - the normalized return type of this method
returnTypeRange - a two element array describing the location of the return type within the method's source range. The first integer is is the position of the first character in the return type, and the second integer is the position of the last character in the return type. For constructors, the contents of this array are -1's. If the return type of this method is qualified with '[]' following the parameter list, this array has four entries. In this case, the last two entries of the array are the inclusive source range of the array qualifiers.
parameterTypes - an array of parameter types in the method declaration or null if the method has no parameters
parameterNames - an array of parameter names in the method declaration or null if the method has no parameters
parameterRange - a two element array describing the location of the parameter list in the method. The first integer is the location of the open parenthesis and the second integer is the location of the closing parenthesis.
exceptions - an array of the names of exceptions thrown by this method or null if the method throws no exceptions
exceptionRange - a two element array describing the location of the exception list in the method declaration. The first integer is the position of the first character in the first exception the method throws, and the second integer is the position of the last character of the last exception this method throws.
bodyRange - a two element array describing the location of the method's body. The first integer is the first character following the method's parameter list, or exception list (if present). The second integer is the location of the last character in the method's source range.
DOMMethod(char[] documentint[] sourceRangeString nameint[] nameRangeint[] commentRangeint flagsint[] modifierRangeboolean isConstructorString returnTypeint[] returnTypeRangeString[] parameterTypesString[] parameterNamesint[] parameterRangeString[] exceptionsint[] exceptionRangeint[] bodyRange) {
	super(documentsourceRangenamenameRangecommentRangeflagsmodifierRange);
	setMask(isConstructor);
	this.returnType;
	this.returnTypeRange;
	this.parameterTypes;
	this.parameterNames;
	this.parameterRange;
	this.exceptionRange;
	this.exceptions;
	this.bodyRange;
Creates a new simple METHOD 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 node, or null if this node does not have a name
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.
flags - an integer representing the modifiers for this member. The integer can be analyzed with org.eclipse.jdt.core.Flags
isConstructor - true if the method is a contructor, otherwise false
returnType - the normalized return type of this method
parameterTypes - an array of parameter types in the method declaration or null if the method has no parameters
parameterNames - an array of parameter names in the method declaration or null if the method has no parameters
exceptions - an array of the names of exceptions thrown by this method or null if the method throws no exceptions
DOMMethod(char[] documentint[] sourceRangeString nameint[] nameRangeint flagsboolean isConstructorString returnTypeString[] parameterTypesString[] parameterNamesString[] exceptions) {
	this(documentsourceRangenamenameRangenew int[] {-1, -1}, flagsnew int[] {-1, -1}, isConstructorreturnTypenew int[] {-1, -1}, parameterTypesparameterNamesnew int[] {-1, -1}, exceptionsnew int[] {-1, -1}, new int[] {-1, -1});
public void addException(String namethrows IllegalArgumentException {
	if (name == null) {
	}
	if (this. == null) {
		this.new String[1];
		this.[0]= name;
else {
	}
public void addParameter(String typeString namethrows IllegalArgumentException {
	if (type == null) {
	}
	if (name == null) {
	}
	if (this. == null) {
		this.new String[1];
		this.[0]= name;
else {
	}
	if (this. == null) {
		this.new String[1];
		this.[0]= type;
else {
	}
protected void appendMemberBodyContents(CharArrayBuffer buffer) {
	if (this. != null) {
		buffer.append(this.);
else {
		buffer.append(this.this.[0], this.[1] + 1 - this.[0]);
	}
	if (isConstructor()) {
		buffer
			.append(this.this.[1] + 1, this.[0] - this.[1] - 1);
else {
		if (this.[0] >= 0) {
			buffer.append(this.this.[1] + 1, this.[0] - this.[1] - 1);
else {
			buffer.append(' ');
		}
		buffer
			.append(this.this.[1] + 1, this.[0] - this.[1] - 1);
	}
	if (this. != null) {
		buffer.append(this.);
else {
		buffer.append(this.this.[0], this.[1] + 1 - this.[0]);
	}
	int start;
		startthis.[3] + 1;
else {
		startthis.[1] + 1;
	}
	if (this. != null) {
		// add 'throws' keyword
		if (this.[0] >= 0) {
			buffer.append(this.startthis.[0] - start);
else {
			buffer.append(" throws "); //$NON-NLS-1$
		}
		// add exception list
		if (this. != null) {
			buffer.append(this.);
			// add space before body
			if (this.[0] >= 0) {
				buffer.append(this.this.[1] + 1, this.[0] - this.[1] - 1);
else {
				buffer.append(this.this.[1] + 1, this.[0] - this.[1] - 1);
			}
else {
			// add list and space before body
			buffer.append(this.this.[0], this.[0] - this.[0]);
		}
else {
		// add space before body
		if (this.[0] >= 0) {
			buffer.append(this.this.[1] + 1, this.[0] - this.[1] - 1);
else {
			buffer.append(this.startthis.[0] - start);
		}
	}
protected void appendSimpleContents(CharArrayBuffer buffer) {
	// append eveything before my name
	buffer.append(this.this.[0], this.[0] - this.[0]);
	// append my name
	if (isConstructor()) {
else {
		buffer.append(this.);
	}
	// append everything after my name
	buffer.append(this.this.[1] + 1, this.[1] - this.[1]);
public String getBody() {
	if (hasBody()) {
		if (this. != null) {
			return this.;
else {
			return new String(this.this.[0], this.[1] + 1 - this.[0]);
		}
else {
		return null;
	}
Returns the simple name of the enclsoing type for this constructor. If the constuctor is not currently enclosed in a type, the original name of the constructor as found in the documnent is returned.
protected String getConstructorName() {
	if (isConstructor()) {
		if (getParent() != null) {
			return getParent().getName();
else {
			// If there is no parent use the original name
			return new String(getNameContents());
		}
else {
		return null;
	}
protected DOMNode getDetailedNode() {
public String[] getExceptions() {
	return this.;
protected char[] generateFlags() {
	char[] flags= Flags.toString(getFlags() & ~.).toCharArray();
	if (flags.length == 0) {
		return flags;
else {
		return CharOperation.concat(flagsnew char[] {' '});
	}
	if (parent.getElementType() == .) {
		// translate parameter types to signatures
		String[] sigsnull;
		if (this. != null) {
			sigsnew String[this..length];
			int i;
			for (i= 0; i < this..lengthi++) {
				sigs[i]= Signature.createTypeSignature(this.[i].toCharArray(), false);
			}
		}
		String namenull;
		if (isConstructor()) {
else {
			namegetName();
		}
		return ((IType)parent).getMethod(namesigs);
else {
	}
	if (this.[0] >= 0) {
		return this.[0];
else {
		return this.[0];
	}
public String getName() {
	if (isConstructor()) {
		return null;
else {
		return super.getName();
	}
public int getNodeType() {
	return this.;
	return this.;
public String getReturnType() {
	if (isConstructor()) {
		return null;
else {
		return this.;
	}
Returns the source code to be used for this method's return type
protected char[] getReturnTypeContents() {
	if (isConstructor()) {
		return null;
else {
			return this..toCharArray();
else {
			return CharOperation.subarray(this.this.[0], this.[1] + 1);
		}
	}
Returns true if this method's return type has array qualifiers ('[]') following the parameter list.
protected boolean hasTrailingArrayQualifier() {
	return this..length > 2;
public boolean isConstructor() {
Returns true if this method's return type has been altered from the original document contents.
protected boolean isReturnTypeAltered() {

See also:
org.eclipse.jdt.core.jdom.IDOMNode.isSignatureEqual(org.eclipse.jdt.core.jdom.IDOMNode)

Two methods have equal signatures if there names are the same and their parameter types are the same.

public boolean isSignatureEqual(IDOMNode node) {
	boolean oknode.getNodeType() == getNodeType();
	if (ok) {
		IDOMMethod method= (IDOMMethod)node;
		ok = (isConstructor() && method.isConstructor()) ||
			(!isConstructor() && !method.isConstructor());
		if (ok && !isConstructor()) {
			okgetName().equals(method.getName());
		}
		if (!ok) {
			return false;
		}
		String[] typesmethod.getParameterTypes();
		if (this. == null || this..length == 0) {
			// this method has no parameters
			if (types == null || types.length == 0) {
				// the other method has no parameters either
				return true;
			}
else {
			// this method has parameters
			if (types == null || types.length == 0) {
				// the other method has no parameters
				return false;
			}
			if (this..length != types.length) {
				// the methods have a different number of parameters
				return false;
			}
			int i;
			for (i= 0; i < types.lengthi++) {
				if (!this.[i].equals(types[i])) {
					return false;
				}
			}
			return true;
		}
	}
	return false;

See also:
DOMNode
protected DOMNode newDOMNode() {
	return new DOMMethod();
Offsets all the source indexes in this node by the given amount.
protected void offset(int offset) {
	super.offset(offset);
	offsetRange(this.offset);
public void setBody(String body) {
	this.body;
	setHasBody(body != null);
	if (!hasBody()) {
		this.";" + Util.getLineSeparator(bodynull); //$NON-NLS-1$
	}
Sets the end of the body range
void setBodyRangeEnd(int end) {
	this.[1] = end;
public void setConstructor(boolean b) {
public void setExceptions(String[] names) {
	if (names == null || names.length == 0) {
		this.null;
else {
		this.names;
		CharArrayBuffer buffer = new CharArrayBuffer();
		char[] comma = new char[] {','' '};
		for (int i = 0, length = names.lengthi < lengthi++) {
			if (i > 0)
				buffer.append(comma);
			buffer.append(names[i]);
		}
		this.buffer.getContents();
	}
public void setName(String name) {
	if (name == null) {
else {
		super.setName(name);
	}
public void setParameters(String[] typesString[] namesthrows IllegalArgumentException {
	if (types== null || names == null) {
		if (types == null && names == null) {
			this.null;
			this.null;
			this.new char[] {'(',')'};
else {
		}
else if (names.length != types.length) {
else if (names.length == 0) {
		setParameters(nullnull);
else {
		this.names;
		this.types;
		CharArrayBuffer parametersBuffer = new CharArrayBuffer();
		parametersBuffer.append("("); //$NON-NLS-1$
		char[] comma = new char[] {','' '};
		for (int i = 0; i < names.lengthi++) {
			if (i > 0) {
				parametersBuffer.append(comma);
			}
			parametersBuffer
				.append(types[i])
				.append(' ')
				.append(names[i]);
		}
		parametersBuffer.append(')');
		this.parametersBuffer.getContents();
	}
public void setReturnType(String namethrows IllegalArgumentException {
	if (name == null) {
	}
	this.name;
Sets the state of this method declaration as having the return type altered from the original document.
protected void setReturnTypeAltered(boolean typeAltered) {
protected void setSourceRangeEnd(int end) {
	this.[1]= end;
protected void shareContents(DOMNode node) {
	super.shareContents(node);
	DOMMethod method= (DOMMethod)node;
	this.method.fBody;
	this.rangeCopy(method.fBodyRange);
	this.method.fExceptionList;
	this.rangeCopy(method.fExceptionRange);
	this.method.fExceptions;
	this.method.fParameterList;
	this.method.fParameterNames;
	this.rangeCopy(method.fParameterRange);
	this.method.fParameterTypes;
	this.method.fReturnType;
	this.rangeCopy(method.fReturnTypeRange);
public String toString() {
	if (isConstructor()) {
		return "CONSTRUCTOR"//$NON-NLS-1$
else {
		return "METHOD: " + getName(); //$NON-NLS-1$
	}
public void setDefault(String defaultValue) {
	this. =  defaultValue;
public String getDefault() {
	return this.;
	return this.;
public void setTypeParameters(String[] typeParameters) {
	this. = typeParameters;
New to GrepCode? Check out our FAQ X