Search in sources :

Example 31 with IProblemLocation

use of org.eclipse.jdt.ui.text.java.IProblemLocation in project liferay-ide by liferay.

the class QuickFixGradleDep method getCorrections.

@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) {
    if (ListUtil.isEmpty(locations)) {
        return null;
    }
    IResource resource = context.getCompilationUnit().getResource();
    IProject project = resource.getProject();
    _gradleFile = project.getFile("build.gradle");
    List<IJavaCompletionProposal> resultingCollections = new ArrayList<>();
    if (FileUtil.exists(_gradleFile)) {
        for (int i = 0; i < locations.length; i++) {
            IProblemLocation curr = locations[i];
            _process(context, curr, resultingCollections);
        }
    }
    return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
Also used : ArrayList(java.util.ArrayList) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 32 with IProblemLocation

use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.

the class ImportPackageQuickFixProcessorTest method getCorrections_forIsClassPath_suggestsBundle.

@Test
public void getCorrections_forIsClassPath_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 33 with IProblemLocation

use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.

the class ImportPackageQuickFixProcessorTest method getCorrections_whenWorkspaceFails_andMultiplePackages_onlyLogsErrorOnce.

@Test
public void getCorrections_whenWorkspaceFails_andMultiplePackages_onlyLogsErrorOnce() {
    Exception ex = makeSUTgetWSRepo_throwException();
    List<IProblemLocation> locs = getProblems("import `org.eclipse.ui'.*; import `org.osgi.framework'.*;", new int[] { ImportNotFound, ImportNotFound });
    proposalsFor(new FakeInvocationContext(7, 0), locs);
    verify(logger, times(1)).logError("Error trying to fetch the repository for the current workspace", ex);
}
Also used : IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) CoreException(org.eclipse.core.runtime.CoreException) Test(org.junit.Test)

Example 34 with IProblemLocation

use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.

the class ImportPackageQuickFixProcessorTest method getCorrections_forIsClassPath_withLowerCaseClassInMainNamespace_returnsNull.

@Test
public void getCorrections_forIsClassPath_withLowerCaseClassInMainNamespace_returnsNull() {
    List<IProblemLocation> locs = getProblems("package other; public class Test { Test2 test = new `Test2()'; }", new ProblemLocation(0, 0, IsClassPathCorrect, new String[] { "test" }, 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 35 with IProblemLocation

use of org.eclipse.jdt.ui.text.java.IProblemLocation in project bndtools by bndtools.

the class ImportPackageQuickFixProcessorTest method testGetProblems.

@Test
public // Internal test for a fairly complicated helper method.
void testGetProblems() {
    assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> {
        getProblems("import `my.pkg.*';", new int[0]);
    });
    List<IProblemLocation> probs = getProblems("import ``my.`p'kg'.*';", ImportNotFound, UndefinedType, AmbiguousField);
    assertThat(cu.toString().trim()).as("source").isEqualTo("import my.pkg.*;");
    assertThat(probs).hasSize(3);
    IProblemLocation loc;
    loc = probs.get(0);
    assertThat(loc.getProblemId()).as("problem 0").isEqualTo(ImportNotFound);
    assertThat(loc.getOffset()).as("offset 0").isEqualTo(10);
    assertThat(loc.getLength()).as("length 0").isEqualTo(1);
    loc = probs.get(1);
    assertThat(loc.getProblemId()).as("problem 1").isEqualTo(UndefinedType);
    assertThat(loc.getOffset()).as("offset 1").isEqualTo(7);
    assertThat(loc.getLength()).as("length 1").isEqualTo(6);
    loc = probs.get(2);
    assertThat(loc.getProblemId()).as("problem 2").isEqualTo(AmbiguousField);
    assertThat(loc.getOffset()).as("offset 2").isEqualTo(7);
    assertThat(loc.getLength()).as("length 2").isEqualTo(8);
}
Also used : 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