Permalink
Browse files

Got rid of code depending on Unit aliasing.

  • Loading branch information...
Evgeny Gerashchenko Evgeny Gerashchenko
Evgeny Gerashchenko authored and Evgeny Gerashchenko committed Mar 19, 2013
1 parent 66e7a01 commit f181907b9cbee74327f7970cc51de62bb4ca6174
@@ -95,11 +95,6 @@ public JetType visitUserType(JetUserType type, Void data) {
String shortName = type.getReferenceExpression().getReferencedName();
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);
}
@@ -397,7 +397,7 @@ public static boolean isVoidType(@Nullable JetTypeReference typeReference) {
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) {
@@ -641,7 +641,7 @@ public JetTypeInfo visitUnaryExpression(JetUnaryExpression expression, Expressio
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
assert returnType != null : "returnType is null for " + resolutionResults.getResultingDescriptor();
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));
}
else {
@@ -55,7 +55,6 @@
import static org.jetbrains.jet.lang.types.lang.PrimitiveType.*;
public class KotlinBuiltIns {
- public static final Name UNIT_ALIAS = Name.identifier("Unit");
public static final JetScope STUB = JetScope.EMPTY;
public static final String BUILT_INS_DIR = "jet";
@@ -203,7 +203,7 @@ private String renderTypeWithoutEscape(@NotNull JetType type) {
return type.toString();
}
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)) {
return renderFunctionType(type);
@@ -5,7 +5,7 @@
import org.jetbrains.jet.jvm.compiler.annotation.ExpectLoadError;
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")
public String foo(String a) {
throw new UnsupportedOperationException();
@@ -24,7 +24,6 @@
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
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.quickfix.ImportInsertHelper;
@@ -82,10 +81,6 @@ else if (classifier == null) {
}
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();
DeclarationDescriptor parent = targetClass.getContainingDeclaration();
while (parent instanceof ClassDescriptor) {
@@ -38,7 +38,6 @@
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
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.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
@@ -56,8 +55,6 @@
public class BuiltInsReferenceResolver extends AbstractProjectComponent {
private BindingContext bindingContext = null;
- private final FqName TUPLE0_FQ_NAME = DescriptorUtils.getFQName(KotlinBuiltIns.getInstance().getUnit()).toSafe();
-
public BuiltInsReferenceResolver(
Project project,
// This parameter is needed to initialize built-ins before this component
@@ -88,25 +85,8 @@ private void initialize() {
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
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,
- getJetFiles("jet", jetFilesIndependentOfUnit));
-
- 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)));
+ getJetFiles("jet", Predicates.<JetFile>alwaysTrue()));
bindingContext = context.getBindingContext();
}
@@ -165,8 +145,7 @@ private DeclarationDescriptor findCurrentDescriptorForMember(@NotNull MemberDesc
descriptors = memberScope.getAllDescriptors();
}
for (DeclarationDescriptor member : descriptors) {
- if (renderedOriginal.equals(DescriptorRenderer.TEXT.render(member).replace(TUPLE0_FQ_NAME.getFqName(),
- KotlinBuiltIns.UNIT_ALIAS.getName()))) {
+ if (renderedOriginal.equals(DescriptorRenderer.TEXT.render(member))) {
return member;
}
}
@@ -59,7 +59,7 @@ public Type visitPrimitiveType(@NotNull PsiPrimitiveType primitiveType) {
IdentifierImpl identifier = new IdentifierImpl(name);
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)) {
myResult = new PrimitiveType(new IdentifierImpl(AstUtil.upperFirstCharacter(name)));

0 comments on commit f181907

Please sign in to comment.