]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/core refactoring/org/eclipse/jdt/internal/corext/refactoring/util/QualifiedNameSearchResult.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / core refactoring / org / eclipse / jdt / internal / corext / refactoring / util / QualifiedNameSearchResult.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 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;
14 import java.util.Collection;
15 import java.util.HashMap;
16 import java.util.Iterator;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.Set;
20
21 import org.eclipse.core.resources.IFile;
22
23 import org.eclipse.ltk.core.refactoring.Change;
24 import org.eclipse.ltk.core.refactoring.CompositeChange;
25 import org.eclipse.ltk.core.refactoring.TextChange;
26 import org.eclipse.ltk.core.refactoring.TextFileChange;
27
28 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
29
30 public class QualifiedNameSearchResult {
31
32         private Map<IFile, TextChange> fChanges;
33
34         public QualifiedNameSearchResult() {
35                 fChanges= new HashMap<IFile, TextChange>();
36         }
37
38         public TextChange getChange(IFile file) {
39                 TextChange result= fChanges.get(file);
40                 if (result == null) {
41                         result= new TextFileChange(file.getName(), file);
42                         fChanges.put(file, result);
43                 }
44                 return result;
45         }
46
47         public TextChange[] getAllChanges() {
48                 Collection<TextChange> values= fChanges.values();
49                 return values.toArray(new TextChange[values.size()]);
50         }
51
52         public IFile[] getAllFiles() {
53                 Set<IFile> keys= fChanges.keySet();
54                 return keys.toArray(new IFile[keys.size()]);
55         }
56
57         public Change getSingleChange(IFile[] alreadyTouchedFiles) {
58                 Collection<TextChange> values= fChanges.values();
59                 if (values.size() == 0)
60                         return null;
61
62                 CompositeChange result= new CompositeChange(RefactoringCoreMessages.QualifiedNameSearchResult_change_name);
63                 result.markAsSynthetic();
64                 List<IFile> files= Arrays.asList(alreadyTouchedFiles);
65                 for (Iterator<TextChange> iter= values.iterator(); iter.hasNext();) {
66                         TextFileChange change= (TextFileChange)iter.next();
67                         if (!files.contains(change.getFile())) {
68                                 result.add(change);
69                         }
70                 }
71                 return result;
72         }
73 }