Skip to content

Commit

Permalink
Consider methods with elevated return types
Browse files Browse the repository at this point in the history
This resolves Mercury/GH-14.
  • Loading branch information
jamierocks committed May 10, 2020
1 parent 48a0422 commit 2a7c0b6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ subprojects {

group = 'org.cadixdev'
archivesBaseName = project.name.toLowerCase()
version = '0.5.2'
version = '0.5.3-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
package org.cadixdev.lorenz.impl.model;

import org.cadixdev.bombe.analysis.InheritanceProvider;
import org.cadixdev.bombe.analysis.InheritanceType;
import org.cadixdev.bombe.type.MethodDescriptor;
import org.cadixdev.bombe.type.signature.FieldSignature;
import org.cadixdev.bombe.type.signature.MethodSignature;
import org.cadixdev.lorenz.MappingSet;
Expand All @@ -36,9 +38,12 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -210,6 +215,12 @@ public void complete(final InheritanceProvider provider, final InheritanceProvid
return;
}

final Map<String, Set<MethodSignature>> nameToMethods = new HashMap<>();
for (final Map.Entry<MethodSignature, InheritanceType> method : info.getMethods().entrySet()) {
final Set<MethodSignature> methods = nameToMethods.computeIfAbsent(method.getKey().getName(), name -> new HashSet<>());
methods.add(method.getKey());
}

for (final InheritanceProvider.ClassInfo parent : info.provideParents(provider)) {
final ClassMapping<?, ?> parentMappings = this.getMappings().getOrCreateClassMapping(parent.getName());
parentMappings.complete(provider, parent);
Expand All @@ -224,6 +235,25 @@ public void complete(final InheritanceProvider provider, final InheritanceProvid
if (parent.canInherit(info, mapping.getSignature())) {
this.methods.putIfAbsent(mapping.getSignature(), mapping);
}

// Check if there are any methods here that override the return type of a parent
// method.
if (nameToMethods.containsKey(mapping.getObfuscatedName())) {
for (final MethodSignature methodSignature : nameToMethods.get(mapping.getObfuscatedName())) {
final MethodDescriptor methodDescriptor = methodSignature.getDescriptor();

final MethodSignature mappingSignature = mapping.getSignature();
final MethodDescriptor mappingDescriptor = mappingSignature.getDescriptor();

// The method MUST have the same parameters
// TODO: handle generic params
if (!Objects.equals(methodDescriptor.getParamTypes(), mappingDescriptor.getParamTypes())) continue;

if (mappingDescriptor.getReturnType().isAssignableFrom(methodDescriptor.getReturnType(), provider)) {
this.methods.putIfAbsent(methodSignature, mapping);
}
}
}
}
}

Expand Down

0 comments on commit 2a7c0b6

Please sign in to comment.