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

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


*/
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

  this.inheritedMethods = new HashtableOfObject(51); // maps method selectors to an array of methods... must search to match paramaters & return type
  ReferenceBinding[] interfacesToVisit = null;
  int nextPosition = 0;
  ReferenceBinding[] itsInterfaces = superInterfaces;
  if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
    nextPosition = itsInterfaces.length;
    interfacesToVisit = itsInterfaces;
  }

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

  while (superType != null && superType.isValidBinding()) {
      if (allSuperclassesAreAbstract) {
        if (superType.isAbstract()) {
        // only need to include superinterfaces if immediate superclasses are abstract
        if ((itsInterfaces = superType.superInterfaces()) != Binding.NO_SUPERINTERFACES) {
          if (interfacesToVisit == null) {
            interfacesToVisit = itsInterfaces;
            nextPosition = interfacesToVisit.length;
          } else {
            int itsLength = itsInterfaces.length;
            if (nextPosition + itsLength >= interfacesToVisit.length)
              System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
            nextInterface : for (int a = 0; a < itsLength; a++) {
              ReferenceBinding next = itsInterfaces[a];
              for (int b = 0; b < nextPosition; b++)
                if (next == interfacesToVisit[b]) continue nextInterface;
              interfacesToVisit[nextPosition++] = next;
            }
          }
        }
      } else {
          allSuperclassesAreAbstract = false;
      }
    }

    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) {
        for (int i = 0, length = existingMethods.length; i < length; i++) {
          if (existingMethods[i].declaringClass != inheritedMethod.declaringClass && areMethodsCompatible(existingMethods[i], inheritedMethod)) {
            if (inheritedMethod.isDefault() && inheritedMethod.isAbstract())
              checkPackagePrivateAbstractMethod(inheritedMethod);
            continue nextMethod;
          }
        }
      }
      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 (!inheritedMethod.isDefault() || inheritedMethod.declaringClass.fPackage == 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 {
        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


  } else {
    methods = type.methods();
  }
  // End AspectJ Extension
  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

        return foundType;
    }

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

      }
    }

    // iterate the field declarations to create the bindings, lose all duplicates
    FieldBinding[] fieldBindings = new FieldBinding[count];
    HashtableOfObject knownFieldNames = new HashtableOfObject(count);
    boolean duplicate = false;
    count = 0;
    for (int i = 0; i < size; i++) {
      FieldDeclaration field = fields[i];
      if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
        if (sourceType.isInterface())
          problemReporter().interfaceCannotHaveInitializers(sourceType, field);
      } 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)) {
          duplicate = true;
          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);
                previousField.binding = null;
                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;
        }
      }
    }
    // remove duplicate fields
    if (duplicate) {
      FieldBinding[] newFieldBindings = new FieldBinding[fieldBindings.length];
      // we know we'll be removing at least 1 duplicate name
      size = count;
      count = 0;
      for (int i = 0; i < size; i++) {
        FieldBinding fieldBinding = fieldBindings[i];
        if (knownFieldNames.get(fieldBinding.name) != null) {
          fieldBinding.id = count;
          newFieldBindings[count++] = fieldBinding;
        }
      }
      fieldBindings = newFieldBindings;
View Full Code Here

TOP

Related Classes of org.aspectj.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.