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:
@@ -82,9 +82,8 @@ public:
|
||||
if (StringLiteral *stringLiteral = cast<StringLiteral *>(_ast)) {
|
||||
const QString valueName = stringLiteral->value.toString();
|
||||
|
||||
if (!enumValue->keys().contains(valueName)) {
|
||||
if (!enumValue->keys().contains(valueName))
|
||||
setMessage(ErrInvalidEnumValue);
|
||||
}
|
||||
} else if (! _rhsValue->asStringValue() && ! _rhsValue->asNumberValue()
|
||||
&& ! _rhsValue->asUnknownValue()) {
|
||||
setMessage(ErrEnumValueMustBeStringOrNumber);
|
||||
@@ -131,9 +130,8 @@ public:
|
||||
fileName.prepend(QDir::separator());
|
||||
fileName.prepend(_doc->path());
|
||||
}
|
||||
if (!QFileInfo(fileName).exists()) {
|
||||
if (!QFileInfo(fileName).exists())
|
||||
setMessage(WarnFileOrDirectoryDoesNotExist);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -421,9 +419,8 @@ protected:
|
||||
|
||||
bool visit(VariableStatement *ast)
|
||||
{
|
||||
if (_seenNonDeclarationStatement) {
|
||||
if (_seenNonDeclarationStatement)
|
||||
addMessage(HintDeclarationsShouldBeAtStartOfFunction, ast->declarationKindToken);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -433,13 +430,12 @@ protected:
|
||||
return true;
|
||||
const QString &name = ast->name.toString();
|
||||
|
||||
if (_formalParameterNames.contains(name)) {
|
||||
if (_formalParameterNames.contains(name))
|
||||
addMessage(WarnAlreadyFormalParameter, ast->identifierToken, name);
|
||||
} else if (_declaredFunctions.contains(name)) {
|
||||
else if (_declaredFunctions.contains(name))
|
||||
addMessage(WarnAlreadyFunction, ast->identifierToken, name);
|
||||
} else if (_declaredVariables.contains(name)) {
|
||||
else if (_declaredVariables.contains(name))
|
||||
addMessage(WarnDuplicateDeclaration, ast->identifierToken, name);
|
||||
}
|
||||
|
||||
if (_possiblyUndeclaredUses.contains(name)) {
|
||||
foreach (const SourceLocation &loc, _possiblyUndeclaredUses.value(name)) {
|
||||
@@ -454,9 +450,8 @@ protected:
|
||||
|
||||
bool visit(FunctionDeclaration *ast)
|
||||
{
|
||||
if (_seenNonDeclarationStatement) {
|
||||
if (_seenNonDeclarationStatement)
|
||||
addMessage(HintDeclarationsShouldBeAtStartOfFunction, ast->functionToken);
|
||||
}
|
||||
|
||||
return visit(static_cast<FunctionExpression *>(ast));
|
||||
}
|
||||
@@ -467,13 +462,12 @@ protected:
|
||||
return false;
|
||||
const QString &name = ast->name.toString();
|
||||
|
||||
if (_formalParameterNames.contains(name)) {
|
||||
if (_formalParameterNames.contains(name))
|
||||
addMessage(WarnAlreadyFormalParameter, ast->identifierToken, name);
|
||||
} else if (_declaredVariables.contains(name)) {
|
||||
else if (_declaredVariables.contains(name))
|
||||
addMessage(WarnAlreadyVar, ast->identifierToken, name);
|
||||
} else if (_declaredFunctions.contains(name)) {
|
||||
else if (_declaredFunctions.contains(name))
|
||||
addMessage(WarnDuplicateDeclaration, ast->identifierToken, name);
|
||||
}
|
||||
|
||||
if (FunctionDeclaration *decl = cast<FunctionDeclaration *>(ast)) {
|
||||
if (_possiblyUndeclaredUses.contains(name)) {
|
||||
@@ -642,9 +636,8 @@ void Check::checkProperty(UiQualifiedId *qualifiedId)
|
||||
{
|
||||
const QString id = toString(qualifiedId);
|
||||
if (id.at(0).isLower()) {
|
||||
if (m_propertyStack.top().contains(id)) {
|
||||
if (m_propertyStack.top().contains(id))
|
||||
addMessage(ErrPropertiesCanOnlyHaveOneBinding, fullLocationForQualifiedId(qualifiedId));
|
||||
}
|
||||
m_propertyStack.top().insert(id);
|
||||
}
|
||||
}
|
||||
@@ -1155,9 +1148,8 @@ bool Check::visit(ExpressionStatement *ast)
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
if (!ok)
|
||||
ok = _inStatementBinding;
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
addMessage(WarnConfusingExpressionStatement,
|
||||
@@ -1242,9 +1234,8 @@ void Check::checkNewExpression(ExpressionNode *ast)
|
||||
const QString name = functionName(ast, &location);
|
||||
if (name.isEmpty())
|
||||
return;
|
||||
if (!name.at(0).isUpper()) {
|
||||
if (!name.at(0).isUpper())
|
||||
addMessage(WarnNewWithLowercaseFunction, location);
|
||||
}
|
||||
}
|
||||
|
||||
void Check::checkBindingRhs(Statement *statement)
|
||||
@@ -1261,9 +1252,8 @@ void Check::checkBindingRhs(Statement *statement)
|
||||
|
||||
void Check::checkExtraParentheses(ExpressionNode *expression)
|
||||
{
|
||||
if (NestedExpression *nested = cast<NestedExpression *>(expression)) {
|
||||
if (NestedExpression *nested = cast<NestedExpression *>(expression))
|
||||
addMessage(HintExtraParentheses, nested->lparenToken);
|
||||
}
|
||||
}
|
||||
|
||||
void Check::addMessages(const QList<Message> &messages)
|
||||
@@ -1311,9 +1301,8 @@ void Check::scanCommentsForAnnotations()
|
||||
const QString &comment = _doc->source().mid(commentLoc.begin(), commentLoc.length);
|
||||
|
||||
// enable all checks annotation
|
||||
if (comment.contains(QLatin1String("@enable-all-checks"))) {
|
||||
if (comment.contains(QLatin1String("@enable-all-checks")))
|
||||
_enabledMessages = Message::allMessageTypes().toSet();
|
||||
}
|
||||
|
||||
// find all disable annotations
|
||||
int lastOffset = -1;
|
||||
|
||||
@@ -833,11 +833,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;
|
||||
}
|
||||
@@ -1318,9 +1317,8 @@ void QtStyleCodeFormatter::adjustIndent(const QList<Token> &tokens, int startLex
|
||||
break;
|
||||
|
||||
case Colon:
|
||||
if (topState.type == ternary_op) {
|
||||
if (topState.type == ternary_op)
|
||||
*indentDepth -= 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case Question:
|
||||
|
||||
@@ -238,9 +238,8 @@ void CompletionContextFinder::checkImport()
|
||||
break;
|
||||
}
|
||||
} else if (tokenString == QLatin1String("import")) {
|
||||
if (state == Unknown || (state & ExpectImport)) {
|
||||
if (state == Unknown || (state & ExpectImport))
|
||||
m_inImport = true;
|
||||
}
|
||||
} else {
|
||||
if (state == Unknown || (state & ExpectAnyTarget)
|
||||
|| (state & ExpectTargetIdentifier)) {
|
||||
|
||||
@@ -61,9 +61,8 @@ private:
|
||||
|
||||
bool BuildParentHash::preVisit(Node* ast)
|
||||
{
|
||||
if (ast->uiObjectMemberCast()) {
|
||||
if (ast->uiObjectMemberCast())
|
||||
stack.append(ast->uiObjectMemberCast());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,9 +70,8 @@ void BuildParentHash::postVisit(Node* ast)
|
||||
{
|
||||
if (ast->uiObjectMemberCast()) {
|
||||
stack.removeLast();
|
||||
if (!stack.isEmpty()) {
|
||||
if (!stack.isEmpty())
|
||||
parent.insert(ast->uiObjectMemberCast(), stack.last());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,9 +289,8 @@ static QString _propertyName(UiQualifiedId *id)
|
||||
static QString _methodName(UiSourceElement *source)
|
||||
{
|
||||
if (source) {
|
||||
if (FunctionDeclaration *declaration = cast<FunctionDeclaration*>(source->sourceElement)) {
|
||||
if (FunctionDeclaration *declaration = cast<FunctionDeclaration*>(source->sourceElement))
|
||||
return declaration->name.toString();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
@@ -415,9 +412,8 @@ void Delta::update(UiObjectMember* oldObject, const QmlJS::Document::Ptr& oldDoc
|
||||
const QString scriptCode = _scriptCode(script, newDoc);
|
||||
UiScriptBinding *previousScript = cast<UiScriptBinding *>(oldMember);
|
||||
if (!previousScript || _scriptCode(previousScript, oldDoc) != scriptCode) {
|
||||
if (debugReferences.count()==0) {
|
||||
if (debugReferences.count()==0)
|
||||
notifyUnsyncronizableElementChange(newObject);
|
||||
}
|
||||
foreach (DebugId ref, debugReferences) {
|
||||
if (ref != -1)
|
||||
updateScriptBinding(ref, newObject, script, property, scriptCode);
|
||||
@@ -429,9 +425,8 @@ void Delta::update(UiObjectMember* oldObject, const QmlJS::Document::Ptr& oldDoc
|
||||
UiSourceElement *previousSource = cast<UiSourceElement*>(oldMember);
|
||||
|
||||
if (!previousSource || _methodCode(previousSource, oldDoc) != methodCode) {
|
||||
if (debugReferences.count()==0) {
|
||||
if (debugReferences.count()==0)
|
||||
notifyUnsyncronizableElementChange(newObject);
|
||||
}
|
||||
foreach (DebugId ref, debugReferences) {
|
||||
if (ref != -1)
|
||||
updateMethodBody(ref, newObject, script, methodName, methodCode);
|
||||
|
||||
@@ -378,9 +378,8 @@ Document::MutablePtr Snapshot::documentFromSource(
|
||||
{
|
||||
Document::MutablePtr newDoc = Document::create(fileName, language);
|
||||
|
||||
if (Document::Ptr thisDocument = document(fileName)) {
|
||||
if (Document::Ptr thisDocument = document(fileName))
|
||||
newDoc->_editorRevision = thisDocument->_editorRevision;
|
||||
}
|
||||
|
||||
newDoc->setSource(code);
|
||||
return newDoc;
|
||||
|
||||
@@ -318,9 +318,8 @@ bool Evaluate::visit(AST::FieldMemberExpression *ast)
|
||||
return false;
|
||||
|
||||
if (const Value *base = _valueOwner->convertToObject(value(ast->base))) {
|
||||
if (const ObjectValue *obj = base->asObjectValue()) {
|
||||
if (const ObjectValue *obj = base->asObjectValue())
|
||||
_result = obj->lookupMember(ast->name.toString(), _context);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -328,26 +327,23 @@ bool Evaluate::visit(AST::FieldMemberExpression *ast)
|
||||
|
||||
bool Evaluate::visit(AST::NewMemberExpression *ast)
|
||||
{
|
||||
if (const FunctionValue *ctor = value_cast<FunctionValue>(value(ast->base))) {
|
||||
if (const FunctionValue *ctor = value_cast<FunctionValue>(value(ast->base)))
|
||||
_result = ctor->returnValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Evaluate::visit(AST::NewExpression *ast)
|
||||
{
|
||||
if (const FunctionValue *ctor = value_cast<FunctionValue>(value(ast->expression))) {
|
||||
if (const FunctionValue *ctor = value_cast<FunctionValue>(value(ast->expression)))
|
||||
_result = ctor->returnValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Evaluate::visit(AST::CallExpression *ast)
|
||||
{
|
||||
if (const Value *base = value(ast->base)) {
|
||||
if (const FunctionValue *obj = base->asFunctionValue()) {
|
||||
if (const FunctionValue *obj = base->asFunctionValue())
|
||||
_result = obj->returnValue();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -119,12 +119,10 @@ QIcon Icons::icon(const QString &packageName, const QString typeName) const
|
||||
|
||||
QIcon Icons::icon(Node *node) const
|
||||
{
|
||||
if (dynamic_cast<AST::UiObjectDefinition*>(node)) {
|
||||
if (dynamic_cast<AST::UiObjectDefinition*>(node))
|
||||
return objectDefinitionIcon();
|
||||
}
|
||||
if (dynamic_cast<AST::UiScriptBinding*>(node)) {
|
||||
if (dynamic_cast<AST::UiScriptBinding*>(node))
|
||||
return scriptBindingIcon();
|
||||
}
|
||||
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
@@ -147,11 +147,10 @@ int QmlJSIndenter::columnForIndex(const QString &t, int index) const
|
||||
index = t.length();
|
||||
|
||||
for (int i = 0; i < index; i++) {
|
||||
if (t.at(i) == QLatin1Char('\t')) {
|
||||
if (t.at(i) == QLatin1Char('\t'))
|
||||
col = ((col / ppHardwareTabSize) + 1) * ppHardwareTabSize;
|
||||
} else {
|
||||
else
|
||||
col++;
|
||||
}
|
||||
}
|
||||
return col;
|
||||
}
|
||||
@@ -288,11 +287,10 @@ int QmlJSIndenter::indentForContinuationLine()
|
||||
delimiters.
|
||||
*/
|
||||
if (braceDepth == -1) {
|
||||
if (j < yyLine->length() - 1) {
|
||||
if (j < yyLine->length() - 1)
|
||||
hook = j;
|
||||
} else {
|
||||
else
|
||||
return 0; // shouldn't happen
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
@@ -587,17 +585,15 @@ int QmlJSIndenter::indentForBottomLine(QTextBlock begin, QTextBlock end, QChar t
|
||||
smartly, unless the user has already played around with it,
|
||||
in which case it's better to leave her stuff alone.
|
||||
*/
|
||||
if (isOnlyWhiteSpace(bottomLine)) {
|
||||
if (isOnlyWhiteSpace(bottomLine))
|
||||
indent = indentWhenBottomLineStartsInMultiLineComment();
|
||||
} else {
|
||||
else
|
||||
indent = indentOfLine(bottomLine);
|
||||
}
|
||||
} else {
|
||||
if (isUnfinishedLine()) {
|
||||
if (isUnfinishedLine())
|
||||
indent = indentForContinuationLine();
|
||||
} else {
|
||||
else
|
||||
indent = indentForStandaloneLine();
|
||||
}
|
||||
|
||||
if ((okay(typedIn, QLatin1Char('}')) && firstCh == QLatin1Char('}'))
|
||||
|| (okay(typedIn, QLatin1Char(']')) && firstCh == QLatin1Char(']'))) {
|
||||
|
||||
@@ -357,9 +357,8 @@ const Value *CppComponentValue::valueForCppName(const QString &typeName) const
|
||||
// might be an enum
|
||||
const CppComponentValue *base = this;
|
||||
const QStringList components = typeName.split(QLatin1String("::"));
|
||||
if (components.size() == 2) {
|
||||
if (components.size() == 2)
|
||||
base = valueOwner()->cppQmlTypes().objectByCppName(components.first());
|
||||
}
|
||||
if (base) {
|
||||
if (const QmlEnumValue *value = base->getEnumValue(components.last()))
|
||||
return value;
|
||||
@@ -413,9 +412,8 @@ QString CppComponentValue::propertyType(const QString &propertyName) const
|
||||
foreach (const CppComponentValue *it, prototypes()) {
|
||||
FakeMetaObject::ConstPtr iter = it->_metaObject;
|
||||
int propIdx = iter->propertyIndex(propertyName);
|
||||
if (propIdx != -1) {
|
||||
if (propIdx != -1)
|
||||
return iter->property(propIdx).typeName();
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
@@ -425,9 +423,8 @@ bool CppComponentValue::isListProperty(const QString &propertyName) const
|
||||
foreach (const CppComponentValue *it, prototypes()) {
|
||||
FakeMetaObject::ConstPtr iter = it->_metaObject;
|
||||
int propIdx = iter->propertyIndex(propertyName);
|
||||
if (propIdx != -1) {
|
||||
if (propIdx != -1)
|
||||
return iter->property(propIdx).isList();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -510,9 +507,8 @@ bool CppComponentValue::isWritable(const QString &propertyName) const
|
||||
foreach (const CppComponentValue *it, prototypes()) {
|
||||
FakeMetaObject::ConstPtr iter = it->_metaObject;
|
||||
int propIdx = iter->propertyIndex(propertyName);
|
||||
if (propIdx != -1) {
|
||||
if (propIdx != -1)
|
||||
return iter->property(propIdx).isWritable();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -522,9 +518,8 @@ bool CppComponentValue::isPointer(const QString &propertyName) const
|
||||
foreach (const CppComponentValue *it, prototypes()) {
|
||||
FakeMetaObject::ConstPtr iter = it->_metaObject;
|
||||
int propIdx = iter->propertyIndex(propertyName);
|
||||
if (propIdx != -1) {
|
||||
if (propIdx != -1)
|
||||
return iter->property(propIdx).isPointer();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -542,9 +537,8 @@ bool CppComponentValue::hasProperty(const QString &propertyName) const
|
||||
foreach (const CppComponentValue *it, prototypes()) {
|
||||
FakeMetaObject::ConstPtr iter = it->_metaObject;
|
||||
int propIdx = iter->propertyIndex(propertyName);
|
||||
if (propIdx != -1) {
|
||||
if (propIdx != -1)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -956,9 +950,8 @@ const ObjectValue *ObjectValue::prototype(const Context *context) const
|
||||
{
|
||||
const ObjectValue *prototypeObject = value_cast<ObjectValue>(_prototype);
|
||||
if (! prototypeObject) {
|
||||
if (const Reference *prototypeReference = value_cast<Reference>(_prototype)) {
|
||||
if (const Reference *prototypeReference = value_cast<Reference>(_prototype))
|
||||
prototypeObject = value_cast<ObjectValue>(context->lookupReference(prototypeReference));
|
||||
}
|
||||
}
|
||||
return prototypeObject;
|
||||
}
|
||||
@@ -1110,9 +1103,8 @@ const ObjectValue *PrototypeIterator::next()
|
||||
|
||||
const ObjectValue *PrototypeIterator::peekNext()
|
||||
{
|
||||
if (hasNext()) {
|
||||
if (hasNext())
|
||||
return m_next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1299,11 +1291,10 @@ void CppQmlTypesLoader::parseQmlTypeDescriptions(const QByteArray &xml,
|
||||
warningMessage->clear();
|
||||
TypeDescriptionReader reader(QString::fromUtf8(xml));
|
||||
if (!reader(newObjects, newModuleApis)) {
|
||||
if (reader.errorMessage().isEmpty()) {
|
||||
if (reader.errorMessage().isEmpty())
|
||||
*errorMessage = QLatin1String("unknown error");
|
||||
} else {
|
||||
else
|
||||
*errorMessage = reader.errorMessage();
|
||||
}
|
||||
}
|
||||
*warningMessage = reader.warningMessage();
|
||||
}
|
||||
@@ -2106,18 +2097,16 @@ ImportInfo ImportInfo::pathImport(const QString &docPath, const QString &path,
|
||||
info._name = path;
|
||||
|
||||
QFileInfo importFileInfo(path);
|
||||
if (!importFileInfo.isAbsolute()) {
|
||||
if (!importFileInfo.isAbsolute())
|
||||
importFileInfo = QFileInfo(docPath + QDir::separator() + path);
|
||||
}
|
||||
info._path = importFileInfo.absoluteFilePath();
|
||||
|
||||
if (importFileInfo.isFile()) {
|
||||
if (importFileInfo.isFile())
|
||||
info._type = FileImport;
|
||||
} else if (importFileInfo.isDir()) {
|
||||
else if (importFileInfo.isDir())
|
||||
info._type = DirectoryImport;
|
||||
} else {
|
||||
else
|
||||
info._type = UnknownFileImport;
|
||||
}
|
||||
|
||||
info._version = version;
|
||||
info._as = as;
|
||||
@@ -2230,11 +2219,10 @@ void TypeScope::processMembers(MemberProcessor *processor) const
|
||||
if (info.type() == ImportInfo::FileImport)
|
||||
continue;
|
||||
|
||||
if (!info.as().isEmpty()) {
|
||||
if (!info.as().isEmpty())
|
||||
processor->processProperty(info.as(), import);
|
||||
} else {
|
||||
else
|
||||
import->processMembers(processor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,11 +205,10 @@ QString LineInfo::trimmedCodeLine(const QString &t)
|
||||
while (i >= 2) {
|
||||
const Token &prev = yyLinizerState.tokens.at(i-1);
|
||||
const Token &prevPrev = yyLinizerState.tokens.at(i-2);
|
||||
if (prev.kind == Token::Dot && prevPrev.kind == Token::Identifier) {
|
||||
if (prev.kind == Token::Dot && prevPrev.kind == Token::Identifier)
|
||||
i -= 2;
|
||||
} else {
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// it could also be 'a = \n Foo \n {', but that sounds unlikely
|
||||
|
||||
@@ -460,11 +460,10 @@ bool LinkPrivate::importLibrary(Document::Ptr doc,
|
||||
// all but no-uri module apis become available for import
|
||||
QList<ModuleApiInfo> noUriModuleApis;
|
||||
foreach (const ModuleApiInfo &moduleApi, libraryInfo.moduleApis()) {
|
||||
if (moduleApi.uri.isEmpty()) {
|
||||
if (moduleApi.uri.isEmpty())
|
||||
noUriModuleApis += moduleApi;
|
||||
} else {
|
||||
else
|
||||
importableModuleApis[moduleApi.uri] += moduleApi;
|
||||
}
|
||||
}
|
||||
|
||||
// if a module api has no uri, it shares the same name
|
||||
@@ -501,9 +500,8 @@ void LinkPrivate::loadQmldirComponents(ObjectValue *import, ComponentVersion ver
|
||||
const LibraryInfo &libraryInfo, const QString &libraryPath)
|
||||
{
|
||||
// if the version isn't valid, import the latest
|
||||
if (!version.isValid()) {
|
||||
if (!version.isValid())
|
||||
version = ComponentVersion(ComponentVersion::MaxVersion, ComponentVersion::MaxVersion);
|
||||
}
|
||||
|
||||
|
||||
QSet<QString> importedTypes;
|
||||
@@ -535,9 +533,8 @@ void LinkPrivate::loadImplicitDirectoryImports(Imports *imports, Document::Ptr d
|
||||
if (directoryImport.object)
|
||||
importCache.insert(ImportCacheKey(implcitDirectoryImportInfo), directoryImport);
|
||||
}
|
||||
if (directoryImport.object) {
|
||||
if (directoryImport.object)
|
||||
imports->append(directoryImport);
|
||||
}
|
||||
}
|
||||
|
||||
void LinkPrivate::loadImplicitDefaultImports(Imports *imports)
|
||||
|
||||
@@ -143,9 +143,8 @@ static bool isEnum(AST::Statement *ast)
|
||||
if (!ast)
|
||||
return false;
|
||||
|
||||
if (ExpressionStatement *exprStmt = cast<ExpressionStatement*>(ast)) {
|
||||
if (ExpressionStatement *exprStmt = cast<ExpressionStatement*>(ast))
|
||||
return isEnum(exprStmt->expression);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -166,11 +166,10 @@ protected:
|
||||
if (precededByEmptyLine(fixedLoc))
|
||||
newLine();
|
||||
out(toString(fixedLoc)); // don't use the sourceloc overload here
|
||||
if (followedByNewLine(fixedLoc)) {
|
||||
if (followedByNewLine(fixedLoc))
|
||||
newLine();
|
||||
} else {
|
||||
else
|
||||
out(" ");
|
||||
}
|
||||
}
|
||||
|
||||
void out(const QString &str, const SourceLocation &lastLoc = SourceLocation())
|
||||
@@ -260,9 +259,8 @@ protected:
|
||||
qreal result = badnessFromSplits;
|
||||
foreach (const QString &line, lines) {
|
||||
// really long lines should be avoided at all cost
|
||||
if (line.size() > strongMaxLineLength) {
|
||||
if (line.size() > strongMaxLineLength)
|
||||
result += 50 + (line.size() - strongMaxLineLength);
|
||||
}
|
||||
// having long lines is bad
|
||||
else if (line.size() > maxLineLength) {
|
||||
result += 3 + (line.size() - maxLineLength);
|
||||
@@ -446,22 +444,20 @@ protected:
|
||||
virtual bool preVisit(Node *ast)
|
||||
{
|
||||
SourceLocation firstLoc;
|
||||
if (ExpressionNode *expr = ast->expressionCast()) {
|
||||
if (ExpressionNode *expr = ast->expressionCast())
|
||||
firstLoc = expr->firstSourceLocation();
|
||||
} else if (Statement *stmt = ast->statementCast()) {
|
||||
else if (Statement *stmt = ast->statementCast())
|
||||
firstLoc = stmt->firstSourceLocation();
|
||||
} else if (UiObjectMember *mem = ast->uiObjectMemberCast()) {
|
||||
else if (UiObjectMember *mem = ast->uiObjectMemberCast())
|
||||
firstLoc = mem->firstSourceLocation();
|
||||
} else if (UiImport *import = cast<UiImport *>(ast)) {
|
||||
else if (UiImport *import = cast<UiImport *>(ast))
|
||||
firstLoc = import->firstSourceLocation();
|
||||
}
|
||||
|
||||
if (firstLoc.isValid() && int(firstLoc.offset) != _lastNewlineOffset) {
|
||||
_lastNewlineOffset = firstLoc.offset;
|
||||
|
||||
if (precededByEmptyLine(firstLoc) && !_result.endsWith(QLatin1String("\n\n"))) {
|
||||
if (precededByEmptyLine(firstLoc) && !_result.endsWith(QLatin1String("\n\n")))
|
||||
newLine();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -470,15 +466,14 @@ protected:
|
||||
virtual void postVisit(Node *ast)
|
||||
{
|
||||
SourceLocation lastLoc;
|
||||
if (ExpressionNode *expr = ast->expressionCast()) {
|
||||
if (ExpressionNode *expr = ast->expressionCast())
|
||||
lastLoc = expr->lastSourceLocation();
|
||||
} else if (Statement *stmt = ast->statementCast()) {
|
||||
else if (Statement *stmt = ast->statementCast())
|
||||
lastLoc = stmt->lastSourceLocation();
|
||||
} else if (UiObjectMember *mem = ast->uiObjectMemberCast()) {
|
||||
else if (UiObjectMember *mem = ast->uiObjectMemberCast())
|
||||
lastLoc = mem->lastSourceLocation();
|
||||
} else if (UiImport *import = cast<UiImport *>(ast)) {
|
||||
else if (UiImport *import = cast<UiImport *>(ast))
|
||||
lastLoc = import->lastSourceLocation();
|
||||
}
|
||||
|
||||
if (lastLoc.isValid()) {
|
||||
const QList<SourceLocation> &comments = _doc->engine()->comments();
|
||||
@@ -510,11 +505,10 @@ protected:
|
||||
virtual bool visit(UiImport *ast)
|
||||
{
|
||||
out("import ", ast->importToken);
|
||||
if (!ast->fileName.isNull()) {
|
||||
if (!ast->fileName.isNull())
|
||||
out(QString::fromLatin1("\"%1\"").arg(ast->fileName.toString()));
|
||||
} else {
|
||||
else
|
||||
accept(ast->importUri);
|
||||
}
|
||||
if (ast->versionToken.isValid()) {
|
||||
out(" ");
|
||||
out(ast->versionToken);
|
||||
|
||||
@@ -288,9 +288,8 @@ void Rewriter::changeBinding(UiObjectInitializer *ast,
|
||||
// for grouped properties:
|
||||
else if (!prefix.isEmpty()) {
|
||||
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(member)) {
|
||||
if (toString(def->qualifiedTypeNameId) == prefix) {
|
||||
if (toString(def->qualifiedTypeNameId) == prefix)
|
||||
changeBinding(def->initializer, suffix, newValue, binding);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,11 +352,10 @@ bool Rewriter::isMatchingPropertyMember(const QString &propertyName,
|
||||
|
||||
bool Rewriter::nextMemberOnSameLine(UiObjectMemberList *members)
|
||||
{
|
||||
if (members && members->next && members->next->member) {
|
||||
if (members && members->next && members->next->member)
|
||||
return members->next->member->firstSourceLocation().startLine == members->member->lastSourceLocation().startLine;
|
||||
} else {
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Rewriter::insertIntoArray(UiArrayBinding *ast, const QString &newValue)
|
||||
@@ -388,15 +386,13 @@ void Rewriter::removeBindingByName(UiObjectInitializer *ast, const QString &prop
|
||||
UiObjectMember *member = it->member;
|
||||
|
||||
// run full name match (for ungrouped properties):
|
||||
if (isMatchingPropertyMember(propertyName, member)) {
|
||||
if (isMatchingPropertyMember(propertyName, member))
|
||||
removeMember(member);
|
||||
}
|
||||
// check for grouped properties:
|
||||
else if (!prefix.isEmpty()) {
|
||||
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(member)) {
|
||||
if (toString(def->qualifiedTypeNameId) == prefix) {
|
||||
if (toString(def->qualifiedTypeNameId) == prefix)
|
||||
removeGroupedProperty(def, propertyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,9 +413,8 @@ void Rewriter::removeGroupedProperty(UiObjectDefinition *ast,
|
||||
++memberCount;
|
||||
UiObjectMember *member = it->member;
|
||||
|
||||
if (!wanted && isMatchingPropertyMember(propName, member)) {
|
||||
if (!wanted && isMatchingPropertyMember(propName, member))
|
||||
wanted = member;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wanted)
|
||||
@@ -517,9 +512,8 @@ void Rewriter::includeEmptyGroupedProperty(UiObjectDefinition *groupedProperty,
|
||||
// grouped property
|
||||
UiObjectMemberList *memberIter = groupedProperty->initializer->members;
|
||||
while (memberIter) {
|
||||
if (memberIter->member != memberToBeRemoved) {
|
||||
if (memberIter->member != memberToBeRemoved)
|
||||
return;
|
||||
}
|
||||
memberIter = memberIter->next;
|
||||
}
|
||||
start = groupedProperty->firstSourceLocation().begin();
|
||||
@@ -670,9 +664,8 @@ void Rewriter::removeObjectMember(UiObjectMember *member, UiObjectMember *parent
|
||||
if (UiArrayBinding *parentArray = cast<UiArrayBinding *>(parent)) {
|
||||
extendToLeadingOrTrailingComma(parentArray, member, start, end);
|
||||
} else {
|
||||
if (UiObjectDefinition *parentObjectDefinition = cast<UiObjectDefinition *>(parent)) {
|
||||
if (UiObjectDefinition *parentObjectDefinition = cast<UiObjectDefinition *>(parent))
|
||||
includeEmptyGroupedProperty(parentObjectDefinition, member, start, end);
|
||||
}
|
||||
includeSurroundingWhitespace(m_originalText, start, end);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,13 +55,12 @@ void ScopeAstPath::accept(Node *node)
|
||||
|
||||
bool ScopeAstPath::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;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,14 +81,12 @@ void ScopeBuilder::push(AST::Node *node)
|
||||
break;
|
||||
}
|
||||
// signals defined in QML
|
||||
if (const ASTSignal *astsig = value_cast<ASTSignal>(value)) {
|
||||
if (const ASTSignal *astsig = value_cast<ASTSignal>(value))
|
||||
_scopeChain->appendJsScope(astsig->bodyScope());
|
||||
}
|
||||
// signals defined in C++
|
||||
else if (const CppComponentValue *qmlObject = value_cast<CppComponentValue>(owner)) {
|
||||
if (const ObjectValue *scope = qmlObject->signalScope(name)) {
|
||||
if (const ObjectValue *scope = qmlObject->signalScope(name))
|
||||
_scopeChain->appendJsScope(scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,11 +168,10 @@ void ScopeBuilder::setQmlScopeObject(Node *node)
|
||||
}
|
||||
|
||||
const ObjectValue *scopeObject = _scopeChain->document()->bind()->findQmlObject(node);
|
||||
if (scopeObject) {
|
||||
if (scopeObject)
|
||||
qmlScopeObjects += scopeObject;
|
||||
} else {
|
||||
else
|
||||
return; // Probably syntax errors, where we're working with a "recovered" AST.
|
||||
}
|
||||
|
||||
// check if the object has a Qt.ListElement or Qt.Connections ancestor
|
||||
// ### allow only signal bindings for Connections
|
||||
@@ -208,11 +205,10 @@ void ScopeBuilder::setQmlScopeObject(Node *node)
|
||||
Evaluate evaluator(_scopeChain);
|
||||
const Value *targetValue = evaluator(scriptBinding->statement);
|
||||
|
||||
if (const ObjectValue *target = value_cast<ObjectValue>(targetValue)) {
|
||||
if (const ObjectValue *target = value_cast<ObjectValue>(targetValue))
|
||||
qmlScopeObjects.prepend(target);
|
||||
} else {
|
||||
else
|
||||
qmlScopeObjects.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,11 +157,10 @@ void TypeDescriptionReader::readModule(UiObjectDefinition *ast)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeName == QLatin1String("Component")) {
|
||||
if (typeName == QLatin1String("Component"))
|
||||
readComponent(component);
|
||||
} else if (typeName == QLatin1String("ModuleApi")) {
|
||||
else if (typeName == QLatin1String("ModuleApi"))
|
||||
readModuleApi(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,15 +190,14 @@ void TypeDescriptionReader::readComponent(UiObjectDefinition *ast)
|
||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
||||
if (component) {
|
||||
QString name = toString(component->qualifiedTypeNameId);
|
||||
if (name == QLatin1String("Property")) {
|
||||
if (name == QLatin1String("Property"))
|
||||
readProperty(component, fmo);
|
||||
} else if (name == QLatin1String("Method") || name == QLatin1String("Signal")) {
|
||||
else if (name == QLatin1String("Method") || name == QLatin1String("Signal"))
|
||||
readSignalOrMethod(component, name == QLatin1String("Method"), fmo);
|
||||
} else if (name == QLatin1String("Enum")) {
|
||||
else if (name == QLatin1String("Enum"))
|
||||
readEnum(component, fmo);
|
||||
} else {
|
||||
else
|
||||
addWarning(component->firstSourceLocation(), tr("Expected only Property, Method, Signal and Enum object definitions"));
|
||||
}
|
||||
} else if (script) {
|
||||
QString name = toString(script->qualifiedId);
|
||||
if (name == QLatin1String("name")) {
|
||||
@@ -283,22 +281,20 @@ void TypeDescriptionReader::readSignalOrMethod(UiObjectDefinition *ast, bool isM
|
||||
UiScriptBinding *script = dynamic_cast<UiScriptBinding *>(member);
|
||||
if (component) {
|
||||
QString name = toString(component->qualifiedTypeNameId);
|
||||
if (name == QLatin1String("Parameter")) {
|
||||
if (name == QLatin1String("Parameter"))
|
||||
readParameter(component, &fmm);
|
||||
} else {
|
||||
else
|
||||
addWarning(component->firstSourceLocation(), tr("Expected only Parameter object definitions"));
|
||||
}
|
||||
} else if (script) {
|
||||
QString name = toString(script->qualifiedId);
|
||||
if (name == QLatin1String("name")) {
|
||||
if (name == QLatin1String("name"))
|
||||
fmm.setMethodName(readStringBinding(script));
|
||||
} else if (name == QLatin1String("type")) {
|
||||
else if (name == QLatin1String("type"))
|
||||
fmm.setReturnType(readStringBinding(script));
|
||||
} else if (name == QLatin1String("revision")) {
|
||||
else if (name == QLatin1String("revision"))
|
||||
fmm.setRevision(readIntBinding(script));
|
||||
} else {
|
||||
else
|
||||
addWarning(script->firstSourceLocation(), tr("Expected only name and type script bindings"));
|
||||
}
|
||||
|
||||
} else {
|
||||
addWarning(member->firstSourceLocation(), tr("Expected only script bindings and object definitions"));
|
||||
@@ -331,21 +327,20 @@ void TypeDescriptionReader::readProperty(UiObjectDefinition *ast, FakeMetaObject
|
||||
}
|
||||
|
||||
QString id = toString(script->qualifiedId);
|
||||
if (id == QLatin1String("name")) {
|
||||
if (id == QLatin1String("name"))
|
||||
name = readStringBinding(script);
|
||||
} else if (id == QLatin1String("type")) {
|
||||
else if (id == QLatin1String("type"))
|
||||
type = readStringBinding(script);
|
||||
} else if (id == QLatin1String("isPointer")) {
|
||||
else if (id == QLatin1String("isPointer"))
|
||||
isPointer = readBoolBinding(script);
|
||||
} else if (id == QLatin1String("isReadonly")) {
|
||||
else if (id == QLatin1String("isReadonly"))
|
||||
isReadonly = readBoolBinding(script);
|
||||
} else if (id == QLatin1String("isList")) {
|
||||
else if (id == QLatin1String("isList"))
|
||||
isList = readBoolBinding(script);
|
||||
} else if (id == QLatin1String("revision")) {
|
||||
else if (id == QLatin1String("revision"))
|
||||
revision = readIntBinding(script);
|
||||
} else {
|
||||
else
|
||||
addWarning(script->firstSourceLocation(), tr("Expected only type, name, revision, isPointer, isReadonly and isList script bindings"));
|
||||
}
|
||||
}
|
||||
|
||||
if (name.isEmpty() || type.isEmpty()) {
|
||||
@@ -369,13 +364,12 @@ void TypeDescriptionReader::readEnum(UiObjectDefinition *ast, FakeMetaObject::Pt
|
||||
}
|
||||
|
||||
QString name = toString(script->qualifiedId);
|
||||
if (name == QLatin1String("name")) {
|
||||
if (name == QLatin1String("name"))
|
||||
fme.setName(readStringBinding(script));
|
||||
} else if (name == QLatin1String("values")) {
|
||||
else if (name == QLatin1String("values"))
|
||||
readEnumValues(script, &fme);
|
||||
} else {
|
||||
else
|
||||
addWarning(script->firstSourceLocation(), tr("Expected only name and values script bindings"));
|
||||
}
|
||||
}
|
||||
|
||||
fmo->addEnum(fme);
|
||||
|
||||
Reference in New Issue
Block a user