code: private Variable checkVariableNameForDeclaration(String name, Expression expression) {
          if ("super".equals(name) || "this".equals(name)) return null;
  
          VariableScope scope = currentScope;
          Variable var = new DynamicVariable(name, currentScope.isInStaticContext());
          Variable orig = var;
          // try to find a declaration of a variable
          boolean crossingStaticContext = false;
          while (true) {
              crossingStaticContext = crossingStaticContext || scope.isInStaticContext();
              Variable var1;
              var1 = scope.getDeclaredVariable(var.getName());
  
              if (var1 != null) {
                  var = var1;
                  break;
              }
  
              var1 = scope.getReferencedLocalVariable(var.getName());
              if (var1 != null) {
                  var = var1;
                  break;
              }
  
              var1 = scope.getReferencedClassVariable(var.getName());
              if (var1 != null) {
                  var = var1;
                  break;
              }
  
              ClassNode classScope = scope.getClassScope();
              if (classScope != null) {
                  Variable member = findClassMember(classScope, var.getName());
                  if (member != null) {
                      boolean staticScope = crossingStaticContext || isSpecialConstructorCall;
                      boolean staticMember = member.isInStaticContext();
                      // We don't allow a static context (e.g. a static method) to access
                      // a non-static variable (e.g. a non-static field).
                      if (!(staticScope && !staticMember))
                          var = member;
                  }
                  break;
              }
              scope = scope.getParent();
          }
          if (var == orig && crossingStaticContext) {
              var = new DynamicVariable(var.getName(), true);
          }
  
          VariableScope end = scope;
  
          scope = currentScope;
          while (scope != end) {
              if (end.isClassScope() ||
                      (end.isReferencedClassVariable(name) && end.getDeclaredVariable(name) == null)) {
                  scope.putReferencedClassVariable(var);
              } else {
                  //var.setClosureSharedVariable(var.isClosureSharedVariable() || inClosure);
                  scope.putReferencedLocalVariable(var);
              }
              scope = scope.getParent();
          }
  
          return var;
      }
docs: -------------------------------