diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandler.java index 1765562b41..984619ef37 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/PrepareRenameHandler.java @@ -18,6 +18,7 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.PackageDeclaration; import org.eclipse.jdt.core.dom.QualifiedName; +import org.eclipse.jdt.core.dom.SimpleName; import org.eclipse.jdt.core.manipulation.CoreASTProvider; import org.eclipse.jdt.internal.core.manipulation.search.IOccurrencesFinder.OccurrenceLocation; import org.eclipse.jdt.internal.core.manipulation.search.OccurrencesFinder; @@ -56,8 +57,9 @@ public Either prepareRename(TextDocumentPositionPara InnovationContext context = new InnovationContext(unit, loc.getOffset(), loc.getLength()); context.setASTRoot(ast); ASTNode node = context.getCoveredNode(); - // Rename package is not fully support yet. - if (!(node instanceof PackageDeclaration) && !(node instanceof QualifiedName && node.getParent() instanceof PackageDeclaration)) { + // Rename package is not fully supported yet. + if (!(node instanceof PackageDeclaration) + && !(((node instanceof QualifiedName) || (node instanceof SimpleName)) && node.getParent() instanceof PackageDeclaration)) { return Either.forLeft(JDTUtils.toRange(unit, loc.getOffset(), loc.getLength())); } } @@ -67,9 +69,9 @@ public Either prepareRename(TextDocumentPositionPara } } catch (CoreException e) { - JavaLanguageServerPlugin.logException("Problem with compute occurrences for" + unit.getElementName() + " in prepareRename", e); + JavaLanguageServerPlugin.logException("Problem computing occurrences for" + unit.getElementName() + " in prepareRename", e); } } - throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InvalidRequest, "Rename this element is not supported yet.", null)); + throw new ResponseErrorException(new ResponseError(ResponseErrorCode.InvalidRequest, "Renaming this element is not supported.", null)); } } diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/RenameHandlerTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/RenameHandlerTest.java index 5f6bbf9902..30845416d9 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/RenameHandlerTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/RenameHandlerTest.java @@ -240,7 +240,7 @@ public void testRenameTypeWithResourceChanges() throws JavaModelException, BadLo Either change = resourceChanges.get(2); RenameFile resourceChange = (RenameFile) change.getRight(); assertEquals(JDTUtils.toURI(cu), resourceChange.getOldUri()); - assertEquals(JDTUtils.toURI(cu).replace("E", "Newname"), resourceChange.getNewUri()); + assertEquals(JDTUtils.toURI(cu).replaceFirst("(?s)E(?!.*?E)", "Newname"), resourceChange.getNewUri()); List testChanges = new LinkedList<>(); testChanges.addAll(resourceChanges.get(0).getLeft().getEdits());