1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Eliminated ASTNameInContext class.

This commit is contained in:
Sergey Prigogin 2011-04-13 02:42:58 +00:00
parent 987feb04be
commit 6e4f88ae53
3 changed files with 15 additions and 49 deletions

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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<String> searchedFiles = new HashSet<String>();
List<ASTNameInContext> definitions = new ArrayList<ASTNameInContext>();
List<IASTName> definitions = new ArrayList<IASTName>();
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<ASTNameInContext> definitions, IProgressMonitor pm)
RefactoringASTCache astCache, List<IASTName> 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<ASTNameInContext> definitions) {
ITranslationUnit tu, List<IASTName> definitions) {
for (IName definition : ast.getDefinitions(binding)) {
if (definition instanceof IASTName) {
definitions.add(new ASTNameInContext((IASTName) definition, tu));
definitions.add((IASTName) definition);
}
}
}