mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
create method from usage optimization: limit number of created parameters to 255 as otherwise it won't compile; for 20+ parameters stop shorting refs and reformat (IDEA-149623)
This commit is contained in:
+7
-4
@@ -237,6 +237,7 @@ public class CreateFromUsageUtils {
|
||||
throws IncorrectOperationException {
|
||||
PsiManager psiManager = method.getManager();
|
||||
JVMElementFactory factory = JVMElementFactories.getFactory(method.getLanguage(), method.getProject());
|
||||
if (factory == null) return;
|
||||
|
||||
PsiParameterList parameterList = method.getParameterList();
|
||||
|
||||
@@ -244,9 +245,11 @@ public class CreateFromUsageUtils {
|
||||
|
||||
GuessTypeParameters guesser = new GuessTypeParameters(JavaPsiFacade.getElementFactory(method.getProject()));
|
||||
|
||||
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(psiManager);
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
final boolean isInterface = containingClass != null && containingClass.isInterface();
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
//255 is the maximum number of method parameters
|
||||
for (int i = 0; i < Math.min(arguments.size(), 255); i++) {
|
||||
Pair<PsiExpression, PsiType> arg = arguments.get(i);
|
||||
PsiExpression exp = arg.first;
|
||||
|
||||
@@ -268,11 +271,11 @@ public class CreateFromUsageUtils {
|
||||
}
|
||||
PsiParameter parameter;
|
||||
if (parameterList.getParametersCount() <= i) {
|
||||
parameter = factory.createParameter(names[0], argType);
|
||||
PsiParameter param = factory.createParameter(names[0], argType);
|
||||
if (isInterface) {
|
||||
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, false);
|
||||
PsiUtil.setModifierProperty(param, PsiModifier.FINAL, false);
|
||||
}
|
||||
parameter = (PsiParameter) parameterList.add(parameter);
|
||||
parameter = codeStyleManager.performActionWithFormatterDisabled(() -> (PsiParameter) parameterList.add(param));
|
||||
} else {
|
||||
parameter = parameterList.getParameters()[i];
|
||||
}
|
||||
|
||||
+4
@@ -249,6 +249,10 @@ public class CreateMethodFromUsageFix extends CreateFromUsageBaseFix {
|
||||
final Editor newEditor = positionCursor(project, targetFile, method);
|
||||
if (newEditor == null) return;
|
||||
Template template = builder.buildTemplate();
|
||||
if (arguments.size() > 20) {
|
||||
template.setToShortenLongNames(false);
|
||||
template.setToReformat(false);
|
||||
}
|
||||
newEditor.getCaretModel().moveToOffset(rangeMarker.getStartOffset());
|
||||
newEditor.getDocument().deleteString(rangeMarker.getStartOffset(), rangeMarker.getEndOffset());
|
||||
rangeMarker.dispose();
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.SkipSlowTestLocally;
|
||||
|
||||
@SkipSlowTestLocally
|
||||
public class CreateMethodFromUsagePerformanceTest extends LightQuickFixTestCase {
|
||||
|
||||
public void testWithHugeNumberOfParameters() {
|
||||
PlatformTestUtil.startPerformanceTest("100 args for a new method", 200000, () -> {
|
||||
configureFromFileText("Foo.java", "class Foo {{ f<caret>oo(" + StringUtil.repeat("\"a\", ", 5000) + " \"a\");}}");
|
||||
doAction("Create method 'foo'");
|
||||
})
|
||||
.useLegacyScaling()
|
||||
.assertTiming();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user