diff --git a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java index ab77b8bf82af..b8fb07f71bd6 100644 --- a/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/inline/InlineMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -221,7 +221,10 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor { @Override public void inlineUsage(UsageInfo usage, PsiElement referenced) { - throw new UnsupportedOperationException("Don't invoke this method!"); + if (usage instanceof NonCodeUsageInfo) return; + + throw new UnsupportedOperationException( + "usage: " + usage.getClass().getName() + ", referenced: " + referenced.getClass().getName() + "text: " + referenced.getText()); } }); diff --git a/java/java-tests/testData/refactoring/inlineMethod/NonCodeUsage.java b/java/java-tests/testData/refactoring/inlineMethod/NonCodeUsage.java new file mode 100644 index 000000000000..7116b8984da7 --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/NonCodeUsage.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class Test { + private int bar() { + System.out.println(42); + } + + //noncode bar usage + public void foo() { + bar(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/inlineMethod/NonCodeUsage.java.after b/java/java-tests/testData/refactoring/inlineMethod/NonCodeUsage.java.after new file mode 100644 index 000000000000..3bb97a21206f --- /dev/null +++ b/java/java-tests/testData/refactoring/inlineMethod/NonCodeUsage.java.after @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class Test { + + //noncode bar usage + public void foo() { + System.out.println(42); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java index 59f27ab992f3..98a2685d5575 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/inline/InlineMethodTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.refactoring.inline; import com.intellij.JavaTestUtil; @@ -233,6 +248,10 @@ public class InlineMethodTest extends LightRefactoringTestCase { doTestInlineThisOnly(); } + public void testNonCodeUsage() throws Exception { + doTest(true); + } + private void doTestInlineThisOnly() { @NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java"; configureByFile(fileName); @@ -241,23 +260,27 @@ public class InlineMethodTest extends LightRefactoringTestCase { public boolean isInlineThisOnly() { return true; } - }); + }, false); checkResultByFile(fileName + ".after"); } private void doTest() throws Exception { + doTest(false); + } + + private void doTest(final boolean nonCode) throws Exception { String name = getTestName(false); @NonNls String fileName = "/refactoring/inlineMethod/" + name + ".java"; configureByFile(fileName); - performAction(); + performAction(nonCode); checkResultByFile(fileName + ".after"); } - private void performAction() { - performAction(new MockInlineMethodOptions()); + private void performAction(final boolean nonCode) { + performAction(new MockInlineMethodOptions(), nonCode); } - private void performAction(final InlineOptions options) { + private void performAction(final InlineOptions options, final boolean nonCode) { PsiElement element = TargetElementUtilBase .findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED); final PsiReference ref = myFile.findReferenceAt(myEditor.getCaretModel().getOffset()); @@ -266,7 +289,8 @@ public class InlineMethodTest extends LightRefactoringTestCase { PsiMethod method = (PsiMethod)element; final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method); assertFalse("Bad returns found", condition); - final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, refExpr, myEditor, options.isInlineThisOnly()); + final InlineMethodProcessor processor = + new InlineMethodProcessor(getProject(), method, refExpr, myEditor, options.isInlineThisOnly(), nonCode, nonCode); processor.run(); } }