Got rid of code depending on Unit aliasing.

This commit is contained in:
Evgeny Gerashchenko
2013-03-19 16:47:47 +04:00
parent 66e7a0110c
commit f181907b9c
9 changed files with 7 additions and 39 deletions
@@ -95,11 +95,6 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
String shortName = type.getReferenceExpression().getReferencedName(); String shortName = type.getReferenceExpression().getReferencedName();
String longName = (qualifier == null ? "" : qualifier.getText() + ".") + shortName; String longName = (qualifier == null ? "" : qualifier.getText() + ".") + shortName;
// TODO remove this code when Unit will be not a synonym for Tuple0
if (KotlinBuiltIns.UNIT_ALIAS.getName().equals(longName)) {
return visitCommonType(KotlinBuiltIns.getInstance().getUnit(), type);
}
return visitCommonType(longName, type); return visitCommonType(longName, type);
} }
@@ -397,7 +397,7 @@ public class JetPsiUtil {
return false; return false;
} }
return KotlinBuiltIns.UNIT_ALIAS.getName().equals(typeReference.getText()); return KotlinBuiltIns.getInstance().getUnit().getName().getName().equals(typeReference.getText());
} }
public static boolean isSafeCall(@NotNull Call call) { public static boolean isSafeCall(@NotNull Call call) {
@@ -641,7 +641,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) { if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
assert returnType != null : "returnType is null for " + resolutionResults.getResultingDescriptor(); assert returnType != null : "returnType is null for " + resolutionResults.getResultingDescriptor();
if (JetTypeChecker.INSTANCE.isSubtypeOf(returnType, KotlinBuiltIns.getInstance().getUnitType())) { if (JetTypeChecker.INSTANCE.isSubtypeOf(returnType, KotlinBuiltIns.getInstance().getUnitType())) {
result = ErrorUtils.createErrorType(KotlinBuiltIns.UNIT_ALIAS.getName()); result = ErrorUtils.createErrorType(KotlinBuiltIns.getInstance().getUnit().getName().getName());
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign)); context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
} }
else { else {
@@ -55,7 +55,6 @@ import java.util.*;
import static org.jetbrains.jet.lang.types.lang.PrimitiveType.*; import static org.jetbrains.jet.lang.types.lang.PrimitiveType.*;
public class KotlinBuiltIns { public class KotlinBuiltIns {
public static final Name UNIT_ALIAS = Name.identifier("Unit");
public static final JetScope STUB = JetScope.EMPTY; public static final JetScope STUB = JetScope.EMPTY;
public static final String BUILT_INS_DIR = "jet"; public static final String BUILT_INS_DIR = "jet";
@@ -203,7 +203,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
return type.toString(); return type.toString();
} }
if (KotlinBuiltIns.getInstance().isUnit(type)) { if (KotlinBuiltIns.getInstance().isUnit(type)) {
return KotlinBuiltIns.UNIT_ALIAS + (type.isNullable() ? "?" : ""); return "Unit" + (type.isNullable() ? "?" : ""); // TODO temp code to avoid failing of 100500 tests
} }
if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type)) { if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type)) {
return renderFunctionType(type); return renderFunctionType(type);
@@ -5,7 +5,7 @@ import jet.runtime.typeinfo.KotlinSignature;
import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError; import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError;
public class WrongTypeName1 { public class WrongTypeName1 {
@ExpectLoadError("Alternative signature type mismatch, expected: jet.Tuple0, actual: jet.String") @ExpectLoadError("Alternative signature type mismatch, expected: Unit, actual: jet.String")
@KotlinSignature("fun foo(a : String) : Unit") @KotlinSignature("fun foo(a : String) : Unit")
public String foo(String a) { public String foo(String a) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade; import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper; import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper;
@@ -82,10 +81,6 @@ public class ReferenceToClassesShortening {
} }
private void compactReferenceToClass(JetUserType userType, ClassDescriptor targetClass) { private void compactReferenceToClass(JetUserType userType, ClassDescriptor targetClass) {
if (targetClass == KotlinBuiltIns.getInstance().getUnitType().getConstructor().getDeclarationDescriptor()) {
// do not replace "Unit" with "Tuple0"
return;
}
String name = targetClass.getName().getName(); String name = targetClass.getName().getName();
DeclarationDescriptor parent = targetClass.getContainingDeclaration(); DeclarationDescriptor parent = targetClass.getContainingDeclaration();
while (parent instanceof ClassDescriptor) { while (parent instanceof ClassDescriptor) {
@@ -38,7 +38,6 @@ import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorImpl;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetReferenceExpression; import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler; import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
@@ -56,8 +55,6 @@ import java.util.List;
public class BuiltInsReferenceResolver extends AbstractProjectComponent { public class BuiltInsReferenceResolver extends AbstractProjectComponent {
private BindingContext bindingContext = null; private BindingContext bindingContext = null;
private final FqName TUPLE0_FQ_NAME = DescriptorUtils.getFQName(KotlinBuiltIns.getInstance().getUnit()).toSafe();
public BuiltInsReferenceResolver( public BuiltInsReferenceResolver(
Project project, Project project,
// This parameter is needed to initialize built-ins before this component // This parameter is needed to initialize built-ins before this component
@@ -88,25 +85,8 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
scope.changeLockLevel(WritableScope.LockLevel.BOTH); scope.changeLockLevel(WritableScope.LockLevel.BOTH);
jetNamespace.setMemberScope(scope); jetNamespace.setMemberScope(scope);
Predicate<JetFile> jetFilesIndependentOfUnit = new Predicate<JetFile>() {
@Override
public boolean apply(@Nullable JetFile file) {
return "Unit.jet".equals(file.getName());
}
};
TopDownAnalyzer.processStandardLibraryNamespace(myProject, context, scope, jetNamespace, TopDownAnalyzer.processStandardLibraryNamespace(myProject, context, scope, jetNamespace,
getJetFiles("jet", jetFilesIndependentOfUnit)); getJetFiles("jet", Predicates.<JetFile>alwaysTrue()));
ClassDescriptor tuple0 = context.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, TUPLE0_FQ_NAME);
assert tuple0 != null : "Can't find the declaration for Tuple0. Please invoke File -> Invalidate Caches...";
scope = new WritableScopeImpl(scope, jetNamespace, RedeclarationHandler.THROW_EXCEPTION,
"Builtin classes scope: needed to analyze builtins which depend on Unit type alias");
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
scope.addClassifierAlias(KotlinBuiltIns.UNIT_ALIAS, tuple0);
jetNamespace.setMemberScope(scope);
TopDownAnalyzer.processStandardLibraryNamespace(myProject, context, scope, jetNamespace,
getJetFiles("jet", Predicates.not(jetFilesIndependentOfUnit)));
bindingContext = context.getBindingContext(); bindingContext = context.getBindingContext();
} }
@@ -165,8 +145,7 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
descriptors = memberScope.getAllDescriptors(); descriptors = memberScope.getAllDescriptors();
} }
for (DeclarationDescriptor member : descriptors) { for (DeclarationDescriptor member : descriptors) {
if (renderedOriginal.equals(DescriptorRenderer.TEXT.render(member).replace(TUPLE0_FQ_NAME.getFqName(), if (renderedOriginal.equals(DescriptorRenderer.TEXT.render(member))) {
KotlinBuiltIns.UNIT_ALIAS.getName()))) {
return member; return member;
} }
} }
@@ -59,7 +59,7 @@ public class TypeVisitor extends PsiTypeVisitor<Type> implements J2KVisitor {
IdentifierImpl identifier = new IdentifierImpl(name); IdentifierImpl identifier = new IdentifierImpl(name);
if (name.equals("void")) { if (name.equals("void")) {
myResult = new PrimitiveType(new IdentifierImpl(KotlinBuiltIns.UNIT_ALIAS.getName())); myResult = new PrimitiveType(new IdentifierImpl(KotlinBuiltIns.getInstance().getUnit().getName().getName()));
} }
else if (Node.PRIMITIVE_TYPES.contains(name)) { else if (Node.PRIMITIVE_TYPES.contains(name)) {
myResult = new PrimitiveType(new IdentifierImpl(AstUtil.upperFirstCharacter(name))); myResult = new PrimitiveType(new IdentifierImpl(AstUtil.upperFirstCharacter(name)));