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;
 }
 protected SignatureHashBuilder appendTypeParameter(JvmTypeParameter p) {
   if (p != null && p.getIdentifier() != null) {
     append(p.getIdentifier());
   } else {
     append("*unresolved*");
   }
   return this;
 }
 protected boolean isCompatibleArgument(
     JvmTypeReference declaredType, JvmTypeReference actualType) {
   if (actualType == null) return true;
   if (actualType.getType() instanceof JvmTypeParameter) {
     JvmTypeParameter type = (JvmTypeParameter) actualType.getType();
     if (type.getConstraints().isEmpty()) return true;
     for (JvmTypeConstraint constraint : type.getConstraints()) {
       if (isCompatibleArgument(declaredType, constraint.getTypeReference())) return true;
     }
     return false;
   }
   return conformance.isConformant(declaredType, actualType, true);
 }
Ejemplo n.º 4
0
 protected void copyAndFixTypeParameters(
     List<JvmTypeParameter> typeParameters, JvmTypeParameterDeclarator target) {
   for (JvmTypeParameter typeParameter : typeParameters) {
     final JvmTypeParameter clonedTypeParameter = cloneWithProxies(typeParameter);
     target.getTypeParameters().add(clonedTypeParameter);
     boolean upperBoundSeen = false;
     for (JvmTypeConstraint constraint : clonedTypeParameter.getConstraints()) {
       if (constraint instanceof JvmUpperBound) {
         upperBoundSeen = true;
         break;
       }
     }
     if (!upperBoundSeen) {
       JvmUpperBound upperBound = typesFactory.createJvmUpperBound();
       upperBound.setTypeReference(typeReferences.getTypeForName(Object.class, typeParameter));
       clonedTypeParameter.getConstraints().add(upperBound);
     }
     associator.associate(typeParameter, clonedTypeParameter);
   }
 }
Ejemplo n.º 5
0
 @Check
 public void checkStartsWithCapital(final JvmTypeParameter ne) {
   String _name = ne.getName();
   char _charAt = _name.charAt(0);
   boolean _isUpperCase = Character.isUpperCase(_charAt);
   boolean _not = (!_isUpperCase);
   if (_not) {
     this.error(
         "Type parameter name must start with a capital",
         TypesPackage.Literals.JVM_TYPE_PARAMETER__NAME);
   }
 }
Ejemplo n.º 6
0
 public boolean isLocalTypeParameter(EObject context, JvmTypeParameter parameter) {
   if (context == parameter.getDeclarator()) return true;
   if (context instanceof JvmOperation && ((JvmOperation) context).isStatic()) return false;
   if (context instanceof JvmDeclaredType && ((JvmDeclaredType) context).isStatic()) return false;
   JvmIdentifiableElement jvmElement = contextProvider.getLogicalContainer(context);
   if (jvmElement != null) {
     return isLocalTypeParameter(jvmElement, parameter);
   }
   EObject container = context.eContainer();
   if (container == null) {
     return false;
   }
   return isLocalTypeParameter(container, parameter);
 }
Ejemplo n.º 7
0
 protected IScope createTypeScope(
     JvmIdentifiableElement context, EReference reference, IScope parentScope) {
   if (context == null) return parentScope;
   if (context.eContainer() instanceof JvmIdentifiableElement) {
     parentScope =
         createTypeScope((JvmIdentifiableElement) context.eContainer(), reference, parentScope);
   }
   if (context instanceof JvmGenericType) {
     JvmGenericType genericType = (JvmGenericType) context;
     List<IEObjectDescription> descriptions = Lists.newArrayList();
     if (genericType.getSimpleName() != null) {
       QualifiedName inferredDeclaringTypeName = QualifiedName.create(genericType.getSimpleName());
       descriptions.add(EObjectDescription.create(inferredDeclaringTypeName, genericType));
     }
     for (JvmTypeParameter param : genericType.getTypeParameters()) {
       if (param.getSimpleName() != null) {
         QualifiedName paramName = QualifiedName.create(param.getSimpleName());
         descriptions.add(EObjectDescription.create(paramName, param));
       }
     }
     if (!descriptions.isEmpty()) return MapBasedScope.createScope(parentScope, descriptions);
   } else if (context instanceof JvmOperation) {
     JvmOperation operation = (JvmOperation) context;
     List<IEObjectDescription> descriptions = null;
     for (JvmTypeParameter param : operation.getTypeParameters()) {
       if (param.getSimpleName() != null) {
         if (descriptions == null) descriptions = Lists.newArrayList();
         QualifiedName paramName = QualifiedName.create(param.getSimpleName());
         descriptions.add(EObjectDescription.create(paramName, param));
       }
     }
     if (descriptions != null && !descriptions.isEmpty())
       return MapBasedScope.createScope(parentScope, descriptions);
   }
   return parentScope;
 }
  protected IScope getLocalElementsScope(
      IScope parent, IScope globalScope, EObject context, EReference reference) {
    IScope result = parent;
    QualifiedName name = getQualifiedNameOfLocalElement(context);
    boolean ignoreCase = isIgnoreCase(reference);
    ISelectable resourceOnlySelectable = getAllDescriptions(context.eResource());
    ISelectable globalScopeSelectable = new ScopeBasedSelectable(globalScope);

    // imports
    List<ImportNormalizer> explicitImports = getImportedNamespaceResolvers(context, ignoreCase);
    if (!explicitImports.isEmpty()) {
      result =
          createImportScope(
              result,
              explicitImports,
              globalScopeSelectable,
              reference.getEReferenceType(),
              ignoreCase);
    }

    // local element
    if (name != null) {
      ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
      result =
          createImportScope(
              result,
              singletonList(localNormalizer),
              resourceOnlySelectable,
              reference.getEReferenceType(),
              ignoreCase);
    }

    // scope for jvm elements
    Set<EObject> elements = associations.getJvmElements(context);
    for (EObject derivedJvmElement : elements) {
      // scope for JvmDeclaredTypes
      if (derivedJvmElement instanceof JvmDeclaredType) {
        JvmDeclaredType declaredType = (JvmDeclaredType) derivedJvmElement;
        QualifiedName jvmTypeName = getQualifiedNameOfLocalElement(declaredType);
        if (declaredType.getDeclaringType() == null
            && !Strings.isEmpty(declaredType.getPackageName())) {
          QualifiedName packageName =
              this.qualifiedNameConverter.toQualifiedName(declaredType.getPackageName());
          ImportNormalizer normalizer = doCreateImportNormalizer(packageName, true, ignoreCase);
          result =
              createImportScope(
                  result,
                  singletonList(normalizer),
                  globalScopeSelectable,
                  reference.getEReferenceType(),
                  ignoreCase);
        }
        if (jvmTypeName != null && !jvmTypeName.equals(name)) {
          ImportNormalizer localNormalizer =
              doCreateImportNormalizer(jvmTypeName, true, ignoreCase);
          result =
              createImportScope(
                  result,
                  singletonList(localNormalizer),
                  resourceOnlySelectable,
                  reference.getEReferenceType(),
                  ignoreCase);
        }
      }
      // scope for JvmTypeParameterDeclarator
      if (derivedJvmElement instanceof JvmTypeParameterDeclarator) {
        JvmTypeParameterDeclarator parameterDeclarator =
            (JvmTypeParameterDeclarator) derivedJvmElement;
        List<IEObjectDescription> descriptions = null;
        for (JvmTypeParameter param : parameterDeclarator.getTypeParameters()) {
          if (param.getSimpleName() != null) {
            if (descriptions == null) descriptions = Lists.newArrayList();
            QualifiedName paramName = QualifiedName.create(param.getSimpleName());
            descriptions.add(EObjectDescription.create(paramName, param));
          }
        }
        if (descriptions != null && !descriptions.isEmpty())
          result = MapBasedScope.createScope(result, descriptions);
      }
    }
    return result;
  }