]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/handlers/TextSelectionInformationHandler.java
now also works with blockless constructs (if, for, etc)
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor / src / no / uio / ifi / refaktor / handlers / TextSelectionInformationHandler.java
CommitLineData
597db767
EK
1package no.uio.ifi.refaktor.handlers;
2
ede92818 3import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection;
4c03afae 4import no.uio.ifi.refaktor.utils.DocumentUtils;
47501704 5import no.uio.ifi.refaktor.utils.ParseUtils;
c519ffef 6
597db767
EK
7import org.eclipse.core.commands.AbstractHandler;
8import org.eclipse.core.commands.ExecutionEvent;
9import org.eclipse.core.commands.ExecutionException;
c519ffef 10import org.eclipse.jdt.core.dom.ASTNode;
597db767 11import org.eclipse.jface.dialogs.MessageDialog;
597db767
EK
12import org.eclipse.ui.IWorkbenchWindow;
13import org.eclipse.ui.handlers.HandlerUtil;
14
87b2afda 15public class TextSelectionInformationHandler extends AbstractHandler {
597db767
EK
16
17 @Override
18 public Object execute(ExecutionEvent event) throws ExecutionException {
18447975
EK
19 CompilationUnitTextSelection textSelection = DocumentUtils.getCompilationUnitTextSelectionFromExecutionEvent(event);
20 ASTNode coveringNode = textSelection.getCoveringNode();
21 ASTNode coveredNode = textSelection.getCoveredNode();
c519ffef 22
597db767
EK
23 String string = "Selection type: " + textSelection.getClass().toString()
24 + "\n\nStart line: " + (textSelection.getStartLine() + 1)
25 + "\nEnd line: " + (textSelection.getEndLine() + 1)
26 + "\nOffset: " + textSelection.getOffset()
27 + "\nLength: " + textSelection.getLength()
34328ca2 28 + "\nEnd: " + textSelection.getEnd()
18447975
EK
29 + "\n\nCoveringNode: " + coveringNode.getClass().getCanonicalName() + ":\n" + ParseUtils.getNodeText(coveringNode)
30 + "\n\nCoveredNode: " + coveredNode.getClass().getCanonicalName() + ":\n" + ParseUtils.getNodeText(coveredNode)
597db767 31 + "\n\nSelected text:\n\n" + textSelection.getText();
57ec7e36
EK
32
33 IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
c519ffef 34 MessageDialog.openInformation(window.getShell(), "Selection Info", string);
597db767
EK
35 return null;
36 }
37
38}