Search in sources :

Example 1 with KtDeclarationContainer

use of org.jetbrains.kotlin.psi.KtDeclarationContainer in project intellij by bazelbuild.

the class BlazeKotlinRunConfigurationProducer method getTargetIdeInfo.

@Nullable
private static TargetIdeInfo getTargetIdeInfo(ConfigurationContext context) {
    Location<?> location = context.getLocation();
    if (location == null) {
        return null;
    }
    VirtualFile virtualFile = location.getVirtualFile();
    if (virtualFile == null) {
        return null;
    }
    KtDeclarationContainer entryPointContainer = KotlinRunConfigurationProducer.Companion.getEntryPointContainer(location.getPsiElement());
    if (entryPointContainer == null) {
        return null;
    }
    String startClassFqName = KotlinRunConfigurationProducer.Companion.getStartClassFqName(entryPointContainer);
    if (startClassFqName == null) {
        return null;
    }
    Collection<TargetIdeInfo> kotlinBinaryTargets = findKotlinBinaryTargets(context.getProject(), VfsUtil.virtualToIoFile(virtualFile));
    // first look for a matching main_class
    TargetIdeInfo match = kotlinBinaryTargets.stream().filter(target -> target.javaIdeInfo != null && startClassFqName.equals(target.javaIdeInfo.javaBinaryMainClass)).findFirst().orElse(null);
    if (match != null) {
        return match;
    }
    match = kotlinBinaryTargets.stream().filter(target -> startClassFqName.equals(target.key.label.targetName().toString())).findFirst().orElse(null);
    if (match != null) {
        return match;
    }
    return Iterables.getFirst(kotlinBinaryTargets, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Iterables(com.google.common.collect.Iterables) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) FilteredTargetMap(com.google.idea.blaze.base.run.testmap.FilteredTargetMap) BlazeCommandRunConfigurationType(com.google.idea.blaze.base.run.BlazeCommandRunConfigurationType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) KotlinRunConfigurationProducer(org.jetbrains.kotlin.idea.run.KotlinRunConfigurationProducer) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ImmutableList(com.google.common.collect.ImmutableList) PsiElement(com.intellij.psi.PsiElement) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) BlazeRunConfigurationProducer(com.google.idea.blaze.base.run.producers.BlazeRunConfigurationProducer) Nullable(javax.annotation.Nullable) Collection(java.util.Collection) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) File(java.io.File) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) Objects(java.util.Objects) SyncCache(com.google.idea.blaze.base.sync.SyncCache) KtDeclarationContainer(org.jetbrains.kotlin.psi.KtDeclarationContainer) VfsUtil(com.intellij.openapi.vfs.VfsUtil) Location(com.intellij.execution.Location) Ref(com.intellij.openapi.util.Ref) KtDeclarationContainer(org.jetbrains.kotlin.psi.KtDeclarationContainer) Nullable(javax.annotation.Nullable)

Example 2 with KtDeclarationContainer

use of org.jetbrains.kotlin.psi.KtDeclarationContainer in project kotlin by JetBrains.

the class JetRunConfiguration method updateMainClassName.

private void updateMainClassName(PsiElement element) {
    KtDeclarationContainer container = KotlinRunConfigurationProducer.Companion.getEntryPointContainer(element);
    String name = KotlinRunConfigurationProducer.Companion.getStartClassFqName(container);
    if (name != null) {
        MAIN_CLASS_NAME = name;
    }
}
Also used : KtDeclarationContainer(org.jetbrains.kotlin.psi.KtDeclarationContainer)

Aggregations

KtDeclarationContainer (org.jetbrains.kotlin.psi.KtDeclarationContainer)2 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)1 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 Kind (com.google.idea.blaze.base.model.primitives.Kind)1 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)1 BlazeCommandRunConfigurationType (com.google.idea.blaze.base.run.BlazeCommandRunConfigurationType)1 BlazeRunConfigurationProducer (com.google.idea.blaze.base.run.producers.BlazeRunConfigurationProducer)1 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)1 FilteredTargetMap (com.google.idea.blaze.base.run.testmap.FilteredTargetMap)1 SyncCache (com.google.idea.blaze.base.sync.SyncCache)1 Location (com.intellij.execution.Location)1 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 Project (com.intellij.openapi.project.Project)1 Ref (com.intellij.openapi.util.Ref)1 VfsUtil (com.intellij.openapi.vfs.VfsUtil)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1