Java Code Examples for org.eclipse.wst.jsdt.core.dom.ASTNode#getLength()

The following examples show how to use org.eclipse.wst.jsdt.core.dom.ASTNode#getLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeFinder.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
public boolean visitNode(final ASTNode node) {
	final int nodeStart = node.getStartPosition();
	final int nodeEnd = nodeStart + node.getLength();
	if (nodeEnd < this.fStart || this.fEnd < nodeStart) {
		return false;
	}
	if (nodeStart <= this.fStart && this.fEnd <= nodeEnd) {
		this.fCoveringNode = node;
	}
	if (this.fStart <= nodeStart && nodeEnd <= this.fEnd) {
		if (this.fCoveringNode == node) { // nodeStart == fStart &&
											// nodeEnd == fEnd
			this.fCoveredNode = node;
			return true; // look further for node with same length as
							// parent
		} else if (this.fCoveredNode == null) { // no better found
			this.fCoveredNode = node;
		}
		return false;
	}
	return true;
}
 
Example 2
Source File: NodeFinder.java    From tassal with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean visitNode(final ASTNode node) {
	final int nodeStart = node.getStartPosition();
	final int nodeEnd = nodeStart + node.getLength();
	if (nodeEnd < this.fStart || this.fEnd < nodeStart) {
		return false;
	}
	if (nodeStart <= this.fStart && this.fEnd <= nodeEnd) {
		this.fCoveringNode = node;
	}
	if (this.fStart <= nodeStart && nodeEnd <= this.fEnd) {
		if (this.fCoveringNode == node) { // nodeStart == fStart &&
											// nodeEnd == fEnd
			this.fCoveredNode = node;
			return true; // look further for node with same length as
							// parent
		} else if (this.fCoveredNode == null) { // no better found
			this.fCoveredNode = node;
		}
		return false;
	}
	return true;
}
 
Example 3
Source File: NodeFinder.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean visitNode(final ASTNode node) {
	final int nodeStart = node.getStartPosition();
	final int nodeEnd = nodeStart + node.getLength();
	if (nodeEnd < this.fStart || this.fEnd < nodeStart) {
		return false;
	}
	if (nodeStart <= this.fStart && this.fEnd <= nodeEnd) {
		this.fCoveringNode = node;
	}
	if (this.fStart <= nodeStart && nodeEnd <= this.fEnd) {
		if (this.fCoveringNode == node) { // nodeStart == fStart &&
											// nodeEnd == fEnd
			this.fCoveredNode = node;
			return true; // look further for node with same length as
							// parent
		} else if (this.fCoveredNode == null) { // no better found
			this.fCoveredNode = node;
		}
		return false;
	}
	return true;
}
 
Example 4
Source File: NodeFinder.java    From api-mining with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Maps a selection to a given ASTNode, where the selection is defined using
 * a start and a length. The result node is determined as follows:
 * <ul>
 * <li>first the visitor tries to find a node with the exact
 * <code>start</code> and <code>length</code></li>
 * <li>if no such node exists then the node that encloses the range defined
 * by <code>start</code> and <code>length</code> is returned.</li>
 * <li>if the length is zero then also nodes are considered where the node's
 * start or end position matches <code>start</code>.</li>
 * <li>otherwise <code>null</code> is returned.</li>
 * </ul>
 * 
 * @param root
 *            the root node from which the search starts
 * @param start
 *            the given start
 * @param length
 *            the given length
 * 
 * @return the found node
 */
public static ASTNode perform(final ASTNode root, final int start,
		final int length) {
	final NodeFinder finder = new NodeFinder(root, start, length);
	final ASTNode result = finder.getCoveredNode();
	if (result == null || result.getStartPosition() != start
			|| result.getLength() != length) {
		return finder.getCoveringNode();
	}
	return result;
}
 
Example 5
Source File: NodeFinder.java    From tassal with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Maps a selection to a given ASTNode, where the selection is defined using
 * a start and a length. The result node is determined as follows:
 * <ul>
 * <li>first the visitor tries to find a node with the exact
 * <code>start</code> and <code>length</code></li>
 * <li>if no such node exists then the node that encloses the range defined
 * by <code>start</code> and <code>length</code> is returned.</li>
 * <li>if the length is zero then also nodes are considered where the node's
 * start or end position matches <code>start</code>.</li>
 * <li>otherwise <code>null</code> is returned.</li>
 * </ul>
 * 
 * @param root
 *            the root node from which the search starts
 * @param start
 *            the given start
 * @param length
 *            the given length
 * 
 * @return the found node
 */
public static ASTNode perform(final ASTNode root, final int start,
		final int length) {
	final NodeFinder finder = new NodeFinder(root, start, length);
	final ASTNode result = finder.getCoveredNode();
	if (result == null || result.getStartPosition() != start
			|| result.getLength() != length) {
		return finder.getCoveringNode();
	}
	return result;
}
 
Example 6
Source File: NodeFinder.java    From codemining-core with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Maps a selection to a given ASTNode, where the selection is defined using
 * a start and a length. The result node is determined as follows:
 * <ul>
 * <li>first the visitor tries to find a node with the exact
 * <code>start</code> and <code>length</code></li>
 * <li>if no such node exists then the node that encloses the range defined
 * by <code>start</code> and <code>length</code> is returned.</li>
 * <li>if the length is zero then also nodes are considered where the node's
 * start or end position matches <code>start</code>.</li>
 * <li>otherwise <code>null</code> is returned.</li>
 * </ul>
 * 
 * @param root
 *            the root node from which the search starts
 * @param start
 *            the given start
 * @param length
 *            the given length
 * 
 * @return the found node
 */
public static ASTNode perform(final ASTNode root, final int start,
		final int length) {
	final NodeFinder finder = new NodeFinder(root, start, length);
	final ASTNode result = finder.getCoveredNode();
	if (result == null || result.getStartPosition() != start
			|| result.getLength() != length) {
		return finder.getCoveringNode();
	}
	return result;
}