Skip to content

Instantly share code, notes, and snippets.

@nbhusare
Last active October 10, 2020 07:15
Show Gist options
  • Save nbhusare/6a8ec8e5c5ac5b3ecb2e8528b2da6078 to your computer and use it in GitHub Desktop.
Save nbhusare/6a8ec8e5c5ac5b3ecb2e8528b2da6078 to your computer and use it in GitHub Desktop.
Import declaration anti pattern
RPackage:
'pkg' name=QualifedName
importDec=ImportDeclaration?;
ImportDec:
'imports' '{'imports+=Import*'}';
Import:
importedNamespace=QNWildcard;
Problems with the above grammar: 1) You have to overwrite `ImportedNamespaceAwareLocalScopeProvider#internalGetImportedNamespaceResolvers()`, and in that you have to write special handling code to deal with the `ImportDec` (PS code below), 2) In real world projects, you'll see 1000's of models files created, which means equal number of `ImportDec` are created in the memory. It increases the memory requirement, and also increases the work of the garbage collector.
Is this an antipattern?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment