Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
Managing anonymous class constructors. Related to #54
Browse files Browse the repository at this point in the history
  • Loading branch information
lmove committed Oct 17, 2019
1 parent ae1a1eb commit bf807ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
2 changes: 1 addition & 1 deletion maracas/src/org/maracas/groundtruth/Compiler.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module org::maracas::m3::JarToSrc
module org::maracas::m3::JarToSource

import lang::java::m3::AST;
import lang::java::m3::Core;
Expand All @@ -11,6 +11,7 @@ import String;
loc transformNestedClass(loc logical, M3 m) {
println("");
println("Starting: <logical>");
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()|
Expand All @@ -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: <logical>");
return logical;
}

private loc transformAnonymClassName(loc logical) {
bool match = true;
do {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit bf807ce

Please sign in to comment.