Astyle Class

Summary

Formats source code in a given directory to a specified code format.
Assembly
NAnt.Contrib.dll
Namespace
NAnt.Contrib.Tasks
Base Types
  • ExternalProgramBase
graph BT Type-->Base0["ExternalProgramBase"] Type["Astyle"] class Type type-node

Syntax

[TaskName("astyle")]
public class Astyle : ExternalProgramBase

Examples

    <astyle style="NAnt" cleanup="true">
    <sources>
        <include name="**/**.cs" />
    </sources>
</astyle>

Remarks

Most examples inline have been produced by Tal Davidson and team and are part of the astyle documentation. They have been included in the task documentation as an easy reference.

NOTE: This task relies on the astyle.exe file being in your path variable. Please download the astyle.exe from http://astyle.sourceforge.net.

Attributes

Type Description
TaskName

Properties

Name Value Summary
BracketsAttach bool
true if brackets should be attached.
if (isFoo){
    bar();
} else {
    anotherBar();
}
BracketsLinux bool
true if brackets should be put on a new line and indented.
namespace foospace
{
    int Foo()
    {
        if (isBar) {
            bar();
            return 1;
        } else
            return 0;
    }
}
BracketsNewLine bool
true if brackets should be put on a new line.
if (isFoo)
{
    bar();
}
else
{
    anotherBar();
}
BreakBlocks bool
true to break block statements with an empty line.
    isFoo = true;
    if (isFoo) {
        bar();
    } else {
        anotherBar();
    }
    isBar = false;

    becomes:

    isFoo = true;

    if (isFoo) {
        bar();
    } else {
        anotherBar();
    }

    isBar = false;
BreakBlocksAll bool
true to break all block statements, even on nested ifs with an empty line.
    isFoo = true;
    if (isFoo) {
        bar();
    } else {
        anotherBar();
    }
    isBar = false;

    becomes:

    isFoo = true;

    if (isFoo) {
        bar();

    } else {
        anotherBar();
    }

    isBar = false;
BreakClosing bool
true if the line after a bracket (i.e. an else statement after the closing if) should be placed on the next line.
    if (isFoo){
        bar();
    }else {
        anotherBar();
    }

    becomes:

    if (isFoo) {
        bar();
    }
    else {
        anotherBar();
    }
BreakElseif bool
true to put the if component of an else if on a new line.
    if (isFoo) {
        bar();
    } else if (isBar()){
        anotherBar();
    }

    becomes:

    if (isFoo) {
        bar();
    } else
        if (isBar()){
            anotherBar();
        } 
CleanUp bool
Astyle leaves the original files around, renamed with a different suffix. Setting this to
true
will remove these files.
CommandLineArguments string
The command-line arguments for the program.
CommandOptions Hashtable
A collection of command line option switches.
ConvertTabs bool
true to convert tabs to spaces.
FillEmptyLines bool
true if empty lines should be filled with the whitespace of the previous line.
IndentBlock bool
true if block statements should be indented. The default: if (isFoo) { bar(); } else anotherBar(); becomes: if (isFoo) { bar(); } else anotherBar();
IndentBracket bool
true
if bracket statements should be indented.
    The default:

    if (isFoo)
    {
        bar();
    }
    else
    {
        anotherBar();
    }

    becomes:

    if (isFoo)
        {
        bar();
        }
    else
        {
        anotherBar();
        }
IndentCase bool
true if case statements should be indented.
    The default:

    switch (foo)
    {
    case 1:
        {
            a += 2;
            break;
        }

    default:
        {
            a += 2;
            break;
        }
    }

    becomes:

    switch (foo)
    {
        case 1:
        {
            a += 2;
            break;
        }

        default:
        {
            a += 2;
            break;
        }
    }
IndentClass bool
true if class statements should be indented.
    The default:

    class Foo
    {
    public:
        Foo();
        virtual ~Foo();
    };

    becomes:

    class Foo
    {
        public:
            Foo();
            virtual ~Foo();
    };
IndentLabels bool
true if label statements should be indented.
    The default:

    int foospace()
    {
        while (isFoo)
        {
            ...
            goto error;

    error:
            ...
        }
    }

    becomes:

    int foospace()
    {
        while (isFoo)
        {
            ...
            goto error;

        error:
            ...
        }
    }
IndentMax int
Indicate the maximum number of spaces to indent relative to a previous line.
IndentMin int
Indicate the maximum number of spaces to indent relative to a previous line.
IndentNamespaces bool
true if namespace statements should be indented.
    The default:

    namespace foospace
    {
    class Foo
    {
        public:
            Foo();
            virtual ~Foo();
    };
    }

    becomes:

    namespace foospace
    {
        class Foo
        {
            public:
                Foo();
                virtual ~Foo();
        };
    }
IndentNumSpaces int
Indicate the maximum number of spaces to indent relative to a previous line.
IndentNumTabs int
Indicate that tabs should be used to indent sources. The number specified indicates the maximum number of spaces the tab character will represent.
IndentNumTabsForce int
Indent using tab characters. Treat each tab as # spaces. Uses tabs as indents in areas '--indent=tab' prefers to use spaces, such as inside multi-line statements.
IndentSwitch bool
true if switch statements should be indented.
        The default:

        switch (foo)
        {
        case 1:
            a += 2;
            break;

        default:
            a += 2;
            break;
        }

        becomes:

        switch (foo)
        {
            case 1:
                a += 2;
                break;

            default:
                a += 2;
                break;
        }
NoBreakComplex bool
true to keep complex statements on the same line.
    if (isFoo)
    {  
        isFoo = false; cout << isFoo << endl;
    }

    remains as is.

    if (isFoo) DoBar();

    remains as is.
NoBreakSingleLineBlocks bool
true to keep single line statements on the same line.
    if (isFoo)
    { isFoo = false; cout << isFoo << endl; }

    remains as is.
PadAll bool
true to pad operators and parenthesis.
    if (isFoo)
        a = bar((b-c)*a,*d--);

    becomes:

    if ( isFoo )
        a = bar( ( b - c ) * a, *d-- );
PadOperators bool
true to pad operators with a space.
    if (isFoo)
        a = bar((b-c)*a,*d--);

    becomes:

    if (isFoo)
        a = bar((b - c) * a, *d--);
PadParenthesis bool
true to pad parenthesis with a space.
    if (isFoo)
        a = bar((b-c)*a,*d--);

    becomes:

    if ( isFoo )
        a = bar( ( b-c )*a, *d-- );
ProgramArguments string
Gets the command-line arguments for the external program.
Sources FileSet
Used to select the files to copy.
Style string
Indicate the preset style to use. ansi namespace foospace { int Foo() { if (isBar) { bar(); return 1; } else return 0; } } kr ( Kernighan&Ritchie ) namespace foospace { int Foo() { if (isBar) { bar(); return 1; } else return 0; } } linux namespace foospace { int Foo() { if (isBar) { bar(); return 1; } else return 0; } } gnu namespace foospace { int Foo() { if (isBar) { bar(); return 1; } else return 0; } } java class foospace { int Foo() { if (isBar) { bar(); return 1; } else return 0; } } NAnt namespace foospace { class foo() { #region Protected Static Fields private int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } #endregion }
Suffix string
The suffix to append to original files, defaults to .orig if not specified.

Methods

Name Value Summary
ExecuteTask() void
PrepareProcess(Process) void
Build up the command line arguments, determine which executable is being used and find the path to that executable and set the working directory.
SetCommandOption(string, string, bool) void
Adds a new command option if none exists. If one does exist then the use switch is toggled on or of.