mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Bug 461676 - refactoring not work for methods in class
Change-Id: I770b579eb327e3f21565e95cab2894702f3d7964
This commit is contained in:
parent
76267c7aa9
commit
a7d3f1d3b5
4 changed files with 93 additions and 75 deletions
|
@ -6423,16 +6423,16 @@ public class AST2CPPTests extends AST2TestBase {
|
|||
assertEquals(0, ors.length);
|
||||
ors= ClassTypeHelper.findOverridden(m2, null);
|
||||
assertEquals(1, ors.length);
|
||||
assertSame(ors[0], m1);
|
||||
assertEquals(ors[0], m1);
|
||||
ors= ClassTypeHelper.findOverridden(m3, null);
|
||||
assertEquals(0, ors.length);
|
||||
ors= ClassTypeHelper.findOverridden(m4, null);
|
||||
assertEquals(2, ors.length);
|
||||
assertSame(ors[0], m2);
|
||||
assertSame(ors[1], m1);
|
||||
assertEquals(ors[0], m2);
|
||||
assertEquals(ors[1], m1);
|
||||
ors= ClassTypeHelper.findOverridden(m5, null);
|
||||
assertEquals(1, ors.length);
|
||||
assertSame(ors[0], m1);
|
||||
assertEquals(ors[0], m1);
|
||||
}
|
||||
|
||||
// struct A {
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
|
@ -1859,4 +1860,85 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
|
|||
public void testNameLookupFromArrayModifier_435075() {
|
||||
checkBindings();
|
||||
}
|
||||
|
||||
// class NonVirt {
|
||||
// void m();
|
||||
// };
|
||||
// class C1 : NonVirt {
|
||||
// virtual void m();
|
||||
// };
|
||||
// class C2 : C1 {
|
||||
// void m();
|
||||
// };
|
||||
// class C3 : C2 {
|
||||
// void m(int);
|
||||
// };
|
||||
// class C4 : C3 {
|
||||
// void m();
|
||||
// };
|
||||
// class C5 : C1 {
|
||||
// void m();
|
||||
// };
|
||||
|
||||
// void test(NonVirt* n, C1* c1, C2* c2, C3* c3, C4* c4, C5* c5) {
|
||||
// n->m();//0
|
||||
// c1->m();//1
|
||||
// c2->m();//2
|
||||
// c3->m(0);//3
|
||||
// c4->m();//4
|
||||
// c5->m();//5
|
||||
// }
|
||||
public void testOverridden_248846() throws Exception {
|
||||
ICPPMethod m0= getBindingFromFirstIdentifier("m();//0");
|
||||
ICPPMethod m1= getBindingFromFirstIdentifier("m();//1");
|
||||
ICPPMethod m2= getBindingFromFirstIdentifier("m();//2");
|
||||
ICPPMethod m3= getBindingFromFirstIdentifier("m(0);");
|
||||
ICPPMethod m4= getBindingFromFirstIdentifier("m();//4");
|
||||
ICPPMethod m5= getBindingFromFirstIdentifier("m();//5");
|
||||
|
||||
assertFalse(ClassTypeHelper.isVirtual(m0));
|
||||
assertFalse(ClassTypeHelper.isVirtual(m3));
|
||||
assertTrue(ClassTypeHelper.isVirtual(m1));
|
||||
assertTrue(ClassTypeHelper.isVirtual(m2));
|
||||
assertTrue(ClassTypeHelper.isVirtual(m4));
|
||||
assertTrue(ClassTypeHelper.isVirtual(m5));
|
||||
|
||||
assertFalse(ClassTypeHelper.isOverrider(m0, m0));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m1, m0));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m2, m0));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m3, m0));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m4, m0));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m5, m0));
|
||||
|
||||
assertFalse(ClassTypeHelper.isOverrider(m0, m1));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m1, m1));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m3, m1));
|
||||
assertTrue(ClassTypeHelper.isOverrider(m2, m1));
|
||||
assertTrue(ClassTypeHelper.isOverrider(m4, m1));
|
||||
assertTrue(ClassTypeHelper.isOverrider(m5, m1));
|
||||
|
||||
assertFalse(ClassTypeHelper.isOverrider(m0, m2));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m1, m2));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m2, m2));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m3, m2));
|
||||
assertFalse(ClassTypeHelper.isOverrider(m5, m2));
|
||||
assertTrue(ClassTypeHelper.isOverrider(m4, m2));
|
||||
|
||||
ICPPMethod[] ors= ClassTypeHelper.findOverridden(m0, null);
|
||||
assertEquals(0, ors.length);
|
||||
ors= ClassTypeHelper.findOverridden(m1, null);
|
||||
assertEquals(0, ors.length);
|
||||
ors= ClassTypeHelper.findOverridden(m2, null);
|
||||
assertEquals(1, ors.length);
|
||||
assertEquals(ors[0], m1);
|
||||
ors= ClassTypeHelper.findOverridden(m3, null);
|
||||
assertEquals(0, ors.length);
|
||||
ors= ClassTypeHelper.findOverridden(m4, null);
|
||||
assertEquals(2, ors.length);
|
||||
assertEquals(ors[0], m2);
|
||||
assertEquals(ors[1], m1);
|
||||
ors= ClassTypeHelper.findOverridden(m5, null);
|
||||
assertEquals(1, ors.length);
|
||||
assertEquals(ors[0], m1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,11 +38,8 @@ import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
|||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.EScopeKind;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionStyleMacroParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||
|
@ -55,7 +52,6 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfndefStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IArrayType;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
|
@ -80,12 +76,10 @@ import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
|||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionPrototypeScope;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
|
||||
import org.eclipse.cdt.core.dom.ast.c.ICScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNameSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
|
@ -110,8 +104,6 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
|||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.c.CVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPImplicitMethod;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPMethod;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||
|
@ -672,59 +664,6 @@ public class ASTManager implements IDisposable {
|
|||
return CVisitor.getContainingScope(name);
|
||||
}
|
||||
|
||||
public static int isVirtualMethod(ICPPMethod method) throws DOMException {
|
||||
IASTDeclaration decl= null;
|
||||
if (method instanceof CPPMethod) {
|
||||
decl = ((CPPMethod) method).getPrimaryDeclaration();
|
||||
} else if (method instanceof CPPImplicitMethod) {
|
||||
decl = ((CPPImplicitMethod) method).getPrimaryDeclaration();
|
||||
}
|
||||
|
||||
IASTDeclSpecifier spec= null;
|
||||
if (decl instanceof IASTFunctionDefinition) {
|
||||
IASTFunctionDefinition def = (IASTFunctionDefinition) decl;
|
||||
spec= def.getDeclSpecifier();
|
||||
} else if (decl instanceof IASTSimpleDeclaration) {
|
||||
IASTSimpleDeclaration sdecl = (IASTSimpleDeclaration) decl;
|
||||
spec= sdecl.getDeclSpecifier();
|
||||
}
|
||||
if (spec instanceof ICPPASTDeclSpecifier) {
|
||||
ICPPASTDeclSpecifier cppSpec = (ICPPASTDeclSpecifier) spec;
|
||||
if (cppSpec.isVirtual()) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
IScope scope= method.getScope();
|
||||
if (scope instanceof ICPPClassScope) {
|
||||
ICPPClassScope classScope = (ICPPClassScope) scope;
|
||||
ICPPClassType classType= classScope.getClassType();
|
||||
ICPPBase[] bases= classType.getBases();
|
||||
for (ICPPBase base : bases) {
|
||||
if (!(base.getBaseClass() instanceof ICPPClassType))
|
||||
continue;
|
||||
ICPPClassType baseType= (ICPPClassType) base.getBaseClass();
|
||||
if (baseType != null) {
|
||||
IScope baseScope= baseType.getCompositeScope();
|
||||
if (baseScope != null) {
|
||||
IBinding[] alternates= baseScope.find(method.getName());
|
||||
for (IBinding binding : alternates) {
|
||||
if (binding instanceof CPPMethod) {
|
||||
CPPMethod alternateMethod = (CPPMethod) binding;
|
||||
if (hasSameSignature(method, alternateMethod) != FALSE) {
|
||||
if (isVirtualMethod(alternateMethod) == TRUE) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
public static boolean isLocalVariable(IVariable v, IScope scope) {
|
||||
if (v instanceof IParameter) {
|
||||
return false;
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2010 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2004, 2015 Wind River Systems, 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:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Sergey Prigogin (Google)
|
||||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.refactoring.rename;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
|
@ -34,6 +34,8 @@ import org.eclipse.cdt.core.model.ISourceRange;
|
|||
import org.eclipse.cdt.core.model.ISourceReference;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
|
||||
/**
|
||||
* Represents the input to a refactoring. Important are file and offset, the rest
|
||||
* can be calculated from the AST.
|
||||
|
@ -126,13 +128,8 @@ public class CRefactoringArgument {
|
|||
IFunction func= (IFunction) binding;
|
||||
if (binding instanceof ICPPMethod) {
|
||||
ICPPMethod method= (ICPPMethod) binding;
|
||||
int isVirtual= ASTManager.UNKNOWN;
|
||||
try {
|
||||
isVirtual = ASTManager.isVirtualMethod(method);
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
if (isVirtual == ASTManager.TRUE) {
|
||||
fKind= CRefactory.ARGUMENT_VIRTUAL_METHOD;
|
||||
if (ClassTypeHelper.isVirtual(method)) {
|
||||
fKind= CRefactory.ARGUMENT_VIRTUAL_METHOD;
|
||||
}
|
||||
} else {
|
||||
boolean isStatic= false;
|
||||
|
|
Loading…
Add table
Reference in a new issue