mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
Bug 273525 - Do not search for insert location twice. Patch by Marc-Andre Laperle.
This commit is contained in:
parent
c78ccde0de
commit
2bb4e50214
1 changed files with 16 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
|
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
|
||||||
* Rapperswil, University of applied sciences and others
|
* Rapperswil, University of applied sciences and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -9,6 +9,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
|
* Marc-Andre Laperle - do not search for definition insert location twice.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters;
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
||||||
CheckConditionsContext checkContext) throws CoreException, OperationCanceledException {
|
CheckConditionsContext checkContext) throws CoreException, OperationCanceledException {
|
||||||
RefactoringStatus result = new RefactoringStatus();
|
RefactoringStatus result = new RefactoringStatus();
|
||||||
if (!context.isImplementationInHeader()) {
|
if (!context.isImplementationInHeader()) {
|
||||||
definitionInsertLocation = findInsertLocation();
|
findDefinitionInsertLocation();
|
||||||
if (definitionInsertLocation == null || tu.equals(definitionInsertLocation.getTranslationUnit())) {
|
if (definitionInsertLocation == null || tu.equals(definitionInsertLocation.getTranslationUnit())) {
|
||||||
result.addInfo(Messages.GenerateGettersAndSettersRefactoring_NoImplFile);
|
result.addInfo(Messages.GenerateGettersAndSettersRefactoring_NoImplFile);
|
||||||
}
|
}
|
||||||
|
@ -248,11 +249,11 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
||||||
|
|
||||||
private void addDefinition(ModificationCollector collector, List<IASTFunctionDefinition> definitions)
|
private void addDefinition(ModificationCollector collector, List<IASTFunctionDefinition> definitions)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
InsertLocation2 location = findInsertLocation();
|
findDefinitionInsertLocation();
|
||||||
IASTNode parent = location.getParentOfNodeToInsertBefore();
|
IASTNode parent = definitionInsertLocation.getParentOfNodeToInsertBefore();
|
||||||
IASTTranslationUnit ast = parent.getTranslationUnit();
|
IASTTranslationUnit ast = parent.getTranslationUnit();
|
||||||
ASTRewrite rewrite = collector.rewriterForTranslationUnit(ast);
|
ASTRewrite rewrite = collector.rewriterForTranslationUnit(ast);
|
||||||
IASTNode nodeToInsertBefore = location.getNodeToInsertBefore();
|
IASTNode nodeToInsertBefore = definitionInsertLocation.getNodeToInsertBefore();
|
||||||
ContainerNode cont = new ContainerNode();
|
ContainerNode cont = new ContainerNode();
|
||||||
for (IASTFunctionDefinition functionDefinition : definitions) {
|
for (IASTFunctionDefinition functionDefinition : definitions) {
|
||||||
cont.addNode(functionDefinition);
|
cont.addNode(functionDefinition);
|
||||||
|
@ -264,16 +265,20 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InsertLocation2 findInsertLocation() throws CoreException {
|
private void findDefinitionInsertLocation() throws CoreException {
|
||||||
|
if (definitionInsertLocation != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
IASTSimpleDeclaration decl = context.existingFields.get(0);
|
IASTSimpleDeclaration decl = context.existingFields.get(0);
|
||||||
InsertLocation2 insertLocation = MethodDefinitionInsertLocationFinder2.find(
|
InsertLocation2 location = MethodDefinitionInsertLocationFinder2.find(
|
||||||
decl.getFileLocation(), decl.getParent(), astCache);
|
decl.getFileLocation(), decl.getParent(), astCache);
|
||||||
|
|
||||||
if (insertLocation.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) {
|
if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) {
|
||||||
insertLocation.setNodeToInsertAfter(NodeHelper.findTopLevelParent(decl), tu);
|
location.setNodeToInsertAfter(NodeHelper.findTopLevelParent(decl), tu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return insertLocation;
|
definitionInsertLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue