1 19 package org.netbeans.modules.javacore.parser; 20 21 import org.netbeans.modules.javacore.jmiimpl.javamodel.JavaEnumImpl; 22 23 27 class EnumInfoMeasure implements Measure { 28 public static final EnumInfoMeasure INSTANCE = new EnumInfoMeasure(); 29 30 private static final int NAME_WEIGHT = 50; 31 private static final int CONSTANTS_WEIGHT = 30; 32 private static final int MEMBERS_WEIGHT = 20; 33 34 35 private EnumInfoMeasure() { 36 } 37 38 43 public int getDistance(Object refObject, Object ast) { 44 JavaEnumImpl refInfo = (JavaEnumImpl) refObject; 45 46 if (ast instanceof EnumInfo) { 47 EnumInfo astInfo = (EnumInfo) ast; 48 int result = 0; 49 50 result += StringMeasure.INSTANCE.getDistance(refInfo.getName(), astInfo.name) * NAME_WEIGHT; 51 if (refInfo.isPersisted()) { 52 String [] refConstantNames = InfoUtil.getElementNames(refInfo.getConstants()); 53 String [] astConstantNames = InfoUtil.getElementNames(astInfo.constants); 54 result += new ArrayMeasure(StringMeasure.INSTANCE).getDistance(refConstantNames, astConstantNames) * CONSTANTS_WEIGHT; 55 String [] refMemberNames = InfoUtil.getElementNames(refInfo.getFeatures()); 56 String [] astMemberNames = InfoUtil.getElementNames(astInfo.features); 57 result += new ArrayMeasure(StringMeasure.INSTANCE).getDistance(refMemberNames, astMemberNames) * MEMBERS_WEIGHT; 58 } 59 result = result / 100; 60 return result > INFINITE_DISTANCE ? INFINITE_DISTANCE : result; 61 } 62 return INFINITE_DISTANCE; 63 } 64 } 65 | Popular Tags |