Unnamed: 0
int64 0
305k
| body
stringlengths 7
52.9k
| name
stringlengths 1
185
|
|---|---|---|
16,600
|
void (final Node n) { if (!myNeighbours.contains(n)) { myNeighbours.add(n); n.addEdge(this); } }
|
addEdge
|
16,601
|
void (final PsiType t) { if (t instanceof PsiTypeVariable) { boundVars.add((PsiTypeVariable)t); } else if (t instanceof PsiArrayType) { visit(t.getDeepComponentType()); } else if (t instanceof PsiClassType) { final PsiSubstitutor subst = Util.resolveType(t).getSubstitutor(); for (final PsiType type : subst.getSubstitutionMap().values()) { visit(type); } } else if (t instanceof PsiIntersectionType) { final PsiType[] conjuncts = ((PsiIntersectionType)t).getConjuncts(); for (PsiType conjunct : conjuncts) { visit(conjunct); } } else if (t instanceof PsiWildcardType) { final PsiType bound = ((PsiWildcardType)t).getBound(); if (bound != null) { visit(bound); } } }
|
visit
|
16,602
|
void (final Constraint constraint, final Set<PsiTypeVariable> vars) { if (myBoundVariables == null) { myBoundVariables = vars; } else { myBoundVariables.addAll(vars); } myConstraints.add(constraint); }
|
addConstraint
|
16,603
|
PsiTypeVariableFactory () { return myTypeVariableFactory; }
|
getVariableFactory
|
16,604
|
Set<PsiTypeVariable> () { return myBoundVariables; }
|
getBoundVariables
|
16,605
|
String (final Binding bestBinding) { final @NonNls String[] data = new String[myElements.size()]; class Substitutor { PsiType substitute(final PsiType t) { if (t instanceof PsiWildcardType wcType) { final PsiType bound = wcType.getBound(); if (bound == null) { return t; } final PsiManager manager = PsiManager.getInstance(myProject); final PsiType subst = substitute(bound); return subst == null || subst instanceof PsiWildcardType ? subst : wcType.isExtends() ? PsiWildcardType.createExtends(manager, subst) : PsiWildcardType.createSuper(manager, subst); } else if (t instanceof PsiTypeVariable) { if (bestBinding != null) { final PsiType b = bestBinding.apply(t); if (b instanceof Bottom || b instanceof PsiTypeVariable) { return null; } return substitute(b); } return null; } else if (t instanceof Bottom) { return null; } else if (t instanceof PsiArrayType) { return substitute(((PsiArrayType)t).getComponentType()).createArrayType(); } else if (t instanceof PsiClassType) { final PsiClassType.ClassResolveResult result = ((PsiClassType)t).resolveGenerics(); final PsiClass aClass = result.getElement(); final PsiSubstitutor aSubst = result.getSubstitutor(); if (aClass == null) { return t; } PsiSubstitutor theSubst = PsiSubstitutor.EMPTY; for (final PsiTypeParameter parm : aSubst.getSubstitutionMap().keySet()) { final PsiType type = aSubst.substitute(parm); theSubst = theSubst.put(parm, substitute(type)); } return JavaPsiFacade.getElementFactory(aClass.getProject()).createType(aClass, theSubst); } else { return t; } } } final Substitutor binding = new Substitutor(); int i = 0; for (final PsiElement element : myElements) { final PsiType t = myTypes.get(element); if (t != null) { data[i++] = binding.substitute(t).getCanonicalText() + "\\n" + elementString(element); } else { data[i++] = "\\n" + elementString(element); } } return StreamEx.of(data).sorted().map(aData -> aData + "\n").joining(); }
|
dumpResult
|
16,606
|
Settings () { return mySettings; }
|
getSettings
|
16,607
|
Set<PsiElement> (final PsiElement[] scopes) { return new VictimCollector(scopes, mySettings).getVictims(); }
|
collect
|
16,608
|
boolean (final PsiElement element, final Set<PsiElement> victims, final PsiSearchHelper helper) { PsiMethod method; PsiParameter parameter = null; int index = 0; if (element instanceof PsiMethod) { method = (PsiMethod)element; } else if (element instanceof PsiParameter) { parameter = (PsiParameter)element; method = (PsiMethod)parameter.getDeclarationScope(); index = method.getParameterList().getParameterIndex(parameter); } else { LOG.error("Parameter or method expected, but found " + (element == null ? "null" : element.getClass().getName())); return false; } final PsiMethod superMethod = method.findDeepestSuperMethod(); PsiMethod keyMethod; PsiParameter keyParameter = null; if (superMethod != null) { Boolean good = myMethodCache.get(superMethod); if (good != null && !good.booleanValue()) { return false; } final PsiElement e = parameter == null ? superMethod : superMethod.getParameterList().getParameters()[index]; if (!victims.contains(e)) { myMethodCache.put(superMethod, Boolean.FALSE); return false; } keyMethod = superMethod; myMethods.put(method, keyMethod); if (parameter != null) { keyParameter = (PsiParameter)e; } } else { Boolean good = myMethodCache.get(method); if (good != null && good.booleanValue()) { myMethods.putIfAbsent(method, method); if (parameter != null && myParameters.get(parameter) == null) { myParameters.put(parameter, parameter); } return true; } keyMethod = method; keyParameter = parameter; } final PsiMethod[] overriders = OverridingMethodsSearch.search(keyMethod).toArray(PsiMethod.EMPTY_ARRAY); for (final PsiMethod overrider : overriders) { final PsiElement e = parameter != null ? overrider.getParameterList().getParameters()[index] : overrider; if (!victims.contains(e)) { myMethodCache.put(keyMethod, Boolean.FALSE); return false; } } for (final PsiMethod overrider : overriders) { final PsiElement e = parameter != null ? overrider.getParameterList().getParameters()[index] : overrider; myMethods.put(overrider, keyMethod); if (parameter != null) { myParameters.put((PsiParameter)e, keyParameter); } } myMethods.put(method, keyMethod); if (parameter != null) { myParameters.put(parameter, keyParameter); } myMethodCache.put(keyMethod, Boolean.TRUE); return true; }
|
verifyMethod
|
16,609
|
void (final PsiElement e, final PsiType t) { myTypes.put(e, t); }
|
setType
|
16,610
|
PsiType (final PsiElement e) { PsiType t = myTypes.get(e); if (t != null) { return t; } t = Util.getType(e); final PsiType parameterizedType = Util.createParameterizedType(t, myTypeVariableFactory, e); myTypes.put(e, parameterizedType); return parameterizedType; }
|
defineType
|
16,611
|
PsiType (final PsiElement e) { final PsiType t = myTypes.get(e); if (t != null) { return t; } return Util.banalize(Util.getType(e)); }
|
getType
|
16,612
|
boolean (final PsiElement element) { return myTypes.get(element) != null; }
|
isCooked
|
16,613
|
PsiType (final PsiTypeParameter typeParameter, final PsiParameter[] parameters, PsiExpression[] arguments, PsiSubstitutor partialSubstitutor, PsiElement parent, ReductionSystem system) { PsiType substitution = PsiTypes.nullType(); PsiResolveHelper helper = JavaPsiFacade.getInstance(typeParameter.getProject()).getResolveHelper(); if (parameters.length > 0) { for (int j = 0; j < arguments.length; j++) { PsiExpression argument = arguments[j]; final PsiParameter parameter = parameters[Math.min(j, parameters.length - 1)]; if (j >= parameters.length && !parameter.isVarArgs()) break; PsiType parameterType = parameter.getType(); PsiType argumentType = evaluateType(argument, system); if (parameterType instanceof PsiEllipsisType) { parameterType = ((PsiEllipsisType)parameterType).getComponentType(); if (arguments.length == parameters.length && argumentType instanceof PsiArrayType && !(((PsiArrayType)argumentType).getComponentType() instanceof PsiPrimitiveType)) { argumentType = ((PsiArrayType)argumentType).getComponentType(); } } final PsiType currentSubstitution = helper.getSubstitutionForTypeParameter(typeParameter, parameterType, argumentType, true, PsiUtil.getLanguageLevel(parent)); if (currentSubstitution == null) { substitution = null; break; } else if (currentSubstitution instanceof PsiWildcardType) { if (substitution instanceof PsiWildcardType) return PsiTypes.nullType(); } else if (PsiTypes.nullType().equals(currentSubstitution)) continue; if (PsiTypes.nullType().equals(substitution)) { substitution = currentSubstitution; continue; } if (!substitution.equals(currentSubstitution)) { if (substitution instanceof PsiTypeVariable || currentSubstitution instanceof PsiTypeVariable) { substitution = GenericsUtil.getLeastUpperBound(substitution, currentSubstitution, typeParameter.getManager()); if (substitution == null) break; } } } } if (PsiTypes.nullType().equals(substitution)) { substitution = inferMethodTypeParameterFromParent(typeParameter, partialSubstitutor, parent, system); } return substitution; }
|
inferTypeForMethodTypeParameter
|
16,614
|
PsiType (final PsiTypeParameter typeParameter, PsiSubstitutor substitutor, PsiElement parent, ReductionSystem system) { PsiTypeParameterListOwner owner = typeParameter.getOwner(); PsiType substitution = PsiTypes.nullType(); if (owner instanceof PsiMethod && parent instanceof PsiMethodCallExpression methodCall) { substitution = inferMethodTypeParameterFromParent(methodCall.getParent(), methodCall, typeParameter, substitutor, system); } return substitution; }
|
inferMethodTypeParameterFromParent
|
16,615
|
PsiType (PsiElement parent, PsiMethodCallExpression methodCall, final PsiTypeParameter typeParameter, PsiSubstitutor substitutor, ReductionSystem system) { PsiType type = null; if (parent instanceof PsiVariable && methodCall.equals(((PsiVariable)parent).getInitializer())) { type = getType(parent); } else if (parent instanceof PsiAssignmentExpression && methodCall.equals(((PsiAssignmentExpression)parent).getRExpression())) { type = evaluateType(((PsiAssignmentExpression)parent).getLExpression(), system); } else if (parent instanceof PsiTypeCastExpression && methodCall.equals(((PsiTypeCastExpression)parent).getOperand())) { type = evaluateType((PsiExpression)parent, system); } else if (parent instanceof PsiReturnStatement) { PsiMethod method = PsiTreeUtil.getParentOfType(parent, PsiMethod.class); if (method != null) { type = getType(method); } } if (type == null) { type = PsiType.getJavaLangObject(methodCall.getManager(), methodCall.getResolveScope()); } PsiType returnType = ((PsiMethod)typeParameter.getOwner()).getReturnType(); PsiType guess = JavaPsiFacade.getInstance(parent.getProject()).getResolveHelper() .getSubstitutionForTypeParameter(typeParameter, returnType, type, false, PsiUtil.getLanguageLevel(parent)); if (PsiTypes.nullType().equals(guess)) { PsiType superType = substitutor.substitute(typeParameter.getSuperTypes()[0]); return superType == null ? PsiType.getJavaLangObject(methodCall.getManager(), methodCall.getResolveScope()) : superType; } //The following code is the result of deep thought, do not shit it out before discussing with [ven] if (returnType instanceof PsiClassType && typeParameter.equals(((PsiClassType)returnType).resolve())) { PsiClassType[] extendsTypes = typeParameter.getExtendsListTypes(); PsiSubstitutor newSubstitutor = substitutor.put(typeParameter, guess); for (PsiClassType t : extendsTypes) { PsiType extendsType = newSubstitutor.substitute(t); if (!extendsType.isAssignableFrom(guess)) { if (guess.isAssignableFrom(extendsType)) { guess = extendsType; newSubstitutor = substitutor.put(typeParameter, guess); } else { break; } } } } return guess; }
|
inferMethodTypeParameterFromParent
|
16,616
|
PsiType (final PsiType ext) { final PsiClassType.ClassResolveResult result = Util.resolveType(ext); final PsiClass aClass = result.getElement(); if (aClass != null) { if (aClass instanceof PsiTypeParameter) { final PsiType type = mapping.get(aClass); if (type != null) { return type; } return ext; } final PsiSubstitutor aSubst = result.getSubstitutor(); PsiSubstitutor theSubst = PsiSubstitutor.EMPTY; for (final PsiTypeParameter param : aSubst.getSubstitutionMap().keySet()) { PsiType type = aSubst.substitute(param); if (type != null) { if (type instanceof PsiWildcardType wildcard) { final PsiType bound = wildcard.getBound(); if (bound != null) { final PsiManager manager = param.getManager(); type = wildcard.isExtends() ? PsiWildcardType.createExtends(manager, substitute(bound)) : PsiWildcardType.createSuper(manager, substitute(bound)); } } else { type = substitute(type); } } theSubst = theSubst.put(param, type); } return JavaPsiFacade.getElementFactory(aClass.getProject()) .createType(aClass, theSubst); } return ext; }
|
substitute
|
16,617
|
void (final ReductionSystem system, final PsiElement element) { if (element instanceof PsiVariable) { final PsiExpression initializer = ((PsiVariable)element).getInitializer(); if (initializer != null) { final PsiExpression core = PsiUtil.deparenthesizeExpression(initializer); if (core instanceof PsiArrayInitializerExpression) { final PsiExpression[] inits = ((PsiArrayInitializerExpression)core).getInitializers(); final PsiType type = getType(element); for (PsiExpression init : inits) { system.addSubtypeConstraint(evaluateType(init, system).createArrayType(), type); } } else if (core instanceof PsiNewExpression) { final PsiArrayInitializerExpression init = ((PsiNewExpression)core).getArrayInitializer(); if (init != null) { final PsiExpression[] inits = init.getInitializers(); final PsiType type = getType(element); for (PsiExpression init1 : inits) { system.addSubtypeConstraint(evaluateType(init1, system).createArrayType(), type); } } system.addSubtypeConstraint(evaluateType(core, system), getType(element)); } else { system.addSubtypeConstraint(evaluateType(core, system), getType(element)); } } if (element instanceof PsiParameter parameter) { final PsiElement declarationScope = parameter.getDeclarationScope(); if (declarationScope instanceof PsiMethod method) { final PsiSearchHelper helper = PsiSearchHelper.getInstance(myManager.getProject()); SearchScope scope = getScope(helper, method); for (PsiReference ref : ReferencesSearch.search(method, scope, true)) { final PsiElement elt = ref.getElement(); final PsiCallExpression call = PsiTreeUtil.getParentOfType(elt, PsiCallExpression.class); if (call != null) { PsiExpressionList argList = call.getArgumentList(); if (argList != null) { PsiExpression[] args = argList.getExpressions(); int index = method.getParameterList().getParameterIndex(parameter); if (index < args.length) { system.addSubtypeConstraint(evaluateType(args[index], system), myTypes.get(element)); } } } } } else if (declarationScope instanceof PsiForeachStatement) { addForEachConstraint(system, (PsiForeachStatement)declarationScope); } } return; } else if (element instanceof PsiMethod) { final PsiType reType = getType(element); element.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReturnStatement(final @NotNull PsiReturnStatement statement) { super.visitReturnStatement(statement); final PsiExpression retExpr = statement.getReturnValue(); if (retExpr != null) { system.addSubtypeConstraint(evaluateType(retExpr, system), reType); } } @Override public void visitClass(@NotNull PsiClass aClass) {} @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) {} }); return; } final PsiElement root = PsiTreeUtil.getParentOfType(element, PsiStatement.class, PsiField.class); if (root != null) { final PsiAnchor anchor = PsiAnchor.create(root); if (!myVisitedConstructions.contains(anchor)) { //return from lambda is processed inside visitReturnStatement //noinspection UnsafeReturnStatementVisitor root.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitAssignmentExpression(final @NotNull PsiAssignmentExpression expression) { super.visitAssignmentExpression(expression); system .addSubtypeConstraint(evaluateType(expression.getRExpression(), system), evaluateType(expression.getLExpression(), system)); } @Override public void visitConditionalExpression(final @NotNull PsiConditionalExpression expression) { super.visitConditionalExpression(expression); system.addSubtypeConstraint(evaluateType(expression.getThenExpression(), system), evaluateType(expression.getElseExpression(), system)); system.addSubtypeConstraint(evaluateType(expression.getElseExpression(), system), evaluateType(expression.getThenExpression(), system)); } @Override public void visitCallExpression(final @NotNull PsiCallExpression expression) { super.visitCallExpression(expression); evaluateType(expression, system); } @Override public void visitReturnStatement(final @NotNull PsiReturnStatement statement) { super.visitReturnStatement(statement); final PsiMethod method = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, true, PsiLambdaExpression.class); if (method != null) { system.addSubtypeConstraint(evaluateType(statement.getReturnValue(), system), getType(method)); } } @Override public void visitTypeCastExpression(final @NotNull PsiTypeCastExpression expression) { super.visitTypeCastExpression(expression); final PsiType operandType = evaluateType(expression.getOperand(), system); final PsiType castType = evaluateType(expression, system); if (operandType == null || castType == null) return; if (Util.bindsTypeVariables(operandType)) { system.addCast(expression, operandType); } if (operandType.getDeepComponentType() instanceof PsiTypeVariable || castType.getDeepComponentType() instanceof PsiTypeVariable) { system.addSubtypeConstraint(operandType, castType); } else { final PsiClassType.ClassResolveResult operandResult = Util.resolveType(operandType); final PsiClassType.ClassResolveResult castResult = Util.resolveType(castType); final PsiClass operandClass = operandResult.getElement(); final PsiClass castClass = castResult.getElement(); if (operandClass != null && castClass != null) { if (InheritanceUtil.isInheritorOrSelf(operandClass, castClass, true)) { system.addSubtypeConstraint(operandType, castType); } } } } @Override public void visitVariable(final @NotNull PsiVariable variable) { super.visitVariable(variable); final PsiExpression init = variable.getInitializer(); if (init != null) { system.addSubtypeConstraint(evaluateType(init, system), getType(variable)); } } @Override public void visitNewExpression(final @NotNull PsiNewExpression expression) { super.visitNewExpression(expression); final PsiArrayInitializerExpression init = expression.getArrayInitializer(); if (init != null) { final PsiExpression[] inits = init.getInitializers(); final PsiType type = getType(expression); for (PsiExpression init1 : inits) { system.addSubtypeConstraint(evaluateType(init1, system).createArrayType(), type); } } } @Override public void visitReferenceExpression(final @NotNull PsiReferenceExpression expression) { final PsiExpression qualifierExpression = expression.getQualifierExpression(); if (qualifierExpression != null) { qualifierExpression.accept(this); } } }); myVisitedConstructions.add(anchor); } } }
|
addUsage
|
16,618
|
void (@NotNull PsiClass aClass) {}
|
visitClass
|
16,619
|
void (@NotNull PsiLambdaExpression expression) {}
|
visitLambdaExpression
|
16,620
|
SearchScope (final PsiSearchHelper helper, final PsiElement element) { SearchScope scope = helper.getUseScope(element); if (scope instanceof GlobalSearchScope) { scope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope)scope, JavaFileType.INSTANCE, StdFileTypes.JSP, StdFileTypes.JSPX); } return scope; }
|
getScope
|
16,621
|
void (final PsiType defined, final PsiType type, final ReductionSystem system) { final PsiClassType.ClassResolveResult resultDefined = Util.resolveType(defined); final PsiClassType.ClassResolveResult resultType = Util.resolveType(type); final PsiClass definedClass = resultDefined.getElement(); if (definedClass == null || !definedClass.equals(resultType.getElement())) { return; } final PsiSubstitutor definedSubst = resultDefined.getSubstitutor(); final PsiSubstitutor typeSubst = resultType.getSubstitutor(); for (final PsiTypeParameter parameter : definedSubst.getSubstitutionMap().keySet()) { final PsiClassType[] extendsList = parameter.getExtendsList().getReferencedTypes(); final PsiType definedType = definedSubst.substitute(parameter); if (definedType instanceof PsiTypeVariable) { for (PsiType extendsType : extendsList) { extendsType = replaceWildCards(extendsType, system, definedSubst); system.addSubtypeConstraint(definedType, Util.banalize(definedSubst.substitute(extendsType))); } } else { addBoundConstraintsImpl(definedType, typeSubst.substitute(parameter), system); } } }
|
addBoundConstraintsImpl
|
16,622
|
void (final ReductionSystem system, final PsiType definedType, final PsiElement element) { final PsiType elementType = Util.getType(element); if (elementType != null) { addBoundConstraintsImpl(definedType, elementType, system); if (mySettings.cookObjects() && elementType.getCanonicalText().equals(CommonClassNames.JAVA_LANG_OBJECT)) { system.addSubtypeConstraint(definedType, elementType); } } }
|
addBoundConstraints
|
16,623
|
ReductionSystem (final PsiElement... scopes) { return build(collect(scopes)); }
|
build
|
16,624
|
ReductionSystem (final Set<PsiElement> victims) { final PsiSearchHelper helper = PsiSearchHelper.getInstance(myManager.getProject()); ReductionSystem system = new ReductionSystem(myProject, victims, myTypes, myTypeVariableFactory, mySettings); for (final PsiElement element : victims) { if (element instanceof PsiParameter && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod || element instanceof PsiMethod) { verifyMethod(element, victims, helper); } } for (final PsiElement element : victims) { PsiType definedType; if (element instanceof PsiParameter && ((PsiParameter)element).getDeclarationScope() instanceof PsiMethod) { final PsiParameter p = myParameters.get(element); if (p != null) { setType(element, definedType = defineType(p)); } else { continue; } } else if (element instanceof PsiMethod) { final PsiMethod m = myMethods.get(element); if (m != null) { system.addSubtypeConstraint(defineType(element), definedType = defineType(m)); } else { continue; } } else { definedType = defineType(element); } addBoundConstraints(system, definedType, element); } for (final PsiElement element : victims) { if (element instanceof PsiParameter) { final PsiElement scope = ((PsiParameter)element).getDeclarationScope(); if (scope instanceof PsiMethod) { final PsiParameter p = myParameters.get(element); if (p == null) continue; } /*else if (scope instanceof PsiForeachStatement) { addForEachConstraint(system, (PsiForeachStatement)scope); }*/ else if (element instanceof PsiMethod) { final PsiMethod m = myMethods.get(element); if (m == null) continue; } } else if (element instanceof PsiMethod) { final PsiMethod m = myMethods.get(element); if (m == null) continue; } addUsage(system, element); if (!(element instanceof PsiExpression)) { for (PsiReference ref : ReferencesSearch.search(element, getScope(helper, element), true)) { addUsage(system, ref.getElement()); } } } return system; }
|
build
|
16,625
|
void (final ReductionSystem system, final PsiForeachStatement statement) { final PsiType paramType = getType(statement.getIterationParameter()); final PsiExpression value = statement.getIteratedValue(); if (value != null) { final PsiType type = evaluateType(value, system); if (type instanceof PsiClassType) { final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)type).resolveGenerics(); final PsiClass clazz = resolveResult.getElement(); if (clazz != null) { final PsiClass iterableClass = JavaPsiFacade.getInstance(clazz.getProject()).findClass("java.lang.Iterable", clazz.getResolveScope()); if (iterableClass != null) { final PsiTypeParameter[] typeParameters = iterableClass.getTypeParameters(); if (typeParameters.length == 1) { final PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(iterableClass, clazz, resolveResult.getSubstitutor()); if (substitutor != null) { final PsiType componentType = substitutor.substitute(typeParameters[0]); system.addSubtypeConstraint(componentType, paramType); } } } } } else if (type instanceof PsiArrayType) { system.addSubtypeConstraint(((PsiArrayType)type).getComponentType(), paramType); } } }
|
addForEachConstraint
|
16,626
|
void (final Binding binding) { if (myBinding == null) { myBinding = binding; } else { myBinding.merge(binding, mySettings.leaveObjectParameterizedTypesRaw()); } }
|
incorporateSolution
|
16,627
|
PsiType (final PsiElement element) { final PsiType originalType = Util.getType(element); if (myBinding != null) { final PsiType type = myBinding.substitute(myTypes.get(element)); @NonNls final String objectFQName = CommonClassNames.JAVA_LANG_OBJECT; if (originalType.getCanonicalText().equals(objectFQName)) { if (type == null) { return originalType; } if (type instanceof PsiWildcardType){ final PsiType bound = ((PsiWildcardType)type).getBound(); if (bound != null){ return bound; } return originalType; } } return type; } return originalType; }
|
getCookedType
|
16,628
|
Set<PsiElement> () { myCookedNumber = 0; final Set<PsiElement> set = new HashSet<>(); for (final PsiElement element : myVictims) { final PsiType originalType = Util.getType(element); final PsiType cookedType = getCookedType(element); if (cookedType != null && !originalType.equals(cookedType)) { set.add(element); myCookedNumber++; } } if (mySettings.dropObsoleteCasts()) { myCastsRemoved = 0; if (myBinding != null) { for (final Map.Entry<PsiTypeCastExpression,PsiType> entry : myCastToOperandType.entrySet()) { final PsiTypeCastExpression cast = entry.getKey(); final PsiType operandType = myBinding.apply(entry.getValue()); final PsiType castType = cast.getType(); if (!(operandType instanceof PsiTypeVariable) && castType != null && !isBottomArgument(operandType) && castType.isAssignableFrom(operandType)) { set.add(cast); } } } } return set; }
|
getCookedElements
|
16,629
|
boolean (final PsiType type) { final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(type); final PsiClass clazz = resolveResult.getElement(); if (clazz != null) { for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(clazz)) { final PsiType t = resolveResult.getSubstitutor().substitute(typeParameter); if (t == Bottom.BOTTOM) return true; } } return false; }
|
isBottomArgument
|
16,630
|
void (final Set<PsiElement> victims) { for (final PsiElement element : victims) { if (element instanceof PsiTypeCastExpression cast && myCastToOperandType.containsKey(element)) { try { cast.replace(cast.getOperand()); myCastsRemoved++; } catch (IncorrectOperationException e1) { LOG.error(e1); } } else { Util.changeType(element, getCookedType(element)); } } }
|
apply
|
16,631
|
String (final int x, final int y) { final String ratio = JavaRareRefactoringsBundle.message("type.cook.ratio.generified", x, y); return ratio + (y != 0 ? " (" + (x * 100 / y) + "%)" : ""); }
|
getRatio
|
16,632
|
Constraint (final Binding b) { return new Subtype(b.apply(myLeft), b.apply(myRight)); }
|
apply
|
16,633
|
PsiType () { return myRight; }
|
getRight
|
16,634
|
PsiType () { return myLeft; }
|
getLeft
|
16,635
|
String () { return myLeft.getCanonicalText() + " " + relationString() + " " + myRight.getCanonicalText(); }
|
toString
|
16,636
|
boolean (Object o) { if (this == o) return true; return o instanceof Constraint constraint && Objects.equals(myLeft, constraint.myLeft) && Objects.equals(myRight, constraint.myRight); }
|
equals
|
16,637
|
int () { int result; result = (myLeft != null ? myLeft.hashCode() : 0); result = 29 * result + (myRight != null ? myRight.hashCode() : 0); return result + relationType(); }
|
hashCode
|
16,638
|
void (final Binding b1) { for (final Binding b2 : mySolutions) { switch (b1.compare(b2)) { case Binding.WORSE, Binding.SAME -> { return; } case Binding.BETTER -> { mySolutions.remove(b2); mySolutions.addFirst(b1); return; } case Binding.NONCOMPARABLE -> { } } } mySolutions.addFirst(b1); }
|
putSolution
|
16,639
|
Binding () { Binding best = null; int width = 0; for (final Binding binding : mySolutions) { final int w = binding.getWidth(); if (w > width && binding.isValid()) { width = w; best = binding; } } return best; }
|
getBestSolution
|
16,640
|
PsiClass[] (final PsiClass aClass, final PsiClass bClass) { if (InheritanceUtil.isInheritorOrSelf(aClass, bClass, true)) { return new PsiClass[]{aClass}; } if (InheritanceUtil.isInheritorOrSelf(bClass, aClass, true)) { return new PsiClass[]{bClass}; } final Set<PsiClass> descendants = new LinkedHashSet<>(); new Object() { public void getGreatestLowerClasses(final PsiClass aClass, final PsiClass bClass, final Set<? super PsiClass> descendants) { if (bClass.hasModifierProperty(PsiModifier.FINAL)) return; if (aClass.isInheritor(bClass, true)) { descendants.add(aClass); } else { for (PsiClass bInheritor : ClassInheritorsSearch.search(bClass, false)) { getGreatestLowerClasses(bInheritor, aClass, descendants); } } } }.getGreatestLowerClasses(aClass, bClass, descendants); return descendants.toArray(PsiClass.EMPTY_ARRAY); }
|
getGreatestLowerClasses
|
16,641
|
void (final PsiClass aClass, final PsiClass bClass, final Set<? super PsiClass> descendants) { if (bClass.hasModifierProperty(PsiModifier.FINAL)) return; if (aClass.isInheritor(bClass, true)) { descendants.add(aClass); } else { for (PsiClass bInheritor : ClassInheritorsSearch.search(bClass, false)) { getGreatestLowerClasses(bInheritor, aClass, descendants); } } }
|
getGreatestLowerClasses
|
16,642
|
PsiType (final PsiType type) { if (type instanceof PsiTypeVariable) { final PsiType t = myBindings.get(((PsiTypeVariable) type).getIndex()); return t == null ? type : t; } else if (type instanceof PsiArrayType) { return apply(((PsiArrayType)type).getComponentType()).createArrayType(); } else if (type instanceof PsiClassType) { final PsiClassType.ClassResolveResult result = Util.resolveType(type); final PsiClass theClass = result.getElement(); final PsiSubstitutor aSubst = result.getSubstitutor(); PsiSubstitutor theSubst = PsiSubstitutor.EMPTY; if (theClass != null) { for (final PsiTypeParameter aParm : aSubst.getSubstitutionMap().keySet()) { final PsiType aType = aSubst.substitute(aParm); theSubst = theSubst.put(aParm, apply(aType)); } return JavaPsiFacade.getElementFactory(theClass.getProject()).createType(theClass, theSubst); } else { return type; } } else if (type instanceof PsiWildcardType wcType) { final PsiType bound = wcType.getBound(); if (bound != null) { final PsiType abound = apply(bound); if (abound instanceof PsiWildcardType) { return null; } return wcType.isExtends() ? PsiWildcardType.createExtends(PsiManager.getInstance(myProject), abound) : PsiWildcardType.createSuper(PsiManager.getInstance(myProject), abound); } return type; } else { return type; } }
|
apply
|
16,643
|
boolean (final Object o) { if (this == o) return true; return o instanceof BindingImpl binding && myBindings.equals(binding.myBindings); }
|
equals
|
16,644
|
Binding (final Binding b) { LOG.assertTrue(b instanceof BindingImpl); final BindingImpl b1 = this; final BindingImpl b2 = (BindingImpl)b; final BindingImpl b3 = new BindingImpl(); for (PsiTypeVariable boundVariable : myBoundVariables) { final int i = boundVariable.getIndex(); final PsiType b1i = b1.myBindings.get(i); final PsiType b2i = b2.myBindings.get(i); final int flag = (b1i == null ? 0 : 1) + (b2i == null ? 0 : 2); switch (flag) { case 0 -> {} case 1 -> /* b1(i)\b2(i) */ { final PsiType type = b2.apply(b1i); if (type == null) { return null; } if (type != PsiTypes.nullType()) { b3.myBindings.put(i, type); b3.myCyclic = type instanceof PsiTypeVariable; } } case 2 -> /* b2(i)\b1(i) */ { final PsiType type = b1.apply(b2i); if (type == null) { return null; } if (type != PsiTypes.nullType()) { b3.myBindings.put(i, type); b3.myCyclic = type instanceof PsiTypeVariable; } } case 3 -> /* b2(i) \cap b1(i) */ { final Binding common = rise(b1i, b2i, null); if (common == null) { return null; } final PsiType type = common.apply(b1i); if (type == null) { return null; } if (type != PsiTypes.nullType()) { b3.myBindings.put(i, type); b3.myCyclic = type instanceof PsiTypeVariable; } } } } return b3; }
|
compose
|
16,645
|
String () { final StringBuilder buffer = new StringBuilder(); for (PsiTypeVariable boundVariable : myBoundVariables) { final int i = boundVariable.getIndex(); final PsiType binding = myBindings.get(i); if (binding != null) { buffer.append("#").append(i).append(" -> ").append(binding.getPresentableText()).append("; "); } } return buffer.toString(); }
|
toString
|
16,646
|
PsiType (final PsiType t) { if (t == null || t instanceof PsiTypeVariable) { return Bottom.BOTTOM; } if (t instanceof PsiWildcardType) { return ((PsiWildcardType)t).getBound(); } return t; }
|
normalize
|
16,647
|
int (final Binding binding) { final BindingImpl b2 = (BindingImpl)binding; final BindingImpl b1 = this; int directoin = Binding.NONCOMPARABLE; boolean first = true; for (PsiTypeVariable boundVariable : myBoundVariables) { final int index = boundVariable.getIndex(); final PsiType x = normalize(b1.myBindings.get(index)); final PsiType y = normalize(b2.myBindings.get(index)); final int comp = new Object() { int compare(final PsiType x, final PsiType y) { final int[] kinds = new Object() { private static int classify(final PsiType type) { if (type == null) { return 0; } if (type instanceof PsiPrimitiveType) { return 1; } if (type instanceof PsiArrayType) { return 2; } if (type instanceof PsiClassType) { return 3; } return 4; // Bottom } int[] classify2(final PsiType x, final PsiType y) { return new int[]{classify(x), classify(y)}; } }.classify2(x, y); final int kindX = kinds[0]; final int kindY = kinds[1]; // Break your brain here... if (kindX + kindY == 0) { return Binding.SAME; } if (kindX * kindY == 0) { if (kindX == 0) { return Binding.WORSE; } return Binding.BETTER; } if (kindX * kindY == 1) { if (x.equals(y)) { return Binding.SAME; } return Binding.NONCOMPARABLE; } if (kindX != kindY) { if (kindX == 4) { return Binding.WORSE; } if (kindY == 4) { return Binding.BETTER; } if (kindX + kindY == 5) { try { final PsiElementFactory f = JavaPsiFacade.getElementFactory(myProject); final PsiType cloneable = f.createTypeFromText("java.lang.Cloneable", null); final PsiType object = f.createTypeFromText(CommonClassNames.JAVA_LANG_OBJECT, null); final PsiType serializable = f.createTypeFromText("java.io.Serializable", null); PsiType type; int flag; if (kindX == 3) { type = x; flag = Binding.WORSE; } else { type = y; flag = Binding.BETTER; } if (type.equals(object) || type.equals(cloneable) || type.equals(serializable)) { return flag; } } catch (IncorrectOperationException e) { LOG.error(e); } } return Binding.NONCOMPARABLE; } if (kindX == 2) { return compare(((PsiArrayType)x).getComponentType(), ((PsiArrayType)y).getComponentType()); } if (x.equals(y)) { return Binding.SAME; } // End of breaking... final PsiClassType.ClassResolveResult resultX = Util.resolveType(x); final PsiClassType.ClassResolveResult resultY = Util.resolveType(y); final PsiClass xClass = resultX.getElement(); final PsiClass yClass = resultY.getElement(); final PsiSubstitutor xSubst = resultX.getSubstitutor(); final PsiSubstitutor ySubst = resultY.getSubstitutor(); if (xClass == null || yClass == null) { return Binding.NONCOMPARABLE; } if (xClass.equals(yClass)) { boolean first = true; int direction = Binding.SAME; for (final PsiTypeParameter p : xSubst.getSubstitutionMap().keySet()) { final PsiType xParm = xSubst.substitute(p); final PsiType yParm = ySubst.substitute(p); final int comp = compare(xParm, yParm); if (comp == Binding.NONCOMPARABLE) { return Binding.NONCOMPARABLE; } if (first) { first = false; direction = comp; } if (direction != comp) { return Binding.NONCOMPARABLE; } } return direction; } else { if (InheritanceUtil.isInheritorOrSelf(xClass, yClass, true)) { return Binding.BETTER; } else if (InheritanceUtil.isInheritorOrSelf(yClass, xClass, true)) { return Binding.WORSE; } return Binding.NONCOMPARABLE; } } }.compare(x, y); if (comp == Binding.NONCOMPARABLE) { return Binding.NONCOMPARABLE; } if (first) { first = false; directoin = comp; } if (directoin != SAME) { if (comp != Binding.SAME && directoin != comp) { return Binding.NONCOMPARABLE; } } else if (comp != SAME) { directoin = comp; } } return directoin; }
|
compare
|
16,648
|
int (final PsiType type) { if (type == null) { return 0; } if (type instanceof PsiPrimitiveType) { return 1; } if (type instanceof PsiArrayType) { return 2; } if (type instanceof PsiClassType) { return 3; } return 4; // Bottom }
|
classify
|
16,649
|
boolean () { return myBindings.size() > 0; }
|
nonEmpty
|
16,650
|
boolean () { return myCyclic; }
|
isCyclic
|
16,651
|
Binding () { final BindingImpl binding = (BindingImpl)create(); for (final PsiTypeVariable var : myBoundVariables) { final int index = var.getIndex(); final PsiType type = myBindings.get(index); if (type != null) { class Verifier extends PsiExtendedTypeVisitor<Void> { boolean myFlag; @Override public Void visitTypeVariable(@NotNull final PsiTypeVariable var) { if (var.getIndex() == index) { myFlag = true; } return null; } } final Verifier verifier = new Verifier(); type.accept(verifier); if (verifier.myFlag) { myBindings.put(index, Bottom.BOTTOM); binding.myBindings.put(index, Bottom.BOTTOM); } else { binding.myBindings.put(index, type); } } else { binding.myBindings.put(index, null); } } for (final PsiTypeVariable var : myBoundVariables) { final int index = var.getIndex(); final PsiType type = myBindings.get(index); if (type != null) { myBindings.put(index, binding.apply(type)); } } return this; }
|
reduceRecursive
|
16,652
|
boolean (final PsiTypeVariable var) { return myBindings.get(var.getIndex()) != null; }
|
binds
|
16,653
|
void (final Binding b, final boolean removeObject) { for (final PsiTypeVariable var : b.getBoundVariables()) { final int index = var.getIndex(); if (myBindings.get(index) != null) { LOG.error("Oops... Binding conflict..."); } else { final PsiType type = b.apply(var); final PsiClassType javaLangObject = PsiType.getJavaLangObject(PsiManager.getInstance(myProject), GlobalSearchScope.allScope(myProject)); if (removeObject && javaLangObject.equals(type)) { final Set<PsiTypeVariable> cluster = myFactory.getClusterOf(var.getIndex()); if (cluster != null) { for (final PsiTypeVariable war : cluster) { final PsiType wtype = b.apply(war); if (!javaLangObject.equals(wtype)) { myBindings.put(index, type); break; } } } } else { myBindings.put(index, type); } } } }
|
merge
|
16,654
|
Set<PsiTypeVariable> () { return myBoundVariables; }
|
getBoundVariables
|
16,655
|
int () { int width= 0; for (Int2ObjectMap.Entry<PsiType> entry : myBindings.int2ObjectEntrySet()) { PsiType type = entry.getValue(); if (substitute(type) != null) width++; } return width; }
|
getWidth
|
16,656
|
boolean () { for (final PsiTypeVariable var : myBoundVariables) { final PsiType type = substitute(var); if (!var.isValidInContext(type)) { return false; } } return true; }
|
isValid
|
16,657
|
void (final PsiTypeVariable var) { myBoundVariables.add(var); }
|
addTypeVariable
|
16,658
|
PsiType (final PsiType t) { if (t instanceof PsiWildcardType wcType) { final PsiType bound = wcType.getBound(); if (bound == null) { return t; } final PsiManager manager = PsiManager.getInstance(myProject); final PsiType subst = substitute(bound); if (subst == null) return null; return subst instanceof PsiWildcardType ? subst : wcType.isExtends() ? PsiWildcardType.createExtends(manager, subst) : PsiWildcardType.createSuper(manager, subst); } else if (t instanceof PsiTypeVariable) { final PsiType b = apply(t); if (b instanceof Bottom || b instanceof PsiTypeVariable) { return null; } return substitute(b); } else if (t instanceof Bottom) { return null; } else if (t instanceof PsiArrayType) { return substitute(((PsiArrayType)t).getComponentType()).createArrayType(); } else if (t instanceof PsiClassType) { final PsiClassType.ClassResolveResult result = ((PsiClassType)t).resolveGenerics(); final PsiClass aClass = result.getElement(); final PsiSubstitutor aSubst = result.getSubstitutor(); if (aClass != null) { PsiSubstitutor theSubst = PsiSubstitutor.EMPTY; for (final PsiTypeParameter parm : aSubst.getSubstitutionMap().keySet()) { final PsiType type = aSubst.substitute(parm); theSubst = theSubst.put(parm, substitute(type)); } return JavaPsiFacade.getElementFactory(aClass.getProject()).createType(aClass, theSubst); } } return t; }
|
substitute
|
16,659
|
Binding (final PsiType x, final PsiType y, final Balancer balancer, final Set<? super Constraint> constraints) { final int indicator = (x instanceof PsiTypeVariable ? 1 : 0) + (y instanceof PsiTypeVariable ? 2 : 0); switch (indicator) { case 0 -> { if (x instanceof PsiWildcardType || y instanceof PsiWildcardType) { final PsiType xType = x instanceof PsiWildcardType ? ((PsiWildcardType)x).getBound() : x; final PsiType yType = y instanceof PsiWildcardType ? ((PsiWildcardType)y).getBound() : y; switch ((x instanceof PsiWildcardType ? 1 : 0) + (y instanceof PsiWildcardType ? 2 : 0)) { case 1 -> { if (((PsiWildcardType)x).isExtends()) { /* ? extends T1, T2 */ return null; } else { /* ? super T1, T2 */ if (xType != null && !CommonClassNames.JAVA_LANG_OBJECT.equals(xType.getCanonicalText())) { return null; } return create(); } } case 2 -> { if (((PsiWildcardType)y).isExtends()) { /* T1, ? extends T2 */ if (yType instanceof PsiTypeVariable) { final PsiTypeVariable beta = myFactory.create(); if (constraints != null) { constraints.add(new Subtype(beta, yType)); if (x != null) { constraints.add(new Subtype(x, yType)); } } return create(); } else { if (constraints != null && xType != null && yType != null) { constraints.add(new Subtype(xType, yType)); } return balance(xType, yType, balancer, constraints); } } else {/* T1, ? super T2 */ if (yType instanceof PsiTypeVariable) { final PsiTypeVariable beta = myFactory.create(); if (constraints != null) { if (x != null) constraints.add(new Subtype(x, beta)); constraints.add(new Subtype(yType, beta)); } return create(); } else { if (constraints != null && yType != null && xType != null) { constraints.add(new Subtype(yType, xType)); } return balance(xType, yType, balancer, constraints); } } } case 3 -> { switch ((((PsiWildcardType)x).isExtends() ? 0 : 1) + (((PsiWildcardType)y).isExtends() ? 0 : 2)) { case 0 -> { /* ? super T1, ? super T2 */ if (constraints != null && xType != null && yType != null) { constraints.add(new Subtype(yType, xType)); } return balance(xType, yType, balancer, constraints); } case 1 -> { /* ? extends T1, ? super T2 */ if (constraints != null && xType != null && yType != null) { constraints.add(new Subtype(xType, yType)); } return balance(xType, yType, balancer, constraints); } case 2 -> { /* ? super T1, ? extends T2*/ return null; } case 3 -> { /* ? extends T1, ? extends T2*/ if (constraints != null && xType != null && yType != null) { constraints.add(new Subtype(xType, yType)); } return balance(xType, yType, balancer, constraints); } } } } return create(); } else if (x instanceof PsiArrayType || y instanceof PsiArrayType) { final PsiType xType = x instanceof PsiArrayType ? ((PsiArrayType)x).getComponentType() : x; final PsiType yType = y instanceof PsiArrayType ? ((PsiArrayType)y).getComponentType() : y; return balance(xType, yType, balancer, constraints); } else if (x instanceof PsiClassType && y instanceof PsiClassType) { final PsiClassType.ClassResolveResult resultX = Util.resolveType(x); final PsiClassType.ClassResolveResult resultY = Util.resolveType(y); final PsiClass xClass = resultX.getElement(); final PsiClass yClass = resultY.getElement(); if (xClass != null && yClass != null) { final PsiSubstitutor ySubst = resultY.getSubstitutor(); PsiSubstitutor xSubst = TypeConversionUtil.getClassSubstitutor(yClass, xClass, resultX.getSubstitutor()); if (xSubst == null) return null; Binding b = create(); for (final PsiTypeParameter aParm : xSubst.getSubstitutionMap().keySet()) { final PsiType xType = xSubst.substitute(aParm); final PsiType yType = ySubst.substitute(aParm); final Binding b1 = unify(xType, yType, new Unifier() { @Override public Binding unify(final PsiType x, final PsiType y) { return balance(x, y, balancer, constraints); } }); if (b1 == null) { return null; } b = b.compose(b1); } return b; } } else if (y instanceof Bottom) { return create(); } else { return null; } } case 1 -> { return balancer.varType((PsiTypeVariable)x, y); } case 2 -> { return balancer.typeVar(x, (PsiTypeVariable)y); } case 3 -> { return balancer.varVar((PsiTypeVariable)x, (PsiTypeVariable)y); } } return null; }
|
balance
|
16,660
|
Binding (final PsiType x, final PsiType y) { return balance(x, y, balancer, constraints); }
|
unify
|
16,661
|
Binding (final PsiType x, final PsiType y, final Unifier unifier) { final int indicator = (x instanceof PsiTypeVariable ? 1 : 0) + (y instanceof PsiTypeVariable ? 2 : 0); if (indicator == 0) { if (x instanceof PsiWildcardType || y instanceof PsiWildcardType) { return unifier.unify(x, y); } else if (x instanceof PsiArrayType || y instanceof PsiArrayType) { final PsiType xType = x instanceof PsiArrayType ? ((PsiArrayType)x).getComponentType() : x; final PsiType yType = y instanceof PsiArrayType ? ((PsiArrayType)y).getComponentType() : y; return unify(xType, yType, unifier); } else if (x instanceof PsiClassType && y instanceof PsiClassType) { final PsiClassType.ClassResolveResult resultX = Util.resolveType(x); final PsiClassType.ClassResolveResult resultY = Util.resolveType(y); final PsiClass xClass = resultX.getElement(); final PsiClass yClass = resultY.getElement(); if (xClass != null && yClass != null) { final PsiSubstitutor ySubst = resultY.getSubstitutor(); final PsiSubstitutor xSubst = resultX.getSubstitutor(); if (!xClass.equals(yClass)) { return null; } Binding b = create(); for (final PsiTypeParameter aParm : xSubst.getSubstitutionMap().keySet()) { final PsiType xType = xSubst.substitute(aParm); final PsiType yType = ySubst.substitute(aParm); final Binding b1 = unify(xType, yType, unifier); if (b1 == null) { return null; } b = b.compose(b1); } return b; } } else if (y instanceof Bottom) { return create(); } else { return null; } } return unifier.unify(x, y); }
|
unify
|
16,662
|
Binding (final PsiType x, final PsiType y, final Set<? super Constraint> constraints) { final Binding binding = balance(x, y, new Balancer() { @Override public Binding varType(final PsiTypeVariable x, final PsiType y) { if (y instanceof Bottom) { return create(); } if (y == null || y instanceof PsiWildcardType) { return null; } final PsiTypeVariable var = myFactory.create(); final Binding binding = create(x, PsiWildcardType.createSuper(PsiManager.getInstance(myProject), var)); binding.addTypeVariable(var); constraints.add(new Subtype(var, y)); return binding; } @Override public Binding varVar(final PsiTypeVariable x, final PsiTypeVariable y) { final int xi = x.getIndex(); final int yi = y.getIndex(); if (xi == yi) return create (); return create (y, PsiWildcardType.createExtends(PsiManager.getInstance(myProject), x)); /* if (xi < yi) { return create(x, y); } else if (yi < xi) { return create(y, x); } else { return create(); } */ } @Override public Binding typeVar(final PsiType x, final PsiTypeVariable y) { if (x == null) { return create(y, Bottom.BOTTOM); } if (x instanceof PsiWildcardType) { return null; } final PsiTypeVariable var = myFactory.create(); final Binding binding = create(y, PsiWildcardType.createExtends(PsiManager.getInstance(myProject), var)); binding.addTypeVariable(var); constraints.add(new Subtype(x, var)); return binding; } }, constraints); return binding != null ? binding.reduceRecursive() : null; }
|
riseWithWildcard
|
16,663
|
Binding (final PsiTypeVariable x, final PsiType y) { if (y instanceof Bottom) { return create(); } if (y == null || y instanceof PsiWildcardType) { return null; } final PsiTypeVariable var = myFactory.create(); final Binding binding = create(x, PsiWildcardType.createSuper(PsiManager.getInstance(myProject), var)); binding.addTypeVariable(var); constraints.add(new Subtype(var, y)); return binding; }
|
varType
|
16,664
|
Binding (final PsiTypeVariable x, final PsiTypeVariable y) { final int xi = x.getIndex(); final int yi = y.getIndex(); if (xi == yi) return create (); return create (y, PsiWildcardType.createExtends(PsiManager.getInstance(myProject), x)); /* if (xi < yi) { return create(x, y); } else if (yi < xi) { return create(y, x); } else { return create(); } */ }
|
varVar
|
16,665
|
Binding (final PsiType x, final PsiTypeVariable y) { if (x == null) { return create(y, Bottom.BOTTOM); } if (x instanceof PsiWildcardType) { return null; } final PsiTypeVariable var = myFactory.create(); final Binding binding = create(y, PsiWildcardType.createExtends(PsiManager.getInstance(myProject), var)); binding.addTypeVariable(var); constraints.add(new Subtype(x, var)); return binding; }
|
typeVar
|
16,666
|
Binding (final PsiType x, final PsiType y, final Set<? super Constraint> constraints) { final Binding binding = balance(x, y, new Balancer() { @Override public Binding varType(final PsiTypeVariable x, final PsiType y) { if (y instanceof Bottom || y instanceof PsiWildcardType) { return create(); } return create(x, y); } @Override public Binding varVar(final PsiTypeVariable x, final PsiTypeVariable y) { final int xi = x.getIndex(); final int yi = y.getIndex(); if (xi < yi) { return create(x, y); } else if (yi < xi) { return create(y, x); } else { return create(); } } @Override public Binding typeVar(final PsiType x, final PsiTypeVariable y) { if (x == null) return create(y, Bottom.BOTTOM); if (x instanceof PsiWildcardType) return create(); return create(y, x); } }, constraints); return binding != null ? binding.reduceRecursive() : null; }
|
rise
|
16,667
|
Binding (final PsiTypeVariable x, final PsiType y) { if (y instanceof Bottom || y instanceof PsiWildcardType) { return create(); } return create(x, y); }
|
varType
|
16,668
|
Binding (final PsiTypeVariable x, final PsiTypeVariable y) { final int xi = x.getIndex(); final int yi = y.getIndex(); if (xi < yi) { return create(x, y); } else if (yi < xi) { return create(y, x); } else { return create(); } }
|
varVar
|
16,669
|
Binding (final PsiType x, final PsiTypeVariable y) { if (x == null) return create(y, Bottom.BOTTOM); if (x instanceof PsiWildcardType) return create(); return create(y, x); }
|
typeVar
|
16,670
|
Binding (final PsiType x, final PsiType y, final Set<? super Constraint> constraints) { return balance(x, y, new Balancer() { @Override public Binding varType(final PsiTypeVariable x, final PsiType y) { return create(x, y); } @Override public Binding varVar(final PsiTypeVariable x, final PsiTypeVariable y) { return create(y, Bottom.BOTTOM); } @Override public Binding typeVar(final PsiType x, final PsiTypeVariable y) { return create(y, Bottom.BOTTOM); } }, constraints); }
|
sink
|
16,671
|
Binding (final PsiTypeVariable x, final PsiType y) { return create(x, y); }
|
varType
|
16,672
|
Binding (final PsiTypeVariable x, final PsiTypeVariable y) { return create(y, Bottom.BOTTOM); }
|
varVar
|
16,673
|
Binding (final PsiType x, final PsiTypeVariable y) { return create(y, Bottom.BOTTOM); }
|
typeVar
|
16,674
|
Binding (final PsiTypeVariable var, final PsiType type) { return new BindingImpl(var, type); }
|
create
|
16,675
|
Binding () { return new BindingImpl(); }
|
create
|
16,676
|
Set<PsiTypeVariable> () { return myBoundVariables; }
|
getBoundVariables
|
16,677
|
Object (@NotNull final PsiTypeVariable var) { mySet.add(var); return null; }
|
visitTypeVariable
|
16,678
|
Set<PsiTypeVariable> (final PsiType type) { type.accept(this); return mySet; }
|
getSet
|
16,679
|
boolean (final PsiTypeVariable var) { return myBindingDegree.getInt(var) != 1; }
|
isBoundElseWhere
|
16,680
|
boolean (final Binding b) { if (mySettings.exhaustive()) return false; for (final PsiTypeVariable var : b.getBoundVariables()) { final PsiType type = b.apply(var); if (!(type instanceof PsiTypeVariable) && isBoundElseWhere(var)) { return false; } } return true; }
|
canBePruned
|
16,681
|
Object2IntMap<PsiTypeVariable> () { Object2IntMap<PsiTypeVariable> result=new Object2IntOpenHashMap<>(); for (Constraint constr : myConstraints) { PsiTypeVarCollector collector = new PsiTypeVarCollector(); setDegree(collector.getSet(constr.getRight()), result); } return result; }
|
calculateDegree
|
16,682
|
void (final Set<PsiTypeVariable> set, Object2IntMap<PsiTypeVariable> result) { for (PsiTypeVariable var : set) { result.mergeInt(var, 1, Math::addExact); } }
|
setDegree
|
16,683
|
Set<Constraint> (final Binding b) { final Set<Constraint> result = new HashSet<>(); for (final Constraint constr : myConstraints) { result.add(constr.apply(b)); } return result; }
|
apply
|
16,684
|
Set<Constraint> (final Binding b, final Set<Constraint> additional) { final Set<Constraint> result = new HashSet<>(); for (final Constraint constr : myConstraints) { result.add(constr.apply(b)); } for (final Constraint constr : additional) { result.add(constr.apply(b)); } return result; }
|
apply
|
16,685
|
ResolverTree (final Binding b) { final Binding newBinding = b != null ? myCurrentBinding.compose(b) : null; return newBinding == null ? null : new ResolverTree(this, apply(b), newBinding); }
|
applyRule
|
16,686
|
ResolverTree (final Binding b, final Set<Constraint> additional) { final Binding newBinding = b != null ? myCurrentBinding.compose(b) : null; return newBinding == null ? null : new ResolverTree(this, apply(b, additional), newBinding); }
|
applyRule
|
16,687
|
void () { final Set<PsiTypeVariable> nodes = new HashSet<>(); final Set<Constraint> candidates = new HashSet<>(); final Map<PsiTypeVariable, Set<PsiTypeVariable>> ins = new HashMap<>(); final Map<PsiTypeVariable, Set<PsiTypeVariable>> outs = new HashMap<>(); for (final Constraint constraint : myConstraints) { final PsiType left = constraint.getLeft(); final PsiType right = constraint.getRight(); if (left instanceof PsiTypeVariable leftVar && right instanceof PsiTypeVariable rightVar) { candidates.add(constraint); nodes.add(leftVar); nodes.add(rightVar); Set<PsiTypeVariable> in = ins.get(leftVar); Set<PsiTypeVariable> out = outs.get(rightVar); if (in == null) { final Set<PsiTypeVariable> newIn = new HashSet<>(); newIn.add(rightVar); ins.put(leftVar, newIn); } else { in.add(rightVar); } if (out == null) { final Set<PsiTypeVariable> newOut = new HashSet<>(); newOut.add(leftVar); outs.put(rightVar, newOut); } else { out.add(leftVar); } } } final DFSTBuilder<PsiTypeVariable> dfstBuilder = new DFSTBuilder<>(new Graph<>() { @NotNull @Override public Collection<PsiTypeVariable> getNodes() { return nodes; } @NotNull @Override public Iterator<PsiTypeVariable> getIn(final PsiTypeVariable n) { final Set<PsiTypeVariable> in = ins.get(n); if (in == null) { return Collections.emptyIterator(); } return in.iterator(); } @NotNull @Override public Iterator<PsiTypeVariable> getOut(final PsiTypeVariable n) { final Set<PsiTypeVariable> out = outs.get(n); if (out == null) { return Collections.emptyIterator(); } return out.iterator(); } }); IntList sccs = dfstBuilder.getSCCs(); Object2IntMap<PsiTypeVariable> index = new Object2IntOpenHashMap<>(); int tNumber = 0; for (IntListIterator iterator = sccs.iterator(); iterator.hasNext(); ) { int size = iterator.nextInt(); for (int j = 0; j < size; j++) { index.put(dfstBuilder.getNodeByTNumber(tNumber + j), tNumber); } tNumber += size; } for (Constraint constraint : candidates) { if (index.getInt(constraint.getLeft()) == index.getInt(constraint.getRight())) { myConstraints.remove(constraint); } } Binding binding = myBindingFactory.create(); for (PsiTypeVariable fromVar : index.keySet()) { PsiTypeVariable toVar = dfstBuilder.getNodeByNNumber(index.getInt(fromVar)); if (!fromVar.equals(toVar)) { binding = binding.compose(myBindingFactory.create(fromVar, toVar)); if (binding == null) { break; } } } if (binding != null && binding.nonEmpty()) { myCurrentBinding = myCurrentBinding.compose(binding); myConstraints = apply(binding); } }
|
reduceCyclicVariables
|
16,688
|
Collection<PsiTypeVariable> () { return nodes; }
|
getNodes
|
16,689
|
Iterator<PsiTypeVariable> (final PsiTypeVariable n) { final Set<PsiTypeVariable> in = ins.get(n); if (in == null) { return Collections.emptyIterator(); } return in.iterator(); }
|
getIn
|
16,690
|
Iterator<PsiTypeVariable> (final PsiTypeVariable n) { final Set<PsiTypeVariable> out = outs.get(n); if (out == null) { return Collections.emptyIterator(); } return out.iterator(); }
|
getOut
|
16,691
|
void (final Constraint constr) { final PsiType left = constr.getLeft(); final PsiType right = constr.getRight(); final Set<Constraint> addendumRise = new HashSet<>(); final Set<Constraint> addendumSink = new HashSet<>(); final Set<Constraint> addendumWcrd = new HashSet<>(); int numSons = 0; Binding riseBinding = myBindingFactory.rise(left, right, addendumRise); if (riseBinding != null) numSons++; Binding sinkBinding = myBindingFactory.sink(left, right, addendumSink); if (sinkBinding != null) numSons++; Binding wcrdBinding = mySettings.cookToWildcards() ? myBindingFactory.riseWithWildcard(left, right, addendumWcrd) : null; if (wcrdBinding != null) numSons++; Binding omitBinding = null; if (mySettings.exhaustive()) { final PsiClassType.ClassResolveResult rightResult = Util.resolveType(right); final PsiClassType.ClassResolveResult leftResult = Util.resolveType(left); final PsiClass rightClass = rightResult.getElement(); final PsiClass leftClass = leftResult.getElement(); if (rightClass != null && leftClass != null && rightClass.getManager().areElementsEquivalent(rightClass, leftClass)) { if (PsiUtil.typeParametersIterator(rightClass).hasNext()) { omitBinding = myBindingFactory.create(); numSons++; for (PsiType type : rightResult.getSubstitutor().getSubstitutionMap().values()) { if (! (type instanceof Bottom)) { numSons--; omitBinding = null; break; } } } } } if (numSons == 0) return; if ((riseBinding != null && sinkBinding != null && riseBinding.equals(sinkBinding)) || canBePruned(riseBinding)) { numSons--; sinkBinding = null; } if (riseBinding != null && wcrdBinding != null && riseBinding.equals(wcrdBinding)) { numSons--; wcrdBinding = null; } myConstraints.remove(constr); mySons = new ResolverTree[numSons]; int n = 0; if (riseBinding != null) { mySons[n++] = applyRule(riseBinding, addendumRise); } if (wcrdBinding != null) { mySons[n++] = applyRule(wcrdBinding, addendumWcrd); } if (omitBinding != null) { mySons[n++] = applyRule(omitBinding, addendumWcrd); } if (sinkBinding != null) { mySons[n++] = applyRule(sinkBinding, addendumSink); } }
|
reduceTypeType
|
16,692
|
void (final PsiType lowerBound, final PsiType upperBound, final Set<PsiType> holder) { if (lowerBound instanceof PsiClassType && upperBound instanceof PsiClassType) { final PsiClassType.ClassResolveResult resultLower = ((PsiClassType)lowerBound).resolveGenerics(); final PsiClassType.ClassResolveResult resultUpper = ((PsiClassType)upperBound).resolveGenerics(); final PsiClass lowerClass = resultLower.getElement(); final PsiClass upperClass = resultUpper.getElement(); if (lowerClass != null && upperClass != null && !lowerClass.equals(upperClass)) { final PsiSubstitutor upperSubst = resultUpper.getSubstitutor(); final PsiClass[] parents = upperClass.getSupers(); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(myProject); for (final PsiClass parent : parents) { final PsiSubstitutor superSubstitutor = TypeConversionUtil.getClassSubstitutor(parent, upperClass, upperSubst); if (superSubstitutor != null) { final PsiClassType type = factory.createType(parent, superSubstitutor); holder.add(type); fillTypeRange(lowerBound, type, holder); } } } } else if (lowerBound instanceof PsiArrayType && upperBound instanceof PsiArrayType) { fillTypeRange(((PsiArrayType)lowerBound).getComponentType(), ((PsiArrayType)upperBound).getComponentType(), holder); } }
|
fillTypeRange
|
16,693
|
PsiType[] (final PsiType lowerBound, final PsiType upperBound) { Set<PsiType> range = new HashSet<>(); range.add(lowerBound); range.add(upperBound); fillTypeRange(lowerBound, upperBound, range); return range.toArray(PsiType.createArray(range.size())); }
|
getTypeRange
|
16,694
|
void (final Constraint left, final Constraint right) { final PsiType leftType = left.getLeft(); final PsiType rightType = right.getRight(); final PsiTypeVariable var = (PsiTypeVariable)left.getRight(); if (leftType.equals(rightType)) { final Binding binding = myBindingFactory.create(var, leftType); myConstraints.remove(left); myConstraints.remove(right); mySons = new ResolverTree[]{applyRule(binding)}; return; } Binding riseBinding = myBindingFactory.rise(leftType, rightType, null); Binding sinkBinding = myBindingFactory.sink(leftType, rightType, null); int indicator = (riseBinding == null ? 0 : 1) + (sinkBinding == null ? 0 : 1); if (indicator == 0) { return; } else if ((indicator == 2 && riseBinding.equals(sinkBinding)) || canBePruned(riseBinding)) { indicator = 1; sinkBinding = null; } PsiType[] riseRange = PsiType.EMPTY_ARRAY; PsiType[] sinkRange = PsiType.EMPTY_ARRAY; if (riseBinding != null) { riseRange = getTypeRange(riseBinding.apply(rightType), riseBinding.apply(leftType)); } if (sinkBinding != null) { sinkRange = getTypeRange(sinkBinding.apply(rightType), sinkBinding.apply(leftType)); } if (riseRange.length + sinkRange.length > 0) { myConstraints.remove(left); myConstraints.remove(right); } mySons = new ResolverTree[riseRange.length + sinkRange.length]; for (int i = 0; i < riseRange.length; i++) { final PsiType type = riseRange[i]; mySons[i] = applyRule(riseBinding.compose(myBindingFactory.create(var, type))); } for (int i = 0; i < sinkRange.length; i++) { final PsiType type = sinkRange[i]; mySons[i + riseRange.length] = applyRule(sinkBinding.compose(myBindingFactory.create(var, type))); } }
|
reduceInterval
|
16,695
|
void () { if (myConstraints.isEmpty()) { return; } if (myCurrentBinding.isCyclic()) { reduceCyclicVariables(); } final Map<PsiTypeVariable, Constraint> myTypeVarConstraints = new HashMap<>(); final Map<PsiTypeVariable, Constraint> myVarTypeConstraints = new HashMap<>(); for (final Constraint constr : myConstraints) { final PsiType left = constr.getLeft(); final PsiType right = constr.getRight(); switch ((left instanceof PsiTypeVariable ? 0 : 1) + (right instanceof PsiTypeVariable ? 0 : 2)) { case 0 -> { } case 1 -> { final Constraint c = myTypeVarConstraints.get(right); if (c == null) { final Constraint d = myVarTypeConstraints.get(right); if (d != null) { reduceInterval(constr, d); return; } myTypeVarConstraints.put((PsiTypeVariable)right, constr); } else { reduceTypeVar(constr, c); return; } } case 2 -> { final Constraint c = myVarTypeConstraints.get(left); if (c == null) { final Constraint d = myTypeVarConstraints.get(left); if (d != null) { reduceInterval(d, constr); return; } myVarTypeConstraints.put((PsiTypeVariable)left, constr); } else { reduceVarType(constr, c); return; } } case 3 -> { reduceTypeType(constr); return; } } } //T1 < a < b ... < T2 { for (final Constraint constr : myConstraints) { final PsiType left = constr.getLeft(); final PsiType right = constr.getRight(); if (!(left instanceof PsiTypeVariable) && right instanceof PsiTypeVariable) { Set<PsiTypeVariable> bound = new PsiTypeVarCollector().getSet(left); if (bound.contains(right)) { myConstraints.remove(constr); mySons = new ResolverTree[]{applyRule(myBindingFactory.create(((PsiTypeVariable)right), Bottom.BOTTOM))}; return; } final PsiManager manager = PsiManager.getInstance(myProject); final PsiType leftType = left instanceof PsiWildcardType ? ((PsiWildcardType)left).getBound() : left; final PsiType[] types = getTypeRange(PsiType.getJavaLangObject(manager, GlobalSearchScope.allScope(myProject)), leftType); mySons = new ResolverTree[types.length]; if (types.length > 0) { myConstraints.remove(constr); } for (int i = 0; i < types.length; i++) { final PsiType type = types[i]; mySons[i] = applyRule(myBindingFactory.create(((PsiTypeVariable)right), type)); } return; } } } //T1 < a < b < ... { Set<PsiTypeVariable> haveLeftBound = new HashSet<>(); Constraint target = null; Set<PsiTypeVariable> boundVariables = new HashSet<>(); for (final Constraint constr : myConstraints) { final PsiType leftType = constr.getLeft(); final PsiType rightType = constr.getRight(); if (leftType instanceof PsiTypeVariable) { boundVariables.add((PsiTypeVariable)leftType); if (rightType instanceof PsiTypeVariable) { boundVariables.add((PsiTypeVariable)rightType); haveLeftBound.add(((PsiTypeVariable)rightType)); } else if (!Util.bindsTypeVariables(rightType)) { target = constr; } } } if (target == null) { if (mySettings.exhaustive()) { for (final Constraint constr : myConstraints) { final PsiType left = constr.getLeft(); final PsiType right = constr.getRight(); PsiType[] range = null; PsiTypeVariable var = null; if (left instanceof PsiTypeVariable && !(right instanceof PsiTypeVariable)) { range = getTypeRange(PsiType.getJavaLangObject(PsiManager.getInstance(myProject), GlobalSearchScope.allScope(myProject)), right); var = (PsiTypeVariable)left; } if (range == null && right instanceof PsiTypeVariable && !(left instanceof PsiTypeVariable)) { range = new PsiType[]{right}; var = (PsiTypeVariable)right; } if (range != null) { mySons = new ResolverTree[range.length]; for (int i = 0; i < range.length; i++) { mySons[i] = applyRule(myBindingFactory.create(var, range[i])); } return; } } } Binding binding = myBindingFactory.create(); for (final PsiTypeVariable var : myBindingFactory.getBoundVariables()) { if (!myCurrentBinding.binds(var) && !boundVariables.contains(var)) { binding = binding.compose(myBindingFactory.create(var, Bottom.BOTTOM)); } } if (!binding.nonEmpty()) { myConstraints.clear(); } mySons = new ResolverTree[]{applyRule(binding)}; } else { final PsiType type = target.getRight(); final PsiTypeVariable var = (PsiTypeVariable)target.getLeft(); final Binding binding = (haveLeftBound.contains(var) || type instanceof PsiWildcardType) || !mySettings.cookToWildcards() ? myBindingFactory.create(var, type) : myBindingFactory.create(var, PsiWildcardType.createExtends(PsiManager.getInstance(myProject), type)); myConstraints.remove(target); mySons = new ResolverTree[]{applyRule(binding)}; } } }
|
reduce
|
16,696
|
void () { LOG.debug("Reduced system:"); for (final Constraint constr : myConstraints) { LOG.debug(constr.toString()); } LOG.debug("End of Reduced system."); LOG.debug("Reduced binding:"); LOG.debug(myCurrentBinding.toString()); LOG.debug("End of Reduced binding."); }
|
logSolution
|
16,697
|
void (final Constraint x, final Constraint y) { reduceSideVar(x, y, new Reducer() { @Override public LinkedList<Pair<PsiType, Binding>> unify(final PsiType x, final PsiType y) { return myBindingFactory.intersect(x, y); } @Override public Constraint create(final PsiTypeVariable var, final PsiType type) { return new Subtype(type, var); } @Override public PsiType getType(final Constraint c) { return c.getLeft(); } @Override public PsiTypeVariable getVar(final Constraint c) { return (PsiTypeVariable)c.getRight(); } }); }
|
reduceTypeVar
|
16,698
|
Constraint (final PsiTypeVariable var, final PsiType type) { return new Subtype(type, var); }
|
create
|
16,699
|
PsiType (final Constraint c) { return c.getLeft(); }
|
getType
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.