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

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


        return foundType;
    }

    // at this point the scope is a compilation unit scope
    CompilationUnitScope unitScope = (CompilationUnitScope) scope;
    HashtableOfObject typeOrPackageCache = unitScope.typeOrPackageCache;
    if (typeOrPackageCache != null) {
      Binding cachedBinding = (Binding) typeOrPackageCache.get(name);
      if (cachedBinding != null) { // can also include NotFound ProblemReferenceBindings if we already know this name is not found
        if (cachedBinding instanceof ImportBinding) { // single type import cached in faultInImports(), replace it in the cache with the type
          ImportReference importReference = ((ImportBinding) cachedBinding).reference;
          if (importReference != null) {
            importReference.bits |= ASTNode.Used;
          }
          if (cachedBinding instanceof ImportConflictBinding)
            typeOrPackageCache.put(name, cachedBinding = ((ImportConflictBinding) cachedBinding).conflictingTypeBinding); // already know its visible
          else
            typeOrPackageCache.put(name, cachedBinding = ((ImportBinding) cachedBinding).resolvedImport); // already know its visible
        }
        if ((mask & Binding.TYPE) != 0) {
          if (foundType != null && foundType.problemId() != ProblemReasons.NotVisible && cachedBinding.problemId() != ProblemReasons.Ambiguous)
            return foundType; // problem type from above supercedes NotFound type but not Ambiguous import case
          if (cachedBinding instanceof ReferenceBinding)
            return cachedBinding; // cached type found in previous walk below
        }
        if ((mask & Binding.PACKAGE) != 0 && cachedBinding instanceof PackageBinding)
          return cachedBinding; // cached package found in previous walk below
      }
    }

    // ask for the imports + name
    if ((mask & Binding.TYPE) != 0) {
      ImportBinding[] imports = unitScope.imports;
      if (imports != null && typeOrPackageCache == null) { // walk single type imports since faultInImports() has not run yet
        nextImport : for (int i = 0, length = imports.length; i < length; i++) {
          ImportBinding importBinding = imports[i];
          if (!importBinding.onDemand) {
            if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
              Binding resolvedImport = unitScope.resolveSingleImport(importBinding, Binding.TYPE);
              if (resolvedImport == null) continue nextImport;
              if (resolvedImport instanceof TypeBinding) {
                ImportReference importReference = importBinding.reference;
                if (importReference != null)
                  importReference.bits |= ASTNode.Used;
                return resolvedImport; // already know its visible
              }
            }
          }
        }
      }

      // check if the name is in the current package, skip it if its a sub-package
      PackageBinding currentPackage = unitScope.fPackage;
      unitScope.recordReference(currentPackage.compoundName, name);
      Binding binding = currentPackage.getTypeOrPackage(name);
      if (binding instanceof ReferenceBinding) {
        ReferenceBinding referenceType = (ReferenceBinding) binding;
        if ((referenceType.tagBits & TagBits.HasMissingType) == 0) {
          if (typeOrPackageCache != null)
            typeOrPackageCache.put(name, referenceType);
          return referenceType; // type is always visible to its own package
        }
      }

      // check on demand imports
      if (imports != null) {
        boolean foundInImport = false;
        ReferenceBinding type = null;
        for (int i = 0, length = imports.length; i < length; i++) {
          ImportBinding someImport = imports[i];
          if (someImport.onDemand) {
            Binding resolvedImport = someImport.resolvedImport;
            ReferenceBinding temp = null;
            if (resolvedImport instanceof PackageBinding) {
              temp = findType(name, (PackageBinding) resolvedImport, currentPackage);
            } else if (someImport.isStatic()) {
              temp = findMemberType(name, (ReferenceBinding) resolvedImport); // static imports are allowed to see inherited member types
              if (temp != null && !temp.isStatic())
                temp = null;
            } else {
              temp = findDirectMemberType(name, (ReferenceBinding) resolvedImport);
            }
            if (temp != type && temp != null) {
              if (temp.isValidBinding()) {
                ImportReference importReference = someImport.reference;
                if (importReference != null) {
                  importReference.bits |= ASTNode.Used;
                }
                if (foundInImport) {
                  // Answer error binding -- import on demand conflict; name found in two import on demand packages.
                  temp = new ProblemReferenceBinding(new char[][]{name}, type, ProblemReasons.Ambiguous);
                  if (typeOrPackageCache != null)
                    typeOrPackageCache.put(name, temp);
                  return temp;
                }
                type = temp;
                foundInImport = true;
              } else if (foundType == null) {
                foundType = temp;
              }
            }
          }
        }
        if (type != null) {
          if (typeOrPackageCache != null)
            typeOrPackageCache.put(name, type);
          return type;
        }
      }
    }

    unitScope.recordSimpleReference(name);
    if ((mask & Binding.PACKAGE) != 0) {
      PackageBinding packageBinding = unitScope.environment.getTopLevelPackage(name);
      if (packageBinding != null) {
        if (typeOrPackageCache != null)
          typeOrPackageCache.put(name, packageBinding);
        return packageBinding;
      }
    }

    // Answer error binding -- could not find name
    if (foundType == null) {
      char[][] qName = new char[][] { name };
      ReferenceBinding closestMatch = null;
      if ((mask & Binding.PACKAGE) != 0 || unitScope.environment.getTopLevelPackage(name) == null) {
        if (needResolve) {
          closestMatch = environment().createMissingType(unitScope.fPackage, qName);
        }
      }
      foundType = new ProblemReferenceBinding(qName, closestMatch, ProblemReasons.NotFound);
      if (typeOrPackageCache != null && (mask & Binding.PACKAGE) != 0) { // only put NotFound type in cache if you know its not a package
        typeOrPackageCache.put(name, foundType);
      }
    } else if ((foundType.tagBits & TagBits.HasMissingType) != 0) {
      char[][] qName = new char[][] { name };
      foundType = new ProblemReferenceBinding(qName, foundType, ProblemReasons.NotFound);
      if (typeOrPackageCache != null && (mask & Binding.PACKAGE) != 0) // only put NotFound type in cache if you know its not a package
        typeOrPackageCache.put(name, foundType);
    }
    return foundType;
  }
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

      }
    }

    // iterate the field declarations to create the bindings, lose all duplicates
    FieldBinding[] fieldBindings = new FieldBinding[count];
    HashtableOfObject knownFieldNames = new HashtableOfObject(count);
    count = 0;
    for (int i = 0; i < size; i++) {
      FieldDeclaration field = fields[i];
      if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
        // We used to report an error for initializers declared inside interfaces, but
        // now this error reporting is moved into the parser itself. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=212713
      } else {
        FieldBinding fieldBinding = new FieldBinding(field, null, field.modifiers | ExtraCompilerModifiers.AccUnresolved, sourceType);
        fieldBinding.id = count;
        // field's type will be resolved when needed for top level types
        checkAndSetModifiersForField(fieldBinding, field);

        if (knownFieldNames.containsKey(field.name)) {
          FieldBinding previousBinding = (FieldBinding) knownFieldNames.get(field.name);
          if (previousBinding != null) {
            for (int f = 0; f < i; f++) {
              FieldDeclaration previousField = fields[f];
              if (previousField.binding == previousBinding) {
                problemReporter().duplicateFieldInType(sourceType, previousField);
                break;
              }
            }
          }
          knownFieldNames.put(field.name, null); // ensure that the duplicate field is found & removed
          problemReporter().duplicateFieldInType(sourceType, field);
          field.binding = null;
        } else {
          knownFieldNames.put(field.name, fieldBinding);
          // remember that we have seen a field with this name
          fieldBindings[count++] = fieldBinding;
        }
      }
    }
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

  public BindingKeyResolver(String key, Compiler compiler, LookupEnvironment environment) {
    super(key);
    this.compiler = compiler;
    this.environment = environment;
    this.resolvedUnits = new HashtableOfObject();
  }
View Full Code Here

  return results;
}
private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, Object docs, MemoryIndex memoryIndex, boolean prevResults) throws IOException {
  // must skip over documents which have been added/changed/deleted in the memory index
  if (results == null)
    results = new HashtableOfObject(13);
  EntryResult result = prevResults ? (EntryResult) results.get(word) : null;
  if (memoryIndex == null) {
    if (result == null)
      results.putUnsafely(word, new EntryResult(word, docs));
    else
View Full Code Here

}
HashtableOfObject addQueryResults(char[][] categories, char[] key, int matchRule, MemoryIndex memoryIndex) throws IOException {
  // assumes sender has called startQuery() & will call stopQuery() when finished
  if (this.categoryOffsets == null) return null; // file is empty

  HashtableOfObject results = null; // initialized if needed
 
  // No need to check the results table for duplicates while processing the
  // first category table or if the first category tables doesn't have any results.
  boolean prevResults = false;
  if (key == null) {
    for (int i = 0, l = categories.length; i < l; i++) {
      HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match
      if (wordsToDocNumbers != null) {
        char[][] words = wordsToDocNumbers.keyTable;
        Object[] values = wordsToDocNumbers.valueTable;
        if (results == null)
          results = new HashtableOfObject(wordsToDocNumbers.elementSize);
        for (int j = 0, m = words.length; j < m; j++)
          if (words[j] != null)
            results = addQueryResult(results, words[j], values[j], memoryIndex, prevResults);
      }
      prevResults = results != null;
    }
    if (results != null && this.cachedChunks == null)
      cacheDocumentNames();
  } else {
    switch (matchRule) {
      case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE:
        for (int i = 0, l = categories.length; i < l; i++) {
          HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false);
          Object value;
          if (wordsToDocNumbers != null && (value = wordsToDocNumbers.get(key)) != null)
            results = addQueryResult(results, key, value, memoryIndex, prevResults);
          prevResults = results != null;
        }
        break;
      case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE:
        for (int i = 0, l = categories.length; i < l; i++) {
          HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false);
          if (wordsToDocNumbers != null) {
            char[][] words = wordsToDocNumbers.keyTable;
            Object[] values = wordsToDocNumbers.valueTable;
            for (int j = 0, m = words.length; j < m; j++) {
              char[] word = words[j];
              if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word))
                results = addQueryResult(results, word, values[j], memoryIndex, prevResults);
            }
          }
          prevResults = results != null;
        }
        break;
      default:
        for (int i = 0, l = categories.length; i < l; i++) {
          HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false);
          if (wordsToDocNumbers != null) {
            char[][] words = wordsToDocNumbers.keyTable;
            Object[] values = wordsToDocNumbers.valueTable;
            for (int j = 0, m = words.length; j < m; j++) {
              char[] word = words[j];
View Full Code Here

  Object[] wordSets = categoryToWords.valueTable;
  for (int i = 0, l = categoryNames.length; i < l; i++) {
    char[] categoryName = categoryNames[i];
    if (categoryName != null) {
      SimpleWordSet wordSet = (SimpleWordSet) wordSets[i];
      HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName);
      if (wordsToDocs == null)
        this.categoryTables.put(categoryName, wordsToDocs = new HashtableOfObject(wordSet.elementSize));

      char[][] words = wordSet.words;
      for (int j = 0, m = words.length; j < m; j++) {
        char[] word = words[j];
        if (word != null) {
          Object o = wordsToDocs.get(word);
          if (o == null) {
            wordsToDocs.putUnsafely(word, new int[] {newPosition});
          } else if (o instanceof IntList) {
            ((IntList) o).add(newPosition);
          } else {
            IntList list = new IntList((int[]) o);
            list.add(newPosition);
            wordsToDocs.put(word, list);
          }
        }
      }
    }
  }
View Full Code Here

  }

  int size = diskIndex.categoryOffsets == null ? 8 : diskIndex.categoryOffsets.elementSize;
  this.categoryOffsets = new HashtableOfIntValues(size);
  this.categoryEnds = new HashtableOfIntValues(size);
  this.categoryTables = new HashtableOfObject(size);
  this.separator = diskIndex.separator;
}
View Full Code Here

    if (categoryNames[i] != null)
      mergeCategory(categoryNames[i], onDisk, positions, stream);
  this.categoryTables = null;
}
private void mergeCategory(char[] categoryName, DiskIndex onDisk, int[] positions, FileOutputStream stream) throws IOException {
  HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName);
  if (wordsToDocs == null)
    wordsToDocs = new HashtableOfObject(3);

  HashtableOfObject oldWordsToDocs = onDisk.readCategoryTable(categoryName, true);
  if (oldWordsToDocs != null) {
    char[][] oldWords = oldWordsToDocs.keyTable;
    Object[] oldArrayOffsets = oldWordsToDocs.valueTable;
    nextWord: for (int i = 0, l = oldWords.length; i < l; i++) {
      char[] oldWord = oldWords[i];
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.