diff --git a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java index 9b160e88e03..6a83ad4d7cb 100644 --- a/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java +++ b/compiler/android-tests/tests/org/jetbrains/jet/compiler/android/SpecialFiles.java @@ -122,6 +122,8 @@ public class SpecialFiles { excludedFiles.add("kt1779.kt"); // Bug KT-2202 - private fun tryToComputeNext() in AbstractIterator.kt excludedFiles.add("kt344.jet"); // Bug KT-2251 excludedFiles.add("kt529.kt"); // Bug + + excludedFiles.add("noClassObjectForJavaClass.kt"); } private SpecialFiles() { diff --git a/compiler/backend/src/org/jetbrains/jet/cli/jvm/compiler/TipsManager.java b/compiler/backend/src/org/jetbrains/jet/cli/jvm/compiler/TipsManager.java index 544133a19eb..1e6f4e894a2 100644 --- a/compiler/backend/src/org/jetbrains/jet/cli/jvm/compiler/TipsManager.java +++ b/compiler/backend/src/org/jetbrains/jet/cli/jvm/compiler/TipsManager.java @@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScopeUtils; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; +import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.NamespaceType; import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils; @@ -61,7 +62,7 @@ public final class TipsManager { JetScope resolutionScope = context.get(BindingContext.RESOLUTION_SCOPE, expression); JetType expressionType = context.get(BindingContext.EXPRESSION_TYPE, receiverExpression); - if (expressionType != null && resolutionScope != null) { + if (expressionType != null && resolutionScope != null && !ErrorUtils.isErrorType(expressionType)) { if (!(expressionType instanceof NamespaceType)) { ExpressionReceiver receiverDescriptor = new ExpressionReceiver(receiverExpression, expressionType); Set descriptors = new HashSet(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java new file mode 100644 index 00000000000..412fd4b21ee --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java @@ -0,0 +1,420 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.codegen; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; +import com.intellij.openapi.util.Pair; +import com.intellij.psi.tree.IElementType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.asm4.Label; +import org.jetbrains.asm4.MethodVisitor; +import org.jetbrains.asm4.Type; +import org.jetbrains.asm4.commons.InstructionAdapter; +import org.jetbrains.jet.codegen.binding.CalculatedClosure; +import org.jetbrains.jet.codegen.state.JetTypeMapper; +import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; +import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; +import org.jetbrains.jet.lang.resolve.java.JvmAbi; +import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; +import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; +import org.jetbrains.jet.lexer.JetTokens; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.CodegenUtil.isInterface; +import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject; +import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE; + +/** + * @author alex.tkachman + */ +public class AsmUtil { + private static final Set PRIMITIVE_NUMBER_CLASSES = Sets.newHashSet( + JetStandardLibrary.getInstance().getByte(), + JetStandardLibrary.getInstance().getShort(), + JetStandardLibrary.getInstance().getInt(), + JetStandardLibrary.getInstance().getLong(), + JetStandardLibrary.getInstance().getFloat(), + JetStandardLibrary.getInstance().getDouble(), + JetStandardLibrary.getInstance().getChar() + ); + + private static final int NO_FLAG_LOCAL = 0; + private static final int NO_FLAG_PACKAGE_PRIVATE = 0; + + @NotNull + private static final Map visibilityToAccessFlag = ImmutableMap.builder() + .put(Visibilities.PRIVATE, ACC_PRIVATE) + .put(Visibilities.PROTECTED, ACC_PROTECTED) + .put(Visibilities.PUBLIC, ACC_PUBLIC) + .put(Visibilities.INTERNAL, ACC_PUBLIC) + .put(Visibilities.LOCAL, NO_FLAG_LOCAL) + .put(JavaDescriptorResolver.PACKAGE_VISIBILITY, NO_FLAG_PACKAGE_PRIVATE) + .build(); + + public static final String RECEIVER$0 = "receiver$0"; + public static final String THIS$0 = "this$0"; + + private static final String STUB_EXCEPTION = "java/lang/RuntimeException"; + private static final String STUB_EXCEPTION_MESSAGE = "Stubs are for compiler only, do not add them to runtime classpath"; + + private AsmUtil() { + } + + public static Type boxType(Type asmType) { + JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByAsmType(asmType); + if (jvmPrimitiveType != null) { + return jvmPrimitiveType.getWrapper().getAsmType(); + } + else { + return asmType; + } + } + + public static boolean isIntPrimitive(Type type) { + return type == Type.INT_TYPE || type == Type.SHORT_TYPE || type == Type.BYTE_TYPE || type == Type.CHAR_TYPE; + } + + public static boolean isNumberPrimitive(Type type) { + return isIntPrimitive(type) || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.LONG_TYPE; + } + + public static boolean isPrimitive(Type type) { + return type.getSort() != Type.OBJECT && type.getSort() != Type.ARRAY; + } + + public static boolean isPrimitiveNumberClassDescriptor(DeclarationDescriptor descriptor) { + if (!(descriptor instanceof ClassDescriptor)) { + return false; + } + return PRIMITIVE_NUMBER_CLASSES.contains(descriptor); + } + + public static Type correctElementType(Type type) { + String internalName = type.getInternalName(); + assert internalName.charAt(0) == '['; + return Type.getType(internalName.substring(1)); + } + + public static Type unboxType(final Type type) { + JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByWrapperAsmType(type); + if (jvmPrimitiveType != null) { + return jvmPrimitiveType.getAsmType(); + } + else { + throw new UnsupportedOperationException("Unboxing: " + type); + } + } + + //TODO: move mapping logic to front-end java + public static int getVisibilityAccessFlag(@NotNull MemberDescriptor descriptor) { + Integer specialCase = specialCaseVisibility(descriptor); + if (specialCase != null) { + return specialCase; + } + Integer defaultMapping = visibilityToAccessFlag.get(descriptor.getVisibility()); + if (defaultMapping == null) { + throw new IllegalStateException(descriptor.getVisibility() + " is not a valid visibility in backend."); + } + return defaultMapping; + } + + @Nullable + private static Integer specialCaseVisibility(@NotNull MemberDescriptor memberDescriptor) { + DeclarationDescriptor containingDeclaration = memberDescriptor.getContainingDeclaration(); + if (isInterface(containingDeclaration)) { + return ACC_PUBLIC; + } + Visibility memberVisibility = memberDescriptor.getVisibility(); + if (memberVisibility != Visibilities.PRIVATE) { + return null; + } + if (isClassObject(containingDeclaration)) { + return NO_FLAG_PACKAGE_PRIVATE; + } + if (memberDescriptor instanceof ConstructorDescriptor) { + ClassKind kind = ((ClassDescriptor) containingDeclaration).getKind(); + if (kind == ClassKind.OBJECT) { + //TODO: should be NO_FLAG_PACKAGE_PRIVATE + // see http://youtrack.jetbrains.com/issue/KT-2700 + return ACC_PUBLIC; + } + else if (kind == ClassKind.ENUM_ENTRY) { + return NO_FLAG_PACKAGE_PRIVATE; + } + else if (kind == ClassKind.ENUM_CLASS) { + //TODO: should be ACC_PRIVATE + // see http://youtrack.jetbrains.com/issue/KT-2680 + return ACC_PROTECTED; + } + } + if (containingDeclaration instanceof NamespaceDescriptor) { + return ACC_PUBLIC; + } + return null; + } + + private static Type stringValueOfOrStringBuilderAppendType(Type type) { + final int sort = type.getSort(); + return sort == Type.OBJECT || sort == Type.ARRAY + ? AsmTypeConstants.OBJECT_TYPE + : sort == Type.BYTE || sort == Type.SHORT ? Type.INT_TYPE : type; + } + + public static void genThrow(MethodVisitor mv, String exception, String message) { + InstructionAdapter iv = new InstructionAdapter(mv); + iv.anew(Type.getObjectType(exception)); + iv.dup(); + iv.aconst(message); + iv.invokespecial(exception, "", "(Ljava/lang/String;)V"); + iv.athrow(); + } + + public static void genMethodThrow(MethodVisitor mv, String exception, String message) { + mv.visitCode(); + genThrow(mv, exception, message); + mv.visitMaxs(-1, -1); + mv.visitEnd(); + } + + public static void genClosureFields(CalculatedClosure closure, ClassBuilder v, JetTypeMapper typeMapper) { + final ClassifierDescriptor captureThis = closure.getCaptureThis(); + final int access = ACC_PUBLIC | ACC_SYNTHETIC | ACC_FINAL; + if (captureThis != null) { + v.newField(null, access, THIS$0, typeMapper.mapType(captureThis).getDescriptor(), null, + null); + } + + final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver(); + if (captureReceiver != null) { + v.newField(null, access, RECEIVER$0, typeMapper.mapType(captureReceiver).getDescriptor(), + null, null); + } + + final List> fields = closure.getRecordedFields(); + for (Pair field : fields) { + v.newField(null, access, field.first, field.second.getDescriptor(), null, null); + } + } + + public static void genInitSingletonField(Type classAsmType, InstructionAdapter iv) { + iv.anew(classAsmType); + iv.dup(); + iv.invokespecial(classAsmType.getInternalName(), "", "()V"); + iv.putstatic(classAsmType.getInternalName(), JvmAbi.INSTANCE_FIELD, classAsmType.getDescriptor()); + } + + public static void genStringBuilderConstructor(InstructionAdapter v) { + v.visitTypeInsn(NEW, "java/lang/StringBuilder"); + v.dup(); + v.invokespecial("java/lang/StringBuilder", "", "()V"); + } + + public static void genInvokeAppendMethod(InstructionAdapter v, Type type) { + type = stringValueOfOrStringBuilderAppendType(type); + v.invokevirtual("java/lang/StringBuilder", "append", "(" + type.getDescriptor() + ")Ljava/lang/StringBuilder;"); + } + + public static StackValue genToString(InstructionAdapter v, StackValue receiver) { + final Type type = stringValueOfOrStringBuilderAppendType(receiver.type); + receiver.put(type, v); + v.invokestatic("java/lang/String", "valueOf", "(" + type.getDescriptor() + ")Ljava/lang/String;"); + return StackValue.onStack(JAVA_STRING_TYPE); + } + + static void genHashCode(MethodVisitor mv, InstructionAdapter iv, Type type) { + if (type.getSort() == Type.ARRAY) { + final Type elementType = correctElementType(type); + if (elementType.getSort() == Type.OBJECT || elementType.getSort() == Type.ARRAY) { + iv.invokestatic("java/util/Arrays", "hashCode", "([Ljava/lang/Object;)I"); + } + else { + iv.invokestatic("java/util/Arrays", "hashCode", "(" + type.getDescriptor() + ")I"); + } + } + else if (type.getSort() == Type.OBJECT) { + iv.invokevirtual("java/lang/Object", "hashCode", "()I"); + } + else if (type.getSort() == Type.LONG) { + genLongHashCode(mv, iv); + } + else if (type.getSort() == Type.DOUBLE) { + iv.invokestatic("java/lang/Double", "doubleToLongBits", "(D)J"); + genLongHashCode(mv, iv); + } + else if (type.getSort() == Type.FLOAT) { + iv.invokestatic("java/lang/Float", "floatToIntBits", "(F)I"); + } + else if (type.getSort() == Type.BOOLEAN) { + Label end = new Label(); + iv.dup(); + iv.ifeq(end); + iv.pop(); + iv.iconst(1); + iv.mark(end); + } + else { // byte short char int + // do nothing + } + } + + private static void genLongHashCode(MethodVisitor mv, InstructionAdapter iv) { + iv.dup2(); + iv.iconst(32); + iv.ushr(Type.LONG_TYPE); + iv.xor(Type.LONG_TYPE); + mv.visitInsn(L2I); + } + + static StackValue compareExpressionsOnStack(InstructionAdapter v, IElementType opToken, Type operandType) { + if (operandType.getSort() == Type.OBJECT) { + v.invokeinterface("java/lang/Comparable", "compareTo", "(Ljava/lang/Object;)I"); + v.iconst(0); + operandType = Type.INT_TYPE; + } + return StackValue.cmp(opToken, operandType); + } + + static StackValue genNullSafeEquals( + InstructionAdapter v, + IElementType opToken, + boolean leftNullable, + boolean rightNullable + ) { + if (!leftNullable) { + v.invokevirtual("java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); + if (opToken == JetTokens.EXCLEQ) { + genInvertBoolean(v); + } + } + else { + if (rightNullable) { + v.dup2(); // left right left right + Label rightNull = new Label(); + v.ifnull(rightNull); + Label leftNull = new Label(); + v.ifnull(leftNull); + v.invokevirtual("java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); + if (opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ) { + genInvertBoolean(v); + } + Label end = new Label(); + v.goTo(end); + v.mark(rightNull); + // left right left + Label bothNull = new Label(); + v.ifnull(bothNull); + v.mark(leftNull); + v.pop2(); + v.iconst(opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ ? 1 : 0); + v.goTo(end); + v.mark(bothNull); + v.pop2(); + v.iconst(opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ ? 0 : 1); + v.mark(end); + } + else { + v.dup2(); // left right left right + v.pop(); + Label leftNull = new Label(); + v.ifnull(leftNull); + v.invokevirtual("java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); + if (opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ) { + genInvertBoolean(v); + } + Label end = new Label(); + v.goTo(end); + // left right + v.mark(leftNull); + v.pop2(); + v.iconst(opToken == JetTokens.EXCLEQ ? 1 : 0); + v.mark(end); + } + } + + return StackValue.onStack(Type.BOOLEAN_TYPE); + } + + static void genInvertBoolean(InstructionAdapter v) { + v.iconst(1); + v.xor(Type.INT_TYPE); + } + + public static StackValue genEqualsForExpressionsOnStack( + InstructionAdapter v, + IElementType opToken, + Type leftType, + Type rightType, + boolean leftNullable, + boolean rightNullable + ) { + if ((isNumberPrimitive(leftType) || leftType.getSort() == Type.BOOLEAN) && leftType == rightType) { + return compareExpressionsOnStack(v, opToken, leftType); + } + else { + if (opToken == JetTokens.EQEQEQ || opToken == JetTokens.EXCLEQEQEQ) { + return StackValue.cmp(opToken, leftType); + } + else { + return genNullSafeEquals(v, opToken, leftNullable, rightNullable); + } + } + } + + public static Type genIncrement(Type expectedType, int myDelta, InstructionAdapter v) { + if (expectedType == Type.LONG_TYPE) { + //noinspection UnnecessaryBoxing + v.lconst(myDelta); + } + else if (expectedType == Type.FLOAT_TYPE) { + //noinspection UnnecessaryBoxing + v.fconst(myDelta); + } + else if (expectedType == Type.DOUBLE_TYPE) { + //noinspection UnnecessaryBoxing + v.dconst(myDelta); + } + else { + v.iconst(myDelta); + expectedType = Type.INT_TYPE; + } + v.add(expectedType); + return expectedType; + } + + public static Type genNegate(Type expectedType, InstructionAdapter v) { + if (expectedType == Type.BYTE_TYPE || expectedType == Type.SHORT_TYPE || expectedType == Type.CHAR_TYPE) { + expectedType = Type.INT_TYPE; + } + v.neg(expectedType); + return expectedType; + } + + public static void genStubThrow(MethodVisitor mv) { + genThrow(mv, STUB_EXCEPTION, STUB_EXCEPTION_MESSAGE); + } + + public static void genStubCode(MethodVisitor mv) { + genMethodThrow(mv, STUB_EXCEPTION, STUB_EXCEPTION_MESSAGE); + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java index d11185aa1ec..218c74a4a44 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java @@ -22,7 +22,6 @@ import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.jet.codegen.context.CodegenContext; import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.state.GenerationStateAware; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.psi.*; @@ -34,14 +33,14 @@ import java.util.Collections; import java.util.List; import static org.jetbrains.asm4.Opcodes.*; -import static org.jetbrains.jet.codegen.CodegenUtil.generateMethodThrow; -import static org.jetbrains.jet.codegen.CodegenUtil.getVisibilityAccessFlag; +import static org.jetbrains.jet.codegen.AsmUtil.genMethodThrow; +import static org.jetbrains.jet.codegen.AsmUtil.getVisibilityAccessFlag; /** * @author max * @author yole */ -public abstract class ClassBodyCodegen extends GenerationStateAware { +public abstract class ClassBodyCodegen extends MemberCodegen { protected final JetClassOrObject myClass; protected final OwnerKind kind; protected final ClassDescriptor descriptor; @@ -89,7 +88,7 @@ public abstract class ClassBodyCodegen extends GenerationStateAware { protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration, FunctionCodegen functionCodegen) { if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) { - state.getMemberCodegen().generateFunctionOrProperty((JetTypeParameterListOwner) declaration, context, v); + genFunctionOrProperty(context, (JetTypeParameterListOwner) declaration, v); } } @@ -146,7 +145,7 @@ public abstract class ClassBodyCodegen extends GenerationStateAware { // generates stub 'remove' function for subclasses of Iterator to be compatible with java.util.Iterator if (DescriptorUtils.isIteratorWithoutRemoveImpl(descriptor)) { final MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "remove", "()V", null, null); - generateMethodThrow(mv, "java/lang/UnsupportedOperationException", "Mutating method called on a Kotlin Iterator"); + genMethodThrow(mv, "java/lang/UnsupportedOperationException", "Mutating method called on a Kotlin Iterator"); } } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassCodegen.java deleted file mode 100644 index b996608ca10..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassCodegen.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.codegen; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.codegen.context.CodegenContext; -import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.state.GenerationStateAware; -import org.jetbrains.jet.lang.descriptors.ClassDescriptor; -import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; -import org.jetbrains.jet.lang.psi.*; -import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.types.ErrorUtils; - -import java.util.Map; - -import static org.jetbrains.jet.codegen.binding.CodegenBinding.enumEntryNeedSubclass; - -/** - * @author max - * @author alex.tkachman - */ -public class ClassCodegen extends GenerationStateAware { - public ClassCodegen(@NotNull GenerationState state) { - super(state); - } - - public void generate(CodegenContext context, JetClassOrObject aClass) { - ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass); - - if (descriptor == null || ErrorUtils.isError(descriptor) || descriptor.getName().equals(JetPsiUtil.NO_NAME_PROVIDED)) { - if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES) { - throw new IllegalStateException( - "Generating bad descriptor in ClassBuilderMode = " + state.getClassBuilderMode() + ": " + descriptor); - } - return; - } - - ClassBuilder classBuilder = state.getFactory().forClassImplementation(descriptor); - - final CodegenContext contextForInners = context.intoClass(descriptor, OwnerKind.IMPLEMENTATION, state); - - if (state.getClassBuilderMode() == ClassBuilderMode.SIGNATURES) { - // Outer class implementation must happen prior inner classes so we get proper scoping tree in JetLightClass's delegate - // The same code is present below for the case when we generate real bytecode. This is because the order should be - // different for the case when we compute closures - generateImplementation(context, aClass, OwnerKind.IMPLEMENTATION, contextForInners.getAccessors(), classBuilder); - } - - for (JetDeclaration declaration : aClass.getDeclarations()) { - if (declaration instanceof JetClass) { - if (declaration instanceof JetEnumEntry && !enumEntryNeedSubclass( - state.getBindingContext(), (JetEnumEntry) declaration)) { - continue; - } - - generate(contextForInners, (JetClass) declaration); - } - else if (declaration instanceof JetClassObject) { - generate(contextForInners, ((JetClassObject) declaration).getObjectDeclaration()); - } - else if (declaration instanceof JetObjectDeclaration) { - generate(contextForInners, (JetObjectDeclaration) declaration); - } - } - - if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES) { - generateImplementation(context, aClass, OwnerKind.IMPLEMENTATION, contextForInners.getAccessors(), classBuilder); - } - - classBuilder.done(); - } - - private void generateImplementation( - CodegenContext context, - JetClassOrObject aClass, - OwnerKind kind, - Map accessors, - ClassBuilder classBuilder - ) { - ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass); - CodegenContext classContext = context.intoClass(descriptor, kind, state); - classContext.copyAccessors(accessors); - - new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate(); - - if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) { - ClassBuilder traitBuilder = state.getFactory().forTraitImplementation(descriptor, state); - new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state), traitBuilder, state) - .generate(); - traitBuilder.done(); - } - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java index 820959a410e..f73de6bcd3c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java @@ -28,6 +28,8 @@ import org.jetbrains.jet.lang.resolve.name.FqName; import javax.inject.Inject; import java.util.*; +import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive; + /** * @author max * @author alex.tkachman @@ -114,7 +116,7 @@ public final class ClassFileFactory extends GenerationStateAware { public ClassBuilder forClassImplementation(ClassDescriptor aClass) { Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.IMPL); - if (CodegenUtil.isPrimitive(type)) { + if (isPrimitive(type)) { throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass); } return newVisitor(type.getInternalName() + ".class"); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java index 5fe40d1b34d..f98e6661b1e 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java @@ -49,6 +49,7 @@ import java.util.ArrayList; import java.util.List; import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.AsmUtil.*; import static org.jetbrains.jet.codegen.CodegenUtil.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass; import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun; @@ -108,7 +109,7 @@ public class ClosureCodegen extends GenerationStateAware { generateConstInstance(fun, cv); } - generateClosureFields(closure, cv, state.getTypeMapper()); + genClosureFields(closure, cv, state.getTypeMapper()); cv.done(); @@ -122,11 +123,11 @@ public class ClosureCodegen extends GenerationStateAware { cv.newField(fun, ACC_PUBLIC | ACC_STATIC | ACC_FINAL, JvmAbi.INSTANCE_FIELD, name.getDescriptor(), null, null); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); - initSingletonField(fun, name.getAsmType(), cv, iv); + genInitSingletonField(name.getAsmType(), iv); mv.visitInsn(RETURN); FunctionCodegen.endVisit(mv, "", fun); } @@ -164,7 +165,7 @@ public class ClosureCodegen extends GenerationStateAware { cv.newMethod(fun, ACC_PUBLIC | ACC_BRIDGE | ACC_VOLATILE, "invoke", bridge.getAsmMethod().getDescriptor(), null, new String[0]); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); @@ -212,7 +213,7 @@ public class ClosureCodegen extends GenerationStateAware { final Method constructor = new Method("", Type.VOID_TYPE, argTypes); final MethodVisitor mv = cv.newMethod(fun, ACC_PUBLIC, "", constructor.getDescriptor(), null, new String[0]); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index 787436e23b1..64c1fc491b9 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -16,70 +16,36 @@ package org.jetbrains.jet.codegen; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; -import com.intellij.openapi.util.Pair; import com.intellij.psi.PsiElement; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.asm4.MethodVisitor; -import org.jetbrains.asm4.Type; -import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.asm4.commons.Method; import org.jetbrains.jet.codegen.binding.CalculatedClosure; import org.jetbrains.jet.codegen.signature.BothSignatureWriter; import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind; import org.jetbrains.jet.codegen.signature.JvmMethodSignature; -import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.psi.JetClassObject; import org.jetbrains.jet.lang.psi.JetClassOrObject; import org.jetbrains.jet.lang.psi.JetObjectDeclaration; import org.jetbrains.jet.lang.resolve.DescriptorUtils; -import org.jetbrains.jet.lang.resolve.java.*; +import org.jetbrains.jet.lang.resolve.java.JvmAbi; +import org.jetbrains.jet.lang.resolve.java.JvmClassName; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; -import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import java.util.*; -import static org.jetbrains.asm4.Opcodes.*; -import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject; -import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*; +import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; /** * @author abreslav * @author alex.tkachman */ public class CodegenUtil { - public static final String RECEIVER$0 = "receiver$0"; - public static final String THIS$0 = "this$0"; - - private static final int NO_FLAG_LOCAL = 0; - private static final int NO_FLAG_PACKAGE_PRIVATE = 0; - - @NotNull - private static final Map visibilityToAccessFlag = ImmutableMap.builder() - .put(Visibilities.PRIVATE, ACC_PRIVATE) - .put(Visibilities.PROTECTED, ACC_PROTECTED) - .put(Visibilities.PUBLIC, ACC_PUBLIC) - .put(Visibilities.INTERNAL, ACC_PUBLIC) - .put(Visibilities.LOCAL, NO_FLAG_LOCAL) - .put(JavaDescriptorResolver.PACKAGE_VISIBILITY, NO_FLAG_PACKAGE_PRIVATE) - .build(); - - private static final Set PRIMITIVE_NUMBER_CLASSES = Sets.newHashSet( - JetStandardLibrary.getInstance().getByte(), - JetStandardLibrary.getInstance().getShort(), - JetStandardLibrary.getInstance().getInt(), - JetStandardLibrary.getInstance().getLong(), - JetStandardLibrary.getInstance().getFloat(), - JetStandardLibrary.getInstance().getDouble(), - JetStandardLibrary.getInstance().getChar() - ); private CodegenUtil() { } @@ -124,7 +90,7 @@ public class CodegenUtil { } - public static String generateTmpVariableName(Collection existingNames) { + public static String createTmpVariableName(Collection existingNames) { String prefix = "tmp"; int i = RANDOM.nextInt(Integer.MAX_VALUE); String name = prefix + i; @@ -136,9 +102,8 @@ public class CodegenUtil { } - public static @NotNull - BitSet getFlagsForVisibility(@NotNull Visibility visibility) { + public static BitSet getFlagsForVisibility(@NotNull Visibility visibility) { BitSet flags = new BitSet(); if (visibility == Visibilities.INTERNAL) { flags.set(JvmStdlibNames.FLAG_INTERNAL_BIT); @@ -149,22 +114,6 @@ public class CodegenUtil { return flags; } - public static void generateThrow(MethodVisitor mv, String exception, String message) { - InstructionAdapter iv = new InstructionAdapter(mv); - iv.anew(Type.getObjectType(exception)); - iv.dup(); - iv.aconst(message); - iv.invokespecial(exception, "", "(Ljava/lang/String;)V"); - iv.athrow(); - } - - public static void generateMethodThrow(MethodVisitor mv, String exception, String message) { - mv.visitCode(); - generateThrow(mv, exception, message); - mv.visitMaxs(-1, -1); - mv.visitEnd(); - } - @NotNull public static JvmClassName getInternalClassName(FunctionDescriptor descriptor) { final int paramCount = descriptor.getValueParameters().size(); @@ -210,123 +159,10 @@ public class CodegenUtil { return closure.getCaptureThis() == null && closure.getCaptureReceiver() == null && closure.getCaptureVariables().isEmpty(); } - public static void generateClosureFields(CalculatedClosure closure, ClassBuilder v, JetTypeMapper typeMapper) { - final ClassifierDescriptor captureThis = closure.getCaptureThis(); - final int access = ACC_PUBLIC | ACC_SYNTHETIC | ACC_FINAL; - if (captureThis != null) { - v.newField(null, access, THIS$0, typeMapper.mapType(captureThis).getDescriptor(), null, - null); - } - - final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver(); - if (captureReceiver != null) { - v.newField(null, access, RECEIVER$0, typeMapper.mapType(captureReceiver).getDescriptor(), - null, null); - } - - final List> fields = closure.getRecordedFields(); - for (Pair field : fields) { - v.newField(null, access, field.first, field.second.getDescriptor(), null, null); - } - } - public static T peekFromStack(Stack stack) { return stack.empty() ? null : stack.peek(); } - //TODO: move mapping logic to front-end java - public static int getVisibilityAccessFlag(@NotNull MemberDescriptor descriptor) { - Integer specialCase = specialCaseVisibility(descriptor); - if (specialCase != null) { - return specialCase; - } - Integer defaultMapping = visibilityToAccessFlag.get(descriptor.getVisibility()); - if (defaultMapping == null) { - throw new IllegalStateException(descriptor.getVisibility() + " is not a valid visibility in backend."); - } - return defaultMapping; - } - - @Nullable - private static Integer specialCaseVisibility(@NotNull MemberDescriptor memberDescriptor) { - DeclarationDescriptor containingDeclaration = memberDescriptor.getContainingDeclaration(); - if (isInterface(containingDeclaration)) { - return ACC_PUBLIC; - } - Visibility memberVisibility = memberDescriptor.getVisibility(); - if (memberVisibility != Visibilities.PRIVATE) { - return null; - } - if (isClassObject(containingDeclaration)) { - return NO_FLAG_PACKAGE_PRIVATE; - } - if (memberDescriptor instanceof ConstructorDescriptor) { - ClassKind kind = ((ClassDescriptor) containingDeclaration).getKind(); - if (kind == ClassKind.OBJECT) { - //TODO: should be NO_FLAG_PACKAGE_PRIVATE - // see http://youtrack.jetbrains.com/issue/KT-2700 - return ACC_PUBLIC; - } - else if (kind == ClassKind.ENUM_ENTRY) { - return NO_FLAG_PACKAGE_PRIVATE; - } - else if (kind == ClassKind.ENUM_CLASS) { - //TODO: should be ACC_PRIVATE - // see http://youtrack.jetbrains.com/issue/KT-2680 - return ACC_PROTECTED; - } - } - if (containingDeclaration instanceof NamespaceDescriptor) { - return ACC_PUBLIC; - } - return null; - } - - public static Type unboxType(final Type type) { - JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByWrapperAsmType(type); - if (jvmPrimitiveType != null) { - return jvmPrimitiveType.getAsmType(); - } - else { - throw new UnsupportedOperationException("Unboxing: " + type); - } - } - - public static Type boxType(Type asmType) { - JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByAsmType(asmType); - if (jvmPrimitiveType != null) { - return jvmPrimitiveType.getWrapper().getAsmType(); - } - else { - return asmType; - } - } - - public static boolean isIntPrimitive(Type type) { - return type == Type.INT_TYPE || type == Type.SHORT_TYPE || type == Type.BYTE_TYPE || type == Type.CHAR_TYPE; - } - - public static boolean isNumberPrimitive(Type type) { - return isIntPrimitive(type) || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.LONG_TYPE; - } - - public static boolean isPrimitive(Type type) { - return type.getSort() != Type.OBJECT && type.getSort() != Type.ARRAY; - } - - public static boolean isPrimitiveNumberClassDescriptor(DeclarationDescriptor descriptor) { - if (!(descriptor instanceof ClassDescriptor)) { - return false; - } - return PRIMITIVE_NUMBER_CLASSES.contains(descriptor); - } - - public static Type correctElementType(Type type) { - String internalName = type.getInternalName(); - assert internalName.charAt(0) == '['; - return Type.getType(internalName.substring(1)); - } - @Nullable public static String getLocalNameForObject(JetObjectDeclaration object) { PsiElement parent = object.getParent(); @@ -363,34 +199,4 @@ public class CodegenUtil { throw new IllegalStateException("code generation for synthesized members should be handled separately"); } } - - public static void initSingletonField(PsiElement element, Type classAsmType, ClassBuilder builder, InstructionAdapter iv) { - iv.anew(classAsmType); - iv.dup(); - iv.invokespecial(classAsmType.getInternalName(), "", "()V"); - iv.putstatic(classAsmType.getInternalName(), JvmAbi.INSTANCE_FIELD, classAsmType.getDescriptor()); - } - - public static void generateStringBuilderConstructor(InstructionAdapter v) { - v.visitTypeInsn(NEW, "java/lang/StringBuilder"); - v.dup(); - v.invokespecial("java/lang/StringBuilder", "", "()V"); - } - - public static void invokeAppendMethod(InstructionAdapter v, Type exprType) { - Method appendDescriptor = new Method("append", getType(StringBuilder.class), - new Type[] {exprType.getSort() == Type.OBJECT ? (exprType.equals(JAVA_STRING_TYPE) ? JAVA_STRING_TYPE : OBJECT_TYPE) : exprType}); - v.invokevirtual("java/lang/StringBuilder", "append", appendDescriptor.getDescriptor()); - } - - public static StackValue genToString(InstructionAdapter v, StackValue receiver) { - final int sort = receiver.type.getSort(); - - final Type type = sort == Type.OBJECT || sort == Type.ARRAY - ? AsmTypeConstants.OBJECT_TYPE - : sort == Type.BYTE || sort == Type.SHORT ? Type.INT_TYPE : receiver.type; - receiver.put(type, v); - v.invokestatic("java/lang/String", "valueOf", "(" + type.getDescriptor() + ")Ljava/lang/String;"); - return StackValue.onStack(JAVA_STRING_TYPE); - } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java b/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java index f48a303a0f7..2f9f8e2fbbc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CompilationException.java @@ -30,7 +30,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; public class CompilationException extends RuntimeException { private final PsiElement element; - CompilationException(@NotNull String message, @Nullable Throwable cause, @NotNull PsiElement element) { + public CompilationException(@NotNull String message, @Nullable Throwable cause, @NotNull PsiElement element) { super(message, cause); this.element = element; } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 7e3b4d1b104..287eabd251d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -61,6 +61,7 @@ import org.jetbrains.jet.lexer.JetTokens; import java.util.*; import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.AsmUtil.*; import static org.jetbrains.jet.codegen.CodegenUtil.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.*; import static org.jetbrains.jet.lang.resolve.BindingContext.*; @@ -116,9 +117,16 @@ public class ExpressionCodegen extends JetVisitor implem //noinspection SuspiciousMethodCalls final CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor); - final CodegenContext objectContext = context.intoAnonymousClass(classDescriptor, this); + final CodegenContext contextForInners = context.intoClass(classDescriptor, OwnerKind.IMPLEMENTATION, state); - new ImplementationBodyCodegen(objectDeclaration, objectContext, classBuilder, state).generate(); + final CodegenContext objectContext = context.intoAnonymousClass(classDescriptor, this); + final ImplementationBodyCodegen implementationBodyCodegen = new ImplementationBodyCodegen(objectDeclaration, objectContext, classBuilder, state); + + implementationBodyCodegen.genInners(contextForInners, state, objectDeclaration); + + objectContext.copyAccessors(contextForInners.getAccessors()); + + implementationBodyCodegen.generate(); return closure; } @@ -991,7 +999,7 @@ public class ExpressionCodegen extends JetVisitor implem return StackValue.constant(constantValue.toString(), type); } else { - generateStringBuilderConstructor(v); + genStringBuilderConstructor(v); for (JetStringTemplateEntry entry : entries) { if (entry instanceof JetStringTemplateEntryWithExpression) { invokeAppend(entry.getExpression()); @@ -1001,7 +1009,7 @@ public class ExpressionCodegen extends JetVisitor implem ? ((JetEscapeStringTemplateEntry) entry).getUnescapedValue() : entry.getText(); v.aconst(text); - invokeAppendMethod(v, JAVA_STRING_TYPE); + genInvokeAppendMethod(v, JAVA_STRING_TYPE); } } v.invokevirtual("java/lang/StringBuilder", "toString", "()Ljava/lang/String;"); @@ -1510,9 +1518,11 @@ public class ExpressionCodegen extends JetVisitor implem boolean isStatic = containingDeclaration instanceof NamespaceDescriptor; boolean overridesTrait = isOverrideForTrait(propertyDescriptor); boolean isFakeOverride = propertyDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE; + boolean isDelegate = propertyDescriptor.getKind() == CallableMemberDescriptor.Kind.DELEGATION; PropertyDescriptor initialDescriptor = propertyDescriptor; propertyDescriptor = initialDescriptor.getOriginal(); boolean isInsideClass = !isFakeOverride && + !isDelegate && (((containingDeclaration == null && !context.hasThisDescriptor() || context.hasThisDescriptor() && containingDeclaration == context.getThisDescriptor()) || (context.getParentContext() instanceof NamespaceContext) && @@ -1660,9 +1670,9 @@ public class ExpressionCodegen extends JetVisitor implem PropertySetterDescriptor setter = propertyDescriptor.getSetter(); PropertyGetterDescriptor getter = propertyDescriptor.getGetter(); - final int flag = CodegenUtil.getVisibilityAccessFlag(propertyDescriptor) | - (getter == null ? 0 : CodegenUtil.getVisibilityAccessFlag(getter)) | - (setter == null ? 0 : CodegenUtil.getVisibilityAccessFlag(setter)); + final int flag = getVisibilityAccessFlag(propertyDescriptor) | + (getter == null ? 0 : getVisibilityAccessFlag(getter)) | + (setter == null ? 0 : getVisibilityAccessFlag(setter)); if ((flag & ACC_PRIVATE) == 0) { return propertyDescriptor; @@ -1672,7 +1682,7 @@ public class ExpressionCodegen extends JetVisitor implem } private FunctionDescriptor accessableFunctionDescriptor(FunctionDescriptor fd) { - final int flag = CodegenUtil.getVisibilityAccessFlag(fd); + final int flag = getVisibilityAccessFlag(fd); if ((flag & ACC_PRIVATE) == 0) { return fd; } @@ -2256,7 +2266,7 @@ public class ExpressionCodegen extends JetVisitor implem else { invokeFunctionByReference(expression.getOperationReference()); if (inverted) { - invertBoolean(); + genInvertBoolean(v); } } return StackValue.onStack(Type.BOOLEAN_TYPE); @@ -2297,7 +2307,7 @@ public class ExpressionCodegen extends JetVisitor implem v.and(Type.INT_TYPE); if (inverted) { - invertBoolean(); + genInvertBoolean(v); } } @@ -2357,10 +2367,11 @@ public class ExpressionCodegen extends JetVisitor implem if (isPrimitive(leftType)) // both are primitive { - return generateEqualsForExpressionsOnStack(opToken, leftType, rightType, false, false); + return genEqualsForExpressionsOnStack(v, opToken, leftType, rightType, false, false); } - return generateEqualsForExpressionsOnStack(opToken, leftType, rightType, leftJetType.isNullable(), rightJetType.isNullable()); + return + genEqualsForExpressionsOnStack(v, opToken, leftType, rightType, leftJetType.isNullable(), rightJetType.isNullable()); } private StackValue genCmpWithNull(JetExpression exp, Type expType, IElementType opToken) { @@ -2379,81 +2390,6 @@ public class ExpressionCodegen extends JetVisitor implem return StackValue.onStack(Type.BOOLEAN_TYPE); } - public StackValue generateEqualsForExpressionsOnStack( - IElementType opToken, - Type leftType, - Type rightType, - boolean leftNullable, - boolean rightNullable - ) { - if ((CodegenUtil.isNumberPrimitive(leftType) || leftType.getSort() == Type.BOOLEAN) && leftType == rightType) { - return compareExpressionsOnStack(opToken, leftType); - } - else { - if (opToken == JetTokens.EQEQEQ || opToken == JetTokens.EXCLEQEQEQ) { - return StackValue.cmp(opToken, leftType); - } - else { - return generateNullSafeEquals(opToken, leftNullable, rightNullable); - } - } - } - - private StackValue generateNullSafeEquals(IElementType opToken, boolean leftNullable, boolean rightNullable) { - if (!leftNullable) { - v.invokevirtual("java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); - if (opToken == JetTokens.EXCLEQ) { - invertBoolean(); - } - } - else { - if (rightNullable) { - v.dup2(); // left right left right - Label rightNull = new Label(); - v.ifnull(rightNull); - Label leftNull = new Label(); - v.ifnull(leftNull); - v.invokevirtual("java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); - if (opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ) { - invertBoolean(); - } - Label end = new Label(); - v.goTo(end); - v.mark(rightNull); - // left right left - Label bothNull = new Label(); - v.ifnull(bothNull); - v.mark(leftNull); - v.pop2(); - v.iconst(opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ ? 1 : 0); - v.goTo(end); - v.mark(bothNull); - v.pop2(); - v.iconst(opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ ? 0 : 1); - v.mark(end); - } - else { - v.dup2(); // left right left right - v.pop(); - Label leftNull = new Label(); - v.ifnull(leftNull); - v.invokevirtual("java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); - if (opToken == JetTokens.EXCLEQ || opToken == JetTokens.EXCLEQEQEQ) { - invertBoolean(); - } - Label end = new Label(); - v.goTo(end); - // left right - v.mark(leftNull); - v.pop2(); - v.iconst(opToken == JetTokens.EXCLEQ ? 1 : 0); - v.mark(end); - } - } - - return StackValue.onStack(Type.BOOLEAN_TYPE); - } - private StackValue generateElvis(JetBinaryExpression expression) { final Type exprType = expressionType(expression); JetType type = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getLeft()); @@ -2490,16 +2426,7 @@ public class ExpressionCodegen extends JetVisitor implem private StackValue generateCompareOp(JetExpression left, JetExpression right, IElementType opToken, Type operandType) { gen(left, operandType); gen(right, operandType); - return compareExpressionsOnStack(opToken, operandType); - } - - private StackValue compareExpressionsOnStack(IElementType opToken, Type operandType) { - if (operandType.getSort() == Type.OBJECT) { - v.invokeinterface("java/lang/Comparable", "compareTo", "(Ljava/lang/Object;)I"); - v.iconst(0); - operandType = Type.INT_TYPE; - } - return StackValue.cmp(opToken, operandType); + return compareExpressionsOnStack(v, opToken, operandType); } private StackValue generateAssignmentExpression(JetBinaryExpression expression) { @@ -2593,7 +2520,7 @@ public class ExpressionCodegen extends JetVisitor implem } Type exprType = expressionType(expr); gen(expr, exprType); - invokeAppendMethod(v, exprType.getSort() == Type.ARRAY ? OBJECT_TYPE : exprType); + genInvokeAppendMethod(v, exprType.getSort() == Type.ARRAY ? OBJECT_TYPE : exprType); } @Nullable @@ -2767,22 +2694,7 @@ public class ExpressionCodegen extends JetVisitor implem StackValue value = genQualified(receiver, operand); value.dupReceiver(v); value.put(asmType, v); - if (asmType == Type.LONG_TYPE) { - //noinspection UnnecessaryBoxing - v.lconst(increment); - } - else if (asmType == Type.FLOAT_TYPE) { - //noinspection UnnecessaryBoxing - v.fconst(increment); - } - else if (asmType == Type.DOUBLE_TYPE) { - //noinspection UnnecessaryBoxing - v.dconst(increment); - } - else { - v.iconst(increment); - } - v.add(asmType); + asmType = genIncrement(asmType, increment, v); value.store(asmType, v); } @@ -3281,12 +3193,12 @@ The "returned" value of try expression with no finally is either the last expres boolean patternIsNullable = false; JetType condJetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, patternExpression); Type condType; - if (CodegenUtil.isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) { + if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) { assert condJetType != null; condType = asmType(condJetType); - if (!(CodegenUtil.isNumberPrimitive(condType) || condType.getSort() == Type.BOOLEAN)) { + if (!(isNumberPrimitive(condType) || condType.getSort() == Type.BOOLEAN)) { subjectType = boxType(subjectType); - expressionToMatch.coerce(subjectType, v); + expressionToMatch.coerceTo(subjectType, v); } } else { @@ -3294,8 +3206,8 @@ The "returned" value of try expression with no finally is either the last expres patternIsNullable = condJetType != null && condJetType.isNullable(); } gen(patternExpression, condType); - return generateEqualsForExpressionsOnStack(JetTokens.EQEQ, subjectType, condType, expressionToMatchIsNullable, - patternIsNullable); + return genEqualsForExpressionsOnStack(v, JetTokens.EQEQ, subjectType, condType, expressionToMatchIsNullable, + patternIsNullable); } else { return gen(patternExpression); @@ -3420,7 +3332,7 @@ The "returned" value of try expression with no finally is either the last expres //invokeFunctionNoParams(op, Type.BOOLEAN_TYPE, v); invokeFunctionByReference(operationReference); if (inverted) { - invertBoolean(); + genInvertBoolean(v); } } return StackValue.onStack(Type.BOOLEAN_TYPE); @@ -3446,11 +3358,6 @@ The "returned" value of try expression with no finally is either the last expres invokeFunction(call, StackValue.none(), resolvedCall); } - private void invertBoolean() { - v.iconst(1); - v.xor(Type.INT_TYPE); - } - private boolean isIntRangeExpr(JetExpression rangeExpression) { if (rangeExpression instanceof JetBinaryExpression) { JetBinaryExpression binaryExpression = (JetBinaryExpression) rangeExpression; @@ -3464,34 +3371,6 @@ The "returned" value of try expression with no finally is either the last expres return false; } - @Override - public StackValue visitTupleExpression(JetTupleExpression expression, StackValue receiver) { - final List entries = expression.getEntries(); - if (entries.size() > 22) { - throw new UnsupportedOperationException("tuple too large"); - } - if (entries.size() == 0) { - v.visitFieldInsn(GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;"); - return StackValue.onStack(JET_TUPLE0_TYPE); - } - - final String className = "jet/Tuple" + entries.size(); - Type tupleType = Type.getObjectType(className); - StringBuilder signature = new StringBuilder("("); - for (int i = 0; i != entries.size(); ++i) { - signature.append("Ljava/lang/Object;"); - } - signature.append(")V"); - - v.anew(tupleType); - v.dup(); - for (JetExpression entry : entries) { - gen(entry, OBJECT_TYPE); - } - v.invokespecial(className, "", signature.toString()); - return StackValue.onStack(tupleType); - } - private void throwNewException(final String className) { v.anew(Type.getObjectType(className)); v.dup(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index d7cae2f6e1c..9a653f4a9d0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -48,6 +48,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import java.util.*; import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.AsmUtil.*; import static org.jetbrains.jet.codegen.CodegenUtil.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalFun; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration; @@ -130,7 +131,7 @@ public class FunctionCodegen extends GenerationStateAware { } if (!isAbstract && state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } @@ -258,7 +259,7 @@ public class FunctionCodegen extends GenerationStateAware { Type sharedVarType = state.getTypeMapper().getSharedVarType(parameter); mv.visitLocalVariable(parameterName, type.getDescriptor(), null, methodBegin, divideLabel, k); - String nameForSharedVar = generateTmpVariableName(localVariableNames); + String nameForSharedVar = createTmpVariableName(localVariableNames); localVariableNames.add(nameForSharedVar); mv.visitLocalVariable(nameForSharedVar, sharedVarType.getDescriptor(), null, divideLabel, methodEnd, k); @@ -516,7 +517,7 @@ public class FunctionCodegen extends GenerationStateAware { descriptor, null, null); InstructionAdapter iv = new InstructionAdapter(mv); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { generateDefaultImpl(owner, state, jvmSignature, functionDescriptor, kind, receiverParameter, hasReceiver, isStatic, @@ -684,7 +685,7 @@ public class FunctionCodegen extends GenerationStateAware { final MethodVisitor mv = v.newMethod(null, flags, jvmSignature.getName(), overridden.getDescriptor(), null, null); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); @@ -738,7 +739,7 @@ public class FunctionCodegen extends GenerationStateAware { final MethodVisitor mv = v.newMethod(null, flags, method.getName(), method.getDescriptor(), null, null); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 74cd8b819b8..4c6812f8118 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.AnnotationVisitor; +import org.jetbrains.asm4.Label; import org.jetbrains.asm4.MethodVisitor; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; @@ -40,6 +41,7 @@ import org.jetbrains.jet.codegen.state.JetTypeMapperMode; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.OverridingUtil; import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; @@ -56,6 +58,7 @@ import org.jetbrains.jet.utils.BitSetUtils; import java.util.*; import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.AsmUtil.*; import static org.jetbrains.jet.codegen.CodegenUtil.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.*; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration; @@ -164,42 +167,43 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { ); v.visitSource(myClass.getContainingFile().getName(), null); - writeInnerOuterClasses(); + writeOuterClass(); + + writeInnerClasses(); AnnotationCodegen.forClass(v.getVisitor(), typeMapper).genAnnotations(descriptor); writeClassSignatureIfNeeded(signature); } - private void writeInnerOuterClasses() { + private void writeOuterClass() { ClassDescriptor container = getContainingClassDescriptor(descriptor); if (container != null) { v.visitOuterClass(typeMapper.mapType(container.getDefaultType(), JetTypeMapperMode.IMPL).getInternalName(), null, null); } + } - for (DeclarationDescriptor declarationDescriptor : descriptor.getUnsubstitutedInnerClassesScope().getAllDescriptors()) { - assert declarationDescriptor instanceof ClassDescriptor; - ClassDescriptor innerClass = (ClassDescriptor) declarationDescriptor; - // TODO: proper access - int innerClassAccess = ACC_PUBLIC; - if (innerClass.getModality() == Modality.FINAL) { - innerClassAccess |= ACC_FINAL; - } - else if (innerClass.getModality() == Modality.ABSTRACT) { - innerClassAccess |= ACC_ABSTRACT; - } + private void writeInnerClasses() { + // Inner enums are moved by frontend to a class object of outer class, but we want them to be inner for the outer class itself + // (to avoid publicly visible names like A$ClassObject$$B), so they are handled specially in this method - if (innerClass.getKind() == ClassKind.TRAIT) { - innerClassAccess |= ACC_INTERFACE; + for (ClassDescriptor innerClass : DescriptorUtils.getInnerClasses(descriptor)) { + // If it's an inner enum inside a class object, don't write it + // (instead write it to inner classes of this class object's containing class) + if (!isEnumMovedToClassObject(innerClass)) { + writeInnerClass(innerClass, false); } - - // TODO: cache internal names - String outerClassInernalName = classAsmType.getInternalName(); - String innerClassInternalName = typeMapper.mapType(innerClass.getDefaultType(), JetTypeMapperMode.IMPL).getInternalName(); - v.visitInnerClass(innerClassInternalName, outerClassInernalName, innerClass.getName().getName(), innerClassAccess); } - if (descriptor.getClassObjectDescriptor() != null) { + ClassDescriptor classObjectDescriptor = descriptor.getClassObjectDescriptor(); + if (classObjectDescriptor != null) { + // Process all enums here which were moved to our class object + for (ClassDescriptor innerClass : DescriptorUtils.getInnerClasses(classObjectDescriptor)) { + if (isEnumMovedToClassObject(innerClass)) { + writeInnerClass(innerClass, true); + } + } + int innerClassAccess = ACC_PUBLIC | ACC_FINAL | ACC_STATIC; v.visitInnerClass(classAsmType.getInternalName() + JvmAbi.CLASS_OBJECT_SUFFIX, classAsmType.getInternalName(), JvmAbi.CLASS_OBJECT_CLASS_NAME, @@ -207,6 +211,39 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } } + private void writeInnerClass(ClassDescriptor innerClass, boolean isStatic) { + // TODO: proper access + int innerClassAccess = ACC_PUBLIC; + if (innerClass.getModality() == Modality.FINAL) { + innerClassAccess |= ACC_FINAL; + } + else if (innerClass.getModality() == Modality.ABSTRACT) { + innerClassAccess |= ACC_ABSTRACT; + } + + if (innerClass.getKind() == ClassKind.TRAIT) { + innerClassAccess |= ACC_INTERFACE; + } + else if (innerClass.getKind() == ClassKind.ENUM_CLASS) { + innerClassAccess |= ACC_ENUM; + } + + if (isStatic) { + innerClassAccess |= ACC_STATIC; + } + + // TODO: cache internal names + String outerClassInternalName = classAsmType.getInternalName(); + String innerClassInternalName = typeMapper.mapType(innerClass.getDefaultType(), JetTypeMapperMode.IMPL).getInternalName(); + v.visitInnerClass(innerClassInternalName, outerClassInternalName, innerClass.getName().getName(), innerClassAccess); + } + + private boolean isEnumMovedToClassObject(ClassDescriptor innerClass) { + // Checks if this is enum, moved to class object by frontend + + return Boolean.TRUE.equals(bindingContext.get(BindingContext.IS_ENUM_MOVED_TO_CLASS_OBJECT, innerClass)); + } + private void writeClassSignatureIfNeeded(JvmClassSignature signature) { if (signature.getKotlinGenericSignature() != null || descriptor.getVisibility() != Visibilities.PUBLIC) { AnnotationVisitor annotationVisitor = v.newAnnotation(JvmStdlibNames.JET_CLASS.getDescriptor(), true); @@ -355,7 +392,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { generateFunctionsForDataClasses(); - generateClosureFields(context.closure, v, state.getTypeMapper()); + genClosureFields(context.closure, v, state.getTypeMapper()); + } + + private List getDataProperties() { + ArrayList result = Lists.newArrayList(); + for (JetParameter parameter : getPrimaryConstructorParameters()) { + if (parameter.getValOrVarNode() == null) continue; + + PropertyDescriptor propertyDescriptor = state.getBindingContext().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter); + assert propertyDescriptor != null; + + result.add(propertyDescriptor); + } + return result; } private void generateFunctionsForDataClasses() { @@ -363,67 +413,135 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { generateComponentFunctionsForDataClasses(); - generateDataClassToStringMethod(); - generateDataClassHashCodeMethod(); - generateDataClassEqualsMethod(); + final List properties = getDataProperties(); + if (!properties.isEmpty()) { + generateDataClassToStringMethod(properties); + generateDataClassHashCodeMethod(properties); + generateDataClassEqualsMethod(properties); + } } - private void generateDataClassEqualsMethod() { - // todo: this is fake implementation - + private void generateDataClassEqualsMethod(List properties) { final MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "equals", "(Ljava/lang/Object;)Z", null, null); - mv.visitVarInsn(ALOAD, 0); - mv.visitVarInsn(ALOAD, 1); - mv.visitMethodInsn(INVOKESPECIAL, superClassAsmType.getInternalName(), "equals", "(Ljava/lang/Object;)Z"); - mv.visitInsn(IRETURN); - mv.visitMaxs(-1,-1); - mv.visitEnd(); + final InstructionAdapter iv = new InstructionAdapter(mv); + + mv.visitCode(); + Label eq = new Label(); + Label ne = new Label(); + + iv.load(0, OBJECT_TYPE); + iv.load(1, AsmTypeConstants.OBJECT_TYPE); + iv.ifacmpeq(eq); + + iv.load(1, AsmTypeConstants.OBJECT_TYPE); + iv.instanceOf(classAsmType); + iv.ifeq(ne); + + iv.load(1, AsmTypeConstants.OBJECT_TYPE); + iv.checkcast(classAsmType); + iv.store(2, AsmTypeConstants.OBJECT_TYPE); + + for (PropertyDescriptor propertyDescriptor : properties) { + final JetType type = propertyDescriptor.getType(); + final Type asmType = typeMapper.mapType(type); + + genPropertyOnStack(iv, propertyDescriptor, 0); + genPropertyOnStack(iv, propertyDescriptor, 2); + + if (asmType.getSort() == Type.ARRAY) { + final Type elementType = correctElementType(asmType); + if (elementType.getSort() == Type.OBJECT || elementType.getSort() == Type.ARRAY) { + iv.invokestatic("java/util/Arrays", "equals", "([Ljava/lang/Object;[Ljava/lang/Object;)Z"); + } + else { + iv.invokestatic("java/util/Arrays", "equals", "([" + elementType.getDescriptor() + "[" + elementType.getDescriptor() + ")Z"); + } + } + else { + final StackValue value = + genEqualsForExpressionsOnStack(iv, JetTokens.EQEQ, asmType, asmType, type.isNullable(), type.isNullable()); + value.put(Type.BOOLEAN_TYPE, iv); + } + + iv.ifeq(ne); + } + + iv.mark(eq); + iv.iconst(1); + iv.areturn(Type.INT_TYPE); + + iv.mark(ne); + iv.iconst(0); + iv.areturn(Type.INT_TYPE); + + FunctionCodegen.endVisit(mv, "equals", myClass); } - private void generateDataClassHashCodeMethod() { - // todo: this is fake implementation - + private void generateDataClassHashCodeMethod(List properties) { final MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "hashCode", "()I", null, null); - mv.visitVarInsn(ALOAD, 0); - mv.visitMethodInsn(INVOKESPECIAL, superClassAsmType.getInternalName(), "hashCode", "()I"); + final InstructionAdapter iv = new InstructionAdapter(mv); + + mv.visitCode(); + boolean first = true; + for (PropertyDescriptor propertyDescriptor : properties) { + if (!first) { + iv.iconst(31); + iv.mul(Type.INT_TYPE); + } + + genPropertyOnStack(iv, propertyDescriptor, 0); + + Label ifNull = null; + if (propertyDescriptor.getType().isNullable()) { + ifNull = new Label(); + + iv.dup(); + iv.ifnull(ifNull); + } + + genHashCode(mv, iv, typeMapper.mapType(propertyDescriptor.getType())); + + if (ifNull != null) { + Label end = new Label(); + iv.goTo(end); + iv.mark(ifNull); + iv.pop(); + iv.iconst(0); + iv.mark(end); + } + + if (first) { + first = false; + } + else { + iv.add(Type.INT_TYPE); + } + } + mv.visitInsn(IRETURN); - mv.visitMaxs(-1,-1); - mv.visitEnd(); + + FunctionCodegen.endVisit(mv, "hashCode", myClass); } - private void generateDataClassToStringMethod() { + private void generateDataClassToStringMethod(List properties) { final MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); final InstructionAdapter iv = new InstructionAdapter(mv); - mv.visitVarInsn(ALOAD, 0); - generateStringBuilderConstructor(iv); + mv.visitCode(); + genStringBuilderConstructor(iv); boolean first = true; - for (JetParameter parameter : getPrimaryConstructorParameters()) { - if (parameter.getValOrVarNode() == null) continue; - - PropertyDescriptor propertyDescriptor = state.getBindingContext().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter); - assert propertyDescriptor != null; - - if(first) { - iv.aconst(descriptor.getName() + "{" + propertyDescriptor.getName().getName()+"="); + for (PropertyDescriptor propertyDescriptor : properties) { + if (first) { + iv.aconst(descriptor.getName() + "(" + propertyDescriptor.getName().getName()+"="); first = false; } else { iv.aconst(", " + propertyDescriptor.getName().getName()+"="); } - CodegenUtil.invokeAppendMethod(iv, JAVA_STRING_TYPE); + genInvokeAppendMethod(iv, JAVA_STRING_TYPE); - iv.load(0, classAsmType); - - // todo: seems to be more correct - need to be changed in sync with 'componentX' generation and related tests - // final Method - // method = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); - // - // iv.invokevirtual(classAsmType.getInternalName(), method.getName(), method.getDescriptor()); - // final Type type = method.getReturnType(); - Type type = typeMapper.mapType(propertyDescriptor); - iv.getfield(classAsmType.getInternalName(), parameter.getName(), type.getDescriptor()); + Type type = genPropertyOnStack(iv, propertyDescriptor, 0); if (type.getSort() == Type.ARRAY) { final Type elementType = correctElementType(type); @@ -438,11 +556,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } } } - CodegenUtil.invokeAppendMethod(iv, type); + genInvokeAppendMethod(iv, type); } - iv.aconst("}"); - CodegenUtil.invokeAppendMethod(iv, JAVA_STRING_TYPE); + iv.aconst(")"); + genInvokeAppendMethod(iv, JAVA_STRING_TYPE); iv.invokevirtual("java/lang/StringBuilder", "toString", "()Ljava/lang/String;"); iv.areturn(JAVA_STRING_TYPE); @@ -450,6 +568,15 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { FunctionCodegen.endVisit(mv, "toString", myClass); } + private Type genPropertyOnStack(InstructionAdapter iv, PropertyDescriptor propertyDescriptor, int index) { + iv.load(index, classAsmType); + final Method + method = typeMapper.mapGetterSignature(propertyDescriptor, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod(); + + iv.invokevirtual(classAsmType.getInternalName(), method.getName(), method.getDescriptor()); + return method.getReturnType(); + } + private void generateComponentFunctionsForDataClasses() { if (!myClass.hasPrimaryConstructor() || !JetStandardLibrary.isData(descriptor)) return; @@ -468,10 +595,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { assert returnType != null : "Return type of component function should not be null: " + function; Type componentType = typeMapper.mapReturnType(returnType); + final String desc = "()" + componentType.getDescriptor(); MethodVisitor mv = v.newMethod(myClass, FunctionCodegen.getMethodAsmFlags(function, OwnerKind.IMPLEMENTATION), function.getName().getName(), - "()" + componentType.getDescriptor(), + desc, null, null); FunctionCodegen.genJetAnnotations(state, function, null, null, mv); @@ -480,7 +608,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { InstructionAdapter iv = new InstructionAdapter(mv); if (!componentType.equals(Type.VOID_TYPE)) { iv.load(0, classAsmType); - iv.getfield(classAsmType.getInternalName(), parameter.getName().getName(), componentType.getDescriptor()); + iv.invokevirtual(classAsmType.getInternalName(), PropertyCodegen.getterName(parameter.getName()), desc); } iv.areturn(componentType); @@ -543,7 +671,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { MethodVisitor mv = v.newMethod(null, ACC_BRIDGE | ACC_SYNTHETIC | ACC_STATIC, bridge.getName().getName(), method.getDescriptor(), null, null); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); @@ -588,7 +716,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { original, getter.getVisibility()); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); @@ -623,7 +751,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { original, setter.getVisibility()); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); @@ -665,7 +793,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { staticInitializerChunks.add(new CodeChunk() { @Override public void generate(InstructionAdapter iv) { - initSingletonField(myClass, classAsmType, v, iv); + genInitSingletonField(classAsmType, iv); } }); } @@ -711,7 +839,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { writeParameterAnnotations(constructorDescriptor, constructorMethod, hasThis0, mv); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); return; } @@ -1108,7 +1236,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { aw.visitEnd(); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubCode(mv); + genStubCode(mv); } else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { mv.visitCode(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/MemberCodegen.java index 420c64c3b75..dd642a4ba1f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/MemberCodegen.java @@ -20,22 +20,28 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.codegen.context.CodegenContext; import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationStateAware; -import org.jetbrains.jet.lang.psi.JetNamedFunction; -import org.jetbrains.jet.lang.psi.JetProperty; -import org.jetbrains.jet.lang.psi.JetTypeParameterListOwner; +import org.jetbrains.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.types.ErrorUtils; + +import java.util.Map; + +import static org.jetbrains.jet.codegen.binding.CodegenBinding.enumEntryNeedSubclass; /** - * @author Stepan Koltsov + * @author alex.tkachman */ public class MemberCodegen extends GenerationStateAware { - public MemberCodegen(@NotNull GenerationState state) { super(state); } - public void generateFunctionOrProperty( + public void genFunctionOrProperty( + CodegenContext context, @NotNull JetTypeParameterListOwner functionOrProperty, - @NotNull CodegenContext context, @NotNull ClassBuilder classBuilder + @NotNull ClassBuilder classBuilder ) { FunctionCodegen functionCodegen = new FunctionCodegen(context, classBuilder, state); if (functionOrProperty instanceof JetNamedFunction) { @@ -64,4 +70,76 @@ public class MemberCodegen extends GenerationStateAware { throw new IllegalArgumentException("Unknown parameter: " + functionOrProperty); } } + + public static void genImplementation( + CodegenContext context, + GenerationState state, + JetClassOrObject aClass, + OwnerKind kind, + Map accessors, + ClassBuilder classBuilder + ) { + ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass); + CodegenContext classContext = context.intoClass(descriptor, kind, state); + classContext.copyAccessors(accessors); + + new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate(); + + if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) { + ClassBuilder traitBuilder = state.getFactory().forTraitImplementation(descriptor, state); + new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state), traitBuilder, state) + .generate(); + traitBuilder.done(); + } + } + + public void genInners(CodegenContext context, GenerationState state, JetClassOrObject aClass) { + for (JetDeclaration declaration : aClass.getDeclarations()) { + if (declaration instanceof JetClass) { + if (declaration instanceof JetEnumEntry && !enumEntryNeedSubclass( + state.getBindingContext(), (JetEnumEntry) declaration)) { + continue; + } + + genClassOrObject(context, (JetClass) declaration); + } + else if (declaration instanceof JetClassObject) { + genClassOrObject(context, ((JetClassObject) declaration).getObjectDeclaration()); + } + else if (declaration instanceof JetObjectDeclaration) { + genClassOrObject(context, (JetObjectDeclaration) declaration); + } + } + } + + public void genClassOrObject(CodegenContext context, JetClassOrObject aClass) { + ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass); + + if (descriptor == null || ErrorUtils.isError(descriptor) || descriptor.getName().equals(JetPsiUtil.NO_NAME_PROVIDED)) { + if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES) { + throw new IllegalStateException( + "Generating bad descriptor in ClassBuilderMode = " + state.getClassBuilderMode() + ": " + descriptor); + } + return; + } + + ClassBuilder classBuilder = state.getFactory().forClassImplementation(descriptor); + + final CodegenContext contextForInners = context.intoClass(descriptor, OwnerKind.IMPLEMENTATION, state); + + if (state.getClassBuilderMode() == ClassBuilderMode.SIGNATURES) { + // Outer class implementation must happen prior inner classes so we get proper scoping tree in JetLightClass's delegate + // The same code is present below for the case when we genClassOrObject real bytecode. This is because the order should be + // different for the case when we compute closures + genImplementation(context, state, aClass, OwnerKind.IMPLEMENTATION, contextForInners.getAccessors(), classBuilder); + } + + genInners(contextForInners, state, aClass); + + if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES) { + genImplementation(context, state, aClass, OwnerKind.IMPLEMENTATION, contextForInners.getAccessors(), classBuilder); + } + + classBuilder.done(); + } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java index fea22cdf3cf..018e4ca7281 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java @@ -28,7 +28,6 @@ import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.jet.codegen.binding.CodegenBinding; import org.jetbrains.jet.codegen.context.CodegenContext; import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.state.GenerationStateAware; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; @@ -48,7 +47,7 @@ import static org.jetbrains.asm4.Opcodes.*; /** * @author max */ -public class NamespaceCodegen extends GenerationStateAware { +public class NamespaceCodegen extends MemberCodegen { @NotNull private final ClassBuilderOnDemand v; @NotNull private final FqName name; @@ -128,19 +127,17 @@ public class NamespaceCodegen extends GenerationStateAware { for (JetDeclaration declaration : file.getDeclarations()) { if (declaration instanceof JetProperty) { final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor); - state.getMemberCodegen().generateFunctionOrProperty( - (JetTypeParameterListOwner) declaration, context, v.getClassBuilder()); + genFunctionOrProperty(context, (JetTypeParameterListOwner) declaration, v.getClassBuilder()); } else if (declaration instanceof JetNamedFunction) { if (!multiFile) { final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor); - state.getMemberCodegen().generateFunctionOrProperty( - (JetTypeParameterListOwner) declaration, context, v.getClassBuilder()); + genFunctionOrProperty(context, (JetTypeParameterListOwner) declaration, v.getClassBuilder()); } } else if (declaration instanceof JetClassOrObject) { final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor); - state.getClassCodegen().generate(context, (JetClassOrObject) declaration); + genClassOrObject(context, (JetClassOrObject) declaration); } else if (declaration instanceof JetScript) { state.getScriptCodegen().generate((JetScript) declaration); @@ -157,7 +154,7 @@ public class NamespaceCodegen extends GenerationStateAware { if (k > 0) { PsiFile containingFile = file.getContainingFile(); - String namespaceInternalName = name.child(Name.identifier(JvmAbi.PACKAGE_CLASS)).getFqName().replace('.', '/'); + String namespaceInternalName = JvmClassName.byFqNameWithoutInnerClasses(name.child(Name.identifier(JvmAbi.PACKAGE_CLASS))).getInternalName(); String className = getMultiFileNamespaceInternalName(namespaceInternalName, containingFile); ClassBuilder builder = state.getFactory().forNamespacepart(className); @@ -176,14 +173,12 @@ public class NamespaceCodegen extends GenerationStateAware { { final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor); - state.getMemberCodegen() - .generateFunctionOrProperty((JetTypeParameterListOwner) declaration, context, builder); + genFunctionOrProperty(context, (JetTypeParameterListOwner) declaration, builder); } { final CodegenContext context = CodegenContext.STATIC.intoNamespacePart(className, descriptor); - state.getMemberCodegen() - .generateFunctionOrProperty((JetTypeParameterListOwner) declaration, context, v.getClassBuilder()); + genFunctionOrProperty(context, (JetTypeParameterListOwner) declaration, v.getClassBuilder()); } } } @@ -287,7 +282,7 @@ public class NamespaceCodegen extends GenerationStateAware { return JvmClassName.byInternalName(JvmAbi.PACKAGE_CLASS); } - return JvmClassName.byInternalName(fqName.getFqName().replace('.', '/') + "/" + JvmAbi.PACKAGE_CLASS); + return JvmClassName.byFqNameWithoutInnerClasses(fqName.child(Name.identifier(JvmAbi.PACKAGE_CLASS))); } @NotNull diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java index 507d9f69e23..d58c281f40a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -24,6 +24,7 @@ import org.jetbrains.asm4.MethodVisitor; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.jet.codegen.context.CodegenContext; +import org.jetbrains.jet.codegen.signature.JvmMethodSignature; import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature; import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter; import org.jetbrains.jet.codegen.state.GenerationStateAware; @@ -41,6 +42,8 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import java.util.BitSet; import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.AsmUtil.genStubThrow; +import static org.jetbrains.jet.codegen.AsmUtil.getVisibilityAccessFlag; import static org.jetbrains.jet.codegen.CodegenUtil.*; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; @@ -192,12 +195,13 @@ public class PropertyCodegen extends GenerationStateAware { } JvmPropertyAccessorSignature signature = typeMapper.mapGetterSignature(propertyDescriptor, kind); - final String descriptor = signature.getJvmMethodSignature().getAsmMethod().getDescriptor(); + final JvmMethodSignature jvmMethodSignature = signature.getJvmMethodSignature(); + final String descriptor = jvmMethodSignature.getAsmMethod().getDescriptor(); String getterName = getterName(propertyDescriptor.getName()); - MethodVisitor mv = v.newMethod(origin, flags, getterName, descriptor, null, null); + MethodVisitor mv = v.newMethod(origin, flags, getterName, descriptor, jvmMethodSignature.getGenericsSignature(), null); PropertyGetterDescriptor getter = propertyDescriptor.getGetter(); generateJetPropertyAnnotation(mv, signature.getPropertyTypeKotlinSignature(), - signature.getJvmMethodSignature().getKotlinTypeParameter(), propertyDescriptor, + jvmMethodSignature.getKotlinTypeParameter(), propertyDescriptor, getter == null ? propertyDescriptor.getVisibility() : getter.getVisibility()); @@ -212,7 +216,7 @@ public class PropertyCodegen extends GenerationStateAware { if (propertyDescriptor.getModality() != Modality.ABSTRACT) { mv.visitCode(); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubThrow(mv); + genStubThrow(mv); } else { InstructionAdapter iv = new InstructionAdapter(mv); @@ -298,12 +302,13 @@ public class PropertyCodegen extends GenerationStateAware { JvmPropertyAccessorSignature signature = typeMapper.mapSetterSignature(propertyDescriptor, kind); assert true; - final String descriptor = signature.getJvmMethodSignature().getAsmMethod().getDescriptor(); - MethodVisitor mv = v.newMethod(origin, flags, setterName(propertyDescriptor.getName()), descriptor, null, null); + final JvmMethodSignature jvmMethodSignature = signature.getJvmMethodSignature(); + final String descriptor = jvmMethodSignature.getAsmMethod().getDescriptor(); + MethodVisitor mv = v.newMethod(origin, flags, setterName(propertyDescriptor.getName()), descriptor, jvmMethodSignature.getGenericsSignature(), null); PropertySetterDescriptor setter = propertyDescriptor.getSetter(); assert setter != null; generateJetPropertyAnnotation(mv, signature.getPropertyTypeKotlinSignature(), - signature.getJvmMethodSignature().getKotlinTypeParameter(), propertyDescriptor, + jvmMethodSignature.getKotlinTypeParameter(), propertyDescriptor, setter.getVisibility()); assert !setter.hasBody(); @@ -313,7 +318,7 @@ public class PropertyCodegen extends GenerationStateAware { if (propertyDescriptor.getModality() != Modality.ABSTRACT) { mv.visitCode(); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { - StubCodegen.generateStubThrow(mv); + genStubThrow(mv); } else { InstructionAdapter iv = new InstructionAdapter(mv); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/RangeCodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/RangeCodegenUtil.java index 503e47984cc..ac18e591bff 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/RangeCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/RangeCodegenUtil.java @@ -27,6 +27,8 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.isPrimitiveNumberClassDescriptor; + /** * @author abreslav */ @@ -91,7 +93,7 @@ public class RangeCodegenUtil { public static boolean isOptimizableRangeTo(CallableDescriptor rangeTo) { if ("rangeTo".equals(rangeTo.getName().getName())) { - if (CodegenUtil.isPrimitiveNumberClassDescriptor(rangeTo.getContainingDeclaration())) { + if (isPrimitiveNumberClassDescriptor(rangeTo.getContainingDeclaration())) { return true; } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java index b7026d1c5f6..11155696bbd 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java @@ -27,7 +27,6 @@ import org.jetbrains.jet.codegen.context.CodegenContext; import org.jetbrains.jet.codegen.context.ScriptContext; import org.jetbrains.jet.codegen.signature.JvmMethodSignature; import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.state.GenerationStateAware; import org.jetbrains.jet.codegen.state.GenerationStrategy; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ScriptDescriptor; @@ -42,18 +41,16 @@ import java.util.Collections; import java.util.List; import static org.jetbrains.asm4.Opcodes.*; -import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; import static org.jetbrains.jet.codegen.binding.CodegenBinding.*; +import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; /** * @author Stepan Koltsov */ -public class ScriptCodegen extends GenerationStateAware { +public class ScriptCodegen extends MemberCodegen { @NotNull private ClassFileFactory classFileFactory; - @NotNull - private MemberCodegen memberCodegen; private List earlierScripts; private Method scriptConstructorMethod; @@ -67,11 +64,6 @@ public class ScriptCodegen extends GenerationStateAware { this.classFileFactory = classFileFactory; } - @Inject - public void setMemberCodegen(@NotNull MemberCodegen memberCodegen) { - this.memberCodegen = memberCodegen; - } - public void generate(JetScript scriptDeclaration) { ScriptDescriptor scriptDescriptor = state.getBindingContext().get(BindingContext.SCRIPT, scriptDeclaration); @@ -209,7 +201,7 @@ public class ScriptCodegen extends GenerationStateAware { private void genMembers(@NotNull JetScript scriptDeclaration, @NotNull CodegenContext context, @NotNull ClassBuilder classBuilder) { for (JetDeclaration decl : scriptDeclaration.getDeclarations()) { - memberCodegen.generateFunctionOrProperty((JetTypeParameterListOwner) decl, context, classBuilder); + genFunctionOrProperty(context, (JetTypeParameterListOwner) decl, classBuilder); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 7cdfb63349c..6e0307c9145 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -39,6 +39,8 @@ import org.jetbrains.jet.lexer.JetTokens; import java.util.List; import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.AsmUtil.boxType; +import static org.jetbrains.jet.codegen.AsmUtil.isIntPrimitive; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.*; /** @@ -61,7 +63,7 @@ public abstract class StackValue { instructionAdapter.aconst(null); } else { - Type boxed = CodegenUtil.boxType(type); + Type boxed = boxType(type); instructionAdapter.invokestatic(boxed.getInternalName(), "valueOf", "(" + type.getDescriptor() + ")" + boxed.getDescriptor()); } } @@ -76,7 +78,7 @@ public abstract class StackValue { * JVM stack after this value was generated. * * @param type the type as which the value should be put - * @param v the visitor used to generate the instructions + * @param v the visitor used to genClassOrObject the instructions * @param depth the number of new values put onto the stack */ protected void moveToTopOfStack(Type type, InstructionAdapter v, int depth) { @@ -99,7 +101,7 @@ public abstract class StackValue { public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) { put(this.type, v); - coerce(Type.BOOLEAN_TYPE, v); + coerceTo(Type.BOOLEAN_TYPE, v); if (jumpIfFalse) { v.ifeq(label); } @@ -171,7 +173,7 @@ public abstract class StackValue { private static void box(final Type type, final Type toType, InstructionAdapter v) { // TODO handle toType correctly - if (type == Type.INT_TYPE || (CodegenUtil.isIntPrimitive(type) && toType.getInternalName().equals("java/lang/Integer"))) { + if (type == Type.INT_TYPE || (isIntPrimitive(type) && toType.getInternalName().equals("java/lang/Integer"))) { v.invokestatic("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;"); } else if (type == Type.BOOLEAN_TYPE) { @@ -231,7 +233,7 @@ public abstract class StackValue { v.checkcast(type); } else { - coerce(type, v); + coerceTo(type, v); } } @@ -244,11 +246,15 @@ public abstract class StackValue { } } - protected void coerce(Type toType, InstructionAdapter v) { + protected void coerceTo(Type toType, InstructionAdapter v) { coerce(this.type, toType, v); } - protected static void coerce(Type fromType, Type toType, InstructionAdapter v) { + protected void coerceFrom(Type topOfStackType, InstructionAdapter v) { + coerce(topOfStackType, this.type, v); + } + + public static void coerce(Type fromType, Type toType, InstructionAdapter v) { if (toType.equals(fromType)) return; if (toType.getSort() == Type.VOID && fromType.getSort() != Type.VOID) { @@ -306,7 +312,7 @@ public abstract class StackValue { } public static void putTuple0Instance(InstructionAdapter v) { - v.visitFieldInsn(GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;"); + v.visitFieldInsn(GETSTATIC, "jet/Tuple0", "VALUE", "Ljet/Tuple0;"); } protected void putAsBoolean(InstructionAdapter v) { @@ -382,7 +388,7 @@ public abstract class StackValue { @Override public void put(Type type, InstructionAdapter v) { - coerce(type, v); + coerceTo(type, v); } } @@ -401,13 +407,13 @@ public abstract class StackValue { @Override public void put(Type type, InstructionAdapter v) { v.load(index, this.type); - coerce(type, v); + coerceTo(type, v); // TODO unbox } @Override public void store(Type topOfStackType, InstructionAdapter v) { - coerce(topOfStackType, this.type, v); + coerceFrom(topOfStackType, v); v.store(index, this.type); } } @@ -419,7 +425,7 @@ public abstract class StackValue { @Override public void put(Type type, InstructionAdapter v) { - coerce(type, v); + coerceTo(type, v); } @Override @@ -465,7 +471,7 @@ public abstract class StackValue { else { v.aconst(value); } - coerce(type, v); + coerceTo(type, v); } @Override @@ -610,18 +616,18 @@ public abstract class StackValue { public ArrayElement(Type type, boolean unbox) { super(type); - this.boxed = unbox ? CodegenUtil.boxType(type) : type; + this.boxed = unbox ? boxType(type) : type; } @Override public void put(Type type, InstructionAdapter v) { v.aload(boxed); // assumes array and index are on the stack - onStack(boxed).coerce(type, v); + coerce(boxed, type, v); } @Override public void store(Type topOfStackType, InstructionAdapter v) { - onStack(type).coerce(boxed, v); + coerce(topOfStackType, boxed, v); v.astore(boxed); } @@ -677,7 +683,7 @@ public abstract class StackValue { else { ((IntrinsicMethod) getter).generate(codegen, v, type, null, null, null, state); } - coerce(type, v); + coerceTo(type, v); } @Override @@ -901,7 +907,7 @@ public abstract class StackValue { @Override public void put(Type type, InstructionAdapter v) { v.visitFieldInsn(isStatic ? GETSTATIC : GETFIELD, owner.getInternalName(), name, this.type.getDescriptor()); - coerce(type, v); + coerceTo(type, v); } @Override @@ -918,7 +924,7 @@ public abstract class StackValue { @Override public void store(Type topOfStackType, InstructionAdapter v) { - coerce(topOfStackType, this.type, v); + coerceFrom(topOfStackType, v); v.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD, owner.getInternalName(), name, this.type.getDescriptor()); } } @@ -976,11 +982,12 @@ public abstract class StackValue { v.visitMethodInsn(invokeOpcode, methodOwner.getInternalName(), getter.getName(), getter.getDescriptor()); } } - coerce(type, v); + coerceTo(type, v); } @Override public void store(Type topOfStackType, InstructionAdapter v) { + coerceFrom(topOfStackType, v); if (isSuper && isInterface) { assert setter != null; v.visitMethodInsn(INVOKESTATIC, methodOwner.getInternalName(), setter.getName(), @@ -1047,8 +1054,8 @@ public abstract class StackValue { Type refType = refType(this.type); Type sharedType = sharedTypeForType(this.type); v.visitFieldInsn(GETFIELD, sharedType.getInternalName(), "ref", refType.getDescriptor()); - coerce(refType, this.type, v); - coerce(this.type, type, v); + coerceFrom(refType, v); + coerceTo(type, v); if (isReleaseOnPut) { v.aconst(null); v.store(index, OBJECT_TYPE); @@ -1057,6 +1064,7 @@ public abstract class StackValue { @Override public void store(Type topOfStackType, InstructionAdapter v) { + coerceFrom(topOfStackType, v); v.load(index, OBJECT_TYPE); v.swap(); Type refType = refType(this.type); @@ -1133,13 +1141,13 @@ public abstract class StackValue { Type sharedType = sharedTypeForType(this.type); Type refType = refType(this.type); v.visitFieldInsn(GETFIELD, sharedType.getInternalName(), "ref", refType.getDescriptor()); - StackValue.onStack(refType).coerce(this.type, v); - StackValue.onStack(this.type).coerce(type, v); + coerceFrom(refType, v); + coerceTo(type, v); } @Override public void store(Type topOfStackType, InstructionAdapter v) { - coerce(topOfStackType, v); + coerceFrom(topOfStackType, v); v.visitFieldInsn(PUTFIELD, sharedTypeForType(type).getInternalName(), "ref", refType(type).getDescriptor()); } } @@ -1200,7 +1208,7 @@ public abstract class StackValue { public void put(Type type, InstructionAdapter v) { if (!type.equals(Type.VOID_TYPE)) { v.load(index, Type.INT_TYPE); - coerce(type, v); + coerceTo(type, v); } v.iinc(index, increment); } @@ -1221,7 +1229,7 @@ public abstract class StackValue { v.iinc(index, increment); if (!type.equals(Type.VOID_TYPE)) { v.load(index, Type.INT_TYPE); - coerce(type, v); + coerceTo(type, v); } } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StubCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/StubCodegen.java deleted file mode 100644 index 7647dd34b4e..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StubCodegen.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.codegen; - -import org.jetbrains.asm4.MethodVisitor; - -import static org.jetbrains.jet.codegen.CodegenUtil.generateMethodThrow; -import static org.jetbrains.jet.codegen.CodegenUtil.generateThrow; - -/** - * @author Stepan Koltsov - */ -public class StubCodegen { - private static final String STUB_EXCEPTION = "java/lang/RuntimeException"; - private static final String STUB_EXCEPTION_MESSAGE = "Stubs are for compiler only, do not add them to runtime classpath"; - - private StubCodegen() { - } - - public static void generateStubThrow(MethodVisitor mv) { - generateThrow(mv, STUB_EXCEPTION, STUB_EXCEPTION_MESSAGE); - } - - public static void generateStubCode(MethodVisitor mv) { - generateMethodThrow(mv, STUB_EXCEPTION, STUB_EXCEPTION_MESSAGE); - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java index 0fa149521b3..977822ddbfc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java @@ -115,7 +115,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid { nameStack.push(classNameForScriptPsi(bindingContext, file.getScript()).getInternalName()); } else { - nameStack.push(JetPsiUtil.getFQName(file).getFqName().replace('.', '/')); + nameStack.push(JvmClassName.byFqNameWithoutInnerClasses(JetPsiUtil.getFQName(file)).getInternalName()); } file.acceptChildren(this); nameStack.pop(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java index b3e59571d47..d040c981f77 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java @@ -19,7 +19,6 @@ package org.jetbrains.jet.codegen.binding; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.psi.*; @@ -39,6 +38,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import static org.jetbrains.jet.codegen.CodegenUtil.isInterface; import static org.jetbrains.jet.lang.resolve.BindingContext.*; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration; @@ -365,7 +365,7 @@ public class CodegenBinding { assert superType != null; ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor(); assert superClassDescriptor != null; - if (!CodegenUtil.isInterface(superClassDescriptor)) { + if (!isInterface(superClassDescriptor)) { return (JetDelegatorToSuperCall) specifier; } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java index d208e444554..472474965fc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java @@ -31,6 +31,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import static org.jetbrains.jet.codegen.AsmUtil.THIS$0; import static org.jetbrains.jet.codegen.binding.CodegenBinding.CLASS_FOR_FUNCTION; import static org.jetbrains.jet.codegen.binding.CodegenBinding.FQN; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; @@ -261,7 +262,7 @@ public abstract class CodegenContext { final ClassDescriptor enclosingClass = getEnclosingClass(); outerExpression = enclosingClass != null ? StackValue - .field(typeMapper.mapType(enclosingClass), CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor), CodegenUtil.THIS$0, + .field(typeMapper.mapType(enclosingClass), CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor), THIS$0, false) : null; } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/LocalLookup.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/LocalLookup.java index 8722a0fd971..ff175602566 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/LocalLookup.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/LocalLookup.java @@ -17,7 +17,6 @@ package org.jetbrains.jet.codegen.context; import org.jetbrains.asm4.Type; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.binding.MutableClosure; @@ -27,6 +26,7 @@ import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.types.JetType; +import static org.jetbrains.jet.codegen.AsmUtil.RECEIVER$0; import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass; import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration; @@ -122,7 +122,7 @@ public interface LocalLookup { final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType(); Type type = state.getTypeMapper().mapType(receiverType); - StackValue innerValue = StackValue.field(type, className, CodegenUtil.RECEIVER$0, false); + StackValue innerValue = StackValue.field(type, className, RECEIVER$0, false); closure.setCaptureReceiver(); return innerValue; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayGet.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayGet.java index 68c154e04e7..1e1afa1c699 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayGet.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayGet.java @@ -20,15 +20,16 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.lang.psi.JetExpression; +import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.correctElementType; + /** * @author alex.tkachman */ @@ -44,7 +45,7 @@ public class ArrayGet implements IntrinsicMethod { @NotNull GenerationState state ) { receiver.put(AsmTypeConstants.OBJECT_TYPE, v); - Type type = CodegenUtil.correctElementType(receiver.type); + Type type = correctElementType(receiver.type); codegen.gen(arguments.get(0), Type.INT_TYPE); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySet.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySet.java index 082c54ca469..b6d55db6c64 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySet.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySet.java @@ -20,15 +20,16 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.lang.psi.JetExpression; +import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.correctElementType; + /** * @author alex.tkachman */ @@ -44,7 +45,7 @@ public class ArraySet implements IntrinsicMethod { @NotNull GenerationState state ) { receiver.put(AsmTypeConstants.OBJECT_TYPE, v); - Type type = CodegenUtil.correctElementType(receiver.type); + Type type = correctElementType(receiver.type); codegen.gen(arguments.get(0), Type.INT_TYPE); codegen.gen(arguments.get(1), type); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.java index 8d334a137e3..e71753f5d86 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.java @@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; @@ -29,6 +28,8 @@ import org.jetbrains.jet.lang.psi.JetExpression; import java.util.List; import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.AsmUtil.boxType; +import static org.jetbrains.jet.codegen.AsmUtil.unboxType; /** * @author yole @@ -52,7 +53,7 @@ public class BinaryOp implements IntrinsicMethod { ) { boolean nullable = expectedType.getSort() == Type.OBJECT; if (nullable) { - expectedType = CodegenUtil.unboxType(expectedType); + expectedType = unboxType(expectedType); } if (arguments.size() == 1) { // Intrinsic is called as an ordinary function @@ -68,7 +69,7 @@ public class BinaryOp implements IntrinsicMethod { v.visitInsn(expectedType.getOpcode(opcode)); if (nullable) { - StackValue.onStack(expectedType).put(expectedType = CodegenUtil.boxType(expectedType), v); + StackValue.onStack(expectedType).put(expectedType = boxType(expectedType), v); } return StackValue.onStack(expectedType); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Concat.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Concat.java index f488a74cb3a..753f8ff037b 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Concat.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Concat.java @@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; @@ -29,6 +28,9 @@ import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.genInvokeAppendMethod; +import static org.jetbrains.jet.codegen.AsmUtil.genStringBuilderConstructor; + /** * @author yole */ @@ -44,15 +46,15 @@ public class Concat implements IntrinsicMethod { @NotNull GenerationState state ) { if (receiver == null || receiver == StackValue.none()) { // LHS + RHS - CodegenUtil.generateStringBuilderConstructor(v); + genStringBuilderConstructor(v); codegen.invokeAppend(arguments.get(0)); // StringBuilder(LHS) codegen.invokeAppend(arguments.get(1)); } else { // LHS.plus(RHS) receiver.put(AsmTypeConstants.OBJECT_TYPE, v); - CodegenUtil.generateStringBuilderConstructor(v); + genStringBuilderConstructor(v); v.swap(); // StringBuilder LHS - CodegenUtil.invokeAppendMethod(v, expectedType); // StringBuilder(LHS) + genInvokeAppendMethod(v, expectedType); // StringBuilder(LHS) codegen.invokeAppend(arguments.get(0)); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.java index 4a3a0a3e876..94908a802d8 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.java @@ -20,18 +20,20 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.lang.psi.JetCallExpression; import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lexer.JetTokens; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.genEqualsForExpressionsOnStack; + /** * @author alex.tkachman */ @@ -74,8 +76,8 @@ public class Equals implements IntrinsicMethod { codegen.gen(rightExpr).put(AsmTypeConstants.OBJECT_TYPE, v); assert rightType != null; - return codegen - .generateEqualsForExpressionsOnStack(JetTokens.EQEQ, AsmTypeConstants.OBJECT_TYPE, AsmTypeConstants.OBJECT_TYPE, leftNullable, - rightType.isNullable()); + return genEqualsForExpressionsOnStack(v, JetTokens.EQEQ, AsmTypeConstants.OBJECT_TYPE, AsmTypeConstants.OBJECT_TYPE, + leftNullable, + rightType.isNullable()); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java index 04063d3160d..d20ef90ee3c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java @@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; @@ -30,6 +29,8 @@ import org.jetbrains.jet.lang.psi.JetReferenceExpression; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.*; + /** * @author yole */ @@ -52,7 +53,7 @@ public class Increment implements IntrinsicMethod { ) { boolean nullable = expectedType.getSort() == Type.OBJECT; if (nullable) { - expectedType = CodegenUtil.unboxType(expectedType); + expectedType = unboxType(expectedType); } if (arguments.size() > 0) { JetExpression operand = arguments.get(0); @@ -61,7 +62,7 @@ public class Increment implements IntrinsicMethod { } if (operand instanceof JetReferenceExpression) { final int index = codegen.indexOfLocal((JetReferenceExpression) operand); - if (index >= 0 && CodegenUtil.isIntPrimitive(expectedType)) { + if (index >= 0 && isIntPrimitive(expectedType)) { return StackValue.preIncrement(index, myDelta); } } @@ -70,30 +71,13 @@ public class Increment implements IntrinsicMethod { value.dupReceiver(v); value.put(expectedType, v); - plusMinus(v, expectedType); - value.store(expectedType, v); + value.store(genIncrement(expectedType, myDelta, v), v); value.put(expectedType, v); } else { receiver.put(expectedType, v); - plusMinus(v, expectedType); + StackValue.coerce(genIncrement(expectedType, myDelta, v), expectedType, v); } return StackValue.onStack(expectedType); } - - private void plusMinus(InstructionAdapter v, Type expectedType) { - if (expectedType == Type.LONG_TYPE) { - v.lconst(myDelta); - } - else if (expectedType == Type.FLOAT_TYPE) { - v.fconst(myDelta); - } - else if (expectedType == Type.DOUBLE_TYPE) { - v.dconst(myDelta); - } - else { - v.iconst(myDelta); - } - v.add(expectedType); - } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java index ed4749b5556..4eea52b6ca4 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java @@ -66,7 +66,7 @@ public class IntrinsicMethods { private static final String KOTLIN_HASH_CODE = "kotlin.hashCode"; private static final EnumValues ENUM_VALUES = new EnumValues(); private static final EnumValueOf ENUM_VALUE_OF = new EnumValueOf(); - public static final ToString TO_STRING = new ToString(); + private static final ToString TO_STRING = new ToString(); private final Map namedMethods = new HashMap(); private static final IntrinsicMethod ARRAY_ITERATOR = new ArrayIterator(); @@ -127,7 +127,6 @@ public class IntrinsicMethods { intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("identityEquals"), 1, IDENTITY_EQUALS); intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("plus"), 1, STRING_PLUS); intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("arrayOfNulls"), 1, new NewArray()); - intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("sure"), 0, new Sure()); intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("synchronized"), 2, new StupidSync()); intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("iterator"), 0, new IteratorIterator()); @@ -149,16 +148,25 @@ public class IntrinsicMethods { declareIntrinsicProperty(Name.identifier("CharSequence"), Name.identifier("length"), new StringLength()); declareIntrinsicProperty(Name.identifier("String"), Name.identifier("length"), new StringLength()); + Name tuple0Name = JetStandardClasses.getTuple(0).getName(); + intrinsicsMap.registerIntrinsic( + getClassObjectFqName(tuple0Name), + Name.identifier("VALUE"), -1, new UnitValue()); + for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) { intrinsicsMap.registerIntrinsic( - JetStandardClasses.STANDARD_CLASSES_FQNAME.child(type.getRangeTypeName()).toUnsafe().child( - getClassObjectName(type.getRangeTypeName())), + getClassObjectFqName(type.getRangeTypeName()), Name.identifier("EMPTY"), -1, new EmptyRange(type)); } declareArrayMethods(); } + @NotNull + private static FqNameUnsafe getClassObjectFqName(@NotNull Name builtinClassName) { + return JetStandardClasses.STANDARD_CLASSES_FQNAME.child(builtinClassName).toUnsafe().child(getClassObjectName(builtinClassName)); + } + private void declareArrayMethods() { for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Inv.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Inv.java index 9e55d256b00..5a5a02c6cf0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Inv.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Inv.java @@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; @@ -28,6 +27,8 @@ import org.jetbrains.jet.lang.psi.JetExpression; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.unboxType; + /** * @author yole * @author alex.tkachman @@ -45,7 +46,7 @@ public class Inv implements IntrinsicMethod { ) { boolean nullable = expectedType.getSort() == Type.OBJECT; if (nullable) { - expectedType = CodegenUtil.unboxType(expectedType); + expectedType = unboxType(expectedType); } receiver.put(expectedType, v); if (expectedType == Type.LONG_TYPE) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.java index 32add939d89..87419ad3a33 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.java @@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; @@ -28,6 +27,8 @@ import org.jetbrains.jet.lang.psi.JetExpression; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.genToString; + /** * @author alex.tkachman */ @@ -42,6 +43,6 @@ public class ToString implements IntrinsicMethod { StackValue receiver, @NotNull GenerationState state ) { - return CodegenUtil.genToString(v, receiver); + return genToString(v, receiver); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java index 91b534a3455..6efdc40f120 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java @@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; @@ -28,6 +27,9 @@ import org.jetbrains.jet.lang.psi.JetExpression; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.genNegate; +import static org.jetbrains.jet.codegen.AsmUtil.unboxType; + /** * @author yole */ @@ -44,7 +46,7 @@ public class UnaryMinus implements IntrinsicMethod { ) { boolean nullable = expectedType.getSort() == Type.OBJECT; if (nullable) { - expectedType = CodegenUtil.unboxType(expectedType); + expectedType = unboxType(expectedType); } if (arguments.size() == 1) { codegen.gen(arguments.get(0), expectedType); @@ -52,7 +54,7 @@ public class UnaryMinus implements IntrinsicMethod { else { receiver.put(expectedType, v); } - v.neg(expectedType); + StackValue.coerce(genNegate(expectedType, v), expectedType, v); return StackValue.onStack(expectedType); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java index 362df6fa695..e2f0350bea3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java @@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; @@ -29,6 +28,8 @@ import org.jetbrains.jet.lang.psi.JetExpression; import java.util.List; +import static org.jetbrains.jet.codegen.AsmUtil.unboxType; + /** * @author alex.tkachman */ @@ -45,7 +46,7 @@ public class UnaryPlus implements IntrinsicMethod { ) { boolean nullable = expectedType.getSort() == Type.OBJECT; if (nullable) { - expectedType = CodegenUtil.unboxType(expectedType); + expectedType = unboxType(expectedType); } if (receiver != null && receiver != StackValue.none()) { receiver.put(expectedType, v); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Sure.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnitValue.java similarity index 53% rename from compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Sure.java rename to compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnitValue.java index 537af1349a4..3a74c0d465a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Sure.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnitValue.java @@ -18,50 +18,34 @@ package org.jetbrains.jet.codegen.intrinsics; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; -import org.jetbrains.asm4.Label; +import org.jetbrains.annotations.Nullable; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.lang.descriptors.CallableDescriptor; -import org.jetbrains.jet.lang.psi.JetCallExpression; import org.jetbrains.jet.lang.psi.JetExpression; -import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; import java.util.List; +import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JET_TUPLE0_TYPE; + /** - * @author alex.tkachman + * @author abreslav */ -public class Sure implements IntrinsicMethod { +public class UnitValue implements IntrinsicMethod { + @Override public StackValue generate( ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type expectedType, - PsiElement element, - List arguments, + @Nullable PsiElement element, + @Nullable List arguments, StackValue receiver, @NotNull GenerationState state ) { - JetCallExpression call = (JetCallExpression) element; - ResolvedCall resolvedCall = - codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression()); - assert resolvedCall != null; - if (resolvedCall.getReceiverArgument().getType().isNullable()) { - receiver.put(receiver.type, v); - v.dup(); - Label ok = new Label(); - v.ifnonnull(ok); - v.invokestatic("jet/runtime/Intrinsics", "throwNpe", "()V"); - v.mark(ok); - StackValue.onStack(receiver.type).put(expectedType, v); - } - else { - codegen.generateFromResolvedCall(resolvedCall.getReceiverArgument(), expectedType); - } + v.getstatic(JET_TUPLE0_TYPE.getInternalName(), "VALUE", JET_TUPLE0_TYPE.getDescriptor()); return StackValue.onStack(expectedType); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java b/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java index f6bb057ba5a..b8e2bc6edc0 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java @@ -152,19 +152,22 @@ public class BothSignatureWriter { state = to; } + public void writeAsmType(Type asmType, boolean nullable) { + writeAsmType(asmType, nullable, null); + } /** * Shortcut */ - public void writeAsmType(Type asmType, boolean nullable) { + public void writeAsmType(Type asmType, boolean nullable, @Nullable String kotlinTypeName) { switch (asmType.getSort()) { case Type.OBJECT: - writeClassBegin(asmType.getInternalName(), nullable, false); + writeClassBegin(asmType.getInternalName(), nullable, false, kotlinTypeName); writeClassEnd(); return; case Type.ARRAY: writeArrayType(nullable); - writeAsmType(asmType.getElementType(), false); + writeAsmType(asmType.getElementType(), false, kotlinTypeName); writeArrayEnd(); return; default: @@ -218,8 +221,12 @@ public class BothSignatureWriter { } public void writeClassBegin(String internalName, boolean nullable, boolean real) { + writeClassBegin(internalName, nullable, real, null); + } + + public void writeClassBegin(String internalName, boolean nullable, boolean real, @Nullable String kotlinTypeName) { signatureVisitor().visitClassType(internalName); - jetSignatureWriter.visitClassType(internalName, nullable, real); + jetSignatureWriter.visitClassType(kotlinTypeName == null ? internalName : kotlinTypeName, nullable, real); writeAsmType0(Type.getObjectType(internalName)); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java index b750818b2a3..8ef4e9be8a1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java @@ -68,12 +68,6 @@ public class GenerationState { @NotNull private final JetTypeMapper typeMapper; - @NotNull - private final MemberCodegen memberCodegen; - - @NotNull - private final ClassCodegen classCodegen; - public GenerationState(Project project, ClassBuilderFactory builderFactory, AnalyzeExhaust analyzeExhaust, List files) { this(project, builderFactory, Progress.DEAF, analyzeExhaust, files, BuiltinToJavaTypesMapping.ENABLED); } @@ -98,8 +92,6 @@ public class GenerationState { builtinToJavaTypesMapping, this, builderFactory, project); this.scriptCodegen = injector.getScriptCodegen(); - this.memberCodegen = injector.getMemberCodegen(); - this.classCodegen = injector.getClassCodegen(); this.intrinsics = injector.getIntrinsics(); this.classFileFactory = injector.getClassFileFactory(); } @@ -154,16 +146,6 @@ public class GenerationState { return intrinsics; } - @NotNull - public MemberCodegen getMemberCodegen() { - return memberCodegen; - } - - @NotNull - public ClassCodegen getClassCodegen() { - return classCodegen; - } - public void beforeCompile() { markUsed(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java index ec641690711..61489afacaa 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Map; import static org.jetbrains.asm4.Opcodes.*; +import static org.jetbrains.jet.codegen.AsmUtil.boxType; import static org.jetbrains.jet.codegen.CodegenUtil.*; import static org.jetbrains.jet.codegen.binding.CodegenBinding.*; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration; @@ -262,7 +263,7 @@ public class JetTypeMapper extends BindingTraceAware { } Type asmType = Type.getObjectType("error/NonExistentClass"); if (signatureVisitor != null) { - writeSimpleType(signatureVisitor, asmType, true); + signatureVisitor.writeAsmType(asmType, true); } checkValidType(asmType); return asmType; @@ -302,7 +303,7 @@ public class JetTypeMapper extends BindingTraceAware { } boolean forceReal = KotlinToJavaTypesMap.getInstance().isForceReal(name); - writeGenericType(jetType, signatureVisitor, asmType, forceReal); + writeGenericType(signatureVisitor, asmType, jetType, forceReal); checkValidType(asmType); return asmType; @@ -339,9 +340,10 @@ public class JetTypeMapper extends BindingTraceAware { parentDeclarationElement != null ? parentDeclarationElement.getText() : "null"); } - private void writeGenericType(JetType jetType, BothSignatureWriter signatureVisitor, Type asmType, boolean forceReal) { + private void writeGenericType(BothSignatureWriter signatureVisitor, Type asmType, JetType jetType, boolean forceReal) { if (signatureVisitor != null) { - signatureVisitor.writeClassBegin(asmType.getInternalName(), jetType.isNullable(), forceReal); + String kotlinTypeName = getKotlinTypeNameForSignature(jetType, asmType); + signatureVisitor.writeClassBegin(asmType.getInternalName(), jetType.isNullable(), forceReal, kotlinTypeName); for (TypeProjection proj : jetType.getArguments()) { // TODO: +- signatureVisitor.writeTypeArgument(proj.getProjectionKind()); @@ -355,18 +357,28 @@ public class JetTypeMapper extends BindingTraceAware { private Type mapKnownAsmType(JetType jetType, Type asmType, @Nullable BothSignatureWriter signatureVisitor) { if (signatureVisitor != null) { if (jetType.getArguments().isEmpty()) { - writeSimpleType(signatureVisitor, asmType, jetType.isNullable()); + String kotlinTypeName = getKotlinTypeNameForSignature(jetType, asmType); + signatureVisitor.writeAsmType(asmType, jetType.isNullable(), kotlinTypeName); } else { - writeGenericType(jetType, signatureVisitor, asmType, false); + writeGenericType(signatureVisitor, asmType, jetType, false); } } checkValidType(asmType); return asmType; } - private static void writeSimpleType(BothSignatureWriter visitor, Type asmType, boolean nullable) { - visitor.writeAsmType(asmType, nullable); + @Nullable + private static String getKotlinTypeNameForSignature(@NotNull JetType jetType, @NotNull Type asmType) { + ClassifierDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor(); + if (descriptor == null) return null; + if (asmType.getSort() != Type.OBJECT) return null; + + JvmClassName jvmClassName = JvmClassName.byType(asmType); + if (JavaToKotlinClassMap.getInstance().mapPlatformClass(jvmClassName.getFqName()).size() > 1) { + return JvmClassName.byClassDescriptor(descriptor).getSignatureName(); + } + return null; } private void checkValidType(@NotNull Type type) { @@ -534,7 +546,7 @@ public class JetTypeMapper extends BindingTraceAware { else { signatureVisitor.writeReturnType(); JetType returnType = f.getReturnType(); - assert returnType != null; + assert returnType != null : "Function " + f + " has no return type"; mapReturnType(returnType, signatureVisitor); signatureVisitor.writeReturnTypeEnd(); } @@ -647,7 +659,7 @@ public class JetTypeMapper extends BindingTraceAware { ((ClassDescriptor) parentDescriptor).getKind() == ClassKind.ANNOTATION_CLASS; String name = isAnnotation ? descriptor.getName().getName() : PropertyCodegen.getterName(descriptor.getName()); - // TODO: do not generate generics if not needed + // TODO: do not genClassOrObject generics if not needed BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true); writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter); @@ -765,10 +777,11 @@ public class JetTypeMapper extends BindingTraceAware { if (closure != null) { for (Map.Entry entry : closure.getCaptureVariables().entrySet()) { - if (entry.getKey() instanceof VariableDescriptor && !(entry.getKey() instanceof PropertyDescriptor)) { - Type sharedVarType = getSharedVarType(entry.getKey()); + DeclarationDescriptor variableDescriptor = entry.getKey(); + if (variableDescriptor instanceof VariableDescriptor && !(variableDescriptor instanceof PropertyDescriptor)) { + Type sharedVarType = getSharedVarType(variableDescriptor); if (sharedVarType == null) { - sharedVarType = mapType(((VariableDescriptor) entry.getKey()).getType()); + sharedVarType = mapType(((VariableDescriptor) variableDescriptor).getType()); } signatureWriter.writeParameterType(JvmMethodParameterKind.SHARED_VAR); signatureWriter.writeAsmType(sharedVarType, false); diff --git a/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java b/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java index b0e94b6bc63..46661b46e1c 100644 --- a/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java @@ -17,23 +17,18 @@ package org.jetbrains.jet.di; -import org.jetbrains.jet.codegen.state.JetTypeMapper; -import java.util.List; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.codegen.BuiltinToJavaTypesMapping; -import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.ClassBuilderFactory; import com.intellij.openapi.project.Project; -import org.jetbrains.jet.lang.resolve.BindingTrace; -import org.jetbrains.jet.lang.resolve.BindingContext; -import org.jetbrains.jet.codegen.ClassBuilderMode; -import org.jetbrains.jet.codegen.ClassCodegen; -import org.jetbrains.jet.codegen.ScriptCodegen; -import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods; -import org.jetbrains.jet.codegen.ClassFileFactory; -import org.jetbrains.jet.codegen.MemberCodegen; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.codegen.*; +import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods; +import org.jetbrains.jet.codegen.state.GenerationState; +import org.jetbrains.jet.codegen.state.JetTypeMapper; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.BindingTrace; + import javax.annotation.PreDestroy; +import java.util.List; /* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */ public class InjectorForJvmCodegen { @@ -47,11 +42,9 @@ public class InjectorForJvmCodegen { private BindingTrace bindingTrace; private BindingContext bindingContext; private ClassBuilderMode classBuilderMode; - private ClassCodegen classCodegen; private ScriptCodegen scriptCodegen; private IntrinsicMethods intrinsics; private ClassFileFactory classFileFactory; - private MemberCodegen memberCodegen; public InjectorForJvmCodegen( @NotNull JetTypeMapper jetTypeMapper, @@ -70,14 +63,11 @@ public class InjectorForJvmCodegen { this.bindingTrace = jetTypeMapper.getBindingTrace(); this.bindingContext = bindingTrace.getBindingContext(); this.classBuilderMode = classBuilderFactory.getClassBuilderMode(); - this.classCodegen = new ClassCodegen(getGenerationState()); this.scriptCodegen = new ScriptCodegen(getGenerationState()); this.intrinsics = new IntrinsicMethods(); this.classFileFactory = new ClassFileFactory(getGenerationState()); - this.memberCodegen = new MemberCodegen(getGenerationState()); this.scriptCodegen.setClassFileFactory(classFileFactory); - this.scriptCodegen.setMemberCodegen(memberCodegen); this.classFileFactory.setBuilderFactory(classBuilderFactory); @@ -105,10 +95,6 @@ public class InjectorForJvmCodegen { return this.project; } - public ClassCodegen getClassCodegen() { - return this.classCodegen; - } - public ScriptCodegen getScriptCodegen() { return this.scriptCodegen; } @@ -121,8 +107,4 @@ public class InjectorForJvmCodegen { return this.classFileFactory; } - public MemberCodegen getMemberCodegen() { - return this.memberCodegen; - } - } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java index 23906b542c2..550acdd8a4c 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java @@ -18,20 +18,33 @@ package org.jetbrains.jet.lang.resolve.java; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.collect.Lists; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.analyzer.AnalyzerFacade; import org.jetbrains.jet.analyzer.AnalyzerFacadeForEverything; +import org.jetbrains.jet.di.InjectorForJavaDescriptorResolver; import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm; import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode; +import org.jetbrains.jet.lang.DefaultModuleConfiguration; import org.jetbrains.jet.lang.ModuleConfiguration; +import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; +import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.psi.JetImportDirective; +import org.jetbrains.jet.lang.psi.JetPsiFactory; import org.jetbrains.jet.lang.resolve.*; +import org.jetbrains.jet.lang.resolve.lazy.FileBasedDeclarationProviderFactory; +import org.jetbrains.jet.lang.resolve.lazy.ResolveSession; +import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.resolve.scopes.WritableScope; +import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -70,6 +83,67 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade { headersTraceContext, bodiesResolveContext, configuration); } + @NotNull + @Override + public ResolveSession getLazyResolveSession(@NotNull final Project fileProject, @NotNull Collection files) { + ModuleDescriptor javaModule = new ModuleDescriptor(Name.special("")); + + BindingTraceContext javaResolverTrace = new BindingTraceContext(); + InjectorForJavaDescriptorResolver injector = new InjectorForJavaDescriptorResolver( + fileProject, javaResolverTrace, javaModule, BuiltinsScopeExtensionMode.ALL); + + final PsiClassFinder psiClassFinder = injector.getPsiClassFinder(); + + // TODO: Replace with stub declaration provider + final FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory(files, new Predicate() { + @Override + public boolean apply(FqName fqName) { + return psiClassFinder.findPsiPackage(fqName) != null || new FqName("jet").equals(fqName); + } + }); + + final JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver(); + + ModuleConfiguration moduleConfiguration = new ModuleConfiguration() { + @Override + public void addDefaultImports(@NotNull Collection directives) { + final Collection defaultImports = Lists.newArrayList(JavaBridgeConfiguration.DEFAULT_JAVA_IMPORTS); + defaultImports.addAll(Arrays.asList(DefaultModuleConfiguration.DEFAULT_JET_IMPORTS)); + + for (ImportPath defaultJetImport : defaultImports) { + directives.add(JetPsiFactory.createImportDirective(fileProject, defaultJetImport)); + } + } + + @Override + public void extendNamespaceScope( + @NotNull BindingTrace trace, + @NotNull NamespaceDescriptor namespaceDescriptor, + @NotNull WritableScope namespaceMemberScope + ) { + FqName fqName = DescriptorUtils.getFQName(namespaceDescriptor).toSafe(); + if (new FqName("jet").equals(fqName)) { + namespaceMemberScope.importScope(JetStandardLibrary.getInstance().getLibraryScope()); + } + if (psiClassFinder.findPsiPackage(fqName) != null) { + JavaPackageScope javaPackageScope = javaDescriptorResolver.getJavaPackageScope(fqName, namespaceDescriptor); + assert javaPackageScope != null; + namespaceMemberScope.importScope(javaPackageScope); + } + } + + @NotNull + @Override + public PlatformToKotlinClassMap getPlatformToKotlinClassMap() { + return PlatformToKotlinClassMap.EMPTY; + } + }; + + ModuleDescriptor lazyModule = new ModuleDescriptor(Name.special("")); + + return new ResolveSession(fileProject, lazyModule, moduleConfiguration, declarationProviderFactory); + } + public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors( JetFile file, List scriptParameters, @NotNull BuiltinsScopeExtensionMode builtinsScopeExtensionMode) { AnalyzingUtils.checkForSyntacticErrors(file); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java index 66130db9c49..1aec6bec876 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java @@ -114,8 +114,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes } this.staticMembers = staticMembers; - this.kotlin = psiClass != null && - (new PsiClassWrapper(psiClass).getJetClass().isDefined() || psiClass.getName().equals(JvmAbi.PACKAGE_CLASS)); + this.kotlin = psiClass != null && isKotlinClass(psiClass); classOrNamespaceDescriptor = descriptor; if (fqName != null && fqName.lastSegmentIs(Name.identifier(JvmAbi.PACKAGE_CLASS)) && psiClass != null && kotlin) { @@ -214,9 +213,9 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes } - static class ResolverEnumClassObjectClassData extends ResolverClassData { + static class ResolverSyntheticClassObjectClassData extends ResolverClassData { - protected ResolverEnumClassObjectClassData( + protected ResolverSyntheticClassObjectClassData( @Nullable PsiClass psiClass, @Nullable FqName fqName, @NotNull ClassDescriptorFromJvmBytecode descriptor @@ -545,8 +544,9 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes false); String context = "constructor of class " + psiClass.getQualifiedName(); ValueParameterDescriptors valueParameterDescriptors = resolveParameterDescriptors(constructorDescriptor, - constructor.getParameters(), - TypeVariableResolvers.classTypeVariableResolver(classData.classDescriptor, context)); + constructor.getParameters(), + TypeVariableResolvers.classTypeVariableResolver( + classData.classDescriptor, context)); if (valueParameterDescriptors.receiverType != null) { throw new IllegalStateException(); } @@ -585,6 +585,17 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes return createClassObjectDescriptorForEnum(containing, psiClass); } + if (!isKotlinClass(psiClass)) { + return null; + } + + // If there's at least one inner enum, we need to create a class object (to put this enum into) + for (PsiClass innerClass : psiClass.getInnerClasses()) { + if (isInnerEnum(innerClass, containing)) { + return createSyntheticClassObject(containing, psiClass); + } + } + PsiClass classObjectPsiClass = getInnerClassClassObject(psiClass); if (classObjectPsiClass == null) { return null; @@ -602,20 +613,39 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes return classObjectDescriptor; } + private static boolean isKotlinClass(@NotNull PsiClass psiClass) { + return new PsiClassWrapper(psiClass).getJetClass().isDefined() || psiClass.getName().equals(JvmAbi.PACKAGE_CLASS); + } + + private static boolean isInnerEnum(@NotNull PsiClass innerClass, DeclarationDescriptor owner) { + if (!innerClass.isEnum()) return false; + if (!(owner instanceof ClassDescriptor)) return false; + + ClassKind kind = ((ClassDescriptor) owner).getKind(); + return kind == ClassKind.CLASS || kind == ClassKind.TRAIT || kind == ClassKind.ENUM_CLASS; + } + @NotNull private MutableClassDescriptorLite createClassObjectDescriptorForEnum(@NotNull ClassDescriptor containing, @NotNull PsiClass psiClass) { + MutableClassDescriptorLite classObjectDescriptor = createSyntheticClassObject(containing, psiClass); + + classObjectDescriptor.getBuilder().addFunctionDescriptor(createEnumClassObjectValuesMethod(classObjectDescriptor, trace)); + classObjectDescriptor.getBuilder().addFunctionDescriptor(createEnumClassObjectValueOfMethod(classObjectDescriptor, trace)); + + return classObjectDescriptor; + } + + @NotNull + private MutableClassDescriptorLite createSyntheticClassObject(@NotNull ClassDescriptor containing, @NotNull PsiClass psiClass) { String psiClassQualifiedName = psiClass.getQualifiedName(); assert psiClassQualifiedName != null : "Reading java class with no qualified name"; FqNameUnsafe fqName = new FqNameUnsafe(psiClassQualifiedName + "." + getClassObjectName(psiClass.getName()).getName()); ClassDescriptorFromJvmBytecode classObjectDescriptor = new ClassDescriptorFromJvmBytecode( containing, ClassKind.CLASS_OBJECT, psiClass, null, this); - ResolverEnumClassObjectClassData data = new ResolverEnumClassObjectClassData(psiClass, null, classObjectDescriptor); + ResolverSyntheticClassObjectClassData data = new ResolverSyntheticClassObjectClassData(psiClass, null, classObjectDescriptor); setUpClassObjectDescriptor(containing, fqName, data, getClassObjectName(containing.getName().getName())); - classObjectDescriptor.getBuilder().addFunctionDescriptor(createEnumClassObjectValuesMethod(classObjectDescriptor, trace)); - classObjectDescriptor.getBuilder().addFunctionDescriptor(createEnumClassObjectValueOfMethod(classObjectDescriptor, trace)); - return classObjectDescriptor; } @@ -656,6 +686,13 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes if (clazz == null) { throw new IllegalStateException("PsiClass not found by name " + containerFqName + ", required to be container declaration of " + fqName); } + if (isInnerEnum(psiClass, clazz) && isKotlinClass(psiClass)) { + ClassDescriptor classObjectDescriptor = clazz.getClassObjectDescriptor(); + if (classObjectDescriptor == null) { + throw new IllegalStateException("Class object for a class with inner enum should've been created earlier: " + clazz); + } + return classObjectDescriptor; + } return clazz; } @@ -1887,7 +1924,7 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes public List resolveInnerClasses(DeclarationDescriptor owner, PsiClass psiClass, boolean staticMembers) { if (staticMembers) { - return new ArrayList(0); + return resolveInnerClassesOfClassObject(owner, psiClass); } PsiClass[] innerPsiClasses = psiClass.getInnerClasses(); @@ -1900,14 +1937,41 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes if (innerPsiClass.getName().equals(JvmAbi.CLASS_OBJECT_CLASS_NAME)) { continue; } - ClassDescriptor classDescriptor = resolveClass(new FqName(innerPsiClass.getQualifiedName()), - DescriptorSearchRule.IGNORE_IF_FOUND_IN_KOTLIN); - assert classDescriptor != null: "couldn't resolve class " + innerPsiClass.getQualifiedName(); + if (isInnerEnum(innerPsiClass, owner)) { + // Inner enums will be put later into our class object + continue; + } + ClassDescriptor classDescriptor = resolveInnerClass(innerPsiClass); r.add(classDescriptor); } return r; } + private List resolveInnerClassesOfClassObject(DeclarationDescriptor owner, PsiClass psiClass) { + if (!DescriptorUtils.isClassObject(owner)) { + return new ArrayList(0); + } + + List r = new ArrayList(0); + // If we're a class object, inner enums of our parent need to be put into us + DeclarationDescriptor containingDeclaration = owner.getContainingDeclaration(); + for (PsiClass innerPsiClass : psiClass.getInnerClasses()) { + if (isInnerEnum(innerPsiClass, containingDeclaration)) { + ClassDescriptor classDescriptor = resolveInnerClass(innerPsiClass); + r.add(classDescriptor); + } + } + return r; + } + + private ClassDescriptor resolveInnerClass(@NotNull PsiClass innerPsiClass) { + String name = innerPsiClass.getQualifiedName(); + assert name != null : "Inner class has no qualified name"; + ClassDescriptor classDescriptor = resolveClass(new FqName(name), DescriptorSearchRule.IGNORE_IF_FOUND_IN_KOTLIN); + assert classDescriptor != null : "Couldn't resolve class " + name; + return classDescriptor; + } + @NotNull public static PsiAnnotation[] getAllAnnotations(@NotNull PsiModifierListOwner owner) { List result = new ArrayList(); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaToKotlinClassMap.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaToKotlinClassMap.java index 4f54a81bfcf..89b48e84678 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaToKotlinClassMap.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaToKotlinClassMap.java @@ -30,13 +30,12 @@ import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.PrimitiveType; -import java.lang.annotation.Annotation; import java.util.*; /** * @author svtk */ -public class JavaToKotlinClassMap implements PlatformToKotlinClassMap { +public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements PlatformToKotlinClassMap { private static JavaToKotlinClassMap instance = null; @NotNull @@ -57,42 +56,6 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap { initPrimitives(); } - private void init() { - JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance(); - - register(Object.class, JetStandardClasses.getAny()); - register(String.class, standardLibrary.getString()); - register(CharSequence.class, standardLibrary.getCharSequence()); - register(Throwable.class, standardLibrary.getThrowable()); - register(Number.class, standardLibrary.getNumber()); - register(Comparable.class, standardLibrary.getComparable()); - register(Enum.class, standardLibrary.getEnum()); - register(Annotation.class, standardLibrary.getAnnotation()); - register(Iterable.class, standardLibrary.getIterable()); - register(Iterator.class, standardLibrary.getIterator()); - - registerCovariant(Iterable.class, standardLibrary.getMutableIterable()); - registerCovariant(Iterator.class, standardLibrary.getMutableIterator()); - - register(Collection.class, standardLibrary.getCollection()); - registerCovariant(Collection.class, standardLibrary.getMutableCollection()); - - register(List.class, standardLibrary.getList()); - registerCovariant(List.class, standardLibrary.getMutableList()); - - register(Set.class, standardLibrary.getSet()); - registerCovariant(Set.class, standardLibrary.getMutableSet()); - - register(Map.class, standardLibrary.getMap()); - registerCovariant(Map.class, standardLibrary.getMutableMap()); - - register(Map.Entry.class, standardLibrary.getMapEntry()); - registerCovariant(Map.Entry.class, standardLibrary.getMutableMapEntry()); - - register(ListIterator.class, standardLibrary.getListIterator()); - registerCovariant(ListIterator.class, standardLibrary.getMutableListIterator()); - } - private void initPrimitives() { JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance(); for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { @@ -131,19 +94,30 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap { return new FqName(javaClass.getName().replace("$", ".")); } - private void register(@NotNull Class javaClass, @NotNull ClassDescriptor kotlinDescriptor) { + @Override + /*package*/ void register( + @NotNull Class javaClass, + @NotNull ClassDescriptor kotlinDescriptor + ) { register(getJavaClassFqName(javaClass), kotlinDescriptor); } + @Override + /*package*/ void register( + @NotNull Class javaClass, + @NotNull ClassDescriptor kotlinDescriptor, + @NotNull ClassDescriptor kotlinMutableDescriptor + ) { + FqName javaClassName = getJavaClassFqName(javaClass); + register(javaClassName, kotlinDescriptor); + registerCovariant(javaClassName, kotlinMutableDescriptor); + } + private void register(@NotNull FqName javaClassName, @NotNull ClassDescriptor kotlinDescriptor) { classDescriptorMap.put(javaClassName, kotlinDescriptor); packagesWithMappedClasses.put(javaClassName.parent(), kotlinDescriptor); } - private void registerCovariant(@NotNull Class javaClass, @NotNull ClassDescriptor kotlinDescriptor) { - registerCovariant(getJavaClassFqName(javaClass), kotlinDescriptor); - } - private void registerCovariant(@NotNull FqName javaClassName, @NotNull ClassDescriptor kotlinDescriptor) { classDescriptorMapForCovariantPositions.put(javaClassName, kotlinDescriptor); packagesWithMappedClasses.put(javaClassName.parent(), kotlinDescriptor); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaToKotlinClassMapBuilder.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaToKotlinClassMapBuilder.java new file mode 100644 index 00000000000..598c45dc438 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaToKotlinClassMapBuilder.java @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.resolve.java; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.types.lang.JetStandardClasses; +import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; + +import java.lang.annotation.Annotation; +import java.util.*; + +/** + * @author svtk + */ +public abstract class JavaToKotlinClassMapBuilder { + + /*package*/ void init() { + JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance(); + + register(Object.class, JetStandardClasses.getAny()); + register(String.class, standardLibrary.getString()); + register(CharSequence.class, standardLibrary.getCharSequence()); + register(Throwable.class, standardLibrary.getThrowable()); + register(Number.class, standardLibrary.getNumber()); + register(Comparable.class, standardLibrary.getComparable()); + register(Enum.class, standardLibrary.getEnum()); + register(Annotation.class, standardLibrary.getAnnotation()); + + register(Iterable.class, standardLibrary.getIterable(), standardLibrary.getMutableIterable()); + register(Iterator.class, standardLibrary.getIterator(), standardLibrary.getMutableIterator()); + register(Collection.class, standardLibrary.getCollection(), standardLibrary.getMutableCollection()); + register(List.class, standardLibrary.getList(), standardLibrary.getMutableList()); + register(Set.class, standardLibrary.getSet(), standardLibrary.getMutableSet()); + register(Map.class, standardLibrary.getMap(), standardLibrary.getMutableMap()); + register(Map.Entry.class, standardLibrary.getMapEntry(), standardLibrary.getMutableMapEntry()); + register(ListIterator.class, standardLibrary.getListIterator(), standardLibrary.getMutableListIterator()); + } + + /*package*/ abstract void register(@NotNull Class javaClass, @NotNull ClassDescriptor kotlinDescriptor); + + /*package*/ abstract void register(@NotNull Class javaClass, @NotNull ClassDescriptor kotlinDescriptor, @NotNull ClassDescriptor kotlinMutableDescriptor); +} diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java index 8e34d09bba8..8dadf73f576 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetTypeJetSignatureReader.java @@ -17,8 +17,10 @@ package org.jetbrains.jet.lang.resolve.java; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; @@ -87,46 +89,58 @@ public abstract class JetTypeJetSignatureReader extends JetSignatureExceptionsAd private List typeArguments; @Override - public void visitClassType(String name, boolean nullable, boolean forceReal) { - FqName ourName = new FqName(name - .replace('/', '.') - .replace('$', '.') // TODO: not sure - ); - - this.classDescriptor = null; - if (!forceReal) { - classDescriptor = JavaToKotlinClassMap.getInstance().mapKotlinClass(ourName, - JavaTypeTransformer.TypeUsage.MEMBER_SIGNATURE_INVARIANT); - } + public void visitClassType(String signatureName, boolean nullable, boolean forceReal) { + FqName fqName = JvmClassName.bySignatureName(signatureName).getFqName(); - if (classDescriptor == null) { - // TODO: this is the worst code in Kotlin project - Matcher matcher = Pattern.compile("jet\\.Function(\\d+)").matcher(ourName.getFqName()); - if (matcher.matches()) { - classDescriptor = JetStandardClasses.getFunction(Integer.parseInt(matcher.group(1))); - } - } - - if (classDescriptor == null) { - Matcher matcher = Pattern.compile("jet\\.Tuple(\\d+)").matcher(ourName.getFqName()); - if (matcher.matches()) { - classDescriptor = JetStandardClasses.getTuple(Integer.parseInt(matcher.group(1))); - } - } + enterClass(resolveClassDescriptorByFqName(fqName, forceReal), fqName.getFqName(), nullable); + } - - if (this.classDescriptor == null) { - this.classDescriptor = javaDescriptorResolver.resolveClass(ourName, DescriptorSearchRule.INCLUDE_KOTLIN); - } + private void enterClass(@Nullable ClassDescriptor classDescriptor, @NotNull String className, boolean nullable) { + this.classDescriptor = classDescriptor; if (this.classDescriptor == null) { // TODO: report in to trace - this.errorType = ErrorUtils.createErrorType("class not found by name: " + ourName); + this.errorType = ErrorUtils.createErrorType("class not found by name: " + className); } this.nullable = nullable; this.typeArguments = new ArrayList(); } + @Nullable + private ClassDescriptor resolveClassDescriptorByFqName(FqName ourName, boolean forceReal) { + if (!forceReal) { + ClassDescriptor mappedDescriptor = JavaToKotlinClassMap.getInstance(). + mapKotlinClass(ourName, JavaTypeTransformer.TypeUsage.MEMBER_SIGNATURE_INVARIANT); + if (mappedDescriptor != null) { + return mappedDescriptor; + } + } + + // TODO: this is the worst code in Kotlin project + Matcher functionMatcher = Pattern.compile("jet\\.Function(\\d+)").matcher(ourName.getFqName()); + if (functionMatcher.matches()) { + return JetStandardClasses.getFunction(Integer.parseInt(functionMatcher.group(1))); + } + + Matcher patternMatcher = Pattern.compile("jet\\.Tuple(\\d+)").matcher(ourName.getFqName()); + if (patternMatcher.matches()) { + return JetStandardClasses.getTuple(Integer.parseInt(patternMatcher.group(1))); + } + + + return javaDescriptorResolver.resolveClass(ourName, DescriptorSearchRule.INCLUDE_KOTLIN); + } + + @Override + public void visitInnerClassType(String signatureName, boolean nullable, boolean forceReal) { + JvmClassName jvmClassName = JvmClassName.bySignatureName(signatureName); + ClassDescriptor descriptor = resolveClassDescriptorByFqName(jvmClassName.getOuterClassFqName(), forceReal); + for (String innerClassName : jvmClassName.getInnerClassNameList()) { + descriptor = descriptor != null ? DescriptorUtils.getInnerClassByName(descriptor, innerClassName) : null; + } + enterClass(descriptor, signatureName, nullable); + } + private static Variance parseVariance(JetSignatureVariance variance) { switch (variance) { case INVARIANT: return Variance.INVARIANT; diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java index e2c3a962d5d..4eb4fcc1dff 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JvmClassName.java @@ -16,11 +16,18 @@ package org.jetbrains.jet.lang.resolve.java; +import com.google.common.collect.Lists; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.asm4.Type; +import org.jetbrains.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.name.FqName; +import java.util.List; + /** * @author Stepan Koltsov */ @@ -45,7 +52,7 @@ public class JvmClassName { */ @NotNull public static JvmClassName byFqNameWithoutInnerClasses(@NotNull FqName fqName) { - JvmClassName r = new JvmClassName(fqName.getFqName().replace('.', '/')); + JvmClassName r = new JvmClassName(fqNameToInternalName(fqName)); r.fqName = fqName; return r; } @@ -55,6 +62,13 @@ public class JvmClassName { return byFqNameWithoutInnerClasses(new FqName(fqName)); } + @NotNull + public static JvmClassName bySignatureName(@NotNull String signatureName) { + JvmClassName className = new JvmClassName(signatureNameToInternalName(signatureName)); + className.signatureName = signatureName; + return className; + } + private static String encodeSpecialNames(String str) { String encodedObjectNames = StringUtil.replace(str, JvmAbi.CLASS_OBJECT_CLASS_NAME, CLASS_OBJECT_REPLACE_GUARD); return StringUtil.replace(encodedObjectNames, JvmAbi.TRAIT_IMPL_CLASS_NAME, TRAIT_IMPL_REPLACE_GUARD); @@ -65,13 +79,67 @@ public class JvmClassName { return StringUtil.replace(decodedObjectNames, TRAIT_IMPL_REPLACE_GUARD, JvmAbi.TRAIT_IMPL_CLASS_NAME); } + @NotNull + private static JvmClassName byFqNameAndInnerClassList(@NotNull FqName fqName, @NotNull List innerClassList) { + String outerClassName = fqNameToInternalName(fqName); + StringBuilder sb = new StringBuilder(outerClassName); + for (String innerClassName : innerClassList) { + sb.append("$").append(innerClassName); + } + return new JvmClassName(sb.toString()); + } + + @NotNull + public static JvmClassName byClassDescriptor(@NotNull ClassifierDescriptor classDescriptor) { + DeclarationDescriptor descriptor = classDescriptor; + + List innerClassNames = Lists.newArrayList(); + while (descriptor.getContainingDeclaration() instanceof ClassDescriptor) { + innerClassNames.add(descriptor.getName().getName()); + descriptor = descriptor.getContainingDeclaration(); + assert descriptor != null; + } + + return byFqNameAndInnerClassList(DescriptorUtils.getFQName(descriptor).toSafe(), innerClassNames); + } + + @NotNull + private static String fqNameToInternalName(@NotNull FqName fqName) { + return fqName.getFqName().replace('.', '/'); + } + + @NotNull + private static String signatureNameToInternalName(@NotNull String signatureName) { + return signatureName.replace('.', '$'); + } + + @NotNull + private static String internalNameToFqName(@NotNull String name) { + return decodeSpecialNames(encodeSpecialNames(name).replace('$', '.').replace('/', '.')); + } + + @NotNull + private static String internalNameToSignatureName(@NotNull String name) { + return decodeSpecialNames(encodeSpecialNames(name).replace('$', '.')); + } + + @NotNull + private static String signatureNameToFqName(@NotNull String name) { + return name.replace('/', '.'); + } + + private final static String CLASS_OBJECT_REPLACE_GUARD = ""; private final static String TRAIT_IMPL_REPLACE_GUARD = ""; - @NotNull + // Internal name: jet/Map$Entry + // FqName: jet.Map.Entry + // Signature name: jet/Map.Entry + private final String internalName; private FqName fqName; private String descriptor; + private String signatureName; private Type asmType; @@ -82,7 +150,7 @@ public class JvmClassName { @NotNull public FqName getFqName() { if (fqName == null) { - this.fqName = new FqName(decodeSpecialNames(encodeSpecialNames(internalName).replace('$', '.').replace('/', '.'))); + this.fqName = new FqName(internalNameToFqName(internalName)); } return fqName; } @@ -112,6 +180,36 @@ public class JvmClassName { return asmType; } + @NotNull + public String getSignatureName() { + if (signatureName == null) { + signatureName = internalNameToSignatureName(internalName); + } + return signatureName; + } + + @NotNull + public FqName getOuterClassFqName() { + String signatureName = getSignatureName(); + int index = signatureName.indexOf('.'); + String outerClassName = index != -1 ? signatureName.substring(0, index) : signatureName; + return new FqName(signatureNameToFqName(outerClassName)); + } + + @NotNull + public List getInnerClassNameList() { + List innerClassList = Lists.newArrayList(); + String signatureName = getSignatureName(); + int index = signatureName.indexOf('.'); + while (index != -1) { + int nextIndex = signatureName.indexOf('.', index + 1); + String innerClassName = nextIndex != -1 ? signatureName.substring(index + 1, nextIndex) : signatureName.substring(index + 1); + innerClassList.add(innerClassName); + index = nextIndex; + } + return innerClassList; + } + @Override public String toString() { return getInternalName(); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/KotlinToJavaTypesMap.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/KotlinToJavaTypesMap.java index 1d925466aec..2334a9f9f61 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/KotlinToJavaTypesMap.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/KotlinToJavaTypesMap.java @@ -27,17 +27,15 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; import org.jetbrains.jet.lang.types.JetType; -import org.jetbrains.jet.lang.types.lang.JetStandardClasses; -import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.PrimitiveType; -import java.lang.annotation.Annotation; -import java.util.*; +import java.util.Map; +import java.util.Set; /** * @author svtk */ -public class KotlinToJavaTypesMap { +public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder { private static KotlinToJavaTypesMap instance = null; @NotNull @@ -57,41 +55,6 @@ public class KotlinToJavaTypesMap { initPrimitives(); } - private void init() { - JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance(); - - register(JetStandardClasses.getAny(), Object.class); - register(standardLibrary.getNumber(), Number.class); - register(standardLibrary.getString(), String.class); - register(standardLibrary.getThrowable(), Throwable.class); - register(standardLibrary.getCharSequence(), CharSequence.class); - register(standardLibrary.getComparable(), Comparable.class); - register(standardLibrary.getEnum(), Enum.class); - register(standardLibrary.getAnnotation(), Annotation.class); - register(standardLibrary.getIterable(), Iterable.class); - register(standardLibrary.getIterator(), Iterator.class); - register(standardLibrary.getMutableIterable(), Iterable.class); - register(standardLibrary.getMutableIterator(), Iterator.class); - - register(standardLibrary.getCollection(), Collection.class); - register(standardLibrary.getMutableCollection(), Collection.class); - - register(standardLibrary.getList(), List.class); - register(standardLibrary.getMutableList(), List.class); - - register(standardLibrary.getSet(), Set.class); - register(standardLibrary.getMutableSet(), Set.class); - - register(standardLibrary.getMap(), Map.class); - register(standardLibrary.getMutableMap(), Map.class); - - register(standardLibrary.getMapEntry(), Map.Entry.class); - register(standardLibrary.getMutableMapEntry(), Map.Entry.class); - - register(standardLibrary.getListIterator(), ListIterator.class); - register(standardLibrary.getMutableListIterator(), ListIterator.class); - } - private void initPrimitives() { for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) { FqName className = jvmPrimitiveType.getPrimitiveType().getClassName(); @@ -121,10 +84,24 @@ public class KotlinToJavaTypesMap { return asmTypes.get(fqName); } - private void register(@NotNull ClassDescriptor kotlinDescriptor, @NotNull Class javaClass) { + @Override + /*package*/ void register( + @NotNull Class javaClass, + @NotNull ClassDescriptor kotlinDescriptor + ) { register(kotlinDescriptor, AsmTypeConstants.getType(javaClass)); } + @Override + /*package*/ void register( + @NotNull Class javaClass, + @NotNull ClassDescriptor kotlinDescriptor, + @NotNull ClassDescriptor kotlinMutableDescriptor + ) { + register(javaClass, kotlinDescriptor); + register(javaClass, kotlinMutableDescriptor); + } + private void register(@NotNull ClassDescriptor kotlinDescriptor, @NotNull Type javaType) { FqNameUnsafe fqName = DescriptorUtils.getFQName(kotlinDescriptor); assert fqName.isSafe(); diff --git a/compiler/frontend/generator/TuplesAndFunctionsGenerator.java b/compiler/frontend/generator/TuplesAndFunctionsGenerator.java index cd3b55a913e..3166c5ade67 100644 --- a/compiler/frontend/generator/TuplesAndFunctionsGenerator.java +++ b/compiler/frontend/generator/TuplesAndFunctionsGenerator.java @@ -22,11 +22,10 @@ import java.io.PrintStream; * @author abreslav */ public class TuplesAndFunctionsGenerator { - private static int TUPLE_COUNT = 23; + private static final int TUPLE_COUNT = 23; private static void generateTuples(PrintStream out, int count) { generated(out); - out.println("public class Tuple0() {}"); for (int i = 1; i < count; i++) { out.print("public class Tuple" + i); out.print("<"); diff --git a/compiler/frontend/src/jet.src/Tuples.jet b/compiler/frontend/src/jet.src/Tuples.jet index ebbecd1e57c..aed69a312ec 100644 --- a/compiler/frontend/src/jet.src/Tuples.jet +++ b/compiler/frontend/src/jet.src/Tuples.jet @@ -3,7 +3,6 @@ package jet -public class Tuple0() {} public class Tuple1(public val _1: T1) {} public class Tuple2(public val _1: T1, public val _2: T2) {} public class Tuple3(public val _1: T1, public val _2: T2, public val _3: T3) {} diff --git a/compiler/frontend/src/jet.src/Unit.jet b/compiler/frontend/src/jet.src/Unit.jet new file mode 100644 index 00000000000..14795ac757a --- /dev/null +++ b/compiler/frontend/src/jet.src/Unit.jet @@ -0,0 +1,7 @@ +package jet + +public class Tuple0 private () { + public class object { + public val VALUE: Tuple0 + } +} \ No newline at end of file diff --git a/compiler/frontend/src/jet/Collections.jet b/compiler/frontend/src/jet/Collections.jet index c7bbbaf1c19..7e26c66cc36 100644 --- a/compiler/frontend/src/jet/Collections.jet +++ b/compiler/frontend/src/jet/Collections.jet @@ -108,7 +108,7 @@ public trait MutableSet : Set, MutableCollection { override fun clear() } -public trait Map { +public trait Map { // Query Operations public fun size() : Int public fun isEmpty() : Boolean diff --git a/compiler/frontend/src/jet/Library.jet b/compiler/frontend/src/jet/Library.jet index b132b00d588..93643bba20e 100644 --- a/compiler/frontend/src/jet/Library.jet +++ b/compiler/frontend/src/jet/Library.jet @@ -16,8 +16,6 @@ public fun Any?.equals(other : Any?) : Boolean// = this === other // Returns "null" for null public fun Any?.toString() : String// = this === other -public fun T?.sure() : T - public fun String?.plus(other: Any?) : String public trait Comparable { diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index a54b8e46855..3d970d9250b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -64,10 +64,15 @@ public interface JetNodeTypes { JetNodeType VALUE_ARGUMENT = new JetNodeType("VALUE_ARGUMENT", JetValueArgument.class); JetNodeType VALUE_ARGUMENT_NAME = new JetNodeType("VALUE_ARGUMENT_NAME", JetValueArgumentName.class); JetNodeType TYPE_REFERENCE = new JetNodeType("TYPE_REFERENCE", JetTypeReference.class); + + @Deprecated // Tuples are to be removed in Kotlin M4 JetNodeType LABELED_TUPLE_ENTRY = new JetNodeType("LABELED_TUPLE_ENTRY"); + @Deprecated // Tuples are to be removed in Kotlin M4 JetNodeType LABELED_TUPLE_TYPE_ENTRY = new JetNodeType("LABELED_TUPLE_TYPE_ENTRY"); JetNodeType USER_TYPE = new JetNodeType("USER_TYPE", JetUserType.class); + + @Deprecated // Tuples are to be removed in Kotlin M4 JetNodeType TUPLE_TYPE = new JetNodeType("TUPLE_TYPE", JetTupleType.class); JetNodeType FUNCTION_TYPE = new JetNodeType("FUNCTION_TYPE", JetFunctionType.class); JetNodeType SELF_TYPE = new JetNodeType("SELF_TYPE", JetSelfType.class); @@ -95,6 +100,7 @@ public interface JetNodeTypes { JetNodeType LITERAL_STRING_TEMPLATE_ENTRY = new JetNodeType("LITERAL_STRING_TEMPLATE_ENTRY", JetLiteralStringTemplateEntry.class); JetNodeType ESCAPE_STRING_TEMPLATE_ENTRY = new JetNodeType("ESCAPE_STRING_TEMPLATE_ENTRY", JetEscapeStringTemplateEntry.class); + @Deprecated // Tuples are to be removed in Kotlin M4 JetNodeType TUPLE = new JetNodeType("TUPLE", JetTupleExpression.class); JetNodeType PARENTHESIZED = new JetNodeType("PARENTHESIZED", JetParenthesizedExpression.class); JetNodeType RETURN = new JetNodeType("RETURN", JetReturnExpression.class); @@ -136,9 +142,7 @@ public interface JetNodeTypes { JetNodeType ARRAY_ACCESS_EXPRESSION = new JetNodeType("ARRAY_ACCESS_EXPRESSION", JetArrayAccessExpression.class); JetNodeType INDICES = new JetNodeType("INDICES", JetContainerNode.class); JetNodeType DOT_QUALIFIED_EXPRESSION = new JetNodeType("DOT_QUALIFIED_EXPRESSION", JetDotQualifiedExpression.class); - JetNodeType HASH_QUALIFIED_EXPRESSION = new JetNodeType("HASH_QUALIFIED_EXPRESSION", JetHashQualifiedExpression.class); JetNodeType SAFE_ACCESS_EXPRESSION = new JetNodeType("SAFE_ACCESS_EXPRESSION", JetSafeQualifiedExpression.class); -// JetNodeType PREDICATE_EXPRESSION = new JetNodeType("PREDICATE_EXPRESSION", JetPredicateExpression.class); JetNodeType OBJECT_LITERAL = new JetNodeType("OBJECT_LITERAL", JetObjectLiteralExpression.class); JetNodeType ROOT_NAMESPACE = new JetNodeType("ROOT_NAMESPACE", JetRootNamespaceExpression.class); diff --git a/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzerFacade.java b/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzerFacade.java index 852378c0f17..eb7256f0ec9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzerFacade.java +++ b/compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzerFacade.java @@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BodiesResolveContext; +import org.jetbrains.jet.lang.resolve.lazy.ResolveSession; import java.util.Collection; import java.util.List; @@ -51,4 +52,10 @@ public interface AnalyzerFacade { @NotNull BodiesResolveContext bodiesResolveContext, @NotNull ModuleConfiguration configuration ); + + @NotNull + ResolveSession getLazyResolveSession( + @NotNull Project project, + @NotNull Collection files + ); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorBase.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorBase.java index f0f55b92c9a..ac146f295af 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorBase.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorBase.java @@ -36,7 +36,9 @@ public abstract class ClassDescriptorBase implements ClassDescriptor { @NotNull @Override public JetScope getMemberScope(List typeArguments) { - assert typeArguments.size() == getTypeConstructor().getParameters().size(); + assert typeArguments.size() == getTypeConstructor().getParameters().size() : "Illegal number of type arguments: expected " + + getTypeConstructor().getParameters().size() + " but was " + typeArguments.size() + + " for " + getTypeConstructor() + " " + getTypeConstructor().getParameters(); if (typeArguments.isEmpty()) return getScopeForMemberLookup(); List typeParameters = getTypeConstructor().getParameters(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java index c4e04e927c0..f589280efbd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java @@ -25,9 +25,11 @@ import org.jetbrains.jet.lang.resolve.scopes.SubstitutingScope; import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.*; -import org.jetbrains.jet.lang.types.lang.JetStandardClasses; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * @author abreslav @@ -40,54 +42,54 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem private ConstructorDescriptor primaryConstructor; private ReceiverDescriptor implicitReceiver; private final Modality modality; + private ClassDescriptor classObjectDescriptor; + private final ClassKind kind; + + public ClassDescriptorImpl( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull List annotations, + @NotNull Modality modality, + @NotNull Name name + ) { + this(containingDeclaration, ClassKind.CLASS, annotations, modality, name); + } public ClassDescriptorImpl( @NotNull DeclarationDescriptor containingDeclaration, + @NotNull ClassKind kind, @NotNull List annotations, @NotNull Modality modality, @NotNull Name name) { super(containingDeclaration, annotations, name); + this.kind = kind; this.modality = modality; } - public final ClassDescriptorImpl initialize(boolean sealed, - @NotNull List typeParameters, - @NotNull Collection supertypes, - @NotNull JetScope memberDeclarations, - @NotNull Set constructors, - @Nullable ConstructorDescriptor primaryConstructor) { - return initialize(sealed, typeParameters, supertypes, memberDeclarations, constructors, primaryConstructor, getClassType(supertypes)); - } - public final ClassDescriptorImpl initialize(boolean sealed, - @NotNull List typeParameters, - @NotNull Collection supertypes, - @NotNull JetScope memberDeclarations, - @NotNull Set constructors, - @Nullable ConstructorDescriptor primaryConstructor, - @Nullable JetType superclassType) { + public final ClassDescriptorImpl initialize( + boolean sealed, + @NotNull List typeParameters, + @NotNull Collection supertypes, + @NotNull JetScope memberDeclarations, + @NotNull Set constructors, + @Nullable ConstructorDescriptor primaryConstructor + ) { this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), sealed, getName().getName(), typeParameters, supertypes); this.memberDeclarations = memberDeclarations; this.constructors = constructors; this.primaryConstructor = primaryConstructor; + this.classObjectDescriptor = classObjectDescriptor; return this; } - @NotNull - private JetType getClassType(@NotNull Collection types) { - for (JetType type : types) { - ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(type); - if (classDescriptor != null) { - return type; - } - } - return JetStandardClasses.getAnyType(); - } - public void setPrimaryConstructor(@NotNull ConstructorDescriptor primaryConstructor) { this.primaryConstructor = primaryConstructor; } + public void setClassObjectDescriptor(@NotNull ClassDescriptor classObjectDescriptor) { + this.classObjectDescriptor = classObjectDescriptor; + } + @Override @NotNull public TypeConstructor getTypeConstructor() { @@ -126,18 +128,18 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem @Override public JetType getClassObjectType() { - return null; + return getClassObjectDescriptor().getDefaultType(); } @Override public ClassDescriptor getClassObjectDescriptor() { - return null; + return classObjectDescriptor; } @NotNull @Override public ClassKind getKind() { - return ClassKind.CLASS; + return kind; } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 627140be7d7..500918719f7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -47,6 +47,12 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING; */ public interface Errors { + // TODO: Temporary error message: to deprecate tuples we report this error and provide a quick fix + @Deprecated // Tuples will be dropped in Kotlin M4 + SimpleDiagnosticFactory TUPLES_ARE_NOT_SUPPORTED = SimpleDiagnosticFactory.create(ERROR); + @Deprecated // Tuples will be dropped in Kotlin M4 + SimpleDiagnosticFactory TUPLES_ARE_NOT_SUPPORTED_BIG = SimpleDiagnosticFactory.create(ERROR); + DiagnosticFactory1 EXCEPTION_WHILE_ANALYZING = DiagnosticFactory1.create(ERROR); UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = UnresolvedReferenceDiagnosticFactory.create(); @@ -70,6 +76,8 @@ public interface Errors { .create(WARNING, positionModifier(JetTokens.OPEN_KEYWORD)); SimpleDiagnosticFactory OPEN_MODIFIER_IN_ENUM = SimpleDiagnosticFactory .create(ERROR, positionModifier(JetTokens.OPEN_KEYWORD)); + SimpleDiagnosticFactory ILLEGAL_ENUM_ANNOTATION = SimpleDiagnosticFactory + .create(ERROR, positionModifier(JetTokens.ENUM_KEYWORD)); SimpleDiagnosticFactory REDUNDANT_MODIFIER_IN_GETTER = SimpleDiagnosticFactory.create(WARNING); SimpleDiagnosticFactory TRAIT_CAN_NOT_BE_FINAL = SimpleDiagnosticFactory.create(ERROR); @@ -151,6 +159,7 @@ public interface Errors { DiagnosticFactory1 ENUM_ENTRY_SHOULD_BE_INITIALIZED = DiagnosticFactory1.create(ERROR, NAME_IDENTIFIER); DiagnosticFactory1 ENUM_ENTRY_ILLEGAL_TYPE = DiagnosticFactory1.create(ERROR); + SimpleDiagnosticFactory ENUM_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR); DiagnosticFactory1 UNINITIALIZED_VARIABLE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 UNINITIALIZED_PARAMETER = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java index c61c72225ff..adb4ec7b05b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java @@ -45,6 +45,11 @@ public class DefaultErrorMessages { public static final DiagnosticRenderer RENDERER = new DispatchingDiagnosticRenderer(MAP); static { + + // TODO: remove when tuples are completely dropped + MAP.put(TUPLES_ARE_NOT_SUPPORTED, "Tuples are not supported. In the IDE you can use Alt+Enter to replace tuples with library classes"); + MAP.put(TUPLES_ARE_NOT_SUPPORTED_BIG, "Tuples are not supported. Use data classes instead"); + MAP.put(EXCEPTION_WHILE_ANALYZING, "{0}", new Renderer() { @NotNull @Override @@ -82,6 +87,7 @@ public class DefaultErrorMessages { MAP.put(ABSTRACT_MODIFIER_IN_TRAIT, "Modifier ''abstract'' is redundant in trait"); MAP.put(OPEN_MODIFIER_IN_TRAIT, "Modifier ''open'' is redundant in trait"); MAP.put(OPEN_MODIFIER_IN_ENUM, "Modifier ''open'' is not applicable for enum class"); + MAP.put(ILLEGAL_ENUM_ANNOTATION, "Annotation ''enum'' is only applicable for class"); MAP.put(REDUNDANT_MODIFIER_IN_GETTER, "Visibility modifiers are redundant in getter"); MAP.put(TRAIT_CAN_NOT_BE_FINAL, "Trait cannot be final"); MAP.put(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, @@ -95,7 +101,7 @@ public class DefaultErrorMessages { MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME); MAP.put(USELESS_HIDDEN_IMPORT, "Useless import, it is hidden further"); MAP.put(USELESS_SIMPLE_IMPORT, "Useless import, does nothing"); - MAP.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class shouldn''t be used in Kotlin. Use {0} instead.", CLASS_DESCRIPTOR_LIST); + MAP.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class shouldn''t be used in Kotlin. Use {0} instead.", CLASSES_OR_SEPARATED); MAP.put(CANNOT_INFER_PARAMETER_TYPE, "Cannot infer a type for this parameter. To specify it explicitly use the {(p : Type) => ...} notation"); @@ -164,6 +170,7 @@ public class DefaultErrorMessages { MAP.put(ENUM_ENTRY_SHOULD_BE_INITIALIZED, "Missing delegation specifier ''{0}''", NAME); MAP.put(ENUM_ENTRY_ILLEGAL_TYPE, "The type constructor of enum entry should be ''{0}''", NAME); + MAP.put(ENUM_NOT_ALLOWED, "Enum class is not allowed here"); MAP.put(UNINITIALIZED_VARIABLE, "Variable ''{0}'' must be initialized", NAME); MAP.put(UNINITIALIZED_PARAMETER, "Parameter ''{0}'' is uninitialized here", NAME); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java index c1548586aa2..2dc18de1cba 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/Renderers.java @@ -288,20 +288,22 @@ public class Renderers { return result; } - public static final Renderer> CLASS_DESCRIPTOR_LIST = new Renderer>() { + public static final Renderer> CLASSES_OR_SEPARATED = new Renderer>() { @NotNull @Override public String render(@NotNull Collection descriptors) { StringBuilder sb = new StringBuilder(); - sb.append("("); - for (Iterator iterator = descriptors.iterator(); iterator.hasNext(); ) { - ClassDescriptor descriptor = iterator.next(); + int index = 0; + for (ClassDescriptor descriptor : descriptors) { sb.append(DescriptorUtils.getFQName(descriptor).getFqName()); - if (iterator.hasNext()) { + index++; + if (index <= descriptors.size() - 2) { sb.append(", "); } + else if (index == descriptors.size() - 1) { + sb.append(" or "); + } } - sb.append(")"); return sb.toString(); } }; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index 52fed0377c7..9f6affc057d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -1591,6 +1591,7 @@ public class JetExpressionParsing extends AbstractJetParsing { * : "#" "(" (((SimpleName "=")? expression){","})? ")" * ; */ + @Deprecated // Tuples are to be removed in Kotlin M4 private void parseTupleExpression() { assert _at(HASH); PsiBuilder.Marker mark = mark(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java index 6ad6630245c..1d06761468e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -980,8 +980,7 @@ public class JetParsing extends AbstractJetParsing { expect(IDENTIFIER, "Expecting parameter name", TokenSet.create(RPAR, COLON, LBRACE, EQ)); if (at(COLON)) { - advance(); - + advance(); // COLON parseTypeRef(); } setterParameter.done(VALUE_PARAMETER); @@ -1565,6 +1564,7 @@ public class JetParsing extends AbstractJetParsing { * : "#" "(" parameter{","} ")" // tuple with named entries, the names do not affect assignment compatibility * ; */ + @Deprecated // Tuples are to be removed in Kotlin M4 private void parseTupleType() { assert _at(HASH); @@ -1730,20 +1730,23 @@ public class JetParsing extends AbstractJetParsing { private boolean parseFunctionParameterRest() { expect(IDENTIFIER, "Parameter name expected", PARAMETER_NAME_RECOVERY_SET); + boolean noErrors = true; + if (at(COLON)) { advance(); // COLON parseTypeRef(); } else { - error("Parameters must have type annotation"); - return false; + errorWithRecovery("Parameters must have type annotation", PARAMETER_NAME_RECOVERY_SET); + noErrors = false; } if (at(EQ)) { advance(); // EQ myExpressionParsing.parseExpression(); } - return true; + + return noErrors; } /* diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTupleExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTupleExpression.java index c6212f6d536..dca8595ce39 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTupleExpression.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTupleExpression.java @@ -25,7 +25,10 @@ import java.util.List; /** * @author max */ +@Deprecated // Tuples are to be removed in Kotlin M4 public class JetTupleExpression extends JetExpressionImpl { + + @Deprecated // Tuples are to be removed in Kotlin M4 public JetTupleExpression(@NotNull ASTNode node) { super(node); } @@ -40,6 +43,7 @@ public class JetTupleExpression extends JetExpressionImpl { return visitor.visitTupleExpression(this, data); } + @Deprecated // Tuples are to be removed in Kotlin M4 public List getEntries() { return PsiTreeUtil.getChildrenOfTypeAsList(this, JetExpression.class); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTupleType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTupleType.java index 872d7ae19a5..a4b71278e6c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTupleType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTupleType.java @@ -25,7 +25,10 @@ import java.util.List; /** * @author max */ +@Deprecated // Tuples are to be removed in Kotlin M4 public class JetTupleType extends JetTypeElement { + + @Deprecated // Tuples are to be removed in Kotlin M4 public JetTupleType(@NotNull ASTNode node) { super(node); } @@ -47,6 +50,7 @@ public class JetTupleType extends JetTypeElement { } @NotNull + @Deprecated // Tuples are to be removed in Kotlin M4 public List getComponentTypeRefs() { return findChildrenByType(JetNodeTypes.TYPE_REFERENCE); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java index 9a3e8a026df..fe9bda0f82b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java @@ -168,6 +168,7 @@ public class JetVisitor extends PsiElementVisitor { return visitExpression(expression, data); } + @Deprecated // Tuples are to be removed in Kotlin M4 public R visitTupleExpression(JetTupleExpression expression, D data) { return visitExpression(expression, data); } @@ -336,6 +337,7 @@ public class JetVisitor extends PsiElementVisitor { return visitTypeElement(type, data); } + @Deprecated // Tuples are to be removed in Kotlin M4 public R visitTupleType(JetTupleType type, D data) { return visitTypeElement(type, data); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java index b1aafd75e77..0092d06c5e0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java @@ -158,6 +158,7 @@ public class JetVisitorVoid extends PsiElementVisitor { visitExpression(expression); } + @Deprecated // Tuples are to be removed in Kotlin M4 public void visitTupleExpression(JetTupleExpression expression) { visitExpression(expression); } @@ -325,6 +326,7 @@ public class JetVisitorVoid extends PsiElementVisitor { visitTypeElement(type); } + @Deprecated // Tuples are to be removed in Kotlin M4 public void visitTupleType(JetTupleType type) { visitTypeElement(type); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java index a82dcc47615..48fe2cb0e8e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContext.java @@ -16,9 +16,11 @@ package org.jetbrains.jet.lang.resolve; +import com.google.common.collect.ImmutableMap; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.diagnostics.Diagnostic; @@ -59,6 +61,13 @@ public interface BindingContext { public Collection getKeys(WritableSlice slice) { return Collections.emptyList(); } + + @NotNull + @TestOnly + @Override + public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) { + return ImmutableMap.of(); + } }; WritableSlice ANNOTATION_DESCRIPTOR_TO_PSI_ELEMENT = Slices.createSimpleSlice(); @@ -221,6 +230,8 @@ public interface BindingContext { ReadOnlySlice DECLARATION_TO_DESCRIPTOR = Slices.sliceBuilder() .setFurtherLookupSlices(DECLARATIONS_TO_DESCRIPTORS).build(); + WritableSlice IS_ENUM_MOVED_TO_CLASS_OBJECT = Slices.createSimpleSlice(); + WritableSlice LABEL_TARGET = Slices.sliceBuilder().build(); WritableSlice VALUE_PARAMETER_AS_PROPERTY = Slices.sliceBuilder().build(); @@ -253,4 +264,9 @@ public interface BindingContext { // slice.isCollective() must be true @NotNull Collection getKeys(WritableSlice slice); + + /** This method should be used only for debug and testing */ + @TestOnly + @NotNull + ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java index 3eddd9bf206..e22ae473589 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingTraceContext.java @@ -16,8 +16,10 @@ package org.jetbrains.jet.lang.resolve; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.util.slicedmap.MutableSlicedMap; import org.jetbrains.jet.util.slicedmap.ReadOnlySlice; @@ -52,6 +54,13 @@ public class BindingTraceContext implements BindingTrace { public Collection getKeys(WritableSlice slice) { return BindingTraceContext.this.getKeys(slice); } + + @NotNull + @TestOnly + @Override + public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) { + return map.getSliceContents(slice); + } }; @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java index e108a350e77..49dd267746c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java @@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; +import org.jetbrains.jet.resolve.DescriptorRenderer; import javax.inject.Inject; import java.util.*; @@ -302,7 +303,8 @@ public class DeclarationResolver { if (descriptors.size() > 1) { for (DeclarationDescriptor declarationDescriptor : descriptors) { for (PsiElement declaration : getDeclarationsByDescriptor(declarationDescriptor)) { - assert declaration != null; + assert declaration != null : "Null declaration for descriptor: " + declarationDescriptor + " " + + (declarationDescriptor != null ? DescriptorRenderer.TEXT.render(declarationDescriptor) : ""); trace.report(REDECLARATION.on(declaration, declarationDescriptor.getName().getName())); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java index e58890599eb..c8387e11037 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java @@ -66,6 +66,7 @@ public class DeclarationsChecker { MutableClassDescriptor objectDescriptor = entry.getValue(); if (!bodiesResolveContext.completeAnalysisNeeded(objectDeclaration)) continue; + checkObject(objectDeclaration); modifiersChecker.checkIllegalModalityModifiers(objectDeclaration); } @@ -91,12 +92,22 @@ public class DeclarationsChecker { } + private void reportErrorIfHasEnumModifier(JetModifierListOwner declaration) { + if (declaration.hasModifier(JetTokens.ENUM_KEYWORD)) { + trace.report(ILLEGAL_ENUM_ANNOTATION.on(declaration)); + } + } + + private void checkObject(JetObjectDeclaration declaration) { + reportErrorIfHasEnumModifier(declaration); + } + private void checkClass(JetClass aClass, MutableClassDescriptor classDescriptor) { checkOpenMembers(classDescriptor); if (aClass.isTrait()) { checkTraitModifiers(aClass); } - else if (aClass.hasModifier(JetTokens.ENUM_KEYWORD)) { + else if (classDescriptor.getKind() == ClassKind.ENUM_CLASS) { checkEnumModifiers(aClass); } else if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY) { @@ -105,6 +116,7 @@ public class DeclarationsChecker { } private void checkTraitModifiers(JetClass aClass) { + reportErrorIfHasEnumModifier(aClass); JetModifierList modifierList = aClass.getModifierList(); if (modifierList == null) return; if (modifierList.hasModifier(JetTokens.FINAL_KEYWORD)) { @@ -130,6 +142,7 @@ public class DeclarationsChecker { } private void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor) { + reportErrorIfHasEnumModifier(property); DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration(); if (containingDeclaration instanceof ClassDescriptor) { checkPropertyAbstractness(property, propertyDescriptor, (ClassDescriptor) containingDeclaration); @@ -247,6 +260,7 @@ public class DeclarationsChecker { } protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) { + reportErrorIfHasEnumModifier(function); DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration(); boolean hasAbstractModifier = function.hasModifier(JetTokens.ABSTRACT_KEYWORD); checkDeclaredTypeInPublicMember(function, functionDescriptor); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatingBindingTrace.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatingBindingTrace.java index a31a5581000..110abc5c45e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatingBindingTrace.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegatingBindingTrace.java @@ -16,10 +16,11 @@ package org.jetbrains.jet.lang.resolve; -import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.util.slicedmap.*; @@ -55,6 +56,15 @@ public class DelegatingBindingTrace implements BindingTrace { return DelegatingBindingTrace.this.getKeys(slice); } + + @NotNull + @TestOnly + @Override + public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) { + ImmutableMap parentContents = parentContext.getSliceContents(slice); + ImmutableMap currentContents = map.getSliceContents(slice); + return ImmutableMap.builder().putAll(parentContents).putAll(currentContents).build(); + } }; public DelegatingBindingTrace(BindingContext parentContext) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java index 2413cd5bd85..990ab991d7d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java @@ -355,4 +355,14 @@ public class DescriptorUtils { + (classifier == null ? "null" : classifier.getClass()); return (ClassDescriptor) classifier; } + + @SuppressWarnings("unchecked") + public static Collection getInnerClasses(ClassDescriptor classDescriptor) { + Collection innerClasses = classDescriptor.getUnsubstitutedInnerClassesScope().getAllDescriptors(); + for (DeclarationDescriptor inner : innerClasses) { + assert inner instanceof ClassDescriptor + : "Not a class in inner classes scope of " + classDescriptor + ": " + inner; + } + return (Collection) innerClasses; + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java index 1ae075bac8e..866eeff1f06 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java @@ -184,22 +184,25 @@ public class OverrideResolver { @NotNull ClassDescriptor current, @NotNull DescriptorSink sink ) { - List notOverridden = Lists.newArrayList(membersFromSupertypes); + Collection notOverridden = Sets.newLinkedHashSet(membersFromSupertypes); for (CallableMemberDescriptor fromCurrent : membersFromCurrent) { - extractAndBindOverridesForMember(fromCurrent, notOverridden, current, sink); + Collection bound = + extractAndBindOverridesForMember(fromCurrent, membersFromSupertypes, current, sink); + notOverridden.removeAll(bound); } createAndBindFakeOverrides(current, notOverridden, sink); } - private static void extractAndBindOverridesForMember( + private static Collection extractAndBindOverridesForMember( @NotNull CallableMemberDescriptor fromCurrent, - @NotNull List notOverridden, @NotNull ClassDescriptor current, + @NotNull Collection descriptorsFromSuper, + @NotNull ClassDescriptor current, @NotNull DescriptorSink sink ) { - for (Iterator iterator = notOverridden.iterator(); iterator.hasNext(); ) { - CallableMemberDescriptor fromSupertype = iterator.next(); + Collection bound = Lists.newArrayList(); + for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) { OverridingUtil.OverrideCompatibilityInfo.Result result = OverridingUtil.isOverridableBy(fromSupertype, fromCurrent).getResult(); @@ -209,23 +212,24 @@ public class OverrideResolver { if (isVisible) { OverridingUtil.bindOverride(fromCurrent, fromSupertype); } - iterator.remove(); + bound.add(fromSupertype); break; case CONFLICT: if (isVisible) { sink.conflict(fromSupertype, fromCurrent); } - iterator.remove(); + bound.add(fromSupertype); break; case INCOMPATIBLE: break; } } + return bound; } private static void createAndBindFakeOverrides( @NotNull ClassDescriptor current, - @NotNull List notOverridden, + @NotNull Collection notOverridden, @NotNull DescriptorSink sink ) { Queue fromSuperQueue = new LinkedList(notOverridden); @@ -735,7 +739,7 @@ public class OverrideResolver { if (OverridingUtil.isOverridableBy(fromSuper, declared).getResult() == OVERRIDABLE) { invisibleOverride = fromSuper; if (Visibilities.isVisible(fromSuper, declared)) { - throw new IllegalStateException("Descriptor " + fromSuper + "is overridable by " + declared + " and visible but does not appear in its getOverriddenDescriptors()"); + throw new IllegalStateException("Descriptor " + fromSuper + " is overridable by " + declared + " and visible but does not appear in its getOverriddenDescriptors()"); } break outer; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java index 4e95b5b8d47..09edbc218c6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; +import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.util.containers.ContainerUtil; @@ -195,164 +196,14 @@ public class TypeHierarchyResolver { ) { final Collection forDeferredResolve = new ArrayList(); + ClassifierCollector collector = new ClassifierCollector(outerScope, owner, forDeferredResolve); + for (PsiElement declaration : declarations) { - declaration.accept(new JetVisitorVoid() { - @Override - public void visitJetFile(JetFile file) { - NamespaceDescriptorImpl namespaceDescriptor = namespaceFactory.createNamespaceDescriptorPathIfNeeded( - file, outerScope, RedeclarationHandler.DO_NOTHING); - context.getNamespaceDescriptors().put(file, namespaceDescriptor); - - WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), - new TraceBasedRedeclarationHandler(trace), "namespace"); - namespaceScope.changeLockLevel(WritableScope.LockLevel.BOTH); - context.getNamespaceScopes().put(file, namespaceScope); - - if (file.isScript()) { - scriptHeaderResolver.processScriptHierarchy(file.getScript(), namespaceScope); - } - - prepareForDeferredCall(namespaceScope, namespaceDescriptor, file); - } - - @Override - public void visitClass(JetClass klass) { - MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor( - owner.getOwnerForChildren(), outerScope, getClassKind(klass), JetPsiUtil.safeName(klass.getName())); - context.getClasses().put(klass, mutableClassDescriptor); - trace.record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(klass), mutableClassDescriptor); - - createClassObjectForEnumClass(klass, mutableClassDescriptor); - - JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution(); - - prepareForDeferredCall(classScope, mutableClassDescriptor, klass); - - owner.addClassifierDescriptor(mutableClassDescriptor); - } - - @Override - public void visitObjectDeclaration(JetObjectDeclaration declaration) { - MutableClassDescriptor objectDescriptor = - createClassDescriptorForObject(declaration, owner, outerScope, JetPsiUtil.safeName(declaration.getName()), - ClassKind.OBJECT); - owner.addObjectDescriptor(objectDescriptor); - trace.record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(declaration), objectDescriptor); - } - - @Override - public void visitEnumEntry(JetEnumEntry enumEntry) { - // TODO: Bad casting - MutableClassDescriptorLite ownerClassDescriptor = (MutableClassDescriptorLite) owner.getOwnerForChildren(); - MutableClassDescriptorLite classObjectDescriptor = ownerClassDescriptor.getClassObjectDescriptor(); - - assert classObjectDescriptor != null : enumEntry.getParent().getText(); - createClassDescriptorForEnumEntry(enumEntry, classObjectDescriptor.getBuilder()); - } - - @Override - public void visitTypedef(JetTypedef typedef) { - trace.report(UNSUPPORTED.on(typedef, "TypeHierarchyResolver")); - } - - @Override - public void visitClassObject(JetClassObject classObject) { - JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration(); - if (objectDeclaration != null) { - Name classObjectName = getClassObjectName(owner.getOwnerForChildren().getName()); - MutableClassDescriptor classObjectDescriptor = - createClassDescriptorForObject(objectDeclaration, owner, getStaticScope(classObject, owner), - classObjectName, ClassKind.CLASS_OBJECT); - NamespaceLikeBuilder.ClassObjectStatus status = owner.setClassObjectDescriptor(classObjectDescriptor); - switch (status) { - case DUPLICATE: - trace.report(MANY_CLASS_OBJECTS.on(classObject)); - break; - case NOT_ALLOWED: - trace.report(CLASS_OBJECT_NOT_ALLOWED.on(classObject)); - break; - case OK: - // Everything is OK so no errors to trace. - break; - } - } - } - - private void createClassObjectForEnumClass(JetClass klass, MutableClassDescriptor mutableClassDescriptor) { - if (klass.hasModifier(JetTokens.ENUM_KEYWORD)) { - MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor( - mutableClassDescriptor, outerScope, ClassKind.CLASS_OBJECT, - getClassObjectName(klass.getName())); - mutableClassDescriptor.getBuilder().setClassObjectDescriptor(classObjectDescriptor); - classObjectDescriptor.setModality(Modality.FINAL); - classObjectDescriptor.setVisibility(ModifiersChecker.resolveVisibilityFromModifiers(klass)); - classObjectDescriptor.setTypeParameterDescriptors(new ArrayList(0)); - classObjectDescriptor.createTypeConstructor(); - ConstructorDescriptorImpl primaryConstructorForObject = - createPrimaryConstructorForObject(null, classObjectDescriptor); - primaryConstructorForObject.setReturnType(classObjectDescriptor.getDefaultType()); - classObjectDescriptor.getBuilder().addFunctionDescriptor(DescriptorResolver.createEnumClassObjectValuesMethod(classObjectDescriptor, trace)); - classObjectDescriptor.getBuilder().addFunctionDescriptor(DescriptorResolver.createEnumClassObjectValueOfMethod(classObjectDescriptor, trace)); - } - } - - private MutableClassDescriptor createClassDescriptorForObject( - @NotNull JetObjectDeclaration declaration, @NotNull NamespaceLikeBuilder owner, - @NotNull JetScope scope, @NotNull Name name, @NotNull ClassKind kind - ) { - MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor( - owner.getOwnerForChildren(), scope, kind, name); - context.getObjects().put(declaration, mutableClassDescriptor); - - JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution(); - - prepareForDeferredCall(classScope, mutableClassDescriptor, declaration); - - createPrimaryConstructorForObject(declaration, mutableClassDescriptor); - trace.record(BindingContext.CLASS, declaration, mutableClassDescriptor); - return mutableClassDescriptor; - } - - private MutableClassDescriptor createClassDescriptorForEnumEntry( - @NotNull JetEnumEntry declaration, - @NotNull NamespaceLikeBuilder owner - ) { - MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor( - owner.getOwnerForChildren(), getStaticScope(declaration, owner), ClassKind.ENUM_ENTRY, - JetPsiUtil.safeName(declaration.getName())); - context.getClasses().put(declaration, mutableClassDescriptor); - - prepareForDeferredCall(mutableClassDescriptor.getScopeForMemberResolution(), mutableClassDescriptor, declaration); - - // ??? - is enum entry object? - createPrimaryConstructorForObject(declaration, mutableClassDescriptor); - owner.addObjectDescriptor(mutableClassDescriptor); - trace.record(BindingContext.CLASS, declaration, mutableClassDescriptor); - return mutableClassDescriptor; - } - - private ConstructorDescriptorImpl createPrimaryConstructorForObject( - @Nullable PsiElement object, - MutableClassDescriptor mutableClassDescriptor - ) { - ConstructorDescriptorImpl constructorDescriptor = DescriptorResolver - .createAndRecordPrimaryConstructorForObject(object, mutableClassDescriptor, trace); - mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor, trace); - return constructorDescriptor; - } - - private void prepareForDeferredCall( - @NotNull JetScope outerScope, - @NotNull WithDeferredResolve withDeferredResolve, - @NotNull JetDeclarationContainer container - ) { - forDeferredResolve.add(container); - context.normalScope.put(container, outerScope); - context.forDeferredResolver.put(container, withDeferredResolve); - } - }); + declaration.accept(collector); } + collector.finishProcessing(); + return forDeferredResolve; } @@ -619,4 +470,255 @@ public class TypeHierarchyResolver { } } } + + private class ClassifierCollector extends JetVisitorVoid { + private final JetScope outerScope; + private final NamespaceLikeBuilder owner; + private final Collection forDeferredResolve; + + private final List enumsToAddLater = new ArrayList(0); + + public ClassifierCollector(@NotNull JetScope outerScope, + @NotNull NamespaceLikeBuilder owner, + @NotNull Collection forDeferredResolve + ) { + this.outerScope = outerScope; + this.owner = owner; + this.forDeferredResolve = forDeferredResolve; + } + + @Override + public void visitJetFile(JetFile file) { + NamespaceDescriptorImpl namespaceDescriptor = namespaceFactory.createNamespaceDescriptorPathIfNeeded( + file, outerScope, RedeclarationHandler.DO_NOTHING); + context.getNamespaceDescriptors().put(file, namespaceDescriptor); + + WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), + new TraceBasedRedeclarationHandler(trace), "namespace"); + namespaceScope.changeLockLevel(WritableScope.LockLevel.BOTH); + context.getNamespaceScopes().put(file, namespaceScope); + + if (file.isScript()) { + scriptHeaderResolver.processScriptHierarchy(file.getScript(), namespaceScope); + } + + prepareForDeferredCall(namespaceScope, namespaceDescriptor, file); + } + + @Override + public void visitClass(JetClass klass) { + if (getClassKind(klass) == ClassKind.ENUM_CLASS && inClass()) { + // Enums inside non-static context are put not to owner, but rather into its class object. + // This is handled after visiting all declarations in this class, because we may or may not + // encounter class object to put this enum into. + enumsToAddLater.add(klass); + return; + } + + MutableClassDescriptor mutableClassDescriptor = createClassDescriptorForClass(klass, owner.getOwnerForChildren()); + + owner.addClassifierDescriptor(mutableClassDescriptor); + } + + private boolean inClass() { + if (!(owner.getOwnerForChildren() instanceof ClassDescriptor)) return false; + ClassKind kind = ((ClassDescriptor) owner.getOwnerForChildren()).getKind(); + return kind == ClassKind.CLASS || kind == ClassKind.ENUM_CLASS || kind == ClassKind.TRAIT; + } + + @Override + public void visitObjectDeclaration(JetObjectDeclaration declaration) { + MutableClassDescriptor objectDescriptor = + createClassDescriptorForObject(declaration, owner, outerScope, JetPsiUtil.safeName(declaration.getName()), + ClassKind.OBJECT); + owner.addObjectDescriptor(objectDescriptor); + trace.record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(declaration), objectDescriptor); + } + + @Override + public void visitEnumEntry(JetEnumEntry enumEntry) { + // TODO: Bad casting + MutableClassDescriptorLite ownerClassDescriptor = (MutableClassDescriptorLite) owner.getOwnerForChildren(); + MutableClassDescriptorLite classObjectDescriptor = ownerClassDescriptor.getClassObjectDescriptor(); + + assert classObjectDescriptor != null : enumEntry.getParent().getText(); + createClassDescriptorForEnumEntry(enumEntry, classObjectDescriptor.getBuilder()); + } + + @Override + public void visitTypedef(JetTypedef typedef) { + trace.report(UNSUPPORTED.on(typedef, "TypeHierarchyResolver")); + } + + @Override + public void visitClassObject(JetClassObject classObject) { + JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration(); + if (objectDeclaration != null) { + Name classObjectName = getClassObjectName(owner.getOwnerForChildren().getName()); + MutableClassDescriptor classObjectDescriptor = + createClassDescriptorForObject(objectDeclaration, owner, getStaticScope(classObject, owner), + classObjectName, ClassKind.CLASS_OBJECT); + NamespaceLikeBuilder.ClassObjectStatus status = owner.setClassObjectDescriptor(classObjectDescriptor); + switch (status) { + case DUPLICATE: + trace.report(MANY_CLASS_OBJECTS.on(classObject)); + break; + case NOT_ALLOWED: + trace.report(CLASS_OBJECT_NOT_ALLOWED.on(classObject)); + break; + case OK: + // Everything is OK so no errors to trace. + break; + } + } + } + + private void createClassObjectForEnumClass(JetClass klass, MutableClassDescriptor mutableClassDescriptor) { + if (mutableClassDescriptor.getKind() == ClassKind.ENUM_CLASS) { + MutableClassDescriptor classObjectDescriptor = + createClassObjectDescriptor(mutableClassDescriptor, ModifiersChecker.resolveVisibilityFromModifiers(klass)); + mutableClassDescriptor.getBuilder().setClassObjectDescriptor(classObjectDescriptor); + classObjectDescriptor.getBuilder().addFunctionDescriptor( + DescriptorResolver.createEnumClassObjectValuesMethod(classObjectDescriptor, trace)); + classObjectDescriptor.getBuilder().addFunctionDescriptor( + DescriptorResolver.createEnumClassObjectValueOfMethod(classObjectDescriptor, trace)); + } + } + + @NotNull + private MutableClassDescriptor createClassObjectDescriptor( + @NotNull ClassDescriptor classDescriptor, + @NotNull Visibility visibility + ) { + MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor( + classDescriptor, outerScope, ClassKind.CLASS_OBJECT, getClassObjectName(classDescriptor.getName())); + classObjectDescriptor.setModality(Modality.FINAL); + classObjectDescriptor.setVisibility(visibility); + classObjectDescriptor.setTypeParameterDescriptors(new ArrayList(0)); + classObjectDescriptor.createTypeConstructor(); + ConstructorDescriptorImpl primaryConstructorForObject = createPrimaryConstructorForObject(null, classObjectDescriptor); + primaryConstructorForObject.setReturnType(classObjectDescriptor.getDefaultType()); + return classObjectDescriptor; + } + + @NotNull + private MutableClassDescriptor createClassDescriptorForClass( + @NotNull JetClass klass, + @NotNull DeclarationDescriptor containingDeclaration + ) { + MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor( + containingDeclaration, outerScope, getClassKind(klass), JetPsiUtil.safeName(klass.getName())); + context.getClasses().put(klass, mutableClassDescriptor); + trace.record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(klass), mutableClassDescriptor); + + createClassObjectForEnumClass(klass, mutableClassDescriptor); + + JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution(); + + prepareForDeferredCall(classScope, mutableClassDescriptor, klass); + + return mutableClassDescriptor; + } + + @NotNull + private MutableClassDescriptor createClassDescriptorForObject( + @NotNull JetObjectDeclaration declaration, @NotNull NamespaceLikeBuilder owner, + @NotNull JetScope scope, @NotNull Name name, @NotNull ClassKind kind + ) { + MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor( + owner.getOwnerForChildren(), scope, kind, name); + context.getObjects().put(declaration, mutableClassDescriptor); + + JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution(); + + prepareForDeferredCall(classScope, mutableClassDescriptor, declaration); + + createPrimaryConstructorForObject(declaration, mutableClassDescriptor); + trace.record(BindingContext.CLASS, declaration, mutableClassDescriptor); + return mutableClassDescriptor; + } + + private MutableClassDescriptor createClassDescriptorForEnumEntry( + @NotNull JetEnumEntry declaration, + @NotNull NamespaceLikeBuilder owner + ) { + MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor( + owner.getOwnerForChildren(), getStaticScope(declaration, owner), ClassKind.ENUM_ENTRY, + JetPsiUtil.safeName(declaration.getName())); + context.getClasses().put(declaration, mutableClassDescriptor); + + prepareForDeferredCall(mutableClassDescriptor.getScopeForMemberResolution(), mutableClassDescriptor, declaration); + + // ??? - is enum entry object? + createPrimaryConstructorForObject(declaration, mutableClassDescriptor); + owner.addObjectDescriptor(mutableClassDescriptor); + trace.record(BindingContext.CLASS, declaration, mutableClassDescriptor); + return mutableClassDescriptor; + } + + private ConstructorDescriptorImpl createPrimaryConstructorForObject( + @Nullable PsiElement object, + MutableClassDescriptor mutableClassDescriptor + ) { + ConstructorDescriptorImpl constructorDescriptor = DescriptorResolver + .createAndRecordPrimaryConstructorForObject(object, mutableClassDescriptor, trace); + mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor, trace); + return constructorDescriptor; + } + + private void prepareForDeferredCall( + @NotNull JetScope outerScope, + @NotNull WithDeferredResolve withDeferredResolve, + @NotNull JetDeclarationContainer container + ) { + forDeferredResolve.add(container); + context.normalScope.put(container, outerScope); + context.forDeferredResolver.put(container, withDeferredResolve); + } + + @Nullable + private MutableClassDescriptor getOrCreateClassObjectDescriptor() { + ClassDescriptor ownerForChildren = (ClassDescriptor) owner.getOwnerForChildren(); + MutableClassDescriptor classObjectDescriptor = (MutableClassDescriptor) ownerForChildren.getClassObjectDescriptor(); + + if (classObjectDescriptor == null) { + classObjectDescriptor = createClassObjectDescriptor(ownerForChildren, Visibilities.PUBLIC); + NamespaceLikeBuilder.ClassObjectStatus status = owner.setClassObjectDescriptor(classObjectDescriptor); + assert status != NamespaceLikeBuilder.ClassObjectStatus.DUPLICATE : + "Attempting to create an artificial class object where the real one exists: " + ownerForChildren; + if (status == NamespaceLikeBuilder.ClassObjectStatus.NOT_ALLOWED) { + return null; + } + } + + return classObjectDescriptor; + } + + private void putEnumsIntoOuterClassObject() { + if (enumsToAddLater.isEmpty()) return; + + MutableClassDescriptor classObjectDescriptor = getOrCreateClassObjectDescriptor(); + if (classObjectDescriptor == null) { + // A class object is not allowed in outer class, so report an error on every declared enum + for (JetClass klass : enumsToAddLater) { + JetModifierList modifierList = klass.getModifierList(); + assert modifierList != null : "Enum class without modifier list: " + klass.getText(); + ASTNode node = modifierList.getModifierNode(JetTokens.ENUM_KEYWORD); + assert node != null : "Enum class without enum modifier: " + klass.getText(); + trace.report(ENUM_NOT_ALLOWED.on(node.getPsi())); + } + return; + } + + for (JetClass klass : enumsToAddLater) { + MutableClassDescriptor mutableClassDescriptor = createClassDescriptorForClass(klass, classObjectDescriptor); + trace.record(BindingContext.IS_ENUM_MOVED_TO_CLASS_OBJECT, mutableClassDescriptor); + classObjectDescriptor.getBuilder().addClassifierDescriptor(mutableClassDescriptor); + } + } + + private void finishProcessing() { + putEnumsIntoOuterClassObject(); + } + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java index 71576375ebe..023cd1edceb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java @@ -37,8 +37,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import static org.jetbrains.jet.lang.diagnostics.Errors.UNSUPPORTED; -import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS; +import static org.jetbrains.jet.lang.diagnostics.Errors.*; /** * @author abreslav @@ -180,6 +179,14 @@ public class TypeResolver { @Override public void visitTupleType(JetTupleType type) { + // TODO: remove this method completely when tuples are droppped + if (type.getComponentTypeRefs().size() <= 3) { + trace.report(TUPLES_ARE_NOT_SUPPORTED.on(type)); + } + else { + trace.report(TUPLES_ARE_NOT_SUPPORTED_BIG.on(type)); + } + // TODO labels result[0] = JetStandardClasses.getTupleType(resolveTypes(scope, type.getComponentTypeRefs(), trace, checkBounds)); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyClassDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyClassDescriptor.java index f223213dbee..4486fc45424 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/LazyClassDescriptor.java @@ -20,6 +20,7 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.google.common.collect.Lists; +import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; @@ -139,7 +140,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes } scope.changeLockLevel(WritableScope.LockLevel.READING); - scopeForClassHeaderResolution = new ChainedScope(this, scope, resolveSession.getResolutionScope(declarationProvider.getOwnerInfo().getScopeAnchor())); + PsiElement scopeAnchor = declarationProvider.getOwnerInfo().getScopeAnchor(); + scopeForClassHeaderResolution = new ChainedScope(this, scope, getScopeProvider().getResolutionScopeForDeclaration(scopeAnchor)); } return scopeForClassHeaderResolution; } @@ -285,8 +287,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes JetModifierList modifierList = classInfo.getModifierList(); if (modifierList != null) { AnnotationResolver annotationResolver = resolveSession.getInjector().getAnnotationResolver(); - annotations = annotationResolver - .resolveAnnotations(resolveSession.getResolutionScope(classInfo.getScopeAnchor()), modifierList, resolveSession.getTrace()); + JetScope scopeForDeclaration = getScopeProvider().getResolutionScopeForDeclaration(classInfo.getScopeAnchor()); + annotations = annotationResolver.resolveAnnotations(scopeForDeclaration, modifierList, resolveSession.getTrace()); } else { annotations = Collections.emptyList(); @@ -426,4 +428,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes }; } + private ScopeProvider getScopeProvider() { + return resolveSession.getInjector().getScopeProvider(); + } + } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java index 0294e3bd6c0..a37def4e990 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSession.java @@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.resolve.BindingTraceContext; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.lang.resolve.scopes.InnerClassesScopeWrapper; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import java.util.List; @@ -135,7 +134,7 @@ public class ResolveSession { if (classOrObject.getParent() instanceof JetClassObject) { return getClassObjectDescriptor((JetClassObject) classOrObject.getParent()); } - JetScope resolutionScope = getInjector().getScopeProvider().getResolutionScopeForDeclaration((JetDeclaration) classOrObject); + JetScope resolutionScope = getInjector().getScopeProvider().getResolutionScopeForDeclaration(classOrObject); Name name = classOrObject.getNameAsName(); assert name != null : "Name is null for " + classOrObject + " " + classOrObject.getText(); ClassifierDescriptor classifier = resolutionScope.getClassifier(name); @@ -170,33 +169,6 @@ public class ResolveSession { return declarationProviderFactory; } - @NotNull - public JetScope getResolutionScope(PsiElement element) { - PsiElement parent = element.getParent(); - if (parent instanceof JetFile) { - JetFile file = (JetFile) parent; - return getInjector().getScopeProvider().getFileScopeForDeclarationResolution(file); - } - - if (parent instanceof JetClassBody) { - return getEnclosingLazyClass(element).getScopeForMemberDeclarationResolution(); - } - - if (parent instanceof JetClassObject) { - return new InnerClassesScopeWrapper(getEnclosingLazyClass(element).getScopeForMemberDeclarationResolution()); - } - - throw new IllegalArgumentException("Unsupported PSI element: " + element); - } - - private LazyClassDescriptor getEnclosingLazyClass(PsiElement element) { - JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(element.getParent(), JetClassOrObject.class); - assert classOrObject != null : "Called for an element that is not a class member: " + element; - ClassDescriptor classDescriptor = getClassDescriptor(classOrObject); - assert classDescriptor instanceof LazyClassDescriptor : "Trying to resolve a member of a non-lazily loaded class: " + element; - return (LazyClassDescriptor) classDescriptor; - } - @NotNull public DeclarationDescriptor resolveToDescriptor(JetDeclaration declaration) { DeclarationDescriptor result = declaration.accept(new JetVisitor() { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSessionUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSessionUtils.java index 1ee8fc80d8f..42f9735cb1b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSessionUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ResolveSessionUtils.java @@ -183,7 +183,7 @@ public class ResolveSessionUtils { JetFile file ) { BodyResolver bodyResolver = createBodyResolver(trace, file, resolveSession.getModuleConfiguration()); - JetScope scope = resolveSession.getResolutionScope(namedFunction); + JetScope scope = resolveSession.getInjector().getScopeProvider().getResolutionScopeForDeclaration(namedFunction); FunctionDescriptor functionDescriptor = (FunctionDescriptor) resolveSession.resolveToDescriptor(namedFunction); bodyResolver.resolveFunctionBody(trace, namedFunction, functionDescriptor, scope); } @@ -216,9 +216,12 @@ public class ResolveSessionUtils { } private static JetScope getExpressionResolutionScope(@NotNull ResolveSession resolveSession, @NotNull JetExpression expression) { + ScopeProvider provider = resolveSession.getInjector().getScopeProvider(); JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetDeclaration.class); - // DeclarationDescriptor descriptor = resolveToDescriptor(parentDeclaration); - return resolveSession.getResolutionScope(parentDeclaration); + if (parentDeclaration == null) { + return provider.getFileScopeForDeclarationResolution((JetFile) expression.getContainingFile()); + } + return provider.getResolutionScopeForDeclaration(parentDeclaration); } public static JetScope getExpressionMemberScope(@NotNull ResolveSession resolveSession, @NotNull JetExpression expression) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ScopeProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ScopeProvider.java index 77c950e0614..9b8bf938314 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ScopeProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/ScopeProvider.java @@ -26,6 +26,9 @@ import org.jetbrains.jet.lang.resolve.ImportsResolver; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.scopes.*; +import java.util.Map; +import java.util.WeakHashMap; + /** * @author abreslav */ @@ -37,56 +40,66 @@ public class ScopeProvider { this.resolveSession = resolveSession; } + private final Map fileScopeCache = new WeakHashMap(); + // This scope does not contain imported functions @NotNull public JetScope getFileScopeForDeclarationResolution(JetFile file) { - // package - JetNamespaceHeader header = file.getNamespaceHeader(); - if (header == null) { - throw new IllegalArgumentException("Scripts are not supported: " + file.getName()); + if (!fileScopeCache.containsKey(file)) { + // package + JetNamespaceHeader header = file.getNamespaceHeader(); + if (header == null) { + throw new IllegalArgumentException("Scripts are not supported: " + file.getName()); + } + + FqName fqName = new FqName(header.getQualifiedName()); + NamespaceDescriptor packageDescriptor = resolveSession.getPackageDescriptorByFqName(fqName); + + if (packageDescriptor == null) { + throw new IllegalStateException("Package not found: " + fqName + " maybe the file is not in scope of this resolve session: " + file.getName()); + } + + WritableScope fileScope = new WritableScopeImpl( + JetScope.EMPTY, packageDescriptor, RedeclarationHandler.DO_NOTHING, "File scope for declaration resolution"); + + fileScope.changeLockLevel(WritableScope.LockLevel.BOTH); + + NamespaceDescriptor rootPackageDescriptor = resolveSession.getPackageDescriptorByFqName(FqName.ROOT); + if (rootPackageDescriptor == null) { + throw new IllegalStateException("Root package not found"); + } + + // Don't import twice + if (!packageDescriptor.getQualifiedName().equals(FqName.ROOT)) { + fileScope.importScope(rootPackageDescriptor.getMemberScope()); + } + + ImportsResolver.processImportsInFile(true, fileScope, Lists.newArrayList(file.getImportDirectives()), + rootPackageDescriptor.getMemberScope(), + resolveSession.getModuleConfiguration(), resolveSession.getTrace(), + resolveSession.getInjector().getQualifiedExpressionResolver()); + + fileScope.changeLockLevel(WritableScope.LockLevel.READING); + fileScopeCache.put(file, new ChainedScope(packageDescriptor, packageDescriptor.getMemberScope(), fileScope)); } - FqName fqName = new FqName(header.getQualifiedName()); - NamespaceDescriptor packageDescriptor = resolveSession.getPackageDescriptorByFqName(fqName); - - if (packageDescriptor == null) { - throw new IllegalStateException("Package not found: " + fqName + " maybe the file is not in scope of this resolve session: " + file.getName()); - } - - WritableScope fileScope = new WritableScopeImpl( - JetScope.EMPTY, packageDescriptor, RedeclarationHandler.DO_NOTHING, "File scope for declaration resolution"); - - fileScope.changeLockLevel(WritableScope.LockLevel.BOTH); - - NamespaceDescriptor rootPackageDescriptor = resolveSession.getPackageDescriptorByFqName(FqName.ROOT); - if (rootPackageDescriptor == null) { - throw new IllegalStateException("Root package not found"); - } - - // Don't import twice - if (!packageDescriptor.getQualifiedName().equals(FqName.ROOT)) { - fileScope.importScope(rootPackageDescriptor.getMemberScope()); - } - - ImportsResolver.processImportsInFile(true, fileScope, Lists.newArrayList(file.getImportDirectives()), - rootPackageDescriptor.getMemberScope(), - resolveSession.getModuleConfiguration(), resolveSession.getTrace(), - resolveSession.getInjector().getQualifiedExpressionResolver()); - - fileScope.changeLockLevel(WritableScope.LockLevel.READING); - - // TODO: Cache - return new ChainedScope(packageDescriptor, packageDescriptor.getMemberScope(), fileScope); + return fileScopeCache.get(file); } @NotNull - public JetScope getResolutionScopeForDeclaration(@NotNull JetDeclaration jetDeclaration) { - PsiElement immediateParent = jetDeclaration.getParent(); - if (immediateParent instanceof JetFile) { - return getFileScopeForDeclarationResolution((JetFile) immediateParent); - } + public JetScope getResolutionScopeForDeclaration(@NotNull PsiElement elementOfDeclaration) { + JetDeclaration jetDeclaration = PsiTreeUtil.getParentOfType(elementOfDeclaration, JetDeclaration.class, false); + + assert !(elementOfDeclaration instanceof JetDeclaration) || jetDeclaration == elementOfDeclaration : + "For JetDeclaration element getParentOfType() should return itself."; JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(jetDeclaration, JetDeclaration.class); + if (parentDeclaration == null) { + return getFileScopeForDeclarationResolution((JetFile) elementOfDeclaration.getContainingFile()); + } + + assert jetDeclaration != null : "Can't happen because of getParentOfType(null, ?) == null"; + if (parentDeclaration instanceof JetClassOrObject) { JetClassOrObject classOrObject = (JetClassOrObject) parentDeclaration; LazyClassDescriptor classDescriptor = (LazyClassDescriptor) resolveSession.getClassDescriptor(classOrObject); @@ -98,13 +111,18 @@ public class ScopeProvider { } return classDescriptor.getScopeForMemberDeclarationResolution(); } - else if (parentDeclaration instanceof JetClassObject) { + + if (parentDeclaration instanceof JetClassObject) { + assert jetDeclaration instanceof JetObjectDeclaration : "Should be situation for getting scope for object in class [object {...}]"; + JetClassObject classObject = (JetClassObject) parentDeclaration; - LazyClassDescriptor classObjectDescriptor = resolveSession.getClassObjectDescriptor(classObject); - return classObjectDescriptor.getScopeForMemberDeclarationResolution(); - } - else { - throw new IllegalStateException("Don't call this method for local declarations: " + jetDeclaration + " " + jetDeclaration.getText()); + LazyClassDescriptor classObjectDescriptor = + (LazyClassDescriptor) resolveSession.getClassObjectDescriptor(classObject).getContainingDeclaration(); + + // During class object header resolve there should be no resolution for parent class generic params + return new InnerClassesScopeWrapper(classObjectDescriptor.getScopeForMemberDeclarationResolution()); } + + throw new IllegalStateException("Don't call this method for local declarations: " + jetDeclaration + " " + jetDeclaration.getText()); } } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 6e8ade4d8ba..65bc1a11294 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -356,6 +356,14 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { @Override public JetTypeInfo visitTupleExpression(JetTupleExpression expression, ExpressionTypingContext context) { + // TODO: remove this method completely when tuples are droppped + if (expression.getEntries().size() <= 3) { + context.trace.report(TUPLES_ARE_NOT_SUPPORTED.on(expression)); + } + else { + context.trace.report(TUPLES_ARE_NOT_SUPPORTED_BIG.on(expression)); + } + List entries = expression.getEntries(); List types = new ArrayList(); for (JetExpression entry : entries) { @@ -882,7 +890,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { return typeInfo; } DataFlowInfo dataFlowInfo = typeInfo.getDataFlowInfo(); - if (isKnownToBeNotNull(baseExpression, context)) { + if (isKnownToBeNotNull(baseExpression, context) && !ErrorUtils.isErrorType(type)) { context.trace.report(UNNECESSARY_NOT_NULL_ASSERTION.on(operationSign, type)); } else { @@ -966,7 +974,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { } else if (OperatorConventions.COMPARISON_OPERATIONS.contains(operationType)) { JetType compareToReturnType = getTypeForBinaryCall(context.scope, Name.identifier("compareTo"), context, expression); - if (compareToReturnType != null) { + if (compareToReturnType != null && !ErrorUtils.isErrorType(compareToReturnType)) { TypeConstructor constructor = compareToReturnType.getConstructor(); JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance(); TypeConstructor intTypeConstructor = standardLibrary.getInt().getTypeConstructor(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java index e7ff6f56e0c..9bf6b06ed00 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardClasses.java @@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.DescriptorResolver; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; @@ -91,7 +92,6 @@ public class JetStandardClasses { }, JetScope.EMPTY, Collections.singleton(constructorDescriptor), - null, null ); NOTHING_TYPE = new JetTypeImpl(getNothing()); @@ -125,7 +125,6 @@ public class JetStandardClasses { Collections.emptySet(), JetScope.EMPTY, Collections.singleton(constructorDescriptor), - null, null ); ANY_TYPE = new JetTypeImpl(ANY.getTypeConstructor(), new JetScopeImpl() { @@ -201,14 +200,84 @@ public class JetStandardClasses { writableScope, Collections.singleton(constructorDescriptor), null); + + if (i == 0) { + // Unit.VALUE + classDescriptor.setClassObjectDescriptor(createClassObjectForUnit(classDescriptor)); + } + TUPLE_CONSTRUCTORS.add(TUPLE[i].getTypeConstructor()); - constructorDescriptor.initialize(classDescriptor.getTypeConstructor().getParameters(), constructorValueParameters, Visibilities.PUBLIC); + constructorDescriptor.initialize(classDescriptor.getTypeConstructor().getParameters(), constructorValueParameters, i == 0 ? Visibilities.PRIVATE : Visibilities.PUBLIC); constructorDescriptor.setReturnType(classDescriptor.getDefaultType()); } } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + @NotNull + private static ClassDescriptor createClassObjectForUnit(@NotNull ClassDescriptorImpl unitClass) { + ClassDescriptorImpl classObjectDescriptor = new ClassDescriptorImpl( + unitClass, + ClassKind.CLASS_OBJECT, + Collections.emptyList(), + Modality.FINAL, + DescriptorUtils.getClassObjectName(unitClass.getName()) + ); + WritableScopeImpl classObjectMemberScope = new WritableScopeImpl( + JetScope.EMPTY, + classObjectDescriptor, + RedeclarationHandler.DO_NOTHING, + "Unit class object members" + ); + PropertyDescriptor valueProperty = createUnitValueProperty(unitClass, classObjectDescriptor); + classObjectMemberScope.addPropertyDescriptor(valueProperty); + classObjectMemberScope.changeLockLevel(WritableScope.LockLevel.READING); + + ConstructorDescriptorImpl classObjectConstructorDescriptor = new ConstructorDescriptorImpl(classObjectDescriptor, Collections.emptyList(), true); + classObjectConstructorDescriptor.initialize( + Collections.emptyList(), + Collections.emptyList(), + Visibilities.PRIVATE + ); + + classObjectDescriptor.initialize( + /*sealed = */ true, + Collections.emptyList(), + Collections.singleton(getAnyType()), + classObjectMemberScope, + Collections.singleton(classObjectConstructorDescriptor), + classObjectConstructorDescriptor + ); + + classObjectConstructorDescriptor.setReturnType(classObjectDescriptor.getDefaultType()); + + return classObjectDescriptor; + } + + @NotNull + private static PropertyDescriptor createUnitValueProperty( + @NotNull ClassDescriptorImpl unitClass, + @NotNull ClassDescriptorImpl unitClassObject + ) { + PropertyDescriptor valueProperty = new PropertyDescriptor( + unitClassObject, + Collections.emptyList(), + Modality.FINAL, + Visibilities.PUBLIC, + /*isVar = */ false, + Name.identifier("VALUE"), + CallableMemberDescriptor.Kind.DECLARATION); + valueProperty.setType( + unitClass.getDefaultType(), + Collections.emptyList(), + unitClassObject.getImplicitReceiver(), + ReceiverDescriptor.NO_RECEIVER); + PropertyGetterDescriptor getter = DescriptorResolver.createDefaultGetter(valueProperty); + getter.initialize(unitClass.getDefaultType()); + valueProperty.initialize(getter, null); + return valueProperty; + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static final int MAX_FUNCTION_ORDER = 22; diff --git a/compiler/frontend/src/org/jetbrains/jet/util/slicedmap/MutableSlicedMap.java b/compiler/frontend/src/org/jetbrains/jet/util/slicedmap/MutableSlicedMap.java index 5d8b30b2e6b..b1af24c2492 100644 --- a/compiler/frontend/src/org/jetbrains/jet/util/slicedmap/MutableSlicedMap.java +++ b/compiler/frontend/src/org/jetbrains/jet/util/slicedmap/MutableSlicedMap.java @@ -16,6 +16,10 @@ package org.jetbrains.jet.util.slicedmap; +import com.google.common.collect.ImmutableMap; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; + /** * @author abreslav */ @@ -26,4 +30,8 @@ public interface MutableSlicedMap extends SlicedMap { V remove(RemovableSlice slice, K key); void clear(); + + @NotNull + @TestOnly + ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice); } diff --git a/compiler/frontend/src/org/jetbrains/jet/util/slicedmap/SlicedMapImpl.java b/compiler/frontend/src/org/jetbrains/jet/util/slicedmap/SlicedMapImpl.java index 91fd6ad3aa2..07210423ee8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/util/slicedmap/SlicedMapImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/util/slicedmap/SlicedMapImpl.java @@ -16,9 +16,11 @@ package org.jetbrains.jet.util.slicedmap; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.util.CommonSuppliers; import java.util.Collection; @@ -106,4 +108,16 @@ public class SlicedMapImpl implements MutableSlicedMap { //noinspection unchecked return (Iterator) map.entrySet().iterator(); } + + @NotNull + @Override + public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) { + ImmutableMap.Builder builder = ImmutableMap.builder(); + for (Map.Entry, ?> entry : map.entrySet()) { + if (entry.getKey().getSlice() == slice) { + builder.put((K) entry.getKey().getKey(), (V) entry.getValue()); + } + } + return builder.build(); + } } diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JavaElementFinder.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JavaElementFinder.java index d678a28e9d1..72d9ee34e19 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JavaElementFinder.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JavaElementFinder.java @@ -29,7 +29,6 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.SmartList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.codegen.NamespaceCodegen; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.java.JavaPsiFacadeKotlinHacks; @@ -41,6 +40,8 @@ import org.jetbrains.jet.util.QualifiedNamesUtil; import java.util.*; +import static org.jetbrains.jet.codegen.CodegenUtil.getLocalNameForObject; + public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacadeKotlinHacks.KotlinFinderMarker { private final Project project; private final PsiManager psiManager; @@ -166,7 +167,7 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade if (given != null) return given; if (declaration instanceof JetObjectDeclaration) { - return CodegenUtil.getLocalNameForObject((JetObjectDeclaration) declaration); + return getLocalNameForObject((JetObjectDeclaration) declaration); } return null; diff --git a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java index 3876582fd74..a8ee19d1825 100644 --- a/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java +++ b/compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java @@ -266,7 +266,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa public static PsiMethod wrapMethod(@NotNull JetNamedFunction function) { //noinspection unchecked if (PsiTreeUtil.getParentOfType(function, JetFunction.class, JetProperty.class) != null) { - // Don't generate method wrappers for internal declarations. Their classes are not generated during calcStub + // Don't genClassOrObject method wrappers for internal declarations. Their classes are not generated during calcStub // with ClassBuilderMode.SIGNATURES mode, and this produces "Class not found exception" in getDelegate() return null; } diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index f4994d4f308..c02a6468cd5 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -864,7 +864,7 @@ public final class jet.LongRange : jet.Range, jet.LongIterable { public final val EMPTY: jet.LongRange } } -public abstract trait jet.Map : jet.Any { +public abstract trait jet.Map : jet.Any { public abstract fun containsKey(/*0*/ key: jet.Any?): jet.Boolean public abstract fun containsValue(/*0*/ value: jet.Any?): jet.Boolean public abstract fun entrySet(): jet.Set> @@ -1123,7 +1123,11 @@ public open class jet.Throwable : jet.Any { public final fun printStackTrace(): jet.Tuple0 } public final class jet.Tuple0 : jet.Any { - public final /*constructor*/ fun (): jet.Tuple0 + private final /*constructor*/ fun (): jet.Tuple0 + public final class object jet.Tuple0. : jet.Any { + private final /*constructor*/ fun (): jet.Tuple0. + public final val VALUE: jet.Tuple0 + } } public final class jet.Tuple1 : jet.Any { public final /*constructor*/ fun (/*0*/ _1: T1): jet.Tuple1 @@ -1466,6 +1470,5 @@ public final fun jet.Iterator.iterator(): jet.Iterator public final fun jet.LongIterator.iterator(): jet.LongIterator public final fun jet.ShortIterator.iterator(): jet.ShortIterator public final fun jet.String?.plus(/*0*/ other: jet.Any?): jet.String -public final fun T?.sure(): T public final fun synchronized(/*0*/ lock: jet.Any, /*1*/ block: jet.Function0): R public final fun jet.Any?.toString(): jet.String diff --git a/compiler/testData/codegen/controlStructures/ifInWhile.jet b/compiler/testData/codegen/controlStructures/ifInWhile.jet index 834c71f2b6f..f0dd043b966 100644 --- a/compiler/testData/codegen/controlStructures/ifInWhile.jet +++ b/compiler/testData/codegen/controlStructures/ifInWhile.jet @@ -1,7 +1,7 @@ import java.lang.Runtime fun box() : String { - val processors = Runtime.getRuntime().sure().availableProcessors() + val processors = Runtime.getRuntime()!!.availableProcessors() var threadNum = 1 while(threadNum <= 1024) { System.out?.println(threadNum) diff --git a/compiler/testData/codegen/dataClasses/equals/genericarray.kt b/compiler/testData/codegen/dataClasses/equals/genericarray.kt new file mode 100644 index 00000000000..46a357ff9c2 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/equals/genericarray.kt @@ -0,0 +1,6 @@ +data class A(val v: Array) + +fun box() : String { + if(A(array(0,1,2)) != A(array(0,1,2))) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/dataClasses/equals/instanceof.kt b/compiler/testData/codegen/dataClasses/equals/instanceof.kt new file mode 100644 index 00000000000..30416c7497a --- /dev/null +++ b/compiler/testData/codegen/dataClasses/equals/instanceof.kt @@ -0,0 +1,13 @@ +class Dummy { + fun equals(other: Any?) = true +} + +open data class A(val v: Any) + +class B(v: Any) : A(v) + +fun box() : String { + val a = A(Dummy()) + val b = B(Dummy()) + return if(b == a) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/dataClasses/equals/intarray.kt b/compiler/testData/codegen/dataClasses/equals/intarray.kt new file mode 100644 index 00000000000..dea1d525996 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/equals/intarray.kt @@ -0,0 +1,6 @@ +data class A(val v: IntArray) + +fun box() : String { + if(A(intArray(0,1,2)) != A(intArray(0,1,2))) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/dataClasses/equals/nullother.kt b/compiler/testData/codegen/dataClasses/equals/nullother.kt new file mode 100644 index 00000000000..900db2781f7 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/equals/nullother.kt @@ -0,0 +1,11 @@ +class Dummy { + fun equals(other: Any?) = true +} + +data class A(val v: Any?) + +fun box() : String { + val a = A(Dummy()) + val b: A? = null + return if(a != b && b != a) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/dataClasses/equals/sameinstance.kt b/compiler/testData/codegen/dataClasses/equals/sameinstance.kt new file mode 100644 index 00000000000..35d3f17d2c4 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/equals/sameinstance.kt @@ -0,0 +1,7 @@ +data class A() + +fun box() : String { + val a = A() + val b = a + return if(b == a) "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/dataClasses/hashcode/array.kt b/compiler/testData/codegen/dataClasses/hashcode/array.kt new file mode 100644 index 00000000000..b9eceabe0ea --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/array.kt @@ -0,0 +1,6 @@ +data class A(val a: IntArray, var b: Array) + +fun box() : String { + if( A(intArray(1,2,3),array("239")).hashCode() != 31*java.util.Arrays.hashCode(intArray(0,1,2)) + "239".hashCode()) "fail" + return "OK" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/boolean.kt b/compiler/testData/codegen/dataClasses/hashcode/boolean.kt new file mode 100644 index 00000000000..afc41bbe2e7 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/boolean.kt @@ -0,0 +1,5 @@ +data class A(val a: Boolean) + +fun box() : String { + return if( A(true).hashCode()==1 && A(false).hashCode()==0 ) "OK" else "fail" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/byte.kt b/compiler/testData/codegen/dataClasses/hashcode/byte.kt new file mode 100644 index 00000000000..d01f082be59 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/byte.kt @@ -0,0 +1,7 @@ +data class A(val a: Byte) + +fun box() : String { + val v1 = A(-10.toByte()).hashCode() + val v2 = (-10.toByte() as Byte?)!!.hashCode() + return if( v1 == v2 ) "OK" else "$v1 $v2" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/char.kt b/compiler/testData/codegen/dataClasses/hashcode/char.kt new file mode 100644 index 00000000000..e2ac5e67291 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/char.kt @@ -0,0 +1,7 @@ +data class A(val a: Char) + +fun box() : String { + val v1 = A('a').hashCode() + val v2 = ('a' as Char?)!!.hashCode() + return if( v1 == v2 ) "OK" else "$v1 $v2" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/double.kt b/compiler/testData/codegen/dataClasses/hashcode/double.kt new file mode 100644 index 00000000000..f0899ad1b59 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/double.kt @@ -0,0 +1,7 @@ +data class A(val a: Double) + +fun box() : String { + val v1 = A(-10.toDouble()).hashCode() + val v2 = (-10.toDouble() as Double?)!!.hashCode() + return if( v1 == v2 ) "OK" else "$v1 $v2" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/float.kt b/compiler/testData/codegen/dataClasses/hashcode/float.kt new file mode 100644 index 00000000000..41dc25c43c4 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/float.kt @@ -0,0 +1,7 @@ +data class A(val a: Float) + +fun box() : String { + val v1 = A(-10.toFloat()).hashCode() + val v2 = (-10.toFloat() as Float?)!!.hashCode() + return if( v1 == v2 ) "OK" else "$v1 $v2" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/int.kt b/compiler/testData/codegen/dataClasses/hashcode/int.kt new file mode 100644 index 00000000000..0596e4c72af --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/int.kt @@ -0,0 +1,7 @@ +data class A(val a: Int) + +fun box() : String { + val v1 = A(-10.toInt()).hashCode() + val v2 = (-10.toInt() as Int?)!!.hashCode() + return if( v1 == v2 ) "OK" else "$v1 $v2" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/long.kt b/compiler/testData/codegen/dataClasses/hashcode/long.kt new file mode 100644 index 00000000000..067593cb672 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/long.kt @@ -0,0 +1,7 @@ +data class A(val a: Long) + +fun box() : String { + val v1 = A(-10.toLong()).hashCode() + val v2 = (-10.toLong() as Long?)!!.hashCode() + return if( v1 == v2 ) "OK" else "$v1 $v2" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/null.kt b/compiler/testData/codegen/dataClasses/hashcode/null.kt new file mode 100644 index 00000000000..7bde4f3e135 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/null.kt @@ -0,0 +1,16 @@ +data class A(val a: Any?, var x: Int) +data class B(val a: Any?, x: Int) +data class C(val a: Int, var x: Int?) +data class D(val a: Int?) + +fun box() : String { + if( A(null,19).hashCode() != 19) "fail" + if( A(239,19).hashCode() != (239*31+19)) "fail" + if( B(null,19).hashCode() != 0) "fail" + if( B(239,19).hashCode() != 239) "fail" + if( C(239,19).hashCode() != (239*31+19)) "fail" + if( C(239,null).hashCode() != 239*31) "fail" + if( D(239).hashCode() != (239)) "fail" + if( D(null).hashCode() != 0) "fail" + return "OK" +} diff --git a/compiler/testData/codegen/dataClasses/hashcode/short.kt b/compiler/testData/codegen/dataClasses/hashcode/short.kt new file mode 100644 index 00000000000..88e26b6d05e --- /dev/null +++ b/compiler/testData/codegen/dataClasses/hashcode/short.kt @@ -0,0 +1,7 @@ +data class A(val a: Short) + +fun box() : String { + val v1 = A(-10.toShort()).hashCode() + val v2 = (-10.toShort() as Short?)!!.hashCode() + return if( v1 == v2 ) "OK" else "$v1 $v2" +} diff --git a/compiler/testData/codegen/dataClasses/overriddenProperty.kt b/compiler/testData/codegen/dataClasses/overriddenProperty.kt index 113a2b176c1..50f27979b39 100644 --- a/compiler/testData/codegen/dataClasses/overriddenProperty.kt +++ b/compiler/testData/codegen/dataClasses/overriddenProperty.kt @@ -1,7 +1,7 @@ open data class A(open val x: String) -class B : A("OK") { - override val x: String = "Fail" +class B : A("Fail") { + override val x: String = "OK" } fun foo(a: A) = a.component1() diff --git a/compiler/testData/codegen/dataClasses/tostring/arrayParams.kt b/compiler/testData/codegen/dataClasses/tostring/arrayParams.kt index 4ddedc80981..8f68bfee5a9 100644 --- a/compiler/testData/codegen/dataClasses/tostring/arrayParams.kt +++ b/compiler/testData/codegen/dataClasses/tostring/arrayParams.kt @@ -2,13 +2,13 @@ data class A(val x: Array?, val y: IntArray?) fun box(): String { var ts = A(Array(2, {it}), IntArray(3)).toString() - if(ts != "A{x=[0, 1], y=[0, 0, 0]}") return ts + if(ts != "A(x=[0, 1], y=[0, 0, 0])") return ts ts = A(null, IntArray(3)).toString() - if(ts != "A{x=null, y=[0, 0, 0]}") return ts + if(ts != "A(x=null, y=[0, 0, 0])") return ts ts = A(null, null).toString() - if(ts != "A{x=null, y=null}") return ts + if(ts != "A(x=null, y=null)") return ts return "OK" } diff --git a/compiler/testData/codegen/dataClasses/tostring/changingVarParam.kt b/compiler/testData/codegen/dataClasses/tostring/changingVarParam.kt index f25581fb18a..0268af29435 100644 --- a/compiler/testData/codegen/dataClasses/tostring/changingVarParam.kt +++ b/compiler/testData/codegen/dataClasses/tostring/changingVarParam.kt @@ -2,10 +2,10 @@ data class A(var string: String) fun box(): String { val a = A("Fail") - if(a.toString() != "A{string=Fail}") return "fail" + if(a.toString() != "A(string=Fail)") return "fail" a.string = "OK" - if("$a" != "A{string=OK}") return a.toString() + if("$a" != "A(string=OK)") return a.toString() return "OK" } diff --git a/compiler/testData/codegen/dataClasses/tostring/genericParam.kt b/compiler/testData/codegen/dataClasses/tostring/genericParam.kt index d751f3c6794..794bad5dbe1 100644 --- a/compiler/testData/codegen/dataClasses/tostring/genericParam.kt +++ b/compiler/testData/codegen/dataClasses/tostring/genericParam.kt @@ -2,10 +2,10 @@ data class A(val x: T) fun box(): String { val a = A(42) - if ("$a" != "A{x=42}") return "$a" + if ("$a" != "A(x=42)") return "$a" val b = A(239.toLong()) - if ("$b" != "A{x=239}") return "$b" + if ("$b" != "A(x=239)") return "$b" return "OK" } diff --git a/compiler/testData/codegen/dataClasses/tostring/mixedParams.kt b/compiler/testData/codegen/dataClasses/tostring/mixedParams.kt index 1d0cfdb46dd..2fb2ab314d1 100644 --- a/compiler/testData/codegen/dataClasses/tostring/mixedParams.kt +++ b/compiler/testData/codegen/dataClasses/tostring/mixedParams.kt @@ -2,6 +2,6 @@ data class A(var x: Int, y: Int, val z: Int?) fun box(): String { val a = A(1, 2, null) - if("$a" != "A{x=1, z=null}") return "$a" + if("$a" != "A(x=1, z=null)") return "$a" return "OK" } diff --git a/compiler/testData/codegen/dataClasses/tostring/overriddenProperty.kt b/compiler/testData/codegen/dataClasses/tostring/overriddenProperty.kt index cac12ae4177..3a4f021fea1 100644 --- a/compiler/testData/codegen/dataClasses/tostring/overriddenProperty.kt +++ b/compiler/testData/codegen/dataClasses/tostring/overriddenProperty.kt @@ -1,11 +1,11 @@ open data class A(open val x: String) -class B : A("OK") { - override val x: String = "Fail" +class B : A("Fail") { + override val x: String = "OK" } fun foo(a: A) = a fun box(): String { - return if ("${foo(B())}" == "A{x=OK}") "OK" else "fail" + return if ("${foo(B())}" == "A(x=OK)") "OK" else "fail" } diff --git a/compiler/testData/codegen/dataClasses/tostring/unitComponent.kt b/compiler/testData/codegen/dataClasses/tostring/unitComponent.kt index 0b6485cb03a..602cb8d897b 100644 --- a/compiler/testData/codegen/dataClasses/tostring/unitComponent.kt +++ b/compiler/testData/codegen/dataClasses/tostring/unitComponent.kt @@ -1,6 +1,6 @@ data class A(val x: Unit) fun box(): String { - val a = A(#()) - return if ("$a" == "A{x=()}") "OK" else "$a" + val a = A(Unit.VALUE) + return if ("$a" == "A(x=Unit.VALUE)") "OK" else "$a" } diff --git a/compiler/testData/codegen/dataClasses/unitComponent.kt b/compiler/testData/codegen/dataClasses/unitComponent.kt index 49046f4240e..0246cebd88a 100644 --- a/compiler/testData/codegen/dataClasses/unitComponent.kt +++ b/compiler/testData/codegen/dataClasses/unitComponent.kt @@ -1,6 +1,6 @@ data class A(val x: Unit) fun box(): String { - val a = A(#()) + val a = A(Unit.VALUE) return if (a.component1() is Unit) "OK" else "Fail ${a.component1()}" } diff --git a/compiler/testData/codegen/enum/inner.kt b/compiler/testData/codegen/enum/inner.kt new file mode 100644 index 00000000000..01ef380fbc3 --- /dev/null +++ b/compiler/testData/codegen/enum/inner.kt @@ -0,0 +1,7 @@ +class A { + enum class E { + OK + } +} + +fun box() = A.E.OK.toString() diff --git a/compiler/testData/codegen/enum/innerWithExistingClassObject.kt b/compiler/testData/codegen/enum/innerWithExistingClassObject.kt new file mode 100644 index 00000000000..74244024e98 --- /dev/null +++ b/compiler/testData/codegen/enum/innerWithExistingClassObject.kt @@ -0,0 +1,8 @@ +class A { + class object {} + enum class E { + OK + } +} + +fun box() = A.E.OK.toString() diff --git a/compiler/testData/codegen/functions/defaultargs2.jet b/compiler/testData/codegen/functions/defaultargs2.jet index 1f2fa12d7b3..cf02fc34f39 100644 --- a/compiler/testData/codegen/functions/defaultargs2.jet +++ b/compiler/testData/codegen/functions/defaultargs2.jet @@ -1,3 +1,18 @@ +class T4( + val c1: Boolean, + val c2: Boolean, + val c3: Boolean, + val c4: String +) { + fun equals(o: Any?): Boolean { + if (o !is T4) return false; + return c1 == o.c1 && + c2 == o.c2 && + c3 == o.c3 && + c4 == o.c4 + } +} + fun reformat( str : String, normalizeCase : Boolean = true, @@ -5,11 +20,11 @@ fun reformat( divideByCamelHumps : Boolean = true, wordSeparator : String = " " ) = - #(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator) + T4(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator) fun box() : String { - val expected = #(true, true, true, " ") + val expected = T4(true, true, true, " ") if(reformat("", true, true, true, " ") != expected) return "fail" if(reformat("", true, true, true) != expected) return "fail" if(reformat("", true, true) != expected) return "fail" diff --git a/compiler/testData/codegen/jdk-annotations/collections.kt b/compiler/testData/codegen/jdk-annotations/collections.kt new file mode 100644 index 00000000000..eec3ec9623c --- /dev/null +++ b/compiler/testData/codegen/jdk-annotations/collections.kt @@ -0,0 +1,150 @@ +package collections + +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import java.security.KeyPair + + +fun testCollectionSize(c: Collection) = assertEquals(0, c.size()) +fun testCollectionIsEmpty(c: Collection) = assertTrue(c.isEmpty()) +fun testCollectionContains(c: Collection) = assertTrue(c.contains(1)) +fun testCollectionIterator(c: Collection) { + val it = c.iterator() + while (it.hasNext()) { + assertEquals(1, it.next()) + } +} +fun testCollectionToArray(c: Collection) = assertEquals(1, c.toArray()[0]) +fun testCollectionContainsAll(c: Collection) = assertTrue(c.containsAll(c)) +fun testMutableCollectionAdd(c: MutableCollection, t: T) { + c.add(t) + assertEquals(1, c.size()) + assertTrue(c.contains(t)) +} +fun testMutableCollectionRemove(c: MutableCollection, t: T) { + c.remove(t) + assertEquals(0, c.size()) + assertFalse(c.contains(t)) +} +fun testMutableCollectionIterator(c: MutableCollection, t: T) { + c.add(t) + val it = c.iterator() + while (it.hasNext()) { + it.next() + it.remove() + } + assertEquals(0, c.size()) +} +fun testMutableCollectionAddAll(c: MutableCollection, t1: T, t2: T) { + c.addAll(arrayList(t1, t2)) + assertEquals(arrayList(t1, t2), c) +} +fun testMutableCollectionRemoveAll(c: MutableCollection, t1: T, t2: T) { + c.addAll(arrayList(t1, t2)) + c.removeAll(arrayList(t1)) + assertEquals(arrayList(t2), c) +} +fun testMutableCollectionRetainAll(c: MutableCollection, t1: T, t2: T) { + c.addAll(arrayList(t1, t2)) + c.retainAll(arrayList(t1)) + assertEquals(arrayList(t1), c) +} +fun testMutableCollectionClear(c: MutableCollection) { + c.clear() + assertTrue(c.isEmpty()) +} + +fun testCollection() { + testCollectionSize(arrayList()) + testCollectionIsEmpty(arrayList()) + testCollectionContains(arrayList(1)) + testCollectionIterator(arrayList(1)) + testCollectionToArray(arrayList(1)) + testCollectionContainsAll(arrayList("a", "b")) + + testMutableCollectionAdd(arrayList(), "") + testMutableCollectionRemove(arrayList("a"), "a") + testMutableCollectionIterator(arrayList(), 1) + testMutableCollectionAddAll(arrayList(), 1, 2) + testMutableCollectionRemoveAll(arrayList(), 1, 2) + testMutableCollectionRetainAll(arrayList(), 1, 2) + testMutableCollectionClear(arrayList(1, 2)) +} + + +fun testListGet(l: List, t: T) = assertEquals(t, l.get(0)) +fun testListIndexOf(l: List, t: T) = assertEquals(0, l.indexOf(t)) +fun testListIterator(l: List, t1 : T, t2 : T) { + val indexes = arrayList() + val result = arrayList() + val it = l.listIterator() + while (it.hasNext()) { + indexes.add(it.nextIndex()) + result.add(it.next()) + } + while (it.hasPrevious()) { + indexes.add(it.previousIndex()) + result.add(it.previous()) + } + assertEquals(arrayList(0, 1, 1, 0), indexes) + assertEquals(arrayList(t1, t2, t2, t1), result) +} +fun testListSublist(l: List, t: T) = assertEquals(arrayList(t), l.subList(0, 1)) + +fun testMutableListSet(l: MutableList, t: T) { + l.set(0, t) + assertEquals(arrayList(t), l) +} +fun testMutableListIterator(l: MutableList, t1: T, t2: T, t3: T) { + val it = l.listIterator() + while (it.hasNext()) { + it.next() + it.add(t3) + } + assertEquals(arrayList(t1, t3, t2, t3), l) +} + +fun testList() { + testListGet(arrayList(1), 1) + testListIndexOf(arrayList(1), 1) + testListIterator(arrayList("a", "b"), "a", "b") + testListSublist(arrayList(1, 2), 1) + + testMutableListSet(arrayList(2), 4) + testMutableListIterator(arrayList(1, 2), 1, 2, 3) +} + +fun testMapContainsKey(map: Map, k: K) = assertTrue(map.containsKey(k)) +fun testMapKeys(map: Map, k1: K, k2: K) = assertEqualCollections(hashSet(k1, k2), map.keySet()) +fun testMapValues(map: Map, v1: V, v2: V) = assertEqualCollections(hashSet(v1, v2), map.values()) +fun testMapEntrySet(map: Map, k : K, v: V) { + for (entry in map.entrySet()) { + assertEquals(k, entry.key) + assertEquals(v, entry.value) + } +} +fun testMutableMapEntry(map: MutableMap, k1 : K, v: V) { + for (entry in map.entrySet()) { + entry.setValue(v) + } + assertEquals(hashMap(k1 to v), map) +} + + +fun testMap() { + testMapContainsKey(hashMap(1 to 'a', 2 to 'b'), 2) + testMapKeys(hashMap(1 to 'a', 2 to 'b'), 1, 2) + testMapValues(hashMap(1 to 'a', 2 to 'b'), 'a', 'b') + testMapEntrySet(hashMap(1 to 'a'), 1, 'a') + testMutableMapEntry(hashMap(1 to 'a'), 1, 'b') +} + +fun box() : String { + testCollection() + testList() + testMap() + return "OK" +} + +fun assertEqualCollections(c1: Collection, c2: Collection) = assertEquals(c1.toCollection(hashSet()), c2.toCollection(hashSet())) diff --git a/compiler/testData/codegen/regressions/kt1018.kt b/compiler/testData/codegen/regressions/kt1018.kt index 5fac168ecf4..68f6c20e5c6 100644 --- a/compiler/testData/codegen/regressions/kt1018.kt +++ b/compiler/testData/codegen/regressions/kt1018.kt @@ -1,7 +1,7 @@ public class StockMarketTableModel() { public fun getColumnCount() : Int { - return COLUMN_TITLES?.size.sure() + return COLUMN_TITLES?.size!! } class object { diff --git a/compiler/testData/codegen/regressions/kt1199.kt b/compiler/testData/codegen/regressions/kt1199.kt index 9939ff6a890..5ea600ddd75 100644 --- a/compiler/testData/codegen/regressions/kt1199.kt +++ b/compiler/testData/codegen/regressions/kt1199.kt @@ -6,7 +6,7 @@ fun T?.iterator() = object { fun next() : T { if (hasNext) { hasNext = false - return this@iterator.sure() + return this@iterator!! } throw java.util.NoSuchElementException() } diff --git a/compiler/testData/codegen/regressions/kt1406.kt b/compiler/testData/codegen/regressions/kt1406.kt index d053b779247..5893c0043ae 100644 --- a/compiler/testData/codegen/regressions/kt1406.kt +++ b/compiler/testData/codegen/regressions/kt1406.kt @@ -7,11 +7,11 @@ import kotlin.util.* class C{ public fun foo(){ - val items : Collection = java.util.Collections.singleton(Item()).sure() + val items : Collection = java.util.Collections.singleton(Item())!! val result = ArrayList() val pattern: Pattern? = Pattern.compile("...") items.filterTo(result) { - pattern.sure().matcher(it.name()).sure().matches() + pattern!!.matcher(it.name())!!.matches() } } diff --git a/compiler/testData/codegen/regressions/kt1482_2279.kt b/compiler/testData/codegen/regressions/kt1482_2279.kt index bed64b91282..df07629e40c 100644 --- a/compiler/testData/codegen/regressions/kt1482_2279.kt +++ b/compiler/testData/codegen/regressions/kt1482_2279.kt @@ -8,12 +8,12 @@ abstract class ClassValAbstract { fun box() : String { for(m in ClassValAbstract.methods) { - if (m.sure().getName() == "getA") { - if(m.sure().getModifiers() != 1025) + if (m!!.getName() == "getA") { + if(m!!.getModifiers() != 1025) return "get failed" } - if (m.sure().getName() == "setA") { - if(m.sure().getModifiers() != 1025) + if (m!!.getName() == "setA") { + if(m!!.getModifiers() != 1025) return "set failed" } } diff --git a/compiler/testData/codegen/regressions/kt1515.kt b/compiler/testData/codegen/regressions/kt1515.kt index cc93cfa3c8d..0cc0dcba2ed 100644 --- a/compiler/testData/codegen/regressions/kt1515.kt +++ b/compiler/testData/codegen/regressions/kt1515.kt @@ -1,4 +1,4 @@ fun box(): String { val c = javaClass() - return if(c.getName().sure() == "java.lang.Runnable") "OK" else "fail" + return if(c.getName()!! == "java.lang.Runnable") "OK" else "fail" } \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt1538.kt b/compiler/testData/codegen/regressions/kt1538.kt index 01635ec2279..44600392f3c 100644 --- a/compiler/testData/codegen/regressions/kt1538.kt +++ b/compiler/testData/codegen/regressions/kt1538.kt @@ -2,17 +2,17 @@ import java.util.HashMap fun parseCatalogs(hashMap: Any?) { val r = toHasMap(hashMap) - if (!r._1) { + if (!r.first) { return } - val nodes = r._2 + val nodes = r.second } -fun toHasMap(value: Any?): #(Boolean, HashMap?) { +fun toHasMap(value: Any?): Pair?> { if(value is HashMap<*, *>) { - return #(true, value as HashMap) + return Pair(true, value as HashMap) } - return #(false, null as HashMap?) + return Pair(false, null as HashMap?) } fun box() : String { diff --git a/compiler/testData/codegen/regressions/kt2062.kt b/compiler/testData/codegen/regressions/kt2062.kt index 169e193c0e7..4f0bce4a8a6 100644 --- a/compiler/testData/codegen/regressions/kt2062.kt +++ b/compiler/testData/codegen/regressions/kt2062.kt @@ -1,5 +1,5 @@ fun box(): String { val a = if(true) { } - return if (a.toString() == "()") "OK" else "fail" + return if (a.toString() == "Unit.VALUE") "OK" else "fail" } diff --git a/compiler/testData/codegen/regressions/kt2251.kt b/compiler/testData/codegen/regressions/kt2251.kt new file mode 100644 index 00000000000..f331f062738 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2251.kt @@ -0,0 +1,39 @@ +class A(var b: Byte) { + fun c(d: Short) = (b + d.toByte()).toChar() +} + +fun box() : String { + if(A(10.toByte()).c(20.toShort()) != 30.toByte().toChar()) return "plus failed" + + var x = 20.toByte() + var y = 20.toByte() + val foo = { + x++ + ++x + } + + if(++x != 21.toByte() || x++ != 21.toByte() || foo() != 24.toByte() || x != 24.toByte()) return "shared byte fail" + if(++y != 21.toByte() || y++ != 21.toByte() || y != 22.toByte()) return "byte fail" + + var xs = 20.toShort() + var ys = 20.toShort() + val foos = { + xs++ + ++xs + } + + if(++xs != 21.toShort() || xs++ != 21.toShort() || foos() != 24.toShort() || xs != 24.toShort()) return "shared short fail" + if(++ys != 21.toShort() || ys++ != 21.toShort() || ys != 22.toShort()) return "short fail" + + var xc = 20.toChar() + var yc = 20.toChar() + val fooc = { + xc++ + ++xc + } + + if(++xc != 21.toChar() || xc++ != 21.toChar() || fooc() != 24.toChar() || xc != 24.toChar()) return "shared char fail" + if(++yc != 21.toChar() || yc++ != 21.toChar() || yc != 22.toChar()) return "char fail" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt237.jet b/compiler/testData/codegen/regressions/kt237.jet index c2867130740..cc96a0e9643 100644 --- a/compiler/testData/codegen/regressions/kt237.jet +++ b/compiler/testData/codegen/regressions/kt237.jet @@ -1,9 +1,9 @@ fun main(args: Array?) { - val y: Unit = #() //do not compile + val y: Unit = Unit.VALUE //do not compile A() //do not compile - C(#()) //do not compile + C(Unit.VALUE) //do not compile //do not compile - System.out?.println(fff(#())) //do not compile + System.out?.println(fff(Unit.VALUE)) //do not compile System.out?.println(id(y)) //do not compile System.out?.println(fff(id(y)) == id(foreach(Array(0,{0}),{(e : Int) : Unit -> }))) //do not compile } diff --git a/compiler/testData/codegen/regressions/kt2607.kt b/compiler/testData/codegen/regressions/kt2607.kt new file mode 100644 index 00000000000..9bc3b5c2b35 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2607.kt @@ -0,0 +1,9 @@ +fun box() : String { + val o = object { + + class C { + fun foo() = "OK" + } + } + return o.C().foo() +} \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt2655.kt b/compiler/testData/codegen/regressions/kt2655.kt new file mode 100644 index 00000000000..d632ea14ad2 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2655.kt @@ -0,0 +1,20 @@ +trait TextField { + fun getText(): String + fun setText(text: String) +} + +class SimpleTextField : TextField { + private var text = "" + override fun getText() = text + override fun setText(text: String) { + this.text = text + } +} + +class TextFieldWrapper(textField: TextField) : TextField by textField + +fun box() : String { + val textField = TextFieldWrapper(SimpleTextField()) + textField.setText("OK") + return textField.getText() +} \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt2677.kt b/compiler/testData/codegen/regressions/kt2677.kt new file mode 100644 index 00000000000..fc1f65ba7bb --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2677.kt @@ -0,0 +1,13 @@ +class U + +open class WeatherReport +{ + public open var forecast: U = U() +} + +open class DerivedWeatherReport() : WeatherReport() +{ + public override var forecast: U + get() = super.forecast + set(newv: U) { super.forecast = newv } +} \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt2786.kt b/compiler/testData/codegen/regressions/kt2786.kt new file mode 100644 index 00000000000..7b813217918 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2786.kt @@ -0,0 +1,13 @@ +trait FooTrait { + val propertyTest: String +} + +class FooDelegate: FooTrait { + override val propertyTest: String = "OK" +} + +class DelegateTest(): FooTrait by FooDelegate() { + fun test() = propertyTest +} + +fun box() = DelegateTest().test() diff --git a/compiler/testData/codegen/regressions/kt2794.kt b/compiler/testData/codegen/regressions/kt2794.kt new file mode 100644 index 00000000000..3e086f682b5 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt2794.kt @@ -0,0 +1,6 @@ +fun box () : String { + val b = 4.toByte() + val s = 5.toShort() + val c: Char = 'A' + return if( "$b" == "4" && " $b" == " 4" && "$s" == "5" && " $s" == " 5" && "$c" == "A" && " $c" == " A") "OK" else "fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt344.jet b/compiler/testData/codegen/regressions/kt344.jet index 99f657592e1..cdec9809fde 100644 --- a/compiler/testData/codegen/regressions/kt344.jet +++ b/compiler/testData/codegen/regressions/kt344.jet @@ -27,7 +27,7 @@ fun t1() : Boolean { x = x + "45" + y x = x.substring(3) x += "aaa" - #() + Unit.VALUE } foo() @@ -43,7 +43,7 @@ fun t2() : Boolean { x = x + 5 + y x += 5 x++ - #() + Unit.VALUE } foo() x -= 55 @@ -55,7 +55,7 @@ fun t3() : Boolean { var x = true val foo = { x = false - #() + Unit.VALUE } foo() return !x @@ -67,7 +67,7 @@ fun t4() : Boolean { val foo = { x = x + 200.toFloat() + y x += 18 - #() + Unit.VALUE } foo() System.out?.println(x) @@ -80,7 +80,7 @@ fun t5() : Boolean { val foo = { x = x + 200.toDouble() + y x -= 22 - #() + Unit.VALUE } foo() System.out?.println(x) @@ -94,7 +94,7 @@ fun t6() : Boolean { x = (x + 20.toByte() + y).toByte() x += 2 x-- - #() + Unit.VALUE } foo() System.out?.println(x) @@ -105,7 +105,7 @@ fun t7() : Boolean { var x : Char = 'a' val foo = { x = 'b' - #() + Unit.VALUE } foo() System.out?.println(x) @@ -117,10 +117,10 @@ fun t8() : Boolean { val foo = { val bar = { x = 30.toShort() - #() + Unit.VALUE } bar() - #() + Unit.VALUE } foo() return x == 30.toShort() diff --git a/compiler/testData/codegen/regressions/kt529.kt b/compiler/testData/codegen/regressions/kt529.kt index 08257e1db14..f57e0f2d8e9 100644 --- a/compiler/testData/codegen/regressions/kt529.kt +++ b/compiler/testData/codegen/regressions/kt529.kt @@ -61,7 +61,7 @@ class Luhny() { private fun printOneDigit() { while (!buffer.isEmpty()) { - val c = buffer.removeFirst().sure() + val c = buffer.removeFirst()!! print(c) if (c.isDigit()) { digits.removeFirst() diff --git a/compiler/testData/codegen/regressions/kt725.kt b/compiler/testData/codegen/regressions/kt725.kt index 950b4c6b734..7ab562ae773 100644 --- a/compiler/testData/codegen/regressions/kt725.kt +++ b/compiler/testData/codegen/regressions/kt725.kt @@ -1,4 +1,4 @@ -fun Int?.inc() = this.sure().inc() +fun Int?.inc() = this!!.inc() public fun box() : String { var i : Int? = 10 diff --git a/compiler/testData/codegen/regressions/kt752.jet b/compiler/testData/codegen/regressions/kt752.jet index 2f6ab3d7d69..f473d6bae24 100644 --- a/compiler/testData/codegen/regressions/kt752.jet +++ b/compiler/testData/codegen/regressions/kt752.jet @@ -1,6 +1,6 @@ package demo_range -fun Int?.rangeTo(other : Int?) : IntRange = this.sure().rangeTo(other.sure()) +fun Int?.rangeTo(other : Int?) : IntRange = this!!.rangeTo(other!!) fun box() : String { val x : Int? = 10 diff --git a/compiler/testData/codegen/regressions/kt753.jet b/compiler/testData/codegen/regressions/kt753.jet index 75a54b5ca33..483bc636cd6 100644 --- a/compiler/testData/codegen/regressions/kt753.jet +++ b/compiler/testData/codegen/regressions/kt753.jet @@ -1,6 +1,6 @@ package bitwise_demo -fun Long?.shl(bits : Int?) : Long = this.sure().shl(bits.sure()) +fun Long?.shl(bits : Int?) : Long = this!!.shl(bits!!) fun box() : String { val x : Long? = 10 diff --git a/compiler/testData/codegen/regressions/kt756.jet b/compiler/testData/codegen/regressions/kt756.jet index e47c2612f1f..e8407abee1c 100644 --- a/compiler/testData/codegen/regressions/kt756.jet +++ b/compiler/testData/codegen/regressions/kt756.jet @@ -1,9 +1,9 @@ package demo_range -fun Int?.plus() : Int = this.sure().plus() -fun Int?.dec() : Int = this.sure().dec() -fun Int?.inc() : Int = this.sure().inc() -fun Int?.minus() : Int = this.sure().minus() +fun Int?.plus() : Int = this!!.plus() +fun Int?.dec() : Int = this!!.dec() +fun Int?.inc() : Int = this!!.inc() +fun Int?.minus() : Int = this!!.minus() fun box() : String { val x : Int? = 10 diff --git a/compiler/testData/codegen/regressions/kt757.jet b/compiler/testData/codegen/regressions/kt757.jet index ad067253ed1..2683f2b72dd 100644 --- a/compiler/testData/codegen/regressions/kt757.jet +++ b/compiler/testData/codegen/regressions/kt757.jet @@ -1,6 +1,6 @@ package demo_long -fun Long?.inv() : Long = this.sure().inv() +fun Long?.inv() : Long = this!!.inv() fun box() : String { val x : Long? = 10 diff --git a/compiler/testData/codegen/regressions/kt796_797.jet b/compiler/testData/codegen/regressions/kt796_797.jet index 03ae120b510..28a02606d39 100644 --- a/compiler/testData/codegen/regressions/kt796_797.jet +++ b/compiler/testData/codegen/regressions/kt796_797.jet @@ -1,4 +1,4 @@ -fun Array?.get(i : Int?) = this.sure().get(i.sure()) +fun Array?.get(i : Int?) = this!!.get(i!!) fun array(vararg t : T) : Array = t fun box() : String { diff --git a/compiler/testData/codegen/regressions/kt903.jet b/compiler/testData/codegen/regressions/kt903.jet index 73f481547e9..d229c0724d8 100644 --- a/compiler/testData/codegen/regressions/kt903.jet +++ b/compiler/testData/codegen/regressions/kt903.jet @@ -1,6 +1,6 @@ import java.util.ArrayList -fun Int.plus(a: Int?) = this + a.sure() +fun Int.plus(a: Int?) = this + a!! public open class PerfectNumberFinder() { open public fun isPerfect(number : Int) : Boolean { diff --git a/compiler/testData/codegen/regressions/kt944.kt b/compiler/testData/codegen/regressions/kt944.kt index 4dca91f84c0..746739fba9a 100644 --- a/compiler/testData/codegen/regressions/kt944.kt +++ b/compiler/testData/codegen/regressions/kt944.kt @@ -5,4 +5,4 @@ fun box() : String { return "OK" } -val String?.indices : IntRange get() = IntRange(0, this.sure().length) \ No newline at end of file +val String?.indices : IntRange get() = IntRange(0, this!!.length) \ No newline at end of file diff --git a/compiler/testData/codegen/stdlib/noClassObjectForJavaClass.java b/compiler/testData/codegen/stdlib/noClassObjectForJavaClass.java new file mode 100644 index 00000000000..6f48ad7b77d --- /dev/null +++ b/compiler/testData/codegen/stdlib/noClassObjectForJavaClass.java @@ -0,0 +1,7 @@ +package test; + +public class noClassObjectForJavaClass { + public enum E { ENTRY } + + public static String foo() { return "OK"; } +} diff --git a/compiler/testData/codegen/stdlib/noClassObjectForJavaClass.kt b/compiler/testData/codegen/stdlib/noClassObjectForJavaClass.kt new file mode 100644 index 00000000000..0bbeb9576b1 --- /dev/null +++ b/compiler/testData/codegen/stdlib/noClassObjectForJavaClass.kt @@ -0,0 +1,5 @@ +package test + +fun box(): String { + return noClassObjectForJavaClass.foo()!! +} diff --git a/compiler/testData/codegen/tuples/UnitValue.kt b/compiler/testData/codegen/tuples/UnitValue.kt new file mode 100644 index 00000000000..8037babc462 --- /dev/null +++ b/compiler/testData/codegen/tuples/UnitValue.kt @@ -0,0 +1,5 @@ +fun foo() {} + +fun box(): String { + return if (foo() == Unit.VALUE) "OK" else "Fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/tuples/basic.jet b/compiler/testData/codegen/tuples/basic.jet deleted file mode 100644 index ab51e54bb89..00000000000 --- a/compiler/testData/codegen/tuples/basic.jet +++ /dev/null @@ -1,6 +0,0 @@ -fun box() : String { - val a = #(1, "2") - if (a._1 != 1) return "Fail 1: ${a._1}" - if (a._2 != "2") return "Fail 1: ${a._2}" - return "OK" -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/Bounds.kt b/compiler/testData/diagnostics/tests/Bounds.kt index 39c6284401b..4f7f205fb64 100644 --- a/compiler/testData/diagnostics/tests/Bounds.kt +++ b/compiler/testData/diagnostics/tests/Bounds.kt @@ -18,7 +18,9 @@ package boundsWithSubstitutors open class A {} open class B() - abstract class CInt>, X : (B<Char>) -> #(B<Any>, B)>() : B<Any>() { // 2 errors + class Pair + + abstract class CInt>, X : (B<Char>) -> PairAny>, B>>() : B<Any>() { // 2 errors val a = B<Char>() // error abstract val x : (B<Char>) -> B<Any> diff --git a/compiler/testData/diagnostics/tests/Casts.kt b/compiler/testData/diagnostics/tests/Casts.kt index 186124aeb95..0dd2247542a 100644 --- a/compiler/testData/diagnostics/tests/Casts.kt +++ b/compiler/testData/diagnostics/tests/Casts.kt @@ -12,5 +12,5 @@ fun test() : Unit { y as? Int : Int? x as? Int? : Int? y as? Int? : Int? - #() + Unit.VALUE } diff --git a/compiler/testData/diagnostics/tests/CompareToWithErrorType.kt b/compiler/testData/diagnostics/tests/CompareToWithErrorType.kt new file mode 100644 index 00000000000..149d875bb6e --- /dev/null +++ b/compiler/testData/diagnostics/tests/CompareToWithErrorType.kt @@ -0,0 +1,5 @@ +fun test() { + if (x > 0) { + + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt index 27eb7d1eb95..1054a4828e3 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt @@ -4,7 +4,7 @@ fun unitEmptyInfer() {} fun unitEmpty() : Unit {} fun unitEmptyReturn() : Unit {return} fun unitIntReturn() : Unit {return 1} -fun unitUnitReturn() : Unit {return #()} +fun unitUnitReturn() : Unit {return Unit.VALUE} fun test1() : Any = {return} fun test2() : Any = @a {return@a 1} fun test3() : Any { return } @@ -25,7 +25,7 @@ fun foo(expr: StringBuilder): Int { } -fun unitShort() : Unit = #() +fun unitShort() : Unit = Unit.VALUE fun unitShortConv() : Unit = 1 fun unitShortNull() : Unit = null @@ -42,7 +42,7 @@ fun intFunctionLiteral(): Int = { 10 } fun blockReturnUnitMismatch() : Int {return} fun blockReturnValueTypeMismatch() : Int {return 3.4} fun blockReturnValueTypeMatch() : Int {return 1} -fun blockReturnValueTypeMismatchUnit() : Int {return #()} +fun blockReturnValueTypeMismatchUnit() : Int {return Unit.VALUE} fun blockAndAndMismatch() : Int { true && false diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.kt b/compiler/testData/diagnostics/tests/LValueAssignment.kt index 5411031f893..79bba0a6e66 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.kt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.kt @@ -36,9 +36,12 @@ class D() { } } +fun foo(): Unit {} + fun cannotBe(var i: Int) { z = 30; - #() = #(); + "" = ""; + foo() = Unit.VALUE; (i as Int) = 34 (i is Int) = false diff --git a/compiler/testData/diagnostics/tests/Nullability.kt b/compiler/testData/diagnostics/tests/Nullability.kt index 07ec8334475..ef418de3b99 100644 --- a/compiler/testData/diagnostics/tests/Nullability.kt +++ b/compiler/testData/diagnostics/tests/Nullability.kt @@ -38,28 +38,28 @@ fun test() { out.println(); } - if (out == null || out.println(0) == #()) { + if (out == null || out.println(0) == Unit.VALUE) { out?.println(1) } else { out.println(2) } - if (out != null && out.println() == #()) { + if (out != null && out.println() == Unit.VALUE) { out.println(); } else { out?.println(); } - if (out == null || out.println() == #()) { + if (out == null || out.println() == Unit.VALUE) { out?.println(); } else { out.println(); } - if (1 == 2 || out != null && out.println(1) == #()) { + if (1 == 2 || out != null && out.println(1) == Unit.VALUE) { out?.println(2); } else { @@ -94,28 +94,28 @@ fun test() { out.println(); } - if (out == null || out.println(0) == #()) { + if (out == null || out.println(0) == Unit.VALUE) { out?.println(1) } else { out.println(2) } - if (out != null && out.println() == #()) { + if (out != null && out.println() == Unit.VALUE) { out.println(); } else { out?.println(); } - if (out == null || out.println() == #()) { + if (out == null || out.println() == Unit.VALUE) { out?.println(); } else { out.println(); } - if (1 == 2 || out != null && out.println(1) == #()) { + if (1 == 2 || out != null && out.println(1) == Unit.VALUE) { out?.println(2); } else { diff --git a/compiler/testData/diagnostics/tests/Super.kt b/compiler/testData/diagnostics/tests/Super.kt index 8301197932d..3aeca7d9493 100644 --- a/compiler/testData/diagnostics/tests/Super.kt +++ b/compiler/testData/diagnostics/tests/Super.kt @@ -34,7 +34,7 @@ class A() : C(), T { super<Int>.foo() super<>.foo() super<() -> Unit>.foo() - super<#()>.foo() + super<Unit>.foo() super@B.foo() super@B.bar() } diff --git a/compiler/testData/diagnostics/tests/Unresolved.kt b/compiler/testData/diagnostics/tests/Unresolved.kt index 3366a449d88..9514b112c74 100644 --- a/compiler/testData/diagnostics/tests/Unresolved.kt +++ b/compiler/testData/diagnostics/tests/Unresolved.kt @@ -1,8 +1,10 @@ package unresolved +class Pair(val a: A, val b: B) + fun testGenericArgumentsCount() { - val p1: Tuple2 = #(2, 2) - val p2: Tuple2 = #(2, 2) + val p1: Pair = Pair(2, 2) + val p2: Pair = Pair(2, 2) } fun testUnresolved() { diff --git a/compiler/testData/diagnostics/tests/When.kt b/compiler/testData/diagnostics/tests/When.kt index 50410cb1647..7cded35b7e3 100644 --- a/compiler/testData/diagnostics/tests/When.kt +++ b/compiler/testData/diagnostics/tests/When.kt @@ -41,6 +41,4 @@ fun test() { when (z) { else -> 1 } -} - -val #(Int, Int).boo : #(Int, Int, Int) = #(1, 1, 1) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.kt b/compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.kt index 14ecb798037..ab24181a58c 100644 --- a/compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.kt +++ b/compiler/testData/diagnostics/tests/checkArguments/SpreadVarargs.kt @@ -75,7 +75,7 @@ fun join(x : Int, vararg a : String) : String { for (s in a) { b.append(s) } - return b.toString()!! + return b.toString() } fun joinG(x : Int, vararg a : T) : String { @@ -83,7 +83,7 @@ fun joinG(x : Int, vararg a : T) : String { for (s in a) { b.append(s) } - return b.toString()!! + return b.toString() } fun joinT(x : Int, vararg a : T) : T? { diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1189.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1189.kt index 09138e4301c..ac05a5f9e5b 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1189.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1189.kt @@ -3,7 +3,7 @@ package kt1189 import java.util.concurrent.locks.ReentrantReadWriteLock inline fun ReentrantReadWriteLock.write(action: ()->T) : T { - val rl = readLock().sure() + val rl = readLock()!! var readCount = 0 val writeCount = getWriteHoldCount() if(writeCount == 0) { @@ -13,7 +13,7 @@ inline fun ReentrantReadWriteLock.write(action: ()->T) : T { rl.unlock() } - val wl = writeLock().sure() + val wl = writeLock()!! wl.lock() try { return action() diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt657.kt b/compiler/testData/diagnostics/tests/controlStructures/kt657.kt index bab366fb5df..82ba5ac1a81 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt657.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt657.kt @@ -1,12 +1,14 @@ //KT-657 Semantic checks for when without condition package kt657 +class Pair(a: A, b: B) + fun foo() = when { cond1() -> 12 cond2() -> 2 4 -> 34 - #(1, 2) -> 3 + Pair(1, 2) -> 3 in 1..10 -> 34 4 -> 38 is Int -> 33 diff --git a/compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt b/compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt index ff227c754f5..9fd46a066a1 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/when.kt234.kt973.kt @@ -3,17 +3,18 @@ package kt234_kt973 +class Pair(a: A, b: B) -fun test(t : #(Int, Int)) : Int { +fun test(t : Pair) : Int { when (t) { - #(10, 10) -> return 1 + Pair(10, 10) -> return 1 } return 0 // unreachable code } -fun test1(t : #(Int, Int)) : Int { +fun test1(t : Pair) : Int { when (t) { - #(10, 10) -> return 1 + Pair(10, 10) -> return 1 else -> return 2 } return 0 // unreachable code diff --git a/compiler/testData/diagnostics/tests/dataFlow/TupleExpression.kt b/compiler/testData/diagnostics/tests/dataFlow/TupleExpression.kt deleted file mode 100644 index e1707933b42..00000000000 --- a/compiler/testData/diagnostics/tests/dataFlow/TupleExpression.kt +++ /dev/null @@ -1,7 +0,0 @@ -class C(val f : Int) - -fun test(e : Any) { - if (e is C) { - #(e.f) - } -} diff --git a/compiler/testData/diagnostics/tests/enum/enumModifier.kt b/compiler/testData/diagnostics/tests/enum/enumModifier.kt new file mode 100644 index 00000000000..be6fcb280b4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumModifier.kt @@ -0,0 +1,15 @@ +enum class B {} + +class A { + enum class object {} +} + +enum object O {} + +enum trait T {} + +enum fun f() = 0 + +enum val x = 0 + +enum var y = 0 diff --git a/compiler/testData/diagnostics/tests/enum/enumWithEmptyName.kt b/compiler/testData/diagnostics/tests/enum/enumWithEmptyName.kt new file mode 100644 index 00000000000..02cc1dbca97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/enumWithEmptyName.kt @@ -0,0 +1,2 @@ +enum class { +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/enum/inner/existingClassObject.kt b/compiler/testData/diagnostics/tests/enum/inner/existingClassObject.kt new file mode 100644 index 00000000000..3a0438c2483 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/existingClassObject.kt @@ -0,0 +1,19 @@ +class A { + enum class E { + ENTRY + } + + class object { + } +} + + + +class B { + class object { + } + + enum class E { + ENTRY + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideClass.kt b/compiler/testData/diagnostics/tests/enum/inner/insideClass.kt new file mode 100644 index 00000000000..27369f8033f --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideClass.kt @@ -0,0 +1,5 @@ +class A { + enum class E { + ENTRY + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideClassObject.kt b/compiler/testData/diagnostics/tests/enum/inner/insideClassObject.kt new file mode 100644 index 00000000000..aaafb505abb --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideClassObject.kt @@ -0,0 +1,7 @@ +class A { + class object { + enum class E { + ENTRY + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideEnum.kt b/compiler/testData/diagnostics/tests/enum/inner/insideEnum.kt new file mode 100644 index 00000000000..f4a9d75cb88 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideEnum.kt @@ -0,0 +1,7 @@ +enum class E { + ABC + + enum class F { + DEF + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry.kt b/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry.kt new file mode 100644 index 00000000000..7f302c53f19 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry.kt @@ -0,0 +1,7 @@ +enum class E { + ABC { + enum class F { + DEF + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.kt b/compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.kt new file mode 100644 index 00000000000..905f6e5f0df --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.kt @@ -0,0 +1,7 @@ +class A { + class B { + enum class E { + ENTRY + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideObject.kt b/compiler/testData/diagnostics/tests/enum/inner/insideObject.kt new file mode 100644 index 00000000000..80f679f8167 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideObject.kt @@ -0,0 +1,5 @@ +object A { + enum class E { + ENTRY + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/insideTrait.kt b/compiler/testData/diagnostics/tests/enum/inner/insideTrait.kt new file mode 100644 index 00000000000..4138b24d5c7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/insideTrait.kt @@ -0,0 +1,5 @@ +trait A { + enum class E { + ENTRY + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/redeclarationInClassObject.kt b/compiler/testData/diagnostics/tests/enum/inner/redeclarationInClassObject.kt new file mode 100644 index 00000000000..75569dd004a --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/redeclarationInClassObject.kt @@ -0,0 +1,11 @@ +class A { + enum class E { + ENTRY + } + + class object { + enum class E { + ENTRY2 + } + } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/twoEnums.kt b/compiler/testData/diagnostics/tests/enum/inner/twoEnums.kt new file mode 100644 index 00000000000..fbf22f500c5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/twoEnums.kt @@ -0,0 +1,4 @@ +class A { + enum class E { ABC } + enum class F { DEF } +} diff --git a/compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.kt b/compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.kt new file mode 100644 index 00000000000..85e3e3708f3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.kt @@ -0,0 +1,9 @@ +class A { + class object { + enum class E { ENTRY } // OK + } + + class B { + enum class E { ENTRY } + } +} diff --git a/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.kt b/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.kt index 5d686699a92..2793a85541e 100644 --- a/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.kt +++ b/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.kt @@ -2,7 +2,7 @@ package outer fun Int?.optint() : Unit {} -val Int?.optval : Unit = #() +val Int?.optval : Unit = Unit.VALUE fun T.foo(x : E, y : A) : T { y.plus(1) diff --git a/compiler/testData/diagnostics/tests/extensions/GenericIterator.kt b/compiler/testData/diagnostics/tests/extensions/GenericIterator.kt index cb36d9a5993..bf5d4297e18 100644 --- a/compiler/testData/diagnostics/tests/extensions/GenericIterator.kt +++ b/compiler/testData/diagnostics/tests/extensions/GenericIterator.kt @@ -14,7 +14,7 @@ fun T?.iterator() = object { fun next() : T { if (hasNext) { hasNext = false - return this@iterator.sure() + return this@iterator!! } throw java.util.NoSuchElementException() } diff --git a/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt b/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt index 769fa72bd6a..63362ef865e 100644 --- a/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt +++ b/compiler/testData/diagnostics/tests/inference/NoInferenceFromDeclaredBounds.kt @@ -6,4 +6,6 @@ fun foo1() { fooT22() } -val n : Nothing = null.sure() \ No newline at end of file +val n : Nothing = null.sure() + +fun T?.sure() : T = this!! diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1358.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1358.kt index 395bf4371ae..5c28166bb42 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt1358.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1358.kt @@ -8,4 +8,5 @@ fun bar(a: Any?) { } } -fun T?.foo() {} \ No newline at end of file +fun T?.foo() {} +fun T?.sure() : T = this!! \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1558.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1558.kt index 6f1a50b4e29..2ec9436e4a2 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt1558.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1558.kt @@ -1,7 +1,9 @@ //KT-1558 Exception while analyzing package j -fun testArrays(val ci: List, val cii: List) { +fun T?.sure() : T = this!! + +fun testArrays(val ci: List, val cii: List?) { val c1: Array = cii.sure().toArray(Array) val c2: Array = ci.toArray(Array()) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt702.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt702.kt index df7771256b8..88f8fcf843c 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt702.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt702.kt @@ -7,7 +7,7 @@ fun getJavaClass() : java.lang.Class { (throwable : Throwable?, declaredType : Class?) : Unit { - if (((throwable != null) && declaredType?.isInstance(throwable).sure())) + if (((throwable != null) && declaredType?.isInstance(throwable)!!)) { throw declaredType?.cast(throwable)!! } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt742.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt742.kt index 1e32ffc67a0..d8f1846148c 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt742.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt742.kt @@ -1,6 +1,8 @@ //KT-742 Stack overflow in type inference package a +fun T?.sure() : T = this!! + class List(val head: T, val tail: List? = null) fun List.map1(f: (T)-> Q): List? = tail!!.map1(f) diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt943.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt943.kt index ed0987b815f..2df5de1d2f4 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt943.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt943.kt @@ -15,4 +15,6 @@ fun foo(lines: List) { } //standard library +fun T?.sure() : T = this!! + public inline fun comparator(fn: (T,T) -> Int): Comparator {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/infos/Autocasts.kt b/compiler/testData/diagnostics/tests/infos/Autocasts.kt index 2cd34dd2ef8..053ee48f6f4 100644 --- a/compiler/testData/diagnostics/tests/infos/Autocasts.kt +++ b/compiler/testData/diagnostics/tests/infos/Autocasts.kt @@ -20,7 +20,7 @@ fun f9(init : A?) { a?.bar() a?.foo() } - if (!(a is B) || a.bar() == #()) { + if (!(a is B) || a.bar() == Unit.VALUE) { a?.bar() } if (!(a is B)) { @@ -102,7 +102,7 @@ fun f13(a : A?) { } a?.foo() - if (a is B && a.foo() == #()) { + if (a is B && a.foo() == Unit.VALUE) { a.foo() a.bar() } @@ -153,7 +153,7 @@ fun illegalWhenBlock(a: Any): Int { } fun declarations(a: Any?) { if (a is String) { - val p4: #(Int, String) = #(2, a) + val p4: String = a } if (a is String?) { if (a != null) { @@ -172,25 +172,6 @@ fun vars(a: Any?) { b = a } } -fun tuples(a: Any?) { - if (a != null) { - val s: #(Any, String) = #(a, a) - } - if (a is String) { - val s: #(Any, String) = #(a, a) - } - fun illegalTupleReturnType(): #(Any, String) = #(a, a) - if (a is String) { - fun legalTupleReturnType(): #(Any, String) = #(a, a) - } - val illegalFunctionLiteral: Function0 = { a } - val illegalReturnValueInFunctionLiteral: Function0 = { (): Int -> a } - - if (a is Int) { - val legalFunctionLiteral: Function0 = { a } - val alsoLegalFunctionLiteral: Function0 = { (): Int -> a } - } -} fun returnFunctionLiteralBlock(a: Any?): Function0 { if (a is Int) return { a } else return { 1 } @@ -199,8 +180,6 @@ fun returnFunctionLiteral(a: Any?): Function0 = if (a is Int) { (): Int -> a } else { () -> 1 } -fun illegalTupleReturnType(a: Any): #(Any, String) = #(a, a) - fun mergeAutocasts(a: Any?) { if (a is String || a is Int) { a.compareTo("") diff --git a/compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt b/compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt index e90852f6637..428e4005c7a 100644 --- a/compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt +++ b/compiler/testData/diagnostics/tests/j+k/OverrideVararg.kt @@ -8,5 +8,5 @@ public abstract class Aaa { // FILE: bbb.kt class Bbb() : Aaa() { - override fun foo(vararg args: String?) = #() + override fun foo(vararg args: String?) = Unit.VALUE } diff --git a/compiler/testData/diagnostics/tests/jdk-annotations/ArrayListAndMap.kt b/compiler/testData/diagnostics/tests/jdk-annotations/ArrayListAndMap.kt index bf44ac7ce79..afd98c48ada 100644 --- a/compiler/testData/diagnostics/tests/jdk-annotations/ArrayListAndMap.kt +++ b/compiler/testData/diagnostics/tests/jdk-annotations/ArrayListAndMap.kt @@ -27,5 +27,5 @@ fun test(a : List, m : Map) { ) HashMap().get(0) if (m.get("") != null) - System.out.println(m.get("").sure().plus(1)) + System.out.println(m.get("")!!.plus(1)) } diff --git a/compiler/testData/diagnostics/tests/library/Collections.kt b/compiler/testData/diagnostics/tests/library/Collections.kt new file mode 100644 index 00000000000..e90aa8f39e0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/library/Collections.kt @@ -0,0 +1,118 @@ +package collections + +fun testCollection(c: Collection, t: T) { + c.size() + c.isEmpty() + c.contains(1) + val iterator: Iterator = c.iterator() + val arrayOfAnys: Array = c.toArray() + val arrayOfTs: Array = c.toArray(array()) + c.containsAll(c) + + val mutableIterator: MutableIterator = c.iterator() + c.add(t) + c.remove(1) + c.addAll(c) + c.removeAll(c) + c.retainAll(c) + c.clear() + +} +fun testMutableCollection(c: MutableCollection, t: T) { + c.size() + c.isEmpty() + c.contains(1) + val iterator: Iterator = c.iterator() + val arrayOfAnys: Array = c.toArray() + val arrayOfTs: Array = c.toArray(array()) + c.containsAll(c) + + + val mutableIterator: MutableIterator = c.iterator() + c.add(t) + c.remove(1) + c.addAll(c) + c.removeAll(c) + c.retainAll(c) + c.clear() +} + +fun testList(l: List, t: T) { + val t: T = l.get(1) + val i: Int = l.indexOf(1) + val i1: Int = l.lastIndexOf(1) + val listIterator: ListIterator = l.listIterator() + val listIterator1: ListIterator = l.listIterator(1) + val list: List = l.subList(1, 2) + + val value: T = l.set(1, t) + l.add(1, t) + l.remove(1) + val mutableListIterator: MutableListIterator = l.listIterator() + val mutableListIterator1: MutableListIterator = l.listIterator(1) + val mutableList: MutableList = l.subList(1, 2) +} + +fun testMutableList(l: MutableList, t: T) { + val value: T = l.set(1, t) + l.add(1, t) + l.remove(1) + val mutableListIterator: MutableListIterator = l.listIterator() + val mutableListIterator1: MutableListIterator = l.listIterator(1) + val mutableList: MutableList = l.subList(1, 2) +} + +fun testSet(s: Set, t: T) { + s.size() + s.isEmpty() + s.contains(1) + val iterator: Iterator = s.iterator() + val arrayOfAnys: Array = s.toArray() + val arrayOfTs: Array = s.toArray(array()) + s.containsAll(s) + + val mutableIterator: MutableIterator = s.iterator() + s.add(t) + s.remove(1) + s.addAll(s) + s.removeAll(s) + s.retainAll(s) + s.clear() + +} +fun testMutableSet(s: MutableSet, t: T) { + s.size() + s.isEmpty() + s.contains(1) + val iterator: Iterator = s.iterator() + val arrayOfAnys: Array = s.toArray() + val arrayOfTs: Array = s.toArray(array()) + s.containsAll(s) + + + val mutableIterator: MutableIterator = s.iterator() + s.add(t) + s.remove(1) + s.addAll(s) + s.removeAll(s) + s.retainAll(s) + s.clear() +} + +fun testMap(m: Map) { + val set: Set = m.keySet() + val collection: Collection = m.values() + val set1: Set> = m.entrySet() + + val mutableSet: MutableSet = m.keySet() + val mutableCollection: MutableCollection = m.values() + val mutableSet1: MutableSet> = m.entrySet() +} + +fun testMutableMap(m: MutableMap) { + val mutableSet: MutableSet = m.keySet() + val mutableCollection: MutableCollection = m.values() + val mutableSet1: MutableSet> = m.entrySet() +} + +fun array(vararg t: T): Array {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt2234.kt b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt2234.kt index b44cb01a354..3898cada328 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt2234.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt2234.kt @@ -2,11 +2,13 @@ package a //KT-2234 'period!!' has type Int? +class Pair(val a: A, val b: B) + fun main(args : Array) { val d : Long = 1 val period : Int? = null - if (period != null) #(d, period!! : Int) else #(d, 1) - if (period != null) #(d, period : Int) else #(d, 1) + if (period != null) Pair(d, period!! : Int) else Pair(d, 1) + if (period != null) Pair(d, period : Int) else Pair(d, 1) } fun foo() { diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt new file mode 100644 index 00000000000..ff08f2d31c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt @@ -0,0 +1,7 @@ +package a + +fun foo() { + bar()!! +} + +fun bar() = aa \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/DuplicateMethod.kt b/compiler/testData/diagnostics/tests/override/DuplicateMethod.kt new file mode 100644 index 00000000000..aefa4f1673f --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/DuplicateMethod.kt @@ -0,0 +1,8 @@ +trait Some { + fun test() +} + +class SomeImpl : Some { + override fun test() {} + override fun test() {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.kt b/compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.kt index 33c380bc350..fd53cf12a9f 100644 --- a/compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.kt +++ b/compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.kt @@ -4,12 +4,12 @@ trait Bar trait A { fun foo() where T : Foo, T : Bar - = #() + = Unit.VALUE } class B : A { override fun foo() where T : Foo, T : Bar - = #() + = Unit.VALUE } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/override/NonGenerics.kt b/compiler/testData/diagnostics/tests/override/NonGenerics.kt index f61c506e0ad..345a3073a14 100644 --- a/compiler/testData/diagnostics/tests/override/NonGenerics.kt +++ b/compiler/testData/diagnostics/tests/override/NonGenerics.kt @@ -15,8 +15,8 @@ open class MyClass() : MyTrait, MyAbstractClass() { override fun foo() {} override fun bar() {} - override val pr : Unit = #() - override val prr : Unit = #() + override val pr : Unit = Unit.VALUE + override val prr : Unit = Unit.VALUE } class MyChildClass() : MyClass() {} @@ -25,14 +25,14 @@ class MyIllegalClass : MyTrait, MyAbstract class MyIllegalClass2() : MyTrait, MyAbstractClass() { override fun foo() {} - override val pr : Unit = #() - override val prr : Unit = #() + override val pr : Unit = Unit.VALUE + override val prr : Unit = Unit.VALUE } class MyIllegalClass3() : MyTrait, MyAbstractClass() { override fun bar() {} - override val pr : Unit = #() - override val prr : Unit = #() + override val pr : Unit = Unit.VALUE + override val prr : Unit = Unit.VALUE } class MyIllegalClass4() : MyTrait, MyAbstractClass() { @@ -44,7 +44,7 @@ class MyIllegalClass4() : MyTrait, MyAbstr class MyChildClass1() : MyClass() { fun foo() {} - val pr : Unit = #() + val pr : Unit = Unit.VALUE override fun bar() {} - override val prr : Unit = #() + override val prr : Unit = Unit.VALUE } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt b/compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt index 309c3ff7e7a..1c24007fa5d 100644 --- a/compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt +++ b/compiler/testData/diagnostics/tests/regressions/DoubleDefine.kt @@ -52,7 +52,7 @@ fun main(args: Array) { System.out.println("Your numbers: " + prompt) System.out.println("Enter your expression:") val reader = BufferedReader(InputStreamReader(System.`in`)) - val expr = StringBuilder(reader.readLine()) + val expr = StringBuilder(reader.readLine()!!) try { val result = evaluate(expr, numbers) if (result != 24) diff --git a/compiler/testData/diagnostics/tests/regressions/kt353.kt b/compiler/testData/diagnostics/tests/regressions/kt353.kt index 0b62948ba27..a986e31c000 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt353.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt353.kt @@ -20,7 +20,7 @@ fun foo(a: A) { a.gen() // unit can be inferred } else { - #() + Unit.VALUE } } diff --git a/compiler/testData/diagnostics/tests/regressions/kt557.kt b/compiler/testData/diagnostics/tests/regressions/kt557.kt index 4ac9a61049c..993d2703426 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt557.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt557.kt @@ -1,5 +1,7 @@ // KT-557 Wrong type inference near sure extension function +fun T?.sure() : T = this!! + fun Array.length() : Int { return 0; } diff --git a/compiler/testData/diagnostics/tests/regressions/kt630.kt b/compiler/testData/diagnostics/tests/regressions/kt630.kt index 2b26b0faa1e..2cef7f519a8 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt630.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt630.kt @@ -1,3 +1,6 @@ // KT-630 Bad type inference + +fun T?.sure() : T = this!! + val x = "lala".sure() val s : String = x diff --git a/compiler/testData/diagnostics/tests/regressions/kt701.kt b/compiler/testData/diagnostics/tests/regressions/kt701.kt index fab435ae4bf..beccf81e97a 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt701.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt701.kt @@ -4,9 +4,9 @@ fun getJavaClass() : java.lang.Class { return "" as public class Throwables() { class object { public fun propagateIfInstanceOf(throwable : Throwable?, declaredType : Class?) { - if (((throwable != null) && declaredType?.isInstance(throwable).sure())) + if (((throwable != null) && declaredType?.isInstance(throwable)!!)) { - throw declaredType?.cast(throwable).sure() + throw declaredType?.cast(throwable)!! } } public fun propagateIfPossible(throwable : Throwable?) { diff --git a/compiler/testData/diagnostics/tests/regressions/kt743.kt b/compiler/testData/diagnostics/tests/regressions/kt743.kt index f508c0af0bd..4d29b36c57d 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt743.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt743.kt @@ -1,5 +1,7 @@ //KT-743 Wrong type inference class List(val head: T, val tail: List? = null) +fun T?.sure() : T = this!! + fun List.map(f: (T)-> Q): List? = tail.sure>().map(f) fun foo(t : T) : T = foo(t) diff --git a/compiler/testData/diagnostics/tests/regressions/kt750.kt b/compiler/testData/diagnostics/tests/regressions/kt750.kt index dbbf53c08bb..b37f565ee9c 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt750.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt750.kt @@ -3,6 +3,8 @@ fun main(args : Array) { var i : Int? = Integer.valueOf(100) var s : Int? = Integer.valueOf(100) - val o = i .sure() + s.sure() + val o = i.sure() + s.sure() System.out.println(o) } + +fun T?.sure() : T = this!! diff --git a/compiler/testData/diagnostics/tests/subtyping/kt-1457.kt b/compiler/testData/diagnostics/tests/subtyping/kt-1457.kt index 29d85aa962a..88d34e3f63c 100644 --- a/compiler/testData/diagnostics/tests/subtyping/kt-1457.kt +++ b/compiler/testData/diagnostics/tests/subtyping/kt-1457.kt @@ -1,7 +1,9 @@ import java.util.ArrayList -class MyListOfPairs : ArrayList<#(T, T)>() { } +class Pair(val a: A, val b: B) + +class MyListOfPairs : ArrayList>() { } fun test() { - MyListOfPairs() : ArrayList<#(Int, Int)> + MyListOfPairs() : ArrayList> } diff --git a/compiler/testData/diagnostics/tests/tuples/BasicTuples.kt b/compiler/testData/diagnostics/tests/tuples/BasicTuples.kt deleted file mode 100644 index fac1a06d005..00000000000 --- a/compiler/testData/diagnostics/tests/tuples/BasicTuples.kt +++ /dev/null @@ -1,4 +0,0 @@ -fun foo(a : #(Int, String)) { - a._1 : Int - a._2 : String -} diff --git a/compiler/testData/diagnostics/tests/tuples/UnitValue.kt b/compiler/testData/diagnostics/tests/tuples/UnitValue.kt new file mode 100644 index 00000000000..720a081353e --- /dev/null +++ b/compiler/testData/diagnostics/tests/tuples/UnitValue.kt @@ -0,0 +1,3 @@ +fun test() { + return Unit.VALUE : Unit +} \ No newline at end of file diff --git a/compiler/testData/lazyResolve/namespaceComparator/classObjectAnnotation.kt b/compiler/testData/lazyResolve/namespaceComparator/classObjectAnnotation.kt new file mode 100644 index 00000000000..3988a5d9673 --- /dev/null +++ b/compiler/testData/lazyResolve/namespaceComparator/classObjectAnnotation.kt @@ -0,0 +1,7 @@ +package test + +class Some { + TestAnnotation class object { + annotation class TestAnnotation + } +} \ No newline at end of file diff --git a/compiler/testData/lazyResolve/namespaceComparator/classObjectAnnotation.txt b/compiler/testData/lazyResolve/namespaceComparator/classObjectAnnotation.txt new file mode 100644 index 00000000000..7b835a327f6 --- /dev/null +++ b/compiler/testData/lazyResolve/namespaceComparator/classObjectAnnotation.txt @@ -0,0 +1,11 @@ +namespace test + +internal final class test.Some : jet.Any { + public final /*constructor*/ fun (): test.Some + [ERROR : Unresolved annotation type]() internal final class object test.Some. : jet.Any { + private final /*constructor*/ fun (): test.Some. + internal final annotation class test.Some..TestAnnotation : jet.Annotation { + public final /*constructor*/ fun (): test.Some..TestAnnotation + } + } +} diff --git a/compiler/testData/lazyResolve/namespaceComparator/classObjectHeader.kt b/compiler/testData/lazyResolve/namespaceComparator/classObjectHeader.kt new file mode 100644 index 00000000000..5bb2a5ad088 --- /dev/null +++ b/compiler/testData/lazyResolve/namespaceComparator/classObjectHeader.kt @@ -0,0 +1,9 @@ +package test + +open class ToResolve(f : (Int) -> Int) +fun testFun(a : Int) = 12 + +class TestSome

{ + class object : ToResolve

({testFun(it)}) { + } +} \ No newline at end of file diff --git a/compiler/testData/lazyResolve/namespaceComparator/classObjectHeader.txt b/compiler/testData/lazyResolve/namespaceComparator/classObjectHeader.txt new file mode 100644 index 00000000000..212cf062de6 --- /dev/null +++ b/compiler/testData/lazyResolve/namespaceComparator/classObjectHeader.txt @@ -0,0 +1,12 @@ +namespace test + +internal final class test.TestSome : jet.Any { + public final /*constructor*/ fun (): test.TestSome

+ internal final class object test.TestSome. : test.ToResolve<[ERROR : P]> { + private final /*constructor*/ fun (): test.TestSome. + } +} +internal open class test.ToResolve : jet.Any { + public final /*constructor*/ fun (/*0*/ f: jet.Function1): test.ToResolve +} +internal final fun testFun(/*0*/ a: jet.Int): jet.Int diff --git a/compiler/testData/lazyResolve/namespaceComparatorWithJavaMerge/stdlib-log.txt b/compiler/testData/lazyResolve/namespaceComparatorWithJavaMerge/stdlib-log.txt index 11513f97feb..4603e755d0e 100644 --- a/compiler/testData/lazyResolve/namespaceComparatorWithJavaMerge/stdlib-log.txt +++ b/compiler/testData/lazyResolve/namespaceComparatorWithJavaMerge/stdlib-log.txt @@ -1378,7 +1378,6 @@ public final fun jet.Iterator.iterator(): jet.Iterator public final fun jet.LongIterator.iterator(): jet.LongIterator public final fun jet.ShortIterator.iterator(): jet.ShortIterator public final fun jet.String?.plus(/*0*/ other: jet.Any?): jet.String -public final fun T?.sure(): T public final fun synchronized(/*0*/ lock: jet.Any, /*1*/ block: jet.Function0): R public final fun jet.Any?.toString(): jet.String // diff --git a/compiler/testData/loadJava/MethodTypePOneUpperBound.kt b/compiler/testData/loadJava/MethodTypePOneUpperBound.kt index 2ca41c64c99..f9d94a8e6d4 100644 --- a/compiler/testData/loadJava/MethodTypePOneUpperBound.kt +++ b/compiler/testData/loadJava/MethodTypePOneUpperBound.kt @@ -1,5 +1,5 @@ package test public open class MethodTypePOneUpperBound() : java.lang.Object() { - public open fun bar() : Unit = #() + public open fun bar() : Unit = Unit.VALUE } diff --git a/compiler/testData/loadJava/MethodWithTypeP.kt b/compiler/testData/loadJava/MethodWithTypeP.kt index 274c3fe0b30..f8607ada2ed 100644 --- a/compiler/testData/loadJava/MethodWithTypeP.kt +++ b/compiler/testData/loadJava/MethodWithTypeP.kt @@ -1,5 +1,5 @@ package test public class MethodWithTypeP() : java.lang.Object() { - public fun

f() : Unit = #() + public fun

f() : Unit = Unit.VALUE } diff --git a/compiler/testData/loadJava/MethodWithTypePP.kt b/compiler/testData/loadJava/MethodWithTypePP.kt index 0fc1e73f2ab..de7bbff43fe 100644 --- a/compiler/testData/loadJava/MethodWithTypePP.kt +++ b/compiler/testData/loadJava/MethodWithTypePP.kt @@ -1,5 +1,5 @@ package test public class MethodWithTypePP() : java.lang.Object() { - public fun f() : Unit = #() + public fun f() : Unit = Unit.VALUE } diff --git a/compiler/testData/loadJava/MethodWithTypePRefClassP.kt b/compiler/testData/loadJava/MethodWithTypePRefClassP.kt index 61f6e06ad72..79ca5eb33bf 100644 --- a/compiler/testData/loadJava/MethodWithTypePRefClassP.kt +++ b/compiler/testData/loadJava/MethodWithTypePRefClassP.kt @@ -1,5 +1,5 @@ package test public open class MethodWithTypePRefClassP

() : java.lang.Object() { - public fun f() : Unit = #() + public fun f() : Unit = Unit.VALUE } diff --git a/compiler/testData/loadJava/MethosWithPRefTP.kt b/compiler/testData/loadJava/MethosWithPRefTP.kt index 974ea3f9e59..2fed7f5b4e8 100644 --- a/compiler/testData/loadJava/MethosWithPRefTP.kt +++ b/compiler/testData/loadJava/MethosWithPRefTP.kt @@ -1,5 +1,5 @@ package test public final class MethosWithPRefTP() : java.lang.Object() { - public fun

f(p0: P?) : Unit = #() + public fun

f(p0: P?) : Unit = Unit.VALUE } diff --git a/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.java b/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.java deleted file mode 100644 index 1c808bf3eaa..00000000000 --- a/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.java +++ /dev/null @@ -1,11 +0,0 @@ -package test; - -import java.util.*; -import jet.runtime.typeinfo.KotlinSignature; -import jet.*; - -public class MethodWithTupleType { - @KotlinSignature("fun foo(pair : #(String, String?))") - public void foo(Tuple2 pair) { - } -} diff --git a/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.kt b/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.kt deleted file mode 100644 index eb61d5ac59f..00000000000 --- a/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.kt +++ /dev/null @@ -1,9 +0,0 @@ -package test - -import java.util.* - -public open class MethodWithTupleType : Object() { - public open fun foo(p0 : Tuple2) { // writing Tuple2<..> instead of #(..), because the latter - // adds unnecessary "out" keywords - } -} diff --git a/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.txt b/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.txt deleted file mode 100644 index 1e7024552a3..00000000000 --- a/compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.txt +++ /dev/null @@ -1,6 +0,0 @@ -namespace test - -public open class test.MethodWithTupleType : java.lang.Object { - public final /*constructor*/ fun (): test.MethodWithTupleType - public open fun foo(/*0*/ p0: jet.Tuple2): jet.Tuple0 -} diff --git a/compiler/testData/loadJava/vararg/VarargInt.kt b/compiler/testData/loadJava/vararg/VarargInt.kt index b76312d69de..01574c53407 100644 --- a/compiler/testData/loadJava/vararg/VarargInt.kt +++ b/compiler/testData/loadJava/vararg/VarargInt.kt @@ -1,5 +1,5 @@ package test public open class VarargInt() : java.lang.Object() { - public open fun vararg(vararg p0: Int): Unit = #() + public open fun vararg(vararg p0: Int): Unit = Unit.VALUE } diff --git a/compiler/testData/loadJava/vararg/VarargString.kt b/compiler/testData/loadJava/vararg/VarargString.kt index b624bea5042..657b08c7a98 100644 --- a/compiler/testData/loadJava/vararg/VarargString.kt +++ b/compiler/testData/loadJava/vararg/VarargString.kt @@ -1,5 +1,5 @@ package test public open class VarargString() : java.lang.Object() { - public open fun vararg(vararg p0: String?): Unit = #() + public open fun vararg(vararg p0: String?): Unit = Unit.VALUE } diff --git a/compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamTwoUpperBounds.kt b/compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamTwoUpperBounds.kt index cc7759ea454..d1d002397aa 100644 --- a/compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamTwoUpperBounds.kt +++ b/compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamTwoUpperBounds.kt @@ -5,4 +5,4 @@ trait Bar fun foo() where T : Foo, T : Bar - = #() + = Unit.VALUE diff --git a/compiler/testData/loadKotlin/type/Tuple0.kt b/compiler/testData/loadKotlin/type/Tuple0.kt index 9464c20c380..35080851976 100644 --- a/compiler/testData/loadKotlin/type/Tuple0.kt +++ b/compiler/testData/loadKotlin/type/Tuple0.kt @@ -1,3 +1,3 @@ package test -fun tuple0() = #() +fun tuple0() = Unit.VALUE diff --git a/compiler/testData/loadKotlinCustom/enum/innerEnum.kt b/compiler/testData/loadKotlinCustom/enum/innerEnum.kt new file mode 100644 index 00000000000..c70ba41c988 --- /dev/null +++ b/compiler/testData/loadKotlinCustom/enum/innerEnum.kt @@ -0,0 +1,7 @@ +package test + +class A { + enum class E { + ENTRY + } +} diff --git a/compiler/testData/loadKotlinCustom/enum/innerEnumBinary.txt b/compiler/testData/loadKotlinCustom/enum/innerEnumBinary.txt new file mode 100644 index 00000000000..ced1db8fa84 --- /dev/null +++ b/compiler/testData/loadKotlinCustom/enum/innerEnumBinary.txt @@ -0,0 +1,19 @@ +namespace test + +internal final class test.A : jet.Any { + public final /*constructor*/ fun (): test.A + internal final class object test.A. { + private final /*constructor*/ fun (): test.A. + internal final enum class test.A..E : jet.Enum.E> { + private final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.A..E + public final override /*1*/ /*fake_override*/ fun name(): jet.String + public final override /*1*/ /*fake_override*/ fun ordinal(): jet.Int + internal final class object test.A..E. { + private final /*constructor*/ fun (): test.A..E. + public final val ENTRY: test.A..E + public final fun valueOf(/*0*/ value: jet.String): test.A..E + public final fun values(): jet.Array.E> + } + } + } +} diff --git a/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObject.kt b/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObject.kt new file mode 100644 index 00000000000..e7ace469ff6 --- /dev/null +++ b/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObject.kt @@ -0,0 +1,8 @@ +package test + +class A { + class object { } + enum class E { + ENTRY + } +} diff --git a/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObjectBinary.txt b/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObjectBinary.txt new file mode 100644 index 00000000000..ced1db8fa84 --- /dev/null +++ b/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObjectBinary.txt @@ -0,0 +1,19 @@ +namespace test + +internal final class test.A : jet.Any { + public final /*constructor*/ fun (): test.A + internal final class object test.A. { + private final /*constructor*/ fun (): test.A. + internal final enum class test.A..E : jet.Enum.E> { + private final /*constructor*/ fun (/*0*/ p0: jet.String?, /*1*/ p1: jet.Int): test.A..E + public final override /*1*/ /*fake_override*/ fun name(): jet.String + public final override /*1*/ /*fake_override*/ fun ordinal(): jet.Int + internal final class object test.A..E. { + private final /*constructor*/ fun (): test.A..E. + public final val ENTRY: test.A..E + public final fun valueOf(/*0*/ value: jet.String): test.A..E + public final fun values(): jet.Array.E> + } + } + } +} diff --git a/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObjectSource.txt b/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObjectSource.txt new file mode 100644 index 00000000000..5b02b0508f5 --- /dev/null +++ b/compiler/testData/loadKotlinCustom/enum/innerEnumExistingClassObjectSource.txt @@ -0,0 +1,24 @@ +namespace test + +internal final class test.A : jet.Any { + public final /*constructor*/ fun (): test.A + internal final class object test.A. : jet.Any { + private final /*constructor*/ fun (): test.A. + internal final enum class test.A..E : jet.Enum.E> { + private final /*constructor*/ fun (): test.A..E + public final override /*1*/ /*fake_override*/ fun name(): jet.String + public final override /*1*/ /*fake_override*/ fun ordinal(): jet.Int + internal final class object test.A..E. { + private final /*constructor*/ fun (): test.A..E. + internal final val ENTRY: test.A..E..ENTRY + internal final enum entry test.A..E..ENTRY : test.A..E { + private final /*constructor*/ fun (): test.A..E..ENTRY + public final override /*1*/ /*fake_override*/ fun name(): jet.String + public final override /*1*/ /*fake_override*/ fun ordinal(): jet.Int + } + public final fun valueOf(/*0*/ value: jet.String): test.A..E + public final fun values(): jet.Array.E> + } + } + } +} diff --git a/compiler/testData/loadKotlinCustom/enum/innerEnumSource.txt b/compiler/testData/loadKotlinCustom/enum/innerEnumSource.txt new file mode 100644 index 00000000000..13bb16d5e0b --- /dev/null +++ b/compiler/testData/loadKotlinCustom/enum/innerEnumSource.txt @@ -0,0 +1,24 @@ +namespace test + +internal final class test.A : jet.Any { + public final /*constructor*/ fun (): test.A + public final class object test.A. { + private final /*constructor*/ fun (): test.A. + internal final enum class test.A..E : jet.Enum.E> { + private final /*constructor*/ fun (): test.A..E + public final override /*1*/ /*fake_override*/ fun name(): jet.String + public final override /*1*/ /*fake_override*/ fun ordinal(): jet.Int + internal final class object test.A..E. { + private final /*constructor*/ fun (): test.A..E. + internal final val ENTRY: test.A..E..ENTRY + internal final enum entry test.A..E..ENTRY : test.A..E { + private final /*constructor*/ fun (): test.A..E..ENTRY + public final override /*1*/ /*fake_override*/ fun name(): jet.String + public final override /*1*/ /*fake_override*/ fun ordinal(): jet.Int + } + public final fun valueOf(/*0*/ value: jet.String): test.A..E + public final fun values(): jet.Array.E> + } + } + } +} diff --git a/compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.jet b/compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.jet new file mode 100644 index 00000000000..bfe2ad9318e --- /dev/null +++ b/compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.jet @@ -0,0 +1 @@ +class Test(val a = 12, val b : Int = 13) \ No newline at end of file diff --git a/compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.txt b/compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.txt new file mode 100644 index 00000000000..ebd52b9b83f --- /dev/null +++ b/compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.txt @@ -0,0 +1,41 @@ +JetFile: ValueParameterNoTypeRecovery.jet + NAMESPACE_HEADER + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Test') + TYPE_PARAMETER_LIST + + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiErrorElement:Parameters must have type annotation + + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('12') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('b') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('13') + PsiElement(RPAR)(')') \ No newline at end of file diff --git a/compiler/testData/renderer/TupleTypes.kt b/compiler/testData/renderer/TupleTypes.kt index 184bf00bc9f..82b6a11e91d 100644 --- a/compiler/testData/renderer/TupleTypes.kt +++ b/compiler/testData/renderer/TupleTypes.kt @@ -2,20 +2,8 @@ var v1 : Tuple0 var v2 : Tuple0? var v3 : Unit var v4 : Unit? -var v5 : #() -var v6 : #(Int) -var v7 : #(Int)? -var v8 : #(Int, String, String) -var v9 : Tuple2 -var v10 : Tuple3? //internal final var v1 : Unit defined in root package //internal final var v2 : Unit? defined in root package //internal final var v3 : Unit defined in root package //internal final var v4 : Unit? defined in root package -//internal final var v5 : Unit defined in root package -//internal final var v6 : #(jet.Int) defined in root package -//internal final var v7 : #(jet.Int)? defined in root package -//internal final var v8 : #(jet.Int, jet.String, jet.String) defined in root package -//internal final var v9 : #(jet.Int, jet.String) defined in root package -//internal final var v10 : #(jet.Int, jet.Int, jet.Int)? defined in root package diff --git a/compiler/testData/writeSignature/ListOfCharSequence.kt b/compiler/testData/writeSignature/ListOfCharSequence.kt index c9226dec0e7..75f2980cf04 100644 --- a/compiler/testData/writeSignature/ListOfCharSequence.kt +++ b/compiler/testData/writeSignature/ListOfCharSequence.kt @@ -4,4 +4,4 @@ fun foo(p: List) = 1 // method: namespace::foo // jvm signature: (Ljava/util/List;)I // generic signature: (Ljava/util/List;)I -// kotlin signature: (Ljava/util/List;)I // TODO: skip Kotlin signature +// kotlin signature: (Ljet/List;)I // TODO: skip Kotlin signature diff --git a/compiler/testData/writeSignature/ListOfStar.kt b/compiler/testData/writeSignature/ListOfStar.kt index 532114a7ec0..edc429c8b25 100644 --- a/compiler/testData/writeSignature/ListOfStar.kt +++ b/compiler/testData/writeSignature/ListOfStar.kt @@ -4,4 +4,4 @@ fun listOfStar(): List<*> = throw Exception() // method: namespace::listOfStar // jvm signature: ()Ljava/util/List; // generic signature: ()Ljava/util/List<+Ljava/lang/Object;>; -// kotlin signature: ()Ljava/util/List<+?Ljava/lang/Object;>; +// kotlin signature: ()Ljet/List<+?Ljava/lang/Object;>; diff --git a/compiler/testData/writeSignature/MapEntry.kt b/compiler/testData/writeSignature/MapEntry.kt new file mode 100644 index 00000000000..472593790bc --- /dev/null +++ b/compiler/testData/writeSignature/MapEntry.kt @@ -0,0 +1,6 @@ +fun getEntry(): jet.Map.Entry? = null + +// method: namespace::getEntry +// jvm signature: ()Ljava/util/Map$Entry; +// generic signature: ()Ljava/util/Map$Entry; +// kotlin signature: ()?Ljet/Map.Entry; diff --git a/compiler/testData/writeSignature/MutableMapEntry.kt b/compiler/testData/writeSignature/MutableMapEntry.kt new file mode 100644 index 00000000000..6f1a31ba6de --- /dev/null +++ b/compiler/testData/writeSignature/MutableMapEntry.kt @@ -0,0 +1,6 @@ +fun getEntry(): jet.MutableMap.MutableEntry? = null + +// method: namespace::getEntry +// jvm signature: ()Ljava/util/Map$Entry; +// generic signature: ()Ljava/util/Map$Entry; +// kotlin signature: ()?Ljet/MutableMap.MutableEntry; diff --git a/compiler/testData/writeSignature/constructor/ConstructorCollectionParameter.kt b/compiler/testData/writeSignature/constructor/ConstructorCollectionParameter.kt index c2fcf9280d3..24e7f775289 100644 --- a/compiler/testData/writeSignature/constructor/ConstructorCollectionParameter.kt +++ b/compiler/testData/writeSignature/constructor/ConstructorCollectionParameter.kt @@ -4,4 +4,4 @@ class TestingKotlinCollections(val arguments: Collection) // method: TestingKotlinCollections:: // jvm signature: (Ljava/util/Collection;)V // generic signature: (Ljava/util/Collection;)V -// kotlin signature: (Ljava/util/Collection;)null +// kotlin signature: (Ljet/Collection;)null diff --git a/compiler/tests/org/jetbrains/jet/JetTestUtils.java b/compiler/tests/org/jetbrains/jet/JetTestUtils.java index 6a9f2c3c717..1e1ce1b16cc 100644 --- a/compiler/tests/org/jetbrains/jet/JetTestUtils.java +++ b/compiler/tests/org/jetbrains/jet/JetTestUtils.java @@ -16,6 +16,7 @@ package org.jetbrains.jet; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.intellij.openapi.Disposable; @@ -30,6 +31,7 @@ import com.intellij.testFramework.LightVirtualFile; import junit.framework.TestCase; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode; @@ -87,6 +89,13 @@ public class JetTestUtils { public Collection getKeys(WritableSlice slice) { return DUMMY_TRACE.getKeys(slice); } + + @NotNull + @TestOnly + @Override + public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) { + return ImmutableMap.of(); + } }; } @@ -138,6 +147,13 @@ public class JetTestUtils { public Collection getKeys(WritableSlice slice) { return DUMMY_EXCEPTION_ON_ERROR_TRACE.getKeys(slice); } + + @NotNull + @TestOnly + @Override + public ImmutableMap getSliceContents(@NotNull ReadOnlySlice slice) { + return ImmutableMap.of(); + } }; } diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index ddbc790f19f..71ee5ab3b31 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -141,6 +141,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/ClassObjects.kt"); } + @TestMetadata("CompareToWithErrorType.kt") + public void testCompareToWithErrorType() throws Exception { + doTest("compiler/testData/diagnostics/tests/CompareToWithErrorType.kt"); + } + @TestMetadata("Constants.kt") public void testConstants() throws Exception { doTest("compiler/testData/diagnostics/tests/Constants.kt"); @@ -1088,11 +1093,6 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/dataFlow/IsExpression.kt"); } - @TestMetadata("TupleExpression.kt") - public void testTupleExpression() throws Exception { - doTest("compiler/testData/diagnostics/tests/dataFlow/TupleExpression.kt"); - } - @TestMetadata("WhenSubject.kt") public void testWhenSubject() throws Exception { doTest("compiler/testData/diagnostics/tests/dataFlow/WhenSubject.kt"); @@ -1357,6 +1357,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage } @TestMetadata("compiler/testData/diagnostics/tests/enum") + @InnerTestClasses({Enum.Inner.class}) public static class Enum extends AbstractDiagnosticsTestWithEagerResolve { public void testAllFilesPresentInEnum() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve", new File("compiler/testData/diagnostics/tests/enum"), "kt", true); @@ -1367,11 +1368,21 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/enum/enumInheritance.kt"); } + @TestMetadata("enumModifier.kt") + public void testEnumModifier() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/enumModifier.kt"); + } + @TestMetadata("enumStarImport.kt") public void testEnumStarImport() throws Exception { doTest("compiler/testData/diagnostics/tests/enum/enumStarImport.kt"); } + @TestMetadata("enumWithEmptyName.kt") + public void testEnumWithEmptyName() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/enumWithEmptyName.kt"); + } + @TestMetadata("importEnumFromJava.kt") public void testImportEnumFromJava() throws Exception { doTest("compiler/testData/diagnostics/tests/enum/importEnumFromJava.kt"); @@ -1412,6 +1423,75 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/enum/javaEnumWithProperty.kt"); } + @TestMetadata("compiler/testData/diagnostics/tests/enum/inner") + public static class Inner extends AbstractDiagnosticsTestWithEagerResolve { + public void testAllFilesPresentInInner() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve", new File("compiler/testData/diagnostics/tests/enum/inner"), "kt", true); + } + + @TestMetadata("existingClassObject.kt") + public void testExistingClassObject() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/existingClassObject.kt"); + } + + @TestMetadata("insideClass.kt") + public void testInsideClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/insideClass.kt"); + } + + @TestMetadata("insideClassObject.kt") + public void testInsideClassObject() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/insideClassObject.kt"); + } + + @TestMetadata("insideEnum.kt") + public void testInsideEnum() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/insideEnum.kt"); + } + + @TestMetadata("insideEnumEntry.kt") + public void testInsideEnumEntry() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/insideEnumEntry.kt"); + } + + @TestMetadata("insideInnerClassNotAllowed.kt") + public void testInsideInnerClassNotAllowed() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/insideInnerClassNotAllowed.kt"); + } + + @TestMetadata("insideObject.kt") + public void testInsideObject() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/insideObject.kt"); + } + + @TestMetadata("insideTrait.kt") + public void testInsideTrait() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/insideTrait.kt"); + } + + @TestMetadata("redeclarationInClassObject.kt") + public void testRedeclarationInClassObject() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/redeclarationInClassObject.kt"); + } + + @TestMetadata("twoEnums.kt") + public void testTwoEnums() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/twoEnums.kt"); + } + + @TestMetadata("twoEnumsInClassObjectAndInnerClass.kt") + public void testTwoEnumsInClassObjectAndInnerClass() throws Exception { + doTest("compiler/testData/diagnostics/tests/enum/inner/twoEnumsInClassObjectAndInnerClass.kt"); + } + + } + + public static Test innerSuite() { + TestSuite suite = new TestSuite("Enum"); + suite.addTestSuite(Enum.class); + suite.addTestSuite(Inner.class); + return suite; + } } @TestMetadata("compiler/testData/diagnostics/tests/extensions") @@ -1990,6 +2070,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve", new File("compiler/testData/diagnostics/tests/library"), "kt", true); } + @TestMetadata("Collections.kt") + public void testCollections() throws Exception { + doTest("compiler/testData/diagnostics/tests/library/Collections.kt"); + } + @TestMetadata("kt828.kt") public void testKt828() throws Exception { doTest("compiler/testData/diagnostics/tests/library/kt828.kt"); @@ -2093,6 +2178,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt362.kt"); } + @TestMetadata("noUnnecessaryNotNullAssertionOnErrorType.kt") + public void testNoUnnecessaryNotNullAssertionOnErrorType() throws Exception { + doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt"); + } + @TestMetadata("NullableNothingIsExactlyNull.kt") public void testNullableNothingIsExactlyNull() throws Exception { doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/NullableNothingIsExactlyNull.kt"); @@ -2340,6 +2430,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/override/DelegationVar.kt"); } + @TestMetadata("DuplicateMethod.kt") + public void testDuplicateMethod() throws Exception { + doTest("compiler/testData/diagnostics/tests/override/DuplicateMethod.kt"); + } + @TestMetadata("EqualityOfIntersectionTypes.kt") public void testEqualityOfIntersectionTypes() throws Exception { doTest("compiler/testData/diagnostics/tests/override/EqualityOfIntersectionTypes.kt"); @@ -3266,9 +3361,9 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve", new File("compiler/testData/diagnostics/tests/tuples"), "kt", true); } - @TestMetadata("BasicTuples.kt") - public void testBasicTuples() throws Exception { - doTest("compiler/testData/diagnostics/tests/tuples/BasicTuples.kt"); + @TestMetadata("UnitValue.kt") + public void testUnitValue() throws Exception { + doTest("compiler/testData/diagnostics/tests/tuples/UnitValue.kt"); } } @@ -3339,7 +3434,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage suite.addTestSuite(DataFlow.class); suite.addTestSuite(DataFlowInfoTraversal.class); suite.addTest(DeclarationChecks.innerSuite()); - suite.addTestSuite(Enum.class); + suite.addTest(Enum.innerSuite()); suite.addTestSuite(Extensions.class); suite.addTestSuite(Generics.class); suite.addTest(IncompleteCode.innerSuite()); diff --git a/compiler/tests/org/jetbrains/jet/codegen/AbstractDataClassCodegenTest.java b/compiler/tests/org/jetbrains/jet/codegen/AbstractDataClassCodegenTest.java index a3c7448ac8c..c6918d0a351 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/AbstractDataClassCodegenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/AbstractDataClassCodegenTest.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.codegen; -import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.test.generator.SimpleTestClassModel; import org.jetbrains.jet.test.generator.TestGenerator; @@ -31,7 +30,7 @@ public abstract class AbstractDataClassCodegenTest extends CodegenTestCase { @Override protected void setUp() throws Exception { super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + createEnvironmentWithFullJdk(); } public static void main(String[] args) throws IOException { diff --git a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java index 066ed9d83e1..d81ffb3ae79 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java @@ -441,7 +441,7 @@ public class ClassGenTest extends CodegenTestCase { } public void testKt1538() throws Exception { - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL); blackBoxFile("regressions/kt1538.kt"); } @@ -606,4 +606,9 @@ public class ClassGenTest extends CodegenTestCase { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); blackBoxFileWithJava("regressions/kt2781.kt", true); } + + public void testKt2607() throws Exception { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("regressions/kt2607.kt"); + } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java index 90300810ad5..052e53c90d9 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java @@ -26,7 +26,7 @@ import java.io.File; /** This class is generated by {@link org.jetbrains.jet.codegen.AbstractDataClassCodegenTest}. DO NOT MODIFY MANUALLY */ @TestMetadata("compiler/testData/codegen/dataClasses") -@InnerTestClasses({DataClassCodegenTestGenerated.Tostring.class}) +@InnerTestClasses({DataClassCodegenTestGenerated.Equals.class, DataClassCodegenTestGenerated.Hashcode.class, DataClassCodegenTestGenerated.Tostring.class}) public class DataClassCodegenTestGenerated extends AbstractDataClassCodegenTest { public void testAllFilesPresentInDataClasses() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.AbstractDataClassCodegenTest", new File("compiler/testData/codegen/dataClasses"), "kt", true); @@ -82,11 +82,101 @@ public class DataClassCodegenTestGenerated extends AbstractDataClassCodegenTest blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/unitComponent.kt"); } + @TestMetadata("compiler/testData/codegen/dataClasses/equals") + public static class Equals extends AbstractDataClassCodegenTest { + public void testAllFilesPresentInEquals() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.AbstractDataClassCodegenTest", new File("compiler/testData/codegen/dataClasses/equals"), "kt", true); + } + + @TestMetadata("genericarray.kt") + public void testGenericarray() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/equals/genericarray.kt"); + } + + @TestMetadata("instanceof.kt") + public void testInstanceof() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/equals/instanceof.kt"); + } + + @TestMetadata("intarray.kt") + public void testIntarray() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/equals/intarray.kt"); + } + + @TestMetadata("nullother.kt") + public void testNullother() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/equals/nullother.kt"); + } + + @TestMetadata("sameinstance.kt") + public void testSameinstance() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/equals/sameinstance.kt"); + } + + } + + @TestMetadata("compiler/testData/codegen/dataClasses/hashcode") + public static class Hashcode extends AbstractDataClassCodegenTest { + public void testAllFilesPresentInHashcode() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.AbstractDataClassCodegenTest", new File("compiler/testData/codegen/dataClasses/hashcode"), "kt", true); + } + + @TestMetadata("array.kt") + public void testArray() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/array.kt"); + } + + @TestMetadata("boolean.kt") + public void testBoolean() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/boolean.kt"); + } + + @TestMetadata("byte.kt") + public void testByte() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/byte.kt"); + } + + @TestMetadata("char.kt") + public void testChar() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/char.kt"); + } + + @TestMetadata("double.kt") + public void testDouble() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/double.kt"); + } + + @TestMetadata("float.kt") + public void testFloat() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/float.kt"); + } + + @TestMetadata("int.kt") + public void testInt() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/int.kt"); + } + + @TestMetadata("long.kt") + public void testLong() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/long.kt"); + } + + @TestMetadata("null.kt") + public void testNull() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/null.kt"); + } + + @TestMetadata("short.kt") + public void testShort() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/hashcode/short.kt"); + } + + } + @TestMetadata("compiler/testData/codegen/dataClasses/tostring") public static class Tostring extends AbstractDataClassCodegenTest { public void testAllFilesPresentInTostring() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.AbstractDataClassCodegenTest", - new File("compiler/testData/codegen/dataClasses/tostring"), "kt", true); + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.AbstractDataClassCodegenTest", new File("compiler/testData/codegen/dataClasses/tostring"), "kt", true); } @TestMetadata("arrayParams.kt") @@ -124,6 +214,8 @@ public class DataClassCodegenTestGenerated extends AbstractDataClassCodegenTest public static Test suite() { TestSuite suite = new TestSuite("DataClassCodegenTestGenerated"); suite.addTestSuite(DataClassCodegenTestGenerated.class); + suite.addTestSuite(Equals.class); + suite.addTestSuite(Hashcode.class); suite.addTestSuite(Tostring.class); return suite; } diff --git a/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java index 531cd7c4799..028ab6e4fc4 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/EnumGenTest.java @@ -155,4 +155,12 @@ public class EnumGenTest extends CodegenTestCase { public void testEntryWithInner() { blackBoxFile("enum/entrywithinner.kt"); } + + public void testInner() { + blackBoxFile("enum/inner.kt"); + } + + public void testInnerWithExistingClassObject() { + blackBoxFile("enum/innerWithExistingClassObject.kt"); + } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java index 1671d1d23f5..17e5c201e4b 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/NamespaceGenTest.java @@ -17,15 +17,12 @@ package org.jetbrains.jet.codegen; import jet.IntRange; -import jet.Tuple2; -import jet.Tuple4; import org.jetbrains.jet.ConfigurationKind; import java.awt.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Arrays; /** * @author yole @@ -507,25 +504,6 @@ public class NamespaceGenTest extends CodegenTestCase { assertEquals("JetLanguage", list.get(0)); } - public void testTupleLiteral() throws Exception { - loadText("fun foo() = #(1, \"foo\")"); -// System.out.println(generateToText()); - final Method main = generateFunction("foo"); - Tuple2 tuple2 = (Tuple2) main.invoke(null); - assertEquals(1, tuple2._1); - assertEquals("foo", tuple2._2); - } - - public void testParametrizedTupleLiteral() throws Exception { - loadText("fun E.foo(extra: java.util.List) = #(1, \"foo\", this, extra)"); -// System.out.println(generateToText()); - final Method main = generateFunction(); - Tuple4 tuple4 = (Tuple4) main.invoke(null, "aaa", Arrays.asList(10)); - assertEquals(1, tuple4._1); - assertEquals("foo", tuple4._2); - assertEquals("aaa", tuple4._3); - } - public void testEscapeSequence() throws Exception { loadText("fun foo() = \"a\\nb\\$\""); final Method main = generateFunction(); diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index 878d143fd4c..6fcdf26c62a 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -320,12 +320,12 @@ public class PrimitiveTypesTest extends CodegenTestCase { } public void testSureNonnull () throws Exception { - loadText("fun box() = 10.sure().toString()"); + loadText("fun box() = 10!!.toString()"); assertFalse(generateToText().contains("IFNONNULL")); } public void testSureNullable () throws Exception { - loadText("val a : Int? = 10; fun box() = a.sure().toString()"); + loadText("val a : Int? = 10; fun box() = a!!.toString()"); assertTrue(generateToText().contains("IFNONNULL")); } @@ -448,4 +448,12 @@ public class PrimitiveTypesTest extends CodegenTestCase { public void testEmptyRanges() throws Exception { blackBoxFile("emptyRanges.kt"); } + + public void test2251() throws Exception { + blackBoxFile("regressions/kt2251.kt"); + } + + public void test2794() throws Exception { + blackBoxFile("regressions/kt2794.kt"); + } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java index 50337f22a69..543fc116893 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java @@ -19,10 +19,7 @@ package org.jetbrains.jet.codegen; import org.jetbrains.asm4.Opcodes; import org.jetbrains.jet.ConfigurationKind; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; +import java.lang.reflect.*; /** * @author yole @@ -280,6 +277,16 @@ public class PropertyGenTest extends CodegenTestCase { blackBoxFile("regressions/kt2509.kt"); } + public void testKt2786() throws Exception { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("regressions/kt2786.kt"); + } + + public void testKt2655() throws Exception { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + blackBoxFile("regressions/kt2655.kt"); + } + public void testKt1528() throws Exception { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); blackBoxMultiFile("regressions/kt1528_1.kt", "regressions/kt1528_3.kt"); @@ -313,4 +320,44 @@ public class PropertyGenTest extends CodegenTestCase { throw new RuntimeException(e); } } + + public void testKt2677() throws Exception { + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); + loadFile("regressions/kt2677.kt"); + final Class aClass = loadImplementationClass(generateClassesInFile(), "DerivedWeatherReport"); + final Class bClass = aClass.getSuperclass(); + + try { + { + Method get = aClass.getDeclaredMethod("getForecast"); + Type type = get.getGenericReturnType(); + assertInstanceOf(type, ParameterizedType.class); + ParameterizedType parameterizedType = (ParameterizedType) type; + assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]); + + Method set = aClass.getDeclaredMethod("setForecast", (Class)parameterizedType.getRawType()); + type = set.getGenericParameterTypes()[0]; + parameterizedType = (ParameterizedType) type; + assertInstanceOf(type, ParameterizedType.class); + assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]); + } + { + Method get = bClass.getDeclaredMethod("getForecast"); + Type type = get.getGenericReturnType(); + assertInstanceOf(type, ParameterizedType.class); + ParameterizedType parameterizedType = (ParameterizedType) type; + assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]); + + Method set = bClass.getDeclaredMethod("setForecast", (Class)parameterizedType.getRawType()); + type = set.getGenericParameterTypes()[0]; + parameterizedType = (ParameterizedType) type; + assertInstanceOf(type, ParameterizedType.class); + assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]); + } + } + catch (Throwable e) { + System.out.println(generateToText()); + throw new RuntimeException(e); + } + } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index 7f26e004cf7..5683b341d58 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -377,4 +377,12 @@ public class StdlibTest extends CodegenTestCase { public void testKt2596() { blackBoxFile("regressions/kt2596.kt"); } + + public void testCollections() { + blackBoxFile("jdk-annotations/collections.kt"); + } + + public void testNoClassObjectForJavaClass() throws Exception { + blackBoxFileWithJava("stdlib/noClassObjectForJavaClass.kt"); + } } diff --git a/compiler/tests/org/jetbrains/jet/codegen/TupleGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/TupleGenTest.java index 49a8c8bd78c..f5025677477 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/TupleGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/TupleGenTest.java @@ -19,9 +19,10 @@ package org.jetbrains.jet.codegen; import org.jetbrains.jet.ConfigurationKind; public class TupleGenTest extends CodegenTestCase { - public void testBasic() { + + public void testUnitValue() { createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - blackBoxFile("/tuples/basic.jet"); + blackBoxFile("/tuples/UnitValue.kt"); // System.out.println(generateToText()); } } diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadCompiledKotlinTest.java similarity index 62% rename from compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTest.java rename to compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadCompiledKotlinTest.java index ce0206778b5..98ee937e105 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractLoadCompiledKotlinTest.java @@ -17,17 +17,19 @@ package org.jetbrains.jet.jvm.compiler; import junit.framework.Assert; -import junit.framework.Test; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.ConfigurationKind; -import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.analyzer.AnalyzeExhaust; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.test.TestCaseWithTmpdir; +import org.jetbrains.jet.test.generator.SimpleTestClassModel; +import org.jetbrains.jet.test.generator.TestGenerator; import org.jetbrains.jet.test.util.NamespaceComparator; import java.io.File; +import java.io.IOException; +import java.util.Arrays; import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.TEST_PACKAGE_FQNAME; import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.compileKotlinToDirAndGetAnalyzeExhaust; @@ -39,40 +41,34 @@ import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaces; * @author Stepan Koltsov */ @SuppressWarnings("JUnitTestCaseWithNoTests") -public final class LoadCompiledKotlinTest extends TestCaseWithTmpdir { - - @NotNull - private final File testFile; - @NotNull - private final File txtFile; - - @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors") - public LoadCompiledKotlinTest(@NotNull File testFile) { - this.testFile = testFile; - this.txtFile = new File(testFile.getPath().replaceFirst("\\.kt$", ".txt")); - setName(testFile.getName()); - } - - @Override - public void runTest() throws Exception { - AnalyzeExhaust exhaust = compileKotlinToDirAndGetAnalyzeExhaust(testFile, tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY); +public abstract class AbstractLoadCompiledKotlinTest extends TestCaseWithTmpdir { + public void doTest(@NotNull String ktFileName) throws Exception { + File ktFile = new File(ktFileName); + File txtFile = new File(ktFileName.replaceFirst("\\.kt$", ".txt")); + AnalyzeExhaust exhaust = compileKotlinToDirAndGetAnalyzeExhaust(ktFile, tmpdir, getTestRootDisposable(), + ConfigurationKind.JDK_ONLY); NamespaceDescriptor namespaceFromSource = exhaust.getBindingContext().get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, TEST_PACKAGE_FQNAME); assert namespaceFromSource != null; Assert.assertEquals("test", namespaceFromSource.getName().getName()); - NamespaceDescriptor namespaceFromClass = LoadDescriptorUtil.loadTestNamespaceFromBinaries(tmpdir, getTestRootDisposable(), ConfigurationKind.JDK_ONLY); + NamespaceDescriptor namespaceFromClass = LoadDescriptorUtil.loadTestNamespaceFromBinaries(tmpdir, getTestRootDisposable(), + ConfigurationKind.JDK_ONLY); compareNamespaces(namespaceFromSource, namespaceFromClass, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, txtFile); } - public static Test suite() { - return JetTestCaseBuilder.suiteForDirectory(JetTestCaseBuilder.getTestDataPathBase(), "/loadKotlin", true, new JetTestCaseBuilder.NamedTestFactory() { - @NotNull - @Override - public Test createTest(@NotNull String dataPath, @NotNull String name, @NotNull File file) { - return new LoadCompiledKotlinTest(file); - } - }); + public static void main(String[] args) throws IOException { + String aPackage = "org.jetbrains.jet.jvm.compiler"; + String extension = "kt"; + new TestGenerator( + "compiler/tests/", + aPackage, + "LoadCompiledKotlinTestGenerated", + AbstractLoadCompiledKotlinTest.class, + Arrays.asList( + new SimpleTestClassModel(new File("compiler/testData/loadKotlin"), true, extension, "doTest") + ), + AbstractLoadCompiledKotlinTest.class + ).generateAndSave(); } - } diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/JvmClassNameTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/JvmClassNameTest.java new file mode 100644 index 00000000000..923be922b1e --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/JvmClassNameTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.jvm.compiler; + +import com.google.common.collect.Lists; +import org.jetbrains.jet.lang.resolve.java.JvmClassName; +import org.junit.Test; + +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +/** + * @author svtk + */ +public class JvmClassNameTest { + @Test + public void signatureName() { + testSignatureName("jet/Map", "jet/Map", "jet.Map", "jet.Map", Collections.emptyList()); + } + + @Test + public void signatureNameOfInnerClass() { + testSignatureName("jet/Map.Entry", "jet/Map$Entry", "jet.Map.Entry", "jet.Map", Lists.newArrayList("Entry")); + } + + @Test + public void signatureNameOfDeepInnerClass() { + testSignatureName("jet/Map.Entry.AAA", "jet/Map$Entry$AAA", "jet.Map.Entry.AAA", "jet.Map", Lists.newArrayList("Entry", "AAA")); + } + + @Test + public void simpleName() { + testSignatureName("jet", "jet", "jet", "jet", Collections.emptyList()); + } + + @Test + public void incorrectSignature() { + testSignatureName("jet/Map.", "jet/Map$", "jet.Map.", "jet.Map", Lists.newArrayList("")); + + } + + private static void testSignatureName( + String className, + String innerClassName, + String fqName, + String outerClassName, + List innerClassNameList + ) { + JvmClassName mapEntryName = JvmClassName.bySignatureName(className); + assertEquals(innerClassName, mapEntryName.getInternalName()); + assertEquals(fqName, mapEntryName.getFqName().getFqName()); + assertEquals(outerClassName, mapEntryName.getOuterClassFqName().getFqName()); + assertEquals(innerClassNameList, mapEntryName.getInnerClassNameList()); + } +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTestGenerated.java new file mode 100644 index 00000000000..52a7909b740 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTestGenerated.java @@ -0,0 +1,901 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.jet.jvm.compiler; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.io.File; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; + +import org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest; + +/** This class is generated by {@link org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest}. DO NOT MODIFY MANUALLY */ +@TestMetadata("compiler/testData/loadKotlin") +@InnerTestClasses({LoadCompiledKotlinTestGenerated.Class.class, LoadCompiledKotlinTestGenerated.ClassFun.class, LoadCompiledKotlinTestGenerated.ClassObject.class, LoadCompiledKotlinTestGenerated.Constructor.class, LoadCompiledKotlinTestGenerated.DataClass.class, LoadCompiledKotlinTestGenerated.Fun.class, LoadCompiledKotlinTestGenerated.Prop.class, LoadCompiledKotlinTestGenerated.Type.class, LoadCompiledKotlinTestGenerated.Visibility.class}) +public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInLoadKotlin() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin"), "kt", true); + } + + @TestMetadata("compiler/testData/loadKotlin/class") + public static class Class extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInClass() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/class"), "kt", true); + } + + @TestMetadata("Class.kt") + public void testClass() throws Exception { + doTest("compiler/testData/loadKotlin/class/Class.kt"); + } + + @TestMetadata("ClassInParam.kt") + public void testClassInParam() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassInParam.kt"); + } + + @TestMetadata("ClassInnerClass.kt") + public void testClassInnerClass() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassInnerClass.kt"); + } + + @TestMetadata("ClassOutParam.kt") + public void testClassOutParam() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassOutParam.kt"); + } + + @TestMetadata("ClassParam.kt") + public void testClassParam() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassParam.kt"); + } + + @TestMetadata("ClassParamReferencesParam.kt") + public void testClassParamReferencesParam() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassParamReferencesParam.kt"); + } + + @TestMetadata("ClassParamReferencesParam2.kt") + public void testClassParamReferencesParam2() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassParamReferencesParam2.kt"); + } + + @TestMetadata("ClassParamReferencesSelf.kt") + public void testClassParamReferencesSelf() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassParamReferencesSelf.kt"); + } + + @TestMetadata("ClassParamUpperClassBound.kt") + public void testClassParamUpperClassBound() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassParamUpperClassBound.kt"); + } + + @TestMetadata("ClassParamUpperClassInterfaceBound.kt") + public void testClassParamUpperClassInterfaceBound() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassParamUpperClassInterfaceBound.kt"); + } + + @TestMetadata("ClassParamUpperInterfaceBound.kt") + public void testClassParamUpperInterfaceBound() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassParamUpperInterfaceBound.kt"); + } + + @TestMetadata("ClassParamUpperInterfaceClassBound.kt") + public void testClassParamUpperInterfaceClassBound() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassParamUpperInterfaceClassBound.kt"); + } + + @TestMetadata("ClassTwoParams.kt") + public void testClassTwoParams() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassTwoParams.kt"); + } + + @TestMetadata("ClassTwoParams2.kt") + public void testClassTwoParams2() throws Exception { + doTest("compiler/testData/loadKotlin/class/ClassTwoParams2.kt"); + } + + @TestMetadata("InheritClassSimple.kt") + public void testInheritClassSimple() throws Exception { + doTest("compiler/testData/loadKotlin/class/InheritClassSimple.kt"); + } + + @TestMetadata("InheritClassWithParam.kt") + public void testInheritClassWithParam() throws Exception { + doTest("compiler/testData/loadKotlin/class/InheritClassWithParam.kt"); + } + + @TestMetadata("InheritTraitWithParam.kt") + public void testInheritTraitWithParam() throws Exception { + doTest("compiler/testData/loadKotlin/class/InheritTraitWithParam.kt"); + } + + @TestMetadata("InnerClass.kt") + public void testInnerClass() throws Exception { + doTest("compiler/testData/loadKotlin/class/InnerClass.kt"); + } + + @TestMetadata("InnerClassExtendInnerClass.kt") + public void testInnerClassExtendInnerClass() throws Exception { + doTest("compiler/testData/loadKotlin/class/InnerClassExtendInnerClass.kt"); + } + + @TestMetadata("Trait.kt") + public void testTrait() throws Exception { + doTest("compiler/testData/loadKotlin/class/Trait.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/classFun") + public static class ClassFun extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInClassFun() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/classFun"), "kt", true); + } + + @TestMetadata("ClassInParamUsedInFun.kt") + public void testClassInParamUsedInFun() throws Exception { + doTest("compiler/testData/loadKotlin/classFun/ClassInParamUsedInFun.kt"); + } + + @TestMetadata("ClassParamUsedInFun.kt") + public void testClassParamUsedInFun() throws Exception { + doTest("compiler/testData/loadKotlin/classFun/ClassParamUsedInFun.kt"); + } + + @TestMetadata("FunDelegationToTraitImpl.kt") + public void testFunDelegationToTraitImpl() throws Exception { + doTest("compiler/testData/loadKotlin/classFun/FunDelegationToTraitImpl.kt"); + } + + @TestMetadata("FunInParamSuper.kt") + public void testFunInParamSuper() throws Exception { + doTest("compiler/testData/loadKotlin/classFun/FunInParamSuper.kt"); + } + + @TestMetadata("TraitFinalFun.kt") + public void testTraitFinalFun() throws Exception { + doTest("compiler/testData/loadKotlin/classFun/TraitFinalFun.kt"); + } + + @TestMetadata("TraitOpenFun.kt") + public void testTraitOpenFun() throws Exception { + doTest("compiler/testData/loadKotlin/classFun/TraitOpenFun.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/classObject") + public static class ClassObject extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInClassObject() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/classObject"), "kt", true); + } + + @TestMetadata("ClassObjectDeclaresVal.kt") + public void testClassObjectDeclaresVal() throws Exception { + doTest("compiler/testData/loadKotlin/classObject/ClassObjectDeclaresVal.kt"); + } + + @TestMetadata("ClassObjectDeclaresVar.kt") + public void testClassObjectDeclaresVar() throws Exception { + doTest("compiler/testData/loadKotlin/classObject/ClassObjectDeclaresVar.kt"); + } + + @TestMetadata("ClassObjectExtendsTrait.kt") + public void testClassObjectExtendsTrait() throws Exception { + doTest("compiler/testData/loadKotlin/classObject/ClassObjectExtendsTrait.kt"); + } + + @TestMetadata("ClassObjectExtendsTraitWithTP.kt") + public void testClassObjectExtendsTraitWithTP() throws Exception { + doTest("compiler/testData/loadKotlin/classObject/ClassObjectExtendsTraitWithTP.kt"); + } + + @TestMetadata("SimpleClassObject.kt") + public void testSimpleClassObject() throws Exception { + doTest("compiler/testData/loadKotlin/classObject/SimpleClassObject.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/constructor") + public static class Constructor extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInConstructor() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/constructor"), "kt", true); + } + + @TestMetadata("Constructor0.kt") + public void testConstructor0() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/Constructor0.kt"); + } + + @TestMetadata("Constructor1.kt") + public void testConstructor1() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/Constructor1.kt"); + } + + @TestMetadata("Constructor1WithParamDefaultValue.kt") + public void testConstructor1WithParamDefaultValue() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/Constructor1WithParamDefaultValue.kt"); + } + + @TestMetadata("ConstructorCollectionParameter.kt") + public void testConstructorCollectionParameter() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/ConstructorCollectionParameter.kt"); + } + + @TestMetadata("ConstructorWithTwoTypeParameters.kt") + public void testConstructorWithTwoTypeParameters() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTwoTypeParameters.kt"); + } + + @TestMetadata("ConstructorWithTwoTypeParametersAndOneIntValueParameter.kt") + public void testConstructorWithTwoTypeParametersAndOneIntValueParameter() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTwoTypeParametersAndOneIntValueParameter.kt"); + } + + @TestMetadata("ConstructorWithTwoTypeParametersAndOnePValueParameter.kt") + public void testConstructorWithTwoTypeParametersAndOnePValueParameter() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTwoTypeParametersAndOnePValueParameter.kt"); + } + + @TestMetadata("ConstructorWithTypeParameter.kt") + public void testConstructorWithTypeParameter() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTypeParameter.kt"); + } + + @TestMetadata("ConstructorWithTypeParametersEAndOnePValueParameter.kt") + public void testConstructorWithTypeParametersEAndOnePValueParameter() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTypeParametersEAndOnePValueParameter.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/dataClass") + public static class DataClass extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInDataClass() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/dataClass"), "kt", true); + } + + @TestMetadata("MixedComponents.kt") + public void testMixedComponents() throws Exception { + doTest("compiler/testData/loadKotlin/dataClass/MixedComponents.kt"); + } + + @TestMetadata("NoComponents.kt") + public void testNoComponents() throws Exception { + doTest("compiler/testData/loadKotlin/dataClass/NoComponents.kt"); + } + + @TestMetadata("OneVal.kt") + public void testOneVal() throws Exception { + doTest("compiler/testData/loadKotlin/dataClass/OneVal.kt"); + } + + @TestMetadata("OpenDataClass.kt") + public void testOpenDataClass() throws Exception { + doTest("compiler/testData/loadKotlin/dataClass/OpenDataClass.kt"); + } + + @TestMetadata("OpenPropertyFinalComponent.kt") + public void testOpenPropertyFinalComponent() throws Exception { + doTest("compiler/testData/loadKotlin/dataClass/OpenPropertyFinalComponent.kt"); + } + + @TestMetadata("TwoVals.kt") + public void testTwoVals() throws Exception { + doTest("compiler/testData/loadKotlin/dataClass/TwoVals.kt"); + } + + @TestMetadata("TwoVars.kt") + public void testTwoVars() throws Exception { + doTest("compiler/testData/loadKotlin/dataClass/TwoVars.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/fun") + @InnerTestClasses({Fun.GenericWithTypeVariables.class, Fun.GenericWithoutTypeVariables.class, Fun.NonGeneric.class}) + public static class Fun extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInFun() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/fun"), "kt", true); + } + + @TestMetadata("compiler/testData/loadKotlin/fun/genericWithTypeVariables") + public static class GenericWithTypeVariables extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInGenericWithTypeVariables() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/fun/genericWithTypeVariables"), "kt", true); + } + + @TestMetadata("FunGenericParam.kt") + public void testFunGenericParam() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunGenericParam.kt"); + } + + @TestMetadata("FunInParam.kt") + public void testFunInParam() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunInParam.kt"); + } + + @TestMetadata("FunOutParam.kt") + public void testFunOutParam() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunOutParam.kt"); + } + + @TestMetadata("FunParamParam.kt") + public void testFunParamParam() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamParam.kt"); + } + + @TestMetadata("FunParamParamErased.kt") + public void testFunParamParamErased() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamParamErased.kt"); + } + + @TestMetadata("FunParamReferencesParam.kt") + public void testFunParamReferencesParam() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamReferencesParam.kt"); + } + + @TestMetadata("FunParamReferencesParam2.kt") + public void testFunParamReferencesParam2() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamReferencesParam2.kt"); + } + + @TestMetadata("FunParamTwoUpperBounds.kt") + public void testFunParamTwoUpperBounds() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamTwoUpperBounds.kt"); + } + + @TestMetadata("FunParamUpperClassBound.kt") + public void testFunParamUpperClassBound() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamUpperClassBound.kt"); + } + + @TestMetadata("FunParamUpperClassInterfaceBound.kt") + public void testFunParamUpperClassInterfaceBound() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamUpperClassInterfaceBound.kt"); + } + + @TestMetadata("FunParamUpperInterfaceBound.kt") + public void testFunParamUpperInterfaceBound() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamUpperInterfaceBound.kt"); + } + + @TestMetadata("FunParamUpperInterfaceClassBound.kt") + public void testFunParamUpperInterfaceClassBound() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamUpperInterfaceClassBound.kt"); + } + + @TestMetadata("FunParamVaragParam.kt") + public void testFunParamVaragParam() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunParamVaragParam.kt"); + } + + @TestMetadata("FunTwoTypeParams.kt") + public void testFunTwoTypeParams() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunTwoTypeParams.kt"); + } + + @TestMetadata("FunTwoTypeParams2.kt") + public void testFunTwoTypeParams2() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithTypeVariables/FunTwoTypeParams2.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/fun/genericWithoutTypeVariables") + public static class GenericWithoutTypeVariables extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInGenericWithoutTypeVariables() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/fun/genericWithoutTypeVariables"), "kt", true); + } + + @TestMetadata("FunClassParamNotNull.kt") + public void testFunClassParamNotNull() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithoutTypeVariables/FunClassParamNotNull.kt"); + } + + @TestMetadata("FunClassParamNullable.kt") + public void testFunClassParamNullable() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithoutTypeVariables/FunClassParamNullable.kt"); + } + + @TestMetadata("FunParamNullable.kt") + public void testFunParamNullable() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithoutTypeVariables/FunParamNullable.kt"); + } + + @TestMetadata("ReturnTypeClassParamNotNull.kt") + public void testReturnTypeClassParamNotNull() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithoutTypeVariables/ReturnTypeClassParamNotNull.kt"); + } + + @TestMetadata("ReturnTypeClassParamNullable.kt") + public void testReturnTypeClassParamNullable() throws Exception { + doTest("compiler/testData/loadKotlin/fun/genericWithoutTypeVariables/ReturnTypeClassParamNullable.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/fun/nonGeneric") + public static class NonGeneric extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInNonGeneric() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/fun/nonGeneric"), "kt", true); + } + + @TestMetadata("ClassFun.kt") + public void testClassFun() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ClassFun.kt"); + } + + @TestMetadata("ClassFunGetFoo.kt") + public void testClassFunGetFoo() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ClassFunGetFoo.kt"); + } + + @TestMetadata("ClassFunGetFooSetFoo.kt") + public void testClassFunGetFooSetFoo() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ClassFunGetFooSetFoo.kt"); + } + + @TestMetadata("ClassFunSetFoo.kt") + public void testClassFunSetFoo() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ClassFunSetFoo.kt"); + } + + @TestMetadata("ExtFun.kt") + public void testExtFun() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ExtFun.kt"); + } + + @TestMetadata("ExtFunInClass.kt") + public void testExtFunInClass() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ExtFunInClass.kt"); + } + + @TestMetadata("FunDefaultArg.kt") + public void testFunDefaultArg() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/FunDefaultArg.kt"); + } + + @TestMetadata("FunParamNotNull.kt") + public void testFunParamNotNull() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/FunParamNotNull.kt"); + } + + @TestMetadata("FunVarargInt.kt") + public void testFunVarargInt() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/FunVarargInt.kt"); + } + + @TestMetadata("FunVarargInteger.kt") + public void testFunVarargInteger() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/FunVarargInteger.kt"); + } + + @TestMetadata("ModifierAbstract.kt") + public void testModifierAbstract() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ModifierAbstract.kt"); + } + + @TestMetadata("ModifierOpen.kt") + public void testModifierOpen() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ModifierOpen.kt"); + } + + @TestMetadata("NsFun.kt") + public void testNsFun() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/NsFun.kt"); + } + + @TestMetadata("NsFunGetFoo.kt") + public void testNsFunGetFoo() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/NsFunGetFoo.kt"); + } + + @TestMetadata("ReturnTypeNotNull.kt") + public void testReturnTypeNotNull() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ReturnTypeNotNull.kt"); + } + + @TestMetadata("ReturnTypeNullable.kt") + public void testReturnTypeNullable() throws Exception { + doTest("compiler/testData/loadKotlin/fun/nonGeneric/ReturnTypeNullable.kt"); + } + + } + + public static Test innerSuite() { + TestSuite suite = new TestSuite("Fun"); + suite.addTestSuite(Fun.class); + suite.addTestSuite(GenericWithTypeVariables.class); + suite.addTestSuite(GenericWithoutTypeVariables.class); + suite.addTestSuite(NonGeneric.class); + return suite; + } + } + + @TestMetadata("compiler/testData/loadKotlin/prop") + public static class Prop extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInProp() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/prop"), "kt", true); + } + + @TestMetadata("ClassVal.kt") + public void testClassVal() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ClassVal.kt"); + } + + @TestMetadata("ClassValAbstract.kt") + public void testClassValAbstract() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ClassValAbstract.kt"); + } + + @TestMetadata("ClassVar.kt") + public void testClassVar() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ClassVar.kt"); + } + + @TestMetadata("CollectionSize.kt") + public void testCollectionSize() throws Exception { + doTest("compiler/testData/loadKotlin/prop/CollectionSize.kt"); + } + + @TestMetadata("ExtValClass.kt") + public void testExtValClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValClass.kt"); + } + + @TestMetadata("ExtValInClass.kt") + public void testExtValInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValInClass.kt"); + } + + @TestMetadata("ExtValInt.kt") + public void testExtValInt() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValInt.kt"); + } + + @TestMetadata("ExtValIntCharSequence.kt") + public void testExtValIntCharSequence() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValIntCharSequence.kt"); + } + + @TestMetadata("ExtValIntCharSequenceQ.kt") + public void testExtValIntCharSequenceQ() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValIntCharSequenceQ.kt"); + } + + @TestMetadata("ExtValIntListQOfIntInClass.kt") + public void testExtValIntListQOfIntInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValIntListQOfIntInClass.kt"); + } + + @TestMetadata("ExtValIntTInClass.kt") + public void testExtValIntTInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValIntTInClass.kt"); + } + + @TestMetadata("ExtValIntTQInClass.kt") + public void testExtValIntTQInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValIntTQInClass.kt"); + } + + @TestMetadata("ExtValTIntInClass.kt") + public void testExtValTIntInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtValTIntInClass.kt"); + } + + @TestMetadata("ExtVarClass.kt") + public void testExtVarClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarClass.kt"); + } + + @TestMetadata("ExtVarInClass.kt") + public void testExtVarInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarInClass.kt"); + } + + @TestMetadata("ExtVarInt.kt") + public void testExtVarInt() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarInt.kt"); + } + + @TestMetadata("ExtVarIntTInClass.kt") + public void testExtVarIntTInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarIntTInClass.kt"); + } + + @TestMetadata("ExtVarIntTQInClass.kt") + public void testExtVarIntTQInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarIntTQInClass.kt"); + } + + @TestMetadata("ExtVarMapPQInt.kt") + public void testExtVarMapPQInt() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarMapPQInt.kt"); + } + + @TestMetadata("ExtVarTIntInClass.kt") + public void testExtVarTIntInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarTIntInClass.kt"); + } + + @TestMetadata("ExtVarTQIntInClass.kt") + public void testExtVarTQIntInClass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarTQIntInClass.kt"); + } + + @TestMetadata("ExtVarl.kt") + public void testExtVarl() throws Exception { + doTest("compiler/testData/loadKotlin/prop/ExtVarl.kt"); + } + + @TestMetadata("NsVal.kt") + public void testNsVal() throws Exception { + doTest("compiler/testData/loadKotlin/prop/NsVal.kt"); + } + + @TestMetadata("NsVar.kt") + public void testNsVar() throws Exception { + doTest("compiler/testData/loadKotlin/prop/NsVar.kt"); + } + + @TestMetadata("OverrideClassVal.kt") + public void testOverrideClassVal() throws Exception { + doTest("compiler/testData/loadKotlin/prop/OverrideClassVal.kt"); + } + + @TestMetadata("OverrideTraitVal.kt") + public void testOverrideTraitVal() throws Exception { + doTest("compiler/testData/loadKotlin/prop/OverrideTraitVal.kt"); + } + + @TestMetadata("PropFromSuperclass.kt") + public void testPropFromSuperclass() throws Exception { + doTest("compiler/testData/loadKotlin/prop/PropFromSuperclass.kt"); + } + + @TestMetadata("TraitFinalVar.kt") + public void testTraitFinalVar() throws Exception { + doTest("compiler/testData/loadKotlin/prop/TraitFinalVar.kt"); + } + + @TestMetadata("TraitOpenVal.kt") + public void testTraitOpenVal() throws Exception { + doTest("compiler/testData/loadKotlin/prop/TraitOpenVal.kt"); + } + + @TestMetadata("VarDelegationToTraitImpl.kt") + public void testVarDelegationToTraitImpl() throws Exception { + doTest("compiler/testData/loadKotlin/prop/VarDelegationToTraitImpl.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/type") + public static class Type extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInType() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/type"), "kt", true); + } + + @TestMetadata("Any.kt") + public void testAny() throws Exception { + doTest("compiler/testData/loadKotlin/type/Any.kt"); + } + + @TestMetadata("AnyQ.kt") + public void testAnyQ() throws Exception { + doTest("compiler/testData/loadKotlin/type/AnyQ.kt"); + } + + @TestMetadata("ArrayOfInt.kt") + public void testArrayOfInt() throws Exception { + doTest("compiler/testData/loadKotlin/type/ArrayOfInt.kt"); + } + + @TestMetadata("ArrayOfInteger.kt") + public void testArrayOfInteger() throws Exception { + doTest("compiler/testData/loadKotlin/type/ArrayOfInteger.kt"); + } + + @TestMetadata("ArrayOfString.kt") + public void testArrayOfString() throws Exception { + doTest("compiler/testData/loadKotlin/type/ArrayOfString.kt"); + } + + @TestMetadata("Function1IntString.kt") + public void testFunction1IntString() throws Exception { + doTest("compiler/testData/loadKotlin/type/Function1IntString.kt"); + } + + @TestMetadata("Int.kt") + public void testInt() throws Exception { + doTest("compiler/testData/loadKotlin/type/Int.kt"); + } + + @TestMetadata("IntArray.kt") + public void testIntArray() throws Exception { + doTest("compiler/testData/loadKotlin/type/IntArray.kt"); + } + + @TestMetadata("IntQ.kt") + public void testIntQ() throws Exception { + doTest("compiler/testData/loadKotlin/type/IntQ.kt"); + } + + @TestMetadata("jlInteger.kt") + public void testJlInteger() throws Exception { + doTest("compiler/testData/loadKotlin/type/jlInteger.kt"); + } + + @TestMetadata("jlIntegerQ.kt") + public void testJlIntegerQ() throws Exception { + doTest("compiler/testData/loadKotlin/type/jlIntegerQ.kt"); + } + + @TestMetadata("jlNumber.kt") + public void testJlNumber() throws Exception { + doTest("compiler/testData/loadKotlin/type/jlNumber.kt"); + } + + @TestMetadata("jlObject.kt") + public void testJlObject() throws Exception { + doTest("compiler/testData/loadKotlin/type/jlObject.kt"); + } + + @TestMetadata("jlObjectQ.kt") + public void testJlObjectQ() throws Exception { + doTest("compiler/testData/loadKotlin/type/jlObjectQ.kt"); + } + + @TestMetadata("jlString.kt") + public void testJlString() throws Exception { + doTest("compiler/testData/loadKotlin/type/jlString.kt"); + } + + @TestMetadata("jlStringQ.kt") + public void testJlStringQ() throws Exception { + doTest("compiler/testData/loadKotlin/type/jlStringQ.kt"); + } + + @TestMetadata("ListOfAny.kt") + public void testListOfAny() throws Exception { + doTest("compiler/testData/loadKotlin/type/ListOfAny.kt"); + } + + @TestMetadata("ListOfAnyQ.kt") + public void testListOfAnyQ() throws Exception { + doTest("compiler/testData/loadKotlin/type/ListOfAnyQ.kt"); + } + + @TestMetadata("ListOfStar.kt") + public void testListOfStar() throws Exception { + doTest("compiler/testData/loadKotlin/type/ListOfStar.kt"); + } + + @TestMetadata("ListOfString.kt") + public void testListOfString() throws Exception { + doTest("compiler/testData/loadKotlin/type/ListOfString.kt"); + } + + @TestMetadata("ListOfjlString.kt") + public void testListOfjlString() throws Exception { + doTest("compiler/testData/loadKotlin/type/ListOfjlString.kt"); + } + + @TestMetadata("Nothing.kt") + public void testNothing() throws Exception { + doTest("compiler/testData/loadKotlin/type/Nothing.kt"); + } + + @TestMetadata("NothingQ.kt") + public void testNothingQ() throws Exception { + doTest("compiler/testData/loadKotlin/type/NothingQ.kt"); + } + + @TestMetadata("String.kt") + public void testString() throws Exception { + doTest("compiler/testData/loadKotlin/type/String.kt"); + } + + @TestMetadata("StringQ.kt") + public void testStringQ() throws Exception { + doTest("compiler/testData/loadKotlin/type/StringQ.kt"); + } + + @TestMetadata("Tuple0.kt") + public void testTuple0() throws Exception { + doTest("compiler/testData/loadKotlin/type/Tuple0.kt"); + } + + } + + @TestMetadata("compiler/testData/loadKotlin/visibility") + public static class Visibility extends AbstractLoadCompiledKotlinTest { + public void testAllFilesPresentInVisibility() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest", new File("compiler/testData/loadKotlin/visibility"), "kt", true); + } + + @TestMetadata("InternalAbstractTraitMembersOverridden.kt") + public void testInternalAbstractTraitMembersOverridden() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/InternalAbstractTraitMembersOverridden.kt"); + } + + @TestMetadata("InternalClass.kt") + public void testInternalClass() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/InternalClass.kt"); + } + + @TestMetadata("InternalConstructor.kt") + public void testInternalConstructor() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/InternalConstructor.kt"); + } + + @TestMetadata("InternalTopLevelMembers.kt") + public void testInternalTopLevelMembers() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/InternalTopLevelMembers.kt"); + } + + @TestMetadata("InternalTraitMembers.kt") + public void testInternalTraitMembers() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/InternalTraitMembers.kt"); + } + + @TestMetadata("InternalTraitMembersInherited.kt") + public void testInternalTraitMembersInherited() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/InternalTraitMembersInherited.kt"); + } + + @TestMetadata("PrivateClass.kt") + public void testPrivateClass() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/PrivateClass.kt"); + } + + @TestMetadata("PrivateTopLevelFun.kt") + public void testPrivateTopLevelFun() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/PrivateTopLevelFun.kt"); + } + + @TestMetadata("PrivateTopLevelVal.kt") + public void testPrivateTopLevelVal() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/PrivateTopLevelVal.kt"); + } + + @TestMetadata("TopLevelVarWithPrivateSetter.kt") + public void testTopLevelVarWithPrivateSetter() throws Exception { + doTest("compiler/testData/loadKotlin/visibility/TopLevelVarWithPrivateSetter.kt"); + } + + } + + public static Test suite() { + TestSuite suite = new TestSuite("LoadCompiledKotlinTestGenerated"); + suite.addTestSuite(LoadCompiledKotlinTestGenerated.class); + suite.addTestSuite(Class.class); + suite.addTestSuite(ClassFun.class); + suite.addTestSuite(ClassObject.class); + suite.addTestSuite(Constructor.class); + suite.addTestSuite(DataClass.class); + suite.addTest(Fun.innerSuite()); + suite.addTestSuite(Prop.class); + suite.addTestSuite(Type.class); + suite.addTestSuite(Visibility.class); + return suite; + } +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java index bcfff22f01a..aea4a176c9d 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java @@ -255,11 +255,6 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTest("compiler/testData/loadJava/kotlinSignature/MethodWithMappedClasses.java"); } - @TestMetadata("MethodWithTupleType.java") - public void testMethodWithTupleType() throws Exception { - doTest("compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.java"); - } - @TestMetadata("MethodWithTypeParameters.java") public void testMethodWithTypeParameters() throws Exception { doTest("compiler/testData/loadJava/kotlinSignature/MethodWithTypeParameters.java"); diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadKotlinCustomTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadKotlinCustomTest.java index a0d5d10c8a6..d94393bd4fa 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadKotlinCustomTest.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadKotlinCustomTest.java @@ -34,7 +34,7 @@ import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaces; * @author Pavel Talanov */ /* - * This test should be implemented via LoadCompiledKotlinTest. + * This test should be implemented via AbstractLoadCompiledKotlinTest. * Atm it's not possible due to enums being loaded differently from binaries (in contrast to from sources). */ public final class LoadKotlinCustomTest extends TestCaseWithTmpdir { @@ -82,6 +82,14 @@ public final class LoadKotlinCustomTest extends TestCaseWithTmpdir { } public void testEnumVisibility() throws Exception { - doTest(PATH + "/enum"); + doTest(ENUM_DIR); + } + + public void testInnerEnum() throws Exception { + doTest(ENUM_DIR); + } + + public void testInnerEnumExistingClassObject() throws Exception { + doTest(ENUM_DIR); } } diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java index 7f912f53e60..2c56667888d 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java @@ -1130,11 +1130,6 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/MethodWithMappedClasses.kt"); } - @TestMetadata("MethodWithTupleType.kt") - public void testMethodWithTupleType() throws Exception { - doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/MethodWithTupleType.kt"); - } - @TestMetadata("MethodWithTypeParameters.kt") public void testMethodWithTypeParameters() throws Exception { doTestSinglePackage("compiler/testData/loadJava/kotlinSignature/MethodWithTypeParameters.kt"); @@ -1349,6 +1344,16 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest", new File("compiler/testData/lazyResolve/namespaceComparator"), "kt", true); } + @TestMetadata("classObjectAnnotation.kt") + public void testClassObjectAnnotation() throws Exception { + doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/classObjectAnnotation.kt"); + } + + @TestMetadata("classObjectHeader.kt") + public void testClassObjectHeader() throws Exception { + doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/classObjectHeader.kt"); + } + @TestMetadata("enum.kt") public void testEnum() throws Exception { doTestSinglePackage("compiler/testData/lazyResolve/namespaceComparator/enum.kt"); diff --git a/compiler/tests/org/jetbrains/jet/runtime/JetNpeTest.java b/compiler/tests/org/jetbrains/jet/runtime/JetNpeTest.java index 60aa4b3ef12..7ca461f2c30 100644 --- a/compiler/tests/org/jetbrains/jet/runtime/JetNpeTest.java +++ b/compiler/tests/org/jetbrains/jet/runtime/JetNpeTest.java @@ -43,12 +43,12 @@ public class JetNpeTest extends CodegenTestCase { } public void testNotNull () throws Exception { - loadText("fun box() = if(10.sure() == 10) \"OK\" else \"fail\""); + loadText("fun box() = if(10!! == 10) \"OK\" else \"fail\""); blackBox(); } public void testNull () throws Exception { - loadText("fun box() = if((null : Int?).sure() == 10) \"OK\" else \"fail\""); + loadText("fun box() = if((null : Int?)!! == 10) \"OK\" else \"fail\""); // System.out.println(generateToText()); Method box = generateFunction("box"); assertThrows(box, NullPointerException.class, null); diff --git a/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java b/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java index 806e3d2fb7a..1d0868a805f 100644 --- a/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java +++ b/compiler/tests/org/jetbrains/jet/test/util/NamespaceComparator.java @@ -23,6 +23,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.codegen.PropertyCodegen; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; @@ -173,7 +174,9 @@ public class NamespaceComparator { ClassifierDescriptor cb = nsb.getMemberScope().getClassifier(name); deferred.assertTrue("Classifier not found in " + nsa + ": " + name, ca != null); deferred.assertTrue("Classifier not found in " + nsb + ": " + name, cb != null); - compareClassifiers(ca, cb, sb); + if (ca != null && cb != null) { + compareClassifiers(ca, cb, sb); + } } for (Name name : sorted(objectNames)) { @@ -181,7 +184,9 @@ public class NamespaceComparator { ClassifierDescriptor cb = nsb.getMemberScope().getObjectDescriptor(name); deferred.assertTrue("Object not found in " + nsa + ": " + name, ca != null); deferred.assertTrue("Object not found in " + nsb + ": " + name, cb != null); - compareClassifiers(ca, cb, sb); + if (ca != null && cb != null) { + compareClassifiers(ca, cb, sb); + } } for (Name name : sorted(propertyNames)) { diff --git a/examples/example-vfs/src/FileSystem.kt b/examples/example-vfs/src/FileSystem.kt index f51edd33b74..1f27aaadca9 100644 --- a/examples/example-vfs/src/FileSystem.kt +++ b/examples/example-vfs/src/FileSystem.kt @@ -36,7 +36,7 @@ public object FileSystem { */ public fun getFileByIoFile(ioFile : File) : VirtualFile { FileSystem.assertCanRead() - return PhysicalVirtualFile(ioFile.getAbsolutePath().sure().toSystemIndependentPath()) + return PhysicalVirtualFile(ioFile.getAbsolutePath()!!.toSystemIndependentPath()) } /** diff --git a/examples/example-vfs/src/RefreshQueue.kt b/examples/example-vfs/src/RefreshQueue.kt index 4fe52a47a3c..d757d285c89 100644 --- a/examples/example-vfs/src/RefreshQueue.kt +++ b/examples/example-vfs/src/RefreshQueue.kt @@ -95,7 +95,7 @@ internal object RefreshQueue { /* Deletes file from file system recursively, notifying listeners */ private fun deleteRecursively(file : VirtualFile) { val fileInfoMaybe : VirtualFileInfo? = FileSystem.fileToInfo[file.path] - val fileInfo = fileInfoMaybe.sure() + val fileInfo = fileInfoMaybe!! fileInfo.children.forEach{ deleteRecursively(it) } FileSystem.notifyEventHappened(VirtualFileDeletedEvent(file)) FileSystem.fileToInfo.remove(file) diff --git a/examples/example-vfs/src/VirtualFile.kt b/examples/example-vfs/src/VirtualFile.kt index 3088cd81dc4..dded4e1d2ef 100644 --- a/examples/example-vfs/src/VirtualFile.kt +++ b/examples/example-vfs/src/VirtualFile.kt @@ -94,7 +94,7 @@ public class PhysicalVirtualFile(path : String) : VirtualFile(path) { get() { FileSystem.assertCanRead() return (ioFile.listFiles() ?: array()). - map{ FileSystem.getFileByIoFile(it.sure()) }?.toList() + map{ FileSystem.getFileByIoFile(it!!) }?.toList() } override public fun openInputStream(): InputStream { @@ -106,7 +106,7 @@ public class PhysicalVirtualFile(path : String) : VirtualFile(path) { } } -private val OS_SEPARATOR = java.io.File.separator.sure() +private val OS_SEPARATOR = java.io.File.separator!! private val VFS_SEPARATOR = "/" private fun String.toSystemDependentPath() : String { diff --git a/examples/maven/mixed-code-hello-world/src/main/java/hello/KotlinHello.kt b/examples/maven/mixed-code-hello-world/src/main/java/hello/KotlinHello.kt index 27a00b5ad1b..2c5eac28b49 100644 --- a/examples/maven/mixed-code-hello-world/src/main/java/hello/KotlinHello.kt +++ b/examples/maven/mixed-code-hello-world/src/main/java/hello/KotlinHello.kt @@ -3,5 +3,5 @@ package hello public val KotlinHelloString : String = "Hello from Kotlin!" public fun getHelloStringFromJava() : String { - return JavaHello.JavaHelloString.sure(); + return JavaHello.JavaHelloString!!; } diff --git a/examples/src/actors/src/Actors.kt b/examples/src/actors/src/Actors.kt index d2327791fbf..b7c5ad69f3a 100644 --- a/examples/src/actors/src/Actors.kt +++ b/examples/src/actors/src/Actors.kt @@ -181,4 +181,4 @@ fun Executor.actor(handler: (Any)->Any?) : Actor = object: Actor(this) { } } -fun singleThreadActor(handler: (Any)->Any?) : Actor = Executors.newSingleThreadExecutor().sure().actor(handler) +fun singleThreadActor(handler: (Any)->Any?) : Actor = Executors.newSingleThreadExecutor()!!.actor(handler) diff --git a/examples/src/actors/src/Main.kt b/examples/src/actors/src/Main.kt index 04def387d69..44ae975a68f 100644 --- a/examples/src/actors/src/Main.kt +++ b/examples/src/actors/src/Main.kt @@ -15,7 +15,7 @@ fun main(args: Array) { println("Stock server started") - val executor = Executors.newFixedThreadPool(4*Runtime.getRuntime().sure().availableProcessors()).sure() + val executor = Executors.newFixedThreadPool(4*Runtime.getRuntime()!!.availableProcessors())!! for(i in 0..numberOfClients) { val client = executor.actor{ message -> diff --git a/examples/src/actors/src/StatCalculator.kt b/examples/src/actors/src/StatCalculator.kt index e0871d7dd3c..ade9ede32f7 100644 --- a/examples/src/actors/src/StatCalculator.kt +++ b/examples/src/actors/src/StatCalculator.kt @@ -5,7 +5,7 @@ import org.jetbrains.kotlin.examples.actors.Actor import java.util.concurrent.Executors import java.util.LinkedList -class StatCalculator() : Actor(Executors.newSingleThreadExecutor().sure()) { +class StatCalculator() : Actor(Executors.newSingleThreadExecutor()!!) { val list = LinkedList () var average = 0.toLong() var sum = 0.toLong() diff --git a/examples/src/actors/src/StockServer.kt b/examples/src/actors/src/StockServer.kt index 58ba36aefed..50c7e8d0098 100644 --- a/examples/src/actors/src/StockServer.kt +++ b/examples/src/actors/src/StockServer.kt @@ -7,7 +7,7 @@ import java.util.concurrent.Executors import java.util.HashMap import java.util.HashSet -class StockServer(val numberOfShards : Int) : Actor(Executors.newFixedThreadPool(numberOfShards+1).sure()) { +class StockServer(val numberOfShards : Int) : Actor(Executors.newFixedThreadPool(numberOfShards+1)!!) { private val stockToServer = HashMap () private val statCalculator = StatCalculator() diff --git a/examples/src/benchmarks/src/lockperf/LockPerf.kt b/examples/src/benchmarks/src/lockperf/LockPerf.kt index 862e04f253d..08b6a29d502 100644 --- a/examples/src/benchmarks/src/lockperf/LockPerf.kt +++ b/examples/src/benchmarks/src/lockperf/LockPerf.kt @@ -32,7 +32,7 @@ fun Int.latch(op: CountDownLatch.() -> T) : T { } fun main(args: Array) { - val processors = Runtime.getRuntime().sure().availableProcessors() + val processors = Runtime.getRuntime()!!.availableProcessors() var threadNum = 1 while(threadNum <= 1024) { val counter = AtomicInteger() diff --git a/examples/src/benchmarks/src/spectralnorm/SpectralNorm.kt b/examples/src/benchmarks/src/spectralnorm/SpectralNorm.kt index 2be52f27411..2e7aed8727d 100644 --- a/examples/src/benchmarks/src/spectralnorm/SpectralNorm.kt +++ b/examples/src/benchmarks/src/spectralnorm/SpectralNorm.kt @@ -26,7 +26,7 @@ fun spectralnormGame(n: Int) : Double { u[i] = 1.0 } - val nthread = Runtime.getRuntime ().sure().availableProcessors (); + val nthread = Runtime.getRuntime ()!!.availableProcessors (); barrier = CyclicBarrier (nthread); val chunk = n / nthread diff --git a/examples/src/benchmarks/src/threadring/ThreadRing.kt b/examples/src/benchmarks/src/threadring/ThreadRing.kt index 8a722e70441..98deb6a72c6 100644 --- a/examples/src/benchmarks/src/threadring/ThreadRing.kt +++ b/examples/src/benchmarks/src/threadring/ThreadRing.kt @@ -43,7 +43,7 @@ fun main(args: Array) { class TokenMessage(val nodeId : Int, value: Int, val isStop: Boolean) : AtomicInteger(value) class ThreadRing(val N: Int) { - val executor = Executors.newFixedThreadPool(MAX_THREADS).sure() + val executor = Executors.newFixedThreadPool(MAX_THREADS)!! val nodes : Array = Array(MAX_NODES+1, { (it : Int) -> Node(it+1) }); @@ -84,17 +84,17 @@ class ThreadRing(val N: Int) { cdl.countDown() } else { m.set(nextValue) - nextNode.sure().sendMessage(m) + nextNode!!.sendMessage(m) } isActive = false } else { if (m.get() == N) { System.out?.println(nodeId); - nextNode.sure().sendMessage(TokenMessage(nodeId, 0, true)); + nextNode!!.sendMessage(TokenMessage(nodeId, 0, true)); } else { m.incrementAndGet() - nextNode.sure().sendMessage(m); + nextNode!!.sendMessage(m); } } } diff --git a/examples/src/guice-kotlin/src/GuiceDsl.kt b/examples/src/guice-kotlin/src/GuiceDsl.kt index 1e285e275c3..1811296f77c 100644 --- a/examples/src/guice-kotlin/src/GuiceDsl.kt +++ b/examples/src/guice-kotlin/src/GuiceDsl.kt @@ -10,7 +10,7 @@ class GuiceInjectorBuilder() { fun module (config: Binder.()->Any?) : Module = object: Module { override fun configure(binder: Binder?) { - binder.sure().config() + binder!!.config() } } @@ -22,29 +22,29 @@ class GuiceInjectorBuilder() { fun injector(config: GuiceInjectorBuilder.() -> Any?) : Injector { val collector = GuiceInjectorBuilder() collector.config() - return Guice.createInjector(collector.collected).sure() + return Guice.createInjector(collector.collected)!! } } } -inline fun Binder.bind() = bind(javaClass()).sure() +inline fun Binder.bind() = bind(javaClass())!! inline fun ScopedBindingBuilder.asSingleton() = `in`(javaClass()) -inline fun AnnotatedBindingBuilder.to() = to(javaClass()).sure() +inline fun AnnotatedBindingBuilder.to() = to(javaClass())!! -inline fun AnnotatedBindingBuilder.toSingleton() = to(javaClass()).sure().asSingleton() +inline fun AnnotatedBindingBuilder.toSingleton() = to(javaClass())!!.asSingleton() -inline fun Injector.getInstance() = getInstance(javaClass()).sure() +inline fun Injector.getInstance() = getInstance(javaClass())!! -inline fun Injector.getProvider() = getProvider(javaClass()).sure() +inline fun Injector.getProvider() = getProvider(javaClass())!! inline fun > LinkedBindingBuilder.toProvider() = toProvider(javaClass()) fun AnnotatedBindingBuilder.toProvider(provider: Injector.()->T) = toProvider(object: Provider { [Inject] val injector : Injector? = null - override fun get(): T = injector.sure().provider() -}).sure() + override fun get(): T = injector!!.provider() +})!! fun AnnotatedBindingBuilder.toSingletonProvider(provider: Injector.()->T) = toProvider(provider).asSingleton() diff --git a/examples/src/guice-kotlin/src/GuiceExample.kt b/examples/src/guice-kotlin/src/GuiceExample.kt index 90307c1d4df..5c9f4de57bf 100644 --- a/examples/src/guice-kotlin/src/GuiceExample.kt +++ b/examples/src/guice-kotlin/src/GuiceExample.kt @@ -17,7 +17,7 @@ class StdoutLoggingService() : LoggingService(){ class JdkLoggingService () : LoggingService() { protected [Inject] var jdkLogger: Logger? = null - override fun info(message: String) = jdkLogger.sure().info(message) + override fun info(message: String) = jdkLogger!!.info(message) } abstract class AppService(protected val mode: String) { diff --git a/examples/src/luhny/solution.kt b/examples/src/luhny/solution.kt index 230530551c9..ceb0061f3c8 100644 --- a/examples/src/luhny/solution.kt +++ b/examples/src/luhny/solution.kt @@ -13,7 +13,7 @@ fun applyMask(a : String) : String { } luhny.processEnd() - return luhny.output.toString().sure() + return luhny.output.toString()!! } class Luhny() { diff --git a/examples/src/luhny/test.kt b/examples/src/luhny/test.kt index a5261ed00ab..b4ca55f9721 100644 --- a/examples/src/luhny/test.kt +++ b/examples/src/luhny/test.kt @@ -147,7 +147,7 @@ fun computeLast(allButLast : String) : Char { return if (remainder == 0) '0' else ('0' + (10 - remainder)).toChar() } -fun computeLast(allButLast : CharSequence) : Char = computeLast(allButLast.toString().sure()) +fun computeLast(allButLast : CharSequence) : Char = computeLast(allButLast.toString()!!) fun setRandomDigits(builder : StringBuilder, start : Int, end : Int) { for (i in start..end-1) @@ -161,7 +161,7 @@ fun nonDigits() : String { val nonDigits = StringBuilder() for (i in 0..999) nonDigits.append((random.nextInt(68) + ':').toChar()) - return nonDigits.toString().sure() + return nonDigits.toString()!! } fun testFormatted(delimiter : Char) { @@ -179,7 +179,7 @@ fun formattedMask(delimiter : Char) : String { mask.append(delimiter) } - return mask.toString().sure() + return mask.toString()!! } /** Computes a random, valid card # with the specified number of digits. */ @@ -187,7 +187,7 @@ fun randomNumber(digits : Int) : String { val number = StringBuilder(digits) number.setLength(digits) setRandomDigits(number, 0, digits - 1) - number.setCharAt(digits - 1, computeLast(number.subSequence(0, digits - 1).sure())) + number.setCharAt(digits - 1, computeLast(number.subSequence(0, digits - 1)!!)) return number.toString() ?: "" } @@ -196,9 +196,9 @@ fun nestedNumber() : String { val number = StringBuilder(16) number.setLength(16); setRandomDigits(number, 0, 14); - number.setCharAt(14, computeLast(number.subSequence(1, 14).sure())) - number.setCharAt(15, computeLast(number.subSequence(0, 15).sure())) - return number.toString().sure() + number.setCharAt(14, computeLast(number.subSequence(1, 14)!!)) + number.setCharAt(15, computeLast(number.subSequence(0, 15)!!)) + return number.toString()!! } /** Creates a sequence of mask characters with the given length. */ @@ -211,7 +211,7 @@ fun repeatingSequence(c : Char, length : Int) : String { val sb = StringBuilder() for (i in 1..length) sb.append(c) - return sb.toString().sure() + return sb.toString()!! } class DigitSet() { @@ -225,10 +225,10 @@ class DigitSet() { fun testOverlappingMatches() { val output = StringBuilder(randomNumber(MAX_LENGTH)) for (i in 0..1000 - MAX_LENGTH - 1) - output.append(computeLast(output.subSequence(i + 1, i + MAX_LENGTH).sure())) + output.append(computeLast(output.subSequence(i + 1, i + MAX_LENGTH)!!)) test("long sequence of overlapping, valid #s") - .send(output.toString().sure()) + .send(output.toString()!!) .expect(mask(output.length())); } @@ -245,7 +245,7 @@ fun nonMatchingSequence(length : Int) : String { val start = lastIndex - (subLength - 1); if (start < 0) break; - excluded.add(computeLast(builder.subSequence(start, lastIndex).sure())); + excluded.add(computeLast(builder.subSequence(start, lastIndex)!!)); } // Find a digit that doesn't result in a valid card #. @@ -256,5 +256,5 @@ fun nonMatchingSequence(length : Int) : String { builder.append(digit); } - return builder.toString().sure() + return builder.toString()!! } diff --git a/examples/src/nettyserver/src/Main.kt b/examples/src/nettyserver/src/Main.kt index b0ca453fcd5..3d104f90524 100644 --- a/examples/src/nettyserver/src/Main.kt +++ b/examples/src/nettyserver/src/Main.kt @@ -23,7 +23,7 @@ fun main(args : Array) { response.content = "Hello, World!" } POST { - response.content = "You said: ${request.getContent().sure().toString(Charset.defaultCharset())}" + response.content = "You said: ${request.getContent()!!.toString(Charset.defaultCharset())}" } } diff --git a/examples/src/nettyserver/src/Netty.kt b/examples/src/nettyserver/src/Netty.kt index 04d5ac3bb0f..eacc2ca9d7e 100644 --- a/examples/src/nettyserver/src/Netty.kt +++ b/examples/src/nettyserver/src/Netty.kt @@ -35,7 +35,7 @@ fun HttpResponse.set(header: String, value: Any?) : Unit { var HttpResponse.content : Any? get() = throw UnsupportedOperationException() set(c: Any?) { - val buffer = ChannelBuffers.copiedBuffer(c.toString(), CharsetUtil.UTF_8).sure() + val buffer = ChannelBuffers.copiedBuffer(c.toString(), CharsetUtil.UTF_8)!! setContent(buffer) setHeader("Content-Length", buffer.readableBytes()) } diff --git a/examples/src/nettyserver/src/Request.kt b/examples/src/nettyserver/src/Request.kt index 865be4455ef..e1a80f8843b 100644 --- a/examples/src/nettyserver/src/Request.kt +++ b/examples/src/nettyserver/src/Request.kt @@ -21,8 +21,8 @@ import org.jboss.netty.channel.ChannelFuture class RequestResponse(e: MessageEvent) { val request = e.getMessage() as HttpRequest val response = DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.FORBIDDEN) - val channel = e.getChannel().sure() - val path = request.getUri().sure().sanitizeUri() + val channel = e.getChannel()!! + val path = request.getUri()!!.sanitizeUri() fun setError(status: HttpResponseStatus?) { response.setStatus(status) @@ -43,8 +43,8 @@ class RequestResponse(e: MessageEvent) { } fun write() = - if(response.getStatus().sure().getCode() >= 400) { - channel.write(response).sure().addListener(ChannelFutureListener.CLOSE) + if(response.getStatus()!!.getCode() >= 400) { + channel.write(response)!!.addListener(ChannelFutureListener.CLOSE) } else { channel.write(response) diff --git a/examples/src/nettyserver/src/RestProcessor.kt b/examples/src/nettyserver/src/RestProcessor.kt index a2ff84c76d6..d9a401a9873 100644 --- a/examples/src/nettyserver/src/RestProcessor.kt +++ b/examples/src/nettyserver/src/RestProcessor.kt @@ -21,11 +21,11 @@ class RestProcessor(val prefix: String, val builder: RestBuilder) : Processor { if(request.path.startsWith(prefix)) { if(request.request.getMethod() == HttpMethod.GET && builder.onGet != null) { request.ok() - request.(builder.onGet.sure())() + request.(builder.onGet!!)() } else if(request.request.getMethod() == HttpMethod.POST && builder.onPost != null) { request.ok() - request.(builder.onPost.sure())() + request.(builder.onPost!!)() } else { request.setError(HttpResponseStatus.METHOD_NOT_ALLOWED) diff --git a/examples/src/swing/SwingBuilder.kt b/examples/src/swing/SwingBuilder.kt index af437b7bf9a..75e213fa5a6 100644 --- a/examples/src/swing/SwingBuilder.kt +++ b/examples/src/swing/SwingBuilder.kt @@ -52,26 +52,26 @@ fun JButton(text : String, action : (ActionEvent) -> Unit) : JButton { val result = JButton(text) result.addActionListener(object : ActionListener { override fun actionPerformed(e: ActionEvent?) { - action(e.sure()) + action(e!!) } }) return result } var JFrame.title : String - get() = getTitle().sure() + get() = getTitle()!! set(t) {setTitle(t)} var JFrame.size : #(Int, Int) - get() = #(getSize().sure().getWidth().toInt(), getSize().sure().getHeight().toInt()) + get() = #(getSize()!!.getWidth().toInt(), getSize()!!.getHeight().toInt()) set(dim) {setSize(Dimension(dim._1, dim._2))} var JFrame.height : Int - get() = getSize().sure().getHeight().toInt() + get() = getSize()!!.getHeight().toInt() set(h) {setSize(width, h)} var JFrame.width : Int - get() = getSize().sure().getWidth().toInt() + get() = getSize()!!.getWidth().toInt() set(w) {setSize(height, w)} var JFrame.defaultCloseOperation : Int diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index ea3bdc60522..998dd072756 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -6,7 +6,7 @@ @snapshot@ JetBrains Inc. - + JUnit @@ -144,6 +144,8 @@ + + @@ -223,7 +225,6 @@ - diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index 8bdad14cc43..55e6b2a6951 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -92,3 +92,5 @@ options.jet.attribute.descriptor.constructor.call=Constructor call options.jet.attribute.descriptor.auto.casted=Smart-cast value options.jet.attribute.descriptor.label=Label change.to.function.invocation=Change to function invocation +migrate.tuple=Migrate tuples in project\: e.g., \#(,) and \#(,,) will be replaced by Pair and Triple +migrate.sure=Replace sure() calls by !! in project diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java b/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java index 4860f777225..5e754fb0d0f 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java +++ b/idea/src/org/jetbrains/jet/plugin/completion/JetCompletionContributor.java @@ -264,8 +264,18 @@ public class JetCompletionContributor extends CompletionContributor { if (element.getParent() instanceof JetSimpleNameExpression) { JetSimpleNameExpression nameExpression = (JetSimpleNameExpression)element.getParent(); - // Top level completion should be executed for simple which is not in qualified expression - return (PsiTreeUtil.getParentOfType(nameExpression, JetQualifiedExpression.class) == null); + // Top level completion should be executed for simple name which is not in qualified expression + if (PsiTreeUtil.getParentOfType(nameExpression, JetQualifiedExpression.class) != null) { + return false; + } + + // Don't call top level completion in qualified named position of user type + PsiElement parent = nameExpression.getParent(); + if (parent instanceof JetUserType && ((JetUserType) parent).getQualifier() != null) { + return false; + } + + return true; } } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.java b/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.java index 0f2a87b1075..e8332db914b 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.java +++ b/idea/src/org/jetbrains/jet/plugin/completion/JetKeywordCompletionContributor.java @@ -221,7 +221,7 @@ public class JetKeywordCompletionContributor extends CompletionContributor { @Override public boolean prefixMatches(@NotNull String name) { - return StringUtil.startsWithIgnoreCase(name, getPrefix()); + return StringUtil.startsWith(name, getPrefix()); } @NotNull diff --git a/idea/src/org/jetbrains/jet/plugin/completion/JetReferenceCharFilter.java b/idea/src/org/jetbrains/jet/plugin/completion/JetReferenceCharFilter.java new file mode 100644 index 00000000000..41e0df2599f --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/completion/JetReferenceCharFilter.java @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.completion; + +import com.intellij.codeInsight.lookup.CharFilter; +import com.intellij.codeInsight.lookup.Lookup; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.psi.JetFile; + +public class JetReferenceCharFilter extends CharFilter { + @Override + @Nullable + public Result acceptChar(char c, int prefixLength, Lookup lookup) { + final PsiFile psiFile = lookup.getPsiFile(); + if (!(psiFile instanceof JetFile)) { + return null; + } + + if (c == '.' && prefixLength == 0 && !lookup.isSelectionTouched()) { + int caret = lookup.getEditor().getCaretModel().getOffset(); + if (caret > 0 && lookup.getEditor().getDocument().getCharsSequence().charAt(caret - 1) == '.') { + return Result.HIDE_LOOKUP; + } + } + + return null; + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java index 3365b6041ba..cf99dbb4a29 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java @@ -26,14 +26,11 @@ import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.JetNodeTypes; -import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.plugin.JetLanguage; import java.util.*; -import static org.jetbrains.jet.JetNodeTypes.BLOCK; -import static org.jetbrains.jet.JetNodeTypes.FUNCTION_LITERAL; +import static org.jetbrains.jet.JetNodeTypes.*; import static org.jetbrains.jet.lexer.JetTokens.*; /** @@ -48,9 +45,9 @@ public class JetBlock extends AbstractBlock { private List mySubBlocks; private static final TokenSet CODE_BLOCKS = TokenSet.create( - JetNodeTypes.BLOCK, - JetNodeTypes.CLASS_BODY, - JetNodeTypes.FUNCTION_LITERAL); + BLOCK, + CLASS_BODY, + FUNCTION_LITERAL); // private static final List @@ -105,7 +102,7 @@ public class JetBlock extends AbstractBlock { Wrap wrap = null; // Affects to spaces around operators... - if (child.getElementType() == JetNodeTypes.OPERATION_REFERENCE) { + if (child.getElementType() == OPERATION_REFERENCE) { ASTNode operationNode = child.getFirstChildNode(); if (operationNode != null) { return new JetBlock(operationNode, childAlignment, Indent.getNoneIndent(), wrap, mySettings, mySpacingBuilder); @@ -116,7 +113,7 @@ public class JetBlock extends AbstractBlock { } private static Indent indentIfNotBrace(@NotNull ASTNode child) { - return child.getElementType() == JetTokens.RBRACE || child.getElementType() == JetTokens.LBRACE + return child.getElementType() == RBRACE || child.getElementType() == LBRACE ? Indent.getNoneIndent() : Indent.getNormalIndent(); } @@ -166,6 +163,14 @@ public class JetBlock extends AbstractBlock { } if (parentType == FUNCTION_LITERAL && child1Type == LBRACE) { + if (child2Type == VALUE_PARAMETER_LIST) { + ASTNode firstParamListNode = ((ASTBlock) child2).getNode().getFirstChildNode(); + if (firstParamListNode != null && firstParamListNode.getElementType() == LPAR) { + // Don't put space for situation {(a: Int) -> a } + return Spacing.createSpacing(0, 0, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); + } + } + return Spacing.createSpacing(spacesInSimpleMethod, spacesInSimpleMethod, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); } @@ -178,22 +183,22 @@ public class JetBlock extends AbstractBlock { public ChildAttributes getChildAttributes(int newChildIndex) { final IElementType type = getNode().getElementType(); if (CODE_BLOCKS.contains(type) || - type == JetNodeTypes.WHEN || - type == JetNodeTypes.IF || - type == JetNodeTypes.FOR || - type == JetNodeTypes.WHILE || - type == JetNodeTypes.DO_WHILE) { + type == WHEN || + type == IF || + type == FOR || + type == WHILE || + type == DO_WHILE) { return new ChildAttributes(Indent.getNormalIndent(), null); } - else if (type == JetNodeTypes.TRY) { + else if (type == TRY) { // In try - try BLOCK catch BLOCK finally BLOCK return new ChildAttributes(Indent.getNoneIndent(), null); } - else if (type == JetNodeTypes.DOT_QUALIFIED_EXPRESSION) { + else if (type == DOT_QUALIFIED_EXPRESSION) { return new ChildAttributes(Indent.getContinuationWithoutFirstIndent(), null); } - else if (type == JetNodeTypes.VALUE_PARAMETER_LIST || type == JetNodeTypes.VALUE_ARGUMENT_LIST) { + else if (type == VALUE_PARAMETER_LIST || type == VALUE_ARGUMENT_LIST) { // Child index 1 - cursor is after ( - parameter alignment should be recreated // Child index 0 - before expression - know nothing about it if (newChildIndex != 1 && newChildIndex != 0 && newChildIndex < getSubBlocks().size()) { @@ -224,15 +229,15 @@ public class JetBlock extends AbstractBlock { // Redefine list of strategies for some special elements IElementType parentType = myNode.getElementType(); - if (parentType == JetNodeTypes.VALUE_PARAMETER_LIST) { + if (parentType == VALUE_PARAMETER_LIST) { strategy = getAlignmentForChildInParenthesis( - jetCommonSettings.ALIGN_MULTILINE_PARAMETERS, JetNodeTypes.VALUE_PARAMETER, JetTokens.COMMA, - jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, JetTokens.LPAR, JetTokens.RPAR); + jetCommonSettings.ALIGN_MULTILINE_PARAMETERS, VALUE_PARAMETER, COMMA, + jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR); } - else if (parentType == JetNodeTypes.VALUE_ARGUMENT_LIST) { + else if (parentType == VALUE_ARGUMENT_LIST) { strategy = getAlignmentForChildInParenthesis( - jetCommonSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS, JetNodeTypes.VALUE_ARGUMENT, JetTokens.COMMA, - jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, JetTokens.LPAR, JetTokens.RPAR); + jetCommonSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS, VALUE_ARGUMENT, COMMA, + jetCommonSettings.ALIGN_MULTILINE_METHOD_BRACKETS, LPAR, RPAR); } // Construct information about children alignment @@ -289,36 +294,37 @@ public class JetBlock extends AbstractBlock { static ASTIndentStrategy[] INDENT_RULES = new ASTIndentStrategy[] { ASTIndentStrategy.forNode("No indent for braces in blocks") - .in(JetNodeTypes.BLOCK, JetNodeTypes.CLASS_BODY, JetNodeTypes.FUNCTION_LITERAL) - .forType(JetTokens.RBRACE, JetTokens.LBRACE) + .in(BLOCK, CLASS_BODY, FUNCTION_LITERAL) + .forType(RBRACE, LBRACE) .set(Indent.getNoneIndent()), ASTIndentStrategy.forNode("Indent for block content") - .in(JetNodeTypes.BLOCK, JetNodeTypes.CLASS_BODY, JetNodeTypes.FUNCTION_LITERAL) - .notForType(JetTokens.RBRACE, JetTokens.LBRACE, JetNodeTypes.BLOCK) + .in(BLOCK, CLASS_BODY, FUNCTION_LITERAL) + .notForType(RBRACE, LBRACE, BLOCK) .set(Indent.getNormalIndent()), ASTIndentStrategy.forNode("Indent for property accessors") - .in(JetNodeTypes.PROPERTY) - .forType(JetNodeTypes.PROPERTY_ACCESSOR) + .in(PROPERTY) + .forType(PROPERTY_ACCESSOR) .set(Indent.getNormalIndent()), ASTIndentStrategy.forNode("For a single statement if 'for'") - .in(JetNodeTypes.BODY) - .notForType(JetNodeTypes.BLOCK) + .in(BODY) + .notForType(BLOCK) .set(Indent.getNormalIndent()), ASTIndentStrategy.forNode("For the entry in when") - .forType(JetNodeTypes.WHEN_ENTRY) + .forType(WHEN_ENTRY) .set(Indent.getNormalIndent()), ASTIndentStrategy.forNode("For single statement in THEN and ELSE") - .in(JetNodeTypes.THEN, JetNodeTypes.ELSE) - .notForType(JetNodeTypes.BLOCK) + .in(THEN, ELSE) + .notForType(BLOCK) .set(Indent.getNormalIndent()), ASTIndentStrategy.forNode("Indent for parts") - .in(JetNodeTypes.PROPERTY, JetNodeTypes.FUN) + .in(PROPERTY, FUN) + .notForType(BLOCK) .set(Indent.getContinuationWithoutFirstIndent()), }; @@ -336,14 +342,14 @@ public class JetBlock extends AbstractBlock { // TODO: Try to rewrite other rules to declarative style - if (childParent != null && childParent.getElementType() == JetNodeTypes.WHEN_ENTRY) { + if (childParent != null && childParent.getElementType() == WHEN_ENTRY) { ASTNode prev = getPrevWithoutWhitespace(child); if (prev != null && prev.getText().equals("->")) { return indentIfNotBrace(child); } } - if (childParent != null && childParent.getElementType() == JetNodeTypes.DOT_QUALIFIED_EXPRESSION) { + if (childParent != null && childParent.getElementType() == DOT_QUALIFIED_EXPRESSION) { if (childParent.getFirstChildNode() != child && childParent.getLastChildNode() != child) { return Indent.getContinuationWithoutFirstIndent(false); } @@ -352,16 +358,16 @@ public class JetBlock extends AbstractBlock { if (childParent != null) { IElementType parentType = childParent.getElementType(); - if (parentType == JetNodeTypes.VALUE_PARAMETER_LIST || parentType == JetNodeTypes.VALUE_ARGUMENT_LIST) { + if (parentType == VALUE_PARAMETER_LIST || parentType == VALUE_ARGUMENT_LIST) { ASTNode prev = getPrevWithoutWhitespace(child); - if (childType == JetTokens.RPAR && (prev == null || prev.getElementType() != TokenType.ERROR_ELEMENT)) { + if (childType == RPAR && (prev == null || prev.getElementType() != TokenType.ERROR_ELEMENT)) { return Indent.getNoneIndent(); } return Indent.getContinuationWithoutFirstIndent(); } - if (parentType == JetNodeTypes.TYPE_PARAMETER_LIST || parentType == JetNodeTypes.TYPE_ARGUMENT_LIST) { + if (parentType == TYPE_PARAMETER_LIST || parentType == TYPE_ARGUMENT_LIST) { return Indent.getContinuationWithoutFirstIndent(); } } diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java index 7269e1280f5..7bb69f508a8 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java @@ -80,6 +80,15 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder { .beforeInside(BLOCK, FUN).spaceIf(jetCommonSettings.SPACE_BEFORE_METHOD_LBRACE) + .afterInside(LPAR, VALUE_PARAMETER_LIST).spaces(0) + .beforeInside(RPAR, VALUE_PARAMETER_LIST).spaces(0) + .afterInside(LT, TYPE_PARAMETER_LIST).spaces(0) + .beforeInside(GT, TYPE_PARAMETER_LIST).spaces(0) + .afterInside(LPAR, VALUE_ARGUMENT_LIST).spaces(0) + .beforeInside(RPAR, VALUE_ARGUMENT_LIST).spaces(0) + .afterInside(LT, TYPE_ARGUMENT_LIST).spaces(0) + .beforeInside(GT, TYPE_ARGUMENT_LIST).spaces(0) + // TODO: Ask for better API // Type of the declaration colon .beforeInside(COLON, PROPERTY).spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/IdeErrorMessages.java b/idea/src/org/jetbrains/jet/plugin/highlighter/IdeErrorMessages.java index 891243cb660..4156094c0af 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/IdeErrorMessages.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/IdeErrorMessages.java @@ -41,6 +41,14 @@ public class IdeErrorMessages { public static final DiagnosticRenderer RENDERER = new DispatchingDiagnosticRenderer(MAP, DefaultErrorMessages.MAP); static { + // TODO: Remove when tuples are completely dropped + MAP.put(TUPLES_ARE_NOT_SUPPORTED, "Tuples are not supported. Press Alt+Enter to replace tuples with library classes"); + MAP.put(TUPLES_ARE_NOT_SUPPORTED_BIG, "" + + "Tuples are not supported.
" + + "Use data classes instead. For example:
" + + "data class FourThings(val a: A, val b: B, val c: C, val d: D)" + + ""); + MAP.put(TYPE_MISMATCH, "Type mismatch.
Required:{0}
Found:{1}
", HTML_RENDER_TYPE, HTML_RENDER_TYPE); diff --git a/idea/src/org/jetbrains/jet/plugin/libraries/JetClsNavigationPolicy.java b/idea/src/org/jetbrains/jet/plugin/libraries/JetClsNavigationPolicy.java index 037ab9d6b94..d0ccbe95d2a 100644 --- a/idea/src/org/jetbrains/jet/plugin/libraries/JetClsNavigationPolicy.java +++ b/idea/src/org/jetbrains/jet/plugin/libraries/JetClsNavigationPolicy.java @@ -63,7 +63,14 @@ public class JetClsNavigationPolicy implements ClsCustomNavigationPolicy { @Override @Nullable public PsiElement getNavigationElement(@NotNull ClsFieldImpl clsField) { - return getJetDeclarationByClsElement(clsField); + JetDeclaration jetDeclaration = getJetDeclarationByClsElement(clsField); + if (jetDeclaration instanceof JetProperty) { + JetDeclaration sourceProperty = JetSourceNavigationHelper.getSourceProperty((JetProperty) jetDeclaration); + if (sourceProperty != null) { + return sourceProperty; + } + } + return jetDeclaration; } @Nullable diff --git a/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java b/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java index 51cd84423f8..c4b416897e2 100644 --- a/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java +++ b/idea/src/org/jetbrains/jet/plugin/libraries/JetSourceNavigationHelper.java @@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderEntry; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.ProjectFileIndex; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; @@ -30,7 +31,6 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.GlobalSearchScopes; import com.intellij.psi.search.UsageSearchContext; import com.intellij.psi.util.PsiTreeUtil; -import jet.Tuple2; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.*; @@ -45,7 +45,6 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lexer.JetTokens; -import org.jetbrains.jet.plugin.project.AnalyzerFacadeProvider; import org.jetbrains.jet.resolve.DescriptorRenderer; import org.jetbrains.jet.util.slicedmap.ReadOnlySlice; @@ -53,7 +52,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Set; /** * @author Evgeny Gerashchenko @@ -64,7 +62,7 @@ public class JetSourceNavigationHelper { } @Nullable - private static Tuple2 + private static Pair getBindingContextAndClassOrNamespaceDescriptor(@NotNull ReadOnlySlice slice, @NotNull JetDeclaration declaration, @Nullable FqName fqName) { @@ -80,19 +78,19 @@ public class JetSourceNavigationHelper { Predicates.alwaysTrue()).getBindingContext(); D descriptor = bindingContext.get(slice, fqName); if (descriptor != null) { - return new Tuple2(bindingContext, descriptor); + return new Pair(bindingContext, descriptor); } return null; } @Nullable - private static Tuple2 getBindingContextAndClassDescriptor(@NotNull JetClass decompiledClass) { + private static Pair getBindingContextAndClassDescriptor(@NotNull JetClass decompiledClass) { return getBindingContextAndClassOrNamespaceDescriptor(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, decompiledClass, JetPsiUtil.getFQName(decompiledClass)); } @Nullable - private static Tuple2 getBindingContextAndNamespaceDescriptor( + private static Pair getBindingContextAndNamespaceDescriptor( @NotNull JetDeclaration declaration) { JetFile file = (JetFile) declaration.getContainingFile(); return getBindingContextAndClassOrNamespaceDescriptor(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, declaration, @@ -101,12 +99,12 @@ public class JetSourceNavigationHelper { @Nullable public static JetClassOrObject getSourceClass(@NotNull JetClass decompiledClass) { - Tuple2 bindingContextAndClassDescriptor = getBindingContextAndClassDescriptor(decompiledClass); + Pair bindingContextAndClassDescriptor = getBindingContextAndClassDescriptor(decompiledClass); if (bindingContextAndClassDescriptor == null) return null; PsiElement declaration = BindingContextUtils.classDescriptorToDeclaration( - bindingContextAndClassDescriptor._1, bindingContextAndClassDescriptor._2); + bindingContextAndClassDescriptor.first, bindingContextAndClassDescriptor.second); if (declaration == null) { - throw new IllegalStateException("class not found by " + bindingContextAndClassDescriptor._2); + throw new IllegalStateException("class not found by " + bindingContextAndClassDescriptor.second); } return (JetClassOrObject) declaration; } @@ -159,11 +157,11 @@ public class JetSourceNavigationHelper { PsiElement declarationContainer = decompiledDeclaration.getParent(); if (declarationContainer instanceof JetFile) { - Tuple2 bindingContextAndNamespaceDescriptor = + Pair bindingContextAndNamespaceDescriptor = getBindingContextAndNamespaceDescriptor(decompiledDeclaration); if (bindingContextAndNamespaceDescriptor == null) return null; - BindingContext bindingContext = bindingContextAndNamespaceDescriptor._1; - NamespaceDescriptor namespaceDescriptor = bindingContextAndNamespaceDescriptor._2; + BindingContext bindingContext = bindingContextAndNamespaceDescriptor.first; + NamespaceDescriptor namespaceDescriptor = bindingContextAndNamespaceDescriptor.second; if (receiverType == null) { // non-extension property for (Descr candidate : matcher.getCandidatesFromScope(namespaceDescriptor.getMemberScope(), entityNameAsName)) { @@ -197,10 +195,10 @@ public class JetSourceNavigationHelper { if (jetClass == null) { return null; } - Tuple2 bindingContextAndClassDescriptor = getBindingContextAndClassDescriptor(jetClass); + Pair bindingContextAndClassDescriptor = getBindingContextAndClassDescriptor(jetClass); if (bindingContextAndClassDescriptor != null) { - BindingContext bindingContext = bindingContextAndClassDescriptor._1; - ClassDescriptor classDescriptor = bindingContextAndClassDescriptor._2; + BindingContext bindingContext = bindingContextAndClassDescriptor.first; + ClassDescriptor classDescriptor = bindingContextAndClassDescriptor.second; JetScope memberScope = classDescriptor.getDefaultType().getMemberScope(); if (isClassObject) { JetType classObjectType = classDescriptor.getClassObjectType(); diff --git a/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeWithCache.java b/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeWithCache.java index 4dade77dd64..36fdd62d1e1 100644 --- a/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeWithCache.java +++ b/idea/src/org/jetbrains/jet/plugin/project/AnalyzerFacadeWithCache.java @@ -16,11 +16,10 @@ package org.jetbrains.jet.plugin.project; -import com.google.common.base.Predicate; import com.google.common.base.Predicates; -import com.google.common.collect.Lists; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.psi.PsiFile; @@ -34,29 +33,15 @@ import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.Function; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.analyzer.AnalyzeExhaust; -import org.jetbrains.jet.di.InjectorForJavaDescriptorResolver; -import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode; -import org.jetbrains.jet.lang.DefaultModuleConfiguration; -import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.ModuleConfiguration; -import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; -import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetImportDirective; -import org.jetbrains.jet.lang.psi.JetPsiFactory; import org.jetbrains.jet.lang.resolve.*; -import org.jetbrains.jet.lang.resolve.java.*; -import org.jetbrains.jet.lang.resolve.lazy.FileBasedDeclarationProviderFactory; +import org.jetbrains.jet.lang.resolve.java.JetFilesProvider; import org.jetbrains.jet.lang.resolve.lazy.ResolveSession; -import org.jetbrains.jet.lang.resolve.name.FqName; -import org.jetbrains.jet.lang.resolve.name.Name; -import org.jetbrains.jet.lang.resolve.scopes.WritableScope; -import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.plugin.util.ApplicationUtils; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -101,6 +86,12 @@ public final class AnalyzerFacadeWithCache { @Override public Result compute() { try { + if (DumbService.isDumb(file.getProject())) { + return new Result( + AnalyzeExhaust.success(BindingContext.EMPTY, ModuleConfiguration.EMPTY), + PsiModificationTracker.MODIFICATION_COUNT); + } + ApplicationUtils.warnTimeConsuming(LOG); // Collect context for headers first @@ -187,11 +178,6 @@ public final class AnalyzerFacadeWithCache { @NotNull public static ResolveSession getLazyResolveSession(@NotNull final JetFile file) { final Project fileProject = file.getProject(); - ModuleDescriptor javaModule = new ModuleDescriptor(Name.special("")); - - BindingTraceContext javaResolverTrace = new BindingTraceContext(); - InjectorForJavaDescriptorResolver injector = new InjectorForJavaDescriptorResolver( - fileProject, javaResolverTrace, javaModule, BuiltinsScopeExtensionMode.ALL); Collection files = JetFilesProvider.getInstance(fileProject).allInScope(GlobalSearchScope.allScope(fileProject)); @@ -200,55 +186,6 @@ public final class AnalyzerFacadeWithCache { files.remove(originalFile); files.add(file); - final PsiClassFinder psiClassFinder = injector.getPsiClassFinder(); - - // TODO: Replace with stub declaration provider - final FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory(files, new Predicate() { - @Override - public boolean apply(FqName fqName) { - return psiClassFinder.findPsiPackage(fqName) != null || new FqName("jet").equals(fqName); - } - }); - - final JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver(); - - ModuleConfiguration moduleConfiguration = new ModuleConfiguration() { - @Override - public void addDefaultImports(@NotNull Collection directives) { - final Collection defaultImports = Lists.newArrayList(JavaBridgeConfiguration.DEFAULT_JAVA_IMPORTS); - defaultImports.addAll(Arrays.asList(DefaultModuleConfiguration.DEFAULT_JET_IMPORTS)); - - for (ImportPath defaultJetImport : defaultImports) { - directives.add(JetPsiFactory.createImportDirective(fileProject, defaultJetImport)); - } - } - - @Override - public void extendNamespaceScope( - @NotNull BindingTrace trace, - @NotNull NamespaceDescriptor namespaceDescriptor, - @NotNull WritableScope namespaceMemberScope - ) { - FqName fqName = DescriptorUtils.getFQName(namespaceDescriptor).toSafe(); - if (new FqName("jet").equals(fqName)) { - namespaceMemberScope.importScope(JetStandardLibrary.getInstance().getLibraryScope()); - } - if (psiClassFinder.findPsiPackage(fqName) != null) { - JavaPackageScope javaPackageScope = javaDescriptorResolver.getJavaPackageScope(fqName, namespaceDescriptor); - assert javaPackageScope != null; - namespaceMemberScope.importScope(javaPackageScope); - } - } - - @NotNull - @Override - public PlatformToKotlinClassMap getPlatformToKotlinClassMap() { - return PlatformToKotlinClassMap.EMPTY; - } - }; - - ModuleDescriptor lazyModule = new ModuleDescriptor(Name.special("")); - - return new ResolveSession(fileProject, lazyModule, moduleConfiguration, declarationProviderFactory); + return AnalyzerFacadeProvider.getAnalyzerFacadeForFile(file).getLazyResolveSession(fileProject, files); } } diff --git a/idea/src/org/jetbrains/jet/plugin/project/JSAnalyzerFacadeForIDEA.java b/idea/src/org/jetbrains/jet/plugin/project/JSAnalyzerFacadeForIDEA.java index 8c23a4e82c8..3c9d1ceb77a 100644 --- a/idea/src/org/jetbrains/jet/plugin/project/JSAnalyzerFacadeForIDEA.java +++ b/idea/src/org/jetbrains/jet/plugin/project/JSAnalyzerFacadeForIDEA.java @@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BodiesResolveContext; +import org.jetbrains.jet.lang.resolve.lazy.ResolveSession; import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS; import java.util.Collection; @@ -65,4 +66,10 @@ public enum JSAnalyzerFacadeForIDEA implements AnalyzerFacade { ) { return AnalyzerFacadeForJS.analyzeBodiesInFiles(filesForBodiesResolve, new IDEAConfig(project), traceContext, bodiesResolveContext, configuration); } + + @NotNull + @Override + public ResolveSession getLazyResolveSession(@NotNull Project project, @NotNull Collection files) { + return AnalyzerFacadeForJS.getLazyResolveSession(files, new IDEAConfig(project)); + } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ConfigureKotlinLibraryNotificationProvider.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ConfigureKotlinLibraryNotificationProvider.java index b5b1ab1fe9c..3d8c9e49625 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ConfigureKotlinLibraryNotificationProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ConfigureKotlinLibraryNotificationProvider.java @@ -26,7 +26,7 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.fileChooser.FileChooserFactory; import com.intellij.openapi.fileChooser.FileTextField; import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; @@ -55,6 +55,7 @@ import com.intellij.ui.EditorNotificationPanel; import com.intellij.ui.EditorNotifications; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.utils.PathUtil; @@ -87,15 +88,10 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific if (CompilerManager.getInstance(myProject).isExcludedFromCompilation(file)) return null; - final Module module = ModuleUtil.findModuleForFile(file, myProject); + final Module module = ModuleUtilCore.findModuleForFile(file, myProject); if (module == null) return null; - if (isMavenModule(module)) return null; - - if (isJsModule(module)) return null; - - GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false); - if (JavaPsiFacade.getInstance(myProject).findClass("jet.JetObject", scope) == null) { + if (!isModuleAlreadyConfigured(module)) { return createNotificationPanel(module); } } @@ -106,7 +102,6 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific // Ignore } - return null; } @@ -251,6 +246,16 @@ public class ConfigureKotlinLibraryNotificationProvider implements EditorNotific }); } + private boolean isModuleAlreadyConfigured(Module module) { + return isMavenModule(module) || isJsModule(module) || isWithJavaModule(module); + } + + private boolean isWithJavaModule(Module module) { + // Can find a reference to kotlin class in module scope + GlobalSearchScope scope = module.getModuleWithDependenciesAndLibrariesScope(false); + return (JavaPsiFacade.getInstance(myProject).findClass(JvmStdlibNames.JET_OBJECT.getFqName().getFqName(), scope) != null); + } + private static boolean isMavenModule(@NotNull Module module) { for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) { if (root.findChild("pom.xml") != null) return true; diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/MigrateSureInProjectFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/MigrateSureInProjectFix.java new file mode 100644 index 00000000000..5b22cdbec1e --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/MigrateSureInProjectFix.java @@ -0,0 +1,145 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.quickfix; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.diagnostics.Diagnostic; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.plugin.JetBundle; +import org.jetbrains.jet.plugin.project.PluginJetFilesProvider; + +import java.util.Collection; + +/** + * @author abreslav + */ +public class MigrateSureInProjectFix extends JetIntentionAction { + public MigrateSureInProjectFix(@NotNull PsiElement element) { + super(element); + } + + @NotNull + @Override + public String getText() { + return JetBundle.message("migrate.sure"); + } + + @NotNull + @Override + public String getFamilyName() { + return JetBundle.message("migrate.sure"); + } + + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + return super.isAvailable(project, editor, file) + && (file instanceof JetFile) + && isUnresolvedSure(element); + } + + private static boolean isUnresolvedSure(PsiElement element) { + if (!(element instanceof JetSimpleNameExpression)) return false; + JetSimpleNameExpression calleeExpression = (JetSimpleNameExpression) element; + + // it must be "sure" + if (!"sure".equals(calleeExpression.getReferencedName())) return false; + + // parent must be a call expression, and this must be the callee + PsiElement parent = calleeExpression.getParent(); + if (!(parent instanceof JetCallExpression)) return false; + JetCallExpression callExpression = (JetCallExpression) parent; + if (callExpression.getCalleeExpression() != calleeExpression) return false; + + // it must be a qualified call + PsiElement callParent = callExpression.getParent(); + assert callParent != null; + if (!(callParent instanceof JetDotQualifiedExpression)) return false; + + // not more than one type argument + if (callExpression.getTypeArguments().size() > 1) return false; + + // no value arguments + if (!callExpression.getValueArguments().isEmpty() || !callExpression.getFunctionLiteralArguments().isEmpty()) return false; + + return true; + } + + @Override + public void invoke(@NotNull Project project, Editor editor, final PsiFile file) throws IncorrectOperationException { + JetFile initialFile = (JetFile) file; + Collection files = PluginJetFilesProvider.WHOLE_PROJECT_DECLARATION_PROVIDER.fun(initialFile); + + AnalyzeExhaust analyzeExhaust = MigrateTuplesInProjectFix.analyzeFiles(initialFile, files); + + for (JetFile jetFile : files) { + replaceUnresolvedSure(jetFile, analyzeExhaust.getBindingContext()); + } + } + + private void replaceUnresolvedSure(JetFile file, final BindingContext context) { + for (JetDeclaration declaration : file.getDeclarations()) { + declaration.acceptChildren(new JetVisitorVoid() { + + @Override + public void visitCallExpression(JetCallExpression expression) { + expression.acceptChildren(this); + + if (!isUnresolvedSure(expression.getCalleeExpression())) return; + + PsiElement parent = expression.getParent(); + assert parent != null : "isUnresolvedSure() must be true"; + JetExpression receiver = ((JetDotQualifiedExpression) parent).getReceiverExpression(); + + // sure() must be unresolved + DeclarationDescriptor callee = context.get(BindingContext.REFERENCE_TARGET, + (JetReferenceExpression) expression.getCalleeExpression()); + if (callee != null) return; + + // replace 'foo.sure()' with 'foo!!' + JetExpression newExpression = JetPsiFactory.createExpression(expression.getProject(), receiver.getText() + "!!"); + parent.replace(newExpression); + } + + @Override + public void visitElement(PsiElement element) { + element.acceptChildren(this); + } + }); + } + } + + + public static JetIntentionActionFactory createFactory() { + return new JetIntentionActionFactory() { + @Nullable + @Override + public JetIntentionAction createAction(Diagnostic diagnostic) { + PsiElement element = diagnostic.getPsiElement(); + return new MigrateSureInProjectFix(element); + } + }; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/MigrateTuplesInProjectFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/MigrateTuplesInProjectFix.java new file mode 100644 index 00000000000..8115c0e5d18 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/MigrateTuplesInProjectFix.java @@ -0,0 +1,251 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.quickfix; + +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.analyzer.AnalyzeExhaust; +import org.jetbrains.jet.lang.ModuleConfiguration; +import org.jetbrains.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.diagnostics.Diagnostic; +import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.BodiesResolveContext; +import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace; +import org.jetbrains.jet.lang.types.lang.JetStandardClasses; +import org.jetbrains.jet.plugin.JetBundle; +import org.jetbrains.jet.plugin.project.AnalyzerFacadeProvider; +import org.jetbrains.jet.plugin.project.PluginJetFilesProvider; + +import java.util.Collection; +import java.util.Collections; + +/** + * @author abreslav + */ +@Deprecated // Tuples are to be removed in Kotlin M4 +public class MigrateTuplesInProjectFix extends JetIntentionAction { + public MigrateTuplesInProjectFix(@NotNull PsiElement element) { + super(element); + } + + @NotNull + @Override + public String getText() { + return JetBundle.message("migrate.tuple"); + } + + @NotNull + @Override + public String getFamilyName() { + return JetBundle.message("migrate.tuple"); + } + + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + return super.isAvailable(project, editor, file) + && (file instanceof JetFile) + && (element instanceof JetTupleExpression || element instanceof JetTupleType); + } + + @Override + public void invoke(@NotNull Project project, Editor editor, final PsiFile file) throws IncorrectOperationException { + JetFile initialFile = (JetFile) file; + Collection files = PluginJetFilesProvider.WHOLE_PROJECT_DECLARATION_PROVIDER.fun(initialFile); + + AnalyzeExhaust exhaust = analyzeFiles(initialFile, files); + + for (JetFile jetFile : files) { + replaceTupleComponentCalls(jetFile, exhaust.getBindingContext()); + replaceTuple(jetFile); + } + } + + public static AnalyzeExhaust analyzeFiles(JetFile initialFile, Collection files) { + AnalyzeExhaust analyzeExhaustHeaders = AnalyzerFacadeProvider.getAnalyzerFacadeForFile(initialFile).analyzeFiles( + initialFile.getProject(), + files, + Collections.emptyList(), + Predicates.alwaysFalse()); + + BodiesResolveContext context = analyzeExhaustHeaders.getBodiesResolveContext(); + ModuleConfiguration moduleConfiguration = analyzeExhaustHeaders.getModuleConfiguration(); + assert context != null : "Headers resolver should prepare and stored information for bodies resolve"; + + // Need to resolve bodies in given file and all in the same package + return AnalyzerFacadeProvider.getAnalyzerFacadeForFile(initialFile).analyzeBodiesInFiles( + initialFile.getProject(), + Collections.emptyList(), + Predicates.alwaysTrue(), + new DelegatingBindingTrace(analyzeExhaustHeaders.getBindingContext()), + context, + moduleConfiguration); + } + + private void replaceTupleComponentCalls(JetFile file, final BindingContext context) { + for (JetDeclaration declaration : file.getDeclarations()) { + declaration.acceptChildren(new JetVisitorVoid() { + + @Override + public void visitSimpleNameExpression(JetSimpleNameExpression expression) { + DeclarationDescriptor referenceTarget = context.get(BindingContext.REFERENCE_TARGET, expression); + if (referenceTarget == null) return; + + DeclarationDescriptor containingDeclaration = referenceTarget.getContainingDeclaration(); + if (containingDeclaration == null) return; + + ImmutableSet supportedTupleClasses = + ImmutableSet.of(JetStandardClasses.getTuple(2), JetStandardClasses.getTuple(3)); + //noinspection SuspiciousMethodCalls + if (!supportedTupleClasses.contains(containingDeclaration)) return; + + ImmutableMap supportedComponents = ImmutableMap.builder() + .put("_1", "first") + .put("_2", "second") + .put("_3", "third") + .build(); + String newName = supportedComponents.get(expression.getReferencedName()); + if (newName == null) return; + + expression.replace(JetPsiFactory.createExpression(expression.getProject(), newName)); + } + + @Override + public void visitElement(PsiElement element) { + element.acceptChildren(this); + } + }); + } + } + + private void replaceTuple(JetFile file) { + for (JetDeclaration declaration : file.getDeclarations()) { + declaration.acceptChildren(new JetVisitorVoid() { + + @Override + public void visitTupleExpression(JetTupleExpression expression) { + expression.acceptChildren(this); + + int size = expression.getEntries().size(); + switch (size) { + case 0: + expression.replace(JetPsiFactory.createExpression(expression.getProject(), "Unit.VALUE")); + return; + case 1: + expression.replace(expression.getEntries().get(0)); + return; + + case 2: + replaceWithExpression(expression, "Pair"); + return; + + case 3: + replaceWithExpression(expression, "Triple"); + return; + + default: + // Can't do anything + } + } + + @Override + public void visitTupleType(JetTupleType type) { + type.acceptChildren(this); + + int size = type.getComponentTypeRefs().size(); + switch (size) { + case 0: + type.replace(JetPsiFactory.createType(type.getProject(), "Unit").getTypeElement()); + return; + case 1: + type.replace(type.getComponentTypeRefs().get(0).getTypeElement()); + return; + + case 2: + replaceWithType(type, "Pair"); + return; + + case 3: + replaceWithType(type, "Triple"); + return; + + default: + // Can't do anything + } + } + + @Override + public void visitElement(PsiElement element) { + element.acceptChildren(this); + } + }); + } + } + + private static void replaceWithExpression(JetTupleExpression expression, String name) { + String tupleContents = getTupleContents(expression.getText()); + if (tupleContents == null) return; + + String newText = name + "(" + tupleContents + ")"; + JetExpression newExpression = JetPsiFactory.createExpression(expression.getProject(), newText); + + expression.replace(newExpression); + } + + private static void replaceWithType(JetTupleType type, String name) { + String tupleContents = getTupleContents(type.getText()); + if (tupleContents == null) return; + + String newText = name + "<" + tupleContents + ">"; + JetTypeReference newExpression = JetPsiFactory.createType(type.getProject(), newText); + + type.replace(newExpression.getTypeElement()); + } + + @Nullable + private static String getTupleContents(String text) { + int indexOfHash = text.indexOf("#("); + assert indexOfHash >= 0; + String noOpenPar = text.substring(indexOfHash + 2); + int lastClosingPar = noOpenPar.lastIndexOf(')'); + if (lastClosingPar < 0) { + return null; + } + return noOpenPar.substring(0, lastClosingPar); + } + + public static JetIntentionActionFactory createFactory() { + return new JetIntentionActionFactory() { + @Nullable + @Override + public JetIntentionAction createAction(Diagnostic diagnostic) { + PsiElement element = diagnostic.getPsiElement(); + return new MigrateTuplesInProjectFix(element); + } + }; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java index 381a1b60a2f..172527bced4 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java @@ -123,6 +123,10 @@ public class QuickFixes { factories.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, ChangeVisibilityModifierFix.createFactory()); factories.put(CANNOT_WEAKEN_ACCESS_PRIVILEGE, ChangeVisibilityModifierFix.createFactory()); + factories.put(TUPLES_ARE_NOT_SUPPORTED, MigrateTuplesInProjectFix.createFactory()); + + factories.put(UNRESOLVED_REFERENCE, MigrateSureInProjectFix.createFactory()); + ImplementMethodsHandler implementMethodsHandler = new ImplementMethodsHandler(); actions.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler); actions.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, implementMethodsHandler); diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/JetNameSuggester.java b/idea/src/org/jetbrains/jet/plugin/refactoring/JetNameSuggester.java index 3ad7cc8d9ed..be59483b93d 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/JetNameSuggester.java +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/JetNameSuggester.java @@ -189,36 +189,36 @@ public class JetNameSuggester { return matcher.replaceAll(""); } - private static void addNamesForExpression(ArrayList result, JetExpression expression, JetNameValidator validator) { - if (expression instanceof JetQualifiedExpression) { - JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) expression; - JetExpression selectorExpression = qualifiedExpression.getSelectorExpression(); - addNamesForExpression(result, selectorExpression, validator); - if (selectorExpression != null && selectorExpression instanceof JetCallExpression) { - JetExpression calleeExpression = ((JetCallExpression)selectorExpression).getCalleeExpression(); - if (calleeExpression != null && calleeExpression instanceof JetSimpleNameExpression) { - String name = ((JetSimpleNameExpression)calleeExpression).getReferencedName(); - if (name != null && name.equals("sure")) { - addNamesForExpression(result, qualifiedExpression.getReceiverExpression(), validator); - } + private static void addNamesForExpression(final ArrayList result, JetExpression expression, final JetNameValidator validator) { + expression.accept(new JetVisitorVoid() { + @Override + public void visitQualifiedExpression(JetQualifiedExpression expression) { + JetExpression selectorExpression = expression.getSelectorExpression(); + addNamesForExpression(result, selectorExpression, validator); + } + + @Override + public void visitSimpleNameExpression(JetSimpleNameExpression expression) { + String referenceName = expression.getReferencedName(); + if (referenceName == null) return; + if (referenceName.equals(referenceName.toUpperCase())) { + addName(result, referenceName, validator); + } + else { + addCamelNames(result, referenceName, validator); } } - } - else if (expression instanceof JetSimpleNameExpression) { - JetSimpleNameExpression reference = (JetSimpleNameExpression) expression; - String referenceName = reference.getReferencedName(); - if (referenceName == null) return; - if (referenceName.equals(referenceName.toUpperCase())) { - addName(result, referenceName, validator); + + @Override + public void visitCallExpression(JetCallExpression expression) { + addNamesForExpression(result, expression.getCalleeExpression(), validator); } - else { - addCamelNames(result, referenceName, validator); + + @Override + public void visitPostfixExpression(JetPostfixExpression expression) { + addNamesForExpression(result, expression.getBaseExpression(), validator); } - } - else if (expression instanceof JetCallExpression) { - JetCallExpression call = (JetCallExpression) expression; - addNamesForExpression(result, call.getCalleeExpression(), validator); - } + }); } public static boolean isIdentifier(String name) { diff --git a/idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.java b/idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.java index e5c30820667..743dc2d8742 100644 --- a/idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.java +++ b/idea/src/org/jetbrains/jet/plugin/references/JetSimpleNameReference.java @@ -75,4 +75,9 @@ public class JetSimpleNameReference extends JetPsiReference { PsiElement element = JetPsiFactory.createNameIdentifier(myExpression.getProject(), newElementName); return myExpression.getReferencedNameElement().replace(element); } + + @Override + public String toString() { + return JetSimpleNameReference.class.getSimpleName() + ": " + myExpression.getText(); + } } diff --git a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java index d8d3bf4e38e..ae93477b829 100644 --- a/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java +++ b/idea/src/org/jetbrains/jet/plugin/structureView/JetStructureViewElement.java @@ -110,10 +110,7 @@ public class JetStructureViewElement implements StructureViewTreeElement { public TreeElement[] getChildren() { if (myElement instanceof JetFile) { final JetFile jetFile = (JetFile) myElement; - - context = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(jetFile) - .getBindingContext(); - + context = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(jetFile).getBindingContext(); return wrapDeclarations(jetFile.getDeclarations()); } else if (myElement instanceof JetClass) { @@ -137,7 +134,7 @@ public class JetStructureViewElement implements StructureViewTreeElement { } } - return new TreeElement[0]; + return EMPTY_ARRAY; } private String getElementText() { @@ -147,8 +144,7 @@ public class JetStructureViewElement implements StructureViewTreeElement { if (myElement instanceof JetDeclaration) { JetDeclaration declaration = (JetDeclaration) myElement; - final DeclarationDescriptor descriptor = - context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration); + final DeclarationDescriptor descriptor = context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration); if (descriptor != null) { text = getDescriptorTreeText(descriptor); } diff --git a/idea/testData/checker/Bounds.jet b/idea/testData/checker/Bounds.jet index d01aaf4e6bc..06742fab9b8 100644 --- a/idea/testData/checker/Bounds.jet +++ b/idea/testData/checker/Bounds.jet @@ -1,7 +1,9 @@ open class A {} open class B() - abstract class CInt>, X : (B<Char>) -> #(B<Any>, B
)>() : B<Any>() { // 2 errors + class Pair + + abstract class CInt>, X : (B<Char>) -> PairAny>, B>>() : B<Any>() { // 2 errors val a = B<Char>() // error abstract val x : (B<Char>) -> B<Any> diff --git a/idea/testData/checker/Casts.jet b/idea/testData/checker/Casts.jet index fbd29ea06b3..d6203aec635 100644 --- a/idea/testData/checker/Casts.jet +++ b/idea/testData/checker/Casts.jet @@ -12,5 +12,5 @@ fun test() : Unit { y as? Int : Int? x as? Int? : Int? y as? Int? : Int? - #() + Unit.VALUE } \ No newline at end of file diff --git a/idea/testData/checker/ExtensionFunctions.jet b/idea/testData/checker/ExtensionFunctions.jet index df72388de3d..6b7b018e0ec 100644 --- a/idea/testData/checker/ExtensionFunctions.jet +++ b/idea/testData/checker/ExtensionFunctions.jet @@ -1,5 +1,5 @@ fun Int?.optint() : Unit {} -val Int?.optval : Unit = #() +val Int?.optval : Unit = Unit.VALUE fun T.foo(x : E, y : A) : T { y.plus(1) diff --git a/idea/testData/checker/FunctionReturnTypes.jet b/idea/testData/checker/FunctionReturnTypes.jet index ef3ca6807b1..9ccd9e1288a 100644 --- a/idea/testData/checker/FunctionReturnTypes.jet +++ b/idea/testData/checker/FunctionReturnTypes.jet @@ -4,7 +4,7 @@ fun unitEmptyInfer() {} fun unitEmpty() : Unit {} fun unitEmptyReturn() : Unit {return} fun unitIntReturn() : Unit {return 1} -fun unitUnitReturn() : Unit {return #()} +fun unitUnitReturn() : Unit {return Unit.VALUE} fun test1() : Any = { return } fun test2() : Any = @a {return@a 1} fun test3() : Any { return } @@ -22,7 +22,7 @@ fun foo(expr: StringBuilder): Int { } -fun unitShort() : Unit = #() +fun unitShort() : Unit = Unit.VALUE fun unitShortConv() : Unit = 1 fun unitShortNull() : Unit = null @@ -39,7 +39,7 @@ fun intFunctionLiteral(): Int = { 10 } fun blockReturnUnitMismatch() : Int {return} fun blockReturnValueTypeMismatch() : Int {return 3.4} fun blockReturnValueTypeMatch() : Int {return 1} -fun blockReturnValueTypeMismatchUnit() : Int {return #()} +fun blockReturnValueTypeMismatchUnit() : Int {return Unit.VALUE} fun blockAndAndMismatch() : Int { true && false diff --git a/idea/testData/checker/Nullability.jet b/idea/testData/checker/Nullability.jet index 07ec8334475..ef418de3b99 100644 --- a/idea/testData/checker/Nullability.jet +++ b/idea/testData/checker/Nullability.jet @@ -38,28 +38,28 @@ fun test() { out.println(); } - if (out == null || out.println(0) == #()) { + if (out == null || out.println(0) == Unit.VALUE) { out?.println(1) } else { out.println(2) } - if (out != null && out.println() == #()) { + if (out != null && out.println() == Unit.VALUE) { out.println(); } else { out?.println(); } - if (out == null || out.println() == #()) { + if (out == null || out.println() == Unit.VALUE) { out?.println(); } else { out.println(); } - if (1 == 2 || out != null && out.println(1) == #()) { + if (1 == 2 || out != null && out.println(1) == Unit.VALUE) { out?.println(2); } else { @@ -94,28 +94,28 @@ fun test() { out.println(); } - if (out == null || out.println(0) == #()) { + if (out == null || out.println(0) == Unit.VALUE) { out?.println(1) } else { out.println(2) } - if (out != null && out.println() == #()) { + if (out != null && out.println() == Unit.VALUE) { out.println(); } else { out?.println(); } - if (out == null || out.println() == #()) { + if (out == null || out.println() == Unit.VALUE) { out?.println(); } else { out.println(); } - if (1 == 2 || out != null && out.println(1) == #()) { + if (1 == 2 || out != null && out.println(1) == Unit.VALUE) { out?.println(2); } else { diff --git a/idea/testData/checker/Unresolved.jet b/idea/testData/checker/Unresolved.jet index 95228d79b6e..fa2b655f6f4 100644 --- a/idea/testData/checker/Unresolved.jet +++ b/idea/testData/checker/Unresolved.jet @@ -1,8 +1,10 @@ package unresolved +class Pair(a: A, b: B) + fun testGenericArgumentsCount() { - val p1: Tuple2 = #(2, 2) - val p2: Tuple2 = #(2, 2) + val p1: Pair = Pair(2, 2) + val p2: Pair = Pair(2, 2) } fun testUnresolved() { diff --git a/idea/testData/checker/When.jet b/idea/testData/checker/When.jet index 70e7a0b0148..48adeae647d 100644 --- a/idea/testData/checker/When.jet +++ b/idea/testData/checker/When.jet @@ -42,6 +42,4 @@ fun test() { when (z) { else -> 1 } -} - -val #(Int, Int).boo : #(Int, Int, Int) = #(1, 1, 1) +} \ No newline at end of file diff --git a/idea/testData/checker/infos/Autocasts.jet b/idea/testData/checker/infos/Autocasts.jet index adfe94ac032..dde367eab2a 100644 --- a/idea/testData/checker/infos/Autocasts.jet +++ b/idea/testData/checker/infos/Autocasts.jet @@ -19,7 +19,7 @@ fun f9(a : A?) { a?.bar() a?.foo() } - if (!(a is B) || a.bar() == #()) { + if (!(a is B) || a.bar() == Unit.VALUE) { a?.bar() } if (!(a is B)) { @@ -97,7 +97,7 @@ fun f13(a : A?) { } a?.foo() - if (a is B && a.foo() == #()) { + if (a is B && a.foo() == Unit.VALUE) { a.foo() a.bar() } @@ -149,7 +149,7 @@ fun illegalWhenBlock(a: Any): Int { } fun declarations(a: Any?) { if (a is String) { - val p4: #(Int, String) = #(2, a) + val p4: String = a } if (a is String?) { if (a != null) { @@ -168,25 +168,6 @@ fun vars(a: Any?) { b = a } } -fun tuples(a: Any?) { - if (a != null) { - val s: #(Any, String) = #(a, a) - } - if (a is String) { - val s: #(Any, String) = #(a, a) - } - fun illegalTupleReturnType(): #(Any, String) = #(a, a) - if (a is String) { - fun legalTupleReturnType(): #(Any, String) = #(a, a) - } - val illegalFunctionLiteral: Function0 = { a } - val illegalReturnValueInFunctionLiteral: Function0 = { (): Int -> a } - - if (a is Int) { - val legalFunctionLiteral: Function0 = { a } - val alsoLegalFunctionLiteral: Function0 = { (): Int -> a } - } -} fun returnFunctionLiteralBlock(a: Any?): Function0 { if (a is Int) return { a } else return { 1 } @@ -195,8 +176,6 @@ fun returnFunctionLiteral(a: Any?): Function0 = if (a is Int) { (): Int -> a } else { () -> 1 } -fun illegalTupleReturnType(a: Any): #(Any, String) = #(a, a) - fun mergeAutocasts(a: Any?) { if (a is String || a is Int) { a.compareTo("") diff --git a/idea/testData/checker/regression/DoubleDefine.jet b/idea/testData/checker/regression/DoubleDefine.jet index 6dc60faa1b2..e8d9f0da451 100644 --- a/idea/testData/checker/regression/DoubleDefine.jet +++ b/idea/testData/checker/regression/DoubleDefine.jet @@ -51,7 +51,7 @@ fun main(args: Array) { System.out.println("Your numbers: " + prompt) System.out.println("Enter your expression:") val reader = BufferedReader(InputStreamReader(System.`in`)) - val expr = StringBuilder(reader.readLine()) + val expr = StringBuilder(reader.readLine()!!) try { val result = evaluate(expr, numbers) if (result != 24) diff --git a/idea/testData/completion/basic/DoNotCompleteForErrorReceivers.kt b/idea/testData/completion/basic/DoNotCompleteForErrorReceivers.kt new file mode 100644 index 00000000000..d5036432850 --- /dev/null +++ b/idea/testData/completion/basic/DoNotCompleteForErrorReceivers.kt @@ -0,0 +1,7 @@ +// KT-1187 Wrong unnecessary completion + +fun anyfun() { + a.b.c.d.e.f. +} + +// NUMBER: 0 \ No newline at end of file diff --git a/idea/testData/completion/basic/NoTopLevelCompletionInQualifiedUserTypes.kt b/idea/testData/completion/basic/NoTopLevelCompletionInQualifiedUserTypes.kt new file mode 100644 index 00000000000..b5576b5f492 --- /dev/null +++ b/idea/testData/completion/basic/NoTopLevelCompletionInQualifiedUserTypes.kt @@ -0,0 +1,3 @@ +class Test : java.lang.A + +// ABSENT: Annotation \ No newline at end of file diff --git a/idea/testData/completion/confidence/CompleteOnDotOutOfRanges.kt b/idea/testData/completion/confidence/CompleteOnDotOutOfRanges.kt new file mode 100644 index 00000000000..594930fc703 --- /dev/null +++ b/idea/testData/completion/confidence/CompleteOnDotOutOfRanges.kt @@ -0,0 +1,5 @@ +fun test() { + 12.in +} + +// TYPE: "." \ No newline at end of file diff --git a/idea/testData/completion/confidence/CompleteOnDotOutOfRanges.kt.after b/idea/testData/completion/confidence/CompleteOnDotOutOfRanges.kt.after new file mode 100644 index 00000000000..2aef6663fb4 --- /dev/null +++ b/idea/testData/completion/confidence/CompleteOnDotOutOfRanges.kt.after @@ -0,0 +1,5 @@ +fun test() { + 12.inc(). +} + +// TYPE: "." \ No newline at end of file diff --git a/idea/testData/completion/confidence/ImportAsConfidence.kt b/idea/testData/completion/confidence/ImportAsConfidence.kt index 23a13a5a418..abf71eafb62 100644 --- a/idea/testData/completion/confidence/ImportAsConfidence.kt +++ b/idea/testData/completion/confidence/ImportAsConfidence.kt @@ -1 +1,3 @@ -import kotlin.util // Comment to prevent for removing trailing spaces \ No newline at end of file +import kotlin.util // Comment to prevent for removing trailing spaces + +// TYPE: "as" \ No newline at end of file diff --git a/idea/testData/completion/confidence/ImportAsConfidence.kt.after b/idea/testData/completion/confidence/ImportAsConfidence.kt.after index 710bdc9420a..c6ade5b4bf8 100644 --- a/idea/testData/completion/confidence/ImportAsConfidence.kt.after +++ b/idea/testData/completion/confidence/ImportAsConfidence.kt.after @@ -1 +1,3 @@ -import kotlin.util as // Comment to prevent for removing trailing spaces \ No newline at end of file +import kotlin.util as// Comment to prevent for removing trailing spaces + +// TYPE: "as" \ No newline at end of file diff --git a/idea/testData/completion/confidence/InBeginningOfFunctionLiteral.kt b/idea/testData/completion/confidence/InBeginningOfFunctionLiteral.kt index 03898c0f8b1..501531ce7d2 100644 --- a/idea/testData/completion/confidence/InBeginningOfFunctionLiteral.kt +++ b/idea/testData/completion/confidence/InBeginningOfFunctionLiteral.kt @@ -1,4 +1,6 @@ fun main(args : Array) { val mmm = 12 val t = { } -} \ No newline at end of file +} + +// TYPE: "mm " \ No newline at end of file diff --git a/idea/testData/completion/confidence/InBeginningOfFunctionLiteral.kt.after b/idea/testData/completion/confidence/InBeginningOfFunctionLiteral.kt.after index c1079d37611..a22e4856c42 100644 --- a/idea/testData/completion/confidence/InBeginningOfFunctionLiteral.kt.after +++ b/idea/testData/completion/confidence/InBeginningOfFunctionLiteral.kt.after @@ -1,4 +1,6 @@ fun main(args : Array) { val mmm = 12 val t = { mm } -} \ No newline at end of file +} + +// TYPE: "mm " \ No newline at end of file diff --git a/idea/testData/completion/confidence/InBeginningOfFunctionLiteralInBrackets.kt b/idea/testData/completion/confidence/InBeginningOfFunctionLiteralInBrackets.kt index 0fcec1593b2..cf28f8c445c 100644 --- a/idea/testData/completion/confidence/InBeginningOfFunctionLiteralInBrackets.kt +++ b/idea/testData/completion/confidence/InBeginningOfFunctionLiteralInBrackets.kt @@ -1,4 +1,6 @@ fun main(args : Array) { val mmm = 12 val t = { () } -} \ No newline at end of file +} + +// TYPE: "mm " \ No newline at end of file diff --git a/idea/testData/completion/confidence/InBeginningOfFunctionLiteralInBrackets.kt.after b/idea/testData/completion/confidence/InBeginningOfFunctionLiteralInBrackets.kt.after index 34d71fc9fe5..03819a122c8 100644 --- a/idea/testData/completion/confidence/InBeginningOfFunctionLiteralInBrackets.kt.after +++ b/idea/testData/completion/confidence/InBeginningOfFunctionLiteralInBrackets.kt.after @@ -1,4 +1,6 @@ fun main(args : Array) { val mmm = 12 val t = { (mm ) } -} \ No newline at end of file +} + +// TYPE: "mm " \ No newline at end of file diff --git a/idea/testData/completion/confidence/InBlockOfFunctionLiteral.kt b/idea/testData/completion/confidence/InBlockOfFunctionLiteral.kt index f438d237441..0a609794637 100644 --- a/idea/testData/completion/confidence/InBlockOfFunctionLiteral.kt +++ b/idea/testData/completion/confidence/InBlockOfFunctionLiteral.kt @@ -1,4 +1,6 @@ fun main(args : Array) { val mmm = 12 val t = { i -> } -} \ No newline at end of file +} + +// TYPE: "mm " \ No newline at end of file diff --git a/idea/testData/completion/confidence/InBlockOfFunctionLiteral.kt.after b/idea/testData/completion/confidence/InBlockOfFunctionLiteral.kt.after index b541c7e8f9f..027b9f2c855 100644 --- a/idea/testData/completion/confidence/InBlockOfFunctionLiteral.kt.after +++ b/idea/testData/completion/confidence/InBlockOfFunctionLiteral.kt.after @@ -1,4 +1,6 @@ fun main(args : Array) { val mmm = 12 val t = { i -> mmm } -} \ No newline at end of file +} + +// TYPE: "mm " \ No newline at end of file diff --git a/idea/testData/completion/confidence/InModifierList.kt b/idea/testData/completion/confidence/InModifierList.kt index 472ffcb0869..88f9177fc10 100644 --- a/idea/testData/completion/confidence/InModifierList.kt +++ b/idea/testData/completion/confidence/InModifierList.kt @@ -2,4 +2,6 @@ package test import java.util.AbstractSet as Hello -// Comment to prevent for removing trailing spaces \ No newline at end of file +// Comment to prevent for removing trailing spaces + +// TYPE: "pub " \ No newline at end of file diff --git a/idea/testData/completion/confidence/InModifierList.kt.after b/idea/testData/completion/confidence/InModifierList.kt.after index 9ee02ecc7e0..4a3a6fe994e 100644 --- a/idea/testData/completion/confidence/InModifierList.kt.after +++ b/idea/testData/completion/confidence/InModifierList.kt.after @@ -2,4 +2,6 @@ package test import java.util.AbstractSet as Hello -public // Comment to prevent for removing trailing spaces \ No newline at end of file +public // Comment to prevent for removing trailing spaces + +// TYPE: "pub " \ No newline at end of file diff --git a/idea/testData/completion/confidence/NoAutoCompletionForRangeOperator.kt b/idea/testData/completion/confidence/NoAutoCompletionForRangeOperator.kt new file mode 100644 index 00000000000..30b134d7d79 --- /dev/null +++ b/idea/testData/completion/confidence/NoAutoCompletionForRangeOperator.kt @@ -0,0 +1,6 @@ +fun test() { + for (i in 12.) { + } +} + +// TYPE: "." diff --git a/idea/testData/completion/confidence/NoAutoCompletionForRangeOperator.kt.after b/idea/testData/completion/confidence/NoAutoCompletionForRangeOperator.kt.after new file mode 100644 index 00000000000..dade80aff41 --- /dev/null +++ b/idea/testData/completion/confidence/NoAutoCompletionForRangeOperator.kt.after @@ -0,0 +1,6 @@ +fun test() { + for (i in 12..) { + } +} + +// TYPE: "." diff --git a/idea/testData/completion/handlers/DoNotInsertImportForAlreadyImported.kt b/idea/testData/completion/handlers/DoNotInsertImportForAlreadyImported.kt new file mode 100644 index 00000000000..ba1d9f3c532 --- /dev/null +++ b/idea/testData/completion/handlers/DoNotInsertImportForAlreadyImported.kt @@ -0,0 +1,5 @@ +// KT-2424 Invoking completion adds unnecessary FQ name + +fun main(args: Array) { + throw IllegalAccessExceptio() //Press Ctrl+Space and select it +} \ No newline at end of file diff --git a/idea/testData/completion/handlers/DoNotInsertImportForAlreadyImported.kt.after b/idea/testData/completion/handlers/DoNotInsertImportForAlreadyImported.kt.after new file mode 100644 index 00000000000..8d24212dac5 --- /dev/null +++ b/idea/testData/completion/handlers/DoNotInsertImportForAlreadyImported.kt.after @@ -0,0 +1,5 @@ +// KT-2424 Invoking completion adds unnecessary FQ name + +fun main(args: Array) { + throw IllegalAccessException() //Press Ctrl+Space and select it +} \ No newline at end of file diff --git a/idea/testData/completion/handlers/SureInsert.kt b/idea/testData/completion/handlers/ExtFunction.kt similarity index 65% rename from idea/testData/completion/handlers/SureInsert.kt rename to idea/testData/completion/handlers/ExtFunction.kt index 0daa1455f68..a12a341e26e 100644 --- a/idea/testData/completion/handlers/SureInsert.kt +++ b/idea/testData/completion/handlers/ExtFunction.kt @@ -1,3 +1,3 @@ fun main(args : Array) { - "".sur + "".toS } \ No newline at end of file diff --git a/idea/testData/completion/handlers/SureInsert.kt.after b/idea/testData/completion/handlers/ExtFunction.kt.after similarity index 65% rename from idea/testData/completion/handlers/SureInsert.kt.after rename to idea/testData/completion/handlers/ExtFunction.kt.after index dc4a19cc514..bad7b3b6669 100644 --- a/idea/testData/completion/handlers/SureInsert.kt.after +++ b/idea/testData/completion/handlers/ExtFunction.kt.after @@ -1,3 +1,3 @@ fun main(args : Array) { - "".sure() + "".toString() } \ No newline at end of file diff --git a/idea/testData/completion/keywords/NoCompletionForCapitalPrefix.kt b/idea/testData/completion/keywords/NoCompletionForCapitalPrefix.kt new file mode 100644 index 00000000000..ca982f7b7c1 --- /dev/null +++ b/idea/testData/completion/keywords/NoCompletionForCapitalPrefix.kt @@ -0,0 +1,3 @@ +P + +// ABSENT: public, private, protected \ No newline at end of file diff --git a/idea/testData/formatter/FunctionWithNewLineBrace.kt b/idea/testData/formatter/FunctionWithNewLineBrace.kt new file mode 100644 index 00000000000..10f601298b1 --- /dev/null +++ b/idea/testData/formatter/FunctionWithNewLineBrace.kt @@ -0,0 +1,3 @@ +fun test() +{ +} \ No newline at end of file diff --git a/idea/testData/formatter/FunctionWithNewLineBrace_after.kt b/idea/testData/formatter/FunctionWithNewLineBrace_after.kt new file mode 100644 index 00000000000..10f601298b1 --- /dev/null +++ b/idea/testData/formatter/FunctionWithNewLineBrace_after.kt @@ -0,0 +1,3 @@ +fun test() +{ +} \ No newline at end of file diff --git a/idea/testData/formatter/SingleLineFunctionLiteral.kt b/idea/testData/formatter/SingleLineFunctionLiteral.kt index 07a52f68fa3..ae2b67ff4a7 100644 --- a/idea/testData/formatter/SingleLineFunctionLiteral.kt +++ b/idea/testData/formatter/SingleLineFunctionLiteral.kt @@ -2,5 +2,7 @@ fun test(some: (Int) -> Int) { } fun foo() = test() { it } +val function = test { (a: Int) -> a } +val function1 = test {a : Int -> a} // SET_TRUE: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD \ No newline at end of file diff --git a/idea/testData/formatter/SingleLineFunctionLiteral_after.kt b/idea/testData/formatter/SingleLineFunctionLiteral_after.kt index 07a52f68fa3..6924202c419 100644 --- a/idea/testData/formatter/SingleLineFunctionLiteral_after.kt +++ b/idea/testData/formatter/SingleLineFunctionLiteral_after.kt @@ -2,5 +2,7 @@ fun test(some: (Int) -> Int) { } fun foo() = test() { it } +val function = test {(a: Int) -> a } +val function1 = test { a : Int -> a } // SET_TRUE: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD \ No newline at end of file diff --git a/idea/testData/formatter/SingleLineFunctionLiteral_after_inv.kt b/idea/testData/formatter/SingleLineFunctionLiteral_after_inv.kt index 55751353d14..ee26dd90c10 100644 --- a/idea/testData/formatter/SingleLineFunctionLiteral_after_inv.kt +++ b/idea/testData/formatter/SingleLineFunctionLiteral_after_inv.kt @@ -2,5 +2,7 @@ fun test(some: (Int) -> Int) { } fun foo() = test() {it} +val function = test {(a: Int) -> a} +val function1 = test {a : Int -> a} // SET_TRUE: INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD \ No newline at end of file diff --git a/idea/testData/formatter/UnnecessarySpacesInParametersLists.kt b/idea/testData/formatter/UnnecessarySpacesInParametersLists.kt new file mode 100644 index 00000000000..43f70d70145 --- /dev/null +++ b/idea/testData/formatter/UnnecessarySpacesInParametersLists.kt @@ -0,0 +1,6 @@ +fun < T > test( a: Int ) = {( a: Int ) -> a } +class Test< T > + +fun foo( ) { + test< Int >( 12 ) +} \ No newline at end of file diff --git a/idea/testData/formatter/UnnecessarySpacesInParametersLists_after.kt b/idea/testData/formatter/UnnecessarySpacesInParametersLists_after.kt new file mode 100644 index 00000000000..7c6a18daa97 --- /dev/null +++ b/idea/testData/formatter/UnnecessarySpacesInParametersLists_after.kt @@ -0,0 +1,6 @@ +fun test(a: Int) = {(a: Int) -> a } +class Test + +fun foo() { + test(12) +} \ No newline at end of file diff --git a/idea/testData/intentions/specifyType/afterUnitType.kt b/idea/testData/intentions/specifyType/afterUnitType.kt index 7e29d4b7520..8f868d0e08f 100644 --- a/idea/testData/intentions/specifyType/afterUnitType.kt +++ b/idea/testData/intentions/specifyType/afterUnitType.kt @@ -1,2 +1,2 @@ // "Specify Type Explicitly" "true" -val x: Unit = #() \ No newline at end of file +val x: Unit = Unit.VALUE \ No newline at end of file diff --git a/idea/testData/intentions/specifyType/beforeUnitType.kt b/idea/testData/intentions/specifyType/beforeUnitType.kt index 666a1e4b64f..71731938f29 100644 --- a/idea/testData/intentions/specifyType/beforeUnitType.kt +++ b/idea/testData/intentions/specifyType/beforeUnitType.kt @@ -1,2 +1,2 @@ // "Specify Type Explicitly" "true" -val x = #() \ No newline at end of file +val x = Unit.VALUE \ No newline at end of file diff --git a/idea/testData/libraries/decompiled/namespace.kt b/idea/testData/libraries/decompiled/namespace.kt index 7357f1b34c7..e7811bb88af 100644 --- a/idea/testData/libraries/decompiled/namespace.kt +++ b/idea/testData/libraries/decompiled/namespace.kt @@ -3,13 +3,13 @@ package testData.libraries -[public final val #(T, T).exProp : jet.String] /* compiled code */ - [public final val jet.Int.exProp : jet.Int] /* compiled code */ [public final val jet.String.exProp : jet.String] /* compiled code */ -[public final val globalVal : #(jet.Int, jet.String)] /* compiled code */ +[public final val testData.libraries.Pair.exProp : jet.String] /* compiled code */ + +[public final val globalVal : testData.libraries.Pair] /* compiled code */ [public final val globalValWithGetter : jet.Long] /* compiled code */ diff --git a/idea/testData/libraries/library/main.kt b/idea/testData/libraries/library/main.kt index a50bbab3605..d6c7eb39369 100644 --- a/idea/testData/libraries/library/main.kt +++ b/idea/testData/libraries/library/main.kt @@ -1,5 +1,7 @@ package testData.libraries +public class Pair(val first: A, val second: B) + public trait SimpleTrait { } @@ -60,7 +62,7 @@ public abstract class ClassWithAbstractAndOpenMembers { public fun main(args : Array) { } -public val globalVal : #(Int, String) = #(239, "239") +public val globalVal : Pair = Pair(239, "239") public val globalValWithGetter : Long get() { @@ -77,9 +79,9 @@ get() { return this } -public val #(T, T).exProp : String +public val Pair.exProp : String get() { - return "${this._1} : ${this._2}" + return "${this.first} : ${this.second}" } public fun func(a : Int, b : String = "55") { diff --git a/idea/testData/libraries/usercode/Enum.kt b/idea/testData/libraries/usercode/Enum.kt index a2f0dcbca6a..c1709a55747 100644 --- a/idea/testData/libraries/usercode/Enum.kt +++ b/idea/testData/libraries/usercode/Enum.kt @@ -4,4 +4,5 @@ val color: Color? = Color.RED val rgb = color?.rgb // main.kt -//public enum class <1><2>Color(val <3>rgb : Int) { \ No newline at end of file +//public enum class <1><2>Color(val <4>rgb : Int) { +// <3>RED : Color(0xFF0000) \ No newline at end of file diff --git a/idea/testData/libraries/usercode/ExtensionProperty.kt b/idea/testData/libraries/usercode/ExtensionProperty.kt index 38f9d1886e9..9a8bc7441d2 100644 --- a/idea/testData/libraries/usercode/ExtensionProperty.kt +++ b/idea/testData/libraries/usercode/ExtensionProperty.kt @@ -2,7 +2,8 @@ import testData.libraries.* fun foo() { println("".exProp) - println(#(1, 2).exProp) + val p = Pair(1, 2) + println(p.exProp) } // main.kt @@ -16,4 +17,4 @@ fun foo() { // return this //} // -//public val #(T, T).<2>exProp : String \ No newline at end of file +//public val Pair.<2>exProp : String \ No newline at end of file diff --git a/idea/testData/libraries/usercode/GlobalProperty.kt b/idea/testData/libraries/usercode/GlobalProperty.kt index 6c675f5b2ed..811cdf85c03 100644 --- a/idea/testData/libraries/usercode/GlobalProperty.kt +++ b/idea/testData/libraries/usercode/GlobalProperty.kt @@ -6,6 +6,6 @@ fun foo() { } // main.kt -//public val <1>globalVal : #(Int, String) = #(239, "239") +//public val <1>globalVal : Pair = Pair(239, "239") // //public val <2>globalValWithGetter : Long \ No newline at end of file diff --git a/idea/testData/quickfix/migration/afterBareSure.kt b/idea/testData/quickfix/migration/afterBareSure.kt new file mode 100644 index 00000000000..f14b883f8a8 --- /dev/null +++ b/idea/testData/quickfix/migration/afterBareSure.kt @@ -0,0 +1,6 @@ +// "Replace sure() calls by !! in project" "false" +// ERROR: Unresolved reference: sure + +fun test() { + sure() +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/afterSure.kt b/idea/testData/quickfix/migration/afterSure.kt new file mode 100644 index 00000000000..cc1326aefdd --- /dev/null +++ b/idea/testData/quickfix/migration/afterSure.kt @@ -0,0 +1,38 @@ +// "Replace sure() calls by !! in project" "true" + +package p + +fun println(a: Any) = a + +fun int(): Int? = 1 + +fun test1(a: Int?) { + println(a!! + 1) + println(a!! + 1) + println((a)!! + 1) + println(int()!! + 1) + println(p.int()!! + 1) + println(if (true) { + null + } else { + 2 + }!! + 1) + println(((2 + 1): Int?)!! + 1) + sure() + p.sure() +} + +fun sure() {} + + +class A { + + fun Int?.sure(x : Int) = x + fun String?.sure() {} + + fun test(x: Int?) { + x.sure(1) + "".sure() + } +} + diff --git a/idea/testData/quickfix/migration/afterTuplesWithRuntime.kt b/idea/testData/quickfix/migration/afterTuplesWithRuntime.kt new file mode 100644 index 00000000000..5edf336a547 --- /dev/null +++ b/idea/testData/quickfix/migration/afterTuplesWithRuntime.kt @@ -0,0 +1,53 @@ +// "Migrate tuples in project: e.g., #(,) and #(,,) will be replaced by Pair and Triple" "true" +// ERROR: Tuples are not supported.
Use data classes instead. For example:
data class FourThings(val a: A, val b: B, val c: C, val d: D) +// ERROR: Tuples are not supported.
Use data classes instead. For example:
data class FourThings(val a: A, val b: B, val c: C, val d: D) + +fun foo2() : Pair { + return Pair(1, 1) +} + +fun test2() { + foo2().first + foo2().second +} + +fun foo3() : Triple> { + return Triple(1, 1, arrayList("")) +} + +fun test3() { + foo3().first + foo3().second + foo3().third +} + +fun foo0(): Unit { + return Unit.VALUE +} + +fun foo4(): #(Int, Int, Int, Int) { + return #(1, 2, 3, 4) +} + +fun test4() { + foo4()._1 + foo4()._2 + foo4()._3 + foo4()._4 +} + +fun fooRec() : Triple, List>> { + Pair(1, Pair(1, "")) + throw Exception() +} + +fun foo1(): Int { + return 1 +} + +class Fake(val _1: Int, val _2: String) + +fun testFake(f: Fake) { + f._1 + f._2 +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/beforeBareSure.kt b/idea/testData/quickfix/migration/beforeBareSure.kt new file mode 100644 index 00000000000..120af475699 --- /dev/null +++ b/idea/testData/quickfix/migration/beforeBareSure.kt @@ -0,0 +1,6 @@ +// "Replace sure() calls by !! in project" "false" +// ERROR: Unresolved reference: sure + +fun test() { + sure() +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/beforeSure.kt b/idea/testData/quickfix/migration/beforeSure.kt new file mode 100644 index 00000000000..48aae6133d7 --- /dev/null +++ b/idea/testData/quickfix/migration/beforeSure.kt @@ -0,0 +1,38 @@ +// "Replace sure() calls by !! in project" "true" + +package p + +fun println(a: Any) = a + +fun int(): Int? = 1 + +fun test1(a: Int?) { + println(a.sure() + 1) + println(a.sure() + 1) + println((a).sure() + 1) + println(int().sure() + 1) + println(p.int().sure() + 1) + println(if (true) { + null + } else { + 2 + }.sure() + 1) + println(((2 + 1): Int?).sure() + 1) + sure() + p.sure() +} + +fun sure() {} + + +class A { + + fun Int?.sure(x : Int) = x + fun String?.sure() {} + + fun test(x: Int?) { + x.sure(1) + "".sure() + } +} + diff --git a/idea/testData/quickfix/migration/beforeTuplesWithRuntime.kt b/idea/testData/quickfix/migration/beforeTuplesWithRuntime.kt new file mode 100644 index 00000000000..dd82996f198 --- /dev/null +++ b/idea/testData/quickfix/migration/beforeTuplesWithRuntime.kt @@ -0,0 +1,53 @@ +// "Migrate tuples in project: e.g., #(,) and #(,,) will be replaced by Pair and Triple" "true" +// ERROR: Tuples are not supported.
Use data classes instead. For example:
data class FourThings(val a: A, val b: B, val c: C, val d: D) +// ERROR: Tuples are not supported.
Use data classes instead. For example:
data class FourThings(val a: A, val b: B, val c: C, val d: D) + +fun foo2() : #(Int, Int) { + return #(1, 1) +} + +fun test2() { + foo2()._1 + foo2()._2 +} + +fun foo3() : #(Int, Int, List) { + return #(1, 1, arrayList("")) +} + +fun test3() { + foo3()._1 + foo3()._2 + foo3()._3 +} + +fun foo0(): #() { + return #() +} + +fun foo4(): #(Int, Int, Int, Int) { + return #(1, 2, 3, 4) +} + +fun test4() { + foo4()._1 + foo4()._2 + foo4()._3 + foo4()._4 +} + +fun fooRec() : #(Int, #(Int, String), List<#(Int, Int)>) { + #(1, #(1, "")) + throw Exception() +} + +fun foo1(): #(Int) { + return #(1) +} + +class Fake(val _1: Int, val _2: String) + +fun testFake(f: Fake) { + f._1 + f._2 +} \ No newline at end of file diff --git a/idea/testData/refactoring/nameSuggester/GetterSure.kt b/idea/testData/refactoring/nameSuggester/GetterSure.kt index 72d401a8c21..305d029beba 100644 --- a/idea/testData/refactoring/nameSuggester/GetterSure.kt +++ b/idea/testData/refactoring/nameSuggester/GetterSure.kt @@ -1,11 +1,10 @@ fun getFooGoo(): String? = "text" fun a() { - getFooGoo().sure() + getFooGoo()!! } /* fooGoo goo s -sure */ \ No newline at end of file diff --git a/idea/testData/resolve/std/equals.kt b/idea/testData/resolve/std/equals.kt new file mode 100644 index 00000000000..60e01c6d5d0 --- /dev/null +++ b/idea/testData/resolve/std/equals.kt @@ -0,0 +1,2 @@ +val x = 5.equals(5) +//jet/Numbers.jet:equals diff --git a/idea/testData/resolve/std/sure.kt b/idea/testData/resolve/std/sure.kt deleted file mode 100644 index e6f03137c38..00000000000 --- a/idea/testData/resolve/std/sure.kt +++ /dev/null @@ -1,2 +0,0 @@ -val x = 5.sure() -//jet/Library.jet:sure \ No newline at end of file diff --git a/idea/testData/resolve/std/toString.kt b/idea/testData/resolve/std/toString.kt new file mode 100644 index 00000000000..62dbdce939a --- /dev/null +++ b/idea/testData/resolve/std/toString.kt @@ -0,0 +1,2 @@ +val x = 5.toString() +//jet/Library.jet:toString diff --git a/idea/testData/resolve/std/unit.kt b/idea/testData/resolve/std/unit.kt index 9e42d93b7ba..52cacf55e73 100644 --- a/idea/testData/resolve/std/unit.kt +++ b/idea/testData/resolve/std/unit.kt @@ -1,2 +1,2 @@ var x : Unit? -//jet.src/Tuples.jet:Tuple0 \ No newline at end of file +//jet.src/Unit.jet:Tuple0 \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/completion/JetBasicCompletionTest.java b/idea/tests/org/jetbrains/jet/completion/JetBasicCompletionTest.java index e46e72d3edf..12f9e227f9e 100644 --- a/idea/tests/org/jetbrains/jet/completion/JetBasicCompletionTest.java +++ b/idea/tests/org/jetbrains/jet/completion/JetBasicCompletionTest.java @@ -56,6 +56,10 @@ public class JetBasicCompletionTest extends JetCompletionTestBase { doTest(); } + public void testDoNotCompleteForErrorReceivers() { + doTest(); + } + public void testExtendClassName() { doTest(); } @@ -172,6 +176,10 @@ public class JetBasicCompletionTest extends JetCompletionTestBase { doTest(); } + public void testNoTopLevelCompletionInQualifiedUserTypes() { + doTest(); + } + public void testOnlyScopedClassesWithoutExplicit() { doTest(); } diff --git a/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java b/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java index e90a03da3f0..a40079f9530 100644 --- a/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java +++ b/idea/tests/org/jetbrains/jet/completion/KeywordsCompletionTest.java @@ -119,6 +119,10 @@ public class KeywordsCompletionTest extends JetCompletionTestBase { doTest(); } + public void testNoCompletionForCapitalPrefix() { + doTest(); + } + public void testPropertySetterGetter() { doTest(); } diff --git a/idea/tests/org/jetbrains/jet/completion/confidence/JetConfidenceTest.java b/idea/tests/org/jetbrains/jet/completion/confidence/JetConfidenceTest.java index 946441feaef..f4b1905c76d 100644 --- a/idea/tests/org/jetbrains/jet/completion/confidence/JetConfidenceTest.java +++ b/idea/tests/org/jetbrains/jet/completion/confidence/JetConfidenceTest.java @@ -21,8 +21,10 @@ import com.intellij.codeInsight.completion.CompletionType; import com.intellij.codeInsight.completion.LightCompletionTestCase; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.util.text.StringUtil; import org.apache.commons.lang.SystemUtils; import org.jetbrains.jet.plugin.PluginTestCaseBase; +import org.jetbrains.jet.testing.InTextDirectivesUtils; import java.io.File; @@ -30,33 +32,51 @@ import java.io.File; * @author Nikolay Krasko */ public class JetConfidenceTest extends LightCompletionTestCase { + private static final String TYPE_DIRECTIVE_PREFIX = "// TYPE:"; - public void testImportAsConfidence() { - doTest("as"); + public void testCompleteOnDotOutOfRanges() { + doTest(); } - public void testInModifierList() { - doTest("pub"); + public void testImportAsConfidence() { + doTest(); } public void testInBeginningOfFunctionLiteral() { - doTest("mm"); + doTest(); } public void testInBeginningOfFunctionLiteralInBrackets() { - doTest("mm"); + doTest(); } public void testInBlockOfFunctionLiteral() { - doTest("mm"); + doTest(); } - protected void doTest(String completionActivateType) { + public void testInModifierList() { + doTest(); + } + + public void testNoAutoCompletionForRangeOperator() { + doTest(); + } + + protected void doTest() { configureByFile(getBeforeFileName()); - type(completionActivateType + " "); + type(getTypeTextFromFile()); checkResultByFile(getAfterFileName()); } + protected static String getTypeTextFromFile() { + String text = getEditor().getDocument().getText(); + + String[] directives = InTextDirectivesUtils.findListWithPrefix(TYPE_DIRECTIVE_PREFIX, text); + assertEquals("One directive with \"" + TYPE_DIRECTIVE_PREFIX +"\" expected", 1, directives.length); + + return StringUtil.unquoteString(directives[0]); + } + protected String getBeforeFileName() { return getTestName(false) + ".kt"; } diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/CompletionHandlerTest.java b/idea/tests/org/jetbrains/jet/completion/handlers/CompletionHandlerTest.java index 8d08c5db676..f54728abc05 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/CompletionHandlerTest.java +++ b/idea/tests/org/jetbrains/jet/completion/handlers/CompletionHandlerTest.java @@ -38,6 +38,10 @@ public class CompletionHandlerTest extends LightCompletionTestCase { doTest(CompletionType.BASIC, 2, "SortedSet", null); } + public void testDoNotInsertImportForAlreadyImported() { + doTest(); + } + public void testNonStandardArray() { doTest(CompletionType.BASIC, 2, "Array", "java.lang.reflect"); } @@ -68,7 +72,7 @@ public class CompletionHandlerTest extends LightCompletionTestCase { doTest(); } - public void testSureInsert() { + public void testExtFunction() { doTest(); } diff --git a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java index 5da03038273..680920fedca 100644 --- a/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java +++ b/idea/tests/org/jetbrains/jet/formatter/JetFormatterTest.java @@ -60,6 +60,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTest(); } + public void testFunctionWithNewLineBrace() throws Exception { + doTest(); + } + public void testGetterAndSetter() throws Exception { doTest(); } @@ -112,6 +116,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest { doTestWithInvert(); } + public void testUnnecessarySpacesInParametersLists() throws Exception { + doTest(); + } + public void testWhen() throws Exception { doTest(); } diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/LibrariesWithSourcesTest.java b/idea/tests/org/jetbrains/jet/plugin/libraries/LibrariesWithSourcesTest.java index 2faf46854fd..c8e29f669f2 100644 --- a/idea/tests/org/jetbrains/jet/plugin/libraries/LibrariesWithSourcesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/LibrariesWithSourcesTest.java @@ -19,6 +19,7 @@ package org.jetbrains.jet.plugin.libraries; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; @@ -27,7 +28,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiReference; import com.intellij.util.containers.MultiMap; -import jet.Tuple2; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.plugin.references.JetPsiReference; @@ -116,13 +116,13 @@ public class LibrariesWithSourcesTest extends AbstractLibrariesTest { } private String getActualAnnotatedLibraryCode() { - MultiMap> filesToNumbersAndOffsets = new MultiMap>(); + MultiMap> filesToNumbersAndOffsets = new MultiMap>(); int refNumber = 1; for (JetPsiReference ref : collectInterestingReferences()) { PsiElement target = ref.resolve(); assertNotNull(target); PsiElement navigationElement = target.getNavigationElement(); - Tuple2 numberAndOffset = new Tuple2(refNumber++, navigationElement.getTextOffset()); + Pair numberAndOffset = new Pair(refNumber++, navigationElement.getTextOffset()); filesToNumbersAndOffsets.putValue(navigationElement.getContainingFile(), numberAndOffset); } @@ -140,27 +140,27 @@ public class LibrariesWithSourcesTest extends AbstractLibrariesTest { StringBuilder result = new StringBuilder(); for (PsiFile file : files) { - List> numbersAndOffsets = new ArrayList>(filesToNumbersAndOffsets.get(file)); + List> numbersAndOffsets = new ArrayList>(filesToNumbersAndOffsets.get(file)); - Collections.sort(numbersAndOffsets, Collections.reverseOrder(new Comparator>() { + Collections.sort(numbersAndOffsets, Collections.reverseOrder(new Comparator>() { @Override - public int compare(Tuple2 t1, Tuple2 t2) { - int offsets = t1._2.compareTo(t2._2); - return offsets == 0 ? t1._1.compareTo(t2._1) : offsets; + public int compare(Pair t1, Pair t2) { + int offsets = t1.second.compareTo(t2.second); + return offsets == 0 ? t1.first.compareTo(t2.first) : offsets; } })); Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file); assertNotNull(document); StringBuilder resultForFile = new StringBuilder(document.getText()); - for (Tuple2 numberOffset : numbersAndOffsets) { - resultForFile.insert(numberOffset._2, String.format("<%d>", numberOffset._1)); + for (Pair numberOffset : numbersAndOffsets) { + resultForFile.insert(numberOffset.second, String.format("<%d>", numberOffset.first)); } int minLine = Integer.MAX_VALUE; int maxLine = Integer.MIN_VALUE; - for (Tuple2 numberOffset : numbersAndOffsets) { - int lineNumber = document.getLineNumber(numberOffset._2); + for (Pair numberOffset : numbersAndOffsets) { + int lineNumber = document.getLineNumber(numberOffset.second); minLine = Math.min(minLine, lineNumber); maxLine = Math.max(maxLine, lineNumber); } diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/JetQuickFixTest.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/JetQuickFixTest.java index 7865a2d0186..15f9166d061 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/JetQuickFixTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/JetQuickFixTest.java @@ -130,11 +130,11 @@ public class JetQuickFixTest extends LightQuickFixTestCase { Collection diagnostics = exhaust.getBindingContext().getDiagnostics(); if (diagnostics.size() != 0) { - String[] expectedErrorStrings = InTextDirectivesUtils.findListWithPrefix("// ERROR:", getFile().getText()); + List expectedErrorStrings = InTextDirectivesUtils.findLinesWithPrefixRemoved("// ERROR:", getFile().getText()); System.out.println(getFile().getText()); - Collection expectedErrors = new HashSet(Arrays.asList(expectedErrorStrings)); + Collection expectedErrors = new HashSet(expectedErrorStrings); StringBuilder builder = new StringBuilder(); boolean hasErrors = false; diff --git a/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java b/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java index 7365213c9d5..f1dab9be946 100644 --- a/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/references/StandardLibraryReferenceResolverTest.java @@ -51,7 +51,11 @@ public class StandardLibraryReferenceResolverTest extends ResolveTestCase { doTest(); } - public void testSure() throws Exception { + public void testEquals() throws Exception { + doTest(); + } + + public void testToString() throws Exception { doTest(); } diff --git a/idea/tests/org/jetbrains/jet/testing/InTextDirectivesUtils.java b/idea/tests/org/jetbrains/jet/testing/InTextDirectivesUtils.java index e02397443dc..648c3503f6c 100644 --- a/idea/tests/org/jetbrains/jet/testing/InTextDirectivesUtils.java +++ b/idea/tests/org/jetbrains/jet/testing/InTextDirectivesUtils.java @@ -61,7 +61,7 @@ public final class InTextDirectivesUtils { } @NotNull - private static List findLinesWithPrefixRemoved(String prefix, String fileText) { + public static List findLinesWithPrefixRemoved(String prefix, String fileText) { ArrayList result = new ArrayList(); for (String line : fileNonEmptyLines(fileText)) { diff --git a/injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java b/injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java index a51bd899b0b..2a0d5691031 100644 --- a/injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java +++ b/injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java @@ -210,11 +210,9 @@ public class AllInjectorsGenerator { new GivenExpression("bindingTrace.getBindingContext()")); generator.addField(false, ClassBuilderMode.class, "classBuilderMode", new GivenExpression("classBuilderFactory.getClassBuilderMode()")); - generator.addPublicField(ClassCodegen.class); generator.addPublicField(ScriptCodegen.class); generator.addField(true, IntrinsicMethods.class, "intrinsics", null); generator.addPublicField(ClassFileFactory.class); - generator.addPublicField(MemberCodegen.class); generator.generate("compiler/backend/src", "org.jetbrains.jet.di", "InjectorForJvmCodegen"); } diff --git a/j2k/src/org/jetbrains/jet/j2k/Converter.java b/j2k/src/org/jetbrains/jet/j2k/Converter.java index 98ae433ccef..881488bf855 100644 --- a/j2k/src/org/jetbrains/jet/j2k/Converter.java +++ b/j2k/src/org/jetbrains/jet/j2k/Converter.java @@ -751,7 +751,7 @@ public class Converter { boolean containsQuestDot = expressionToExpression(expression).toKotlin().contains("?."); if (isPrimitiveTypeOrNull && isRef && containsQuestDot) { - conversion += ".sure()"; + conversion += "!!"; } if (actualType != null) { diff --git a/j2k/tests/testData/ast/issues/file/kt-809.kt b/j2k/tests/testData/ast/issues/file/kt-809.kt index 78932463e03..d31d733c260 100644 --- a/j2k/tests/testData/ast/issues/file/kt-809.kt +++ b/j2k/tests/testData/ast/issues/file/kt-809.kt @@ -13,7 +13,7 @@ open class Test() { open fun putInt(i : Int) : Unit { } open fun test() : Unit { -putInt((One.myContainer?.myInt).sure()) -IntContainer((One.myContainer?.myInt).sure()) +putInt((One.myContainer?.myInt)!!) +IntContainer((One.myContainer?.myInt)!!) } } \ No newline at end of file diff --git a/j2k/tests/testData/ast/issues/file/kt-820-field.kt b/j2k/tests/testData/ast/issues/file/kt-820-field.kt index 9ea09ce6370..5f9141abcc7 100644 --- a/j2k/tests/testData/ast/issues/file/kt-820-field.kt +++ b/j2k/tests/testData/ast/issues/file/kt-820-field.kt @@ -8,5 +8,5 @@ var myContainer : Container? = Container() } } open class Test() { -var b : Byte = One.myContainer?.myInt.sure().toByte() +var b : Byte = One.myContainer?.myInt!!.toByte() } \ No newline at end of file diff --git a/j2k/tests/testData/ast/issues/file/kt-820-string.kt b/j2k/tests/testData/ast/issues/file/kt-820-string.kt index 4e57eeda5ec..762e1aa8f90 100644 --- a/j2k/tests/testData/ast/issues/file/kt-820-string.kt +++ b/j2k/tests/testData/ast/issues/file/kt-820-string.kt @@ -1,7 +1,7 @@ open class Test() { class object { public open fun toFileSystemSafeName(name : String?) : String? { -var size : Int = name?.length().sure() +var size : Int = name?.length()!! return name } } diff --git a/j2k/tests/testData/ast/issues/file/kt-820.kt b/j2k/tests/testData/ast/issues/file/kt-820.kt index b9940817b8b..77fbee788f3 100644 --- a/j2k/tests/testData/ast/issues/file/kt-820.kt +++ b/j2k/tests/testData/ast/issues/file/kt-820.kt @@ -9,6 +9,6 @@ var myContainer : Container? = Container() } open class Test() { open fun test() : Unit { -var b : Byte = One.myContainer?.myInt.sure().toByte() +var b : Byte = One.myContainer?.myInt!!.toByte() } } \ No newline at end of file diff --git a/j2k/tests/testData/ast/issues/file/kt-824-isDir.kt b/j2k/tests/testData/ast/issues/file/kt-824-isDir.kt index 3ed40c7ecc3..488b6b79db6 100644 --- a/j2k/tests/testData/ast/issues/file/kt-824-isDir.kt +++ b/j2k/tests/testData/ast/issues/file/kt-824-isDir.kt @@ -8,7 +8,7 @@ if (parent == null || !parent?.exists()) return false } var result : Boolean = true -if (parent?.isDirectory().sure()) +if (parent?.isDirectory()!!) { return true } diff --git a/j2k/tests/testData/ast/issues/file/kt-824.kt b/j2k/tests/testData/ast/issues/file/kt-824.kt index 5059669b42a..065f372cb69 100644 --- a/j2k/tests/testData/ast/issues/file/kt-824.kt +++ b/j2k/tests/testData/ast/issues/file/kt-824.kt @@ -9,18 +9,18 @@ var myContainer : Container? = Container() } open class Test() { open fun test() : Unit { -if (One.myContainer?.myBoolean.sure()) +if (One.myContainer?.myBoolean!!) System.out?.println("Ok") -var s : String? = (if (One.myContainer?.myBoolean.sure()) +var s : String? = (if (One.myContainer?.myBoolean!!) "YES" else "NO") -while (One.myContainer?.myBoolean.sure()) +while (One.myContainer?.myBoolean!!) System.out?.println("Ok") do { System.out?.println("Ok") } -while (One.myContainer?.myBoolean.sure()) +while (One.myContainer?.myBoolean!!) } } \ No newline at end of file diff --git a/j2k/tests/testData/ast/issues/file/kt-837.kt b/j2k/tests/testData/ast/issues/file/kt-837.kt index 07834c5c81e..a04124924ea 100644 --- a/j2k/tests/testData/ast/issues/file/kt-837.kt +++ b/j2k/tests/testData/ast/issues/file/kt-837.kt @@ -3,7 +3,7 @@ import java.io.Serializable public open class Language(code : String?) : Serializable { protected var code : String? = null public open fun equals(other : Language?) : Boolean { -return other?.toString()?.equals(this.toString()).sure() +return other?.toString()?.equals(this.toString())!! } { this.code = code diff --git a/j2k/tests/testData/ast/issues/file/kt-852.kt b/j2k/tests/testData/ast/issues/file/kt-852.kt index 4e642d623ac..e6a3cb181f0 100644 --- a/j2k/tests/testData/ast/issues/file/kt-852.kt +++ b/j2k/tests/testData/ast/issues/file/kt-852.kt @@ -4,9 +4,9 @@ open fun test() : String? { var s1 : String? = "" var s2 : String? = "" var s3 : String? = "" -if ((s1?.isEmpty()).sure() && (s2?.isEmpty()).sure()) +if ((s1?.isEmpty())!! && (s2?.isEmpty())!!) return "OK" -if ((s1?.isEmpty()).sure() && (s2?.isEmpty()).sure() && (s3?.isEmpty()).sure()) +if ((s1?.isEmpty())!! && (s2?.isEmpty())!! && (s3?.isEmpty())!!) return "OOOK" return "" } diff --git a/jdk-annotations/java/io/annotations.xml b/jdk-annotations/java/io/annotations.xml new file mode 100644 index 00000000000..9c2cf79582b --- /dev/null +++ b/jdk-annotations/java/io/annotations.xml @@ -0,0 +1,767 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jdk-annotations/java/lang/annotations.xml b/jdk-annotations/java/lang/annotations.xml index 8b71cbfee98..9ec35489299 100644 --- a/jdk-annotations/java/lang/annotations.xml +++ b/jdk-annotations/java/lang/annotations.xml @@ -9,19 +9,743 @@ - + - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jdk-annotations/java/math/annotations.xml b/jdk-annotations/java/math/annotations.xml new file mode 100644 index 00000000000..cbb847292ef --- /dev/null +++ b/jdk-annotations/java/math/annotations.xml @@ -0,0 +1,533 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jdk-annotations/java/util/annotations.xml b/jdk-annotations/java/util/annotations.xml index fe4cdb61e10..ac63a9aa5f7 100644 --- a/jdk-annotations/java/util/annotations.xml +++ b/jdk-annotations/java/util/annotations.xml @@ -751,20 +751,536 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jdk-annotations/java/util/regex/annotations.xml b/jdk-annotations/java/util/regex/annotations.xml new file mode 100644 index 00000000000..3ded7a86028 --- /dev/null +++ b/jdk-annotations/java/util/regex/annotations.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js/js.libraries/src/core/string.kt b/js/js.libraries/src/core/string.kt index 6e803d81eca..25ec83bb81a 100644 --- a/js/js.libraries/src/core/string.kt +++ b/js/js.libraries/src/core/string.kt @@ -34,20 +34,20 @@ native public fun String.equalsIgnoreCase(anotherString: String) : Boolean = (th native public fun String.hashCode() : Int = (this as java.lang.String).hashCode() -native public fun String.replace(oldChar: Char, newChar : Char) : String = (this as java.lang.String).replace(oldChar, newChar).sure() +native public fun String.replace(oldChar: Char, newChar : Char) : String = (this as java.lang.String).replace(oldChar, newChar)!! -native public fun String.replaceAll(regex: String, replacement : String) : String = (this as java.lang.String).replaceAll(regex, replacement).sure() +native public fun String.replaceAll(regex: String, replacement : String) : String = (this as java.lang.String).replaceAll(regex, replacement)!! native public fun String.length() : Int = (this as java.lang.String).length() -native public fun String.getBytes() : ByteArray = (this as java.lang.String).getBytes().sure() +native public fun String.getBytes() : ByteArray = (this as java.lang.String).getBytes()!! -native public fun String.toCharArray() : CharArray = (this as java.lang.String).toCharArray().sure() +native public fun String.toCharArray() : CharArray = (this as java.lang.String).toCharArray()!! native public fun String.toCharList(): List = toCharArray().toList() -native public fun String.format(format : String, vararg args : Any?) : String = java.lang.String.format(format, args).sure() +native public fun String.format(format : String, vararg args : Any?) : String = java.lang.String.format(format, args)!! native public fun String.split(ch : Char) : Array = (this as java.lang.String).split(java.util.regex.Pattern.quote(ch.toString())) as Array @@ -84,48 +84,48 @@ native public fun String(stringBuffer : java.lang.StringBuffer) : String = java. native public fun String(stringBuilder : java.lang.StringBuilder) : String = java.lang.String(stringBuilder) as String -native public fun String.replaceFirst(regex : String, replacement : String) : String = (this as java.lang.String).replaceFirst(regex, replacement).sure() +native public fun String.replaceFirst(regex : String, replacement : String) : String = (this as java.lang.String).replaceFirst(regex, replacement)!! -native public fun String.split(regex : String, limit : Int) : Array = (this as java.lang.String).split(regex, limit).sure() +native public fun String.split(regex : String, limit : Int) : Array = (this as java.lang.String).split(regex, limit)!! -native public fun String.codePointAt(index : Int) : Int = (this as java.lang.String).codePointAt(index).sure() +native public fun String.codePointAt(index : Int) : Int = (this as java.lang.String).codePointAt(index)!! -native public fun String.codePointBefore(index : Int) : Int = (this as java.lang.String).codePointBefore(index).sure() +native public fun String.codePointBefore(index : Int) : Int = (this as java.lang.String).codePointBefore(index)!! native public fun String.codePointCount(beginIndex : Int, endIndex : Int) : Int = (this as java.lang.String).codePointCount(beginIndex, endIndex) -native public fun String.compareToIgnoreCase(str : String) : Int = (this as java.lang.String).compareToIgnoreCase(str).sure() +native public fun String.compareToIgnoreCase(str : String) : Int = (this as java.lang.String).compareToIgnoreCase(str)!! -native public fun String.contentEquals(cs : CharSequence) : Boolean = (this as java.lang.String).contentEquals(cs).sure() +native public fun String.contentEquals(cs : CharSequence) : Boolean = (this as java.lang.String).contentEquals(cs)!! -native public fun String.contentEquals(sb : StringBuffer) : Boolean = (this as java.lang.String).contentEquals(sb).sure() +native public fun String.contentEquals(sb : StringBuffer) : Boolean = (this as java.lang.String).contentEquals(sb)!! -native public fun String.getBytes(charset : java.nio.charset.Charset) : ByteArray = (this as java.lang.String).getBytes(charset).sure() +native public fun String.getBytes(charset : java.nio.charset.Charset) : ByteArray = (this as java.lang.String).getBytes(charset)!! -native public fun String.getBytes(charsetName : String) : ByteArray = (this as java.lang.String).getBytes(charsetName).sure() +native public fun String.getBytes(charsetName : String) : ByteArray = (this as java.lang.String).getBytes(charsetName)!! -native public fun String.getChars(srcBegin : Int, srcEnd : Int, dst : CharArray, dstBegin : Int) : Tuple0 = (this as java.lang.String).getChars(srcBegin, srcEnd, dst, dstBegin).sure() +native public fun String.getChars(srcBegin : Int, srcEnd : Int, dst : CharArray, dstBegin : Int) : Tuple0 = (this as java.lang.String).getChars(srcBegin, srcEnd, dst, dstBegin)!! -native public fun String.intern() : String = (this as java.lang.String).intern().sure() +native public fun String.intern() : String = (this as java.lang.String).intern()!! -native public fun String.isEmpty() : Boolean = (this as java.lang.String).isEmpty().sure() +native public fun String.isEmpty() : Boolean = (this as java.lang.String).isEmpty()!! -native public fun String.offsetByCodePoints(index : Int, codePointOffset : Int) : Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset).sure() +native public fun String.offsetByCodePoints(index : Int, codePointOffset : Int) : Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset)!! -native public fun String.regionMatches(ignoreCase : Boolean, toffset : Int, other : String, ooffset : Int, len : Int) : Boolean = (this as java.lang.String).regionMatches(ignoreCase, toffset, other, ooffset, len).sure() +native public fun String.regionMatches(ignoreCase : Boolean, toffset : Int, other : String, ooffset : Int, len : Int) : Boolean = (this as java.lang.String).regionMatches(ignoreCase, toffset, other, ooffset, len)!! -native public fun String.regionMatches(toffset : Int, other : String, ooffset : Int, len : Int) : Boolean = (this as java.lang.String).regionMatches(toffset, other, ooffset, len).sure() +native public fun String.regionMatches(toffset : Int, other : String, ooffset : Int, len : Int) : Boolean = (this as java.lang.String).regionMatches(toffset, other, ooffset, len)!! -native public fun String.replace(target : CharSequence, replacement : CharSequence) : String = (this as java.lang.String).replace(target, replacement).sure() +native public fun String.replace(target : CharSequence, replacement : CharSequence) : String = (this as java.lang.String).replace(target, replacement)!! -native public fun String.subSequence(beginIndex : Int, endIndex : Int) : CharSequence = (this as java.lang.String).subSequence(beginIndex, endIndex).sure() +native public fun String.subSequence(beginIndex : Int, endIndex : Int) : CharSequence = (this as java.lang.String).subSequence(beginIndex, endIndex)!! -native public fun String.toLowerCase(locale : java.util.Locale) : String = (this as java.lang.String).toLowerCase(locale).sure() +native public fun String.toLowerCase(locale : java.util.Locale) : String = (this as java.lang.String).toLowerCase(locale)!! -native public fun String.toUpperCase(locale : java.util.Locale) : String = (this as java.lang.String).toUpperCase(locale).sure() +native public fun String.toUpperCase(locale : java.util.Locale) : String = (this as java.lang.String).toUpperCase(locale)!! native public fun CharSequence.charAt(index : Int) : Char = (this as java.lang.CharSequence).charAt(index) @@ -140,21 +140,21 @@ native public fun CharSequence.toString() : String? = (this as java.lang.CharSeq native public fun String.toByteArray(encoding: String?=null):ByteArray { if(encoding==null) { - return (this as java.lang.String).getBytes().sure() + return (this as java.lang.String).getBytes()!! } else { - return (this as java.lang.String).getBytes(encoding).sure() + return (this as java.lang.String).getBytes(encoding)!! } } -native public fun String.toByteArray(encoding: java.nio.charset.Charset):ByteArray = (this as java.lang.String).getBytes(encoding).sure() +native public fun String.toByteArray(encoding: java.nio.charset.Charset):ByteArray = (this as java.lang.String).getBytes(encoding)!! -native public fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this).sure() -native public fun String.toShort() : Short = java.lang.Short.parseShort(this).sure() -native public fun String.toInt() : Int = java.lang.Integer.parseInt(this).sure() -native public fun String.toLong() : Long = java.lang.Long.parseLong(this).sure() -native public fun String.toFloat() : Float = java.lang.Float.parseFloat(this).sure() -native public fun String.toDouble() : Double = java.lang.Double.parseDouble(this).sure() +native public fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this)!! +native public fun String.toShort() : Short = java.lang.Short.parseShort(this)!! +native public fun String.toInt() : Int = java.lang.Integer.parseInt(this)!! +native public fun String.toLong() : Long = java.lang.Long.parseLong(this)!! +native public fun String.toFloat() : Float = java.lang.Float.parseFloat(this)!! +native public fun String.toDouble() : Double = java.lang.Double.parseDouble(this)!! native public fun String.toRegex(flags: Int=0): java.util.regex.Pattern { - return java.util.regex.Pattern.compile(this, flags).sure() + return java.util.regex.Pattern.compile(this, flags)!! } */ \ No newline at end of file diff --git a/js/js.tests/test/org/jetbrains/k2js/test/semantics/TupleTest.java b/js/js.tests/test/org/jetbrains/k2js/test/semantics/TupleTest.java deleted file mode 100644 index b938748fe17..00000000000 --- a/js/js.tests/test/org/jetbrains/k2js/test/semantics/TupleTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.k2js.test.semantics; - -import org.jetbrains.k2js.test.SingleFileTranslationTest; - -/** - * @author Pavel Talanov - */ -public final class TupleTest extends SingleFileTranslationTest { - - - public TupleTest() { - super("tuple/"); - } - - public void testTwoElements() throws Exception { - fooBoxTest(); - } - - public void testMultipleMembers() throws Exception { - fooBoxTest(); - } - - public void testTuplesEquals() throws Exception { - fooBoxTest(); - } - - -} - diff --git a/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java b/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java index 2dba34b18cc..8116f783dbf 100644 --- a/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java +++ b/js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java @@ -29,6 +29,9 @@ import org.jetbrains.jet.lang.ModuleConfiguration; import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.*; +import org.jetbrains.jet.lang.resolve.lazy.FileBasedDeclarationProviderFactory; +import org.jetbrains.jet.lang.resolve.lazy.ResolveSession; +import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.k2js.config.Config; @@ -136,4 +139,12 @@ public final class AnalyzerFacadeForJS { } }; } + + @NotNull + public static ResolveSession getLazyResolveSession(Collection files, final Config config) { + FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory( + Config.withJsLibAdded(files, config), Predicates.alwaysFalse()); + ModuleDescriptor lazyModule = new ModuleDescriptor(Name.special("")); + return new ResolveSession(config.getProject(), lazyModule, new JsConfiguration(config.getProject(), null), declarationProviderFactory); + } } diff --git a/js/js.translator/src/org/jetbrains/k2js/analyze/JsConfiguration.java b/js/js.translator/src/org/jetbrains/k2js/analyze/JsConfiguration.java index 792b542e7f3..916ca121c6d 100644 --- a/js/js.translator/src/org/jetbrains/k2js/analyze/JsConfiguration.java +++ b/js/js.translator/src/org/jetbrains/k2js/analyze/JsConfiguration.java @@ -21,8 +21,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode; import org.jetbrains.jet.lang.DefaultModuleConfiguration; -import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.ModuleConfiguration; +import org.jetbrains.jet.lang.PlatformToKotlinClassMap; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.psi.JetImportDirective; import org.jetbrains.jet.lang.psi.JetPsiFactory; @@ -31,8 +31,10 @@ import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.ImportPath; import org.jetbrains.jet.lang.resolve.name.FqName; +import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.types.lang.JetStandardClasses; +import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import java.util.Arrays; import java.util.Collection; @@ -43,13 +45,15 @@ import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isRootNamespace; /** * @author Pavel Talanov */ -public final class JsConfiguration implements ModuleConfiguration { +public class JsConfiguration implements ModuleConfiguration { @NotNull - private static final List DEFAULT_IMPORT_PATHS = Arrays.asList(new ImportPath("js.*"), new ImportPath("java.lang.*"), - new ImportPath(JetStandardClasses.STANDARD_CLASSES_FQNAME, - true), - new ImportPath("kotlin.*")); + public static final List DEFAULT_IMPORT_PATHS = Arrays.asList( + new ImportPath("js.*"), + new ImportPath("java.lang.*"), + new ImportPath(JetStandardClasses.STANDARD_CLASSES_FQNAME, true), + new ImportPath("kotlin.*")); + @NotNull private final Project project; /* @@ -75,6 +79,12 @@ public final class JsConfiguration implements ModuleConfiguration { @NotNull WritableScope namespaceMemberScope) { DefaultModuleConfiguration.createStandardConfiguration(project, BuiltinsScopeExtensionMode.ALL) .extendNamespaceScope(trace, namespaceDescriptor, namespaceMemberScope); + + // Extend root namespace with standard classes + if (namespaceDescriptor.getQualifiedName().shortNameOrSpecial().equals(FqNameUnsafe.ROOT_NAME)) { + namespaceMemberScope.importScope(JetStandardLibrary.getInstance().getLibraryScope()); + } + if (hasPreanalyzedContextForTests()) { extendScopeWithPreAnalyzedContextForTests(namespaceDescriptor, namespaceMemberScope); } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/context/StandardClasses.java b/js/js.translator/src/org/jetbrains/k2js/translate/context/StandardClasses.java index ee81cae0fc2..466c23be6a1 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/context/StandardClasses.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/context/StandardClasses.java @@ -105,8 +105,6 @@ public final class StandardClasses { standardClasses.declare().forFQ("jet.IntRange").kotlinClass("NumberRange") .methods("iterator", "contains").properties("start", "size", "end", "reversed"); - standardClasses.declare().forFQ("jet.sure").kotlinFunction("sure"); - standardClasses.declare().forFQ("jet.Any.toString").kotlinFunction("toString"); standardClasses.declare().forFQ("java.util.Collections..max").kotlinFunction("collectionsMax"); diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/expression/ExpressionVisitor.java b/js/js.translator/src/org/jetbrains/k2js/translate/expression/ExpressionVisitor.java index 90e15ae8bb6..6e3dc47c44a 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/expression/ExpressionVisitor.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/expression/ExpressionVisitor.java @@ -353,17 +353,6 @@ public final class ExpressionVisitor extends TranslatorVisitor { return TryTranslator.translate(expression, context); } - @Override - @NotNull - public JsNode visitTupleExpression(@NotNull JetTupleExpression expression, - @NotNull TranslationContext context) { - JsArrayLiteral result = new JsArrayLiteral(); - for (JetExpression entry : expression.getEntries()) { - result.getExpressions().add(translateAsExpression(entry, context)); - } - return result; - } - @Override @NotNull public JsNode visitThrowExpression(@NotNull JetThrowExpression expression, diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java index c1a1c02d2d6..55070d993e4 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/FunctionIntrinsics.java @@ -45,7 +45,6 @@ public final class FunctionIntrinsics { private void registerFactories() { register(PrimitiveUnaryOperationFIF.INSTANCE); register(PrimitiveBinaryOperationFIF.INSTANCE); - register(TupleGetterFIF.INSTANCE); register(StringOperationFIF.INSTANCE); register(ArrayFIF.INSTANCE); register(TopLevelFIF.INSTANCE); diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/TupleGetterFIF.java b/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/TupleGetterFIF.java deleted file mode 100644 index 70e9bf75fd8..00000000000 --- a/js/js.translator/src/org/jetbrains/k2js/translate/intrinsic/functions/factories/TupleGetterFIF.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.k2js.translate.intrinsic.functions.factories; - -import com.google.common.base.Predicate; -import com.google.common.collect.Lists; -import com.google.dart.compiler.backend.js.ast.JsArrayAccess; -import com.google.dart.compiler.backend.js.ast.JsExpression; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; -import org.jetbrains.jet.lang.types.lang.JetStandardClasses; -import org.jetbrains.k2js.translate.context.TranslationContext; -import org.jetbrains.k2js.translate.intrinsic.functions.basic.FunctionIntrinsic; -import org.jetbrains.k2js.translate.intrinsic.functions.patterns.NamePredicate; -import org.jetbrains.k2js.translate.intrinsic.functions.patterns.PatternBuilder; - -import java.util.List; - -/** - * @author Pavel Talanov - */ -public enum TupleGetterFIF implements FunctionIntrinsicFactory { - INSTANCE; - - @NotNull - private static final NamePredicate TUPLES; - - static { - List tupleNames = Lists.newArrayList(); - for (int tupleSize = 0; tupleSize <= JetStandardClasses.MAX_TUPLE_ORDER; ++tupleSize) { - tupleNames.add("Tuple" + tupleSize); - } - TUPLES = new NamePredicate(tupleNames); - } - - @NotNull - private static final NamePredicate TUPLE_UNDERSCORE_ACCESSORS; - - static { - List accessorNames = Lists.newArrayList(); - for (int tupleSize = 0; tupleSize <= JetStandardClasses.MAX_TUPLE_ORDER; ++tupleSize) { - accessorNames.add(""); - } - TUPLE_UNDERSCORE_ACCESSORS = new NamePredicate(accessorNames); - } - - @NotNull - @Override - public Predicate getPredicate() { - return PatternBuilder.pattern(TUPLES, TUPLE_UNDERSCORE_ACCESSORS); - } - - @NotNull - @Override - public FunctionIntrinsic getIntrinsic(@NotNull FunctionDescriptor descriptor) { - String nameString = descriptor.getName().getName(); - String elementIndexSubString = nameString.substring(6, nameString.length() - 1); - final int elementIndex = Integer.parseInt(elementIndexSubString) - 1; - return new FunctionIntrinsic() { - @NotNull - @Override - public JsExpression apply(@Nullable JsExpression receiver, - @NotNull List arguments, - @NotNull TranslationContext context) { - assert arguments.isEmpty() : "Tuple access expression should not have any arguments."; - return new JsArrayAccess(receiver, context.program().getNumberLiteral(elementIndex)); - } - }; - } -} \ No newline at end of file diff --git a/js/js.translator/testFiles/additional/cases/defaultargs2.jet b/js/js.translator/testFiles/additional/cases/defaultargs2.jet index 0c708f35dd8..f780965ad43 100644 --- a/js/js.translator/testFiles/additional/cases/defaultargs2.jet +++ b/js/js.translator/testFiles/additional/cases/defaultargs2.jet @@ -1,3 +1,18 @@ +class T4( + val c1: Boolean, + val c2: Boolean, + val c3: Boolean, + val c4: String +) { + fun equals(o: Any?): Boolean { + if (o !is T4) return false; + return c1 == o.c1 && + c2 == o.c2 && + c3 == o.c3 && + c4 == o.c4 + } +} + fun reformat( str : String, normalizeCase : Boolean = true, @@ -5,11 +20,11 @@ fun reformat( divideByCamelHumps : Boolean = true, wordSeparator : String = " " ) = - #(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator) + T4(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator) fun box() : String { - val expected = #(true, true, true, " ") + val expected = T4(true, true, true, " ") if(reformat("", true, true, true, " ") != expected) return "fail1" if(reformat("", true, true, true) != expected) return "fail2" if(reformat("", true, true) != expected) return "fail3" diff --git a/js/js.translator/testFiles/tuple/cases/multipleMembers.kt b/js/js.translator/testFiles/tuple/cases/multipleMembers.kt deleted file mode 100644 index 3bf9c6eb000..00000000000 --- a/js/js.translator/testFiles/tuple/cases/multipleMembers.kt +++ /dev/null @@ -1,15 +0,0 @@ -package foo - -fun box() : Boolean { - if (#(1, 2, 3)._1 != 1) return false; - if (#("a", "b")._2 != "b") return false; - val x = #("1", 2, "3", 4, "5", 6); - if (x._1 != "1") return false; - if (x._2 != 2) return false; - if (x._2 != 2) return false; - if (x._6 != 6) return false; - if (x._5 != "5") return false; - if (x._3 != "3") return false; - if (#(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)._21 != 1) return false; - return true; -} \ No newline at end of file diff --git a/js/js.translator/testFiles/tuple/cases/tuplesEquals.kt b/js/js.translator/testFiles/tuple/cases/tuplesEquals.kt deleted file mode 100644 index 8768ee0e43c..00000000000 --- a/js/js.translator/testFiles/tuple/cases/tuplesEquals.kt +++ /dev/null @@ -1,31 +0,0 @@ -package foo - -class A(val i: Int = 2) { - fun equals(other: Any?): Boolean { - if (other !is A) { - return false - } - return i % 2 == other.i % 2 - } -} - -fun box(): Boolean { - val c = #(3, 1) - if (c != #(3, 1)) { - return false - } - if (c == #(1, 3)) { - return false - } - val b = #(A(2), A(1)) - if (b != #(A(0), A(3))) { - return false - } - if (b == #(A(2), A(4))) { - return false - } - if (#("aaa") != #("aaa")) { - return false - } - return true -} diff --git a/js/js.translator/testFiles/tuple/cases/twoElements.kt b/js/js.translator/testFiles/tuple/cases/twoElements.kt deleted file mode 100644 index d0ab07e1916..00000000000 --- a/js/js.translator/testFiles/tuple/cases/twoElements.kt +++ /dev/null @@ -1,6 +0,0 @@ -package foo - -fun box() : Boolean { - val a : #(Int, Int) = #(1, 2) - return ((a._1 == 1) && (a._2 == 2)) - } \ No newline at end of file diff --git a/js/js.translator/testFiles/webDemoCanvasExamples/cases/Creatures.kt b/js/js.translator/testFiles/webDemoCanvasExamples/cases/Creatures.kt index c91e2484624..d61088a405d 100644 --- a/js/js.translator/testFiles/webDemoCanvasExamples/cases/Creatures.kt +++ b/js/js.translator/testFiles/webDemoCanvasExamples/cases/Creatures.kt @@ -156,7 +156,7 @@ class Creature(override var pos: Vector, val state: CanvasState): Shape() { val gradientCentre = position + directionToLogo * (radius / 4) val gradient = context.createRadialGradient(gradientCentre.x, gradientCentre.y, 1.0, gradientCentre.x, gradientCentre.y, 2 * radius)!! for (colorStop in colorStops) { - gradient.addColorStop(colorStop._1, colorStop._2) + gradient.addColorStop(colorStop.first, colorStop.second) } return gradient } @@ -226,14 +226,14 @@ class CanvasState(val canvas: HTMLCanvasElement) { jq(canvas).mousemove { if (selection != null) { - selection.sure().pos = mousePos(it) - dragOff + selection!!.pos = mousePos(it) - dragOff valid = false } } jq(canvas).mouseup { if (selection != null) { - selection.sure().selected = false + selection!!.selected = false } selection = null valid = false @@ -254,7 +254,7 @@ class CanvasState(val canvas: HTMLCanvasElement) { var offset = Vector() var element: HTMLElement? = canvas while (element != null) { - val el: HTMLElement = element.sure() + val el: HTMLElement = element!! offset += Vector(el.offsetLeft, el.offsetTop) element = el.offsetParent } @@ -287,23 +287,23 @@ class CanvasState(val canvas: HTMLCanvasElement) { } class RadialGradientGenerator(val context: CanvasContext) { - val gradients = ArrayList>() + val gradients = ArrayList>>() var current = 0 - fun newColorStops(vararg colorStops: #(Double, String)) { + fun newColorStops(vararg colorStops: Pair) { gradients.add(colorStops) } { - newColorStops(#(0.0, "#F59898"), #(0.5, "#F57373"), #(1.0, "#DB6B6B")) - newColorStops(#(0.39, "rgb(140,167,209)"), #(0.7, "rgb(104,139,209)"), #(0.85, "rgb(67,122,217)")) - newColorStops(#(0.0, "rgb(255,222,255)"), #(0.5, "rgb(255,185,222)"), #(1.0, "rgb(230,154,185)")) - newColorStops(#(0.0, "rgb(255,209,114)"), #(0.5, "rgb(255,174,81)"), #(1.0, "rgb(241,145,54)")) - newColorStops(#(0.0, "rgb(132,240,135)"), #(0.5, "rgb(91,240,96)"), #(1.0, "rgb(27,245,41)")) - newColorStops(#(0.0, "rgb(250,147,250)"), #(0.5, "rgb(255,80,255)"), #(1.0, "rgb(250,0,217)")) + newColorStops(Pair(0.0, "#F59898"), Pair(0.5, "#F57373"), Pair(1.0, "#DB6B6B")) + newColorStops(Pair(0.39, "rgb(140,167,209)"), Pair(0.7, "rgb(104,139,209)"), Pair(0.85, "rgb(67,122,217)")) + newColorStops(Pair(0.0, "rgb(255,222,255)"), Pair(0.5, "rgb(255,185,222)"), Pair(1.0, "rgb(230,154,185)")) + newColorStops(Pair(0.0, "rgb(255,209,114)"), Pair(0.5, "rgb(255,174,81)"), Pair(1.0, "rgb(241,145,54)")) + newColorStops(Pair(0.0, "rgb(132,240,135)"), Pair(0.5, "rgb(91,240,96)"), Pair(1.0, "rgb(27,245,41)")) + newColorStops(Pair(0.0, "rgb(250,147,250)"), Pair(0.5, "rgb(255,80,255)"), Pair(1.0, "rgb(250,0,217)")) } - fun getNext(): Array<#(Double, String)> { + fun getNext(): Array> { val result = gradients.get(current) current = (current + 1) % gradients.size() return result diff --git a/js/js.translator/testFiles/webDemoCanvasExamples/cases/Traffic light.kt b/js/js.translator/testFiles/webDemoCanvasExamples/cases/Traffic light.kt index 35c31895899..eabc4564391 100644 --- a/js/js.translator/testFiles/webDemoCanvasExamples/cases/Traffic light.kt +++ b/js/js.translator/testFiles/webDemoCanvasExamples/cases/Traffic light.kt @@ -430,7 +430,7 @@ class CanvasState(val canvas: HTMLCanvasElement) { var offset = Vector() var element: HTMLElement? = canvas while (element != null) { - val el: HTMLElement = element.sure() + val el: HTMLElement = element!! offset += Vector(el.offsetLeft, el.offsetTop) element = el.offsetParent } diff --git a/js/js.translator/testFiles/webDemoExamples2/cases/builder.kt b/js/js.translator/testFiles/webDemoExamples2/cases/builder.kt index 2bae4e90e95..78cab743d76 100644 --- a/js/js.translator/testFiles/webDemoExamples2/cases/builder.kt +++ b/js/js.translator/testFiles/webDemoExamples2/cases/builder.kt @@ -128,7 +128,7 @@ class P() : BodyTag("p") class H1() : BodyTag("h1") class A() : BodyTag("a") { public var href : String - get() = attributes["href"].sure() + get() = attributes["href"]!! set(value) { attributes["href"] = value } diff --git a/js/js.translator/testFiles/webDemoExamples2/cases/life.kt b/js/js.translator/testFiles/webDemoExamples2/cases/life.kt index a525dc79193..6f1da594f5a 100644 --- a/js/js.translator/testFiles/webDemoExamples2/cases/life.kt +++ b/js/js.translator/testFiles/webDemoExamples2/cases/life.kt @@ -139,7 +139,7 @@ fun makeField(s : String) : Field { val l1 : Int = o1.size val l2 = o2.size l1 - l2 - }).sure() + })!! val data = Array(lines.size) {Array(w.size) {false}} // workaround @@ -160,7 +160,7 @@ fun makeField(s : String) : Field { } // An excerpt from the Standard Library -val String?.indices : IntRange get() = IntRange(0, this.sure().size) +val String?.indices : IntRange get() = IntRange(0, this!!.size) fun MutableMap.set(k : K, v : V) { put(k, v) } diff --git a/js/js.translator/testFiles/webDemoExamples2/cases/maze.kt b/js/js.translator/testFiles/webDemoExamples2/cases/maze.kt index 4467dee98a8..52d86463ef9 100644 --- a/js/js.translator/testFiles/webDemoExamples2/cases/maze.kt +++ b/js/js.translator/testFiles/webDemoExamples2/cases/maze.kt @@ -171,12 +171,12 @@ fun printMaze(str : String) { * OOOOOOOOOOOOOOOOO */ fun makeMaze(s : String) : Maze { - val lines = s.split("\n").sure() + val lines = s.split("\n")!! val w = max(lines.toList(), comparator {o1, o2 -> val l1 : Int = o1?.size ?: 0 val l2 = o2?.size ?: 0 l1 - l2 - }).sure() + })!! val data = Array>(lines.size) {Array(w.size) {false}} var start : #(Int, Int)? = null @@ -184,7 +184,7 @@ fun makeMaze(s : String) : Maze { for (line in lines.indices) { for (x in lines[line].indices) { - val c = lines[line].sure()[x] + val c = lines[line]!![x] data[line][x] = c == 'O' when (c) { 'I' -> start = #(line, x) @@ -202,12 +202,12 @@ fun makeMaze(s : String) : Maze { throw IllegalArgumentException("No goal point in the maze (should be indicated with a '$' sign)") } - return Maze(w.size, lines.size, data, start.sure(), end.sure()) + return Maze(w.size, lines.size, data, start!!, end!!) } // An excerpt from the Standard Library -val String?.indices : IntRange get() = IntRange(0, this.sure().size) +val String?.indices : IntRange get() = IntRange(0, this!!.size) fun Map.set(k : K, v : V) { put(k, v) } diff --git a/libraries/docs/website/src/main/kotlin/org/jetbrains/kotlin/site/SiteGenerator.kt b/libraries/docs/website/src/main/kotlin/org/jetbrains/kotlin/site/SiteGenerator.kt index 0b9bc52b829..b73b3cd51c5 100644 --- a/libraries/docs/website/src/main/kotlin/org/jetbrains/kotlin/site/SiteGenerator.kt +++ b/libraries/docs/website/src/main/kotlin/org/jetbrains/kotlin/site/SiteGenerator.kt @@ -29,7 +29,7 @@ class SiteGenerator(val sourceDir: File, val outputDir: File) : Runnable { val outFile = File(outputDir, relativePath) outFile.directory.mkdirs() if (output != null) { - val text = layout(relativePath, it, output.sure()) + val text = layout(relativePath, it, output!!) outFile.writeText(text) } else { it.copyTo(outFile) diff --git a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Connections.kt b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Connections.kt index 6f3afc5e18f..641e528e2fd 100644 --- a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Connections.kt +++ b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/Connections.kt @@ -8,7 +8,7 @@ import java.util.Properties /** * create connection for the specified jdbc url with no credentials */ -fun getConnection(url : String) : Connection = DriverManager.getConnection(url).sure() +fun getConnection(url : String) : Connection = DriverManager.getConnection(url)!! /** * create connection for the specified jdbc url and properties diff --git a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/ResultSets.kt b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/ResultSets.kt index 55689978d74..877d5b341a7 100644 --- a/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/ResultSets.kt +++ b/libraries/kotlin-jdbc/src/main/kotlin/kotlin/jdbc/ResultSets.kt @@ -47,7 +47,7 @@ fun ResultSet.map(fn : (ResultSet) -> T) : jet.Iterable { * Returns array with column names */ fun ResultSet.getColumnNames() : jet.Array { - val meta = getMetaData().sure() + val meta = getMetaData()!! return jet.Array(meta.getColumnCount(), {meta.getColumnName(it + 1) ?: it.toString()}) } diff --git a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Frames.kt b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Frames.kt index ec43b266d2b..f2ca4004063 100644 --- a/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Frames.kt +++ b/libraries/kotlin-swing/src/main/kotlin/kotlin/swing/Frames.kt @@ -25,25 +25,25 @@ var JFrame.contentPane: Container? } var JFrame.title: String - get() = getTitle().sure() + get() = getTitle()!! set(t) { setTitle(t) } var JFrame.size: Pair - get() = Pair(getSize().sure().getWidth().toInt(), getSize().sure().getHeight().toInt()) + get() = Pair(getSize()!!.getWidth().toInt(), getSize()!!.getHeight().toInt()) set(dim) { setSize(Dimension(dim.first, dim.second)) } var JFrame.height: Int - get() = getSize().sure().getHeight().toInt() + get() = getSize()!!.getHeight().toInt() set(h) { setSize(width, h) } var JFrame.width: Int - get() = getSize().sure().getWidth().toInt() + get() = getSize()!!.getWidth().toInt() set(w) { setSize(height, w) } diff --git a/libraries/sandbox/extensionTraits/src/kotlin2/Iterators.kt b/libraries/sandbox/extensionTraits/src/kotlin2/Iterators.kt index bda69c9d7bb..50b7c304425 100644 --- a/libraries/sandbox/extensionTraits/src/kotlin2/Iterators.kt +++ b/libraries/sandbox/extensionTraits/src/kotlin2/Iterators.kt @@ -102,14 +102,14 @@ public abstract class AbstractIterator: Iterator { override fun next(): T { if (!hasNext) throw NoSuchElementException() state = State.NotReady - return next.sure() + return next!! } /** Returns the next element in the iteration without advancing the iteration */ fun peek(): T { if (!hasNext) throw NoSuchElementException() - return next.sure(); + return next!!; } private fun tryToComputeNext(): Boolean { diff --git a/libraries/sandbox/extensionTraits/src/kotlin2/Traversable.kt b/libraries/sandbox/extensionTraits/src/kotlin2/Traversable.kt index 902e86c03f3..881eb244175 100644 --- a/libraries/sandbox/extensionTraits/src/kotlin2/Traversable.kt +++ b/libraries/sandbox/extensionTraits/src/kotlin2/Traversable.kt @@ -201,7 +201,7 @@ public trait Traversable: Iterable { public inline fun makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { val buffer = StringBuilder() appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString().sure() + return buffer.toString()!! } /** Returns a list containing the everything but the first elements that satisfy the given *predicate* */ diff --git a/libraries/sandbox/templatelib/src/TemplateHtml.kt b/libraries/sandbox/templatelib/src/TemplateHtml.kt index 5d34c5cdf14..6a0f23a1e67 100644 --- a/libraries/sandbox/templatelib/src/TemplateHtml.kt +++ b/libraries/sandbox/templatelib/src/TemplateHtml.kt @@ -65,7 +65,7 @@ abstract class Tag(val name : String) : Element() { fun toString(): String { val builder = StringBuilder() appendTo(builder) - return builder.toString().sure() + return builder.toString()!! } } diff --git a/libraries/sandbox/templatelib/src/TemplateJavaIo.kt b/libraries/sandbox/templatelib/src/TemplateJavaIo.kt index 7941dd93c0d..2c45150e986 100644 --- a/libraries/sandbox/templatelib/src/TemplateJavaIo.kt +++ b/libraries/sandbox/templatelib/src/TemplateJavaIo.kt @@ -23,7 +23,7 @@ class WriterPrinter(val writer: Writer) : Printer { fun Template.renderToText(): String { val buffer = StringWriter() renderTo(buffer) - return buffer.toString().sure() + return buffer.toString()!! } fun Template.renderTo(writer: Writer): Unit { diff --git a/libraries/stdlib/src/generated/ArraysFromIterables.kt b/libraries/stdlib/src/generated/ArraysFromIterables.kt index f3b4db871ee..71a736dae05 100644 --- a/libraries/stdlib/src/generated/ArraysFromIterables.kt +++ b/libraries/stdlib/src/generated/ArraysFromIterables.kt @@ -172,7 +172,7 @@ public inline fun Array.foldRight(initial: T, operation: (T, T) -> T): T * @includeFunctionBody ../../test/CollectionTest.kt reduce */ public inline fun Array.reduce(operation: (T, T) -> T): T { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun Array.groupByTo(result: MutableMap public inline fun Array.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { val buffer = StringBuilder() appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString().sure() + return buffer.toString()!! } /** Returns a list containing the everything but the first elements that satisfy the given *predicate* */ diff --git a/libraries/stdlib/src/generated/BooleanArraysFromIterables.kt b/libraries/stdlib/src/generated/BooleanArraysFromIterables.kt index 70609b187d6..f75ce70c6f8 100644 --- a/libraries/stdlib/src/generated/BooleanArraysFromIterables.kt +++ b/libraries/stdlib/src/generated/BooleanArraysFromIterables.kt @@ -172,7 +172,7 @@ public inline fun BooleanArray.foldRight(initial: Boolean, operation: (Boolean, * @includeFunctionBody ../../test/CollectionTest.kt reduce */ public inline fun BooleanArray.reduce(operation: (Boolean, Boolean) -> Boolean): Boolean { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun BooleanArray.groupByTo(result: MutableMap * @includeFunctionBody ../../test/CollectionTest.kt reduce */ public inline fun ByteArray.reduce(operation: (Byte, Byte) -> Byte): Byte { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun ByteArray.groupByTo(result: MutableMap * @includeFunctionBody ../../test/CollectionTest.kt reduce */ public inline fun CharArray.reduce(operation: (Char, Char) -> Char): Char { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun CharArray.groupByTo(result: MutableMap Double): Double { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun DoubleArray.groupByTo(result: MutableMap Float): Float { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun FloatArray.groupByTo(result: MutableMap Int) * @includeFunctionBody ../../test/CollectionTest.kt reduce */ public inline fun IntArray.reduce(operation: (Int, Int) -> Int): Int { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun IntArray.groupByTo(result: MutableMap> public inline fun IntArray.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { val buffer = StringBuilder() appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString().sure() + return buffer.toString()!! } /** Returns a list containing the everything but the first elements that satisfy the given *predicate* */ diff --git a/libraries/stdlib/src/generated/IteratorsFromIterables.kt b/libraries/stdlib/src/generated/IteratorsFromIterables.kt index 7add95fb920..0cdb895c2bd 100644 --- a/libraries/stdlib/src/generated/IteratorsFromIterables.kt +++ b/libraries/stdlib/src/generated/IteratorsFromIterables.kt @@ -171,7 +171,7 @@ public inline fun Iterator.foldRight(initial: T, operation: (T, T) -> T): * @includeFunctionBody ../../test/CollectionTest.kt reduce */ public inline fun Iterator.reduce(operation: (T, T) -> T): T { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -225,7 +225,7 @@ public inline fun Iterator.groupByTo(result: MutableMap Iterator.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { val buffer = StringBuilder() appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString().sure() + return buffer.toString()!! } /** Returns a list containing the everything but the first elements that satisfy the given *predicate* */ diff --git a/libraries/stdlib/src/generated/LongArraysFromIterables.kt b/libraries/stdlib/src/generated/LongArraysFromIterables.kt index 8928763bff3..496c35357e4 100644 --- a/libraries/stdlib/src/generated/LongArraysFromIterables.kt +++ b/libraries/stdlib/src/generated/LongArraysFromIterables.kt @@ -172,7 +172,7 @@ public inline fun LongArray.foldRight(initial: Long, operation: (Long, Long) -> * @includeFunctionBody ../../test/CollectionTest.kt reduce */ public inline fun LongArray.reduce(operation: (Long, Long) -> Long): Long { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun LongArray.groupByTo(result: MutableMap Short): Short { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -226,7 +226,7 @@ public inline fun ShortArray.groupByTo(result: MutableMap Array.copyOf(newLength: Int = this.size) : Array = Arrays.copyOf(this as Array, newLength) as Array -public inline fun BooleanArray.copyOfRange(from: Int, to: Int) : BooleanArray = Arrays.copyOfRange(this, from, to).sure() -public inline fun ByteArray.copyOfRange(from: Int, to: Int) : ByteArray = Arrays.copyOfRange(this, from, to).sure() -public inline fun ShortArray.copyOfRange(from: Int, to: Int) : ShortArray = Arrays.copyOfRange(this, from, to).sure() -public inline fun IntArray.copyOfRange(from: Int, to: Int) : IntArray = Arrays.copyOfRange(this, from, to).sure() -public inline fun LongArray.copyOfRange(from: Int, to: Int) : LongArray = Arrays.copyOfRange(this, from, to).sure() -public inline fun FloatArray.copyOfRange(from: Int, to: Int) : FloatArray = Arrays.copyOfRange(this, from, to).sure() -public inline fun DoubleArray.copyOfRange(from: Int, to: Int) : DoubleArray = Arrays.copyOfRange(this, from, to).sure() -public inline fun CharArray.copyOfRange(from: Int, to: Int) : CharArray = Arrays.copyOfRange(this, from, to).sure() +public inline fun BooleanArray.copyOfRange(from: Int, to: Int) : BooleanArray = Arrays.copyOfRange(this, from, to)!! +public inline fun ByteArray.copyOfRange(from: Int, to: Int) : ByteArray = Arrays.copyOfRange(this, from, to)!! +public inline fun ShortArray.copyOfRange(from: Int, to: Int) : ShortArray = Arrays.copyOfRange(this, from, to)!! +public inline fun IntArray.copyOfRange(from: Int, to: Int) : IntArray = Arrays.copyOfRange(this, from, to)!! +public inline fun LongArray.copyOfRange(from: Int, to: Int) : LongArray = Arrays.copyOfRange(this, from, to)!! +public inline fun FloatArray.copyOfRange(from: Int, to: Int) : FloatArray = Arrays.copyOfRange(this, from, to)!! +public inline fun DoubleArray.copyOfRange(from: Int, to: Int) : DoubleArray = Arrays.copyOfRange(this, from, to)!! +public inline fun CharArray.copyOfRange(from: Int, to: Int) : CharArray = Arrays.copyOfRange(this, from, to)!! // TODO: resuling array may contain nulls even if T is non-nullable public inline fun Array.copyOfRange(from: Int, to: Int) : Array = Arrays.copyOfRange(this as Array, from, to) as Array diff --git a/libraries/stdlib/src/kotlin/Iterables.kt b/libraries/stdlib/src/kotlin/Iterables.kt index 1bb064c181d..af32fc11812 100644 --- a/libraries/stdlib/src/kotlin/Iterables.kt +++ b/libraries/stdlib/src/kotlin/Iterables.kt @@ -163,7 +163,7 @@ public inline fun Iterable.foldRight(initial: T, operation: (T, T) -> T): * @includeFunctionBody ../../test/CollectionTest.kt reduce */ public inline fun Iterable.reduce(operation: (T, T) -> T): T { - val iterator = this.iterator().sure() + val iterator = this.iterator()!! if (!iterator.hasNext()) { throw UnsupportedOperationException("Empty iterable can't be reduced") } @@ -217,7 +217,7 @@ public inline fun Iterable.groupByTo(result: MutableMap Iterable.makeString(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int = -1, truncated: String = "..."): String { val buffer = StringBuilder() appendString(buffer, separator, prefix, postfix, limit, truncated) - return buffer.toString().sure() + return buffer.toString()!! } /** Returns a list containing the everything but the first elements that satisfy the given *predicate* */ diff --git a/libraries/stdlib/src/kotlin/IterablesSpecial.kt b/libraries/stdlib/src/kotlin/IterablesSpecial.kt index 5b36aa4143c..162086445ae 100644 --- a/libraries/stdlib/src/kotlin/IterablesSpecial.kt +++ b/libraries/stdlib/src/kotlin/IterablesSpecial.kt @@ -40,7 +40,7 @@ public inline fun Iterable.first() : T { return this.get(0) } - return this.iterator().sure().next() + return this.iterator()!!.next() } /** @@ -60,7 +60,7 @@ public fun Iterable.last() : T { return this.get(this.size() - 1) } - val iterator = this.iterator().sure() + val iterator = this.iterator()!! var last : T = iterator.next() while (iterator.hasNext()) { diff --git a/libraries/stdlib/src/kotlin/Maps.kt b/libraries/stdlib/src/kotlin/Maps.kt index acc6f594b82..3632653de1b 100644 --- a/libraries/stdlib/src/kotlin/Maps.kt +++ b/libraries/stdlib/src/kotlin/Maps.kt @@ -23,20 +23,20 @@ public inline fun Map?.orEmpty() : Map /** Returns the key of the entry */ val Map.Entry.key : K - get() = getKey().sure() + get() = getKey()!! /** Returns the value of the entry */ val Map.Entry.value : V - get() = getValue().sure() + get() = getValue()!! /** Returns the key of the entry */ fun Map.Entry.component1() : K { - return getKey().sure() + return getKey()!! } /** Returns the value of the entry */ fun Map.Entry.component2() : V { - return getValue().sure() + return getValue()!! } /** diff --git a/libraries/stdlib/src/kotlin/Standard.kt b/libraries/stdlib/src/kotlin/Standard.kt index be62277c299..2c2fb2e0523 100644 --- a/libraries/stdlib/src/kotlin/Standard.kt +++ b/libraries/stdlib/src/kotlin/Standard.kt @@ -10,7 +10,7 @@ Helper to make java.util.Enumeration usable in for public fun java.util.Enumeration.iterator(): Iterator = object: Iterator { override fun hasNext(): Boolean = hasMoreElements() - public override fun next() : T = nextElement().sure() + public override fun next() : T = nextElement()!! } /* diff --git a/libraries/stdlib/src/kotlin/StringsJVM.kt b/libraries/stdlib/src/kotlin/StringsJVM.kt index ae0a0183451..560847bccc4 100644 --- a/libraries/stdlib/src/kotlin/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/StringsJVM.kt @@ -14,33 +14,33 @@ public inline fun String.indexOf(str : String) : Int = (this as java.lang.String public inline fun String.indexOf(str : String, fromIndex : Int) : Int = (this as java.lang.String).indexOf(str, fromIndex) -public inline fun String.replace(oldChar: Char, newChar : Char) : String = (this as java.lang.String).replace(oldChar, newChar).sure() +public inline fun String.replace(oldChar: Char, newChar : Char) : String = (this as java.lang.String).replace(oldChar, newChar)!! -public inline fun String.replaceAll(regex: String, replacement : String) : String = (this as java.lang.String).replaceAll(regex, replacement).sure() +public inline fun String.replaceAll(regex: String, replacement : String) : String = (this as java.lang.String).replaceAll(regex, replacement)!! -public inline fun String.trim() : String = (this as java.lang.String).trim().sure() +public inline fun String.trim() : String = (this as java.lang.String).trim()!! -public inline fun String.toUpperCase() : String = (this as java.lang.String).toUpperCase().sure() +public inline fun String.toUpperCase() : String = (this as java.lang.String).toUpperCase()!! -public inline fun String.toLowerCase() : String = (this as java.lang.String).toLowerCase().sure() +public inline fun String.toLowerCase() : String = (this as java.lang.String).toLowerCase()!! public inline fun String.length() : Int = (this as java.lang.String).length() -public inline fun String.getBytes() : ByteArray = (this as java.lang.String).getBytes().sure() +public inline fun String.getBytes() : ByteArray = (this as java.lang.String).getBytes()!! -public inline fun String.toCharArray() : CharArray = (this as java.lang.String).toCharArray().sure() +public inline fun String.toCharArray() : CharArray = (this as java.lang.String).toCharArray()!! public inline fun String.toCharList(): List = toCharArray().toList() -public inline fun String.format(format : String, vararg args : Any?) : String = java.lang.String.format(format, args).sure() +public inline fun String.format(format : String, vararg args : Any?) : String = java.lang.String.format(format, args)!! public inline fun String.split(regex : String) : Array = (this as java.lang.String).split(regex) as Array public inline fun String.split(ch : Char) : Array = (this as java.lang.String).split(java.util.regex.Pattern.quote(ch.toString())) as Array -public inline fun String.substring(beginIndex : Int) : String = (this as java.lang.String).substring(beginIndex).sure() +public inline fun String.substring(beginIndex : Int) : String = (this as java.lang.String).substring(beginIndex)!! -public inline fun String.substring(beginIndex : Int, endIndex : Int) : String = (this as java.lang.String).substring(beginIndex, endIndex).sure() +public inline fun String.substring(beginIndex : Int, endIndex : Int) : String = (this as java.lang.String).substring(beginIndex, endIndex)!! public inline fun String.startsWith(prefix: String) : Boolean = (this as java.lang.String).startsWith(prefix) @@ -60,7 +60,7 @@ public inline fun String(bytes : ByteArray, offset : Int, length : Int, charsetN public inline fun String(bytes : ByteArray, offset : Int, length : Int, charset : java.nio.charset.Charset) : String = java.lang.String(bytes, offset, length, charset) as String -public inline fun String(bytes : ByteArray, charsetName : String?) : String = java.lang.String(bytes, charsetName) as String +public inline fun String(bytes : ByteArray, charsetName : String) : String = java.lang.String(bytes, charsetName) as String public inline fun String(bytes : ByteArray, charset : java.nio.charset.Charset) : String = java.lang.String(bytes, charset) as String @@ -74,59 +74,59 @@ public inline fun String(stringBuffer : java.lang.StringBuffer) : String = java. public inline fun String(stringBuilder : java.lang.StringBuilder) : String = java.lang.String(stringBuilder) as String -public inline fun String.replaceFirst(regex : String, replacement : String) : String = (this as java.lang.String).replaceFirst(regex, replacement).sure() +public inline fun String.replaceFirst(regex : String, replacement : String) : String = (this as java.lang.String).replaceFirst(regex, replacement)!! -public inline fun String.charAt(index : Int) : Char = (this as java.lang.String).charAt(index).sure() +public inline fun String.charAt(index : Int) : Char = (this as java.lang.String).charAt(index)!! -public inline fun String.split(regex : String, limit : Int) : Array = (this as java.lang.String).split(regex, limit).sure() +public inline fun String.split(regex : String, limit : Int) : Array = (this as java.lang.String).split(regex, limit) -public inline fun String.codePointAt(index : Int) : Int = (this as java.lang.String).codePointAt(index).sure() +public inline fun String.codePointAt(index : Int) : Int = (this as java.lang.String).codePointAt(index)!! -public inline fun String.codePointBefore(index : Int) : Int = (this as java.lang.String).codePointBefore(index).sure() +public inline fun String.codePointBefore(index : Int) : Int = (this as java.lang.String).codePointBefore(index)!! public inline fun String.codePointCount(beginIndex : Int, endIndex : Int) : Int = (this as java.lang.String).codePointCount(beginIndex, endIndex) -public inline fun String.compareToIgnoreCase(str : String) : Int = (this as java.lang.String).compareToIgnoreCase(str).sure() +public inline fun String.compareToIgnoreCase(str : String) : Int = (this as java.lang.String).compareToIgnoreCase(str)!! -public inline fun String.concat(str : String) : String = (this as java.lang.String).concat(str).sure() +public inline fun String.concat(str : String) : String = (this as java.lang.String).concat(str)!! -public inline fun String.contentEquals(cs : CharSequence) : Boolean = (this as java.lang.String).contentEquals(cs).sure() +public inline fun String.contentEquals(cs : CharSequence) : Boolean = (this as java.lang.String).contentEquals(cs)!! -public inline fun String.contentEquals(sb : StringBuffer) : Boolean = (this as java.lang.String).contentEquals(sb).sure() +public inline fun String.contentEquals(sb : StringBuffer) : Boolean = (this as java.lang.String).contentEquals(sb)!! -public inline fun String.getBytes(charset : java.nio.charset.Charset) : ByteArray = (this as java.lang.String).getBytes(charset).sure() +public inline fun String.getBytes(charset : java.nio.charset.Charset) : ByteArray = (this as java.lang.String).getBytes(charset)!! -public inline fun String.getBytes(charsetName : String) : ByteArray = (this as java.lang.String).getBytes(charsetName).sure() +public inline fun String.getBytes(charsetName : String) : ByteArray = (this as java.lang.String).getBytes(charsetName)!! -public inline fun String.getChars(srcBegin : Int, srcEnd : Int, dst : CharArray, dstBegin : Int) : Tuple0 = (this as java.lang.String).getChars(srcBegin, srcEnd, dst, dstBegin).sure() +public inline fun String.getChars(srcBegin : Int, srcEnd : Int, dst : CharArray, dstBegin : Int) : Tuple0 = (this as java.lang.String).getChars(srcBegin, srcEnd, dst, dstBegin)!! -public inline fun String.indexOf(ch : Char) : Int = (this as java.lang.String).indexOf(ch.toString()).sure() +public inline fun String.indexOf(ch : Char) : Int = (this as java.lang.String).indexOf(ch.toString())!! -public inline fun String.indexOf(ch : Char, fromIndex : Int) : Int = (this as java.lang.String).indexOf(ch.toString(), fromIndex).sure() +public inline fun String.indexOf(ch : Char, fromIndex : Int) : Int = (this as java.lang.String).indexOf(ch.toString(), fromIndex)!! -public inline fun String.intern() : String = (this as java.lang.String).intern().sure() +public inline fun String.intern() : String = (this as java.lang.String).intern()!! -public inline fun String.isEmpty() : Boolean = (this as java.lang.String).isEmpty().sure() +public inline fun String.isEmpty() : Boolean = (this as java.lang.String).isEmpty()!! -public inline fun String.lastIndexOf(ch : Char, fromIndex : Int) : Int = (this as java.lang.String).lastIndexOf(ch.toString(), fromIndex).sure() +public inline fun String.lastIndexOf(ch : Char, fromIndex : Int) : Int = (this as java.lang.String).lastIndexOf(ch.toString(), fromIndex)!! -public inline fun String.lastIndexOf(str : String, fromIndex : Int) : Int = (this as java.lang.String).lastIndexOf(str, fromIndex).sure() +public inline fun String.lastIndexOf(str : String, fromIndex : Int) : Int = (this as java.lang.String).lastIndexOf(str, fromIndex)!! -public inline fun String.matches(regex : String) : Boolean = (this as java.lang.String).matches(regex).sure() +public inline fun String.matches(regex : String) : Boolean = (this as java.lang.String).matches(regex)!! -public inline fun String.offsetByCodePoints(index : Int, codePointOffset : Int) : Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset).sure() +public inline fun String.offsetByCodePoints(index : Int, codePointOffset : Int) : Int = (this as java.lang.String).offsetByCodePoints(index, codePointOffset)!! -public inline fun String.regionMatches(ignoreCase : Boolean, toffset : Int, other : String, ooffset : Int, len : Int) : Boolean = (this as java.lang.String).regionMatches(ignoreCase, toffset, other, ooffset, len).sure() +public inline fun String.regionMatches(ignoreCase : Boolean, toffset : Int, other : String, ooffset : Int, len : Int) : Boolean = (this as java.lang.String).regionMatches(ignoreCase, toffset, other, ooffset, len)!! -public inline fun String.regionMatches(toffset : Int, other : String, ooffset : Int, len : Int) : Boolean = (this as java.lang.String).regionMatches(toffset, other, ooffset, len).sure() +public inline fun String.regionMatches(toffset : Int, other : String, ooffset : Int, len : Int) : Boolean = (this as java.lang.String).regionMatches(toffset, other, ooffset, len)!! -public inline fun String.replace(target : CharSequence, replacement : CharSequence) : String = (this as java.lang.String).replace(target, replacement).sure() +public inline fun String.replace(target : CharSequence, replacement : CharSequence) : String = (this as java.lang.String).replace(target, replacement)!! -public inline fun String.subSequence(beginIndex : Int, endIndex : Int) : CharSequence = (this as java.lang.String).subSequence(beginIndex, endIndex).sure() +public inline fun String.subSequence(beginIndex : Int, endIndex : Int) : CharSequence = (this as java.lang.String).subSequence(beginIndex, endIndex)!! -public inline fun String.toLowerCase(locale : java.util.Locale) : String = (this as java.lang.String).toLowerCase(locale).sure() +public inline fun String.toLowerCase(locale : java.util.Locale) : String = (this as java.lang.String).toLowerCase(locale)!! -public inline fun String.toUpperCase(locale : java.util.Locale) : String = (this as java.lang.String).toUpperCase(locale).sure() +public inline fun String.toUpperCase(locale : java.util.Locale) : String = (this as java.lang.String).toUpperCase(locale)!! public inline fun CharSequence.charAt(index : Int) : Char = (this as java.lang.CharSequence).charAt(index) @@ -144,19 +144,19 @@ public inline fun CharSequence.length() : Int = (this as java.lang.CharSequence) public inline fun String.toByteArray(encoding: String?=null):ByteArray { if(encoding==null) { - return (this as java.lang.String).getBytes().sure() + return (this as java.lang.String).getBytes()!! } else { - return (this as java.lang.String).getBytes(encoding).sure() + return (this as java.lang.String).getBytes(encoding)!! } } -public inline fun String.toByteArray(encoding: java.nio.charset.Charset):ByteArray = (this as java.lang.String).getBytes(encoding).sure() +public inline fun String.toByteArray(encoding: java.nio.charset.Charset):ByteArray = (this as java.lang.String).getBytes(encoding)!! -public inline fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this).sure() -public inline fun String.toShort() : Short = java.lang.Short.parseShort(this).sure() -public inline fun String.toInt() : Int = java.lang.Integer.parseInt(this).sure() -public inline fun String.toLong() : Long = java.lang.Long.parseLong(this).sure() -public inline fun String.toFloat() : Float = java.lang.Float.parseFloat(this).sure() -public inline fun String.toDouble() : Double = java.lang.Double.parseDouble(this).sure() +public inline fun String.toBoolean() : Boolean = java.lang.Boolean.parseBoolean(this)!! +public inline fun String.toShort() : Short = java.lang.Short.parseShort(this)!! +public inline fun String.toInt() : Int = java.lang.Integer.parseInt(this)!! +public inline fun String.toLong() : Long = java.lang.Long.parseLong(this)!! +public inline fun String.toFloat() : Float = java.lang.Float.parseFloat(this)!! +public inline fun String.toDouble() : Double = java.lang.Double.parseDouble(this)!! /** * Converts the string into a regular expression [[Pattern]] optionally @@ -164,7 +164,7 @@ public inline fun String.toDouble() : Double = java.lang.Double.parseDouble(this * so that strings can be split or matched on. */ public inline fun String.toRegex(flags: Int=0): java.util.regex.Pattern { - return java.util.regex.Pattern.compile(this, flags).sure() + return java.util.regex.Pattern.compile(this, flags)!! } inline val String.reader : StringReader diff --git a/libraries/stdlib/src/kotlin/concurrent/Locks.kt b/libraries/stdlib/src/kotlin/concurrent/Locks.kt index 4f57d3ec09d..cf029a7e637 100644 --- a/libraries/stdlib/src/kotlin/concurrent/Locks.kt +++ b/libraries/stdlib/src/kotlin/concurrent/Locks.kt @@ -24,7 +24,7 @@ Executes given calculation under read lock Returns result of the calculation */ public inline fun ReentrantReadWriteLock.read(action: ()->T) : T { - val rl = readLock().sure() + val rl = readLock()!! rl.lock() try { return action() @@ -41,12 +41,12 @@ If such write has been initiated by checking some condition, the condition must Returns result of the calculation */ public inline fun ReentrantReadWriteLock.write(action: ()->T) : T { - val rl = readLock().sure() + val rl = readLock()!! val readCount = if (getWriteHoldCount() == 0) getReadHoldCount() else 0 readCount times { rl.unlock() } - val wl = writeLock().sure() + val wl = writeLock()!! wl.lock() try { return action() diff --git a/libraries/stdlib/src/kotlin/concurrent/Thread.kt b/libraries/stdlib/src/kotlin/concurrent/Thread.kt index 0c12a2dfc1a..6d2bcb95103 100644 --- a/libraries/stdlib/src/kotlin/concurrent/Thread.kt +++ b/libraries/stdlib/src/kotlin/concurrent/Thread.kt @@ -6,10 +6,10 @@ import java.util.concurrent.Future import java.util.concurrent.Callable inline val currentThread : Thread - get() = Thread.currentThread().sure() + get() = Thread.currentThread()!! inline var Thread.name : String - get() = getName().sure() + get() = getName()!! set(name: String) { setName(name) } inline var Thread.daemon : Boolean @@ -66,7 +66,7 @@ public inline fun Executor.invoke(action: ()->Unit) { */ public inline fun ExecutorService.submit(action: ()->T):Future { val c:Callable = callable(action) - return submit(c).sure(); + return submit(c)!!; } /** diff --git a/libraries/stdlib/src/kotlin/dom/Dom.kt b/libraries/stdlib/src/kotlin/dom/Dom.kt index 783688646af..4b46e897811 100644 --- a/libraries/stdlib/src/kotlin/dom/Dom.kt +++ b/libraries/stdlib/src/kotlin/dom/Dom.kt @@ -39,7 +39,7 @@ var Element.childrenText: String i++ } } - return buffer.toString().sure() + return buffer.toString()!! } set(value) { val element = this as Element @@ -336,7 +336,7 @@ public fun nodesToXmlString(nodes: Iterable, xmlDeclaration: Boolean = fal for (n in nodes) { builder.append(n.toXmlString(xmlDeclaration)) } - return builder.toString().sure() + return builder.toString()!! } // Syntax sugar @@ -359,7 +359,7 @@ inline fun Element.plusAssign(text: String?): Element = this.addText(text) * Creates a new element which can be configured via a function */ fun Document.createElement(name: String, init: Element.()-> Unit): Element { - val elem = this.createElement(name).sure() + val elem = this.createElement(name)!! elem.init() return elem } @@ -368,7 +368,7 @@ fun Document.createElement(name: String, init: Element.()-> Unit): Element { * Creates a new element to an element which has an owner Document which can be configured via a function */ fun Element.createElement(name: String, doc: Document? = null, init: Element.()-> Unit): Element { - val elem = ownerDocument(doc).createElement(name).sure() + val elem = ownerDocument(doc).createElement(name)!! elem.init() return elem } diff --git a/libraries/stdlib/src/kotlin/dom/DomJVM.kt b/libraries/stdlib/src/kotlin/dom/DomJVM.kt index 17d64a9b217..f26a42c4530 100644 --- a/libraries/stdlib/src/kotlin/dom/DomJVM.kt +++ b/libraries/stdlib/src/kotlin/dom/DomJVM.kt @@ -157,7 +157,7 @@ fun Element.removeClass(cssClass: String): Boolean { /** Creates a new document with the given document builder*/ public fun createDocument(builder: DocumentBuilder): Document { - return builder.newDocument().sure() + return builder.newDocument()!! } /** Creates a new document with an optional DocumentBuilderFactory */ @@ -209,13 +209,13 @@ public fun parseXml(inputSource: InputSource, builder: DocumentBuilder = default /** Creates a new TrAX transformer */ -public fun createTransformer(source: Source? = null, factory: TransformerFactory = TransformerFactory.newInstance().sure()): Transformer { +public fun createTransformer(source: Source? = null, factory: TransformerFactory = TransformerFactory.newInstance()!!): Transformer { val transformer = if (source != null) { factory.newTransformer(source) } else { factory.newTransformer() } - return transformer.sure() + return transformer!! } /** Converts the node to an XML String */ @@ -225,7 +225,7 @@ public fun Node.toXmlString(): String = toXmlString(false) public fun Node.toXmlString(xmlDeclaration: Boolean): String { val writer = StringWriter() writeXmlString(writer, xmlDeclaration) - return writer.toString().sure() + return writer.toString()!! } /** Converts the node to an XML String and writes it to the given [[Writer]] */ diff --git a/libraries/stdlib/src/kotlin/io/Files.kt b/libraries/stdlib/src/kotlin/io/Files.kt index ad7437c4f15..d6ee6ccea0a 100644 --- a/libraries/stdlib/src/kotlin/io/Files.kt +++ b/libraries/stdlib/src/kotlin/io/Files.kt @@ -25,7 +25,7 @@ public fun File.recurse(block: (File) -> Unit): Unit { * Returns this if the file is a directory or the parent if its a file inside a directory */ inline val File.directory: File -get() = if (this.isDirectory()) this else this.getParentFile().sure() +get() = if (this.isDirectory()) this else this.getParentFile()!! /** * Returns the canoncial path of the file @@ -207,6 +207,6 @@ fun File.readLines(charset : String = "UTF-8") : List { */ fun File.listFiles(filter : (file : File) -> Boolean) : Array? = listFiles( object : FileFilter { - override fun accept(file: File?) = filter(file!!) + override fun accept(file: File) = filter(file) } ) as Array? diff --git a/libraries/stdlib/src/kotlin/io/JIO.kt b/libraries/stdlib/src/kotlin/io/JIO.kt index bf13b0f0454..b800af03689 100644 --- a/libraries/stdlib/src/kotlin/io/JIO.kt +++ b/libraries/stdlib/src/kotlin/io/JIO.kt @@ -13,7 +13,7 @@ public val defaultBufferSize: Int = 64 * 1024 /** * Returns the default [[Charset]] which defaults to UTF-8 */ -public val defaultCharset: Charset = Charset.forName("UTF-8").sure() +public val defaultCharset: Charset = Charset.forName("UTF-8")!! /** Prints the given message to [[System.out]] */ @@ -111,7 +111,7 @@ private val stdin : BufferedReader = BufferedReader(InputStreamReader(object : I System.`in`?.reset() } - public override fun read(b: ByteArray?): Int { + public override fun read(b: ByteArray): Int { return System.`in`?.read(b) ?: -1 } @@ -135,7 +135,7 @@ private val stdin : BufferedReader = BufferedReader(InputStreamReader(object : I return System.`in`?.markSupported() ?: false } - public override fun read(b: ByteArray?, off: Int, len: Int): Int { + public override fun read(b: ByteArray, off: Int, len: Int): Int { return System.`in`?.read(b, off, len) ?: -1 } })) @@ -251,7 +251,7 @@ class LineIterator(val reader: BufferedReader) : Iterator { } val answer = nextValue nextValue = null - return answer.sure() + return answer!! } } @@ -266,7 +266,7 @@ class LineIterator(val reader: BufferedReader) : Iterator { public fun InputStream.readBytes(estimatedSize: Int = defaultBufferSize): ByteArray { val buffer = ByteArrayOutputStream(estimatedSize) this.copyTo(buffer) - return buffer.toByteArray().sure() + return buffer.toByteArray()!! } /** @@ -277,7 +277,7 @@ public fun InputStream.readBytes(estimatedSize: Int = defaultBufferSize): ByteAr public fun Reader.readText(): String { val buffer = StringWriter() copyTo(buffer) - return buffer.toString().sure() + return buffer.toString()!! } /** @@ -333,5 +333,5 @@ public fun URL.readText(encoding: Charset): String = readBytes().toString(encodi * * This method is not recommended on huge files. */ -public fun URL.readBytes(): ByteArray = this.openStream().sure().use{ it.readBytes() } +public fun URL.readBytes(): ByteArray = this.openStream()!!.use{ it.readBytes() } diff --git a/libraries/stdlib/src/kotlin/math/JMath.kt b/libraries/stdlib/src/kotlin/math/JMath.kt index 5c33928ca90..5a4aa45801b 100644 --- a/libraries/stdlib/src/kotlin/math/JMath.kt +++ b/libraries/stdlib/src/kotlin/math/JMath.kt @@ -3,25 +3,25 @@ package kotlin.math import java.math.BigInteger import java.math.BigDecimal -public fun BigInteger.plus(other: BigInteger) : BigInteger = this.add(other).sure() +public fun BigInteger.plus(other: BigInteger) : BigInteger = this.add(other)!! -public fun BigInteger.minus(other: BigInteger) : BigInteger = this.subtract(other).sure() +public fun BigInteger.minus(other: BigInteger) : BigInteger = this.subtract(other)!! -public fun BigInteger.times(other: BigInteger) : BigInteger = this.multiply(other).sure() +public fun BigInteger.times(other: BigInteger) : BigInteger = this.multiply(other)!! -public fun BigInteger.div(other: BigInteger) : BigInteger = this.divide(other).sure() +public fun BigInteger.div(other: BigInteger) : BigInteger = this.divide(other)!! -public fun BigInteger.minus() : BigInteger = this.negate().sure() +public fun BigInteger.minus() : BigInteger = this.negate()!! -public fun BigDecimal.plus(other: BigDecimal) : BigDecimal = this.add(other).sure() +public fun BigDecimal.plus(other: BigDecimal) : BigDecimal = this.add(other)!! -public fun BigDecimal.minus(other: BigDecimal) : BigDecimal = this.subtract(other).sure() +public fun BigDecimal.minus(other: BigDecimal) : BigDecimal = this.subtract(other)!! -public fun BigDecimal.times(other: BigDecimal) : BigDecimal = this.multiply(other).sure() +public fun BigDecimal.times(other: BigDecimal) : BigDecimal = this.multiply(other)!! -public fun BigDecimal.div(other: BigDecimal) : BigDecimal = this.divide(other).sure() +public fun BigDecimal.div(other: BigDecimal) : BigDecimal = this.divide(other)!! -public fun BigDecimal.mod(other: BigDecimal) : BigDecimal = this.remainder(other).sure() +public fun BigDecimal.mod(other: BigDecimal) : BigDecimal = this.remainder(other)!! -public fun BigDecimal.minus() : BigDecimal = this.negate().sure() \ No newline at end of file +public fun BigDecimal.minus() : BigDecimal = this.negate()!! \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/modules/ModuleBuilder.kt b/libraries/stdlib/src/kotlin/modules/ModuleBuilder.kt index 3adc8dc405f..95db7d82f78 100644 --- a/libraries/stdlib/src/kotlin/modules/ModuleBuilder.kt +++ b/libraries/stdlib/src/kotlin/modules/ModuleBuilder.kt @@ -6,7 +6,7 @@ import jet.modules.* public fun module(name: String, callback: ModuleBuilder.() -> Unit) { val builder = ModuleBuilder(name) builder.callback() - AllModules.modules.sure().get()?.add(builder) + AllModules.modules!!.get()?.add(builder) } class SourcesBuilder(val parent: ModuleBuilder) { diff --git a/libraries/stdlib/src/kotlin/nullable/Nullables.kt b/libraries/stdlib/src/kotlin/nullable/Nullables.kt index b9d7f655204..ee1a3ba11a0 100644 --- a/libraries/stdlib/src/kotlin/nullable/Nullables.kt +++ b/libraries/stdlib/src/kotlin/nullable/Nullables.kt @@ -129,7 +129,7 @@ public inline fun T?.makeString(separator: String = ", ", prefix: String = " buffer.append(this) } buffer.append(postfix) - return buffer.toString().sure() + return buffer.toString()!! } diff --git a/libraries/stdlib/src/kotlin/properties/Properties.kt b/libraries/stdlib/src/kotlin/properties/Properties.kt index 06beec8ec1b..6c5aa09312f 100644 --- a/libraries/stdlib/src/kotlin/properties/Properties.kt +++ b/libraries/stdlib/src/kotlin/properties/Properties.kt @@ -39,7 +39,7 @@ public abstract class ChangeSupport { var listeners = nameListeners?.get(name) if (listeners == null) { listeners = arrayList() - nameListeners?.put(name, listeners.sure()) + nameListeners?.put(name, listeners!!) } listeners?.add(listener) } diff --git a/libraries/stdlib/src/kotlin/support/AbstractIterator.kt b/libraries/stdlib/src/kotlin/support/AbstractIterator.kt index 72983ef1cd3..4530e41c55a 100644 --- a/libraries/stdlib/src/kotlin/support/AbstractIterator.kt +++ b/libraries/stdlib/src/kotlin/support/AbstractIterator.kt @@ -33,13 +33,13 @@ public abstract class AbstractIterator: Iterator { override fun next(): T { if (!hasNext()) throw NoSuchElementException() state = State.NotReady - return next.sure() + return next!! } /** Returns the next element in the iteration without advancing the iteration */ fun peek(): T { if (!hasNext()) throw NoSuchElementException() - return next.sure(); + return next!!; } private fun tryToComputeNext(): Boolean { diff --git a/libraries/stdlib/src/kotlin/template/Templates.kt b/libraries/stdlib/src/kotlin/template/Templates.kt index d81171176d6..c97e66e9002 100644 --- a/libraries/stdlib/src/kotlin/template/Templates.kt +++ b/libraries/stdlib/src/kotlin/template/Templates.kt @@ -116,7 +116,7 @@ public open class ToStringFormatter : Formatter { } } -public val defaultLocale : Locale = Locale.getDefault().sure() +public val defaultLocale : Locale = Locale.getDefault()!! /** * Formats values using a given [[Locale]] for internationalisation @@ -125,9 +125,9 @@ public open class LocaleFormatter(val locale : Locale = defaultLocale) : ToStrin public override fun toString() : String = "LocaleFormatter{$locale}" - public var numberFormat : NumberFormat = NumberFormat.getInstance(locale).sure() + public var numberFormat : NumberFormat = NumberFormat.getInstance(locale)!! - public var dateFormat : DateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale).sure() + public var dateFormat : DateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale)!! public override fun format(out : Appendable, value : Any?) { if (value is Number) { diff --git a/libraries/stdlib/src/kotlin/test/TestJVM.kt b/libraries/stdlib/src/kotlin/test/TestJVM.kt index 23c99e83077..d305028609e 100644 --- a/libraries/stdlib/src/kotlin/test/TestJVM.kt +++ b/libraries/stdlib/src/kotlin/test/TestJVM.kt @@ -28,7 +28,7 @@ public var asserter: Asserter } //debug("using asserter $_asserter") } - return _asserter.sure() + return _asserter!! } set(value) { diff --git a/libraries/stdlib/test/CollectionTest.kt b/libraries/stdlib/test/CollectionTest.kt index 315cf933aef..90f65113a23 100644 --- a/libraries/stdlib/test/CollectionTest.kt +++ b/libraries/stdlib/test/CollectionTest.kt @@ -105,7 +105,7 @@ class CollectionTest { assertNull(x) val f = data.find{it.startsWith("f")} - f.sure() + f!! assertEquals("foo", f) } @@ -390,7 +390,7 @@ class CollectionTest { private val collection = collection override fun iterator(): Iterator { - return collection.iterator().sure() + return collection.iterator()!! } } } diff --git a/libraries/stdlib/test/Test.kt b/libraries/stdlib/test/Test.kt index cb74e35f5d9..da96728df80 100644 --- a/libraries/stdlib/test/Test.kt +++ b/libraries/stdlib/test/Test.kt @@ -14,7 +14,7 @@ class TestBuilt(name: String, val builder: TestBuilder, val test: TestBuil private var myState: T? = null var state : T - get() = myState.sure() + get() = myState!! set(newState: T) { myState = newState } override fun countTestCases(): Int = 1 diff --git a/libraries/stdlib/test/concurrent/ThreadTest.kt b/libraries/stdlib/test/concurrent/ThreadTest.kt index 54bab4576ae..a0530e8f4a4 100644 --- a/libraries/stdlib/test/concurrent/ThreadTest.kt +++ b/libraries/stdlib/test/concurrent/ThreadTest.kt @@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit.* class ThreadTest { test fun scheduledTask() { - val pool = Executors.newFixedThreadPool(1).sure() + val pool = Executors.newFixedThreadPool(1)!! val countDown = CountDownLatch(1) pool { countDown.countDown() @@ -21,7 +21,7 @@ class ThreadTest { test fun callableInvoke() { - val pool = Executors.newFixedThreadPool(1).sure() + val pool = Executors.newFixedThreadPool(1)!! val future = pool { "Hello" } diff --git a/libraries/stdlib/test/iterators/IteratorsJVMTest.kt b/libraries/stdlib/test/iterators/IteratorsJVMTest.kt index bfd7aba4acb..016dd4edc65 100644 --- a/libraries/stdlib/test/iterators/IteratorsJVMTest.kt +++ b/libraries/stdlib/test/iterators/IteratorsJVMTest.kt @@ -9,7 +9,7 @@ class IteratorsJVMTest { test fun flatMapAndTakeExtractTheTransformedElements() { fun intToBinaryDigits() = { (i: Int) -> - val binary = Integer.toBinaryString(i).sure() + val binary = Integer.toBinaryString(i)!! var index = 0 iterate { if (index < binary.length()) binary.get(index++) else null } } diff --git a/libraries/stdlib/test/regressions/kt1202.kt b/libraries/stdlib/test/regressions/kt1202.kt index 48b3f735e55..e7c1101c872 100644 --- a/libraries/stdlib/test/regressions/kt1202.kt +++ b/libraries/stdlib/test/regressions/kt1202.kt @@ -99,7 +99,7 @@ fun parseAtomic(tokens : Deque) : ParseResult { else Failure("Expecting ')'") } - is Number -> Success(Num(Integer.parseInt((token as Token).text).sure())) + is Number -> Success(Num(Integer.parseInt((token as Token).text)!!)) else -> Failure("Unexpected EOF") } } diff --git a/libraries/stdlib/test/template/LocaleTemplateTest.kt b/libraries/stdlib/test/template/LocaleTemplateTest.kt index b1483ab377e..9761e770575 100644 --- a/libraries/stdlib/test/template/LocaleTemplateTest.kt +++ b/libraries/stdlib/test/template/LocaleTemplateTest.kt @@ -13,11 +13,11 @@ class LocaleTemplateTest : TestCase() { } fun testFrance() : Unit { - format(LocaleFormatter(Locale.FRANCE.sure())) + format(LocaleFormatter(Locale.FRANCE!!)) } fun testGermany() : Unit { - format(LocaleFormatter(Locale.GERMANY.sure())) + format(LocaleFormatter(Locale.GERMANY!!)) } fun format(formatter: LocaleFormatter): Unit { diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/Html2CompilerPlugin.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/Html2CompilerPlugin.kt index b327b9930fe..7db9c2cd415 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/Html2CompilerPlugin.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/highlighter2/Html2CompilerPlugin.kt @@ -35,7 +35,7 @@ class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Doclet private val sourceDirPaths: List = sourceDirs.map { d -> d.getPath()!! } private fun fileToWrite(psiFile: PsiFile): String { - val file = File((psiFile.getVirtualFile() as CoreLocalVirtualFile).getPath()).getCanonicalFile()!! + val file = File((psiFile.getVirtualFile() as CoreLocalVirtualFile).getPath()!!).getCanonicalFile()!! val filePath = file.getPath()!! for (sourceDirPath in sourceDirPaths) { if (filePath.startsWith(sourceDirPath) && filePath.length() > sourceDirPath.length()) { @@ -54,7 +54,7 @@ class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Doclet File(srcOutputRoot, "highlight.css").write { outputStream -> css.copyTo(outputStream) - #() + Unit.VALUE } for (sourceInfo in model.sourcesInfo) { diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt index 3c461368b9c..14df8f011f4 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/model/KotlinModel.kt @@ -136,15 +136,15 @@ fun inheritedExtensionProperties(properties: Collection): Map): Map> { - val map = TreeMap>() - functions.filter{ it.extensionClass != null }.groupByTo(map){ it.extensionClass.sure() } + val map = TreeMap>() + functions.filter{ it.extensionClass != null }.groupByTo(map){ it.extensionClass!! } return map } // TODO for some reason the SortedMap causes kotlin to freak out a little :) fun extensionProperties(properties: Collection): Map> { - val map = TreeMap>() - properties.filter{ it.extensionClass != null }.groupByTo(map){ it.extensionClass.sure() } + val map = TreeMap>() + properties.filter{ it.extensionClass != null }.groupByTo(map){ it.extensionClass!! } return map } @@ -176,7 +176,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs public val packageMap: SortedMap = TreeMap() public val allPackages: Collection - get() = packageMap.values().sure() + get() = packageMap.values()!! /** Returns the local packages */ public val packages: Collection @@ -212,7 +212,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs sourceDirs.map { file -> file.getCanonicalPath()!! } fun relativePath(psiFile: PsiFile): String { - val file = File((psiFile.getVirtualFile() as CoreLocalVirtualFile).getPath()).getCanonicalFile()!! + val file = File((psiFile.getVirtualFile() as CoreLocalVirtualFile).getPath()!!).getCanonicalFile()!! val filePath = file.getPath()!! for (sourceDirPath in normalizedSourceDirs) { if (filePath.startsWith(sourceDirPath) && filePath.length() > sourceDirPath.length()) { @@ -345,7 +345,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs } fun wikiConvert(text: String, linkRenderer: LinkRenderer, fileName: String?): String { - return markdownProcessor.markdownToHtml(text, linkRenderer).sure() + return markdownProcessor.markdownToHtml(text, linkRenderer)!! } fun sourceLinkFor(filePath: String, sourceLine: Int, lineLinkText: String = "#L"): String? { @@ -552,8 +552,8 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs // source code function if folks adopted a convention of naming the test method after the // method its acting as a demo/test for if (words.size > 1) { - val includeFile = words[0].sure() - val fnName = words[1].sure() + val includeFile = words[0]!! + val fnName = words[1]!! val content = findFunctionInclude(psiElement, includeFile, fnName) if (content != null) { return content @@ -571,7 +571,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs protected fun findFunctionInclude(psiElement: PsiElement, includeFile: String, functionName: String): String? { var dir = psiElement.getContainingFile()?.getParent() if (dir != null) { - val file = relativeFile(dir.sure(), includeFile) + val file = relativeFile(dir!!, includeFile) if (file != null) { val text = file.getText() if (text != null) { @@ -947,7 +947,7 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor, public val classMap: SortedMap = TreeMap() public val classes: Collection - get() = classMap.values().sure().filter{ it.isApi() } + get() = classMap.values()!!.filter{ it.isApi() } public val annotations: Collection = ArrayList() @@ -1037,7 +1037,7 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor, } fun groupClassMap(): Map> { - return classes.groupByTo(TreeMap>()){it.group} + return classes.groupByTo(TreeMap>()){it.group} } fun packageFunctions() = functions.filter{ it.extensionClass == null } @@ -1046,7 +1046,7 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor, } class KType(val jetType: JetType, model: KModel, val klass: KClass?, val arguments: MutableList = ArrayList()) -: KNamed(klass?.name ?: jetType.toString().sure(), model, jetType.getConstructor().getDeclarationDescriptor().sure()) { +: KNamed(klass?.name ?: jetType.toString()!!, model, jetType.getConstructor().getDeclarationDescriptor()!!) { { if (klass != null) { this.wikiDescription = klass.wikiDescription diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt index 3a70e92978a..9d52609a46f 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/doc/templates/PackageTemplateSupport.kt @@ -257,7 +257,7 @@ abstract class PackageTemplateSupport(open val pkg: KPackage) : KDocTemplate() { } val pType = if (p.isVarArg()) { print("vararg ") - p.varArgType().sure() + p.varArgType()!! } else { p.aType } diff --git a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/TemplateCore.kt b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/TemplateCore.kt index ee174667c7c..5faf369be0d 100644 --- a/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/TemplateCore.kt +++ b/libraries/tools/kdoc/src/main/kotlin/org/jetbrains/kotlin/template/TemplateCore.kt @@ -72,7 +72,7 @@ abstract class TextTemplate() : TemplateSupport(), Printer { fun renderToText(): String { val buffer = StringWriter() renderTo(buffer) - return buffer.toString().sure() + return buffer.toString()!! } fun renderTo(writer: Writer): Unit { diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocTest.kt index 35db9577a63..eada2ec9fbf 100644 --- a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocTest.kt +++ b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/kdoc/KDocTest.kt @@ -38,8 +38,7 @@ class KDocTest { config.docOutputDir = outDir.toString()!! config.title = "Kotlin API" - //todo@svtk KT-2745 - val ignorePackages = config.ignorePackages as MutableSet + val ignorePackages = config.ignorePackages ignorePackages.add("org.jetbrains.kotlin") ignorePackages.add("java") ignorePackages.add("jet") diff --git a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/PegdownTest.kt b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/PegdownTest.kt index 532be0094d6..5e3513bde0e 100644 --- a/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/PegdownTest.kt +++ b/libraries/tools/kdoc/src/test/kotlin/test/kotlin/template/PegdownTest.kt @@ -19,7 +19,7 @@ class PegdownTest() : TestCase() { "a [Link](somewhere) blah") for (text in markups) { - val answer = markdownProcessor.markdownToHtml(text, linkRenderer).sure() + val answer = markdownProcessor.markdownToHtml(text, linkRenderer)!! println("$text = $answer") } } diff --git a/runtime/src/jet/StringTemplate.java b/runtime/src/jet/StringTemplate.java deleted file mode 100644 index a3f5e9f9f26..00000000000 --- a/runtime/src/jet/StringTemplate.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package jet; - -/** - * Represents a string template object; that is a string with $ expressions such as "Hello $user". - * - * It is represented as an object that contains a Tuple such that all the even items in the tuple are constant - * strings and the odd items are dynamic expressions which may need to be escaped. - * - * So the expression "Hello $foo$bar how are you?" would be represented as a tuple #("Hello ", foo, "", bar, " how are you?). - * i.e. we insert an empty string to ensure that the tuple starts with a constant string and every other value is a dynamic expression. - */ -public class StringTemplate { - private final Tuple tuple; - - public StringTemplate(Tuple tuple) { - this.tuple = tuple; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - StringTemplate that = (StringTemplate) o; - - if (tuple != null ? !tuple.equals(that.tuple) : that.tuple != null) return false; - - return true; - } - - @Override - public int hashCode() { - return tuple != null ? tuple.hashCode() : 0; - } - - /** - * Returns the plain string version of the string template with no special escaping - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - tuple.forEach(new Function1(){ - @Override - public Tuple0 invoke(Object o) { - builder.append(o); - return Tuple0.INSTANCE; - } - }); - return builder.toString(); - - } - - /** - * Returns the tuple of values in the string template - */ - public Tuple getValues() { - return tuple; - } - - - /** - * Performs the given function on each value in the string template - */ - public void forEach(Function1 fn) { - if (tuple != null) { - tuple.forEach(fn); - } - } - -} diff --git a/runtime/src/jet/Tuple.java b/runtime/src/jet/Tuple.java deleted file mode 100644 index 51451cfd9e7..00000000000 --- a/runtime/src/jet/Tuple.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -/** - * Represents the common interface of a tuple - */ -// @AssertInvisibleInResolver // TODO TupleN classes has no Tuple superclass -public abstract class Tuple extends DefaultJetObject { - - /** - * Performs the given function on each item in the tuple - */ - public abstract void forEach(Function1 fn); - - /** - * Returns the size of the tuple - */ - public abstract int size(); -} diff --git a/runtime/src/jet/Tuple0.java b/runtime/src/jet/Tuple0.java index b2ef9060651..5825ff85fc8 100644 --- a/runtime/src/jet/Tuple0.java +++ b/runtime/src/jet/Tuple0.java @@ -22,33 +22,24 @@ import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; * @author alex.tkachman */ @AssertInvisibleInResolver -public class Tuple0 extends Tuple { - public static final Tuple0 INSTANCE = new Tuple0(); +public class Tuple0 { + public static final Tuple0 VALUE = new Tuple0(); private Tuple0() { } @Override public String toString() { - return "()"; + return "Unit.VALUE"; } @Override public boolean equals(Object o) { - return o == INSTANCE; + return o == VALUE; } @Override public int hashCode() { return 239; } - - @Override - public void forEach(Function1 fn) { - } - - @Override - public int size() { - return 0; - } } diff --git a/runtime/src/jet/Tuple1.java b/runtime/src/jet/Tuple1.java deleted file mode 100644 index 27a92920755..00000000000 --- a/runtime/src/jet/Tuple1.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple1 extends Tuple { - public final T1 _1; - - public Tuple1(T1 t1) { - _1 = t1; - } - - @Override - public String toString() { - return "(" + _1 + ")"; - } - public final T1 get_1() { - return _1; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple1 t = (Tuple1) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - } - - @Override - public int size() { - return 1; - } -} diff --git a/runtime/src/jet/Tuple10.java b/runtime/src/jet/Tuple10.java deleted file mode 100644 index 0fcae84272f..00000000000 --- a/runtime/src/jet/Tuple10.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple10 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - - public Tuple10(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple10 t = (Tuple10) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - } - - @Override - public int size() { - return 10; - } -} diff --git a/runtime/src/jet/Tuple11.java b/runtime/src/jet/Tuple11.java deleted file mode 100644 index 0923cf2f0a4..00000000000 --- a/runtime/src/jet/Tuple11.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple11 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - - public Tuple11(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple11 t = (Tuple11) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - } - - @Override - public int size() { - return 11; - } -} diff --git a/runtime/src/jet/Tuple12.java b/runtime/src/jet/Tuple12.java deleted file mode 100644 index d69ee7eeb2b..00000000000 --- a/runtime/src/jet/Tuple12.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple12 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - - public Tuple12(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple12 t = (Tuple12) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - } - - @Override - public int size() { - return 12; - } -} diff --git a/runtime/src/jet/Tuple13.java b/runtime/src/jet/Tuple13.java deleted file mode 100644 index 44d7b42b3a5..00000000000 --- a/runtime/src/jet/Tuple13.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple13 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - - public Tuple13(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple13 t = (Tuple13) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - } - - @Override - public int size() { - return 13; - } -} diff --git a/runtime/src/jet/Tuple14.java b/runtime/src/jet/Tuple14.java deleted file mode 100644 index 61717ad56a8..00000000000 --- a/runtime/src/jet/Tuple14.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple14 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - - public Tuple14(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple14 t = (Tuple14) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - } - - @Override - public int size() { - return 14; - } -} diff --git a/runtime/src/jet/Tuple15.java b/runtime/src/jet/Tuple15.java deleted file mode 100644 index e96ab5db2d2..00000000000 --- a/runtime/src/jet/Tuple15.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple15 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - public final T15 _15; - - public Tuple15(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - _15 = t15; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ", " + _15 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - public final T15 get_15() { - return _15; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple15 t = (Tuple15) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - if (_15 != null ? !_15.equals(t._15) : t._15 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - result = 31 * result + (_15 != null ? _15.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - fn.invoke(_15); - } - - @Override - public int size() { - return 15; - } -} diff --git a/runtime/src/jet/Tuple16.java b/runtime/src/jet/Tuple16.java deleted file mode 100644 index db4efa2a6b3..00000000000 --- a/runtime/src/jet/Tuple16.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple16 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - public final T15 _15; - public final T16 _16; - - public Tuple16(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - _15 = t15; - _16 = t16; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ", " + _15 + ", " + _16 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - public final T15 get_15() { - return _15; - } - public final T16 get_16() { - return _16; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple16 t = (Tuple16) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - if (_15 != null ? !_15.equals(t._15) : t._15 != null) return false; - if (_16 != null ? !_16.equals(t._16) : t._16 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - result = 31 * result + (_15 != null ? _15.hashCode() : 0); - result = 31 * result + (_16 != null ? _16.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - fn.invoke(_15); - fn.invoke(_16); - } - - @Override - public int size() { - return 16; - } -} diff --git a/runtime/src/jet/Tuple17.java b/runtime/src/jet/Tuple17.java deleted file mode 100644 index c2cd770876f..00000000000 --- a/runtime/src/jet/Tuple17.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple17 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - public final T15 _15; - public final T16 _16; - public final T17 _17; - - public Tuple17(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16, T17 t17) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - _15 = t15; - _16 = t16; - _17 = t17; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ", " + _15 + ", " + _16 + ", " + _17 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - public final T15 get_15() { - return _15; - } - public final T16 get_16() { - return _16; - } - public final T17 get_17() { - return _17; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple17 t = (Tuple17) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - if (_15 != null ? !_15.equals(t._15) : t._15 != null) return false; - if (_16 != null ? !_16.equals(t._16) : t._16 != null) return false; - if (_17 != null ? !_17.equals(t._17) : t._17 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - result = 31 * result + (_15 != null ? _15.hashCode() : 0); - result = 31 * result + (_16 != null ? _16.hashCode() : 0); - result = 31 * result + (_17 != null ? _17.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - fn.invoke(_15); - fn.invoke(_16); - fn.invoke(_17); - } - - @Override - public int size() { - return 17; - } -} diff --git a/runtime/src/jet/Tuple18.java b/runtime/src/jet/Tuple18.java deleted file mode 100644 index d4b47515c0a..00000000000 --- a/runtime/src/jet/Tuple18.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple18 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - public final T15 _15; - public final T16 _16; - public final T17 _17; - public final T18 _18; - - public Tuple18(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16, T17 t17, T18 t18) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - _15 = t15; - _16 = t16; - _17 = t17; - _18 = t18; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ", " + _15 + ", " + _16 + ", " + _17 + ", " + _18 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - public final T15 get_15() { - return _15; - } - public final T16 get_16() { - return _16; - } - public final T17 get_17() { - return _17; - } - public final T18 get_18() { - return _18; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple18 t = (Tuple18) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - if (_15 != null ? !_15.equals(t._15) : t._15 != null) return false; - if (_16 != null ? !_16.equals(t._16) : t._16 != null) return false; - if (_17 != null ? !_17.equals(t._17) : t._17 != null) return false; - if (_18 != null ? !_18.equals(t._18) : t._18 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - result = 31 * result + (_15 != null ? _15.hashCode() : 0); - result = 31 * result + (_16 != null ? _16.hashCode() : 0); - result = 31 * result + (_17 != null ? _17.hashCode() : 0); - result = 31 * result + (_18 != null ? _18.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - fn.invoke(_15); - fn.invoke(_16); - fn.invoke(_17); - fn.invoke(_18); - } - - @Override - public int size() { - return 18; - } -} diff --git a/runtime/src/jet/Tuple19.java b/runtime/src/jet/Tuple19.java deleted file mode 100644 index f63ff76c149..00000000000 --- a/runtime/src/jet/Tuple19.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple19 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - public final T15 _15; - public final T16 _16; - public final T17 _17; - public final T18 _18; - public final T19 _19; - - public Tuple19(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16, T17 t17, T18 t18, T19 t19) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - _15 = t15; - _16 = t16; - _17 = t17; - _18 = t18; - _19 = t19; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ", " + _15 + ", " + _16 + ", " + _17 + ", " + _18 + ", " + _19 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - public final T15 get_15() { - return _15; - } - public final T16 get_16() { - return _16; - } - public final T17 get_17() { - return _17; - } - public final T18 get_18() { - return _18; - } - public final T19 get_19() { - return _19; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple19 t = (Tuple19) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - if (_15 != null ? !_15.equals(t._15) : t._15 != null) return false; - if (_16 != null ? !_16.equals(t._16) : t._16 != null) return false; - if (_17 != null ? !_17.equals(t._17) : t._17 != null) return false; - if (_18 != null ? !_18.equals(t._18) : t._18 != null) return false; - if (_19 != null ? !_19.equals(t._19) : t._19 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - result = 31 * result + (_15 != null ? _15.hashCode() : 0); - result = 31 * result + (_16 != null ? _16.hashCode() : 0); - result = 31 * result + (_17 != null ? _17.hashCode() : 0); - result = 31 * result + (_18 != null ? _18.hashCode() : 0); - result = 31 * result + (_19 != null ? _19.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - fn.invoke(_15); - fn.invoke(_16); - fn.invoke(_17); - fn.invoke(_18); - fn.invoke(_19); - } - - @Override - public int size() { - return 19; - } -} diff --git a/runtime/src/jet/Tuple2.java b/runtime/src/jet/Tuple2.java deleted file mode 100644 index 40f35220286..00000000000 --- a/runtime/src/jet/Tuple2.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple2 extends Tuple { - public final T1 _1; - public final T2 _2; - - public Tuple2(T1 t1, T2 t2) { - _1 = t1; - _2 = t2; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple2 t = (Tuple2) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - } - - @Override - public int size() { - return 2; - } -} diff --git a/runtime/src/jet/Tuple20.java b/runtime/src/jet/Tuple20.java deleted file mode 100644 index ef3e431b718..00000000000 --- a/runtime/src/jet/Tuple20.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple20 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - public final T15 _15; - public final T16 _16; - public final T17 _17; - public final T18 _18; - public final T19 _19; - public final T20 _20; - - public Tuple20(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16, T17 t17, T18 t18, T19 t19, T20 t20) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - _15 = t15; - _16 = t16; - _17 = t17; - _18 = t18; - _19 = t19; - _20 = t20; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ", " + _15 + ", " + _16 + ", " + _17 + ", " + _18 + ", " + _19 + ", " + _20 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - public final T15 get_15() { - return _15; - } - public final T16 get_16() { - return _16; - } - public final T17 get_17() { - return _17; - } - public final T18 get_18() { - return _18; - } - public final T19 get_19() { - return _19; - } - public final T20 get_20() { - return _20; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple20 t = (Tuple20) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - if (_15 != null ? !_15.equals(t._15) : t._15 != null) return false; - if (_16 != null ? !_16.equals(t._16) : t._16 != null) return false; - if (_17 != null ? !_17.equals(t._17) : t._17 != null) return false; - if (_18 != null ? !_18.equals(t._18) : t._18 != null) return false; - if (_19 != null ? !_19.equals(t._19) : t._19 != null) return false; - if (_20 != null ? !_20.equals(t._20) : t._20 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - result = 31 * result + (_15 != null ? _15.hashCode() : 0); - result = 31 * result + (_16 != null ? _16.hashCode() : 0); - result = 31 * result + (_17 != null ? _17.hashCode() : 0); - result = 31 * result + (_18 != null ? _18.hashCode() : 0); - result = 31 * result + (_19 != null ? _19.hashCode() : 0); - result = 31 * result + (_20 != null ? _20.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - fn.invoke(_15); - fn.invoke(_16); - fn.invoke(_17); - fn.invoke(_18); - fn.invoke(_19); - fn.invoke(_20); - } - - @Override - public int size() { - return 20; - } -} diff --git a/runtime/src/jet/Tuple21.java b/runtime/src/jet/Tuple21.java deleted file mode 100644 index ff9b0751724..00000000000 --- a/runtime/src/jet/Tuple21.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple21 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - public final T15 _15; - public final T16 _16; - public final T17 _17; - public final T18 _18; - public final T19 _19; - public final T20 _20; - public final T21 _21; - - public Tuple21(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16, T17 t17, T18 t18, T19 t19, T20 t20, T21 t21) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - _15 = t15; - _16 = t16; - _17 = t17; - _18 = t18; - _19 = t19; - _20 = t20; - _21 = t21; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ", " + _15 + ", " + _16 + ", " + _17 + ", " + _18 + ", " + _19 + ", " + _20 + ", " + _21 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - public final T15 get_15() { - return _15; - } - public final T16 get_16() { - return _16; - } - public final T17 get_17() { - return _17; - } - public final T18 get_18() { - return _18; - } - public final T19 get_19() { - return _19; - } - public final T20 get_20() { - return _20; - } - public final T21 get_21() { - return _21; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple21 t = (Tuple21) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - if (_15 != null ? !_15.equals(t._15) : t._15 != null) return false; - if (_16 != null ? !_16.equals(t._16) : t._16 != null) return false; - if (_17 != null ? !_17.equals(t._17) : t._17 != null) return false; - if (_18 != null ? !_18.equals(t._18) : t._18 != null) return false; - if (_19 != null ? !_19.equals(t._19) : t._19 != null) return false; - if (_20 != null ? !_20.equals(t._20) : t._20 != null) return false; - if (_21 != null ? !_21.equals(t._21) : t._21 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - result = 31 * result + (_15 != null ? _15.hashCode() : 0); - result = 31 * result + (_16 != null ? _16.hashCode() : 0); - result = 31 * result + (_17 != null ? _17.hashCode() : 0); - result = 31 * result + (_18 != null ? _18.hashCode() : 0); - result = 31 * result + (_19 != null ? _19.hashCode() : 0); - result = 31 * result + (_20 != null ? _20.hashCode() : 0); - result = 31 * result + (_21 != null ? _21.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - fn.invoke(_15); - fn.invoke(_16); - fn.invoke(_17); - fn.invoke(_18); - fn.invoke(_19); - fn.invoke(_20); - fn.invoke(_21); - } - - @Override - public int size() { - return 21; - } -} diff --git a/runtime/src/jet/Tuple22.java b/runtime/src/jet/Tuple22.java deleted file mode 100644 index d17613849dd..00000000000 --- a/runtime/src/jet/Tuple22.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple22 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - public final T10 _10; - public final T11 _11; - public final T12 _12; - public final T13 _13; - public final T14 _14; - public final T15 _15; - public final T16 _16; - public final T17 _17; - public final T18 _18; - public final T19 _19; - public final T20 _20; - public final T21 _21; - public final T22 _22; - - public Tuple22(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13, T14 t14, T15 t15, T16 t16, T17 t17, T18 t18, T19 t19, T20 t20, T21 t21, T22 t22) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - _10 = t10; - _11 = t11; - _12 = t12; - _13 = t13; - _14 = t14; - _15 = t15; - _16 = t16; - _17 = t17; - _18 = t18; - _19 = t19; - _20 = t20; - _21 = t21; - _22 = t22; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ", " + _10 + ", " + _11 + ", " + _12 + ", " + _13 + ", " + _14 + ", " + _15 + ", " + _16 + ", " + _17 + ", " + _18 + ", " + _19 + ", " + _20 + ", " + _21 + ", " + _22 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - public final T10 get_10() { - return _10; - } - public final T11 get_11() { - return _11; - } - public final T12 get_12() { - return _12; - } - public final T13 get_13() { - return _13; - } - public final T14 get_14() { - return _14; - } - public final T15 get_15() { - return _15; - } - public final T16 get_16() { - return _16; - } - public final T17 get_17() { - return _17; - } - public final T18 get_18() { - return _18; - } - public final T19 get_19() { - return _19; - } - public final T20 get_20() { - return _20; - } - public final T21 get_21() { - return _21; - } - public final T22 get_22() { - return _22; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple22 t = (Tuple22) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - if (_10 != null ? !_10.equals(t._10) : t._10 != null) return false; - if (_11 != null ? !_11.equals(t._11) : t._11 != null) return false; - if (_12 != null ? !_12.equals(t._12) : t._12 != null) return false; - if (_13 != null ? !_13.equals(t._13) : t._13 != null) return false; - if (_14 != null ? !_14.equals(t._14) : t._14 != null) return false; - if (_15 != null ? !_15.equals(t._15) : t._15 != null) return false; - if (_16 != null ? !_16.equals(t._16) : t._16 != null) return false; - if (_17 != null ? !_17.equals(t._17) : t._17 != null) return false; - if (_18 != null ? !_18.equals(t._18) : t._18 != null) return false; - if (_19 != null ? !_19.equals(t._19) : t._19 != null) return false; - if (_20 != null ? !_20.equals(t._20) : t._20 != null) return false; - if (_21 != null ? !_21.equals(t._21) : t._21 != null) return false; - if (_22 != null ? !_22.equals(t._22) : t._22 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - result = 31 * result + (_10 != null ? _10.hashCode() : 0); - result = 31 * result + (_11 != null ? _11.hashCode() : 0); - result = 31 * result + (_12 != null ? _12.hashCode() : 0); - result = 31 * result + (_13 != null ? _13.hashCode() : 0); - result = 31 * result + (_14 != null ? _14.hashCode() : 0); - result = 31 * result + (_15 != null ? _15.hashCode() : 0); - result = 31 * result + (_16 != null ? _16.hashCode() : 0); - result = 31 * result + (_17 != null ? _17.hashCode() : 0); - result = 31 * result + (_18 != null ? _18.hashCode() : 0); - result = 31 * result + (_19 != null ? _19.hashCode() : 0); - result = 31 * result + (_20 != null ? _20.hashCode() : 0); - result = 31 * result + (_21 != null ? _21.hashCode() : 0); - result = 31 * result + (_22 != null ? _22.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - fn.invoke(_10); - fn.invoke(_11); - fn.invoke(_12); - fn.invoke(_13); - fn.invoke(_13); - fn.invoke(_14); - fn.invoke(_15); - fn.invoke(_16); - fn.invoke(_17); - fn.invoke(_18); - fn.invoke(_19); - fn.invoke(_20); - fn.invoke(_22); - } - - @Override - public int size() { - return 22; - } -} diff --git a/runtime/src/jet/Tuple3.java b/runtime/src/jet/Tuple3.java deleted file mode 100644 index c8624d97b9c..00000000000 --- a/runtime/src/jet/Tuple3.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple3 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - - public Tuple3(T1 t1, T2 t2, T3 t3) { - _1 = t1; - _2 = t2; - _3 = t3; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple3 t = (Tuple3) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - } - - @Override - public int size() { - return 3; - } -} diff --git a/runtime/src/jet/Tuple4.java b/runtime/src/jet/Tuple4.java deleted file mode 100644 index 9303c50e039..00000000000 --- a/runtime/src/jet/Tuple4.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple4 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - - public Tuple4(T1 t1, T2 t2, T3 t3, T4 t4) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple4 t = (Tuple4) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - } - - @Override - public int size() { - return 4; - } -} diff --git a/runtime/src/jet/Tuple5.java b/runtime/src/jet/Tuple5.java deleted file mode 100644 index 35d8553f298..00000000000 --- a/runtime/src/jet/Tuple5.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple5 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - - public Tuple5(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple5 t = (Tuple5) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - } - - @Override - public int size() { - return 5; - } -} diff --git a/runtime/src/jet/Tuple6.java b/runtime/src/jet/Tuple6.java deleted file mode 100644 index ff10829be89..00000000000 --- a/runtime/src/jet/Tuple6.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple6 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - - public Tuple6(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple6 t = (Tuple6) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - } - - @Override - public int size() { - return 6; - } -} diff --git a/runtime/src/jet/Tuple7.java b/runtime/src/jet/Tuple7.java deleted file mode 100644 index 31b453c3ae5..00000000000 --- a/runtime/src/jet/Tuple7.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple7 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - - public Tuple7(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple7 t = (Tuple7) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - } - - @Override - public int size() { - return 7; - } -} diff --git a/runtime/src/jet/Tuple8.java b/runtime/src/jet/Tuple8.java deleted file mode 100644 index c257346ca54..00000000000 --- a/runtime/src/jet/Tuple8.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple8 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - - public Tuple8(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple8 t = (Tuple8) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - } - - @Override - public int size() { - return 8; - } -} diff --git a/runtime/src/jet/Tuple9.java b/runtime/src/jet/Tuple9.java deleted file mode 100644 index 1a7e4f5ddb1..00000000000 --- a/runtime/src/jet/Tuple9.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jet; - -import org.jetbrains.jet.rt.annotation.AssertInvisibleInResolver; - -@AssertInvisibleInResolver -public class Tuple9 extends Tuple { - public final T1 _1; - public final T2 _2; - public final T3 _3; - public final T4 _4; - public final T5 _5; - public final T6 _6; - public final T7 _7; - public final T8 _8; - public final T9 _9; - - public Tuple9(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) { - _1 = t1; - _2 = t2; - _3 = t3; - _4 = t4; - _5 = t5; - _6 = t6; - _7 = t7; - _8 = t8; - _9 = t9; - } - - @Override - public String toString() { - return "(" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + ")"; - } - public final T1 get_1() { - return _1; - } - public final T2 get_2() { - return _2; - } - public final T3 get_3() { - return _3; - } - public final T4 get_4() { - return _4; - } - public final T5 get_5() { - return _5; - } - public final T6 get_6() { - return _6; - } - public final T7 get_7() { - return _7; - } - public final T8 get_8() { - return _8; - } - public final T9 get_9() { - return _9; - } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Tuple9 t = (Tuple9) o; - if (_1 != null ? !_1.equals(t._1) : t._1 != null) return false; - if (_2 != null ? !_2.equals(t._2) : t._2 != null) return false; - if (_3 != null ? !_3.equals(t._3) : t._3 != null) return false; - if (_4 != null ? !_4.equals(t._4) : t._4 != null) return false; - if (_5 != null ? !_5.equals(t._5) : t._5 != null) return false; - if (_6 != null ? !_6.equals(t._6) : t._6 != null) return false; - if (_7 != null ? !_7.equals(t._7) : t._7 != null) return false; - if (_8 != null ? !_8.equals(t._8) : t._8 != null) return false; - if (_9 != null ? !_9.equals(t._9) : t._9 != null) return false; - return true; - } - @Override - public int hashCode() { - int result = _1 != null ? _1.hashCode() : 0; - result = 31 * result + (_2 != null ? _2.hashCode() : 0); - result = 31 * result + (_3 != null ? _3.hashCode() : 0); - result = 31 * result + (_4 != null ? _4.hashCode() : 0); - result = 31 * result + (_5 != null ? _5.hashCode() : 0); - result = 31 * result + (_6 != null ? _6.hashCode() : 0); - result = 31 * result + (_7 != null ? _7.hashCode() : 0); - result = 31 * result + (_8 != null ? _8.hashCode() : 0); - result = 31 * result + (_9 != null ? _9.hashCode() : 0); - return result; - } - - @Override - public void forEach(Function1 fn) { - fn.invoke(_1); - fn.invoke(_2); - fn.invoke(_3); - fn.invoke(_4); - fn.invoke(_5); - fn.invoke(_6); - fn.invoke(_7); - fn.invoke(_8); - fn.invoke(_9); - } - - @Override - public int size() { - return 9; - } -} diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureAdapter.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureAdapter.java index a2abeab9256..0f5bed09806 100644 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureAdapter.java +++ b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureAdapter.java @@ -84,7 +84,7 @@ public class JetSignatureAdapter implements JetSignatureVisitor { } @Override - public void visitInnerClassType(String name, boolean nullable) { + public void visitInnerClassType(String name, boolean nullable, boolean forceReal) { } @Override diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureExceptionsAdapter.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureExceptionsAdapter.java index 4874a8c3ff1..a789c096a93 100644 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureExceptionsAdapter.java +++ b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureExceptionsAdapter.java @@ -88,7 +88,7 @@ public class JetSignatureExceptionsAdapter implements JetSignatureVisitor { } @Override - public void visitInnerClassType(String name, boolean nullable) { + public void visitInnerClassType(String name, boolean nullable, boolean forceReal) { throw new IllegalStateException(); } diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureReader.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureReader.java index bf2e4bdadf4..c255c4c8aca 100644 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureReader.java +++ b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureReader.java @@ -144,15 +144,19 @@ public class JetSignatureReader { } char c; - int start, end; - boolean visited, inner; - String name; + int start; + int end; + boolean visited; + boolean inner; - boolean nullable = false; + boolean nullable; if (signature.charAt(pos) == '?') { nullable = true; pos++; } + else { + nullable = false; + } switch (c = signature.charAt(pos++)) { case 'Z': @@ -186,53 +190,23 @@ public class JetSignatureReader { case '.': case ';': if (!visited) { - name = signature.substring(start, pos - 1); - if (inner) { - v.visitInnerClassType(name, nullable); - } - else { - v.visitClassType(name, nullable, forceReal); - } + parseTypeConstructor(signature, v, start, pos, inner, nullable, forceReal); } if (c == ';') { v.visitEnd(); return pos; } - start = pos; visited = false; inner = true; break; case '<': - name = signature.substring(start, pos - 1); - if (inner) { - v.visitInnerClassType(name, nullable); - } - else { - v.visitClassType(name, nullable, forceReal); - } + parseTypeConstructor(signature, v, start, pos, inner, nullable, forceReal); visited = true; - top: while (true) { - switch (c = signature.charAt(pos)) { - case '>': - break top; - case '*': - ++pos; - v.visitTypeArgument(); - break; - case '+': - case '-': - pos = parseType(signature, - pos + 1, - v.visitTypeArgument(JetSignatureVariance.parseVariance(c))); - break; - default: - pos = parseType(signature, - pos, - v.visitTypeArgument(JetSignatureVariance.INVARIANT)); - break; - } - } + pos = parseTypeArguments(signature, pos, v); + + default: + break; } } default: @@ -240,5 +214,46 @@ public class JetSignatureReader { } } + private static void parseTypeConstructor( + String signature, + JetSignatureVisitor v, + int start, + int pos, + boolean inner, + boolean nullable, + boolean forceReal + ) { + String name = signature.substring(start, pos - 1); + if (inner) { + v.visitInnerClassType(name, nullable, forceReal); + } + else { + v.visitClassType(name, nullable, forceReal); + } + } + private static int parseTypeArguments(String signature, int pos, JetSignatureVisitor v) { + char c; + while (true) { + switch (c = signature.charAt(pos)) { + case '>': + return pos; + case '*': + ++pos; + v.visitTypeArgument(); + break; + case '+': + case '-': + pos = parseType(signature, + pos + 1, + v.visitTypeArgument(JetSignatureVariance.parseVariance(c))); + break; + default: + pos = parseType(signature, + pos, + v.visitTypeArgument(JetSignatureVariance.INVARIANT)); + break; + } + } + } } diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVisitor.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVisitor.java index 5e1a8f85d7d..95d95cdd477 100644 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVisitor.java +++ b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVisitor.java @@ -136,9 +136,9 @@ public interface JetSignatureVisitor { /** * Visits an inner class. * - * @param name the local name of the inner class in its enclosing class. + * @param name the full name of the inner class. */ - void visitInnerClassType(String name, boolean nullable); + void visitInnerClassType(String name, boolean nullable, boolean forceReal); /** * Visits an unbounded type argument of the last visited class or inner diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureWriter.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureWriter.java index b1842d5a574..cdc5f1db008 100644 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureWriter.java +++ b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureWriter.java @@ -172,7 +172,7 @@ public class JetSignatureWriter implements JetSignatureVisitor { } @Override - public void visitInnerClassType(final String name, boolean nullable) { + public void visitInnerClassType(final String name, boolean nullable, boolean forceReal) { endArguments(); visitNullabe(nullable); buf.append('.');