/**
  * @param declaringElement
  * @param declaringElement2
  * @return true if both parameters are equals, false otherwise
  */
 static boolean isEqual(
     Binding declaringElement, Binding declaringElement2, HashSet visitedTypes) {
   if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
     if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding)) {
       return false;
     }
     return isEqual(
         (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement,
         (org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement2,
         visitedTypes);
   } else if (declaringElement instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) {
     if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding)) {
       return false;
     }
     return isEqual(
         (org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement,
         (org.eclipse.jdt.internal.compiler.lookup.MethodBinding) declaringElement2,
         visitedTypes);
   } else if (declaringElement instanceof VariableBinding) {
     if (!(declaringElement2 instanceof VariableBinding)) {
       return false;
     }
     return isEqual((VariableBinding) declaringElement, (VariableBinding) declaringElement2);
   } else if (declaringElement
       instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
     if (!(declaringElement2 instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding)) {
       return false;
     }
     org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding =
         (org.eclipse.jdt.internal.compiler.lookup.PackageBinding) declaringElement;
     org.eclipse.jdt.internal.compiler.lookup.PackageBinding packageBinding2 =
         (org.eclipse.jdt.internal.compiler.lookup.PackageBinding) declaringElement2;
     return CharOperation.equals(packageBinding.compoundName, packageBinding2.compoundName);
   } else if (declaringElement instanceof ImportBinding) {
     if (!(declaringElement2 instanceof ImportBinding)) {
       return false;
     }
     ImportBinding importBinding = (ImportBinding) declaringElement;
     ImportBinding importBinding2 = (ImportBinding) declaringElement2;
     return importBinding.isStatic() == importBinding2.isStatic()
         && importBinding.onDemand == importBinding2.onDemand
         && CharOperation.equals(importBinding.compoundName, importBinding2.compoundName);
   }
   return false;
 }
  private void searchVisibleVariablesAndMethods(
      Scope scope,
      ObjectVector localsFound,
      ObjectVector fieldsFound,
      ObjectVector methodsFound,
      boolean notInJavadoc) {

    InvocationSite invocationSite = CompletionEngine.FakeInvocationSite;

    boolean staticsOnly = false;
    // need to know if we're in a static context (or inside a constructor)

    Scope currentScope = scope;

    done1:
    while (true) { // done when a COMPILATION_UNIT_SCOPE is found

      switch (currentScope.kind) {
        case Scope.METHOD_SCOPE:
          // handle the error case inside an explicit constructor call (see MethodScope>>findField)
          MethodScope methodScope = (MethodScope) currentScope;
          staticsOnly |= methodScope.isStatic | methodScope.isConstructorCall;
          // $FALL-THROUGH$
        case Scope.BLOCK_SCOPE:
          BlockScope blockScope = (BlockScope) currentScope;

          next:
          for (int i = 0, length = blockScope.locals.length; i < length; i++) {
            LocalVariableBinding local = blockScope.locals[i];

            if (local == null) break next;

            if (local.isSecret()) continue next;
            // If the local variable declaration's initialization statement itself has the
            // completion,
            // then don't propose the local variable
            if (local.declaration.initialization != null) {
              /*(use this if-else block if it is found that local.declaration.initialization != null is not sufficient to
                guarantee that proposal is being asked inside a local variable declaration's initializer)
               if(local.declaration.initialization.sourceEnd > 0) {
              	if (this.assistNode.sourceEnd <= local.declaration.initialization.sourceEnd
              			&& this.assistNode.sourceStart >= local.declaration.initialization.sourceStart) {
              		continue next;
              	}
              } else {
              	CompletionNodeDetector detector = new CompletionNodeDetector(
              			this.assistNode,
              			local.declaration.initialization);
              	if (detector.containsCompletionNode()) {
              		continue next;
              	}
              }*/
              continue next;
            }
            for (int f = 0; f < localsFound.size; f++) {
              LocalVariableBinding otherLocal = (LocalVariableBinding) localsFound.elementAt(f);
              if (CharOperation.equals(otherLocal.name, local.name, true)) continue next;
            }

            localsFound.add(local);
          }
          break;

        case Scope.COMPILATION_UNIT_SCOPE:
          break done1;
      }
      currentScope = currentScope.parent;
    }

    staticsOnly = false;
    currentScope = scope;

    done2:
    while (true) { // done when a COMPILATION_UNIT_SCOPE is found

      switch (currentScope.kind) {
        case Scope.METHOD_SCOPE:
          // handle the error case inside an explicit constructor call (see MethodScope>>findField)
          MethodScope methodScope = (MethodScope) currentScope;
          staticsOnly |= methodScope.isStatic | methodScope.isConstructorCall;
          break;
        case Scope.CLASS_SCOPE:
          ClassScope classScope = (ClassScope) currentScope;
          SourceTypeBinding enclosingType = classScope.referenceContext.binding;

          searchVisibleFields(
              enclosingType,
              classScope,
              invocationSite,
              scope,
              staticsOnly,
              notInJavadoc,
              localsFound,
              fieldsFound);

          searchVisibleMethods(
              enclosingType,
              classScope,
              invocationSite,
              scope,
              staticsOnly,
              notInJavadoc,
              methodsFound);

          staticsOnly |= enclosingType.isStatic();
          break;

        case Scope.COMPILATION_UNIT_SCOPE:
          break done2;
      }
      currentScope = currentScope.parent;
    }

    // search in static import
    ImportBinding[] importBindings = scope.compilationUnitScope().imports;
    for (int i = 0; i < importBindings.length; i++) {
      ImportBinding importBinding = importBindings[i];
      if (importBinding.isValidBinding() && importBinding.isStatic()) {
        Binding binding = importBinding.resolvedImport;
        if (binding != null && binding.isValidBinding()) {
          if (importBinding.onDemand) {
            if ((binding.kind() & Binding.TYPE) != 0) {
              searchVisibleFields(
                  (ReferenceBinding) binding,
                  scope,
                  invocationSite,
                  scope,
                  staticsOnly,
                  notInJavadoc,
                  localsFound,
                  fieldsFound);

              searchVisibleMethods(
                  (ReferenceBinding) binding,
                  scope,
                  invocationSite,
                  scope,
                  staticsOnly,
                  notInJavadoc,
                  methodsFound);
            }
          } else {
            if ((binding.kind() & Binding.FIELD) != 0) {
              searchVisibleFields(
                  new FieldBinding[] {(FieldBinding) binding},
                  ((FieldBinding) binding).declaringClass,
                  scope,
                  invocationSite,
                  scope,
                  staticsOnly,
                  localsFound,
                  fieldsFound);
            } else if ((binding.kind() & Binding.METHOD) != 0) {
              MethodBinding methodBinding = (MethodBinding) binding;

              searchVisibleLocalMethods(
                  methodBinding.declaringClass.getMethods(methodBinding.selector),
                  methodBinding.declaringClass,
                  scope,
                  invocationSite,
                  scope,
                  true,
                  methodsFound);
            }
          }
        }
      }
    }
  }