use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method proposalsFor.
private AddBundleCompletionProposal[] proposalsFor(IInvocationContext context, List<? extends IProblemLocation> locs) {
final AtomicReference<IJavaCompletionProposal[]> ref = new AtomicReference<>();
IProblemLocation[] locArray = new IProblemLocation[locs.size()];
assertThatCode(() -> {
ref.set(sut.getCorrections(context, locs.toArray(locArray)));
}).doesNotThrowAnyException();
final IJavaCompletionProposal[] props = ref.get();
if (props == null) {
return null;
}
assertThat(props).as("proposals").hasOnlyElementsOfType(AddBundleCompletionProposal.class);
AddBundleCompletionProposal[] retval = new AddBundleCompletionProposal[props.length];
int i = 0;
for (IJavaCompletionProposal prop : props) {
retval[i++] = (AddBundleCompletionProposal) prop;
}
return retval;
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method getCorrections_forIsClassPath_withBadType_returnsNullGracefully_andLogsWarning.
@Test
public void getCorrections_forIsClassPath_withBadType_returnsNullGracefully_andLogsWarning() {
List<IProblemLocation> locs = getProblems("package other; public class Test { Test2 test = new `Test2()'; }", new ProblemLocation(0, 0, IsClassPathCorrect, new String[] { "invalid type/string" }, true, JDT_PROBLEM));
assertThat(proposalsFor(locs)).isNull();
verify(logger).logWarning(eq("Illegal type 'invalid type/string'"), any(IllegalArgumentException.class));
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method getCorrections_forIsClassPath_withLowerCaseClass_suggestsBundle.
@Test
public void getCorrections_forIsClassPath_withLowerCaseClass_suggestsBundle() {
List<IProblemLocation> locs = getProblems("public class Test { Test2 test = new `Test2()'; }", new ProblemLocation(0, 0, IsClassPathCorrect, new String[] { "org.osgi.framework.clazz" }, true, JDT_PROBLEM));
assertThatContainsFrameworkBundles(proposalsFor(locs));
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method getCorrections_forIsClassPath_withEmptyArgs_returnsNullGracefully.
// These next three types are paranoia checks, because I'm not quite sure how Eclipse will behave in all
// circumstances, so I'm being defensive.
@Test
public void getCorrections_forIsClassPath_withEmptyArgs_returnsNullGracefully() {
List<IProblemLocation> locs = getProblems("public class Test { Test2 test = new `Test2()'; }", new ProblemLocation(0, 0, IsClassPathCorrect, new String[0], true, JDT_PROBLEM));
assertThat(proposalsFor(locs)).isNull();
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.
the class ImportPackageQuickFixProcessorTest method getCorrections_whenContainsBundleFails_throwsException.
@Test
public void getCorrections_whenContainsBundleFails_throwsException() {
containsBundleException = new CoreException(new Status(IStatus.ERROR, "bundle", "Hi there"));
List<IProblemLocation> locs = getProblems("import `org.osgi.framework'.*;", ImportNotFound);
IProblemLocation[] locArray = new IProblemLocation[locs.size()];
assertThatExceptionOfType(CoreException.class).isThrownBy(() -> {
sut.getCorrections(new FakeInvocationContext(), locs.toArray(locArray));
}).isSameAs(containsBundleException);
}
Aggregations