]>
Commit | Line | Data |
---|---|---|
1 | package no.uio.ifi.refaktor.handlers; | |
2 | ||
3 | import no.uio.ifi.refaktor.textselection.CompilationUnitTextSelection; | |
4 | import no.uio.ifi.refaktor.utils.DocumentUtils; | |
5 | import no.uio.ifi.refaktor.utils.ParseUtils; | |
6 | ||
7 | import org.eclipse.core.commands.AbstractHandler; | |
8 | import org.eclipse.core.commands.ExecutionEvent; | |
9 | import org.eclipse.core.commands.ExecutionException; | |
10 | import org.eclipse.jdt.core.dom.ASTNode; | |
11 | import org.eclipse.jface.dialogs.MessageDialog; | |
12 | import org.eclipse.ui.IWorkbenchWindow; | |
13 | import org.eclipse.ui.handlers.HandlerUtil; | |
14 | ||
15 | public class TextSelectionInformationHandler extends AbstractHandler { | |
16 | ||
17 | @Override | |
18 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
19 | CompilationUnitTextSelection textSelection = DocumentUtils.getCompilationUnitTextSelectionFromExecutionEvent(event); | |
20 | ASTNode coveringNode = textSelection.getCoveringNode(); | |
21 | ASTNode coveredNode = textSelection.getCoveredNode(); | |
22 | ||
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() | |
28 | + "\nEnd: " + textSelection.getEnd() | |
29 | + "\n\nCoveringNode: " + coveringNode.getClass().getCanonicalName() + ":\n" + ParseUtils.getNodeText(coveringNode) | |
30 | + "\n\nCoveredNode: " + coveredNode.getClass().getCanonicalName() + ":\n" + ParseUtils.getNodeText(coveredNode) | |
31 | + "\n\nSelected text:\n\n" + textSelection.getText(); | |
32 | ||
33 | IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); | |
34 | MessageDialog.openInformation(window.getShell(), "Selection Info", string); | |
35 | return null; | |
36 | } | |
37 | ||
38 | } |