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

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


        Alignment.R_INNERMOST,
        3,
        this.scribe.scanner.currentPosition);
    this.scribe.enterAlignment(methodDeclAlignment);
    boolean ok = false;
    final MethodScope methodDeclarationScope = methodDeclaration.scope;
    do {
      try {

        this.scribe.printModifiers(methodDeclaration.annotations, this, ICodeFormatterConstants.ANNOTATION_ON_METHOD);
        int fragmentIndex = 0;
View Full Code Here


        break;
      case Scope.CLASS_SCOPE:
        specifiedTags = CLASS_TAGS;
        break;
      case Scope.METHOD_SCOPE:
        MethodScope methodScope = (MethodScope) scope;
        if (methodScope.referenceMethod() == null) {
          if (methodScope.initializedField == null) {
            specifiedTags = PACKAGE_TAGS;
          } else {
            specifiedTags = FIELD_TAGS;
          }
View Full Code Here

      return param;
    }

    private JMethodBody findEnclosingMethod(BlockScope scope) {
      JMethod method;
      MethodScope methodScope = scope.methodScope();
      if (methodScope.isInsideInitializer()) {
        JReferenceType enclosingType = (JReferenceType) typeMap.get(scope.classScope().referenceContext.binding);
        if (methodScope.isStatic) {
          // clinit
          method = (JMethod) enclosingType.methods.get(0);
        } else {
          // init
          assert (enclosingType instanceof JClassType);
          method = (JMethod) enclosingType.methods.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

  this.initsOnReturn = FlowInfo.DEAD_END;
  this.  initializationParent = initializationParent;
}

public void complainIfUnusedExceptionHandlers(AbstractMethodDeclaration method) {
  MethodScope scope = method.scope;
  // can optionally skip overriding methods
  if ((method.binding.modifiers & (ExtraCompilerModifiers.AccOverriding | ExtraCompilerModifiers.AccImplementing)) != 0
          && !scope.compilerOptions().reportUnusedDeclaredThrownExceptionWhenOverriding) {
      return;
  }

  // report errors for unreachable exception handlers
  TypeBinding[] docCommentReferences = null;
  int docCommentReferencesLength = 0;
  if (scope.compilerOptions().
        reportUnusedDeclaredThrownExceptionIncludeDocCommentReference &&
      method.javadoc != null &&
      method.javadoc.exceptionReferences != null &&
      (docCommentReferencesLength = method.javadoc.exceptionReferences.length) > 0) {
    docCommentReferences = new TypeBinding[docCommentReferencesLength];
    for (int i = 0; i < docCommentReferencesLength; i++) {
      docCommentReferences[i] = method.javadoc.exceptionReferences[i].resolvedType;
    }
  }
  nextHandledException: for (int i = 0, count = this.handledExceptions.length; i < count; i++) {
    int index = this.indexes.get(this.handledExceptions[i]);
    if ((this.isReached[index / ExceptionHandlingFlowContext.BitCacheSize] & 1 << (index % ExceptionHandlingFlowContext.BitCacheSize)) == 0) {
      for (int j = 0; j < docCommentReferencesLength; j++) {
        if (docCommentReferences[j] == this.handledExceptions[i]) {
          continue nextHandledException;
        }
      }
      scope.problemReporter().unusedDeclaredThrownException(
        this.handledExceptions[index],
        method,
        method.thrownExceptions[index]);
    }
  }
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

        && 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

    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 (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

  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 & ASTNode.IsStrictlyAssigned) !=0))
    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

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.