fCurrentDocument = null;
}
}
void updateSlice(CompilationUnit unit, IResource resource, IProgressMonitor monitor) throws InvalidSlicingSelectionException {
final NodeFinder finder = new NodeFinder();
Display.getDefault().syncExec(new Runnable() {
public void run() {
try {
if(fEditor == null) {
JavaPlugin.logErrorMessage("fEditor == null, can't compute the slice");
return;
}
ISelectionProvider selProv = fEditor.getSelectionProvider();
if(selProv == null) {
throw new InvalidSlicingSelectionException("No selection provider. Something is wrong.");
}
ISelection selection = selProv.getSelection();
if(selection == null) {
throw new InvalidSlicingSelectionException("No selection detected. Please select an identifier.");
}
if(! (selection instanceof ITextSelection) ) {
throw new InvalidSlicingSelectionException("Selection type is not valid. Please select an identifier in a Java text editor.");
}
ITextSelection textSelection = (ITextSelection) selection;
log("Working with " + textSelection.getText() + " in " + fEditor.getTitle());
/*if(textSelection.getLength() == 0) {
throw new InvalidSlicingSelectionException("The selection is empty. Please select an identifier.");
}*/
if(fRoot == null) {
throw new InvalidSlicingSelectionException("No current document for the plugin. Something is wrong.");
}
finder.setOffset(textSelection.getOffset());
finder.setLength(textSelection.getLength());
fRoot.accept(finder);
} catch (InvalidSlicingSelectionException e) {
throw new RuntimeException(e);
}
}
});
// found the relevant ASTNode
ASTNode covering = finder.getCoveringNode();
updateSlice(covering, unit, resource, monitor);
// restore editor position
// TODO:
//fEditor.setHighlightRange(textSelection.getOffset(), textSelection.getLength(), true);