IDEA-96839 Inline static method refactoring throws UnsupportedOperationException

This commit is contained in:
Max Medvedev
2012-12-11 13:33:37 +04:00
parent 5d2c5ce873
commit dc2ce9522d
4 changed files with 84 additions and 8 deletions
@@ -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());
}
});
@@ -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() {
ba<caret>r();
}
}
@@ -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);
}
}
@@ -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();
}
}