diff options
author | Alex Lorenz <arphaman@gmail.com> | 2017-11-01 00:20:55 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2017-11-01 00:20:55 +0000 |
commit | 1e416fe23df4750fe79c717357c427b2ecb09cf0 (patch) | |
tree | 700610d922291520b874f3d3aeefc9f44cb2cb7e /clang/lib/Tooling/Refactoring/Extract.cpp | |
parent | cde781015f21252d5fec3185e1e372ca1f73078a (diff) | |
download | bcm5719-llvm-1e416fe23df4750fe79c717357c427b2ecb09cf0.tar.gz bcm5719-llvm-1e416fe23df4750fe79c717357c427b2ecb09cf0.zip |
[refactor][extract] prohibit extraction of ObjC property setters
llvm-svn: 317056
Diffstat (limited to 'clang/lib/Tooling/Refactoring/Extract.cpp')
-rw-r--r-- | clang/lib/Tooling/Refactoring/Extract.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/Tooling/Refactoring/Extract.cpp b/clang/lib/Tooling/Refactoring/Extract.cpp index b1000b60ee0..e81bb3ffe9b 100644 --- a/clang/lib/Tooling/Refactoring/Extract.cpp +++ b/clang/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); } |