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

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


        }
        if (this.binding instanceof FieldBinding) {
          this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
          this.bits |= Binding.FIELD;
          FieldBinding fieldBinding = (FieldBinding) this.binding;
          MethodScope methodScope = scope.methodScope();
          ReferenceBinding declaringClass = fieldBinding.original().declaringClass;
          SourceTypeBinding sourceType = methodScope.enclosingSourceType();
          // check for forward references
          if ((this.indexOfFirstFieldBinding == 1 || (fieldBinding.modifiers & ClassFileConstants.AccEnum) != 0 || (!fieldBinding.isFinal() && declaringClass.isEnum())) // enum constants are checked even when qualified
              && sourceType == declaringClass
              && methodScope.lastVisibleFieldID >= 0
              && fieldBinding.id >= methodScope.lastVisibleFieldID
              && (!fieldBinding.isStatic() || methodScope.isStatic)) {
            if (methodScope.insideTypeAnnotation && fieldBinding.id == methodScope.lastVisibleFieldID) {
              // false alarm, location is NOT a field initializer but the value in a memberValuePair
            } else {
              scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
            }
          }
          if (isFieldUseDeprecated(fieldBinding, scope, this.indexOfFirstFieldBinding == this.tokens.length ? this.bits : 0)) {
            scope.problemReporter().deprecatedField(fieldBinding, this)
          }
          if (fieldBinding.isStatic()) {
            // only last field is actually a write access if any
            // check if accessing enum static field in initializer
            if (declaringClass.isEnum()) {
              if ((sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body
                  && fieldBinding.constant() == Constant.NotAConstant
                  && !methodScope.isStatic
                  && methodScope.isInsideInitializerOrConstructor()) {
                scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this);
              }
            }
            if (this.indexOfFirstFieldBinding > 1
                && fieldBinding.declaringClass != this.actualReceiverType
View Full Code Here


    // the return type should be void for a constructor.
    // the test is made into getConstructor

    // mark the fact that we are in a constructor call.....
    // unmark at all returns
    MethodScope methodScope = scope.methodScope();
    try {
      AbstractMethodDeclaration methodDeclaration = methodScope.referenceMethod();
      if (methodDeclaration == null
          || !methodDeclaration.isConstructor()
          || ((ConstructorDeclaration) methodDeclaration).constructorCall != this) {
        scope.problemReporter().invalidExplicitConstructorCall(this);
        // fault-tolerance
        if (this.qualification != null) {
          this.qualification.resolveType(scope);
        }
        if (this.typeArguments != null) {
          for (int i = 0, max = this.typeArguments.length; i < max; i++) {
            this.typeArguments[i].resolveType(scope, true /* check bounds*/);
          }
        }
        if (this.arguments != null) {
          for (int i = 0, max = this.arguments.length; i < max; i++) {
            this.arguments[i].resolveType(scope);
          }
        }
        return;
      }
      methodScope.isConstructorCall = true;
      ReferenceBinding receiverType = scope.enclosingReceiverType();
      boolean rcvHasError = false;
      if (this.accessMode != ExplicitConstructorCall.This) {
        receiverType = receiverType.superclass();
        TypeReference superclassRef = scope.referenceType().superclass;
        if (superclassRef != null && superclassRef.resolvedType != null && !superclassRef.resolvedType.isValidBinding()) {
          rcvHasError = true;
        }
      }
      if (receiverType != null) {
        // prevent (explicit) super constructor invocation from within enum
        if (this.accessMode == ExplicitConstructorCall.Super && receiverType.erasure().id == TypeIds.T_JavaLangEnum) {
          scope.problemReporter().cannotInvokeSuperConstructorInEnum(this, methodScope.referenceMethod().binding);
        }
        // qualification should be from the type of the enclosingType
        if (this.qualification != null) {
          if (this.accessMode != ExplicitConstructorCall.Super) {
            scope.problemReporter().unnecessaryEnclosingInstanceSpecification(
              this.qualification,
              receiverType);
          }
          if (!rcvHasError) {
            ReferenceBinding enclosingType = receiverType.enclosingType();
            if (enclosingType == null) {
              scope.problemReporter().unnecessaryEnclosingInstanceSpecification(this.qualification, receiverType);
              this.bits |= ASTNode.DiscardEnclosingInstance;
            } else {
              TypeBinding qTb = this.qualification.resolveTypeExpecting(scope, enclosingType);
              this.qualification.computeConversion(scope, qTb, qTb);
            }
          }
        }
      }
      // resolve type arguments (for generic constructor call)
      if (this.typeArguments != null) {
        boolean argHasError = scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_5;
        int length = this.typeArguments.length;
        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 (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;
        }
      }
      // arguments buffering for the method lookup
      TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
      boolean argsContainCast = false;
      if (this.arguments != null) {
        boolean argHasError = false; // typeChecks all arguments
        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) {
            argHasError = true;
          }
        }
        if (argHasError) {
          if (receiverType == null) {
            return;
          }
          // record a best guess, for clients who need hint about possible contructor match
          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(receiverType, 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;
              }
            }
          }
          return;
        }
      } else if (receiverType.erasure().id == TypeIds.T_JavaLangEnum) {
        // TODO (philippe) get rid of once well-known binding is available
        argumentTypes = new TypeBinding[] { scope.getJavaLangString(), TypeBinding.INT };
      }
      if (receiverType == null) {
        return;
      }
      if ((this.binding = scope.getConstructor(receiverType, argumentTypes, this)).isValidBinding()) {
        if ((this.binding.tagBits & TagBits.HasMissingType) != 0) {
          if (!methodScope.enclosingSourceType().isAnonymousType()) {
            scope.problemReporter().missingTypeInConstructor(this, this.binding);
          }
        }
        if (isMethodUseDeprecated(this.binding, scope, this.accessMode != ExplicitConstructorCall.ImplicitSuper)) {
          scope.problemReporter().deprecatedMethod(this.binding, this);
View Full Code Here

  FieldBinding fieldBinding = (FieldBinding) this.binding;
  this.constant = fieldBinding.constant();

  this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
  this.bits |= Binding.FIELD;
  MethodScope methodScope = scope.methodScope();
  if (fieldBinding.isStatic()) {
    // check if accessing enum static field in initializer
    ReferenceBinding declaringClass = fieldBinding.declaringClass;
    if (declaringClass.isEnum()) {
      SourceTypeBinding sourceType = scope.enclosingSourceType();
      if (this.constant == Constant.NotAConstant
          && !methodScope.isStatic
          && (sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body
          && methodScope.isInsideInitializerOrConstructor()) {
        scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this);
      }
    }
  } else {
    if (scope.compilerOptions().getSeverity(CompilerOptions.UnqualifiedFieldAccess) != ProblemSeverities.Ignore) {
      scope.problemReporter().unqualifiedFieldAccess(this, fieldBinding);
    }
    // must check for the static status....
    if (methodScope.isStatic) {
      scope.problemReporter().staticFieldAccessToNonStaticVariable(this, fieldBinding);
      return fieldBinding.type;
    }
  }

  if (isFieldUseDeprecated(fieldBinding, scope, this.bits))
    scope.problemReporter().deprecatedField(fieldBinding, this);

  if ((this.bits & ASTNode.IsStrictlyAssigned) == 0
      && methodScope.enclosingSourceType() == fieldBinding.original().declaringClass
      && methodScope.lastVisibleFieldID >= 0
      && fieldBinding.id >= methodScope.lastVisibleFieldID
      && (!fieldBinding.isStatic() || methodScope.isStatic)) {
    scope.problemReporter().forwardReference(this, 0, fieldBinding);
    this.bits |= ASTNode.IgnoreNoEffectAssignCheck;
View Full Code Here

      return; // still waiting to see more usages of this kind
  }
  // at this point we know we have something to report
  if (localBinding.declaration instanceof Argument) {
    // check compiler options to report against unused arguments
    MethodScope methodScope = currentScope.methodScope();
    if (methodScope != null) {
      MethodBinding method = ((AbstractMethodDeclaration)methodScope.referenceContext()).binding;
     
      boolean shouldReport = !method.isMain();
      if (method.isImplementing()) {
        shouldReport &= currentScope.compilerOptions().reportUnusedParameterWhenImplementingAbstract;
      } else if (method.isOverriding()) {
View Full Code Here

    if (visitor.visit(this, this.scope)) {
      if (this.types != null && isPackageInfo()) {
              // resolve synthetic type declaration
        final TypeDeclaration syntheticTypeDeclaration = this.types[0];
        // resolve javadoc package if any
        final MethodScope methodScope = syntheticTypeDeclaration.staticInitializerScope;
        // Don't traverse in null scope and invite trouble a la bug 252555.
        if (this.javadoc != null && methodScope != null) {
          this.javadoc.traverse(visitor, methodScope);
        }
        // Don't traverse in null scope and invite trouble a la bug 252555.
View Full Code Here

        && declaringClass.canBeSeenBy(scope)) {
      scope.problemReporter().indirectAccessToStaticField(this, fieldBinding);
    }
    // check if accessing enum static field in initializer
    if (declaringClass.isEnum()) {
      MethodScope methodScope = scope.methodScope();
      SourceTypeBinding sourceType = scope.enclosingSourceType();
      if (this.constant == Constant.NotAConstant
          && !methodScope.isStatic
          && (sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body
          && methodScope.isInsideInitializerOrConstructor()) {
        scope.problemReporter().enumStaticFieldUsedDuringInitialization(this.binding, this);
      }
    }
  }
  TypeBinding fieldType = fieldBinding.type;
View Full Code Here

TOP

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

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.