map literals with 'super' key may be assigned to the classes with a non-default constructor

This commit is contained in:
peter
2010-07-23 11:08:58 +01:00
parent 84891eec84
commit 9f839c2d79
4 changed files with 22 additions and 1 deletions
@@ -66,6 +66,11 @@ public class GppTypeConverter extends GrTypeConverter {
(!TypesUtil.isAssignable(lKeyType, parameters[0], context) || !TypesUtil.isAssignable(lValueType, parameters[1], context))) {
return null;
}
if (((GrMapType)rType).getValueType("super") != null) {
return true;
}
if (hasDefaultConstructor(lType)) {
return true;
}
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiType;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -149,6 +150,11 @@ public class GrMapType extends GrLiteralClassType {
return super.equals(obj);
}
@Nullable
public PsiType getValueType(@NotNull String key) {
return myStringEntries.get(key);
}
public boolean isAssignableFrom(@NotNull PsiType type) {
return type instanceof GrMapType || myFacade.getElementFactory().createTypeFromText(getJavaClassName(), null).isAssignableFrom(type);
}
@@ -103,7 +103,7 @@ public class GrArgumentLabelImpl extends GroovyPsiElementImpl implements GrArgum
}
final IElementType elemType = element.getNode().getElementType();
if (GroovyTokenTypes.mIDENT == elemType) {
if (GroovyTokenTypes.mIDENT == elemType || GroovyTokenTypes.KEYWORDS.contains(elemType)) {
return element.getText();
}
@@ -375,6 +375,16 @@ s.do<caret>Smth()
assertEquals "doSmth", ((PsiMethod) findReference().resolve()).name
}
public void testBaseConstructorCallInMapLiteras() throws Exception {
configureScript """
@Typed File foo() { ['super':['a']] }
@Typed File goo() { <warning descr="Cannot assign 'Map' to 'File'">[:]</warning> }
File bar() { <warning descr="Cannot assign 'Map' to 'File'">[:]</warning> }
"""
myFixture.enableInspections new GroovyAssignabilityCheckInspection()
myFixture.checkHighlighting(true, false, false)
}
}
class GppProjectDescriptor extends DefaultLightProjectDescriptor {