Lines 79-96
Link Here
|
79 |
|
79 |
|
80 |
protected final int caretOffset; |
80 |
protected final int caretOffset; |
81 |
protected final Callable<Boolean> cancel; |
81 |
protected final Callable<Boolean> cancel; |
|
|
82 |
private int caretInSnapshot; |
82 |
|
83 |
|
83 |
protected BaseTask(int caretOffset, Callable<Boolean> cancel) { |
84 |
protected BaseTask(int caretOffset, Callable<Boolean> cancel) { |
84 |
this.caretOffset = caretOffset; |
85 |
this.caretOffset = caretOffset; |
85 |
this.cancel = cancel; |
86 |
this.cancel = cancel; |
86 |
} |
87 |
} |
|
|
88 |
|
89 |
final int getCaretInSnapshot() { |
90 |
return caretInSnapshot; |
91 |
} |
92 |
|
93 |
private CompilationController controller; |
94 |
|
95 |
final int snapshotPos(int pos) { |
96 |
if (pos < 0) { |
97 |
return pos; |
98 |
} |
99 |
int r = controller.getSnapshot().getEmbeddedOffset(pos); |
100 |
if (r == -1) { |
101 |
return pos; |
102 |
} else { |
103 |
return r; |
104 |
} |
105 |
} |
87 |
|
106 |
|
88 |
@Override |
107 |
@Override |
89 |
public void run(ResultIterator resultIterator) throws Exception { |
108 |
public void run(ResultIterator resultIterator) throws Exception { |
90 |
Parser.Result result = resultIterator.getParserResult(caretOffset); |
109 |
Parser.Result result = resultIterator.getParserResult(caretOffset); |
91 |
CompilationController controller = result != null ? CompilationController.get(result) : null; |
110 |
CompilationController controller = result != null ? CompilationController.get(result) : null; |
92 |
if (controller != null && (cancel == null || !cancel.call())) { |
111 |
if (controller != null && (cancel == null || !cancel.call())) { |
93 |
resolve(controller); |
112 |
try { |
|
|
113 |
this.controller = controller; |
114 |
caretInSnapshot = snapshotPos(caretOffset); |
115 |
resolve(controller); |
116 |
} finally { |
117 |
this.controller = null; |
118 |
} |
94 |
} |
119 |
} |
95 |
} |
120 |
} |
96 |
|
121 |
|
Lines 365-372
Link Here
|
365 |
if (blockPath.getParentPath().getLeaf().getKind() == Tree.Kind.METHOD |
390 |
if (blockPath.getParentPath().getLeaf().getKind() == Tree.Kind.METHOD |
366 |
|| TreeUtilities.CLASS_TREE_KINDS.contains(blockPath.getParentPath().getLeaf().getKind())) { |
391 |
|| TreeUtilities.CLASS_TREE_KINDS.contains(blockPath.getParentPath().getLeaf().getKind())) { |
367 |
final int blockPos = (int) sourcePositions.getStartPosition(root, blockPath.getLeaf()); |
392 |
final int blockPos = (int) sourcePositions.getStartPosition(root, blockPath.getLeaf()); |
368 |
final String blockText = upToOffset && caretOffset > offset |
393 |
final String blockText = upToOffset && getCaretInSnapshot() > offset |
369 |
? controller.getText().substring(blockPos, offset) + whitespaceString(caretOffset - offset) + controller.getText().substring(caretOffset, (int) sourcePositions.getEndPosition(root, blockPath.getLeaf())) |
394 |
? controller.getText().substring(blockPos, offset) + whitespaceString(getCaretInSnapshot() - offset) + controller.getText().substring(getCaretInSnapshot(), (int) sourcePositions.getEndPosition(root, blockPath.getLeaf())) |
370 |
: controller.getText().substring(blockPos, (int) sourcePositions.getEndPosition(root, blockPath.getLeaf())); |
395 |
: controller.getText().substring(blockPos, (int) sourcePositions.getEndPosition(root, blockPath.getLeaf())); |
371 |
final SourcePositions[] sp = new SourcePositions[1]; |
396 |
final SourcePositions[] sp = new SourcePositions[1]; |
372 |
final StatementTree block = (((BlockTree) blockPath.getLeaf()).isStatic() ? tu.parseStaticBlock(blockText, sp) : tu.parseStatement(blockText, sp)); |
397 |
final StatementTree block = (((BlockTree) blockPath.getLeaf()).isStatic() ? tu.parseStaticBlock(blockText, sp) : tu.parseStatement(blockText, sp)); |