PsiType (PsiElement element, PsiElement context) { //if(!element.isValid()) return null; if(element instanceof PsiType){ return (PsiType)element; } if(element instanceof PsiClass){ return JavaPsiFacade.getElementFactory(element.getProject()).createType((PsiClass)element); } if(element instanceof PsiMethod){ if (((PsiMethod)element).isConstructor()) { final PsiClass containingClass = ((PsiMethod)element).getContainingClass(); if (containingClass != null) { return JavaPsiFacade.getElementFactory(element.getProject()).createType(containingClass); } } return ((PsiMethod)element).getReturnType(); } if(element instanceof PsiVariable){ return ((PsiVariable)element).getType(); } if(element instanceof PsiKeyword){ return getKeywordItemType(context, element.getText()); } if(element instanceof PsiExpression){ return ((PsiExpression)element).getType(); } return null; }