Пример #1
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);
       }
     }
   }
 }
Пример #2
0
 public RewritableImportSection parse(XtextResource resource) {
   RewritableImportSection rewritableImportSection =
       new RewritableImportSection(
           resource,
           importsConfiguration,
           importsConfiguration.getImportSection(resource),
           whitespaceInformationProvider
               .getLineSeparatorInformation(resource.getURI())
               .getLineSeparator(),
           regionUtil,
           nameValueConverter);
   return rewritableImportSection;
 }
Пример #3
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);
  }