PsiType (PsiElement context, final String keyword) { if(PsiKeyword.CLASS.equals(keyword)){ return PsiType.getJavaLangClass(context.getManager(), context.getResolveScope()); } else if(PsiKeyword.TRUE.equals(keyword) || PsiKeyword.FALSE.equals(keyword)){ return PsiTypes.booleanType(); } else if(PsiKeyword.THIS.equals(keyword)){ PsiElement previousElement = getPreviousElement(context, false); if(previousElement != null && ".".equals(previousElement.getText())){ previousElement = getPreviousElement(previousElement, false); assert previousElement != null; final String className = previousElement.getText(); PsiElement walker = context; while(walker != null){ if(walker instanceof PsiClass && !(walker instanceof PsiAnonymousClass)){ if(className.equals(((PsiClass)walker).getName())) return getTypeByElement(walker, context); } walker = walker.getContext(); } } else{ final PsiClass owner = PsiTreeUtil.getContextOfType(context, PsiClass.class, true); return getTypeByElement(owner, context); } } return null; }