Ejemplo n.º 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);
       }
     }
   }
 }
Ejemplo n.º 2
0
 public boolean addImport(JvmDeclaredType type) {
   if (plainImports.containsKey(type.getSimpleName()) || !needsImport(type)) return false;
   Maps2.putIntoListMap(type.getSimpleName(), type, plainImports);
   XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration();
   importDeclaration.setImportedType(type);
   addedImportDeclarations.add(importDeclaration);
   return true;
 }
Ejemplo n.º 3
0
 public boolean addStaticImport(JvmDeclaredType type, String memberName) {
   if (hasStaticImport(staticImports, type, memberName)) {
     return false;
   }
   Maps2.putIntoSetMap(type, memberName, staticImports);
   XImportDeclaration importDeclaration = XtypeFactory.eINSTANCE.createXImportDeclaration();
   importDeclaration.setImportedType(type);
   importDeclaration.setStatic(true);
   if (memberName == null) {
     importDeclaration.setWildcard(true);
   } else {
     importDeclaration.setMemberName(memberName);
   }
   addedImportDeclarations.add(importDeclaration);
   return true;
 }