本文整理汇总了Java中org.mozilla.javascript.ast.AstNode.getAbsolutePosition方法的典型用法代码示例。如果您正苦于以下问题:Java AstNode.getAbsolutePosition方法的具体用法?Java AstNode.getAbsolutePosition怎么用?Java AstNode.getAbsolutePosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.ast.AstNode
的用法示例。
在下文中一共展示了AstNode.getAbsolutePosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addCodeBlock
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* for each child of parent AstNode add a new code block and add completions
* for each block of code
*
* @param parent AstNode to iterate children
* @param set completions set to add to
* @param entered Text entered
* @param codeBlock parent CodeBlock
* @param offset codeblock offset
*/
private void addCodeBlock(Node parent, Set<Completion> set,
String entered, CodeBlock codeBlock, int offset) {
if(parent == null)
return;
Node child = parent.getFirstChild();
while (child != null) {
CodeBlock childBlock = codeBlock;
if (child instanceof AstNode) {
AstNode node = (AstNode) child;
int start = node.getAbsolutePosition();
childBlock = codeBlock.addChildCodeBlock(start);
childBlock.setEndOffset(offset);
}
iterateNode((AstNode) child, set, entered, childBlock, offset);
child = child.getNext();
}
}
示例2: processIfThenElse
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Extract variables from if/else node(s)
*/
private void processIfThenElse(Node child, CodeBlock block,
Set<Completion> set, String entered, int offset) {
IfStatement ifStatement = (IfStatement) child;
if (canProcessNode(ifStatement)) {
offset = ifStatement.getAbsolutePosition()
+ ifStatement.getLength();
addCodeBlock(ifStatement.getThenPart(), set, entered, block, offset);
AstNode elseNode = ifStatement.getElsePart();
if (elseNode != null) {
int start = elseNode.getAbsolutePosition();
CodeBlock childBlock = block.addChildCodeBlock(start);
offset = start + elseNode.getLength();
iterateNode(elseNode, set, entered, childBlock, offset);
childBlock.setEndOffset(offset);
}
}
}
示例3: createTreeNode
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Creates and returns a node for the outline tree that corresponds to
* a specific AST node.
*
* @param node The AST node.
* @return The outline tree node.
*/
private final JavaScriptTreeNode createTreeNode(AstNode node) {
JavaScriptTreeNode tn = new JavaScriptTreeNode(node);
try {
int offs = node.getAbsolutePosition();
tn.setOffset(textArea.getDocument().createPosition(offs));
} catch (BadLocationException ble) { // Never happens
ble.printStackTrace();
}
return tn;
}
示例4: actionPerformed
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
JavaScriptParser parser = getParser(textArea);
if (parser==null) {
return; // Shouldn't happen
}
AstRoot astRoot = parser.getAstRoot();
if (astRoot!=null) {
int dot = textArea.getCaretPosition();
visitor.reset(dot);
astRoot.visit(visitor);
AstNode scope = visitor.getDeepestScope();
if (scope!=null && scope!=astRoot) {
int start = scope.getAbsolutePosition();
int end = Math.min(start + scope.getLength() - 1,
textArea.getDocument().getLength());
try {
int startLine = textArea.getLineOfOffset(start);
int endLine = end<0 ? textArea.getLineCount() :
textArea.getLineOfOffset(end);
textArea.setActiveLineRange(startLine, endLine);
} catch (BadLocationException ble) {
ble.printStackTrace(); // Never happens
}
}
else {
textArea.setActiveLineRange(-1, -1);
}
}
}
示例5: processTryCatchNode
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
/**
* Extract variables from try/catch node(s)
*/
private void processTryCatchNode(Node child, CodeBlock block,
Set<Completion> set, String entered, int offset) {
TryStatement tryStatement = (TryStatement) child;
if (canProcessNode(tryStatement)) {
offset = tryStatement.getTryBlock().getAbsolutePosition()
+ tryStatement.getTryBlock().getLength();
addCodeBlock(tryStatement.getTryBlock(), set, entered, block,
offset);
// iterate catch
for (int i = 0; i < tryStatement.getCatchClauses().size(); i++) {
CatchClause clause = tryStatement.getCatchClauses().get(i);
if (canProcessNode(clause)) {
offset = clause.getAbsolutePosition() + clause.getLength();
CodeBlock catchBlock = block.getParent().addChildCodeBlock(
clause.getAbsolutePosition());
catchBlock.setEndOffset(offset);
AstNode target = clause.getVarName();
JavaScriptVariableDeclaration dec = extractVariableFromNode(
target, catchBlock, offset);
if (dec != null) {
dec.setTypeDeclaration(clause);
}
addCodeBlock(clause.getBody(), set, entered, catchBlock,
offset);
}
}
// now sort out finally block
if (tryStatement.getFinallyBlock() != null) {
AstNode finallyNode = tryStatement.getFinallyBlock();
if (canProcessNode(finallyNode)) {
offset = finallyNode.getAbsolutePosition()
+ finallyNode.getLength();
CodeBlock finallyBlock = block.getParent()
.addChildCodeBlock(
tryStatement.getFinallyBlock()
.getAbsolutePosition());
addCodeBlock(finallyNode, set, entered, finallyBlock,
offset);
finallyBlock.setEndOffset(offset);
}
}
}
}
示例6: canProcessNode
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
private boolean canProcessNode(AstNode node) {
int start = node.getAbsolutePosition();
int offset = start + node.getLength();
return dot >= start && dot < offset;
}
示例7: containsOffs
import org.mozilla.javascript.ast.AstNode; //导入方法依赖的package包/类
private boolean containsOffs(AstNode node) {
int start = node.getAbsolutePosition();
return start<=offs && start+node.getLength()>offs;
}