public static PsiType[] getLeftTypes(PsiElement context) { if((context = FilterUtil.getPreviousElement(context, true)) == null) return PsiType.EMPTY_ARRAY; if(!PsiKeyword.INSTANCEOF.equals(context.getText())) return PsiType.EMPTY_ARRAY; if((context = FilterUtil.getPreviousElement(context, false)) == null) return PsiType.EMPTY_ARRAY; final PsiExpression contextOfType = PsiTreeUtil.getContextOfType(context, PsiExpression.class, false); if (contextOfType == null) return PsiType.EMPTY_ARRAY; PsiType type = contextOfType.getType(); if (type == null) return PsiType.EMPTY_ARRAY; if (type instanceof PsiClassType) { final PsiClass psiClass = ((PsiClassType)type).resolve(); if (psiClass instanceof PsiTypeParameter) { return psiClass.getExtendsListTypes(); } } return new PsiType[]{type}; }
public static boolean isAcceptable(PsiElement element, PsiElement context, PsiType expectedType, PsiSubstitutor substitutor) { if (element instanceof PsiMethod && isReturnTypeInferrable((PsiMethod)element, context, expectedType, substitutor)) { return true; } PsiType typeByElement = FilterUtil.getTypeByElement(element, context); if (typeByElement == null) { return false; } if(substitutor != null) { typeByElement = substitutor.substitute(typeByElement); } if (!allowBoxing(context) && (expectedType instanceof PsiPrimitiveType != typeByElement instanceof PsiPrimitiveType)) { return false; } return expectedType.isAssignableFrom(typeByElement); }
@Override public boolean isAcceptable(Object element, PsiElement context){ if(myType != null){ if(element == null) return false; if (element instanceof PsiType) return myType.isAssignableFrom((PsiType) element); PsiSubstitutor substitutor = null; if(element instanceof CandidateInfo){ final CandidateInfo info = (CandidateInfo)element; substitutor = info.getSubstitutor(); element = info.getElement(); } PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement)element, context); if(substitutor != null) typeByElement = substitutor.substitute(typeByElement); return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType); } else if(myFilter != null){ if(element == null) return false; return myFilter.isAcceptable(element, context); } else return false; }
@Override public boolean isAcceptable(Object element, PsiElement context) { if(element == null) { return false; } if(element instanceof PsiType) { return myType.isAssignableFrom((PsiType) element); } PsiSubstitutor substitutor = null; if(element instanceof CandidateInfo) { final CandidateInfo info = (CandidateInfo) element; substitutor = info.getSubstitutor(); element = info.getElement(); } PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement) element, context); if(substitutor != null) { typeByElement = substitutor.substitute(typeByElement); } return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType); }
@Override public boolean isAcceptable(Object element, PsiElement context){ if(element == null) return false; if (element instanceof PsiType) return myType.isAssignableFrom((PsiType) element); PsiSubstitutor substitutor = null; if(element instanceof CandidateInfo){ final CandidateInfo info = (CandidateInfo)element; substitutor = info.getSubstitutor(); element = info.getElement(); } PsiType typeByElement = FilterUtil.getTypeByElement((PsiElement)element, context); if(substitutor != null) typeByElement = substitutor.substitute(typeByElement); return typeByElement != null && typeByElement.isAssignableFrom(myType) && !typeByElement.equals(myType); }
@Override public PsiType getType() { return FilterUtil.getKeywordItemType(myPosition, getLookupString()); }
@Override public boolean isAcceptable(Object element, PsiElement context){ if (!(element instanceof PsiElement)) return false; return FilterUtil.getPreviousElement((PsiElement) element, false) == null; }