boolean (@NotNull PsiScopeProcessor processor, @NotNull PsiJavaCodeReferenceElement ref, @Nullable PsiElement maxScope, boolean incompleteCode) { final PsiElement qualifier = ref.getQualifier(); final PsiElement classNameElement = ref.getReferenceNameElement(); if (classNameElement == null) return true; if (qualifier != null) { // Composite expression PsiElement target = null; PsiSubstitutor substitutor = PsiSubstitutor.EMPTY; if (qualifier instanceof PsiExpression || qualifier instanceof PsiJavaCodeReferenceElement || qualifier instanceof PsiTypeElement) { PsiType type = null; if (qualifier instanceof PsiExpression) { type = ((PsiExpression)qualifier).getType(); assert type == null || type.isValid() : type.getClass() + "; " + qualifier; processTypeDeclarations(type, ref, processor); } else if (qualifier instanceof PsiTypeElement) { type = ((PsiTypeElement)qualifier).getType(); processTypeDeclarations(type, ref, processor); } if (type == null && qualifier instanceof PsiJavaCodeReferenceElement) { // In case of class qualifier final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)qualifier; final JavaResolveResult result = referenceElement.advancedResolve(incompleteCode); target = result.getElement(); substitutor = result.getSubstitutor(); if (target instanceof PsiVariable) { type = substitutor.substitute(((PsiVariable)target).getType()); if (type instanceof PsiClassType) { final JavaResolveResult typeResult = ((PsiClassType)type).resolveGenerics(); target = typeResult.getElement(); substitutor = substitutor.putAll(typeResult.getSubstitutor()); } else { target = null; } } else if (target instanceof PsiMethod) { type = substitutor.substitute(((PsiMethod)target).getReturnType()); if (type instanceof PsiClassType) { final JavaResolveResult typeResult = ((PsiClassType)type).resolveGenerics(); target = typeResult.getElement(); substitutor = substitutor.putAll(typeResult.getSubstitutor()); } else { target = null; } final PsiType[] types = referenceElement.getTypeParameters(); if (target instanceof PsiClass) { substitutor = substitutor.putAll((PsiClass)target, types); } } else if (target instanceof PsiClass) { processor.handleEvent(JavaScopeProcessorEvent.START_STATIC, null); } } } if (target != null) { return target.processDeclarations(processor, ResolveState.initial().put(PsiSubstitutor.KEY, substitutor), target, ref); } } else { // simple expression -> trying to resolve variable or method return treeWalkUp(processor, ref, maxScope); } return true; }