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

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


      if (typeBinding != null) {
        return typeBinding;
      }
    } if (node instanceof JavadocSingleNameReference) {
      JavadocSingleNameReference singleNameReference = (JavadocSingleNameReference) node;
      LocalVariableBinding localVariable = (LocalVariableBinding)singleNameReference.binding;
      if (localVariable != null) {
        return this.getTypeBinding(localVariable.type);
      }
    } if (node instanceof SingleNameReference) {
      SingleNameReference singleNameReference = (SingleNameReference) node;
View Full Code Here


    if (!isField()) {
      ASTNode node = this.resolver.findDeclaringNode(this);
      while (true) {
        if (node == null) {
          if (this.binding instanceof LocalVariableBinding) {
            LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
            BlockScope blockScope = localVariableBinding.declaringScope;
            if (blockScope != null) {
              ReferenceContext referenceContext = blockScope.referenceContext();
              if (referenceContext instanceof Initializer) {
                return null;
View Full Code Here

    }
    int sourceEnd = sourceStart+sourceLength-1;
    char[] typeSig = this.binding.type.genericTypeSignature();
    JavaElement parent = null;
    IMethodBinding declaringMethod = getDeclaringMethod();
    final LocalVariableBinding localVariableBinding = (LocalVariableBinding) this.binding;
    if (declaringMethod == null) {
      ReferenceContext referenceContext = localVariableBinding.declaringScope.referenceContext();
      if (referenceContext instanceof TypeDeclaration){
        // Local variable is declared inside an initializer
        TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
View Full Code Here

  }
  else { // no enclosing loop, be as precise as possible right now
    for (int i = 0; i < this.nullCount; i++) {
      ASTNode location = this.nullReferences[i];
      // final local variable
      LocalVariableBinding local = this.nullLocals[i];
      switch (this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) {
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL:
        case CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL:
          if (flowInfo.isDefinitelyNonNull(local)) {
            if ((this.nullCheckTypes[i] & ~HIDE_NULL_COMPARISON_WARNING_MASK) == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NON_NULL)) {
View Full Code Here

    List allTypeAnnotationContexts = ((TypeAnnotationCodeStream) this.codeStream).allTypeAnnotationContexts;
    int invisibleTypeAnnotationsCounter = 0;
    int visibleTypeAnnotationsCounter = 0;

    for (int i = 0, max = this.codeStream.allLocalsCounter; i < max; i++) {
      LocalVariableBinding localVariable = this.codeStream.locals[i];
      if (localVariable.isCatchParameter()) continue;
      LocalDeclaration declaration = localVariable.declaration;
      if (declaration == null
          || (declaration.isArgument() && ((declaration.bits & ASTNode.IsUnionType) == 0))
          || (localVariable.initializationCount == 0)
          || ((declaration.bits & ASTNode.HasTypeAnnotations) == 0)) {
View Full Code Here

        break;
       
      case AnnotationTargetTypeConstants.LOCAL_VARIABLE :
      case AnnotationTargetTypeConstants.RESOURCE_VARIABLE :
        int localVariableTableOffset = this.contentsOffset;
        LocalVariableBinding localVariable = annotationContext.variableBinding;
        int actualSize = 0;
        int initializationCount = localVariable.initializationCount;
        actualSize += 6 * initializationCount;
        // reserve enough space
        if (this.contentsOffset + actualSize >= this.contents.length) {
View Full Code Here

    int numberOfEntries = 0;
    int localVariableNameIndex =
      this.constantPool.literalIndex(AttributeNamesConstants.LocalVariableTableName);
    int maxOfEntries = 8 + 10 * (methodDeclarationIsStatic ? 0 : 1);
    for (int i = 0; i < this.codeStream.allLocalsCounter; i++) {
      LocalVariableBinding localVariableBinding = this.codeStream.locals[i];
      maxOfEntries += 10 * localVariableBinding.initializationCount;
    }
    // reserve enough space
    if (localContentsOffset + maxOfEntries >= this.contents.length) {
      resizeContents(maxOfEntries);
    }
    this.contents[localContentsOffset++] = (byte) (localVariableNameIndex >> 8);
    this.contents[localContentsOffset++] = (byte) localVariableNameIndex;
    int localVariableTableOffset = localContentsOffset;
    // leave space for attribute_length and local_variable_table_length
    localContentsOffset += 6;
    int nameIndex;
    int descriptorIndex;
    SourceTypeBinding declaringClassBinding = null;
    if (!methodDeclarationIsStatic && !isSynthetic) {
      numberOfEntries++;
      this.contents[localContentsOffset++] = 0; // the startPC for this is always 0
      this.contents[localContentsOffset++] = 0;
      this.contents[localContentsOffset++] = (byte) (code_length >> 8);
      this.contents[localContentsOffset++] = (byte) code_length;
      nameIndex = this.constantPool.literalIndex(ConstantPool.This);
      this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
      this.contents[localContentsOffset++] = (byte) nameIndex;
      declaringClassBinding = (SourceTypeBinding)
          (this.codeStream.methodDeclaration != null ? this.codeStream.methodDeclaration.binding.declaringClass : this.codeStream.lambdaExpression.binding.declaringClass);
      descriptorIndex =
        this.constantPool.literalIndex(
          declaringClassBinding.signature());
      this.contents[localContentsOffset++] = (byte) (descriptorIndex >> 8);
      this.contents[localContentsOffset++] = (byte) descriptorIndex;
      this.contents[localContentsOffset++] = 0;// the resolved position for this is always 0
      this.contents[localContentsOffset++] = 0;
    }
    // used to remember the local variable with a generic type
    int genericLocalVariablesCounter = 0;
    LocalVariableBinding[] genericLocalVariables = null;
    int numberOfGenericEntries = 0;

    for (int i = 0, max = this.codeStream.allLocalsCounter; i < max; i++) {
      LocalVariableBinding localVariable = this.codeStream.locals[i];
      int initializationCount = localVariable.initializationCount;
      if (initializationCount == 0) continue;
      if (localVariable.declaration == null) continue;
      final TypeBinding localVariableTypeBinding = localVariable.type;
      boolean isParameterizedType = localVariableTypeBinding.isParameterizedType() || localVariableTypeBinding.isTypeVariable();
      if (isParameterizedType) {
        if (genericLocalVariables == null) {
          // we cannot have more than max locals
          genericLocalVariables = new LocalVariableBinding[max];
        }
        genericLocalVariables[genericLocalVariablesCounter++] = localVariable;
      }
      for (int j = 0; j < initializationCount; j++) {
        int startPC = localVariable.initializationPCs[j << 1];
        int endPC = localVariable.initializationPCs[(j << 1) + 1];
        if (startPC != endPC) { // only entries for non zero length
          if (endPC == -1) {
            localVariable.declaringScope.problemReporter().abortDueToInternalError(
                Messages.bind(Messages.abort_invalidAttribute, new String(localVariable.name)),
                (ASTNode) localVariable.declaringScope.methodScope().referenceContext);
          }
          if (isParameterizedType) {
            numberOfGenericEntries++;
          }
          // now we can safely add the local entry
          numberOfEntries++;
          this.contents[localContentsOffset++] = (byte) (startPC >> 8);
          this.contents[localContentsOffset++] = (byte) startPC;
          int length = endPC - startPC;
          this.contents[localContentsOffset++] = (byte) (length >> 8);
          this.contents[localContentsOffset++] = (byte) length;
          nameIndex = this.constantPool.literalIndex(localVariable.name);
          this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
          this.contents[localContentsOffset++] = (byte) nameIndex;
          descriptorIndex = this.constantPool.literalIndex(localVariableTypeBinding.signature());
          this.contents[localContentsOffset++] = (byte) (descriptorIndex >> 8);
          this.contents[localContentsOffset++] = (byte) descriptorIndex;
          int resolvedPosition = localVariable.resolvedPosition;
          this.contents[localContentsOffset++] = (byte) (resolvedPosition >> 8);
          this.contents[localContentsOffset++] = (byte) resolvedPosition;
        }
      }
    }
    int value = numberOfEntries * 10 + 2;
    this.contents[localVariableTableOffset++] = (byte) (value >> 24);
    this.contents[localVariableTableOffset++] = (byte) (value >> 16);
    this.contents[localVariableTableOffset++] = (byte) (value >> 8);
    this.contents[localVariableTableOffset++] = (byte) value;
    this.contents[localVariableTableOffset++] = (byte) (numberOfEntries >> 8);
    this.contents[localVariableTableOffset] = (byte) numberOfEntries;
    attributesNumber++;

    final boolean currentInstanceIsGeneric =
      !methodDeclarationIsStatic
      && declaringClassBinding != null
      && declaringClassBinding.typeVariables != Binding.NO_TYPE_VARIABLES;
    if (genericLocalVariablesCounter != 0 || currentInstanceIsGeneric) {
      // add the local variable type table attribute
      numberOfGenericEntries += (currentInstanceIsGeneric ? 1 : 0);
      maxOfEntries = 8 + numberOfGenericEntries * 10;
      // reserve enough space
      if (localContentsOffset + maxOfEntries >= this.contents.length) {
        resizeContents(maxOfEntries);
      }
      int localVariableTypeNameIndex =
        this.constantPool.literalIndex(AttributeNamesConstants.LocalVariableTypeTableName);
      this.contents[localContentsOffset++] = (byte) (localVariableTypeNameIndex >> 8);
      this.contents[localContentsOffset++] = (byte) localVariableTypeNameIndex;
      value = numberOfGenericEntries * 10 + 2;
      this.contents[localContentsOffset++] = (byte) (value >> 24);
      this.contents[localContentsOffset++] = (byte) (value >> 16);
      this.contents[localContentsOffset++] = (byte) (value >> 8);
      this.contents[localContentsOffset++] = (byte) value;
      this.contents[localContentsOffset++] = (byte) (numberOfGenericEntries >> 8);
      this.contents[localContentsOffset++] = (byte) numberOfGenericEntries;
      if (currentInstanceIsGeneric) {
        this.contents[localContentsOffset++] = 0; // the startPC for this is always 0
        this.contents[localContentsOffset++] = 0;
        this.contents[localContentsOffset++] = (byte) (code_length >> 8);
        this.contents[localContentsOffset++] = (byte) code_length;
        nameIndex = this.constantPool.literalIndex(ConstantPool.This);
        this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
        this.contents[localContentsOffset++] = (byte) nameIndex;
        descriptorIndex = this.constantPool.literalIndex(declaringClassBinding.genericTypeSignature());
        this.contents[localContentsOffset++] = (byte) (descriptorIndex >> 8);
        this.contents[localContentsOffset++] = (byte) descriptorIndex;
        this.contents[localContentsOffset++] = 0;// the resolved position for this is always 0
        this.contents[localContentsOffset++] = 0;
      }

      for (int i = 0; i < genericLocalVariablesCounter; i++) {
        LocalVariableBinding localVariable = genericLocalVariables[i];
        for (int j = 0; j < localVariable.initializationCount; j++) {
          int startPC = localVariable.initializationPCs[j << 1];
          int endPC = localVariable.initializationPCs[(j << 1) + 1];
          if (startPC != endPC) {
            // only entries for non zero length
View Full Code Here

    if (maxLocals != 0) {
      int resolvedPosition = 0;
      // take into account enum constructor synthetic name+ordinal
      final boolean isConstructor = methodBinding.isConstructor();
      if (isConstructor || !methodBinding.isStatic()) {
        LocalVariableBinding localVariableBinding = new LocalVariableBinding(ConstantPool.This, methodBinding.declaringClass, 0, false);
        localVariableBinding.resolvedPosition = 0;
        this.codeStream.record(localVariableBinding);
        localVariableBinding.recordInitializationStartPC(0);
        localVariableBinding.recordInitializationEndPC(codeLength);
        frame.putLocal(resolvedPosition, new VerificationTypeInfo(
            isConstructor ? VerificationTypeInfo.ITEM_UNINITIALIZED_THIS : VerificationTypeInfo.ITEM_OBJECT,
            methodBinding.declaringClass));
        resolvedPosition++;
      }

      if (isConstructor) {
        if (methodBinding.declaringClass.isEnum()) {
          LocalVariableBinding localVariableBinding = new LocalVariableBinding(" name".toCharArray(), this.referenceBinding.scope.getJavaLangString(), 0, false); //$NON-NLS-1$
          localVariableBinding.resolvedPosition = resolvedPosition;
          this.codeStream.record(localVariableBinding);
          localVariableBinding.recordInitializationStartPC(0);
          localVariableBinding.recordInitializationEndPC(codeLength);

          frame.putLocal(resolvedPosition, new VerificationTypeInfo(
              TypeIds.T_JavaLangString,
              ConstantPool.JavaLangStringConstantPoolName));
          resolvedPosition++;

          localVariableBinding = new LocalVariableBinding(" ordinal".toCharArray(), TypeBinding.INT, 0, false); //$NON-NLS-1$
          localVariableBinding.resolvedPosition = resolvedPosition;
          this.codeStream.record(localVariableBinding);
          localVariableBinding.recordInitializationStartPC(0);
          localVariableBinding.recordInitializationEndPC(codeLength);
          frame.putLocal(resolvedPosition, new VerificationTypeInfo(
              TypeBinding.INT));
          resolvedPosition++;
        }

        // take into account the synthetic parameters
        if (methodBinding.declaringClass.isNestedType()) {
          ReferenceBinding enclosingInstanceTypes[];
          if ((enclosingInstanceTypes = methodBinding.declaringClass.syntheticEnclosingInstanceTypes()) != null) {
            for (int i = 0, max = enclosingInstanceTypes.length; i < max; i++) {
              // an enclosingInstanceType can only be a reference
              // binding. It cannot be
              // LongBinding or DoubleBinding
              LocalVariableBinding localVariableBinding = new LocalVariableBinding((" enclosingType" + i).toCharArray(), enclosingInstanceTypes[i], 0, false); //$NON-NLS-1$
              localVariableBinding.resolvedPosition = resolvedPosition;
              this.codeStream.record(localVariableBinding);
              localVariableBinding.recordInitializationStartPC(0);
              localVariableBinding.recordInitializationEndPC(codeLength);

              frame.putLocal(resolvedPosition,
                  new VerificationTypeInfo(enclosingInstanceTypes[i]));
              resolvedPosition++;
            }
          }

          TypeBinding[] arguments;
          if ((arguments = methodBinding.parameters) != null) {
            for (int i = 0, max = arguments.length; i < max; i++) {
              final TypeBinding typeBinding = arguments[i];
              frame.putLocal(resolvedPosition,
                  new VerificationTypeInfo(typeBinding));
              switch (typeBinding.id) {
                case TypeIds.T_double:
                case TypeIds.T_long:
                  resolvedPosition += 2;
                  break;
                default:
                  resolvedPosition++;
              }
            }
          }

          SyntheticArgumentBinding syntheticArguments[];
          if ((syntheticArguments = methodBinding.declaringClass.syntheticOuterLocalVariables()) != null) {
            for (int i = 0, max = syntheticArguments.length; i < max; i++) {
              final TypeBinding typeBinding = syntheticArguments[i].type;
              LocalVariableBinding localVariableBinding = new LocalVariableBinding((" synthetic" + i).toCharArray(), typeBinding, 0, false); //$NON-NLS-1$
              localVariableBinding.resolvedPosition = resolvedPosition;
              this.codeStream.record(localVariableBinding);
              localVariableBinding.recordInitializationStartPC(0);
              localVariableBinding.recordInitializationEndPC(codeLength);

              frame.putLocal(resolvedPosition,
                  new VerificationTypeInfo(typeBinding));
              switch (typeBinding.id) {
                case TypeIds.T_double:
                case TypeIds.T_long:
                  resolvedPosition += 2;
                  break;
                default:
                  resolvedPosition++;
              }
            }
          }
        } else {
          TypeBinding[] arguments;
          if ((arguments = methodBinding.parameters) != null) {
            for (int i = 0, max = arguments.length; i < max; i++) {
              final TypeBinding typeBinding = arguments[i];
              frame.putLocal(resolvedPosition,
                  new VerificationTypeInfo(typeBinding));
              switch (typeBinding.id) {
                case TypeIds.T_double:
                case TypeIds.T_long:
                  resolvedPosition += 2;
                  break;
                default:
                  resolvedPosition++;
              }
            }
          }
        }
      } else {
        TypeBinding[] arguments;
        if ((arguments = methodBinding.parameters) != null) {
          for (int i = 0, max = arguments.length; i < max; i++) {
            final TypeBinding typeBinding = arguments[i];
            // For the branching complexities in the generated $deserializeLambda$ we need the local variable
            LocalVariableBinding localVariableBinding = new LocalVariableBinding((" synthetic"+i).toCharArray(), typeBinding, 0, true); //$NON-NLS-1$
            localVariableBinding.resolvedPosition = i;
            this.codeStream.record(localVariableBinding);
            localVariableBinding.recordInitializationStartPC(0);
            localVariableBinding.recordInitializationEndPC(codeLength);
            frame.putLocal(resolvedPosition,
                new VerificationTypeInfo(typeBinding));
            switch (typeBinding.id) {
              case TypeIds.T_double:
              case TypeIds.T_long:
View Full Code Here

    for (; i < localsLength; i++) {
      locals[i] = null;
    }
    i = 0;
    locals: for (int max = this.codeStream.allLocalsCounter; i < max; i++) {
      LocalVariableBinding localVariable = this.codeStream.locals[i];
      if (localVariable == null) continue;
      int resolvedPosition = localVariable.resolvedPosition;
      final TypeBinding localVariableTypeBinding = localVariable.type;
      inits: for (int j = 0; j < localVariable.initializationCount; j++) {
        int startPC = localVariable.initializationPCs[j << 1];
View Full Code Here

    System.arraycopy(this.contents, 0, this.contents = new byte[length + toAdd], 0, length);
  }

  private VerificationTypeInfo retrieveLocal(int currentPC, int resolvedPosition) {
    for (int i = 0, max = this.codeStream.allLocalsCounter; i < max; i++) {
      LocalVariableBinding localVariable = this.codeStream.locals[i];
      if (localVariable == null) continue;
      if (resolvedPosition == localVariable.resolvedPosition) {
        inits: for (int j = 0; j < localVariable.initializationCount; j++) {
          int startPC = localVariable.initializationPCs[j << 1];
          int endPC = localVariable.initializationPCs[(j << 1) + 1];
View Full Code Here

TOP

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

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.