mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Removed a redundant method.
This commit is contained in:
parent
68b5958f0c
commit
75e0f1868f
9 changed files with 72 additions and 79 deletions
|
@ -7,8 +7,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
||||||
* Sergey Prigogin (Google)
|
* Sergey Prigogin (Google)
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ import org.eclipse.cdt.core.dom.ast.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a selection and a translation unit, this class finds a
|
* Given a selection and a translation unit, this class finds a
|
||||||
* ICPPASTFunctionDeclarator if possible. Special case: Nested local functions
|
* ICPPASTFunctionDeclarator if possible. Special case: Nested local functions
|
||||||
|
@ -104,6 +106,6 @@ public class DeclaratorFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPartOfAStatement(IASTNode node) {
|
private boolean isPartOfAStatement(IASTNode node) {
|
||||||
return ToggleNodeHelper.getAncestorOfType(node, IASTStatement.class) != null;
|
return CPPVisitor.findAncestorWithType(node, IASTStatement.class) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
||||||
|
|
||||||
|
@ -27,18 +27,19 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
||||||
|
|
||||||
public class InsertionPointFinder {
|
public class InsertionPointFinder {
|
||||||
|
|
||||||
private static ArrayList<ICPPASTFunctionDeclarator> allafterdeclarations;
|
private static ArrayList<ICPPASTFunctionDeclarator> allafterdeclarations;
|
||||||
private static ArrayList<ICPPASTFunctionDefinition> alldefinitionsoutside;
|
private static ArrayList<ICPPASTFunctionDefinition> alldefinitionsoutside;
|
||||||
private static IASTDeclaration position;
|
private static IASTDeclaration position;
|
||||||
|
|
||||||
public static IASTDeclaration findInsertionPoint(IASTTranslationUnit classunit, IASTTranslationUnit functiondefunit, IASTFunctionDeclarator funcdecl) {
|
public static IASTDeclaration findInsertionPoint(IASTTranslationUnit classunit,
|
||||||
|
IASTTranslationUnit functiondefunit, IASTFunctionDeclarator funcDecl) {
|
||||||
position = null;
|
position = null;
|
||||||
findAllDeclarationsAfterInClass(classunit, funcdecl);
|
findAllDeclarationsAfterInClass(classunit, funcDecl);
|
||||||
findAllDefinitionsoutSideClass(functiondefunit);
|
findAllDefinitionsoutSideClass(functiondefunit);
|
||||||
findRightPlace();
|
findRightPlace();
|
||||||
return position;
|
return position;
|
||||||
|
@ -54,38 +55,39 @@ public class InsertionPointFinder {
|
||||||
if (def.getDeclarator().getName() instanceof ICPPASTQualifiedName) {
|
if (def.getDeclarator().getName() instanceof ICPPASTQualifiedName) {
|
||||||
ICPPASTQualifiedName qname = (ICPPASTQualifiedName) def.getDeclarator().getName();
|
ICPPASTQualifiedName qname = (ICPPASTQualifiedName) def.getDeclarator().getName();
|
||||||
def_name = qname.getNames()[1].toString();
|
def_name = qname.getNames()[1].toString();
|
||||||
}
|
} else if (def.getDeclarator().getName() instanceof CPPASTName) {
|
||||||
else if (def.getDeclarator().getName() instanceof CPPASTName) {
|
|
||||||
def_name = def.getDeclarator().getName().toString();
|
def_name = def.getDeclarator().getName().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decl_name.equals(def_name)) {
|
if (decl_name.equals(def_name)) {
|
||||||
if (def.getParent() != null && def.getParent() instanceof ICPPASTTemplateDeclaration)
|
if (def.getParent() != null && def.getParent() instanceof ICPPASTTemplateDeclaration) {
|
||||||
position = (IASTDeclaration) def.getParent();
|
position = (IASTDeclaration) def.getParent();
|
||||||
else
|
} else {
|
||||||
position = def;
|
position = def;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void findAllDeclarationsAfterInClass(IASTTranslationUnit classunit, IASTFunctionDeclarator funcdecl) {
|
private static void findAllDeclarationsAfterInClass(IASTTranslationUnit classunit,
|
||||||
|
IASTFunctionDeclarator funcDecl) {
|
||||||
ICPPASTCompositeTypeSpecifier klass = getklass(classunit);
|
ICPPASTCompositeTypeSpecifier klass = getklass(classunit);
|
||||||
if (klass != null)
|
if (klass != null)
|
||||||
allafterdeclarations = getDeclarationsInClass(klass, funcdecl);
|
allafterdeclarations = getDeclarationsInClass(klass, funcDecl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param unit the translation unit where to find the definitions
|
* @param ast the translation unit where to find the definitions
|
||||||
*/
|
*/
|
||||||
private static void findAllDefinitionsoutSideClass(IASTTranslationUnit unit) {
|
private static void findAllDefinitionsoutSideClass(IASTTranslationUnit ast) {
|
||||||
final ArrayList<ICPPASTFunctionDefinition> definitions = new ArrayList<ICPPASTFunctionDefinition>();
|
final ArrayList<ICPPASTFunctionDefinition> definitions = new ArrayList<ICPPASTFunctionDefinition>();
|
||||||
if (unit == null) {
|
if (ast == null) {
|
||||||
alldefinitionsoutside = definitions;
|
alldefinitionsoutside = definitions;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unit.accept(
|
ast.accept(
|
||||||
new ASTVisitor() {
|
new ASTVisitor() {
|
||||||
{
|
{
|
||||||
shouldVisitDeclarations = true;
|
shouldVisitDeclarations = true;
|
||||||
|
@ -94,8 +96,10 @@ public class InsertionPointFinder {
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTDeclaration declaration) {
|
public int visit(IASTDeclaration declaration) {
|
||||||
if (declaration instanceof ICPPASTFunctionDefinition) {
|
if (declaration instanceof ICPPASTFunctionDefinition) {
|
||||||
if (declaration.getParent() != null && ToggleNodeHelper.getAncestorOfType(declaration, CPPASTCompositeTypeSpecifier.class) != null)
|
if (declaration.getParent() != null &&
|
||||||
return PROCESS_CONTINUE;
|
CPPVisitor.findAncestorWithType(declaration, CPPASTCompositeTypeSpecifier.class) != null) {
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
definitions.add((ICPPASTFunctionDefinition) declaration);
|
definitions.add((ICPPASTFunctionDefinition) declaration);
|
||||||
}
|
}
|
||||||
return super.visit(declaration);
|
return super.visit(declaration);
|
||||||
|
@ -108,7 +112,7 @@ public class InsertionPointFinder {
|
||||||
final ArrayList<ICPPASTFunctionDeclarator> declarations = new ArrayList<ICPPASTFunctionDeclarator>();
|
final ArrayList<ICPPASTFunctionDeclarator> declarations = new ArrayList<ICPPASTFunctionDeclarator>();
|
||||||
|
|
||||||
klass.accept(
|
klass.accept(
|
||||||
new ASTVisitor() {
|
new ASTVisitor() {
|
||||||
{
|
{
|
||||||
shouldVisitDeclarators = true;
|
shouldVisitDeclarators = true;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +130,7 @@ public class InsertionPointFinder {
|
||||||
}
|
}
|
||||||
return super.visit(declarator);
|
return super.visit(declarator);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return declarations;
|
return declarations;
|
||||||
}
|
}
|
||||||
|
@ -136,19 +140,19 @@ public class InsertionPointFinder {
|
||||||
|
|
||||||
unit.accept(
|
unit.accept(
|
||||||
new ASTVisitor() {
|
new ASTVisitor() {
|
||||||
{
|
{
|
||||||
shouldVisitDeclSpecifiers = true;
|
shouldVisitDeclSpecifiers = true;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int visit(IASTDeclSpecifier declSpec) {
|
|
||||||
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
|
||||||
result.setObject((ICPPASTCompositeTypeSpecifier) declSpec);
|
|
||||||
return PROCESS_ABORT;
|
|
||||||
}
|
}
|
||||||
return super.visit(declSpec);
|
|
||||||
}
|
@Override
|
||||||
});
|
public int visit(IASTDeclSpecifier declSpec) {
|
||||||
|
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
|
||||||
|
result.setObject((ICPPASTCompositeTypeSpecifier) declSpec);
|
||||||
|
return PROCESS_ABORT;
|
||||||
|
}
|
||||||
|
return super.visit(declSpec);
|
||||||
|
}
|
||||||
|
});
|
||||||
return result.getObject();
|
return result.getObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||||
|
|
||||||
public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStrategy {
|
public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStrategy {
|
||||||
|
@ -42,8 +44,7 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInClass(IASTNode node) {
|
private boolean isInClass(IASTNode node) {
|
||||||
return ToggleNodeHelper.getAncestorOfType(node,
|
return CPPVisitor.findAncestorWithType(node, ICPPASTCompositeTypeSpecifier.class) != null;
|
||||||
ICPPASTCompositeTypeSpecifier.class) != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,8 +80,7 @@ public class ToggleFromClassToInHeaderStrategy implements IToggleRefactoringStra
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTNode getParentNamespace() {
|
private IASTNode getParentNamespace() {
|
||||||
IASTNode parentNamespace = ToggleNodeHelper.getAncestorOfType(
|
IASTNode parentNamespace = CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
||||||
context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
|
||||||
if (parentNamespace == null)
|
if (parentNamespace == null)
|
||||||
parentNamespace = context.getDefinitionUnit();
|
parentNamespace = context.getDefinitionUnit();
|
||||||
return parentNamespace;
|
return parentNamespace;
|
||||||
|
|
|
@ -28,20 +28,19 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition;
|
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.CPPASTAllVisitor;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.CPPASTAllVisitor;
|
||||||
|
|
||||||
public class ToggleFromImplementationToHeaderOrClassStrategy implements IToggleRefactoringStrategy {
|
public class ToggleFromImplementationToHeaderOrClassStrategy implements IToggleRefactoringStrategy {
|
||||||
|
|
||||||
private ToggleRefactoringContext context;
|
private ToggleRefactoringContext context;
|
||||||
private TextEditGroup infoText;
|
private TextEditGroup infoText;
|
||||||
private IASTTranslationUnit other_tu;
|
private IASTTranslationUnit other_tu;
|
||||||
private ASTLiteralNode includenode;
|
private ASTLiteralNode includenode;
|
||||||
|
|
||||||
public ToggleFromImplementationToHeaderOrClassStrategy(
|
public ToggleFromImplementationToHeaderOrClassStrategy(ToggleRefactoringContext context) {
|
||||||
ToggleRefactoringContext context) {
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.infoText = new TextEditGroup(Messages.EditGroupName);
|
this.infoText = new TextEditGroup(Messages.EditGroupName);
|
||||||
}
|
}
|
||||||
|
@ -89,9 +88,8 @@ public class ToggleFromImplementationToHeaderOrClassStrategy implements IToggleR
|
||||||
private void addDefinitionToHeader(ModificationCollector modifications, List<IASTComment> leadingComments) {
|
private void addDefinitionToHeader(ModificationCollector modifications, List<IASTComment> leadingComments) {
|
||||||
ASTRewrite headerRewrite = modifications.rewriterForTranslationUnit(other_tu);
|
ASTRewrite headerRewrite = modifications.rewriterForTranslationUnit(other_tu);
|
||||||
IASTFunctionDefinition newDefinition = ToggleNodeHelper.createFunctionSignatureWithEmptyBody(
|
IASTFunctionDefinition newDefinition = ToggleNodeHelper.createFunctionSignatureWithEmptyBody(
|
||||||
context
|
context.getDefinition().getDeclSpecifier().copy(CopyStyle.withLocations),
|
||||||
.getDefinition().getDeclSpecifier().copy(CopyStyle.withLocations), context.getDefinition()
|
context.getDefinition().getDeclarator().copy(CopyStyle.withLocations),
|
||||||
.getDeclarator().copy(CopyStyle.withLocations),
|
|
||||||
context.getDefinition().copy(CopyStyle.withLocations));
|
context.getDefinition().copy(CopyStyle.withLocations));
|
||||||
newDefinition.setParent(other_tu);
|
newDefinition.setParent(other_tu);
|
||||||
headerRewrite.insertBefore(other_tu.getTranslationUnit(), null, newDefinition, infoText);
|
headerRewrite.insertBefore(other_tu.getTranslationUnit(), null, newDefinition, infoText);
|
||||||
|
@ -105,8 +103,7 @@ context
|
||||||
ASTRewrite headerRewrite = modifications.rewriterForTranslationUnit(
|
ASTRewrite headerRewrite = modifications.rewriterForTranslationUnit(
|
||||||
context.getDeclarationUnit());
|
context.getDeclarationUnit());
|
||||||
IASTFunctionDefinition newDefinition = ToggleNodeHelper.createInClassDefinition(
|
IASTFunctionDefinition newDefinition = ToggleNodeHelper.createInClassDefinition(
|
||||||
context.getDeclaration(), context.getDefinition(),
|
context.getDeclaration(), context.getDefinition(), context.getDeclarationUnit());
|
||||||
context.getDeclarationUnit());
|
|
||||||
newDefinition.setParent(getParent());
|
newDefinition.setParent(getParent());
|
||||||
restoreBody(headerRewrite, newDefinition, modifications);
|
restoreBody(headerRewrite, newDefinition, modifications);
|
||||||
headerRewrite.replace(context.getDeclaration().getParent(), newDefinition, infoText);
|
headerRewrite.replace(context.getDeclaration().getParent(), newDefinition, infoText);
|
||||||
|
@ -116,13 +113,12 @@ context
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTNode getParent() {
|
private IASTNode getParent() {
|
||||||
IASTNode parent = ToggleNodeHelper.getAncestorOfType(context.getDefinition(),
|
IASTNode parent = CPPVisitor.findAncestorWithType(context.getDefinition(),
|
||||||
ICPPASTCompositeTypeSpecifier.class);
|
ICPPASTCompositeTypeSpecifier.class);
|
||||||
IASTNode parentnode = null;
|
IASTNode parentnode = null;
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
parentnode = parent;
|
parentnode = parent;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
parentnode =context.getDeclarationUnit();
|
parentnode =context.getDeclarationUnit();
|
||||||
}
|
}
|
||||||
return parentnode;
|
return parentnode;
|
||||||
|
@ -133,7 +129,8 @@ context
|
||||||
IASTFunctionDefinition oldDefinition = context.getDefinition();
|
IASTFunctionDefinition oldDefinition = context.getDefinition();
|
||||||
newDefinition.setBody(oldDefinition.getBody().copy(CopyStyle.withLocations));
|
newDefinition.setBody(oldDefinition.getBody().copy(CopyStyle.withLocations));
|
||||||
|
|
||||||
if (newDefinition instanceof ICPPASTFunctionWithTryBlock && oldDefinition instanceof ICPPASTFunctionWithTryBlock) {
|
if (newDefinition instanceof ICPPASTFunctionWithTryBlock &&
|
||||||
|
oldDefinition instanceof ICPPASTFunctionWithTryBlock) {
|
||||||
ICPPASTFunctionWithTryBlock newTryDef = (ICPPASTFunctionWithTryBlock) newDefinition;
|
ICPPASTFunctionWithTryBlock newTryDef = (ICPPASTFunctionWithTryBlock) newDefinition;
|
||||||
ICPPASTFunctionWithTryBlock oldTryDef = (ICPPASTFunctionWithTryBlock) oldDefinition;
|
ICPPASTFunctionWithTryBlock oldTryDef = (ICPPASTFunctionWithTryBlock) oldDefinition;
|
||||||
for (ICPPASTCatchHandler handler : oldTryDef.getCatchHandlers()) {
|
for (ICPPASTCatchHandler handler : oldTryDef.getCatchHandlers()) {
|
||||||
|
@ -161,12 +158,11 @@ context
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeDefinitionFromImplementation(ASTRewrite implast) {
|
private void removeDefinitionFromImplementation(ASTRewrite implast) {
|
||||||
ICPPASTNamespaceDefinition ns = ToggleNodeHelper.getAncestorOfType(
|
ICPPASTNamespaceDefinition ns =
|
||||||
context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTNamespaceDefinition.class);
|
||||||
if (ns != null && isSingleElementInNamespace(ns, context.getDefinition())) {
|
if (ns != null && isSingleElementInNamespace(ns, context.getDefinition())) {
|
||||||
implast.remove(ns, infoText);
|
implast.remove(ns, infoText);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition;
|
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||||
|
|
||||||
|
@ -55,8 +56,7 @@ public class ToggleFromInHeaderToClassStrategy implements IToggleRefactoringStra
|
||||||
if (declarator.getName() instanceof ICPPASTQualifiedName) {
|
if (declarator.getName() instanceof ICPPASTQualifiedName) {
|
||||||
declarator = backup;
|
declarator = backup;
|
||||||
}
|
}
|
||||||
return (ToggleNodeHelper.getAncestorOfType(declarator,
|
return (CPPVisitor.findAncestorWithType(declarator, IASTCompositeTypeSpecifier.class) == null);
|
||||||
IASTCompositeTypeSpecifier.class) == null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,8 +102,7 @@ public class ToggleFromInHeaderToClassStrategy implements IToggleRefactoringStra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IASTNode parent = ToggleNodeHelper.getAncestorOfType(context.getDefinition(),
|
IASTNode parent = CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTCompositeTypeSpecifier.class);
|
||||||
ICPPASTCompositeTypeSpecifier.class);
|
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
newDefinition.setParent(parent);
|
newDefinition.setParent(parent);
|
||||||
}
|
}
|
||||||
|
@ -115,8 +114,7 @@ public class ToggleFromInHeaderToClassStrategy implements IToggleRefactoringStra
|
||||||
|
|
||||||
private ASTRewrite replaceDeclarationWithDefinition(ASTRewrite rewriter,
|
private ASTRewrite replaceDeclarationWithDefinition(ASTRewrite rewriter,
|
||||||
IASTFunctionDefinition newDefinition) {
|
IASTFunctionDefinition newDefinition) {
|
||||||
IASTSimpleDeclaration fullDeclaration = ToggleNodeHelper.getAncestorOfType(
|
IASTSimpleDeclaration fullDeclaration = CPPVisitor.findAncestorWithType(context.getDeclaration(), CPPASTSimpleDeclaration.class);
|
||||||
context.getDeclaration(), CPPASTSimpleDeclaration.class);
|
|
||||||
ASTRewrite newRewriter = rewriter.replace(fullDeclaration, newDefinition, infoText);
|
ASTRewrite newRewriter = rewriter.replace(fullDeclaration, newDefinition, infoText);
|
||||||
return newRewriter;
|
return newRewriter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ import org.eclipse.cdt.core.dom.rewrite.ASTRewrite.CommentPosition;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
|
import org.eclipse.cdt.internal.core.dom.rewrite.ASTLiteralNode;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
import org.eclipse.cdt.internal.ui.refactoring.Container;
|
||||||
|
@ -261,7 +262,7 @@ public class ToggleFromInHeaderToImplementationStrategy implements IToggleRefact
|
||||||
if (toquery == null) {
|
if (toquery == null) {
|
||||||
toquery = context.getDefinition();
|
toquery = context.getDefinition();
|
||||||
}
|
}
|
||||||
return ToggleNodeHelper.getAncestorOfType(toquery, ICPPASTNamespaceDefinition.class);
|
return CPPVisitor.findAncestorWithType(toquery, ICPPASTNamespaceDefinition.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTNode findInsertionPoint(IASTNode insertionParent, IASTTranslationUnit unit) {
|
private IASTNode findInsertionPoint(IASTNode insertionParent, IASTTranslationUnit unit) {
|
||||||
|
|
|
@ -64,6 +64,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTQualifiedName;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSimpleDeclaration;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateId;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateId;
|
||||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTypeId;
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
import org.eclipse.cdt.internal.ui.refactoring.ModificationCollector;
|
||||||
|
@ -461,15 +462,4 @@ public class ToggleNodeHelper extends NodeHelper {
|
||||||
}
|
}
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T getAncestorOfType(IASTNode node, Class<?> T) {
|
|
||||||
while (node != null) {
|
|
||||||
if (T.isInstance(node)) {
|
|
||||||
return (T) node;
|
|
||||||
}
|
|
||||||
node = node.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.IndexToASTNameHelper;
|
import org.eclipse.cdt.internal.ui.refactoring.IndexToASTNameHelper;
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
|
import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
|
||||||
|
|
||||||
|
@ -173,11 +175,11 @@ public class ToggleRefactoringContext {
|
||||||
if (node instanceof IASTSimpleDeclaration) {
|
if (node instanceof IASTSimpleDeclaration) {
|
||||||
return (IASTFunctionDeclarator) ((IASTSimpleDeclaration) node).getDeclarators()[0];
|
return (IASTFunctionDeclarator) ((IASTSimpleDeclaration) node).getDeclarators()[0];
|
||||||
}
|
}
|
||||||
return ToggleNodeHelper.getAncestorOfType(node, IASTFunctionDeclarator.class);
|
return CPPVisitor.findAncestorWithType(node, IASTFunctionDeclarator.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTFunctionDefinition findFunctionDefinition(IASTNode node) {
|
private IASTFunctionDefinition findFunctionDefinition(IASTNode node) {
|
||||||
return ToggleNodeHelper.getAncestorOfType(node, IASTFunctionDefinition.class);
|
return CPPVisitor.findAncestorWithType(node, IASTFunctionDefinition.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultAnswer(boolean defaultAnswer) {
|
public void setDefaultAnswer(boolean defaultAnswer) {
|
||||||
|
|
|
@ -7,13 +7,15 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
* Martin Schwab & Thomas Kallenberg - initial API and implementation
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
package org.eclipse.cdt.internal.ui.refactoring.togglefunction;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||||
|
|
||||||
public class ToggleStrategyFactory {
|
public class ToggleStrategyFactory {
|
||||||
|
|
||||||
private ToggleRefactoringContext context;
|
private ToggleRefactoringContext context;
|
||||||
|
@ -43,12 +45,10 @@ public class ToggleStrategyFactory {
|
||||||
|
|
||||||
private boolean isInClassSituation() {
|
private boolean isInClassSituation() {
|
||||||
return (context.getDeclaration() == null) &&
|
return (context.getDeclaration() == null) &&
|
||||||
(ToggleNodeHelper.getAncestorOfType(context.getDefinition(),
|
(CPPVisitor.findAncestorWithType(context.getDefinition(), IASTCompositeTypeSpecifier.class) != null);
|
||||||
IASTCompositeTypeSpecifier.class) != null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isTemplateSituation() {
|
private boolean isTemplateSituation() {
|
||||||
return (ToggleNodeHelper.getAncestorOfType(context.getDefinition(),
|
return (CPPVisitor.findAncestorWithType(context.getDefinition(), ICPPASTTemplateDeclaration.class) != null);
|
||||||
ICPPASTTemplateDeclaration.class) != null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue