Merge remote-tracking branch 'origin/2.8'

Conflicts:
	qtcreator.pri
	qtcreator.qbs

Change-Id: I1aa7506519e0f461f33921ca20ce1b51adb5783f
This commit is contained in:
Eike Ziller
2013-06-27 14:24:57 +02:00
71 changed files with 767 additions and 404 deletions

View File

@@ -115,7 +115,7 @@ static unsigned firstTypeSpecifierWithoutFollowingAttribute(
PointerDeclarationFormatter::PointerDeclarationFormatter(
const CppRefactoringFilePtr refactoringFile,
const Overview &overview,
Overview &overview,
CursorHandling cursorHandling)
: ASTVisitor(refactoringFile->cppDocument()->translationUnit())
, m_cppRefactoringFile(refactoringFile)
@@ -413,21 +413,14 @@ void PointerDeclarationFormatter::checkAndRewrite(DeclaratorAST *declarator,
QString rewrittenDeclaration;
const Name *name = symbol->name();
if (name) {
if (name->isOperatorNameId()) {
// Take the operator name from the file instead from the AST, so the white
// spaces within the operator names can be respected, e.g. in "operator =".
const QByteArray operatorText
= m_cppRefactoringFile->textOf(declarator->core_declarator).toLatin1();
Identifier operatorName(operatorText.constData(), operatorText.size());
rewrittenDeclaration = rewriteDeclaration(type, &operatorName);
} else {
rewrittenDeclaration = rewriteDeclaration(type, name);
if (name->isOperatorNameId()
|| (name->isQualifiedNameId()
&& name->asQualifiedNameId()->name()->isOperatorNameId())) {
const QString operatorText = m_cppRefactoringFile->textOf(declarator->core_declarator);
m_overview.includeWhiteSpaceInOperatorName = operatorText.contains(QLatin1Char(' '));
}
} else {
// The declaration will be correctly rewritten for name == 0 (e.g. "int *").
rewrittenDeclaration = rewriteDeclaration(type, name);
}
rewrittenDeclaration = m_overview.prettyType(type, name);
rewrittenDeclaration.remove(0, charactersToRemove);
CHECK_R(originalDeclaration != rewrittenDeclaration, "Rewritten is same as original");
@@ -460,21 +453,6 @@ void PointerDeclarationFormatter::checkAndRewrite(DeclaratorAST *declarator,
qDebug() << "Replacement operation failed";
}
/*! Rewrite/format the given type and name. */
QString PointerDeclarationFormatter::rewriteDeclaration(FullySpecifiedType type, const Name *name)
const
{
CHECK_RV(type.isValid(), "Invalid type", QString());
const char *identifier = 0;
if (const Name *declarationName = name) {
if (const Identifier *id = declarationName->identifier())
identifier = id->chars();
}
return m_overview.prettyType(type, QLatin1String(identifier));
}
void PointerDeclarationFormatter::printCandidate(AST *ast)
{
#if DEBUG_OUTPUT

View File

@@ -78,7 +78,7 @@ public:
enum CursorHandling { RespectCursor, IgnoreCursor };
explicit PointerDeclarationFormatter(const CppRefactoringFilePtr refactoringFile,
const Overview &overview,
Overview &overview,
CursorHandling cursorHandling = IgnoreCursor);
/*!
@@ -113,11 +113,10 @@ private:
void processIfWhileForStatement(ExpressionAST *expression, Symbol *symbol);
void checkAndRewrite(DeclaratorAST *declarator, Symbol *symbol, TokenRange range,
unsigned charactersToRemove = 0);
QString rewriteDeclaration(FullySpecifiedType type, const Name *name) const;
void printCandidate(AST *ast);
const CppRefactoringFilePtr m_cppRefactoringFile;
const Overview &m_overview;
Overview &m_overview;
const CursorHandling m_cursorHandling;
ChangeSet m_changeSet;

View File

@@ -349,9 +349,13 @@ void CppToolsPlugin::test_format_pointerdeclaration_in_simpledeclarations_data()
<< source << stripCursor(source);
// Respect white space within operator names
QTest::newRow("operators")
QTest::newRow("operators1")
<< "class C { C@&operator = (const C &); };"
<< "class C { C & operator = (const C &); };";
QTest::newRow("operators2")
<< "C &C::operator = (const C &) {}"
<< "C & C::operator = (const C &) {}";
}
void CppToolsPlugin::test_format_pointerdeclaration_in_controlflowstatements()

View File

@@ -237,6 +237,35 @@ static int commonStringLength(const QString &s1, const QString &s2)
return length;
}
static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo,
const QStringList &candidateFileNames,
const ProjectExplorer::Project *project)
{
QString bestFileName;
int compareValue = 0;
const QString filePath = fileInfo.filePath();
foreach (const QString &candidateFileName, candidateFileNames) {
const QStringList projectFiles = findFilesInProject(candidateFileName, project);
// Find the file having the most common path with fileName
foreach (const QString &projectFile, projectFiles) {
int value = commonStringLength(filePath, projectFile);
if (value > compareValue) {
compareValue = value;
bestFileName = projectFile;
}
}
}
if (!bestFileName.isEmpty()) {
const QFileInfo candidateFi(bestFileName);
QTC_ASSERT(candidateFi.isFile(), return QString());
m_headerSourceMapping[fileInfo.absoluteFilePath()] = candidateFi.absoluteFilePath();
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fileInfo.absoluteFilePath();
return candidateFi.absoluteFilePath();
}
return QString();
}
} // namespace Internal
QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
@@ -287,29 +316,26 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
}
}
// Find files in the project
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
if (project) {
QString bestFileName;
int compareValue = 0;
foreach (const QString &candidateFileName, candidateFileNames) {
const QStringList projectFiles = findFilesInProject(candidateFileName, project);
// Find the file having the most common path with fileName
foreach (const QString &projectFile, projectFiles) {
int value = commonStringLength(fileName, projectFile);
if (value > compareValue) {
compareValue = value;
bestFileName = projectFile;
}
}
}
if (!bestFileName.isEmpty()) {
const QFileInfo candidateFi(bestFileName);
QTC_ASSERT(candidateFi.isFile(), return QString());
m_headerSourceMapping[fi.absoluteFilePath()] = candidateFi.absoluteFilePath();
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
return candidateFi.absoluteFilePath();
}
// Find files in the current project
ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject();
if (currentProject) {
const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
currentProject);
if (!path.isEmpty())
return path;
}
// Find files in other projects
CppModelManager *modelManager = CppModelManager::instance();
QList<CppModelManagerInterface::ProjectInfo> projectInfos = modelManager->projectInfos();
foreach (const CppModelManagerInterface::ProjectInfo &projectInfo, projectInfos) {
const ProjectExplorer::Project *project = projectInfo.project().data();
if (project == currentProject)
continue; // We have already checked the current project.
const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames, project);
if (!path.isEmpty())
return path;
}
return QString();