Search in sources :

Example 36 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeKotlinRunConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    TargetIdeInfo target = getTargetIdeInfo(context);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    return target != null && handlerState != null && Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.RUN) && configuration.getTarget() != null && Objects.equals(configuration.getTarget(), target.key.label);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)

Example 37 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeKotlinRunConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    Location<?> location = context.getLocation();
    if (location == null) {
        return false;
    }
    sourceElement.set(location.getPsiElement());
    TargetIdeInfo target = getTargetIdeInfo(context);
    if (target == null) {
        return false;
    }
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
    configuration.setTargetInfo(target.toTargetInfo());
    configuration.setGeneratedName();
    return true;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)

Example 38 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporter method importWorkspace.

public BlazeScalaImportResult importWorkspace() {
    ProjectViewTargetImportFilter importFilter = new ProjectViewTargetImportFilter(project, workspaceRoot, projectViewSet);
    Collection<Kind> scalaKinds = Kind.allKindsForLanguage(LanguageClass.SCALA);
    List<TargetKey> scalaSourceTargets = targetMap.targets().stream().filter(target -> target.javaIdeInfo != null).filter(target -> target.kindIsOneOf(scalaKinds)).filter(importFilter::isSourceTarget).map(target -> target.key).collect(Collectors.toList());
    Map<LibraryKey, BlazeJarLibrary> libraries = Maps.newHashMap();
    // but since they'll all merged into one set, we will end up with exactly one of each.
    for (TargetKey dependency : TransitiveDependencyMap.getTransitiveDependencies(scalaSourceTargets, targetMap)) {
        TargetIdeInfo target = targetMap.get(dependency);
        if (target == null) {
            continue;
        }
        // Except source targets.
        if (JavaSourceFilter.importAsSource(importFilter, target)) {
            continue;
        }
        if (target.javaIdeInfo != null) {
            target.javaIdeInfo.jars.stream().map(BlazeJarLibrary::new).forEach(library -> libraries.putIfAbsent(library.key, library));
        }
    }
    return new BlazeScalaImportResult(ImmutableMap.copyOf(libraries));
}
Also used : LibraryKey(com.google.idea.blaze.base.model.LibraryKey) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) TransitiveDependencyMap(com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap) List(java.util.List) Map(java.util.Map) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)

Example 39 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeScalaMainClassRunConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    ScObject mainObject = getMainObject(context);
    if (mainObject == null) {
        return false;
    }
    Option<PsiMethod> mainMethod = ScalaMainMethodUtil.findMainMethod(mainObject);
    if (mainMethod.isEmpty()) {
        sourceElement.set(mainObject);
    } else {
        sourceElement.set(mainMethod.get());
    }
    TargetIdeInfo target = getTarget(context.getProject(), mainObject);
    if (target == null) {
        return false;
    }
    configuration.setTargetInfo(target.toTargetInfo());
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
    configuration.setGeneratedName();
    return true;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) PsiMethod(com.intellij.psi.PsiMethod) ScObject(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject)

Example 40 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeScalaMainClassRunConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    if (!Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.RUN)) {
        return false;
    }
    ScObject mainObject = getMainObject(context);
    if (mainObject == null) {
        return false;
    }
    TargetIdeInfo target = getTarget(context.getProject(), mainObject);
    return target != null && Objects.equals(configuration.getTarget(), target.key.label);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ScObject(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject)

Aggregations

TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)57 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)28 File (java.io.File)20 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)19 Nullable (javax.annotation.Nullable)16 Kind (com.google.idea.blaze.base.model.primitives.Kind)15 ImmutableList (com.google.common.collect.ImmutableList)14 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)14 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)14 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)14 Project (com.intellij.openapi.project.Project)14 List (java.util.List)12 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)11 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)11 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)10 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)10 Collection (java.util.Collection)10 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)9 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)9 Set (java.util.Set)9