mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-16 20:55:44 +02:00
Eliminated ASTNameInContext class.
This commit is contained in:
parent
987feb04be
commit
6e4f88ae53
3 changed files with 15 additions and 49 deletions
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
|
@ -29,7 +30,6 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder;
|
import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
|
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.ASTNameInContext;
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder2;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder2;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
|
||||||
|
|
||||||
|
@ -49,24 +49,25 @@ public class MethodDefinitionInsertLocationFinder2 {
|
||||||
|
|
||||||
for (IASTSimpleDeclaration simpleDeclaration : getAllPreviousSimpleDeclarationsFromClassInReverseOrder(
|
for (IASTSimpleDeclaration simpleDeclaration : getAllPreviousSimpleDeclarationsFromClassInReverseOrder(
|
||||||
declarations, methodDeclarationLocation)) {
|
declarations, methodDeclarationLocation)) {
|
||||||
ASTNameInContext definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache);
|
IASTName definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache);
|
||||||
if (definition != null) {
|
if (definition != null) {
|
||||||
insertLocation.setNodeToInsertAfter(findFirstSurroundingParentFunctionNode(
|
insertLocation.setNodeToInsertAfter(findFirstSurroundingParentFunctionNode(definition),
|
||||||
definition.getName()), definition.getTranslationUnit());
|
definition.getTranslationUnit().getOriginatingTranslationUnit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IASTSimpleDeclaration simpleDeclaration : getAllFollowingSimpleDeclarationsFromClass(
|
for (IASTSimpleDeclaration simpleDeclaration : getAllFollowingSimpleDeclarationsFromClass(
|
||||||
declarations, methodDeclarationLocation)) {
|
declarations, methodDeclarationLocation)) {
|
||||||
ASTNameInContext definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache);
|
IASTName definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache);
|
||||||
if (definition != null) {
|
if (definition != null) {
|
||||||
insertLocation.setNodeToInsertBefore(findFirstSurroundingParentFunctionNode(
|
insertLocation.setNodeToInsertBefore(findFirstSurroundingParentFunctionNode(definition),
|
||||||
definition.getName()), definition.getTranslationUnit());
|
definition.getTranslationUnit().getOriginatingTranslationUnit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (insertLocation.getTranslationUnit() == null) {
|
if (insertLocation.getTranslationUnit() == null) {
|
||||||
ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(declarationTu, astCache);
|
ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(
|
||||||
|
declarationTu, astCache);
|
||||||
if (partner != null) {
|
if (partner != null) {
|
||||||
insertLocation.setParentNode(astCache.getAST(partner, null), partner);
|
insertLocation.setParentNode(astCache.getAST(partner, null), partner);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2011 Google, Inc 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
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Sergey Prigogin (Google) - initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.utils;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Encapsulates an IASTName and the ITranslationUnit it belongs to.
|
|
||||||
*/
|
|
||||||
public class ASTNameInContext {
|
|
||||||
private final IASTName name;
|
|
||||||
private final ITranslationUnit tu;
|
|
||||||
|
|
||||||
ASTNameInContext(IASTName name, ITranslationUnit tu) {
|
|
||||||
this.name = name;
|
|
||||||
this.tu = tu;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTName getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ITranslationUnit getTranslationUnit() {
|
|
||||||
return tu;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -43,7 +43,7 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
*/
|
*/
|
||||||
public class DefinitionFinder2 {
|
public class DefinitionFinder2 {
|
||||||
|
|
||||||
public static ASTNameInContext getDefinition(IASTSimpleDeclaration simpleDeclaration,
|
public static IASTName getDefinition(IASTSimpleDeclaration simpleDeclaration,
|
||||||
RefactoringASTCache astCache) throws CoreException {
|
RefactoringASTCache astCache) throws CoreException {
|
||||||
IIndex index = astCache.getIndex();
|
IIndex index = astCache.getIndex();
|
||||||
IASTDeclarator declarator = simpleDeclaration.getDeclarators()[0];
|
IASTDeclarator declarator = simpleDeclaration.getDeclarators()[0];
|
||||||
|
@ -57,10 +57,10 @@ public class DefinitionFinder2 {
|
||||||
return getDefinition(binding, astCache, index);
|
return getDefinition(binding, astCache, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ASTNameInContext getDefinition(IIndexBinding binding,
|
private static IASTName getDefinition(IIndexBinding binding,
|
||||||
RefactoringASTCache astCache, IIndex index) throws CoreException {
|
RefactoringASTCache astCache, IIndex index) throws CoreException {
|
||||||
Set<String> searchedFiles = new HashSet<String>();
|
Set<String> searchedFiles = new HashSet<String>();
|
||||||
List<ASTNameInContext> definitions = new ArrayList<ASTNameInContext>();
|
List<IASTName> definitions = new ArrayList<IASTName>();
|
||||||
IEditorPart[] dirtyEditors = EditorUtility.getDirtyEditors(true);
|
IEditorPart[] dirtyEditors = EditorUtility.getDirtyEditors(true);
|
||||||
for (IEditorPart editor : dirtyEditors) {
|
for (IEditorPart editor : dirtyEditors) {
|
||||||
IEditorInput editorInput = editor.getEditorInput();
|
IEditorInput editorInput = editor.getEditorInput();
|
||||||
|
@ -85,17 +85,17 @@ public class DefinitionFinder2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void findDefinitionsInTranslationUnit(IIndexBinding binding, ITranslationUnit tu,
|
private static void findDefinitionsInTranslationUnit(IIndexBinding binding, ITranslationUnit tu,
|
||||||
RefactoringASTCache astCache, List<ASTNameInContext> definitions, IProgressMonitor pm)
|
RefactoringASTCache astCache, List<IASTName> definitions, IProgressMonitor pm)
|
||||||
throws OperationCanceledException, CoreException {
|
throws OperationCanceledException, CoreException {
|
||||||
IASTTranslationUnit ast = astCache.getAST(tu, pm);
|
IASTTranslationUnit ast = astCache.getAST(tu, pm);
|
||||||
findDefinitionsInAST(binding, ast, tu, definitions);
|
findDefinitionsInAST(binding, ast, tu, definitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void findDefinitionsInAST(IIndexBinding binding, IASTTranslationUnit ast,
|
private static void findDefinitionsInAST(IIndexBinding binding, IASTTranslationUnit ast,
|
||||||
ITranslationUnit tu, List<ASTNameInContext> definitions) {
|
ITranslationUnit tu, List<IASTName> definitions) {
|
||||||
for (IName definition : ast.getDefinitions(binding)) {
|
for (IName definition : ast.getDefinitions(binding)) {
|
||||||
if (definition instanceof IASTName) {
|
if (definition instanceof IASTName) {
|
||||||
definitions.add(new ASTNameInContext((IASTName) definition, tu));
|
definitions.add((IASTName) definition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue