mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
inline chained constructor from library class
This commit is contained in:
@@ -470,7 +470,6 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
GenericInlineHandler.inlineReference(usage, myMethod, myInliners);
|
||||
}
|
||||
}
|
||||
myMethod.delete();
|
||||
}
|
||||
else {
|
||||
List<PsiReferenceExpression> refExprList = new ArrayList<>();
|
||||
@@ -513,8 +512,8 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
psiElement.delete();
|
||||
}
|
||||
}
|
||||
if (myMethod.isWritable()) myMethod.delete();
|
||||
}
|
||||
if (myMethod.isWritable()) myMethod.delete();
|
||||
}
|
||||
removeAddedBracesWhenPossible();
|
||||
}
|
||||
@@ -544,8 +543,9 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
public static void inlineConstructorCall(PsiCall constructorCall) {
|
||||
final PsiMethod oldConstructor = constructorCall.resolveMethod();
|
||||
PsiMethod oldConstructor = constructorCall.resolveMethod();
|
||||
LOG.assertTrue(oldConstructor != null);
|
||||
oldConstructor = (PsiMethod)oldConstructor.getNavigationElement();
|
||||
PsiExpression[] instanceCreationArguments = constructorCall.getArgumentList().getExpressions();
|
||||
if (oldConstructor.isVarArgs()) { //wrap with explicit array
|
||||
final PsiParameter[] parameters = oldConstructor.getParameterList().getParameters();
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import java.io.FileInputStream;
|
||||
|
||||
class Launcher<T> {
|
||||
{
|
||||
try {
|
||||
FileInputStream f = new File<caret>InputStream("");
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
class Launcher<T> {
|
||||
{
|
||||
try {
|
||||
FileInputStream f = new FileInputStream("" != null ? new File("") : null);
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,7 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.LightRefactoringTestCase;
|
||||
import com.intellij.refactoring.MockInlineMethodOptions;
|
||||
@@ -348,6 +345,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRespectProjectScopeSrcConstructorCall() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return getTestName(false).contains("Src") ? IdeaTestUtil.getMockJdk17() : super.getProjectJDK();
|
||||
@@ -385,6 +386,12 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
PsiElement element = TargetElementUtil
|
||||
.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
|
||||
final PsiReference ref = myFile.findReferenceAt(myEditor.getCaretModel().getOffset());
|
||||
if (ref instanceof PsiJavaCodeReferenceElement) {
|
||||
final PsiElement parent = ((PsiJavaCodeReferenceElement)ref).getParent();
|
||||
if (parent instanceof PsiNewExpression) {
|
||||
element = ((PsiNewExpression)parent).resolveConstructor();
|
||||
}
|
||||
}
|
||||
PsiReferenceExpression refExpr = ref instanceof PsiReferenceExpression ? (PsiReferenceExpression)ref : null;
|
||||
assertTrue(element instanceof PsiMethod);
|
||||
PsiMethod method = (PsiMethod)element.getNavigationElement();
|
||||
|
||||
Reference in New Issue
Block a user