private static @Nullable PsiClassType substituteEventType(@Nullable PsiType eventHandlerType, @NotNull Project project) {
    if (!(eventHandlerType instanceof PsiClassType)) return null;
    final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)eventHandlerType).resolveGenerics();
    final PsiClass eventHandlerClass = resolveResult.getElement();
    if (eventHandlerClass == null) return null;
    final PsiSubstitutor eventHandlerClassSubstitutor = resolveResult.getSubstitutor();

    final PsiClass eventHandlerInterface =
      JavaPsiFacade.getInstance(project).findClass(JavaFxCommonNames.JAVAFX_EVENT_EVENT_HANDLER, GlobalSearchScope.allScope(project));
    if (eventHandlerInterface == null) return null;
    if (!InheritanceUtil.isInheritorOrSelf(eventHandlerClass, eventHandlerInterface, true)) return null;
    final PsiTypeParameter[] typeParameters = eventHandlerInterface.getTypeParameters();
    if (typeParameters.length != 1) return null;
    final PsiTypeParameter eventTypeParameter = typeParameters[0];
    final PsiSubstitutor substitutor =
      TypeConversionUtil.getSuperClassSubstitutor(eventHandlerInterface, eventHandlerClass, eventHandlerClassSubstitutor);
    final PsiType eventType = substitutor.substitute(eventTypeParameter);
    if (eventType instanceof PsiClassType) {
      return (PsiClassType)eventType;
    }
    if (eventType instanceof PsiWildcardType) { // TODO Handle wildcards more accurately
      final PsiType boundType = ((PsiWildcardType)eventType).getBound();
      if (boundType instanceof PsiClassType) {
        return (PsiClassType)boundType;
      }
    }
    return null;
  }
private static @Nullable PsiClassType substituteEventType(@Nullable PsiType eventHandlerType, @NotNull Project project)