use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class KotlinBytecodeToolWindow method compileSingleFile.
@NotNull
public static GenerationState compileSingleFile(@NotNull final KtFile ktFile, @NotNull CompilerConfiguration configuration) {
ResolutionFacade resolutionFacade = ResolutionUtils.getResolutionFacade(ktFile);
BindingContext bindingContextForFile = resolutionFacade.analyzeFullyAndGetResult(Collections.singletonList(ktFile)).getBindingContext();
kotlin.Pair<BindingContext, List<KtFile>> result = DebuggerUtils.INSTANCE.analyzeInlinedFunctions(resolutionFacade, ktFile, configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE), bindingContextForFile);
BindingContext bindingContext = result.getFirst();
List<KtFile> toProcess = result.getSecond();
GenerationState.GenerateClassFilter generateClassFilter = new GenerationState.GenerateClassFilter() {
@Override
public boolean shouldGeneratePackagePart(@NotNull KtFile file) {
return file == ktFile;
}
@Override
public boolean shouldAnnotateClass(@NotNull KtClassOrObject processingClassOrObject) {
return true;
}
@Override
public boolean shouldGenerateClass(@NotNull KtClassOrObject processingClassOrObject) {
return processingClassOrObject.getContainingKtFile() == ktFile;
}
@Override
public boolean shouldGenerateScript(@NotNull KtScript script) {
return script.getContainingKtFile() == ktFile;
}
};
GenerationState state = new GenerationState(ktFile.getProject(), ClassBuilderFactories.TEST, resolutionFacade.getModuleDescriptor(), bindingContext, toProcess, configuration, generateClassFilter);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
return state;
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class KotlinBytecodeToolWindow method getBytecodeForFile.
// public for tests
@NotNull
public static String getBytecodeForFile(@NotNull KtFile ktFile, @NotNull CompilerConfiguration configuration) {
GenerationState state;
try {
state = compileSingleFile(ktFile, configuration);
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
return printStackTraceToString(e);
}
StringBuilder answer = new StringBuilder();
Collection<Diagnostic> diagnostics = state.getCollectedExtraJvmDiagnostics().all();
if (!diagnostics.isEmpty()) {
answer.append("// Backend Errors: \n");
answer.append("// ================\n");
for (Diagnostic diagnostic : diagnostics) {
answer.append("// Error at ").append(diagnostic.getPsiFile().getName()).append(StringsKt.join(diagnostic.getTextRanges(), ",")).append(": ").append(DefaultErrorMessages.render(diagnostic)).append("\n");
}
answer.append("// ================\n\n");
}
OutputFileCollection outputFiles = state.getFactory();
for (OutputFile outputFile : outputFiles.asList()) {
answer.append("// ================");
answer.append(outputFile.getRelativePath());
answer.append(" =================\n");
answer.append(outputFile.asText()).append("\n\n");
}
return answer.toString();
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class PluginJetFilesProvider method allFilesInProject.
@NotNull
public static Collection<KtFile> allFilesInProject(@NotNull Project project) {
Collection<KtFile> result = new ArrayList<KtFile>();
GlobalSearchScope scope = KotlinSourceFilterScope.sources(GlobalSearchScope.allScope(project), project);
for (String packageWithFiles : KotlinExactPackagesIndex.getInstance().getAllKeys(project)) {
result.addAll(KotlinExactPackagesIndex.getInstance().get(packageWithFiles, project, scope));
}
return result;
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class IdeStubIndexService method deserializeFileStub.
@NotNull
@Override
public KotlinFileStub deserializeFileStub(@NotNull StubInputStream dataStream) throws IOException {
StringRef packageFqNameAsString = dataStream.readName();
boolean isScript = dataStream.readBoolean();
StringRef facadeSimpleName = dataStream.readName();
StringRef partSimpleName = dataStream.readName();
int numPartNames = dataStream.readInt();
List<StringRef> facadePartNames = new ArrayList<StringRef>();
for (int i = 0; i < numPartNames; ++i) {
StringRef partNameRef = dataStream.readName();
facadePartNames.add(partNameRef);
}
return new KotlinFileStubForIde(null, packageFqNameAsString, isScript, facadeSimpleName, partSimpleName, facadePartNames);
}
use of org.jetbrains.annotations.NotNull in project kotlin by JetBrains.
the class IdeStubIndexService method createFileStub.
@NotNull
@Override
public KotlinFileStub createFileStub(@NotNull KtFile file) {
StringRef packageFqName = StringRef.fromString(file.getPackageFqNameByTree().asString());
boolean isScript = file.isScriptByTree();
if (PackagePartClassUtils.fileHasTopLevelCallables(file)) {
JvmFileClassInfo fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(file);
StringRef facadeSimpleName = StringRef.fromString(fileClassInfo.getFacadeClassFqName().shortName().asString());
StringRef partSimpleName = StringRef.fromString(fileClassInfo.getFileClassFqName().shortName().asString());
return new KotlinFileStubForIde(file, packageFqName, isScript, facadeSimpleName, partSimpleName, null);
}
return new KotlinFileStubForIde(file, packageFqName, isScript, null, null, null);
}
Aggregations