1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 22:22:11 +02:00

Bug 356239 - ClassCastException in ClassTypeHelper.getOwnMethods.

This commit is contained in:
Sergey Prigogin 2011-08-30 14:44:22 -07:00
parent 97d0869a9a
commit fb7d64098f
2 changed files with 19 additions and 15 deletions

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Anton Gorenkov - initial implementation
* Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.codan.internal.checkers;
@ -30,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
@ -179,22 +181,23 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker {
}
/**
* Checks whether specified type (class or typedef to the class) is abstract class.
* If it is - reports violations on each pure virtual method
* Checks whether specified type (class or typedef to the class) is an abstract class.
* If it is, reports violations on each pure virtual method
*/
private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode ) {
IType unwindedType = CxxAstUtils.getInstance().unwindTypedef(typeToCheck);
if (unwindedType instanceof ICPPClassType) {
ICPPClassType classType = (ICPPClassType) unwindedType;
ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType);
if (pureVirtualMethods == null) {
pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType);
pureVirtualMethodsCache.put(classType, pureVirtualMethods);
}
for (ICPPMethod method : pureVirtualMethods) {
reportProblem(ER_ID, problemNode, resolveName(classType), resolveName(method));
}
if (!(unwindedType instanceof ICPPClassType) || unwindedType instanceof IProblemBinding) {
return;
}
ICPPClassType classType = (ICPPClassType) unwindedType;
ICPPMethod[] pureVirtualMethods = pureVirtualMethodsCache.get(classType);
if (pureVirtualMethods == null) {
pureVirtualMethods = ClassTypeHelper.getPureVirtualMethods(classType);
pureVirtualMethodsCache.put(classType, pureVirtualMethods);
}
for (ICPPMethod method : pureVirtualMethods) {
reportProblem(ER_ID, problemNode, resolveName(classType), resolveName(method));
}
}
}

View file

@ -310,12 +310,13 @@ public class ClassTypeHelper {
/**
* Returns methods either declared by the given class or generated by the compiler. Does not
* include methods declared in base classes.
* @param classType
* @return
*/
private static ObjectSet<ICPPMethod> getOwnMethods(ICPPClassType classType) {
ObjectSet<ICPPMethod> set= new ObjectSet<ICPPMethod>(4);
set.addAll(classType.getDeclaredMethods());
if (classType instanceof IProblemBinding) {
return set;
}
ICPPClassScope scope= (ICPPClassScope) classType.getCompositeScope();
set.addAll(scope.getImplicitMethods());
return set;