Skip to content

Refactor: remove detectioncontext instanceof#424

Open
Sanchay117 wants to merge 1 commit into
cbomkit:mainfrom
Sanchay117:refactor/remove-detectioncontext-instanceof
Open

Refactor: remove detectioncontext instanceof#424
Sanchay117 wants to merge 1 commit into
cbomkit:mainfrom
Sanchay117:refactor/remove-detectioncontext-instanceof

Conversation

@Sanchay117
Copy link
Copy Markdown

Fix : #165

Summary

Change all translate function signatures across the translation layer to accept DetectionContext (concrete abstract class) instead of IDetectionContext (interface). This eliminates unnecessary instanceof DetectionContext runtime type checks.

Changes

Core Interface & Abstract Class

  • IContextTranslation<T>: Changed translate() parameter from IDetectionContextDetectionContext
  • ITranslator<R,T,S,P>: Changed abstract translate() parameter and translateStore() local variable to use DetectionContext (with a cast at the DetectionStore boundary)

Engine Model Hierarchy

  • PRNGContext: Now extends DetectionContext instead of directly implementing IDetectionContext
  • ProtocolContext: Now extends DetectionContext instead of directly implementing IDetectionContext

This brings all context types into the DetectionContext hierarchy, making the cast in ITranslator.translateStore() safe.

Language Translators (4 modules)

Module Files Modified
Java JavaTranslator, JavaAbstractLibraryTranslator, JavaCipherContextTranslator, JavaDigestContextTranslator, JavaSignatureContextTranslator, JavaKeyContextTranslator, JavaMacContextTranslator, JavaKeyAgreementContextTranslator, JavaAlgorithmParameterContextTranslator, JavaSecretKeyContextTranslator, JavaPRNGContextTranslator, JavaProtocolContextTranslator
Python PythonTranslator, PycaCipherContextTranslator, PycaDigestContextTranslator, PycaKeyAgreementContextTranslator, PycaKeyDerivationContextTranslator, PycaMacContextTranslator, PycaPrivateKeyContextTranslator, PycaPublicKeyContextTranslator, PycaSecretContextTranslator, PycaSecretKeyContextTranslator, PycaSignatureContextTranslator
Go GoTranslator, GoCipherContextTranslator, GoDigestContextTranslator, GoKeyContextTranslator, GoMacContextTranslator, GoPRNGContextTranslator, GoProtocolContextTranslator, GoSignatureContextTranslator
C# CSharpTranslator, CSharpCipherContextTranslator, CSharpDigestContextTranslator, CSharpKeyContextTranslator, CSharpMacContextTranslator

What was removed

All instanceof DetectionContext context checks in translator methods, replaced with direct usage of the detectionContext parameter. For example:

-if (value instanceof ValueAction<Tree> valueAction
-        && detectionContext instanceof DetectionContext context) {
-    String kind = context.get("kind").orElse("");
+if (value instanceof ValueAction<Tree> valueAction) {
+    String kind = detectionContext.get("kind").orElse("");

Testing

  • All existing tests pass

…ators

Signed-off-by: sanchaysingh <sanchay072@gmail.com>
@Sanchay117 Sanchay117 requested a review from a team as a code owner May 22, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove detectionContext instanceof DetectionContext context from the translation

1 participant