public void testConstants() throws Exception { assertType("1", builtIns.getIntType()); assertType("0x1", builtIns.getIntType()); assertType("0X1", builtIns.getIntType()); assertType("0b1", builtIns.getIntType()); assertType("0B1", builtIns.getIntType()); assertType("1.toLong()", builtIns.getLongType()); assertType("1.0", builtIns.getDoubleType()); assertType("1.0.toDouble()", builtIns.getDoubleType()); assertType("0x1.fffffffffffffp1023", builtIns.getDoubleType()); assertType("1.0.toFloat()", builtIns.getFloatType()); assertType("0x1.fffffffffffffp1023.toFloat()", builtIns.getFloatType()); assertType("true", builtIns.getBooleanType()); assertType("false", builtIns.getBooleanType()); assertType("'d'", builtIns.getCharType()); assertType("\"d\"", builtIns.getStringType()); assertType("\"\"\"d\"\"\"", builtIns.getStringType()); assertType("Unit", KotlinBuiltIns.getInstance().getUnitType()); assertType("null", KotlinBuiltIns.getInstance().getNullableNothingType()); }
private static boolean isFromBuiltinModule(@NotNull DeclarationDescriptor originalDescriptor) { // TODO This is optimization only // It should be rewritten by checking declarationDescriptor.getSource(), when the latter returns // something non-trivial for builtins. return KotlinBuiltIns.getInstance().getBuiltInsModule() == DescriptorUtils.getContainingModule(originalDescriptor); }
@Override public void setUp() throws Exception { super.setUp(); builtIns = KotlinBuiltIns.getInstance(); ContainerForTests container = DiPackage.createContainerForTests(getProject(), JetTestUtils.createEmptyModule()); typeResolver = container.getTypeResolver(); expressionTypingServices = container.getExpressionTypingServices(); scopeWithImports = getDeclarationsScope("compiler/testData/type-checker-test.kt"); }
@Override public boolean processUsage(JetChangeInfo changeInfo, PsiElement element) { JetParameterList parameterList; JetPsiFactory psiFactory = JetPsiFactory(element.getProject()); if (element instanceof JetFunction) { JetFunction function = (JetFunction) element; parameterList = function.getValueParameterList(); if (changeInfo.isNameChanged()) { PsiElement identifier = function.getNameIdentifier(); if (identifier != null) { identifier.replace(psiFactory.createIdentifier(changeInfo.getNewName())); } } boolean returnTypeIsNeeded = (changeInfo.isRefactoringTarget(originalFunctionDescriptor) || !(function instanceof JetFunctionLiteral) || function.getTypeReference() != null) && !(function instanceof JetSecondaryConstructor); if (changeInfo.isReturnTypeChanged() && returnTypeIsNeeded) { function.setTypeReference(null); String returnTypeText = changeInfo.renderReturnType((JetFunctionDefinitionUsage<PsiElement>) this); // TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) { ShortenPackage.addToShorteningWaitSet( function.setTypeReference(JetPsiFactory(function).createType(returnTypeText)), Options.DEFAULT); } } } else { parameterList = ((JetClass) element).getPrimaryConstructorParameterList(); } if (changeInfo.isParameterSetOrOrderChanged()) { processParameterListWithStructuralChanges(changeInfo, element, parameterList, psiFactory); } else if (parameterList != null) { int paramIndex = 0; for (JetParameter parameter : parameterList.getParameters()) { JetParameterInfo parameterInfo = changeInfo.getNewParameters()[paramIndex]; changeParameter(paramIndex, parameter, parameterInfo); paramIndex++; } ShortenPackage.addToShorteningWaitSet(parameterList, Options.DEFAULT); } if (element instanceof JetFunction && changeInfo.isReceiverTypeChanged()) { //noinspection unchecked String receiverTypeText = changeInfo.renderReceiverType((JetFunctionDefinitionUsage<PsiElement>) this); JetTypeReference receiverTypeRef = receiverTypeText != null ? psiFactory.createType(receiverTypeText) : null; JetTypeReference newReceiverTypeRef = TypeRefHelpersPackage.setReceiverTypeReference((JetFunction) element, receiverTypeRef); if (newReceiverTypeRef != null) { ShortenPackage.addToShorteningWaitSet( newReceiverTypeRef, ShortenReferences.Options.DEFAULT); } } if (changeInfo.isVisibilityChanged() && !JetPsiUtil.isLocal((JetDeclaration) element)) { changeVisibility(changeInfo, element); } return true; }
public void testJumps() throws Exception { assertType("throw java.lang.Exception()", KotlinBuiltIns.getInstance().getNothingType()); assertType("continue", KotlinBuiltIns.getInstance().getNothingType()); assertType("break", KotlinBuiltIns.getInstance().getNothingType()); }