diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.api/src/main/java/org/eclipse/che/jdt/ls/extension/api/Commands.java b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.api/src/main/java/org/eclipse/che/jdt/ls/extension/api/Commands.java index ec60b55..ba265a6 100644 --- a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.api/src/main/java/org/eclipse/che/jdt/ls/extension/api/Commands.java +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.api/src/main/java/org/eclipse/che/jdt/ls/extension/api/Commands.java @@ -31,5 +31,10 @@ public class Commands { public static final String RESOLVE_CLASSPATH_COMMAND = "che.jdt.ls.extension.resolveClasspath"; public static final String GET_OUTPUT_DIR_COMMAND = "che.jdt.ls.extension.outputDir"; + // debug + + public static final String FQN_TO_LOCATION_COMMAND = "che.jdt.ls.extension.debug.fqnToLocation"; + public static final String LOCATION_TO_FQN_COMMAND = "che.jdt.ls.extension.debug.locationToFqn"; + private Commands() {} } diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.api/src/main/java/org/eclipse/che/jdt/ls/extension/api/dto/LocationParameters.java b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.api/src/main/java/org/eclipse/che/jdt/ls/extension/api/dto/LocationParameters.java new file mode 100644 index 0000000..630cee6 --- /dev/null +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.api/src/main/java/org/eclipse/che/jdt/ls/extension/api/dto/LocationParameters.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.jdt.ls.extension.api.dto; + +/** @author Anatolii Bazko */ +public class LocationParameters { + private String projectPath; + private String target; + private int lineNumber; + private int libId; + + public LocationParameters() {} + + public LocationParameters(String target, int lineNumber, String projectPath) { + this.target = target; + this.lineNumber = lineNumber; + this.projectPath = projectPath; + this.libId = 0; + } + + public LocationParameters(String target, int lineNumber, int libId, String projectPath) { + this.target = target; + this.lineNumber = lineNumber; + this.projectPath = projectPath; + this.libId = libId; + } + + public int getLineNumber() { + return lineNumber; + } + + public void setLineNumber(int lineNumber) { + this.lineNumber = lineNumber; + } + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getProjectPath() { + return projectPath; + } + + public void setProjectPath(String projectPath) { + this.projectPath = projectPath; + } + + public int getLibId() { + return libId; + } + + public void setLibId(int libId) { + this.libId = libId; + } +} diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/META-INF/MANIFEST.MF b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/META-INF/MANIFEST.MF index 5ca9117..2fa820b 100644 --- a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/META-INF/MANIFEST.MF +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/META-INF/MANIFEST.MF @@ -4,19 +4,22 @@ Bundle-Name: jdt.ls.extension Core Extension Bundle-SymbolicName: jdt.ls.extension.core;singleton:=true Bundle-Version: 0.0.1.qualifier Bundle-Activator: org.eclipse.che.jdt.ls.extension.core.internal.ExtensionActivator -Import-Package: com.google.gson, +Import-Package: com.google.common.base;version="15.0.0", + com.google.gson, + org.apache.commons.lang3.tuple;version="3.1.0", org.eclipse.che.jdt.ls.extension.api, org.eclipse.che.jdt.ls.extension.api.dto, org.eclipse.core.resources, + org.eclipse.core.runtime, org.eclipse.jdt.core, org.eclipse.jdt.launching, org.eclipse.jdt.ls.core.internal, - org.eclipse.core.runtime, org.eclipse.lsp4j, org.eclipse.lsp4j.jsonrpc.json.adapters Require-Bundle: org.eclipse.core.runtime, org.eclipse.jdt.core, org.eclipse.jdt.ls.core, + org.eclipse.jface.text, org.eclipse.jdt.core.manipulation Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.8 diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/plugin.xml b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/plugin.xml index fa15993..91d6fa9 100644 --- a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/plugin.xml +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/plugin.xml @@ -1,8 +1,8 @@ - - + + @@ -12,6 +12,8 @@ - - + + + + diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/pom.xml b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/pom.xml index 87511c5..3d0f7ec 100644 --- a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/pom.xml +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/pom.xml @@ -23,8 +23,8 @@ eclipse-plugin Che Ls Jdt :: Extension :: Core - - + + com.mycila license-maven-plugin @@ -33,6 +33,6 @@ - + diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/CheDelegateCommandHandler.java b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/CheDelegateCommandHandler.java index 81ba806..e0c491a 100644 --- a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/CheDelegateCommandHandler.java +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/CheDelegateCommandHandler.java @@ -16,6 +16,7 @@ import java.util.function.BiFunction; import org.eclipse.che.jdt.ls.extension.api.Commands; import org.eclipse.che.jdt.ls.extension.core.internal.classpath.ResolveClassPathsHandler; +import org.eclipse.che.jdt.ls.extension.core.internal.debug.FqnConverter; import org.eclipse.che.jdt.ls.extension.core.internal.testdetection.TestDetectionHandler; import org.eclipse.che.jdt.ls.extension.core.internal.testdetection.TestFinderHandler; import org.eclipse.core.runtime.IProgressMonitor; @@ -42,6 +43,8 @@ public class CheDelegateCommandHandler implements IDelegateCommandHandler { commands.put(Commands.FIND_TESTS_IN_FILE_COMMAND, TestFinderHandler::getClassFqn); commands.put(Commands.RESOLVE_CLASSPATH_COMMAND, ResolveClassPathsHandler::resolveClasspaths); commands.put(Commands.GET_OUTPUT_DIR_COMMAND, ResolveClassPathsHandler::getOutputDirectory); + commands.put(Commands.LOCATION_TO_FQN_COMMAND, FqnConverter::locationToFqn); + commands.put(Commands.FQN_TO_LOCATION_COMMAND, FqnConverter::fqnToLocation); } @Override diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/debug/FqnConverter.java b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/debug/FqnConverter.java new file mode 100644 index 0000000..9ff4831 --- /dev/null +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.core/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/debug/FqnConverter.java @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.jdt.ls.extension.core.internal.debug; + +import com.google.common.base.Preconditions; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.apache.commons.lang3.tuple.Pair; +import org.eclipse.che.jdt.ls.extension.api.dto.LocationParameters; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClassFile; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IMember; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.search.IJavaSearchConstants; +import org.eclipse.jdt.core.search.IJavaSearchScope; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.core.search.TypeNameMatch; +import org.eclipse.jdt.core.search.TypeNameMatchRequestor; +import org.eclipse.jdt.internal.core.JavaModel; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.JavaProject; +import org.eclipse.jdt.internal.core.SourceMethod; +import org.eclipse.jdt.internal.core.SourceType; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IRegion; +import org.eclipse.lsp4j.jsonrpc.json.adapters.CollectionTypeAdapterFactory; +import org.eclipse.lsp4j.jsonrpc.json.adapters.EitherTypeAdapterFactory; +import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapterFactory; + +/** @author Anatolii Bazko */ +public class FqnConverter { + + private static final Gson gson = + new GsonBuilder() + .registerTypeAdapterFactory(new CollectionTypeAdapterFactory()) + .registerTypeAdapterFactory(new EitherTypeAdapterFactory()) + .registerTypeAdapterFactory(new EnumTypeAdapterFactory()) + .create(); + + /** Converts {@link LocationParameters} into fqn. */ + public static String locationToFqn(List params, IProgressMonitor pm) { + Preconditions.checkArgument(params.size() >= 1, "LocationParameter is expected"); + + LocationParameters location; + if (params.get(0) instanceof LocationParameters) { + location = (LocationParameters) params.get(0); + } else { + location = gson.fromJson(gson.toJson(params.get(0)), LocationParameters.class); + } + + if (pm.isCanceled()) { + throw new OperationCanceledException(); + } + + JavaModel javaModel = JavaModelManager.getJavaModelManager().getJavaModel(); + + IPath path = Path.fromOSString(location.getTarget()); + IJavaProject project; + try { + project = getJavaProject(path, javaModel); + } catch (JavaModelException e) { + throw new RuntimeException(e); + } + + if (project == null) { + if (location.getProjectPath() != null) { + project = javaModel.getJavaProject(location.getProjectPath()); + } else { + return location.getTarget(); + } + } + + String fqn = null; + for (int i = path.segmentCount(); i > 0; i--) { + try { + IClasspathEntry classpathEntry = + ((JavaProject) project).getClasspathEntryFor(path.removeLastSegments(i)); + + if (classpathEntry != null) { + fqn = + path.removeFirstSegments(path.segmentCount() - i) + .removeFileExtension() + .toString() + .replace("/", "."); + break; + } + } catch (JavaModelException e) { + return location.getTarget(); + } + } + + if (fqn == null) { + return location.getTarget(); + } + + IType outerClass; + IJavaElement iMember; + try { + outerClass = project.findType(fqn); + + if (outerClass == null) { + return location.getTarget(); + } + + String source; + if (outerClass.isBinary()) { + IClassFile classFile = outerClass.getClassFile(); + source = classFile.getSource(); + } else { + ICompilationUnit unit = outerClass.getCompilationUnit(); + source = unit.getSource(); + } + + Document document = new Document(source); + IRegion region = document.getLineInformation(location.getLineNumber()); + int start = region.getOffset(); + int end = start + region.getLength(); + + iMember = binSearch(outerClass, start, end); + } catch (JavaModelException e) { + throw new IllegalArgumentException( + String.format( + "Unable to find source for class with fqn '%s' in the project '%s'", + location.getTarget(), project), + e); + } catch (BadLocationException e) { + throw new IllegalArgumentException("Unable to calculate breakpoint location", e); + } + + if (iMember instanceof IType) { + return ((IType) iMember).getFullyQualifiedName(); + } + + if (iMember != null) { + fqn = ((IMember) iMember).getDeclaringType().getFullyQualifiedName(); + while (iMember != null && !(iMember instanceof CompilationUnit)) { + if (iMember instanceof SourceType + && !((SourceType) iMember).isAnonymous() + && iMember.getParent() instanceof SourceMethod) { + + fqn = fqn.replace("$" + iMember.getElementName(), "$1" + iMember.getElementName()); + } + + iMember = iMember.getParent(); + } + + return fqn; + } + + throw new IllegalArgumentException("Unable to calculate breakpoint location"); + } + + /** Converts fqn into {@link LocationParameters}. */ + public static List fqnToLocation( + List parameters, IProgressMonitor pm) { + Preconditions.checkArgument(parameters.size() >= 2, "Fqn and line number are expected."); + + String fqn = (String) parameters.get(0); + Integer lineNumber = Integer.parseInt(parameters.get(1).toString()); + + if (pm.isCanceled()) { + throw new OperationCanceledException(); + } + + Pair fqnPair = prepareFqnToSearch(fqn); + List types; + try { + types = + findTypeByFqn(fqnPair.getKey(), fqnPair.getValue(), SearchEngine.createWorkspaceScope()); + } catch (JavaModelException e) { + throw new RuntimeException(e); + } + + if (types.isEmpty()) { + throw new RuntimeException("Type with fully qualified name: " + fqn + " was not found"); + } + + IType type = types.get(0); // TODO we need handle few result! It's temporary solution. + String typeProjectPath = type.getJavaProject().getPath().toOSString(); + if (type.isBinary()) { + IClassFile classFile = type.getClassFile(); + int libId = classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode(); + return Collections.singletonList( + new LocationParameters(fqn, lineNumber, libId, typeProjectPath)); + } else { + ICompilationUnit compilationUnit = type.getCompilationUnit(); + typeProjectPath = type.getJavaProject().getPath().toOSString(); + String resourcePath = compilationUnit.getPath().toOSString(); + return Collections.singletonList( + new LocationParameters(resourcePath, lineNumber, typeProjectPath)); + } + } + + private static List findTypeByFqn( + char[][] packages, char[][] names, IJavaSearchScope scope) throws JavaModelException { + List result = new ArrayList<>(); + + SearchEngine searchEngine = new SearchEngine(); + searchEngine.searchAllTypeNames( + packages, + names, + scope, + new TypeNameMatchRequestor() { + @Override + public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) { + result.add(typeNameMatch.getType()); + } + }, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + new NullProgressMonitor()); + return result; + } + + private static Pair prepareFqnToSearch(String fqn) { + String outerClassFqn = extractOuterClassFqn(fqn); + int lastDotIndex = outerClassFqn.trim().lastIndexOf('.'); + + char[][] packages; + char[][] names; + if (lastDotIndex == -1) { + packages = new char[0][]; + names = new char[][] {outerClassFqn.toCharArray()}; + } else { + String packageLine = fqn.substring(0, lastDotIndex); + packages = new char[][] {packageLine.toCharArray()}; + + String nameLine = fqn.substring(lastDotIndex + 1, outerClassFqn.length()); + names = new char[][] {nameLine.toCharArray()}; + } + return Pair.of(packages, names); + } + + private static String extractOuterClassFqn(String fqn) { + // handle fqn in case nested classes + if (fqn.contains("$")) { + return fqn.substring(0, fqn.indexOf("$")); + } + + // handle fqn in case lambda expressions + return fqn.contains("$$") ? fqn.substring(0, fqn.indexOf("$$")) : fqn; + } + + private static IJavaProject getJavaProject(IPath path, JavaModel javaModel) + throws JavaModelException { + IJavaProject project = null; + outer: + for (int i = 1; i < path.segmentCount(); i++) { + IPath projectPath = path.removeLastSegments(i); + for (IJavaProject p : javaModel.getJavaProjects()) { + if (p.getPath().equals(projectPath)) { + project = p; + break outer; + } + } + } + return project; + } + + /** + * Searches the given source range of the container for a member that is not the same as the given + * type. + * + * @param type the {@link IType} + * @param start the starting position + * @param end the ending position + * @return the {@link IMember} from the given start-end range + * @throws JavaModelException if there is a problem with the backing Java model + */ + private static IMember binSearch(IType type, int start, int end) throws JavaModelException { + IJavaElement je = getElementAt(type, start); + if (je != null && !je.equals(type)) { + return asMember(je); + } + if (end > start) { + je = getElementAt(type, end); + if (je != null && !je.equals(type)) { + return asMember(je); + } + int mid = ((end - start) / 2) + start; + if (mid > start) { + je = binSearch(type, start + 1, mid); + if (je == null) { + je = binSearch(type, mid + 1, end - 1); + } + return asMember(je); + } + } + return null; + } + + /** + * Returns the given Java element if it is an IMember, otherwise null. + * + * @param element Java element + * @return the given element if it is a type member, otherwise null + */ + private static IMember asMember(IJavaElement element) { + if (element instanceof IMember) { + return (IMember) element; + } + return null; + } + + /** + * Returns the element at the given position in the given type + * + * @param type the {@link IType} + * @param pos the position + * @return the {@link IJavaElement} at the given position + * @throws JavaModelException if there is a problem with the backing Java model + */ + private static IJavaElement getElementAt(IType type, int pos) throws JavaModelException { + if (type.isBinary()) { + return type.getClassFile().getElementAt(pos); + } + return type.getCompilationUnit().getElementAt(pos); + } +} diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/projects/maven/debugproject/pom.xml b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/projects/maven/debugproject/pom.xml new file mode 100644 index 0000000..64f435f --- /dev/null +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/projects/maven/debugproject/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + org.eclipse.che.examples + debugproject + jar + 1.0-SNAPSHOT + hello-app + http://maven.apache.org + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + true + lib/ + org.eclipse.che.examples.HelloWorld + + + + + + maven-compiler-plugin + 3.6.1 + + eclipse + 1.8 + 1.8 + true + true + + + + org.codehaus.plexus + plexus-compiler-eclipse + 2.8.1 + + + + + + diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/projects/maven/debugproject/src/main/java/org/eclipse/che/examples/HelloWorld.java b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/projects/maven/debugproject/src/main/java/org/eclipse/che/examples/HelloWorld.java new file mode 100644 index 0000000..aca45d4 --- /dev/null +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/projects/maven/debugproject/src/main/java/org/eclipse/che/examples/HelloWorld.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.examples; + +public class HelloWorld { + public static void main(String[] argvs) { + String a = "Che"; + + new InnerClass().sayHello(); + + new Thread() { + @Override + public void run() { + System.out.println("Hello"); + } + }.run(); + + Stream.of("a", "b") + .forEach( + v -> { + System.out.println(v); + }); + } + + private static class InnerClass { + public void sayHello() { + System.out.println("Hello"); + } + } +} diff --git a/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/debug/FqnConverterTest.java b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/debug/FqnConverterTest.java new file mode 100644 index 0000000..b8d1cc0 --- /dev/null +++ b/org-eclipse-che-jdt-ls-extension/jdt.ls.extension.test/src/main/java/org/eclipse/che/jdt/ls/extension/core/internal/debug/FqnConverterTest.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.jdt.ls.extension.core.internal.debug; + +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import org.eclipse.che.jdt.ls.extension.api.dto.LocationParameters; +import org.eclipse.che.jdt.ls.extension.core.internal.AbstractProjectsManagerBasedTest; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.junit.Before; +import org.junit.Test; + +public class FqnConverterTest extends AbstractProjectsManagerBasedTest { + + private static final String PROJECT = "/debugproject"; + private static final String TEST_CLASS = + PROJECT + "/src/main/java/org/eclipse/che/examples/HelloWorld.java"; + private static final String FQN = "org.eclipse.che.examples.HelloWorld"; + + @Before + public void setup() throws Exception { + importProjects("maven/debugproject"); + } + + @Test + public void shouldConvertSimpleLocation() throws Exception { + List result = + FqnConverter.fqnToLocation(asList(FQN, "15"), new NullProgressMonitor()); + + assertEquals(result.size(), 1); + + LocationParameters location = result.get(0); + assertEquals(location.getLineNumber(), 15); + assertEquals(location.getTarget(), TEST_CLASS); + assertEquals(location.getProjectPath(), PROJECT); + assertEquals(location.getLibId(), 0); + + String fqn = FqnConverter.locationToFqn(singletonList(location), new NullProgressMonitor()); + + assertEquals(fqn, FQN); + } + + @Test + public void shouldConvertExternalLibLocation() throws Exception { + List result = + FqnConverter.fqnToLocation(asList("java.lang.String", "100"), new NullProgressMonitor()); + + assertEquals(result.size(), 1); + + LocationParameters location = result.get(0); + assertEquals(location.getLineNumber(), 100); + assertEquals(location.getTarget(), "java.lang.String"); + assertNotNull(location.getProjectPath()); + assertTrue(location.getLibId() != 0); + + String fqn = FqnConverter.locationToFqn(singletonList(location), new NullProgressMonitor()); + + assertEquals(fqn, "java.lang.String"); + } + + @Test + public void shouldConvertInnerClassLocation() throws Exception { + List result = + FqnConverter.fqnToLocation(asList(FQN + "$InnerClass", "35"), new NullProgressMonitor()); + + assertEquals(result.size(), 1); + + LocationParameters location = result.get(0); + + assertEquals(location.getLineNumber(), 35); + assertEquals(location.getTarget(), TEST_CLASS); + assertEquals(location.getProjectPath(), PROJECT); + assertEquals(location.getLibId(), 0); + + String fqn = FqnConverter.locationToFqn(singletonList(location), new NullProgressMonitor()); + + assertEquals(fqn, FQN + "$InnerClass"); + } + + @Test + public void shouldConvertAnonymousClassLocation() throws Exception { + List result = + FqnConverter.fqnToLocation(asList(FQN + "$1", "22"), new NullProgressMonitor()); + + assertEquals(result.size(), 1); + + LocationParameters location = result.get(0); + + assertEquals(location.getLineNumber(), 22); + assertEquals(location.getTarget(), TEST_CLASS); + assertEquals(location.getProjectPath(), PROJECT); + assertEquals(location.getLibId(), 0); + + String fqn = FqnConverter.locationToFqn(singletonList(location), new NullProgressMonitor()); + + assertEquals(fqn, FQN + "$1"); + } + + @Test + public void shouldConvertLocationInsideLambdaToFqn() throws Exception { + List result = + FqnConverter.fqnToLocation(asList(FQN, "29"), new NullProgressMonitor()); + + assertEquals(result.size(), 1); + + LocationParameters location = result.get(0); + + assertEquals(location.getLineNumber(), 29); + assertEquals(location.getTarget(), TEST_CLASS); + assertEquals(location.getProjectPath(), PROJECT); + assertEquals(location.getLibId(), 0); + + String fqn = FqnConverter.locationToFqn(singletonList(location), new NullProgressMonitor()); + + assertEquals(fqn, FQN); + } +} diff --git a/org-eclipse-che-jdt-ls-extension/pom.xml b/org-eclipse-che-jdt-ls-extension/pom.xml index 117135c..8d5c170 100644 --- a/org-eclipse-che-jdt-ls-extension/pom.xml +++ b/org-eclipse-che-jdt-ls-extension/pom.xml @@ -16,8 +16,7 @@ Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Red Hat, Inc. - initial API and implementation --> - + 4.0.0 che-ls-jdt-parent @@ -29,7 +28,7 @@ pom Che Ls Jdt :: Extension :: Parent - jdt.ls.extension.api + jdt.ls.extension.api jdt.ls.extension.core jdt.ls.extension.test jdt.ls.extension.site @@ -62,7 +61,7 @@ http://download.eclipse.org/jdtls/snapshots/repository/latest/ p2 - + org.mockito.mockito-all http://download.eclipse.org/scout/releases/4.0/testing p2 @@ -144,7 +143,6 @@ -err:-forbidden -warn:-forbidden - 1.8 1.8 diff --git a/pom.xml b/pom.xml index 5901d1c..d330824 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ pom Che Ls Jdt :: Parent - org-eclipse-che-jdt-ls-extension + org-eclipse-che-jdt-ls-extension scm:git@github.com:eclipse/che-ls-jdt.git