From 4cf9bb3afcfd723174b7a5cbfbf25ff0350ea7fb Mon Sep 17 00:00:00 2001 From: Yaohai Zheng Date: Tue, 27 Nov 2018 13:47:54 +0800 Subject: [PATCH] Address review feedback. --- .../jdt/ls/core/internal/handlers/PrepareRenameHandler.java | 6 ++++-- .../jdt/ls/core/internal/handlers/RenameHandlerTest.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) 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..f95182f8f1 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; @@ -57,7 +58,8 @@ public Either prepareRename(TextDocumentPositionPara 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)) { + if (!(node instanceof PackageDeclaration) + && !(((node instanceof QualifiedName) || (node instanceof SimpleName)) && node.getParent() instanceof PackageDeclaration)) { return Either.forLeft(JDTUtils.toRange(unit, loc.getOffset(), loc.getLength())); } } @@ -70,6 +72,6 @@ public Either prepareRename(TextDocumentPositionPara JavaLanguageServerPlugin.logException("Problem with compute 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, "Rename 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());