system/src/sc/lang/java/IdentifierExpression.java
public static Object findClosestMethod(Object currentType, String nextName, List<Expression> args) {
      Object[] otherMethods = ModelUtil.getMethods(currentType, nextName, null);
      if (otherMethods == null) {
         Object enclType = ModelUtil.getEnclosingType(currentType);
         if (enclType != null)
            return findClosestMethod(enclType, nextName, args);
         return null;
      }
      int numParams = args == null ? 0 : args.size();
      Object bestMatch = null;
      int bestMatchNum = -1;
      Object[] ps = ModelUtil.getTypesFromExpressions(args);
      for (Object other:otherMethods) {
         Object[] ops = ModelUtil.getParameterTypes(other);
         int numOtherParams = ops == null ? 0 : ops.length;
         if (numOtherParams == numParams) {
            if (bestMatchNum == -1) {
               bestMatchNum = 0;
               bestMatch = other;
            }
            int matchNum = 0;
            for (int i = 0; i < numParams; i++) {
               if (ModelUtil.sameTypes(ops[i], ps[i]))
                  matchNum++;
            }
            if (matchNum > bestMatchNum) {
               bestMatch = other;
            }
         }
         if (bestMatch == null)
            bestMatch = other;
      }
      return bestMatch;
   }
/** For error checking, return a method of the same name which has the fewest mismatching arguments */
For error checking, return a method of the same name which has the fewest mismatching arguments
For error checking return a method of the same name which has the fewest mismatching arguments
public static Object findClosestMethod(Object currentType, String nextName, List<Expression> args) {
      Object[] otherMethods = ModelUtil.getMethods(currentType, nextName, null);
      if (otherMethods == null) {
         Object enclType = ModelUtil.getEnclosingType(currentType);
         if (enclType != null)
            return findClosestMethod(enclType, nextName, args);
         return null;
      }
      int numParams = args == null ? 0 : args.size();
      Object bestMatch = null;
      int bestMatchNum = -1;
      Object[] ps = ModelUtil.getTypesFromExpressions(args);
      for (Object other:otherMethods) {
         Object[] ops = ModelUtil.getParameterTypes(other);
         int numOtherParams = ops == null ? 0 : ops.length;
         if (numOtherParams == numParams) {
            if (bestMatchNum == -1) {
               bestMatchNum = 0;
               bestMatch = other;
            }
            int matchNum = 0;
            for (int i = 0; i < numParams; i++) {
               if (ModelUtil.sameTypes(ops[i], ps[i]))
                  matchNum++;
            }
            if (matchNum > bestMatchNum) {
               bestMatch = other;
            }
         }
         if (bestMatch == null)
            bestMatch = other;
      }
      return bestMatch;
   }
public static Object findClosestMethod ( Object currentType , String nextName , List < Expression > args ) { Object [ ] otherMethods = ModelUtil . getMethods ( currentType , nextName , null ) ; if ( otherMethods == null ) { Object enclType = ModelUtil . getEnclosingType ( currentType ) ; if ( enclType != null ) return findClosestMethod ( enclType , nextName , args ) ; return null ; } int numParams = args == null ? 0 : args . size ( ) ; Object bestMatch = null ; int bestMatchNum = - 1 ; Object [ ] ps = ModelUtil . getTypesFromExpressions ( args ) ; for ( Object other : otherMethods ) { Object [ ] ops = ModelUtil . getParameterTypes ( other ) ; int numOtherParams = ops == null ? 0 : ops . length ; if ( numOtherParams == numParams ) { if ( bestMatchNum == - 1 ) { bestMatchNum = 0 ; bestMatch = other ; } int matchNum = 0 ; for ( int i = 0 ; i < numParams ; i ++ ) { if ( ModelUtil . sameTypes ( ops [ i ] , ps [ i ] ) ) matchNum ++ ; } if ( matchNum > bestMatchNum ) { bestMatch = other ; } } if ( bestMatch == null ) bestMatch = other ; } return bestMatch ; }
For error checking, return a method of the same name which has the fewest mismatching arguments
For error checking return a method of the same name which has the fewest mismatching arguments