Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 541-latest-featur…
Browse files Browse the repository at this point in the history
…e-classeswithcallbacks-does-not-work-as-expected
  • Loading branch information
masesdevelopers committed Sep 26, 2024
2 parents c91781b + 40b95db commit d40860b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/net/JNetReflector/InternalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ public static string RemoveThrowsAndCleanupSignature(this string methodSignature
if (methodSignature.Contains(SpecialNames.JavaLangThrows))
{
methodSignature = methodSignature.Substring(0, methodSignature.IndexOf(SpecialNames.JavaLangThrows));
return methodSignature.TrimEnd();
return RemoveThrowsAndCleanupSignature(methodSignature.TrimEnd());
}
else if (methodSignature.EndsWith(';'))
{
return methodSignature.Substring(0, methodSignature.Length - 1);
return RemoveThrowsAndCleanupSignature(methodSignature.Substring(0, methodSignature.Length - 1));
}
return methodSignature;
return methodSignature.Replace(", ", ",");
}

public static string AddClassNameToSignature(this string methodSignature, string className)
Expand Down
61 changes: 58 additions & 3 deletions src/net/JNetReflector/JNetReflectorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,24 @@ public static IDictionary<Class, IReadOnlyDictionary<string, string>> ExtractJav
si.Arguments = arguments;

process = Process.Start(si);
TimeSpan initial = process.TotalProcessorTime;
TimeSpan initialTotalProcessorTime = process.TotalProcessorTime;
int cycles = 0;
while ((exited = process.WaitForExit(100)) == false)
{
process.Refresh();
TimeSpan current = process.TotalProcessorTime;
if ((current - initial) < TimeSpan.FromMilliseconds(10)) break; // process is idle???
TimeSpan currentTotalProcessorTime = process.TotalProcessorTime;
if ((currentTotalProcessorTime - initialTotalProcessorTime) < TimeSpan.FromMilliseconds(10)) break; // process is idle???
if (++cycles > toBeAnalyzed.Count) break; // elapsed max cycles
}
if (exited && process.ExitCode != 0) throw new InvalidOperationException($"javap falied with error {process.ExitCode}");

Dictionary<string, string> map = new Dictionary<string, string>();
string line;
int classCounter = -1;
string methodName = string.Empty;
string className = string.Empty;
bool nextLineIsDescriptor = false;
#if OLD_ALGORITHM
while ((line = process.StandardOutput.ReadLine()) != null)
{
if (line.Contains("Compiled from"))
Expand All @@ -151,6 +153,59 @@ public static IDictionary<Class, IReadOnlyDictionary<string, string>> ExtractJav
methodName = methodName.AddClassNameToSignature(className);
}
}
#else
int endCounter = 0;
int cycleCounter = 0;
do
{
line = process.StandardOutput.ReadLine();
if (line == null)
{
if (endCounter != toBeAnalyzed.Count)
{
// wait a while
cycleCounter++;
System.Threading.Thread.Sleep(1);
continue;
}
else break;
}
else
{
if (line.Contains("Compiled from"))
{
if (classCounter != -1) { dict.TryAdd(toBeAnalyzed[classCounter], map); }
classCounter++;
className = toBeAnalyzed[classCounter].Name;
map = new Dictionary<string, string>();
}
if (nextLineIsDescriptor)
{
nextLineIsDescriptor = false;
string signature = line.TrimStart().TrimEnd();
signature = signature.Remove(0, "descriptor: ".Length);
map.Add(methodName, signature);
}
bool isInterfaceOrClassLine = line.Contains("class") || line.Contains("interface");
if (line.Contains("public") && !isInterfaceOrClassLine)
{
nextLineIsDescriptor = true;
methodName = line.TrimStart().TrimEnd();
methodName = methodName.RemoveThrowsAndCleanupSignature();
methodName = methodName.AddClassNameToSignature(className);
}

cycleCounter = 0;
}

if (line.TrimEnd() == "}")
{
endCounter++;
}
if (endCounter == toBeAnalyzed.Count) break;
}
while (cycleCounter < 100);
#endif
dict.TryAdd(toBeAnalyzed[classCounter], map);
}
catch { }
Expand Down

0 comments on commit d40860b

Please sign in to comment.