mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+38
-2
@@ -345,6 +345,17 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitParameter(PsiParameter parameter) {
|
||||
super.visitParameter(parameter);
|
||||
final PsiElement declarationScope = parameter.getDeclarationScope();
|
||||
for (PsiVariable variable : outputVariables) {
|
||||
if (Comparing.strEqual(variable.getName(), parameter.getName())) {
|
||||
replacementMap.put(parameter, myElementFactory.createStatementFromText(myInnerClassName + ".this." + var2FieldNames.get(variable.getName()) + " = " + parameter.getName() + ";", declarationScope));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitReferenceExpression(final PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
@@ -368,16 +379,37 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
Map<PsiStatement, PsiForeachStatement> blocksToReplace = new LinkedHashMap<>();
|
||||
for (PsiElement statement : replacementMap.keySet()) {
|
||||
final PsiElement replacement = replacementMap.get(statement);
|
||||
if (replacement != null) {
|
||||
if (statement instanceof PsiLocalVariable) {
|
||||
if (statement instanceof PsiParameter) {
|
||||
PsiCodeBlock codeBlock = null;
|
||||
final PsiElement declarationScope = ((PsiParameter)statement).getDeclarationScope();
|
||||
if (declarationScope instanceof PsiForeachStatement) {
|
||||
final PsiStatement loopBody = ((PsiForeachStatement)declarationScope).getBody();
|
||||
if (loopBody instanceof PsiBlockStatement) {
|
||||
codeBlock = ((PsiBlockStatement)loopBody).getCodeBlock();
|
||||
}
|
||||
else {
|
||||
blocksToReplace.put((PsiStatement)replacement, (PsiForeachStatement)declarationScope);
|
||||
}
|
||||
}
|
||||
else if (declarationScope instanceof PsiCatchSection){
|
||||
codeBlock = ((PsiCatchSection)declarationScope).getCatchBlock();
|
||||
}
|
||||
if (codeBlock != null) {
|
||||
codeBlock.addBefore(replacement, codeBlock.getFirstBodyElement());
|
||||
}
|
||||
}
|
||||
else if (statement instanceof PsiLocalVariable) {
|
||||
PsiLocalVariable variable = (PsiLocalVariable)statement;
|
||||
variable.normalizeDeclaration();
|
||||
PsiDeclarationStatement declaration = PsiTreeUtil.getParentOfType(statement, PsiDeclarationStatement.class);
|
||||
LOG.assertTrue(declaration != null);
|
||||
declaration.replace(replacement);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (statement instanceof PsiReturnStatement) {
|
||||
final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue();
|
||||
if (!(returnValue instanceof PsiReferenceExpression || returnValue == null || returnValue instanceof PsiLiteralExpression)) {
|
||||
@@ -392,6 +424,10 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiStatement statement : blocksToReplace.keySet()) {
|
||||
RefactoringUtil.putStatementInLoopBody(statement, blocksToReplace.get(statement), null);
|
||||
}
|
||||
|
||||
myChangeReturnType = true;
|
||||
}
|
||||
|
||||
|
||||
+10
-4
@@ -333,7 +333,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
public static List<PsiMethod> getEnclosingMethods(PsiMethod nearest) {
|
||||
public static List<PsiMethod> getEnclosingMethods(@NotNull PsiMethod nearest) {
|
||||
List<PsiMethod> enclosingMethods = new ArrayList<>();
|
||||
enclosingMethods.add(nearest);
|
||||
PsiMethod method = nearest;
|
||||
@@ -531,7 +531,11 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
|
||||
if (inplaceIntroducer instanceof InplaceIntroduceParameterPopup) {
|
||||
return false;
|
||||
}
|
||||
final List<PsiMethod> enclosingMethods = getEnclosingMethods(Util.getContainingMethod(elements[0]));
|
||||
final PsiMethod containingMethod = Util.getContainingMethod(elements[0]);
|
||||
if (containingMethod == null) {
|
||||
return false;
|
||||
}
|
||||
final List<PsiMethod> enclosingMethods = getEnclosingMethods(containingMethod);
|
||||
if (enclosingMethods.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -550,7 +554,9 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
|
||||
? new PsiElement[]{exprInRange}
|
||||
: CodeInsightUtil.findStatementsInRange(copy, range.getStartOffset(), range.getEndOffset());
|
||||
}
|
||||
final List<PsiMethod> enclosingMethodsInCopy = getEnclosingMethods(Util.getContainingMethod(elementsCopy[0]));
|
||||
final PsiMethod containingMethodCopy = Util.getContainingMethod(elementsCopy[0]);
|
||||
LOG.assertTrue(containingMethodCopy != null);
|
||||
final List<PsiMethod> enclosingMethodsInCopy = getEnclosingMethods(containingMethodCopy);
|
||||
final MyExtractMethodProcessor processor = new MyExtractMethodProcessor(project, editor, elementsCopy,
|
||||
enclosingMethodsInCopy.get(enclosingMethodsInCopy.size() - 1));
|
||||
try {
|
||||
@@ -702,7 +708,7 @@ public class IntroduceParameterHandler extends IntroduceHandlerBase {
|
||||
private static class MyExtractMethodProcessor extends ExtractMethodProcessor {
|
||||
private final PsiMethod myTopEnclosingMethod;
|
||||
|
||||
public MyExtractMethodProcessor(Project project, Editor editor, PsiElement[] elements, PsiMethod topEnclosing) {
|
||||
public MyExtractMethodProcessor(Project project, Editor editor, PsiElement[] elements, @NotNull PsiMethod topEnclosing) {
|
||||
super(project, editor, elements, null, REFACTORING_NAME, null, null);
|
||||
myTopEnclosingMethod = topEnclosing;
|
||||
}
|
||||
|
||||
@@ -142,6 +142,16 @@ public class CreateTestAction extends PsiElementBaseIntentionAction {
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
if (computeSuitableTestRootUrls(productionModule).isEmpty()) {
|
||||
final HashSet<Module> modules = new HashSet<>();
|
||||
ModuleUtilCore.collectModulesDependsOn(productionModule, modules);
|
||||
modules.remove(productionModule);
|
||||
for (Module module : modules) {
|
||||
if (!computeSuitableTestRootUrls(module).isEmpty()) return module;
|
||||
}
|
||||
}
|
||||
|
||||
return productionModule;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user