Example #1
0
wxString FormatOptions::GetClangFormatStyleAsString(const wxFileName& fileName) const
{
    // If the rules file option is enabled it overrides everything here
    if(m_clangFormatOptions & kClangFormatFile) {
        // Even if the user specified to use rules file, we only enable it incase it exists
        if(HasConfigForFile(fileName, ".clang-format")) {
            return "file";
        }
    }

    wxString style = "\"{ BasedOnStyle: ";
    if(m_clangFormatOptions & kClangFormatChromium) {
        style << "Chromium";
    } else if(m_clangFormatOptions & kClangFormatGoogle) {
        style << "Google";
    } else if(m_clangFormatOptions & kClangFormatLLVM) {
        style << "LLVM";
    } else if(m_clangFormatOptions & kClangFormatMozilla) {
        style << "Mozilla";
    } else {
        // Default style
        style << "WebKit";
    }

    // add tab width and space vs tabs based on the global editor settings
    style << ClangGlobalSettings();

    // Language
    clClangFormatLocator locator;
    double clangFormatVersion = locator.GetVersion(GetClangFormatExe());
    if(clangFormatVersion >= 3.5) {
        wxString forceLanguage;

        if(FileExtManager::IsJavascriptFile(fileName)) {
            forceLanguage << "Language : JavaScript";

        } else if(FileExtManager::IsCxxFile(fileName)) {
            forceLanguage << "Language : Cpp";

        } else if(FileExtManager::IsJavaFile(fileName)) {
            forceLanguage << "Language : Java";
        }

        if(!forceLanguage.IsEmpty()) {
            style << ", " << forceLanguage << " ";
        }
    }

    style << ", AlignEscapedNewlinesLeft: " << ClangFlagToBool(kAlignEscapedNewlinesLeft);
    style << ", AlignTrailingComments : " << ClangFlagToBool(kAlignTrailingComments);
    style << ", AllowAllParametersOfDeclarationOnNextLine : "
          << ClangFlagToBool(kAllowAllParametersOfDeclarationOnNextLine);
    if(clangFormatVersion >= 3.5) {
        style << ", AllowShortFunctionsOnASingleLine : " << ClangFlagToBool(kAllowShortFunctionsOnASingleLine);
        style << ", AllowShortBlocksOnASingleLine : " << ClangFlagToBool(kAllowShortBlocksOnASingleLine);
    }
    style << ", AllowShortLoopsOnASingleLine : " << ClangFlagToBool(kAllowShortLoopsOnASingleLine);
    style << ", AllowShortIfStatementsOnASingleLine : " << ClangFlagToBool(kAllowShortIfStatementsOnASingleLine);
    style << ", AlwaysBreakBeforeMultilineStrings : " << ClangFlagToBool(kAlwaysBreakBeforeMultilineStrings);
    style << ", AlwaysBreakTemplateDeclarations : " << ClangFlagToBool(kAlwaysBreakTemplateDeclarations);
    style << ", BinPackParameters : " << ClangFlagToBool(kBinPackParameters);
    style << ", BreakBeforeBinaryOperators : " << ClangFlagToBool(kBreakBeforeBinaryOperators);
    style << ", BreakBeforeTernaryOperators : " << ClangFlagToBool(kBreakBeforeTernaryOperators);
    style << ", BreakConstructorInitializersBeforeComma : "
          << ClangFlagToBool(kBreakConstructorInitializersBeforeComma);
    style << ", IndentCaseLabels : " << ClangFlagToBool(kIndentCaseLabels);
    style << ", IndentFunctionDeclarationAfterType : " << ClangFlagToBool(kIndentFunctionDeclarationAfterType);
    style << ", SpaceBeforeAssignmentOperators : " << ClangFlagToBool(kSpaceBeforeAssignmentOperators);
    if(clangFormatVersion >= 3.5) {
        style << ", SpaceBeforeParens : " << (m_clangFormatOptions & kSpaceBeforeParens ? "Always" : "Never");
    }
    style << ", SpacesInParentheses : " << ClangFlagToBool(kSpacesInParentheses);
    style << ", BreakBeforeBraces : " << ClangBreakBeforeBrace();
    style << ", ColumnLimit : " << m_clangColumnLimit;
    if(clangFormatVersion >= 3.5) {
        style << ", PointerAlignment : " << (m_clangFormatOptions & kPointerAlignmentRight ? "Right" : "Left");
    }
    style << " }\"";
    return style;
}
Example #2
0
wxString FormatOptions::ClangFormatOptionsAsString(const wxFileName& filename, double clangFormatVersion) const
{
    wxString options, forceLanguage;

    // Try to autodetect the file type
    if(clangFormatVersion >= 3.5) {
        if(FileExtManager::IsJavascriptFile(filename)) {
            forceLanguage << "Language : JavaScript";

        } else if(FileExtManager::IsCxxFile(filename)) {
            forceLanguage << "Language : Cpp";

        } else if(FileExtManager::IsJavaFile(filename)) {
            forceLanguage << "Language : Java";
        }
    }

    options << " -style=\"{ BasedOnStyle: ";
    if(m_clangFormatOptions & kClangFormatChromium) {
        options << "Chromium";
    } else if(m_clangFormatOptions & kClangFormatGoogle) {
        options << "Google";
    } else if(m_clangFormatOptions & kClangFormatLLVM) {
        options << "LLVM";
    } else if(m_clangFormatOptions & kClangFormatMozilla) {
        options << "Mozilla";
    } else if(m_clangFormatOptions & kClangFormatWebKit) {
        options << "WebKit";
    }

    // add tab width and space vs tabs based on the global editor settings
    options << ClangGlobalSettings();

    // Language
    if(!forceLanguage.IsEmpty()) {
        options << ", " << forceLanguage << " ";
    }
    options << ", AlignEscapedNewlinesLeft: " << ClangFlagToBool(kAlignEscapedNewlinesLeft);
    options << ", AlignTrailingComments : " << ClangFlagToBool(kAlignTrailingComments);
    options << ", AllowAllParametersOfDeclarationOnNextLine : "
            << ClangFlagToBool(kAllowAllParametersOfDeclarationOnNextLine);
    if(clangFormatVersion >= 3.5) {
        options << ", AllowShortFunctionsOnASingleLine : " << ClangFlagToBool(kAllowShortFunctionsOnASingleLine);
        options << ", AllowShortBlocksOnASingleLine : " << ClangFlagToBool(kAllowShortBlocksOnASingleLine);
    }
    options << ", AllowShortLoopsOnASingleLine : " << ClangFlagToBool(kAllowShortLoopsOnASingleLine);
    options << ", AllowShortIfStatementsOnASingleLine : " << ClangFlagToBool(kAllowShortIfStatementsOnASingleLine);
    options << ", AlwaysBreakBeforeMultilineStrings : " << ClangFlagToBool(kAlwaysBreakBeforeMultilineStrings);
    options << ", AlwaysBreakTemplateDeclarations : " << ClangFlagToBool(kAlwaysBreakTemplateDeclarations);
    options << ", BinPackParameters : " << ClangFlagToBool(kBinPackParameters);
    options << ", BreakBeforeBinaryOperators : " << ClangFlagToBool(kBreakBeforeBinaryOperators);
    options << ", BreakBeforeTernaryOperators : " << ClangFlagToBool(kBreakBeforeTernaryOperators);
    options << ", BreakConstructorInitializersBeforeComma : "
            << ClangFlagToBool(kBreakConstructorInitializersBeforeComma);
    options << ", IndentCaseLabels : " << ClangFlagToBool(kIndentCaseLabels);
    options << ", IndentFunctionDeclarationAfterType : " << ClangFlagToBool(kIndentFunctionDeclarationAfterType);
    options << ", SpaceBeforeAssignmentOperators : " << ClangFlagToBool(kSpaceBeforeAssignmentOperators);
    if(clangFormatVersion >= 3.5) {
        options << ", SpaceBeforeParens : " << (m_clangFormatOptions & kSpaceBeforeParens ? "Always" : "Never");
    }
    options << ", SpacesInParentheses : " << ClangFlagToBool(kSpacesInParentheses);
    options << ", BreakBeforeBraces : " << ClangBreakBeforeBrace();
    options << ", ColumnLimit : " << m_clangColumnLimit;
    if(clangFormatVersion >= 3.5) {
        options << ", PointerAlignment : " << (m_clangFormatOptions & kPointerAlignmentRight ? "Right" : "Left");
    }
    options << " }\" ";
    return options;
}