Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] refactoring update

Here is an update on refactoring:

* compiles with M7
* fixed warnings in plugin.xml

* added a warning, in case potential matches exist.
* improved heuristics on macro arguments.
* some optimizations for macro renamings.

* simplified type-hierarchy of RenameProcessors.
* added a few testcases.

Markus.
Index: plugin.xml
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/plugin.xml,v
retrieving revision 1.2
diff -u -r1.2 plugin.xml
--- plugin.xml	22 Apr 2005 17:10:09 -0000	1.2
+++ plugin.xml	18 May 2005 09:45:57 -0000
@@ -143,36 +143,38 @@
             categoryId="org.eclipse.cdt.ui.category.refactoring"
             id="org.eclipse.cdt.ui.edit.text.c.rename.element">
       </command>
-      <keyBinding
-            keySequence="Alt+Shift+R"
-            contextId="org.eclipse.cdt.ui.cEditorScope"
-            commandId="org.eclipse.cdt.ui.edit.text.c.rename.element"
-            keyConfigurationId="org.eclipse.ui.defaultAcceleratorConfiguration">
-      </keyBinding>
       <command
             name="%ActionDefinition.refactorRedo.name"
             description="%ActionDefinition.refactorRedo.description"
             categoryId="org.eclipse.cdt.ui.category.refactoring"
             id="org.eclipse.cdt.ui.edit.text.c.refactor.redo">
       </command>
-      <keyBinding
-            keySequence="Alt+Shift+Y"
-            contextId="org.eclipse.cdt.ui.cEditorScope"
-            commandId="org.eclipse.cdt.ui.edit.text.c.refactor.redo"
-            keyConfigurationId="org.eclipse.ui.defaultAcceleratorConfiguration">
-      </keyBinding>
       <command
             name="%ActionDefinition.refactorUndo.name"
             description="%ActionDefinition.refactorUndo.description"
             categoryId="org.eclipse.cdt.ui.category.refactoring"
             id="org.eclipse.cdt.ui.edit.text.c.refactor.undo">
-      </command>
-      <keyBinding
-            keySequence="Alt+Shift+Z"
+      </command>      
+   </extension>    
+   <extension
+         point="org.eclipse.ui.bindings">
+   	  <key
+            sequence="Alt+Shift+R"
+            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+            contextId="org.eclipse.cdt.ui.cEditorScope"
+            commandId="org.eclipse.cdt.ui.edit.text.c.rename.element"
+      />
+   	  <key
+            sequence="Alt+Shift+Y"
+            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+            contextId="org.eclipse.cdt.ui.cEditorScope"
+            commandId="org.eclipse.cdt.ui.edit.text.c.refactor.redo"
+      />
+   	  <key
+            sequence="Alt+Shift+Z"
+            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
             contextId="org.eclipse.cdt.ui.cEditorScope"
             commandId="org.eclipse.cdt.ui.edit.text.c.refactor.undo"
-            keyConfigurationId="org.eclipse.ui.defaultAcceleratorConfiguration">
-      </keyBinding>
-      
-   </extension>            
+      />
+   </extension>    
 </plugin>
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/META-INF/MANIFEST.MF,v
retrieving revision 1.2
diff -u -r1.2 MANIFEST.MF
--- META-INF/MANIFEST.MF	22 Apr 2005 17:10:09 -0000	1.2
+++ META-INF/MANIFEST.MF	18 May 2005 09:45:57 -0000
@@ -1,6 +1,6 @@
 Manifest-Version: 1.0
 Bundle-Name: %pluginName
-Bundle-SymbolicName: org.eclipse.cdt.refactoring
+Bundle-SymbolicName: org.eclipse.cdt.refactoring;singleton=true
 Bundle-Version: 3.0.0
 Bundle-ClassPath: refactoring.jar
 Bundle-Activator: org.eclipse.cdt.refactoring.CRefactoringPlugin
Index: src/org/eclipse/cdt/internal/refactoring/ASTManager.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/ASTManager.java,v
retrieving revision 1.7
diff -u -r1.7 ASTManager.java
--- src/org/eclipse/cdt/internal/refactoring/ASTManager.java	17 May 2005 20:16:22 -0000	1.7
+++ src/org/eclipse/cdt/internal/refactoring/ASTManager.java	18 May 2005 09:45:57 -0000
@@ -45,7 +45,7 @@
     private CRefactoringArgument fArgument;
     private IBinding[] fValidBindings;
     private String fRenameTo;
-    private HashSet fEqualToValidBinding;
+    private HashMap fKnownBindings;
     private HashSet fConflictingBinding;
 
     public static String nth_of_m(int n, int m) {
@@ -102,6 +102,9 @@
         }
         String n1= b1.getName();
         String n2= b2.getName();
+        if (n1==null || n2==null) {
+            return UNKNOWN;
+        }
         if (!n1.equals(n2)) {
             return FALSE;
         }
@@ -115,7 +118,9 @@
                 return FALSE;
             }
             IScope s1= c1.getCompositeScope();
+            if (s1 != null) s1= s1.getParent();
             IScope s2= c2.getCompositeScope();
+            if (s2 != null) s2= s2.getParent();
             return isSameScope(s1, s2, false);
         }
 
@@ -203,9 +208,13 @@
             if (!(b2 instanceof IMacroBinding)) {
                 return FALSE;
             }
-            IMacroBinding m1= (IMacroBinding) b1;
-            IMacroBinding m2= (IMacroBinding) b2;
-            return isSameScope(m1.getScope(), m2.getScope(), true);
+            return TRUE;
+        }
+        if (b1 instanceof IEnumeration) {
+            if (!(b2 instanceof IEnumeration)) {
+                return FALSE;
+            }
+            return isSameScope(b1.getScope(), b2.getScope(), false);
         }
         int scopeCmp= isSameScope(b1.getScope(), b2.getScope(), false);
         if (scopeCmp != TRUE) {
@@ -222,7 +231,20 @@
         if (s1==s2) {
             return TRUE;
         }
-        if (s1==null || s2==null) {
+        IASTNode node1= s1==null ? null : s1.getPhysicalNode();
+        IASTNode node2= s2==null ? null : s2.getPhysicalNode();
+
+        // forward declarations do not have parent scopes.
+        if (s1==null) {
+            if (!fileStatic && node2 instanceof IASTTranslationUnit) {
+                return TRUE;
+            }
+            return UNKNOWN;
+        }
+        if (s2==null) {
+            if (!fileStatic && node1 instanceof IASTTranslationUnit) {
+                return TRUE;
+            }
             return UNKNOWN;
         }
         
@@ -231,8 +253,6 @@
         }
 
         
-        IASTNode node1= s1.getPhysicalNode();
-        IASTNode node2= s2.getPhysicalNode();
 
         if (node1 instanceof IASTTranslationUnit &&
                 node2 instanceof IASTTranslationUnit) {
@@ -378,6 +398,9 @@
 
 
     private static int isSameType(IType t1, IType t2) throws DOMException {
+        if (t1 != null && t2 != null && t1.isSameType(t2)) {
+            return TRUE;
+        }
         t1= getRealType(t1);
         t2= getRealType(t2);
         if (t1==t2) {
@@ -593,30 +616,20 @@
         for (int i= expansionCount-2; i>=0; i--) {
             macroExpansions[i]= (IASTMacroExpansion) macroExpansions[i+1].getExpansionLocations()[0];
         }
-        String orig= name.getTranslationUnit().getUnpreprocessedSignature(locs);
         
-        int count= countOccurrencesOf(name.toString(), orig);
-        if (count != 1) {
-            return -1;
-        }
         // because of bug#90956 we need to use a heuristics.
-        int lidx= orig.indexOf(name.toString());
-        if (lidx == -1) {
+        String orig= name.getTranslationUnit().getUnpreprocessedSignature(locs);
+        Pattern p= Pattern.compile("\\b" +name.toString()+"\\b");  //$NON-NLS-1$//$NON-NLS-2$
+        Matcher m= p.matcher(orig);
+        if (!m.find()) {
             return -1;
         }
-        return locs[0].getNodeOffset()+lidx;
-    }
-
-    private static int countOccurrencesOf(String sf, String text) {
-        Pattern p= Pattern.compile("\\b" +sf+"\\b");  //$NON-NLS-1$//$NON-NLS-2$
-        Matcher m= p.matcher(text);
-        int count= 0;
-        int start= 0;
-        while(m.find(start)) {
-            count++;
-            start= m.end();
+        int start= m.start();
+        
+        if (m.find(m.end())) {
+            return -1;
         }
-        return count;
+        return locs[0].getNodeOffset()+start;
     }
 
     private static IScope getContainingScope(IASTName name) {
@@ -914,19 +927,21 @@
 
     private void analyzeTextMatchesOfTranslationUnit(IASTTranslationUnit tu, 
             final CRefactoringMatchStore store, final RefactoringStatus status) {
-        fEqualToValidBinding= new HashSet();
+        fKnownBindings= new HashMap();
         fConflictingBinding= new HashSet();
         final Set paths= new HashSet();
+        boolean renamesMacro= fArgument.getArgumentKind() == CRefactory.ARGUMENT_MACRO;
         
         analyzeMacroMatches(tu, store, paths, status);
-        if (status.hasFatalError()) {
-            return;
-        }
-        if (fArgument.getArgumentKind() == CRefactory.ARGUMENT_MACRO) {
-            analyzeRenameToMatches(tu, store, paths, status);
+        if (status.hasFatalError()) return;
+
+        if (renamesMacro) {
+            findConflictingBindingsWithNewName(tu, store, paths, status);
+            if (status.hasFatalError()) return;
         }
 
         analyzeLanguageMatches(tu, store, paths, status);
+        if (status.hasFatalError()) return;
 
         for (Iterator iter = paths.iterator(); iter.hasNext();) {
             IPath path = (IPath) iter.next();
@@ -935,7 +950,7 @@
             }
         }
         handleConflictingBindings(tu, status);
-        fEqualToValidBinding= null;
+        fKnownBindings= null;
         fConflictingBinding= null;
     }
 
@@ -970,7 +985,7 @@
             else if (lookfor.equals(macroNameStr)) {
                 IPath path= analyzeAstMatch(macroName, store, false, status);
                 pathsVisited.add(path);
-                IBinding macroBinding= macroName.getBinding();
+                IBinding macroBinding= macroName.resolveBinding();
                 if (macroBinding != null) {
                     IASTName[] refs= tu.getReferences(macroBinding);
                     for (int j = 0; j < refs.length; j++) {
@@ -995,13 +1010,11 @@
                         IASTFileLocation floc= mdef.getNodeLocations()[0].asFileLocation();
                         int offset= floc.getNodeOffset();
                         int end= offset+ floc.getNodeLength();
-                        Collection matches= store.getMatchesForPath(new Path(floc.getFileName()));
+                        Collection matches= store.findMatchesInRange(
+                                new Path(floc.getFileName()), offset, end);
                         for (Iterator iter = matches.iterator(); iter.hasNext();) {
                             CRefactoringMatch match = (CRefactoringMatch) iter.next();
-                            int mo= match.getOffset();
-                            if (mo>=offset && mo<end) {
-                                match.setASTInformation(CRefactoringMatch.AST_REFERENCE_OTHER);
-                            }
+                            match.setASTInformation(CRefactoringMatch.AST_REFERENCE_OTHER);
                         }
                     }
                 }
@@ -1009,12 +1022,40 @@
         }
     }
 
-    private void analyzeRenameToMatches(IASTTranslationUnit tu, 
+//    private void markPreprocessorMatchesAsReference(
+//            IASTTranslationUnit tu, final CRefactoringMatchStore store, 
+//            final Set pathsVisited, final RefactoringStatus status) {
+//        IASTPreprocessorStatement[] pdefs= tu.getAllPreprocessorStatements();
+//        for (int i = 0; i < pdefs.length; i++) {
+//            IASTPreprocessorStatement pdef = pdefs[i];
+//            if (pdef instanceof IASTPreprocessorIfdefStatement
+//                    || pdef instanceof IASTPreprocessorIfndefStatement
+//                    || pdef instanceof IASTPreprocessorIfStatement
+//                    || pdef instanceof IASTPreprocessorElifStatement
+////                  || pdef instanceof IASTPreprocessorElseStatement
+//                    || pdef instanceof IASTPreprocessorUndefStatement) {
+//        IPath path= new Path(tu.getContainingFilename());
+//                if (!store.getMatchesForPath(path).isEmpty()) {
+//                    IASTFileLocation floc= pdef.getNodeLocations()[0].asFileLocation();
+//                    int offset= floc.getNodeOffset();
+//                    int end= offset+ floc.getNodeLength();
+//                    Collection matches= store.findMatchesInRange(
+//                            new Path(floc.getFileName()), offset, end);
+//                    for (Iterator iter = matches.iterator(); iter.hasNext();) {
+//                        CRefactoringMatch match = (CRefactoringMatch) iter.next();
+//                        match.setASTInformation(CRefactoringMatch.AST_REFERENCE);
+//                    }
+//                }
+//            }
+//        }
+//    }
+
+    private void findConflictingBindingsWithNewName(IASTTranslationUnit tu, 
             CRefactoringMatchStore store, final Set paths, 
             final RefactoringStatus status) {
         ASTNameVisitor nv = new ASTSpecificNameVisitor(fRenameTo) {
             protected int visitName(IASTName name, boolean isDestructor) {
-                IPath path= analyzeRenameToMatch(status, name);
+                IPath path= addConflictingBindingForName(status, name);
                 paths.add(path);
                 return ASTVisitor.PROCESS_CONTINUE;
             }
@@ -1022,7 +1063,7 @@
         tu.accept(nv);
     }
 
-    protected IPath analyzeRenameToMatch(final RefactoringStatus status, IASTName name) {
+    protected IPath addConflictingBindingForName(final RefactoringStatus status, IASTName name) {
         IASTNodeLocation[] locations= name.getNodeLocations();
         IPath path= null;
         if (locations != null && locations.length==1) {
@@ -1077,8 +1118,9 @@
         
         IBinding binding= name.resolveBinding();
         int cmp= FALSE;
-        if (fEqualToValidBinding.contains(binding)) {
-            cmp= TRUE;
+        Integer cmpObj= (Integer) fKnownBindings.get(binding);
+        if (cmpObj != null) {
+            cmp= cmpObj.intValue();
         }
         else if (binding instanceof IProblemBinding) {
             cmp= UNKNOWN;
@@ -1093,7 +1135,6 @@
                         cmp= cmp0;
                     }
                     if (cmp0 == TRUE) {
-                        fEqualToValidBinding.add(renameBinding);
                         break;
                     }
                 }
@@ -1102,6 +1143,7 @@
                     cmp= UNKNOWN;
                 }
             }
+            fKnownBindings.put(binding, new Integer(cmp));
         }
         switch(cmp) {
         case TRUE:
@@ -1244,7 +1286,7 @@
                         else {
                             try {
                                 if (conflictingVar.isStatic()) {
-                                    what= Messages.getString("CRenameTextProcessor.fileStaticVariable"); //$NON-NLS-1$
+                                    what= Messages.getString("CRenameProcessorDelegate.fileStaticVariable"); //$NON-NLS-1$
                                 }
                             } catch (DOMException e) {
                             }
@@ -1306,10 +1348,10 @@
                             } catch (DOMException e) {
                             }
                             if (isStatic) {
-                                what= Messages.getString("CRenameTextProcessor.fileStaticFunction"); //$NON-NLS-1$
+                                what= Messages.getString("CRenameProcessorDelegate.fileStaticFunction"); //$NON-NLS-1$
                             }
                             else {
-                                what= Messages.getString("CRenameTextProcessor.globalFunction"); //$NON-NLS-1$
+                                what= Messages.getString("CRenameProcessorDelegate.globalFunction"); //$NON-NLS-1$
                             }
                         }
                     }
@@ -1318,12 +1360,12 @@
                         conflict instanceof IEnumeration ||
                         conflict instanceof ITypedef) {
                     if (isContainer || isMacro) {
-                        what= Messages.getString("CRenameTextProcessor.type"); //$NON-NLS-1$
+                        what= Messages.getString("CRenameProcessorDelegate.type"); //$NON-NLS-1$
                     }
                 }
                 else if (conflict instanceof ICPPNamespace) {
                     if (isContainer || isMacro) {
-                        what= Messages.getString("CRenameTextProcessor.namespace"); //$NON-NLS-1$
+                        what= Messages.getString("CRenameProcessorDelegate.namespace"); //$NON-NLS-1$
                         if (argKind==CRefactory.ARGUMENT_NAMESPACE) {
                             warn= true;
                         }
@@ -1360,10 +1402,11 @@
         String name= fArgument.getName();
         IBinding[] newBindingsAboverOrEqual= null;
         IScope oldBindingsScope= null;
-        for (Iterator iter = fEqualToValidBinding.iterator(); 
-                (newBindingsAboverOrEqual==null || newBindingsAboverOrEqual.length==0) && iter.hasNext();) {
-            IBinding oldBinding = (IBinding) iter.next();
-            if (oldBinding.getName().equals(name)) {
+        for (Iterator iter= fKnownBindings.entrySet().iterator(); iter.hasNext();) {
+            Map.Entry entry= (Map.Entry) iter.next();
+            IBinding oldBinding= (IBinding) entry.getKey();
+            Integer value= (Integer) entry.getValue();
+            if (value.intValue() == TRUE && oldBinding.getName().equals(name)) {
                 try {
                     oldBindingsScope = oldBinding.getScope();
                     if (oldBindingsScope != null) {
@@ -1373,6 +1416,10 @@
                     handleDOMException(tu, e, status);
                 }
             }            
+
+            if (newBindingsAboverOrEqual!=null && newBindingsAboverOrEqual.length>0) {
+                break;
+            }
         }
         if (newBindingsAboverOrEqual == null) {
             newBindingsAboverOrEqual= new IBinding[0];
Index: src/org/eclipse/cdt/internal/refactoring/ASTNameVisitor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/ASTNameVisitor.java,v
retrieving revision 1.3
diff -u -r1.3 ASTNameVisitor.java
--- src/org/eclipse/cdt/internal/refactoring/ASTNameVisitor.java	12 May 2005 14:39:16 -0000	1.3
+++ src/org/eclipse/cdt/internal/refactoring/ASTNameVisitor.java	18 May 2005 09:45:57 -0000
@@ -28,70 +28,51 @@
     public ASTNameVisitor(String fileName, int offset) {
         fFileName= fileName;
         fOffset= offset;
-        shouldVisitDeclarations= shouldVisitStatements= shouldVisitNames= shouldVisitEnumerators=true;
+        shouldVisitNames=true;
     }
     
     abstract protected int visitName(IASTName name);
     
     final public int visit(IASTName name) {
-        if (checkLocation(name, true)) {
-            if (name instanceof ICPPASTQualifiedName) {
-                ICPPASTQualifiedName qn= (ICPPASTQualifiedName) name;
-                IASTName[] names= qn.getNames();
-                boolean visited= false;
-                for (int i = 0; i < names.length; i++) {
-                    if (checkLocation(names[i], false)) {
-                        if (visitName(names[i]) == PROCESS_ABORT) {
-                            return PROCESS_ABORT;
-                        }
-                        visited= true;
+        if (name instanceof ICPPASTQualifiedName) {
+            ICPPASTQualifiedName qn= (ICPPASTQualifiedName) name;
+            IASTName[] names= qn.getNames();
+            boolean visited= false;
+            for (int i = 0; i < names.length; i++) {
+                if (checkLocation(names[i])) {
+                    if (visitName(names[i]) == PROCESS_ABORT) {
+                        return PROCESS_ABORT;
                     }
+                    visited= true;
                 }
-                if (!visited && names.length>0) {
-                    if (checkLocation(name, false)) {
-                        return visitName(names[names.length-1]);
-                    }
+            }
+            if (!visited && names.length>0) {
+                if (checkLocation(name)) {
+                    return visitName(names[names.length-1]);
                 }
-                return PROCESS_SKIP;
             }
-            return visitName(name);
-        }
-        return PROCESS_SKIP;
-    }
-    
-    final public int visit(IASTDeclaration decl) {
-        if (checkLocation(decl, true)) {
-            return PROCESS_CONTINUE;
         }
-        return PROCESS_SKIP;
-    }
-     
-    final public int visit(IASTStatement statement) {
-        if (checkLocation(statement, true)) {
-            return PROCESS_CONTINUE;
+        else if (checkLocation(name)) {
+            return visitName(name);
         }
-        return PROCESS_SKIP;
+        return PROCESS_CONTINUE;
     }
-    
-    private boolean checkLocation(IASTNode node, boolean allowMultiLocs) {
+        
+    private boolean checkLocation(IASTNode node) {
         if (fFileName==null) {
             return true;
         }
-        IASTNodeLocation[] locs= node.getNodeLocations();
-        if (locs==null || locs.length==0) {
+        if (!fFileName.equals(node.getContainingFilename())) {
             return false;
         }
-        if (locs.length > 1) {
-            return allowMultiLocs;
-        }
-        IASTFileLocation floc= locs[0].asFileLocation();
-        if (!fFileName.equals(floc.getFileName())) {
+        IASTNodeLocation[] locs= node.getNodeLocations();
+        if (locs==null || locs.length!=1) {
             return false;
         }
-        
         if (fOffset==-1) {
             return true;
         }
+        IASTFileLocation floc= locs[0].asFileLocation();
         int off= floc.getNodeOffset();
         int len = floc.getNodeLength();
         if (locs[0] instanceof IASTMacroExpansion && node instanceof IASTName) {
Index: src/org/eclipse/cdt/internal/refactoring/CRefactoringMatchStore.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/CRefactoringMatchStore.java,v
retrieving revision 1.3
diff -u -r1.3 CRefactoringMatchStore.java
--- src/org/eclipse/cdt/internal/refactoring/CRefactoringMatchStore.java	12 May 2005 14:39:16 -0000	1.3
+++ src/org/eclipse/cdt/internal/refactoring/CRefactoringMatchStore.java	18 May 2005 09:45:57 -0000
@@ -16,6 +16,7 @@
 import org.eclipse.cdt.refactoring.CRefactoringMatch;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
 
 public class CRefactoringMatchStore {
     private Map fFileToPathMap= new HashMap();
@@ -78,12 +79,12 @@
 
     public Collection getMatchesForPath(IPath path) {
         if (path != null) {
-            Map map= (Map) fPathToMatches.get(path);
+            SortedMap map= (SortedMap) fPathToMatches.get(path);
             if (map != null) {
                 return map.keySet();
             }
         }
-        return Collections.EMPTY_LIST;
+        return Collections.EMPTY_SET;
     }
 
     public CRefactoringMatch findMatch(IPath path, int nodeOffset) {
@@ -101,4 +102,15 @@
             fFileToPathMap.remove(file);
         }
     }
+
+    public Collection findMatchesInRange(Path path, int offset, int end) {
+        if (path != null) {
+            SortedMap map= (SortedMap) fPathToMatches.get(path);
+            if (map != null) {
+                return map.subMap(new CRefactoringMatch(null, offset, 0, 0),
+                        new CRefactoringMatch(null, end, 0, 0)).keySet();
+            }
+        }
+        return Collections.EMPTY_SET;
+    }
 }
Index: src/org/eclipse/cdt/internal/refactoring/CRenameGlobalProcessor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/CRenameGlobalProcessor.java,v
retrieving revision 1.2
diff -u -r1.2 CRenameGlobalProcessor.java
--- src/org/eclipse/cdt/internal/refactoring/CRenameGlobalProcessor.java	15 Apr 2005 13:55:27 -0000	1.2
+++ src/org/eclipse/cdt/internal/refactoring/CRenameGlobalProcessor.java	18 May 2005 09:45:57 -0000
@@ -16,16 +16,13 @@
 /**
  * Rename processor that sets up the input page for renaming a global entity.
  */
-public class CRenameGlobalProcessor extends CRenameTextProcessor {
+public class CRenameGlobalProcessor extends CRenameProcessorDelegate {
 
     public CRenameGlobalProcessor(CRenameProcessor processor, String name) {
         super(processor, name);
-    }
-
-    protected int getAvailableOptions() {
-        return CRefactory.OPTION_ASK_SCOPE | 
-            CRefactory.OPTION_IN_CODE |
-            CRefactory.OPTION_IN_COMMENT | 
-            CRefactory.OPTION_IN_MACRO_DEFINITION;
+        setAvailableOptions(CRefactory.OPTION_ASK_SCOPE | 
+                CRefactory.OPTION_IN_CODE |
+                CRefactory.OPTION_IN_COMMENT | 
+                CRefactory.OPTION_IN_MACRO_DEFINITION);
     }
 }
Index: src/org/eclipse/cdt/internal/refactoring/CRenameIncludeProcessor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/CRenameIncludeProcessor.java,v
retrieving revision 1.1
diff -u -r1.1 CRenameIncludeProcessor.java
--- src/org/eclipse/cdt/internal/refactoring/CRenameIncludeProcessor.java	9 Mar 2005 21:49:02 -0000	1.1
+++ src/org/eclipse/cdt/internal/refactoring/CRenameIncludeProcessor.java	18 May 2005 09:45:57 -0000
@@ -15,30 +15,19 @@
 /**
  * Rename processor setting up input page for renaming include directives.
  */
-public class CRenameIncludeProcessor extends CRenameTextProcessor {
+public class CRenameIncludeProcessor extends CRenameProcessorDelegate {
     
     public CRenameIncludeProcessor(CRenameProcessor input, String kind) {
         super(input, kind);
+        setAvailableOptions(CRefactory.OPTION_ASK_SCOPE | 
+                CRefactory.OPTION_IN_COMMENT | 
+                CRefactory.OPTION_IN_MACRO_DEFINITION);
+        setOptionsForcingPreview(-1);
+        setOptionsEnablingScope(-1);
     }
 
-    // overrider
-    public int getAvailableOptions() {
-        return CRefactory.OPTION_ASK_SCOPE | 
-        CRefactory.OPTION_IN_COMMENT | 
-        CRefactory.OPTION_IN_MACRO_DEFINITION;
-    }
 
     protected int getAcceptedLocations(int selectedOptions) {
         return selectedOptions | CRefactory.OPTION_IN_INCLUDE_DIRECTIVE;
     }
-    
-    // overrider
-    public int getOptionsForcingPreview() {
-        return -1;
-    }
-
-    // overrider
-    public int getOptionsEnablingScope() {
-        return -1;
-    }
 }
Index: src/org/eclipse/cdt/internal/refactoring/CRenameLocalProcessor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/CRenameLocalProcessor.java,v
retrieving revision 1.2
diff -u -r1.2 CRenameLocalProcessor.java
--- src/org/eclipse/cdt/internal/refactoring/CRenameLocalProcessor.java	15 Apr 2005 13:55:27 -0000	1.2
+++ src/org/eclipse/cdt/internal/refactoring/CRenameLocalProcessor.java	18 May 2005 09:45:57 -0000
@@ -20,25 +20,18 @@
 /**
  * Rename processor, setting up input page for a local rename.
  */
-public class CRenameLocalProcessor extends CRenameTextProcessor {
+public class CRenameLocalProcessor extends CRenameProcessorDelegate {
     private IScope fScope;
     public CRenameLocalProcessor(CRenameProcessor input, String kind, IScope scope) {
         super(input, kind);
         fScope= scope;
+        setAvailableOptions(0);
+        setOptionsForcingPreview(0);
     }
     
     // overrider
     protected int getAcceptedLocations(int selectedOptions) {
-        return CRefactory.OPTION_IN_CODE | selectedOptions;
-    }
-    // overrider
-    protected int getAvailableOptions() {
-        return 0;
-    }
-    
-    // overrider
-    protected int getOptionsForcingPreview() {
-        return 0;
+        return CRefactory.OPTION_IN_CODE | CRefactory.OPTION_IN_MACRO_DEFINITION | selectedOptions;
     }
     
     // overrider
Index: src/org/eclipse/cdt/internal/refactoring/CRenameMacroProcessor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/CRenameMacroProcessor.java,v
retrieving revision 1.1
diff -u -r1.1 CRenameMacroProcessor.java
--- src/org/eclipse/cdt/internal/refactoring/CRenameMacroProcessor.java	15 Apr 2005 13:55:27 -0000	1.1
+++ src/org/eclipse/cdt/internal/refactoring/CRenameMacroProcessor.java	18 May 2005 09:45:57 -0000
@@ -11,7 +11,13 @@
 
 package org.eclipse.cdt.internal.refactoring;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.cdt.refactoring.CRefactoringMatch;
 import org.eclipse.cdt.refactoring.CRefactory;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
 
 
 /**
@@ -21,13 +27,21 @@
 
     public CRenameMacroProcessor(CRenameProcessor processor, String name) {
         super(processor, name);
+        setAvailableOptions(CRefactory.OPTION_ASK_SCOPE | 
+                CRefactory.OPTION_IN_CODE |
+                CRefactory.OPTION_IN_COMMENT | 
+                CRefactory.OPTION_IN_MACRO_DEFINITION |
+                CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE);
     }
     
-    protected int getAvailableOptions() {
-        return CRefactory.OPTION_ASK_SCOPE | 
-            CRefactory.OPTION_IN_CODE |
-            CRefactory.OPTION_IN_COMMENT | 
-            CRefactory.OPTION_IN_MACRO_DEFINITION |
-            CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE;
+    protected void analyzeTextMatches(ArrayList matches, IProgressMonitor monitor, 
+            RefactoringStatus status) {
+        for (Iterator iter = matches.iterator(); iter.hasNext();) {
+            CRefactoringMatch m = (CRefactoringMatch) iter.next();
+            if ((m.getLocation() & CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE) != 0) {
+                m.setASTInformation(CRefactoringMatch.AST_REFERENCE);
+            }
+        }
+        super.analyzeTextMatches(matches, monitor, status);
     }
 }
Index: src/org/eclipse/cdt/internal/refactoring/CRenameProcessorDelegate.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/CRenameProcessorDelegate.java,v
retrieving revision 1.1
diff -u -r1.1 CRenameProcessorDelegate.java
--- src/org/eclipse/cdt/internal/refactoring/CRenameProcessorDelegate.java	9 Mar 2005 21:49:02 -0000	1.1
+++ src/org/eclipse/cdt/internal/refactoring/CRenameProcessorDelegate.java	18 May 2005 09:45:58 -0000
@@ -11,11 +11,19 @@
 
 package org.eclipse.cdt.internal.refactoring;
 
+import java.text.MessageFormat;
+import java.util.*;
+
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.refactoring.*;
 import org.eclipse.cdt.refactoring.CRefactory;
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.*;
+import org.eclipse.ltk.core.refactoring.*;
 import org.eclipse.ltk.core.refactoring.Change;
 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
 import org.eclipse.ltk.core.refactoring.participants.*;
+import org.eclipse.text.edits.*;
 
 /**
  * Abstract base for all different rename processors used by the top 
@@ -23,18 +31,30 @@
  */
 public abstract class CRenameProcessorDelegate {
     private CRenameProcessor fTopProcessor;
+    private ArrayList fMatches= null;
+    protected String fProcessorBaseName;
+    private int fAvailableOptions=         
+        CRefactory.OPTION_ASK_SCOPE | 
+        CRefactory.OPTION_IN_CODE |
+        CRefactory.OPTION_IN_COMMENT | 
+        CRefactory.OPTION_IN_MACRO_DEFINITION |
+        CRefactory.OPTION_IN_STRING_LITERAL;
+
+    private int fOptionsForcingPreview=
+        CRefactory.OPTION_IN_CODE |
+        CRefactory.OPTION_IN_COMMENT | 
+        CRefactory.OPTION_IN_MACRO_DEFINITION |
+        CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE |
+        CRefactory.OPTION_IN_STRING_LITERAL;
+    
+    private int fOptionsEnablingScope= fOptionsForcingPreview;        
+
 
-    protected CRenameProcessorDelegate(CRenameProcessor topProcessor) {
+    protected CRenameProcessorDelegate(CRenameProcessor topProcessor, String name) {
         fTopProcessor= topProcessor;
+        fProcessorBaseName= name;
     }
     
-    abstract public String getProcessorName();
-    abstract public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
-        throws CoreException, OperationCanceledException;
-    abstract public RefactoringStatus checkFinalConditions(IProgressMonitor pm, 
-            CheckConditionsContext context) throws CoreException;
-    abstract public Change createChange(IProgressMonitor pm) throws CoreException;
-
     final public CRefactoringArgument getArgument() {
         return fTopProcessor.getArgument();
     }
@@ -56,26 +76,210 @@
     final public ASTManager getAstManager() {
         return fTopProcessor.getAstManager();
     }
+    final public String getProcessorName() {
+        String identifier= getArgument().getName();
+        if (identifier != null) {
+            return MessageFormat.format(
+                    Messages.getString("CRenameProcessorDelegate.wizard.title"),  //$NON-NLS-1$
+                    new Object[] {fProcessorBaseName, identifier});
+        }
+        return null;
+    }
 
     /**
      * The options presented by the page in the refactoring wizard.
      */
-    protected int getAvailableOptions() {
-        return 0;
+    public void setAvailableOptions(int options) {
+        fAvailableOptions= options;
+    }
+    final int getAvailableOptions() {
+        return fAvailableOptions;
     }
 
     /**
      * The options each of which forces the preview, when selected.
      */
-    protected int getOptionsForcingPreview() {
-        return 0;
+    public void setOptionsForcingPreview(int options) {
+        fOptionsForcingPreview= options;
+    }
+    
+    final int getOptionsForcingPreview() {
+    	return fOptionsForcingPreview;
     }
 
     /**
      * The options that need the scope definition. When one of them is 
      * selected, the scope options are enabled.
      */
-    protected int getOptionsEnablingScope() {
-        return 0;
+    public void setOptionsEnablingScope(int options) {
+        fOptionsEnablingScope= options;
+    }
+    
+    final int getOptionsEnablingScope() {
+        return fOptionsEnablingScope;
+    }
+
+    protected int getSearchScope() {
+        return getSelectedScope();
+    }
+
+    public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+        return new RefactoringStatus();
+    }
+
+    public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context) throws CoreException, OperationCanceledException {
+        RefactoringStatus result= new RefactoringStatus();
+        monitor.beginTask(Messages.getString("CRenameProcessorDelegate.task.checkFinalCondition"), 2); //$NON-NLS-1$
+        IFile file= getArgument().getSourceFile();
+        //assert file!=null;
+    
+        // perform text-search
+        fMatches= new ArrayList();
+        ICRefactoringSearch txtSearch= getManager().getTextSearch();
+        IStatus stat= txtSearch.searchWord(getSearchScope(), file, getSelectedWorkingSet(), 
+                getManager().getCCppPatterns(), getArgument().getName(), 
+                new SubProgressMonitor(monitor, 1), fMatches);
+        if (monitor.isCanceled()) {
+            throw new OperationCanceledException();
+        }
+        result.merge(RefactoringStatus.create(stat));
+        if (result.hasFatalError()) {
+            return result;
+        }
+        selectMatchesByLocation(fMatches);        
+        analyzeTextMatches(fMatches, new SubProgressMonitor(monitor, 1), result);
+        if (result.hasFatalError()) {
+            return result;
+        }
+        
+        HashSet fileset= new HashSet();
+        int potentialMatchCount= 0;
+        for (Iterator iter = fMatches.iterator(); iter.hasNext();) {
+            CRefactoringMatch tm = (CRefactoringMatch) iter.next();
+            switch(tm.getAstInformation()) {
+                case CRefactoringMatch.AST_REFERENCE_OTHER:
+                    iter.remove();
+                    break;
+                case CRefactoringMatch.POTENTIAL:
+                    potentialMatchCount++;
+                    fileset.add(tm.getFile());
+                    break;
+                default:
+                    fileset.add(tm.getFile());
+                    break;
+            }
+        }
+        if (potentialMatchCount != 0) {
+            String msg= null;
+            if (potentialMatchCount == 1) {
+                msg= Messages.getString("CRenameProcessorDelegate.warning.potentialMatch.singular"); //$NON-NLS-1$
+            }
+            else {
+                msg= MessageFormat.format(
+                    Messages.getString("CRenameProcessorDelegate.warning.potentialMatch.plural"), //$NON-NLS-1$
+                    new Object[]{new Integer(potentialMatchCount)});
+            }
+            result.addWarning(msg);
+        }
+        IFile[] files= (IFile[]) fileset.toArray(new IFile[fileset.size()]);
+        if (context != null) {
+            ValidateEditChecker editChecker= 
+                (ValidateEditChecker) context.getChecker(ValidateEditChecker.class);
+            editChecker.addFiles(files);
+        }
+        monitor.done();
+        return result;
+    }
+
+    protected void analyzeTextMatches(ArrayList matches, IProgressMonitor monitor, RefactoringStatus status) {
+        CRefactoringArgument argument= getArgument();
+        IBinding[] renameBindings= getBindingsToBeRenamed(status);
+        if (renameBindings != null && renameBindings.length > 0 && 
+                argument.getArgumentKind() != CRefactory.ARGUMENT_UNKNOWN) {
+            ASTManager mngr= getAstManager();
+            mngr.setValidBindings(renameBindings);
+            mngr.setRenameTo(getReplacementText());
+            mngr.analyzeTextMatches(matches, monitor, status);
+        }
+    }
+
+    private void selectMatchesByLocation(ArrayList matches) {
+        int acceptTextLocation= getAcceptedLocations(getSelectedOptions());
+        for (Iterator iter = matches.iterator(); iter.hasNext();) {
+            CRefactoringMatch match = (CRefactoringMatch) iter.next();
+            int location= match.getLocation();
+            if (location != 0 && ((location & acceptTextLocation) == 0)) {
+                iter.remove();
+            }
+        }
+    }
+
+    protected int getAcceptedLocations(int selectedOptions) {
+        return selectedOptions;
+    }
+
+    public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+        if (fMatches.size() == 0) {
+            return null;
+        }
+        Collections.sort(fMatches, new Comparator(){
+            public int compare(Object o1, Object o2) {
+                CRefactoringMatch m1= (CRefactoringMatch) o1;
+                CRefactoringMatch m2= (CRefactoringMatch) o2;
+                IFile f1= m1.getFile();
+                IFile f2= m2.getFile();
+                int cmp= f1.getName().compareTo(f2.getName());
+                if (cmp != 0) return cmp;
+    
+                cmp= f1.getFullPath().toString().compareTo(f2.getFullPath().toString());   
+                if (cmp != 0) return cmp;
+                
+                return m1.getOffset() - m2.getOffset();
+            }});
+        pm.beginTask(Messages.getString("CRenameProcessorDelegate.task.createChange"), fMatches.size()); //$NON-NLS-1$
+        final String identifier= getArgument().getName();
+        final String replacement= getReplacementText();
+        CompositeChange overallChange= new CompositeChange(getProcessorName()); 
+        IFile file= null;
+        TextFileChange fileChange= null;
+        MultiTextEdit fileEdit= null;
+        for (Iterator iter = fMatches.iterator(); iter.hasNext();) {
+            CRefactoringMatch match= (CRefactoringMatch) iter.next();
+            switch(match.getAstInformation()) {
+            case CRefactoringMatch.AST_REFERENCE_OTHER:
+                continue;
+            case CRefactoringMatch.IN_COMMENT:
+            case CRefactoringMatch.POTENTIAL:
+                break;
+            case CRefactoringMatch.AST_REFERENCE:
+                break;
+            }
+            if (match.getAstInformation() != CRefactoringMatch.AST_REFERENCE_OTHER) {
+                IFile mfile= match.getFile();
+                if (file==null || !file.equals(mfile)) {
+                    file= mfile;
+                    fileEdit= new MultiTextEdit();
+                    fileChange= new TextFileChange(file.getName(), file); 
+                    fileChange.setEdit(fileEdit);
+                    overallChange.add(fileChange);
+                }
+                
+                ReplaceEdit replaceEdit= new ReplaceEdit(match.getOffset(), 
+                        identifier.length(), replacement);
+                fileEdit.addChild(replaceEdit);
+                TextEditGroup editGroup= new TextEditGroup(match.getLabel(), replaceEdit);
+                TextEditChangeGroup changeGroup= new TextEditChangeGroup(fileChange, editGroup);
+                fileChange.addTextEditChangeGroup(changeGroup);
+            }
+            pm.worked(1);
+        }
+        return overallChange;
+    }
+
+    /**
+     * Returns the array of bindings that must be renamed
+     */
+    protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
+        return new IBinding[] {getArgument().getBinding()};
     }
 }
Index: src/org/eclipse/cdt/internal/refactoring/CRenameTextProcessor.java
===================================================================
RCS file: src/org/eclipse/cdt/internal/refactoring/CRenameTextProcessor.java
diff -N src/org/eclipse/cdt/internal/refactoring/CRenameTextProcessor.java
--- src/org/eclipse/cdt/internal/refactoring/CRenameTextProcessor.java	12 May 2005 14:39:16 -0000	1.3
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,205 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004-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.internal.refactoring;
-
-import java.text.MessageFormat;
-import java.util.*;
-
-import org.eclipse.cdt.core.dom.ast.*;
-import org.eclipse.cdt.refactoring.*;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.*;
-import org.eclipse.ltk.core.refactoring.*;
-import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
-import org.eclipse.ltk.core.refactoring.participants.ValidateEditChecker;
-import org.eclipse.text.edits.*;
-
-/**
- * Performs text search, filtering by options and finally creates the change object.
- */
-public class CRenameTextProcessor extends CRenameProcessorDelegate {
-
-    private ArrayList fMatches= null;
-    private String fKind;
-
-    public CRenameTextProcessor(CRenameProcessor processor, String kind) {
-        super(processor);
-        fKind= kind;
-    }
-    
-    // overrider
-    public String getProcessorName() {
-        String identifier= getArgument().getName();
-        if (identifier != null) {
-            return MessageFormat.format(
-                    Messages.getString("CRenameTextProcessor.wizard.title"),  //$NON-NLS-1$
-                    new Object[] {fKind, identifier});
-        }
-        return null;
-    }
-
-    
-    // overrider
-    protected int getAvailableOptions() {
-        return CRefactory.OPTION_ASK_SCOPE | 
-        	CRefactory.OPTION_IN_CODE |
-        	CRefactory.OPTION_IN_COMMENT | 
-        	CRefactory.OPTION_IN_MACRO_DEFINITION |
-        	CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE |
-        	CRefactory.OPTION_IN_STRING_LITERAL;
-    }
-
-    protected int getOptionsForcingPreview() {
-    	return CRefactory.OPTION_IN_CODE |
-	    	CRefactory.OPTION_IN_COMMENT | 
-	    	CRefactory.OPTION_IN_MACRO_DEFINITION |
-	    	CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE |
-	    	CRefactory.OPTION_IN_STRING_LITERAL;        
-    }
-    
-    protected int getOptionsEnablingScope() {
-        return getOptionsForcingPreview();
-    }
-    
-    protected int getSearchScope() {
-        return getSelectedScope();
-    }
-    
-    public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
-        return new RefactoringStatus();
-    }
-
-    // overrider
-    public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, 
-            CheckConditionsContext context) throws CoreException, OperationCanceledException {
-	    RefactoringStatus result= new RefactoringStatus();
-	    monitor.beginTask(Messages.getString("CRenameTextProcessor.task.checkFinalCondition"), 2); //$NON-NLS-1$
-	    IFile file= getArgument().getSourceFile();
-	    //assert file!=null;
-
-        // perform text-search
-	    fMatches= new ArrayList();
-	    ICRefactoringSearch txtSearch= getManager().getTextSearch();
-        IStatus stat= txtSearch.searchWord(getSearchScope(), file, getSelectedWorkingSet(), 
-                getManager().getCCppPatterns(), getArgument().getName(), 
-                new SubProgressMonitor(monitor, 1), fMatches);
-        if (monitor.isCanceled()) {
-            throw new OperationCanceledException();
-        }
-        result.merge(RefactoringStatus.create(stat));
-        if (result.hasFatalError()) {
-            return result;
-        }
-        selectMatchesByLocation(fMatches);        
-        analyzeTextMatches(fMatches, new SubProgressMonitor(monitor, 1), result);
-        if (result.hasFatalError()) {
-            return result;
-        }
-        
-        HashSet fileset= new HashSet();
-        for (Iterator iter = fMatches.iterator(); iter.hasNext();) {
-            CRefactoringMatch tm = (CRefactoringMatch) iter.next();
-            if (tm.getAstInformation() == CRefactoringMatch.AST_REFERENCE_OTHER) {
-                iter.remove();
-            }
-            else {
-                fileset.add(tm.getFile());
-            }
-        }
-        IFile[] files= (IFile[]) fileset.toArray(new IFile[fileset.size()]);
-        if (context != null) {
-            ValidateEditChecker editChecker= 
-                (ValidateEditChecker) context.getChecker(ValidateEditChecker.class);
-            editChecker.addFiles(files);
-        }
-        monitor.done();
-        return result;
-    }
-
-    protected void analyzeTextMatches(ArrayList matches, IProgressMonitor monitor, 
-            RefactoringStatus status) {
-        CRefactoringArgument argument= getArgument();
-        IBinding[] renameBindings= getBindingsToBeRenamed(status);
-        if (renameBindings != null && renameBindings.length > 0 && 
-                argument.getArgumentKind() != CRefactory.ARGUMENT_UNKNOWN) {
-            ASTManager mngr= getAstManager();
-            mngr.setValidBindings(renameBindings);
-            mngr.setRenameTo(getReplacementText());
-            mngr.analyzeTextMatches(matches, monitor, status);
-        }
-    }
-    
-    private void selectMatchesByLocation(ArrayList matches) {
-        int acceptTextLocation= getAcceptedLocations(getSelectedOptions());
-        for (Iterator iter = matches.iterator(); iter.hasNext();) {
-            CRefactoringMatch match = (CRefactoringMatch) iter.next();
-            int location= match.getLocation();
-            if (location != 0 && ((location & acceptTextLocation) == 0)) {
-                iter.remove();
-            }
-        }
-    }
-
-    protected int getAcceptedLocations(int selectedOptions) {
-        return selectedOptions;
-    }
-
-    // overrider
-    public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
-        if (fMatches.size() == 0) {
-            return null;
-        }
-        pm.beginTask(Messages.getString("CRenameTextProcessor.task.createChange"), fMatches.size()); //$NON-NLS-1$
-        final String identifier= getArgument().getName();
-        final String replacement= getReplacementText();
-        CompositeChange change= new CompositeChange(getProcessorName()); 
-        IFile file= null;
-        TextFileChange fileChange= null;
-        MultiTextEdit fileEdit= null;
-        for (Iterator iter = fMatches.iterator(); iter.hasNext();) {
-            CRefactoringMatch match= (CRefactoringMatch) iter.next();
-            switch(match.getAstInformation()) {
-            case CRefactoringMatch.AST_REFERENCE_OTHER:
-                continue;
-            case CRefactoringMatch.IN_COMMENT:
-            case CRefactoringMatch.POTENTIAL:
-                break;
-            case CRefactoringMatch.AST_REFERENCE:
-                break;
-            }
-            if (match.getAstInformation() != CRefactoringMatch.AST_REFERENCE_OTHER) {
-                IFile mfile= match.getFile();
-                if (file==null || !file.equals(mfile)) {
-                    file= mfile;
-                    fileChange= new TextFileChange(file.getName(), file); 
-                    change.add(fileChange);
-                    fileEdit= new MultiTextEdit();
-                    fileChange.setEdit(fileEdit);
-                }
-                
-                ReplaceEdit replaceEdit= new ReplaceEdit(match.getOffset(), 
-                        identifier.length(), replacement);
-                fileEdit.addChild(replaceEdit);
-                fileChange.addTextEditGroup(new TextEditGroup(match.getLabel(), replaceEdit));
-            }
-            pm.worked(1);
-        }
-        return change;
-    }
-
-    /**
-     * Returns the array of bindings that must be renamed
-     */
-    protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
-        return new IBinding[] {getArgument().getBinding()};
-    }
-}
Index: src/org/eclipse/cdt/internal/refactoring/TextSearchWrapper.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/TextSearchWrapper.java,v
retrieving revision 1.2
diff -u -r1.2 TextSearchWrapper.java
--- src/org/eclipse/cdt/internal/refactoring/TextSearchWrapper.java	15 Apr 2005 13:55:27 -0000	1.2
+++ src/org/eclipse/cdt/internal/refactoring/TextSearchWrapper.java	18 May 2005 09:45:58 -0000
@@ -17,11 +17,9 @@
 import org.eclipse.cdt.internal.refactoring.scanner.Scanner;
 import org.eclipse.cdt.internal.refactoring.scanner.Token;
 import org.eclipse.cdt.refactoring.*;
-import org.eclipse.cdt.refactoring.CRefactory;
-import org.eclipse.cdt.refactoring.ICRefactoringSearch;
 import org.eclipse.core.resources.*;
 import org.eclipse.core.runtime.*;
-import org.eclipse.search.internal.core.ISearchScope;
+import org.eclipse.search.internal.core.SearchScope;
 import org.eclipse.search.internal.core.text.*;
 import org.eclipse.ui.*;
 
@@ -33,7 +31,7 @@
     
     public TextSearchWrapper() {}
     
-    private ISearchScope createSearchScope(IFile file, int scope, 
+    private SearchScope createSearchScope(IFile file, int scope, 
             String workingSetName, String[] patterns) {
         switch (scope) {
         	case SCOPE_WORKSPACE:
@@ -43,7 +41,7 @@
         	case SCOPE_FILE:
         	    return defineSearchScope(file, patterns);
         	case SCOPE_WORKING_SET: {
-        	    ISearchScope result= defineWorkingSetAsSearchScope(workingSetName, patterns);
+        	    SearchScope result= defineWorkingSetAsSearchScope(workingSetName, patterns);
         	    if (result == null) {
         	        result= defineSearchScope(file.getWorkspace().getRoot(), patterns);
         	    }
@@ -53,7 +51,7 @@
 	    return defineRelatedProjectsAsSearchScope(file.getProject(), patterns);
     }
     
-    private ISearchScope defineRelatedProjectsAsSearchScope(IProject project, String[] patterns) {
+    private SearchScope defineRelatedProjectsAsSearchScope(IProject project, String[] patterns) {
         HashSet projects= new HashSet();
         LinkedList workThrough= new LinkedList();
         workThrough.add(project);
@@ -72,7 +70,7 @@
         return defineSearchScope(resources, patterns);
     }
 
-    private ISearchScope defineWorkingSetAsSearchScope(String wsName, String[] patterns) {
+    private SearchScope defineWorkingSetAsSearchScope(String wsName, String[] patterns) {
         if (wsName == null) {
             return null;
         }
@@ -81,28 +79,26 @@
 		if (ws == null) {
 		    return null;
 		}
-		TextSearchScope result= 	
-		    new TextSearchScope("c/cpp", new IWorkingSet[] {ws}); //$NON-NLS-1$
+		SearchScope result= SearchScope.newSearchScope("c/cpp", new IWorkingSet[] {ws}); //$NON-NLS-1$
 		applyFilePatterns(result, patterns);
 		return result;
     }
 
-    private void applyFilePatterns(TextSearchScope scope, String[] patterns) {
+    private void applyFilePatterns(SearchScope scope, String[] patterns) {
         for (int i = 0; i < patterns.length; i++) {
             String pattern = patterns[i];
-            scope.addExtension(pattern);
+            scope.addFileNamePattern(pattern);
         }
     }
 
-    private ISearchScope defineSearchScope(IResource resource, String[] patterns) {
-        TextSearchScope result= new TextSearchScope("c/cpp"); //$NON-NLS-1$
-        result.add(resource);
+    private SearchScope defineSearchScope(IResource resource, String[] patterns) {
+        SearchScope result= SearchScope.newSearchScope("c/cpp", new IResource[]{resource}); //$NON-NLS-1$
         applyFilePatterns(result, patterns);
         return result;
     }
     
-    private ISearchScope defineSearchScope(IResource[] resources, String[] patterns) {
-        TextSearchScope result= new TextSearchScope("c/cpp", resources); //$NON-NLS-1$            
+    private SearchScope defineSearchScope(IResource[] resources, String[] patterns) {
+        SearchScope result= SearchScope.newSearchScope("c/cpp", resources); //$NON-NLS-1$            
         applyFilePatterns(result, patterns);
         return result;
     }
@@ -121,7 +117,7 @@
         searchPattern.append("\\E"); //$NON-NLS-1$
         searchPattern.append("\\b"); //$NON-NLS-1$
 
-        ISearchScope searchscope= createSearchScope(resource, scope, workingSet, patterns);
+        SearchScope searchscope= createSearchScope(resource, scope, workingSet, patterns);
         MatchLocator locator= new MatchLocator(searchPattern.toString(), true, true);
         final IProgressMonitor subProgress= new SubProgressMonitor(monitor, 95);
         ITextSearchResultCollector collector= new ITextSearchResultCollector() {
@@ -143,7 +139,7 @@
                 }                
             }
         };
-        IStatus result= engine.search(searchscope, false, collector, locator, false);
+        IStatus result= engine.search(searchscope, false, collector, locator);
         categorizeMatches(target.subList(startPos, target.size()), 
                 new SubProgressMonitor(monitor, 5));
 
Index: src/org/eclipse/cdt/internal/refactoring/messages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring/src/org/eclipse/cdt/internal/refactoring/messages.properties,v
retrieving revision 1.4
diff -u -r1.4 messages.properties
--- src/org/eclipse/cdt/internal/refactoring/messages.properties	12 May 2005 14:39:16 -0000	1.4
+++ src/org/eclipse/cdt/internal/refactoring/messages.properties	18 May 2005 09:45:58 -0000
@@ -1,9 +1,9 @@
-CRenameTextProcessor.wizard.title=Rename {0} ''{1}''
-CRenameTextProcessor.globalFunction=a global function
-CRenameTextProcessor.fileStaticFunction=a file static function
-CRenameTextProcessor.task.label=renaming
-CRenameTextProcessor.type=a type
-CRenameTextProcessor.namespace=a namespace
+CRenameProcessorDelegate.wizard.title=Rename {0} ''{1}''
+CRenameProcessorDelegate.globalFunction=a global function
+CRenameProcessorDelegate.fileStaticFunction=a file static function
+CRenameProcessorDelegate.task.label=renaming
+CRenameProcessorDelegate.type=a type
+CRenameProcessorDelegate.namespace=a namespace
 CRenameLocalProcessor.parameter=a parameter
 CRenameTopProcessor.wizard.title=Rename ''{0}''
 CRenameTopProcessor.localVar=local variable
@@ -29,12 +29,14 @@
 CRenameTopProcessor.macro=macro
 CRenameTopProcessor.word=word
 CRefactory.title.rename=Rename
-CRenameTextProcessor.task.createChange=creating changes
-CRenameTextProcessor.fileStaticVariable=a file static variable
+CRenameProcessorDelegate.task.createChange=creating changes
+CRenameProcessorDelegate.fileStaticVariable=a file static variable
 CRenameLocalProcessor.error.isShadowed=will be shadowed by
 CRenameLocalProcessor.error.overloads=will overload
-CRenameTextProcessor.task.checkFinalCondition=Checking final conditions
-CRenameTextProcessor.error.conflictingDecl=New name conflicts with other declarations
+CRenameProcessorDelegate.task.checkFinalCondition=Checking final conditions
+CRenameProcessorDelegate.warning.potentialMatch.singular=Refactoring contains 1 potential match.
+CRenameProcessorDelegate.warning.potentialMatch.plural=Refactoring contains {0} potential matches.
+CRenameProcessorDelegate.error.conflictingDecl=New name conflicts with other declarations
 CRenameTopProcessor.wizard.backup.title=Rename
 CRenameTopProcessor.filelocalFunction=file local function
 CRenameLocalProcessor.error.redeclare=will redeclare
Index: src/org/eclipse/cdt/refactoring/tests/RefactoringTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RefactoringTests.java,v
retrieving revision 1.4
diff -u -r1.4 RefactoringTests.java
--- src/org/eclipse/cdt/refactoring/tests/RefactoringTests.java	12 May 2005 14:39:20 -0000	1.4
+++ src/org/eclipse/cdt/refactoring/tests/RefactoringTests.java	18 May 2005 09:46:24 -0000
@@ -23,7 +23,6 @@
  * @author markus.schorn@xxxxxxxxxxxxx
  */
 public class RefactoringTests extends BaseTestFramework {
-
     public RefactoringTests() {
     }
 
@@ -42,16 +41,18 @@
     }
 
     protected void assertTotalChanges(int numChanges, Change changes) throws Exception {
-        assertTotalChanges(numChanges, 0, changes);
+        assertTotalChanges(numChanges, 0, 0, changes);
     }
 
-    protected void assertTotalChanges(int numChanges, int potChanges, Change changes) throws Exception {
-        int count[]= {0,0};
+    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) {
@@ -76,7 +77,7 @@
             count[1]++;
         }
         else if (name.indexOf("comment") != -1) { //$NON-NLS-1$
-            count[1]++;
+            count[2]++;
         }
         else {
             count[0]++;
Index: src/org/eclipse/cdt/refactoring/tests/RenameMacroTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameMacroTests.java,v
retrieving revision 1.2
diff -u -r1.2 RenameMacroTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameMacroTests.java	12 May 2005 14:39:20 -0000	1.2
+++ src/org/eclipse/cdt/refactoring/tests/RenameMacroTests.java	18 May 2005 09:46:24 -0000
@@ -16,6 +16,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+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;
@@ -32,12 +33,8 @@
         return suite(true);
     }
     public static Test suite( boolean cleanup ) {
-        TestSuite suite = new TestSuite("RenameTypeTests"); //$NON-NLS-1$
-        suite.addTest(new RenameMacroTests("testMacroRename") ); //$NON-NLS-1$
-        suite.addTest(new RenameMacroTests("testMacroNameConflicts") ); //$NON-NLS-1$
-        suite.addTest(new RenameMacroTests("testIncludeGuard"));  //$NON-NLS-1$
-        suite.addTest(new RenameMacroTests("testClassMacroClash"));  //$NON-NLS-1$
-
+        TestSuite suite = new TestSuite(RenameMacroTests.class); //$NON-NLS-1$
+        suite.addTest(new FailingTest(new RenameMacroTests("failingRenameMacroAsMacroArgument"), 94673)); //$NON-NLS-1$
         if (cleanup) {
             suite.addTest( new RefactoringTests("cleanupProject") );    //$NON-NLS-1$
         }
@@ -143,26 +140,6 @@
         assertRefactoringError(status, "'enum_item' will conflict with the name of an enumerator."); //$NON-NLS-1$
    }
 
-    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$
-        // mstodo for now the match within the ifndef is reported as potential.
-        assertTotalChanges(1, 2, 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 testClassMacroClash() throws Exception {
         StringWriter writer = new StringWriter();
         writer.write("class CC {int a;};         \n"); //$NON-NLS-1$
@@ -183,4 +160,51 @@
         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 failingRenameMacroAsMacroArgument() 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$
+    }        
 }
Index: src/org/eclipse/cdt/refactoring/tests/RenameRegressionTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameRegressionTests.java,v
retrieving revision 1.4
diff -u -r1.4 RenameRegressionTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameRegressionTests.java	12 May 2005 14:39:20 -0000	1.4
+++ src/org/eclipse/cdt/refactoring/tests/RenameRegressionTests.java	18 May 2005 09:46:25 -0000
@@ -100,6 +100,7 @@
         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$
@@ -121,7 +122,7 @@
         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, 2, changes );
+        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$
     }
Index: src/org/eclipse/cdt/refactoring/tests/RenameTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameTests.java,v
retrieving revision 1.1
diff -u -r1.1 RenameTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameTests.java	9 Mar 2005 21:50:49 -0000	1.1
+++ src/org/eclipse/cdt/refactoring/tests/RenameTests.java	18 May 2005 09:46:25 -0000
@@ -102,4 +102,14 @@
         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;
+    }
+
 }
Index: src/org/eclipse/cdt/refactoring/tests/RenameTypeTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameTypeTests.java,v
retrieving revision 1.1
diff -u -r1.1 RenameTypeTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameTypeTests.java	15 Apr 2005 13:55:35 -0000	1.1
+++ src/org/eclipse/cdt/refactoring/tests/RenameTypeTests.java	18 May 2005 09:46:26 -0000
@@ -17,6 +17,7 @@
 import junit.framework.TestSuite;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.ltk.core.refactoring.Change;
 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
 
 /**
@@ -31,18 +32,7 @@
         return suite(true);
     }
     public static Test suite( boolean cleanup ) {
-        TestSuite suite = new TestSuite("RenameTypeTests"); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testNamespaceNameConflicts") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testClassNameConflicts") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testStructNameConflicts") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testStructNameConflictsPlainC") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testUnionNameConflicts") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testUnionNameConflictsPlainC") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testEnumNameConflicts") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testEnumNameConflictsPlainC") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testTypedefNameConflicts") ); //$NON-NLS-1$
-        suite.addTest(new RenameTypeTests("testTypedefNameConflictsPlainC") ); //$NON-NLS-1$
-
+        TestSuite suite = new TestSuite(RenameTypeTests.class); //$NON-NLS-1$
         if (cleanup) {
             suite.addTest( new RefactoringTests("cleanupProject") );    //$NON-NLS-1$
         }
@@ -1290,7 +1280,7 @@
         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("     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$
@@ -1625,4 +1615,31 @@
         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$
+    }
 }
Index: src/org/eclipse/cdt/refactoring/tests/RenameVariableTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-core/org.eclipse.cdt.refactoring.tests/src/org/eclipse/cdt/refactoring/tests/RenameVariableTests.java,v
retrieving revision 1.3
diff -u -r1.3 RenameVariableTests.java
--- src/org/eclipse/cdt/refactoring/tests/RenameVariableTests.java	12 May 2005 14:39:20 -0000	1.3
+++ src/org/eclipse/cdt/refactoring/tests/RenameVariableTests.java	18 May 2005 09:46:26 -0000
@@ -1424,7 +1424,7 @@
         
         int offset =  contents.indexOf("v1") ; //$NON-NLS-1$
         Change changes = getRefactorChanges(cpp, offset, "z"); //$NON-NLS-1$
-        assertTotalChanges( 1, 1, changes );
+        assertTotalChanges( 1, 1, 0, changes );
         assertChange( changes, cpp, offset, 2, "z" );  //$NON-NLS-1$
     }
 
Index: src/org/eclipse/cdt/refactoring/tests/RenameTemplatesTests.java
===================================================================
RCS file: src/org/eclipse/cdt/refactoring/tests/RenameTemplatesTests.java
diff -N src/org/eclipse/cdt/refactoring/tests/RenameTemplatesTests.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/refactoring/tests/RenameTemplatesTests.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.refactoring.tests;
+
+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@xxxxxxxxxxxxx
+ */
+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); //$NON-NLS-1$
+        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);
+    }
+}

Back to the top