PsiQualifiedReferenceElement (@NotNull final PsiClass refClass, final boolean addImports, @NotNull final PsiQualifiedReferenceElement reference) { PsiClass parentClass = refClass.getContainingClass(); if (parentClass != null) { JavaPsiFacade facade = JavaPsiFacade.getInstance(parentClass.getProject()); final PsiResolveHelper resolveHelper = facade.getResolveHelper(); if (resolveHelper.isAccessible(refClass, reference, null) && isSafeToShortenReference(reference.getReferenceName(), reference, refClass)) { return reference; } if (!JavaCodeStyleSettings.getInstance(reference.getContainingFile()).isInsertInnerClassImportsFor(refClass.getName())) { final PsiElement qualifier = reference.getQualifier(); if (qualifier instanceof PsiQualifiedReferenceElement) { return getClassReferenceToShorten(parentClass, addImports, (PsiQualifiedReferenceElement)qualifier); } return null; } } if (addImports && !((PsiImportHolder)reference.getContainingFile()).importClass(refClass)) return null; if (!isSafeToShortenReference(reference, refClass)) return null; return reference; }