/** * Type Hierarchy Resolution * * Tracks class inheritance and interface implementations across files * to enable polymorphic sink detection. * * Example: When sink is Statement.executeQuery(), we can match calls * on PreparedStatement, CallableStatement, or any other subtype. */ import type { TypeInfo, TypeHierarchy as TypeHierarchyData, CircleIR } from '../types/index.js'; /** * Node representation for hierarchy tracking */ export interface TypeNode { name: string; fqn: string; kind: 'class' | 'interface' | 'enum'; extends: string | null; implements: string[]; extendsInterfaces: string[]; file: string; line: number; } /** * TypeHierarchyResolver - Builds and queries type inheritance relationships */ export declare class TypeHierarchyResolver { private types; private nameToFqn; private subtypes; private implementations; private _subtypeCache; private _implCache; private factoryReturnTypes; /** * Add types from a CircleIR analysis result */ addFromIR(ir: CircleIR, filePath: string): void; /** * Add a single type to the hierarchy */ addType(type: TypeInfo, filePath: string, defaultPackage?: string | null): void; /** * Get all direct subtypes of a class */ getDirectSubtypes(className: string): string[]; /** * Get all subtypes (transitive) of a class */ getAllSubtypes(className: string): string[]; /** * Get all direct implementations of an interface */ getDirectImplementations(interfaceName: string): string[]; /** * Get all implementations (including through subinterfaces) of an interface */ getAllImplementations(interfaceName: string): string[]; /** * Check if a type is a subtype of another (including transitive) */ isSubtypeOf(childName: string, parentName: string): boolean; /** * Check if a type implements an interface (directly or through inheritance) * Also handles interface-extends-interface relationships */ implementsInterface(typeName: string, interfaceName: string): boolean; /** * Get type info by name */ getType(name: string): TypeNode | undefined; /** * Get all types matching a simple name */ getTypesByName(simpleName: string): TypeNode[]; /** * Get the file where a type is defined */ getTypeFile(name: string): string | undefined; /** * Check if a receiver type could match a target class * Handles: exact match, subtype, implementation, simple name match */ couldBeType(receiverType: string, targetClass: string): boolean; /** * Export hierarchy data in the CircleIR format */ toTypeHierarchyData(): TypeHierarchyData; /** * Get statistics about the hierarchy */ getStats(): { totalTypes: number; classes: number; interfaces: number; enums: number; }; /** * Get all types in the hierarchy */ getAllTypes(): TypeNode[]; /** * Register the return type of a static factory method. * * @param factoryClass Simple class name of the factory (e.g. `HttpClients`). * @param method Factory method name (e.g. `createDefault`). * @param returnFqn Fully-qualified return type (e.g. * `org.apache.http.impl.client.CloseableHttpClient`). * * — cognium-dev #241 Java */ registerFactoryReturnType(factoryClass: string, method: string, returnFqn: string): void; /** * Resolve a static-factory receiver expression to its return type FQN. * * Accepts a receiver expression of shape `.()` (or * a longer dotted prefix ending in the same). Returns the registered * return-type FQN, or `null` when no matching factory is registered. * * Examples that resolve (given Apache HttpClient registration): * `HttpClients.createDefault()` → `org.apache.http.impl.client.CloseableHttpClient` * `org.apache.http.impl.client.HttpClients.createDefault()` → same * * — cognium-dev #241 Java */ resolveFactoryReturnType(receiver: string): string | null; /** * Clear all data */ clear(): void; /** * Resolve a type name to its FQN */ private resolveTypeName; /** * Resolve a name (simple or FQN) to its FQN */ private resolveFqn; /** * Get simple name from FQN */ private getSimpleName; /** * Get package from FQN */ private getPackage; } /** * Pre-populated common Java type hierarchy * These are standard JDK types that code often extends/implements */ export declare function createWithJdkTypes(): TypeHierarchyResolver; /** * Pre-registered type hierarchies for widely used third-party libraries. * * These are strictly additive facts — code that supplies its own IR types * for these classes overrides the pre-registered facts via the normal * `addFromIR()` path. Purpose: allow sink patterns keyed on a base class / * interface (e.g. `HttpClient.execute`) to match subtype receivers * (`CloseableHttpClient`, `InternalHttpClient`, etc.) via * `TypeHierarchyResolver.isSubtypeOf()`. * * Currently registered: * - Apache HttpClient 4.x (`org.apache.http.*`) * - Apache HttpClient 5.x (`org.apache.hc.client5.*`) */ export declare function registerCommonLibraries(resolver: TypeHierarchyResolver): void; //# sourceMappingURL=type-hierarchy.d.ts.map