mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Fixes a CCE, bug 203967.
This commit is contained in:
parent
b7afd7af2c
commit
b3256c51da
3 changed files with 63 additions and 62 deletions
|
@ -50,8 +50,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
||||||
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
|
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
|
||||||
//first check if we already know it
|
//first check if we already know it
|
||||||
if( declarations != null ){
|
if( declarations != null ){
|
||||||
for( int i = 0; i < declarations.length; i++ ){
|
for (IASTName declaration : declarations) {
|
||||||
IASTNode parent = declarations[i].getParent();
|
IASTNode parent = declaration.getParent();
|
||||||
while( !(parent instanceof IASTDeclaration) )
|
while( !(parent instanceof IASTDeclaration) )
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
|
|
||||||
|
@ -69,17 +69,17 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
||||||
ICPPClassScope clsScope = (ICPPClassScope) scope;
|
ICPPClassScope clsScope = (ICPPClassScope) scope;
|
||||||
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(clsScope);
|
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(clsScope);
|
||||||
IASTDeclaration [] members = compSpec.getMembers();
|
IASTDeclaration [] members = compSpec.getMembers();
|
||||||
for( int i = 0; i < members.length; i++ ){
|
for (IASTDeclaration member : members) {
|
||||||
if( members[i] instanceof ICPPASTTemplateDeclaration ){
|
if( member instanceof ICPPASTTemplateDeclaration ){
|
||||||
IASTDeclaration decl = ((ICPPASTTemplateDeclaration)members[i]).getDeclaration();
|
IASTDeclaration decl = ((ICPPASTTemplateDeclaration)member).getDeclaration();
|
||||||
if( decl instanceof IASTSimpleDeclaration ){
|
if( decl instanceof IASTSimpleDeclaration ){
|
||||||
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
|
||||||
for( int j = 0; j < dtors.length; j++ ){
|
for (IASTDeclarator dtor : dtors) {
|
||||||
IASTName name = CPPVisitor.getMostNestedDeclarator( dtors[j] ).getName();
|
IASTName name = CPPVisitor.getMostNestedDeclarator( dtor ).getName();
|
||||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||||
name.resolveBinding() == this )
|
name.resolveBinding() == this )
|
||||||
{
|
{
|
||||||
return members[i];
|
return member;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( decl instanceof IASTFunctionDefinition ){
|
} else if( decl instanceof IASTFunctionDefinition ){
|
||||||
|
@ -87,7 +87,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
||||||
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
|
||||||
name.resolveBinding() == this )
|
name.resolveBinding() == this )
|
||||||
{
|
{
|
||||||
return members[i];
|
return member;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,12 +99,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
||||||
public int getVisibility() throws DOMException {
|
public int getVisibility() throws DOMException {
|
||||||
IASTDeclaration decl = getPrimaryDeclaration();
|
IASTDeclaration decl = getPrimaryDeclaration();
|
||||||
if( decl == null ){
|
if( decl == null ){
|
||||||
IScope scope = getScope();
|
ICPPClassType cls = getClassOwner();
|
||||||
if( scope instanceof ICPPTemplateScope)
|
if (cls != null) {
|
||||||
scope = scope.getParent();
|
|
||||||
if( scope instanceof ICPPClassScope ){
|
|
||||||
ICPPClassType cls = ((ICPPClassScope)scope).getClassType();
|
|
||||||
if( cls != null )
|
|
||||||
return ( cls.getKey() == ICPPClassType.k_class ) ? ICPPASTVisiblityLabel.v_private : ICPPASTVisiblityLabel.v_public;
|
return ( cls.getKey() == ICPPClassType.k_class ) ? ICPPASTVisiblityLabel.v_private : ICPPASTVisiblityLabel.v_public;
|
||||||
}
|
}
|
||||||
return ICPPASTVisiblityLabel.v_private;
|
return ICPPASTVisiblityLabel.v_private;
|
||||||
|
@ -112,10 +108,10 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
||||||
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
|
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
|
||||||
IASTDeclaration [] members = cls.getMembers();
|
IASTDeclaration [] members = cls.getMembers();
|
||||||
ICPPASTVisiblityLabel vis = null;
|
ICPPASTVisiblityLabel vis = null;
|
||||||
for( int i = 0; i < members.length; i++ ){
|
for (IASTDeclaration member : members) {
|
||||||
if( members[i] instanceof ICPPASTVisiblityLabel )
|
if( member instanceof ICPPASTVisiblityLabel )
|
||||||
vis = (ICPPASTVisiblityLabel) members[i];
|
vis = (ICPPASTVisiblityLabel) member;
|
||||||
else if( members[i] == decl )
|
else if( member == decl )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( vis != null ){
|
if( vis != null ){
|
||||||
|
@ -127,8 +123,14 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICPPClassType getClassOwner() throws DOMException {
|
public ICPPClassType getClassOwner() throws DOMException {
|
||||||
ICPPClassScope scope = (ICPPClassScope)getScope();
|
IScope scope= getScope();
|
||||||
return scope.getClassType();
|
while (scope instanceof ICPPTemplateScope) {
|
||||||
|
scope= scope.getParent();
|
||||||
|
}
|
||||||
|
if( scope instanceof ICPPClassScope ){
|
||||||
|
return ((ICPPClassScope)scope).getClassType();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVirtual() {
|
public boolean isVirtual() {
|
||||||
|
|
|
@ -70,6 +70,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
|
||||||
openCallHierarchy(editor);
|
openCallHierarchy(editor);
|
||||||
Tree tree = getCHTreeViewer().getTree();
|
Tree tree = getCHTreeViewer().getTree();
|
||||||
checkTreeNode(tree, 0, "proto()");
|
checkTreeNode(tree, 0, "proto()");
|
||||||
|
expandTreeItem(tree, 0);
|
||||||
checkTreeNode(tree, 0, 0, "main()");
|
checkTreeNode(tree, 0, 0, "main()");
|
||||||
|
|
||||||
editor.selectAndReveal(content.indexOf("func"), 2);
|
editor.selectAndReveal(content.indexOf("func"), 2);
|
||||||
|
|
|
@ -64,8 +64,8 @@ public class CHQueries {
|
||||||
if (calleeBinding != null) {
|
if (calleeBinding != null) {
|
||||||
findCalledBy(index, calleeBinding, true, project, result);
|
findCalledBy(index, calleeBinding, true, project, result);
|
||||||
IBinding[] overriddenBindings= getOverriddenBindings(index, calleeBinding);
|
IBinding[] overriddenBindings= getOverriddenBindings(index, calleeBinding);
|
||||||
for (int i = 0; i < overriddenBindings.length; i++) {
|
for (IBinding overriddenBinding : overriddenBindings) {
|
||||||
findCalledBy(index, overriddenBindings[i], false, project, result);
|
findCalledBy(index, overriddenBinding, false, project, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cp.createNodes(node, result);
|
return cp.createNodes(node, result);
|
||||||
|
@ -78,11 +78,11 @@ public class CHQueries {
|
||||||
final ICPPMethod m= (ICPPMethod) binding;
|
final ICPPMethod m= (ICPPMethod) binding;
|
||||||
final char[] mname= m.getNameCharArray();
|
final char[] mname= m.getNameCharArray();
|
||||||
final ICPPClassType mcl= m.getClassOwner();
|
final ICPPClassType mcl= m.getClassOwner();
|
||||||
|
if (mcl != null) {
|
||||||
final IFunctionType mft= m.getType();
|
final IFunctionType mft= m.getType();
|
||||||
boolean isVirtual= m.isVirtual();
|
boolean isVirtual= m.isVirtual();
|
||||||
ICPPMethod[] allMethods= mcl.getMethods();
|
ICPPMethod[] allMethods= mcl.getMethods();
|
||||||
for (int i = 0; i < allMethods.length; i++) {
|
for (ICPPMethod method : allMethods) {
|
||||||
ICPPMethod method = allMethods[i];
|
|
||||||
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && !mcl.isSameType(method.getClassOwner())) {
|
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && !mcl.isSameType(method.getClassOwner())) {
|
||||||
if (mft.isSameType(method.getType())) {
|
if (mft.isSameType(method.getType())) {
|
||||||
isVirtual= isVirtual || method.isVirtual();
|
isVirtual= isVirtual || method.isVirtual();
|
||||||
|
@ -93,6 +93,7 @@ public class CHQueries {
|
||||||
if (isVirtual) {
|
if (isVirtual) {
|
||||||
return result.toArray(new IBinding[result.size()]);
|
return result.toArray(new IBinding[result.size()]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
// index bindings don't throw DOMExceptions
|
// index bindings don't throw DOMExceptions
|
||||||
}
|
}
|
||||||
|
@ -108,13 +109,12 @@ public class CHQueries {
|
||||||
final ArrayList<ICPPMethod> result= new ArrayList<ICPPMethod>();
|
final ArrayList<ICPPMethod> result= new ArrayList<ICPPMethod>();
|
||||||
final char[] mname= m.getNameCharArray();
|
final char[] mname= m.getNameCharArray();
|
||||||
final ICPPClassType mcl= m.getClassOwner();
|
final ICPPClassType mcl= m.getClassOwner();
|
||||||
|
if (mcl != null) {
|
||||||
final IFunctionType mft= m.getType();
|
final IFunctionType mft= m.getType();
|
||||||
ICPPClassType[] subclasses= getSubClasses(index, mcl);
|
ICPPClassType[] subclasses= getSubClasses(index, mcl);
|
||||||
for (int i = 0; i < subclasses.length; i++) {
|
for (ICPPClassType subClass : subclasses) {
|
||||||
ICPPClassType subClass = subclasses[i];
|
|
||||||
ICPPMethod[] methods= subClass.getDeclaredMethods();
|
ICPPMethod[] methods= subClass.getDeclaredMethods();
|
||||||
for (int j = 0; j < methods.length; j++) {
|
for (ICPPMethod method : methods) {
|
||||||
ICPPMethod method = methods[j];
|
|
||||||
if (CharArrayUtils.equals(mname, method.getNameCharArray()) &&
|
if (CharArrayUtils.equals(mname, method.getNameCharArray()) &&
|
||||||
mft.isSameType(method.getType())) {
|
mft.isSameType(method.getType())) {
|
||||||
result.add(method);
|
result.add(method);
|
||||||
|
@ -123,6 +123,7 @@ public class CHQueries {
|
||||||
}
|
}
|
||||||
return result.toArray(new IBinding[result.size()]);
|
return result.toArray(new IBinding[result.size()]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
// index bindings don't throw DOMExceptions
|
// index bindings don't throw DOMExceptions
|
||||||
}
|
}
|
||||||
|
@ -153,8 +154,7 @@ public class CHQueries {
|
||||||
}
|
}
|
||||||
|
|
||||||
IIndexName[] names= index.findNames(classOrTypedef, IIndex.FIND_REFERENCES | IIndex.FIND_DEFINITIONS);
|
IIndexName[] names= index.findNames(classOrTypedef, IIndex.FIND_REFERENCES | IIndex.FIND_DEFINITIONS);
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (IIndexName indexName : names) {
|
||||||
IIndexName indexName = names[i];
|
|
||||||
if (indexName.isBaseSpecifier()) {
|
if (indexName.isBaseSpecifier()) {
|
||||||
IIndexName subClassDef= indexName.getEnclosingDefinition();
|
IIndexName subClassDef= indexName.getEnclosingDefinition();
|
||||||
if (subClassDef != null) {
|
if (subClassDef != null) {
|
||||||
|
@ -174,16 +174,17 @@ public class CHQueries {
|
||||||
}
|
}
|
||||||
final char[] mname= m.getNameCharArray();
|
final char[] mname= m.getNameCharArray();
|
||||||
final ICPPClassType mcl= m.getClassOwner();
|
final ICPPClassType mcl= m.getClassOwner();
|
||||||
|
if (mcl != null) {
|
||||||
final IFunctionType mft= m.getType();
|
final IFunctionType mft= m.getType();
|
||||||
ICPPMethod[] allMethods= mcl.getMethods();
|
ICPPMethod[] allMethods= mcl.getMethods();
|
||||||
for (int i = 0; i < allMethods.length; i++) {
|
for (ICPPMethod method : allMethods) {
|
||||||
ICPPMethod method = allMethods[i];
|
|
||||||
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && mft.isSameType(method.getType())) {
|
if (CharArrayUtils.equals(mname, method.getNameCharArray()) && mft.isSameType(method.getType())) {
|
||||||
if (method.isVirtual()) {
|
if (method.isVirtual()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
// index bindings don't throw DOMExceptions
|
// index bindings don't throw DOMExceptions
|
||||||
}
|
}
|
||||||
|
@ -193,8 +194,7 @@ public class CHQueries {
|
||||||
private static void findCalledBy(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
|
private static void findCalledBy(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
IIndexName[] names= index.findNames(callee, IIndex.FIND_REFERENCES | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
IIndexName[] names= index.findNames(callee, IIndex.FIND_REFERENCES | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (IIndexName rname : names) {
|
||||||
IIndexName rname = names[i];
|
|
||||||
if (includeOrdinaryCalls || rname.couldBePolymorphicMethodCall()) {
|
if (includeOrdinaryCalls || rname.couldBePolymorphicMethodCall()) {
|
||||||
IIndexName caller= rname.getEnclosingDefinition();
|
IIndexName caller= rname.getEnclosingDefinition();
|
||||||
if (caller != null) {
|
if (caller != null) {
|
||||||
|
@ -217,8 +217,7 @@ public class CHQueries {
|
||||||
IIndexName callerName= IndexUI.elementToName(index, caller);
|
IIndexName callerName= IndexUI.elementToName(index, caller);
|
||||||
if (callerName != null) {
|
if (callerName != null) {
|
||||||
IIndexName[] refs= callerName.getEnclosedNames();
|
IIndexName[] refs= callerName.getEnclosedNames();
|
||||||
for (int i = 0; i < refs.length; i++) {
|
for (IIndexName name : refs) {
|
||||||
IIndexName name = refs[i];
|
|
||||||
IBinding binding= index.findBinding(name);
|
IBinding binding= index.findBinding(name);
|
||||||
if (CallHierarchyUI.isRelevantForCallHierarchy(binding)) {
|
if (CallHierarchyUI.isRelevantForCallHierarchy(binding)) {
|
||||||
IBinding[] virtualOverriders= getOverridingBindings(index, binding);
|
IBinding[] virtualOverriders= getOverridingBindings(index, binding);
|
||||||
|
@ -229,8 +228,7 @@ public class CHQueries {
|
||||||
else {
|
else {
|
||||||
ArrayList<ICElementHandle> list= new ArrayList<ICElementHandle>();
|
ArrayList<ICElementHandle> list= new ArrayList<ICElementHandle>();
|
||||||
list.addAll(Arrays.asList(IndexUI.findRepresentative(index, binding)));
|
list.addAll(Arrays.asList(IndexUI.findRepresentative(index, binding)));
|
||||||
for (int j = 0; j < virtualOverriders.length; j++) {
|
for (IBinding overrider : virtualOverriders) {
|
||||||
IBinding overrider = virtualOverriders[j];
|
|
||||||
list.addAll(Arrays.asList(IndexUI.findRepresentative(index, overrider)));
|
list.addAll(Arrays.asList(IndexUI.findRepresentative(index, overrider)));
|
||||||
}
|
}
|
||||||
defs= list.toArray(new ICElement[list.size()]);
|
defs= list.toArray(new ICElement[list.size()]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue