diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/jaxrs/JaxRsUtils.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/jaxrs/JaxRsUtils.java index ce01ca93f..45744a776 100644 --- a/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/jaxrs/JaxRsUtils.java +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.core/src/main/java/org/eclipse/lsp4mp/jdt/core/jaxrs/JaxRsUtils.java @@ -36,6 +36,7 @@ import org.eclipse.jdt.core.JavaModelException; import org.eclipse.lsp4j.CodeLens; import org.eclipse.lsp4j.Command; +import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4mp.jdt.core.utils.IJDTUtils; @@ -133,12 +134,18 @@ public static CodeLens createURLCodeLens(String baseURL, String rootPath, String } private static CodeLens createURLCodeLens(IMethod method, IJDTUtils utils) throws JavaModelException { - ISourceRange r = method.getNameRange(); - if (r == null) { + IAnnotation[] annotations = method.getAnnotations(); + if (annotations == null) { return null; } + ISourceRange r = annotations[annotations.length - 1].getSourceRange(); + CodeLens lens = new CodeLens(); - final Range range = utils.toRange(method.getOpenable(), r.getOffset(), r.getLength()); + Range range = utils.toRange(method.getOpenable(), r.getOffset(), r.getLength()); + // Increment line number for code lens to appear on the line right after the last annotation + Position codeLensPosition = new Position(range.getEnd().getLine() + 1, range.getEnd().getCharacter()); + range.setStart(codeLensPosition); + range.setEnd(codeLensPosition); lens.setRange(range); return lens; } diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/hibernate-orm-resteasy-yaml/src/main/java/org/acme/hibernate/orm/FruitResource.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/hibernate-orm-resteasy-yaml/src/main/java/org/acme/hibernate/orm/FruitResource.java index 16d9481a4..4007e1955 100644 --- a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/hibernate-orm-resteasy-yaml/src/main/java/org/acme/hibernate/orm/FruitResource.java +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/hibernate-orm-resteasy-yaml/src/main/java/org/acme/hibernate/orm/FruitResource.java @@ -75,9 +75,13 @@ public Fruit update(@PathParam Integer id, Fruit fruit) { } @DELETE - @Path("{id}") @Transactional - public Response delete(@PathParam Integer id) { + @Path( + "{id}" + ) + public + Response + delete(@PathParam Integer id) { Fruit entity = entityManager.getReference(Fruit.class, id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/hibernate-orm-resteasy/src/main/java/org/acme/hibernate/orm/FruitResource.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/hibernate-orm-resteasy/src/main/java/org/acme/hibernate/orm/FruitResource.java index 16d9481a4..4007e1955 100644 --- a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/hibernate-orm-resteasy/src/main/java/org/acme/hibernate/orm/FruitResource.java +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/projects/maven/hibernate-orm-resteasy/src/main/java/org/acme/hibernate/orm/FruitResource.java @@ -75,9 +75,13 @@ public Fruit update(@PathParam Integer id, Fruit fruit) { } @DELETE - @Path("{id}") @Transactional - public Response delete(@PathParam Integer id) { + @Path( + "{id}" + ) + public + Response + delete(@PathParam Integer id) { Fruit entity = entityManager.getReference(Fruit.class, id); if (entity == null) { throw new WebApplicationException("Fruit with id of " + id + " does not exist.", 404); diff --git a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/src/main/java/org/eclipse/lsp4mp/jdt/core/jaxrs/java/JaxRsCodeLensTest.java b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/src/main/java/org/eclipse/lsp4mp/jdt/core/jaxrs/java/JaxRsCodeLensTest.java index 96b814521..ba4618576 100644 --- a/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/src/main/java/org/eclipse/lsp4mp/jdt/core/jaxrs/java/JaxRsCodeLensTest.java +++ b/microprofile.jdt/org.eclipse.lsp4mp.jdt.test/src/main/java/org/eclipse/lsp4mp/jdt/core/jaxrs/java/JaxRsCodeLensTest.java @@ -21,6 +21,8 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.lsp4j.CodeLens; +import org.eclipse.lsp4j.Position; +import org.eclipse.lsp4j.Range; import org.eclipse.lsp4mp.commons.MicroProfileJavaCodeLensParams; import org.eclipse.lsp4mp.jdt.core.BasePropertiesManagerTest; import org.eclipse.lsp4mp.jdt.core.PropertiesManagerForJava; @@ -101,11 +103,22 @@ private static void assertCodeLenses(int port, MicroProfileJavaCodeLensParams pa Assert.assertEquals("http://localhost:" + port + "/fruits/{id}", lensForPut.getCommand().getTitle()); //@DELETE - //@Path("{id}") - //public Response delete(@PathParam Integer id) { + //@Transactional + //@Path( + //"{id}" + //) + //--> code lens should appear here + //public + //Response + //delete(@PathParam Integer id) { CodeLens lensForDelete = lenses.get(4); Assert.assertNotNull(lensForDelete.getCommand()); Assert.assertEquals("http://localhost:" + port + "/fruits/{id}", lensForDelete.getCommand().getTitle()); + Assert.assertEquals(r(81, 9, 81, 9), lensForDelete.getRange()); + } + + public static Range r(int startLine, int startCharacter, int endLine, int endCharacter) { + return new Range(new Position(startLine, startCharacter), new Position(endLine, endCharacter)); } }