Ejemplo n.º 1
0
 protected void addSectionToAppend(IAcceptor<ReplaceRegion> acceptor) {
   StringBuilder importDeclarationsToAppend = getImportDeclarationsToAppend();
   if (importDeclarationsToAppend.length() == 0) return;
   importRegion = regionUtil.addLeadingWhitespace(importRegion, resource);
   importRegion = regionUtil.addTrailingSingleWhitespace(importRegion, lineSeparator, resource);
   int insertOffset = importRegion.getOffset() + importRegion.getLength();
   if (insertOffset != 0 && originalImportDeclarations.isEmpty())
     importDeclarationsToAppend.insert(0, lineSeparator);
   importDeclarationsToAppend.append(lineSeparator);
   int insertLength = -importRegion.getLength();
   insertLength += regionUtil.addTrailingWhitespace(importRegion, resource).getLength();
   ReplaceRegion appendDeclarations =
       new ReplaceRegion(
           new TextRegion(insertOffset, insertLength), importDeclarationsToAppend.toString());
   acceptor.accept(appendDeclarations);
 }
Ejemplo n.º 2
0
 protected String serializeImports(List<XImportDeclaration> allDeclarations) {
   StringBuilder builder = new StringBuilder();
   if (needsPreceedingBlankLine()) builder.append(lineSeparator).append(lineSeparator);
   boolean needNewline =
       appendSubsection(
           builder,
           filter(
               allDeclarations,
               new Predicate<XImportDeclaration>() {
                 @Override
                 public boolean apply(XImportDeclaration input) {
                   return !input.isStatic();
                 }
               }),
           false);
   needNewline =
       appendSubsection(
           builder,
           filter(
               allDeclarations,
               new Predicate<XImportDeclaration>() {
                 @Override
                 public boolean apply(XImportDeclaration input) {
                   return input.isStatic() && !input.isExtension();
                 }
               }),
           needNewline);
   appendSubsection(
       builder,
       filter(
           allDeclarations,
           new Predicate<XImportDeclaration>() {
             @Override
             public boolean apply(XImportDeclaration input) {
               return input.isStatic() && input.isExtension();
             }
           }),
       needNewline);
   if (!isEmpty(allDeclarations)) builder.append(lineSeparator);
   return builder.toString();
 }