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 |
} |