View | Details | Raw Unified | Return to bug 297320 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/jdt/ui/tests/search/NLSSearchTest.java (-7 / +44 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 165-172 Link Here
165
165
166
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 2);
166
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 2);
167
167
168
		NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource());
168
		NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource(), true);
169
		NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Client_s1", (IFile)client.getCorrespondingResource());
169
		NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Client_s1", (IFile)client.getCorrespondingResource(), false);
170
	}
170
	}
171
171
172
	public void test04() throws Exception {
172
	public void test04() throws Exception {
Lines 196-203 Link Here
196
196
197
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 2);
197
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 2);
198
198
199
		NLSSearchTestHelper.assertHasUnusedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource());
199
		NLSSearchTestHelper.assertHasUnusedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource(), true);
200
		NLSSearchTestHelper.assertHasUnusedKey(accessor, propertiesFile, "Client_s1", propertiesFile);
200
		NLSSearchTestHelper.assertHasUnusedKey(accessor, propertiesFile, "Client_s1", propertiesFile, false);
201
	}
201
	}
202
202
203
	public void test05() throws Exception {
203
	public void test05() throws Exception {
Lines 226-233 Link Here
226
226
227
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 2);
227
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 2);
228
228
229
		NLSSearchTestHelper.assertHasUnusedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource());
229
		NLSSearchTestHelper.assertHasUnusedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource(), true);
230
		NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource());
230
		NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Client_s1", (IFile)accessor.getCorrespondingResource(), true);
231
	}
231
	}
232
232
233
	public void test06() throws Exception {
233
	public void test06() throws Exception {
Lines 476-479 Link Here
476
476
477
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 1);
477
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 1);
478
	}
478
	}
479
480
	public void testBug247012_4() throws Exception {
481
		IPackageFragment pack1= fSourceFolder.createPackageFragment("test", false, null);
482
		StringBuffer buf= new StringBuffer();
483
		buf.append("package test;\n");
484
		buf.append("import java.util.MissingResourceException;\n");
485
		buf.append("import java.util.ResourceBundle;\n");
486
		buf.append("public class Accessor {\n");
487
		buf.append("    private static final String BUNDLE_NAME = \"test.Accessor\"; //$NON-NLS-1$\n");
488
		buf.append("    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);\n");
489
		buf.append("    private Accessor() {}\n");
490
		buf.append("    public static String getString(String key) {\n");
491
		buf.append("        try {\n");
492
		buf.append("            return RESOURCE_BUNDLE.getString(key);\n");
493
		buf.append("        } catch (MissingResourceException e) {\n");
494
		buf.append("            return '!' + key + '!';\n");
495
		buf.append("        }\n");
496
		buf.append("    }\n");
497
		buf.append("}\n");
498
		ICompilationUnit accessor= pack1.createCompilationUnit("Accessor.java", buf.toString(), false, null);
499
500
		buf= new StringBuffer();
501
		buf.append("package test;\n");
502
		buf.append("public class Client {\n");
503
		buf.append("	public static void main(String[] args) { \n");
504
		buf.append("		System.out.println(Accessor.getString(\"Main.undefined\")); //$NON-NLS-1$ \n");
505
		buf.append("	}\n");
506
		buf.append("}\n");
507
508
		ICompilationUnit client= pack1.createCompilationUnit("Client.java", buf.toString(), false, null);
509
510
		buf= new StringBuffer();
511
		IFile propertiesFile= write((IFolder)pack1.getCorrespondingResource(), buf.toString(), "Accessor.properties");
512
513
		NLSSearchTestHelper.assertNumberOfProblems(accessor, propertiesFile, 1);
514
		NLSSearchTestHelper.assertHasUndefinedKey(accessor, propertiesFile, "Main.undefined", (IFile)client.getCorrespondingResource(), false);
515
	}
479
}
516
}
(-)ui/org/eclipse/jdt/ui/tests/search/NLSSearchTestHelper.java (-10 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 38-49 Link Here
38
		assertNumberResults(searchProblems(accessor, propertiesFile), expected);
38
		assertNumberResults(searchProblems(accessor, propertiesFile), expected);
39
	}
39
	}
40
40
41
	public static void assertHasUndefinedKey(ICompilationUnit accessor, IFile propertiesFile, String key, IFile file) throws CoreException {
41
	public static void assertHasUndefinedKey(ICompilationUnit accessor, IFile propertiesFile, String key, IFile file, boolean isAccessor) throws CoreException {
42
		assertResultHasUndefinedKey(key, file, searchProblems(accessor, propertiesFile));
42
		assertResultHasUndefinedKey(key, file, isAccessor, searchProblems(accessor, propertiesFile));
43
	}
43
	}
44
44
45
	public static void assertHasUnusedKey(ICompilationUnit accessor, IFile propertiesFile, String key, IFile file) throws IOException, CoreException {
45
	public static void assertHasUnusedKey(ICompilationUnit accessor, IFile propertiesFile, String key, IFile file, boolean isAccessor) throws IOException, CoreException {
46
		assertResultHasUnusedKey(key, file, searchProblems(accessor, propertiesFile));
46
		assertResultHasUnusedKey(key, file, isAccessor, searchProblems(accessor, propertiesFile));
47
	}
47
	}
48
48
49
	public static void assertHasDuplicateKey(ICompilationUnit accessor, IFile propertiesFile, String key, IFile file) throws CoreException, IOException {
49
	public static void assertHasDuplicateKey(ICompilationUnit accessor, IFile propertiesFile, String key, IFile file) throws CoreException, IOException {
Lines 63-69 Link Here
63
		Assert.assertTrue("Expected number of results is " + expected + " but was " + is, is == expected);
63
		Assert.assertTrue("Expected number of results is " + expected + " but was " + is, is == expected);
64
	}
64
	}
65
65
66
	private static void assertResultHasUndefinedKey(String key, IFile file, NLSSearchResult result) throws CoreException {
66
	private static void assertResultHasUndefinedKey(String key, IFile file, boolean isAccessor, NLSSearchResult result) throws CoreException {
67
		Match[] matches= result.getFileMatchAdapter().computeContainedMatches(result, file);
67
		Match[] matches= result.getFileMatchAdapter().computeContainedMatches(result, file);
68
68
69
		for (int i= 0; i < matches.length; i++) {
69
		for (int i= 0; i < matches.length; i++) {
Lines 71-77 Link Here
71
			if (match.getElement() instanceof ICompilationUnit) {
71
			if (match.getElement() instanceof ICompilationUnit) {
72
				ICompilationUnit unit= (ICompilationUnit)match.getElement();
72
				ICompilationUnit unit= (ICompilationUnit)match.getElement();
73
				String field= unit.getSource().substring(match.getOffset(), match.getOffset() + match.getLength());
73
				String field= unit.getSource().substring(match.getOffset(), match.getOffset() + match.getLength());
74
				if (field.indexOf(key) != -1)
74
				if ((isAccessor && field.indexOf(key) != -1) || (!isAccessor && field.equals(key)))
75
					return;
75
					return;
76
			}
76
			}
77
		}
77
		}
Lines 79-85 Link Here
79
		Assert.assertTrue("No undefined key problem found for " + key + " in " + file.getName(), false);
79
		Assert.assertTrue("No undefined key problem found for " + key + " in " + file.getName(), false);
80
	}
80
	}
81
81
82
	private static void assertResultHasUnusedKey(String key, IFile file, NLSSearchResult result) throws IOException, CoreException {
82
	private static void assertResultHasUnusedKey(String key, IFile file, boolean isAccessor, NLSSearchResult result) throws IOException, CoreException {
83
		Match[] matches= result.getFileMatchAdapter().computeContainedMatches(result, file);
83
		Match[] matches= result.getFileMatchAdapter().computeContainedMatches(result, file);
84
84
85
		for (int i= 0; i < matches.length; i++) {
85
		for (int i= 0; i < matches.length; i++) {
Lines 87-99 Link Here
87
			if (match.getElement() instanceof CompilationUnitEntry) {
87
			if (match.getElement() instanceof CompilationUnitEntry) {
88
				ICompilationUnit unit= ((CompilationUnitEntry)match.getElement()).getCompilationUnit();
88
				ICompilationUnit unit= ((CompilationUnitEntry)match.getElement()).getCompilationUnit();
89
				String field= unit.getSource().substring(match.getOffset(), match.getOffset() + match.getLength());
89
				String field= unit.getSource().substring(match.getOffset(), match.getOffset() + match.getLength());
90
				if (field.indexOf(key) != -1)
90
				if ((isAccessor && field.indexOf(key) != -1) || (!isAccessor && field.equals(key)))
91
					return;
91
					return;
92
			} else if (match.getElement() instanceof FileEntry) {
92
			} else if (match.getElement() instanceof FileEntry) {
93
				FileEntry entry= (FileEntry)match.getElement();
93
				FileEntry entry= (FileEntry)match.getElement();
94
				String content= getContent(entry.getPropertiesFile());
94
				String content= getContent(entry.getPropertiesFile());
95
				String propkey= content.substring(match.getOffset(), match.getOffset() + match.getLength());
95
				String propkey= content.substring(match.getOffset(), match.getOffset() + match.getLength());
96
				if (propkey.indexOf(key) != -1)
96
				if ((isAccessor && propkey.indexOf(key) != -1) || (!isAccessor && propkey.equals(key)))
97
					return;
97
					return;
98
			}
98
			}
99
		}
99
		}

Return to bug 297320