예제 #1
0
            public override IAnalysisSet GetIndex(Node node, AnalysisUnit unit, IAnalysisSet index)
            {
                var res = base.GetIndex(node, unit, index);

                var names = index.GetConstantValueAsString()
                            .Where(s => !string.IsNullOrEmpty(s) && ModulePath.IsImportable(s))
                            .Distinct()
                            .ToArray();

                if (names.Length != 1)
                {
                    // Unless you request a specific module by string literal,
                    // you won't get any object out of sys.modules.
                    return(AnalysisSet.Empty);
                }

                var name = names[0];

                lock (_owner.Modules) {
                    IAnalysisSet knownValues;
                    if (_owner.Modules.TryGetValue(name, out knownValues) &&
                        knownValues != null &&
                        knownValues.Any()
                        )
                    {
                        return(knownValues);
                    }
                }

                ModuleReference modRef;

                if (unit.State.Modules.TryImport(name, out modRef))
                {
                    return(modRef.AnalysisModule);
                }

                return(AnalysisSet.Empty);
            }
예제 #2
0
 // Avoid hitting the filesystem, but exclude non-importable
 // paths. Ideally, we'd stop at the first path that's a known
 // search path, except we don't know search paths here.
 private static bool IsPackageCheck(string path)
 {
     return(ModulePath.IsImportable(PathUtils.GetFileName(path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))));
 }
예제 #3
0
 // Avoid hitting the filesystem, but exclude non-importable
 // paths. Ideally, we'd stop at the first path that's a known
 // search path, except we don't know search paths here.
 private static bool IsPackageCheck(string path)
 {
     return(ModulePath.IsImportable(PathUtils.GetFileOrDirectoryName(path)));
 }