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.core;


A source range defines an element's source coordinates relative to its source buffer.

Since:
3.6
See also:
ISourceRange
public final class SourceRange implements ISourceRange {

Helper method that answers whether a valid source range is available in the given ISourceRange. When an element has no associated source code, Java Model APIs may return either null or a range of [-1, 0] to indicate an invalid range. This utility method can be used to detect that case.

Parameters:
range a source range, can be null
Returns:
true iff range is not null and range.getOffset() is not -1
	public static boolean isAvailable(ISourceRange range) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=130161
		return range != null && range.getOffset() != -1;
	}
	private int offset;
	private int length;

Instantiate a new source range using the given offset and the given length.

Parameters:
offset the given offset
length the given length
	public SourceRange(int offsetint length) {
		this. = offset;
		this. = length;
	}
	/*
	 * @see Object#equals(Object)
	 */
	public boolean equals(Object obj) {
		if (!(obj instanceof ISourceRange))
			return false;
		ISourceRange sourceRange = (ISourceRangeobj;
		return sourceRange.getOffset() == this. && sourceRange.getLength() == this.;
	}

See also:
ISourceRange
	public int getLength() {
		return this.;
	}

See also:
ISourceRange
	public int getOffset() {
		return this.;
	}
	/*
	 * @see Object#hashCode()
	 */
	public int hashCode() {
		return this. ^ this.;
	}
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("[offset="); //$NON-NLS-1$
		buffer.append(this.);
		buffer.append(", length="); //$NON-NLS-1$
		buffer.append(this.);
		buffer.append("]"); //$NON-NLS-1$
		return buffer.toString();
	}
New to GrepCode? Check out our FAQ X