Package org.eclipse.jdt.internal.compiler.lookup

Examples of org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding


    return null;
  }

  synchronized IAnnotationBinding getAnnotationInstance(org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalInstance) {
    if (internalInstance == null) return null;
    ReferenceBinding annotationType = internalInstance.getAnnotationType();
    if (!this.isRecoveringBindings) {
      if (annotationType == null || ((annotationType.tagBits & TagBits.HasMissingType) != 0)) {
        return null;
      }
    }
View Full Code Here


            } else  if (binding instanceof ProblemFieldBinding) {
              ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding;
              switch(problemFieldBinding.problemId()) {
                case ProblemReasons.NotVisible :
                case ProblemReasons.NonStaticReferenceInStaticContext :
                  ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
                  if (declaringClass != null) {
                    FieldBinding exactBinding = declaringClass.getField(tokens[tokens.length - 1], true /*resolve*/);
                    if (exactBinding != null) {
                      if (exactBinding.type != null) {
                        IVariableBinding variableBinding = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
                        if (variableBinding != null) {
                          return variableBinding;
                        }
                        variableBinding = new VariableBinding(this, exactBinding);
                        this.bindingTables.compilerBindingsToASTBindings.put(exactBinding, variableBinding);
                        return variableBinding;
                      }
                    }
                  }
                  break;
              }
            }
          }
        }
      } else {
        /* This is the case for a name which is part of a qualified name that
         * cannot be resolved. See PR 13063.
         */
        if (qualifiedNameReference.otherBindings == null || (index - indexOfFirstFieldBinding - 1) < 0) {
          return null;
        } else {
          return this.getVariableBinding(qualifiedNameReference.otherBindings[index - indexOfFirstFieldBinding - 1]);
        }
      }
    } else if (node instanceof QualifiedTypeReference) {
      QualifiedTypeReference qualifiedTypeReference = (QualifiedTypeReference) node;
      if (qualifiedTypeReference.resolvedType == null) {
        return null;
      }
      if (index == qualifiedTypeReference.tokens.length) {
        if (!qualifiedTypeReference.resolvedType.isValidBinding() && qualifiedTypeReference instanceof JavadocQualifiedTypeReference) {
          JavadocQualifiedTypeReference typeRef = (JavadocQualifiedTypeReference) node;
          if (typeRef.packageBinding != null) {
            return getPackageBinding(typeRef.packageBinding);
          }
        }
        return this.getTypeBinding(qualifiedTypeReference.resolvedType.leafComponentType());
      } else {
        if (index >= 0) {
          BlockScope internalScope = (BlockScope) this.astNodesToBlockScope.get(name);
          Binding binding = null;
          try {
            if (internalScope == null) {
              if (this.scope == null) return null;
              binding = this.scope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
            } else {
              binding = internalScope.getTypeOrPackage(CharOperation.subarray(qualifiedTypeReference.tokens, 0, index));
            }
          } catch (AbortCompilation e) {
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
          }
          if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
            return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
          } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
            // it is a type
            return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
          } else {
            return null;
          }
        }
      }
    } else if (node instanceof ImportReference) {
      ImportReference importReference = (ImportReference) node;
      int importReferenceLength = importReference.tokens.length;
      if (index >= 0) {
        Binding binding = null;
        if (this.scope == null) return null;
        if (importReferenceLength == index) {
          try {
            binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), (importReference.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.OnDemand) != 0, importReference.isStatic());
          } catch (AbortCompilation e) {
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
          }
        } else {
          try {
            binding = this.scope.getImport(CharOperation.subarray(importReference.tokens, 0, index), true, importReference.isStatic());
          } catch (AbortCompilation e) {
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
          }
        }
        if (binding != null) {
          if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
            return getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding)binding);
          } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.TypeBinding) {
            // it is a type
            return this.getTypeBinding((org.eclipse.jdt.internal.compiler.lookup.TypeBinding)binding);
          } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.FieldBinding) {
            // it is a type
            return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.FieldBinding)binding);
          } else if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.MethodBinding) {
            // it is a type
            return getMethodBinding((org.eclipse.jdt.internal.compiler.lookup.MethodBinding)binding);
          } else {
            return null;
          }
        }
      }
    } else if (node instanceof CompilationUnitDeclaration) {
      CompilationUnitDeclaration compilationUnitDeclaration = (CompilationUnitDeclaration) node;
      org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types;
      if (types == null || types.length == 0) {
        return null;
      }
      org.eclipse.jdt.internal.compiler.ast.TypeDeclaration type = types[0];
      if (type != null) {
        ITypeBinding typeBinding = this.getTypeBinding(type.binding);
        if (typeBinding != null) {
          return typeBinding.getPackage();
        }
      }
    } else if (node instanceof AbstractMethodDeclaration) {
      AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) node;
      IMethodBinding methodBinding = getMethodBinding(methodDeclaration.binding);
      if (methodBinding != null) {
        return methodBinding;
      }
    } else if (node instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
      org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) node;
      ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
      if (typeBinding != null) {
        return typeBinding;
      }
    } if (node instanceof SingleNameReference) {
      SingleNameReference singleNameReference = (SingleNameReference) node;
      if (singleNameReference.isTypeReference()) {
        return this.getTypeBinding(singleNameReference.resolvedType);
      } else {
        // this is a variable or a field
        Binding binding = singleNameReference.binding;
        if (binding != null) {
          if (binding.isValidBinding()) {
            return this.getVariableBinding((org.eclipse.jdt.internal.compiler.lookup.VariableBinding) binding);
          } else {
            /*
             * http://dev.eclipse.org/bugs/show_bug.cgi?id=24449
             */
            if (binding instanceof ProblemFieldBinding) {
              ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) binding;
              switch(problemFieldBinding.problemId()) {
                case ProblemReasons.NotVisible :
                case ProblemReasons.NonStaticReferenceInStaticContext :
                case ProblemReasons.NonStaticReferenceInConstructorInvocation :
                  ReferenceBinding declaringClass = problemFieldBinding.declaringClass;
                  FieldBinding exactBinding = declaringClass.getField(problemFieldBinding.name, true /*resolve*/);
                  if (exactBinding != null) {
                    if (exactBinding.type != null) {
                      IVariableBinding variableBinding2 = (IVariableBinding) this.bindingTables.compilerBindingsToASTBindings.get(exactBinding);
                      if (variableBinding2 != null) {
                        return variableBinding2;
View Full Code Here

    if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
      ReferenceBinding[] interfacesToVisit = itsInterfaces;
      int nextPosition = interfacesToVisit.length;

      for (int i = 0; i < nextPosition; i++) {
        ReferenceBinding currentType = interfacesToVisit[i];
        MethodBinding[] methods = currentType.availableMethods();
        if(methods != null) {
          searchVisibleLocalMethods(
              methods,
              receiverType,
              scope,
              invocationSite,
              invocationScope,
              onlyStaticMethods,
              methodsFound);
        }

        itsInterfaces = currentType.superInterfaces();
        if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) {
          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;
          }
        }
View Full Code Here

      InvocationSite invocationSite,
      Scope invocationScope,
      boolean onlyStaticMethods,
      boolean notInJavadoc,
      ObjectVector methodsFound) {
    ReferenceBinding currentType = receiverType;
    if (notInJavadoc) {
      if (receiverType.isInterface()) {
        searchVisibleInterfaceMethods(
            new ReferenceBinding[]{currentType},
            receiverType,
            scope,
            invocationSite,
            invocationScope,
            onlyStaticMethods,
            methodsFound);

        currentType = scope.getJavaLangObject();
      }
    }
    boolean hasPotentialDefaultAbstractMethods = true;
    while (currentType != null) {

      MethodBinding[] methods = currentType.availableMethods();
      if (methods != null) {
        searchVisibleLocalMethods(
            methods,
            receiverType,
            scope,
            invocationSite,
            invocationScope,
            onlyStaticMethods,
            methodsFound);
      }

      if (notInJavadoc &&
          hasPotentialDefaultAbstractMethods &&
          (currentType.isAbstract() ||
              currentType.isTypeVariable() ||
              currentType.isIntersectionType() ||
              currentType.isEnum())){

        ReferenceBinding[] superInterfaces = currentType.superInterfaces();
        if (superInterfaces != null && currentType.isIntersectionType()) {
          for (int i = 0; i < superInterfaces.length; i++) {
            superInterfaces[i] = (ReferenceBinding)superInterfaces[i].capture(invocationScope, invocationSite.sourceEnd());
          }
        }

        searchVisibleInterfaceMethods(
            superInterfaces,
            receiverType,
            scope,
            invocationSite,
            invocationScope,
            onlyStaticMethods,
            methodsFound);
      } else {
        hasPotentialDefaultAbstractMethods = false;
      }
      if(currentType.isParameterizedType()) {
        currentType = ((ParameterizedTypeBinding)currentType).genericType().superclass();
      } else {
        currentType = currentType.superclass();
      }
    }
  }
View Full Code Here

        ImportReference importReference = (ImportReference) node;
        Binding binding = this.scope.getTypeOrPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length));
        if ((binding != null) && (binding.isValidBinding())) {
          if (binding instanceof ReferenceBinding) {
            // this only happens if a type name has the same name as its package
            ReferenceBinding referenceBinding = (ReferenceBinding) binding;
            binding = referenceBinding.fPackage;
          }
          if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
            IPackageBinding packageBinding = getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding);
            if (packageBinding == null) {
View Full Code Here

  public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
    if (!valueRequired)
      currentScope.problemReporter().unusedObjectAllocation(this);
    int pc = codeStream.position;
    MethodBinding codegenBinding = this.binding.original();
    ReferenceBinding allocatedType = codegenBinding.declaringClass;
    codeStream.new_(allocatedType);
    boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
    if (valueRequired || isUnboxing) {
      codeStream.dup();
    }
    // better highlight for allocation: display the type individually
    if (this.type != null) { // null for enum constant body
      codeStream.recordPositionsFrom(pc, this.type.sourceStart);
    } else {
      // push enum constant name and ordinal
      codeStream.ldc(String.valueOf(this.enumConstant.name));
      codeStream.generateInlinedValue(this.enumConstant.binding.id);
    }
    // handling innerclass instance allocation - enclosing instance arguments
    if (allocatedType.isNestedType()) {
      codeStream.generateSyntheticEnclosingInstanceValues(
        currentScope,
        allocatedType,
        enclosingInstance(),
        this);
    }
    // generate the arguments for constructor
    generateArguments(this.binding, this.arguments, currentScope, codeStream);
    // handling innerclass instance allocation - outer local arguments
    if (allocatedType.isNestedType()) {
      codeStream.generateSyntheticOuterArgumentValues(
        currentScope,
        allocatedType,
        this);
    }
View Full Code Here

   * types, since by the time we reach them, we might not yet know their
   * exact need.
   */
  public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
    if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0)  {
    ReferenceBinding allocatedTypeErasure = (ReferenceBinding) this.binding.declaringClass.erasure();

    // perform some extra emulation work in case there is some and we are inside a local type only
    if (allocatedTypeErasure.isNestedType()
      && currentScope.enclosingSourceType().isLocalType()) {

      if (allocatedTypeErasure.isLocalType()) {
        ((LocalTypeBinding) allocatedTypeErasure).addInnerEmulationDependent(currentScope, this.enclosingInstance != null);
      } else {
        // locally propagate, since we already now the desired shape for sure
        currentScope.propagateInnerEmulation(allocatedTypeErasure, this.enclosingInstance != null);
      }
View Full Code Here

    // ClassInstanceCreationExpression ::= Primary '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt
    // ClassInstanceCreationExpression ::= Name '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt

    this.constant = Constant.NotAConstant;
    TypeBinding enclosingInstanceType = null;
    ReferenceBinding enclosingInstanceReference = null;
    TypeBinding receiverType = null;
    boolean hasError = false;
    boolean enclosingInstanceContainsCast = false;
    boolean argsContainCast = false;

    if (this.enclosingInstance != null) {
      if (this.enclosingInstance instanceof CastExpression) {
        this.enclosingInstance.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
        enclosingInstanceContainsCast = true;
      }
      if ((enclosingInstanceType = this.enclosingInstance.resolveType(scope)) == null){
        hasError = true;
      } else if (enclosingInstanceType.isBaseType() || enclosingInstanceType.isArrayType()) {
        scope.problemReporter().illegalPrimitiveOrArrayTypeForEnclosingInstance(
          enclosingInstanceType,
          this.enclosingInstance);
        hasError = true;
      } else if (this.type instanceof QualifiedTypeReference) {
        scope.problemReporter().illegalUsageOfQualifiedTypeReference((QualifiedTypeReference)this.type);
        hasError = true;
      } else if (!(enclosingInstanceReference = (ReferenceBinding) enclosingInstanceType).canBeSeenBy(scope)) {
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=317212
        enclosingInstanceType = new ProblemReferenceBinding(
              enclosingInstanceReference.compoundName,
              enclosingInstanceReference,
              ProblemReasons.NotVisible);
        scope.problemReporter().invalidType(this.enclosingInstance, enclosingInstanceType);
        hasError = true;
      } else {
        receiverType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingInstanceType);
        if (receiverType != null && enclosingInstanceContainsCast) {
          CastExpression.checkNeedForEnclosingInstanceCast(scope, this.enclosingInstance, enclosingInstanceType, receiverType);
        }
      }
    } else {
      if (this.type == null) {
        // initialization of an enum constant
        receiverType = scope.enclosingSourceType();
      } else {
        receiverType = this.type.resolveType(scope, true /* check bounds*/);
        checkParameterizedAllocation: {
          if (receiverType == null || !receiverType.isValidBinding()) break checkParameterizedAllocation;
          if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
            ReferenceBinding currentType = (ReferenceBinding)receiverType;
            do {
              // isStatic() is answering true for toplevel types
              if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
              if (currentType.isRawType()) break checkParameterizedAllocation;
            } while ((currentType = currentType.enclosingType())!= null);
            ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
            for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
              if (qRef.typeArguments[i] != null) {
                scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, receiverType);
                break;
              }
            }
          }
        }
      }
    }
    if (receiverType == null || !receiverType.isValidBinding()) {
      hasError = true;
    }

    // resolve type arguments (for generic constructor call)
    final boolean isDiamond = this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0;
    if (this.typeArguments != null) {
      int length = this.typeArguments.length;
      boolean argHasError = scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_5;
      this.genericTypeArguments = new TypeBinding[length];
      for (int i = 0; i < length; i++) {
        TypeReference typeReference = this.typeArguments[i];
        if ((this.genericTypeArguments[i] = typeReference.resolveType(scope, true /* check bounds*/)) == null) {
          argHasError = true;
        }
        if (argHasError && typeReference instanceof Wildcard) {
          scope.problemReporter().illegalUsageOfWildcard(typeReference);
        }
      }
      if (isDiamond) {
        scope.problemReporter().diamondNotWithExplicitTypeArguments(this.typeArguments);
        return null;
      }
      if (argHasError) {
        if (this.arguments != null) { // still attempt to resolve arguments
          for (int i = 0, max = this.arguments.length; i < max; i++) {
            this.arguments[i].resolveType(scope);
          }
        }
        return null;
      }
    }

    // will check for null after args are resolved
    TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
    if (this.arguments != null) {
      int length = this.arguments.length;
      argumentTypes = new TypeBinding[length];
      for (int i = 0; i < length; i++) {
        Expression argument = this.arguments[i];
        if (argument instanceof CastExpression) {
          argument.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
          argsContainCast = true;
        }
        if ((argumentTypes[i] = argument.resolveType(scope)) == null){
          hasError = true;
        }
      }
    }

    // limit of fault-tolerance
    if (hasError) {
      /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=345359, if arguments have errors, completely bail out in the <> case.
         No meaningful type resolution is possible since inference of the elided types is fully tied to argument types. Do
         not return the partially resolved type.
       */
      if (isDiamond) {
        return null; // not the partially cooked this.resolvedType
      }
      if (receiverType instanceof ReferenceBinding) {
        ReferenceBinding referenceReceiver = (ReferenceBinding) receiverType;
        if (receiverType.isValidBinding()) {
          // record a best guess, for clients who need hint about possible contructor match
          int length = this.arguments  == null ? 0 : this.arguments.length;
          TypeBinding[] pseudoArgs = new TypeBinding[length];
          for (int i = length; --i >= 0;) {
            pseudoArgs[i] = argumentTypes[i] == null ? TypeBinding.NULL : argumentTypes[i]; // replace args with errors with null type
          }
          this.binding = scope.findMethod(referenceReceiver, TypeConstants.INIT, pseudoArgs, this);
          if (this.binding != null && !this.binding.isValidBinding()) {
            MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
            // record the closest match, for clients who may still need hint about possible method match
            if (closestMatch != null) {
              if (closestMatch.original().typeVariables != Binding.NO_TYPE_VARIABLES) { // generic method
                // shouldn't return generic method outside its context, rather convert it to raw method (175409)
                closestMatch = scope.environment().createParameterizedGenericMethod(closestMatch.original(), (RawTypeBinding)null);
              }
              this.binding = closestMatch;
              MethodBinding closestMatchOriginal = closestMatch.original();
              if (closestMatchOriginal.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(closestMatchOriginal)) {
                // ignore cases where method is used from within inside itself (e.g. direct recursions)
                closestMatchOriginal.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
              }
            }
          }
        }
        if (this.anonymousType != null) {
          // insert anonymous type in scope (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=210070)
          scope.addAnonymousType(this.anonymousType, referenceReceiver);
          this.anonymousType.resolve(scope);
          return this.resolvedType = this.anonymousType.binding;
        }
      }
      return this.resolvedType = receiverType;
    }
    if (this.anonymousType == null) {
      // qualified allocation with no anonymous type
      if (!receiverType.canBeInstantiated()) {
        scope.problemReporter().cannotInstantiate(this.type, receiverType);
        return this.resolvedType = receiverType;
      }
      if (isDiamond) {
        TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) receiverType).genericType(), receiverType.enclosingType(), argumentTypes, scope);
        if (inferredTypes == null) {
          scope.problemReporter().cannotInferElidedTypes(this);
          return this.resolvedType = null;
        }
        receiverType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) receiverType).genericType(), inferredTypes, ((ParameterizedTypeBinding) receiverType).enclosingType());
      }
      ReferenceBinding allocationType = (ReferenceBinding) receiverType;
      if ((this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
        if (isMethodUseDeprecated(this.binding, scope, true)) {
          scope.problemReporter().deprecatedMethod(this.binding, this);
        }
        if (checkInvocationArguments(scope, null, allocationType, this.binding, this.arguments, argumentTypes, argsContainCast, this)) {
          this.bits |= ASTNode.Unchecked;
        }
        if (this.typeArguments != null && this.binding.original().typeVariables == Binding.NO_TYPE_VARIABLES) {
          scope.problemReporter().unnecessaryTypeArgumentsForMethodInvocation(this.binding, this.genericTypeArguments, this.typeArguments);
        }
      } else {
        if (this.binding.declaringClass == null) {
          this.binding.declaringClass = allocationType;
        }
        if (this.type != null && !this.type.resolvedType.isValidBinding()) {
          // problem already got signaled on type reference, do not report secondary problem
          return null;
        }
        scope.problemReporter().invalidConstructor(this, this.binding);
        return this.resolvedType = receiverType;
      }
      if ((this.binding.tagBits & TagBits.HasMissingType) != 0) {
        scope.problemReporter().missingTypeInConstructor(this, this.binding);
      }
      if (!isDiamond && receiverType.isParameterizedTypeWithActualArguments()) {
         checkTypeArgumentRedundancy((ParameterizedTypeBinding)receiverType, receiverType.enclosingType(), argumentTypes , scope);
       }
      // The enclosing instance must be compatible with the innermost enclosing type
      ReferenceBinding expectedType = this.binding.declaringClass.enclosingType();
      if (expectedType != enclosingInstanceType) // must call before computeConversion() and typeMismatchError()
        scope.compilationUnitScope().recordTypeConversion(expectedType, enclosingInstanceType);
      if (enclosingInstanceType.isCompatibleWith(expectedType) || scope.isBoxingCompatibleWith(enclosingInstanceType, expectedType)) {
        this.enclosingInstance.computeConversion(scope, expectedType, enclosingInstanceType);
        return this.resolvedType = receiverType;
      }
      scope.problemReporter().typeMismatchError(enclosingInstanceType, expectedType, this.enclosingInstance, null);
      return this.resolvedType = receiverType;
    } else {
      if (isDiamond) {
        scope.problemReporter().diamondNotWithAnoymousClasses(this.type);
        return null;
     
    }
    ReferenceBinding superType = (ReferenceBinding) receiverType;
    if (superType.isTypeVariable()) {
      superType = new ProblemReferenceBinding(new char[][]{superType.sourceName()}, superType, ProblemReasons.IllegalSuperTypeVariable);
      scope.problemReporter().invalidType(this, superType);
      return null;
    } else if (this.type != null && superType.isEnum()) { // tolerate enum constant body
      scope.problemReporter().cannotInstantiate(this.type, superType);
      return this.resolvedType = superType;
    }
    // anonymous type scenario
    // an anonymous class inherits from java.lang.Object when declared "after" an interface
    ReferenceBinding anonymousSuperclass = superType.isInterface() ? scope.getJavaLangObject() : superType;
    // insert anonymous type in scope
    scope.addAnonymousType(this.anonymousType, superType);
    this.anonymousType.resolve(scope);

    // find anonymous super constructor
    this.resolvedType = this.anonymousType.binding; // 1.2 change
    if ((this.resolvedType.tagBits & TagBits.HierarchyHasProblems) != 0) {
      return null; // stop secondary errors
    }
    MethodBinding inheritedBinding = scope.getConstructor(anonymousSuperclass, argumentTypes, this);
    if (!inheritedBinding.isValidBinding()) {
      if (inheritedBinding.declaringClass == null) {
        inheritedBinding.declaringClass = anonymousSuperclass;
      }
      if (this.type != null && !this.type.resolvedType.isValidBinding()) {
        // problem already got signaled on type reference, do not report secondary problem
        return null;
      }
      scope.problemReporter().invalidConstructor(this, inheritedBinding);
      return this.resolvedType;
    }
    if ((inheritedBinding.tagBits & TagBits.HasMissingType) != 0) {
      scope.problemReporter().missingTypeInConstructor(this, inheritedBinding);
    }
    if (this.enclosingInstance != null) {
      ReferenceBinding targetEnclosing = inheritedBinding.declaringClass.enclosingType();
      if (targetEnclosing == null) {
        scope.problemReporter().unnecessaryEnclosingInstanceSpecification(this.enclosingInstance, superType);
        return this.resolvedType;
      } else if (!enclosingInstanceType.isCompatibleWith(targetEnclosing) && !scope.isBoxingCompatibleWith(enclosingInstanceType, targetEnclosing)) {
        scope.problemReporter().typeMismatchError(enclosingInstanceType, targetEnclosing, this.enclosingInstance, null);
View Full Code Here

        }
      }
    }

    if (this.referenceBinding.isHierarchyInconsistent()) {
      ReferenceBinding superclass = this.referenceBinding.superclass;
      if (superclass != null) {
        this.missingTypes = superclass.collectMissingTypes(this.missingTypes);
      }
      ReferenceBinding[] superInterfaces = this.referenceBinding.superInterfaces();
      for (int i = 0, max = superInterfaces.length; i < max; i++) {
        this.missingTypes = superInterfaces[i].collectMissingTypes(this.missingTypes);
      }
View Full Code Here

    this.contents[localContentsOffset++] = (byte) (value >> 8);
    this.contents[localContentsOffset++] = (byte) value;
    this.contents[localContentsOffset++] = (byte) (numberOfInnerClasses >> 8);
    this.contents[localContentsOffset++] = (byte) numberOfInnerClasses;
    for (int i = 0; i < numberOfInnerClasses; i++) {
      ReferenceBinding innerClass = innerClasses[i];
      int accessFlags = innerClass.getAccessFlags();
      int innerClassIndex = this.constantPool.literalIndexForType(innerClass.constantPoolName());
      // inner class index
      this.contents[localContentsOffset++] = (byte) (innerClassIndex >> 8);
      this.contents[localContentsOffset++] = (byte) innerClassIndex;
      // outer class index: anonymous and local have no outer class index
      if (innerClass.isMemberType()) {
        // member or member of local
        int outerClassIndex = this.constantPool.literalIndexForType(innerClass.enclosingType().constantPoolName());
        this.contents[localContentsOffset++] = (byte) (outerClassIndex >> 8);
        this.contents[localContentsOffset++] = (byte) outerClassIndex;
      } else {
        // equals to 0 if the innerClass is not a member type
        this.contents[localContentsOffset++] = 0;
        this.contents[localContentsOffset++] = 0;
      }
      // name index
      if (!innerClass.isAnonymousType()) {
        int nameIndex = this.constantPool.literalIndex(innerClass.sourceName());
        this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
        this.contents[localContentsOffset++] = (byte) nameIndex;
      } else {
        // equals to 0 if the innerClass is an anonymous type
        this.contents[localContentsOffset++] = 0;
        this.contents[localContentsOffset++] = 0;
      }
      // access flag
      if (innerClass.isAnonymousType()) {
        accessFlags &= ~ClassFileConstants.AccFinal;
      } else if (innerClass.isMemberType() && innerClass.isInterface()) {
        accessFlags |= ClassFileConstants.AccStatic; // implicitely static
      }
      this.contents[localContentsOffset++] = (byte) (accessFlags >> 8);
      this.contents[localContentsOffset++] = (byte) accessFlags;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding

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.