01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.javaeditor.selectionactions;
11:
12: import org.eclipse.ui.PlatformUI;
13:
14: import org.eclipse.jdt.core.ISourceRange;
15: import org.eclipse.jdt.core.ISourceReference;
16: import org.eclipse.jdt.core.JavaModelException;
17: import org.eclipse.jdt.core.dom.ASTNode;
18:
19: import org.eclipse.jdt.internal.corext.dom.SelectionAnalyzer;
20:
21: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
22: import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
23:
24: public class StructureSelectEnclosingAction extends
25: StructureSelectionAction {
26:
27: public StructureSelectEnclosingAction(JavaEditor editor,
28: SelectionHistory history) {
29: super (SelectionActionMessages.StructureSelectEnclosing_label,
30: editor, history);
31: setToolTipText(SelectionActionMessages.StructureSelectEnclosing_tooltip);
32: setDescription(SelectionActionMessages.StructureSelectEnclosing_description);
33: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
34: IJavaHelpContextIds.STRUCTURED_SELECT_ENCLOSING_ACTION);
35: }
36:
37: /*
38: * This constructor is for testing purpose only.
39: */
40: public StructureSelectEnclosingAction() {
41: }
42:
43: /*
44: * @see StructureSelectionAction#internalGetNewSelectionRange(ISourceRange, ICompilationUnit, SelectionAnalyzer)
45: */
46: ISourceRange internalGetNewSelectionRange(
47: ISourceRange oldSourceRange, ISourceReference sr,
48: SelectionAnalyzer selAnalyzer) throws JavaModelException {
49: ASTNode first = selAnalyzer.getFirstSelectedNode();
50: if (first == null || first.getParent() == null)
51: return getLastCoveringNodeRange(oldSourceRange, sr,
52: selAnalyzer);
53:
54: return getSelectedNodeSourceRange(sr, first.getParent());
55: }
56: }
|