PsiClass (PsiVariable variable, boolean ignoreInvisibleFields, boolean ignoreStaticHidingInstance) { PsiClass aClass = ClassUtils.getContainingClass(variable); final String variableName = variable.getName(); if (variableName == null) { return null; } while (aClass != null) { final PsiField field = aClass.findFieldByName(variableName, true); if (field != null) { if (!ignoreInvisibleFields || ClassUtils.isFieldVisible(field, aClass)) { if (!ignoreStaticHidingInstance || field.hasModifierProperty(PsiModifier.STATIC) || !CommonJavaRefactoringUtil.isInStaticContext(variable, aClass)) { return aClass; } } } aClass = ClassUtils.getContainingClass(aClass); } return null; }