If the type is not accessible from current context, try to figure out the
sharpest accessible supertype.

@param originalType type to sharpen
@return sharped type
358286
Type sharpestAccessible(Type originalType) {
        if (originalType.hasTag(ARRAY)) {
            return types.makeArrayType(sharpestAccessible(types.elemtype(originalType)));
        }

        Type type = originalType;
        while (!rs.isAccessible(gen.getAttrEnv(), type.asElement())) {
            type = types.supertype(type);
        }
        return type;
    }
1009318
@SuppressWarnings("serial")
    public static Type forGenericSuperclass(final Class<?> type) {
        return forTypeProvider(new DefaultTypeProvider() {
            @Override
            public Type getType() {
                return type.getGenericSuperclass();
            }
        });
    }
118256
private Node tryFoldTypeof(Node originalTypeofNode) {
    checkArgument(originalTypeofNode.isTypeOf());

    Node argumentNode = originalTypeofNode.getFirstChild();
    if (argumentNode == null || !NodeUtil.isLiteralValue(argumentNode, true)) {
      return originalTypeofNode;
    }

    String typeNameString = null;

    switch (argumentNode.getToken()) {
      case FUNCTION:
        typeNameString = "function";
        break;
      case STRING:
        typeNameString = "string";
        break;
      case NUMBER:
        typeNameString = "number";
        break;
      case TRUE:
      case FALSE:
        typeNameString = "boolean";
        break;
      case NULL:
      case OBJECTLIT:
      case ARRAYLIT:
        typeNameString = "object";
        break;
      case VOID:
        typeNameString = "undefined";
        break;
      case NAME:
        // We assume here that programs don't change the value of the
        // keyword undefined to something other than the value undefined.
        if ("undefined".equals(argumentNode.getString())) {
          typeNameString = "undefined";
        }
        break;
      default:
        break;
    }

    if (typeNameString != null) {
      Node newNode = IR.string(typeNameString);
      reportChangeToEnclosingScope(originalTypeofNode);
      originalTypeofNode.replaceWith(newNode);
      markFunctionsDeleted(originalTypeofNode);

      return newNode;
    }

    return originalTypeofNode;
  }
953489
public static JCGLScalarType scalarTypeFromGL(
    final int type)
  {
    switch (type) {
      case GL.GL_HALF_FLOAT:
        return JCGLScalarType.TYPE_HALF_FLOAT;
      case GL.GL_BYTE:
        return JCGLScalarType.TYPE_BYTE;
      case GL.GL_UNSIGNED_BYTE:
        return JCGLScalarType.TYPE_UNSIGNED_BYTE;
      case GL.GL_SHORT:
        return JCGLScalarType.TYPE_SHORT;
      case GL.GL_UNSIGNED_SHORT:
        return JCGLScalarType.TYPE_UNSIGNED_SHORT;
      case GL2ES2.GL_INT:
        return JCGLScalarType.TYPE_INT;
      case GL.GL_UNSIGNED_INT:
        return JCGLScalarType.TYPE_UNSIGNED_INT;
      case GL.GL_FLOAT:
        return JCGLScalarType.TYPE_FLOAT;
      default:
        throw new UnreachableCodeException();
    }
  }
1050631
public void loadDefault(TypeMirror type) throws IOException
    {
        if (type.getKind() != TypeKind.VOID)
        {
            if (Typ.isPrimitive(type))
            {
                tconst(type, 0);
            }
            else
            {
                aconst_null();
            }
        }
    }
65542
public static TypeConverter converterForType(Class type)
    {
        for (TypeConverter converter : converters)
        {
            if (converter.canConvertTo( type )) return converter;
        }

        return null;
    }
1124505
@Requires("type != null")
  @Ensures("result == null || result.getDeclaredName().equals(type.toString())")
  TypeName getTypeNameForType(TypeMirror type) {
    switch (type.getKind()) {
      case NONE:
        return null;
      default:
        return new TypeName(type.toString());
    }
  }
726615
@SuppressWarnings("unchecked")
	public <T> Converter<T> getDefaultConverter(Type type) {
		return (null == defaultConverterMap) ? null : (Converter<T>) defaultConverterMap.get(type);
	}
872585
@SuppressWarnings("unchecked")
	public <T> Converter<T> getCustomConverter(Type type) {
		return (null == customConverterMap) ? null : (Converter<T>) customConverterMap.get(type);
	}
1055810
public JvmTypeReference inferredType() {
		XComputedTypeReference result = xtypesFactory.createXComputedTypeReference();
		result.setTypeProvider(new InferredTypeIndicator(null));
		return result;
	}
899853
public static Class<?> getRawType(Type type) {
		if (type instanceof Class<?>) {
			// type is a normal class.
			return (Class<?>) type;

		} else if (type instanceof ParameterizedType) {
			ParameterizedType parameterizedType = (ParameterizedType) type;

			// I'm not exactly sure why getRawType() returns Type instead of Class.
			// Neal isn't either but suspects some pathological case related
			// to nested classes exists.
			Type rawType = parameterizedType.getRawType();
			if (!(rawType instanceof Class)) {
				String message = MessageFormat.format("Expected a Class, but <{0}> is of type {1}", type, type.getClass()
						.getName());
				throw new IllegalArgumentException(message);
			}
			return (Class<?>) rawType;

		} else if (type instanceof GenericArrayType) {
			Type componentType = ((GenericArrayType) type).getGenericComponentType();
			return Array.newInstance(getRawType(componentType), 0).getClass();

		} else if (type instanceof TypeVariable) {
			// we could use the variable's bounds, but that'll won't work if there are multiple.
			// having a raw type that's more general than necessary is okay  
			return Object.class;

		} else {
			throw new IllegalArgumentException("Expected a Class, ParameterizedType, or " + "GenericArrayType, but <"
					+ type + "> is of type " + type.getClass().getName());
		}
	}
1052710
protected synchronized HierarchicalType getDataType(String type) {
        HierarchicalType dataType = typeInstances.get(type);
        //todo: are there still cases where type can be null?
        if (dataType == null) {
            dataType = createDataType(type);
            typeInstances.put(type, dataType);
        }
        return dataType;
    }
581798
private final Type getGenericType() {
        final Class<?> raw = getClass();
        final TypeVariable<?>[] typeParameters = raw.getTypeParameters();
        if (ArrayUtils.isEmpty(typeParameters)) {
            return raw;
        }
        final Type[] parameters = new Type[typeParameters.length];

        // use empty type variable map because we're relying on @BindTypeVariable functionality:
        final Map<TypeVariable<?>, Type> typeVariableMap = Collections.emptyMap();
        for (int i = 0; i < parameters.length; i++) {
            parameters[i] = Types.resolveAt(this, typeParameters[i], typeVariableMap);
        }
        return TypeUtils.parameterize(raw, parameters);
    }
607670
public <T extends Mapping> T getMapping(MappingType type)
    {
        return (T) mappings.get(type);
    }
1179251
public static <I extends ImageGray<I>, II extends ImageGray<II>>
	Class<II> getIntegralType( Class<I> inputType ) {
		if( inputType == GrayF32.class ) {
			return (Class<II>)GrayF32.class;
		} else if( inputType == GrayU8.class ){
			return (Class<II>)GrayS32.class;
		} else if( inputType == GrayS32.class ){
			return (Class<II>)GrayS32.class;
		} else {
			throw new IllegalArgumentException("Unknown input image type: "+inputType.getSimpleName());
		}
	}
379002
public static String getPrimitiveObjCType(TypeMirror type) {
    return TypeUtil.isVoid(type) ? "void"
        : type.getKind().isPrimitive() ? "j" + TypeUtil.getName(type) : "id";
  }
472533
public static Class getPrimitiveType(Class wrapperType) {
        Class<?> wrapper = WRAPPER_TO_PRIMITIVE.get(wrapperType);
        if (wrapper != null) {
            return wrapper;
        }
        return wrapperType;
    }