Example #1
0
 public JvmParameterizedTypeReference createTypeRef(JvmType type, JvmTypeReference... typeArgs) {
   List<JvmTypeReference> typeReferences = Collections.emptyList();
   if (typeArgs != null && typeArgs.length > 0) {
     typeReferences = newArrayListWithCapacity(typeArgs.length);
     for (int i = 0; i < typeArgs.length; i++) {
       JvmTypeReference jvmTypeReference = typeArgs[i];
       typeReferences.add(EcoreUtil2.clone(jvmTypeReference));
     }
   }
   if (type instanceof JvmGenericType) {
     List<JvmTypeParameter> list = ((JvmGenericType) type).getTypeParameters();
     if (!typeReferences.isEmpty() && list.size() != typeReferences.size()) {
       throw new IllegalArgumentException(
           "The type "
               + type.getIdentifier()
               + " expects "
               + list.size()
               + " type arguments, but was "
               + typeReferences.size()
               + ". Either pass zero arguments (raw type) or the correct number.");
     }
     // Raw type -> create type references to type param
     if (typeReferences.isEmpty() && !list.isEmpty()) {
       typeReferences = newArrayListWithCapacity(list.size());
       for (JvmTypeParameter typeParameter : list) {
         typeReferences.add(createTypeRef(typeParameter));
       }
     }
   }
   JvmParameterizedTypeReference reference = factory.createJvmParameterizedTypeReference();
   reference.setType(type);
   if (!typeReferences.isEmpty()) reference.getArguments().addAll(typeReferences);
   return reference;
 }
 protected JvmTypeReference getTypeProxy(EObject pointer) {
   JvmParameterizedTypeReference typeReference =
       typesFactory.createJvmParameterizedTypeReference();
   final Resource eResource = pointer.eResource();
   String fragment = eResource.getURIFragment(pointer);
   URI uri = eResource.getURI();
   uri = uri.appendFragment(Xtend2Resource.FRAGMENT_PREFIX + fragment);
   ((InternalEObject) typeReference).eSetProxyURI(uri);
   return typeReference;
 }