public static boolean inSamePackage(@Nullable PsiElement element1, @Nullable PsiElement element2) {
    if (element1 == null || element2 == null) {
      return false;
    }
    final PsiFile containingFile1 = element1.getContainingFile();
    if (!(containingFile1 instanceof PsiClassOwner containingJavaFile1)) {
      return false;
    }
    final String packageName1 = containingJavaFile1.getPackageName();
    final PsiFile containingFile2 = element2.getContainingFile();
    if (!(containingFile2 instanceof PsiClassOwner containingJavaFile2)) {
      return false;
    }
    final String packageName2 = containingJavaFile2.getPackageName();
    return packageName1.equals(packageName2);
  }
public static boolean inSamePackage(@Nullable PsiElement element1, @Nullable PsiElement element2)