protected TypeBinding getTypeBinding(Scope scope) {
    // it can be a package, type or member type
    Binding binding = scope.parent.getTypeOrPackage(this.tokens); // step up from the ClassScope
    if (!binding.isValidBinding()) {
      scope.problemReporter().invalidType(this, (TypeBinding) binding);

      if (binding.problemId() == ProblemReasons.NotFound) {
        throw new CompletionNodeFound(this, binding, scope);
      }

      throw new CompletionNodeFound();
    }

    throw new CompletionNodeFound(this, binding, scope);
  }
 /**
  * Resolve selected node if not null and throw exception to let clients know that it has been
  * found.
  *
  * @throws SelectionNodeFound
  */
 private void internalResolve(Scope scope) {
   if (this.selectedNode != null) {
     switch (scope.kind) {
       case Scope.CLASS_SCOPE:
         this.selectedNode.resolveType((ClassScope) scope);
         break;
       case Scope.METHOD_SCOPE:
         this.selectedNode.resolveType((MethodScope) scope);
         break;
     }
     Binding binding = null;
     if (this.selectedNode instanceof JavadocFieldReference) {
       JavadocFieldReference fieldRef = (JavadocFieldReference) this.selectedNode;
       binding = fieldRef.binding;
       if (binding == null && fieldRef.methodBinding != null) {
         binding = fieldRef.methodBinding;
       }
     } else if (this.selectedNode instanceof JavadocMessageSend) {
       binding = ((JavadocMessageSend) this.selectedNode).binding;
     } else if (this.selectedNode instanceof JavadocAllocationExpression) {
       binding = ((JavadocAllocationExpression) this.selectedNode).binding;
     } else if (this.selectedNode instanceof JavadocSingleNameReference) {
       binding = ((JavadocSingleNameReference) this.selectedNode).binding;
     } else if (this.selectedNode instanceof JavadocSingleTypeReference) {
       JavadocSingleTypeReference typeRef = (JavadocSingleTypeReference) this.selectedNode;
       if (typeRef.packageBinding == null) {
         binding = typeRef.resolvedType;
       }
     } else if (this.selectedNode instanceof JavadocQualifiedTypeReference) {
       JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) this.selectedNode;
       if (typeRef.packageBinding == null) {
         binding = typeRef.resolvedType;
       }
     } else {
       binding = this.selectedNode.resolvedType;
     }
     throw new SelectionNodeFound(binding);
   } else if (this.inheritDocSelected) {
     // no selection node when inheritDoc tag is selected
     // But we need to detect it to enable code select on inheritDoc
     ReferenceContext referenceContext = scope.referenceContext();
     if (referenceContext instanceof MethodDeclaration) {
       throw new SelectionNodeFound(((MethodDeclaration) referenceContext).binding);
     }
   }
 }