public void addOpenBrace(IToken nextToken, int braceCode) { // addBracePart(nextToken, braceCode, "{"); if (getFormatMode()!=FORMAT_INDENT) { CommonToken token=(CommonToken)nextToken; bool hasBraces=(token.Type==AS3_exParser.LCURLY); StatementBraceInfo braceInfo=new StatementBraceInfo(braceCode, hasBraces); // braceInfo.setStartBracePos(mOutputBuffer.Length); //add the current pos; will be cleaned up later if there is a brace CommonToken startToken=findNextNonWhitespaceTokenAfterCurrentLine(token); if (startToken.Channel==AS3_exParser.CHANNEL_MLCOMMENT || startToken.Channel==AS3_exParser.CHANNEL_SLCOMMENT) braceInfo.setHasComment(true); else braceInfo.setHasComment(false); braceInfo.setNextTokenType(nextToken.Type); braceInfo.setOriginalDocStartPosition(startToken.StartIndex); mAddBraceStack.Add(braceInfo); } }
public bool isNeedSwitchBraces(StatementBraceInfo info) { if (getSwitchBraceModifyMode()==Braces_AddSmart) { //if smart adding, return true unless the next token is the end 'break' (empty case statement), //the next case/default statement, or the end brace of the switch if (info.getNextTokenType()!=AS3_exLexer.BREAK && info.getNextTokenType()!=AS3_exLexer.CASE && info.getNextTokenType()!=AS3_exLexer.DEFAULT && info.getNextTokenType()!=AS3_exLexer.RCURLY) return true; } // //if smart mode, then do some more tests // if (getLoopBraceModifyMode()==Braces_AddSmart || getLoopBraceModifyMode()==Braces_AddRemoveSmart) // { // //if there's a comment before the statement, definitely add braces // if (info.isHasComment()) // return true; // // //if the loop control statement itself crosses lines, then we want to add braces // String statementText=mOutputBuffer.Substring(info.getOutputStatementStartPos(), info.getOutputStatementEndPos()); // if (statementText.IndexOf('\n')>=0) // return true; // // //if the statement is on more than one line (that is, if there is wrapping involved), return true // String statementData=mOutputBuffer.Substring(info.getStartBracePos(), info.getEndBracePos()); // if (statementData.IndexOf('\n')>=0) // return true; // } return false; }
private bool isRemoveBraces(StatementBraceInfo info) { switch (info.getStatementType()) { case BraceAdd_Loop: return isRemoveLoopBraces(info); case BraceAdd_Conditional: return isRemoveConditionalBraces(info); case BraceAdd_Switch: return isRemoveSwitchBraces(info); default: return false; } }
public bool isRemoveSwitchBraces(StatementBraceInfo info) { if (getSwitchBraceModifyMode()==Braces_RemoveUnnecessary) { return true; } return false; }
private bool isSmartNeedBraces(StatementBraceInfo info) { //if there's a comment before the statement, definitely add braces if (info.isHasComment()) return true; //if the loop control statement itself crosses lines, then we want to add braces if (info.getOutputStatementStartPos()>0 && info.getOutputStatementEndPos()>0) { String statementText = mOutputBuffer.ToString().Substring(info.getOutputStatementStartPos(), info.getOutputStatementEndPos() - info.getOutputStatementStartPos()); if (statementText.Trim().IndexOf('\n')>=0) return true; } //if the statement is on more than one line (that is, if there is wrapping involved), return true String statementData = mOutputBuffer.ToString().Substring(info.getStartBracePos(), info.getEndBracePos() - info.getStartBracePos()).Trim(); if (info.isBracesCurrentlyExist()) { //remove braces from statementData, if at ends statementData=statementData.Trim(); if (statementData.StartsWith('{')) statementData=statementData.Substring(1); if (statementData.EndsWith('}')) statementData=statementData.Substring(0, statementData.Length-1); } if (statementData.Trim().IndexOf('\n')>=0) return true; //more than 2 statements means block plus more than one statement. If there is only one statement (and braces exist), //that means an empty block, which we don't want to touch either. if (info.getStatementCount()>2 || (info.isBracesCurrentlyExist() && info.getStatementCount()<=1)) return true; return false; }
public bool isNeedLoopBraces(StatementBraceInfo info) { //if always adding, return true if (getLoopBraceModifyMode()==Braces_AddIfMissing) return true; //if smart mode, then do some more tests if (getLoopBraceModifyMode()==Braces_AddSmart || getLoopBraceModifyMode()==Braces_AddRemoveSmart) { return isSmartNeedBraces(info); } return false; }
public bool isRemoveLoopBraces(StatementBraceInfo info) { if (getLoopBraceModifyMode()==Braces_AddRemoveSmart) { return !isNeedLoopBraces(info); } return false; }
public bool isRemoveConditionalBraces(StatementBraceInfo info) { if (getConditionalBraceModifyMode()==Braces_AddRemoveSmart) { return !isNeedConditionalBraces(info); } return false; }