mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cache expected names (IDEA-116085)
This commit is contained in:
@@ -17,10 +17,13 @@
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.openapi.util.NullableComputable;
|
||||
import com.intellij.openapi.util.NullableLazyValue;
|
||||
import com.intellij.openapi.util.VolatileNullableLazyValue;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ExpectedTypeInfoImpl implements ExpectedTypeInfo {
|
||||
public static final NullableComputable<String> NULL = new NullableComputable<String>() {
|
||||
@@ -37,7 +40,8 @@ public class ExpectedTypeInfoImpl implements ExpectedTypeInfo {
|
||||
@NotNull
|
||||
private final TailType myTailType;
|
||||
private final PsiMethod myCalledMethod;
|
||||
@NotNull private final NullableComputable<String> expectedName;
|
||||
@NotNull private final NullableComputable<String> expectedNameComputable;
|
||||
@NotNull private final NullableLazyValue<String> expectedNameLazyValue;
|
||||
|
||||
@Override
|
||||
public int getKind() {
|
||||
@@ -62,15 +66,22 @@ public class ExpectedTypeInfoImpl implements ExpectedTypeInfo {
|
||||
this.myTailType = myTailType;
|
||||
this.defaultType = defaultType;
|
||||
myCalledMethod = calledMethod;
|
||||
this.expectedName = expectedName;
|
||||
this.expectedNameComputable = expectedName;
|
||||
expectedNameLazyValue = new VolatileNullableLazyValue<String>() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected String compute() {
|
||||
return expectedNameComputable.compute();
|
||||
}
|
||||
};
|
||||
|
||||
PsiUtil.ensureValidType(type);
|
||||
PsiUtil.ensureValidType(defaultType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NullableComputable<String> getExpectedName() {
|
||||
return expectedName;
|
||||
@Nullable
|
||||
public String getExpectedName() {
|
||||
return expectedNameLazyValue.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -630,9 +630,15 @@ public class ExpectedTypesProvider {
|
||||
myResult = visitor.getResult();
|
||||
if (!(expr.getParent() instanceof PsiExpressionList)) {
|
||||
for (int i = 0; i < myResult.length; i++) {
|
||||
ExpectedTypeInfo info = myResult[i];
|
||||
final ExpectedTypeInfo info = myResult[i];
|
||||
myResult[i] = createInfoImpl(info.getType(), info.getKind(), info.getDefaultType(), TailType.NONE, info.getCalledMethod(),
|
||||
((ExpectedTypeInfoImpl)info).getExpectedName());
|
||||
new NullableComputable<String>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public String compute() {
|
||||
return ((ExpectedTypeInfoImpl)info).getExpectedName();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -870,9 +876,15 @@ public class ExpectedTypesProvider {
|
||||
else if (myExpr.equals(expr.getThenExpression())) {
|
||||
ExpectedTypeInfo[] types = getExpectedTypes(expr, myForCompletion);
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
ExpectedTypeInfo info = types[i];
|
||||
final ExpectedTypeInfo info = types[i];
|
||||
types[i] = createInfoImpl(info.getType(), info.getKind(), info.getDefaultType(), TailType.COND_EXPR_COLON, info.getCalledMethod(),
|
||||
((ExpectedTypeInfoImpl)info).getExpectedName());
|
||||
new NullableComputable<String>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public String compute() {
|
||||
return ((ExpectedTypeInfoImpl)info).getExpectedName();
|
||||
}
|
||||
});
|
||||
}
|
||||
myResult = types;
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ public class JavaCompletionSorting {
|
||||
|
||||
private static int calcMatch(final List<String> words, int max, ExpectedTypeInfo[] myExpectedInfos) {
|
||||
for (ExpectedTypeInfo myExpectedInfo : myExpectedInfos) {
|
||||
String expectedName = ((ExpectedTypeInfoImpl)myExpectedInfo).getExpectedName().compute();
|
||||
String expectedName = ((ExpectedTypeInfoImpl)myExpectedInfo).getExpectedName();
|
||||
if (expectedName == null) continue;
|
||||
max = calcMatch(expectedName, words, max);
|
||||
max = calcMatch(truncDigits(expectedName), words, max);
|
||||
@@ -504,7 +504,7 @@ public class JavaCompletionSorting {
|
||||
int max = 0;
|
||||
final List<String> wordsNoDigits = NameUtil.nameToWordsLowerCase(truncDigits(name));
|
||||
for (ExpectedTypeInfo myExpectedInfo : myExpectedTypes) {
|
||||
String expectedName = ((ExpectedTypeInfoImpl)myExpectedInfo).getExpectedName().compute();
|
||||
String expectedName = ((ExpectedTypeInfoImpl)myExpectedInfo).getExpectedName();
|
||||
if (expectedName != null) {
|
||||
final THashSet<String> set = new THashSet<String>(NameUtil.nameToWordsLowerCase(truncDigits(expectedName)));
|
||||
set.retainAll(wordsNoDigits);
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class JavaCompletionStatistician extends CompletionStatistician{
|
||||
|
||||
PsiClass containingClass = ((PsiMember)o).getContainingClass();
|
||||
if (containingClass != null) {
|
||||
String expectedName = firstInfo instanceof ExpectedTypeInfoImpl ? ((ExpectedTypeInfoImpl)firstInfo).getExpectedName().compute() : null;
|
||||
String expectedName = firstInfo instanceof ExpectedTypeInfoImpl ? ((ExpectedTypeInfoImpl)firstInfo).getExpectedName() : null;
|
||||
String contextPrefix = expectedName == null ? "" : "expectedName=" + expectedName + "###";
|
||||
String context = contextPrefix + JavaStatisticsManager.getMemberUseKey2(containingClass);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user