1212import java .util .*;
1313
1414public class NameResolution {
15- private static final String PACKAGE_NAME_LOOKUP_PREFIX = "__pkg_name__" ;
16- private static final String PACKAGE_TYPE_LOOKUP_PREFIX = "__pkg_type__" ;
17-
1815 private static String memberFuncCacheName (String name , WurstType receiverType ) {
1916 return name
2017 + "@"
@@ -24,70 +21,13 @@ private static String memberFuncCacheName(String name, WurstType receiverType) {
2421 }
2522
2623 private static ImmutableCollection <DefLink > scopeNameLinks (WScope scope , String name ) {
27- if (scope instanceof WPackage ) {
28- return packageNameLinks ((WPackage ) scope , name );
29- }
3024 return scope .attrNameLinks ().get (name );
3125 }
3226
3327 private static ImmutableCollection <TypeLink > scopeTypeLinks (WScope scope , String name ) {
34- if (scope instanceof WPackage ) {
35- return packageTypeLinks ((WPackage ) scope , name );
36- }
3728 return scope .attrTypeNameLinks ().get (name );
3829 }
3930
40- private static ImmutableCollection <DefLink > packageNameLinks (WPackage p , String name ) {
41- GlobalCaches .CacheKey key = new GlobalCaches .CacheKey (p , PACKAGE_NAME_LOOKUP_PREFIX + name , GlobalCaches .LookupType .PACKAGE );
42- @ SuppressWarnings ("unchecked" )
43- ImmutableCollection <DefLink > cached = (ImmutableCollection <DefLink >) GlobalCaches .lookupCache .get (key );
44- if (cached != null ) {
45- return cached ;
46- }
47-
48- LinkedHashSet <DefLink > result = new LinkedHashSet <>();
49- boolean repl = p .getName ().equals ("WurstREPL" );
50- for (WImport imp : p .getImports ()) {
51- if (imp .getPackagename ().equals ("NoWurst" )) {
52- continue ;
53- }
54- WPackage importedPackage = imp .attrImportedPackage ();
55- if (importedPackage == null ) {
56- continue ;
57- }
58- if (repl ) {
59- result .addAll (importedPackage .getElements ().attrNameLinks ().get (name ));
60- result .addAll (importedPackage .attrNameLinks ().get (name ));
61- } else {
62- result .addAll (importedPackage .attrExportedNameLinks ().get (name ));
63- }
64- }
65- ImmutableCollection <DefLink > links = ImmutableList .copyOf (result );
66- GlobalCaches .lookupCache .put (key , links );
67- return links ;
68- }
69-
70- private static ImmutableCollection <TypeLink > packageTypeLinks (WPackage p , String name ) {
71- GlobalCaches .CacheKey key = new GlobalCaches .CacheKey (p , PACKAGE_TYPE_LOOKUP_PREFIX + name , GlobalCaches .LookupType .PACKAGE );
72- @ SuppressWarnings ("unchecked" )
73- ImmutableCollection <TypeLink > cached = (ImmutableCollection <TypeLink >) GlobalCaches .lookupCache .get (key );
74- if (cached != null ) {
75- return cached ;
76- }
77-
78- LinkedHashSet <TypeLink > result = new LinkedHashSet <>();
79- for (WImport imp : p .getImports ()) {
80- WPackage importedPackage = imp .attrImportedPackage ();
81- if (importedPackage == null ) {
82- continue ;
83- }
84- result .addAll (importedPackage .attrExportedTypeNameLinks ().get (name ));
85- }
86- ImmutableCollection <TypeLink > links = ImmutableList .copyOf (result );
87- GlobalCaches .lookupCache .put (key , links );
88- return links ;
89- }
90-
9131 public static ImmutableCollection <FuncLink > lookupFuncsNoConfig (Element node , String name , boolean showErrors ) {
9232 if (!showErrors ) {
9333 GlobalCaches .CacheKey key = new GlobalCaches .CacheKey (node , name , GlobalCaches .LookupType .FUNC );
0 commit comments