List<PsiExpression> (PsiElement context) { boolean first = true; final List<PsiExpression> expressions = new ArrayList<>(); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject()); PsiElement prev = context; context = context.getContext(); while(context != null){ if(context instanceof PsiClass && !(prev instanceof PsiExpressionList)){ final String expressionText; if(first){ first = false; expressionText = PsiKeyword.THIS; } else expressionText = ((PsiClass)context).getName() + "." + PsiKeyword.THIS; try{ expressions.add(factory.createExpressionFromText(expressionText, context)); } catch(IncorrectOperationException ioe){} } if(context instanceof PsiModifierListOwner){ if(((PsiModifierListOwner)context).hasModifierProperty(PsiModifier.STATIC)) break; } prev = context; context = context.getContext(); } return expressions; }