diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/MethodDefinitionInsertLocationFinder2.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/MethodDefinitionInsertLocationFinder2.java index 99967d86f2b..2b8ffc59944 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/MethodDefinitionInsertLocationFinder2.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/implementmethod/MethodDefinitionInsertLocationFinder2.java @@ -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.IASTFunctionDeclarator; 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.IASTSimpleDeclaration; 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.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.NodeHelper; @@ -49,24 +49,25 @@ public class MethodDefinitionInsertLocationFinder2 { for (IASTSimpleDeclaration simpleDeclaration : getAllPreviousSimpleDeclarationsFromClassInReverseOrder( declarations, methodDeclarationLocation)) { - ASTNameInContext definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache); + IASTName definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache); if (definition != null) { - insertLocation.setNodeToInsertAfter(findFirstSurroundingParentFunctionNode( - definition.getName()), definition.getTranslationUnit()); + insertLocation.setNodeToInsertAfter(findFirstSurroundingParentFunctionNode(definition), + definition.getTranslationUnit().getOriginatingTranslationUnit()); } } for (IASTSimpleDeclaration simpleDeclaration : getAllFollowingSimpleDeclarationsFromClass( declarations, methodDeclarationLocation)) { - ASTNameInContext definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache); + IASTName definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache); if (definition != null) { - insertLocation.setNodeToInsertBefore(findFirstSurroundingParentFunctionNode( - definition.getName()), definition.getTranslationUnit()); + insertLocation.setNodeToInsertBefore(findFirstSurroundingParentFunctionNode(definition), + definition.getTranslationUnit().getOriginatingTranslationUnit()); } } if (insertLocation.getTranslationUnit() == null) { - ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(declarationTu, astCache); + ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit( + declarationTu, astCache); if (partner != null) { insertLocation.setParentNode(astCache.getAST(partner, null), partner); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/ASTNameInContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/ASTNameInContext.java deleted file mode 100644 index 0e1ea0d3cc3..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/ASTNameInContext.java +++ /dev/null @@ -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; - } -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder2.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder2.java index 5d5598a52e2..86c7baa48b5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder2.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/DefinitionFinder2.java @@ -43,7 +43,7 @@ import org.eclipse.cdt.internal.ui.util.EditorUtility; */ public class DefinitionFinder2 { - public static ASTNameInContext getDefinition(IASTSimpleDeclaration simpleDeclaration, + public static IASTName getDefinition(IASTSimpleDeclaration simpleDeclaration, RefactoringASTCache astCache) throws CoreException { IIndex index = astCache.getIndex(); IASTDeclarator declarator = simpleDeclaration.getDeclarators()[0]; @@ -57,10 +57,10 @@ public class DefinitionFinder2 { return getDefinition(binding, astCache, index); } - private static ASTNameInContext getDefinition(IIndexBinding binding, + private static IASTName getDefinition(IIndexBinding binding, RefactoringASTCache astCache, IIndex index) throws CoreException { Set searchedFiles = new HashSet(); - List definitions = new ArrayList(); + List definitions = new ArrayList(); IEditorPart[] dirtyEditors = EditorUtility.getDirtyEditors(true); for (IEditorPart editor : dirtyEditors) { IEditorInput editorInput = editor.getEditorInput(); @@ -85,17 +85,17 @@ public class DefinitionFinder2 { } private static void findDefinitionsInTranslationUnit(IIndexBinding binding, ITranslationUnit tu, - RefactoringASTCache astCache, List definitions, IProgressMonitor pm) + RefactoringASTCache astCache, List definitions, IProgressMonitor pm) throws OperationCanceledException, CoreException { IASTTranslationUnit ast = astCache.getAST(tu, pm); findDefinitionsInAST(binding, ast, tu, definitions); } private static void findDefinitionsInAST(IIndexBinding binding, IASTTranslationUnit ast, - ITranslationUnit tu, List definitions) { + ITranslationUnit tu, List definitions) { for (IName definition : ast.getDefinitions(binding)) { if (definition instanceof IASTName) { - definitions.add(new ASTNameInContext((IASTName) definition, tu)); + definitions.add((IASTName) definition); } } }