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;
  }