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

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


      return synthetic;
    }

    private JMethodBody findEnclosingMethod(BlockScope scope) {
      JMethod method;
      MethodScope methodScope = scope.methodScope();
      if (methodScope.isInsideInitializer()) {
        JDeclaredType enclosingType = (JDeclaredType) typeMap.get(scope.classScope().referenceContext.binding);
        if (methodScope.isStatic) {
          // clinit
          method = enclosingType.getMethods().get(0);
        } else {
          // init
          assert (enclosingType instanceof JClassType);
          method = enclosingType.getMethods().get(1);
        }
      } else {
        AbstractMethodDeclaration referenceMethod = methodScope.referenceMethod();
        method = (JMethod) typeMap.get(referenceMethod.binding);
      }
      assert !method.isNative() && !method.isAbstract();
      return (JMethodBody) method.getBody();
    }
View Full Code Here


      return synthetic;
    }

    private JMethodBody findEnclosingMethod(BlockScope scope) {
      JMethod method;
      MethodScope methodScope = scope.methodScope();
      if (methodScope.isInsideInitializer()) {
        JDeclaredType enclosingType = (JDeclaredType) typeMap.get(scope.classScope().referenceContext.binding);
        if (methodScope.isStatic) {
          // clinit
          method = enclosingType.getMethods().get(0);
        } else {
          // init
          assert (enclosingType instanceof JClassType);
          method = enclosingType.getMethods().get(1);
        }
      } else {
        AbstractMethodDeclaration referenceMethod = methodScope.referenceMethod();
        method = (JMethod) typeMap.get(referenceMethod.binding);
      }
      assert !method.isNative() && !method.isAbstract();
      return (JMethodBody) method.getBody();
    }
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

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

    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

      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

    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

    codeStream.reset(this, classFile);
    TypeDeclaration declaringType = classScope.referenceContext;

    // initialize local positions - including initializer scope.
    MethodScope staticInitializerScope = declaringType.staticInitializerScope;
    staticInitializerScope.computeLocalVariablePositions(0, codeStream);

    // 1.4 feature
    // This has to be done before any other initialization
    if (this.assertionSyntheticFieldBinding != null) {
      // generate code related to the activation of assertion for this class
View Full Code Here

    return output;
  }

  public void resolve(ClassScope classScope) {

    this.scope = new MethodScope(classScope, classScope.referenceContext, true);
  }
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

        }
        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)) {
            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

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.