This method gets the declaration-index of the given {@code typeVariable}.

@param typeVariable is the {@link TypeVariable}.
@return the index of the given {@code typeVariable} in its {@link TypeVariable#getGenericDeclaration()
declaration} .
546863
protected int getDeclarationIndex(TypeVariable<?> typeVariable) {

    GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
    TypeVariable<?>[] variables = genericDeclaration.getTypeParameters();
    for (int variableIndex = 0; variableIndex < variables.length; variableIndex++) {
      if (variables[variableIndex] == typeVariable) {
        return variableIndex;
      }
    }
    return -1;
  }
1124729
Type resolveTypeVariables(final Type type) {
        if (type instanceof Class<?>) {
            // Arrays and non-generic classes have no type variables
            return type;

        } else if (type instanceof ParameterizedType) {
            // Recursively resolve parameterized types
            final ParameterizedType parameterizedType = (ParameterizedType) type;
            final Type[] typeArgs = parameterizedType.getActualTypeArguments();
            Type[] typeArgsResolved = null;
            for (int i = 0; i < typeArgs.length; i++) {
                // Recursively revolve each parameter of the type
                final Type typeArgResolved = resolveTypeVariables(typeArgs[i]);
                // Only compare typeArgs to typeArgResolved until the first difference is found
                if (typeArgsResolved == null) {
                    if (!typeArgResolved.equals(typeArgs[i])) {
                        // After the first difference is found, lazily allocate typeArgsResolved 
                        typeArgsResolved = new Type[typeArgs.length];
                        // Go back and copy all the previous args
                        System.arraycopy(typeArgs, 0, typeArgsResolved, 0, i);
                        // Insert the first different arg
                        typeArgsResolved[i] = typeArgResolved;
                    }
                } else {
                    // After the first difference is found, keep copying the resolved args into the array 
                    typeArgsResolved[i] = typeArgResolved;
                }
            }
            if (typeArgsResolved == null) {
                // There were no type parameters to resolve
                return type;
            } else {
                // Return new ParameterizedType that wraps the resolved type args
                return new ParameterizedTypeImpl((Class<?>) parameterizedType.getRawType(), typeArgsResolved,
                        parameterizedType.getOwnerType());
            }

        } else if (type instanceof TypeVariable<?>) {
            // Look up concrete type for type variable
            final TypeVariable<?> typeVariable = (TypeVariable<?>) type;
            for (int i = 0; i < typeVariables.length; i++) {
                if (typeVariables[i].getName().equals(typeVariable.getName())) {
                    return resolvedTypeArguments[i];
                }
            }
            // Could not resolve type variable
            return type;

        } else if (type instanceof GenericArrayType) {
            // Count the array dimensions, and resolve the innermost type of the array
            int numArrayDims = 0;
            Type t = type;
            while (t instanceof GenericArrayType) {
                numArrayDims++;
                t = ((GenericArrayType) t).getGenericComponentType();
            }
            final Type innermostType = t;
            final Type innermostTypeResolved = resolveTypeVariables(innermostType);
            if (!(innermostTypeResolved instanceof Class<?>)) {
                throw new IllegalArgumentException("Could not resolve generic array type " + type);
            }
            final Class<?> innermostTypeResolvedClass = (Class<?>) innermostTypeResolved;

            // Build an array to hold the size of each dimension, filled with zeroes
            final int[] dims = (int[]) Array.newInstance(int.class, numArrayDims);

            // Build a zero-sized array of the required number of dimensions, using the resolved innermost class 
            final Object arrayInstance = Array.newInstance(innermostTypeResolvedClass, dims);

            // Get the class of this array instance -- this is the resolved array type
            return arrayInstance.getClass();

        } else if (type instanceof WildcardType) {
            // TODO: Support WildcardType
            throw ClassGraphException.newClassGraphException("WildcardType not yet supported: " + type);

        } else {
            throw ClassGraphException.newClassGraphException("Got unexpected type: " + type);
        }
    }
1050496
public static TypeVariableName get(String name, TypeName... bounds) {
    return TypeVariableName.of(name, Arrays.asList(bounds));
  }
175858
public int getOrCreateVarIndex(final Variable var) {
        Integer index = this.name2idx.get(var.name());
        if (index == null) {
            index = this.name2idx.size() + 1;
            this.name2idx.put(var.name(), index);
            this.idx2name.put(index, var.name());
        }
        return index;
    }
1106385
public static List<? extends Element> getEnclosedElementsDeclarationOrder(TypeElement type) {
        List<? extends Element> result = null;
        try {
            Object binding = field(type, "_binding");

            Class<?> sourceTypeBinding = null;
            {
                Class<?> c = binding.getClass();
                do {
                    if (c.getCanonicalName().equals(
                            "org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding")) {
                        sourceTypeBinding = c;
                        break;
                    }
                } while ((c = c.getSuperclass()) != null);
            }

            final List<Object> declarationOrder;
            if (sourceTypeBinding != null) {
                declarationOrder = findSourceOrder(binding);

                List<Element> enclosedElements = new ArrayList<Element>(type.getEnclosedElements());
                Collections.sort(enclosedElements, new Comparator<Element>() {

                    public int compare(Element o1, Element o2) {
                        try {
                            Object o1Binding = field(o1, "_binding");
                            Object o2Binding = field(o2, "_binding");

                            int i1 = declarationOrder.indexOf(o1Binding);
                            int i2 = declarationOrder.indexOf(o2Binding);

                            return i1 - i2;
                        } catch (Exception e) {
                            return 0;
                        }
                    }

                });
                result = enclosedElements;
            }
        } catch (Exception e) {
            // ignore
        }
        return (result != null) ? result : type.getEnclosedElements();
    }
548581
public String typeName() {
        return (type instanceof ClassDoc || type instanceof TypeVariable)
                ? type.typeName()       // omit formal type params or bounds
                : type.toString();
    }
1057612
protected Type[] getUppermostTypeVariableBounds(TypeVariable<?> bound) {
        if (bound.getBounds()[0] instanceof TypeVariable<?>) {
            return getUppermostTypeVariableBounds((TypeVariable<?>) bound.getBounds()[0]);
        }
        return bound.getBounds();
    }
1155727
public GenericUtilities.TypeCategory getTypeCategory() {
        if (hasParameters() && variable == null && extension == null) {
            return GenericUtilities.TypeCategory.PARAMETERIZED;

        } else if (!hasParameters() && variable != null && extension == null) {
            if ("*".equals(variable)) {
                return GenericUtilities.TypeCategory.WILDCARD;
            } else {
                return GenericUtilities.TypeCategory.TYPE_VARIABLE;
            }

        } else if (!hasParameters() && variable != null && extension != null) {
            if ("+".equals(variable)) {
                return GenericUtilities.TypeCategory.WILDCARD_EXTENDS;
            } else if ("-".equals(variable)) {
                return GenericUtilities.TypeCategory.WILDCARD_SUPER;
            }

        }
        // this should never happen
        throw new IllegalStateException("The Generic Object Type is badly initialized");
    }
1254590
public TypeDefinition getType(String typeId) {

        refresh();
        TypeDefinitionContainer tc = m_types.get(typeId);
        if (tc == null) {
            return null;
        }

        return tc.getTypeDefinition();
    }
509588
protected static JRDesignExpression getExpressionFromVariable(JRDesignVariable var){
		JRDesignExpression exp = new JRDesignExpression();
		exp.setText("$V{" + var.getName() + "}");
		exp.setValueClass(var.getValueClass());
		return exp;
	}
375401
public String getVariableQualifiedName(VariableElement var) {
    String shortName = getVariableShortName(var);
    if (ElementUtil.isGlobalVar(var)) {
      String className = getFullName(ElementUtil.getDeclaringClass(var));
      if (ElementUtil.isEnumConstant(var)) {
        // Enums are declared in an array, so we use a macro to shorten the
        // array access expression.
        return "JreEnum(" + className + ", " + shortName + ")";
      }
      return className + '_' + shortName;
    }
    return shortName;
  }
1081397
private int getLocalVariableIndex(int i) {
        int index = classMethod.isStatic() ? 0 : 1;
        for (String type : classMethod.getParameters()) {
            if (type.equals(DOUBLE_CLASS_DESCRIPTOR) || type.equals(LONG_CLASS_DESCRIPTOR)) {
                index += 2;
            } else {
                index++;
            }
        }
        return index + i;
    }
777514
public static SymbolType typeVariableOf(final String typeVariable, List<SymbolType> upperBounds) {
        return new SymbolType(upperBounds, typeVariable);
    }
769940
@SuppressWarnings("unchecked")
    public Map<String, Declaration> getDeclarations() {
        if ( this.dirty || (this.declarations == null) ) {
            this.declarations = this.getExtendedLhs( this, null ).getOuterDeclarations();
            this.dirty = false;
        }
        return this.declarations;
    }
33539
static Type extractBoundForTypeVariable(TypeVariable typeVariable) {
		Type[] bounds = typeVariable.getBounds();
		if (bounds.length == 0) {
			return Object.class;
		}
		Type bound = bounds[0];
		if (bound instanceof TypeVariable) {
			bound = extractBoundForTypeVariable((TypeVariable) bound);
		}
		return bound;
	}
661306
public TypeName resolve(TypeName inputType) {
		if (!hasTypeVariables())
			return inputType;
		
		if (inputType.isPrimitive() || inputType.isBoxedPrimitive() || inputType.equals(TypeName.get(String.class))) {
			return inputType;
		}
		
		if (TypeName.VOID.equals(inputType)) return inputType;
		
		TypeName resolved=null;
		if (inputType instanceof ParameterizedTypeName)
		{
			ParameterizedTypeName inputParametrizedTypeName=(ParameterizedTypeName)inputType;
			
			TypeName[] typeArguments=new TypeName[inputParametrizedTypeName.typeArguments.size()];
			int i=0;
			for (TypeName item: inputParametrizedTypeName.typeArguments)
			{
				typeArguments[i]=resolve(item);
				i++;
			}
			
			resolved=ParameterizedTypeName.get((ClassName)resolve(inputParametrizedTypeName.rawType), typeArguments);
			
			return resolved;
		} else if (inputType instanceof ArrayTypeName)
		{
			ArrayTypeName inputTypeName=(ArrayTypeName)inputType;
			
			resolved=ArrayTypeName.of(resolve(inputTypeName.componentType));
			
			return resolved;
		} else {
			// it's not a type variable
			if (inputType.toString().contains(".")) {
				return inputType;
			}
			// ASSERT: simple typeName 
			if (typeVariableMap.containsKey(inputType.toString())) {
				TypeName type = typeVariableMap.get(inputType.toString());
				return type;
			} else if (declaredTypeArgumentList.size()==1){
				resolved = declaredTypeArgumentList.get(0);
				// if we found an unique type variable, we use it.
				//typeVariableMap = new HashMap<>();
				//typeVariableMap.put(inputTypeName.toString(), resolved);

				return resolved;
			}
			
			AssertKripton.assertTrue(false, "In type hierarchy of %s '%s' there is a unresolved type variable named '%s'. Define it with @BindTypeVariables", element.getKind()==ElementKind.CLASS ? "class" :"interface", element.getQualifiedName(),
					inputType.toString());
			
			return resolved;
		}
		
	}
208744
Type findTypeVar(Name name) {
        Symbol s = typevars.findFirst(name);
        if (s != null) {
            return s.type;
        } else {
            if (readingClassAttr) {
                // While reading the class attribute, the supertypes
                // might refer to a type variable from an enclosing element
                // (method or class).
                // If the type variable is defined in the enclosing class,
                // we can actually find it in
                // currentOwner.owner.type.getTypeArguments()
                // However, until we have read the enclosing method attribute
                // we don't know for sure if this owner is correct.  It could
                // be a method and there is no way to tell before reading the
                // enclosing method attribute.
                TypeVar t = new TypeVar(name, currentOwner, syms.botType);
                missingTypeVariables = missingTypeVariables.prepend(t);
                // System.err.println("Missing type var " + name);
                return t;
            }
            throw badClassFile("undecl.type.var", name);
        }
    }