forked from qt-creator/qt-creator
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -665,11 +665,10 @@ bool CheckSymbols::visit(NewExpressionAST *ast)
|
||||
int arguments = 0;
|
||||
if (ast->new_initializer) {
|
||||
ExpressionListAST *list = 0;
|
||||
if (ExpressionListParenAST *exprListParen = ast->new_initializer->asExpressionListParen()) {
|
||||
if (ExpressionListParenAST *exprListParen = ast->new_initializer->asExpressionListParen())
|
||||
list = exprListParen->expression_list;
|
||||
} else if (BracedInitializerAST *braceInit = ast->new_initializer->asBracedInitializer()) {
|
||||
else if (BracedInitializerAST *braceInit = ast->new_initializer->asBracedInitializer())
|
||||
list = braceInit->expression_list;
|
||||
}
|
||||
for (ExpressionListAST *it = list; it; it = it->next)
|
||||
++arguments;
|
||||
}
|
||||
|
||||
@@ -989,11 +989,10 @@ int CodeFormatter::column(int index) const
|
||||
const QChar tab = QLatin1Char('\t');
|
||||
|
||||
for (int i = 0; i < index; i++) {
|
||||
if (m_currentLine[i] == tab) {
|
||||
if (m_currentLine[i] == tab)
|
||||
col = ((col / m_tabSize) + 1) * m_tabSize;
|
||||
} else {
|
||||
else
|
||||
col++;
|
||||
}
|
||||
}
|
||||
return col;
|
||||
}
|
||||
@@ -1328,9 +1327,8 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
||||
*indentDepth += m_tabSettings.m_indentSize;
|
||||
}
|
||||
|
||||
if (followedByData) {
|
||||
if (followedByData)
|
||||
*paddingDepth = nextTokenPosition-*indentDepth;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1483,11 +1481,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
|
||||
} else if ((topState.type == expression && previousState.type == declaration_start)
|
||||
|| topState.type == member_init || topState.type == member_init_open) {
|
||||
// the declaration_start indent is the base
|
||||
if (topState.type == member_init) {
|
||||
if (topState.type == member_init)
|
||||
*indentDepth = state(2).savedIndentDepth;
|
||||
} else {
|
||||
else
|
||||
*indentDepth = previousState.savedIndentDepth;
|
||||
}
|
||||
if (m_styleSettings.indentFunctionBraces)
|
||||
*indentDepth += m_tabSettings.m_indentSize;
|
||||
*paddingDepth = 0;
|
||||
|
||||
@@ -71,9 +71,8 @@ void CppCodeStylePreferences::setCodeStyleSettings(const CppCodeStyleSettings &d
|
||||
v.setValue(data);
|
||||
emit valueChanged(v);
|
||||
emit codeStyleSettingsChanged(m_data);
|
||||
if (!currentDelegate()) {
|
||||
if (!currentDelegate())
|
||||
emit currentValueChanged(v);
|
||||
}
|
||||
}
|
||||
|
||||
CppCodeStyleSettings CppCodeStylePreferences::currentCodeStyleSettings() const
|
||||
|
||||
@@ -264,9 +264,8 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
|
||||
#if 0
|
||||
} else if (function->templateParameterCount() != 0 && typedChar != QLatin1Char('(')) {
|
||||
// If there are no arguments, then we need the template specification
|
||||
if (function->argumentCount() == 0) {
|
||||
if (function->argumentCount() == 0)
|
||||
extraChars += QLatin1Char('<');
|
||||
}
|
||||
#endif
|
||||
} else if (!isDereferenced(editor, basePosition) && ! function->isAmbiguous()) {
|
||||
// When the user typed the opening parenthesis, he'll likely also type the closing one,
|
||||
@@ -579,9 +578,8 @@ protected:
|
||||
virtual void visit(const Identifier *name)
|
||||
{
|
||||
_item = newCompletionItem(name);
|
||||
if (!_symbol->isScope() || _symbol->isFunction()) {
|
||||
if (!_symbol->isScope() || _symbol->isFunction())
|
||||
_item->setDetail(overview.prettyType(_symbol->type(), name));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void visit(const TemplateNameId *name)
|
||||
@@ -1580,11 +1578,10 @@ void CppCompletionAssistProcessor::completeClass(CPlusPlus::ClassOrNamespace *b,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (member->isPublic()) {
|
||||
if (member->isPublic())
|
||||
addCompletionItem(member, PublicClassMemberOrder);
|
||||
} else {
|
||||
else
|
||||
addCompletionItem(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1818,9 +1815,8 @@ bool CppCompletionAssistProcessor::completeConstructorOrFunction(const QList<CPl
|
||||
Symbol *overload = r.declaration();
|
||||
FullySpecifiedType overloadTy = overload->type().simplified();
|
||||
|
||||
if (Function *funTy = overloadTy->asFunctionType()) {
|
||||
if (Function *funTy = overloadTy->asFunctionType())
|
||||
functions.append(funTy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,18 +120,16 @@ void CppCurrentDocumentFilter::refresh(QFutureInterface<void> &future)
|
||||
|
||||
void CppCurrentDocumentFilter::onDocumentUpdated(Document::Ptr doc)
|
||||
{
|
||||
if (m_currentFileName == doc->fileName()) {
|
||||
if (m_currentFileName == doc->fileName())
|
||||
m_itemsOfCurrentDoc.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void CppCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor * currentEditor)
|
||||
{
|
||||
if (currentEditor) {
|
||||
if (currentEditor)
|
||||
m_currentFileName = currentEditor->document()->fileName();
|
||||
} else {
|
||||
else
|
||||
m_currentFileName.clear();
|
||||
}
|
||||
m_itemsOfCurrentDoc.clear();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -450,9 +450,8 @@ bool CppFindReferences::findSymbol(CppFindReferencesParameters *parameters,
|
||||
const Snapshot &snapshot)
|
||||
{
|
||||
QString symbolFile = QLatin1String(parameters->symbol->fileName());
|
||||
if (!snapshot.contains(symbolFile)) {
|
||||
if (!snapshot.contains(symbolFile))
|
||||
return false;
|
||||
}
|
||||
|
||||
Document::Ptr newSymbolDocument = snapshot.document(symbolFile);
|
||||
// document is not parsed and has no bindings yet, do it
|
||||
|
||||
@@ -270,9 +270,8 @@ void CppPreprocessor::addFrameworkPath(const QString &frameworkPath)
|
||||
if (!framework.isDir())
|
||||
continue;
|
||||
const QFileInfo privateFrameworks(framework.absoluteFilePath(), QLatin1String("Frameworks"));
|
||||
if (privateFrameworks.exists() && privateFrameworks.isDir()) {
|
||||
if (privateFrameworks.exists() && privateFrameworks.isDir())
|
||||
addFrameworkPath(privateFrameworks.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,9 +644,8 @@ CppModelManager *CppModelManager::instance()
|
||||
if (m_modelManagerInstance)
|
||||
return m_modelManagerInstance;
|
||||
QMutexLocker locker(&m_modelManagerMutex);
|
||||
if (!m_modelManagerInstance) {
|
||||
if (!m_modelManagerInstance)
|
||||
m_modelManagerInstance = new CppModelManager;
|
||||
}
|
||||
return m_modelManagerInstance;
|
||||
}
|
||||
|
||||
@@ -1202,9 +1200,8 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
|
||||
|
||||
void CppModelManager::onAboutToUnloadSession()
|
||||
{
|
||||
if (Core::ProgressManager *pm = Core::ICore::progressManager()) {
|
||||
if (Core::ProgressManager *pm = Core::ICore::progressManager())
|
||||
pm->cancelTasks(QLatin1String(CppTools::Constants::TASK_INDEX));
|
||||
}
|
||||
do {
|
||||
QMutexLocker locker(&mutex);
|
||||
m_projects.clear();
|
||||
@@ -1232,9 +1229,8 @@ void CppModelManager::GC()
|
||||
|
||||
processed.insert(fn);
|
||||
|
||||
if (Document::Ptr doc = currentSnapshot.document(fn)) {
|
||||
if (Document::Ptr doc = currentSnapshot.document(fn))
|
||||
todo += doc->includedFiles();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList removedFiles;
|
||||
|
||||
@@ -108,9 +108,8 @@ void CppEditorSupport::updateDocument()
|
||||
{
|
||||
_revision = editorRevision();
|
||||
|
||||
if (qobject_cast<TextEditor::BaseTextEditorWidget*>(_textEditor->widget()) != 0) {
|
||||
if (qobject_cast<TextEditor::BaseTextEditorWidget*>(_textEditor->widget()) != 0)
|
||||
_modelManager->stopEditorSelectionsUpdate();
|
||||
}
|
||||
|
||||
_updateDocumentTimer->start(_updateDocumentInterval);
|
||||
}
|
||||
|
||||
@@ -278,13 +278,12 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
|
||||
} else if (symbol->isEnum()) {
|
||||
type = QLatin1String("enum");
|
||||
} else if (const Class *c = symbol->asClass()) {
|
||||
if (c->isUnion()) {
|
||||
if (c->isUnion())
|
||||
type = QLatin1String("union");
|
||||
} else if (c->isStruct()) {
|
||||
else if (c->isStruct())
|
||||
type = QLatin1String("struct");
|
||||
} else {
|
||||
else
|
||||
type = QLatin1String("class");
|
||||
}
|
||||
} else {
|
||||
type = QLatin1String("symbol");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user