PsiFile (Project project, Location location) { if (location == null) { return null; } final ReferenceType refType = location.declaringType(); if (refType == null) { return null; } final PsiFile psiFile = PsiManager.getInstance(project).findFile(myScratchFile); if (!(psiFile instanceof PsiJavaFile)) { return null; } final PsiClass[] classes = ((PsiJavaFile)psiFile).getClasses(); if (classes.length == 0) { return null; } final String originalQName = refType.name(); for (PsiClass aClass : classes) { if (StringUtil.equals(originalQName, aClass.getQualifiedName())) { return psiFile; } } final int dollar = originalQName.indexOf('$'); final String alternativeQName = dollar > 0? originalQName.substring(0, dollar) : null; if (!StringUtil.isEmpty(alternativeQName)) { for (PsiClass aClass : classes) { if (StringUtil.equals(alternativeQName, aClass.getQualifiedName())) { return psiFile; } } } return null; }