public TypeReference copyDims(int dim, Annotation[][] annotationsOnDims) {
   ParameterizedSingleTypeReference parameterizedSingleTypeReference =
       new ParameterizedSingleTypeReference(
           this.token,
           this.typeArguments,
           dim,
           annotationsOnDims,
           (((long) this.sourceStart) << 32) + this.sourceEnd);
   parameterizedSingleTypeReference.bits |= (this.bits & ASTNode.HasTypeAnnotations);
   if (annotationsOnDims != null) {
     parameterizedSingleTypeReference.bits |= ASTNode.HasTypeAnnotations;
   }
   return parameterizedSingleTypeReference;
 }
Esempio n. 2
0
  /**
   * You can't share TypeReference objects or subtle errors start happening. Unfortunately the
   * TypeReference type hierarchy is complicated and there's no clone method on TypeReference
   * itself. This method can clone them.
   */
  public static TypeReference copyType(TypeReference ref, ASTNode source) {
    if (ref instanceof ParameterizedQualifiedTypeReference) {
      ParameterizedQualifiedTypeReference iRef = (ParameterizedQualifiedTypeReference) ref;
      TypeReference[][] args = null;
      if (iRef.typeArguments != null) {
        args = new TypeReference[iRef.typeArguments.length][];
        int idx = 0;
        for (TypeReference[] inRefArray : iRef.typeArguments) {
          if (inRefArray == null) args[idx++] = null;
          else {
            TypeReference[] outRefArray = new TypeReference[inRefArray.length];
            int idx2 = 0;
            for (TypeReference inRef : inRefArray) {
              outRefArray[idx2++] = copyType(inRef, source);
            }
            args[idx++] = outRefArray;
          }
        }
      }
      TypeReference typeRef =
          new ParameterizedQualifiedTypeReference(
              iRef.tokens, args, iRef.dimensions(), iRef.sourcePositions);
      setGeneratedBy(typeRef, source);
      return typeRef;
    }

    if (ref instanceof ArrayQualifiedTypeReference) {
      ArrayQualifiedTypeReference iRef = (ArrayQualifiedTypeReference) ref;
      TypeReference typeRef =
          new ArrayQualifiedTypeReference(iRef.tokens, iRef.dimensions(), iRef.sourcePositions);
      setGeneratedBy(typeRef, source);
      return typeRef;
    }

    if (ref instanceof QualifiedTypeReference) {
      QualifiedTypeReference iRef = (QualifiedTypeReference) ref;
      TypeReference typeRef = new QualifiedTypeReference(iRef.tokens, iRef.sourcePositions);
      setGeneratedBy(typeRef, source);
      return typeRef;
    }

    if (ref instanceof ParameterizedSingleTypeReference) {
      ParameterizedSingleTypeReference iRef = (ParameterizedSingleTypeReference) ref;
      TypeReference[] args = null;
      if (iRef.typeArguments != null) {
        args = new TypeReference[iRef.typeArguments.length];
        int idx = 0;
        for (TypeReference inRef : iRef.typeArguments) {
          if (inRef == null) args[idx++] = null;
          else args[idx++] = copyType(inRef, source);
        }
      }

      TypeReference typeRef =
          new ParameterizedSingleTypeReference(
              iRef.token, args, iRef.dimensions(), (long) iRef.sourceStart << 32 | iRef.sourceEnd);
      setGeneratedBy(typeRef, source);
      return typeRef;
    }

    if (ref instanceof ArrayTypeReference) {
      ArrayTypeReference iRef = (ArrayTypeReference) ref;
      TypeReference typeRef =
          new ArrayTypeReference(
              iRef.token, iRef.dimensions(), (long) iRef.sourceStart << 32 | iRef.sourceEnd);
      setGeneratedBy(typeRef, source);
      return typeRef;
    }

    if (ref instanceof Wildcard) {
      Wildcard wildcard = new Wildcard(((Wildcard) ref).kind);
      wildcard.sourceStart = ref.sourceStart;
      wildcard.sourceEnd = ref.sourceEnd;
      setGeneratedBy(wildcard, source);
      return wildcard;
    }

    if (ref instanceof SingleTypeReference) {
      SingleTypeReference iRef = (SingleTypeReference) ref;
      TypeReference typeRef =
          new SingleTypeReference(iRef.token, (long) iRef.sourceStart << 32 | iRef.sourceEnd);
      setGeneratedBy(typeRef, source);
      return typeRef;
    }

    return ref;
  }