Skip to content

Commit

Permalink
Improve method name propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Apr 27, 2024
1 parent 1550142 commit b9c4b02
Showing 1 changed file with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static void completeMappingsFromTr(TrEnvironment trEnvironment) {
int srcNamespace = FULL_MAPPINGS.getNamespaceId("official");
int targetNamespace = FULL_MAPPINGS.getNamespaceId(getTargetNamespace());

Map<String, List<ExtendedClassMember>> classMembers = new HashMap<>();
Map<ExtendedClassMember, List<String>> classMembers = new HashMap<>();

for (MappingTree.ClassMapping classMapping : FULL_MAPPINGS.getClasses()) {
String className = classMapping.getName(srcNamespace);
Expand All @@ -226,36 +226,52 @@ public static void completeMappingsFromTr(TrEnvironment trEnvironment) {
TrMethod method = trClass.getMethod(methodMapping.getName(srcNamespace), methodMapping.getDesc(srcNamespace));

if (method != null && method.isVirtual()) {
for (String child : children) {
if (!classMembers.containsKey(child)) classMembers.put(child, new ArrayList<>());

classMembers.get(child).add(new ExtendedClassMember(
methodMapping.getName(srcNamespace), methodMapping.getDesc(srcNamespace), className
));
}
classMembers.put(new ExtendedClassMember(
methodMapping.getName(srcNamespace), methodMapping.getDesc(srcNamespace), className
), children);
}
}
}

int propagated = 0;

for (Map.Entry<String, List<ExtendedClassMember>> entry : classMembers.entrySet()) {
TrClass trClass = trEnvironment.getClass(entry.getKey());
for (Map.Entry<ExtendedClassMember, List<String>> entry : classMembers.entrySet()) {
List<String> toAdd = new ArrayList<>(entry.getValue());

if (trClass == null) continue;
while (!toAdd.isEmpty()) {
TrClass trClass = trEnvironment.getClass(toAdd.remove(0));
if (trClass == null) continue;

try {
FULL_MAPPINGS.visitClass(entry.getKey());
} catch (IOException e) {
e.printStackTrace();
List<String> children = trClass.getChildren().stream().map(TrClass::getName).collect(Collectors.toList());

for (String child : children) {
if (!entry.getValue().contains(child)) {
toAdd.add(child);
entry.getValue().add(child);
}
}
}
}

for (Map.Entry<ExtendedClassMember, List<String>> entry : classMembers.entrySet()) {
ExtendedClassMember member = entry.getKey();

for (String child : entry.getValue()) {
TrClass trClass = trEnvironment.getClass(child);
if (trClass == null) continue;

try {
FULL_MAPPINGS.visitClass(child);
} catch (IOException e) {
e.printStackTrace();
}

MappingTree.ClassMapping classMapping = FULL_MAPPINGS.getClass(entry.getKey());
MappingTree.ClassMapping classMapping = FULL_MAPPINGS.getClass(child);

for (ExtendedClassMember member : entry.getValue()) {
TrMethod method = trClass.getMethod(member.name, member.desc);
if (classMapping == null) continue;

if (method == null) continue;
TrMethod trMethod = trClass.getMethod(member.name, member.desc);
if (trMethod == null) continue;

if (classMapping.getMethod(member.name, member.desc, srcNamespace) != null) continue;

Expand Down

0 comments on commit b9c4b02

Please sign in to comment.