summaryrefslogtreecommitdiff
path: root/lib/Tooling
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-11-01 00:20:55 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-11-01 00:20:55 +0000
commit06b063e3bbf2ce05d25770a4c77cf1b748ce198c (patch)
tree8af8956f508641ac75680b71bb07738688467755 /lib/Tooling
parent3d102c8ddd12ab268a8484ee21f828ef5cd8f2c9 (diff)
downloadclang-06b063e3bbf2ce05d25770a4c77cf1b748ce198c.tar.gz
[refactor][extract] prohibit extraction of ObjC property setters
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317056 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling')
-rw-r--r--lib/Tooling/Refactoring/Extract.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/Tooling/Refactoring/Extract.cpp b/lib/Tooling/Refactoring/Extract.cpp
index b1000b60ee..e81bb3ffe9 100644
--- a/lib/Tooling/Refactoring/Extract.cpp
+++ b/lib/Tooling/Refactoring/Extract.cpp
@@ -16,6 +16,7 @@
#include "clang/Tooling/Refactoring/Extract/Extract.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Expr.h"
+#include "clang/AST/ExprObjC.h"
#include "clang/Rewrite/Core/Rewriter.h"
namespace clang {
@@ -70,12 +71,20 @@ ExtractFunction::initiate(RefactoringRuleContext &Context,
return Context.createDiagnosticError(
diag::err_refactor_code_outside_of_function);
- // Avoid extraction of simple literals and references.
- if (Code.size() == 1 && isSimpleExpression(dyn_cast<Expr>(Code[0])))
- return Context.createDiagnosticError(
- diag::err_refactor_extract_simple_expression);
+ if (Code.size() == 1) {
+ // Avoid extraction of simple literals and references.
+ if (isSimpleExpression(dyn_cast<Expr>(Code[0])))
+ return Context.createDiagnosticError(
+ diag::err_refactor_extract_simple_expression);
+
+ // Property setters can't be extracted.
+ if (const auto *PRE = dyn_cast<ObjCPropertyRefExpr>(Code[0])) {
+ if (!PRE->isMessagingGetter())
+ return Context.createDiagnosticError(
+ diag::err_refactor_extract_prohibited_expression);
+ }
+ }
- // FIXME (Alex L): Prohibit extraction of Objective-C property setters.
return ExtractFunction(std::move(Code), DeclName);
}