Search in sources :

Example 6 with IProblemLocation

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;
}
Also used : AddBundleCompletionProposal(org.bndtools.core.editors.ImportPackageQuickFixProcessor.AddBundleCompletionProposal) AtomicReference(java.util.concurrent.atomic.AtomicReference) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)

Example 7 with IProblemLocation

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));
}
Also used : IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) Test(org.junit.Test)

Example 8 with IProblemLocation

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));
}
Also used : IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) Test(org.junit.Test)

Example 9 with IProblemLocation

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();
}
Also used : IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) ProblemLocation(org.eclipse.jdt.internal.ui.text.correction.ProblemLocation) Test(org.junit.Test)

Example 10 with IProblemLocation

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) Test(org.junit.Test)

Aggregations

IProblemLocation (org.eclipse.jdt.ui.text.java.IProblemLocation)39 ArrayList (java.util.ArrayList)15 ProblemLocation (org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)15 Test (org.junit.Test)10 IProblem (org.eclipse.jdt.core.compiler.IProblem)8 ASTNode (org.eclipse.jdt.core.dom.ASTNode)7 HashSet (java.util.HashSet)5 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)5 IJavaCompletionProposal (org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)4 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)2 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)2 SimpleName (org.eclipse.jdt.core.dom.SimpleName)2 ICommandAccess (org.eclipse.jdt.ui.text.java.correction.ICommandAccess)2 ArrayDeque (java.util.ArrayDeque)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 LinkedHashSet (java.util.LinkedHashSet)1