private @Nullable PsiVariable checkCodeFragment(@NotNull PsiElement refElement) {
    PsiElement codeFragment;
    if (refElement instanceof PsiParameter) {
      final PsiElement declarationScope = ((PsiParameter)refElement).getDeclarationScope();
      if (declarationScope instanceof PsiMethod) {
        codeFragment = ((PsiMethod)declarationScope).getBody();
      }
      else if (declarationScope instanceof PsiLambdaExpression) {
        codeFragment = ((PsiLambdaExpression)declarationScope).getBody();
      }
      else {
        codeFragment = ControlFlowUtil.findCodeFragment(refElement);
      }
    }
    else {
      codeFragment = ControlFlowUtil.findCodeFragment(refElement);
    }
    if (codeFragment == null) return null;
    if (myCodeFragment.getContainingFile() == codeFragment.getContainingFile() &&  // in order for jsp includes to work
        !myCodeFragment.equals(codeFragment) &&
        !(myCodeFragment.getParent() instanceof PsiLambdaExpression && 
          PsiTreeUtil.isAncestor(PsiTreeUtil.getParentOfType(myCodeFragment, PsiClass.class), codeFragment, false))) {
      return null;
    }
    return (PsiVariable)refElement;
  }
private @Nullable PsiVariable checkCodeFragment(@NotNull PsiElement refElement)