Exemple #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 param(JvmTypeConstraint... constraints) {
   JvmParameterizedTypeReference result =
       TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
   JvmTypeParameter parameter = TypesFactory.eINSTANCE.createJvmTypeParameter();
   parameter.getConstraints().addAll(Arrays.asList(constraints));
   result.setType(parameter);
   return result;
 }
Exemple #3
0
 @Check
 public void checkSpecializeReference(final Ecosystem ecosystem) {
   final JvmParameterizedTypeReference superTypeRef = ecosystem.getSpecializes();
   boolean _tripleNotEquals = (superTypeRef != null);
   if (_tripleNotEquals) {
     JvmType _type = superTypeRef.getType();
     final Ecosystem superType = this._speADLUtils.associatedEcosystem(_type);
     boolean _tripleEquals = (superType == null);
     if (_tripleEquals) {
       JvmParameterizedTypeReference _specializes = ecosystem.getSpecializes();
       String _simpleName = _specializes.getSimpleName();
       String _plus = (_simpleName + " cannot be resolved");
       JvmParameterizedTypeReference _specializes_1 = ecosystem.getSpecializes();
       this.error(
           _plus, _specializes_1, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
     } else {
       EList<Part> _parts = superType.getParts();
       boolean _isEmpty = _parts.isEmpty();
       boolean _not = (!_isEmpty);
       if (_not) {
         this.error(
             "Can only implements components without subcomponents",
             SpeadlPackage.Literals.ABSTRACT_COMPONENT__SPECIALIZES);
       }
       boolean _hasCycleInHierarchy = this._speADLUtils.hasCycleInHierarchy(superType);
       if (_hasCycleInHierarchy) {
         String _name = ecosystem.getName();
         String _plus_1 = ("The inheritance hierarchy of " + _name);
         String _plus_2 = (_plus_1 + " contains cycles");
         this.error(_plus_2, SpeadlPackage.Literals.ABSTRACT_COMPONENT__NAME);
       }
       boolean _isInvalidWildcard = this.isInvalidWildcard(superTypeRef);
       if (_isInvalidWildcard) {
         String _name_1 = ecosystem.getName();
         String _plus_3 = ("The type " + _name_1);
         String _plus_4 = (_plus_3 + " cannot extend or implement ");
         String _identifier = superTypeRef.getIdentifier();
         String _plus_5 = (_plus_4 + _identifier);
         String _plus_6 = (_plus_5 + ". A supertype may not specify any wildcard");
         this.error(_plus_6, SpeadlPackage.Literals.ABSTRACT_COMPONENT__SPECIALIZES);
       }
       EList<RequiredPort> _requires = ecosystem.getRequires();
       final Procedure2<RequiredPort, Integer> _function =
           new Procedure2<RequiredPort, Integer>() {
             public void apply(final RequiredPort p, final Integer index) {
               SpeADLValidator.this.error(
                   "Requires can\'t be declared in a specialising component",
                   SpeadlPackage.Literals.ABSTRACT_COMPONENT__REQUIRES,
                   (index).intValue());
             }
           };
       IterableExtensions.<RequiredPort>forEach(_requires, _function);
     }
   }
 }
 @Test
 public void testConformanceWithTypeParameter() throws Exception {
   JvmTypeParameter typeParamE =
       ((JvmGenericType) ref(List.class).getType()).getTypeParameters().get(0);
   JvmParameterizedTypeReference reference =
       TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
   reference.setType(typeParamE);
   assertFalse(getComputer().isConformant(reference, ref(Object.class)));
   assertFalse(getComputer().isConformant(reference, ref(String.class)));
   assertFalse(getComputer().isConformant(reference, ref(CharSequence.class)));
   assertFalse(getComputer().isConformant(reference, ref(Serializable.class)));
 }
 @Test
 public void testConformanceWithTypeParameter_02() throws Exception {
   JvmTypeParameter typeParamE =
       ((JvmGenericType) ref(List.class).getType()).getTypeParameters().get(0);
   JvmParameterizedTypeReference reference =
       TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
   reference.setType(typeParamE);
   JvmTypeReference typeParamExtends = param(upper(reference));
   assertTrue(getComputer().isConformant(reference, typeParamExtends, true));
   assertTrue(getComputer().isConformant(reference, typeParamExtends, false));
   assertFalse(getComputer().isConformant(typeParamExtends, reference, true));
   assertFalse(getComputer().isConformant(typeParamExtends, reference, false));
 }
 @Test
 public void testBug300216() {
   JvmDeclaredType type = (JvmDeclaredType) getTypeProvider().findTypeByName("java.lang.Object");
   assertTrue(type.getSuperTypes().isEmpty());
   URI unresolveableType = URI.createURI("java:/Objects/Something#Something");
   JvmVoid proxy = TypesFactory.eINSTANCE.createJvmVoid();
   JvmParameterizedTypeReference typeReference =
       TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
   typeReference.setType(proxy);
   ((InternalEObject) proxy).eSetProxyURI(unresolveableType);
   type.getSuperTypes().add(typeReference);
   assertTrue(type.getSuperTypes().get(0).getType().eIsProxy());
   assertEquals(2, type.eResource().getResourceSet().getResources().size());
 }
Exemple #7
0
 @Check
 public void checkComponentReference(final ComponentPart p) {
   JvmParameterizedTypeReference _componentReference = p.getComponentReference();
   JvmType _type = _componentReference.getType();
   final Ecosystem eco = this._speADLUtils.associatedEcosystem(_type);
   boolean _tripleEquals = (eco == null);
   if (_tripleEquals) {
     JvmParameterizedTypeReference _componentReference_1 = p.getComponentReference();
     String _simpleName = _componentReference_1.getSimpleName();
     String _plus = (_simpleName + " cannot be resolved");
     JvmParameterizedTypeReference _componentReference_2 = p.getComponentReference();
     this.error(
         _plus,
         _componentReference_2,
         TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
   }
 }
 protected JvmTypeReference ref(java.lang.reflect.Type type, JvmTypeReference... arguments) {
   JvmTypeReference result = factory.createTypeReference(type);
   if (arguments.length > 0) {
     for (JvmTypeReference typeArgument : arguments) {
       ((JvmParameterizedTypeReference) result).getArguments().add(typeArgument);
     }
   }
   Resource syntheticResource = getSyntheticResource();
   syntheticResource.getContents().add(result);
   EcoreUtil.resolveAll(syntheticResource);
   return result;
 }
 public void serialize(
     final JvmTypeReference type,
     EObject context,
     IAppendable appendable,
     boolean withoutConstraints,
     boolean paramsToWildcard,
     boolean paramsToObject,
     boolean allowPrimitives) {
   IAppendable tracedAppendable = appendable;
   boolean tracing = false;
   if (appendable instanceof ITreeAppendable && type.eResource() == context.eResource()) {
     tracedAppendable = ((ITreeAppendable) appendable).trace(type);
     tracing = true;
   }
   if (type instanceof JvmWildcardTypeReference) {
     JvmWildcardTypeReference wildcard = (JvmWildcardTypeReference) type;
     if (!withoutConstraints) {
       tracedAppendable.append("?");
     }
     if (!wildcard.getConstraints().isEmpty()) {
       for (JvmTypeConstraint constraint : wildcard.getConstraints()) {
         if (constraint instanceof JvmLowerBound) {
           if (!withoutConstraints) tracedAppendable.append(" super ");
           serialize(
               constraint.getTypeReference(),
               context,
               tracedAppendable,
               withoutConstraints,
               paramsToWildcard,
               paramsToObject,
               false);
           return;
         }
       }
       boolean first = true;
       for (JvmTypeConstraint constraint : wildcard.getConstraints()) {
         if (constraint instanceof JvmUpperBound) {
           if (first) {
             if (!withoutConstraints) tracedAppendable.append(" extends ");
             first = false;
           } else {
             if (withoutConstraints)
               throw new IllegalStateException(
                   "cannot have two upperbounds if type should be printed without constraints");
             tracedAppendable.append(" & ");
           }
           serialize(
               constraint.getTypeReference(),
               context,
               tracedAppendable,
               withoutConstraints,
               paramsToWildcard,
               paramsToObject,
               false);
         }
       }
     } else if (withoutConstraints) {
       tracedAppendable.append("Object");
     }
   } else if (type instanceof JvmGenericArrayTypeReference) {
     serialize(
         ((JvmGenericArrayTypeReference) type).getComponentType(),
         context,
         tracedAppendable,
         withoutConstraints,
         paramsToWildcard,
         paramsToObject,
         true);
     tracedAppendable.append("[]");
   } else if (type instanceof JvmParameterizedTypeReference) {
     JvmParameterizedTypeReference parameterized = (JvmParameterizedTypeReference) type;
     if ((paramsToWildcard || paramsToObject)
         && parameterized.getType() instanceof JvmTypeParameter) {
       JvmTypeParameter parameter = (JvmTypeParameter) parameterized.getType();
       if (!isLocalTypeParameter(context, parameter)) {
         if (paramsToWildcard) tracedAppendable.append("?");
         else tracedAppendable.append("Object");
         return;
       }
     }
     JvmType jvmType =
         allowPrimitives ? type.getType() : primitives.asWrapperTypeIfPrimitive(type).getType();
     if (tracing) {
       ITextRegion region =
           locationProvider.getFullTextRegion(
               type, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, 0);
       if (region instanceof ITextRegionWithLineInformation) {
         ((ITreeAppendable) tracedAppendable)
             .trace(new LocationData((ITextRegionWithLineInformation) region, null))
             .append(jvmType);
       } else {
         tracedAppendable.append(jvmType);
       }
     } else {
       tracedAppendable.append(jvmType);
     }
     if (!parameterized.getArguments().isEmpty()) {
       tracedAppendable.append("<");
       for (int i = 0; i < parameterized.getArguments().size(); i++) {
         if (i != 0) {
           tracedAppendable.append(",");
         }
         serialize(
             parameterized.getArguments().get(i),
             context,
             tracedAppendable,
             withoutConstraints,
             paramsToWildcard,
             paramsToObject,
             false);
       }
       tracedAppendable.append(">");
     }
   } else if (type instanceof JvmAnyTypeReference) {
     tracedAppendable.append("Object");
   } else if (type instanceof JvmMultiTypeReference) {
     serialize(
         resolveMultiType(type, context),
         context,
         tracedAppendable,
         withoutConstraints,
         paramsToWildcard,
         paramsToObject,
         allowPrimitives);
   } else if (type instanceof JvmDelegateTypeReference) {
     JvmTypeReference delegate = ((JvmDelegateTypeReference) type).getDelegate();
     if (delegate != null)
       serialize(
           delegate,
           context,
           tracedAppendable,
           withoutConstraints,
           paramsToWildcard,
           paramsToObject,
           allowPrimitives);
     else tracedAppendable.append("Object");
   } else if (type instanceof JvmSpecializedTypeReference) {
     serialize(
         ((JvmSpecializedTypeReference) type).getEquivalent(),
         context,
         tracedAppendable,
         withoutConstraints,
         paramsToWildcard,
         paramsToObject,
         allowPrimitives);
   } else if (type instanceof JvmUnknownTypeReference) {
     if (type.eIsSet(TypesPackage.Literals.JVM_UNKNOWN_TYPE_REFERENCE__QUALIFIED_NAME)) {
       tracedAppendable.append(type.getQualifiedName());
     } else {
       tracedAppendable.append("Object");
     }
   } else {
     throw new IllegalArgumentException(String.valueOf(type));
   }
 }