diff --git a/maracas/src/org/maracas/m3/Core.rsc b/maracas/src/org/maracas/m3/Core.rsc index 58df3c77..bff18a9b 100644 --- a/maracas/src/org/maracas/m3/Core.rsc +++ b/maracas/src/org/maracas/m3/Core.rsc @@ -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) @@ -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; -} \ No newline at end of file +} + diff --git a/maracas/src/org/maracas/m3/JarToSrc.rsc b/maracas/src/org/maracas/m3/JarToSrc.rsc index bf3e93c0..db666f5b 100644 --- a/maracas/src/org/maracas/m3/JarToSrc.rsc +++ b/maracas/src/org/maracas/m3/JarToSrc.rsc @@ -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; @@ -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) {