IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
JVM.Resolver.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Concurrent;
3using System.Collections.Generic;
4using System.ComponentModel;
5using System.Linq;
6using System.Reflection;
8
11
12namespace IKVM.Runtime
13{
14
15#if FIRST_PASS == false && IMPORTER == false && EXPORTER == false
16
17 static partial class JVM
18 {
19
23 internal class Resolver : ISymbolResolver
24 {
25
30 static IEnumerable<Assembly> GetCoreAssemblies()
31 {
32 yield return typeof(object).Assembly;
33 yield return typeof(RuntimeCompatibilityAttribute).Assembly;
34 yield return typeof(Console).Assembly;
35 yield return typeof(System.Threading.Interlocked).Assembly;
36 yield return typeof(EditorBrowsableAttribute).Assembly;
37 yield return typeof(System.Collections.IEnumerable).Assembly;
38 yield return typeof(IEnumerable<>).Assembly;
39 yield return typeof(Environment).Assembly;
40 }
41
42 readonly static Assembly[] coreAssemblies = GetCoreAssemblies().Distinct().ToArray();
43
44 readonly ReflectionSymbolContext _context = new();
45 readonly IAssemblySymbol[] _coreAssemblies;
46 readonly ConcurrentDictionary<string, ITypeSymbol> _typeCache = new();
47
51 public Resolver()
52 {
53 _coreAssemblies = coreAssemblies.Select(_context.GetOrCreateAssemblySymbol).ToArray();
54 }
55
57 public IAssemblySymbol ResolveAssembly(string assemblyName)
58 {
59 return Assembly.Load(assemblyName) is { } a ? _context.GetOrCreateAssemblySymbol(a) : null;
60 }
61
63 public IAssemblySymbol ResolveBaseAssembly()
64 {
65 return _context.GetOrCreateAssemblySymbol(typeof(java.lang.Object).Assembly);
66 }
67
69 public ITypeSymbol ResolveCoreType(string typeName)
70 {
71 return _typeCache.GetOrAdd(typeName, ResolveCoreTypeImpl);
72 }
73
74 ITypeSymbol ResolveCoreTypeImpl(string typeName)
75 {
76 // loop over core assemblies searching for type
77 foreach (var assembly in _coreAssemblies)
78 if (assembly.GetType(typeName) is ITypeSymbol t)
79 return t;
80
81 return null;
82 }
83
85 public ITypeSymbol ResolveRuntimeType(string typeName)
86 {
87 return typeof(Resolver).Assembly.GetType(typeName) is { } t ? _context.GetOrCreateTypeSymbol(t) : null;
88 }
89
90 }
91
92 }
93
94#endif
95
96}
IKVM.Reflection.Assembly Assembly
Holds references to symbols derived from System.Reflection.
Main state of the running JVM.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
ITypeSymbol? GetType(string name)
Gets the ITypeSymbol object with the specified name in the assembly instance.
Provides an interface to resolve a maaged type symbols.
Represents type declarations: class types, interface types, array types, value types,...
IAssemblySymbol Assembly
Gets the IAssemblySymbol in which the type is declared. For generic types, gets the IAssemblySymbol i...