public static void ConfigureASPrinter(ASPrettyPrinter printer, Settings settings, int tabSize) { printer.SetIndentMultilineComments(settings.Pref_AS_IndentMultilineComments); printer.SetBlankLinesBeforeFunction(settings.Pref_AS_BlankLinesBeforeFunctions); printer.SetBlankLinesBeforeClass(settings.Pref_AS_BlankLinesBeforeClasses); printer.SetBlankLinesBeforeControlStatement(settings.Pref_AS_BlankLinesBeforeControlStatements); printer.SetBlankLinesBeforeProperties(settings.Pref_AS_BlankLinesBeforeProperties); printer.SetBlockIndent(tabSize); printer.SetUseTabs(settings.Pref_Flex_UseTabs); printer.SetTabSize(tabSize); printer.SetSpacesAfterComma(settings.Pref_AS_SpacesAfterComma); printer.SetSpacesBeforeComma(settings.Pref_AS_SpacesBeforeComma); printer.SetCRBeforeOpenBrace(settings.Pref_AS_OpenBraceOnNewLine); printer.SetCRBeforeCatch(settings.Pref_AS_CatchOnNewLine); printer.SetCRBeforeElse(settings.Pref_AS_ElseOnNewLine); printer.SetUseBraceStyleSetting(settings.Pref_AS_UseBraceStyle); printer.SetBraceStyleSetting((Int32)settings.Pref_AS_BraceStyle); printer.SetKeepBlankLines(settings.Pref_AS_KeepBlankLines); printer.SetBlankLinesToKeep(settings.Pref_AS_BlankLinesToKeep); printer.SetSpacesAroundAssignment(settings.Pref_AS_SpacesAroundAssignment); printer.SetAdvancedSpacesAroundAssignmentInOptionalParameters(settings.Pref_AS_Tweak_SpacesAroundEqualsInOptionalParameters); printer.SetUseAdvancedSpacesAroundAssignmentInOptionalParameters(settings.Pref_AS_Tweak_UseSpacesAroundEqualsInOptionalParameters); printer.SetSpacesAroundColons(settings.Pref_AS_SpacesAroundColons); printer.SetAdvancedSpacesAfterColons(settings.Pref_AS_AdvancedSpacesAfterColons); printer.SetAdvancedSpacesBeforeColons(settings.Pref_AS_AdvancedSpacesBeforeColons); printer.SetUseGlobalSpacesAroundColons(settings.Pref_AS_UseGlobalSpacesAroundColons); printer.SetMaxLineLength(settings.Pref_AS_MaxLineLength); printer.SetExpressionSpacesAroundSymbolicOperators(settings.Pref_AS_SpacesAroundSymbolicOperator); printer.SetKeepElseIfOnSameLine(settings.Pref_AS_ElseIfOnSameLine); printer.SetKeepSingleLineCommentsAtColumn1(settings.Pref_AS_KeepSLCommentsOnColumn1); printer.SetSpacesInsideParensEtc(settings.Pref_AS_SpacesInsideParens); printer.SetUseSpacesInsideParensEtc(settings.Pref_AS_UseGlobalSpacesInsideParens); printer.SetAdvancedSpacesInsideArrayDeclBrackets(settings.Pref_AS_AdvancedSpacesInsideArrayDeclBrackets); printer.SetAdvancedSpacesInsideArrayReferenceBrackets(settings.Pref_AS_AdvancedSpacesInsideArrayRefBrackets); printer.SetAdvancedSpacesInsideObjectBraces(settings.Pref_AS_AdvancedSpacesInsideLiteralBraces); printer.SetAdvancedSpacesInsideParens(settings.Pref_AS_AdvancedSpacesInsideParens); printer.SetSpacesBetweenControlKeywordsAndParens(settings.Pref_AS_SpacesBeforeOpenControlParen); printer.SetAlwaysGenerateIndent(settings.Pref_AS_AlwaysGenerateIndent); printer.SetIndentAtPackageLevel(!settings.Pref_AS_DontIndentPackageItems); printer.SetKeepingExcessDeclWhitespace(settings.Pref_AS_LeaveExtraWhitespaceAroundVarDecls); printer.SetCollapseSpaceForAdjacentParens(settings.Pref_AS_CollapseSpacesForAdjacentParens); printer.SetNewlineAfterBindable(settings.Pref_AS_NewlineAfterBindable); printer.SetTrimTrailingWS(settings.Pref_AS_TrimTrailingWhitespace); printer.SetSpacesAfterLabel(settings.Pref_AS_SpacesAfterLabel); printer.SetEmptyStatementsOnNewLine(settings.Pref_AS_PutEmptyStatementsOnNewLine); bool breakBeforeComma = settings.Pref_AS_BreakLinesBeforeComma; int wrapIndentStyle = (Int32)settings.Pref_AS_WrapIndentStyle; WrapOptions options = new WrapOptions((Int32)settings.Pref_AS_WrapArrayDeclMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetArrayInitWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapMethodCallMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetMethodCallWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapMethodDeclMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetMethodDeclWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapExpressionMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetExpressionWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapXMLMode); options.BeforeSeparator = breakBeforeComma; options.IndentStyle = wrapIndentStyle; printer.SetXMLWrapOptions(options); }
public static void configureASPrinter(ASPrettyPrinter printer, Settings settings) { Boolean useTabs = PluginBase.Settings.UseTabs; Int32 tabSize = PluginBase.Settings.TabWidth; Int32 spaceSize = PluginBase.Settings.IndentSize; Int32 braceStyle = PluginBase.Settings.CodingStyle == CodingStyle.BracesOnLine ? 4 : 5; printer.setIndentMultilineComments(settings.Pref_AS_IndentMultilineComments); printer.setBlankLinesBeforeFunction(settings.Pref_AS_BlankLinesBeforeFunctions); printer.setBlankLinesBeforeClass(settings.Pref_AS_BlankLinesBeforeClasses); printer.setBlankLinesBeforeControlStatement(settings.Pref_AS_BlankLinesBeforeControlStatements); printer.setBlankLinesBeforeImports(settings.Pref_AS_BlankLinesBeforeImportBlock); printer.setBlankLinesBeforeProperties(settings.Pref_AS_BlankLinesBeforeProperties); printer.setBlankLinesToStartFunctions(settings.Pref_AS_BlankLinesAtFunctionStart); printer.setBlankLinesToEndFunctions(settings.Pref_AS_BlankLinesAtFunctionEnd); printer.setBlockIndent(spaceSize); printer.setUseTabs(useTabs); printer.setTabSize(tabSize); printer.setSpacesAfterComma(settings.Pref_AS_SpacesAfterComma); printer.setSpacesBeforeComma(settings.Pref_AS_SpacesBeforeComma); printer.setCRBeforeOpenBrace(settings.Pref_AS_OpenBraceOnNewLine); printer.setCRBeforeCatch(settings.Pref_AS_CatchOnNewLine); printer.setCRBeforeElse(settings.Pref_AS_ElseOnNewLine); printer.setCRBeforeWhile(settings.Pref_AS_WhileOnNewLine); printer.setUseBraceStyleSetting(true); printer.setBraceStyleSetting(braceStyle); printer.setKeepBlankLines(settings.Pref_AS_KeepBlankLines); printer.setBlankLinesToKeep(settings.Pref_AS_BlankLinesToKeep); printer.setSpacesAroundAssignment(settings.Pref_AS_SpacesAroundAssignment); printer.setAdvancedSpacesAroundAssignmentInOptionalParameters(settings.Pref_AS_Tweak_SpacesAroundEqualsInOptionalParameters); printer.setUseAdvancedSpacesAroundAssignmentInOptionalParameters(settings.Pref_AS_Tweak_UseSpacesAroundEqualsInOptionalParameters); printer.setAdvancedSpacesAroundAssignmentInMetatags(settings.Pref_AS_Tweak_SpacesAroundEqualsInMetatags); printer.setUseAdvancedSpacesAroundAssignmentInMetatags(settings.Pref_AS_Tweak_UseSpacesAroundEqualsInMetatags); printer.setSpacesAroundColons(settings.Pref_AS_SpacesAroundColons); printer.setAdvancedSpacesAfterColonsInDeclarations(settings.Pref_AS_AdvancedSpacesAfterColonsInDeclarations); printer.setAdvancedSpacesBeforeColonsInDeclarations(settings.Pref_AS_AdvancedSpacesBeforeColonsInDeclarations); printer.setAdvancedSpacesAfterColonsInFunctionTypes(settings.Pref_AS_AdvancedSpacesAfterColonsInFunctionTypes); printer.setAdvancedSpacesBeforeColonsInFunctionTypes(settings.Pref_AS_AdvancedSpacesBeforeColonsInFunctionTypes); printer.setUseGlobalSpacesAroundColons(settings.Pref_AS_UseGlobalSpacesAroundColons); printer.setMaxLineLength(settings.Pref_AS_MaxLineLength); printer.setExpressionSpacesAroundSymbolicOperators(settings.Pref_AS_SpacesAroundSymbolicOperator); printer.setKeepElseIfOnSameLine(settings.Pref_AS_ElseIfOnSameLine); printer.setKeepSingleLineCommentsAtColumn1(settings.Pref_AS_KeepSLCommentsOnColumn1); printer.setUseLineCommentWrapping(settings.Pref_AS_UseLineCommentWrapping); printer.setUseMLCommentWrapping(settings.Pref_AS_UseMLCommentWrapping); printer.setMLCommentCollapseLines(settings.Pref_AS_MLCommentReflow); printer.setDocCommentCollapseLines(settings.Pref_AS_DocCommentReflow); printer.setMLTextOnNewLines(settings.Pref_AS_MLCommentHeaderOnSeparateLine); printer.setMLAsteriskMode((Int32)settings.Pref_AS_MLCommentAsteriskMode); printer.setUseDocCommentWrapping(settings.Pref_AS_UseDocCommentWrapping); printer.setDocCommentHangingIndentTabs(settings.Pref_AS_DocCommentHangingIndentTabs); printer.setDocCommentKeepBlankLines(settings.Pref_AS_DocCommentKeepBlankLines); printer.setMLCommentKeepBlankLines(settings.Pref_AS_MLCommentKeepBlankLines); printer.setKeepSingleLineFunctions(settings.Pref_AS_LeaveSingleLineFunctions); printer.setNoIndentForTerminators(settings.Pref_AS_UnindentExpressionTerminators); printer.setNoCRBeforeBreak(settings.Pref_AS_NoNewCRsBeforeBreak); printer.setNoCRBeforeContinue(settings.Pref_AS_NoNewCRsBeforeContinue); printer.setNoCRBeforeReturn(settings.Pref_AS_NoNewCRsBeforeReturn); printer.setNoCRBeforeThrow(settings.Pref_AS_NoNewCRsBeforeThrow); printer.setNoCRBeforeExpressions(settings.Pref_AS_NoNewCRsBeforeExpression); printer.setKeepRelativeCommentIndent(settings.Pref_AS_KeepRelativeIndentInDocComments); printer.setSpacesInsideParensEtc(settings.Pref_AS_SpacesInsideParens); printer.setUseSpacesInsideParensEtc(settings.Pref_AS_UseGlobalSpacesInsideParens); printer.setHangingIndentTabs(settings.Pref_AS_TabsInHangingIndent); printer.setAdvancedSpacesInsideArrayDeclBrackets(settings.Pref_AS_AdvancedSpacesInsideArrayDeclBrackets); printer.setAdvancedSpacesInsideArrayReferenceBrackets(settings.Pref_AS_AdvancedSpacesInsideArrayRefBrackets); printer.setAdvancedSpacesInsideObjectBraces(settings.Pref_AS_AdvancedSpacesInsideLiteralBraces); printer.setAdvancedSpacesInsideParensInOtherPlaces(settings.Pref_AS_AdvancedSpacesInsideParensInOtherPlaces); printer.setAdvancedSpacesInsideParensInParameterLists(settings.Pref_AS_AdvancedSpacesInsideParensInParameterLists); printer.setAdvancedSpacesInsideParensInArgumentLists(settings.Pref_AS_AdvancedSpacesInsideParensInArgumentLists); printer.setSpacesBetweenControlKeywordsAndParens(settings.Pref_AS_SpacesBeforeOpenControlParen); printer.setSpacesBeforeFormalParameters(settings.Pref_AS_SpacesBeforeFormalParameters); printer.setSpacesBeforeArguments(settings.Pref_AS_SpacesBeforeArguments); printer.setAlwaysGenerateIndent(settings.Pref_AS_AlwaysGenerateIndent); printer.setUseGNUBraceIndent(settings.Pref_AS_UseGnuBraceIndent); printer.setLoopBraceMode(settings.Pref_AS_EnsureLoopsHaveBraces ? ASPrettyPrinter.Braces_AddIfMissing : ASPrettyPrinter.Braces_NoModify); printer.setLoopBraceMode(settings.Pref_AS_AddBracesToLoops); printer.setSwitchBraceMode(settings.Pref_AS_EnsureSwitchCasesHaveBraces ? ASPrettyPrinter.Braces_AddIfMissing : ASPrettyPrinter.Braces_NoModify); printer.setSwitchBraceMode(settings.Pref_AS_AddBracesToCases); printer.setConditionalBraceMode(settings.Pref_AS_EnsureConditionalsHaveBraces ? ASPrettyPrinter.Braces_AddIfMissing : ASPrettyPrinter.Braces_NoModify); printer.setConditionalBraceMode(settings.Pref_AS_AddBracesToConditionals); printer.setIndentAtPackageLevel(!settings.Pref_AS_DontIndentPackageItems); printer.setIndentSwitchCases(!settings.Pref_AS_DontIndentSwitchCases); printer.setKeepingExcessDeclWhitespace(settings.Pref_AS_LeaveExtraWhitespaceAroundVarDecls); printer.setAlignDeclEquals(settings.Pref_AS_AlignDeclEquals); printer.setAlignDeclMode((Int32)settings.Pref_AS_AlignDeclMode); printer.setKeepSpacesBeforeLineComments(settings.Pref_AS_KeepSpacesBeforeLineComments); printer.setLineCommentColumn(settings.Pref_AS_AlignLineCommentsAtColumn); printer.setUseGlobalNewlineBeforeBraceSetting(settings.Pref_AS_UseGlobalCRBeforeBrace); printer.setAdvancedNewlineBeforeBraceSettings(settings.Pref_AS_AdvancedCRBeforeBraceSettings); printer.setCollapseSpaceForAdjacentParens(settings.Pref_AS_CollapseSpacesForAdjacentParens); //printer.setNewlineAfterBindable(settings.Pref_AS_NewlineAfterBindable); printer.setNewlineBeforeBindableFunction(settings.Pref_AS_NewlineBeforeBindableFunction); printer.setNewlineBeforeBindableProperty(settings.Pref_AS_NewlineBeforeBindableProperty); List<String> tags = new List<String>(); tags.AddRange(settings.Pref_AS_MetaTagsOnSameLineAsTargetFunction.Split(',')); printer.setMetaTagsToKeepOnSameLineAsFunction(tags); tags.Clear(); tags.AddRange(settings.Pref_AS_MetaTagsOnSameLineAsTargetProperty.Split(',')); printer.setMetaTagsToKeepOnSameLineAsProperty(tags); printer.setTrimTrailingWS(settings.Pref_AS_TrimTrailingWhitespace); printer.setSpacesAfterLabel(settings.Pref_AS_SpacesAfterLabel); printer.setEmptyStatementsOnNewLine(settings.Pref_AS_PutEmptyStatementsOnNewLine); printer.setUseAdvancedWrapping(settings.Pref_AS_UseAdvancedWrapping); printer.setAdvancedWrappingElements(settings.Pref_AS_AdvancedWrappingElements); printer.setAdvancedWrappingEnforceMax(settings.Pref_AS_AdvancedWrappingEnforceMax); printer.setWrapAllArgumentsIfAny(settings.Pref_AS_AdvancedWrappingAllArgs); printer.setWrapAllParametersIfAny(settings.Pref_AS_AdvancedWrappingAllParms); printer.setWrapFirstArgument(settings.Pref_AS_AdvancedWrappingFirstArg); printer.setWrapFirstParameter(settings.Pref_AS_AdvancedWrappingFirstParm); printer.setWrapFirstArrayItem(settings.Pref_AS_AdvancedWrappingFirstArrayItem); printer.setWrapFirstObjectItem(settings.Pref_AS_AdvancedWrappingFirstObjectItem); printer.setWrapAllArrayItemsIfAny(settings.Pref_AS_AdvancedWrappingAllArrayItems); printer.setWrapAllObjectItemsIfAny(settings.Pref_AS_AdvancedWrappingAllObjectItems); printer.setWrapArrayItemsAlignStart(settings.Pref_AS_AdvancedWrappingAlignArrayItems); printer.setWrapObjectItemsAlignStart(settings.Pref_AS_AdvancedWrappingAlignObjectItems); printer.setAdvancedWrappingGraceColumns(settings.Pref_AS_AdvancedWrappingGraceColumns); printer.setAdvancedWrappingPreservePhrases(settings.Pref_AS_AdvancedWrappingPreservePhrases); bool breakBeforeComma = settings.Pref_AS_BreakLinesBeforeComma; bool breakBeforeArithmetic = settings.Pref_AS_BreakLinesBeforeArithmetic; bool breakBeforeLogical = settings.Pref_AS_BreakLinesBeforeLogical; bool breakBeforeAssign = settings.Pref_AS_BreakLinesBeforeAssignment; int wrapIndentStyle = (Int32)settings.Pref_AS_WrapIndentStyle; WrapOptions options = new WrapOptions((Int32)settings.Pref_AS_WrapArrayDeclMode); options.setBeforeSeparator(breakBeforeComma); options.setBeforeArithmeticOperator(breakBeforeArithmetic); options.setBeforeLogicalOperator(breakBeforeLogical); options.setBeforeAssignmentOperator(breakBeforeAssign); options.setIndentStyle(wrapIndentStyle); printer.setArrayInitWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapMethodCallMode); options.setBeforeSeparator(breakBeforeComma); options.setBeforeArithmeticOperator(breakBeforeArithmetic); options.setBeforeLogicalOperator(breakBeforeLogical); options.setBeforeAssignmentOperator(breakBeforeAssign); options.setIndentStyle(wrapIndentStyle); printer.setMethodCallWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapMethodDeclMode); options.setBeforeSeparator(breakBeforeComma); options.setIndentStyle(wrapIndentStyle); printer.setMethodDeclWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapExpressionMode); options.setBeforeSeparator(breakBeforeComma); options.setBeforeArithmeticOperator(breakBeforeArithmetic); options.setBeforeLogicalOperator(breakBeforeLogical); options.setBeforeAssignmentOperator(breakBeforeAssign); options.setIndentStyle(wrapIndentStyle); printer.setExpressionWrapOptions(options); options = new WrapOptions((Int32)settings.Pref_AS_WrapXMLMode); options.setBeforeSeparator(breakBeforeComma); options.setBeforeArithmeticOperator(breakBeforeArithmetic); options.setBeforeLogicalOperator(breakBeforeLogical); options.setBeforeAssignmentOperator(breakBeforeAssign); options.setIndentStyle(wrapIndentStyle); printer.setXMLWrapOptions(options); }
public AS3_exParser(ASPrettyPrinter printer, CommonTokenStream tokenStream) : this(tokenStream, new RecognizerSharedState()) { mRawTokens=tokenStream; mPrinter=printer; }
/// <summary> /// /// </summary> public void Format(Object sender, System.EventArgs e) { ITabbedDocument doc = PluginBase.MainForm.CurrentDocument; if (doc.IsEditable) { doc.SciControl.BeginUndoAction(); Int32 oldPos = CurrentPos; String source = doc.SciControl.Text; try { switch (DocumentType) { case TYPE_AS3PURE: ASPrettyPrinter asPrinter = new ASPrettyPrinter(true, source); FormatUtility.ConfigureASPrinter(asPrinter, this.settingObject, PluginBase.Settings.TabWidth); String asResultData = asPrinter.Print(0); if (asResultData == null) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { doc.SciControl.Text = asResultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; case TYPE_MXML: case TYPE_XML: MXMLPrettyPrinter mxmlPrinter = new MXMLPrettyPrinter(source); FormatUtility.ConfigureMXMLPrinter(mxmlPrinter, this.settingObject, PluginBase.Settings.TabWidth); String mxmlResultData = mxmlPrinter.Print(0); if (mxmlResultData == null) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { doc.SciControl.Text = mxmlResultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; } } catch (Exception) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } CurrentPos = oldPos; doc.SciControl.EndUndoAction(); } }
/// <summary> /// Formats the specified document /// </summary> private void DoFormat(ITabbedDocument doc) { if (doc.IsEditable) { doc.SciControl.BeginUndoAction(); Int32 oldPos = CurrentPos; String source = doc.SciControl.Text; try { switch (DocumentType) { case TYPE_AS3: ASPrettyPrinter asPrinter = new ASPrettyPrinter(true, source); FormatUtility.configureASPrinter(asPrinter, this.settingObject); String asResultData = asPrinter.print(0); if (asResultData == null) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { doc.SciControl.Text = asResultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; case TYPE_MXML: case TYPE_XML: MXMLPrettyPrinter mxmlPrinter = new MXMLPrettyPrinter(source); FormatUtility.configureMXMLPrinter(mxmlPrinter, this.settingObject); String mxmlResultData = mxmlPrinter.print(0); if (mxmlResultData == null) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { doc.SciControl.Text = mxmlResultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; case TYPE_CPP: AStyleInterface asi = new AStyleInterface(); String optionData = this.GetOptionData(doc.SciControl.ConfigurationLanguage.ToLower()); String resultData = asi.FormatSource(source, optionData); if (String.IsNullOrEmpty(resultData)) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } else { // Remove all empty lines if not specified for astyle if (!optionData.Contains("--delete-empty-lines")) { resultData = Regex.Replace(resultData, @"^\s+$[\r\n]*", Environment.NewLine, RegexOptions.Multiline); } doc.SciControl.Text = resultData; doc.SciControl.ConvertEOLs(doc.SciControl.EOLMode); } break; } } catch (Exception) { TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3); PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } CurrentPos = oldPos; doc.SciControl.EndUndoAction(); } }