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

Commit

Permalink
Point to anonymous class owner type. Related to #54
Browse files Browse the repository at this point in the history
  • Loading branch information
lmove committed Oct 16, 2019
1 parent 1cae570 commit ae1a1eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 3 additions & 1 deletion maracas/src/org/maracas/m3/Core.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ set[loc] types(set[loc] locs) = { e | e <- locs, isType(e) };
bool isType(loc entity) = isClass(entity) || isInterface(entity);
bool isAPIEntity(loc entity) = isType(entity) || isMethod(entity) || isField(entity);
bool isKnown(loc elem) = elem != |unknwon:///|;
bool isAnonymousClass(loc entity) = entity.scheme == "java+anonymousClass";

bool isTargetMemberExclInterface(loc elem)
= isClass(elem)
Expand Down Expand Up @@ -418,4 +419,5 @@ bool isDeclared(loc logical, M3 m) = m.declarations[logical] != {};
loc getDeclaration(loc logical, M3 m) {
set[loc] decls = m.declarations[logical];
return (!isEmpty(decls)) ? getOneFrom(decls) : unknownSource;
}
}
31 changes: 21 additions & 10 deletions maracas/src/org/maracas/m3/JarToSrc.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ private loc resolveAnonymousClass(loc logical, M3 m) {
begin = begin + end + index + 1;

anonym = resolveAnonymousClass(anonym, anonymName, m);
anonym = (anonym == unknownSource) ? anonym : resolve(original, anonym, begin, m);

if (index == size(rest) || anonym == unknownSource) {
return anonym;
}
anonym = resolve(original, anonym, begin, m);
}
else {
anonym.scheme = original.scheme;
Expand Down Expand Up @@ -93,29 +97,36 @@ private loc resolveAnonymousClass(loc original, loc anonym, int begin, M3 m) {
return anonym;
}

//str anonName = memberName(anonClass);
private loc resolveAnonymousClass(loc parent, str anonName, M3 m) {
//str anonymName = memberName(anonymClass);
private loc resolveAnonymousClass(loc parent, str anonymName, M3 m) {
parent = resolveTypeScheme(parent, m);
set[loc] children = m.containment[parent];
loc anonClass = parent + anonName;
anonClass.scheme = "java+anonymousClass";
loc anonymClass = parent + anonymName;
anonymClass.scheme = "java+anonymousClass";

if (anonClass in children) {
return anonClass;
if (anonymClass in children) {
return anonymClass;
}

for (c <- children) {
set[loc] localChildren = m.containment[c];
anonClass.path = (c + anonName).path;
anonymClass.path = (c + anonymName).path;

if (anonClass in localChildren) {
return anonClass;
if (anonymClass in localChildren) {
return anonymClass;
}
if (hasAnonymousClass(localChildren, m)) {
return parent;
}
}

return unknownSource;
}

bool hasAnonymousClass(set[loc] locs, M3 m) {
return if (loc l <- locs, isAnonymousClass(l)) true; else false;
}

// Only considering java+class and java+interface cases
// Enums and annotations are left behind
private loc resolveTypeScheme(loc logical, M3 m) {
Expand Down

0 comments on commit ae1a1eb

Please sign in to comment.