本文整理匯總了Java中org.eclipse.jdt.core.dom.ASTNode.getStartPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java ASTNode.getStartPosition方法的具體用法?Java ASTNode.getStartPosition怎麽用?Java ASTNode.getStartPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ASTNode
的用法示例。
在下文中一共展示了ASTNode.getStartPosition方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serializePosition
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
private void serializePosition(CompilationUnit cu, ASTNode node, JsonGenerator jG) throws IOException {
final int startPosition = node.getStartPosition();
jG.writeFieldName("startPosition");
jG.writeNumber(startPosition);
jG.writeFieldName("startLine");
jG.writeNumber(cu.getLineNumber(startPosition));
jG.writeFieldName("startColumn");
jG.writeNumber(cu.getColumnNumber(startPosition) + 1); // 1-based numbering
final int endPosition = startPosition + node.getLength();
jG.writeFieldName("endPosition");
jG.writeNumber(endPosition);
jG.writeFieldName("endLine");
jG.writeNumber(cu.getLineNumber(endPosition));
jG.writeFieldName("endColumn");
jG.writeNumber(cu.getColumnNumber(endPosition) + 1); // 1-based numbering
}
示例2: getNodeSource
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的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;
}
示例3: getNodeToInsertBefore
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
/**
* Evaluates the insertion position of a new node.
*
* @param listRewrite The list rewriter to which the new node will be added
* @param sibling The Java element before which the new element should be added.
* @return the AST node of the list to insert before or null to insert as last.
* @throws JavaModelException thrown if accessing the Java element failed
*/
public static ASTNode getNodeToInsertBefore(ListRewrite listRewrite, IJavaElement sibling) throws JavaModelException {
if (sibling instanceof IMember) {
ISourceRange sourceRange= ((IMember) sibling).getSourceRange();
if (sourceRange == null) {
return null;
}
int insertPos= sourceRange.getOffset();
List<? extends ASTNode> members= listRewrite.getOriginalList();
for (int i= 0; i < members.size(); i++) {
ASTNode curr= members.get(i);
if (curr.getStartPosition() >= insertPos) {
return curr;
}
}
}
return null;
}
示例4: getMessages
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static Message[] getMessages(ASTNode node, int flags) {
ASTNode root= node.getRoot();
if (!(root instanceof CompilationUnit)) {
return EMPTY_MESSAGES;
}
Message[] messages= ((CompilationUnit)root).getMessages();
if (root == node) {
return messages;
}
final int iterations= computeIterations(flags);
List<Message> result= new ArrayList<>(5);
for (int i= 0; i < messages.length; i++) {
Message message= messages[i];
ASTNode temp= node;
int count= iterations;
do {
int nodeOffset= temp.getStartPosition();
int messageOffset= message.getStartPosition();
if (nodeOffset <= messageOffset && messageOffset < nodeOffset + temp.getLength()) {
result.add(message);
count= 0;
} else {
count--;
}
} while ((temp= temp.getParent()) != null && count > 0);
}
return result.toArray(new Message[result.size()]);
}
示例5: getEndVisitSelectionMode
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public int getEndVisitSelectionMode(ASTNode node) {
int nodeStart = node.getStartPosition();
int nodeEnd = nodeStart + node.getLength();
if (nodeEnd <= fStart) {
return BEFORE;
} else if (covers(node)) {
return SELECTED;
} else if (nodeEnd >= fExclusiveEnd) {
return AFTER;
}
return INTERSECTS;
}
示例6: liesOutside
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public boolean liesOutside(ASTNode node) {
int nodeStart = node.getStartPosition();
int nodeEnd = nodeStart + node.getLength();
boolean nodeBeforeSelection = nodeEnd < fStart;
boolean selectionBeforeNode = fExclusiveEnd < nodeStart;
return nodeBeforeSelection || selectionBeforeNode;
}
示例7: getSelectedNodeRange
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public Selection getSelectedNodeRange() {
if (fSelectedNodes == null || fSelectedNodes.isEmpty()) {
return null;
}
ASTNode firstNode = fSelectedNodes.get(0);
ASTNode lastNode = fSelectedNodes.get(fSelectedNodes.size() - 1);
int start = firstNode.getStartPosition();
return Selection.createFromStartLength(start, lastNode.getStartPosition() + lastNode.getLength() - start);
}
示例8: findByProblems
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static SimpleName[] findByProblems(ASTNode parent, SimpleName nameNode) {
ArrayList<SimpleName> res= new ArrayList<>();
ASTNode astRoot = parent.getRoot();
if (!(astRoot instanceof CompilationUnit)) {
return null;
}
IProblem[] problems= ((CompilationUnit) astRoot).getProblems();
int nameNodeKind= getNameNodeProblemKind(problems, nameNode);
if (nameNodeKind == 0) { // no problem on node
return null;
}
int bodyStart= parent.getStartPosition();
int bodyEnd= bodyStart + parent.getLength();
String name= nameNode.getIdentifier();
for (int i= 0; i < problems.length; i++) {
IProblem curr= problems[i];
int probStart= curr.getSourceStart();
int probEnd= curr.getSourceEnd() + 1;
if (probStart > bodyStart && probEnd < bodyEnd) {
int currKind= getProblemKind(curr);
if ((nameNodeKind & currKind) != 0) {
ASTNode node= NodeFinder.perform(parent, probStart, (probEnd - probStart));
if (node instanceof SimpleName && name.equals(((SimpleName) node).getIdentifier())) {
res.add((SimpleName) node);
}
}
}
}
return res.toArray(new SimpleName[res.size()]);
}
示例9: isAffected
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
private boolean isAffected(ASTNode node) {
if (fSubRange == null) {
return true;
}
int nodeStart= node.getStartPosition();
int offset= fSubRange.getOffset();
return nodeStart + node.getLength() > offset && offset + fSubRange.getLength() > nodeStart;
}
示例10: visit
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
@Override
public boolean visit(LambdaExpression node) {
Selection selection = getSelection();
int selectionStart = selection.getOffset();
int selectionExclusiveEnd = selection.getExclusiveEnd();
int lambdaStart = node.getStartPosition();
int lambdaExclusiveEnd = lambdaStart + node.getLength();
ASTNode body = node.getBody();
int bodyStart = body.getStartPosition();
int bodyExclusiveEnd = bodyStart + body.getLength();
boolean isValidSelection = false;
if ((body instanceof Block) && (bodyStart < selectionStart && selectionExclusiveEnd <= bodyExclusiveEnd)) {
// if selection is inside lambda body's block
isValidSelection = true;
} else if (body instanceof Expression) {
try {
TokenScanner scanner = new TokenScanner(fCUnit);
int arrowExclusiveEnd = scanner.getTokenEndOffset(ITerminalSymbols.TokenNameARROW, lambdaStart);
if (selectionStart >= arrowExclusiveEnd) {
isValidSelection = true;
}
} catch (CoreException e) {
// ignore
}
}
if (selectionStart <= lambdaStart && selectionExclusiveEnd >= lambdaExclusiveEnd) {
// if selection covers the lambda node
isValidSelection = true;
}
if (!isValidSelection) {
return false;
}
return super.visit(node);
}
示例11: getExclusiveEnd
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static int getExclusiveEnd(ASTNode node){
return node.getStartPosition() + node.getLength();
}
示例12: getInclusiveEnd
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public static int getInclusiveEnd(ASTNode node){
return node.getStartPosition() + node.getLength() - 1;
}
示例13: traverseNode
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
@Override
protected boolean traverseNode(ASTNode node) {
return node.getStartPosition() + node.getLength() > fSelection.getInclusiveEnd();
}
示例14: covers
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public boolean covers(ASTNode node) {
int nodeStart = node.getStartPosition();
return fStart <= nodeStart && nodeStart + node.getLength() <= fExclusiveEnd;
}
示例15: coveredBy
import org.eclipse.jdt.core.dom.ASTNode; //導入方法依賴的package包/類
public boolean coveredBy(ASTNode node) {
int nodeStart = node.getStartPosition();
return nodeStart <= fStart && fExclusiveEnd <= nodeStart + node.getLength();
}