From 598b328061d8124a54dac97b07d9b9a9a7e13212 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Wed, 1 Jan 2014 00:38:48 +0100 Subject: [PATCH] IDEA-116803 UI frozen after project open --- .../codeStyle/JavaCodeStyleManagerImpl.java | 37 ++++++++++++++----- .../psi/codeStyle/JavaCodeStyleManager.java | 4 ++ .../psi/impl/compiled/ClsParameterImpl.java | 7 ++-- .../testData/psi/cls/mirror/Bounds.txt | 4 +- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java index 3056eccd9291..d3e78b584859 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java @@ -208,6 +208,12 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager { return new ImportHelper(getSettings()).findEntryIndex(statement); } + @Override + public SuggestedNameInfo suggestSimpleParameterName(@NotNull PsiType type) { + return new SuggestedNameInfo(suggestVariableNameByType(type, VariableKind.PARAMETER, true, true)) { + }; + } + @Override public SuggestedNameInfo suggestVariableName(@NotNull final VariableKind kind, @Nullable final String propertyName, @@ -301,7 +307,11 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager { } private String[] suggestVariableNameByType(PsiType type, final VariableKind variableKind, boolean correctKeywords) { - String longTypeName = getLongTypeName(type); + return suggestVariableNameByType(type, variableKind, correctKeywords, false); + } + + private String[] suggestVariableNameByType(PsiType type, final VariableKind variableKind, boolean correctKeywords, boolean skipIndices) { + String longTypeName = skipIndices ? type.getCanonicalText():getLongTypeName(type); CodeStyleSettings.TypeToNameMap map = getMapByVariableKind(variableKind); if (map != null && longTypeName != null) { if (type.equals(PsiType.NULL)) { @@ -315,11 +325,15 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager { Collection suggestions = new LinkedHashSet(); - suggestNamesForCollectionInheritors(type, variableKind, suggestions, correctKeywords); - suggestNamesFromGenericParameters(type, variableKind, suggestions, correctKeywords); + if (!skipIndices) { + suggestNamesForCollectionInheritors(type, variableKind, suggestions, correctKeywords); + suggestNamesFromGenericParameters(type, variableKind, suggestions, correctKeywords); + } + + String typeName = getTypeName(type, !skipIndices); - String typeName = normalizeTypeName(getTypeName(type)); if (typeName != null) { + typeName = normalizeTypeName(typeName); ContainerUtil.addAll(suggestions, getSuggestionsByName(typeName, variableKind, type instanceof PsiArrayType, correctKeywords)); } @@ -376,11 +390,16 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager { @Nullable private static String getTypeName(PsiType type) { + return getTypeName(type, true); + } + + @Nullable + private static String getTypeName(PsiType type, boolean withIndices) { type = type.getDeepComponentType(); if (type instanceof PsiClassType) { final PsiClassType classType = (PsiClassType)type; final String className = classType.getClassName(); - if (className != null) return className; + if (className != null || !withIndices) return className; final PsiClass aClass = classType.resolve(); return aClass instanceof PsiAnonymousClass ? ((PsiAnonymousClass)aClass).getBaseClassType().getClassName() : null; } @@ -388,16 +407,16 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager { return type.getPresentableText(); } else if (type instanceof PsiWildcardType) { - return getTypeName(((PsiWildcardType)type).getExtendsBound()); + return getTypeName(((PsiWildcardType)type).getExtendsBound(), withIndices); } else if (type instanceof PsiIntersectionType) { - return getTypeName(((PsiIntersectionType)type).getRepresentative()); + return getTypeName(((PsiIntersectionType)type).getRepresentative(), withIndices); } else if (type instanceof PsiCapturedWildcardType) { - return getTypeName(((PsiCapturedWildcardType)type).getWildcard()); + return getTypeName(((PsiCapturedWildcardType)type).getWildcard(), withIndices); } else if (type instanceof PsiDisjunctionType) { - return getTypeName(((PsiDisjunctionType)type).getLeastUpperBound()); + return getTypeName(((PsiDisjunctionType)type).getLeastUpperBound(), withIndices); } else { return null; diff --git a/java/java-psi-api/src/com/intellij/psi/codeStyle/JavaCodeStyleManager.java b/java/java-psi-api/src/com/intellij/psi/codeStyle/JavaCodeStyleManager.java index 174438533371..869093dc21f9 100644 --- a/java/java-psi-api/src/com/intellij/psi/codeStyle/JavaCodeStyleManager.java +++ b/java/java-psi-api/src/com/intellij/psi/codeStyle/JavaCodeStyleManager.java @@ -122,6 +122,10 @@ public abstract class JavaCodeStyleManager { return suggestVariableName(kind, propertyName, expr, type, true); } + public SuggestedNameInfo suggestSimpleParameterName(@NotNull PsiType type) { + return suggestVariableName(VariableKind.PARAMETER, null, null, type, true); + } + public abstract SuggestedNameInfo suggestVariableName(@NotNull VariableKind kind, @Nullable String propertyName, diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java index a10343bfeb03..88cb85d23398 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsParameterImpl.java @@ -170,10 +170,11 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement } if (name == null) { - JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(getProject()); - String[] nameSuggestions = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, null, getType()).names; - name = "p"; + + // avoid hang due to nice name evaluation IDEA-116803 + JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(getProject()); + String[] nameSuggestions = codeStyleManager.suggestSimpleParameterName(getType()).names; if (nameSuggestions.length > 0 && nameSuggestions[0] != null) { name = nameSuggestions[0]; } diff --git a/java/java-tests/testData/psi/cls/mirror/Bounds.txt b/java/java-tests/testData/psi/cls/mirror/Bounds.txt index 0854f8511168..2350274b8a44 100644 --- a/java/java-tests/testData/psi/cls/mirror/Bounds.txt +++ b/java/java-tests/testData/psi/cls/mirror/Bounds.txt @@ -7,7 +7,7 @@ package pkg; class Bounds { Bounds() { /* compiled code */ } - public static > T max(java.util.Collection ts) { /* compiled code */ } + public static > T max(java.util.Collection collection) { /* compiled code */ } - public static T max(java.util.Collection ts, java.util.Comparator comparator) { /* compiled code */ } + public static T max(java.util.Collection collection, java.util.Comparator comparator) { /* compiled code */ } } \ No newline at end of file