String (PsiReferenceExpression reference, PsiVariable variable, PsiElement context) { final String text = reference.getText(); final PsiResolveHelper resolveHelper = PsiResolveHelper.getInstance(context.getProject()); PsiExpression qualifier = reference.getQualifierExpression(); while (qualifier != null) { if (!(qualifier instanceof PsiReferenceExpression)) return text; qualifier = ((PsiReferenceExpression)qualifier).getQualifierExpression(); } final PsiVariable target = resolveHelper.resolveReferencedVariable(text, context); if (variable != target) { final PsiExpression effectiveQualifier = ExpressionUtils.getEffectiveQualifier(reference); if (effectiveQualifier != null) { return effectiveQualifier.getText() + "." + text; } } return text; }