mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-02 13:55:39 +02:00
Bug 45203. Added more tests and fixed problems uncovered by the new
tests.
This commit is contained in:
parent
5ee378e351
commit
be62d685af
2 changed files with 48 additions and 13 deletions
|
@ -18,6 +18,8 @@ import java.util.TreeSet;
|
||||||
|
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
|
|
||||||
import com.ibm.icu.text.MessageFormat;
|
import com.ibm.icu.text.MessageFormat;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
@ -29,6 +31,8 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.parser.util.StringUtil;
|
import org.eclipse.cdt.core.parser.util.StringUtil;
|
||||||
import org.eclipse.cdt.core.testplugin.util.OneSourceMultipleHeadersTestCase;
|
import org.eclipse.cdt.core.testplugin.util.OneSourceMultipleHeadersTestCase;
|
||||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||||
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.refactoring.includes.BindingClassifier;
|
import org.eclipse.cdt.internal.ui.refactoring.includes.BindingClassifier;
|
||||||
|
@ -39,7 +43,6 @@ import org.eclipse.cdt.internal.ui.refactoring.includes.InclusionContext;
|
||||||
*/
|
*/
|
||||||
public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
private IIndex fIndex;
|
private IIndex fIndex;
|
||||||
private InclusionContext fContext;
|
|
||||||
private BindingClassifier fBindingClassifier;
|
private BindingClassifier fBindingClassifier;
|
||||||
|
|
||||||
public BindingClassifierTest() {
|
public BindingClassifierTest() {
|
||||||
|
@ -57,23 +60,38 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
fIndex = CCorePlugin.getIndexManager().getIndex(getCProject(),
|
fIndex = CCorePlugin.getIndexManager().getIndex(getCProject(),
|
||||||
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_EXTENSION_FRAGMENTS_ADD_IMPORT);
|
IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_EXTENSION_FRAGMENTS_ADD_IMPORT);
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
ITranslationUnit tu = ast.getOriginatingTranslationUnit();
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
fContext = new InclusionContext(tu, fIndex);
|
preferenceStore.setToDefault(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS);
|
||||||
fBindingClassifier = new BindingClassifier(fContext);
|
}
|
||||||
fBindingClassifier.classifyNodeContents(ast);
|
|
||||||
|
private void classifyBindings() {
|
||||||
|
if (fBindingClassifier == null) {
|
||||||
|
IASTTranslationUnit ast = getAst();
|
||||||
|
ITranslationUnit tu = ast.getOriginatingTranslationUnit();
|
||||||
|
InclusionContext context = new InclusionContext(tu, fIndex);
|
||||||
|
fBindingClassifier = new BindingClassifier(context);
|
||||||
|
fBindingClassifier.classifyNodeContents(ast);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
fIndex.releaseReadLock();
|
fIndex.releaseReadLock();
|
||||||
|
fBindingClassifier = null;
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IPreferenceStore getPreferenceStore() {
|
||||||
|
return CUIPlugin.getDefault().getPreferenceStore();
|
||||||
|
}
|
||||||
|
|
||||||
private void assertDefined(String... names) {
|
private void assertDefined(String... names) {
|
||||||
|
classifyBindings();
|
||||||
assertExpectedBindings(names, fBindingClassifier.getBindingsToDefine(), "defined");
|
assertExpectedBindings(names, fBindingClassifier.getBindingsToDefine(), "defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertDeclared(String... names) {
|
private void assertDeclared(String... names) {
|
||||||
|
classifyBindings();
|
||||||
assertExpectedBindings(names, fBindingClassifier.getBindingsToDeclare(), "declared");
|
assertExpectedBindings(names, fBindingClassifier.getBindingsToDeclare(), "declared");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +187,19 @@ public class BindingClassifierTest extends OneSourceMultipleHeadersTestCase {
|
||||||
assertDeclared();
|
assertDeclared();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// class A {};
|
||||||
|
// void f(const A* p);
|
||||||
|
|
||||||
|
// void test(A* a) {
|
||||||
|
// f(a);
|
||||||
|
// }
|
||||||
|
public void testFunctionCall() throws Exception {
|
||||||
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
|
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
|
||||||
|
assertDefined();
|
||||||
|
assertDeclared("f", "A");
|
||||||
|
}
|
||||||
|
|
||||||
// struct A {};
|
// struct A {};
|
||||||
// struct B {};
|
// struct B {};
|
||||||
|
|
||||||
|
|
|
@ -155,21 +155,25 @@ public class BindingClassifier {
|
||||||
private void processParameters(IParameter[] declaredParameters, IASTInitializerClause[] arguments) {
|
private void processParameters(IParameter[] declaredParameters, IASTInitializerClause[] arguments) {
|
||||||
for (int i = 0; i < declaredParameters.length; i++) {
|
for (int i = 0; i < declaredParameters.length; i++) {
|
||||||
IType declaredParameterType = declaredParameters[i].getType();
|
IType declaredParameterType = declaredParameters[i].getType();
|
||||||
IType actualParameterType = null;
|
IType argumentType = null;
|
||||||
boolean canBeDeclared = false;
|
boolean canBeDeclared = false;
|
||||||
if (declaredParameterType instanceof IPointerType || declaredParameterType instanceof ICPPReferenceType) {
|
if (declaredParameterType instanceof IPointerType || declaredParameterType instanceof ICPPReferenceType) {
|
||||||
// The declared parameter type is a pointer or reference type. A declaration is
|
// The declared parameter type is a pointer or reference type. A declaration is
|
||||||
// sufficient if it matches the actual parameter type.
|
// sufficient if it matches the actual parameter type.
|
||||||
declaredParameterType = getNestedType(declaredParameterType, REF);
|
declaredParameterType = getNestedType(declaredParameterType, REF | ALLCVQ);
|
||||||
if (i < arguments.length) {
|
if (i < arguments.length) {
|
||||||
// This parameter is present within the function call expression.
|
// This parameter is present within the function call expression.
|
||||||
// It's therefore not a default parameter.
|
// It's therefore not a default parameter.
|
||||||
IASTInitializerClause actualParameter = arguments[i];
|
IASTInitializerClause argument = arguments[i];
|
||||||
if (actualParameter instanceof IASTExpression) {
|
if (argument instanceof IASTExpression) {
|
||||||
actualParameterType = ((IASTExpression) actualParameter).getExpressionType();
|
argumentType = ((IASTExpression) argument).getExpressionType();
|
||||||
actualParameterType = getNestedType(actualParameterType, REF);
|
argumentType = getNestedType(argumentType, REF | ALLCVQ);
|
||||||
|
|
||||||
if (isSameType(declaredParameterType, actualParameterType)) {
|
if (declaredParameterType instanceof IPointerType && argumentType instanceof IPointerType) {
|
||||||
|
declaredParameterType = getNestedType(((IPointerType) declaredParameterType).getType(), ALLCVQ);
|
||||||
|
argumentType = getNestedType(((IPointerType) argumentType).getType(), ALLCVQ);
|
||||||
|
}
|
||||||
|
if (isSameType(declaredParameterType, argumentType)) {
|
||||||
canBeDeclared = true;
|
canBeDeclared = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +192,7 @@ public class BindingClassifier {
|
||||||
// Both the type of the declared parameter as well as the type of the actual
|
// Both the type of the declared parameter as well as the type of the actual
|
||||||
// parameter require a full definition.
|
// parameter require a full definition.
|
||||||
defineTypeExceptTypedefOrNonFixedEnum(declaredParameterType);
|
defineTypeExceptTypedefOrNonFixedEnum(declaredParameterType);
|
||||||
defineTypeExceptTypedefOrNonFixedEnum(actualParameterType);
|
defineTypeExceptTypedefOrNonFixedEnum(argumentType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue