コード例 #1
0
  public void manageSyntheticAccessIfNecessary(
      BlockScope currentScope, FlowInfo flowInfo, boolean isReadAccess) {
    if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return;

    // If inlinable field, forget the access emulation, the code gen will directly target it
    if (this.constant != Constant.NotAConstant) return;

    if ((this.bits & Binding.FIELD) != 0) {
      FieldBinding fieldBinding = (FieldBinding) this.binding;
      FieldBinding codegenField = fieldBinding.original();
      if (((this.bits & ASTNode.DepthMASK) != 0)
          && (codegenField.isPrivate() // private access
              || (codegenField.isProtected() // implicit protected access
                  && codegenField.declaringClass.getPackage()
                      != currentScope.enclosingSourceType().getPackage()))) {
        if (this.syntheticAccessors == null) this.syntheticAccessors = new MethodBinding[2];
        this.syntheticAccessors[
                isReadAccess ? SingleNameReference.READ : SingleNameReference.WRITE] =
            ((SourceTypeBinding)
                    currentScope
                        .enclosingSourceType()
                        .enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT))
                .addSyntheticMethod(codegenField, isReadAccess, false /*not super access*/);
        currentScope.problemReporter().needToEmulateFieldAccess(codegenField, this, isReadAccess);
        return;
      }
    }
  }
コード例 #2
0
 /**
  * @see
  *     org.eclipse.che.ide.ext.java.jdt.internal.compiler.ast.Expression#computeConversion(org.eclipse.che.ide.ext.java.jdt.internal.compiler.lookup.Scope,
  *     org.eclipse.che.ide.ext.java.jdt.internal.compiler.lookup.TypeBinding,
  *     org.eclipse.che.ide.ext.java.jdt.internal.compiler.lookup .TypeBinding)
  */
 public void computeConversion(
     Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
   if (runtimeTimeType == null || compileTimeType == null) return;
   if ((this.bits & Binding.FIELD) != 0 && this.binding != null && this.binding.isValidBinding()) {
     // set the generic cast after the fact, once the type expectation is fully known (no need for
     // strict cast)
     FieldBinding field = (FieldBinding) this.binding;
     FieldBinding originalBinding = field.original();
     TypeBinding originalType = originalBinding.type;
     // extra cast needed if field type is type variable
     if (originalType.leafComponentType().isTypeVariable()) {
       TypeBinding targetType =
           (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
               ? compileTimeType
               // unboxing: checkcast before conversion
               : runtimeTimeType;
       this.genericCast = originalType.genericCast(scope.boxing(targetType));
       if (this.genericCast instanceof ReferenceBinding) {
         ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast;
         if (!referenceCast.canBeSeenBy(scope)) {
           scope
               .problemReporter()
               .invalidType(
                   this,
                   new ProblemReferenceBinding(
                       CharOperation.splitOn('.', referenceCast.shortReadableName()),
                       referenceCast,
                       ProblemReasons.NotVisible));
         }
       }
     }
   }
   super.computeConversion(scope, runtimeTimeType, compileTimeType);
 }
コード例 #3
0
  public void generatePostIncrement(
      BlockScope currentScope, CompoundAssignment postIncrement, boolean valueRequired) {
    switch (this.bits & ASTNode.RestrictiveFlagMASK) {
      case Binding.FIELD: // assigning to a field
        FieldBinding fieldBinding = (FieldBinding) this.binding;
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
        // check if postIncrement is the only usage of a private field
        reportOnlyUselesslyReadPrivateField(currentScope, fieldBinding, valueRequired);
        FieldBinding codegenField = fieldBinding.original();

        fieldStore(
            currentScope,
            codegenField,
            this.syntheticAccessors == null
                ? null
                : this.syntheticAccessors[SingleNameReference.WRITE],
            this.actualReceiverType,
            true /*implicit this*/,
            false);
        // no need for generic cast
        return;
      case Binding.LOCAL: // assigning to a local variable
        LocalVariableBinding localBinding = (LocalVariableBinding) this.binding;
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682
        // check if postIncrement is the only usage of this local
        Reference.reportOnlyUselesslyReadLocal(currentScope, localBinding, valueRequired);
        if (localBinding.resolvedPosition == -1) {
          if (valueRequired) {
            // restart code gen
            localBinding.useFlag = LocalVariableBinding.USED;
            throw new AbortMethod(null, null);
          }
        }
    }
  }
コード例 #4
0
  public TypeBinding checkFieldAccess(BlockScope scope) {
    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))
      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;
    }
    return fieldBinding.type;
  }