use of kotlin.Unit in project kotlin by JetBrains.
the class TypeSubstitutorTest method getContextScope.
private LexicalScope getContextScope() throws IOException {
// todo comments
String text = FileUtil.loadFile(new File("compiler/testData/type-substitutor.kt"), true);
KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile(text);
AnalysisResult analysisResult = JvmResolveUtil.analyze(ktFile, getEnvironment());
ModuleDescriptor module = analysisResult.getModuleDescriptor();
LexicalScope topLevelScope = analysisResult.getBindingContext().get(BindingContext.LEXICAL_SCOPE, ktFile);
final ClassifierDescriptor contextClass = ScopeUtilsKt.findClassifier(topLevelScope, Name.identifier("___Context"), NoLookupLocation.FROM_TEST);
assert contextClass instanceof ClassDescriptor;
LocalRedeclarationChecker redeclarationChecker = new ThrowingLocalRedeclarationChecker(new OverloadChecker(TypeSpecificityComparator.NONE.INSTANCE));
LexicalScope typeParameters = new LexicalScopeImpl(topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC, redeclarationChecker, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
handler.addClassifierDescriptor(parameterDescriptor);
}
return Unit.INSTANCE;
}
});
return new LexicalChainedScope(typeParameters, module, false, null, LexicalScopeKind.SYNTHETIC, Arrays.asList(contextClass.getDefaultType().getMemberScope(), module.getBuiltIns().getBuiltInsPackageScope()));
}
use of kotlin.Unit in project kotlin by JetBrains.
the class AbstractBlackBoxCodegenTest method doLightAnalysisModeTest.
private void doLightAnalysisModeTest(@NotNull File wholeFile, @NotNull List<TestFile> files, @Nullable File javaFilesDir) {
if (SKIP_LIGHT_ANALYSIS_MODE_TESTS)
return;
File boxTestsDir = new File("compiler/testData/codegen/box");
String relativePath = FilesKt.toRelativeString(wholeFile, boxTestsDir);
// Do nothing if this test is not under codegen/box
if (relativePath.startsWith(".."))
return;
String outDir = new File("compiler/testData/codegen/light-analysis", relativePath).getParent();
File txtFile = new File(outDir, FilesKt.getNameWithoutExtension(wholeFile) + ".txt");
AbstractBytecodeListingTest.doTest(getTestRootDisposable(), files, javaFilesDir, txtFile, ClassBuilderFactories.TEST_KAPT3, new Function1<KotlinCoreEnvironment, Unit>() {
@Override
public Unit invoke(KotlinCoreEnvironment environment) {
AnalysisHandlerExtension.Companion.registerExtension(environment.getProject(), new PartialAnalysisHandlerExtension());
return Unit.INSTANCE;
}
});
}
use of kotlin.Unit in project kotlin by JetBrains.
the class CompileEnvironmentUtil method getKtFiles.
@NotNull
public static List<KtFile> getKtFiles(@NotNull final Project project, @NotNull Collection<String> sourceRoots, @NotNull CompilerConfiguration configuration, @NotNull Function1<String, Unit> reportError) throws IOException {
final VirtualFileSystem localFileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL);
final Set<VirtualFile> processedFiles = Sets.newHashSet();
final List<KtFile> result = Lists.newArrayList();
for (String sourceRootPath : sourceRoots) {
if (sourceRootPath == null) {
continue;
}
VirtualFile vFile = localFileSystem.findFileByPath(sourceRootPath);
if (vFile == null) {
String message = "Source file or directory not found: " + sourceRootPath;
File moduleFilePath = configuration.get(JVMConfigurationKeys.MODULE_XML_FILE);
if (moduleFilePath != null) {
String moduleFileContent = FileUtil.loadFile(moduleFilePath);
LOG.warn(message + "\n\nmodule file path: " + moduleFilePath + "\ncontent:\n" + moduleFileContent);
}
reportError.invoke(message);
continue;
}
if (!vFile.isDirectory() && vFile.getFileType() != KotlinFileType.INSTANCE) {
reportError.invoke("Source entry is not a Kotlin file: " + sourceRootPath);
continue;
}
SequencesKt.forEach(FilesKt.walkTopDown(new File(sourceRootPath)), new Function1<File, Unit>() {
@Override
public Unit invoke(File file) {
if (file.isFile()) {
VirtualFile virtualFile = localFileSystem.findFileByPath(file.getAbsolutePath());
if (virtualFile != null && !processedFiles.contains(virtualFile)) {
processedFiles.add(virtualFile);
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile instanceof KtFile) {
result.add((KtFile) psiFile);
}
}
}
return Unit.INSTANCE;
}
});
}
return result;
}
use of kotlin.Unit in project kotlin by JetBrains.
the class ExpressionCodegen method visitBinaryWithTypeRHSExpression.
@Override
public StackValue visitBinaryWithTypeRHSExpression(@NotNull KtBinaryExpressionWithTypeRHS expression, StackValue receiver) {
KtExpression left = expression.getLeft();
final IElementType opToken = expression.getOperationReference().getReferencedNameElementType();
final KotlinType rightType = bindingContext.get(TYPE, expression.getRight());
assert rightType != null;
final StackValue value = genQualified(receiver, left);
return StackValue.operation(boxType(asmType(rightType)), new Function1<InstructionAdapter, Unit>() {
@Override
public Unit invoke(InstructionAdapter v) {
value.put(boxType(value.type), v);
if (value.type == Type.VOID_TYPE) {
StackValue.putUnitInstance(v);
}
boolean safeAs = opToken == KtTokens.AS_SAFE;
Type type = boxType(asmType(rightType));
if (TypeUtils.isReifiedTypeParameter(rightType)) {
putReifiedOperationMarkerIfTypeIsReifiedParameter(rightType, safeAs ? ReifiedTypeInliner.OperationKind.SAFE_AS : ReifiedTypeInliner.OperationKind.AS);
v.checkcast(type);
return Unit.INSTANCE;
}
CodegenUtilKt.generateAsCast(v, rightType, type, safeAs);
return Unit.INSTANCE;
}
});
}
use of kotlin.Unit in project kotlin by JetBrains.
the class ExpressionCodegen method generateElvis.
private StackValue generateElvis(@NotNull final KtBinaryExpression expression) {
KtExpression left = expression.getLeft();
final Type exprType = expressionType(expression);
final Type leftType = expressionType(left);
final Label ifNull = new Label();
assert left != null : "left expression in elvis should be not null: " + expression.getText();
final StackValue value = generateExpressionWithNullFallback(left, ifNull);
if (isPrimitive(leftType)) {
return value;
}
return StackValue.operation(exprType, new Function1<InstructionAdapter, Unit>() {
@Override
public Unit invoke(InstructionAdapter v) {
value.put(value.type, v);
v.dup();
v.ifnull(ifNull);
StackValue.onStack(leftType).put(exprType, v);
Label end = new Label();
v.goTo(end);
v.mark(ifNull);
v.pop();
gen(expression.getRight(), exprType);
v.mark(end);
return null;
}
});
}
Aggregations