Get a capture variable's lower bound, returning other types unchanged.
@param t a type
554048
public Type cvarLowerBound(Type t) {
        if (t.hasTag(TYPEVAR) && ((TypeVar) t).isCaptured()) {
            return cvarLowerBound(t.getLowerBound());
        }
        else return t;
    }
1271983
public int filterObject(CaptureSearchResult r) {
		String captureDate = r.getCaptureTimestamp();
		
		int captureDateLength = Math.min(captureDate.length(), endDate.length());

		return (endDate.substring(0, captureDateLength).compareTo(
				captureDate) < 0) ? 
				FILTER_ABORT : FILTER_INCLUDE; 
	}
862928
Type unaryPromotion(Type t) {
        Type unboxed = types.unboxedTypeOrType(t);
        switch (unboxed.getTag()) {
            case BYTE:
            case SHORT:
            case CHAR:
                return syms.intType;
            default:
                return unboxed;
        }
    }
478908
public List<Type> capture(List<Type> ts) {
        List<Type> buf = List.nil();
        for (Type t : ts) {
            buf = buf.prepend(capture(t));
        }
        return buf.reverse();
    }
812040
public static Type resolveBound(TypeVariable<?> typeVariable) {
    Type[] bounds = typeVariable.getBounds();
    if (bounds.length == 0)
      return Unknown.class;

    Type bound = bounds[0];
    if (bound instanceof TypeVariable)
      bound = resolveBound((TypeVariable<?>) bound);

    return bound == Object.class ? Unknown.class : bound;
  }
806569
public Type unboxedTypeOrType(Type t) {
        Type unboxedType = unboxedType(t);
        return unboxedType.hasTag(NONE) ? t : unboxedType;
    }
135966
private static Map<TypeVariable<?>, Type> getAllAssignments(final Type t) {
        return spider(new TypeVariableMap(), new HashSet<>(), t);
    }
379794
public static <T extends Comparable<T>> T lt(T value) {
        reportMatcher(new LessThan<T>(value));
        return null;
    }
1074357
static Type getRawType(Type genericType, Map<TypeVariable, Type> typeVariableMap) {
		Type resolvedType = genericType;
		if (genericType instanceof TypeVariable) {
			TypeVariable tv = (TypeVariable) genericType;
			resolvedType = typeVariableMap.get(tv);
			if (resolvedType == null) {
				resolvedType = extractBoundForTypeVariable(tv);
			}
		}
		if (resolvedType instanceof ParameterizedType) {
			return ((ParameterizedType) resolvedType).getRawType();
		}
		else {
			return resolvedType;
		}
	}
1009743
@Override
    double lowerBound(int k) {
        return min * Double.longBitsToDouble((k + (0x3ffL << bitsOfPrecision)) << (52 - bitsOfPrecision)) /* / fuzz */;
    }
604071
private double getUsedScore( VarBindingDef binding, boolean onceOnly)
    {
    // Since used tuples are in least-recently-used-first order, start from the end of the list and look
    // for the first tuple that includes this binding. This is the most recent use of this binding.
    // Return the distance of this tuple from the start of the list, as percentage of the size of the list.
    int index;
    int usedCount;
    Tuple nextTuple;
    for( usedCount = used_.size(),
           index = usedCount - 1;

         index >= 0
           && (nextTuple = used_.get( index)) != null
           && !((!onceOnly || nextTuple.isOnce()) && nextTuple.contains( binding));

         index--);

    return
      index < 0
      ? 0.0

      : (double)(index + 1) / (usedCount + 1);
    }
1357626
private static List<Type> getBounds(TypeVar v, DocEnv env) {
        final Type upperBound = v.getUpperBound();
        Name boundname = upperBound.tsym.getQualifiedName();
        if (boundname == boundname.table.names.java_lang_Object
            && !upperBound.isAnnotated()) {
            return List.nil();
        } else {
            return env.types.getBounds(v);
        }
    }
630225
public TypeBindings withUnboundVariable(String name)
    {
        int len = (_unboundVariables == null) ? 0 : _unboundVariables.length;
        String[] names =  (len == 0)
                ? new String[1] : Arrays.copyOf(_unboundVariables, len+1);
        names[len] = name;
        return new TypeBindings(_names, _types, names);
    }
301968
public VarValueDef getBinding( VarDef var)
    {
    VarBindingDef binding = bindings_.get( var);
    return
      binding == null
      ? null
      : binding.getValueDef();
    }
138556
private Comparator<VarBindingDef> byUsage( final VarTupleSet varTupleSet)
    {
    return
      new Comparator<VarBindingDef>()
        {
        public int compare( VarBindingDef binding1, VarBindingDef binding2)
          {
          // Compare by usage score: higher score is preferred.
          int resultScore = getScore( binding2).compareTo( getScore( binding1));
          return
            // If equal usage score...
            resultScore == 0
            // ...then compare lexigraphically
            ? varBindingDefSorter_.compare( binding1, binding2)
            : resultScore;
          }

        private Integer getScore( VarBindingDef binding)
          {
          Integer score = bindingScores_.get( binding);
          if( score == null)
            {
            // Preferred higher "unused-ness" and lower "used-ness" (especially among once-only tuples)
            int maxScore = 1000;
            int unusedScore = (int) (varTupleSet.getUnusedScore( binding) * maxScore);
            int usedScore = (int) ((1.0 - varTupleSet.getUsedScore( binding)) * (maxScore - 1));
            int usedOnceScore = (int) ((1.0 - varTupleSet.getUsedOnceScore( binding)) * (maxScore - 1));
            score = ((unusedScore * maxScore) + usedOnceScore) * maxScore + usedScore;
            bindingScores_.put( binding, score);
            }
          
          return score;
          }
        private Map<VarBindingDef,Integer> bindingScores_ = new HashMap<VarBindingDef,Integer>();
      };
    }
1180600
public static TypeBinding bind( Generator g, IType t, String nameHint ) throws BindingException {
        IPrimitiveType pt = t.queryInterface(IPrimitiveType.class);
        if(pt!=null) {
            // primitive
            TypeBinding r = primitiveTypeBindings.get(pt.getVarType());
            if(r!=null)     return r;

            throw new BindingException(Messages.UNSUPPORTED_VARTYPE.format(pt.getVarType()));
        }

        IPtrType ptrt = t.queryInterface(IPtrType.class);
        if(ptrt!=null) {
            // pointer type
            IType comp = ptrt.getPointedAtType();
            IInterfaceDecl compDecl = comp.queryInterface(IInterfaceDecl.class);
            if( compDecl!=null ) {
                // t = T* where T is a declared interface
                return new TypeBinding( g.getTypeName(compDecl), NativeType.ComObject, true );
            }

            IDispInterfaceDecl dispDecl = comp.queryInterface(IDispInterfaceDecl.class);
            if( dispDecl!=null ) {
                // t = T* where T is a declared interface
                return new TypeBinding( g.getTypeName(dispDecl), NativeType.ComObject,  true );
            }

            // t = coclass*
            ICoClassDecl classdecl = comp.queryInterface(ICoClassDecl.class);
            if(classdecl!=null) {
                // bind to its default interface
                ITypeDecl di = g.getDefaultInterface(classdecl);
                if(di==null)
                    // no primary interface known. treat it as IUnknown
                    return new TypeBinding(Com4jObject.class, NativeType.ComObject, true);
                else
                    return new TypeBinding( g.getTypeName(di), NativeType.ComObject, true );
            }

            IPrimitiveType compPrim = comp.queryInterface(IPrimitiveType.class);
            if( compPrim!=null ) {
                // T = PRIMITIVE*
                if( compPrim.getVarType()== VarType.VT_VARIANT ) {
                    // T = VARIANT*
                    return new TypeBinding(Object.class, NativeType.VARIANT_ByRef, true);
                }
                if( compPrim.getVarType()==VarType.VT_VOID ) {
                    // T = void*
                    return new TypeBinding(Buffer.class,  NativeType.PVOID, true );
                }
                if( compPrim.getVarType()==VarType.VT_UI2 ) {
                    // T = ushort*
                    if( isPsz(nameHint) )
                        // this is a common mistake
                        return new TypeBinding( String.class, NativeType.Unicode, false );
                }
                if( compPrim.getVarType()==VarType.VT_BOOL ) {
                    return new TypeBinding("Holder<Boolean>", NativeType.VariantBool_ByRef, true );
                }
            }

            ISafeArrayType at = comp.queryInterface(ISafeArrayType.class);
            if(at!=null) {
                // T=SAFEARRAY(...)
                IType comp2 = at.getComponentType();

                IPrimitiveType compPrim2 = comp2.queryInterface(IPrimitiveType.class);
                if( compPrim2!=null ) {
                    TypeBinding r = primitiveTypeBindings.get(compPrim2.getVarType());
                    if(r!=null) {
                        return new TypeBinding("Holder<"+r.javaType+"[]>", NativeType.SafeArray, true );
                    }
                }
                TypeBinding tb = TypeBinding.bind(g, comp2, null);
                if(tb.nativeType == NativeType.VARIANT){
                  return new TypeBinding("Holder<Object[]>", NativeType.SafeArray, true);
                }
            }

            // a few other random checks
            String name = getTypeString(ptrt);
            if( name.equals("_RemotableHandle*") ) {
                // marshal as the raw pointer value
                return new TypeBinding( Integer.TYPE, NativeType.Int32,  true );
            }
            if(name.equals("GUID*")) {
                return new TypeBinding( "GUID", NativeType.GUID, true );
            }

            // otherwise use a holder
            TypeBinding b = bind(g,comp,null);
            if(b!=null && b.nativeType.byRef()!=null )
                return b.createByRef();
        }

        ISafeArrayType at = t.queryInterface(ISafeArrayType.class);
        if(at!=null) {
            // T=SAFEARRAY(...)
            IType comp = at.getComponentType();

            IPrimitiveType compPrim = comp.queryInterface(IPrimitiveType.class);
            if( compPrim!=null ) {
                TypeBinding r = primitiveTypeBindings.get(compPrim.getVarType());
                if(r!=null) {
                    return new TypeBinding(r.javaType+"[]", NativeType.SafeArray, true );
                }
            }
            TypeBinding tb = TypeBinding.bind(g, comp, null);
            if(tb.nativeType == NativeType.VARIANT){
              return new TypeBinding("Object[]", NativeType.SafeArray, true);
            }
        }

        // T = typedef
        ITypedefDecl typedef = t.queryInterface(ITypedefDecl.class);
        if(typedef!=null) {
            return bind(g,typedef.getDefinition(),nameHint);
        }

        // T = enum
        IEnumDecl enumdef = t.queryInterface(IEnumDecl.class);
        if(enumdef!=null) {
            // TODO: we should probably check the size of the enum.
            // there's no guarantee it's 32 bit.
            return new TypeBinding( g.getTypeName(enumdef), NativeType.Int32, true );
        }

        // a few other random checks
        String name = getTypeString(t);
        if(name.equals("GUID")) {
            return new TypeBinding( "GUID", NativeType.GUID, true );
        }

        IDispInterfaceDecl disp = t.queryInterface(IDispInterfaceDecl.class);
        if(disp != null) {
            // TODO check this: this is a dispatch interface, so bind to Com4jObject?
            if(disp.getGUID().equals(COM4J.IID_IPictureDisp)){
                return new TypeBinding(IPictureDisp.class, NativeType.ComObject, true);
            }
            if(disp.getGUID().equals(COM4J.IID_IFontDisp)){
                return new TypeBinding(IFontDisp.class, NativeType.ComObject, true);
            }
            // TODO: not clear how we should handle this
            throw new BindingException(Messages.UNSUPPORTED_TYPE.format(getTypeString(t)));
        }

        ITypeDecl declt = t.queryInterface(ITypeDecl.class);
        if(declt!=null) {
            // TODO: not clear how we should handle this
            throw new BindingException(Messages.UNSUPPORTED_TYPE.format(getTypeString(t)));
        }

        throw new BindingException(Messages.UNSUPPORTED_TYPE.format(getTypeString(t)));
    }
1184822
private static Class<?> extractGeneric(Type type) {
        if (type instanceof ParameterizedType) {
            Type[] genericTypes = ((ParameterizedType) type).getActualTypeArguments();
            if (genericTypes.length > 0 && genericTypes[0] instanceof Class) {
                return (Class<?>) genericTypes[0];
            }
        }
        return Object.class;
    }