PsiElement (@NotNull String signature, @NotNull String fileRelativePath, @NotNull Project project) { String filePath = project.getBasePath() + File.separator + fileRelativePath; VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(filePath); if (virtualFile == null || !virtualFile.exists()) { throw new IllegalArgumentException(String.format("File '%s' doesn't exist", filePath)); } PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile); if (psiFile == null) { return null; } int offset = psiFile.getText().indexOf(signature); return psiFile.findElementAt(offset); }