mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 07:15:39 +02:00
FIXED - bug 249177: ExtractFunction specifies void for constant types
https://bugs.eclipse.org/bugs/show_bug.cgi?id=249177
This commit is contained in:
parent
a359eb6090
commit
41f790c534
2 changed files with 283 additions and 1 deletions
|
@ -428,3 +428,261 @@ int main() {
|
|||
contains(has(c));
|
||||
}
|
||||
|
||||
//!Extract string constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=greeting
|
||||
|
||||
//@test.h
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
wchar_t greeting();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
char* hi = /*$*/"hello"/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
wchar_t Test::greeting()
|
||||
{
|
||||
return "hello";
|
||||
}
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
char* hi = greeting();
|
||||
}
|
||||
|
||||
//!Extract int constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=size
|
||||
|
||||
//@test.h
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
int size();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
int i = /*$*/42/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
int Test::size()
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
int i = size();
|
||||
}
|
||||
|
||||
//!Extract float constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=certainty
|
||||
|
||||
//@test.h
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
float certainty();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
float f = /*$*/0.42/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
float Test::certainty()
|
||||
{
|
||||
return 0.42;
|
||||
}
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
float f = certainty();
|
||||
}
|
||||
|
||||
//!Extract char constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=newline
|
||||
|
||||
//@test.h
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
char newline();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
char nl = /*$*/'\n'/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
char Test::newline()
|
||||
{
|
||||
return '\n';
|
||||
}
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
char nl = newline();
|
||||
}
|
||||
|
||||
//!Extract boolean true constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=valid
|
||||
|
||||
//@test.h
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
bool valid();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
bool b = /*$*/true/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
bool Test::valid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
bool b = valid();
|
||||
}
|
||||
|
||||
//!Extract boolean false constant
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||
|
||||
//@.config
|
||||
filename=test.cpp
|
||||
methodname=invalid
|
||||
|
||||
//@test.h
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
};
|
||||
|
||||
|
||||
//=
|
||||
class Test
|
||||
{
|
||||
void test();
|
||||
bool invalid();
|
||||
};
|
||||
|
||||
|
||||
//@test.cpp
|
||||
#include "test.h"
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
bool b = /*$*/false/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
#include "test.h"
|
||||
|
||||
bool Test::invalid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Test::test()
|
||||
{
|
||||
bool b = invalid();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||
|
@ -90,6 +91,10 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
|
|||
declSpecifier = handleFunctionCallExpression((IASTFunctionCallExpression) extractedNode);
|
||||
}
|
||||
|
||||
if (extractedNode instanceof IASTLiteralExpression) {
|
||||
declSpecifier = handleLiteralExpression((IASTLiteralExpression) extractedNode);
|
||||
}
|
||||
|
||||
if(declSpecifier == null) {
|
||||
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_void);
|
||||
}
|
||||
|
@ -97,7 +102,26 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
|
|||
return declSpecifier;
|
||||
}
|
||||
|
||||
private IASTDeclSpecifier handleNewExpression(ICPPASTNewExpression expression) {
|
||||
private IASTDeclSpecifier handleLiteralExpression(IASTLiteralExpression extractedNode) {
|
||||
switch(extractedNode.getKind()){
|
||||
case IASTLiteralExpression.lk_char_constant:
|
||||
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_char);
|
||||
case IASTLiteralExpression.lk_float_constant:
|
||||
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_float);
|
||||
case IASTLiteralExpression.lk_integer_constant:
|
||||
return createSimpleDeclSpecifier(IASTSimpleDeclSpecifier.t_int);
|
||||
case IASTLiteralExpression.lk_string_literal:
|
||||
return createSimpleDeclSpecifier(ICPPASTSimpleDeclSpecifier.t_wchar_t);
|
||||
case ICPPASTLiteralExpression.lk_false:
|
||||
//Like lk_true a boolean type
|
||||
case ICPPASTLiteralExpression.lk_true:
|
||||
return createSimpleDeclSpecifier(ICPPASTSimpleDeclSpecifier.t_bool);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IASTDeclSpecifier handleNewExpression(ICPPASTNewExpression expression) {
|
||||
return expression.getTypeId().getDeclSpecifier();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue