mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Groovy: don't use type.getCanonicalText() to infer type qualified name since it can lead to inferring of type parameters and wasting time
This commit is contained in:
+6
-4
@@ -108,10 +108,12 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImpl<GrExpressi
|
||||
|
||||
if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP)) return false;
|
||||
|
||||
final String canonicalText = type.getCanonicalText();
|
||||
if (canonicalText.startsWith("java.")) return true;
|
||||
if (GroovyCommonClassNames.GROOVY_UTIL_CONFIG_OBJECT.equals(canonicalText)) return false;
|
||||
if (canonicalText.startsWith("groovy.")) return true;
|
||||
final String qname = TypesUtil.getQualifiedName(type);
|
||||
if (qname != null) {
|
||||
if (qname.startsWith("java.")) return true; //so we have jdk map here
|
||||
if (GroovyCommonClassNames.GROOVY_UTIL_CONFIG_OBJECT.equals(qname)) return false;
|
||||
if (qname.startsWith("groovy.")) return true; //we have gdk map here
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
+22
-10
@@ -422,7 +422,7 @@ public class TypesUtil {
|
||||
|
||||
public static boolean isNumericType(@Nullable PsiType type) {
|
||||
if (type instanceof PsiClassType) {
|
||||
return TYPE_TO_RANK.contains(type.getCanonicalText());
|
||||
return TYPE_TO_RANK.contains(getQualifiedName(type));
|
||||
}
|
||||
|
||||
return type instanceof PsiPrimitiveType && TypeConversionUtil.isNumericType(type);
|
||||
@@ -547,12 +547,12 @@ public class TypesUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(type1.getCanonicalText()) &&
|
||||
CommonClassNames.JAVA_LANG_STRING.equals(type2.getInternalCanonicalText())) {
|
||||
else if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(getQualifiedName(type1)) &&
|
||||
CommonClassNames.JAVA_LANG_STRING.equals(getQualifiedName(type2))) {
|
||||
return type2;
|
||||
}
|
||||
else if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(type2.getCanonicalText()) &&
|
||||
CommonClassNames.JAVA_LANG_STRING.equals(type1.getInternalCanonicalText())) {
|
||||
else if (GroovyCommonClassNames.GROOVY_LANG_GSTRING.equals(getQualifiedName(type2)) &&
|
||||
CommonClassNames.JAVA_LANG_STRING.equals(getQualifiedName(type1))) {
|
||||
return type1;
|
||||
}
|
||||
return GenericsUtil.getLeastUpperBound(type1, type2, manager);
|
||||
@@ -628,11 +628,7 @@ public class TypesUtil {
|
||||
}
|
||||
|
||||
public static boolean isClassType(@Nullable PsiType type, @NotNull String qName) {
|
||||
if (type instanceof PsiClassType) {
|
||||
final PsiClass psiClass = ((PsiClassType)type).resolve();
|
||||
return psiClass != null && qName.equals(psiClass.getQualifiedName());
|
||||
}
|
||||
return false;
|
||||
return qName.equals(getQualifiedName(type));
|
||||
}
|
||||
|
||||
public static PsiSubstitutor composeSubstitutors(PsiSubstitutor s1, PsiSubstitutor s2) {
|
||||
@@ -859,4 +855,20 @@ public class TypesUtil {
|
||||
|
||||
return GroovyCommonClassNames.GROOVY_LANG_CLOSURE.equals(psiClass.getQualifiedName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getQualifiedName(@Nullable PsiType type) {
|
||||
if (type instanceof PsiClassType) {
|
||||
PsiClass resolved = ((PsiClassType)type).resolve();
|
||||
if (resolved instanceof PsiAnonymousClass) {
|
||||
return getQualifiedName(((PsiAnonymousClass)resolved).getBaseClassType());
|
||||
}
|
||||
if (resolved != null) {
|
||||
return resolved.getQualifiedName();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-5
@@ -374,8 +374,11 @@ public class ResolveUtil {
|
||||
else if (base instanceof GrTraitType) {
|
||||
key = ((GrTraitType)base).erasure().getCanonicalText();
|
||||
}
|
||||
else if (base instanceof PsiClassType) {
|
||||
key = TypesUtil.getQualifiedName(base);
|
||||
}
|
||||
else {
|
||||
key = TypeConversionUtil.erasure(base).getCanonicalText();
|
||||
key = base.getCanonicalText();
|
||||
}
|
||||
Map<String, PsiType> result = cache.get(key);
|
||||
if (result == null) {
|
||||
@@ -388,10 +391,13 @@ public class ResolveUtil {
|
||||
|
||||
@NotNull
|
||||
private static String rawCanonicalText(@NotNull PsiType type) {
|
||||
final String result = type.getCanonicalText();
|
||||
final int i = result.indexOf('<');
|
||||
if (i > 0) return result.substring(0, i);
|
||||
return result;
|
||||
if (type instanceof PsiClassType) {
|
||||
String qname = TypesUtil.getQualifiedName(type);
|
||||
if (qname != null) {
|
||||
return qname;
|
||||
}
|
||||
}
|
||||
return TypeConversionUtil.erasure(type).getCanonicalText();
|
||||
}
|
||||
|
||||
public static GroovyPsiElement resolveProperty(GroovyPsiElement place, String name) {
|
||||
|
||||
+2
@@ -31,10 +31,12 @@ class GrAssignabilityTest extends GrHighlightingTestBase {
|
||||
public void testIncompatibleTypesAssignments() { doTest(); }
|
||||
|
||||
public void testDefaultMapConstructorNamedArgs() {
|
||||
addBigDecimal()
|
||||
doTest(new GroovyConstructorNamedArgumentsInspection());
|
||||
}
|
||||
|
||||
public void testDefaultMapConstructorNamedArgsError() {
|
||||
addBigDecimal()
|
||||
doTest(new GroovyConstructorNamedArgumentsInspection());
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -161,7 +161,10 @@ public final class Matcher {
|
||||
|
||||
void testArrayAccess() { doTest() }
|
||||
|
||||
void testCastWithEquality() { doTest() }
|
||||
void testCastWithEquality() {
|
||||
addBigDecimal()
|
||||
doTest()
|
||||
}
|
||||
|
||||
void testAsserts() { doTest() }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user