@Override protected PsiClassType calcType() { final PsiElement classElement = myClass.getElement(); if (!(classElement instanceof PsiClass)) return null; Map<PsiTypeParameter, PsiType> resurrected = new HashMap<PsiTypeParameter, PsiType>(); final Set<Map.Entry<SmartPsiElementPointer, SmartTypePointer>> set = myMap.entrySet(); for (Map.Entry<SmartPsiElementPointer, SmartTypePointer> entry : set) { PsiElement element = entry.getKey().getElement(); if (element instanceof PsiTypeParameter) { SmartTypePointer typePointer = entry.getValue(); resurrected.put((PsiTypeParameter)element, typePointer == null ? null : typePointer.getType()); } } for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable((PsiClass)classElement)) { if (!resurrected.containsKey(typeParameter)) { resurrected.put(typeParameter, null); } } final PsiSubstitutor resurrectedSubstitutor = PsiSubstitutorImpl.createSubstitutor(resurrected); return new PsiImmediateClassType((PsiClass)classElement, resurrectedSubstitutor); }
@NotNull public static MultiMap<MethodSignature, PsiMethod> findRawMethodSignatures(@NotNull PsiMethod[] methods, @NotNull PsiClass clazz) { Map<PsiTypeParameter, PsiType> initialMap = ContainerUtil.newHashMap(); for (PsiTypeParameter parameter : clazz.getTypeParameters()) { initialMap.put(parameter, null); } final PsiSubstitutor initialSubstitutor = PsiSubstitutorImpl.createSubstitutor(initialMap); MultiMap<MethodSignature, PsiMethod> result = new MultiMap<MethodSignature, PsiMethod>(); for (PsiMethod method : methods) { final PsiMethod actual = method instanceof GrReflectedMethod ? ((GrReflectedMethod)method).getBaseMethod() : method; PsiSubstitutor substitutor = calcRawSubstitutor(initialMap, initialSubstitutor, actual); result.putValue(method.getSignature(substitutor), actual); } return result; }
@NotNull private static PsiSubstitutor removeRawMappingsLeftFromResolve(@NotNull PsiSubstitutor substitutor) { Map<PsiTypeParameter, PsiType> map = null; for(Map.Entry<PsiTypeParameter, PsiType> entry : substitutor.getSubstitutionMap().entrySet()) { if(entry.getValue() == null) { if(map == null) { map = new THashMap<PsiTypeParameter, PsiType>(); } map.put(entry.getKey(), entry.getValue()); } } if(map == null) { return substitutor; } Map<PsiTypeParameter, PsiType> newMap = new THashMap<PsiTypeParameter, PsiType>(substitutor.getSubstitutionMap()); newMap.keySet().removeAll(map.keySet()); return PsiSubstitutorImpl.createSubstitutor(newMap); }
public TypeView(PsiVariable var, PsiSubstitutor varSubstitutor, PsiSubstitutor evalSubstitutor) { myOriginType = varSubstitutor != null ? varSubstitutor.substitute(var.getType()) : var.getType(); Map<PsiTypeParameter, PsiType> realMap = new HashMap<>(); if(varSubstitutor != null) { realMap.putAll(varSubstitutor.getSubstitutionMap()); } if(evalSubstitutor != null) { realMap.putAll(evalSubstitutor.getSubstitutionMap()); } myType = PsiSubstitutorImpl.createSubstitutor(realMap).substitute(myTypeEvaluator.getType(var)); myChanged = !(myOriginType == null || myType == null) && !myType.equals(myOriginType); }
private static PsiSubstitutor composeIfNotAssignable(PsiSubstitutor actual, PsiSubstitutor required) { if(actual == PsiSubstitutor.EMPTY) { return required; } if(required == PsiSubstitutor.EMPTY) { return actual; } PsiSubstitutor result = PsiSubstitutorImpl.createSubstitutor(actual.getSubstitutionMap()); for(Map.Entry<PsiTypeParameter, PsiType> e : required.getSubstitutionMap().entrySet()) { final PsiTypeParameter typeParameter = e.getKey(); final PsiType requiredType = e.getValue(); final PsiType actualType = result.getSubstitutionMap().get(typeParameter); if(requiredType != null && (actualType == null || !TypeConversionUtil.isAssignable(actualType, requiredType))) { result = result.put(typeParameter, requiredType); } } return result; }
private JavaResolveResult advancedResolveImpl(@NotNull PsiFile containingFile) { PsiTypeElement[] typeElements = myRefParameterList == null ? PsiTypeElement.EMPTY_ARRAY : myRefParameterList.getTypeParameterElements(); PsiElement resolve = resolveElement(containingFile); if (resolve == null) return null; if (resolve instanceof PsiClass) { Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<PsiTypeParameter, PsiType>(); int index = 0; for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable((PsiClass)resolve)) { if (index >= typeElements.length) { PsiTypeParameterListOwner parameterOwner = parameter.getOwner(); if (parameterOwner == resolve) { substitutionMap.put(parameter, null); } else if (parameterOwner instanceof PsiClass) { PsiElement containingClass = myParent; while ((containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class, true)) != null) { PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getClassSubstitutor((PsiClass)parameterOwner, (PsiClass)containingClass, PsiSubstitutor.EMPTY); if (superClassSubstitutor != null) { substitutionMap.put(parameter, superClassSubstitutor.substitute(parameter)); break; } } } } else { substitutionMap.put(parameter, typeElements[index].getType()); } index++; } collectOuterClassTypeArgs((PsiClass)resolve, myCanonicalText, substitutionMap); return new CandidateInfo(resolve, PsiSubstitutorImpl.createSubstitutor(substitutionMap)); } else { return new CandidateInfo(resolve, PsiSubstitutor.EMPTY); } }
@NotNull private static PsiSubstitutor removeRawMappingsLeftFromResolve(@NotNull PsiSubstitutor substitutor) { Map<PsiTypeParameter, PsiType> map = null; for (Map.Entry<PsiTypeParameter, PsiType> entry : substitutor.getSubstitutionMap().entrySet()) { if (entry.getValue() == null) { if (map == null) map = new THashMap<PsiTypeParameter, PsiType>(); map.put(entry.getKey(), entry.getValue()); } } if (map == null) return substitutor; Map<PsiTypeParameter, PsiType> newMap = new THashMap<PsiTypeParameter, PsiType>(substitutor.getSubstitutionMap()); newMap.keySet().removeAll(map.keySet()); return PsiSubstitutorImpl.createSubstitutor(newMap); }
@NotNull private static PsiSubstitutor calcRawSubstitutor(@NotNull Map<PsiTypeParameter, PsiType> initialMap, @NotNull PsiSubstitutor initialSubstitutor, @NotNull PsiMethod actual) { if (actual.hasTypeParameters()) { final HashMap<PsiTypeParameter, PsiType> map1 = ContainerUtil.newHashMap(initialMap); for (PsiTypeParameter parameter : actual.getTypeParameters()) { map1.put(parameter, null); } return PsiSubstitutorImpl.createSubstitutor(map1); } else { return initialSubstitutor; } }
private JavaResolveResult advancedResolveImpl() { PsiTypeElement[] typeElements = myRefParameterList == null ? PsiTypeElement.EMPTY_ARRAY : myRefParameterList.getTypeParameterElements(); PsiElement resolve = resolveElement(); if (resolve instanceof PsiClass) { Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<PsiTypeParameter, PsiType>(); int index = 0; for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable((PsiClass)resolve)) { if (index >= typeElements.length) { PsiTypeParameterListOwner parameterOwner = parameter.getOwner(); if (parameterOwner == resolve) { substitutionMap.put(parameter, null); } else if (parameterOwner instanceof PsiClass) { PsiElement containingClass = myParent; while ((containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class, true)) != null) { PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getClassSubstitutor((PsiClass)parameterOwner, (PsiClass)containingClass, PsiSubstitutor.EMPTY); if (superClassSubstitutor != null) { substitutionMap.put(parameter, superClassSubstitutor.substitute(parameter)); break; } } } } else { substitutionMap.put(parameter, typeElements[index].getType()); } index++; } return new CandidateInfo(resolve, PsiSubstitutorImpl.createSubstitutor(substitutionMap)); } else { return new CandidateInfo(resolve, PsiSubstitutor.EMPTY); } }
@NotNull private static PsiSubstitutor removeRawMappingsLeftFromResolve(@NotNull PsiSubstitutor substitutor) { Map<PsiTypeParameter, PsiType> map = null; for (Map.Entry<PsiTypeParameter, PsiType> entry : substitutor.getSubstitutionMap().entrySet()) { if (entry.getValue() == null) { if (map == null) map = new THashMap<PsiTypeParameter, PsiType>(); map.put(entry.getKey(), entry.getValue()); } } if (map == null) return substitutor; Map<PsiTypeParameter, PsiType> newmap = new THashMap<PsiTypeParameter, PsiType>(substitutor.getSubstitutionMap()); newmap.keySet().removeAll(map.keySet()); return PsiSubstitutorImpl.createSubstitutor(newmap); }
@Override protected PsiClassType calcType() { final PsiElement classElement = myClass.getElement(); if(!(classElement instanceof PsiClass)) { return null; } Map<PsiTypeParameter, PsiType> resurrected = new HashMap<PsiTypeParameter, PsiType>(); final Set<Map.Entry<SmartPsiElementPointer, SmartTypePointer>> set = myMap.entrySet(); for(Map.Entry<SmartPsiElementPointer, SmartTypePointer> entry : set) { PsiElement element = entry.getKey().getElement(); if(element instanceof PsiTypeParameter) { SmartTypePointer typePointer = entry.getValue(); resurrected.put((PsiTypeParameter) element, typePointer == null ? null : typePointer.getType()); } } for(PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable((PsiClass) classElement)) { if(!resurrected.containsKey(typeParameter)) { resurrected.put(typeParameter, null); } } final PsiSubstitutor resurrectedSubstitutor = PsiSubstitutorImpl.createSubstitutor(resurrected); return new PsiImmediateClassType((PsiClass) classElement, resurrectedSubstitutor); }
private JavaResolveResult advancedResolveImpl(@NotNull PsiFile containingFile) { PsiTypeElement[] typeElements = myRefParameterList == null ? PsiTypeElement.EMPTY_ARRAY : myRefParameterList.getTypeParameterElements(); PsiElement resolve = resolveElement(containingFile); if(resolve == null) { return null; } if(resolve instanceof PsiClass) { Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<>(); int index = 0; for(PsiTypeParameter parameter : PsiUtil.typeParametersIterable((PsiClass) resolve)) { if(index >= typeElements.length) { PsiTypeParameterListOwner parameterOwner = parameter.getOwner(); if(parameterOwner == resolve) { substitutionMap.put(parameter, null); } else if(parameterOwner instanceof PsiClass) { PsiElement containingClass = myParent; while((containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class, true)) != null) { PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getClassSubstitutor((PsiClass) parameterOwner, (PsiClass) containingClass, PsiSubstitutor.EMPTY); if(superClassSubstitutor != null) { substitutionMap.put(parameter, superClassSubstitutor.substitute(parameter)); break; } } } } else { substitutionMap.put(parameter, typeElements[index].getType()); } index++; } collectOuterClassTypeArgs((PsiClass) resolve, myCanonicalText, substitutionMap); return new CandidateInfo(resolve, PsiSubstitutorImpl.createSubstitutor(substitutionMap)); } else { return new CandidateInfo(resolve, PsiSubstitutor.EMPTY); } }