mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Renamed InsertLocation2 to InsertLocation and MethodDefinitionInsertLocationFinder2 to MethodDefinitionInsertLocationFinder2.
This commit is contained in:
parent
6c11ab94ca
commit
9bcc2f85f4
6 changed files with 173 additions and 413 deletions
|
@ -51,8 +51,8 @@ import org.eclipse.cdt.internal.ui.refactoring.AddDeclarationNodeToClassChange;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
|
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.implementmethod.InsertLocation2;
|
import org.eclipse.cdt.internal.ui.refactoring.implementmethod.InsertLocation;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.implementmethod.MethodDefinitionInsertLocationFinder2;
|
import org.eclipse.cdt.internal.ui.refactoring.implementmethod.MethodDefinitionInsertLocationFinder;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.Checks;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.Checks;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
|
||||||
|
@ -90,7 +90,7 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
||||||
|
|
||||||
private static final String MEMBER_DECLARATION = "MEMBER_DECLARATION"; //$NON-NLS-1$
|
private static final String MEMBER_DECLARATION = "MEMBER_DECLARATION"; //$NON-NLS-1$
|
||||||
private final GetterAndSetterContext context;
|
private final GetterAndSetterContext context;
|
||||||
private InsertLocation2 definitionInsertLocation;
|
private InsertLocation definitionInsertLocation;
|
||||||
|
|
||||||
public GenerateGettersAndSettersRefactoring(ICElement element, ISelection selection,
|
public GenerateGettersAndSettersRefactoring(ICElement element, ISelection selection,
|
||||||
ICProject project, RefactoringASTCache astCache) {
|
ICProject project, RefactoringASTCache astCache) {
|
||||||
|
@ -271,8 +271,8 @@ public class GenerateGettersAndSettersRefactoring extends CRefactoring2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTSimpleDeclaration decl = context.existingFields.get(0);
|
IASTSimpleDeclaration decl = context.existingFields.get(0);
|
||||||
MethodDefinitionInsertLocationFinder2 methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder2();
|
MethodDefinitionInsertLocationFinder methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder();
|
||||||
InsertLocation2 location = methodDefinitionInsertLocationFinder.find(
|
InsertLocation location = methodDefinitionInsertLocationFinder.find(
|
||||||
tu, decl.getFileLocation(), decl.getParent(), astCache, pm);
|
tu, decl.getFileLocation(), decl.getParent(), astCache, pm);
|
||||||
|
|
||||||
if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) {
|
if (location.getFile() == null || NodeHelper.isContainedInTemplateDeclaration(decl)) {
|
||||||
|
|
|
@ -74,15 +74,15 @@ import org.eclipse.cdt.internal.ui.refactoring.utils.SelectionHelper;
|
||||||
public class ImplementMethodRefactoring extends CRefactoring2 {
|
public class ImplementMethodRefactoring extends CRefactoring2 {
|
||||||
private ICPPASTFunctionDeclarator createdMethodDeclarator;
|
private ICPPASTFunctionDeclarator createdMethodDeclarator;
|
||||||
private ImplementMethodData data;
|
private ImplementMethodData data;
|
||||||
private MethodDefinitionInsertLocationFinder2 methodDefinitionInsertLocationFinder;
|
private MethodDefinitionInsertLocationFinder methodDefinitionInsertLocationFinder;
|
||||||
private Map<IASTSimpleDeclaration, InsertLocation2> insertLocations;
|
private Map<IASTSimpleDeclaration, InsertLocation> insertLocations;
|
||||||
private static ICPPNodeFactory nodeFactory = ASTNodeFactoryFactory.getDefaultCPPNodeFactory();
|
private static ICPPNodeFactory nodeFactory = ASTNodeFactoryFactory.getDefaultCPPNodeFactory();
|
||||||
|
|
||||||
public ImplementMethodRefactoring(ICElement element, ISelection selection, ICProject project, RefactoringASTCache astCache) {
|
public ImplementMethodRefactoring(ICElement element, ISelection selection, ICProject project, RefactoringASTCache astCache) {
|
||||||
super(element, selection, project, astCache);
|
super(element, selection, project, astCache);
|
||||||
data = new ImplementMethodData();
|
data = new ImplementMethodData();
|
||||||
methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder2();
|
methodDefinitionInsertLocationFinder = new MethodDefinitionInsertLocationFinder();
|
||||||
insertLocations = new HashMap<IASTSimpleDeclaration, InsertLocation2>();
|
insertLocations = new HashMap<IASTSimpleDeclaration, InsertLocation>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -140,7 +140,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
|
||||||
if (binding instanceof ICPPMethod) {
|
if (binding instanceof ICPPMethod) {
|
||||||
ICPPMethod methodBinding = (ICPPMethod) binding;
|
ICPPMethod methodBinding = (ICPPMethod) binding;
|
||||||
if (methodBinding.isPureVirtual()) {
|
if (methodBinding.isPureVirtual()) {
|
||||||
return false; //Êpure virtual not handled for now, see bug 303870
|
return false; //�pure virtual not handled for now, see bug 303870
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
}
|
}
|
||||||
IASTSimpleDeclaration decl = config.getDeclaration();
|
IASTSimpleDeclaration decl = config.getDeclaration();
|
||||||
InsertLocation2 insertLocation = findInsertLocation(decl, subMonitor);
|
InsertLocation insertLocation = findInsertLocation(decl, subMonitor);
|
||||||
if (subMonitor.isCanceled()) {
|
if (subMonitor.isCanceled()) {
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
}
|
}
|
||||||
|
@ -218,11 +218,11 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private InsertLocation2 findInsertLocation(IASTSimpleDeclaration methodDeclaration, IProgressMonitor subMonitor) throws CoreException {
|
private InsertLocation findInsertLocation(IASTSimpleDeclaration methodDeclaration, IProgressMonitor subMonitor) throws CoreException {
|
||||||
if (insertLocations.containsKey(methodDeclaration)) {
|
if (insertLocations.containsKey(methodDeclaration)) {
|
||||||
return insertLocations.get(methodDeclaration);
|
return insertLocations.get(methodDeclaration);
|
||||||
}
|
}
|
||||||
InsertLocation2 insertLocation = methodDefinitionInsertLocationFinder.find(tu, methodDeclaration.getFileLocation(), methodDeclaration.getParent(), astCache, subMonitor);
|
InsertLocation insertLocation = methodDefinitionInsertLocationFinder.find(tu, methodDeclaration.getFileLocation(), methodDeclaration.getParent(), astCache, subMonitor);
|
||||||
|
|
||||||
if (insertLocation.getTranslationUnit() == null || NodeHelper.isContainedInTemplateDeclaration(methodDeclaration)) {
|
if (insertLocation.getTranslationUnit() == null || NodeHelper.isContainedInTemplateDeclaration(methodDeclaration)) {
|
||||||
insertLocation.setNodeToInsertAfter(NodeHelper.findTopLevelParent(methodDeclaration), tu);
|
insertLocation.setNodeToInsertAfter(NodeHelper.findTopLevelParent(methodDeclaration), tu);
|
||||||
|
@ -231,7 +231,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
|
||||||
return insertLocation;
|
return insertLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTDeclaration createFunctionDefinition(IASTTranslationUnit unit, IASTSimpleDeclaration methodDeclaration, InsertLocation2 insertLocation) throws CoreException {
|
private IASTDeclaration createFunctionDefinition(IASTTranslationUnit unit, IASTSimpleDeclaration methodDeclaration, InsertLocation insertLocation) throws CoreException {
|
||||||
IASTDeclSpecifier declSpecifier = methodDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations);
|
IASTDeclSpecifier declSpecifier = methodDeclaration.getDeclSpecifier().copy(CopyStyle.withLocations);
|
||||||
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) methodDeclaration.getDeclarators()[0];
|
ICPPASTFunctionDeclarator functionDeclarator = (ICPPASTFunctionDeclarator) methodDeclaration.getDeclarators()[0];
|
||||||
IASTNode declarationParent = methodDeclaration.getParent();
|
IASTNode declarationParent = methodDeclaration.getParent();
|
||||||
|
@ -274,7 +274,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICPPASTQualifiedName createQualifiedNameFor(IASTFunctionDeclarator functionDeclarator,
|
private ICPPASTQualifiedName createQualifiedNameFor(IASTFunctionDeclarator functionDeclarator,
|
||||||
IASTNode declarationParent, InsertLocation2 insertLocation) throws CoreException {
|
IASTNode declarationParent, InsertLocation insertLocation) throws CoreException {
|
||||||
int insertOffset = insertLocation.getInsertPosition();
|
int insertOffset = insertLocation.getInsertPosition();
|
||||||
return NameHelper.createQualifiedNameFor(
|
return NameHelper.createQualifiedNameFor(
|
||||||
functionDeclarator.getName(), tu, functionDeclarator.getFileLocation().getNodeOffset(),
|
functionDeclarator.getName(), tu, functionDeclarator.getFileLocation().getNodeOffset(),
|
||||||
|
@ -298,7 +298,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
|
||||||
files.add(file);
|
files.add(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (InsertLocation2 insertLocation : insertLocations.values()) {
|
for (InsertLocation insertLocation : insertLocations.values()) {
|
||||||
if (insertLocation != null) {
|
if (insertLocation != null) {
|
||||||
file = insertLocation.getFile();
|
file = insertLocation.getFile();
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
@ -331,7 +331,7 @@ public class ImplementMethodRefactoring extends CRefactoring2 {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (InsertLocation2 insertLocation : insertLocations.values()) {
|
for (InsertLocation insertLocation : insertLocations.values()) {
|
||||||
if (insertLocation != null && tu.equals(insertLocation.getTranslationUnit())) {
|
if (insertLocation != null && tu.equals(insertLocation.getTranslationUnit())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008, 2010 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
|
||||||
|
@ -7,29 +7,33 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
|
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is returned when using the find-method of the MethodDefinitionInsertLocationFinder.
|
* Is returned when using the find method of the MethodDefinitionInsertLocationFinder.
|
||||||
* Contains all the infos needet to insert at the correct position.
|
* Contains all the information needed to insert at the correct position.
|
||||||
|
* This class is intended as a replacement for InsertLocation.
|
||||||
*
|
*
|
||||||
* @author Lukas Felber
|
* @author Lukas Felber
|
||||||
*/
|
*/
|
||||||
public class InsertLocation {
|
public class InsertLocation {
|
||||||
private IFile insertFile;
|
|
||||||
private IASTNode nodeToInsertAfter;
|
private IASTNode nodeToInsertAfter;
|
||||||
private IASTNode nodeToInsertBefore;
|
private IASTNode nodeToInsertBefore;
|
||||||
private IASTTranslationUnit targetTranslationUnit;
|
private IASTNode parentNode;
|
||||||
|
private ITranslationUnit tu;
|
||||||
|
|
||||||
|
public InsertLocation() {
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasAnyNode() {
|
public boolean hasAnyNode() {
|
||||||
return nodeToInsertAfter != null || nodeToInsertBefore != null;
|
return nodeToInsertAfter != null || nodeToInsertBefore != null;
|
||||||
|
@ -39,59 +43,41 @@ public class InsertLocation {
|
||||||
return nodeToInsertBefore;
|
return nodeToInsertBefore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTNode getPartenOfNodeToInsertBefore() throws CoreException {
|
public IASTNode getParentOfNodeToInsertBefore() throws CoreException {
|
||||||
IASTNode affectedNode = getAffectedNode();
|
IASTNode node = nodeToInsertBefore != null ? nodeToInsertBefore : nodeToInsertAfter;
|
||||||
return (affectedNode != null) ? affectedNode.getParent() : getTargetTranslationUnit();
|
return node != null ? node.getParent() : parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTNode getAffectedNode() {
|
public ITranslationUnit getTranslationUnit() {
|
||||||
IASTNode concernedNode = (nodeToInsertBefore != null) ? nodeToInsertBefore : nodeToInsertAfter;
|
return tu;
|
||||||
return concernedNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFile getInsertFile() {
|
public IFile getFile() {
|
||||||
return insertFile;
|
return tu != null ? (IFile) tu.getResource() : null;
|
||||||
}
|
|
||||||
|
|
||||||
public void setInsertFile(IFile insertFile) {
|
|
||||||
this.insertFile = insertFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNodeToInsertAfter(IASTNode nodeToInsertAfter) {
|
|
||||||
this.nodeToInsertAfter = nodeToInsertAfter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNodeToInsertBefore(IASTNode nodeToInsertBefore) {
|
|
||||||
this.nodeToInsertBefore = nodeToInsertBefore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasFile() {
|
|
||||||
return insertFile != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTTranslationUnit getTargetTranslationUnit() throws CoreException{
|
|
||||||
if (targetTranslationUnit == null) {
|
|
||||||
loadTargetTranslationUnit();
|
|
||||||
}
|
|
||||||
return targetTranslationUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadTargetTranslationUnit() throws CoreException{
|
|
||||||
IASTNode affectedNode = getAffectedNode();
|
|
||||||
if (affectedNode != null) {
|
|
||||||
targetTranslationUnit = affectedNode.getTranslationUnit();
|
|
||||||
} else if (hasFile()) {
|
|
||||||
targetTranslationUnit = TranslationUnitHelper.loadTranslationUnit(insertFile, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInsertPosition() {
|
public int getInsertPosition() {
|
||||||
if (nodeToInsertBefore != null) {
|
if (nodeToInsertBefore != null) {
|
||||||
return nodeToInsertBefore.getFileLocation().getNodeOffset();
|
return nodeToInsertBefore.getFileLocation().getNodeOffset();
|
||||||
} else if (nodeToInsertAfter != null) {
|
} else if (nodeToInsertAfter != null) {
|
||||||
return nodeToInsertAfter.getFileLocation().getNodeOffset() + nodeToInsertAfter.getFileLocation().getNodeLength();
|
IASTFileLocation fileLocation = nodeToInsertAfter.getFileLocation();
|
||||||
} else {
|
return fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNodeToInsertAfter(IASTNode nodeToInsertAfter, ITranslationUnit tu) {
|
||||||
|
this.nodeToInsertAfter = nodeToInsertAfter;
|
||||||
|
this.tu = tu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNodeToInsertBefore(IASTNode nodeToInsertBefore, ITranslationUnit tu) {
|
||||||
|
this.nodeToInsertBefore = nodeToInsertBefore;
|
||||||
|
this.tu = tu;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentNode(IASTNode parentNode, ITranslationUnit tu) {
|
||||||
|
this.parentNode = parentNode;
|
||||||
|
this.tu = tu;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
* Sergey Prigogin (Google)
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
|
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is returned when using the find method of the MethodDefinitionInsertLocationFinder.
|
|
||||||
* Contains all the information needed to insert at the correct position.
|
|
||||||
* This class is intended as a replacement for InsertLocation.
|
|
||||||
*
|
|
||||||
* @author Lukas Felber
|
|
||||||
*/
|
|
||||||
public class InsertLocation2 {
|
|
||||||
private IASTNode nodeToInsertAfter;
|
|
||||||
private IASTNode nodeToInsertBefore;
|
|
||||||
private IASTNode parentNode;
|
|
||||||
private ITranslationUnit tu;
|
|
||||||
|
|
||||||
public InsertLocation2() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasAnyNode() {
|
|
||||||
return nodeToInsertAfter != null || nodeToInsertBefore != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTNode getNodeToInsertBefore() {
|
|
||||||
return nodeToInsertBefore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IASTNode getParentOfNodeToInsertBefore() throws CoreException {
|
|
||||||
IASTNode node = nodeToInsertBefore != null ? nodeToInsertBefore : nodeToInsertAfter;
|
|
||||||
return node != null ? node.getParent() : parentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ITranslationUnit getTranslationUnit() {
|
|
||||||
return tu;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFile getFile() {
|
|
||||||
return tu != null ? (IFile) tu.getResource() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInsertPosition() {
|
|
||||||
if (nodeToInsertBefore != null) {
|
|
||||||
return nodeToInsertBefore.getFileLocation().getNodeOffset();
|
|
||||||
} else if (nodeToInsertAfter != null) {
|
|
||||||
IASTFileLocation fileLocation = nodeToInsertAfter.getFileLocation();
|
|
||||||
return fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNodeToInsertAfter(IASTNode nodeToInsertAfter, ITranslationUnit tu) {
|
|
||||||
this.nodeToInsertAfter = nodeToInsertAfter;
|
|
||||||
this.tu = tu;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNodeToInsertBefore(IASTNode nodeToInsertBefore, ITranslationUnit tu) {
|
|
||||||
this.nodeToInsertBefore = nodeToInsertBefore;
|
|
||||||
this.tu = tu;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParentNode(IASTNode parentNode, ITranslationUnit tu) {
|
|
||||||
this.parentNode = parentNode;
|
|
||||||
this.tu = tu;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2008 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
|
||||||
|
@ -7,17 +7,22 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
|
* Marc-Andre Laperle
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
|
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
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;
|
||||||
|
@ -28,20 +33,88 @@ 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;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder;
|
import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.DefinitionFinder;
|
import org.eclipse.cdt.internal.ui.refactoring.RefactoringASTCache;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.FileHelper;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the information that are needed to tell where a MethodDefinition of a certain
|
* Finds the information that are needed to tell where a method definition of a certain
|
||||||
* method declaration should be inserted.
|
* method declaration should be inserted.
|
||||||
|
* This class is intended as a replacement for MethodDefinitionInsertLocationFinder.
|
||||||
*
|
*
|
||||||
* @author Mirko Stocker, Lukas Felber
|
* @author Mirko Stocker, Lukas Felber
|
||||||
*/
|
*/
|
||||||
public class MethodDefinitionInsertLocationFinder {
|
public class MethodDefinitionInsertLocationFinder {
|
||||||
|
// We cache DefinitionFinder2.getDefinition results because refactorings like Implement Method
|
||||||
|
// might want to find multiple insert locations in the same translation unit. This prevents
|
||||||
|
// many redundant calls to DefinitionFinder2.getDefinition and speeds up the process quite
|
||||||
|
//a bit. Unfortunately, this has the minor side-effect or having to instantiate this class.
|
||||||
|
Map<IASTSimpleDeclaration, IASTName> cachedDeclarationToDefinition =
|
||||||
|
new HashMap<IASTSimpleDeclaration, IASTName>();
|
||||||
|
|
||||||
|
public InsertLocation find(ITranslationUnit declarationTu, IASTFileLocation methodDeclarationLocation,
|
||||||
|
IASTNode parent, RefactoringASTCache astCache, IProgressMonitor pm) throws CoreException {
|
||||||
|
IASTDeclaration[] declarations = NodeHelper.getDeclarations(parent);
|
||||||
|
InsertLocation insertLocation = new InsertLocation();
|
||||||
|
|
||||||
|
Collection<IASTSimpleDeclaration> allPreviousSimpleDeclarationsFromClassInReverseOrder =
|
||||||
|
getAllPreviousSimpleDeclarationsFromClassInReverseOrder(declarations, methodDeclarationLocation, pm);
|
||||||
|
Collection<IASTSimpleDeclaration> allFollowingSimpleDeclarationsFromClass =
|
||||||
|
getAllFollowingSimpleDeclarationsFromClass(declarations, methodDeclarationLocation, pm);
|
||||||
|
|
||||||
|
for (IASTSimpleDeclaration simpleDeclaration : allPreviousSimpleDeclarationsFromClassInReverseOrder) {
|
||||||
|
if (pm != null && pm.isCanceled()) {
|
||||||
|
throw new OperationCanceledException();
|
||||||
|
}
|
||||||
|
|
||||||
|
IASTName definition = null;
|
||||||
|
if (cachedDeclarationToDefinition.containsKey(simpleDeclaration)) {
|
||||||
|
definition = cachedDeclarationToDefinition.get(simpleDeclaration);
|
||||||
|
} else {
|
||||||
|
definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache, pm);
|
||||||
|
if (definition != null) {
|
||||||
|
cachedDeclarationToDefinition.put(simpleDeclaration, definition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definition != null) {
|
||||||
|
insertLocation.setNodeToInsertAfter(findFirstSurroundingParentFunctionNode(
|
||||||
|
definition), definition.getTranslationUnit().getOriginatingTranslationUnit());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IASTSimpleDeclaration simpleDeclaration : allFollowingSimpleDeclarationsFromClass) {
|
||||||
|
if (pm != null && pm.isCanceled()) {
|
||||||
|
throw new OperationCanceledException();
|
||||||
|
}
|
||||||
|
|
||||||
|
IASTName definition = null;
|
||||||
|
if (cachedDeclarationToDefinition.containsKey(simpleDeclaration)) {
|
||||||
|
definition = cachedDeclarationToDefinition.get(simpleDeclaration);
|
||||||
|
} else {
|
||||||
|
definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache, pm);
|
||||||
|
if (definition != null) {
|
||||||
|
cachedDeclarationToDefinition.put(simpleDeclaration, definition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definition != null) {
|
||||||
|
insertLocation.setNodeToInsertBefore(findFirstSurroundingParentFunctionNode(definition),
|
||||||
|
definition.getTranslationUnit().getOriginatingTranslationUnit());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (insertLocation.getTranslationUnit() == null) {
|
||||||
|
ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(
|
||||||
|
declarationTu, astCache);
|
||||||
|
if (partner != null) {
|
||||||
|
insertLocation.setParentNode(astCache.getAST(partner, null), partner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return insertLocation;
|
||||||
|
}
|
||||||
|
|
||||||
private static IASTNode findFunctionDefinitionInParents(IASTNode node) {
|
private static IASTNode findFunctionDefinitionInParents(IASTNode node) {
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
|
@ -57,82 +130,60 @@ public class MethodDefinitionInsertLocationFinder {
|
||||||
|
|
||||||
private static IASTNode findFirstSurroundingParentFunctionNode(IASTNode definition) {
|
private static IASTNode findFirstSurroundingParentFunctionNode(IASTNode definition) {
|
||||||
IASTNode functionDefinitionInParents = findFunctionDefinitionInParents(definition);
|
IASTNode functionDefinitionInParents = findFunctionDefinitionInParents(definition);
|
||||||
if (functionDefinitionInParents == null ||
|
if (functionDefinitionInParents == null) {
|
||||||
functionDefinitionInParents.getNodeLocations().length == 0) {
|
return null;
|
||||||
|
}
|
||||||
|
if (functionDefinitionInParents.getNodeLocations().length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return functionDefinitionInParents;
|
return functionDefinitionInParents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InsertLocation find(IASTFileLocation methodDeclarationLocation, IASTNode parent,
|
|
||||||
IFile file) throws CoreException {
|
|
||||||
IASTName definition = null;
|
|
||||||
IASTDeclaration[] declarations = NodeHelper.getDeclarations(parent);
|
|
||||||
InsertLocation result = new InsertLocation();
|
|
||||||
|
|
||||||
for (IASTSimpleDeclaration simpleDeclaration : getAllPreviousSimpleDeclarationsFromClassInReverseOrder(declarations, methodDeclarationLocation)) {
|
|
||||||
definition = DefinitionFinder.getDefinition(simpleDeclaration, file);
|
|
||||||
|
|
||||||
if (definition != null) {
|
|
||||||
result.setNodeToInsertAfter(findFirstSurroundingParentFunctionNode(definition));
|
|
||||||
result.setInsertFile(FileHelper.getIFilefromIASTNode(definition));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IASTSimpleDeclaration simpleDeclaration : getAllFollowingSimpleDeclarationsFromClass(declarations, methodDeclarationLocation)) {
|
|
||||||
definition = DefinitionFinder.getDefinition(simpleDeclaration, file);
|
|
||||||
|
|
||||||
if (definition != null) {
|
|
||||||
result.setNodeToInsertBefore(findFirstSurroundingParentFunctionNode(definition));
|
|
||||||
result.setInsertFile(FileHelper.getIFilefromIASTNode(definition));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ITranslationUnit tu = (ITranslationUnit) CCorePlugin.getDefault().getCoreModel().create(file);
|
|
||||||
ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(tu);
|
|
||||||
if (partner != null) {
|
|
||||||
IFile fileForLocation = ResourceLookup.selectFileForLocation(partner.getLocation(), file.getProject());
|
|
||||||
if (fileForLocation != null && fileForLocation.exists()) {
|
|
||||||
result.setInsertFile(fileForLocation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches the given class for all IASTSimpleDeclarations occurring before 'method'
|
* Searches the given class for all IASTSimpleDeclarations occurring before 'method'
|
||||||
* and returns them in reverse order.
|
* and returns them in reverse order.
|
||||||
*
|
*
|
||||||
* @param declarations to be searched
|
* @param declarations to be searched
|
||||||
* @param methodPosition on which the search aborts
|
* @param methodPosition on which the search aborts
|
||||||
|
* @param pm
|
||||||
* @return all declarations, sorted in reverse order
|
* @return all declarations, sorted in reverse order
|
||||||
*/
|
*/
|
||||||
private static Collection<IASTSimpleDeclaration> getAllPreviousSimpleDeclarationsFromClassInReverseOrder(
|
private static Collection<IASTSimpleDeclaration> getAllPreviousSimpleDeclarationsFromClassInReverseOrder(
|
||||||
IASTDeclaration[] declarations, IASTFileLocation methodPosition) {
|
IASTDeclaration[] declarations, IASTFileLocation methodPosition, IProgressMonitor pm) {
|
||||||
ArrayList<IASTSimpleDeclaration> allIASTSimpleDeclarations = new ArrayList<IASTSimpleDeclaration>();
|
ArrayList<IASTSimpleDeclaration> outputDeclarations = new ArrayList<IASTSimpleDeclaration>();
|
||||||
for (IASTDeclaration decl : declarations) {
|
if (declarations.length >= 0) {
|
||||||
if (decl.getFileLocation().getStartingLineNumber() >= methodPosition.getStartingLineNumber()) {
|
for (IASTDeclaration decl : declarations) {
|
||||||
return allIASTSimpleDeclarations;
|
if (pm != null && pm.isCanceled()) {
|
||||||
}
|
return outputDeclarations;
|
||||||
if (isMemberFunctionDeclaration(decl)) {
|
}
|
||||||
allIASTSimpleDeclarations.add(0, (IASTSimpleDeclaration) decl);
|
if (decl.getFileLocation().getStartingLineNumber() >= methodPosition.getStartingLineNumber()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (isMemberFunctionDeclaration(decl)) {
|
||||||
|
outputDeclarations.add((IASTSimpleDeclaration) decl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allIASTSimpleDeclarations;
|
Collections.reverse(outputDeclarations);
|
||||||
|
return outputDeclarations;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<IASTSimpleDeclaration> getAllFollowingSimpleDeclarationsFromClass(
|
private static Collection<IASTSimpleDeclaration> getAllFollowingSimpleDeclarationsFromClass(
|
||||||
IASTDeclaration[] declarations, IASTFileLocation methodPosition) {
|
IASTDeclaration[] declarations, IASTFileLocation methodPosition, IProgressMonitor pm) {
|
||||||
ArrayList<IASTSimpleDeclaration> allIASTSimpleDeclarations = new ArrayList<IASTSimpleDeclaration>();
|
ArrayList<IASTSimpleDeclaration> outputDeclarations = new ArrayList<IASTSimpleDeclaration>();
|
||||||
|
|
||||||
for (IASTDeclaration decl : declarations) {
|
if (declarations.length >= 0) {
|
||||||
if (isMemberFunctionDeclaration(decl) &&
|
for (IASTDeclaration decl : declarations) {
|
||||||
decl.getFileLocation().getStartingLineNumber() > methodPosition.getStartingLineNumber() ) {
|
if (pm != null && pm.isCanceled()) {
|
||||||
allIASTSimpleDeclarations.add((IASTSimpleDeclaration) decl);
|
return outputDeclarations;
|
||||||
|
}
|
||||||
|
if (isMemberFunctionDeclaration(decl) &&
|
||||||
|
decl.getFileLocation().getStartingLineNumber() > methodPosition.getStartingLineNumber() ) {
|
||||||
|
outputDeclarations.add((IASTSimpleDeclaration) decl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allIASTSimpleDeclarations;
|
return outputDeclarations;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isMemberFunctionDeclaration(IASTDeclaration decl) {
|
private static boolean isMemberFunctionDeclaration(IASTDeclaration decl) {
|
||||||
|
|
|
@ -1,194 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
|
|
||||||
* Rapperswil, University of applied sciences 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:
|
|
||||||
* Institute for Software - initial API and implementation
|
|
||||||
* Sergey Prigogin (Google)
|
|
||||||
* Marc-Andre Laperle
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.implementmethod;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
|
||||||
|
|
||||||
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;
|
|
||||||
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.DefinitionFinder2;
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.NodeHelper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the information that are needed to tell where a method definition of a certain
|
|
||||||
* method declaration should be inserted.
|
|
||||||
* This class is intended as a replacement for MethodDefinitionInsertLocationFinder.
|
|
||||||
*
|
|
||||||
* @author Mirko Stocker, Lukas Felber
|
|
||||||
*/
|
|
||||||
public class MethodDefinitionInsertLocationFinder2 {
|
|
||||||
// We cache DefinitionFinder2.getDefinition results because refactorings like Implement Method
|
|
||||||
// might want to find multiple insert locations in the same translation unit. This prevents
|
|
||||||
// many redundant calls to DefinitionFinder2.getDefinition and speeds up the process quite
|
|
||||||
//a bit. Unfortunately, this has the minor side-effect or having to instantiate this class.
|
|
||||||
Map<IASTSimpleDeclaration, IASTName> cachedDeclarationToDefinition =
|
|
||||||
new HashMap<IASTSimpleDeclaration, IASTName>();
|
|
||||||
|
|
||||||
public InsertLocation2 find(ITranslationUnit declarationTu, IASTFileLocation methodDeclarationLocation,
|
|
||||||
IASTNode parent, RefactoringASTCache astCache, IProgressMonitor pm) throws CoreException {
|
|
||||||
IASTDeclaration[] declarations = NodeHelper.getDeclarations(parent);
|
|
||||||
InsertLocation2 insertLocation = new InsertLocation2();
|
|
||||||
|
|
||||||
Collection<IASTSimpleDeclaration> allPreviousSimpleDeclarationsFromClassInReverseOrder =
|
|
||||||
getAllPreviousSimpleDeclarationsFromClassInReverseOrder(declarations, methodDeclarationLocation, pm);
|
|
||||||
Collection<IASTSimpleDeclaration> allFollowingSimpleDeclarationsFromClass =
|
|
||||||
getAllFollowingSimpleDeclarationsFromClass(declarations, methodDeclarationLocation, pm);
|
|
||||||
|
|
||||||
for (IASTSimpleDeclaration simpleDeclaration : allPreviousSimpleDeclarationsFromClassInReverseOrder) {
|
|
||||||
if (pm != null && pm.isCanceled()) {
|
|
||||||
throw new OperationCanceledException();
|
|
||||||
}
|
|
||||||
|
|
||||||
IASTName definition = null;
|
|
||||||
if (cachedDeclarationToDefinition.containsKey(simpleDeclaration)) {
|
|
||||||
definition = cachedDeclarationToDefinition.get(simpleDeclaration);
|
|
||||||
} else {
|
|
||||||
definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache, pm);
|
|
||||||
if (definition != null) {
|
|
||||||
cachedDeclarationToDefinition.put(simpleDeclaration, definition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (definition != null) {
|
|
||||||
insertLocation.setNodeToInsertAfter(findFirstSurroundingParentFunctionNode(
|
|
||||||
definition), definition.getTranslationUnit().getOriginatingTranslationUnit());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IASTSimpleDeclaration simpleDeclaration : allFollowingSimpleDeclarationsFromClass) {
|
|
||||||
if (pm != null && pm.isCanceled()) {
|
|
||||||
throw new OperationCanceledException();
|
|
||||||
}
|
|
||||||
|
|
||||||
IASTName definition = null;
|
|
||||||
if (cachedDeclarationToDefinition.containsKey(simpleDeclaration)) {
|
|
||||||
definition = cachedDeclarationToDefinition.get(simpleDeclaration);
|
|
||||||
} else {
|
|
||||||
definition = DefinitionFinder2.getDefinition(simpleDeclaration, astCache, pm);
|
|
||||||
if (definition != null) {
|
|
||||||
cachedDeclarationToDefinition.put(simpleDeclaration, definition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (definition != null) {
|
|
||||||
insertLocation.setNodeToInsertBefore(findFirstSurroundingParentFunctionNode(definition),
|
|
||||||
definition.getTranslationUnit().getOriginatingTranslationUnit());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (insertLocation.getTranslationUnit() == null) {
|
|
||||||
ITranslationUnit partner = SourceHeaderPartnerFinder.getPartnerTranslationUnit(
|
|
||||||
declarationTu, astCache);
|
|
||||||
if (partner != null) {
|
|
||||||
insertLocation.setParentNode(astCache.getAST(partner, null), partner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return insertLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IASTNode findFunctionDefinitionInParents(IASTNode node) {
|
|
||||||
if (node == null) {
|
|
||||||
return null;
|
|
||||||
} else if (node instanceof IASTFunctionDefinition) {
|
|
||||||
if (node.getParent() instanceof ICPPASTTemplateDeclaration) {
|
|
||||||
node = node.getParent();
|
|
||||||
}
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
return findFunctionDefinitionInParents(node.getParent());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IASTNode findFirstSurroundingParentFunctionNode(IASTNode definition) {
|
|
||||||
IASTNode functionDefinitionInParents = findFunctionDefinitionInParents(definition);
|
|
||||||
if (functionDefinitionInParents == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (functionDefinitionInParents.getNodeLocations().length == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return functionDefinitionInParents;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches the given class for all IASTSimpleDeclarations occurring before 'method'
|
|
||||||
* and returns them in reverse order.
|
|
||||||
*
|
|
||||||
* @param declarations to be searched
|
|
||||||
* @param methodPosition on which the search aborts
|
|
||||||
* @param pm
|
|
||||||
* @return all declarations, sorted in reverse order
|
|
||||||
*/
|
|
||||||
private static Collection<IASTSimpleDeclaration> getAllPreviousSimpleDeclarationsFromClassInReverseOrder(
|
|
||||||
IASTDeclaration[] declarations, IASTFileLocation methodPosition, IProgressMonitor pm) {
|
|
||||||
ArrayList<IASTSimpleDeclaration> outputDeclarations = new ArrayList<IASTSimpleDeclaration>();
|
|
||||||
if (declarations.length >= 0) {
|
|
||||||
for (IASTDeclaration decl : declarations) {
|
|
||||||
if (pm != null && pm.isCanceled()) {
|
|
||||||
return outputDeclarations;
|
|
||||||
}
|
|
||||||
if (decl.getFileLocation().getStartingLineNumber() >= methodPosition.getStartingLineNumber()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (isMemberFunctionDeclaration(decl)) {
|
|
||||||
outputDeclarations.add((IASTSimpleDeclaration) decl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.reverse(outputDeclarations);
|
|
||||||
return outputDeclarations;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Collection<IASTSimpleDeclaration> getAllFollowingSimpleDeclarationsFromClass(
|
|
||||||
IASTDeclaration[] declarations, IASTFileLocation methodPosition, IProgressMonitor pm) {
|
|
||||||
ArrayList<IASTSimpleDeclaration> outputDeclarations = new ArrayList<IASTSimpleDeclaration>();
|
|
||||||
|
|
||||||
if (declarations.length >= 0) {
|
|
||||||
for (IASTDeclaration decl : declarations) {
|
|
||||||
if (pm != null && pm.isCanceled()) {
|
|
||||||
return outputDeclarations;
|
|
||||||
}
|
|
||||||
if (isMemberFunctionDeclaration(decl) &&
|
|
||||||
decl.getFileLocation().getStartingLineNumber() > methodPosition.getStartingLineNumber() ) {
|
|
||||||
outputDeclarations.add((IASTSimpleDeclaration) decl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return outputDeclarations;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isMemberFunctionDeclaration(IASTDeclaration decl) {
|
|
||||||
return decl instanceof IASTSimpleDeclaration &&
|
|
||||||
((IASTSimpleDeclaration) decl).getDeclarators().length > 0 &&
|
|
||||||
((IASTSimpleDeclaration) decl).getDeclarators()[0] instanceof IASTFunctionDeclarator;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue