mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
enable shortening of FQNs in Create Field templates
Add ability to revert to previous behaviour with the Registry key.
This commit is contained in:
+11
-3
@@ -22,6 +22,7 @@ import com.intellij.codeInsight.template.Template;
|
||||
import com.intellij.codeInsight.template.TemplateBuilderImpl;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.introduceField.BaseExpressionToFieldHandler;
|
||||
@@ -64,14 +65,21 @@ public class JavaCreateFieldFromUsageHelper extends CreateFieldFromUsageHelper {
|
||||
|
||||
editor.getCaretModel().moveToOffset(field.getTextRange().getStartOffset());
|
||||
Template template = builder.buildInlineTemplate();
|
||||
if (ExpectedTypesProvider.processExpectedTypes((ExpectedTypeInfo[])expectedTypes, new PsiTypeVisitor<PsiType>() {
|
||||
if (disableShortenLongNames(project, ((ExpectedTypeInfo[])expectedTypes))) {
|
||||
template.setToShortenLongNames(false);
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
private static boolean disableShortenLongNames(Project project, ExpectedTypeInfo[] expectedTypes) {
|
||||
if (Registry.is("ide.create.field.enable.shortening")) return false;
|
||||
return ExpectedTypesProvider.processExpectedTypes(expectedTypes, new PsiTypeVisitor<PsiType>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiType visitType(PsiType type) {
|
||||
return type;
|
||||
}
|
||||
}, project).length > 1) template.setToShortenLongNames(false);
|
||||
return template;
|
||||
}, project).length > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1257,3 +1257,5 @@ duplicates.inspection.only.extractable.description=Highlight duplicate code only
|
||||
|
||||
ide.interlanguage.fixes=false
|
||||
ide.interlanguage.fixes.description=Enable 'Create Xxx from usage' fixes in JVM languages
|
||||
ide.create.field.enable.shortening=true
|
||||
ide.create.field.enable.shortening.description=Always enable shortening of FQNs in templates in Create Field fixes
|
||||
|
||||
+4
-1
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.template.TemplateBuilderImpl;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
|
||||
@@ -78,7 +79,9 @@ public class GroovyCreateFieldFromUsageHelper extends CreateFieldFromUsageHelper
|
||||
editor.getDocument().deleteString(range.getStartOffset(), range.getEndOffset());
|
||||
|
||||
if (expectedTypes instanceof ExpectedTypeInfo[]) {
|
||||
if (((ExpectedTypeInfo[])expectedTypes).length > 1) template.setToShortenLongNames(false);
|
||||
if (!Registry.is("ide.create.field.enable.shortening") && ((ExpectedTypeInfo[])expectedTypes).length > 1) {
|
||||
template.setToShortenLongNames(false);
|
||||
}
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user