package net.chrizzly.csharp4netbeans.filetypes.cs.parser.reformatting;

import javax.swing.text.BadLocationException;
import org.netbeans.modules.editor.indent.spi.Context;
import org.netbeans.modules.editor.indent.spi.ExtraLock;
import org.netbeans.modules.editor.indent.spi.ReformatTask;
import org.openide.awt.StatusDisplayer;

/**
 *
 * @author chrl
 */
public class CsReformatTask implements ReformatTask {

    private Context context;

    public CsReformatTask(Context context) {
        this.context = context;
    }

    @Override
    public void reformat() throws BadLocationException {
        StatusDisplayer.getDefault().setStatusText("We will format this now...");
    }

    @Override
    public ExtraLock reformatLock() {
        return null;
    }
    
}
@@ -65,16 +65,39 @@
 tting;%0A%0A
+import java.util.List;%0A
 import j
@@ -134,16 +134,102 @@
 eption;%0A
+import javax.swing.text.Document;%0Aimport net.chrizzly.csharp4netbeans.utils.MiscUtil;%0A
 import o
@@ -527,16 +527,22 @@
 private 
+final 
 Context 
@@ -788,16 +788,410 @@
 w...%22);%0A
+        Document document = context.document();%0A        String fileContent = document.getText(document.getStartPosition().getOffset(),%0A                document.getEndPosition().getOffset());%0A        String fileFormattedFinal = formatFile(fileContent, 4);%0A        int length = document.getLength();%0A        document.remove(0, length);%0A        document.insertString(0, fileFormattedFinal, null);%0A
     %7D%0A%0A 
@@ -1268,14 +1268,1064 @@
 ;%0A    %7D%0A
+%0A
     
+private static String formatFile(String fileContent, int spacesToIncrement) %7B%0A        short currentSpacesToUse = 0;%0A%0A        StringBuilder sbResult = new StringBuilder();%0A%0A        List%3CString%3E listLines = MiscUtil.getLinesFromFileContent(fileContent);%0A        for (String line : listLines) %7B%0A            int openTagsAmount = MiscUtil.getOpenSymbolsAmount(line);%0A%0A            String amountSeparatorChars;%0A            if (openTagsAmount %3E 0) %7B%0A                amountSeparatorChars = MiscUtil.getAmountSeparatorChars(currentSpacesToUse);%0A                currentSpacesToUse += spacesToIncrement * openTagsAmount;%0A            %7D else %7B%0A                currentSpacesToUse += spacesToIncrement * openTagsAmount;%0A                amountSeparatorChars = MiscUtil.getAmountSeparatorChars(currentSpacesToUse);%0A            %7D%0A%0A            sbResult.append(amountSeparatorChars).append(line.trim()).append(MiscUtil.LINE_SEPARATOR);%0A        %7D%0A%0A        return sbResult.toString().substring(0, sbResult.length() - 1); //substring to remove the last LINE_SEPARATOR%0A    %7D
 %0A%7D

Copy over the reformat code from a fork of pedro.