public Set<QualifiedName> getImportedNames(XtextResource resource) {
   XPackage xPackage = getXPackage(resource);
   String packageName = xPackage.getName();
   List<String> implicitPackageImports = newArrayList(packageName, "java.lang");
   Set<QualifiedName> importedNames = newLinkedHashSet();
   Map<String, QualifiedName> implicitAliases = getImplicitAliases();
   for (INode node : XcoreUtil.importableCrossReferences(xPackage)) {
     CrossReference grammarElement = (CrossReference) node.getGrammarElement();
     EObject container = grammarElement.eContainer();
     if (container instanceof Assignment) {
       String name = node.getText().trim();
       if (name.endsWith("::")) {
         name = name.substring(0, name.length() - 2);
       }
       QualifiedName actualQualifiedName = nameConverter.toQualifiedName(name);
       Assignment assignment = (Assignment) container;
       String feature = assignment.getFeature();
       EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
       EStructuralFeature eStructuralFeature =
           semanticObject.eClass().getEStructuralFeature(feature);
       if (!eStructuralFeature.isMany()) {
         EObject eCrossReference = (EObject) semanticObject.eGet(eStructuralFeature);
         EObject eContainer = eCrossReference.eContainer();
         if (eContainer != xPackage
             && !(eContainer instanceof XPackage
                 && "xcore.lang".equals(((XPackage) eContainer).getName()))
             && !(eContainer instanceof GenPackage
                 && packageName.equals(((GenPackage) eContainer).getQualifiedPackageName()))
             && !(eCrossReference instanceof JvmDeclaredType
                 && implicitPackageImports.contains(
                     ((JvmDeclaredType) eCrossReference).getPackageName()))) {
           QualifiedName fullyQualifiedName = nameProvider.getFullyQualifiedName(eCrossReference);
           if (fullyQualifiedName != null
               && !actualQualifiedName.equals(fullyQualifiedName)
               && !fullyQualifiedName.equals(implicitAliases.get(name))) {
             importedNames.add(fullyQualifiedName);
           }
         }
       } else {
         throw new RuntimeException("Not expecting multi-valued cross references in these models");
       }
     } else {
       throw new RuntimeException(
           "Expecting all cross references to be part of an assignment in these models");
     }
   }
   return importedNames;
 }
  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;
  }