Package org.eclipse.jdt.internal.compiler.util

Examples of org.eclipse.jdt.internal.compiler.util.ObjectVector


 
      Scope scope = this.assistScope;
      ASTNode astNode = this.assistNode;
      boolean notInJavadoc = this.completionContext.javadoc == 0;
 
      this.visibleLocalVariables = new ObjectVector();
      this.visibleFields = new ObjectVector();
      this.visibleMethods = new ObjectVector();
 
      ReferenceContext referenceContext = scope.referenceContext();
      if (referenceContext instanceof AbstractMethodDeclaration) {
        // completion is inside a method body
        searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc);
View Full Code Here


      InvocationSite invocationSite,
      Scope invocationScope,
      boolean onlyStaticFields,
      ObjectVector localsFound,
      ObjectVector fieldsFound) {
    ObjectVector newFieldsFound = new ObjectVector();
    // Inherited fields which are hidden by subclasses are filtered out
    // No visibility checks can be performed without the scope & invocationSite

    next : for (int f = fields.length; --f >= 0;) {
      FieldBinding field = fields[f];

      if (field.isSynthetic()) continue next;

      if (onlyStaticFields && !field.isStatic()) continue next;

      if (!field.canBeSeenBy(receiverType, invocationSite, scope)) continue next;

      for (int i = fieldsFound.size; --i >= 0;) {
        FieldBinding otherField = (FieldBinding) fieldsFound.elementAt(i);
        if (CharOperation.equals(field.name, otherField.name, true)) {
          continue next;
        }
      }

      for (int l = localsFound.size; --l >= 0;) {
        LocalVariableBinding local = (LocalVariableBinding) localsFound.elementAt(l);

        if (CharOperation.equals(field.name, local.name, true)) {
          continue next;
        }
      }

      newFieldsFound.add(field);
    }

    fieldsFound.addAll(newFieldsFound);
  }
View Full Code Here

      Scope scope,
      InvocationSite invocationSite,
      Scope invocationScope,
      boolean onlyStaticMethods,
      ObjectVector methodsFound) {
    ObjectVector newMethodsFound =  new ObjectVector();
    // Inherited methods which are hidden by subclasses are filtered out
    // No visibility checks can be performed without the scope & invocationSite

    next : for (int f = methods.length; --f >= 0;) {
      MethodBinding method = methods[f];

      if (method.isSynthetic()) continue next;

      if (method.isDefaultAbstract())  continue next;

      if (method.isConstructor()) continue next;

      if (onlyStaticMethods && !method.isStatic()) continue next;

      if (!method.canBeSeenBy(receiverType, invocationSite, scope)) continue next;

      for (int i = methodsFound.size; --i >= 0;) {
        MethodBinding otherMethod = (MethodBinding) methodsFound.elementAt(i);
        if (method == otherMethod)
          continue next;

        if (CharOperation.equals(method.selector, otherMethod.selector, true)) {
          if (this.lookupEnvironment.methodVerifier().isMethodSubsignature(otherMethod, method)) {
            continue next;
          }
        }
      }

      newMethodsFound.add(method);
    }

    methodsFound.addAll(newMethodsFound);
  }
View Full Code Here

  // Internal use only - use findMethod()
  public MethodBinding findMethod(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite, boolean inStaticContext) {
    ReferenceBinding currentType = receiverType;
    boolean receiverTypeIsInterface = receiverType.isInterface();
    ObjectVector found = new ObjectVector(3);
    CompilationUnitScope unitScope = compilationUnitScope();
    unitScope.recordTypeReferences(argumentTypes);

    if (receiverTypeIsInterface) {
      unitScope.recordTypeReference(receiverType);
      MethodBinding[] receiverMethods = receiverType.getMethods(selector, argumentTypes.length);
      if (receiverMethods.length > 0)
        found.addAll(receiverMethods);
      findMethodInSuperInterfaces(receiverType, selector, found, invocationSite);
      currentType = getJavaLangObject();
    }

    // superclass lookup
    long complianceLevel = compilerOptions().complianceLevel;
    boolean isCompliant14 = complianceLevel >= ClassFileConstants.JDK1_4;
    boolean isCompliant15 = complianceLevel >= ClassFileConstants.JDK1_5;
    ReferenceBinding classHierarchyStart = currentType;
    MethodVerifier verifier = environment().methodVerifier();
    while (currentType != null) {
      unitScope.recordTypeReference(currentType);
      currentType = (ReferenceBinding) currentType.capture(this, invocationSite == null ? 0 : invocationSite.sourceEnd());
      MethodBinding[] currentMethods = currentType.getMethods(selector, argumentTypes.length);
      int currentLength = currentMethods.length;
      if (currentLength > 0) {
        if (isCompliant14 && (receiverTypeIsInterface || found.size > 0)) {
          nextMethod: for (int i = 0, l = currentLength; i < l; i++) { // currentLength can be modified inside the loop
            MethodBinding currentMethod = currentMethods[i];
            if (currentMethod == null) continue nextMethod;
            if (receiverTypeIsInterface && !currentMethod.isPublic()) { // only public methods from Object are visible to interface receiverTypes
              currentLength--;
              currentMethods[i] = null;
              continue nextMethod;
            }

            // if 1.4 compliant, must filter out redundant protected methods from superclasses
            // protected method need to be checked only - default access is already dealt with in #canBeSeen implementation
            // when checking that p.C -> q.B -> p.A cannot see default access members from A through B.
            // if ((currentMethod.modifiers & AccProtected) == 0) continue nextMethod;
            // BUT we can also ignore any overridden method since we already know the better match (fixes 80028)
            for (int j = 0, max = found.size; j < max; j++) {
              MethodBinding matchingMethod = (MethodBinding) found.elementAt(j);
              MethodBinding matchingOriginal = matchingMethod.original();
              MethodBinding currentOriginal = matchingOriginal.findOriginalInheritedMethod(currentMethod);
              if (currentOriginal != null && verifier.isParameterSubsignature(matchingOriginal, currentOriginal)) {
                if (isCompliant15) {
                  if (matchingMethod.isBridge() && !currentMethod.isBridge())
                    continue nextMethod; // keep inherited methods to find concrete method over a bridge method
                }
                currentLength--;
                currentMethods[i] = null;
                continue nextMethod;
              }
            }
          }
        }

        if (currentLength > 0) {
          // append currentMethods, filtering out null entries
          if (currentMethods.length == currentLength) {
            found.addAll(currentMethods);
          } else {
            for (int i = 0, max = currentMethods.length; i < max; i++) {
              MethodBinding currentMethod = currentMethods[i];
              if (currentMethod != null)
                found.add(currentMethod);
            }
          }
        }
      }
      currentType = currentType.superclass();
    }

    // if found several candidates, then eliminate those not matching argument types
    int foundSize = found.size;
    MethodBinding[] candidates = null;
    int candidatesCount = 0;
    MethodBinding problemMethod = null;
    boolean searchForDefaultAbstractMethod = isCompliant14 && ! receiverTypeIsInterface && (receiverType.isAbstract() || receiverType.isTypeVariable());
    if (foundSize > 0) {
      // argument type compatibility check
      for (int i = 0; i < foundSize; i++) {
        MethodBinding methodBinding = (MethodBinding) found.elementAt(i);
        MethodBinding compatibleMethod = computeCompatibleMethod(methodBinding, argumentTypes, invocationSite);
        if (compatibleMethod != null) {
          if (compatibleMethod.isValidBinding()) {
            if (foundSize == 1 && compatibleMethod.canBeSeenBy(receiverType, invocationSite, this)) {
              // return the single visible match now
              if (searchForDefaultAbstractMethod)
                return findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, compatibleMethod);
              unitScope.recordTypeReferences(compatibleMethod.thrownExceptions);
              return compatibleMethod;
            }
            if (candidatesCount == 0)
              candidates = new MethodBinding[foundSize];
            candidates[candidatesCount++] = compatibleMethod;
          } else if (problemMethod == null) {
            problemMethod = compatibleMethod;
          }
        }
      }
    }

    // no match was found
    if (candidatesCount == 0) {
      if (problemMethod != null) {
        switch (problemMethod.problemId()) {
          case ProblemReasons.TypeArgumentsForRawGenericMethod :
          case ProblemReasons.TypeParameterArityMismatch :
            return problemMethod;
        }
      }
      // abstract classes may get a match in interfaces; for non abstract
      // classes, reduces secondary errors since missing interface method
      // error is already reported
      MethodBinding interfaceMethod =
        findDefaultAbstractMethod(receiverType, selector, argumentTypes, invocationSite, classHierarchyStart, found, null);
      if (interfaceMethod != null) return interfaceMethod;
      if (found.size == 0) return null;
      if (problemMethod != null) return problemMethod;

      // still no match; try to find a close match when the parameter
      // order is wrong or missing some parameters

      // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=69471
      // bad guesses are foo(), when argument types have been supplied
      // and foo(X, Y), when the argument types are (int, float, Y)
      // so answer the method with the most argType matches and least parameter type mismatches
      int bestArgMatches = -1;
      MethodBinding bestGuess = (MethodBinding) found.elementAt(0); // if no good match so just use the first one found
      int argLength = argumentTypes.length;
      foundSize = found.size;
      nextMethod : for (int i = 0; i < foundSize; i++) {
        MethodBinding methodBinding = (MethodBinding) found.elementAt(i);
        TypeBinding[] params = methodBinding.parameters;
        int paramLength = params.length;
        int argMatches = 0;
        next: for (int a = 0; a < argLength; a++) {
          TypeBinding arg = argumentTypes[a];
View Full Code Here

      // at this point the scope is a compilation unit scope & need to check for imported static methods
      CompilationUnitScope unitScope = (CompilationUnitScope) scope;
      unitScope.faultInImports(); // field constants can cause static imports to be accessed before they're resolved
      ImportBinding[] imports = unitScope.imports;
      if (imports != null) {
        ObjectVector visible = null;
        boolean skipOnDemand = false; // set to true when matched static import of method name so stop looking for on demand methods
        for (int i = 0, length = imports.length; i < length; i++) {
          ImportBinding importBinding = imports[i];
          if (importBinding.isStatic()) {
            Binding resolvedImport = importBinding.resolvedImport;
            MethodBinding possible = null;
            if (importBinding.onDemand) {
              if (!skipOnDemand && resolvedImport instanceof ReferenceBinding)
                // answers closest approximation, may not check argumentTypes or visibility
                possible = findMethod((ReferenceBinding) resolvedImport, selector, argumentTypes, invocationSite, true);
            } else {
              if (resolvedImport instanceof MethodBinding) {
                MethodBinding staticMethod = (MethodBinding) resolvedImport;
                if (CharOperation.equals(staticMethod.selector, selector))
                  // answers closest approximation, may not check argumentTypes or visibility
                  possible = findMethod(staticMethod.declaringClass, selector, argumentTypes, invocationSite, true);
              } else if (resolvedImport instanceof FieldBinding) {
                // check to see if there are also methods with the same name
                FieldBinding staticField = (FieldBinding) resolvedImport;
                if (CharOperation.equals(staticField.name, selector)) {
                  // must find the importRef's type again since the field can be from an inherited type
                  char[][] importName = importBinding.reference.tokens;
                  TypeBinding referencedType = getType(importName, importName.length - 1);
                  if (referencedType != null)
                    // answers closest approximation, may not check argumentTypes or visibility
                    possible = findMethod((ReferenceBinding) referencedType, selector, argumentTypes, invocationSite, true);
                }
              }
            }
            if (possible != null && possible != foundProblem) {
              if (!possible.isValidBinding()) {
                if (foundProblem == null)
                  foundProblem = possible; // answer as error case match
              } else if (possible.isStatic()) {
                MethodBinding compatibleMethod = computeCompatibleMethod(possible, argumentTypes, invocationSite);
                if (compatibleMethod != null) {
                  if (compatibleMethod.isValidBinding()) {
                    if (compatibleMethod.canBeSeenBy(unitScope.fPackage)) {
                      if (visible == null || !visible.contains(compatibleMethod)) {
                        ImportReference importReference = importBinding.reference;
                        if (importReference != null) {
                          importReference.bits |= ASTNode.Used;
                        }
                        if (!skipOnDemand && !importBinding.onDemand) {
                          visible = null; // forget previous matches from on demand imports
                          skipOnDemand = true;
                        }
                        if (visible == null)
                          visible = new ObjectVector(3);
                        visible.add(compatibleMethod);
                      }
                    } else if (foundProblem == null) {
                      foundProblem = new ProblemMethodBinding(compatibleMethod, selector, compatibleMethod.parameters, ProblemReasons.NotVisible);
                    }
                  } else if (foundProblem == null) {
                    foundProblem = compatibleMethod;
                  }
                } else if (foundProblem == null) {
                  foundProblem = new ProblemMethodBinding(possible, selector, argumentTypes, ProblemReasons.NotFound);
                }
              }
            }
          }
        }
        if (visible != null) {
          MethodBinding[] temp = new MethodBinding[visible.size];
          visible.copyInto(temp);
          foundMethod = mostSpecificMethodBinding(temp, temp.length, argumentTypes, invocationSite, null);
        }
      }
    }
View Full Code Here

            pkgFragmentRoots = new PackageFragmentRoot[] { oldRoot };
          }
        }
        if (pkgFragmentRoots == null) {
          try {
            ObjectVector accumulatedRoots = new ObjectVector();
            HashSet rootIDs = new HashSet(5);
            rootIDs.add(this.project.rootID());
            this.project.computePackageFragmentRoots(
              this.oldResolvedClasspath[i],
              accumulatedRoots,
              rootIDs,
              null, // inside original project
              false, // don't retrieve exported roots
              null); /*no reverse map*/
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335986
            // When a package fragment's corresponding resource is removed from the project,
            // IJavaProject#computePackageFragmentRoots() doesn't include that entry. Hence
            // the cache become necessary in such cases. Add the cache to the accumulatedRoots
            // only when it's not already present.
            RootInfo rootInfo = (RootInfo) state.oldRoots.get(this.oldResolvedClasspath[i].getPath());
            if (rootInfo != null && rootInfo.cache != null) {
              IPackageFragmentRoot oldRoot = rootInfo.cache;
              boolean found = false;
              for (int j = 0; j < accumulatedRoots.size(); j++) {
                IPackageFragmentRoot root = (IPackageFragmentRoot) accumulatedRoots.elementAt(j);
                if (!root.getPath().equals(oldRoot.getPath())) {
                  found = true;
                  break;
                }
              }
              if (!found)
                accumulatedRoots.add(oldRoot);
            }

            pkgFragmentRoots = new PackageFragmentRoot[accumulatedRoots.size()];
            accumulatedRoots.copyInto(pkgFragmentRoots);
          } catch (JavaModelException e) {
            pkgFragmentRoots =  new PackageFragmentRoot[] {};
          }
        }
        addClasspathDeltas(delta, pkgFragmentRoots, IJavaElementDelta.F_REMOVED_FROM_CLASSPATH);
View Full Code Here

      int length = projectsAndJars.length;
      JavaProject[] projectsCanSeeFocus = new JavaProject[length];
      SimpleSet visitedProjects = new SimpleSet(length);
      int projectIndex = 0;
      SimpleSet externalLibsToCheck = new SimpleSet(length);
      ObjectVector superTypes = new ObjectVector();
      IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
      char[][][] focusQualifiedNames = null;
      boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
      if (isAutoBuilding && focus instanceof IJavaProject) {
        focusQualifiedNames = getQualifiedNames(superTypes);
View Full Code Here

        scope,
        invocationSite,
        invocationScope,
        exactMatch,
        false,
        new ObjectVector(),
        new ObjectVector(),
        methodsFound,
        false,
        proposeMethod);
  }
View Full Code Here

          receiverType,
          scope,
          scope.enclosingSourceType(),
          false,
          true,
          new ObjectVector(),
          missingElements,
          missingElementsStarts,
          missingElementsEnds,
          missingElementsHaveProblems);
    }
    if (!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) {
      findClassField(
          token,
          receiverType,
          scope,
          missingElements,
          missingElementsStarts,
          missingElementsEnds,
          missingElementsHaveProblems);
    }

    MethodScope methodScope = null;
    if (!isInsideAnnotationAttribute &&
        !this.requestor.isIgnored(CompletionProposal.KEYWORD) &&
        ((scope instanceof MethodScope && !((MethodScope)scope).isStatic)
        || ((methodScope = scope.enclosingMethodScope()) != null && !methodScope.isStatic))) {
      if (token.length > 0) {
        findKeywords(token, new char[][]{Keywords.THIS}, false, true);
      } else {
        int relevance = computeBaseRelevance();
        relevance += computeRelevanceForResolution();
        relevance += computeRelevanceForInterestingProposal();
        relevance += computeRelevanceForCaseMatching(this.completionToken, Keywords.THIS);
        relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for keywords
        relevance += R_NON_INHERITED;

        this.noProposal = false;
        if (!this.requestor.isIgnored(CompletionProposal.KEYWORD)) {
          InternalCompletionProposal proposal =  createProposal(CompletionProposal.KEYWORD, this.actualCompletionPosition);
          proposal.setName(Keywords.THIS);
          proposal.setCompletion(Keywords.THIS);
          proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset);
          proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset);
          proposal.setRelevance(relevance);
          this.requestor.accept(proposal);
          if (DEBUG) {
            this.printDebug(proposal);
          }
        }
      }
    }

    if (!this.requestor.isIgnored(CompletionProposal.FIELD_REF)) {
      findFields(
        token,
        receiverType,
        scope,
        new ObjectVector(),
        new ObjectVector(),
        true,
        invocationSite,
        scope,
        false,
        false,
        missingElements,
        missingElementsStarts,
        missingElementsEnds,
        missingElementsHaveProblems,
        null,
        -1,
        -1);
    }

    if (!isInsideAnnotationAttribute && !this.requestor.isIgnored(CompletionProposal.METHOD_REF)) {
      findMethods(
        token,
        null,
        null,
        receiverType,
        scope,
        new ObjectVector(),
        true,
        false,
        invocationSite,
        scope,
        false,
View Full Code Here

                (ReferenceBinding)guessedType,
                scope,
                scope.enclosingSourceType(),
                false,
                false,
                new ObjectVector(),
                missingElements,
                missingElementsStarts,
                missingElementsEnds,
                hasProblems);
          }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.util.ObjectVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.