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:
Orgad Shaneh
2013-01-08 03:32:53 +02:00
committed by hjk
parent 73a2717bed
commit 29a93998df
396 changed files with 1856 additions and 3135 deletions

View File

@@ -121,9 +121,8 @@ QString JsFileWizard::fileContents(const QString &, bool statelessLibrary) const
QString contents;
QTextStream str(&contents);
if (statelessLibrary) {
if (statelessLibrary)
str << QLatin1String(".pragma library\n\n");
}
str << QLatin1String("function func() {\n")
<< QLatin1String("\n")
<< QLatin1String("}\n");

View File

@@ -138,9 +138,8 @@ public:
if (const FunctionValue *func = value->asFunctionValue()) {
// constructors usually also have other interesting members,
// don't consider them pure functions and complete the '()'
if (!func->lookupMember(QLatin1String("prototype"), 0, 0, false)) {
if (!func->lookupMember(QLatin1String("prototype"), 0, 0, false))
data = QVariant::fromValue(CompleteFunctionCall(func->namedArgumentCount() || func->isVariadic()));
}
}
addCompletion(completions, name, icon, order, data);
}

View File

@@ -406,9 +406,8 @@ protected:
virtual bool visit(AST::UiScriptBinding *ast)
{
if (AST::Block *block = AST::cast<AST::Block *>(ast->statement)) {
if (AST::Block *block = AST::cast<AST::Block *>(ast->statement))
_ranges.append(createRange(ast, block));
}
return true;
}
@@ -663,13 +662,12 @@ static void appendExtraSelectionsForMessages(
sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, d.location.length);
}
if (d.severity == StaticAnalysis::Warning || d.severity == StaticAnalysis::MaybeWarning) {
if (d.severity == StaticAnalysis::Warning || d.severity == StaticAnalysis::MaybeWarning)
sel.format.setUnderlineColor(Qt::darkYellow);
} else if (d.severity == StaticAnalysis::Error || d.severity == StaticAnalysis::MaybeError) {
else if (d.severity == StaticAnalysis::Error || d.severity == StaticAnalysis::MaybeError)
sel.format.setUnderlineColor(Qt::red);
} else if (d.severity == StaticAnalysis::Hint) {
else if (d.severity == StaticAnalysis::Hint)
sel.format.setUnderlineColor(Qt::darkGreen);
}
sel.format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
sel.format.setToolTip(d.message);
@@ -896,9 +894,8 @@ protected:
UiQualifiedId *id = qualifiedTypeNameId(member);
if (id) {
const QStringRef &name = id->name;
if (!name.isEmpty() && name.at(0).isUpper()) {
if (!name.isEmpty() && name.at(0).isUpper())
return true;
}
}
return false;
@@ -1286,9 +1283,8 @@ void QmlJSTextEditorWidget::wheelEvent(QWheelEvent *event)
BaseTextEditorWidget::wheelEvent(event);
if (visible) {
if (visible)
m_contextPane->apply(editor(), semanticInfo().document, 0, m_semanticInfo.declaringMemberNoProperties(m_oldCursorPosition), false, true);
}
}
void QmlJSTextEditorWidget::resizeEvent(QResizeEvent *event)
@@ -1424,9 +1420,8 @@ QModelIndex QmlJSTextEditorWidget::indexForPosition(unsigned cursorPosition, con
bool QmlJSTextEditorWidget::hideContextPane()
{
bool b = (m_contextPane) && m_contextPane->widget()->isVisible();
if (b) {
if (b)
m_contextPane->apply(editor(), semanticInfo().document, 0, 0, false);
}
return b;
}

View File

@@ -250,9 +250,8 @@ private:
if (idEnv && idEnv->lookupMember(_name, _scopeChain.context()))
return idEnv == _scope;
const ObjectValue *root = chain->document()->bind()->rootObjectValue();
if (root && root->lookupMember(_name, _scopeChain.context())) {
if (root && root->lookupMember(_name, _scopeChain.context()))
return check(root);
}
foreach (const QmlComponentChain *parent, chain->instantiatingComponents()) {
if (contains(parent))
@@ -506,13 +505,12 @@ protected:
virtual bool preVisit(Node *node)
{
if (Statement *stmt = node->statementCast()) {
if (Statement *stmt = node->statementCast())
return containsOffset(stmt->firstSourceLocation(), stmt->lastSourceLocation());
} else if (ExpressionNode *exp = node->expressionCast()) {
else if (ExpressionNode *exp = node->expressionCast())
return containsOffset(exp->firstSourceLocation(), exp->lastSourceLocation());
} else if (UiObjectMember *ui = node->uiObjectMemberCast()) {
else if (UiObjectMember *ui = node->uiObjectMemberCast())
return containsOffset(ui->firstSourceLocation(), ui->lastSourceLocation());
}
return true;
}

View File

@@ -203,23 +203,22 @@ bool Highlighter::maybeQmlKeyword(const QStringRef &text) const
return false;
const QChar ch = text.at(0);
if (ch == QLatin1Char('p') && text == QLatin1String("property")) {
if (ch == QLatin1Char('p') && text == QLatin1String("property"))
return true;
} else if (ch == QLatin1Char('a') && text == QLatin1String("alias")) {
else if (ch == QLatin1Char('a') && text == QLatin1String("alias"))
return true;
} else if (ch == QLatin1Char('s') && text == QLatin1String("signal")) {
else if (ch == QLatin1Char('s') && text == QLatin1String("signal"))
return true;
} else if (ch == QLatin1Char('p') && text == QLatin1String("property")) {
else if (ch == QLatin1Char('p') && text == QLatin1String("property"))
return true;
} else if (ch == QLatin1Char('r') && text == QLatin1String("readonly")) {
else if (ch == QLatin1Char('r') && text == QLatin1String("readonly"))
return true;
} else if (ch == QLatin1Char('i') && text == QLatin1String("import")) {
else if (ch == QLatin1Char('i') && text == QLatin1String("import"))
return true;
} else if (ch == QLatin1Char('o') && text == QLatin1String("on")) {
else if (ch == QLatin1Char('o') && text == QLatin1String("on"))
return true;
} else {
else
return false;
}
}
bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const
@@ -229,47 +228,46 @@ bool Highlighter::maybeQmlBuiltinType(const QStringRef &text) const
const QChar ch = text.at(0);
if (ch == QLatin1Char('a') && text == QLatin1String("action")) {
if (ch == QLatin1Char('a') && text == QLatin1String("action"))
return true;
} else if (ch == QLatin1Char('b') && text == QLatin1String("bool")) {
else if (ch == QLatin1Char('b') && text == QLatin1String("bool"))
return true;
} else if (ch == QLatin1Char('c') && text == QLatin1String("color")) {
else if (ch == QLatin1Char('c') && text == QLatin1String("color"))
return true;
} else if (ch == QLatin1Char('d') && text == QLatin1String("date")) {
else if (ch == QLatin1Char('d') && text == QLatin1String("date"))
return true;
} else if (ch == QLatin1Char('d') && text == QLatin1String("double")) {
else if (ch == QLatin1Char('d') && text == QLatin1String("double"))
return true;
} else if (ch == QLatin1Char('e') && text == QLatin1String("enumeration")) {
else if (ch == QLatin1Char('e') && text == QLatin1String("enumeration"))
return true;
} else if (ch == QLatin1Char('f') && text == QLatin1String("font")) {
else if (ch == QLatin1Char('f') && text == QLatin1String("font"))
return true;
} else if (ch == QLatin1Char('i') && text == QLatin1String("int")) {
else if (ch == QLatin1Char('i') && text == QLatin1String("int"))
return true;
} else if (ch == QLatin1Char('l') && text == QLatin1String("list")) {
else if (ch == QLatin1Char('l') && text == QLatin1String("list"))
return true;
} else if (ch == QLatin1Char('p') && text == QLatin1String("point")) {
else if (ch == QLatin1Char('p') && text == QLatin1String("point"))
return true;
} else if (ch == QLatin1Char('r') && text == QLatin1String("real")) {
else if (ch == QLatin1Char('r') && text == QLatin1String("real"))
return true;
} else if (ch == QLatin1Char('r') && text == QLatin1String("rect")) {
else if (ch == QLatin1Char('r') && text == QLatin1String("rect"))
return true;
} else if (ch == QLatin1Char('s') && text == QLatin1String("size")) {
else if (ch == QLatin1Char('s') && text == QLatin1String("size"))
return true;
} else if (ch == QLatin1Char('s') && text == QLatin1String("string")) {
else if (ch == QLatin1Char('s') && text == QLatin1String("string"))
return true;
} else if (ch == QLatin1Char('t') && text == QLatin1String("time")) {
else if (ch == QLatin1Char('t') && text == QLatin1String("time"))
return true;
} else if (ch == QLatin1Char('u') && text == QLatin1String("url")) {
else if (ch == QLatin1Char('u') && text == QLatin1String("url"))
return true;
} else if (ch == QLatin1Char('v') && text == QLatin1String("variant")) {
else if (ch == QLatin1Char('v') && text == QLatin1String("variant"))
return true;
} else if (ch == QLatin1Char('v') && text == QLatin1String("var")) {
else if (ch == QLatin1Char('v') && text == QLatin1String("var"))
return true;
} else if (ch == QLatin1Char('v') && text == QLatin1String("vector3d")) {
else if (ch == QLatin1Char('v') && text == QLatin1String("vector3d"))
return true;
} else {
else
return false;
}
}
int Highlighter::onBlockStart()

View File

@@ -64,9 +64,8 @@ bool QmlJSOutlineFilterModel::filterAcceptsRow(int sourceRow,
if (m_filterBindings) {
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
QVariant itemType = sourceIndex.data(QmlOutlineModel::ItemTypeRole);
if (itemType == QmlOutlineModel::NonElementBindingType) {
if (itemType == QmlOutlineModel::NonElementBindingType)
return false;
}
}
return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
}

View File

@@ -270,11 +270,10 @@ protected:
bool visit(UiObjectDefinition *ast)
{
if (m_scopeChain.document()->bind()->isGroupedPropertyBinding(ast)) {
if (m_scopeChain.document()->bind()->isGroupedPropertyBinding(ast))
processBindingName(ast->qualifiedTypeNameId);
} else {
else
processTypeId(ast->qualifiedTypeNameId);
}
scopedAccept(ast, ast->initializer);
return false;
}
@@ -342,9 +341,8 @@ protected:
return false;
const QString &value = ast->value.toString();
if (m_stateNames.contains(value)) {
if (m_stateNames.contains(value))
addUse(ast->literalToken, SemanticHighlighter::LocalStateNameType);
}
return false;
}

View File

@@ -76,9 +76,8 @@ QVariant QmlOutlineItem::data(int role) const
return prettyPrint(value, scopeChain.context());
}
if (role == Qt::DecorationRole) {
if (role == Qt::DecorationRole)
return m_outlineModel->icon(index());
}
return QStandardItem::data(role);
}
@@ -104,15 +103,13 @@ QString QmlOutlineItem::prettyPrint(const Value *value, const ContextPtr &contex
if (const ObjectValue *objectValue = value->asObjectValue()) {
const QString className = objectValue->className();
if (!className.isEmpty()) {
if (!className.isEmpty())
return className;
}
}
const QString typeId = context->valueOwner()->typeId(value);
if (typeId == QLatin1String("undefined")) {
if (typeId == QLatin1String("undefined"))
return QString();
}
return typeId;
}
@@ -145,9 +142,8 @@ private:
{
if (AST::UiObjectMember *objMember = node->uiObjectMemberCast()) {
stack.removeLast();
if (!stack.isEmpty()) {
if (!stack.isEmpty())
parent.insert(objMember, stack.last());
}
}
}
};
@@ -462,9 +458,8 @@ QModelIndex QmlOutlineModel::enterObjectDefinition(AST::UiObjectDefinition *objD
data.insert(ItemTypeRole, ElementType);
data.insert(AnnotationRole, getAnnotation(objDef->initializer));
idNode = objDef->qualifiedTypeNameId;
if (!m_typeToIcon.contains(typeName)) {
if (!m_typeToIcon.contains(typeName))
m_typeToIcon.insert(typeName, getIcon(objDef->qualifiedTypeNameId));
}
icon = m_typeToIcon.value(typeName);
} else {
// it's a grouped propery like 'anchors'
@@ -492,9 +487,8 @@ QModelIndex QmlOutlineModel::enterObjectBinding(AST::UiObjectBinding *objBinding
QmlOutlineItem *bindingItem = enterNode(bindingData, objBinding, objBinding->qualifiedId, m_icons->scriptBindingIcon());
const QString typeName = asString(objBinding->qualifiedTypeNameId);
if (!m_typeToIcon.contains(typeName)) {
if (!m_typeToIcon.contains(typeName))
m_typeToIcon.insert(typeName, getIcon(objBinding->qualifiedTypeNameId));
}
QMap<int, QVariant> objectData;
objectData.insert(Qt::DisplayRole, typeName);
@@ -608,13 +602,12 @@ QModelIndex QmlOutlineModel::enterTestCaseProperties(AST::PropertyNameAndValueLi
objectData.insert(Qt::DisplayRole, propertyName->id.toString());
objectData.insert(ItemTypeRole, ElementBindingType);
QmlOutlineItem *item;
if (propertyNameAndValueList->value->kind == AST::Node::Kind_FunctionExpression) {
if (propertyNameAndValueList->value->kind == AST::Node::Kind_FunctionExpression)
item = enterNode(objectData, propertyNameAndValueList, 0, m_icons->functionDeclarationIcon());
} else if (propertyNameAndValueList->value->kind == AST::Node::Kind_ObjectLiteral) {
else if (propertyNameAndValueList->value->kind == AST::Node::Kind_ObjectLiteral)
item = enterNode(objectData, propertyNameAndValueList, 0, m_icons->objectDefinitionIcon());
} else {
else
item = enterNode(objectData, propertyNameAndValueList, 0, m_icons->scriptBindingIcon());
}
return item->index();
} else {
@@ -645,13 +638,12 @@ AST::SourceLocation QmlOutlineModel::sourceLocation(const QModelIndex &index) co
QTC_ASSERT(index.isValid() && (index.model() == this), return location);
AST::Node *node = nodeForIndex(index);
if (node) {
if (AST::UiObjectMember *member = node->uiObjectMemberCast()) {
if (AST::UiObjectMember *member = node->uiObjectMemberCast())
location = getLocation(member);
} else if (AST::ExpressionNode *expression = node->expressionCast()) {
else if (AST::ExpressionNode *expression = node->expressionCast())
location = getLocation(expression);
} else if (AST::PropertyNameAndValueList *propertyNameAndValueList = AST::cast<AST::PropertyNameAndValueList *>(node)) {
else if (AST::PropertyNameAndValueList *propertyNameAndValueList = AST::cast<AST::PropertyNameAndValueList *>(node))
location = getLocation(propertyNameAndValueList);
}
}
return location;
}
@@ -830,11 +822,10 @@ void QmlOutlineModel::moveObjectMember(AST::UiObjectMember *toMove,
}
Rewriter::BindingType bindingType = Rewriter::ScriptBinding;
if (insertionOrderSpecified) {
if (insertionOrderSpecified)
*addedRange = rewriter.addBinding(objDefinition->initializer, propertyName, propertyValue, bindingType, listInsertAfter);
} else {
else
*addedRange = rewriter.addBinding(objDefinition->initializer, propertyName, propertyValue, bindingType);
}
} else {
QString strToMove;
{
@@ -843,11 +834,10 @@ void QmlOutlineModel::moveObjectMember(AST::UiObjectMember *toMove,
strToMove = documentText.mid(offset, length);
}
if (insertionOrderSpecified) {
if (insertionOrderSpecified)
*addedRange = rewriter.addObject(objDefinition->initializer, strToMove, listInsertAfter);
} else {
else
*addedRange = rewriter.addObject(objDefinition->initializer, strToMove);
}
}
} else if (AST::UiArrayBinding *arrayBinding = AST::cast<AST::UiArrayBinding*>(newParent)) {
AST::UiArrayMemberList *listInsertAfter = 0;
@@ -865,11 +855,10 @@ void QmlOutlineModel::moveObjectMember(AST::UiObjectMember *toMove,
strToMove = documentText.mid(offset, length);
}
if (insertionOrderSpecified) {
if (insertionOrderSpecified)
*addedRange = rewriter.addObject(arrayBinding, strToMove, listInsertAfter);
} else {
else
*addedRange = rewriter.addObject(arrayBinding, strToMove);
}
} else if (AST::cast<AST::UiObjectBinding*>(newParent)) {
qDebug() << "TODO: Reparent to UiObjectBinding";
return;

View File

@@ -73,11 +73,10 @@ static inline const ObjectValue * getPropertyChangesTarget(Node *node, const Sco
&& ! scriptBinding->qualifiedId->next) {
Evaluate evaluator(&scopeChain);
const Value *targetValue = evaluator(scriptBinding->statement);
if (const ObjectValue *targetObject = value_cast<ObjectValue>(targetValue)) {
if (const ObjectValue *targetObject = value_cast<ObjectValue>(targetValue))
return targetObject;
} else {
else
return 0;
}
}
}
}
@@ -267,12 +266,11 @@ bool QuickToolBar::isAvailable(TextEditor::BaseTextEditor *, Document::Ptr docum
UiObjectDefinition *objectDefinition = cast<UiObjectDefinition*>(node);
UiObjectBinding *objectBinding = cast<UiObjectBinding*>(node);
if (objectDefinition) {
if (objectDefinition)
name = objectDefinition->qualifiedTypeNameId->name.toString();
} else if (objectBinding) {
else if (objectBinding)
name = objectBinding->qualifiedTypeNameId->name.toString();
}
QStringList prototypes;
prototypes.append(name);
@@ -320,11 +318,10 @@ void QuickToolBar::setProperty(const QString &propertyName, const QVariant &valu
bindingType = Rewriter::ObjectBinding;
PropertyReader propertyReader(m_doc, initializer);
if (propertyReader.hasProperty(propertyName)) {
if (propertyReader.hasProperty(propertyName))
rewriter.changeBinding(initializer, propertyName, stringValue, bindingType);
} else {
else
rewriter.addBinding(initializer, propertyName, stringValue, bindingType);
}
int column;