Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-03-12 09:56:10 +0000
committerMarkus Schorn2008-03-12 09:56:10 +0000
commit73869d3e94e3e20573c56bbc79546394d43f8102 (patch)
tree54be2da282b4c8cc25bf8d8050a456562e195fa6 /core/org.eclipse.cdt.ui.tests
parent8c518b15d3b3b2b2bdad398da896e8b3495fc7c0 (diff)
downloadorg.eclipse.cdt-73869d3e94e3e20573c56bbc79546394d43f8102.tar.gz
org.eclipse.cdt-73869d3e94e3e20573c56bbc79546394d43f8102.tar.xz
org.eclipse.cdt-73869d3e94e3e20573c56bbc79546394d43f8102.zip
Reworked refactoring: moved rename refactoring into ui-plugin (bug 220741), applied patch for extract constant (bug 181493).
Diffstat (limited to 'core/org.eclipse.cdt.ui.tests')
-rw-r--r--core/org.eclipse.cdt.ui.tests/.classpath2
-rw-r--r--core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs11
-rw-r--r--core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF5
-rw-r--r--core/org.eclipse.cdt.ui.tests/plugin.xml17
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts370
-rw-r--r--core/org.eclipse.cdt.ui.tests/resources/refactoring/TranslationunitHelper.rts35
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java12
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/Messages.java33
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java116
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java150
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java34
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTester.java216
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java20
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java88
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantRefactoringTest.java64
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/messages.properties8
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RefactoringTests.java268
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameFunctionTests.java819
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java223
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java1263
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTemplatesTests.java67
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTests.java119
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java2298
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameVariableTests.java1999
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/TestRenameParticipant.java65
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/CorrectCaseTest.java86
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DigitFirstCaseTest.java47
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/EmptyCaseTest.java38
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java36
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IllegalCharCaseTest.java47
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/KeywordCaseTest.java164
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/TranslationUnitHelperTest.java51
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java31
33 files changed, 8787 insertions, 15 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/.classpath b/core/org.eclipse.cdt.ui.tests/.classpath
index b0a17ea7314..e2fea57c451 100644
--- a/core/org.eclipse.cdt.ui.tests/.classpath
+++ b/core/org.eclipse.cdt.ui.tests/.classpath
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="ui"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs b/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs
index f9b0a2ca0a4..684bece864b 100644
--- a/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs
+++ b/core/org.eclipse.cdt.ui.tests/.settings/org.eclipse.jdt.core.prefs
@@ -1,9 +1,9 @@
-#Fri Feb 15 10:15:35 CET 2008
+#Wed Feb 27 13:20:15 CET 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -16,7 +16,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
@@ -79,7 +79,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.4
+org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
@@ -151,7 +151,6 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
org.eclipse.jdt.core.formatter.indentation.size=4
-org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
diff --git a/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF
index e577675c810..0ae4b96ec9f 100644
--- a/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@ Export-Package: org.eclipse.cdt.ui.testplugin,
org.eclipse.cdt.ui.tests,
org.eclipse.cdt.ui.tests.DOMAST,
org.eclipse.cdt.ui.tests.chelp,
+ org.eclipse.cdt.ui.tests.refactoring.rename,
org.eclipse.cdt.ui.tests.text,
org.eclipse.cdt.ui.tests.text.contentassist,
org.eclipse.cdt.ui.tests.text.selection
@@ -33,7 +34,7 @@ Require-Bundle: org.eclipse.jface.text,
org.eclipse.core.expressions,
org.eclipse.cdt.make.core,
com.ibm.icu,
- org.eclipse.cdt.refactoring.tests
+ org.eclipse.ltk.core.refactoring;bundle-version="3.4.0"
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Eclipse.org
-Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/core/org.eclipse.cdt.ui.tests/plugin.xml b/core/org.eclipse.cdt.ui.tests/plugin.xml
index 72140c1c76f..8a98421c5b1 100644
--- a/core/org.eclipse.cdt.ui.tests/plugin.xml
+++ b/core/org.eclipse.cdt.ui.tests/plugin.xml
@@ -198,4 +198,21 @@
</owner>
</extension>
+ <extension point="org.eclipse.ltk.core.refactoring.renameParticipants">
+ <renameParticipant
+ class="org.eclipse.cdt.ui.tests.refactoring.rename.TestRenameParticipant"
+ name="TestRenameParticipant"
+ id="org.eclipse.cdt.ui.tests.TestRenameParticipant">
+ <enablement>
+ <with variable="affectedNatures">
+ <iterate operator="or">
+ <equals value="org.eclipse.cdt.core.cnature"/>
+ </iterate>
+ </with>
+ <with variable="element">
+ <instanceof value="org.eclipse.cdt.core.dom.ast.IBinding"/>
+ </with>
+ </enablement>
+ </renameParticipant>
+ </extension>
</plugin>
diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts
new file mode 100644
index 00000000000..e1a000aa607
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractConstant.rts
@@ -0,0 +1,370 @@
+//!ExtractConstantInt
+//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
+//@A.h
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ int foo();
+ void bar();
+};
+
+#endif /*A_H_*/
+
+
+//=
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ int foo();
+ void bar();
+ static const int theAnswer = 42;
+};
+
+#endif /*A_H_*/
+
+
+//@A.cpp
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+int A::foo()
+{
+ return //$42$//;
+}
+
+void A::bar()
+{
+ int a = 42;
+ int b = 42;
+}
+
+//=
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+int A::foo()
+{
+ return theAnswer;
+}
+
+void A::bar()
+{
+ int a = theAnswer;
+ int b = theAnswer;
+}
+
+//!ExtractConstantFloat
+//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
+//@A.h
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ float foo();
+ void bar();
+};
+
+#endif /*A_H_*/
+
+
+//=
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ float foo();
+ void bar();
+ static const float theAnswer = 42.0;
+};
+
+#endif /*A_H_*/
+
+
+//@A.cpp
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+float A::foo()
+{
+ return //$42.0$//;
+}
+
+void A::bar()
+{
+ float a = 42.0;
+ float b = 42.0;
+}
+
+//=
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+float A::foo()
+{
+ return theAnswer;
+}
+
+void A::bar()
+{
+ float a = theAnswer;
+ float b = theAnswer;
+}
+
+//!ExtractConstantStaticInt
+//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
+//@A.h
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ int foo();
+ static const int a = 42;
+};
+
+#endif /*A_H_*/
+
+//=
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ int foo();
+ static const int a = 42;
+};
+
+#endif /*A_H_*/
+
+//@A.cpp
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+int A::foo()
+{
+ return 42;
+}
+
+int bar()
+{
+ return //$42$//;
+}
+
+
+//=
+#include "A.h"
+
+namespace
+{
+ const int theAnswer = 42;
+}
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+int A::foo()
+{
+ return theAnswer;
+}
+
+int bar()
+{
+ return theAnswer;
+}
+
+
+//!replaceNumberProtected
+//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
+//@.config
+visibility=protected
+//@A.h
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ int foo();
+};
+
+#endif /*A_H_*/
+
+//=
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ int foo();
+protected:
+ static const int theAnswer = 42;
+};
+
+#endif /*A_H_*/
+
+//@A.cpp
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+int A::foo()
+{
+ return //$42$//;
+}
+
+//=
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+int A::foo()
+{
+ return theAnswer;
+}
+
+//!replaceNumberPrivate
+//#org.eclipse.cdt.ui.tests.refactoring.extractconstant.ExtractConstantRefactoringTest
+//@.config
+visibility=private
+//@A.h
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ int foo();
+};
+
+#endif /*A_H_*/
+
+//=
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ virtual ~A();
+ int foo();
+private:
+ static const int theAnswer = 42;
+};
+
+#endif /*A_H_*/
+
+//@A.cpp
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+int A::foo()
+{
+ return //$42$//;
+}
+
+//=
+#include "A.h"
+
+A::A()
+{
+}
+
+A::~A()
+{
+}
+
+int A::foo()
+{
+ return theAnswer;
+}
+
diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/TranslationunitHelper.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/TranslationunitHelper.rts
new file mode 100644
index 00000000000..a277b9e4566
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/TranslationunitHelper.rts
@@ -0,0 +1,35 @@
+//!before the class
+//#org.eclipse.cdt.ui.tests.refactoring.utils.TranslationUnitHelperTest
+//@.config
+filename=A.h
+offset_unix=27
+offset_win=30
+//@A.h
+#ifndef A_H_
+#define A_H_
+
+class A
+{
+public:
+ A();
+ void foo();
+};
+
+#endif /*A_H_*/
+
+
+//!before a typedef
+//#org.eclipse.cdt.ui.tests.refactoring.utils.TranslationUnitHelperTest
+//@.config
+filename=A.h
+offset_unix=0
+offset_win=0
+//@A.h
+typedef int nummere;
+
+class A
+{
+public:
+ A();
+};
+
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java
index 892c9f4b79e..98da9377358 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java
@@ -15,10 +15,10 @@ package org.eclipse.cdt.ui.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.cdt.refactoring.tests.RenameRegressionTests;
import org.eclipse.cdt.ui.tests.buildconsole.BuildConsoleTests;
import org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyTestSuite;
import org.eclipse.cdt.ui.tests.includebrowser.IncludeBrowserTestSuite;
+import org.eclipse.cdt.ui.tests.refactoring.RefactoringTestSuite;
import org.eclipse.cdt.ui.tests.search.SearchTestSuite;
import org.eclipse.cdt.ui.tests.text.TextTestSuite;
import org.eclipse.cdt.ui.tests.text.contentassist.ContentAssistTestSuite;
@@ -36,14 +36,14 @@ public class AutomatedSuite extends TestSuite {
* Returns the suite. This is required to
* use the JUnit Launcher.
*/
- public static Test suite() {
+ public static Test suite() throws Exception {
return new AutomatedSuite();
}
/**
* Construct the test suite.
*/
- public AutomatedSuite() {
+ public AutomatedSuite() throws Exception {
// tests from package org.eclipse.cdt.ui.tests.text
addTest(TextTestSuite.suite());
@@ -65,9 +65,6 @@ public class AutomatedSuite extends TestSuite {
// tests from package org.eclipse.cdt.ui.tests.text.contentAssist2
addTest(ContentAssist2TestSuite.suite());
-
- // tests from the refactoring plugin
- addTest(RenameRegressionTests.suite());
// tests from package org.eclipse.cdt.ui.tests.text.selection
addTest(SelectionTestSuite.suite());
@@ -77,6 +74,9 @@ public class AutomatedSuite extends TestSuite {
// tests from package org.eclipse.cdt.ui.tests.search
addTest(SearchTestSuite.suite());
+
+ // tests from package org.eclipse.cdt.ui.tests.refactoring
+ addTest(RefactoringTestSuite.suite());
}
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/Messages.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/Messages.java
new file mode 100644
index 00000000000..85863e7c112
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/Messages.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.tests.refactoring.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java
new file mode 100644
index 00000000000..f705bc44d3c
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringBaseTest.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import org.eclipse.cdt.core.tests.BaseTestFramework;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.TextSelection;
+
+/**
+ * @author Guido Zgraggen IFS
+ *
+ */
+public abstract class RefactoringBaseTest extends BaseTestFramework implements ILogListener{
+ protected static final NullProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor();
+
+ protected TreeMap<String, TestSourceFile> fileMap = new TreeMap<String, TestSourceFile>();
+ protected String fileWithSelection;
+ protected TextSelection selection;
+
+ protected RefactoringBaseTest(String name) {
+ super(name);
+ }
+
+ public RefactoringBaseTest(String name, Vector<TestSourceFile> files) {
+ super(name);
+ for (TestSourceFile file : files) {
+ fileMap.put(file.getName(), file);
+ }
+ }
+
+ @Override
+ protected abstract void runTest() throws Throwable;
+
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ for (TestSourceFile testFile : fileMap.values()) {
+ if(testFile.getSource().length() > 0) {
+ importFile(testFile.getName(), testFile.getSource());
+ }
+ }
+ }
+
+ protected void assertEquals(TestSourceFile file, IFile file2) throws Exception {
+ StringBuffer code = getCodeFromIFile(file2);
+ assertEquals(file.getExpectedSource(), TestHelper.unifyNewLines(code.toString()));
+ }
+
+ protected void compareFiles(Map<String,TestSourceFile> testResourceFiles) throws Exception {
+ for (String fileName : testResourceFiles.keySet()) {
+ TestSourceFile file = testResourceFiles.get(fileName);
+ IFile iFile = project.getFile(new Path(fileName));
+ StringBuffer code = getCodeFromIFile(iFile);
+ assertEquals(TestHelper.unifyNewLines(file.getExpectedSource()), TestHelper.unifyNewLines(code.toString()));
+ }
+ }
+
+ protected StringBuffer getCodeFromIFile(IFile file) throws Exception {
+ BufferedReader br = new BufferedReader(new InputStreamReader(file.getContents()));
+ StringBuffer code = new StringBuffer();
+ String line;
+ while((line = br.readLine()) != null) {
+ code.append(line);
+ code.append('\n');
+ }
+ br.close();
+ return code;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ System.gc();
+ fileManager.closeAllFiles();
+ super.tearDown();
+ }
+
+ public void logging(IStatus status, String plugin) {
+ Throwable ex = status.getException();
+ StringBuffer stackTrace = new StringBuffer();
+ if(ex != null) {
+ stackTrace.append('\n');
+ for(StackTraceElement ste : ex.getStackTrace()) {
+ stackTrace.append(ste.toString());
+ }
+ }
+ fail("Log-Message: " + status.getMessage() + stackTrace.toString()); //$NON-NLS-1$
+ }
+
+ public void setFileWithSelection(String fileWithSelection) {
+ this.fileWithSelection = fileWithSelection;
+ }
+
+ public void setSelection(TextSelection selection) {
+ this.selection = selection;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java
new file mode 100644
index 00000000000..7523d81fc19
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTest.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.IPDOMManager;
+import org.eclipse.cdt.core.index.IIndexManager;
+import org.eclipse.cdt.ui.testplugin.CTestPlugin;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public abstract class RefactoringTest extends RefactoringBaseTest {
+
+ private static final String CONFIG_FILE_NAME = ".config"; //$NON-NLS-1$
+
+ protected String fileName;
+
+ public RefactoringTest(String name, Vector<TestSourceFile> files) {
+ super(name, files);
+ initializeConfiguration(files);
+ for (TestSourceFile file : files) {
+ fileMap.put(file.getName(), file);
+ }
+ }
+
+ protected abstract void configureRefactoring(Properties refactoringProperties);
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
+ CTestPlugin.getDefault().getLog().addLogListener(this);
+ CCorePlugin.getIndexManager().reindex(cproject);
+ boolean joined = CCorePlugin.getIndexManager().joinIndexer(IIndexManager.FOREVER, NULL_PROGRESS_MONITOR);
+ assertTrue(joined);
+ }
+
+ private void initializeConfiguration(Vector<TestSourceFile> files) {
+ TestSourceFile configFile = null;
+
+ for (TestSourceFile currentFile : files) {
+ if (currentFile.getName().equals(CONFIG_FILE_NAME)) {
+ configFile = currentFile;
+ }
+ }
+
+ Properties refactoringProperties = new Properties();
+
+ try {
+ if(configFile != null) {
+ refactoringProperties.load(new ByteArrayInputStream(configFile.getSource().getBytes()));
+ }
+ } catch (IOException e) {
+ // Property initialization failed
+ }
+
+ initCommonFields(refactoringProperties);
+ configureRefactoring(refactoringProperties);
+ files.remove(configFile);
+
+ }
+
+ private void initCommonFields(Properties refactoringProperties) {
+ fileName = refactoringProperties.getProperty("filename", "A.cpp"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ protected void assertConditionsOk(RefactoringStatus conditions) {
+ assertTrue(conditions.isOK() ? "OK" : "Error or Warning in initial Conditions: " + conditions.getEntries()[0].getMessage() //$NON-NLS-1$ //$NON-NLS-2$
+ , conditions.isOK());
+ }
+
+ protected void assertConditionsWarning(RefactoringStatus conditions, int number) {
+ if (number > 0) {
+ assertTrue("Warning in Condition expected", conditions.hasWarning()); //$NON-NLS-1$
+ }
+ RefactoringStatusEntry[] entries = conditions.getEntries();
+ int count = 0;
+ for (RefactoringStatusEntry entry : entries) {
+ if (entry.isWarning()) {
+ ++count;
+ }
+ }
+ assertEquals(number + " Warnings expected found " + count, count, number); //$NON-NLS-1$
+ }
+
+ protected void assertConditionsInfo(RefactoringStatus status, int number) {
+ if (number > 0) {
+ assertTrue("Info in Condition expected", status.hasInfo()); //$NON-NLS-1$
+ }
+ RefactoringStatusEntry[] entries = status.getEntries();
+ int count = 0;
+ for (RefactoringStatusEntry entry : entries) {
+ if (entry.isInfo()) {
+ ++count;
+ }
+ }
+ assertEquals(number + " Infos expected found " + count, number, count); //$NON-NLS-1$
+ }
+
+ protected void assertConditionsError(RefactoringStatus status, int number) {
+ if (number > 0) {
+ assertTrue("Error in Condition expected", status.hasError()); //$NON-NLS-1$
+ }
+ RefactoringStatusEntry[] entries = status.getEntries();
+ int count = 0;
+ for (RefactoringStatusEntry entry : entries) {
+ if (entry.isError()) {
+ ++count;
+ }
+ }
+ assertEquals(number + " Errors expected found " + count, number, count); //$NON-NLS-1$
+ }
+
+ protected void assertConditionsFatalError(RefactoringStatus status, int number) {
+ if (number > 0) {
+ assertTrue("Fatal Error in Condition expected", status.hasFatalError()); //$NON-NLS-1$
+ }
+ RefactoringStatusEntry[] entries = status.getEntries();
+ int count = 0;
+ for (RefactoringStatusEntry entry : entries) {
+ if (entry.isFatalError()) {
+ ++count;
+ }
+ }
+ assertEquals(number + " Fatal Errors expected found " + count, number, count); //$NON-NLS-1$
+ }
+
+ protected void assertConditionsFatalError(RefactoringStatus conditions) {
+ assertTrue("Fatal Error in Condition expected", conditions.hasFatalError()); //$NON-NLS-1$
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java
new file mode 100644
index 00000000000..7a3fbf47520
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTestSuite.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.ui.tests.refactoring.rename.RenameRegressionTests;
+import org.eclipse.cdt.ui.tests.refactoring.utils.UtilTestSuite;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class RefactoringTestSuite extends TestSuite {
+
+ public static Test suite() throws Exception {
+ TestSuite suite = new RefactoringTestSuite();
+ suite.addTest(RenameRegressionTests.suite());
+ suite.addTest(RefactoringTester.suite("ExtractConstantRefactoringTests", "resources/refactoring/ExtractConstant.rts"));
+ suite.addTest(UtilTestSuite.suite());
+ return suite;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTester.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTester.java
new file mode 100644
index 00000000000..203a704bc00
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/RefactoringTester.java
@@ -0,0 +1,216 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.TextSelection;
+import org.osgi.framework.Bundle;
+
+import org.eclipse.cdt.ui.testplugin.CTestPlugin;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class RefactoringTester extends TestSuite{
+
+ enum MatcherState{skip, inTest, inSource, inExpectedResult}
+
+ private static final String classRegexp = "//#(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
+ private static final String testRegexp = "//!(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
+ private static final String fileRegexp = "//@(.*)\\s*(\\w*)*$"; //$NON-NLS-1$
+ private static final String resultRegexp = "//=.*$"; //$NON-NLS-1$
+
+ public static Test suite(String name, String file)throws Exception {
+ BufferedReader in = createReader(file);
+
+ ArrayList<RefactoringBaseTest> testCases = createTests(in);
+ in.close();
+ return createSuite(testCases, name);
+ }
+
+ protected static BufferedReader createReader(String file) throws IOException {
+ Bundle bundle = CTestPlugin.getDefault().getBundle();
+ Path path = new Path(file);
+ String file2 = FileLocator.toFileURL(FileLocator.find(bundle, path, null)).getFile();
+ return new BufferedReader(new FileReader(file2));
+ }
+
+ private static ArrayList<RefactoringBaseTest> createTests(BufferedReader inputReader) throws Exception {
+
+ String line;
+ Vector<TestSourceFile> files = new Vector<TestSourceFile>();
+ TestSourceFile actFile = null;
+ MatcherState matcherState = MatcherState.skip;
+ ArrayList<RefactoringBaseTest> testCases = new ArrayList<RefactoringBaseTest>();
+ String testName = null;
+ String className = null;
+ boolean bevorFirstTest = true;
+
+ while ((line = inputReader.readLine()) != null){
+
+ if(lineMatchesBeginOfTest(line)) {
+ if(!bevorFirstTest) {
+ RefactoringBaseTest test = createTestClass(className, testName, files);
+ testCases.add(test);
+ files = new Vector<TestSourceFile>();
+ className = null;
+ testName = null;
+ }
+ matcherState = MatcherState.inTest;
+ testName = getNameOfTest(line);
+ bevorFirstTest = false;
+ continue;
+ } else if (lineMatchesBeginOfResult(line)) {
+ matcherState = MatcherState.inExpectedResult;
+ continue;
+ }else if (lineMatchesFileName(line)) {
+ matcherState = MatcherState.inSource;
+ actFile = new TestSourceFile(getFileName(line));
+ files.add(actFile);
+ continue;
+ }else if(lineMatchesClassName(line)) {
+ className = getNameOfClass(line);
+ continue;
+ }
+
+ switch(matcherState) {
+ case inSource:
+ if(actFile != null) {
+ actFile.addLineToSource(line);
+ }
+ break;
+ case inExpectedResult:
+ if(actFile != null) {
+ actFile.addLineToExpectedSource(line);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ RefactoringBaseTest test = createTestClass(className, testName, files);
+ testCases.add(test);
+ return testCases;
+ }
+
+
+
+ private static RefactoringBaseTest createTestClass(String className, String testName, Vector<TestSourceFile> files) throws Exception {
+
+
+ try {
+ Class<?> refClass = Class.forName(className);
+ Class<?> paratypes[] = new Class[2];
+ paratypes[0] = testName.getClass();
+ paratypes[1] = files.getClass();
+ Constructor<?> ct = refClass.getConstructor(paratypes);
+ Object arglist[] = new Object[2];
+ arglist[0] = testName;
+ arglist[1] = files;
+ RefactoringBaseTest test = (RefactoringBaseTest) ct.newInstance(arglist);
+ for (TestSourceFile file : files) {
+ TextSelection sel = file.getSelection();
+ if(sel != null) {
+ test.setFileWithSelection(file.getName());
+ test.setSelection(sel);
+ break;
+ }
+ }
+ return test;
+ } catch (ClassNotFoundException e) {
+ throw new Exception(Messages.getString("RefactoringTester.UnknownTestClass")); //$NON-NLS-1$
+ } catch (SecurityException e) {
+ throw new Exception(Messages.getString("RefactoringTester.SecurityException"), e); //$NON-NLS-1$
+ } catch (NoSuchMethodException e) {
+ throw new Exception(Messages.getString("RefactoringTester.ConstructorError")); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ throw new Exception(Messages.getString("RefactoringTester.IllegalArgument"), e); //$NON-NLS-1$
+ } catch (InstantiationException e) {
+ throw new Exception(Messages.getString("RefactoringTester.InstantiationException"), e); //$NON-NLS-1$
+ } catch (IllegalAccessException e) {
+ throw new Exception(Messages.getString("RefactoringTester.IllegalAccessException"), e); //$NON-NLS-1$
+ } catch (InvocationTargetException e) {
+ throw new Exception(Messages.getString("RefactoringTester.InvocationTargetException"), e); //$NON-NLS-1$
+ }
+ }
+
+ private static String getFileName(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(fileRegexp, line);
+ if(matcherBeginOfTest.find())
+ return matcherBeginOfTest.group(1);
+ else
+ return null;
+ }
+
+ private static String getNameOfClass(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(classRegexp, line);
+ if(matcherBeginOfTest.find())
+ return matcherBeginOfTest.group(1);
+ else
+ return null;
+ }
+
+ private static boolean lineMatchesBeginOfTest(String line) {
+ return createMatcherFromString(testRegexp, line).find();
+ }
+
+ private static boolean lineMatchesClassName(String line) {
+ return createMatcherFromString(classRegexp, line).find();
+ }
+
+ private static boolean lineMatchesFileName(String line) {
+ return createMatcherFromString(fileRegexp, line).find();
+ }
+
+ protected static Matcher createMatcherFromString(String pattern, String line) {
+ return Pattern.compile(pattern).matcher(line);
+ }
+
+ private static String getNameOfTest(String line) {
+ Matcher matcherBeginOfTest = createMatcherFromString(testRegexp, line);
+ if(matcherBeginOfTest.find())
+ return matcherBeginOfTest.group(1);
+ else
+ return Messages.getString("RefactoringTester.NotNamed"); //$NON-NLS-1$
+ }
+
+ private static boolean lineMatchesBeginOfResult(String line) {
+ return createMatcherFromString(resultRegexp, line).find();
+ }
+
+ private static TestSuite createSuite(ArrayList<RefactoringBaseTest> testCases, String name) {
+ TestSuite suite = new TestSuite(name);
+ Iterator<RefactoringBaseTest> it = testCases.iterator();
+ while(it.hasNext()) {
+ RefactoringBaseTest subject =it.next();
+ suite.addTest(subject);
+ }
+ return suite;
+ }
+}
+
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java
new file mode 100644
index 00000000000..a2ec884cede
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestHelper.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring;
+
+public class TestHelper {
+
+ public static String unifyNewLines(String code) {
+ String replacement = System.getProperty("line.separator"); //$NON-NLS-1$
+ return code.replaceAll("(\n)|(\r\n)", replacement); //$NON-NLS-1$
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java
new file mode 100644
index 00000000000..04b5905e5cd
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/TestSourceFile.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.jface.text.TextSelection;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class TestSourceFile {
+
+ private static final String REPLACEMENT = ""; //$NON-NLS-1$
+ private String name;
+ private StringBuffer source = new StringBuffer();
+ private StringBuffer expectedSource = new StringBuffer();
+ private String separator = System.getProperty("line.separator"); //$NON-NLS-1$
+ private int selectionStart = -1;
+ private int selectionEnd = -1;
+
+ protected static final String selectionStartRegex = "//\\$"; //$NON-NLS-1$
+ protected static final String selectionEndRegex = "\\$//"; //$NON-NLS-1$
+ protected static final String selectionStartLineRegex = "(.*)(" + selectionStartRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
+ protected static final String selectionEndLineRegex = "(.*)("+ selectionEndRegex + ")(.*)"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ public TestSourceFile(String name) {
+ super();
+ this.name = name;
+ }
+ public String getExpectedSource() {
+ String exp = expectedSource.toString();
+ if(exp.length() == 0) {
+ return getSource();
+ }else {
+ return exp;
+ }
+ }
+ public String getName() {
+ return name;
+ }
+ public String getSource() {
+ return source.toString();
+ }
+
+ public void addLineToSource(String code) {
+ Matcher start = createMatcherFromString(selectionStartLineRegex, code);
+ if(start.matches()) {
+ selectionStart = start.start(2) + source.length();
+ code = code.replaceAll(selectionStartRegex, REPLACEMENT);
+ }
+ Matcher end = createMatcherFromString(selectionEndLineRegex, code);
+ if(end.matches()) {
+ selectionEnd = end.start(2) + source.length();
+ code = code.replaceAll(selectionEndRegex, REPLACEMENT);
+ }
+ source.append(code);
+ source.append(separator);
+ }
+
+ public void addLineToExpectedSource(String code) {
+ expectedSource.append(code);
+ expectedSource.append(separator);
+ }
+
+ public TextSelection getSelection() {
+ if(selectionStart < 0 || selectionEnd <0 ) {
+ return null;
+ }else {
+ return new TextSelection(selectionStart, selectionEnd -selectionStart);
+ }
+ }
+
+ protected static Matcher createMatcherFromString(String pattern, String line) {
+ return Pattern.compile(pattern).matcher(line);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantRefactoringTest.java
new file mode 100644
index 00000000000..3722ad107cc
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractconstant/ExtractConstantRefactoringTest.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.extractconstant;
+
+import java.util.Properties;
+import java.util.Vector;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
+import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
+
+import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
+import org.eclipse.cdt.internal.ui.refactoring.extractconstant.ExtractConstantRefactoring;
+import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
+
+/**
+ * @author Emanuel Graf
+ */
+public class ExtractConstantRefactoringTest extends RefactoringTest {
+
+
+ protected VisibilityEnum visibility;
+
+ public ExtractConstantRefactoringTest(String name, Vector<TestSourceFile> files) {
+ super(name, files);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ IFile refFile = project.getFile(fileName);
+ NameNVisibilityInformation info = new NameNVisibilityInformation();
+ ExtractConstantRefactoring refactoring = new ExtractConstantRefactoring( refFile, selection, info, true);
+ RefactoringStatus checkInitialConditions = refactoring.checkInitialConditions(NULL_PROGRESS_MONITOR);
+ assertConditionsOk(checkInitialConditions);
+ info.setName("theAnswer"); //$NON-NLS-1$
+ info.setVisibility(visibility);
+ Change createChange = refactoring.createChange(NULL_PROGRESS_MONITOR);
+ RefactoringStatus finalConditions = refactoring.checkFinalConditions(NULL_PROGRESS_MONITOR);
+ assertConditionsOk(finalConditions);
+ createChange.perform(NULL_PROGRESS_MONITOR);
+
+ compareFiles(fileMap);
+
+ }
+
+ @Override
+ protected void configureRefactoring(Properties refactoringProperties) {
+ visibility = VisibilityEnum.getEnumForStringRepresentation(refactoringProperties.getProperty("visibility", VisibilityEnum.v_public.toString())); //$NON-NLS-1$
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/messages.properties b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/messages.properties
new file mode 100644
index 00000000000..04890cb5ab7
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/messages.properties
@@ -0,0 +1,8 @@
+RefactoringTester.UnknownTestClass=Unknown TestClass. Make sure the test's sourcefile specifies a valid test class.
+RefactoringTester.SecurityException=Security Exception during Test creation
+RefactoringTester.ConstructorError=Test class does not provied required constructor.
+RefactoringTester.IllegalArgument=IllegalArgumentException during Test creation
+RefactoringTester.InstantiationException=InstantiationException during Test creation
+RefactoringTester.IllegalAccessException=IllegalAccessException during Test creation
+RefactoringTester.InvocationTargetException=InvocationTargetException during Test creation
+RefactoringTester.NotNamed=Not Named
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RefactoringTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RefactoringTests.java
new file mode 100644
index 00000000000..644c53f65d4
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RefactoringTests.java
@@ -0,0 +1,268 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2007 Wind River Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import java.io.StringWriter;
+
+import org.eclipse.cdt.core.tests.BaseTestFramework;
+import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
+import org.eclipse.ltk.core.refactoring.TextEditChangeGroup;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.search.internal.core.text.FileCharSequenceProvider;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.text.edits.TextEditGroup;
+
+
+/**
+ * @author markus.schorn@windriver.com
+ */
+public class RefactoringTests extends BaseTestFramework {
+ private int fBufferSize;
+
+ public RefactoringTests() {
+ }
+
+ public RefactoringTests(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ fBufferSize= FileCharSequenceProvider.BUFFER_SIZE;
+ FileCharSequenceProvider.BUFFER_SIZE= 1024*4;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ SavedCodeReaderFactory.getInstance().getCodeReaderCache().flush();
+ FileCharSequenceProvider.BUFFER_SIZE= fBufferSize;
+ }
+
+ protected void assertTotalChanges(int numChanges, Change changes) throws Exception {
+ assertTotalChanges(numChanges, 0, 0, changes);
+ }
+
+ protected void assertTotalChanges(int numChanges, int potChanges, int commentCh,
+ Change changes) throws Exception {
+ int count[]= {0,0,0};
+ if( changes != null ) {
+ countChanges( changes, count);
+ }
+ assertEquals( numChanges, count[0] );
+ assertEquals("potential changes: ", potChanges, count[1]); //$NON-NLS-1$
+ assertEquals("comment changes: ", commentCh, count[2]); //$NON-NLS-1$
+ }
+
+ private void countChanges(Change change, int[] count) {
+ if( change instanceof CompositeChange ){
+ Change [] children = ((CompositeChange) change).getChildren();
+ for( int i = 0; i < children.length; i++ ){
+ countChanges( children[i], count);
+ }
+ } else if( change instanceof TextFileChange ){
+ TextFileChange tfc= (TextFileChange) change;
+ TextEditChangeGroup[] tecgs= tfc.getTextEditChangeGroups();
+ for (int i = 0; i < tecgs.length; i++) {
+ TextEditChangeGroup group = tecgs[i];
+ countChanges(group, count);
+ }
+ }
+ }
+
+ private void countChanges(TextEditChangeGroup edit, int[] count) {
+ String name= edit.getName();
+ if (name.indexOf("potential") != -1) { //$NON-NLS-1$
+ count[1]++;
+ }
+ else if (name.indexOf("comment") != -1) { //$NON-NLS-1$
+ count[2]++;
+ }
+ else {
+ count[0]++;
+ }
+ }
+
+ protected void assertChange(Change changes, IFile file, int startOffset, int numChars, String newText) throws Exception {
+ assertChange(changes, file, startOffset, numChars, newText, false);
+ }
+
+ protected void assertChange(Change changes, IFile file, int startOffset, int numChars, String newText, boolean potential) throws Exception {
+ boolean found = false;
+ if( changes != null && changes instanceof CompositeChange ){
+ found = checkCompositeChange( (CompositeChange) changes, file, startOffset, numChars, newText, potential);
+ }
+
+ if( !found ) {
+ fail ("Rename at offset " + startOffset + " in \"" + file.getLocation() + "\" not found."); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ assertFalse( true );
+ }
+ }
+
+ private boolean checkCompositeChange(CompositeChange composite, IFile file, int startOffset, int numChars, String newText, boolean potential) {
+ boolean found = false;
+ Change [] children = composite.getChildren();
+ for( int i = 0; i < children.length; i++ ){
+ if( children[i] instanceof CompositeChange )
+ found = checkCompositeChange( (CompositeChange) children[i], file, startOffset, numChars, newText, potential);
+ else if( children[i] instanceof TextFileChange ){
+ TextFileChange tuChange = (TextFileChange) children[i];
+ if( tuChange.getFile().toString().equals( file.toString() ) ){
+ found = checkTranslationUnitChange( tuChange, startOffset, numChars, newText, potential );
+ }
+ }
+ if( found )
+ return found;
+ }
+ return found;
+ }
+
+ private boolean checkTranslationUnitChange(TextFileChange change, int startOffset, int numChars, String newText, boolean potential) {
+ TextEditChangeGroup[] groups= change.getTextEditChangeGroups();
+ for (int i = 0; i < groups.length; i++) {
+ TextEditGroup group = groups[i].getTextEditGroup();
+ if ((group.getName().indexOf("potential") != -1) == potential) { //$NON-NLS-1$
+ TextEdit[] edits= group.getTextEdits();
+ if (checkTextEdits(edits, startOffset, numChars, newText)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean checkTextEdit(TextEdit edit, int startOffset, int numChars, String newText) {
+ if (edit instanceof MultiTextEdit) {
+ if (checkTextEdits(((MultiTextEdit) edit).getChildren(),
+ startOffset, numChars, newText)) {
+ return true;
+ }
+ }
+ else if (edit instanceof ReplaceEdit) {
+ if (checkReplaceEdit((ReplaceEdit) edit, startOffset, numChars, newText ) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean checkTextEdits(TextEdit[] edits, int startOffset, int numChars, String newText) {
+ for (int i = 0; i < edits.length; i++) {
+ TextEdit edit = edits[i];
+ if (checkTextEdit(edit, startOffset, numChars, newText)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean checkReplaceEdit(ReplaceEdit edit, int startOffset, int numChars, String newText) {
+ return ( edit.getOffset() == startOffset && edit.getLength() == numChars && edit.getText().equals( newText ) );
+ }
+
+ protected IFile createCppFwdDecls(String fileName) throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class class_fwd; \n"); //$NON-NLS-1$
+ writer.write( "struct struct_fwd; \n"); //$NON-NLS-1$
+ writer.write( "union union_fwd; \n"); //$NON-NLS-1$
+ writer.write( "int func_proto(); \n"); //$NON-NLS-1$
+ writer.write( "int func_proto_ov(); \n"); //$NON-NLS-1$
+ writer.write( "int func_proto_ov(int); \n"); //$NON-NLS-1$
+ writer.write( "int func_proto_ov(int*); \n"); //$NON-NLS-1$
+ writer.write( "extern int extern_var; \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ return importFile(fileName, contents );
+ }
+
+ protected IFile createCFwdDecls(String fileName) throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "struct struct_fwd; \n"); //$NON-NLS-1$
+ writer.write( "union union_fwd; \n"); //$NON-NLS-1$
+ writer.write( "int func_proto(); \n"); //$NON-NLS-1$
+ writer.write( "extern int extern_var; \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ return importFile(fileName, contents );
+ }
+
+ protected IFile createCppDefs(String fileName) throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class class_def { \n"); //$NON-NLS-1$
+ writer.write( "public: \n"); //$NON-NLS-1$
+ writer.write( " int member; \n"); //$NON-NLS-1$
+ writer.write( " static int static_member; \n"); //$NON-NLS-1$
+ writer.write( " void method(int par); \n"); //$NON-NLS-1$
+ writer.write( " void static_method(int par); \n"); //$NON-NLS-1$
+ writer.write( " int method_ov(); \n"); //$NON-NLS-1$
+ writer.write( " int method_ov(int); \n"); //$NON-NLS-1$
+ writer.write( " int method_ov(int*); \n"); //$NON-NLS-1$
+ writer.write( "}; \n"); //$NON-NLS-1$
+ writer.write( "struct struct_def { \n"); //$NON-NLS-1$
+ writer.write( " int st_member; \n"); //$NON-NLS-1$
+ writer.write( "}; \n"); //$NON-NLS-1$
+ writer.write( "union union_def { \n"); //$NON-NLS-1$
+ writer.write( " int un_member; \n"); //$NON-NLS-1$
+ writer.write( "}; \n"); //$NON-NLS-1$
+ writer.write( "typedef int typedef_def; \n"); //$NON-NLS-1$
+ writer.write( "namespace namespace_def{}; \n"); //$NON-NLS-1$
+ writer.write( "enum enum_def { \n"); //$NON-NLS-1$
+ writer.write( " enum_item }; \n"); //$NON-NLS-1$
+ writer.write( "int func_def() {} \n"); //$NON-NLS-1$
+ writer.write( "int func_def_ov() {} \n"); //$NON-NLS-1$
+ writer.write( "int func_def_ov(int){} \n"); //$NON-NLS-1$
+ writer.write( "int func_def_ov(int*){} \n"); //$NON-NLS-1$
+ writer.write( "int var_def; \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ return importFile(fileName, contents );
+ }
+
+ protected IFile createCDefs(String fileName) throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "struct struct_def { \n"); //$NON-NLS-1$
+ writer.write( " int st_member; \n"); //$NON-NLS-1$
+ writer.write( "}; \n"); //$NON-NLS-1$
+ writer.write( "union union_def { \n"); //$NON-NLS-1$
+ writer.write( " int un_member; \n"); //$NON-NLS-1$
+ writer.write( "}; \n"); //$NON-NLS-1$
+ writer.write( "typedef int typedef_def; \n"); //$NON-NLS-1$
+ writer.write( "enum enum_def { \n"); //$NON-NLS-1$
+ writer.write( " enum_item }; \n"); //$NON-NLS-1$
+ writer.write( "int func_def() {} \n"); //$NON-NLS-1$
+ writer.write( "int var_def; \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ return importFile(fileName, contents );
+ }
+
+ protected void assertRefactoringError(RefactoringStatus status, String msg) {
+ RefactoringStatusEntry e= status.getEntryMatchingSeverity(RefactoringStatus.ERROR);
+ assertNotNull("Expected refactoring error!", e); //$NON-NLS-1$
+ assertEquals(msg, e.getMessage());
+ }
+
+ protected void assertRefactoringWarning(RefactoringStatus status, String msg) {
+ RefactoringStatusEntry e= status.getEntryMatchingSeverity(RefactoringStatus.WARNING);
+ assertNotNull("Expected refactoring warning!", e); //$NON-NLS-1$
+ assertEquals(msg, e.getMessage());
+ }
+
+ protected void assertRefactoringOk(RefactoringStatus status) {
+ assertTrue("Expected refactoring status ok: " + //$NON-NLS-1$
+ status.getMessageMatchingSeverity(status.getSeverity()),
+ status.getSeverity()==RefactoringStatus.OK);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameFunctionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameFunctionTests.java
new file mode 100644
index 00000000000..565d363e755
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameFunctionTests.java
@@ -0,0 +1,819 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2007 Wind River Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import java.io.StringWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+/**
+ * @author markus.schorn@windriver.com
+ */
+public class RenameFunctionTests extends RenameTests {
+
+ public RenameFunctionTests(String name) {
+ super(name);
+ }
+ public static Test suite(){
+ return suite(true);
+ }
+ public static Test suite( boolean cleanup ) {
+ TestSuite suite = new TestSuite(RenameFunctionTests.class);
+
+ if (cleanup) {
+ suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
+ }
+ return suite;
+ }
+
+ public void testFunctionNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
+ writer.write("static int s1(); \n"); //$NON-NLS-1$
+ writer.write("static int s2(); \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2(); \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3(); \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "static int static_other_file(); \n" ); //$NON-NLS-1$
+ importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$
+
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w2 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par2 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w3 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par3 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings depending on scope
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+// lookup inside a static method also returns non-static members
+// we may want to have a check whether a binding is accessible or not.
+
+// status= checkConditions(cpp, offset3, "member"); //$NON-NLS-1$
+// assertRefactoringOk(status);
+// status= checkConditions(cpp, offset3, "method"); //$NON-NLS-1$
+// assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ // would be good to see an error here
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ // would be good to see an error here
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // file static stuff
+ status= checkConditions(cpp, contents.indexOf("s1"), "s2"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: s2 \n" +
+ "Conflicting element type: File static function"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, contents.indexOf("s1"), "static_other_file"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ }
+
+ public void testFunctionsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
+ writer.write("int func_proto(); \n"); //$NON-NLS-1$
+ writer.write("static int s2(); \n"); //$NON-NLS-1$
+ writer.write("void func_def(){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("func_proto"); //$NON-NLS-1$
+ Change change= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$
+ assertTotalChanges(2, change);
+
+ offset1= contents.indexOf("func_def"); //$NON-NLS-1$
+ change= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$
+ assertTotalChanges(2, change);
+ }
+
+
+ public void testFunctionNameConflictsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
+ writer.write("static int s1(); \n"); //$NON-NLS-1$
+ writer.write("static int s2(); \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "static int static_other_file(); \n" ); //$NON-NLS-1$
+ importFile( "other.c", writer.toString() ); //$NON-NLS-1$
+
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // file static stuff
+ status= checkConditions(cpp, contents.indexOf("s1"), "s2"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: s2 \n" +
+ "Conflicting element type: File static function"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, contents.indexOf("s1"), "static_other_file"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ }
+
+ public void testMethodNameConflicts1() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("class Dummy { \n"); //$NON-NLS-1$
+ writer.write(" int v1(); int v2(); \n"); //$NON-NLS-1$
+ writer.write(" int member; \n"); //$NON-NLS-1$
+ writer.write(" int method(int); \n"); //$NON-NLS-1$
+ writer.write(" int method_samesig(); \n"); //$NON-NLS-1$
+ writer.write(" static int static_method(int); \n"); //$NON-NLS-1$
+ writer.write(" static int static_member; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("int Dummy::method(int par1) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static int Dummy::static_method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2(); \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w2 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par2 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Overloading \n" +
+ "New element: method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "method_samesig"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: method_samesig \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Overloading \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ }
+
+ public void testMethodNameConflicts2() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("class Dummy { \n"); //$NON-NLS-1$
+ writer.write(" int v1(), v2(), v3(); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("Dummy d; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; d.v1(); \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; d.v2(); \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; d.v3(); \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings depending on scope
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testBug72605() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("class Foo { \n"); //$NON-NLS-1$
+ writer.write(" void m1(int x=0); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("void Foo::m1(int x) {} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset = contents.indexOf("m1") ; //$NON-NLS-1$
+ int offset2= contents.indexOf("m1", offset+1) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ changes = getRefactorChanges(cpp, offset2, "z"); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ }
+
+ public void testBug72732() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("class Foo { \n"); //$NON-NLS-1$
+ writer.write(" virtual void mthd() = 0;\n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("class Moo: public Foo{ \n"); //$NON-NLS-1$
+ writer.write(" void mthd() = 0; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf("mthd") ; //$NON-NLS-1$
+ offset= contents.indexOf("mthd", offset+1) ; //$NON-NLS-1$
+ RefactoringStatus status= checkConditions(cpp, offset, "xxx"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "Renaming a virtual method. Consider renaming the base and derived class methods (if any)."); //$NON-NLS-1$
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java
new file mode 100644
index 00000000000..a0098de9af8
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2007 Wind River Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import java.io.StringWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+/**
+ * @author markus.schorn@windriver.com
+ */
+public class RenameMacroTests extends RenameTests {
+
+ public RenameMacroTests(String name) {
+ super(name);
+ }
+ public static Test suite(){
+ return suite(true);
+ }
+ public static Test suite( boolean cleanup ) {
+ TestSuite suite = new TestSuite(RenameMacroTests.class);
+ if (cleanup) {
+ suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
+ }
+ return suite;
+ }
+
+
+ public void testMacroRename() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("#define HALLO x \n"); //$NON-NLS-1$
+ writer.write("class v1 { \n"); //$NON-NLS-1$
+ writer.write(" int HALLO; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("class HALLO { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("class v3 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("class v4 { \n"); //$NON-NLS-1$
+ writer.write(" int HALLO(); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("int v4::HALLO(){} \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int HALLO; v1::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("HALLO"); //$NON-NLS-1$
+ int offset2= contents.indexOf("HALLO", offset1+1); //$NON-NLS-1$
+
+ Change ch= getRefactorChanges(cpp, offset1, "WELT"); //$NON-NLS-1$
+ assertTotalChanges(6, ch);
+ int off= offset1;
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+
+ ch= getRefactorChanges(cpp, offset2, "WELT"); //$NON-NLS-1$
+ assertTotalChanges(6, ch);
+ off= offset1;
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$
+ }
+
+ public void testMacroNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("#define MACRO 1 \n"); //$NON-NLS-1$
+ writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
+ writer.write("static int s1(); \n"); //$NON-NLS-1$
+ writer.write("static int s2(); \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1(); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "static int static_other_file(); \n" ); //$NON-NLS-1$
+ importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$
+
+
+ int offset1= contents.indexOf("MACRO"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Name conflict \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("par1"), "MACRO"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "'MACRO' conflicts with the name of an existing macro!"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Name conflict \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Name conflict \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Name conflict \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Name conflict \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+ }
+
+ public void testClassMacroClash() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("class CC {int a;}; \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write("#define CC mm \n"); //$NON-NLS-1$
+ writer.write("int CC; \n"); //$NON-NLS-1$
+ String contents2 = writer.toString();
+ IFile cpp2= importFile("test2.cpp", contents2 ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("CC"); //$NON-NLS-1$
+ Change ch= getRefactorChanges(cpp, offset1, "CCC"); //$NON-NLS-1$
+ assertTotalChanges(1, ch);
+
+ int offset2= contents2.indexOf("CC"); //$NON-NLS-1$
+ ch= getRefactorChanges(cpp2, offset2, "CCC"); //$NON-NLS-1$
+ assertTotalChanges(2, ch);
+ }
+
+ public void testIncludeGuard() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("#ifndef _guard \n"); //$NON-NLS-1$
+ writer.write("#define _guard \n"); //$NON-NLS-1$
+ writer.write(" int HALLO \n"); //$NON-NLS-1$
+ writer.write("#endif /* _guard */ \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("_guard"); //$NON-NLS-1$
+ int offset2= contents.indexOf("_guard", offset1+1); //$NON-NLS-1$
+ Change ch= getRefactorChanges(cpp, offset2, "WELT"); //$NON-NLS-1$
+ assertTotalChanges(2, 0, 1, ch);
+ int off= offset1;
+ assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$
+ off= contents.indexOf("_guard", off+1); //$NON-NLS-1$
+ assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$
+ }
+
+ public void testMacroParameters() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("int var; \n"); //$NON-NLS-1$
+ writer.write("#define M1(var) var \n"); //$NON-NLS-1$
+ writer.write("#define M2(var, x) (var+x)*var \n"); //$NON-NLS-1$
+ writer.write("#define M3 var \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("var"); //$NON-NLS-1$
+ Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$
+ assertTotalChanges(1, 1, 0, ch);
+ }
+
+ public void testRenameMacroAsMacroArgument() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("#define M1(var) var \n"); //$NON-NLS-1$
+ writer.write("#define M2 1 \n"); //$NON-NLS-1$
+ writer.write("int b= M2; \n"); //$NON-NLS-1$
+ writer.write("int a= M1(M2); \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("M2"); //$NON-NLS-1$
+ Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$
+ assertTotalChanges(countOccurrences(contents, "M2"), ch); //$NON-NLS-1$
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java
new file mode 100644
index 00000000000..584e3a8ecff
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameRegressionTests.java
@@ -0,0 +1,1263 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Wind River Systems Inc. - ported for new rename implementation
+ *******************************************************************************/
+
+/*
+ * Created on Nov 10, 2004
+ */
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import java.io.StringWriter;
+
+import junit.framework.*;
+
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.tests.FailingTest;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
+
+/**
+ * @author aniefer
+ */
+public class RenameRegressionTests extends RenameTests {
+
+ public RenameRegressionTests() {
+ super();
+ }
+ public RenameRegressionTests(String name) {
+ super(name);
+ }
+
+ public static Test suite(){
+ return suite( true );
+ }
+ public static Test suite( boolean cleanup ) {
+
+ TestSuite innerSuite= new TestSuite(RenameRegressionTests.class);
+ innerSuite.addTest( new FailingTest(new RenameRegressionTests("_testMethod_35_72726"),72726) ); //$NON-NLS-1$
+
+ TestSuite suite = new TestSuite("RenameRegressionTests"); //$NON-NLS-1$
+ suite.addTest( innerSuite );
+ suite.addTest( RenameVariableTests.suite(false));
+ suite.addTest( RenameFunctionTests.suite(false));
+ suite.addTest( RenameTypeTests.suite(false));
+ suite.addTest( RenameMacroTests.suite(false));
+ suite.addTest( RenameTemplatesTests.suite(false));
+
+ if( cleanup )
+ suite.addTest( new RenameRegressionTests("cleanupProject") ); //$NON-NLS-1$
+
+ return suite;
+ }
+
+ public void testSimpleRename() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "int boo; // boo \n" ); //$NON-NLS-1$
+ writer.write( "#ifdef 0 \n" ); //$NON-NLS-1$
+ writer.write( "boo \n" ); //$NON-NLS-1$
+ writer.write( "#endif \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ Change changes = getRefactorChanges( file, contents.indexOf( "boo" ), "ooga" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+ assertTotalChanges( 2, 1, 1, changes );
+ assertChange( changes, file, contents.indexOf("boo"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("boo++"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ public void testLocalVar() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " int boo; \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( " { \n" ); //$NON-NLS-1$
+ writer.write( " int boo; \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ int offset= contents.indexOf("boo"); //$NON-NLS-1$
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ Change changes = getRefactorChanges( file, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 3, changes );
+ assertChange( changes, file, offset, 3, "ooga" ); //$NON-NLS-1$
+ offset= contents.indexOf("boo", offset+1); //$NON-NLS-1$
+ assertChange( changes, file, offset, 3, "ooga" ); //$NON-NLS-1$
+ offset= contents.lastIndexOf("boo"); //$NON-NLS-1$
+ assertChange( changes, file, offset, 3, "ooga" ); //$NON-NLS-1$
+ }
+
+ public void testParameter() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "void f(int boo) { \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( " { \n" ); //$NON-NLS-1$
+ writer.write( " int boo; \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ int offset= contents.indexOf("boo"); //$NON-NLS-1$
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ Change changes = getRefactorChanges( file, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 3, changes );
+ assertChange( changes, file, offset, 3, "ooga" ); //$NON-NLS-1$
+ offset= contents.indexOf("boo", offset+1); //$NON-NLS-1$
+ assertChange( changes, file, offset, 3, "ooga" ); //$NON-NLS-1$
+ offset= contents.lastIndexOf("boo"); //$NON-NLS-1$
+ assertChange( changes, file, offset, 3, "ooga" ); //$NON-NLS-1$
+ }
+
+ public void testFileStaticVar() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "static int boo; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ writer.write( "void g(int boo) { \n" ); //$NON-NLS-1$
+ writer.write( " boo++; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ importFile( "t2.cpp", contents ); //$NON-NLS-1$
+
+ int offset= contents.indexOf("boo"); //$NON-NLS-1$
+ Change changes = getRefactorChanges( file, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, offset, 3, "ooga" ); //$NON-NLS-1$
+ offset= contents.indexOf("boo", offset+1); //$NON-NLS-1$
+ assertChange( changes, file, offset, 3, "ooga" ); //$NON-NLS-1$
+ }
+
+ public void testClass_1() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo/*vp1*/{}; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Boo a; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset= contents.indexOf( "Boo/*vp1*/" ); //$NON-NLS-1$
+ Change changes = getRefactorChanges( file, offset, "Ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("Boo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Boo a"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testAttribute_2() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{ \n" ); //$NON-NLS-1$
+ writer.write( " int att1;//vp1,res1 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Boo a; \n" ); //$NON-NLS-1$
+ writer.write( " a.att1;//res2 \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "att1;//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("att1;//vp1,res1"), 4, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("att1;//res2"), 4, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testMethod_1() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( "public: \n" ); //$NON-NLS-1$
+ writer.write( " const void* method1(const char*); \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "const void* Foo::method1(const char* x) { \n"); //$NON-NLS-1$
+ writer.write( " return (void*) x; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ writer.write( "void test() { \n" ); //$NON-NLS-1$
+ writer.write( " Foo d; \n" ); //$NON-NLS-1$
+ writer.write( " d.method1(\"hello\"); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ String source = writer.toString();
+ IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$
+ //vp1 const
+ int offset = source.indexOf( "method1" ); //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset, "m1" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, cpp, source.indexOf("method1"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(const"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(\"hello"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ public void testMethod_3() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{ \n" ); //$NON-NLS-1$
+ writer.write( " int method1(){}//vp1,res1 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Boo a; \n" ); //$NON-NLS-1$
+ writer.write( " a.method1();//res2 \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "method1(){}//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("method1(){}//vp1,res1"), 7, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("method1();//res2"), 7, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+
+ public void testConstructor_26() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{ \n" ); //$NON-NLS-1$
+ writer.write( " Boo(){}//vp1,res1 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Boo a = new Boo(); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "Boo(){}" ) ; //$NON-NLS-1$
+ try {
+ getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+ } catch (AssertionFailedError e) {
+ assertTrue(e.getMessage().startsWith("Input check on ooga failed.")); //$NON-NLS-1$
+ return;
+ }
+ fail ("An error should have occurred in the input check."); //$NON-NLS-1$
+ }
+ //The constructor name is accepted, but the refactoring doesn't remove the return
+ //type and there is a compile error. Renaming to a constructor should be disabled.
+ //However, the UI does display the error in the preview panel. Defect 78769 states
+ //the error should be shown on the first page. The parser passes, but the UI could be
+ //better.
+ public void testConstructor_27() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{ \n" ); //$NON-NLS-1$
+ writer.write( " int foo(){}//vp1 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Boo a; \n" ); //$NON-NLS-1$
+ writer.write( " a.foo(); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "foo(){}" ) ; //$NON-NLS-1$
+ try {
+ getRefactorChanges(file, offset, "Boo" ); //$NON-NLS-1$
+ } catch (AssertionFailedError e) {
+ //test passes
+ assertTrue(e.getMessage().startsWith("Input check on Boo failed.")); //$NON-NLS-1$
+ return;
+ }
+ fail ("An error should have occurred in the input check."); //$NON-NLS-1$
+ }
+ public void testDestructor_28() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{ \n" ); //$NON-NLS-1$
+ writer.write( " ~Boo(){}//vp1 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Boo a ; \n" ); //$NON-NLS-1$
+ writer.write( " a.~Boo(); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "~Boo(){}" ) ; //$NON-NLS-1$
+ try {
+ getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+ } catch (AssertionFailedError e) {
+ assertTrue(e.getMessage().startsWith("Input check on ooga failed.")); //$NON-NLS-1$
+ return;
+ }
+ fail ("An error should have occurred in the input check."); //$NON-NLS-1$
+ }
+ public void testDestructor_29_72612() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{ \n" ); //$NON-NLS-1$
+ writer.write( " int foo(){}//vp1 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Boo a; \n" ); //$NON-NLS-1$
+ writer.write( " a.foo(); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "foo(){}" ) ; //$NON-NLS-1$
+ try {
+ getRefactorChanges(file, offset, "~Boo" ); //$NON-NLS-1$
+ } catch (AssertionFailedError e) {
+ //test passes
+ assertTrue(e.getMessage().startsWith("Input check on ~Boo failed.")); //$NON-NLS-1$
+ return;
+ }
+ fail ("An error should have occurred in the input check."); //$NON-NLS-1$
+ }
+ public void testFunction_31() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "void foo(){} \n" ); //$NON-NLS-1$
+ writer.write( "void foo/*vp1*/(int i){} \n" ); //$NON-NLS-1$
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " int method1(){ \n" ); //$NON-NLS-1$
+ writer.write( " foo(3); \n" ); //$NON-NLS-1$
+ writer.write( " foo(); \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "foo/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("foo/*vp1*/"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("foo(3)"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testMethod_32_72717() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Base { \n" ); //$NON-NLS-1$
+ writer.write( " virtual void foo()=0; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "class Derived: public Base { \n" ); //$NON-NLS-1$
+ writer.write( " virtual void foo(); \n" ); //$NON-NLS-1$
+ writer.write( " void foo(char i); \n" ); //$NON-NLS-1$
+ writer.write( " void moon/*vp1*/(int i); \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "moon/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "foo" ); //$NON-NLS-1$
+ assertTotalChanges( 1, changes );
+ assertChange( changes, file, contents.indexOf("moon/*vp1*/"), 4, "foo" ); //$NON-NLS-1$//$NON-NLS-2$
+ RefactoringStatus status= checkConditions(file, offset, "foo"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Overloading \n" +
+ "New element: foo \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ }
+
+ public void testMethod_33_72605() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo { \n" ); //$NON-NLS-1$
+ writer.write( " void aMethod/*vp1*/(int x=0); \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void Foo::aMethod(int x){} \n" ); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "aMethod/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("aMethod/*vp1*/"), 7, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("aMethod(int x)"), 7, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+
+ public void testMethod_33b_72605() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo { \n" ); //$NON-NLS-1$
+ writer.write( " void aMethod/*vp1*/(int x=0); \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile hFile= importFile("t.hh", header); //$NON-NLS-1$
+ writer= new StringWriter();
+ writer.write( "#include \"t.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "void Foo::aMethod(int x){} \n" ); //$NON-NLS-1$
+ String source = writer.toString();
+ IFile cppfile = importFile( "t.cpp", source ); //$NON-NLS-1$
+
+ int hoffset = header.indexOf( "aMethod" ) ; //$NON-NLS-1$
+ int cppoffset = source.indexOf( "aMethod" ) ; //$NON-NLS-1$
+
+ Change changes = getRefactorChanges(hFile, hoffset, "ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, hFile, hoffset, 7, "ooga" ); //$NON-NLS-1$
+ assertChange( changes, cppfile, cppoffset, 7, "ooga" ); //$NON-NLS-1$
+
+ changes = getRefactorChanges(cppfile, cppoffset, "ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, hFile, hoffset, 7, "ooga" ); //$NON-NLS-1$
+ assertChange( changes, cppfile, cppoffset, 7, "ooga" ); //$NON-NLS-1$
+ }
+
+ public void testMethod_34() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Base{ \n" ); //$NON-NLS-1$
+ writer.write( " virtual void v/*vp1*/()=0; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "class Derived: Base { \n" ); //$NON-NLS-1$
+ writer.write( " void v(){}; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "v/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+ //dervied method is not renamed; only a warning to rename derived or base class methods
+ assertTotalChanges( 1, changes );
+ assertChange( changes, file, contents.indexOf("v/*vp1*/"), 1, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ // defect is input for new name is not allowed
+ public void _testMethod_35_72726() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " Foo& operator *=/*vp1*/(const Foo &rhs);\n" ); //$NON-NLS-1$
+ writer.write( " Foo& operator==/*vp2*/(const Foo &rhs);\n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "Foo& Foo::operator *=(const Foo &rhs){ \n" ); //$NON-NLS-1$
+ writer.write( " return *this; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "Foo& Foo::operator==(const Foo &rhs){ \n" ); //$NON-NLS-1$
+ writer.write( " return *this; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //vp1 with space
+ int offset = contents.indexOf( "operator *=/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "operator +=" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("operator *=/*vp1*/"), 11, "operator +=" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("operator *=(const"), 11, "operator +=" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp2 without space
+ offset = contents.indexOf( "operator==/*vp2*/" ) ; //$NON-NLS-1$
+ changes = getRefactorChanges(file, offset, "operator=" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("operator==/*vp2*/"), 11, "operator=" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("operator==(const"), 11, "operator=" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testMethod_39() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " const void* method1(const char*); \n" ); //$NON-NLS-1$
+ writer.write( " const int method2(int j); \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "t.hh", header ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "#include \"t.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "const void* Foo::method1(const char* x){return (void*) x;} \n" ); //$NON-NLS-1$
+ writer.write( "const int Foo::method2(int){return 5;} \n" ); //$NON-NLS-1$
+ writer.write( "void test() { \n" ); //$NON-NLS-1$
+ writer.write( " Foo d; \n" ); //$NON-NLS-1$
+ writer.write( " d.method1(\"hello\"); \n" ); //$NON-NLS-1$
+ writer.write( " int i =d.method2(3); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ String source = writer.toString();
+ IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$
+ //vp1 const
+ int offset = header.indexOf( "method1" ); //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "m1" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, h, header.indexOf("method1"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(const"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(\"hello"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp2 const in definition with ::
+ offset = source.indexOf( "method2(int" ); //$NON-NLS-1$
+ changes = getRefactorChanges(cpp, offset, "m2" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, h, header.indexOf("method2"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method2(int"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method2(3"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testMethod_40() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " static int method1/*vp1*/(const char* x); \n" ); //$NON-NLS-1$
+ writer.write( " static int method2/*vp2*/(int); \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "t.hh", header ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "#include \"t.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "static int Foo::method1(const char* x){return 5;} \n" ); //$NON-NLS-1$
+ writer.write( "static int Foo::method2(int x){return (2);}; \n" ); //$NON-NLS-1$
+ writer.write( "void test() { \n" ); //$NON-NLS-1$
+ writer.write( " Foo::method1(\"hello\"); \n" ); //$NON-NLS-1$
+ writer.write( " int i =Foo::method2(3); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ String source = writer.toString();
+ IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$
+ //vp1 static method declaration
+ int offset = header.indexOf( "method1/*vp1*/" ); //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "m1" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, h, header.indexOf("method1/*vp1*/"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(const"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(\"hello"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp2 static method definition
+ offset = source.indexOf( "Foo::method2" )+5; //$NON-NLS-1$
+ changes = getRefactorChanges(cpp, offset, "m2" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, h, header.indexOf("method2/*vp2*/"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method2(int x"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method2(3"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+
+ public void testMethod_41() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( "public: \n" ); //$NON-NLS-1$
+ writer.write( " volatile int method1/*vp1*/(int); \n" ); //$NON-NLS-1$
+ writer.write( "private: \n" ); //$NON-NLS-1$
+ writer.write( " int b; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "t.hh", header ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "#include \"t.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "volatile int Foo::method1(int x){return (2);}; \n" ); //$NON-NLS-1$
+ writer.write( "void test() { \n" ); //$NON-NLS-1$
+ writer.write( " Foo d; \n" ); //$NON-NLS-1$
+ writer.write( " int i =d.method1(1); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ String source = writer.toString();
+ IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$
+ //vp1 volatile
+ int offset = header.indexOf( "method1/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "m1" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, h, header.indexOf("method1/*vp1*/"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(int x"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(1"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testMethod_43() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( "public: \n" ); //$NON-NLS-1$
+ writer.write( " inline void method1/*vp1*/(int i) {b=i;} \n" ); //$NON-NLS-1$
+ writer.write( "private: \n" ); //$NON-NLS-1$
+ writer.write( " int b; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "t.hh", header ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "#include \"t.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "void test() { \n" ); //$NON-NLS-1$
+ writer.write( " Foo d; \n" ); //$NON-NLS-1$
+ writer.write( " d->method1(1); \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ String source = writer.toString();
+ IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$
+ //vp1 inline
+ int offset = header.indexOf( "method1/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "m1" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, h, header.indexOf("method1/*vp1*/"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("method1(1"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testMethod_44() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Base{ \n" ); //$NON-NLS-1$
+ writer.write( " virtual void v(); \n" ); //$NON-NLS-1$
+ writer.write( " int i; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void Base::v(){} \n" ); //$NON-NLS-1$
+ writer.write( "class Derived: Base { \n" ); //$NON-NLS-1$
+ writer.write( " virtual void v/*vp1*/(){}//explicitly virtual \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "class Derived2: Derived {\n" ); //$NON-NLS-1$
+ writer.write( " void v(){i++;} \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //vp1 implicit virtual method
+ int offset = contents.indexOf( "v/*vp1*/" ) ; //$NON-NLS-1$
+ String[] messages= getRefactorMessages( file, offset, "v2" ); //$NON-NLS-1$
+ assertEquals(1, messages.length);
+ assertEquals("Renaming a virtual method. Consider renaming the base and derived class methods (if any).", messages[0] ); //$NON-NLS-1$
+
+}
+ public void testMethod_45() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Base{ \n" ); //$NON-NLS-1$
+ writer.write( " virtual void v(); \n" ); //$NON-NLS-1$
+ writer.write( " int i; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void Base::v(){} \n" ); //$NON-NLS-1$
+ writer.write( "class Derived: Base { \n" ); //$NON-NLS-1$
+ writer.write( " void v/*vp1*/(){}//implicitly virtual \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "class Derived2: Derived {\n" ); //$NON-NLS-1$
+ writer.write( " void v(){i++;} \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //vp1 implicit virtual method
+ int offset = contents.indexOf( "v/*vp1*/" ) ; //$NON-NLS-1$
+ String[] messages= getRefactorMessages( file, offset, "v2" ); //$NON-NLS-1$
+ assertEquals(1, messages.length);
+ assertEquals("Renaming a virtual method. Consider renaming the base and derived class methods (if any).", messages[0] ); //$NON-NLS-1$
+
+
+ }
+ public void testStruct_46() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "struct st1/*vp1*/{}; \n" ); //$NON-NLS-1$
+ writer.write( "class c1/*vp1*/{ \n" ); //$NON-NLS-1$
+ writer.write( " public: struct st2/*vp2*/{} s; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "namespace N{ \n" ); //$NON-NLS-1$
+ writer.write( " struct st3/*vp3*/{}; \n" ); //$NON-NLS-1$
+ writer.write( " class c2/*vp1*/{ \n" ); //$NON-NLS-1$
+ writer.write( " st1 s; \n" ); //$NON-NLS-1$
+ writer.write( " st3 ss; \n" ); //$NON-NLS-1$
+ writer.write( " c2() { \n" ); //$NON-NLS-1$
+ writer.write( " c1::st2 s; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " }; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //vp1 global declaration
+ int offset = contents.indexOf( "st1/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga1" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("st1/*vp1*/"), 3, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("st1 s"), 3, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp2 Declared in class
+ offset = contents.indexOf( "st2/*vp2*/" ) ; //$NON-NLS-1$
+ changes = getRefactorChanges(file, offset, "Ooga2" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("st2/*vp2*/"), 3, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("st2 s"), 3, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp3 Declared in namespace
+ offset = contents.indexOf( "st3/*vp3*/" ) ; //$NON-NLS-1$
+ changes = getRefactorChanges(file, offset, "Ooga3" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("st3/*vp3*/"), 3, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("st3 ss"), 3, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testUnion_47() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "union st1/*vp1*/{}; \n" ); //$NON-NLS-1$
+ writer.write( "class c1/*vp1*/{ \n" ); //$NON-NLS-1$
+ writer.write( " public: union st2/*vp2*/{} s; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "namespace N{ \n" ); //$NON-NLS-1$
+ writer.write( " union st3/*vp3*/{}; \n" ); //$NON-NLS-1$
+ writer.write( " class c2/*vp1*/{ \n" ); //$NON-NLS-1$
+ writer.write( " st1 s; \n" ); //$NON-NLS-1$
+ writer.write( " st3 ss; \n" ); //$NON-NLS-1$
+ writer.write( " c2() { \n" ); //$NON-NLS-1$
+ writer.write( " c1::st2 s; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " }; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //vp1 global declaration
+ int offset = contents.indexOf( "st1/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga1" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("st1/*vp1*/"), 3, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("st1 s"), 3, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp2 Declared in class
+ offset = contents.indexOf( "st2/*vp2*/" ) ; //$NON-NLS-1$
+ changes = getRefactorChanges(file, offset, "Ooga2" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("st2/*vp2*/"), 3, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("st2 s"), 3, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp3 Declared in namespace
+ offset = contents.indexOf( "st3/*vp3*/" ) ; //$NON-NLS-1$
+ changes = getRefactorChanges(file, offset, "Ooga3" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("st3/*vp3*/"), 3, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("st3 ss"), 3, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$
+}
+ public void testEnumeration_48() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "enum e1/*vp1*/{E0}; \n" ); //$NON-NLS-1$
+ writer.write( "class c1 { \n" ); //$NON-NLS-1$
+ writer.write( " public: enum e2/*vp2*/{E1} s; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "namespace N{ \n" ); //$NON-NLS-1$
+ writer.write( " enum e3/*vp3*/{}; \n" ); //$NON-NLS-1$
+ writer.write( " class c2/*vp1*/{ \n" ); //$NON-NLS-1$
+ writer.write( " e1 s; \n" ); //$NON-NLS-1$
+ writer.write( " e3 ss; \n" ); //$NON-NLS-1$
+ writer.write( " c2() { \n" ); //$NON-NLS-1$
+ writer.write( " c1::e2 s; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " }; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //vp1 global declaration
+ int offset = contents.indexOf( "e1/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga1" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("e1/*vp1*/"), 2, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("e1 s"), 2, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp2 Declared in class
+ offset = contents.indexOf( "e2/*vp2*/" ) ; //$NON-NLS-1$
+ changes = getRefactorChanges(file, offset, "Ooga2" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("e2/*vp2*/"), 2, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("e2 s"), 2, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp3 Declared in namespace
+ offset = contents.indexOf( "e3/*vp3*/" ) ; //$NON-NLS-1$
+ changes = getRefactorChanges(file, offset, "Ooga3" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("e3/*vp3*/"), 2, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("e3 ss"), 2, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testTemplate_49_72626() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "template <class Type> \n" ); //$NON-NLS-1$
+ writer.write( "class Array/*vp1*/ { \n" ); //$NON-NLS-1$
+ writer.write( " public: Array(){ \n" ); //$NON-NLS-1$
+ writer.write( " a=new Type[10]; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " virtual Type& operator[](int i){return a[i];} \n" ); //$NON-NLS-1$
+ writer.write( " protected: Type *a; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void f(){ \n" ); //$NON-NLS-1$
+ writer.write( " Array <int> a; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "Array" ) ; //$NON-NLS-1$
+ Change changes= getRefactorChanges(file, offset, "Arr2" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, file, offset, 5, "Arr2" ); //$NON-NLS-1$
+ assertChange( changes, file, offset=contents.indexOf("Array", offset+1), 5, "Arr2" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, offset=contents.indexOf("Array", offset+1), 5, "Arr2" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testClass_52() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "namespace N1 { \n" ); //$NON-NLS-1$
+ writer.write( "class Boo{}; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ writer.write( "namespace N2 { \n" ); //$NON-NLS-1$
+ writer.write( "class Boo/*vp1*/{}; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " N1::Boo c1; \n" ); //$NON-NLS-1$
+ writer.write( " N2::Boo c2; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "Boo/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("Boo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Boo c2"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testClass_53() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo/*vp1*/ {//ren1 \n" ); //$NON-NLS-1$
+ writer.write( " Foo();//ren2 \n" ); //$NON-NLS-1$
+ writer.write( " virtual ~Foo();//ren3 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "Foo::Foo() {}//ren4,5 \n" ); //$NON-NLS-1$
+ writer.write( "Foo::~Foo() {}//ren6,7 \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Foo *f=new Foo();//ren8,9 \n" ); //$NON-NLS-1$
+ writer.write( " f->~Foo();//ren10 \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "Foo/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 10, changes );
+ assertChange( changes, file, contents.indexOf("Foo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo();//ren2"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo();//ren3"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo::Foo() {}//ren4,5"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo() {}//ren4,5"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo::~Foo() {}//ren6,7"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo() {}//ren6,7"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo *f=new Foo();//ren8,9"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo();//ren8,9"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo();//ren10"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testAttribute_54() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{ \n" ); //$NON-NLS-1$
+ writer.write( " static int att;//vp1,rn1 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Boo a; \n" ); //$NON-NLS-1$
+ writer.write( " a.att;//rn2 \n" ); //$NON-NLS-1$
+ writer.write( " Boo::att;//rn3 \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "att;//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 3, changes );
+ assertChange( changes, file, contents.indexOf("att;//vp1"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("att;//rn2"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("att;//rn3"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testClass_55() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " class Hoo{//vp1 \n" ); //$NON-NLS-1$
+ writer.write( " public: Hoo(); \n" ); //$NON-NLS-1$
+ writer.write( " }; \n" ); //$NON-NLS-1$
+ writer.write( " Foo(){ \n" ); //$NON-NLS-1$
+ writer.write( " Foo::Hoo h; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "Foo::Hoo::Hoo(){} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "Hoo{" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 5, changes );
+ assertChange( changes, file, contents.indexOf("Hoo{//vp1"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Hoo();"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Hoo h;"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Hoo::Hoo(){}"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Hoo(){}"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testClass_55_79231() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{};//vp1 \n" ); //$NON-NLS-1$
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " Foo() { \n" ); //$NON-NLS-1$
+ writer.write( " class Boo{}; \n" ); //$NON-NLS-1$
+ writer.write( " Boo t; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //defect is that the inner class defined in a method is also renamed, when it
+ // shouldn't be.
+ int offset = contents.indexOf( "Boo{};//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 1, changes );
+ assertChange( changes, file, contents.indexOf("Boo{};//vp1"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ public void testClass_55_72748() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{};//vp1 \n" ); //$NON-NLS-1$
+ writer.write( "void f(){ \n" ); //$NON-NLS-1$
+ writer.write( " Foo *somePtr; \n" ); //$NON-NLS-1$
+ writer.write( " if (somePtr == reinterpret_cast<Foo*>(0)){} \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //defect is that the Foo in <> is not renamed
+ int offset = contents.indexOf( "Foo{};//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 3, changes );
+ assertChange( changes, file, contents.indexOf("Foo{};//vp1"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo *somePtr"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo*>(0)"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testClass_56() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{};//vp1,rn1 \n" ); //$NON-NLS-1$
+ writer.write( "class Derived: public Foo{//rn2 \n" ); //$NON-NLS-1$
+ writer.write( " Derived():Foo(){}//rn3 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //defect is that the inner class defined in a method is also renamed, when it
+ // shouldn't be.
+ int offset = contents.indexOf( "Foo{};//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 3, changes );
+ assertChange( changes, file, contents.indexOf("Foo{};//vp1"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo{//rn2"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo(){}//rn3"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testAttribute_61() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " private: static int count;//vp1 \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "Foo.hh", header ); //$NON-NLS-1$
+ writer = new StringWriter();
+ writer.write( "#include \"Foo.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "int Foo::count=10; \n" ); //$NON-NLS-1$
+
+ String source = writer.toString();
+ IFile cpp = importFile( "Foo.cpp", source ); //$NON-NLS-1$
+ int offset = header.indexOf( "count" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, h, header.indexOf("count"), 5, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("count"), 5, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testEnumerator_62() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "enum Foo{E0, E1};//vp1 \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "Foo.hh", header ); //$NON-NLS-1$
+ writer = new StringWriter();
+ writer.write( "#include \"Foo.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " int i=E1; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String source = writer.toString();
+ IFile cpp=importFile( "Foo.cpp", source ); //$NON-NLS-1$
+ int offset = header.indexOf( "E1" ) ; //$NON-NLS-1$
+ getRefactorChanges(h, offset, "Ooga" ); //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, h, header.indexOf("E1"), 2, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("E1"), 2, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testAttribute_63() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " int att; \n" ); //$NON-NLS-1$
+ writer.write( " Foo(int i); \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "Foo.hh", header ); //$NON-NLS-1$
+ writer = new StringWriter();
+ writer.write( "#include \"Foo.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "Foo::Foo(int i): att(i) {} \n" ); //$NON-NLS-1$
+
+ String source = writer.toString();
+ IFile cpp = importFile( "Foo.cpp", source ); //$NON-NLS-1$
+ int offset = header.indexOf( "att" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, h, header.indexOf("att"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("att"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testAttribute_64() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " private: \n" ); //$NON-NLS-1$
+ writer.write( " int b;//vp1,rn1 \n" ); //$NON-NLS-1$
+ writer.write( " int m(int b) { \n" ); //$NON-NLS-1$
+ writer.write( " return b; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " int n() { \n" ); //$NON-NLS-1$
+ writer.write( " return b;//rn2 \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " int o() { \n" ); //$NON-NLS-1$
+ writer.write( " int b=2; \n" ); //$NON-NLS-1$
+ writer.write( " return b; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "Foo.hh", header ); //$NON-NLS-1$
+ int offset = header.indexOf( "b;//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, h, header.indexOf("b;//vp1"), 1, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, h, header.indexOf("b;//rn2"), 1, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testAttribute_65() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class A{ \n" ); //$NON-NLS-1$
+ writer.write( " int x(); \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "class B{ \n" ); //$NON-NLS-1$
+ writer.write( " friend class A; \n" ); //$NON-NLS-1$
+ writer.write( " private: \n" ); //$NON-NLS-1$
+ writer.write( " int att; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "Foo.hh", header ); //$NON-NLS-1$
+ writer = new StringWriter();
+ writer.write( "#include \"Foo.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "int A::x() { \n" ); //$NON-NLS-1$
+ writer.write( " B b; \n" ); //$NON-NLS-1$
+ writer.write( " int att=b.att; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ String source = writer.toString();
+ IFile cpp = importFile( "Foo.cpp", source ); //$NON-NLS-1$
+ int offset = header.indexOf( "att" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 2, changes );
+ assertChange( changes, h, header.indexOf("att"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, cpp, source.indexOf("att;"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+ public void testNamespace_66() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "namespace Foo/*vp1*/{ \n" ); //$NON-NLS-1$
+ writer.write( " namespace Baz/*vp2*/ { \n" ); //$NON-NLS-1$
+ writer.write( " int i; \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( " using namespace Baz; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Foo::i = 1; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //vp1 Foo with ref in function
+ int offset = contents.indexOf( "Foo/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("Foo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo::"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ //vp2 nested Baz with ref in using
+ offset = contents.indexOf( "Baz/*vp2*/" ) ; //$NON-NLS-1$
+ changes = getRefactorChanges(file, offset, "Wooga" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("Baz/*vp2*/"), 3, "Wooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Baz;"), 3, "Wooga" ); //$NON-NLS-1$//$NON-NLS-2$
+
+ }
+
+ public void testNamespace_66_79281() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "namespace Foo{ \n" ); //$NON-NLS-1$
+ writer.write( " int i; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ writer.write( "namespace Bar/*vp1*/ = Foo; \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " Bar::i = 1; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "Bar/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("Bar/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Bar::"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ public void testNamespace_66_79282() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "namespace Foo/*vp1*/{} \n" ); //$NON-NLS-1$
+ writer.write( "namespace Bar = Foo; \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //defect is Foo on line 2 is not renamed
+ int offset = contents.indexOf( "Foo/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "Ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, file, contents.indexOf("Foo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("Foo;"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testFunction_67() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "void foo/*vp1*/(){}//rn1 \n" ); //$NON-NLS-1$
+ writer.write( "void bar(){ \n" ); //$NON-NLS-1$
+ writer.write( " foo();//rn2 \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ writer.write( "namespace N{ \n" ); //$NON-NLS-1$
+ writer.write( " class A{ \n" ); //$NON-NLS-1$
+ writer.write( " A() {foo();}//rn3 \n" ); //$NON-NLS-1$
+ writer.write( " }; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "foo/*vp1*/" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, file, contents.indexOf("foo/*vp1*/"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("foo();//rn2"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("foo();}//rn3"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testVariable_68() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class A{ \n" ); //$NON-NLS-1$
+ writer.write( " public: int i; \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "A var;//vp1,rn1 \n" ); //$NON-NLS-1$
+ writer.write( "void f(){ \n" ); //$NON-NLS-1$
+ writer.write( " int j = ::var.i;//rn2 \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ writer.write( "class B{ \n" ); //$NON-NLS-1$
+ writer.write( " void g(){ \n" ); //$NON-NLS-1$
+ writer.write( " var.i=3;//rn3 \n" ); //$NON-NLS-1$
+ writer.write( " } \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "var;//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, file, contents.indexOf("var;//vp1"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("var.i;//rn2"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ assertChange( changes, file, contents.indexOf("var.i=3;//rn3"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ public void testVariable_68_79295() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "int var;//vp1 \n" ); //$NON-NLS-1$
+ writer.write( "void f(int var){ \n" ); //$NON-NLS-1$
+ writer.write( " int i = var; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ //defect is the argument and local variable var are incorrectly renamed
+ int offset = contents.indexOf( "var;//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(file, offset, "ooga" ); //$NON-NLS-1$
+ assertTotalChanges( 1, changes );
+ assertChange( changes, file, contents.indexOf("var;//vp1"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ //similar to test 92, except this one will continue with warning, or error status
+ //while case in 92 must stop refactor with fatal status
+ public void testClass_81_72620() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "union u_haul{}; \n" ); //$NON-NLS-1$
+ writer.write( "struct s_haul{}; \n" ); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "s_haul" ) ; //$NON-NLS-1$
+ try {
+ getRefactorChanges(file, offset, "u_haul" ); //$NON-NLS-1$
+ } catch (AssertionFailedError e) {
+ assertTrue(e.getMessage().startsWith("Input check on u_haul failed.")); //$NON-NLS-1$
+ return;
+ }
+ fail ("An error should have occurred in the input check."); //$NON-NLS-1$
+ }
+ public void testVariable_88_72617() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class A{}; \n" ); //$NON-NLS-1$
+ writer.write( "A a;//vp1 \n" ); //$NON-NLS-1$
+ String header = writer.toString();
+ IFile h = importFile( "Foo.hh", header ); //$NON-NLS-1$
+ writer = new StringWriter();
+ writer.write( "#include \"Foo.hh\" \n" ); //$NON-NLS-1$
+ writer.write( "void f() { \n" ); //$NON-NLS-1$
+ writer.write( " A a; \n" ); //$NON-NLS-1$
+ writer.write( "} \n" ); //$NON-NLS-1$
+ String source = writer.toString();
+ importFile( "Foo.cpp", source ); //$NON-NLS-1$
+ int offset = header.indexOf( "a;//vp1" ) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(h, offset, "ooga" ); //$NON-NLS-1$
+
+ assertTotalChanges( 1, changes );
+ assertChange( changes, h, header.indexOf("a;//vp1"), 1, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ //2 ways to test name collistion on same type:
+ //if you don't know the error message, catch on getRefactorChanges
+ //or if you want to verify a message or severity, use getRefactorMessages
+ //and getRefactorSeverity
+ public void testClass_92A() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class Boo{}; \n" ); //$NON-NLS-1$
+ writer.write( " void f() {} \n" ); //$NON-NLS-1$
+ writer.write( "}; \n" ); //$NON-NLS-1$
+ writer.write( "class Foo/*vp1*/{}; \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "Foo/*vp1*/" ) ; //$NON-NLS-1$
+ try {
+ getRefactorChanges(file, offset, "Boo" ); //$NON-NLS-1$
+ } catch (AssertionFailedError e) {
+ assertTrue(e.getMessage().startsWith("Input check on Boo failed.")); //$NON-NLS-1$
+ return;
+ }
+ fail ("An error or warning should have occurred in the input check."); //$NON-NLS-1$
+ }
+ public void testClass_92B() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write( "class A{}; \n" ); //$NON-NLS-1$
+ writer.write( "class B{};//vp1 \n" ); //$NON-NLS-1$
+
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "B{};//vp1" ) ; //$NON-NLS-1$
+
+ String[] messages = getRefactorMessages( file, offset, "A" ); //$NON-NLS-1$
+ assertEquals(1, messages.length);
+ assertEquals("A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: A \n" +
+ "Conflicting element type: Type", messages[0]); //$NON-NLS-1$
+ // assert that you cannot refactor because severity is FATAL (4)
+ int s = getRefactorSeverity(file, offset, "A"); //$NON-NLS-1$
+ assertEquals(RefactoringStatus.ERROR,s);
+ }
+
+ public void testRenameParticipant() throws Exception {
+ TestRenameParticipant.reset();
+ StringWriter writer = new StringWriter();
+ writer.write( "class A{}; " ); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$
+ int offset = contents.indexOf( "A" ) ; //$NON-NLS-1$
+ getRefactorChanges(file, offset, "B"); //$NON-NLS-1$
+ assertEquals(1, TestRenameParticipant.getConditionCheckCount());
+ assertEquals(1, TestRenameParticipant.getCreateChangeCount());
+ Object element= TestRenameParticipant.getElement();
+
+ assertNotNull(element);
+ assertTrue(element instanceof IBinding);
+ IBinding binding= (IBinding) element;
+ assertEquals(binding.getName(), "A"); //$NON-NLS-1$
+
+ RenameArguments args= TestRenameParticipant.staticGetArguments();
+ assertNotNull(args);
+ assertEquals("B", args.getNewName()); //$NON-NLS-1$
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTemplatesTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTemplatesTests.java
new file mode 100644
index 00000000000..b8852a6c92e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTemplatesTests.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 Wind River Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import java.io.StringWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+/**
+ * @author markus.schorn@windriver.com
+ */
+public class RenameTemplatesTests extends RenameTests {
+
+ public RenameTemplatesTests(String name) {
+ super(name);
+ }
+ public static Test suite(){
+ return suite(true);
+ }
+ public static Test suite( boolean cleanup ) {
+ TestSuite suite = new TestSuite(RenameTemplatesTests.class);
+ if (cleanup) {
+ suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
+ }
+ return suite;
+ }
+
+
+ public void testClassTemplate() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("template <class Type> \n"); //$NON-NLS-1$
+ writer.write("class Array { \n"); //$NON-NLS-1$
+ writer.write("public: \n"); //$NON-NLS-1$
+ writer.write(" Array(unsigned sz) {} \n"); //$NON-NLS-1$
+ writer.write(" ~Array(){} \n"); //$NON-NLS-1$
+ writer.write(" Type& operator[] (unsigned idx); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("template <class Type> \n"); //$NON-NLS-1$
+ writer.write("inline Type& Array<Type>::operator[] (unsigned index) {\n"); //$NON-NLS-1$
+ writer.write(" return 1; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("Array"); //$NON-NLS-1$
+
+ RefactoringStatus stat= checkConditions(cpp, offset1, "WELT"); //$NON-NLS-1$
+ assertRefactoringOk(stat);
+
+ Change ch= getRefactorChanges(cpp, offset1, "WELT"); //$NON-NLS-1$
+ assertTotalChanges(4, ch);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTests.java
new file mode 100644
index 00000000000..d4d4adfe91a
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTests.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Wind River Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.RefactoringStatusEntry;
+
+import org.eclipse.cdt.internal.ui.refactoring.rename.CRefactoringArgument;
+import org.eclipse.cdt.internal.ui.refactoring.rename.CRefactory;
+import org.eclipse.cdt.internal.ui.refactoring.rename.CRenameProcessor;
+import org.eclipse.cdt.internal.ui.refactoring.rename.CRenameRefactoring;
+import org.eclipse.cdt.internal.ui.refactoring.rename.TextSearchWrapper;
+
+/**
+ * @author markus.schorn@windriver.com
+ */
+public class RenameTests extends RefactoringTests {
+
+ public RenameTests(String name) {
+ super(name);
+ }
+
+ public RenameTests() {
+ }
+
+ /**
+ * @param element The CElement to rename
+ * @param newName The new name for the element
+ * @return
+ * @throws Exception
+ */
+ public Change getRefactorChanges(IFile file, int offset, String newName) throws Exception {
+ CRenameRefactoring proc = createRefactoring(file, offset, newName);
+
+ RefactoringStatus rs = checkConditions(proc);
+ if (!rs.hasError()) {
+ Change change = proc.createChange( new NullProgressMonitor() );
+ return change;
+ }
+
+ fail ("Input check on "+ newName + " failed. "+rs.getEntryMatchingSeverity(RefactoringStatus.ERROR) ); //$NON-NLS-1$ //$NON-NLS-2$
+ //rs.getFirstMessage(RefactoringStatus.ERROR) is not the message displayed in
+ //the UI for renaming a method to a constructor, the first message which is only
+ //a warning is shown in the UI. If you click preview, then the error and the warning
+ //is shown.
+ return null;
+ }
+
+ private CRenameRefactoring createRefactoring(IFile file, int offset, String newName) {
+ CRefactoringArgument arg= new CRefactoringArgument(file, offset, 0);
+ CRenameProcessor proc= new CRenameProcessor(CRefactory.getInstance(), arg);
+ proc.setReplacementText( newName );
+ proc.setSelectedOptions(-1);
+ proc.setScope(TextSearchWrapper.SCOPE_WORKSPACE);
+ return new CRenameRefactoring(proc);
+ }
+
+ public String[] getRefactorMessages(IFile file, int offset, String newName) throws Exception {
+ String[] result;
+ CRenameRefactoring proc = createRefactoring(file, offset, newName);
+ RefactoringStatus rs = checkConditions(proc);
+ if (!rs.hasWarning()){
+ fail ("Input check on "+ newName + " passed. There should have been warnings or errors. ") ; //$NON-NLS-1$ //$NON-NLS-2$
+ return null;
+ }
+ RefactoringStatusEntry[] rse = rs.getEntries();
+ result = new String[rse.length];
+ for (int i=0; i< rse.length; i++){
+ RefactoringStatusEntry entry = rse[i];
+ result[i]=entry.getMessage();
+
+ }
+ return result;
+ }
+
+ public RefactoringStatus checkConditions(IFile file, int offset, String newName) throws Exception {
+ CRenameRefactoring proc = createRefactoring(file, offset, newName);
+ return checkConditions(proc);
+ }
+
+ private RefactoringStatus checkConditions(CRenameRefactoring proc) throws CoreException {
+ RefactoringStatus rs =proc.checkInitialConditions(new NullProgressMonitor() );
+ if (!rs.hasError()){
+ rs= proc.checkFinalConditions(new NullProgressMonitor());
+ }
+ return rs;
+ }
+
+ public int getRefactorSeverity(IFile file, int offset, String newName) throws Exception {
+ CRenameRefactoring proc = createRefactoring(file, offset, newName);
+ RefactoringStatus rs = checkConditions(proc);
+
+ return (rs.getSeverity());
+ }
+
+ protected int countOccurrences(String contents, String lookup) {
+ int idx= contents.indexOf(lookup);
+ int count= 0;
+ while (idx >=0) {
+ count++;
+ idx= contents.indexOf(lookup, idx+lookup.length());
+ }
+ return count;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java
new file mode 100644
index 00000000000..01c23f6a7cf
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTypeTests.java
@@ -0,0 +1,2298 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2007 Wind River Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import java.io.StringWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+/**
+ * @author markus.schorn@windriver.com
+ */
+public class RenameTypeTests extends RenameTests {
+
+ public RenameTypeTests(String name) {
+ super(name);
+ }
+ public static Test suite(){
+ return suite(true);
+ }
+ public static Test suite( boolean cleanup ) {
+ TestSuite suite = new TestSuite(RenameTypeTests.class);
+ if (cleanup) {
+ suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
+ }
+ return suite;
+ }
+
+
+ public void testClassNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("class v1 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("class v2 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("class v3 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("class v4 { \n"); //$NON-NLS-1$
+ writer.write(" int function(); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("int v4::function(){} \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+ int offset4= contents.indexOf("v4"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset4, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testNamespaceNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("namespace v4 { \n"); //$NON-NLS-1$
+ writer.write(" int function(); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("namespace v1 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("namespace v2 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("namespace v3 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("int v4::function(){} \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+ int offset4= contents.indexOf("v4"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset4, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testStructNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("struct v4 { \n"); //$NON-NLS-1$
+ writer.write(" int function(); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("struct v1 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("struct v2 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("struct v3 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("int v4::function(){} \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+ int offset4= contents.indexOf("v4"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset4, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testStructNameConflictsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("struct v1 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("struct v2 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("struct v3 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ }
+
+ public void testUnionNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("union v4 { \n"); //$NON-NLS-1$
+ writer.write(" int function(); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("union v1 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("union v2 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("union v3 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("int v4::function(){} \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3::v++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+ int offset4= contents.indexOf("v4"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset4, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset4, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset4, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testUnionNameConflictsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("union v1 { \n"); //$NON-NLS-1$
+ writer.write(" int v; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("union v1 vv1; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; vv1.v++; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ }
+
+ public void testEnumNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("enum v1 { \n"); //$NON-NLS-1$
+ writer.write(" v11 \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("enum v2 { \n"); //$NON-NLS-1$
+ writer.write(" v22 \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("enum v3 { \n"); //$NON-NLS-1$
+ writer.write(" v33 \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1 v; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2 v; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3 v; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testEnumNameConflictsPlainC() throws Exception {
+ createCppFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCppDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("enum v1 { \n"); //$NON-NLS-1$
+ writer.write(" v11 \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("enum v2 { \n"); //$NON-NLS-1$
+ writer.write(" v22 \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("enum v3 { \n"); //$NON-NLS-1$
+ writer.write(" v33 \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; enum v1 v; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testTypedefNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("typedef int v1; \n"); //$NON-NLS-1$
+ writer.write("typedef long v2; \n"); //$NON-NLS-1$
+ writer.write("typedef struct {int a;} v3; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1 v; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2 v; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3 v; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringWarning(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: namespace_def \n" +
+ "Conflicting element type: Namespace"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testTypedefNameConflictsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("typedef int v1; \n"); //$NON-NLS-1$
+ writer.write("typedef long v2; \n"); //$NON-NLS-1$
+ writer.write("typedef struct {int a;} v3; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1 v; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings colliding with types.
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_fwd \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: struct_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: union_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: typedef_def \n" +
+ "Conflicting element type: Type"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testRenameClass() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("class String \n"); //$NON-NLS-1$
+ writer.write("{ \n"); //$NON-NLS-1$
+ writer.write("public: \n"); //$NON-NLS-1$
+ writer.write(" String(); \n"); //$NON-NLS-1$
+ writer.write(" String(const String &other); \n"); //$NON-NLS-1$
+ writer.write(" ~String(); \n"); //$NON-NLS-1$
+ writer.write(" String &operator=( const String &other ); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write(" String::String(){} \n"); //$NON-NLS-1$
+ writer.write(" String::String(const String &other){}; \n"); //$NON-NLS-1$
+ writer.write(" String::~String(){}; \n"); //$NON-NLS-1$
+ writer.write(" String& String::operator=( const String &other ) \n"); //$NON-NLS-1$
+ writer.write(" {return *this;} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("String"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "CString"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ Change ch= getRefactorChanges(cpp, offset1, "CString"); //$NON-NLS-1$
+ assertTotalChanges(countOccurrences(contents, "String"), ch); //$NON-NLS-1$
+ }
+
+ public void testBug72888() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("class MyEx {}; \n"); //$NON-NLS-1$
+ writer.write("void someFunc() { \n"); //$NON-NLS-1$
+ writer.write(" throw MyEx(); \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("int main(){ \n"); //$NON-NLS-1$
+ writer.write(" try{ \n"); //$NON-NLS-1$
+ writer.write(" someFunc(); \n"); //$NON-NLS-1$
+ writer.write(" } catch(MyEx &e) {} \n"); //$NON-NLS-1$
+ writer.write(" return 0; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset = contents.indexOf("MyEx") ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset, "xx"); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameVariableTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameVariableTests.java
new file mode 100644
index 00000000000..b4d643c21a8
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameVariableTests.java
@@ -0,0 +1,1999 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2007 Wind River Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import java.io.StringWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+/**
+ * @author markus.schorn@windriver.com
+ */
+public class RenameVariableTests extends RenameTests {
+
+ public RenameVariableTests(String name) {
+ super(name);
+ }
+ public static Test suite(){
+ return suite(true);
+ }
+ public static Test suite( boolean cleanup ) {
+ TestSuite suite = new TestSuite(RenameVariableTests.class);
+
+ if (cleanup) {
+ suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$
+ }
+ return suite;
+ }
+
+ public void testLocalNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("void f(int par1) { \n"); //$NON-NLS-1$
+ writer.write(" int v1, x1; \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" int v2; \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" int v3; \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("x1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w2 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par2 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w3 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par3 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings depending on scope
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+// lookup inside a static method also returns non-static members
+// we may want to have a check whether a binding is accessible or not.
+
+// status= checkConditions(cpp, offset3, "member"); //$NON-NLS-1$
+// assertRefactoringOk(status);
+// status= checkConditions(cpp, offset3, "method"); //$NON-NLS-1$
+// assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testLocalNameConflictsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("void f(int par1) { \n"); //$NON-NLS-1$
+ writer.write(" int v1, x1, w1; \n"); //$NON-NLS-1$
+ writer.write(" w1++; v1++; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.c", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("x1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ }
+
+
+ public void testParameterNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("void f(int par1, int v1) {\n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2, int v2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3, int v3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w2 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: par2 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w3 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: par3 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings depending on scope
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+// lookup inside a static method also returns non-static members
+// we may want to have a check whether a binding is accessible or not.
+
+// status= checkConditions(cpp, offset3, "member"); //$NON-NLS-1$
+// assertRefactoringOk(status);
+// status= checkConditions(cpp, offset3, "method"); //$NON-NLS-1$
+// assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testParameterNameConflictsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("void f(int par1, int v1) {\n"); //$NON-NLS-1$
+ writer.write(" int w1; v1++; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile c= importFile("test.c", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(c, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(c, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(c, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(c, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings that are ok.
+ status= checkConditions(c, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testVaribleNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("int v1, v2, v3; \n"); //$NON-NLS-1$
+ writer.write("static int s1; \n"); //$NON-NLS-1$
+ writer.write("static int s2; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; v3++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "static int static_other_file; \n" ); //$NON-NLS-1$
+ importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$
+
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w2 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par2 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w3 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par3 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings depending on scope
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+// lookup inside a static method also returns non-static members
+// we may want to have a check whether a binding is accessible or not.
+
+// status= checkConditions(cpp, offset3, "member"); //$NON-NLS-1$
+// assertRefactoringOk(status);
+// status= checkConditions(cpp, offset3, "method"); //$NON-NLS-1$
+// assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ // would be good to see an error here
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ // would be good to see an error here
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // file static stuff
+ status= checkConditions(cpp, contents.indexOf("s1"), "s2"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: s2 \n" +
+ "Conflicting element type: File static variable"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, contents.indexOf("s1"), "static_other_file"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ }
+
+ public void testVaribleNameConflictsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("int v1; \n"); //$NON-NLS-1$
+ writer.write("static int s1; \n"); //$NON-NLS-1$
+ writer.write("static int s2; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1++; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile c= importFile("test.c", contents ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "static int static_other_file; \n" ); //$NON-NLS-1$
+ importFile( "other.c", writer.toString() ); //$NON-NLS-1$
+
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(c, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(c, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(c, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(c, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(c, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // file static stuff
+ status= checkConditions(c, contents.indexOf("s1"), "s2"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: s2 \n" +
+ "Conflicting element type: File static variable"); //$NON-NLS-1$
+
+ status= checkConditions(c, contents.indexOf("s1"), "static_other_file"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ }
+
+ public void testEnumeratorNameConflicts() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("enum E {v1, v2, v3}; \n"); //$NON-NLS-1$
+ writer.write("static int s1; \n"); //$NON-NLS-1$
+ writer.write("static int s2; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1=v1; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2=v2; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3=v3; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "static int static_other_file; \n" ); //$NON-NLS-1$
+ importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$
+
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w2 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par2 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w3 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par3 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings depending on scope
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ // would be good to see an error here
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ // would be good to see an error here
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def_ov \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+
+ // renamings that are ok.
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: class_def \n" +
+ "Conflicting element type: Constructor"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // file static stuff
+ status= checkConditions(cpp, contents.indexOf("s1"), "s2"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: s2 \n" +
+ "Conflicting element type: File static variable"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, contents.indexOf("s1"), "static_other_file"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringOk(status);
+ }
+
+ public void testEnumeratorNameConflictsPlainC() throws Exception {
+ createCFwdDecls("c_fwd.h"); //$NON-NLS-1$
+ createCDefs("c_def.h"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"c_fwd.h\" \n"); //$NON-NLS-1$
+ writer.write("#include \"c_def.h\" \n"); //$NON-NLS-1$
+ writer.write("enum E {v1, v2, v3}; \n"); //$NON-NLS-1$
+ writer.write("static int s1; \n"); //$NON-NLS-1$
+ writer.write("static int s2; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" int w1=v1; \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile c= importFile("test.c", contents ); //$NON-NLS-1$
+
+ writer = new StringWriter();
+ writer.write( "static int static_other_file; \n" ); //$NON-NLS-1$
+ importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$
+
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(c, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(c, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+ status= checkConditions(c, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ // renamings conflicting with global stuff.
+ status= checkConditions(c, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_proto \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+ status= checkConditions(c, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: func_def \n" +
+ "Conflicting element type: Global function"); //$NON-NLS-1$
+
+ status= checkConditions(c, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(c, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testMemberNameConflicts1() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("class Dummy { \n"); //$NON-NLS-1$
+ writer.write(" int v1, v2, v3; \n"); //$NON-NLS-1$
+ writer.write(" int member; \n"); //$NON-NLS-1$
+ writer.write(" int method(int); \n"); //$NON-NLS-1$
+ writer.write(" static int static_method(int); \n"); //$NON-NLS-1$
+ writer.write(" static int static_member; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("void Dummy::method(int par1) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; v1++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void Dummy::static_method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; v2++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w1 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("w1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, contents.indexOf("par1"), "v1"); //$NON-NLS-1$ //$NON-NLS-2$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: v1 \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par1 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: w2 \n" +
+ "Conflicting element type: Local variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: par2 \n" +
+ "Conflicting element type: Parameter"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: extern_var \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: var_def \n" +
+ "Conflicting element type: Global variable"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Shadowing \n" +
+ "New element: enum_item \n" +
+ "Conflicting element type: Enumerator"); //$NON-NLS-1$
+
+
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: static_member \n" +
+ "Conflicting element type: Field"); //$NON-NLS-1$
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
+ "Type of problem: Redeclaration \n" +
+ "New element: static_method \n" +
+ "Conflicting element type: Method"); //$NON-NLS-1$
+ }
+
+ public void testMemberNameConflicts2() throws Exception {
+ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
+ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
+ StringWriter writer = new StringWriter();
+ writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
+ writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
+ writer.write("class Dummy { \n"); //$NON-NLS-1$
+ writer.write(" int v1, v2, v3; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("Dummy d; \n"); //$NON-NLS-1$
+ writer.write("void f(int par1){ \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w1; d.v1++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void class_def::method(int par2) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w2; d.v2++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("static void class_def::static_method(int par3) { \n"); //$NON-NLS-1$
+ writer.write(" { \n"); //$NON-NLS-1$
+ writer.write(" int w3; d.v3++; \n"); //$NON-NLS-1$
+ writer.write(" } \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset1= contents.indexOf("v1"); //$NON-NLS-1$
+ int offset2= contents.indexOf("v2"); //$NON-NLS-1$
+ int offset3= contents.indexOf("v3"); //$NON-NLS-1$
+
+ // conflicting renamings
+ RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "w2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "par2"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "w3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "par3"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "extern_var"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "var_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_item"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ // renamings depending on scope
+ status= checkConditions(cpp, offset1, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "static_method"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset1, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_proto_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "func_def_ov"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "class_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset1, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset2, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "class_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset2, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+
+ status= checkConditions(cpp, offset3, "class_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_fwd"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "class_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "struct_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "union_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "enum_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "typedef_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "namespace_def"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "st_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ status= checkConditions(cpp, offset3, "un_member"); //$NON-NLS-1$
+ assertRefactoringOk(status);
+ }
+
+ public void testReferenceViaMacro() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("#define PASSON(x) (x) \n"); //$NON-NLS-1$
+ writer.write("#define INC(x) PASSON(/*pc*/x)++ \n"); //$NON-NLS-1$
+ writer.write("void f() { \n"); //$NON-NLS-1$
+ writer.write(" int v1; \n"); //$NON-NLS-1$
+ writer.write(" INC(/*comment*/ v1); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset = contents.indexOf("v1") ; //$NON-NLS-1$
+ int offset2= contents.indexOf("v1", offset+1) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset2, "z"); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, cpp, offset, 2, "z" ); //$NON-NLS-1$
+ assertChange( changes, cpp, offset2, 2, "z" ); //$NON-NLS-1$
+ }
+
+ public void testReferenceViaMacro2() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("#define INC(x,y) x+=y \n"); //$NON-NLS-1$
+ writer.write("void f() { \n"); //$NON-NLS-1$
+ writer.write(" int v1,v2; \n"); //$NON-NLS-1$
+ writer.write(" INC(v2,v1); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset = contents.indexOf("v1") ; //$NON-NLS-1$
+ int offset2= contents.indexOf("v1", offset+1) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset2, "z"); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, cpp, offset, 2, "z" ); //$NON-NLS-1$
+ assertChange( changes, cpp, offset2, 2, "z" ); //$NON-NLS-1$
+ }
+
+ public void testReferenceViaMacro3() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("#define INC(x,y) x+=y \n"); //$NON-NLS-1$
+ writer.write("void f() { \n"); //$NON-NLS-1$
+ writer.write(" int v1,v2; \n"); //$NON-NLS-1$
+ writer.write(" INC(v1,v1); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset = contents.indexOf("v1") ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
+ assertTotalChanges( 3, changes );
+ assertChange( changes, cpp, offset, 2, "z" ); //$NON-NLS-1$
+ offset= contents.indexOf("v1", offset+1) ; //$NON-NLS-1$
+ assertChange( changes, cpp, offset, 2, "z" ); //$NON-NLS-1$
+ offset= contents.indexOf("v1", offset+1) ; //$NON-NLS-1$
+ assertChange( changes, cpp, offset, 2, "z" ); //$NON-NLS-1$
+ }
+
+ public void testReferenceViaMacro4() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("#define INC(x) v2++ \n"); //$NON-NLS-1$
+ writer.write("void f() { \n"); //$NON-NLS-1$
+ writer.write(" int v1; \n"); //$NON-NLS-1$
+ writer.write(" INC(v1); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset = contents.indexOf("v1") ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
+ assertTotalChanges( 1, 1, 0, changes );
+ assertChange( changes, cpp, offset, 2, "z" ); //$NON-NLS-1$
+ }
+
+ public void testReferenceViaMacro5() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("#define INC(x) v1++ \n"); //$NON-NLS-1$
+ writer.write("void f() { \n"); //$NON-NLS-1$
+ writer.write(" int v1,v2; \n"); //$NON-NLS-1$
+ writer.write(" INC(v2); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ writer.write("void f2() { \n"); //$NON-NLS-1$
+ writer.write(" int v12; \n"); //$NON-NLS-1$
+ writer.write(" INC(v12); \n"); //$NON-NLS-1$
+ writer.write("} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset = contents.indexOf("v1") ; //$NON-NLS-1$
+ offset= contents.indexOf("v1", offset+1) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
+ assertTotalChanges( 1, changes );
+ assertChange( changes, cpp, offset, 2, "z" ); //$NON-NLS-1$
+ }
+
+ public void testBug72646() throws Exception {
+ StringWriter writer = new StringWriter();
+ writer.write("class C2: public C1 { \n"); //$NON-NLS-1$
+ writer.write(" C2(int x, int y); \n"); //$NON-NLS-1$
+ writer.write(" int y; \n"); //$NON-NLS-1$
+ writer.write("}; \n"); //$NON-NLS-1$
+ writer.write("C2::C2(int x, int y) \n"); //$NON-NLS-1$
+ writer.write(" :C1(x), y(y) {} \n"); //$NON-NLS-1$
+ String contents = writer.toString();
+ IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$
+
+ int offset = contents.indexOf("y") ; //$NON-NLS-1$
+ offset= contents.indexOf("y", offset+1) ; //$NON-NLS-1$
+ Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
+ assertTotalChanges( 2, changes );
+ assertChange( changes, cpp, offset, 1, "z" ); //$NON-NLS-1$
+ offset= contents.indexOf("y", offset+1) ; //$NON-NLS-1$
+ offset= contents.indexOf("y", offset+1) ; //$NON-NLS-1$
+ assertChange( changes, cpp, offset, 1, "z" ); //$NON-NLS-1$
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/TestRenameParticipant.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/TestRenameParticipant.java
new file mode 100644
index 00000000000..997526c7ae2
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/TestRenameParticipant.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Wind River Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Markus Schorn - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.cdt.ui.tests.refactoring.rename;
+
+import org.eclipse.core.runtime.*;
+import org.eclipse.ltk.core.refactoring.*;
+import org.eclipse.ltk.core.refactoring.participants.*;
+
+public class TestRenameParticipant extends RenameParticipant {
+ private static Object sElement= null;
+ private static RenameArguments sArguments= null;
+ private static int sConditionCheck= 0;
+ private static int sCreateChange= 0;
+
+ public static int getConditionCheckCount() {
+ return sConditionCheck;
+ }
+
+ public static int getCreateChangeCount() {
+ return sCreateChange;
+ }
+
+ public static Object getElement() {
+ return sElement;
+ }
+
+ public static RenameArguments staticGetArguments() {
+ return sArguments;
+ }
+
+ public static void reset() {
+ sElement= null;
+ sArguments= null;
+ sConditionCheck= sCreateChange= 0;
+ }
+
+ protected boolean initialize(Object element) {
+ sElement= element;
+ return true;
+ }
+
+ public String getName() {
+ return "TestRenameParticipant"; //$NON-NLS-1$
+ }
+
+ public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
+ sConditionCheck++;
+ sArguments= getArguments();
+ return new RefactoringStatus();
+ }
+
+ public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ sCreateChange++;
+ return null;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/CorrectCaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/CorrectCaseTest.java
new file mode 100644
index 00000000000..a3ae5735ec6
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/CorrectCaseTest.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.utils;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class CorrectCaseTest extends TestCase {
+
+ public CorrectCaseTest(){
+ super("Check Correct Identifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void runTest() {
+ IdentifierResult result;
+
+ result = IdentifierHelper.checkIdentifierName("A"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("Z"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("a"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("z"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("_"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("_A"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("_Z"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("_a"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("_z"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("__"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("_0"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("_9"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("Aaaa"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("Zaaa"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("aaaa"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("zaaa"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("_aaa"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.VALID == result.getResult());
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DigitFirstCaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DigitFirstCaseTest.java
new file mode 100644
index 00000000000..3367c6b5790
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/DigitFirstCaseTest.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.utils;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class DigitFirstCaseTest extends TestCase {
+
+ public DigitFirstCaseTest() {
+ super("Check Digit First Identifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void runTest() {
+ IdentifierResult result;
+
+ result = IdentifierHelper.checkIdentifierName("0"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.DIGIT_FIRST == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("9"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.DIGIT_FIRST == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("0a"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.DIGIT_FIRST == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("99"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.DIGIT_FIRST == result.getResult());
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/EmptyCaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/EmptyCaseTest.java
new file mode 100644
index 00000000000..bbb5c2a1ae6
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/EmptyCaseTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.utils;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class EmptyCaseTest extends TestCase {
+
+ public EmptyCaseTest() {
+ super("Check Empty Identifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void runTest() {
+ IdentifierResult result;
+
+ result = IdentifierHelper.checkIdentifierName(""); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.EMPTY == result.getResult());
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java
new file mode 100644
index 00000000000..33e7bec0993
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.utils;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class IdentifierHelperTest extends TestSuite {
+
+ public IdentifierHelperTest() {
+ super("Identifier Helper Test"); //$NON-NLS-1$
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for Identifier Helper"); //$NON-NLS-1$
+ suite.addTest(new CorrectCaseTest());
+ suite.addTest(new DigitFirstCaseTest());
+ suite.addTest(new EmptyCaseTest());
+ suite.addTest(new IllegalCharCaseTest());
+ suite.addTest(new KeywordCaseTest());
+ return suite;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IllegalCharCaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IllegalCharCaseTest.java
new file mode 100644
index 00000000000..0b6d2f557e3
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IllegalCharCaseTest.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.utils;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class IllegalCharCaseTest extends TestCase {
+
+ public IllegalCharCaseTest() {
+ super("Check Illegal Character Identifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void runTest() {
+ IdentifierResult result;
+
+ result = IdentifierHelper.checkIdentifierName("a~"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.ILLEGAL_CHARACTER == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("a%"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.ILLEGAL_CHARACTER == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("a!"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.ILLEGAL_CHARACTER == result.getResult());
+
+ result = IdentifierHelper.checkIdentifierName("{}"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.ILLEGAL_CHARACTER == result.getResult());
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/KeywordCaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/KeywordCaseTest.java
new file mode 100644
index 00000000000..8cfd6feea5c
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/KeywordCaseTest.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.utils;
+
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class KeywordCaseTest extends TestCase {
+
+ public KeywordCaseTest() {
+ super("Check Keyword Identifier"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void runTest() {
+ IdentifierResult result;
+
+ result = IdentifierHelper.checkIdentifierName("using"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("bitand"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("for"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("const_cast"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("namespace"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("break"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("static_cast"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("false"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("volatile"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("template"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("else"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("dynamic_cast"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("static"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("or"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("not_eq"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("class"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("enum"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("typedef"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("restrict"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("and"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("reinterpret_cast"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("not"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("default"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("explicit"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("sizeof"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("auto"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("case"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("this"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("try"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("friend"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("asm"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("virtual"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("const"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("or_eq"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("catch"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("switch"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("goto"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("while"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("private"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("throw"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("protected"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("struct"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("if"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("extern"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("union"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("typeid"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("inline"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("compl"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("delete"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("do"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("xor"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("export"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("bitor"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("return"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("true"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("operator"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("register"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("new"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("and_eq"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("typename"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("continue"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("mutable"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("xor_eq"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+ result = IdentifierHelper.checkIdentifierName("public"); //$NON-NLS-1$
+ assertTrue(result.getMessage(), IdentifierResult.KEYWORD == result.getResult());
+
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/TranslationUnitHelperTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/TranslationUnitHelperTest.java
new file mode 100644
index 00000000000..7c99fcdf1c9
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/TranslationUnitHelperTest.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.utils;
+
+import java.util.Properties;
+import java.util.Vector;
+
+import org.eclipse.core.resources.IFile;
+
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.ui.tests.refactoring.RefactoringTest;
+import org.eclipse.cdt.ui.tests.refactoring.TestSourceFile;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.TranslationUnitHelper;
+
+/**
+ * @author Mirko Stocker
+ *
+ */
+public class TranslationUnitHelperTest extends RefactoringTest {
+
+ private int offset;
+
+ public TranslationUnitHelperTest(String name,Vector<TestSourceFile> files) {
+ super(name, files);
+ }
+
+ @Override
+ protected void runTest() throws Throwable {
+ IFile file = project.getFile(fileName);
+ IASTTranslationUnit unit = TranslationUnitHelper.loadTranslationUnit(file);
+ IASTNode firstNode = TranslationUnitHelper.getFirstNode(unit);
+ assertEquals(offset, firstNode.getNodeLocations()[0].getNodeOffset());
+ }
+
+ @Override
+ protected void configureRefactoring(Properties refactoringProperties) {
+ String offsetKind = (System.getProperty("line.separator").equals("\n")) ? "offset_unix" : "offset_win"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ offset = new Integer(refactoringProperties.getProperty(offsetKind, "0")).intValue(); //$NON-NLS-1$
+ }
+}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java
new file mode 100644
index 00000000000..b7270e19e01
--- /dev/null
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/UtilTestSuite.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Rapperswil, University of applied sciences and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Institute for Software - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.ui.tests.refactoring.utils;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.ui.tests.refactoring.RefactoringTester;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class UtilTestSuite {
+
+ public static Test suite() throws Exception {
+ TestSuite suite = new TestSuite("UtilTests"); //$NON-NLS-1$
+ suite.addTest(IdentifierHelperTest.suite());
+ suite.addTest(RefactoringTester.suite("TranslationUnitHelperTest", "resources/refactoring/TranslationunitHelper.rts")); //$NON-NLS-1$ //$NON-NLS-2$
+ return suite;
+ }
+}

Back to the top