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

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


      }

      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) // 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.bits & ASTNode.IsStrictlyAssigned) != 0 && this.indexOfFirstFieldBinding == this.tokens.length)) {
            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

    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

          knownScopes.put(scope, newElement);
        }
        break;
      case Scope.METHOD_SCOPE :
        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

 
  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

/**
* 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())
      && 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

      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

  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

    this.scribe.space();
    /*
     * Print the method return type
     */
    final TypeReference returnType = annotationTypeMemberDeclaration.returnType;
    final MethodScope annotationTypeMemberDeclarationScope = annotationTypeMemberDeclaration.scope;

    if (returnType != null) {
      returnType.traverse(this, annotationTypeMemberDeclarationScope);
    }
    /*
 
View Full Code Here

        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

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.