Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java6
-rw-r--r--core/org.eclipse.cdt.core/META-INF/MANIFEST.MF14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ICTextFileChangeFactory.java26
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/CTextFileChange.java223
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java5
-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
-rw-r--r--core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF14
-rw-r--r--core/org.eclipse.cdt.ui/plugin.properties19
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml92
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java6
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java85
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java19
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java8
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java9
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java2
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java15
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties5
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java76
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java10
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/AddDeclarationNodeToClassChange.java133
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java425
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CTextFileChangeFactory.java29
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Container.java34
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CreateFileChange.java119
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/DeleteFileChange.java105
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/DocumentAdapter.java493
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java46
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/MethodContext.java202
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/ModificationCollector.java69
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java52
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner.java42
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/UndoCTextFileChange.java89
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Visibility.java92
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/CTextEditChangePreviewViewer.java265
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/CreateFileChangePreview.java86
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ExtractInputPage.java95
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/LabeledTextField.java60
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/Messages.java34
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/NameAndVisibilityComposite.java73
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/VisibilitySelectionPanel.java96
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/messages.properties17
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoring.java365
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringRunner.java61
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/ExtractConstantRefactoringWizard.java37
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/InputPage.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/Messages.java37
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractconstant/messages.properties21
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/messages.properties29
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTManager.java1496
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTNameVisitor.java95
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/ASTSpecificNameVisitor.java45
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringArgument.java191
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringMatch.java92
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringMatchStore.java123
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringUtils.java40
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactory.java161
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameClassProcessor.java63
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameGlobalProcessor.java26
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameIncludeProcessor.java32
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameLocalProcessor.java87
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMacroProcessor.java49
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMethodProcessor.java93
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessor.java290
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessorDelegate.java316
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameRefactoring.java32
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameRefactoringInputPage.java559
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameRefactoringWizard.java31
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameTypeProcessor.java21
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/Messages.java31
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/TextSearchWrapper.java363
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/messages.properties96
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/EclipseObjects.java145
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/FileContentHelper.java101
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/FileHelper.java77
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/IdentifierHelper.java85
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/IdentifierResult.java49
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/Messages.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/OffsetHelper.java97
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/TranslationUnitHelper.java92
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/VisibilityEnum.java80
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/utils/messages.properties21
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/Messages.java5
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THViewPart.java66
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/messages.properties4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/folderwizard/NewFolderWizardMessages.properties5
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CUIPlugin.java7
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/CTextFileChange.java102
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/CRefactoringActionGroup.java266
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/CRenameAction.java53
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/ExtractConstantAction.java52
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/Messages.java27
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/RefactoringAction.java79
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/refactoring/actions/messages.properties13
-rw-r--r--releng/org.eclipse.cdt-feature/feature.xml7
-rw-r--r--releng/org.eclipse.cdt.releng/build.xml6
-rw-r--r--releng/org.eclipse.cdt.releng/maps/cdt.map2
-rw-r--r--releng/org.eclipse.cdt.testing-feature/feature.xml7
132 files changed, 18106 insertions, 415 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java
index 95d96c18276..287ecc73416 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/rewrite/changegenerator/ChangeGeneratorTest.java
@@ -19,13 +19,13 @@ import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.parser.tests.rewrite.TestHelper;
import org.eclipse.cdt.core.tests.BaseTestFramework;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
-import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.CTextFileChange;
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.Document;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
public abstract class ChangeGeneratorTest extends BaseTestFramework {
@@ -63,8 +63,8 @@ public abstract class ChangeGeneratorTest extends BaseTestFramework {
changegenartor.generateChange(unit);
Document doc = new Document(source);
for(Change curChange : ((CompositeChange)changegenartor.getChange()).getChildren()){
- if (curChange instanceof CTextFileChange) {
- CTextFileChange textChange = (CTextFileChange) curChange;
+ if (curChange instanceof TextFileChange) {
+ TextFileChange textChange = (TextFileChange) curChange;
textChange.getEdit().apply(doc);
}
}
diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
index 61acc88498b..3a60c567de9 100644
--- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
@@ -42,11 +42,11 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.browser.util;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.cdtvariables;x-internal:=true,
- org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
- org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.refactoring",
- org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.refactoring",
- org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
- org.eclipse.cdt.internal.core.dom.rewrite;x-friends:="org.eclipse.cdt.core.tests",
+ org.eclipse.cdt.internal.core.dom;x-friends:="org.eclipse.cdt.ui",
+ org.eclipse.cdt.internal.core.dom.parser;x-friends:="org.eclipse.cdt.ui",
+ org.eclipse.cdt.internal.core.dom.parser.c;x-friends:="org.eclipse.cdt.ui",
+ org.eclipse.cdt.internal.core.dom.parser.cpp;x-friends:="org.eclipse.cdt.ui",
+ org.eclipse.cdt.internal.core.dom.rewrite;x-friends:="org.eclipse.cdt.core.tests,org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.dom.rewrite.astwriter;x-internal:=true,
org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;x-internal:=true,
org.eclipse.cdt.internal.core.dom.rewrite.commenthandler;x-internal:=true,
@@ -54,7 +54,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core.index;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.index.provider;x-internal:=true,
org.eclipse.cdt.internal.core.language;x-friends:="org.eclipse.cdt.ui",
- org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.refactoring",
+ org.eclipse.cdt.internal.core.model;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.model.ext;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.parser;x-internal:=true,
org.eclipse.cdt.internal.core.parser.problem;x-internal:=true,
@@ -72,7 +72,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.errorparsers;x-internal:=true,
org.eclipse.cdt.internal.formatter;x-internal:=true,
org.eclipse.cdt.internal.formatter.align;x-internal:=true,
- org.eclipse.cdt.internal.formatter.scanner;x-internal:=true,
+ org.eclipse.cdt.internal.formatter.scanner;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.utils,
org.eclipse.cdt.utils.cdtvariables,
org.eclipse.cdt.utils.coff,
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
index b86f09b6a9d..2b273d457ee 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java
@@ -12,13 +12,27 @@ package org.eclipse.cdt.internal.core.dom.rewrite;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator;
+import org.eclipse.core.resources.IFile;
import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
public class ASTRewriteAnalyzer {
+ private static ICTextFileChangeFactory sFileChangeFactory;
public static Change rewriteAST(IASTTranslationUnit root, ASTModificationStore modificationStore) {
ChangeGenerator rewriter = new ChangeGenerator(modificationStore);
rewriter.generateChange(root);
return rewriter.getChange();
}
+
+ public static void setCTextFileChangeFactory(ICTextFileChangeFactory factory) {
+ sFileChangeFactory= factory;
+ }
+
+ public static TextFileChange createCTextFileChange(IFile file) {
+ if (sFileChangeFactory == null) {
+ return new TextFileChange(file.getName(), file);
+ }
+ return sFileChangeFactory.createCTextFileChange(file);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ICTextFileChangeFactory.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ICTextFileChangeFactory.java
new file mode 100644
index 00000000000..c544af7cc8a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/ICTextFileChangeFactory.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems, Inc. 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:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.core.dom.rewrite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+
+/**
+ * Factory to create CTextFileChanges. Allows for creating ui-dependent objects in the core plugin.
+ * @since 5.0
+ */
+public interface ICTextFileChangeFactory {
+
+ /**
+ * Creates a text file change for the given file.
+ */
+ TextFileChange createCTextFileChange(IFile file);
+}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/CTextFileChange.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/CTextFileChange.java
deleted file mode 100644
index 1c4cf31bb4d..00000000000
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/CTextFileChange.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*******************************************************************************
- * 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.internal.core.dom.rewrite.changegenerator;
-
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.ChangeDescriptor;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup;
-import org.eclipse.ltk.core.refactoring.TextEditChangeGroup;
-import org.eclipse.ltk.core.refactoring.TextFileChange;
-import org.eclipse.text.edits.MalformedTreeException;
-import org.eclipse.text.edits.TextEdit;
-import org.eclipse.text.edits.TextEditGroup;
-
-/**
- * @author Emanuel Graf
- *
- */
-public class CTextFileChange extends Change {
-
- private TextFileChange change;
-
- /**
- * @param name
- * @param file
- */
- public CTextFileChange(String name, IFile file) {
- change = new TextFileChange(name, file);
- }
-
- @Override
- public Object getModifiedElement() {
- return change.getModifiedElement();
- }
-
- @Override
- public String getName() {
- return change.getName();
- }
-
- @Override
- public void initializeValidationData(IProgressMonitor pm) {
- change.initializeValidationData(pm);
- }
-
- @Override
- public Change perform(IProgressMonitor pm) throws CoreException {
- return change.perform(pm);
- }
-
- public void setEdit(TextEdit edit) {
- change.setEdit(edit);
- }
-
- public TextEdit getEdit() {
- return change.getEdit();
- }
-
- public void addTextEditGroup(TextEditBasedChangeGroup group) {
- change.addChangeGroup(group);
- }
-
- public String getCurrentContent(IProgressMonitor pm) throws CoreException{
- return change.getCurrentContent(pm);
- }
-
- public String getPreviewContent(IProgressMonitor pm) throws CoreException{
- return change.getPreviewContent(pm);
- }
- public String getTextType() {
- return change.getTextType();
- }
-
- public IFile getFile() {
- return change.getFile();
- }
-
- public void addChangeGroup(TextEditBasedChangeGroup group) {
- change.addChangeGroup(group);
- }
-
- public void addEdit(TextEdit edit) throws MalformedTreeException {
- change.addEdit(edit);
- }
-
- public void addTextEditChangeGroup(TextEditChangeGroup group) {
- change.addTextEditChangeGroup(group);
- }
-
- public void addTextEditGroup(TextEditGroup group) {
- change.addTextEditGroup(group);
- }
-
- @Override
- public void dispose() {
- change.dispose();
- }
-
- @Override
- public boolean equals(Object obj) {
- return change.equals(obj);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Object getAdapter(Class adapter) {
- return change.getAdapter(adapter);
- }
-
- @Override
- public Object[] getAffectedObjects() {
- return change.getAffectedObjects();
- }
-
- public String getCurrentContent(IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
- return change.getCurrentContent(region, expandRegionToFullLine, surroundingLines, pm);
- }
-
- public IDocument getCurrentDocument(IProgressMonitor pm) throws CoreException {
- return change.getCurrentDocument(pm);
- }
-
- @Override
- public ChangeDescriptor getDescriptor() {
- return change.getDescriptor();
- }
-
- public boolean getKeepPreviewEdits() {
- return change.getKeepPreviewEdits();
- }
-
- @Override
- public Change getParent() {
- return change.getParent();
- }
-
- public String getPreviewContent(TextEditBasedChangeGroup[] changeGroups, IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
- return change.getPreviewContent(changeGroups, region, expandRegionToFullLine, surroundingLines, pm);
- }
-
- public String getPreviewContent(TextEditChangeGroup[] changeGroups, IRegion region, boolean expandRegionToFullLine, int surroundingLines, IProgressMonitor pm) throws CoreException {
- return change.getPreviewContent(changeGroups, region, expandRegionToFullLine, surroundingLines, pm);
- }
-
- public IDocument getPreviewDocument(IProgressMonitor pm) throws CoreException {
- return change.getPreviewDocument(pm);
- }
-
- public TextEdit getPreviewEdit(TextEdit original) {
- return change.getPreviewEdit(original);
- }
-
- public TextEdit[] getPreviewEdits(TextEdit[] originals) {
- return change.getPreviewEdits(originals);
- }
-
- public int getSaveMode() {
- return change.getSaveMode();
- }
-
- public TextEditChangeGroup[] getTextEditChangeGroups() {
- return change.getTextEditChangeGroups();
- }
-
- @Override
- public int hashCode() {
- return change.hashCode();
- }
-
- @SuppressWarnings("unchecked")
- public boolean hasOneGroupCategory(List groupCategories) {
- return change.hasOneGroupCategory(groupCategories);
- }
-
- @Override
- public boolean isEnabled() {
- return change.isEnabled();
- }
-
- @Override
- public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
- return change.isValid(pm);
- }
-
- @Override
- public void setEnabled(boolean enabled) {
- change.setEnabled(enabled);
- }
-
- public void setKeepPreviewEdits(boolean keep) {
- change.setKeepPreviewEdits(keep);
- }
-
- public void setSaveMode(int saveMode) {
- change.setSaveMode(saveMode);
- }
-
- public void setTextType(String type) {
- change.setTextType(type);
- }
-
- @Override
- public String toString() {
- return change.toString();
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
index c792011b218..231733a9ee7 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java
@@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModification;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationMap;
import org.eclipse.cdt.internal.core.dom.rewrite.ASTModificationStore;
+import org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ASTWriter;
import org.eclipse.cdt.internal.core.dom.rewrite.astwriter.ProblemRuntimeException;
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper;
@@ -40,6 +41,7 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.MultiTextEdit;
@@ -98,8 +100,7 @@ public class ChangeGenerator extends CPPASTVisitor {
rootNode.accept(pathProvider);
for (IFile currentFile : changes.keySet()) {
- CTextFileChange subchange = new CTextFileChange(currentFile
- .getName(), currentFile);
+ TextFileChange subchange= ASTRewriteAnalyzer.createCTextFileChange(currentFile);
subchange.setEdit(changes.get(currentFile));
change.add(subchange);
}
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;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
index d7a738d42a8..1fb28426ea0 100644
--- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF
@@ -28,6 +28,11 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
org.eclipse.cdt.internal.ui.navigator,
org.eclipse.cdt.internal.ui.preferences;x-internal:=true,
org.eclipse.cdt.internal.ui.preferences.formatter,
+ org.eclipse.cdt.internal.ui.refactoring;x-friends:="org.eclipse.cdt.ui.tests",
+ org.eclipse.cdt.internal.ui.refactoring.dialogs,
+ org.eclipse.cdt.internal.ui.refactoring.extractconstant;x-friends:="org.eclipse.cdt.ui.tests",
+ org.eclipse.cdt.internal.ui.refactoring.rename;x-friends:="org.eclipse.cdt.ui.tests",
+ org.eclipse.cdt.internal.ui.refactoring.utils;x-friends:="org.eclipse.cdt.ui.tests",
org.eclipse.cdt.internal.ui.search;x-internal:=true,
org.eclipse.cdt.internal.ui.search.actions;x-internal:=true,
org.eclipse.cdt.internal.ui.text;x-internal:=true,
@@ -52,6 +57,8 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
org.eclipse.cdt.ui.browser.typeinfo,
org.eclipse.cdt.ui.dialogs,
org.eclipse.cdt.ui.newui,
+ org.eclipse.cdt.ui.refactoring,
+ org.eclipse.cdt.ui.refactoring.actions,
org.eclipse.cdt.ui.templateengine,
org.eclipse.cdt.ui.templateengine.event,
org.eclipse.cdt.ui.templateengine.pages,
@@ -61,8 +68,8 @@ Export-Package: org.eclipse.cdt.internal.corext;x-internal:=true,
org.eclipse.cdt.ui.text.c.hover,
org.eclipse.cdt.ui.text.contentassist,
org.eclipse.cdt.ui.text.doctools,
- org.eclipse.cdt.ui.text.doctools.generic,
org.eclipse.cdt.ui.text.doctools.doxygen,
+ org.eclipse.cdt.ui.text.doctools.generic,
org.eclipse.cdt.ui.text.folding,
org.eclipse.cdt.ui.wizards,
org.eclipse.cdt.ui.wizards.conversion,
@@ -82,9 +89,10 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.3.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.help;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui.navigator;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.cdt.refactoring;bundle-version="[5.0.0,6.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.1.0,2.0.0)",
- org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)"
+ org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.4.0",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.4.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: com.ibm.icu.text
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index 92038b04d7d..27c24ab2c36 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -128,6 +128,24 @@ ActionDefinition.forwardMacroExpansion.description= Step forward in macro expans
ActionDefinition.showMacroExplorer.name= Explore Macro Expansion
ActionDefinition.showMacroExplorer.description= Opens a quick view for macro expansion exploration
+category.refactoring.description= C/C++ Refactorings
+category.refactoring.name = Refactor - C++
+refactoringExtractConstant.label = Extract Constant...
+
+
+ActionDefinition.renameElement.name= Rename - Refactoring
+ActionDefinition.renameElement.description= Rename the selected element
+ActionDefinition.extractConstant.name= Extract Constant - Refactoring
+ActionDefinition.extractConstant.description= Extract a constant for the selected expression
+
+# Action Set
+CodingActionSet.label= C/C++ Coding
+CodingActionSet.description= Action set containing coding related C/C++ actions
+
+Refactoring.menu.label= Refac&tor
+Refactoring.renameAction.label=Re&name...
+Refactoring.extractConstant.label=Extr&act Constant...
+
CEditor.name=C/C++ Editor
CPluginPreferencePage.name=C/C++
@@ -198,7 +216,6 @@ CEditorPresentationActionSet.description=Actions to customize the C/C++ editor p
# Menus
searchMenu.label= Se&arch
-refactoringMenu.label= Re&factor
# Open Element
OpenTypeAction.label= Open &Element...
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 264f2ce2451..d6cb8fc5423 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -234,6 +234,7 @@
<actionSet id="org.eclipse.cdt.ui.buildConfigActionSet"/>
<actionSet id="org.eclipse.cdt.ui.NavigationActionSet"/>
<actionSet id="org.eclipse.cdt.ui.OpenActionSet"/>
+ <actionSet id="org.eclipse.cdt.ui.CodingActionSet"/>
<actionSet id="org.eclipse.ui.edit.text.actionSet.presentation"/>
<showInPart id="org.eclipse.cdt.ui.includeBrowser"/>
@@ -1125,6 +1126,39 @@
<extension
point="org.eclipse.ui.actionSets">
<actionSet
+ label="%CodingActionSet.label"
+ description="%CodingActionSet.description"
+ visible="false"
+ id="org.eclipse.cdt.ui.CodingActionSet">
+ <menu
+ label="%Refactoring.menu.label"
+ path="edit"
+ id="org.eclipse.jdt.ui.refactoring.menu">
+ <separator name="reorgGroup"/>
+ <separator name="codingGroup"/>
+ <separator name="reorgGroup2"/>
+ <separator name="typeGroup"/>
+ <separator name="typeGroup2"/>
+ <separator name="codingGroup2"/>
+ <separator name="typeGroup3"/>
+ </menu>
+ <!-- reorg group -->
+ <action
+ definitionId="org.eclipse.cdt.ui.edit.text.rename.element"
+ label="%Refactoring.renameAction.label"
+ menubarPath="org.eclipse.jdt.ui.refactoring.menu/reorgGroup"
+ id="org.eclipse.cdt.ui.actions.Rename"
+ retarget="true">
+ </action>
+ <action
+ definitionId="org.eclipse.cdt.ui.refactor.extract.constant"
+ label="%Refactoring.extractConstant.label"
+ menubarPath="org.eclipse.jdt.ui.refactoring.menu/codingGroup"
+ id="org.eclipse.cdt.ui.actions.ExtractConstant"
+ retarget="true">
+ </action>
+ </actionSet>
+ <actionSet
label="%CSearchActionSet.label"
description="%CSearchActionSet.description"
visible="false"
@@ -1551,6 +1585,21 @@
contextId="org.eclipse.cdt.ui.cEditorScope"
commandId="org.eclipse.cdt.ui.edit.open.quick.macro.explorer"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
+ <key
+ sequence="M2+M3+R"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ contextId="org.eclipse.cdt.ui.cEditorScope"
+ commandId="org.eclipse.cdt.ui.edit.text.rename.element"/>
+ <key
+ sequence="M2+M3+R"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ contextId="org.eclipse.cdt.ui.cViewScope"
+ commandId="org.eclipse.cdt.ui.edit.text.rename.element"/>
+ <key
+ sequence="M3+C"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ contextId="org.eclipse.cdt.ui.cEditorScope"
+ commandId="org.eclipse.cdt.ui.refactor.extract.constant"/>
</extension>
<extension
point="org.eclipse.ui.commands">
@@ -1714,6 +1763,27 @@
description="%ActionDefinition.showMacroExplorer.description"
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.open.quick.macro.explorer"/>
+ <category
+ name="%category.refactoring.name"
+ description="%category.refactoring.description"
+ id="org.eclipse.cdt.ui.category.refactoring"/>
+ <command
+ categoryId="org.eclipse.cdt.ui.category.refactoring"
+ id="org.eclipse.cdt.ui.refactoring.command.ExtractConstant"
+ name="%refactoringExtractConstant.label"/>
+ <command
+ name="%ActionDefinition.renameElement.name"
+ description="%ActionDefinition.renameElement.description"
+ categoryId="org.eclipse.cdt.ui.category.refactoring"
+ id="org.eclipse.cdt.ui.edit.text.rename.element">
+ </command>
+ <command
+ name="%ActionDefinition.extractConstant.name"
+ description="%ActionDefinition.extractConstant.description"
+ categoryId="org.eclipse.cdt.ui.category.refactoring"
+ id="org.eclipse.cdt.ui.refactor.extract.constant">
+ </command>
+
</extension>
<extension
id="pdomSearchPage"
@@ -1744,6 +1814,11 @@
id="org.eclipse.search.SearchResultView">
</part>
</actionSetPartAssociation>
+ <actionSetPartAssociation targetID="org.eclipse.cdt.ui.CodingActionSet">
+ <part id="org.eclipse.cdt.ui.editor.CEditor"/>
+ <part id="org.eclipse.cdt.ui.CView"/>
+ </actionSetPartAssociation>
+
<actionSetPartAssociation
targetID="org.eclipse.ui.edit.text.actionSet.annotationNavigation">
<part
@@ -2567,6 +2642,23 @@
</owner>
</extension>
<extension
+ point="org.eclipse.ltk.ui.refactoring.changePreviewViewers">
+ <changePreviewViewer
+ class="org.eclipse.cdt.internal.ui.refactoring.dialogs.CreateFileChangePreview"
+ id="org.eclipse.cdt.internal.ui.refactoring.createFileChangePreviewhangePreview">
+ <enablement>
+ <instanceof value="org.eclipse.cdt.internal.ui.refactoring.CreateFileChange"/>
+ </enablement>
+ </changePreviewViewer>
+ <changePreviewViewer
+ class="org.eclipse.cdt.internal.ui.refactoring.dialogs.CTextEditChangePreviewViewer"
+ id="org.eclipse.cdt.internal.ui.refactoring.CTextChangePreviewhangePreview">
+ <enablement>
+ <instanceof value="org.eclipse.cdt.ui.refactoring.CTextFileChange"/>
+ </enablement>
+ </changePreviewViewer>
+ </extension>
+ <extension
point="org.eclipse.ui.decorators">
<decorator
class="org.eclipse.cdt.internal.ui.viewsupport.IndexedFilesLabelProvider"
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java
index b8d84f3300c..e471674a2b2 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. 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
@@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.ui.callhierarchy;
import org.eclipse.osgi.util.NLS;
@@ -27,13 +26,10 @@ public class CHMessages extends NLS {
public static String CHViewPart_FilterVariables_label;
public static String CHViewPart_FilterVariables_tooltip;
public static String CHViewPart_FocusOn_label;
- public static String CHViewPart_HideMacros_label;
- public static String CHViewPart_HideMacros_tooltip;
public static String CHViewPart_NextReference_label;
public static String CHViewPart_NextReference_tooltip;
public static String CHViewPart_Open_label;
public static String CHViewPart_Open_tooltip;
- public static String CHViewPart_OpenReference_label;
public static String CHViewPart_PreviousReference_label;
public static String CHViewPart_PreviousReference_tooltip;
public static String CHViewPart_Refresh_label;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties
index 98425868c36..f544a8079e9 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMessages.properties
@@ -17,8 +17,6 @@ CHViewPart_ShowReference_label=Show Reference
CHViewPart_ShowReference_tooltip=Show Reference
CHViewPart_FilterVariables_label=Filter Variables
CHViewPart_FilterVariables_tooltip=Hide Variables, Constants and Enumerators
-CHViewPart_HideMacros_label=Hide Macros
-CHViewPart_HideMacros_tooltip=Hides Macros
CHViewPart_ShowFiles_label=Show File Names
CHViewPart_ShowFiles_tooltip=Show File Names
CHViewPart_NextReference_label=Next Reference
@@ -35,7 +33,6 @@ CHViewPart_FocusOn_label=Focus On ''{0}''
CHViewPart_Open_label=Open
CHViewPart_Open_tooltip=Open
CHLabelProvider_matches=matches
-CHViewPart_OpenReference_label=Open Reference
CHHistoryDropDownAction_ClearHistory_label=Clear History
CHHistoryListAction_HistoryDialog_title=Call Hierarchy History
CHHistoryListAction_HistoryList_label=Select the input for the Call Hierarchy:
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java
index ab0fd551cca..d62d34114f8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. 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
@@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.ui.callhierarchy;
import java.util.ArrayList;
@@ -64,9 +63,9 @@ import org.eclipse.cdt.core.model.IFunction;
import org.eclipse.cdt.core.model.IMethod;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.util.CElementBaseLabels;
-import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
+import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
@@ -97,7 +96,7 @@ public class CHViewPart extends ViewPart {
private CHNode fNavigationNode;
private int fNavigationDetail;
- private ArrayList fHistoryEntries= new ArrayList(MAX_HISTORY_SIZE);
+ private ArrayList<ICElement> fHistoryEntries= new ArrayList<ICElement>(MAX_HISTORY_SIZE);
// widgets
private PageBook fPagebook;
@@ -136,7 +135,8 @@ public class CHViewPart extends ViewPart {
private IContextActivation fContextActivation;
- public void setFocus() {
+ @Override
+ public void setFocus() {
fPagebook.setFocus();
}
@@ -192,6 +192,7 @@ public class CHViewPart extends ViewPart {
return false;
}
+ @Override
public void createPartControl(Composite parent) {
fPagebook = new PageBook(parent, SWT.NULL);
fPagebook.setLayoutData(new GridData(GridData.FILL_BOTH));
@@ -214,6 +215,7 @@ public class CHViewPart extends ViewPart {
}
}
+ @Override
public void dispose() {
if (fContextActivation != null) {
IContextService ctxService = (IContextService)getSite().getService(IContextService.class);
@@ -267,13 +269,15 @@ public class CHViewPart extends ViewPart {
updateSorter();
}
- public void init(IViewSite site, IMemento memento) throws PartInitException {
+ @Override
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
fMemento= memento;
super.init(site, memento);
}
- public void saveState(IMemento memento) {
+ @Override
+ public void saveState(IMemento memento) {
if (fWorkingSetFilterUI != null) {
fWorkingSetFilterUI.saveState(memento, KEY_WORKING_SET_FILTER);
}
@@ -341,17 +345,20 @@ public class CHViewPart extends ViewPart {
fRefactoringActionGroup= new CRefactoringActionGroup(this);
fWorkingSetFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
- protected void onWorkingSetChange() {
+ @Override
+ protected void onWorkingSetChange() {
updateWorkingSetFilter(this);
}
- protected void onWorkingSetNameChange() {
+ @Override
+ protected void onWorkingSetNameChange() {
updateDescription();
}
};
fReferencedByAction=
new Action(CHMessages.CHViewPart_ShowCallers_label, IAction.AS_RADIO_BUTTON) {
- public void run() {
+ @Override
+ public void run() {
if (isChecked()) {
onSetShowReferencedBy(true);
}
@@ -362,7 +369,8 @@ public class CHViewPart extends ViewPart {
fMakesReferenceToAction=
new Action(CHMessages.CHViewPart_ShowCallees_label, IAction.AS_RADIO_BUTTON) {
- public void run() {
+ @Override
+ public void run() {
if (isChecked()) {
onSetShowReferencedBy(false);
}
@@ -372,7 +380,8 @@ public class CHViewPart extends ViewPart {
CPluginImages.setImageDescriptors(fMakesReferenceToAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_SHOW_RELATES_TO);
fVariableFilter= new ViewerFilter() {
- public boolean select(Viewer viewer, Object parentElement, Object element) {
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof CHNode) {
CHNode node= (CHNode) element;
return !node.isVariableOrEnumerator();
@@ -381,7 +390,8 @@ public class CHViewPart extends ViewPart {
}
};
fFilterVariablesAction= new Action(CHMessages.CHViewPart_FilterVariables_label, IAction.AS_CHECK_BOX) {
- public void run() {
+ @Override
+ public void run() {
if (isChecked()) {
fTreeViewer.addFilter(fVariableFilter);
}
@@ -392,38 +402,18 @@ public class CHViewPart extends ViewPart {
};
fFilterVariablesAction.setToolTipText(CHMessages.CHViewPart_FilterVariables_tooltip);
CPluginImages.setImageDescriptors(fFilterVariablesAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_HIDE_FIELDS);
-
-// fMacroFilter= new ViewerFilter() {
-// public boolean select(Viewer viewer, Object parentElement, Object element) {
-// if (element instanceof CHNode) {
-// CHNode node= (CHNode) element;
-// return !node.isMacro();
-// }
-// return true;
-// }
-// };
-// fFilterMacrosAction= new Action(CHMessages.CHViewPart_HideMacros_label, IAction.AS_CHECK_BOX) {
-// public void run() {
-// if (isChecked()) {
-// fTreeViewer.addFilter(fMacroFilter);
-// }
-// else {
-// fTreeViewer.removeFilter(fMacroFilter);
-// }
-// }
-// };
-// fFilterMacrosAction.setToolTipText(CHMessages.CHViewPart_HideMacros_tooltip);
-// CPluginImages.setImageDescriptors(fFilterMacrosAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_HIDE_MACROS);
fSorterAlphaNumeric= new ViewerComparator();
fSorterReferencePosition= new ViewerComparator() {
- public int category(Object element) {
+ @Override
+ public int category(Object element) {
if (element instanceof CHNode) {
return 0;
}
return 1;
}
- public int compare(Viewer viewer, Object e1, Object e2) {
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
if (!(e1 instanceof CHNode)) {
if (!(e2 instanceof CHNode)) {
return 0;
@@ -442,26 +432,30 @@ public class CHViewPart extends ViewPart {
};
fShowReference= new Action(CHMessages.CHViewPart_ShowReference_label) {
- public void run() {
+ @Override
+ public void run() {
onShowSelectedReference(fTreeViewer.getSelection());
}
};
fShowReference.setToolTipText(CHMessages.CHViewPart_ShowReference_tooltip);
fOpenElement= new Action(CHMessages.CHViewPart_Open_label) {
- public void run() {
+ @Override
+ public void run() {
onOpenElement(fTreeViewer.getSelection());
}
};
fOpenElement.setToolTipText(CHMessages.CHViewPart_Open_tooltip);
fShowFilesInLabelsAction= new Action(CHMessages.CHViewPart_ShowFiles_label, IAction.AS_CHECK_BOX) {
- public void run() {
+ @Override
+ public void run() {
onShowFilesInLabels(isChecked());
}
};
fShowFilesInLabelsAction.setToolTipText(CHMessages.CHViewPart_ShowFiles_tooltip);
fNextAction = new Action(CHMessages.CHViewPart_NextReference_label) {
- public void run() {
+ @Override
+ public void run() {
onNextOrPrevious(true);
}
};
@@ -469,7 +463,8 @@ public class CHViewPart extends ViewPart {
CPluginImages.setImageDescriptors(fNextAction, CPluginImages.T_LCL, CPluginImages.IMG_SHOW_NEXT);
fPreviousAction = new Action(CHMessages.CHViewPart_PreviousReference_label) {
- public void run() {
+ @Override
+ public void run() {
onNextOrPrevious(false);
}
};
@@ -477,7 +472,8 @@ public class CHViewPart extends ViewPart {
CPluginImages.setImageDescriptors(fPreviousAction, CPluginImages.T_LCL, CPluginImages.IMG_SHOW_PREV);
fRefreshAction = new Action(CHMessages.CHViewPart_Refresh_label) {
- public void run() {
+ @Override
+ public void run() {
onRefresh();
}
};
@@ -705,6 +701,7 @@ public class CHViewPart extends ViewPart {
String label= Messages.format(CHMessages.CHViewPart_FocusOn_label,
CElementLabels.getTextLabel(element, CElementBaseLabels.ALL_FULLY_QUALIFIED | CElementBaseLabels.M_PARAMETER_TYPES));
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, new Action(label) {
+ @Override
public void run() {
setInput(element);
}
@@ -784,7 +781,7 @@ public class CHViewPart extends ViewPart {
}
public ICElement[] getHistoryEntries() {
- return (ICElement[]) fHistoryEntries.toArray(new ICElement[fHistoryEntries.size()]);
+ return fHistoryEntries.toArray(new ICElement[fHistoryEntries.size()]);
}
public void setHistoryEntries(ICElement[] remaining) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
index 9c7fa474800..11f6b85deeb 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 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
@@ -39,9 +39,9 @@ import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
+import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
@@ -91,6 +91,7 @@ public class MainActionGroup extends CViewActionGroup {
/**
* Handles key events in viewer.
*/
+ @Override
public void handleKeyPressed(KeyEvent event) {
refactorGroup.handleKeyPressed(event);
openFileGroup.handleKeyPressed(event);
@@ -102,6 +103,7 @@ public class MainActionGroup extends CViewActionGroup {
/**
* Handles key events in viewer.
*/
+ @Override
public void handleKeyReleased(KeyEvent event) {
refactorGroup.handleKeyReleased(event);
openFileGroup.handleKeyReleased(event);
@@ -110,6 +112,7 @@ public class MainActionGroup extends CViewActionGroup {
buildGroup.handleKeyReleased(event);
}
+ @Override
protected void makeActions() {
final Viewer viewer = getCView().getViewer();
IShellProvider shellProvider = getCView().getViewSite();
@@ -147,8 +150,8 @@ public class MainActionGroup extends CViewActionGroup {
workingSetGroup.setWorkingSet(getCView().getWorkingSet());
fCustomFiltersActionGroup= new CustomFiltersActionGroup(getCView(), getCView().getViewer());
- addBookmarkAction = new AddBookmarkAction(shell);
- addTaskAction = new AddTaskAction(shell);
+ addBookmarkAction = new AddBookmarkAction(shellProvider, true);
+ addTaskAction = new AddTaskAction(shellProvider);
// Importing/exporting.
importAction = new ImportResourcesAction(getCView().getSite().getWorkbenchWindow());
@@ -170,6 +173,7 @@ public class MainActionGroup extends CViewActionGroup {
* Called when the context menu is about to open. Override to add your own
* context dependent menu contributions.
*/
+ @Override
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection celements = (IStructuredSelection) getCView().getViewer().getSelection();
IStructuredSelection resources = SelectionConverter.convertSelectionToResources(celements);
@@ -233,6 +237,7 @@ public class MainActionGroup extends CViewActionGroup {
* Extends the superclass implementation to set the context in the
* subgroups.
*/
+ @Override
public void setContext(ActionContext context) {
super.setContext(context);
gotoGroup.setContext(context);
@@ -276,6 +281,7 @@ public class MainActionGroup extends CViewActionGroup {
}
}
+ @Override
public void runDefaultAction(IStructuredSelection selection) {
openFileGroup.runDefaultAction(selection);
openProjectGroup.runDefaultAction(selection);
@@ -291,6 +297,7 @@ public class MainActionGroup extends CViewActionGroup {
* if the selection in the viewer hasn't. E.g. A project was opened or
* closed.
*/
+ @Override
public void updateActionBars() {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
@@ -311,6 +318,7 @@ public class MainActionGroup extends CViewActionGroup {
crefactoringActionGroup.updateActionBars();
}
+ @Override
public void fillActionBars(IActionBars actionBars) {
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), addBookmarkAction);
actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), addTaskAction);
@@ -339,11 +347,13 @@ public class MainActionGroup extends CViewActionGroup {
//---- Persistent state -----------------------------------------------------------------------
+ @Override
public void restoreFilterAndSorterState(IMemento memento) {
//fWorkingSetFilterActionGroup.restoreState(memento);
fCustomFiltersActionGroup.restoreState(memento);
}
+ @Override
public void saveFilterAndSorterState(IMemento memento) {
//fWorkingSetFilterActionGroup.saveState(memento);
fCustomFiltersActionGroup.saveState(memento);
@@ -353,6 +363,7 @@ public class MainActionGroup extends CViewActionGroup {
return fCustomFiltersActionGroup;
}
+ @Override
public void dispose() {
importAction.dispose();
exportAction.dispose();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java
index 490b3b9c6c1..e81072806bd 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AbstractCModelOutlinePage.java
@@ -138,7 +138,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
public IncludeGroupingAction(AbstractCModelOutlinePage outlinePage) {
super(ActionMessages.getString("IncludesGroupingAction.label")); //$NON-NLS-1$
setDescription(ActionMessages.getString("IncludesGroupingAction.description")); //$NON-NLS-1$
- setToolTipText(ActionMessages.getString("IncludeGroupingAction.tooltip")); //$NON-NLS-1$
+ setToolTipText(ActionMessages.getString("IncludesGroupingAction.tooltip")); //$NON-NLS-1$
CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_GROUP_INCLUDE);
boolean enabled= isIncludesGroupingEnabled();
@@ -149,6 +149,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
/**
* Runs the action.
*/
+ @Override
public void run() {
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_GROUP_INCLUDES, isChecked());
}
@@ -177,6 +178,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
/**
* Runs the action.
*/
+ @Override
public void run() {
boolean checked = isChecked();
PreferenceConstants.getPreferenceStore().setValue(PreferenceConstants.OUTLINE_LINK_TO_EDITOR, checked);
@@ -301,6 +303,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
return fTreeViewer;
}
+ @Override
public void createControl(Composite parent) {
fTreeViewer = createTreeViewer(parent);
initDragAndDrop();
@@ -344,6 +347,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
PlatformUI.getWorkbench().getHelpSystem().setHelp(control, ICHelpContextIds.COUTLINE_VIEW);
}
+ @Override
public void dispose() {
if (fTreeViewer != null) {
fTreeViewer.removeSelectionChangedListener(this);
@@ -498,6 +502,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
}
}
+ @Override
public Control getControl() {
if (fTreeViewer == null)
return null;
@@ -531,6 +536,7 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
/**
* Sets focus to a part in the page.
*/
+ @Override
public void setFocus() {
fTreeViewer.getControl().setFocus();
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
index 50ab6a64b52..cdb5e1f0715 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CContentOutlinePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 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
@@ -15,10 +15,10 @@ package org.eclipse.cdt.internal.ui.editor;
import org.eclipse.ui.actions.ActionGroup;
-import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
+import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
@@ -40,24 +40,29 @@ public class CContentOutlinePage extends AbstractCModelOutlinePage {
return (CEditor)fEditor;
}
+ @Override
protected SelectionSearchGroup createSearchActionGroup() {
return new SelectionSearchGroup(this);
}
+ @Override
protected OpenViewActionGroup createOpenViewActionGroup() {
OpenViewActionGroup ovag= new OpenViewActionGroup(this);
ovag.setEnableIncludeBrowser(true);
return ovag;
}
+ @Override
protected ActionGroup createRefactoringActionGroup() {
return new CRefactoringActionGroup(this);
}
+ @Override
protected ActionGroup createCustomFiltersActionGroup() {
return new CustomFiltersActionGroup("org.eclipse.cdt.ui.COutlinePage", getTreeViewer()); //$NON-NLS-1$
}
+ @Override
protected ActionGroup createMemberFilterActionGroup() {
return new MemberFilterActionGroup(getTreeViewer(), "COutlineViewer"); //$NON-NLS-1$
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java
index a68a265f537..e5e77d725ba 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java
@@ -172,12 +172,12 @@ import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
-import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.actions.GenerateActionGroup;
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
+import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java
index 069ba1444a8..31975edd089 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java
@@ -81,13 +81,6 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
public static final String OPEN_DECL= "org.eclipse.cdt.ui.edit.opendecl"; //$NON-NLS-1$
/**
- * Action definition ID of the open definition action
- * (value <code>"org.eclipse.cdt.ui.edit.opendef"</code>).
- * @deprecated see bug 167162
- */
- public static final String OPEN_DEF= "org.eclipse.cdt.ui.edit.opendef"; //$NON-NLS-1$
-
- /**
* Action definition ID of the show in C/C++ Projects View action
* (value <code>"org.eclipse.cdt.ui.edit.opencview"</code>).
*/
@@ -98,7 +91,13 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
* (value <code>"org.eclipse.cdt.ui.edit.text.rename.element"</code>).
*/
public static final String RENAME_ELEMENT= "org.eclipse.cdt.ui.edit.text.rename.element"; //$NON-NLS-1$
-
+
+ /**
+ * Action definition ID of the refactor -> extract constant action
+ * (value <code>"org.eclipse.cdt.ui.refactor.extract.constant"</code>).
+ */
+ public static final String EXTRACT_CONSTANT= "org.eclipse.cdt.ui.refactor.extract.constant"; //$NON-NLS-1$
+
/**
* Action definition ID of the refactor -> undo action
* (value <code>"org.eclipse.cdt.ui.edit.text.undo.action"</code>).
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java
index 6bf86430078..56c4b03aca2 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. 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
@@ -8,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.ui.includebrowser;
import org.eclipse.osgi.util.NLS;
@@ -35,7 +34,6 @@ public class IBMessages extends NLS {
public static String IBViewPart_jobCheckInput;
public static String IBViewPart_nextMatch_label;
public static String IBViewPart_nextMatch_tooltip;
- public static String IBViewPart_OpenWithMenu_label;
public static String IBViewPart_previousMatch_label;
public static String IBViewPart_previousMatch_tooltip;
public static String IBViewPart_refresh_label;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties
index 0441999d969..2e945d47a6d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBMessages.properties
@@ -1,12 +1,12 @@
###############################################################################
-# Copyright (c) 2006, 2007 Wind River Systems, Inc and others.
+# Copyright (c) 2006, 2008 Wind River Systems, Inc 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:
-# Markus Schorn - Initial API and implementation
+# Markus Schorn - Initial API and implementation
###############################################################################
IBViewPart_instructionMessage=To display an include hierarchy, drop a c/c++-file onto this view.
@@ -23,7 +23,6 @@ IBViewPart_IncludedByContentDescription=Files including ''{0}'' - in {1}
IBViewPart_IncludesToContentDescription=Files included by ''{0}'' - in {1}
IBViewPart_hideInactive_tooltip=Hide Includes from Inactive Code
IBViewPart_previousMatch_tooltip=Show Previous Include
-IBViewPart_OpenWithMenu_label=Open With
IBViewPart_hideInactive_label=Hide Inactive Includes
IBViewPart_hideSystem_tooltip=Hide System Includes
IBViewPart_ShowInMenu_label=Show In
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java
index 2c2299c1f5b..5c1e7e80c6b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2008 Wind River Systems, Inc. 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
@@ -9,7 +9,6 @@
* Markus Schorn - initial API and implementation
* Ed Swartz (Nokia)
*******************************************************************************/
-
package org.eclipse.cdt.internal.ui.includebrowser;
import java.util.ArrayList;
@@ -113,7 +112,7 @@ public class IBViewPart extends ViewPart
private IMemento fMemento;
private boolean fShowsMessage;
private IBNode fLastNavigationNode;
- private ArrayList fHistoryEntries= new ArrayList(MAX_HISTORY_SIZE);
+ private ArrayList<ITranslationUnit> fHistoryEntries= new ArrayList<ITranslationUnit>(MAX_HISTORY_SIZE);
// widgets
private PageBook fPagebook;
@@ -147,7 +146,8 @@ public class IBViewPart extends ViewPart
private IBSetInputJob fSetInputJob;
- public void setFocus() {
+ @Override
+ public void setFocus() {
fPagebook.setFocus();
}
@@ -206,6 +206,7 @@ public class IBViewPart extends ViewPart
updateDescription();
final Display display= Display.getCurrent();
Job job= new Job(IBMessages.IBViewPart_jobCheckInput) {
+ @Override
protected IStatus run(IProgressMonitor monitor) {
try {
IIndex index= CCorePlugin.getIndexManager().getIndex(input.getCProject());
@@ -246,6 +247,7 @@ public class IBViewPart extends ViewPart
fRefreshAction.setEnabled(!fShowsMessage);
}
+ @Override
public void createPartControl(Composite parent) {
fSetInputJob= new IBSetInputJob(this, Display.getCurrent());
@@ -271,6 +273,7 @@ public class IBViewPart extends ViewPart
}
}
+ @Override
public void dispose() {
if (fContextActivation != null) {
IContextService ctxService = (IContextService)getSite().getService(IContextService.class);
@@ -329,13 +332,15 @@ public class IBViewPart extends ViewPart
}
- public void init(IViewSite site, IMemento memento) throws PartInitException {
+ @Override
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
fMemento= memento;
super.init(site, memento);
}
- public void saveState(IMemento memento) {
+ @Override
+ public void saveState(IMemento memento) {
if (fWorkingSetFilter != null) {
fWorkingSetFilter.getUI().saveState(memento, KEY_WORKING_SET_FILTER);
}
@@ -410,17 +415,20 @@ public class IBViewPart extends ViewPart
private void createActions() {
fWorkingSetFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
- protected void onWorkingSetChange() {
+ @Override
+ protected void onWorkingSetChange() {
updateWorkingSetFilter(this);
}
- protected void onWorkingSetNameChange() {
+ @Override
+ protected void onWorkingSetNameChange() {
updateDescription();
}
};
fIncludedByAction=
new Action(IBMessages.IBViewPart_showIncludedBy_label, IAction.AS_RADIO_BUTTON) {
- public void run() {
+ @Override
+ public void run() {
if (isChecked()) {
onSetDirection(true);
}
@@ -431,7 +439,8 @@ public class IBViewPart extends ViewPart
fIncludesToAction=
new Action(IBMessages.IBViewPart_showIncludesTo_label, IAction.AS_RADIO_BUTTON) {
- public void run() {
+ @Override
+ public void run() {
if (isChecked()) {
onSetDirection(false);
}
@@ -441,7 +450,8 @@ public class IBViewPart extends ViewPart
CPluginImages.setImageDescriptors(fIncludesToAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_SHOW_RELATES_TO);
fInactiveFilter= new ViewerFilter() {
- public boolean select(Viewer viewer, Object parentElement, Object element) {
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IBNode) {
IBNode node= (IBNode) element;
return node.isActiveCode();
@@ -450,7 +460,8 @@ public class IBViewPart extends ViewPart
}
};
fFilterInactiveAction= new Action(IBMessages.IBViewPart_hideInactive_label, IAction.AS_CHECK_BOX) {
- public void run() {
+ @Override
+ public void run() {
if (isChecked()) {
fTreeViewer.addFilter(fInactiveFilter);
}
@@ -463,7 +474,8 @@ public class IBViewPart extends ViewPart
CPluginImages.setImageDescriptors(fFilterInactiveAction, CPluginImages.T_LCL, CPluginImages.IMG_ACTION_HIDE_INACTIVE);
fSystemFilter= new ViewerFilter() {
- public boolean select(Viewer viewer, Object parentElement, Object element) {
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IBNode) {
IBNode node= (IBNode) element;
return !node.isSystemInclude();
@@ -472,7 +484,8 @@ public class IBViewPart extends ViewPart
}
};
fFilterSystemAction= new Action(IBMessages.IBViewPart_hideSystem_label, IAction.AS_CHECK_BOX) {
- public void run() {
+ @Override
+ public void run() {
if (isChecked()) {
fTreeViewer.addFilter(fSystemFilter);
}
@@ -486,13 +499,15 @@ public class IBViewPart extends ViewPart
fSorterAlphaNumeric= new ViewerComparator();
fSorterReferencePosition= new ViewerComparator() {
- public int category(Object element) {
+ @Override
+ public int category(Object element) {
if (element instanceof IBNode) {
return 0;
}
return 1;
}
- public int compare(Viewer viewer, Object e1, Object e2) {
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
if (!(e1 instanceof IBNode)) {
if (!(e2 instanceof IBNode)) {
return 0;
@@ -509,13 +524,15 @@ public class IBViewPart extends ViewPart
};
fShowFolderInLabelsAction= new Action(IBMessages.IBViewPart_showFolders_label, IAction.AS_CHECK_BOX) {
- public void run() {
+ @Override
+ public void run() {
onShowFolderInLabels(isChecked());
}
};
fShowFolderInLabelsAction.setToolTipText(IBMessages.IBViewPart_showFolders_tooltip);
fNextAction = new Action(IBMessages.IBViewPart_nextMatch_label) {
- public void run() {
+ @Override
+ public void run() {
onNextOrPrevious(true);
}
};
@@ -523,7 +540,8 @@ public class IBViewPart extends ViewPart
CPluginImages.setImageDescriptors(fNextAction, CPluginImages.T_LCL, CPluginImages.IMG_SHOW_NEXT);
fPreviousAction = new Action(IBMessages.IBViewPart_previousMatch_label) {
- public void run() {
+ @Override
+ public void run() {
onNextOrPrevious(false);
}
};
@@ -531,7 +549,8 @@ public class IBViewPart extends ViewPart
CPluginImages.setImageDescriptors(fPreviousAction, CPluginImages.T_LCL, CPluginImages.IMG_SHOW_PREV);
fRefreshAction = new Action(IBMessages.IBViewPart_refresh_label) {
- public void run() {
+ @Override
+ public void run() {
onRefresh();
}
};
@@ -694,7 +713,8 @@ public class IBViewPart extends ViewPart
// open include
if (node.getParent() != null && node.getDirectiveFile() != null) {
m.add(new Action(IBMessages.IBViewPart_showInclude_label) {
- public void run() {
+ @Override
+ public void run() {
onShowInclude(selection);
}
});
@@ -707,15 +727,6 @@ public class IBViewPart extends ViewPart
ofa.selectionChanged(selection);
m.add(ofa);
- // open with
- // keep the menu shorter, no open with support
-// final IResource r= tu.getResource();
-// if (r != null) {
-// IMenuManager submenu= new MenuManager(IBMessages.IBViewPart_OpenWithMenu_label);
-// submenu.add(new OpenWithMenu(page, r));
-// m.add(submenu);
-// }
-
// show in
IMenuManager submenu= new MenuManager(IBMessages.IBViewPart_ShowInMenu_label);
submenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getSite().getWorkbenchWindow()));
@@ -723,7 +734,8 @@ public class IBViewPart extends ViewPart
if (node.getParent() != null) {
m.add(new Separator());
m.add(new Action(Messages.format(IBMessages.IBViewPart_FocusOn_label, tu.getPath().lastSegment())) {
- public void run() {
+ @Override
+ public void run() {
setInput(tu);
}
});
@@ -804,7 +816,7 @@ public class IBViewPart extends ViewPart
}
public ITranslationUnit[] getHistoryEntries() {
- return (ITranslationUnit[]) fHistoryEntries.toArray(new ITranslationUnit[fHistoryEntries.size()]);
+ return fHistoryEntries.toArray(new ITranslationUnit[fHistoryEntries.size()]);
}
public void setHistoryEntries(ITranslationUnit[] remaining) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java
index a19b01532cc..2a592570131 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorRefactorActionProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2008 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
@@ -23,7 +23,7 @@ import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
import org.eclipse.ui.operations.UndoRedoActionGroup;
-import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
+import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
@@ -41,6 +41,7 @@ public class CNavigatorRefactorActionProvider extends CommonActionProvider {
/*
* @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite)
*/
+ @Override
public void init(ICommonActionExtensionSite actionSite) {
site = actionSite;
resourceRefactorGroup= new CNavigatorRefactorActionGroup(site.getViewSite().getShell(), (Tree)site.getStructuredViewer().getControl());
@@ -55,12 +56,14 @@ public class CNavigatorRefactorActionProvider extends CommonActionProvider {
}
}
+ @Override
public void dispose() {
undoRedoGroup.dispose();
resourceRefactorGroup.dispose();
cElementRefactorGroup.dispose();
}
+ @Override
public void fillActionBars(IActionBars actionBars) {
undoRedoGroup.fillActionBars(actionBars);
resourceRefactorGroup.fillActionBars(actionBars);
@@ -68,18 +71,21 @@ public class CNavigatorRefactorActionProvider extends CommonActionProvider {
cElementRefactorGroup.fillActionBars(actionBars);
}
+ @Override
public void fillContextMenu(IMenuManager menu) {
undoRedoGroup.fillContextMenu(menu);
resourceRefactorGroup.fillContextMenu(menu);
cElementRefactorGroup.fillContextMenu(menu);
}
+ @Override
public void setContext(ActionContext context) {
undoRedoGroup.setContext(context);
resourceRefactorGroup.setContext(convertToResources(context));
cElementRefactorGroup.setContext(context);
}
+ @Override
public void updateActionBars() {
undoRedoGroup.updateActionBars();
resourceRefactorGroup.updateActionBars();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/AddDeclarationNodeToClassChange.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/AddDeclarationNodeToClassChange.java
new file mode 100644
index 00000000000..ef51fa2fb48
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/AddDeclarationNodeToClassChange.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 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.internal.ui.refactoring;
+
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.text.edits.TextEditGroup;
+
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
+import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
+
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTVisibilityLabel;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
+
+public class AddDeclarationNodeToClassChange {
+
+ private final ICPPASTCompositeTypeSpecifier nodeClass;
+ private final VisibilityEnum visibility;
+ private final IASTNode fieldNodes;
+ private final ModificationCollector collector;
+
+ public static void createChange(ICPPASTCompositeTypeSpecifier nodeClass, VisibilityEnum visibility, IASTNode fieldNodes, boolean isField, ModificationCollector collector) {
+ new AddDeclarationNodeToClassChange(nodeClass, visibility, fieldNodes, collector, isField);
+ }
+
+ private AddDeclarationNodeToClassChange(ICPPASTCompositeTypeSpecifier nodeClass, VisibilityEnum visibility, IASTNode fieldNodes, ModificationCollector collector, boolean isField) {
+ this.nodeClass = nodeClass;
+ this.visibility = visibility;
+ this.fieldNodes = fieldNodes;
+ this.collector = collector;
+ createRewrites(isField);
+ }
+
+ private void createRewrites(boolean isField) {
+ int lastFunctionDeclaration = -1;
+ int lastFieldDeclaration = -1;
+ IASTDeclaration[] members = nodeClass.getMembers();
+
+ // XXX Don't we have to differentiate between the default visibility in a class and a struct?
+ VisibilityEnum currentVisibility = VisibilityEnum.v_private;
+
+ // Find the insert location by iterating over the elements of the class
+ // and remembering the last element with the matching visibility
+ for(int i = 0; i < members.length; i++) {
+ IASTDeclaration declaration = members[i];
+
+ if(declaration instanceof ICPPASTVisiblityLabel){
+ currentVisibility = VisibilityEnum.from((ICPPASTVisiblityLabel) declaration);
+ }
+
+ if (declaration instanceof IASTSimpleDeclaration) {
+ IASTSimpleDeclaration simple = (IASTSimpleDeclaration) declaration;
+ IASTDeclarator[] declarators = simple.getDeclarators();
+ if(declarators.length > 0 && declarators[0] != null && declarators[0] instanceof IASTFunctionDeclarator){
+ if(currentVisibility.equals(visibility)){
+ lastFunctionDeclaration = i;
+ }
+
+ } else if (declarators.length > 0 && declarators[0] != null){
+ if(currentVisibility.equals(visibility)){
+ lastFieldDeclaration = i;
+ }
+ }
+ }
+ }
+
+ IASTDeclaration nextFunctionDeclaration = null;
+ if (lastFunctionDeclaration < members.length-1 && lastFunctionDeclaration >= 0)
+ nextFunctionDeclaration = members[lastFunctionDeclaration+1];
+
+ IASTDeclaration nextFieldDeclaration = null;
+ if (lastFieldDeclaration < members.length-1 && lastFieldDeclaration >= 0)
+ nextFieldDeclaration = members[lastFieldDeclaration +1];
+
+ createInsert(isField, nextFunctionDeclaration, nextFieldDeclaration, currentVisibility);
+ }
+
+ private void createInsert(boolean isField, IASTDeclaration nextFunctionDeclaration, IASTDeclaration nextFieldDeclaration, VisibilityEnum currentVisibility) {
+ if(isField) {
+ if(nextFieldDeclaration != null) {
+ insertBefore(nextFieldDeclaration);
+ } else if(nextFunctionDeclaration != null){
+ insertBefore(nextFunctionDeclaration);
+ } else {
+ insertAtTheEnd(currentVisibility);
+ }
+ } else {
+ if(nextFunctionDeclaration != null){
+ insertBefore(nextFunctionDeclaration);
+ } else if(nextFieldDeclaration != null) {
+ insertBefore(nextFieldDeclaration);
+ } else {
+ insertAtTheEnd(currentVisibility);
+ }
+ }
+ }
+
+ private void insertBefore(IASTNode nearestNode) {
+ ASTRewrite rewrite = collector.rewriterForTranslationUnit(nearestNode.getTranslationUnit());
+ rewrite.insertBefore(nearestNode.getParent(), nearestNode, fieldNodes, createEditDescription());
+ }
+
+ private void insertAtTheEnd(VisibilityEnum currentVisibility) {
+
+ ASTRewrite rewrite = collector.rewriterForTranslationUnit(nodeClass.getTranslationUnit());
+
+ if(! currentVisibility.equals(visibility)) {
+ ICPPASTVisiblityLabel label = new CPPASTVisibilityLabel(visibility.getICPPASTVisiblityLabelVisibility());
+ rewrite.insertBefore(nodeClass, null, label, createEditDescription());
+ }
+
+ rewrite.insertBefore(nodeClass, null, fieldNodes, createEditDescription());
+ }
+
+ private TextEditGroup createEditDescription() {
+ return new TextEditGroup(NLS.bind(Messages.AddDeclarationNodeToClassChange_AddDeclaration, nodeClass.getName()));
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java
new file mode 100644
index 00000000000..d7142ccf237
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CRefactoring.java
@@ -0,0 +1,425 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.Refactoring;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ui.IWorkbenchPage;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.dom.ast.ASTVisitor;
+import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTExpression;
+import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTNodeLocation;
+import org.eclipse.cdt.core.dom.ast.IASTProblem;
+import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTProblemExpression;
+import org.eclipse.cdt.core.dom.ast.IASTProblemStatement;
+import org.eclipse.cdt.core.dom.ast.IASTProblemTypeId;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IASTTypeId;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
+import org.eclipse.cdt.core.index.IIndex;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousDeclaration;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousExpression;
+import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguousStatement;
+import org.eclipse.cdt.internal.core.dom.parser.IASTDeclarationAmbiguity;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.EclipseObjects;
+
+public abstract class CRefactoring extends Refactoring {
+ protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ private static final int AST_STYLE = ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT | ITranslationUnit.AST_SKIP_INDEXED_HEADERS;
+
+ protected String name = Messages.HSRRefactoring_name;
+ protected IFile file;
+ protected ISelection selection;
+ protected RefactoringStatus initStatus;
+ protected IASTTranslationUnit unit;
+ private IIndex fIndex;
+ public static final String NEWLINE = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ public CRefactoring(IFile file, ISelection selection, boolean runHeadless) {
+ this.file = file;
+ this.selection = selection;
+ this.initStatus=new RefactoringStatus();
+
+ if(!runHeadless) {
+ IWorkbenchPage activePage = EclipseObjects.getActivePage();
+
+ if(!activePage.saveAllEditors(true)){
+ initStatus.addError("EDITOR_NOT_SAVE"); //$NON-NLS-1$
+ }
+ }
+ if(selection == null){
+ initStatus.addError(Messages.HSRRefactoring_SelectionNotValid);
+ }
+
+ }
+
+ public CRefactoring(IFile file, ISelection selection) {
+ this(file, selection, false);
+ }
+
+ private class ProblemFinder extends ASTVisitor{
+
+ private boolean problemFound = false;
+ private final RefactoringStatus status;
+
+ public ProblemFinder(RefactoringStatus status){
+ this.status = status;
+ }
+
+ {
+ shouldVisitProblems = true;
+ shouldVisitDeclarations = true;
+ shouldVisitExpressions = true;
+ shouldVisitStatements = true;
+ shouldVisitTypeIds = true;
+ }
+
+ @Override
+ public int visit(IASTProblem problem) {
+ addWarningToState();
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ if (declaration instanceof IASTProblemDeclaration) {
+ addWarningToState();
+ }
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof IASTProblemExpression) {
+ addWarningToState();
+ }
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTStatement statement) {
+ if (statement instanceof IASTProblemStatement) {
+ addWarningToState();
+ }
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTTypeId typeId) {
+ if (typeId instanceof IASTProblemTypeId) {
+ addWarningToState();
+ }
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ public boolean hasProblem() {
+ return problemFound;
+ }
+
+ private void addWarningToState() {
+ if(!problemFound){
+ status.addWarning(Messages.HSRRefactoring_CompileErrorInTU);
+ problemFound = true;
+ }
+ }
+
+ }
+
+ private class AmbiguityFinder extends ASTVisitor{
+
+ private boolean ambiguityFound = false;
+
+ {
+ shouldVisitDeclarations = true;
+ shouldVisitExpressions = true;
+ shouldVisitStatements= true;
+ }
+
+ @Override
+ public int visit(IASTDeclaration declaration) {
+ if (declaration instanceof IASTAmbiguousDeclaration || declaration instanceof IASTDeclarationAmbiguity) {
+ ambiguityFound = true;
+ }
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if (expression instanceof IASTAmbiguousExpression) {
+ ambiguityFound = true;
+ }
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ @Override
+ public int visit(IASTStatement statement) {
+ if (statement instanceof IASTAmbiguousStatement) {
+ ambiguityFound = true;
+ }
+ return ASTVisitor.PROCESS_CONTINUE;
+ }
+
+ public boolean ambiguityFound() {
+ return ambiguityFound;
+ }
+
+ }
+
+ @Override
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm)
+ throws CoreException, OperationCanceledException {
+ RefactoringStatus status = new RefactoringStatus();
+ return status;
+ }
+
+ @Override
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
+ throws CoreException, OperationCanceledException {
+ SubMonitor sm = SubMonitor.convert(pm, 10);
+ sm.subTask(Messages.HSRRefactoring_PM_LoadTU);
+ if(isProgressMonitorCanceld(sm, initStatus)) {
+ return initStatus;
+ }
+ if(!loadTranslationUnit(initStatus, sm.newChild(8))){
+ initStatus.addError(Messages.HSRRefactoring_CantLoadTU);
+ }
+ if(isProgressMonitorCanceld(sm, initStatus)) {
+ return initStatus;
+ }
+ sm.subTask(Messages.HSRRefactoring_PM_CheckTU);
+ translationUnitHasProblem();
+ if(translationUnitIsAmbiguous()) {
+ initStatus.addError(Messages.HSRRefactoring_Ambiguity);
+ }
+ sm.worked(2);
+ sm.subTask(Messages.HSRRefactoring_PM_InitRef);
+ sm.done();
+ return initStatus;
+ }
+
+ protected boolean isProgressMonitorCanceld(IProgressMonitor sm,
+ RefactoringStatus initStatus2) {
+ if(sm.isCanceled()) {
+ initStatus2.addFatalError(Messages.HSRRefactoring_CanceledByUser);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ ModificationCollector collector = new ModificationCollector();
+ collectModifications(pm, collector);
+ return collector.createFinalChange();
+ }
+
+ protected void collectModifications(IProgressMonitor pm, ModificationCollector collector)
+ throws CoreException, OperationCanceledException {
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ protected boolean loadTranslationUnit(RefactoringStatus status, IProgressMonitor mon) {
+ SubMonitor subMonitor = SubMonitor.convert(mon, 10);
+ if (file != null) {
+ try {
+ subMonitor.subTask(Messages.HSRRefactoring_PM_ParseTU);
+ ITranslationUnit tu = (ITranslationUnit) CCorePlugin
+ .getDefault().getCoreModel().create(file);
+ unit = tu.getAST(fIndex, AST_STYLE);
+ subMonitor.worked(2);
+ if(isProgressMonitorCanceld(subMonitor, initStatus)) {
+ return true;
+ }
+ subMonitor.subTask(Messages.HSRRefactoring_PM_MergeComments);
+
+ subMonitor.worked(8);
+ } catch (CoreException e) {
+ status.addFatalError(e.getMessage());
+ subMonitor.done();
+ return false;
+ }
+
+ } else {
+ status.addFatalError(Messages.NO_FILE);
+ subMonitor.done();
+ return false;
+ }
+ subMonitor.done();
+ return true;
+ }
+
+ private static class ExpressionPosition {
+ public int start;
+ public int end;
+
+ @Override
+ public String toString() {
+ return String.format("Position ranges from %d to %d and has a length of %d", Integer.valueOf(start), //$NON-NLS-1$
+ Integer.valueOf(end), Integer.valueOf(end - start));
+ }
+ }
+
+ protected static ExpressionPosition createExpressionPosition(IASTNode expression) {
+ ExpressionPosition selection = new ExpressionPosition();
+
+ int nodeLength = 0;
+ IASTNodeLocation[] nodeLocations = expression.getNodeLocations();
+ if (nodeLocations.length != 1) {
+ for (IASTNodeLocation location : nodeLocations) {
+ if (location instanceof IASTMacroExpansionLocation) {
+ IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) location;
+ selection.start = macroLoc.asFileLocation().getNodeOffset();
+ nodeLength = macroLoc.asFileLocation().getNodeLength();
+ }
+ }
+ } else {
+ if (nodeLocations[0] instanceof IASTMacroExpansionLocation) {
+ IASTMacroExpansionLocation macroLoc = (IASTMacroExpansionLocation) nodeLocations[0];
+ selection.start = macroLoc.asFileLocation().getNodeOffset();
+ nodeLength = macroLoc.asFileLocation().getNodeLength();
+ } else {
+ IASTFileLocation loc = expression.getFileLocation();
+ selection.start = loc.getNodeOffset();
+ nodeLength = loc.getNodeLength();
+ }
+ }
+ selection.end = selection.start + nodeLength;
+ return selection;
+ }
+
+ protected boolean isExpressionWhollyInSelection(ITextSelection textSelection, IASTNode expression) {
+ ExpressionPosition exprPos = createExpressionPosition(expression);
+
+ int selStart = textSelection.getOffset();
+ int selEnd = textSelection.getLength() + selStart;
+
+ return exprPos.start >= selStart && exprPos.end <= selEnd;
+ }
+
+ public static boolean isSelectionOnExpression(ITextSelection textSelection, IASTNode expression) {
+ ExpressionPosition exprPos = createExpressionPosition(expression);
+ int selStart = textSelection.getOffset();
+ int selEnd = textSelection.getLength() + selStart;
+ return exprPos.end > selStart && exprPos.start < selEnd;
+ }
+
+ protected boolean isInSameFile(IASTNode node) {
+ IPath path = new Path(node.getContainingFilename());
+ IFile locFile = ResourcesPlugin.getWorkspace().getRoot().getFile(file.getLocation());
+ IFile tmpFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ return locFile.equals(tmpFile);
+ }
+
+ protected boolean isInSameFileSelection(ITextSelection textSelection, IASTNode node) {
+ if( isInSameFile(node) ) {
+ return isSelectionOnExpression(textSelection, node);
+ }
+ return false;
+ }
+
+ protected MethodContext findContext(IASTNode node) {
+ boolean found = false;
+ MethodContext context = new MethodContext();
+ context.setType(MethodContext.ContextType.NONE);
+ IASTName name = null;
+ while(node != null && !found){
+ node = node.getParent();
+ if(node instanceof IASTFunctionDeclarator){
+ name=((IASTFunctionDeclarator)node).getName();
+ found = true;
+ context.setType(MethodContext.ContextType.FUNCTION);
+ } else if (node instanceof IASTFunctionDefinition){
+ name=((IASTFunctionDefinition)node).getDeclarator().getName();
+ found = true;
+ context.setType(MethodContext.ContextType.FUNCTION);
+ }
+ }
+ if(name instanceof ICPPASTQualifiedName){
+ ICPPASTQualifiedName qname =( ICPPASTQualifiedName )name;
+ context.setMethodQName(qname);
+ IBinding bind = qname.resolveBinding();
+ IASTName[] decl = unit.getDeclarationsInAST(bind);//TODO HSR funktioniert nur fuer namen aus der aktuellen Translationunit
+ for (IASTName tmpname : decl) {
+ IASTNode methoddefinition = tmpname.getParent().getParent();
+ if (methoddefinition instanceof IASTSimpleDeclaration) {
+ context.setMethodDeclarationName(tmpname);
+ context.setType(MethodContext.ContextType.METHOD);
+ }
+ }
+
+ }
+ return context;
+ }
+
+ protected boolean translationUnitHasProblem() {
+ ProblemFinder pf = new ProblemFinder(initStatus);
+ unit.accept(pf);
+ return pf.hasProblem();
+ }
+
+ protected boolean translationUnitIsAmbiguous() {
+ AmbiguityFinder af = new AmbiguityFinder();
+ unit.accept(af);
+ return af.ambiguityFound();
+ }
+
+ public void lockIndex() throws CoreException, InterruptedException {
+ if (fIndex == null) {
+ ICProject[] projects= CoreModel.getDefault().getCModel().getCProjects();
+ fIndex= CCorePlugin.getIndexManager().getIndex(projects);
+ }
+ fIndex.acquireReadLock();
+ }
+
+ public void unlockIndex() {
+ if (fIndex != null) {
+ fIndex.releaseReadLock();
+ }
+ fIndex= null;
+ }
+
+ public IIndex getIndex() {
+ return fIndex;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CTextFileChangeFactory.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CTextFileChangeFactory.java
new file mode 100644
index 00000000000..41868e1e6f6
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CTextFileChangeFactory.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Wind River Systems, Inc. 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:
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.refactoring;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+
+import org.eclipse.cdt.ui.refactoring.CTextFileChange;
+
+import org.eclipse.cdt.internal.core.dom.rewrite.ICTextFileChangeFactory;
+
+/**
+ * Factory provided to the core plugin to create appropriate text file changes.
+ * @since 5.0
+ */
+public class CTextFileChangeFactory implements ICTextFileChangeFactory {
+
+ public TextFileChange createCTextFileChange(IFile file) {
+ return new CTextFileChange(file.getName(), file);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Container.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Container.java
new file mode 100644
index 00000000000..af997d4c74e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Container.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.internal.ui.refactoring;
+
+public class Container<T>{
+ private T object;
+
+ public Container(T object) {
+ super();
+ this.object = object;
+ }
+
+ public Container() {
+ super();
+ this.object = null;
+ }
+
+ public T getObject() {
+ return object;
+ }
+
+ public void setObject(T object) {
+ this.object = object;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CreateFileChange.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CreateFileChange.java
new file mode 100644
index 00000000000..8706ff46464
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/CreateFileChange.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class CreateFileChange extends Change {
+
+ private String name;
+ private final IPath path;
+ private final String source;
+ private final String encoding;
+
+
+
+ public CreateFileChange(String name, IPath path, String source, String encoding) {
+ super();
+ this.name = name;
+ this.path = path;
+ this.source = source;
+ this.encoding = encoding;
+ }
+
+ public CreateFileChange(IPath path, String source, String encoding) {
+ this(null, path, source, encoding);
+ }
+
+ @Override
+ public Object getModifiedElement() {
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ return file;
+ }
+
+ @Override
+ public String getName() {
+ if(name == null) {
+ return NLS.bind(Messages.CreateFileChange_CreateFile, path.toOSString());
+ }else {
+ return name;
+ }
+ }
+
+ @Override
+ public void initializeValidationData(IProgressMonitor pm) {
+ }
+
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ RefactoringStatus result= new RefactoringStatus();
+ IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+
+ URI location= file.getLocationURI();
+ if (location == null) {
+ result.addFatalError(NLS.bind(Messages.CreateFileChange_UnknownLoc, file.getFullPath().toString()));
+ return result;
+ }
+
+ if (file.exists()) {
+ result.addFatalError( NLS.bind(Messages.CreateFileChange_FileExists,
+ file.getFullPath().toString()));
+ return result;
+ }
+ return result;
+ }
+
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ InputStream is = new ByteArrayInputStream(source.getBytes());
+ file.create(is, false, new SubProgressMonitor(pm, 1));
+ if(encoding != null) {
+ file.setCharset(encoding, new SubProgressMonitor(pm,1));
+ }
+ return new DeleteFileChange(file.getFullPath());
+ }
+
+
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/DeleteFileChange.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/DeleteFileChange.java
new file mode 100644
index 00000000000..911efce1422
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/DeleteFileChange.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class DeleteFileChange extends Change {
+
+ private IPath path;
+ private String source;
+
+ public DeleteFileChange(IPath path) {
+ this.path = path;
+ }
+
+ @Override
+ public Object getModifiedElement() {
+ return path;
+ }
+
+
+ @Override
+ public String getName() {
+ return Messages.DeleteFileChange_0 + path.toOSString();
+ }
+
+
+ @Override
+ public void initializeValidationData(IProgressMonitor pm) {
+ // Nothing to do
+ }
+
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ RefactoringStatus status = new RefactoringStatus();
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ if(!file.exists()) {
+ status.addFatalError(Messages.DeleteFileChange_1 + path.toString());
+ }
+ return status;
+ }
+
+ private String getSource(IFile file) throws CoreException {
+ String encoding= null;
+ try {
+ encoding= file.getCharset();
+ } catch (CoreException ex) {
+ // fall through. Take default encoding.
+ }
+ StringBuffer sb= new StringBuffer();
+ BufferedReader br= null;
+ InputStream in= null;
+ try {
+ in= file.getContents();
+ if (encoding != null)
+ br= new BufferedReader(new InputStreamReader(in, encoding));
+ else
+ br= new BufferedReader(new InputStreamReader(in));
+ int read= 0;
+ while ((read= br.read()) != -1) {
+ sb.append((char) read);
+ }
+ br.close();
+ } catch (IOException e){
+
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ source = getSource(file);
+ Change undo = new CreateFileChange(file.getFullPath(), source, file.getCharset());
+ file.delete(true,true, pm);
+ return undo;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/DocumentAdapter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/DocumentAdapter.java
new file mode 100644
index 00000000000..03edd5320b0
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/DocumentAdapter.java
@@ -0,0 +1,493 @@
+/*******************************************************************************
+ * Copyright (c) 2002, 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:
+ * Rational Software - Initial API and implementation
+ * Markus Schorn (Wind River Systems)
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.refactoring;
+
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourceAttributes;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultLineTracker;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.swt.widgets.Display;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.BufferChangedEvent;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.IBuffer;
+import org.eclipse.cdt.core.model.IBufferChangedListener;
+import org.eclipse.cdt.core.model.IOpenable;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+
+import org.eclipse.cdt.internal.core.model.IBufferFactory;
+
+
+/**
+ * Adapts <code>IDocument</code> to <code>IBuffer</code>. Uses the
+ * same algorithm as the text widget to determine the buffer's line delimiter.
+ * All text inserted into the buffer is converted to this line delimiter.
+ * This class is <code>public</code> for test purposes only.
+ *
+ * This class is similar to the JDT DocumentAdapter class.
+ */
+public class DocumentAdapter implements IBuffer, IAdaptable, IDocumentListener {
+
+ /**
+ * Executes a document set content call in the ui thread.
+ */
+ protected class DocumentSetCommand implements Runnable {
+
+ private String fContents;
+
+ public void run() {
+ fDocument.set(fContents);
+ }
+
+ public void set(String contents) {
+ fContents= contents;
+ Display.getDefault().syncExec(this);
+ }
+ }
+
+ /**
+ * Executes a document replace call in the ui thread.
+ */
+ protected class DocumentReplaceCommand implements Runnable {
+
+ private int fOffset;
+ private int fLength;
+ private String fText;
+
+ public void run() {
+ try {
+ fDocument.replace(fOffset, fLength, fText);
+ } catch (BadLocationException x) {
+ // ignore
+ }
+ }
+
+ public void replace(int offset, int length, String text) {
+ fOffset= offset;
+ fLength= length;
+ fText= text;
+ Display.getDefault().syncExec(this);
+ }
+ }
+
+ private static final boolean DEBUG_LINE_DELIMITERS= true;
+ public static final IBuffer NULL_BUFFER = new IBuffer(){
+ public void addBufferChangedListener(IBufferChangedListener listener) {}
+ public void append(char[] text) {}
+ public void append(String text) {}
+ public void close() {}
+ public char getChar(int position) {return 0;}
+ public char[] getCharacters() {return new char[0];}
+ public String getContents() {return "";} //$NON-NLS-1$
+ public int getLength() {return 0;}
+ public IOpenable getOwner() {return null;}
+ public String getText(int offset, int length) {return "";} //$NON-NLS-1$
+ public IResource getUnderlyingResource() {return null;}
+ public boolean hasUnsavedChanges() {return false;}
+ public boolean isClosed() {return false;}
+ public boolean isReadOnly() {return true;}
+ public void removeBufferChangedListener(IBufferChangedListener listener) {}
+ public void replace(int position, int length, char[] text) {}
+ public void replace(int position, int length, String text) {}
+ public void save(IProgressMonitor progress, boolean force) throws CModelException {}
+ public void setContents(char[] contents) {}
+ public void setContents(String contents) {}
+ };
+
+ public static IBufferFactory FACTORY= new IBufferFactory() {
+ public IBuffer createBuffer(IOpenable owner) {
+ if (owner instanceof IWorkingCopy) {
+ IWorkingCopy wc= (IWorkingCopy) owner;
+ ITranslationUnit tu= wc.getOriginalElement();
+ if (tu != null) {
+ IResource r= tu.getResource();
+ if (r instanceof IFile) {
+ return new DocumentAdapter(wc, (IFile) r);
+ }
+ }
+ }
+ assert false;
+ return DocumentAdapter.NULL_BUFFER;
+ }
+ };
+
+ private ITranslationUnit fTranslationUnit;
+ private IWorkingCopy fOwner;
+ private IFile fFile;
+ private ITextFileBuffer fTextFileBuffer;
+ IDocument fDocument;
+
+ private DocumentSetCommand fSetCmd= new DocumentSetCommand();
+ private DocumentReplaceCommand fReplaceCmd= new DocumentReplaceCommand();
+
+ private Set<String> fLegalLineDelimiters;
+
+ private List<IBufferChangedListener> fBufferListeners= new ArrayList<IBufferChangedListener>(3);
+ private IStatus fStatus;
+
+
+ public DocumentAdapter(IWorkingCopy owner, IFile file) {
+ fOwner= owner;
+ fFile= file;
+ fTranslationUnit= owner.getOriginalElement();
+ if (fTranslationUnit != null) {
+ addBufferChangedListener(fTranslationUnit);
+ }
+ initialize();
+ }
+
+ private void initialize() {
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ IPath location= fFile.getFullPath();
+ try {
+ manager.connect(location, LocationKind.IFILE, new NullProgressMonitor());
+ fTextFileBuffer= manager.getTextFileBuffer(location, LocationKind.IFILE);
+ fDocument= fTextFileBuffer.getDocument();
+ } catch (CoreException x) {
+ fStatus= x.getStatus();
+ fDocument= manager.createEmptyDocument(location, LocationKind.IFILE);
+ }
+ fDocument.addPrenotifiedDocumentListener(this);
+ }
+
+ /**
+ * Returns the status of this document adapter.
+ */
+ public IStatus getStatus() {
+ if (fStatus != null)
+ return fStatus;
+ if (fTextFileBuffer != null)
+ return fTextFileBuffer.getStatus();
+ return null;
+ }
+
+ /**
+ * Returns the adapted document.
+ *
+ * @return the adapted document
+ */
+ public IDocument getDocument() {
+ return fDocument;
+ }
+
+ /*
+ * @see IBuffer#addBufferChangedListener(IBufferChangedListener)
+ */
+ public void addBufferChangedListener(IBufferChangedListener listener) {
+ Assert.isNotNull(listener);
+ if (!fBufferListeners.contains(listener))
+ fBufferListeners.add(listener);
+ }
+
+ /*
+ * @see IBuffer#removeBufferChangedListener(IBufferChangedListener)
+ */
+ public void removeBufferChangedListener(IBufferChangedListener listener) {
+ Assert.isNotNull(listener);
+ fBufferListeners.remove(listener);
+ }
+
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#append(char[])
+ */
+ public void append(char[] text) {
+ append(new String(text));
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#append(java.lang.String)
+ */
+ public void append(String text) {
+ if (DEBUG_LINE_DELIMITERS) {
+ validateLineDelimiters(text);
+ }
+ fReplaceCmd.replace(fDocument.getLength(), 0, text);
+ }
+
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#close()
+ */
+ public void close() {
+
+ if (isClosed())
+ return;
+
+ IDocument d= fDocument;
+ fDocument= null;
+ d.removePrenotifiedDocumentListener(this);
+
+ if (fTextFileBuffer != null) {
+ ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
+ try {
+ manager.disconnect(fTextFileBuffer.getLocation(), LocationKind.IFILE, new NullProgressMonitor());
+ } catch (CoreException x) {
+ // ignore
+ }
+ fTextFileBuffer= null;
+ }
+
+ fireBufferChanged(new BufferChangedEvent(this, 0, 0, null));
+ fBufferListeners.clear();
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#getChar(int)
+ */
+ public char getChar(int position) {
+ try {
+ return fDocument.getChar(position);
+ } catch (BadLocationException x) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#getCharacters()
+ */
+ public char[] getCharacters() {
+ String content= getContents();
+ return content == null ? null : content.toCharArray();
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#getContents()
+ */
+ public String getContents() {
+ return fDocument.get();
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#getLength()
+ */
+ public int getLength() {
+ return fDocument.getLength();
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#getOwner()
+ */
+ public IOpenable getOwner() {
+ return fOwner;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#getText(int, int)
+ */
+ public String getText(int offset, int length) {
+ try {
+ return fDocument.get(offset, length);
+ } catch (BadLocationException x) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#getUnderlyingResource()
+ */
+ public IResource getUnderlyingResource() {
+ return fFile;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#hasUnsavedChanges()
+ */
+ public boolean hasUnsavedChanges() {
+ return fTextFileBuffer != null ? fTextFileBuffer.isDirty() : false;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#isClosed()
+ */
+ public boolean isClosed() {
+ return fDocument == null;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#isReadOnly()
+ */
+ public boolean isReadOnly() {
+ IResource resource= getUnderlyingResource();
+ if (resource != null) {
+ ResourceAttributes attributes = resource.getResourceAttributes();
+ if (attributes != null) {
+ return attributes.isReadOnly();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#replace(int, int, char[])
+ */
+ public void replace(int position, int length, char[] text) {
+ replace(position, length, new String(text));
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#replace(int, int, java.lang.String)
+ */
+ public void replace(int position, int length, String text) {
+ if (DEBUG_LINE_DELIMITERS) {
+ validateLineDelimiters(text);
+ }
+ fReplaceCmd.replace(position, length, text);
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#save(org.eclipse.core.runtime.IProgressMonitor, boolean)
+ */
+ public void save(IProgressMonitor progress, boolean force) throws CModelException {
+ try {
+ if (fTextFileBuffer != null)
+ fTextFileBuffer.commit(progress, force);
+ } catch (CoreException e) {
+ throw new CModelException(e);
+ }
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#setContents(char[])
+ */
+ public void setContents(char[] contents) {
+ setContents(new String(contents));
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.IBuffer#setContents(java.lang.String)
+ */
+ public void setContents(String contents) {
+ int oldLength= fDocument.getLength();
+
+ if (contents == null) {
+
+ if (oldLength != 0)
+ fSetCmd.set(""); //$NON-NLS-1$
+
+ } else {
+ // set only if different
+ if (DEBUG_LINE_DELIMITERS) {
+ validateLineDelimiters(contents);
+ }
+
+ int newLength= contents.length();
+ if (oldLength != newLength || !contents.equals(fDocument.get()))
+ fSetCmd.set(contents);
+
+ }
+ }
+
+ private void validateLineDelimiters(String contents) {
+
+ if (fLegalLineDelimiters == null) {
+ // collect all line delimiters in the document
+ HashSet<String> existingDelimiters= new HashSet<String>();
+
+ for (int i= fDocument.getNumberOfLines() - 1; i >= 0; i-- ) {
+ try {
+ String curr= fDocument.getLineDelimiter(i);
+ if (curr != null) {
+ existingDelimiters.add(curr);
+ }
+ } catch (BadLocationException e) {
+ CCorePlugin.log(e);
+ }
+ }
+ if (existingDelimiters.isEmpty()) {
+ return; // first insertion of a line delimiter: no test
+ }
+ fLegalLineDelimiters= existingDelimiters;
+
+ }
+
+ DefaultLineTracker tracker= new DefaultLineTracker();
+ tracker.set(contents);
+
+ int lines= tracker.getNumberOfLines();
+ if (lines <= 1)
+ return;
+
+ for (int i= 0; i < lines; i++) {
+ try {
+ String curr= tracker.getLineDelimiter(i);
+ if (curr != null && !fLegalLineDelimiters.contains(curr)) {
+ StringBuffer buf= new StringBuffer("New line delimiter added to new code: "); //$NON-NLS-1$
+ for (int k= 0; k < curr.length(); k++) {
+ buf.append(String.valueOf((int) curr.charAt(k)));
+ }
+ CCorePlugin.log(new Exception(buf.toString()));
+ }
+ } catch (BadLocationException e) {
+ CCorePlugin.log(e);
+ }
+ }
+ }
+
+ /*
+ * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
+ */
+ public void documentAboutToBeChanged(DocumentEvent event) {
+ // there is nothing to do here
+ }
+
+ /*
+ * @see IDocumentListener#documentChanged(DocumentEvent)
+ */
+ public void documentChanged(DocumentEvent event) {
+ fireBufferChanged(new BufferChangedEvent(this, event.getOffset(), event.getLength(), event.getText()));
+ }
+
+ private void fireBufferChanged(BufferChangedEvent event) {
+ if (fBufferListeners != null && fBufferListeners.size() > 0) {
+ Iterator<IBufferChangedListener> e= new ArrayList<IBufferChangedListener>(fBufferListeners).iterator();
+ while (e.hasNext())
+ e.next().bufferChanged(event);
+ }
+ }
+
+ public ITextFileBuffer getTextFileBuffer() {
+ return fTextFileBuffer;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter) {
+ if (adapter.isAssignableFrom(ITextFileBuffer.class)) {
+ return fTextFileBuffer;
+ }
+ return null;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java
new file mode 100644
index 00000000000..87eaa0e3483
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Messages.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import org.eclipse.osgi.util.NLS;
+
+public final class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.refactoring.messages";//$NON-NLS-1$
+
+ private Messages() {
+ // Do not instantiate
+ }
+
+ public static String DeleteFileChange_0;
+ public static String DeleteFileChange_1;
+ public static String HSRRefactoring_name;
+ public static String HSRRefactoring_PM_LoadTU;
+ public static String HSRRefactoring_PM_CheckTU;
+ public static String HSRRefactoring_PM_InitRef;
+ public static String HSRRefactoring_PM_ParseTU;
+ public static String HSRRefactoring_PM_MergeComments;
+ public static String HSRRefactoring_CanceledByUser;
+ public static String HSRRefactoring_CompileErrorInTU;
+ public static String AddDeclarationNodeToClassChange_AddDeclaration;
+ public static String CreateFileChange_CreateFile;
+ public static String CreateFileChange_UnknownLoc;
+ public static String CreateFileChange_FileExists;
+ public static String HSRRefactoring_SelectionNotValid;
+ public static String HSRRefactoring_CantLoadTU;
+ public static String HSRRefactoring_Ambiguity;
+ public static String NO_FILE;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/MethodContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/MethodContext.java
new file mode 100644
index 00000000000..5d6805111f4
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/MethodContext.java
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IScope;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
+import org.eclipse.cdt.ui.CUIPlugin;
+
+import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTVisibilityLabel;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
+
+public class MethodContext {
+ public enum ContextType{ NONE, FUNCTION, METHOD }
+
+ private ContextType type;
+ private IASTName declarationName;
+ private ICPPASTQualifiedName qname;
+
+ public ContextType getType() {
+ return type;
+ }
+
+ public void setType(ContextType type) {
+ this.type = type;
+ }
+
+ public void setMethodDeclarationName(IASTName tmpname) {
+ this.declarationName=tmpname;
+ }
+
+ public IASTName getMethodDeclarationName(){
+ return declarationName;
+ }
+
+ public IASTSimpleDeclaration getMethodDeclaration(){
+ IASTNode parent = declarationName.getParent().getParent();
+ if (parent instanceof IASTSimpleDeclaration) {
+ return (IASTSimpleDeclaration) parent;
+ } else {
+ return null;
+ }
+ }
+
+ public ICPPASTVisiblityLabel getMethodDeclarationASTVisibility(){
+ ICPPASTVisiblityLabel label = new CPPASTVisibilityLabel();
+ ICPPMember member = ((ICPPMember)qname.resolveBinding());
+
+ try {
+ label.setVisibility(member.getVisibility());
+ } catch (DOMException e) {
+ CUIPlugin.getDefault().log(e);
+ }
+ return label;
+ }
+
+ public Visibility getMethodDeclarationVisibility(){
+ return Visibility.getVisibility(declarationName);
+ }
+
+ public void setMethodQName(ICPPASTQualifiedName qname) {
+ this.qname = qname;
+ }
+
+ public ICPPASTQualifiedName getMethodQName() {
+ return qname;
+ }
+
+ public static boolean isSameClass(ICPPASTQualifiedName qname1, ICPPASTQualifiedName qname2) {
+ ICPPInternalBinding bind1 = getClassBinding(qname1);
+ ICPPInternalBinding bind2 = getClassBinding(qname2);
+ return isSameClass(bind1,bind2);
+ }
+
+ public static boolean isSameOrSubClass(MethodContext context1, MethodContext contextOfSameOrSubclass) {
+ ICPPInternalBinding bind1 = getICPPInternalBinding(context1);
+ ICPPInternalBinding subclassBind = getICPPInternalBinding(contextOfSameOrSubclass);
+ if(isSameClass(bind1,subclassBind)){
+ return true;
+ } else {
+ return isSubclass(bind1,subclassBind);
+ }
+ }
+
+ private static boolean isSubclass(ICPPInternalBinding bind1, ICPPInternalBinding subclassBind) {
+ if (subclassBind instanceof ICPPClassType) {
+ ICPPClassType classType = (ICPPClassType) subclassBind;
+ ICPPBase[] bases;
+ try {
+ bases = classType.getBases();
+ } catch (DOMException e) {
+ return false;
+ }
+ for (ICPPBase base : bases) {
+ if(isSameClass(base,bind1)){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public static boolean isSameClass(MethodContext context1, MethodContext context2) {
+ ICPPInternalBinding bind1 = getICPPInternalBinding(context1);
+ ICPPInternalBinding bind2 = getICPPInternalBinding(context2);
+
+ return isSameClass(bind1,bind2);
+ }
+
+ private static boolean isSameClass(ICPPBase base, ICPPInternalBinding bind2) {
+ try {
+ IBinding bind1 = base.getBaseClass();
+ IScope scope1 = bind1.getScope();
+ if(scope1 == null)
+ return false;
+ IASTNode node1 = ASTInternal.getPhysicalNodeOfScope(scope1);
+
+ IScope scope2 = bind2.getScope();
+ if(scope2 == null)
+ return false;
+ IASTNode node2 = ASTInternal.getPhysicalNodeOfScope(scope2);
+
+ if( node1.equals(node2) ){
+ if (bind1 instanceof ICPPInternalBinding) {
+ ICPPInternalBinding bind1int = (ICPPInternalBinding) bind1;
+ return bind1int.getDefinition().equals(bind2.getDefinition());
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ } catch (DOMException e) {
+ return false;
+ }
+ }
+
+ private static boolean isSameClass(ICPPInternalBinding bind1, ICPPInternalBinding bind2) {
+ try {
+ IScope scope1 = bind1.getScope();
+ if(scope1 == null)
+ return false;
+ IASTNode node1 = ASTInternal.getPhysicalNodeOfScope(scope1);
+
+ IScope scope2 = bind2.getScope();
+ if(scope2 == null)
+ return false;
+ IASTNode node2 = ASTInternal.getPhysicalNodeOfScope(scope2);
+
+ if( node1.equals(node2) ){
+ return bind1.getDefinition().equals(bind2.getDefinition());
+ } else {
+ return false;
+ }
+ } catch (DOMException e) {
+ return false;
+ }
+ }
+
+ public static ICPPInternalBinding getICPPInternalBinding(MethodContext context) {
+ IASTName decl = context.getMethodDeclarationName();
+ IASTNode node = decl;
+ while(node != null){
+ if (node instanceof ICPPASTCompositeTypeSpecifier) {
+ ICPPASTCompositeTypeSpecifier type = (ICPPASTCompositeTypeSpecifier) node;
+ IASTName classname = type.getName();
+ ICPPInternalBinding bind = (ICPPInternalBinding)classname.resolveBinding();
+
+ return bind;
+ }
+
+ node = node.getParent();
+ }
+
+ return null;
+ }
+
+ private static ICPPInternalBinding getClassBinding(ICPPASTQualifiedName qname){
+ IASTName classname = qname.getNames()[qname.getNames().length - 2];
+ ICPPInternalBinding bind = (ICPPInternalBinding)classname.resolveBinding();
+ return bind;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/ModificationCollector.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/ModificationCollector.java
new file mode 100644
index 00000000000..3347c0ac3f7
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/ModificationCollector.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
+
+/**
+ * @author Mirko Stocker
+ *
+ * A ModificationCollector can be passed through a refactoring and manages the rewriters
+ * and additional changes a refactoring can create.
+ */
+public class ModificationCollector {
+
+ // Each Translationunit can have only one ASTRewrite
+ private final Map<IASTTranslationUnit, ASTRewrite> rewriters = new HashMap<IASTTranslationUnit, ASTRewrite>();
+
+ private Collection<CreateFileChange> changes;
+
+ public ASTRewrite rewriterForTranslationUnit(IASTTranslationUnit unit) {
+ if(! rewriters.containsKey(unit)) {
+ rewriters.put(unit, ASTRewrite.create(unit));
+ }
+
+ return rewriters.get(unit);
+ }
+
+ // Creating new files doesn't concern the rewriter, the refactorings can add them here as needed.
+ public void addFileChange(CreateFileChange change) {
+ if(changes == null) {
+ changes = new ArrayList<CreateFileChange>();
+ }
+ changes.add(change);
+ }
+
+ public CompositeChange createFinalChange() {
+ // Synthetic changes aren't displayed and therefore don't need a name
+ CompositeChange result = new CompositeChange(""); //$NON-NLS-1$
+ result.markAsSynthetic();
+
+ if(changes != null)
+ result.addAll(changes.toArray(new Change[changes.size()]));
+
+ for (ASTRewrite each : rewriters.values()) {
+ result.add(each.rewriteAST());
+ }
+
+ return result;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java
new file mode 100644
index 00000000000..f76113d5ec9
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NameNVisibilityInformation.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import java.util.Vector;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
+
+public class NameNVisibilityInformation {
+
+ private String name = ""; //$NON-NLS-1$
+ private VisibilityEnum visibility = VisibilityEnum.v_public;
+ private final Vector<String> usedNames = new Vector<String>();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public VisibilityEnum getVisibility() {
+ return visibility;
+ }
+
+ public void setVisibility(VisibilityEnum visibility) {
+ this.visibility = visibility;
+ }
+
+ public Vector<String> getUsedNames(){
+ return usedNames;
+ }
+
+ public void addNameToUsedNames(String name) {
+ usedNames.add(name);
+ }
+
+ public void addNamesToUsedNames(Vector<String> names) {
+ usedNames.addAll(names);
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner.java
new file mode 100644
index 00000000000..004224f4aff
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/RefactoringRunner.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public abstract class RefactoringRunner {
+
+ protected IFile file;
+ protected ISelection selection;
+ protected IWorkbenchWindow window;
+
+ public RefactoringRunner(IFile file, ISelection selection, IWorkbenchWindow window) {
+ super();
+ this.file = file;
+ this.selection = selection;
+ if(window != null) {
+ this.window = window;
+ }else {
+ this.window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ }
+ }
+
+ public abstract void run();
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/UndoCTextFileChange.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/UndoCTextFileChange.java
new file mode 100644
index 00000000000..294ae79505d
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/UndoCTextFileChange.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 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
+ * Markus Schorn (Wind River Systems)
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.refactoring;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.ContentStamp;
+import org.eclipse.ltk.core.refactoring.UndoTextFileChange;
+import org.eclipse.text.edits.MalformedTreeException;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.text.edits.UndoEdit;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.IBuffer;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.core.model.IWorkingCopy;
+
+/**
+ * UndoCTextFileChange that uses a working copy in order to generate CModel events.
+ * @author janees
+ */
+public class UndoCTextFileChange
+ extends UndoTextFileChange {
+
+ UndoEdit mUndoEdit = null;
+
+ public UndoCTextFileChange(String name, IFile file, UndoEdit undo, ContentStamp stamp, int saveMode) {
+ super(name, file, undo, stamp, saveMode);
+ mUndoEdit = undo;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.UndoTextFileChange#perform(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change perform(IProgressMonitor pm)
+ throws CoreException {
+ if (pm == null){
+ pm= new NullProgressMonitor();
+ }
+ Object obj = getModifiedElement();
+ if(!(obj instanceof IFile)){
+ throw new IllegalArgumentException();
+ }
+ final IFile file = (IFile) obj;
+ ICElement element = CoreModel.getDefault().create(file);
+ if (!(element instanceof ITranslationUnit)) {
+ return super.perform(pm);
+ }
+
+ final ITranslationUnit tu = (ITranslationUnit) element;
+ IWorkingCopy wc= tu.getWorkingCopy(pm, DocumentAdapter.FACTORY);
+ final IBuffer buffer= wc.getBuffer();
+ assert buffer instanceof DocumentAdapter;
+ if (buffer instanceof DocumentAdapter) {
+ IDocument document= ((DocumentAdapter) buffer).getDocument();
+ try {
+ UndoEdit redo= mUndoEdit.apply(document, TextEdit.CREATE_UNDO);
+ wc.commit(false, pm);
+ return new UndoCTextFileChange(getName(), file, redo, null, getSaveMode());
+ } catch (MalformedTreeException e) {
+ CCorePlugin.log(e);
+ } catch (BadLocationException e) {
+ CCorePlugin.log(e);
+ }
+ finally {
+ wc.destroy();
+ }
+ }
+ return null;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Visibility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Visibility.java
new file mode 100644
index 00000000000..1093192d386
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/Visibility.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring;
+
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisiblityLabel;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
+
+public class Visibility {
+
+ /**
+ * The visibility public.
+ */
+ public static final Visibility PUBLIC = new Visibility(){
+ @Override
+ public String stringValue(){
+ return "public"; //$NON-NLS-1$
+ }
+ };
+
+ /**
+ * The visibility protected.
+ */
+ public static final Visibility PROTECTED = new Visibility(){
+ @Override
+ public String stringValue(){
+ return "protected"; //$NON-NLS-1$
+ }
+ };
+
+ /**
+ * The visibility private.
+ */
+ public static final Visibility PRIVATE = new Visibility(){
+ @Override
+ public String stringValue(){
+ return "private"; //$NON-NLS-1$
+ }
+ };
+
+ /**
+ * The visibility unknown, cause of parsing error.
+ */
+ public static final Visibility UNKNOWN = new Visibility(){ };
+
+
+
+ private Visibility(){ }
+
+ public static Visibility getVisibility(IASTName name){
+ try {
+ ICPPMember member = ((ICPPMember)name.resolveBinding());
+
+ switch (member.getVisibility()){
+ case ICPPASTVisiblityLabel.v_public:
+ return PUBLIC;
+ case ICPPASTVisiblityLabel.v_protected:
+ return PROTECTED;
+ case ICPPASTVisiblityLabel.v_private:
+ return PRIVATE;
+ default:
+ return UNKNOWN;
+ }
+
+ } catch (DOMException e) {
+ return UNKNOWN;
+ } catch (RuntimeException e){
+ return UNKNOWN;
+ }
+ }
+
+ public String stringValue(){
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public String toString() {
+ return stringValue();
+ }
+
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/CTextEditChangePreviewViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/CTextEditChangePreviewViewer.java
new file mode 100644
index 00000000000..937262c1500
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/CTextEditChangePreviewViewer.java
@@ -0,0 +1,265 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring.dialogs;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareViewerPane;
+import org.eclipse.compare.IEncodedStreamContentAccessor;
+import org.eclipse.compare.IResourceProvider;
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.contentmergeviewer.IMergeViewerContentProvider;
+import org.eclipse.compare.structuremergeviewer.DiffNode;
+import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput;
+import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.cdt.ui.CElementLabelProvider;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.refactoring.CTextFileChange;
+
+import org.eclipse.cdt.internal.ui.compare.CMergeViewer;
+import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
+import org.eclipse.cdt.internal.ui.text.CTextTools;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class CTextEditChangePreviewViewer implements IChangePreviewViewer {
+
+ private CPPMergeViewer viewer;
+ private CTextEditChangePane viewerPane;
+ private CTextEditChangePreviewViewerContentProvider textEditChangeContentProvider;
+
+ private static class CTextEditChangePane extends CompareViewerPane{
+
+ /**
+ * @param parent
+ * @param style
+ */
+ public CTextEditChangePane(Composite parent, int style) {
+ super(parent, style);
+ }
+
+ }
+
+ private class CPPMergeViewer extends CMergeViewer{
+
+ /**
+ * @param parent
+ * @param styles
+ * @param mp
+ */
+ public CPPMergeViewer(Composite parent, int styles, CompareConfiguration mp) {
+ super(parent, styles, mp);
+ }
+
+ @Override
+ protected CSourceViewerConfiguration getSourceViewerConfiguration() {
+ CTextTools tools= CUIPlugin.getDefault().getTextTools();
+ IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
+ return new CSourceViewerConfiguration(tools.getColorManager(), store, null, tools.getDocumentPartitioning());
+ }
+
+ @Override
+ protected void configureTextViewer(TextViewer textViewer) {
+ if (textViewer instanceof SourceViewer) {
+ ((SourceViewer)textViewer).configure(getSourceViewerConfiguration());
+ }
+ }
+
+
+ }
+
+
+ private class CTextEditChangePreviewViewerContentProvider implements IMergeViewerContentProvider{
+
+ public Object getAncestorContent(Object input) {
+ if (input instanceof ICompareInput)
+ return ((ICompareInput) input).getAncestor();
+ return null;
+ }
+
+ public Image getAncestorImage(Object input) {
+ if (input instanceof ICompareInput) {
+ ITypedElement ancestor = ((ICompareInput) input).getAncestor();
+ if(ancestor != null) {
+ return ancestor.getImage();
+ }
+ }
+ return null;
+ }
+
+ public String getAncestorLabel(Object input) {
+ if (input instanceof ICompareInput) {
+ ITypedElement ancestor = ((ICompareInput) input).getAncestor();
+ if(ancestor != null) {
+ return ancestor.getName();
+ }
+ }
+ return null;
+ }
+
+ public Object getLeftContent(Object input) {
+ if (input instanceof ICompareInput)
+ return ((ICompareInput) input).getLeft();
+ return null;
+ }
+
+ public Image getLeftImage(Object input) {
+ if (input instanceof ICompareInput)
+ return ((ICompareInput) input).getLeft().getImage();
+ return null;
+ }
+
+ public String getLeftLabel(Object input) {
+ return Messages.CTextEditChangePreviewViewer_OrgSource;
+ }
+
+ public Object getRightContent(Object input) {
+ if (input instanceof ICompareInput)
+ return ((ICompareInput) input).getRight();
+ return null;
+ }
+
+ public Image getRightImage(Object input) {
+ if (input instanceof ICompareInput)
+ return ((ICompareInput) input).getRight().getImage();
+ return null;
+ }
+
+ public String getRightLabel(Object input) {
+ return Messages.CTextEditChangePreviewViewer_RefactoredSource;
+ }
+
+ public boolean isLeftEditable(Object input) {
+ return false;
+ }
+
+ public boolean isRightEditable(Object input) {
+ return false;
+ }
+
+ public void saveLeftContent(Object input, byte[] bytes) {
+ //No Edits
+ }
+
+ public void saveRightContent(Object input, byte[] bytes) {
+ //No Edits
+ }
+
+ public boolean showAncestor(Object input) {
+ //no Ancestor
+ return false;
+ }
+
+ public void dispose() {
+ //
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ //Nothing to do
+ }
+
+ }
+
+ private static class CompareElement implements ITypedElement, IEncodedStreamContentAccessor, IResourceProvider {
+ private static final String ENCODING= "UTF-8"; //$NON-NLS-1$
+ private final String fContent;
+ private final String fType;
+ private final IResource fResource;
+ public CompareElement(String content, String type, IResource resource) {
+ fContent= content;
+ fType= type;
+ fResource= resource;
+ }
+ public String getName() {
+ return ""; //$NON-NLS-1$
+ }
+ public Image getImage() {
+ return null;
+ }
+ public String getType() {
+ return fType;
+ }
+ public InputStream getContents() throws CoreException {
+ try {
+ return new ByteArrayInputStream(fContent.getBytes(ENCODING));
+ } catch (UnsupportedEncodingException e) {
+ return new ByteArrayInputStream(fContent.getBytes());
+ }
+ }
+ public String getCharset() {
+ return ENCODING;
+ }
+ public IResource getResource() {
+ return fResource;
+ }
+ }
+
+ public void createControl(Composite parent) {
+ CompareConfiguration compConfig = new CompareConfiguration();
+ compConfig.setLeftEditable(false);
+ compConfig.setRightEditable(false);
+ viewerPane = new CTextEditChangePane(parent, SWT.BORDER | SWT.FLAT);
+ viewer = new CPPMergeViewer(viewerPane,SWT.MULTI | SWT.FULL_SELECTION, compConfig);
+ textEditChangeContentProvider = new CTextEditChangePreviewViewerContentProvider();
+ viewer.setContentProvider(textEditChangeContentProvider);
+ viewerPane.setContent(viewer.getControl());
+ }
+
+ public Control getControl() {
+ return viewerPane;
+ }
+
+ public void setInput(ChangePreviewViewerInput input) {
+ try {
+ Change change= input.getChange();
+ if (change instanceof CTextFileChange) {
+ CTextFileChange editChange= (CTextFileChange)change;
+ setInput(editChange, editChange.getCurrentContent(new NullProgressMonitor()), editChange.getPreviewContent(new NullProgressMonitor()), editChange.getTextType());
+ return;
+ } else {
+ viewer.setInput(null);
+ }
+ } catch (CoreException e) {
+ viewer.setInput(null);
+ }
+ }
+
+ private void setInput(CTextFileChange change, String left, String right, String type) {
+ IFile resource = change.getFile();
+ viewerPane.setText(resource.getName());
+ viewerPane.setImage(new CElementLabelProvider().getImage(resource));
+ viewer.setInput(new DiffNode(
+ new CompareElement(left, type, resource),
+ new CompareElement(right, type, resource)));
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/CreateFileChangePreview.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/CreateFileChangePreview.java
new file mode 100644
index 00000000000..3e2ff1ecb46
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/CreateFileChangePreview.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.internal.ui.refactoring.dialogs;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.source.SourceViewer;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput;
+import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.cdt.ui.CUIPlugin;
+
+import org.eclipse.cdt.internal.ui.editor.CSourceViewer;
+import org.eclipse.cdt.internal.ui.refactoring.CreateFileChange;
+import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
+import org.eclipse.cdt.internal.ui.text.CTextTools;
+import org.eclipse.cdt.internal.ui.util.ViewerPane;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public class CreateFileChangePreview implements IChangePreviewViewer {
+
+ private static class CreateFileChangePane extends ViewerPane{
+
+ /**
+ * @param parent
+ * @param style
+ */
+ public CreateFileChangePane(Composite parent, int style) {
+ super(parent, style);
+ }
+
+ }
+
+ private CreateFileChangePane control;
+ private SourceViewer srcViewer;
+ private CTextTools textTools;
+
+ public void createControl(Composite parent) {
+ control = new CreateFileChangePane(parent, SWT.BORDER | SWT.FLAT);
+ Dialog.applyDialogFont(control);
+ srcViewer= new CSourceViewer(control, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION, CUIPlugin.getDefault().getPreferenceStore());
+ textTools = CUIPlugin.getDefault().getTextTools();
+ IPreferenceStore store= CUIPlugin.getDefault().getCombinedPreferenceStore();
+ CSourceViewerConfiguration sourceViewerConfiguration = new CSourceViewerConfiguration(textTools.getColorManager(), store, null, textTools.getDocumentPartitioning());
+ srcViewer.configure(sourceViewerConfiguration);
+ srcViewer.setEditable(false);
+ control.setContent(srcViewer.getControl());
+ }
+
+ public Control getControl() {
+ return control;
+ }
+
+ public void setInput(ChangePreviewViewerInput input) {
+ Assert.isNotNull(input);
+ if(control != null) {
+ Change change = input.getChange();
+ if (change instanceof CreateFileChange) {
+ CreateFileChange createFileChange = (CreateFileChange) change;
+ control.setText(createFileChange.getName());
+ Document document = new Document(createFileChange.getSource());
+ textTools.setupCDocument(document);
+ srcViewer.setDocument(document);
+ }
+ }
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ExtractInputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ExtractInputPage.java
new file mode 100644
index 00000000000..ddabf5ab613
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ExtractInputPage.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring.dialogs;
+
+
+import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.cdt.internal.ui.refactoring.NameNVisibilityInformation;
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierHelper;
+import org.eclipse.cdt.internal.ui.refactoring.utils.IdentifierResult;
+import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
+
+/**
+ * @author Emanuel Graf
+ *
+ */
+public abstract class ExtractInputPage extends UserInputWizardPage {
+
+ protected NameAndVisibilityComposite control;
+ protected NameNVisibilityInformation info;
+ protected String label = Messages.ExtractInputPage_ReplaceInSubclass;
+ protected String errorLabel = Messages.ExtractInputPage_EnterName;
+
+ public ExtractInputPage(String name, NameNVisibilityInformation info) {
+ super(name);
+ this.info = info;
+ }
+
+ public void createControl(Composite parent) {
+ control = new NameAndVisibilityComposite(parent, label);
+ setTitle(getName());
+ setPageComplete(false);
+ control.getConstantNameText().addKeyListener(new KeyAdapter(){
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ info.setName(control.getConstantNameText().getText());
+ checkName();
+ }
+
+ });
+
+ for (Control buttons : control.getVisibiltyGroup().getChildren()) {
+ buttons.addMouseListener(new MouseAdapter() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ String text = ((Button)e.getSource()).getText();
+ visibilityChange(text);
+ }
+
+ });
+ }
+
+ checkName();
+ setControl(control);
+ }
+
+ protected void checkName() {
+ String methodName = control.getConstantNameText().getText();
+ IdentifierResult result = IdentifierHelper.checkIdentifierName(methodName);
+ if(result.isCorrect()){
+ setErrorMessage(null);
+ setPageComplete(true);
+ }
+ else{
+ setErrorMessage(NLS.bind(Messages.ExtractInputPage_CheckName, result.getMessage()));
+ setPageComplete(false);
+ }
+ }
+
+ abstract protected void verifyName(String name);
+
+ protected void visibilityChange(String visibilityText) {
+ info.setVisibility(VisibilityEnum.getEnumForStringRepresentation(visibilityText));
+ }
+
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/LabeledTextField.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/LabeledTextField.java
new file mode 100644
index 00000000000..691b6d7fd59
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/LabeledTextField.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring.dialogs;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * @author Mirko Stocker
+ *
+ */
+public class LabeledTextField extends Composite {
+
+ private final Text textField;
+
+ public LabeledTextField(Composite parent, String labelName, String textContent) {
+ super(parent, SWT.NONE);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginWidth = 0;
+ setLayout(layout);
+
+ Label label = new Label(this, SWT.NONE);
+ label.setText(labelName);
+ label.setLayoutData(new GridData());
+
+ textField = new Text(this, SWT.BORDER |SWT.SINGLE);
+ textField.setText(textContent);
+ textField.selectAll();
+ GridData textData = new GridData(GridData.FILL_HORIZONTAL);
+ textData.grabExcessHorizontalSpace = true;
+ textField.setLayoutData(textData);
+ }
+
+ public LabeledTextField(Composite parent, String labelName) {
+ this(parent, labelName, ""); //$NON-NLS-1$
+ }
+
+ public Text getText() {
+ return textField;
+ }
+
+ public String getFieldContent(){
+ return textField.getText();
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/Messages.java
new file mode 100644
index 00000000000..be8666fcec7
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/Messages.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.internal.ui.refactoring.dialogs;
+
+import org.eclipse.osgi.util.NLS;
+
+public final class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.refactoring.dialogs.messages";//$NON-NLS-1$
+
+ private Messages() {
+ // Do not instantiate
+ }
+
+ public static String CTextEditChangePreviewViewer_OrgSource;
+ public static String CTextEditChangePreviewViewer_RefactoredSource;
+ public static String ExtractInputPage_ReplaceInSubclass;
+ public static String ExtractInputPage_EnterName;
+ public static String ExtractInputPage_CheckName;
+ public static String VisibilitySelectionPanel_AccessModifier;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/NameAndVisibilityComposite.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/NameAndVisibilityComposite.java
new file mode 100644
index 00000000000..80db77eaecb
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/NameAndVisibilityComposite.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring.dialogs;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
+
+public class NameAndVisibilityComposite extends Composite {
+
+ private LabeledTextField constantName;
+ private final String labelName;
+ private final VisibilitySelectionPanel visibilityPanel;
+
+ public NameAndVisibilityComposite(Composite parent, String labelName) {
+ this(parent, labelName, VisibilityEnum.v_public);
+ }
+
+ public NameAndVisibilityComposite(Composite parent, String labelName, VisibilityEnum defaultVisibility){
+
+ super(parent, SWT.NONE);
+
+ this.labelName = labelName;
+
+ setLayout(new GridLayout());
+
+ createNewMethodNameComposite(this);
+ visibilityPanel = new VisibilitySelectionPanel(this, defaultVisibility,SWT.NONE);
+ }
+
+
+ public Text getConstantNameText() {
+ return constantName.getText();
+ }
+
+ public Group getVisibiltyGroup() {
+ return visibilityPanel.getGroup();
+ }
+
+ public void visibilityPanelsetVisible(boolean visible) {
+ visibilityPanel.setVisible(visible);
+ }
+
+
+ private void createNewMethodNameComposite(Composite control) {
+ Composite methodNameComposite = new Composite(control, SWT.NONE);
+ FillLayout compositeLayout = new FillLayout(SWT.HORIZONTAL);
+ GridData gridData = new GridData(SWT.FILL,SWT.BEGINNING, true, false);
+ gridData.horizontalAlignment = GridData.FILL;
+ methodNameComposite.setLayoutData(gridData);
+ methodNameComposite.setLayout(compositeLayout);
+ constantName = new LabeledTextField(methodNameComposite, labelName);
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/VisibilitySelectionPanel.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/VisibilitySelectionPanel.java
new file mode 100644
index 00000000000..e7b90ccb6d1
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/VisibilitySelectionPanel.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * 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.internal.ui.refactoring.dialogs;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+
+import org.eclipse.cdt.internal.ui.refactoring.utils.VisibilityEnum;
+
+/**
+ * @author Thomas Corbat
+ *
+ */
+public class VisibilitySelectionPanel extends Composite {
+
+
+ private Button publicAccessRadioButton;
+ private Button protectedAccessRadioButton;
+ private Button privateAccessRadioButton;
+ private Group accessModifierGroup;
+
+ public VisibilitySelectionPanel(Composite parent, VisibilityEnum defaultVisibility, int style) {
+ super(parent, style);
+
+ FillLayout compositeLayout = new FillLayout(SWT.HORIZONTAL);
+ setLayout(compositeLayout);
+ GridData gridData = new GridData(SWT.FILL,SWT.BEGINNING, true, false);
+ gridData.horizontalAlignment = GridData.FILL;
+ setLayoutData(gridData);
+
+ createAccessModifierComposite(this);
+ setSelected(defaultVisibility);
+
+ }
+
+ private void createAccessModifierComposite(Composite control) {
+
+ accessModifierGroup = new Group(this, SWT.SHADOW_NONE );
+ RowLayout groupLayout = new RowLayout(SWT.HORIZONTAL);
+ groupLayout.fill = true;
+ accessModifierGroup.setLayout(groupLayout);
+ accessModifierGroup.setText(Messages.VisibilitySelectionPanel_AccessModifier);
+
+ publicAccessRadioButton = new Button(accessModifierGroup, SWT.RADIO | SWT.LEFT);
+ publicAccessRadioButton.setText(VisibilityEnum.v_public.toString());
+