Esempio n. 1
0
 public TypeBinding checkResolvedType(
     TypeBinding type, Scope scope, int location, boolean hasError) {
   // SH}
   if (type.isArrayType() && ((ArrayBinding) type).leafComponentType == TypeBinding.VOID) {
     scope.problemReporter().cannotAllocateVoidArray(this);
     return null;
   }
   if (!(this
           instanceof
           QualifiedTypeReference) // QualifiedTypeReference#getTypeBinding called above will have
                                   // already checked deprecation
       && isTypeUseDeprecated(type, scope)) {
     reportDeprecatedType(type, scope);
   }
   type =
       scope
           .environment()
           .convertToRawType(type, false /*do not force conversion of enclosing types*/);
   if (type.leafComponentType().isRawType()
       && (this.bits & ASTNode.IgnoreRawTypeCheck) == 0
       && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference)
           != ProblemSeverities.Ignore) {
     scope.problemReporter().rawTypeReference(this, type);
   }
   if (hasError) {
     resolveAnnotations(scope, 0); // don't apply null defaults to buggy type
     return type;
   } else {
     // store the computed type only if no error, otherwise keep the problem type instead
     this.resolvedType = type;
     resolveAnnotations(scope, location);
     return this
         .resolvedType; // pick up value that may have been changed in resolveAnnotations(..)
   }
 }
 public String annotatedDebugName() {
   StringBuffer buffer = new StringBuffer(10);
   buffer.append(super.annotatedDebugName());
   if (!this.inRecursiveFunction) {
     this.inRecursiveFunction = true;
     try {
       if (this.superclass != null && TypeBinding.equalsEquals(this.firstBound, this.superclass)) {
         buffer.append(" extends ").append(this.superclass.annotatedDebugName()); // $NON-NLS-1$
       }
       if (this.superInterfaces != null && this.superInterfaces != Binding.NO_SUPERINTERFACES) {
         if (TypeBinding.notEquals(this.firstBound, this.superclass)) {
           buffer.append(" extends "); // $NON-NLS-1$
         }
         for (int i = 0, length = this.superInterfaces.length; i < length; i++) {
           if (i > 0 || TypeBinding.equalsEquals(this.firstBound, this.superclass)) {
             buffer.append(" & "); // $NON-NLS-1$
           }
           buffer.append(this.superInterfaces[i].annotatedDebugName());
         }
       }
     } finally {
       this.inRecursiveFunction = false;
     }
   }
   return buffer.toString();
 }
 /** Returns true if the type variable is directly bound to a given type */
 public boolean isErasureBoundTo(TypeBinding type) {
   if (TypeBinding.equalsEquals(this.superclass.erasure(), type)) return true;
   for (int i = 0, length = this.superInterfaces.length; i < length; i++) {
     if (TypeBinding.equalsEquals(this.superInterfaces[i].erasure(), type)) return true;
   }
   return false;
 }
  public void resolveReceiver() {
    if (this.receiver == null) return;

    if (this.receiver.modifiers != 0) {
      this.scope
          .problemReporter()
          .illegalModifiers(
              this.receiver.declarationSourceStart, this.receiver.declarationSourceEnd);
    }

    TypeBinding resolvedReceiverType = this.receiver.type.resolvedType;
    if (this.binding == null
        || resolvedReceiverType == null
        || !resolvedReceiverType.isValidBinding()) {
      return;
    }

    ReferenceBinding declaringClass = this.binding.declaringClass;
    /* neither static methods nor methods in anonymous types can have explicit 'this' */
    if (this.isStatic() || declaringClass.isAnonymousType()) {
      this.scope.problemReporter().disallowedThisParameter(this.receiver);
      return; // No need to do further validation
    }

    ReferenceBinding enclosingReceiver = this.scope.enclosingReceiverType();
    if (this.isConstructor()) {
      /* Only non static member types or local types can declare explicit 'this' params in constructors */
      if (declaringClass.isStatic()
          || (declaringClass.tagBits & (TagBits.IsLocalType | TagBits.IsMemberType)) == 0) {
          /* neither member nor local type */
        this.scope.problemReporter().disallowedThisParameter(this.receiver);
        return; // No need to do further validation
      }
      enclosingReceiver = enclosingReceiver.enclosingType();
    }

    char[][] tokens =
        (this.receiver.qualifyingName == null) ? null : this.receiver.qualifyingName.getName();
    if (this.isConstructor()) {
      if (tokens == null
          || tokens.length > 1
          || !CharOperation.equals(enclosingReceiver.sourceName(), tokens[0])) {
        this.scope
            .problemReporter()
            .illegalQualifierForExplicitThis(this.receiver, enclosingReceiver);
        this.receiver.qualifyingName = null;
      }
    } else if (tokens != null && tokens.length > 0) {
      this.scope.problemReporter().illegalQualifierForExplicitThis2(this.receiver);
      this.receiver.qualifyingName = null;
    }

    if (TypeBinding.notEquals(enclosingReceiver, resolvedReceiverType)) {
      this.scope.problemReporter().illegalTypeForExplicitThis(this.receiver, enclosingReceiver);
    }

    if (this.receiver.type.hasNullTypeAnnotation(AnnotationPosition.ANY)) {
      this.scope.problemReporter().nullAnnotationUnsupportedLocation(this.receiver.type);
    }
  }
 public String process() {
   if (this.type.getCanonicalName() == null) {
     new RuntimeException("" + this.type).printStackTrace();
   } else {
     this.elem(Elem.mapping);
     if (this.abs) {
       this.attr("abstract", "true");
     } else {
       this.attr("name", this.type.getSimpleName())
           .attr("extends", this.type.getSuperclass().getCanonicalName());
     }
     this.attr("class", this.type.getCanonicalName());
     if (BindingGenerator.MSG_TYPE.isAssignableFrom(this.type.getSuperclass())
         || BindingGenerator.DATA_TYPE.isAssignableFrom(this.type.getSuperclass())) {
       this.elem(Elem.structure)
           .attr("map-as", this.type.getSuperclass().getCanonicalName())
           .end();
     }
     for (Field f : type.getDeclaredFields()) {
       TypeBinding tb = getTypeBinding(f);
       if (!(tb instanceof NoopTypeBinding)) {
         System.out.printf(
             "BOUND:  %-70s [type=%s:%s]\n",
             f.getDeclaringClass().getCanonicalName() + "." + f.getName(),
             tb.getTypeName(),
             f.getType().getCanonicalName());
         this.append(tb.toString());
       }
     }
     this.end();
   }
   return this.toString();
 }
 /** @see TypeBinding#isEquivalentTo(TypeBinding) */
 public boolean isEquivalentTo(TypeBinding otherType) {
   // from CaptureBinding:
   if (equalsEquals(this, otherType)) return true;
   if (otherType == null) return false;
   if (this.upperBounds != null) {
     // from CaptureBinding:
     for (int i = 0; i < this.upperBounds.length; i++) {
       TypeBinding aBound = this.upperBounds[i];
       // capture of ? extends X[]
       if (aBound != null && aBound.isArrayType()) {
         if (!aBound.isCompatibleWith(otherType)) continue;
       }
       switch (otherType.kind()) {
         case Binding.WILDCARD_TYPE:
         case Binding.INTERSECTION_TYPE:
           if (!((WildcardBinding) otherType).boundCheck(aBound)) return false;
           break;
         default:
           return false;
       }
     }
     return true;
   }
   return false;
 }
Esempio n. 7
0
  /**
   * Collect the substitutes into a map for certain type variables inside the receiver type e.g.
   * Collection<T>.collectSubstitutes(Collection<List<X>>, Map), will populate Map with: T -->
   * List<X> Constraints: A << F corresponds to: F.collectSubstitutes(..., A, ...,
   * CONSTRAINT_EXTENDS (1)) A = F corresponds to: F.collectSubstitutes(..., A, ...,
   * CONSTRAINT_EQUAL (0)) A >> F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_SUPER
   * (2))
   */
  public void collectSubstitutes(
      Scope scope, TypeBinding actualType, InferenceContext inferenceContext, int constraint) {

    if ((this.tagBits & TagBits.HasTypeVariable) == 0) return;
    if (actualType == TypeBinding.NULL) return;

    switch (actualType.kind()) {
      case Binding.ARRAY_TYPE:
        int actualDim = actualType.dimensions();
        if (actualDim == this.dimensions) {
          this.leafComponentType.collectSubstitutes(
              scope, actualType.leafComponentType(), inferenceContext, constraint);
        } else if (actualDim > this.dimensions) {
          ArrayBinding actualReducedType =
              this.environment.createArrayType(
                  actualType.leafComponentType(), actualDim - this.dimensions);
          this.leafComponentType.collectSubstitutes(
              scope, actualReducedType, inferenceContext, constraint);
        }
        break;
      case Binding.TYPE_PARAMETER:
        // TypeVariableBinding variable = (TypeVariableBinding) otherType;
        // TODO (philippe) should consider array bounds, and recurse
        break;
    }
  }
 public String process() {
   if (this.type.getCanonicalName() == null) {
     //          new RuntimeException( "Ignoring anonymous class: " + this.type
     // ).printStackTrace( );
   } else {
     this.elem(Elem.mapping);
     if (this.abs) {
       this.attr("abstract", "true");
     } else {
       this.attr("name", this.type.getSimpleName())
           .attr("extends", this.type.getSuperclass().getCanonicalName());
     }
     this.attr("class", this.type.getCanonicalName());
     if (BindingFileSearch.INSTANCE.MSG_BASE_CLASS.isAssignableFrom(this.type.getSuperclass())
         || BindingFileSearch.INSTANCE.MSG_DATA_CLASS.isAssignableFrom(
             this.type.getSuperclass())) {
       this.elem(Elem.structure)
           .attr("map-as", this.type.getSuperclass().getCanonicalName())
           .end();
     }
     for (Field f : this.type.getDeclaredFields()) {
       if (!Ats.from(f).has(Transient.class) || Modifier.isTransient(f.getModifiers())) {
         TypeBinding tb = getTypeBinding(f);
         if (!(tb instanceof NoopTypeBinding)) {
           //                System.out.printf( "BOUND:  %-70s [type=%s:%s]\n",
           // f.getDeclaringClass( ).getCanonicalName( ) +"."+ f.getName( ), tb.getTypeName( ),
           // f.getType( ).getCanonicalName( ) );
           this.append(tb.toString());
         }
       }
     }
     this.end();
   }
   return this.toString();
 }
Esempio n. 9
0
 protected int findNullTypeAnnotationMismatch(TypeBinding requiredType, TypeBinding providedType) {
   int severity = 0;
   if (requiredType instanceof ArrayBinding) {
     long[] requiredDimsTagBits = ((ArrayBinding) requiredType).nullTagBitsPerDimension;
     if (requiredDimsTagBits != null) {
       int dims = requiredType.dimensions();
       if (requiredType.dimensions() == providedType.dimensions()) {
         long[] providedDimsTagBits = ((ArrayBinding) providedType).nullTagBitsPerDimension;
         if (providedDimsTagBits == null) {
           severity = 1; // required is annotated, provided not, need unchecked conversion
         } else {
           for (int i = 0; i < dims; i++) {
             long requiredBits = requiredDimsTagBits[i] & TagBits.AnnotationNullMASK;
             long providedBits = providedDimsTagBits[i] & TagBits.AnnotationNullMASK;
             if (requiredBits != 0 && requiredBits != providedBits) {
               if (providedBits == 0)
                 severity = 1; // need unchecked conversion regarding type detail
               else return 2; // mismatching annotations
             }
           }
         }
       }
     }
   }
   return severity;
 }
 public boolean equalsEquals(ConstraintTypeFormula that) {
   return (that != null
       && this.relation == that.relation
       && this.isSoft == that.isSoft
       && TypeBinding.equalsEquals(this.left, that.left)
       && TypeBinding.equalsEquals(this.right, that.right));
 }
 @Override
 public char[] nullAnnotatedReadableName(CompilerOptions options, boolean shortNames) {
   StringBuffer nameBuffer = new StringBuffer(10);
   appendNullAnnotation(nameBuffer, options);
   nameBuffer.append(this.sourceName());
   if (!this.inRecursiveFunction) {
     this.inRecursiveFunction = true;
     try {
       if (this.superclass != null && TypeBinding.equalsEquals(this.firstBound, this.superclass)) {
         nameBuffer
             .append(" extends ")
             .append(
                 this.superclass.nullAnnotatedReadableName(options, shortNames)); // $NON-NLS-1$
       }
       if (this.superInterfaces != null && this.superInterfaces != Binding.NO_SUPERINTERFACES) {
         if (TypeBinding.notEquals(this.firstBound, this.superclass)) {
           nameBuffer.append(" extends "); // $NON-NLS-1$
         }
         for (int i = 0, length = this.superInterfaces.length; i < length; i++) {
           if (i > 0 || TypeBinding.equalsEquals(this.firstBound, this.superclass)) {
             nameBuffer.append(" & "); // $NON-NLS-1$
           }
           nameBuffer.append(
               this.superInterfaces[i].nullAnnotatedReadableName(options, shortNames));
         }
       }
     } finally {
       this.inRecursiveFunction = false;
     }
   }
   int nameLength = nameBuffer.length();
   char[] readableName = new char[nameLength];
   nameBuffer.getChars(0, nameLength, readableName, 0);
   return readableName;
 }
 boolean denotesRelevantSuperClass(TypeBinding type) {
   if (!type.isTypeVariable() && !type.isInterface() && type.id != TypeIds.T_JavaLangObject)
     return true;
   ReferenceBinding aSuperClass = type.superclass();
   return aSuperClass != null
       && aSuperClass.id != TypeIds.T_JavaLangObject
       && !aSuperClass.isTypeVariable();
 }
 private Object reduceTypeEquality(TypeBinding object) {
   // 18.2.4
   if (this.left.kind() == Binding.WILDCARD_TYPE) {
     if (this.right.kind() == Binding.WILDCARD_TYPE) {
       // left and right are wildcards ("type arguments")
       WildcardBinding leftWC = (WildcardBinding) this.left;
       WildcardBinding rightWC = (WildcardBinding) this.right;
       if (leftWC.boundKind == Wildcard.UNBOUND && rightWC.boundKind == Wildcard.UNBOUND)
         return TRUE;
       if (leftWC.boundKind == Wildcard.UNBOUND && rightWC.boundKind == Wildcard.EXTENDS)
         return ConstraintTypeFormula.create(object, rightWC.bound, SAME, this.isSoft);
       if (leftWC.boundKind == Wildcard.EXTENDS && rightWC.boundKind == Wildcard.UNBOUND)
         return ConstraintTypeFormula.create(leftWC.bound, object, SAME, this.isSoft);
       if ((leftWC.boundKind == Wildcard.EXTENDS && rightWC.boundKind == Wildcard.EXTENDS)
           || (leftWC.boundKind == Wildcard.SUPER && rightWC.boundKind == Wildcard.SUPER)) {
         return ConstraintTypeFormula.create(leftWC.bound, rightWC.bound, SAME, this.isSoft);
       }
     }
   } else {
     if (this.right.kind() != Binding.WILDCARD_TYPE) {
       // left and right are types (vs. wildcards)
       if (this.left.isProperType(true) && this.right.isProperType(true)) {
         if (TypeBinding.equalsEquals(this.left, this.right)) return TRUE;
         return FALSE;
       }
       if (this.left instanceof InferenceVariable) {
         return new TypeBound((InferenceVariable) this.left, this.right, SAME, this.isSoft);
       }
       if (this.right instanceof InferenceVariable) {
         return new TypeBound((InferenceVariable) this.right, this.left, SAME, this.isSoft);
       }
       if ((this.left.isClass() || this.left.isInterface())
           && (this.right.isClass() || this.right.isInterface())
           && TypeBinding.equalsEquals(this.left.erasure(), this.right.erasure())) {
         TypeBinding[] leftParams = this.left.typeArguments();
         TypeBinding[] rightParams = this.right.typeArguments();
         if (leftParams == null || rightParams == null)
           return leftParams == rightParams ? TRUE : FALSE;
         if (leftParams.length != rightParams.length) return FALSE;
         int len = leftParams.length;
         ConstraintFormula[] constraints = new ConstraintFormula[len];
         for (int i = 0; i < len; i++) {
           constraints[i] =
               ConstraintTypeFormula.create(leftParams[i], rightParams[i], SAME, this.isSoft);
         }
         return constraints;
       }
       if (this.left.isArrayType()
           && this.right.isArrayType()
           && this.left.dimensions() == this.right.dimensions()) {
         // checking dimensions already now is an optimization over reducing one dim at a time
         return ConstraintTypeFormula.create(
             this.left.leafComponentType(), this.right.leafComponentType(), SAME, this.isSoft);
       }
     }
   }
   return FALSE;
 }
  ReferenceBinding resolve() {
    if ((this.modifiers & ExtraCompilerModifiers.AccUnresolved) == 0) return this;

    long nullTagBits = this.tagBits & TagBits.AnnotationNullMASK;

    TypeBinding oldSuperclass = this.superclass, oldFirstInterface = null;
    if (this.superclass != null) {
      ReferenceBinding resolveType =
          (ReferenceBinding)
              BinaryTypeBinding.resolveType(
                  this.superclass, this.environment, true /* raw conversion */);
      this.tagBits |= resolveType.tagBits & TagBits.ContainsNestedTypeReferences;
      long superNullTagBits = resolveType.tagBits & TagBits.AnnotationNullMASK;
      if (superNullTagBits != 0L) {
        if (nullTagBits == 0L) {
          this.tagBits |= (superNullTagBits | TagBits.HasNullTypeAnnotation);
        } else {
          //					System.err.println("TODO(stephan): report proper error: conflict binary
          // TypeVariable vs. first bound");
        }
      }
      this.setSuperClass(resolveType);
    }
    ReferenceBinding[] interfaces = this.superInterfaces;
    int length;
    if ((length = interfaces.length) != 0) {
      oldFirstInterface = interfaces[0];
      for (int i = length; --i >= 0; ) {
        ReferenceBinding resolveType =
            (ReferenceBinding)
                BinaryTypeBinding.resolveType(
                    interfaces[i], this.environment, true /* raw conversion */);
        this.tagBits |= resolveType.tagBits & TagBits.ContainsNestedTypeReferences;
        long superNullTagBits = resolveType.tagBits & TagBits.AnnotationNullMASK;
        if (superNullTagBits != 0L) {
          if (nullTagBits == 0L) {
            this.tagBits |= (superNullTagBits | TagBits.HasNullTypeAnnotation);
          } else {
            //						System.err.println("TODO(stephan): report proper error: conflict binary
            // TypeVariable vs. bound "+i);
          }
        }
        interfaces[i] = resolveType;
      }
    }
    // refresh the firstBound in case it changed
    if (this.firstBound != null) {
      if (TypeBinding.equalsEquals(this.firstBound, oldSuperclass)) {
        this.setFirstBound(this.superclass);
      } else if (TypeBinding.equalsEquals(this.firstBound, oldFirstInterface)) {
        this.setFirstBound(interfaces[0]);
      }
    }
    this.modifiers &= ~ExtraCompilerModifiers.AccUnresolved;
    return this;
  }
 TypeBinding substituteInferenceVariable(InferenceVariable var, TypeBinding substituteType) {
   if (this.inRecursiveFunction) return this;
   this.inRecursiveFunction = true;
   try {
     boolean haveSubstitution = false;
     ReferenceBinding currentSuperclass = this.superclass;
     if (currentSuperclass != null) {
       currentSuperclass =
           (ReferenceBinding) currentSuperclass.substituteInferenceVariable(var, substituteType);
       haveSubstitution |= TypeBinding.notEquals(currentSuperclass, this.superclass);
     }
     ReferenceBinding[] currentSuperInterfaces = null;
     if (this.superInterfaces != null) {
       int length = this.superInterfaces.length;
       if (haveSubstitution)
         System.arraycopy(
             this.superInterfaces,
             0,
             currentSuperInterfaces = new ReferenceBinding[length],
             0,
             length);
       for (int i = 0; i < length; i++) {
         ReferenceBinding currentSuperInterface = this.superInterfaces[i];
         if (currentSuperInterface != null) {
           currentSuperInterface =
               (ReferenceBinding)
                   currentSuperInterface.substituteInferenceVariable(var, substituteType);
           if (TypeBinding.notEquals(currentSuperInterface, this.superInterfaces[i])) {
             if (currentSuperInterfaces == null)
               System.arraycopy(
                   this.superInterfaces,
                   0,
                   currentSuperInterfaces = new ReferenceBinding[length],
                   0,
                   length);
             currentSuperInterfaces[i] = currentSuperInterface;
             haveSubstitution = true;
           }
         }
       }
     }
     if (haveSubstitution) {
       TypeVariableBinding newVar =
           new TypeVariableBinding(
               this.sourceName, this.declaringElement, this.rank, this.environment);
       newVar.superclass = currentSuperclass;
       newVar.superInterfaces = currentSuperInterfaces;
       newVar.tagBits = this.tagBits;
       return newVar;
     }
     return this;
   } finally {
     this.inRecursiveFunction = false;
   }
 }
 private TypeReference findBound(TypeBinding bound, TypeParameter parameter) {
   if (parameter.type != null && TypeBinding.equalsEquals(parameter.type.resolvedType, bound))
     return parameter.type;
   TypeReference[] bounds = parameter.bounds;
   if (bounds != null) {
     for (int i = 0; i < bounds.length; i++) {
       if (TypeBinding.equalsEquals(bounds[i].resolvedType, bound)) return bounds[i];
     }
   }
   return null;
 }
 private boolean haveTypeAnnotations(
     TypeBinding baseType,
     TypeBinding someType,
     TypeBinding[] someTypes,
     AnnotationBinding[] annotations) {
   if (baseType != null && baseType.hasTypeAnnotations()) return true;
   if (someType != null && someType.hasTypeAnnotations()) return true;
   for (int i = 0, length = annotations == null ? 0 : annotations.length; i < length; i++)
     if (annotations[i] != null) return true;
   for (int i = 0, length = someTypes == null ? 0 : someTypes.length; i < length; i++)
     if (someTypes[i].hasTypeAnnotations()) return true;
   return false;
 }
Esempio n. 18
0
 /**
  * Check whether this type reference conforms to the null constraints defined for the
  * corresponding type variable.
  */
 protected void checkNullConstraints(
     Scope scope, Substitution substitution, TypeBinding[] variables, int rank) {
   if (variables != null && variables.length > rank) {
     TypeBinding variable = variables[rank];
     if (variable.hasNullTypeAnnotations()) {
       if (NullAnnotationMatching.analyse(
               variable, this.resolvedType, null, substitution, -1, null, CheckMode.BOUND_CHECK)
           .isAnyMismatch())
         scope.problemReporter().nullityMismatchTypeArgument(variable, this.resolvedType, this);
     }
   }
   checkIllegalNullAnnotation(scope);
 }
  public TypeBinding resolveType(BlockScope scope) {
    this.constant = Constant.NotAConstant;
    TypeBinding expressionType = this.expression.resolveType(scope);
    TypeBinding checkedType = this.type.resolveType(scope, true /* check bounds*/);
    if (expressionType == null || checkedType == null) return null;

    if (!checkedType.isReifiable()) {
      scope.problemReporter().illegalInstanceOfGenericType(checkedType, this);
    } else if ((expressionType != TypeBinding.NULL
            && expressionType.isBaseType()) // disallow autoboxing
        || !checkCastTypesCompatibility(scope, checkedType, expressionType, null)) {
      scope.problemReporter().notCompatibleTypesError(this, expressionType, checkedType);
    }
    return this.resolvedType = TypeBinding.BOOLEAN;
  }
 @Override
 public long updateTagBits() {
   if (!this.inRecursiveFunction) {
     this.inRecursiveFunction = true;
     try {
       if (this.superclass != null) this.tagBits |= this.superclass.updateTagBits();
       if (this.superInterfaces != null)
         for (TypeBinding superIfc : this.superInterfaces)
           this.tagBits |= superIfc.updateTagBits();
     } finally {
       this.inRecursiveFunction = false;
     }
   }
   return super.updateTagBits();
 }
 public TypeBinding getTypeBinding(Field field) {
   Class itsType = field.getType();
   if (this.isIgnored(field)) {
     return new NoopTypeBinding(field);
   } else if (List.class.isAssignableFrom(itsType)) {
     Class listType = getTypeArgument(field);
     if (listType == null) {
       Logs.extreme()
           .debug(
               String.format(
                   "IGNORE: %-70s [type=%s] NO GENERIC TYPE FOR LIST\n",
                   field.getDeclaringClass().getCanonicalName() + "." + field.getName(),
                   listType));
       return new NoopTypeBinding(field);
     } else if (this.typeBindings.containsKey(listType.getCanonicalName())) {
       return new CollectionTypeBinding(
           field.getName(), this.typeBindings.get(listType.getCanonicalName()));
     } else if (BindingFileSearch.INSTANCE.MSG_DATA_CLASS.isAssignableFrom(listType)) {
       return new CollectionTypeBinding(
           field.getName(), new ObjectTypeBinding(field.getName(), listType));
     } else {
       Logs.extreme()
           .debug(
               String.format(
                   "IGNORE: %-70s [type=%s] LIST'S GENERIC TYPE DOES NOT CONFORM TO EucalyptusData\n",
                   field.getDeclaringClass().getCanonicalName() + "." + field.getName(),
                   listType.getCanonicalName()));
       return new NoopTypeBinding(field);
     }
   } else if (this.typeBindings.containsKey(itsType.getCanonicalName())) {
     TypeBinding t = this.typeBindings.get(itsType.getCanonicalName());
     try {
       t = this.typeBindings.get(itsType.getCanonicalName()).getClass().newInstance();
     } catch (Exception e) {
     }
     return t.value(field.getName());
   } else if (BindingFileSearch.INSTANCE.MSG_DATA_CLASS.isAssignableFrom(field.getType())) {
     return new ObjectTypeBinding(field);
   } else {
     Logs.extreme()
         .debug(
             String.format(
                 "IGNORE: %-70s [type=%s] TYPE DOES NOT CONFORM TO EucalyptusData\n",
                 field.getDeclaringClass().getCanonicalName() + "." + field.getName(),
                 field.getType().getCanonicalName()));
     return new NoopTypeBinding(field);
   }
 }
  /**
   * Collect the substitutes into a map for certain type variables inside the receiver type e.g.
   * Collection<T>.collectSubstitutes(Collection<List<X>>, Map), will populate Map with: T -->
   * List<X> Constraints: A << F corresponds to: F.collectSubstitutes(..., A, ...,
   * CONSTRAINT_EXTENDS (1)) A = F corresponds to: F.collectSubstitutes(..., A, ...,
   * CONSTRAINT_EQUAL (0)) A >> F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_SUPER
   * (2))
   */
  public void collectSubstitutes(
      Scope scope, TypeBinding actualType, InferenceContext inferenceContext, int constraint) {

    //	only infer for type params of the generic method
    if (this.declaringElement != inferenceContext.genericMethod) return;

    // cannot infer anything from a null type
    switch (actualType.kind()) {
      case Binding.BASE_TYPE:
        if (actualType == TypeBinding.NULL) return;
        TypeBinding boxedType = scope.environment().computeBoxingType(actualType);
        if (boxedType == actualType) return; // $IDENTITY-COMPARISON$
        actualType = boxedType;
        break;
      case Binding.POLY_TYPE: // cannot steer inference, only learn from it.
      case Binding.WILDCARD_TYPE:
        return; // wildcards are not true type expressions (JLS 15.12.2.7, p.453 2nd discussion)
    }

    // reverse constraint, to reflect variable on rhs:   A << T --> T >: A
    int variableConstraint;
    switch (constraint) {
      case TypeConstants.CONSTRAINT_EQUAL:
        variableConstraint = TypeConstants.CONSTRAINT_EQUAL;
        break;
      case TypeConstants.CONSTRAINT_EXTENDS:
        variableConstraint = TypeConstants.CONSTRAINT_SUPER;
        break;
      default:
        // case CONSTRAINT_SUPER :
        variableConstraint = TypeConstants.CONSTRAINT_EXTENDS;
        break;
    }
    inferenceContext.recordSubstitute(this, actualType, variableConstraint);
  }
Esempio n. 23
0
  /**
   * Answer the receiver's constant pool name. NOTE: This method should only be used during/after
   * code gen. e.g. '[Ljava/lang/Object;'
   */
  public char[] constantPoolName() {
    if (constantPoolName != null) return constantPoolName;

    char[] brackets = new char[dimensions];
    for (int i = dimensions - 1; i >= 0; i--) brackets[i] = '[';
    return constantPoolName = CharOperation.concat(brackets, leafComponentType.signature());
  }
Esempio n. 24
0
  protected boolean isBoxingCompatible(
      TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope) {
    if (scope.isBoxingCompatibleWith(expressionType, targetType)) return true;

    return expressionType
            .isBaseType() // narrowing then boxing ? Only allowed for some target types see 362279
        && !targetType.isBaseType()
        && !targetType.isTypeVariable()
        && scope.compilerOptions().sourceLevel
            >= org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5 // autoboxing
        && (targetType.id == TypeIds.T_JavaLangByte
            || targetType.id == TypeIds.T_JavaLangShort
            || targetType.id == TypeIds.T_JavaLangCharacter)
        && expression.isConstantValueOfTypeAssignableToType(
            expressionType, scope.environment().computeBoxingType(targetType));
  }
Esempio n. 25
0
 void checkAssignment(BlockScope scope, TypeBinding lhsType, TypeBinding rhsType) {
   FieldBinding leftField = getLastField(this.lhs);
   if (leftField != null
       && rhsType != TypeBinding.NULL
       && (lhsType.kind() == Binding.WILDCARD_TYPE)
       && ((WildcardBinding) lhsType).boundKind != Wildcard.SUPER) {
     scope.problemReporter().wildcardAssignment(lhsType, rhsType, this.expression);
   } else if (leftField != null
       && !leftField.isStatic()
       && leftField.declaringClass != null /*length pseudo field*/
       && leftField.declaringClass.isRawType()) {
     scope.problemReporter().unsafeRawFieldAssignment(leftField, rhsType, this.lhs);
   } else if (rhsType.needsUncheckedConversion(lhsType)) {
     scope.problemReporter().unsafeTypeConversion(this.expression, rhsType, lhsType);
   }
 }
Esempio n. 26
0
 public char[] readableName() /* java.lang.Object[] */ {
   char[] brackets = new char[dimensions * 2];
   for (int i = dimensions * 2 - 1; i >= 0; i -= 2) {
     brackets[i] = ']';
     brackets[i - 1] = '[';
   }
   return CharOperation.concat(leafComponentType.readableName(), brackets);
 }
Esempio n. 27
0
 public char[] sourceName() {
   char[] brackets = new char[dimensions * 2];
   for (int i = dimensions * 2 - 1; i >= 0; i -= 2) {
     brackets[i] = ']';
     brackets[i - 1] = '[';
   }
   return CharOperation.concat(leafComponentType.sourceName(), brackets);
 }
  /* (non-Javadoc)
   * @see org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding#superclass()
   */
  public ReferenceBinding superclass() {
    if (this.superclass == null) {
      TypeBinding superType = null;
      if (this.boundKind == Wildcard.EXTENDS && !this.bound.isInterface()) {
        superType = this.bound;
      } else {
        TypeVariableBinding variable = typeVariable();
        if (variable != null) superType = variable.firstBound;
      }
      this.superclass =
          superType instanceof ReferenceBinding && !superType.isInterface()
              ? (ReferenceBinding) superType
              : this.environment.getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null);
    }

    return this.superclass;
  }
  /**
   * Returns true if the 2 variables are playing exact same role: they have the same bounds,
   * providing one is substituted with the other: <T1 extends List<T1>> is interchangeable with <T2
   * extends List<T2>>.
   */
  public boolean isInterchangeableWith(TypeVariableBinding otherVariable, Substitution substitute) {
    if (TypeBinding.equalsEquals(this, otherVariable)) return true;
    int length = this.superInterfaces.length;
    if (length != otherVariable.superInterfaces.length) return false;

    if (TypeBinding.notEquals(
        this.superclass, Scope.substitute(substitute, otherVariable.superclass))) return false;

    next:
    for (int i = 0; i < length; i++) {
      TypeBinding superType = Scope.substitute(substitute, otherVariable.superInterfaces[i]);
      for (int j = 0; j < length; j++)
        if (TypeBinding.equalsEquals(superType, this.superInterfaces[j])) continue next;
      return false; // not a match
    }
    return true;
  }
 /*
  * parameterizedDeclaringUniqueKey dot selector originalMethodGenericSignature percent typeArguments
  * p.X<U> { <T> void bar(T t, U u) { new X<String>().bar(this, "") } } --> Lp/X<Ljava/lang/String;>;.bar<T:Ljava/lang/Object;>(TT;Ljava/lang/String;)V%<Lp/X;>
  */
 public char[] computeUniqueKey(boolean isLeaf) {
   StringBuffer buffer = new StringBuffer();
   buffer.append(this.originalMethod.computeUniqueKey(false /*not a leaf*/));
   buffer.append('%');
   buffer.append('<');
   if (!this.isRaw) {
     int length = this.typeArguments.length;
     for (int i = 0; i < length; i++) {
       TypeBinding typeArgument = this.typeArguments[i];
       buffer.append(typeArgument.computeUniqueKey(false /*not a leaf*/));
     }
   }
   buffer.append('>');
   int resultLength = buffer.length();
   char[] result = new char[resultLength];
   buffer.getChars(0, resultLength, result, 0);
   return result;
 }