diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/RefactorProcessor.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/RefactorProcessor.java index 92d222f7f0..4f97d99eb7 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/RefactorProcessor.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/corrections/RefactorProcessor.java @@ -346,7 +346,7 @@ private boolean getInlineProposal(IInvocationContext context, ASTNode node, Coll // Inline Local Variable if (binding.getJavaElement() instanceof ILocalVariable && RefactoringAvailabilityTesterCore.isInlineTempAvailable((ILocalVariable) binding.getJavaElement())) { InlineTempRefactoring refactoring= new InlineTempRefactoring((VariableDeclaration) decl); - if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK()) { + if (refactoring.checkInitialConditions(new NullProgressMonitor()).isOK() && refactoring.getReferences().length > 0) { String label = CorrectionMessages.QuickAssistProcessor_inline_local_description; int relevance = IProposalRelevance.INLINE_LOCAL; RefactoringCorrectionProposal proposal = new RefactoringCorrectionProposal(label, CodeActionKind.RefactorInline, context.getCompilationUnit(), refactoring, relevance); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/InlineVariableTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/InlineVariableTest.java index b167348c92..8e9814244e 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/InlineVariableTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/refactoring/InlineVariableTest.java @@ -71,4 +71,22 @@ public void testInlineLocalVariable() throws Exception { Expected expected = new Expected(INLINE_LOCAL_VARIABLE, buf.toString(), CodeActionKind.RefactorInline); assertCodeActions(cu, expected); } + + @Test + public void testInlineLocalVariableWithNoReferences() throws Exception { + IPackageFragment pack1 = testSourceFolder.createPackageFragment("test", false, null); + + StringBuilder buf = new StringBuilder(); + buf.append("package test;\n"); + buf.append("public class E {\n"); + buf.append(" public void foo(String[] parameters, int j) {\n"); + buf.append(" int temp = parameters.length + j;\n"); + buf.append(" int /*]*/temp1/*[*/ = temp;\n"); + buf.append(" System.out.println(temp);\n"); + buf.append(" }\n"); + buf.append("}\n"); + + ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null); + assertCodeActionNotExists(cu, INLINE_LOCAL_VARIABLE); + } }