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

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


  protected void reset() {

    super.reset(false);
    this.validPackageNames = new SimpleSetOfCharArray(10);
    this.invalidPackageNames = new SimpleSetOfCharArray(1);
    this.knownPkgs = new HashtableOfObject(10);
    this.knownTypes = new HashtableOfObject(10);
    if (this.noCacheNameEnvironment != null) {
      this.noCacheNameEnvironment.cleanup();
      this.noCacheNameEnvironment = null;
      JavaModelManager.getJavaModelManager().flushZipFiles(this);
    }
View Full Code Here


      IProgressMonitor monitor) {
    super(settings);
    this.javaProject = javaProject;
    this.requestor = requestor;
    this.nameEnvironment = nameEnvironment;
    this.typeCache = new HashtableOfObject(5);
    this.openedBinaryTypes = 0;
    this.sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
    this.complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);

    this.problemFactory = new CompletionProblemFactory(Locale.getDefault());
View Full Code Here

    int length = this.acceptedConstructors.size();

    if(length == 0) return;
   
    HashtableOfObject onDemandFound = new HashtableOfObject();
   
    ArrayList deferredProposals = null;
    if (DEFER_QUALIFIED_PROPOSALS) {
      deferredProposals = new ArrayList();
    }
   
    try {
      next : for (int i = 0; i < length; i++) {
       
        // does not check cancellation for every types to avoid performance loss
        if ((i % CHECK_CANCEL_FREQUENCY) == 0) checkCancel();
       
        AcceptedConstructor acceptedConstructor = (AcceptedConstructor)this.acceptedConstructors.elementAt(i);
        final int typeModifiers = acceptedConstructor.typeModifiers;
        final char[] packageName = acceptedConstructor.packageName;
        final char[] simpleTypeName = acceptedConstructor.simpleTypeName;
        final int modifiers = acceptedConstructor.modifiers;
        final int parameterCount = acceptedConstructor.parameterCount;
        final char[] signature = acceptedConstructor.signature;
        final char[][] parameterTypes = acceptedConstructor.parameterTypes;
        final char[][] parameterNames = acceptedConstructor.parameterNames;
        final int extraFlags = acceptedConstructor.extraFlags;
        final int accessibility = acceptedConstructor.accessibility;
       
        boolean proposeType = hasArrayTypeAsExpectedSuperTypes() || (extraFlags & ExtraFlags.HasNonPrivateStaticMemberTypes) != 0;
       
        char[] fullyQualifiedName = CharOperation.concat(packageName, simpleTypeName, '.');
           
        Object knownTypeKind = this.knownTypes.get(fullyQualifiedName);
        if (knownTypeKind != null) {
          if (knownTypeKind == KNOWN_TYPE_WITH_KNOWN_CONSTRUCTORS) {
            // the type and its constructors are already accepted
            continue next;
          }
          // this type is already accepted
          proposeType = false;
        } else {
          this.knownTypes.put(fullyQualifiedName, KNOWN_TYPE_WITH_UNKNOWN_CONSTRUCTORS);
        }
       
        boolean proposeConstructor = true;
         
        if (this.options.checkVisibility) {
          if((modifiers & ClassFileConstants.AccPublic) == 0) {
            if((modifiers & ClassFileConstants.AccPrivate) != 0) {
              if (!proposeType) continue next;
              proposeConstructor = false;
            } else {
              if (this.currentPackageName == null) {
                initializePackageCache();
              }
             
              if(!CharOperation.equals(packageName, this.currentPackageName)) {
               
                if((typeModifiers & ClassFileConstants.AccAbstract) == 0 ||
                    (modifiers & ClassFileConstants.AccProtected) == 0) {
                  if (!proposeType) continue next;
                  proposeConstructor = false;
                }
              }
            }
          }
        }
       
        acceptedConstructor.fullyQualifiedName = fullyQualifiedName;
        acceptedConstructor.proposeType = proposeType;
        acceptedConstructor.proposeConstructor = proposeConstructor;
       
       
        if(!this.importCachesInitialized) {
          initializeImportCaches();
        }
       
        for (int j = 0; j < this.importCacheCount; j++) {
          char[][] importName = this.importsCache[j];
          if(CharOperation.equals(simpleTypeName, importName[0])) {
            if (proposeType) {
              proposeType(
                  packageName,
                  simpleTypeName,
                  typeModifiers,
                  accessibility,
                  simpleTypeName,
                  fullyQualifiedName,
                  !CharOperation.equals(fullyQualifiedName, importName[1]),
                  scope);
            }
           
            if (proposeConstructor && !Flags.isEnum(typeModifiers)) {
              boolean isQualified = !CharOperation.equals(fullyQualifiedName, importName[1]);
              if (!isQualified) {
                proposeConstructor(
                    simpleTypeName,
                    parameterCount,
                    signature,
                    parameterTypes,
                    parameterNames,
                    modifiers,
                    packageName,
                    typeModifiers,
                    accessibility,
                    simpleTypeName,
                    fullyQualifiedName,
                    isQualified,
                    scope,
                    extraFlags);
              } else {
                acceptedConstructor.mustBeQualified = true;
                if (DEFER_QUALIFIED_PROPOSALS) {
                  deferredProposals.add(acceptedConstructor);
                } else {
                  proposeConstructor(acceptedConstructor, scope);
                }
              }
            }
            continue next;
          }
        }


        if (CharOperation.equals(this.currentPackageName, packageName)) {
          if (proposeType) {
            proposeType(
                packageName,
                simpleTypeName,
                typeModifiers,
                accessibility,
                simpleTypeName,
                fullyQualifiedName,
                false,
                scope);
          }
         
          if (proposeConstructor && !Flags.isEnum(typeModifiers)) {
            proposeConstructor(
                simpleTypeName,
                parameterCount,
                signature,
                parameterTypes,
                parameterNames,
                modifiers,
                packageName,
                typeModifiers,
                accessibility,
                simpleTypeName,
                fullyQualifiedName,
                false,
                scope,
                extraFlags);
          }
          continue next;
        } else {
          char[] fullyQualifiedEnclosingTypeOrPackageName = null;

          AcceptedConstructor foundConstructor = null;
          if((foundConstructor = (AcceptedConstructor)onDemandFound.get(simpleTypeName)) == null) {
            for (int j = 0; j < this.onDemandImportCacheCount; j++) {
              ImportBinding importBinding = this.onDemandImportsCache[j];

              char[][] importName = importBinding.compoundName;
              char[] importFlatName = CharOperation.concatWith(importName, '.');

              if(fullyQualifiedEnclosingTypeOrPackageName == null) {
                fullyQualifiedEnclosingTypeOrPackageName = packageName;
              }
              if(CharOperation.equals(fullyQualifiedEnclosingTypeOrPackageName, importFlatName)) {
                if(importBinding.isStatic()) {
                  if((typeModifiers & ClassFileConstants.AccStatic) != 0) {
                    onDemandFound.put(
                        simpleTypeName,
                        acceptedConstructor);
                    continue next;
                  }
                } else {
                  onDemandFound.put(
                      simpleTypeName,
                      acceptedConstructor);
                  continue next;
                }
              }
View Full Code Here

    int length = this.acceptedTypes.size();

    if(length == 0) return;

    HashtableOfObject onDemandFound = new HashtableOfObject();
   
    try {
      next : for (int i = 0; i < length; i++) {
       
        // does not check cancellation for every types to avoid performance loss
        if ((i % CHECK_CANCEL_FREQUENCY) == 0) checkCancel();
       
        AcceptedType acceptedType = (AcceptedType)this.acceptedTypes.elementAt(i);
        char[] packageName = acceptedType.packageName;
        char[] simpleTypeName = acceptedType.simpleTypeName;
        char[][] enclosingTypeNames = acceptedType.enclosingTypeNames;
        int modifiers = acceptedType.modifiers;
        int accessibility = acceptedType.accessibility;
 
        char[] typeName;
        char[] flatEnclosingTypeNames;
        if(enclosingTypeNames == null || enclosingTypeNames.length == 0) {
          flatEnclosingTypeNames = null;
          typeName = simpleTypeName;
        } else {
          flatEnclosingTypeNames = CharOperation.concatWith(acceptedType.enclosingTypeNames, '.');
          typeName = CharOperation.concat(flatEnclosingTypeNames, simpleTypeName, '.');
        }
        char[] fullyQualifiedName = CharOperation.concat(packageName, typeName, '.');
 
        if (this.knownTypes.containsKey(fullyQualifiedName)) continue next;
 
        this.knownTypes.put(fullyQualifiedName, KNOWN_TYPE_WITH_UNKNOWN_CONSTRUCTORS);
 
        if (this.resolvingImports) {
          if(this.compilerOptions.complianceLevel >= ClassFileConstants.JDK1_4 && packageName.length == 0) {
            continue next; // import of default package is forbidden when compliance is 1.4 or higher
          }
 
          char[] completionName = this.insideQualifiedReference ? simpleTypeName : fullyQualifiedName;
 
          if(this.resolvingStaticImports) {
            if(enclosingTypeNames == null || enclosingTypeNames.length == 0) {
              completionName = CharOperation.concat(completionName, new char[] { '.' });
            } else if ((modifiers & ClassFileConstants.AccStatic) == 0) {
              continue next;
            } else {
              completionName = CharOperation.concat(completionName, new char[] { ';' });
            }
          } else {
            completionName = CharOperation.concat(completionName, new char[] { ';' });
          }
 
          int relevance = computeBaseRelevance();
          relevance += computeRelevanceForResolution();
          relevance += computeRelevanceForInterestingProposal(packageName, fullyQualifiedName);
          relevance += computeRelevanceForRestrictions(accessibility);
          relevance += computeRelevanceForCaseMatching(this.completionToken, simpleTypeName);
 
          this.noProposal = false;
          if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
            createTypeProposal(packageName, typeName, modifiers, accessibility, completionName, relevance);
          }
        } else {
          if(!this.importCachesInitialized) {
            initializeImportCaches();
          }
 
          for (int j = 0; j < this.importCacheCount; j++) {
            char[][] importName = this.importsCache[j];
            if(CharOperation.equals(typeName, importName[0])) {
              proposeType(
                  packageName,
                  simpleTypeName,
                  modifiers,
                  accessibility,
                  typeName,
                  fullyQualifiedName,
                  !CharOperation.equals(fullyQualifiedName, importName[1]),
                  scope);
              continue next;
            }
          }
 
 
          if ((enclosingTypeNames == null || enclosingTypeNames.length == 0 ) && CharOperation.equals(this.currentPackageName, packageName)) {
            proposeType(
                packageName,
                simpleTypeName,
                modifiers,
                accessibility,
                typeName,
                fullyQualifiedName,
                false,
                scope);
            continue next;
          } else {
            char[] fullyQualifiedEnclosingTypeOrPackageName = null;
 
            AcceptedType foundType = null;
            if((foundType = (AcceptedType)onDemandFound.get(simpleTypeName)) == null) {
              for (int j = 0; j < this.onDemandImportCacheCount; j++) {
                ImportBinding importBinding = this.onDemandImportsCache[j];
 
                char[][] importName = importBinding.compoundName;
                char[] importFlatName = CharOperation.concatWith(importName, '.');
 
                if(fullyQualifiedEnclosingTypeOrPackageName == null) {
                  if(enclosingTypeNames != null && enclosingTypeNames.length != 0) {
                    fullyQualifiedEnclosingTypeOrPackageName =
                      CharOperation.concat(
                          packageName,
                          flatEnclosingTypeNames,
                          '.');
                  } else {
                    fullyQualifiedEnclosingTypeOrPackageName =
                      packageName;
                  }
                }
                if(CharOperation.equals(fullyQualifiedEnclosingTypeOrPackageName, importFlatName)) {
                  if(importBinding.isStatic()) {
                    if((modifiers & ClassFileConstants.AccStatic) != 0) {
                      acceptedType.qualifiedTypeName = typeName;
                      acceptedType.fullyQualifiedName = fullyQualifiedName;
                      onDemandFound.put(
                          simpleTypeName,
                          acceptedType);
                      continue next;
                    }
                  } else {
                    acceptedType.qualifiedTypeName = typeName;
                    acceptedType.fullyQualifiedName = fullyQualifiedName;
                    onDemandFound.put(
                        simpleTypeName,
                        acceptedType);
                    continue next;
                  }
                }
View Full Code Here

  int waitingPolicy,  // WaitUntilReadyToSearch | ForceImmediateSearch | CancelIfNotReadyToSearch
  final IProgressMonitor progressMonitor) {

  /* embed constructs inside arrays so as to pass them to (inner) collector */
  final Queue queue = new Queue();
  final HashtableOfObject foundSuperNames = new HashtableOfObject(5);

  IndexManager indexManager = JavaModelManager.getIndexManager();

  /* use a special collector to collect paths and queue new subtype names */
  IndexQueryRequestor searchRequestor = new IndexQueryRequestor() {
    public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) {
      SuperTypeReferencePattern record = (SuperTypeReferencePattern)indexRecord;
      boolean isLocalOrAnonymous = record.enclosingTypeName == IIndexConstants.ONE_ZERO;
      pathRequestor.acceptPath(documentPath, isLocalOrAnonymous);
      char[] typeName = record.simpleName;
      if (documentPath.toLowerCase().endsWith(SUFFIX_STRING_class)) {
          int suffix = documentPath.length()-SUFFIX_STRING_class.length();
        HierarchyBinaryType binaryType = (HierarchyBinaryType)binariesFromIndexMatches.get(documentPath);
        if (binaryType == null){
          char[] enclosingTypeName = record.enclosingTypeName;
          if (isLocalOrAnonymous) {
            int lastSlash = documentPath.lastIndexOf('/');
            int lastDollar = documentPath.lastIndexOf('$');
            if (lastDollar == -1) {
              // malformed local or anonymous type: it doesn't contain a $ in its name
              // treat it as a top level type
              enclosingTypeName = null;
              typeName = documentPath.substring(lastSlash+1, suffix).toCharArray();
            } else {
              enclosingTypeName = documentPath.substring(lastSlash+1, lastDollar).toCharArray();
              typeName = documentPath.substring(lastDollar+1, suffix).toCharArray();
            }
          }
          binaryType = new HierarchyBinaryType(record.modifiers, record.pkgName, typeName, enclosingTypeName, record.typeParameterSignatures, record.classOrInterface);
          binariesFromIndexMatches.put(documentPath, binaryType);
        }
        binaryType.recordSuperType(record.superSimpleName, record.superQualification, record.superClassOrInterface);
      }
      if (!isLocalOrAnonymous // local or anonymous types cannot have subtypes outside the cu that define them
          && !foundSuperNames.containsKey(typeName)){
        foundSuperNames.put(typeName, typeName);
        queue.add(typeName);
      }
      return true;
    }
  };
View Full Code Here

    this.totalUnits = 0;
    this.unitsToProcess = new CompilationUnitDeclaration[maxUnits];
    int index = 0;

    // walks the source units
    this.requestedSources = new HashtableOfObject();
    for (int i = 0; i < sourceLength; i++) {
      org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = sourceUnits[i];
      CompilationUnitDeclaration parsedUnit;
      CompilationResult unitResult =
        new CompilationResult(sourceUnit, index++, maxUnits, this.options.maxProblemsPerUnit);
      try {
        if (this.options.verbose) {
          this.out.println(
            Messages.bind(Messages.compilation_request,
            new String[] {
              String.valueOf(index++ + 1),
              String.valueOf(maxUnits),
              new String(sourceUnit.getFileName())
            }));
        }
        // diet parsing for large collection of units
        if (this.totalUnits < this.parseThreshold) {
          parsedUnit = this.parser.parse(sourceUnit, unitResult);
        } else {
          parsedUnit = this.parser.dietParse(sourceUnit, unitResult);
        }
        // initial type binding creation
        this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
        addCompilationUnit(sourceUnit, parsedUnit);
        this.requestedSources.put(unitResult.getFileName(), sourceUnit);
        worked(1);
      } finally {
        sourceUnits[i] = null; // no longer hold onto the unit
      }
    }

    // walk the binding keys
    this.requestedKeys = new HashtableOfObject();
    for (int i = 0; i < keyLength; i++) {
      BindingKeyResolver resolver = new BindingKeyResolver(bindingKeys[i], this, this.lookupEnvironment);
      resolver.parse(true/*pause after fully qualified name*/);
      // If it doesn't have a type name, then it is either an array type, package or base type, which will definitely not have a compilation unit.
      // Skipping it will speed up performance because the call will open jars. (theodora)
View Full Code Here

*  Build the set of compilation source units
*/
public CompilationUnit[] getCompilationUnits() {
  int fileCount = this.filenames.length;
  CompilationUnit[] units = new CompilationUnit[fileCount];
  HashtableOfObject knownFileNames = new HashtableOfObject(fileCount);

  String defaultEncoding = (String) this.options.get(CompilerOptions.OPTION_Encoding);
  if (Util.EMPTY_STRING.equals(defaultEncoding))
    defaultEncoding = null;

  for (int i = 0; i < fileCount; i++) {
    char[] charName = this.filenames[i].toCharArray();
    if (knownFileNames.get(charName) != null)
      throw new IllegalArgumentException(this.bind("unit.more", this.filenames[i])); //$NON-NLS-1$
    knownFileNames.put(charName, charName);
    File file = new File(this.filenames[i]);
    if (!file.exists())
      throw new IllegalArgumentException(this.bind("unit.missing", this.filenames[i])); //$NON-NLS-1$
    String encoding = this.encodings[i];
    if (encoding == null)
View Full Code Here

    TypeVariableBinding var = this.type.typeVariables[i];
    // must verify bounds if the variable has more than 1
    if (var.superInterfaces == Binding.NO_SUPERINTERFACES) continue;
    if (var.superInterfaces.length == 1 && var.superclass.id == TypeIds.T_JavaLangObject) continue;

    this.currentMethods = new HashtableOfObject(0);
    ReferenceBinding superclass = var.superclass();
    if (superclass.kind() == Binding.TYPE_PARAMETER)
      superclass = (ReferenceBinding) superclass.erasure();
    ReferenceBinding[] itsInterfaces = var.superInterfaces();
    ReferenceBinding[] superInterfaces = new ReferenceBinding[itsInterfaces.length];
View Full Code Here

*/
void computeInheritedMethods(ReferenceBinding superclass, ReferenceBinding[] superInterfaces) {
  // only want to remember inheritedMethods that can have an impact on the current type
  // if an inheritedMethod has been 'replaced' by a supertype's method then skip it, however
    // see usage of canOverridingMethodDifferInErasure below.
  this.inheritedMethods = new HashtableOfObject(51); // maps method selectors to an array of methods... must search to match paramaters & return type

  ReferenceBinding superType = superclass;
  HashtableOfObject nonVisibleDefaultMethods = new HashtableOfObject(3); // maps method selectors to an array of methods

  while (superType != null && superType.isValidBinding()) {

    MethodBinding[] methods = superType.unResolvedMethods();
    nextMethod : for (int m = methods.length; --m >= 0;) {
      MethodBinding inheritedMethod = methods[m];
      if (inheritedMethod.isPrivate() || inheritedMethod.isConstructor() || inheritedMethod.isDefaultAbstract())
        continue nextMethod;
      MethodBinding[] existingMethods = (MethodBinding[]) this.inheritedMethods.get(inheritedMethod.selector);
      if (existingMethods != null) {
        existing : for (int i = 0, length = existingMethods.length; i < length; i++) {
          MethodBinding existingMethod = existingMethods[i];
          // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358, skip inherited method only if any overriding version
          // in a subclass is guaranteed to have the same erasure as an existing method.
          if (TypeBinding.notEquals(existingMethod.declaringClass, inheritedMethod.declaringClass) && areMethodsCompatible(existingMethod, inheritedMethod) && !canOverridingMethodDifferInErasure(existingMethod, inheritedMethod)) {
            if (inheritedMethod.isDefault()) {
              if (inheritedMethod.isAbstract()) {
                checkPackagePrivateAbstractMethod(inheritedMethod);
              } else if (existingMethod.declaringClass.fPackage != inheritedMethod.declaringClass.fPackage) {
                if (this.type.fPackage == inheritedMethod.declaringClass.fPackage && !areReturnTypesCompatible(inheritedMethod, existingMethod))
                  continue existing; // may need to record incompatible return type
              }
            }
            continue nextMethod;
          }
        }
      }

      if (!inheritedMethod.isDefault() || inheritedMethod.declaringClass.fPackage == this.type.fPackage) {
        if (existingMethods == null) {
          existingMethods = new MethodBinding[] {inheritedMethod};
        } else {
          int length = existingMethods.length;
          System.arraycopy(existingMethods, 0, existingMethods = new MethodBinding[length + 1], 0, length);
          existingMethods[length] = inheritedMethod;
        }
        this.inheritedMethods.put(inheritedMethod.selector, existingMethods);
      } else {
        MethodBinding[] nonVisible = (MethodBinding[]) nonVisibleDefaultMethods.get(inheritedMethod.selector);
        if (nonVisible != null)
          for (int i = 0, l = nonVisible.length; i < l; i++)
            if (areMethodsCompatible(nonVisible[i], inheritedMethod))
              continue nextMethod;
        if (nonVisible == null) {
          nonVisible = new MethodBinding[] {inheritedMethod};
        } else {
          int length = nonVisible.length;
          System.arraycopy(nonVisible, 0, nonVisible = new MethodBinding[length + 1], 0, length);
          nonVisible[length] = inheritedMethod;
        }
        nonVisibleDefaultMethods.put(inheritedMethod.selector, nonVisible);

        if (inheritedMethod.isAbstract() && !this.type.isAbstract()) // non visible abstract methods cannot be overridden so the type must be defined abstract
          problemReporter().abstractMethodCannotBeOverridden(this.type, inheritedMethod);

        MethodBinding[] current = (MethodBinding[]) this.currentMethods.get(inheritedMethod.selector);
View Full Code Here

  return false;   // the case for <= 1.4  (cannot differ)
}
void computeMethods() {
  MethodBinding[] methods = this.type.methods();
  int size = methods.length;
  this.currentMethods = new HashtableOfObject(size == 0 ? 1 : size); // maps method selectors to an array of methods... must search to match paramaters & return type
  for (int m = size; --m >= 0;) {
    MethodBinding method = methods[m];
    if (!(method.isConstructor() || method.isDefaultAbstract())) { // keep all methods which are NOT constructors or default abstract
      MethodBinding[] existingMethods = (MethodBinding[]) this.currentMethods.get(method.selector);
      if (existingMethods == null)
View Full Code Here

TOP

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

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.