summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/cppeditor/cppeditor.cpp18
-rw-r--r--src/plugins/cpptools/cpptoolsreuse.cpp54
-rw-r--r--src/plugins/cpptools/cpptoolsreuse.h8
3 files changed, 75 insertions, 5 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index d1b665b8fe..8b6a0fb4c9 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -68,6 +68,7 @@
#include <cpptools/cppqtstyleindenter.h>
#include <cpptools/cppcodestylesettings.h>
#include <cpptools/cpprefactoringchanges.h>
+#include <cpptools/cpptoolsreuse.h>
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
@@ -1776,6 +1777,11 @@ void CPPEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo)
m_renameSelections.clear();
m_currentRenameSelection = NoCurrentRenameSelection;
+ // We can use the semanticInfo's snapshot (and avoid locking), but not its
+ // document, since it doesn't contain expanded macros.
+ LookupContext context(semanticInfo.snapshot.document(file()->fileName()),
+ semanticInfo.snapshot);
+
SemanticInfo::LocalUseIterator it(semanticInfo.localUses);
while (it.hasNext()) {
it.next();
@@ -1791,12 +1797,14 @@ void CPPEditorWidget::updateSemanticInfo(const SemanticInfo &semanticInfo)
}
}
- if (uses.size() == 1)
- // it's an unused declaration
- highlightUses(uses, semanticInfo, &unusedSelections);
-
- else if (good && m_renameSelections.isEmpty())
+ if (uses.size() == 1) {
+ if (!CppTools::isOwnershipRAIIType(it.key(), context)) {
+ // it's an unused declaration
+ highlightUses(uses, semanticInfo, &unusedSelections);
+ }
+ } else if (good && m_renameSelections.isEmpty()) {
highlightUses(uses, semanticInfo, &m_renameSelections);
+ }
}
if (m_lastSemanticInfo.forced || previousSemanticInfo.revision != semanticInfo.revision) {
diff --git a/src/plugins/cpptools/cpptoolsreuse.cpp b/src/plugins/cpptools/cpptoolsreuse.cpp
index ec1903c7a5..27b09656e7 100644
--- a/src/plugins/cpptools/cpptoolsreuse.cpp
+++ b/src/plugins/cpptools/cpptoolsreuse.cpp
@@ -32,9 +32,17 @@
#include "cpptoolsreuse.h"
+#include <Symbols.h>
+#include <CoreTypes.h>
+#include <cplusplus/Overview.h>
+#include <cplusplus/LookupContext.h>
+
+#include <QtCore/QSet>
#include <QtGui/QTextDocument>
#include <QtGui/QTextCursor>
+using namespace CPlusPlus;
+
namespace CppTools {
void moveCursorToEndOfIdentifier(QTextCursor *tc) {
@@ -49,4 +57,50 @@ void moveCursorToEndOfIdentifier(QTextCursor *tc) {
}
}
+static bool isOwnershipRAIIName(const QString &name)
+{
+ static QSet<QString> knownNames;
+ if (knownNames.isEmpty()) {
+ // Qt
+ knownNames.insert(QLatin1String("QScopedPointer"));
+ knownNames.insert(QLatin1String("QScopedArrayPointer"));
+ knownNames.insert(QLatin1String("QMutexLocker"));
+ knownNames.insert(QLatin1String("QReadLocker"));
+ knownNames.insert(QLatin1String("QWriteLocker"));
+ // Standard C++
+ knownNames.insert(QLatin1String("auto_ptr"));
+ knownNames.insert(QLatin1String("unique_ptr"));
+ // Boost
+ knownNames.insert(QLatin1String("scoped_ptr"));
+ knownNames.insert(QLatin1String("scoped_array"));
+ }
+
+ return knownNames.contains(name);
+}
+
+bool isOwnershipRAIIType(CPlusPlus::Symbol *symbol, const LookupContext &context)
+{
+ if (!symbol)
+ return false;
+
+ // This is not a "real" comparison of types. What we do is to resolve the symbol
+ // in question and then try to match its name with already known ones.
+ if (symbol->isDeclaration()) {
+ Declaration *declaration = symbol->asDeclaration();
+ const NamedType *namedType = declaration->type()->asNamedType();
+ if (namedType) {
+ ClassOrNamespace *clazz = context.lookupType(namedType->name(),
+ declaration->enclosingScope());
+ if (clazz && !clazz->symbols().isEmpty()) {
+ Overview overview;
+ Symbol *symbol = clazz->symbols().at(0);
+ return isOwnershipRAIIName(overview.prettyName(symbol->name()));
+ }
+ }
+ }
+
+ return false;
+}
+
+
} // CppTools
diff --git a/src/plugins/cpptools/cpptoolsreuse.h b/src/plugins/cpptools/cpptoolsreuse.h
index a82520754c..a290905bda 100644
--- a/src/plugins/cpptools/cpptoolsreuse.h
+++ b/src/plugins/cpptools/cpptoolsreuse.h
@@ -37,10 +37,18 @@
QT_FORWARD_DECLARE_CLASS(QTextCursor)
+namespace CPlusPlus {
+class Symbol;
+class LookupContext;
+}
+
namespace CppTools {
void CPPTOOLS_EXPORT moveCursorToEndOfIdentifier(QTextCursor *tc);
+bool CPPTOOLS_EXPORT isOwnershipRAIIType(CPlusPlus::Symbol *symbol,
+ const CPlusPlus::LookupContext &context);
+
} // CppTools
#endif // CPPTOOLSREUSE_H