protected IScope doGetTypeScope(XFeatureCall call, JvmType type) {
   if (call.isPackageFragment()) {
     if (type instanceof JvmDeclaredType) {
       String packageName = ((JvmDeclaredType) type).getPackageName();
       int dot = packageName.indexOf('.');
       if (dot == -1) {
         return new SingletonScope(EObjectDescription.create(packageName, type), IScope.NULLSCOPE);
       } else {
         String firstSegment = packageName.substring(0, dot);
         return new SingletonScope(
             EObjectDescription.create(firstSegment, type), IScope.NULLSCOPE);
       }
     }
     return IScope.NULLSCOPE;
   } else {
     if (type instanceof JvmDeclaredType && ((JvmDeclaredType) type).getDeclaringType() != null) {
       Resource resource = call.eResource();
       if (resource instanceof XtextResource) {
         XImportSection importSection =
             importsConfiguration.getImportSection((XtextResource) resource);
         if (importSection != null) {
           List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
           List<IEObjectDescription> descriptions = Lists.newArrayList();
           for (XImportDeclaration importDeclaration : importDeclarations) {
             if (!importDeclaration.isStatic()
                 && !importDeclaration.isWildcard()
                 && !importDeclaration.isExtension()) {
               JvmDeclaredType importedType = importDeclaration.getImportedType();
               if (importedType == type) {
                 String syntax = importsConfiguration.getLegacyImportSyntax(importDeclaration);
                 if (syntax != null /* no node model attached */
                     && syntax.equals(type.getQualifiedName())) {
                   String packageName = importedType.getPackageName();
                   descriptions.add(
                       EObjectDescription.create(
                           syntax.substring(packageName.length() + 1), type));
                 }
               }
               if (EcoreUtil.isAncestor(importedType, type)) {
                 String name = type.getSimpleName();
                 JvmType worker = type;
                 while (worker != importedType) {
                   worker = (JvmType) worker.eContainer();
                   name = worker.getSimpleName() + "$" + name;
                 }
                 descriptions.add(EObjectDescription.create(name, type));
               }
             }
           }
           return new SimpleScope(descriptions);
         }
       }
       return new SingletonScope(
           EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE);
     } else {
       return new SingletonScope(
           EObjectDescription.create(type.getSimpleName(), type), IScope.NULLSCOPE);
     }
   }
 }
예제 #2
0
 public RewritableImportSection(
     XtextResource resource,
     IImportsConfiguration importsConfiguration,
     XImportSection originalImportSection,
     String lineSeparator,
     ImportSectionRegionUtil regionUtil,
     IValueConverter<String> nameConverter) {
   this.importsConfiguration = importsConfiguration;
   this.resource = resource;
   this.lineSeparator = lineSeparator;
   this.regionUtil = regionUtil;
   this.nameValueConverter = nameConverter;
   this.implicitlyImportedPackages = importsConfiguration.getImplicitlyImportedPackages(resource);
   this.importRegion = regionUtil.computeRegion(resource);
   if (originalImportSection != null) {
     for (XImportDeclaration originalImportDeclaration :
         originalImportSection.getImportDeclarations()) {
       this.originalImportDeclarations.add(originalImportDeclaration);
       JvmDeclaredType importedType = originalImportDeclaration.getImportedType();
       if (originalImportDeclaration.isStatic()) {
         String memberName = originalImportDeclaration.getMemberName();
         if (originalImportDeclaration.isExtension()) {
           Maps2.putIntoSetMap(importedType, memberName, staticExtensionImports);
         } else {
           Maps2.putIntoSetMap(importedType, memberName, staticImports);
         }
       } else if (importedType != null) {
         Maps2.putIntoListMap(importedType.getSimpleName(), importedType, plainImports);
       }
     }
   }
 }
 protected List<ImportNormalizer> getImportedNamespaceResolvers(
     XImportSection importSection, boolean ignoreCase) {
   List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
   List<ImportNormalizer> result = Lists.newArrayListWithExpectedSize(importDeclarations.size());
   for (XImportDeclaration imp : importDeclarations) {
     if (!imp.isStatic()) {
       String value = imp.getImportedNamespace();
       if (value == null) value = imp.getImportedTypeName();
       ImportNormalizer resolver = createImportedNamespaceResolver(value, ignoreCase);
       if (resolver != null) result.add(resolver);
     }
   }
   return result;
 }
예제 #4
0
  public void update() {
    XImportSection importSection = importsConfiguration.getImportSection(resource);
    if (importSection == null && importsConfiguration instanceof IMutableImportsConfiguration) {
      importSection = XtypeFactory.eINSTANCE.createXImportSection();

      IMutableImportsConfiguration mutableImportsConfiguration =
          (IMutableImportsConfiguration) importsConfiguration;
      mutableImportsConfiguration.setImportSection(resource, importSection);
    }
    if (importSection == null) {
      return;
    }
    removeObsoleteStaticImports();

    List<XImportDeclaration> allImportDeclarations = newArrayList();
    allImportDeclarations.addAll(originalImportDeclarations);
    allImportDeclarations.addAll(addedImportDeclarations);
    allImportDeclarations.removeAll(removedImportDeclarations);

    List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
    importDeclarations.clear();
    importDeclarations.addAll(allImportDeclarations);
  }