KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > util > QualifiedNameSearchResult


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.refactoring.util;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.Set JavaDoc;
20
21 import org.eclipse.core.resources.IFile;
22
23 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
24 import org.eclipse.ltk.core.refactoring.Change;
25 import org.eclipse.ltk.core.refactoring.CompositeChange;
26 import org.eclipse.ltk.core.refactoring.TextChange;
27 import org.eclipse.ltk.core.refactoring.TextFileChange;
28
29 public class QualifiedNameSearchResult {
30
31     private Map JavaDoc fChanges;
32     
33     public QualifiedNameSearchResult() {
34         fChanges= new HashMap JavaDoc();
35     }
36     
37     public TextChange getChange(IFile file) {
38         TextChange result= (TextChange)fChanges.get(file);
39         if (result == null) {
40             result= new TextFileChange(file.getName(), file);
41             fChanges.put(file, result);
42         }
43         return result;
44     }
45     
46     public TextChange[] getAllChanges() {
47         Collection JavaDoc values= fChanges.values();
48         return (TextChange[])values.toArray(new TextChange[values.size()]);
49     }
50     
51     public IFile[] getAllFiles() {
52         Set JavaDoc keys= fChanges.keySet();
53         return (IFile[])keys.toArray(new IFile[keys.size()]);
54     }
55
56     public Change getSingleChange(IFile[] alreadyTouchedFiles) {
57         Collection JavaDoc values= fChanges.values();
58         if (values.size() == 0)
59             return null;
60         
61         CompositeChange result= new CompositeChange(RefactoringCoreMessages.QualifiedNameSearchResult_change_name);
62         result.markAsSynthetic();
63         List JavaDoc files= Arrays.asList(alreadyTouchedFiles);
64         for (Iterator JavaDoc iter= values.iterator(); iter.hasNext();) {
65             TextFileChange change= (TextFileChange)iter.next();
66             if (!files.contains(change.getFile())) {
67                 result.add(change);
68             }
69         }
70         return result;
71     }
72 }
73
Popular Tags