Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2008-04-16 12:32:52 -0400
committerMarkus Schorn2008-04-16 12:32:52 -0400
commitb3256c51da19a7f46a8fb13bc913cf5c10e8679a (patch)
treea11de1b22bf327cfc4648cda674cb6b0819d223c /core
parentb7afd7af2c519cf732695405e36f685434fbd409 (diff)
downloadorg.eclipse.cdt-b3256c51da19a7f46a8fb13bc913cf5c10e8679a.tar.gz
org.eclipse.cdt-b3256c51da19a7f46a8fb13bc913cf5c10e8679a.tar.xz
org.eclipse.cdt-b3256c51da19a7f46a8fb13bc913cf5c10e8679a.zip
Fixes a CCE, bug 203967.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java46
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java1
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java78
3 files changed, 63 insertions, 62 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java
index 46d304fd0c0..6ec70c41450 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPMethodTemplate.java
@@ -50,8 +50,8 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
public IASTDeclaration getPrimaryDeclaration() throws DOMException{
//first check if we already know it
if( declarations != null ){
- for( int i = 0; i < declarations.length; i++ ){
- IASTNode parent = declarations[i].getParent();
+ for (IASTName declaration : declarations) {
+ IASTNode parent = declaration.getParent();
while( !(parent instanceof IASTDeclaration) )
parent = parent.getParent();
@@ -69,17 +69,17 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
ICPPClassScope clsScope = (ICPPClassScope) scope;
ICPPASTCompositeTypeSpecifier compSpec = (ICPPASTCompositeTypeSpecifier) ASTInternal.getPhysicalNodeOfScope(clsScope);
IASTDeclaration [] members = compSpec.getMembers();
- for( int i = 0; i < members.length; i++ ){
- if( members[i] instanceof ICPPASTTemplateDeclaration ){
- IASTDeclaration decl = ((ICPPASTTemplateDeclaration)members[i]).getDeclaration();
+ for (IASTDeclaration member : members) {
+ if( member instanceof ICPPASTTemplateDeclaration ){
+ IASTDeclaration decl = ((ICPPASTTemplateDeclaration)member).getDeclaration();
if( decl instanceof IASTSimpleDeclaration ){
IASTDeclarator [] dtors = ((IASTSimpleDeclaration)decl).getDeclarators();
- for( int j = 0; j < dtors.length; j++ ){
- IASTName name = CPPVisitor.getMostNestedDeclarator( dtors[j] ).getName();
+ for (IASTDeclarator dtor : dtors) {
+ IASTName name = CPPVisitor.getMostNestedDeclarator( dtor ).getName();
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
- return members[i];
+ return member;
}
}
} else if( decl instanceof IASTFunctionDefinition ){
@@ -87,7 +87,7 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
if( CharArrayUtils.equals( name.toCharArray(), myName ) &&
name.resolveBinding() == this )
{
- return members[i];
+ return member;
}
}
}
@@ -99,23 +99,19 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
public int getVisibility() throws DOMException {
IASTDeclaration decl = getPrimaryDeclaration();
if( decl == null ){
- IScope scope = getScope();
- if( scope instanceof ICPPTemplateScope)
- 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;
+ ICPPClassType cls = getClassOwner();
+ if (cls != null) {
+ return ( cls.getKey() == ICPPClassType.k_class ) ? ICPPASTVisiblityLabel.v_private : ICPPASTVisiblityLabel.v_public;
}
return ICPPASTVisiblityLabel.v_private;
}
IASTCompositeTypeSpecifier cls = (IASTCompositeTypeSpecifier) decl.getParent();
IASTDeclaration [] members = cls.getMembers();
ICPPASTVisiblityLabel vis = null;
- for( int i = 0; i < members.length; i++ ){
- if( members[i] instanceof ICPPASTVisiblityLabel )
- vis = (ICPPASTVisiblityLabel) members[i];
- else if( members[i] == decl )
+ for (IASTDeclaration member : members) {
+ if( member instanceof ICPPASTVisiblityLabel )
+ vis = (ICPPASTVisiblityLabel) member;
+ else if( member == decl )
break;
}
if( vis != null ){
@@ -127,8 +123,14 @@ public class CPPMethodTemplate extends CPPFunctionTemplate implements
}
public ICPPClassType getClassOwner() throws DOMException {
- ICPPClassScope scope = (ICPPClassScope)getScope();
- return scope.getClassType();
+ IScope scope= getScope();
+ while (scope instanceof ICPPTemplateScope) {
+ scope= scope.getParent();
+ }
+ if( scope instanceof ICPPClassScope ){
+ return ((ICPPClassScope)scope).getClassType();
+ }
+ return null;
}
public boolean isVirtual() {
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java
index b65737cf5ae..3c49e2d668d 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/BasicCallHierarchyTest.java
@@ -70,6 +70,7 @@ public class BasicCallHierarchyTest extends CallHierarchyBaseTest {
openCallHierarchy(editor);
Tree tree = getCHTreeViewer().getTree();
checkTreeNode(tree, 0, "proto()");
+ expandTreeItem(tree, 0);
checkTreeNode(tree, 0, 0, "main()");
editor.selectAndReveal(content.indexOf("func"), 2);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java
index cf622ef99f3..5fa5ae99952 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java
@@ -64,8 +64,8 @@ public class CHQueries {
if (calleeBinding != null) {
findCalledBy(index, calleeBinding, true, project, result);
IBinding[] overriddenBindings= getOverriddenBindings(index, calleeBinding);
- for (int i = 0; i < overriddenBindings.length; i++) {
- findCalledBy(index, overriddenBindings[i], false, project, result);
+ for (IBinding overriddenBinding : overriddenBindings) {
+ findCalledBy(index, overriddenBinding, false, project, result);
}
}
return cp.createNodes(node, result);
@@ -78,20 +78,21 @@ public class CHQueries {
final ICPPMethod m= (ICPPMethod) binding;
final char[] mname= m.getNameCharArray();
final ICPPClassType mcl= m.getClassOwner();
- final IFunctionType mft= m.getType();
- boolean isVirtual= m.isVirtual();
- ICPPMethod[] allMethods= mcl.getMethods();
- for (int i = 0; i < allMethods.length; i++) {
- ICPPMethod method = allMethods[i];
- if (CharArrayUtils.equals(mname, method.getNameCharArray()) && !mcl.isSameType(method.getClassOwner())) {
- if (mft.isSameType(method.getType())) {
- isVirtual= isVirtual || method.isVirtual();
- result.add(method);
+ if (mcl != null) {
+ final IFunctionType mft= m.getType();
+ boolean isVirtual= m.isVirtual();
+ ICPPMethod[] allMethods= mcl.getMethods();
+ for (ICPPMethod method : allMethods) {
+ if (CharArrayUtils.equals(mname, method.getNameCharArray()) && !mcl.isSameType(method.getClassOwner())) {
+ if (mft.isSameType(method.getType())) {
+ isVirtual= isVirtual || method.isVirtual();
+ result.add(method);
+ }
}
}
- }
- if (isVirtual) {
- return result.toArray(new IBinding[result.size()]);
+ if (isVirtual) {
+ return result.toArray(new IBinding[result.size()]);
+ }
}
} catch (DOMException e) {
// index bindings don't throw DOMExceptions
@@ -108,20 +109,20 @@ public class CHQueries {
final ArrayList<ICPPMethod> result= new ArrayList<ICPPMethod>();
final char[] mname= m.getNameCharArray();
final ICPPClassType mcl= m.getClassOwner();
- final IFunctionType mft= m.getType();
- ICPPClassType[] subclasses= getSubClasses(index, mcl);
- for (int i = 0; i < subclasses.length; i++) {
- ICPPClassType subClass = subclasses[i];
- ICPPMethod[] methods= subClass.getDeclaredMethods();
- for (int j = 0; j < methods.length; j++) {
- ICPPMethod method = methods[j];
- if (CharArrayUtils.equals(mname, method.getNameCharArray()) &&
- mft.isSameType(method.getType())) {
- result.add(method);
+ if (mcl != null) {
+ final IFunctionType mft= m.getType();
+ ICPPClassType[] subclasses= getSubClasses(index, mcl);
+ for (ICPPClassType subClass : subclasses) {
+ ICPPMethod[] methods= subClass.getDeclaredMethods();
+ for (ICPPMethod method : methods) {
+ if (CharArrayUtils.equals(mname, method.getNameCharArray()) &&
+ mft.isSameType(method.getType())) {
+ result.add(method);
+ }
}
}
+ return result.toArray(new IBinding[result.size()]);
}
- return result.toArray(new IBinding[result.size()]);
}
} catch (DOMException e) {
// index bindings don't throw DOMExceptions
@@ -153,8 +154,7 @@ public class CHQueries {
}
IIndexName[] names= index.findNames(classOrTypedef, IIndex.FIND_REFERENCES | IIndex.FIND_DEFINITIONS);
- for (int i = 0; i < names.length; i++) {
- IIndexName indexName = names[i];
+ for (IIndexName indexName : names) {
if (indexName.isBaseSpecifier()) {
IIndexName subClassDef= indexName.getEnclosingDefinition();
if (subClassDef != null) {
@@ -174,13 +174,14 @@ public class CHQueries {
}
final char[] mname= m.getNameCharArray();
final ICPPClassType mcl= m.getClassOwner();
- final IFunctionType mft= m.getType();
- ICPPMethod[] allMethods= mcl.getMethods();
- for (int i = 0; i < allMethods.length; i++) {
- ICPPMethod method = allMethods[i];
- if (CharArrayUtils.equals(mname, method.getNameCharArray()) && mft.isSameType(method.getType())) {
- if (method.isVirtual()) {
- return true;
+ if (mcl != null) {
+ final IFunctionType mft= m.getType();
+ ICPPMethod[] allMethods= mcl.getMethods();
+ for (ICPPMethod method : allMethods) {
+ if (CharArrayUtils.equals(mname, method.getNameCharArray()) && mft.isSameType(method.getType())) {
+ if (method.isVirtual()) {
+ return true;
+ }
}
}
}
@@ -193,8 +194,7 @@ public class CHQueries {
private static void findCalledBy(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
throws CoreException {
IIndexName[] names= index.findNames(callee, IIndex.FIND_REFERENCES | IIndex.SEARCH_ACCROSS_LANGUAGE_BOUNDARIES);
- for (int i = 0; i < names.length; i++) {
- IIndexName rname = names[i];
+ for (IIndexName rname : names) {
if (includeOrdinaryCalls || rname.couldBePolymorphicMethodCall()) {
IIndexName caller= rname.getEnclosingDefinition();
if (caller != null) {
@@ -217,8 +217,7 @@ public class CHQueries {
IIndexName callerName= IndexUI.elementToName(index, caller);
if (callerName != null) {
IIndexName[] refs= callerName.getEnclosedNames();
- for (int i = 0; i < refs.length; i++) {
- IIndexName name = refs[i];
+ for (IIndexName name : refs) {
IBinding binding= index.findBinding(name);
if (CallHierarchyUI.isRelevantForCallHierarchy(binding)) {
IBinding[] virtualOverriders= getOverridingBindings(index, binding);
@@ -229,8 +228,7 @@ public class CHQueries {
else {
ArrayList<ICElementHandle> list= new ArrayList<ICElementHandle>();
list.addAll(Arrays.asList(IndexUI.findRepresentative(index, binding)));
- for (int j = 0; j < virtualOverriders.length; j++) {
- IBinding overrider = virtualOverriders[j];
+ for (IBinding overrider : virtualOverriders) {
list.addAll(Arrays.asList(IndexUI.findRepresentative(index, overrider)));
}
defs= list.toArray(new ICElement[list.size()]);

Back to the top