Search in sources :

Example 96 with NotNull

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;
}
Also used : KtClassOrObject(org.jetbrains.kotlin.psi.KtClassOrObject) KtScript(org.jetbrains.kotlin.psi.KtScript) BindingContext(org.jetbrains.kotlin.resolve.BindingContext) NotNull(org.jetbrains.annotations.NotNull) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) ResolutionFacade(org.jetbrains.kotlin.idea.resolve.ResolutionFacade) List(java.util.List) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with NotNull

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();
}
Also used : OutputFile(org.jetbrains.kotlin.backend.common.output.OutputFile) OutputFileCollection(org.jetbrains.kotlin.backend.common.output.OutputFileCollection) Diagnostic(org.jetbrains.kotlin.diagnostics.Diagnostic) GenerationState(org.jetbrains.kotlin.codegen.state.GenerationState) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 98 with NotNull

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;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) KtFile(org.jetbrains.kotlin.psi.KtFile) NotNull(org.jetbrains.annotations.NotNull)

Example 99 with NotNull

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);
}
Also used : ArrayList(java.util.ArrayList) StringRef(com.intellij.util.io.StringRef) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with NotNull

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);
}
Also used : JvmFileClassInfo(org.jetbrains.kotlin.fileClasses.JvmFileClassInfo) StringRef(com.intellij.util.io.StringRef) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)8141 VirtualFile (com.intellij.openapi.vfs.VirtualFile)888 ArrayList (java.util.ArrayList)809 PsiElement (com.intellij.psi.PsiElement)764 Project (com.intellij.openapi.project.Project)647 File (java.io.File)627 Nullable (org.jetbrains.annotations.Nullable)518 List (java.util.List)400 PsiFile (com.intellij.psi.PsiFile)358 Module (com.intellij.openapi.module.Module)336 IOException (java.io.IOException)325 TextRange (com.intellij.openapi.util.TextRange)260 Document (com.intellij.openapi.editor.Document)173 ContainerUtil (com.intellij.util.containers.ContainerUtil)173 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)169 ASTNode (com.intellij.lang.ASTNode)167 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)167 Map (java.util.Map)156 java.util (java.util)154 IElementType (com.intellij.psi.tree.IElementType)146