From 19360036af3e78939ee20709a5ebf4ba6509326e Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 10 May 2013 16:45:01 -0700 Subject: [PATCH] Bug 407719 - [Call Hierarchy] java.lang.Exception: Unsafe method call --- .../core/dom/parser/cpp/ClassTypeHelper.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java index 615bb1a3eb8..78de34c2458 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/ClassTypeHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2012 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM Corporation 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 @@ -582,61 +582,64 @@ public class ClassTypeHelper { final ArrayList result= new ArrayList(); final HashMap virtualInClass= new HashMap(); - final ICPPFunctionType mft= method.getType(); + final ICPPFunctionType methodType= method.getType(); virtualInClass.put(mcl, method.isVirtual()); ICPPBase[] bases= getBases(mcl, point); for (ICPPBase base : bases) { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { - findOverridden((ICPPClassType) b, mname, mft, virtualInClass, result); + findOverridden((ICPPClassType) b, point, mname, methodType, virtualInClass, result); } } - // list is filled from most derived up to here, reverse it + // List is filled from most derived up to here, reverse it. Collections.reverse(result); return result.toArray(new ICPPMethod[result.size()]); } /** - * Searches for overridden methods starting in {@code cl}. The map {@code virtualInClass} contains a mapping - * of classes that have been visited to the information whether they (or a base-class) contain an overridden - * method. - * Returns whether {@code cl} contains an overridden method. + * Searches for overridden methods starting in {@code classType}. The map {@code virtualInClass} + * contains a mapping of classes that have been visited to the information whether they + * (or a base-class) contain an overridden method. + * + * @return whether {@code classType} contains an overridden method. */ - private static boolean findOverridden(ICPPClassType cl, char[] mname, ICPPFunctionType mft, - HashMap virtualInClass, ArrayList result) { - Boolean visitedBefore= virtualInClass.get(cl); + private static boolean findOverridden(ICPPClassType classType, IASTNode point, char[] methodName, + ICPPFunctionType methodType, Map virtualInClass, + List result) { + Boolean visitedBefore= virtualInClass.get(classType); if (visitedBefore != null) return visitedBefore; - ICPPMethod[] methods= cl.getDeclaredMethods(); + ICPPMethod[] methods= classType.getDeclaredMethods(); ICPPMethod candidate= null; boolean hasOverridden= false; for (ICPPMethod method : methods) { - if (CharArrayUtils.equals(mname, method.getNameCharArray()) && functionTypesAllowOverride(mft,method.getType())) { + if (CharArrayUtils.equals(methodName, method.getNameCharArray()) && + functionTypesAllowOverride(methodType, method.getType())) { candidate= method; hasOverridden= method.isVirtual(); break; } } - // prevent recursion - virtualInClass.put(cl, hasOverridden); - ICPPBase[] bases= cl.getBases(); + // Prevent recursion. + virtualInClass.put(classType, hasOverridden); + ICPPBase[] bases= getBases(classType, point); for (ICPPBase base : bases) { IBinding b= base.getBaseClass(); if (b instanceof ICPPClassType) { - if (findOverridden((ICPPClassType) b, mname, mft, virtualInClass, result)) { + if (findOverridden((ICPPClassType) b, point, methodName, methodType, virtualInClass, result)) { hasOverridden= true; } } } if (hasOverridden) { - // the candidate is virtual + // The candidate is virtual. if (candidate != null) result.add(candidate); - virtualInClass.put(cl, hasOverridden); + virtualInClass.put(classType, hasOverridden); } return hasOverridden; }