本文整理匯總了Java中org.eclipse.jdt.core.dom.CompilationUnit.getExtendedLength方法的典型用法代碼示例。如果您正苦於以下問題:Java CompilationUnit.getExtendedLength方法的具體用法?Java CompilationUnit.getExtendedLength怎麽用?Java CompilationUnit.getExtendedLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.getExtendedLength方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNodeSource
import org.eclipse.jdt.core.dom.CompilationUnit; //導入方法依賴的package包/類
/**
* Returns the source of the given node from the location where it was parsed.
* @param node the node to get the source from
* @param extendedRange if set, the extended ranges of the nodes should ne used
* @param removeIndent if set, the indentation is removed.
* @return return the source for the given node or null if accessing the source failed.
*/
public static String getNodeSource(ASTNode node, boolean extendedRange, boolean removeIndent) {
ASTNode root= node.getRoot();
if (root instanceof CompilationUnit) {
CompilationUnit astRoot= (CompilationUnit) root;
ITypeRoot typeRoot= astRoot.getTypeRoot();
try {
if (typeRoot != null && typeRoot.getBuffer() != null) {
IBuffer buffer= typeRoot.getBuffer();
int offset= extendedRange ? astRoot.getExtendedStartPosition(node) : node.getStartPosition();
int length= extendedRange ? astRoot.getExtendedLength(node) : node.getLength();
String str= buffer.getText(offset, length);
if (removeIndent) {
IJavaProject project= typeRoot.getJavaProject();
int indent= getIndentUsed(buffer, node.getStartPosition(), project);
str= Strings.changeIndent(str, indent, project, new String(), typeRoot.findRecommendedLineSeparator());
}
return str;
}
} catch (JavaModelException e) {
// ignore
}
}
return null;
}