1
/*******************************************************************************
2
* Copyright (c) 2012 Google, Inc and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Sergey Prigogin (Google) - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.core.dom.rewrite.util;
13
import static org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit.getNodeEndOffset;
15
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
16
import org.eclipse.cdt.core.dom.ast.IASTNode;
19
* Collection of helper methods for common operations on AST nodes.
21
public class ASTNodes {
22
/** Not instantiatable. */
27
* Returns the offset of an AST node.
29
public static int offset(IASTNode node) {
30
return node.getFileLocation().getNodeOffset();
34
* Returns the exclusive end offset of an AST node.
36
public static int endOffset(IASTNode node) {
37
IASTFileLocation location = node.getFileLocation();
38
return location.getNodeOffset() + location.getNodeLength();
42
* Returns the offset of the beginning of the next line after the node, or the end-of-file
43
* offset if there is no line delimiter after the node.
45
public static int skipToNextLineAfterNode(String text, IASTNode node) {
46
return TextUtil.skipToNextLine(text, getNodeEndOffset(node));