Improved type inference based on imported types
enables the matching of
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
in the call of extracted method
private Object[] resolvePreparedArguments(String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor)
in commit
@@ -3,6 +3,7 @@ package gr.uom.java.xmi.decomposition;
import gr.uom.java.xmi.LocationInfo.CodeElementType;
import gr.uom.java.xmi.UMLAbstractClass;
import gr.uom.java.xmi.UMLClass;
+import gr.uom.java.xmi.UMLImport;
import gr.uom.java.xmi.UMLOperation;
import gr.uom.java.xmi.UMLParameter;
import gr.uom.java.xmi.UMLType;
@@ -317,7 +318,7 @@ public class OperationInvocation extends AbstractCall {
if(inferredArgumentTypes.size() > i && inferredArgumentTypes.get(i) != null) {
if(!parameterType.getClassType().equals(inferredArgumentTypes.get(i).toString()) &&
!parameterType.toString().equals(inferredArgumentTypes.get(i).toString()) &&
- !compatibleTypes(parameter, inferredArgumentTypes.get(i), modelDiff)) {
+ !compatibleTypes(parameter, inferredArgumentTypes.get(i), callerOperation, modelDiff)) {
return false;
}
}
@@ -327,7 +328,7 @@ public class OperationInvocation extends AbstractCall {
return this.numberOfArguments == operation.getParameterTypeList().size() || varArgsMatch(operation, lastInferredArgumentType);
}
- private boolean compatibleTypes(UMLParameter parameter, UMLType type, UMLModelDiff modelDiff) {
+ private boolean compatibleTypes(UMLParameter parameter, UMLType type, VariableDeclarationContainer callerOperation, UMLModelDiff modelDiff) {
String type1 = parameter.getType().toString();
String type2 = type.toString();
if(collectionMatch(parameter.getType(), type))
@@ -375,6 +376,24 @@ public class OperationInvocation extends AbstractCall {
return true;
}
}
+ for(UMLClassBaseDiff classDiff : modelDiff.getCommonClassDiffList()) {
+ if(classDiff.getNextClassName().startsWith(callerOperation.getClassName())) {
+ List<UMLImport> imports = classDiff.getNextClass().getImportedTypes();
+ String qualifiedType1Prefix = null;
+ String qualifiedType2Prefix = null;
+ for(UMLImport umlImport : imports) {
+ if(umlImport.getName().endsWith("." + type1)) {
+ qualifiedType1Prefix = umlImport.getName().substring(0, umlImport.getName().indexOf("." + type1));
+ }
+ if(umlImport.getName().endsWith("." + type2)) {
+ qualifiedType2Prefix = umlImport.getName().substring(0, umlImport.getName().indexOf("." + type2));
+ }
+ }
+ if(qualifiedType1Prefix != null && qualifiedType2Prefix != null && qualifiedType1Prefix.equals(qualifiedType2Prefix)) {
+ return true;
+ }
+ }
+ }
}
if(!parameter.isVarargs() && type1.endsWith("Object") && !type2.endsWith("Object"))
return true;
