Skip to content

[Java.Interop.Tools.JavaCallableWrappers] make TypeNameMapGenerator d… #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ namespace Java.Interop.Tools.JavaCallableWrappers {
* The rows MUST be sorted so that strcmp(3) can be used to compare keys
* values between rows
*/
public class TypeNameMapGenerator {
public class TypeNameMapGenerator : IDisposable {

Action<string, object[]> Log;
List<TypeDefinition> Types;
DirectoryAssemblyResolver Resolver;

public TypeNameMapGenerator (IEnumerable<string> assemblies, Action<string, object []> logMessage)
{
Expand All @@ -70,20 +71,19 @@ public TypeNameMapGenerator (IEnumerable<string> assemblies, Action<string, obje
var Assemblies = assemblies.ToList ();
var rp = new ReaderParameters (ReadingMode.Immediate);

using (var resolver = new DirectoryAssemblyResolver (Log, loadDebugSymbols: true, loadReaderParameters: rp)) {
foreach (var assembly in Assemblies) {
var directory = Path.GetDirectoryName (assembly);
if (string.IsNullOrEmpty (directory))
continue;
if (!resolver.SearchDirectories.Contains (directory))
resolver.SearchDirectories.Add (directory);
}
foreach (var assembly in Assemblies) {
resolver.Load (Path.GetFullPath (assembly));
}

Types = JavaTypeScanner.GetJavaTypes (Assemblies, resolver, logMessage);
Resolver = new DirectoryAssemblyResolver (Log, loadDebugSymbols: true, loadReaderParameters: rp);
foreach (var assembly in Assemblies) {
var directory = Path.GetDirectoryName (assembly);
if (string.IsNullOrEmpty (directory))
continue;
if (!Resolver.SearchDirectories.Contains (directory))
Resolver.SearchDirectories.Add (directory);
}
foreach (var assembly in Assemblies) {
Resolver.Load (Path.GetFullPath (assembly));
}

Types = JavaTypeScanner.GetJavaTypes (Assemblies, Resolver, logMessage);
}

public TypeNameMapGenerator (IEnumerable<TypeDefinition> types, Action<string, object[]> logMessage)
Expand All @@ -97,6 +97,21 @@ public TypeNameMapGenerator (IEnumerable<TypeDefinition> types, Action<string, o
Types = types.ToList ();
}

public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}

protected virtual void Dispose (bool disposing)
{
if (!disposing || Resolver == null)
return;

Resolver.Dispose ();
Resolver = null;
}

void LogWarning (string format, params object[] args)
{
Log (format, args);
Expand Down