boolean (Match match) { PsiFile psiFile = myExtractedMethod.getContainingFile(); PsiFile matchFile = match.getMatchStart().getContainingFile(); return psiFile instanceof PsiJavaFile && matchFile instanceof PsiJavaFile && Objects.equals(((PsiJavaFile)psiFile).getPackageName(), ((PsiJavaFile)matchFile).getPackageName()); }