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
              && TypeBinding.equalsEquals(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 ((TypeBinding.equalsEquals(sourceType, declaringClass) || TypeBinding.equalsEquals(sourceType.superclass, declaringClass)) // enum constant body
                  && fieldBinding.constant() == Constant.NotAConstant
                  && !methodScope.isStatic
                  && methodScope.isInsideInitializerOrConstructor()) {
                scope.problemReporter().enumStaticFieldUsedDuringInitialization(fieldBinding, this);
              }
            }
            if (this.indexOfFirstFieldBinding > 1
                && TypeBinding.notEquals(fieldBinding.declaringClass, this.actualReceiverType)
View Full Code Here


    arguments,
    nodeSourceStart(binding, location),
    nodeSourceEnd(binding, location));
}
private boolean methodHasMissingSwitchDefault() {
  MethodScope methodScope = null;
  if (this.referenceContext instanceof Block) {
    methodScope = ((Block)this.referenceContext).scope.methodScope();
  } else if (this.referenceContext instanceof AbstractMethodDeclaration) {
    methodScope = ((AbstractMethodDeclaration)this.referenceContext).scope;
  }
View Full Code Here

            return newElement;
          }
          return parentElement;
        }
        IType parentType = (IType) createElement(scope.parent, elementPosition, unit, existingElements, knownScopes);
        MethodScope methodScope = (MethodScope) scope;
        if (methodScope.isInsideInitializer()) {
          // inside field or initializer, must find proper one
          TypeDeclaration type = methodScope.referenceType();
          int occurenceCount = 1;
          int length = type.fields == null ? 0 : type.fields.length;
          for (int i = 0; i < length; i++) {
            FieldDeclaration field = type.fields[i];
            if (field.declarationSourceStart <= elementPosition && elementPosition <= field.declarationSourceEnd) {
              switch (field.getKind()) {
                case AbstractVariableDeclaration.FIELD :
                case AbstractVariableDeclaration.ENUM_CONSTANT :
                  newElement = parentType.getField(new String(field.name));
                  break;
                case AbstractVariableDeclaration.INITIALIZER :
                  newElement = parentType.getInitializer(occurenceCount);
                  break;
              }
              break;
            } else if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
              occurenceCount++;
            }
          }
        } else {
          // method element
          AbstractMethodDeclaration method = methodScope.referenceMethod();
          newElement = parentType.getMethod(new String(method.selector), Util.typeParameterSignatures(method));
          if (newElement != null) {
            knownScopes.put(scope, newElement);
          }
        }
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

    // 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)
      long sourceLevel = scope.compilerOptions().sourceLevel;
      if (this.typeArguments != null) {
        boolean argHasError = 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;
          }
          argument.setExpressionContext(INVOCATION_CONTEXT);
          if ((argumentTypes[i] = argument.resolveType(scope)) == null) {
            argHasError = true;
          }
          if (sourceLevel >= ClassFileConstants.JDK1_8 && argument.isPolyExpression()) {
            if (this.innerInferenceHelper == null)
              this.innerInferenceHelper = new InnerInferenceHelper();
          }
        }
        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, false);
          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;
      }
      this.binding = findConstructorBinding(scope, this, receiverType, argumentTypes);

      if (this.binding.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

      switch (currentScope.kind) {

        case Scope.METHOD_SCOPE :
          // handle the error case inside an explicit constructor call (see MethodScope>>findField)
          MethodScope methodScope = (MethodScope) currentScope;
          staticsOnly |= methodScope.isStatic | methodScope.isConstructorCall;
          //$FALL-THROUGH$
        case Scope.BLOCK_SCOPE :
          BlockScope blockScope = (BlockScope) currentScope;

          next : for (int i = 0, length = blockScope.locals.length; i < length; i++) {
            LocalVariableBinding local = blockScope.locals[i];

            if (local == null)
              break next;

            if (local.isSecret())
              continue next;
            // If the local variable declaration's initialization statement itself has the completion,
            // then don't propose the local variable
            if (local.declaration.initialization != null) {
              /*(use this if-else block if it is found that local.declaration.initialization != null is not sufficient to
                guarantee that proposal is being asked inside a local variable declaration's initializer)
               if(local.declaration.initialization.sourceEnd > 0) {
                if (this.assistNode.sourceEnd <= local.declaration.initialization.sourceEnd
                    && this.assistNode.sourceStart >= local.declaration.initialization.sourceStart) {
                  continue next;
                }
              } else {
                CompletionNodeDetector detector = new CompletionNodeDetector(
                    this.assistNode,
                    local.declaration.initialization);
                if (detector.containsCompletionNode()) {
                  continue next;
                }
              }*/
              continue next;
            }
            for (int f = 0; f < localsFound.size; f++) {
              LocalVariableBinding otherLocal =
                (LocalVariableBinding) localsFound.elementAt(f);
              if (CharOperation.equals(otherLocal.name, local.name, true))
                continue next;
            }

            localsFound.add(local);
          }
          break;

        case Scope.COMPILATION_UNIT_SCOPE :
          break done1;
      }
      currentScope = currentScope.parent;
    }

    staticsOnly = false;
    currentScope = scope;

    done2 : while (true) { // done when a COMPILATION_UNIT_SCOPE is found

      switch (currentScope.kind) {
        case Scope.METHOD_SCOPE :
          // handle the error case inside an explicit constructor call (see MethodScope>>findField)
          MethodScope methodScope = (MethodScope) currentScope;
          staticsOnly |= methodScope.isStatic | methodScope.isConstructorCall;
          break;
        case Scope.CLASS_SCOPE :
          ClassScope classScope = (ClassScope) currentScope;
          SourceTypeBinding enclosingType = classScope.referenceContext.binding;
View Full Code Here

/**
* Check and/or redirect the field access to the delegate receiver if any
*/
public TypeBinding checkFieldAccess(BlockScope scope) {
  FieldBinding fieldBinding = (FieldBinding) this.binding;
  MethodScope methodScope = scope.methodScope();
  TypeBinding declaringClass = fieldBinding.original().declaringClass;
  // check for forward references
  if ((this.indexOfFirstFieldBinding == 1 || declaringClass.isEnum())
      && TypeBinding.equalsEquals(methodScope.enclosingSourceType(), declaringClass)
      && methodScope.lastVisibleFieldID >= 0
      && fieldBinding.id >= methodScope.lastVisibleFieldID
      && (!fieldBinding.isStatic() || methodScope.isStatic)) {
    scope.problemReporter().forwardReference(this, this.indexOfFirstFieldBinding-1, fieldBinding);
  }
View Full Code Here

    this.isImplicit = isImplicit;
  }
 
  public boolean checkAccess(BlockScope scope, ReferenceBinding thisType) {
    // this/super cannot be used in constructor call
    MethodScope methodScope = scope.methodScope();
    if (this.evaluationContext.isConstructorCall) {
      methodScope.problemReporter().fieldsOrThisBeforeConstructorInvocation(this);
      return false;
    }

    // static may not refer to this/super
    if (this.evaluationContext.declaringTypeName == null || this.evaluationContext.isStatic) {
      methodScope.problemReporter().errorThisSuperInStatic(this);
      return false;
    }
    scope.tagAsAccessingEnclosingInstanceStateOf(thisType, false /* type variable access */);
    return true;
  }
View Full Code Here

 
  public TypeBinding resolveType(BlockScope scope) {
    // implicit this
    this.constant = Constant.NotAConstant;
    ReferenceBinding snippetType = scope.enclosingSourceType();
    MethodScope methodScope = scope.methodScope();
    if (!this.isImplicit && !checkAccess(scope, snippetType)) {
      return null;
    }

    this.delegateThis = scope.getField(snippetType, DELEGATE_THIS, this);
    if (this.delegateThis == null || !this.delegateThis.isValidBinding()) {
      // should not happen
      // if this happen we should report illegal access to this in a static context
      methodScope.problemReporter().errorThisSuperInStatic(this);
      return null;
    }
    return this.resolvedType = this.delegateThis.type;
  }
View Full Code Here

      }

      if (field.isStatic()) {
        if ((field.modifiers & ClassFileConstants.AccEnum) != 0) { // enum constants are checked even when qualified)
          ReferenceBinding declaringClass = field.original().declaringClass;
          MethodScope methodScope = scope.methodScope();
          SourceTypeBinding sourceType = methodScope.enclosingSourceType();
          if ((this.bits & ASTNode.IsStrictlyAssigned) == 0
              && sourceType == declaringClass
              && methodScope.lastVisibleFieldID >= 0
              && field.id >= methodScope.lastVisibleFieldID
              && (!field.isStatic() || methodScope.isStatic)) {
            scope.problemReporter().forwardReference(this, index, field);
          }         
          // check if accessing enum static field in initializer
          if ((sourceType == declaringClass || sourceType.superclass == declaringClass) // enum constant body
              && field.constant() == Constant.NotAConstant
              && !methodScope.isStatic
              && methodScope.isInsideInitializerOrConstructor()) {
            scope.problemReporter().enumStaticFieldUsedDuringInitialization(field, this);
          }
        }
        // static field accessed through receiver? legal but unoptimal (optional warning)
        scope.problemReporter().nonStaticAccessToStaticField(this, field, index);
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.