From bf807ceec60428a96335ed99579029b1c9885fd6 Mon Sep 17 00:00:00 2001 From: Lina Ochoa Date: Thu, 17 Oct 2019 11:39:55 +0200 Subject: [PATCH] Managing anonymous class constructors. Related to #54 --- .../src/org/maracas/groundtruth/Compiler.rsc | 2 +- .../m3/{JarToSrc.rsc => JarToSource.rsc} | 48 +++++++------------ 2 files changed, 18 insertions(+), 32 deletions(-) rename maracas/src/org/maracas/m3/{JarToSrc.rsc => JarToSource.rsc} (75%) diff --git a/maracas/src/org/maracas/groundtruth/Compiler.rsc b/maracas/src/org/maracas/groundtruth/Compiler.rsc index a914fd56..6421fcd8 100644 --- a/maracas/src/org/maracas/groundtruth/Compiler.rsc +++ b/maracas/src/org/maracas/groundtruth/Compiler.rsc @@ -5,7 +5,7 @@ import lang::java::m3::Core; import org::maracas::delta::JApiCmp; import org::maracas::delta::JApiCmpDetector; import org::maracas::m3::Core; -import org::maracas::m3::JarToSrc; +import org::maracas::m3::JarToSource; import IO; import Message; diff --git a/maracas/src/org/maracas/m3/JarToSrc.rsc b/maracas/src/org/maracas/m3/JarToSource.rsc similarity index 75% rename from maracas/src/org/maracas/m3/JarToSrc.rsc rename to maracas/src/org/maracas/m3/JarToSource.rsc index db666f5b..d0d4f086 100644 --- a/maracas/src/org/maracas/m3/JarToSrc.rsc +++ b/maracas/src/org/maracas/m3/JarToSource.rsc @@ -1,4 +1,4 @@ -module org::maracas::m3::JarToSrc +module org::maracas::m3::JarToSource import lang::java::m3::AST; import lang::java::m3::Core; @@ -11,6 +11,7 @@ import String; loc transformNestedClass(loc logical, M3 m) { println(""); println("Starting: "); + logical = transformAnonymClassCons(logical); // |java+constructor:///pkg/A$1$1/A$1$1()| -> |java+constructor:///pkg/A$1$1/()| logical = transformInnerClass(logical); // |java+method:///pkg/A$1$1/m()| -> |java+method:///pkg/1/1/m()| logical = transformAnonymClassName(logical); // |java+method:///pkg/A/1/1/m()| -> |java+method:///pkg/A/$anonymous1/$anonymous1/m()| return resolveAnonymousClass(logical, m); // |java+method:///pkg/A/$anonymous1/$anonymous1/m()| -> |java+method:///pkg/A/n()/$anonymous1/n()/$anonymous1/m()| @@ -22,6 +23,16 @@ private loc transformInnerClass(loc logical) { return logical; } +private loc transformAnonymClassCons(loc logical) { + if (logical.scheme == "java+constructor") { + logical.path = visit(logical.path) { + case /\/[^\/]+\$\d+\([a-zA-Z0-9_\$.]*\)$/ => "/()" + } + } + println("Constructor: "); + return logical; +} + private loc transformAnonymClassName(loc logical) { bool match = true; do { @@ -51,12 +62,12 @@ private loc resolveAnonymousClass(loc logical, M3 m) { str anonymName = rest[..index]; begin = begin + end + index + 1; - anonym = resolveAnonymousClass(anonym, anonymName, m); - - if (index == size(rest) || anonym == unknownSource) { - return anonym; + loc candidate = resolveAnonymousClass(anonym, anonymName, m); + if (candidate.path == anonym.path || index == size(rest) || candidate == unknownSource) { + return candidate; } - anonym = resolve(original, anonym, begin, m); + + anonym = resolve(original, candidate, begin, m); } else { anonym.scheme = original.scheme; @@ -72,31 +83,6 @@ private loc resolveAnonymousClass(loc logical, M3 m) { return res; } -private loc resolveAnonymousClass(loc original, loc anonym, int begin, M3 m) { - str focus = original.path[begin..]; - - if (contains(focus, "$anonymous")) { - int end = findFirst(focus, "/$anonymous"); - str parent = focus[..end]; - anonym.path = anonym.path + parent; - - str rest = focus[end + 1..]; - int index = contains(rest, "/") ? findFirst(rest, "/") : size(rest); - str anonymName = rest[..index]; - - rest = rest[index..]; - anonym = resolveAnonymousClass(anonym, anonymName, m); - anonym = (anonym == unknownSource) ? anonym - : resolveAnonymousClass(original, anonym, begin + end + index + 1, m); - } - else { - anonym.scheme = original.scheme; - anonym.path = (!isEmpty(focus)) ? anonym.path + focus : anonym.path; - } - - return anonym; -} - //str anonymName = memberName(anonymClass); private loc resolveAnonymousClass(loc parent, str anonymName, M3 m) { parent = resolveTypeScheme(parent, m);