mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
inline method: decode before class declaration become invalid
This commit is contained in:
@@ -493,19 +493,7 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
if (methodCall.getParent() instanceof PsiExpressionStatement || tailCall == InlineUtil.TailCallType.Return) {
|
||||
methodCall.getParent().delete();
|
||||
}
|
||||
else {
|
||||
if (blockData.resultVar != null) {
|
||||
PsiExpression expr = myFactory.createExpressionFromText(blockData.resultVar.getName(), null);
|
||||
methodCall.replace(expr);
|
||||
}
|
||||
else {
|
||||
//??
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PsiClass thisClass = myMethod.getContainingClass();
|
||||
PsiExpression thisAccessExpr;
|
||||
if (thisVar != null) {
|
||||
@@ -521,6 +509,19 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
ChangeContextUtil.decodeContextInfo(anchorParent, thisClass, thisAccessExpr);
|
||||
|
||||
if (methodCall.getParent() instanceof PsiExpressionStatement || tailCall == InlineUtil.TailCallType.Return) {
|
||||
methodCall.getParent().delete();
|
||||
}
|
||||
else {
|
||||
if (blockData.resultVar != null) {
|
||||
PsiExpression expr = myFactory.createExpressionFromText(blockData.resultVar.getName(), null);
|
||||
methodCall.replace(expr);
|
||||
}
|
||||
else {
|
||||
//??
|
||||
}
|
||||
}
|
||||
|
||||
if (thisVar != null) {
|
||||
inlineParmOrThisVariable(thisVar, false);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 void bar() {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public void foo() {
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
bar();
|
||||
}
|
||||
}.ru<caret>n();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 void bar() {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public void foo() {
|
||||
bar();
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,18 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
public void testInlineAnonymousClassWithPrivateMethodInside() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInlineRunnableRun() throws Exception {
|
||||
@NonNls String fileName = "/refactoring/inlineMethod/" + getTestName(false) + ".java";
|
||||
configureByFile(fileName);
|
||||
performAction(new MockInlineMethodOptions(){
|
||||
@Override
|
||||
public boolean isInlineThisOnly() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
checkResultByFile(fileName + ".after");
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
String name = getTestName(false);
|
||||
@@ -184,6 +196,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
private void performAction() {
|
||||
performAction(new MockInlineMethodOptions());
|
||||
}
|
||||
|
||||
private void performAction(final InlineOptions options) {
|
||||
PsiElement element = TargetElementUtilBase
|
||||
.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
|
||||
final PsiReference ref = myFile.findReferenceAt(myEditor.getCaretModel().getOffset());
|
||||
@@ -192,7 +208,6 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
final boolean condition = InlineMethodProcessor.checkBadReturns(method) && !InlineUtil.allUsagesAreTailCalls(method);
|
||||
assertFalse("Bad returns found", condition);
|
||||
InlineOptions options = new MockInlineMethodOptions();
|
||||
final InlineMethodProcessor processor = new InlineMethodProcessor(getProject(), method, refExpr, myEditor, options.isInlineThisOnly());
|
||||
processor.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user