Skip to content

Commit

Permalink
F2 rename of Lombok @Singular attribute does nothing
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Sep 7, 2023
1 parent f4d1a4a commit 10ab0e8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,15 @@ public static IJavaElement[] findElementsAtSelection(ITypeRoot unit, int line, i
return null;
}
if (offset > -1) {
return unit.codeSelect(offset, 0);
IJavaElement[] elements = unit.codeSelect(offset, 0);
if (elements == null || elements.length == 0) {
IJavaElement element = unit.getElementAt(offset);
if (element != null) {
return new IJavaElement[] { element };
}
} else {
return elements;
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sample;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.Singular;
@Builder
@Getter
public class Test2 {
@Singular("singular")
List<String> singulars;
List<String> normals;
}
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,25 @@ public void testRenameTypeLombok() throws Exception {
assertEquals(expected, TextEditUtil.apply(source, edit.getChanges().get(JDTUtils.toURI(cu))));
}

// this test should pass when starting with -javaagent:<lombok_jar> (-javagent:~/.m2/repository/org/projectlombok/lombok/1.18.28/lombok-1.18.28.jar)
// https:/redhat-developer/vscode-java/issues/3203
@Test
public void testLombokSingular() throws Exception {
when(preferenceManager.getPreferences().isImportMavenEnabled()).thenReturn(true);
importProjects("maven/mavenlombok");
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("mavenlombok");
IFile file = project.getFile("src/main/java/org/sample/Test2.java");
assertTrue(file.exists());
ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
Position pos = new Position(9, 18);
String source = cu.getSource();
String expected = source.replace("singulars", "singulars2");
WorkspaceEdit edit = getRenameEdit(cu, pos, "singulars2");
assertNotNull(edit);
assertEquals(1, edit.getChanges().size());
assertEquals(expected, TextEditUtil.apply(source, edit.getChanges().get(JDTUtils.toURI(cu))));
}

// this test should pass when starting with -javaagent:<lombok_jar> (-javagent:~/.m2/repository/org/projectlombok/lombok/1.18.28/lombok-1.18.28.jar)
// https:/redhat-developer/vscode-java/issues/2805
@Test
Expand Down

0 comments on commit 10ab0e8

Please sign in to comment.