Skip to content

Commit 9cf20a7

Browse files
howlgerakurtakov
authored andcommitted
Remove unused code
In org.eclipse.help.internal.search.DefaultAnalyzer, the locale is no longer used, so it does not need to be calculated.
1 parent 8186345 commit 9cf20a7

File tree

3 files changed

+4
-85
lines changed

3 files changed

+4
-85
lines changed

ua/org.eclipse.help.base/src/org/eclipse/help/internal/search/AnalyzerDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public AnalyzerDescriptor(String locale) {
5454
+ "#" //$NON-NLS-1$
5555
+ HelpBasePlugin.getDefault().getBundle().getHeaders().get(Constants.BUNDLE_VERSION)
5656
+ "?locale=" + locale; //$NON-NLS-1$
57-
this.luceneAnalyzer = new DefaultAnalyzer(locale);
57+
this.luceneAnalyzer = new DefaultAnalyzer();
5858
this.lang = locale;
5959
}
6060
}
@@ -65,7 +65,7 @@ public AnalyzerDescriptor(String locale) {
6565
* @return Returns a Analyzer
6666
*/
6767
public Analyzer getAnalyzer() {
68-
return new SmartAnalyzer(lang, luceneAnalyzer);
68+
return new SmartAnalyzer(luceneAnalyzer);
6969
}
7070

7171
/**

ua/org.eclipse.help.base/src/org/eclipse/help/internal/search/DefaultAnalyzer.java

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,94 +16,16 @@
1616
*******************************************************************************/
1717
package org.eclipse.help.internal.search;
1818

19-
import java.text.BreakIterator;
20-
import java.util.Locale;
21-
import java.util.StringTokenizer;
22-
2319
import org.apache.lucene.analysis.Analyzer;
2420
import org.apache.lucene.analysis.Tokenizer;
2521
import org.apache.lucene.analysis.core.LowerCaseFilter;
2622
import org.apache.lucene.analysis.standard.StandardTokenizer;
27-
import org.eclipse.core.runtime.ILog;
28-
import org.eclipse.core.runtime.Platform;
2923

3024
/**
3125
* Lucene Analyzer. LowerCaseFilter->StandardTokenizer
3226
*/
3327
public final class DefaultAnalyzer extends Analyzer {
3428

35-
private Locale locale;
36-
37-
/**
38-
* Creates a new analyzer using the given locale.
39-
*/
40-
public DefaultAnalyzer(String localeString) {
41-
super();
42-
// Create a locale object for a given locale string
43-
Locale userLocale = getLocale(localeString);
44-
45-
// Check if the locale is supported by BreakIterator
46-
// check here to do it only once.
47-
Locale[] availableLocales = BreakIterator.getAvailableLocales();
48-
for (Locale availableLocale : availableLocales) {
49-
if (userLocale.equals(availableLocale)) {
50-
locale = userLocale;
51-
break;
52-
}
53-
}
54-
if (locale == null && userLocale.getDisplayVariant().length() > 0) {
55-
// Check if the locale without variant is supported by BreakIterator
56-
Locale countryLocale = Locale.of(userLocale.getLanguage(), userLocale.getCountry());
57-
for (Locale availableLocale : availableLocales) {
58-
if (countryLocale.equals(availableLocale)) {
59-
locale = countryLocale;
60-
break;
61-
}
62-
}
63-
}
64-
if (locale == null && userLocale.getCountry().length() > 0) {
65-
// Check if at least the language is supported by BreakIterator
66-
Locale language = Locale.of(userLocale.getLanguage(), ""); //$NON-NLS-1$
67-
for (Locale availableLocale : availableLocales) {
68-
if (language.equals(availableLocale)) {
69-
locale = language;
70-
break;
71-
}
72-
}
73-
}
74-
75-
if (locale == null) {
76-
// Locale is not supported, will use en_US
77-
ILog.of(getClass()).error(
78-
"Text Analyzer could not be created for locale {0}. An analyzer that extends org.eclipse.help.luceneAnalyzer extension point needs to be plugged in for locale " //$NON-NLS-1$
79-
+ localeString
80-
+ ", or Java Virtual Machine needs to be upgraded to version with proper support for locale {0}.", //$NON-NLS-1$
81-
null);
82-
locale = Locale.of("en", "US"); //$NON-NLS-1$ //$NON-NLS-2$
83-
}
84-
}
85-
86-
/**
87-
* Creates a Locale object out of a string representation
88-
*/
89-
private Locale getLocale(String clientLocale) {
90-
if (clientLocale == null)
91-
clientLocale = Platform.getNL();
92-
if (clientLocale == null)
93-
clientLocale = Locale.getDefault().toString();
94-
95-
// break the string into tokens to get the Locale object
96-
StringTokenizer locales = new StringTokenizer(clientLocale, "_"); //$NON-NLS-1$
97-
if (locales.countTokens() == 1)
98-
return Locale.of(locales.nextToken(), ""); //$NON-NLS-1$
99-
else if (locales.countTokens() == 2)
100-
return Locale.of(locales.nextToken(), locales.nextToken());
101-
else if (locales.countTokens() == 3)
102-
return Locale.of(locales.nextToken(), locales.nextToken(), locales.nextToken());
103-
else
104-
return Locale.getDefault();
105-
}
106-
10729
/*
10830
* Can't use try-with-resources because the Lucene internally reuses
10931
* components. See {@link org.apache.lucene.analysis.Analyzer.ReuseStrategy}

ua/org.eclipse.help.base/src/org/eclipse/help/internal/search/SmartAnalyzer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ public final class SmartAnalyzer extends AnalyzerWrapper {
2525
Analyzer pluggedInAnalyzer;
2626
Analyzer exactAnalyzer;
2727

28-
/**
29-
* Constructor for SmartAnalyzer.
30-
*/
31-
public SmartAnalyzer(String locale, Analyzer pluggedInAnalyzer) {
28+
public SmartAnalyzer(Analyzer pluggedInAnalyzer) {
3229
super(PER_FIELD_REUSE_STRATEGY);
3330
this.pluggedInAnalyzer = pluggedInAnalyzer;
34-
this.exactAnalyzer = new DefaultAnalyzer(locale);
31+
this.exactAnalyzer = new DefaultAnalyzer();
3532
}
3633

3734
@Override

0 commit comments

Comments
 (0)