mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Improved "Expand Selection To Enclosing Element" command for template
definitions.
This commit is contained in:
parent
5d6e09d1cb
commit
75900af3ae
1 changed files with 10 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Tomasz Wesolowski and others.
|
||||
* Copyright (c) 2010, 2015 Tomasz Wesolowski and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Tomasz Wesolowski - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
|
@ -18,6 +19,7 @@ import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.ext.SourceRange;
|
||||
|
@ -39,16 +41,19 @@ public class StructureSelectEnclosingAction extends StructureSelectionAction {
|
|||
}
|
||||
return newSourceRange;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Made public to serve as fallback for other expansions
|
||||
* Package visibility to serve as a fallback for other expansions.
|
||||
*/
|
||||
public static ISourceRange expandToEnclosing(IASTTranslationUnit ast, SourceRange current) {
|
||||
static ISourceRange expandToEnclosing(IASTTranslationUnit ast, SourceRange current) {
|
||||
final IASTNodeSelector nodeSelector = ast.getNodeSelector(null);
|
||||
IASTNode node = nodeSelector.findStrictlyEnclosingNode(current.getStartPos(), current.getLength());
|
||||
if (node == null)
|
||||
return null;
|
||||
|
||||
|
||||
if (node.getPropertyInParent() == ICPPASTTemplateDeclaration.OWNED_DECLARATION)
|
||||
node = node.getParent();
|
||||
|
||||
final IASTFileLocation fileLocation = node.getFileLocation();
|
||||
return new SourceRange(fileLocation.getNodeOffset(), fileLocation.getNodeLength());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue