1 19 package org.netbeans.modules.javacore.parser; 20 21 import org.netbeans.modules.javacore.jmiimpl.javamodel.MethodImpl; 22 23 24 28 class MethodInfoMeasure implements Measure { 29 public static final MethodInfoMeasure INSTANCE = new MethodInfoMeasure(); 30 31 private static final int NAME_WEIGHT = 60; 32 private static final int PARAMETERS_WEIGHT = 40; 33 34 35 private MethodInfoMeasure() { 36 } 37 38 43 public int getDistance(Object refObject, Object ast) { 44 if (ast instanceof MethodInfo) { 45 MethodInfo astInfo = (MethodInfo) ast; 46 MethodImpl refInfo = (MethodImpl) refObject; 47 int result; 48 TypeRef[] refTypeNames; 49 TypeRef[] astTypeNames; 50 51 if (astInfo.infoType!=MethodInfo.METHOD_TYPE) 52 return INFINITE_DISTANCE; 53 result = StringMeasure.INSTANCE.getDistance(refInfo.getName(), astInfo.name) * NAME_WEIGHT; 54 55 if (refInfo.isPersisted()) { 56 refTypeNames = InfoUtil.getTypeNames(refInfo); 57 astTypeNames = InfoUtil.getTypeNames(astInfo.parameters); 58 result += new OrderedArrayMeasure(ClassNameMeasure.INSTANCE).getDistance(refTypeNames, astTypeNames) * PARAMETERS_WEIGHT; 59 } 60 result/=100; 61 return result > INFINITE_DISTANCE ? INFINITE_DISTANCE : result; 62 } 63 return INFINITE_DISTANCE; 64 } 65 } 66 | Popular Tags |