]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/nls/search/NLSSearchQuery.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui refactoring / org / eclipse / jdt / internal / ui / refactoring / nls / search / NLSSearchQuery.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
12 package org.eclipse.jdt.internal.ui.refactoring.nls.search;
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16
17 import org.eclipse.core.resources.IFile;
18
19 import org.eclipse.search.ui.ISearchQuery;
20 import org.eclipse.search.ui.ISearchResult;
21
22 import org.eclipse.jdt.core.Flags;
23 import org.eclipse.jdt.core.IField;
24 import org.eclipse.jdt.core.IJavaElement;
25 import org.eclipse.jdt.core.JavaModelException;
26 import org.eclipse.jdt.core.search.IJavaSearchScope;
27
28 import org.eclipse.jdt.internal.corext.refactoring.nls.NLSRefactoring;
29 import org.eclipse.jdt.internal.corext.util.Messages;
30
31 import org.eclipse.jdt.ui.JavaElementLabels;
32
33
34 public class NLSSearchQuery implements ISearchQuery {
35
36         NLSSearchResult fResult;
37         IJavaElement[] fWrapperClass;
38         IFile[] fPropertiesFile;
39         IJavaSearchScope fScope;
40         private String fScopeDescription;
41
42         public NLSSearchQuery(IJavaElement[] wrapperClass, IFile[] propertiesFile, IJavaSearchScope scope, String scopeDescription) {
43                 fWrapperClass= wrapperClass;
44                 fPropertiesFile= propertiesFile;
45                 fScope= scope;
46                 fScopeDescription= scopeDescription;
47         }
48
49         /*
50          * @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor)
51          */
52         public IStatus run(IProgressMonitor monitor) {
53                 monitor.beginTask("", 5 * fWrapperClass.length); //$NON-NLS-1$
54
55                 return fResult.generated_2736082692135152007(this, monitor);
56         }
57
58         boolean isNLSField(IField field) throws JavaModelException {
59                 int flags= field.getFlags();
60                 if (!Flags.isPublic(flags))
61                         return false;
62
63                 if (!Flags.isStatic(flags))
64                         return false;
65
66                 String fieldName= field.getElementName();
67                 if (NLSRefactoring.BUNDLE_NAME_FIELD.equals(fieldName))
68                         return false;
69
70                 if ("RESOURCE_BUNDLE".equals(fieldName)) //$NON-NLS-1$
71                         return false;
72
73                 return true;
74         }
75
76         /*
77          * @see org.eclipse.search.ui.ISearchQuery#getLabel()
78          */
79         public String getLabel() {
80                 return NLSSearchMessages.NLSSearchQuery_label;
81         }
82
83         public String getResultLabel(int nMatches) {
84                 if (fWrapperClass.length == 1) {
85                         if (nMatches == 1) {
86                                 String[] args= new String[] {JavaElementLabels.getElementLabel(fWrapperClass[0], JavaElementLabels.ALL_DEFAULT), fScopeDescription};
87                                 return Messages.format(NLSSearchMessages.SearchOperation_singularLabelPostfix, args);
88                         }
89                         String[] args= new String[] {JavaElementLabels.getElementLabel(fWrapperClass[0], JavaElementLabels.ALL_DEFAULT), String.valueOf(nMatches), fScopeDescription};
90                         return Messages.format(NLSSearchMessages.SearchOperation_pluralLabelPatternPostfix, args);
91                 } else {
92                         if (nMatches == 1) {
93                                 return Messages.format(NLSSearchMessages.NLSSearchQuery_oneProblemInScope_description, fScopeDescription);
94                         }
95                         return Messages.format(NLSSearchMessages.NLSSearchQuery_xProblemsInScope_description, new Object[] {String.valueOf(nMatches), fScopeDescription});
96                 }
97         }
98
99         /*
100          * @see org.eclipse.search.ui.ISearchQuery#canRerun()
101          */
102         public boolean canRerun() {
103                 return true;
104         }
105
106         /*
107          * @see org.eclipse.search.ui.ISearchQuery#canRunInBackground()
108          */
109         public boolean canRunInBackground() {
110                 return true;
111         }
112
113         /*
114          * @see org.eclipse.search.ui.ISearchQuery#getSearchResult()
115          */
116         public ISearchResult getSearchResult() {
117                 if (fResult == null)
118                         fResult= new NLSSearchResult(this);
119                 return fResult;
120         }
121 }