Search in sources :

Example 16 with MockBlazeProjectDataBuilder

use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder in project intellij by bazelbuild.

the class BlazeScalaMainClassConfigurationProducerTest method testNoResultForObjectWithoutMainMethod.

@Test
public void testNoResultForObjectWithoutMainMethod() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/MainClass.scala")).setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.MainClass")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary { object MainClass {} }", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
    assertThat(createConfigurationFromLocation(scalaFile)).isNull();
}
Also used : MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 17 with MockBlazeProjectDataBuilder

use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder in project intellij by bazelbuild.

the class BlazeScalaMainClassConfigurationProducerTest method testScalaBinaryWithMatchingNameChosen.

@Test
public void testScalaBinaryWithMatchingNameChosen() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:UnrelatedName").addSource(sourceRoot("com/google/binary/MainClass.scala")).build()).addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/MainClass.scala")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary {", "  object MainClass {", "    def main(args: Array[String]) {}", "  }", "}", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
    RunConfiguration config = createConfigurationFromLocation(scalaFile);
    assertThat(config).isInstanceOf(BlazeRunConfiguration.class);
    BlazeRunConfiguration blazeConfig = (BlazeRunConfiguration) config;
    assertThat(blazeConfig).isNotNull();
    assertThat(blazeConfig.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//com/google/binary:MainClass"));
}
Also used : BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 18 with MockBlazeProjectDataBuilder

use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder in project intellij by bazelbuild.

the class BlazeScalaMainClassConfigurationProducerTest method testNoScalaBinaryChosenIfNotInRDeps.

@Test
public void testNoScalaBinaryChosenIfNotInRDeps() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/OtherClass.scala")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary {", "  object MainClass {", "    def main(args: Array[String]) {}", "  }", "}", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
    assertThat(createConfigurationFromLocation(scalaFile)).isNotInstanceOf(BlazeRunConfiguration.class);
}
Also used : MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 19 with MockBlazeProjectDataBuilder

use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder in project intellij by bazelbuild.

the class BlazeScalaMainClassConfigurationProducerTest method testScalaBinaryWithMatchingMainClassChosen.

@Test
public void testScalaBinaryWithMatchingMainClassChosen() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:UnrelatedName").addSource(sourceRoot("com/google/binary/MainClass.scala")).build()).addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:OtherName").setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.MainClass")).addSource(sourceRoot("com/google/binary/MainClass.scala")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary {", "  object MainClass {", "    def main(args: Array[String]) {}", "  }", "}", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
    RunConfiguration config = createConfigurationFromLocation(scalaFile);
    assertThat(config).isInstanceOf(BlazeRunConfiguration.class);
    BlazeRunConfiguration blazeConfig = (BlazeRunConfiguration) config;
    assertThat(blazeConfig).isNotNull();
    assertThat(blazeConfig.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//com/google/binary:OtherName"));
}
Also used : BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 20 with MockBlazeProjectDataBuilder

use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder in project intellij by bazelbuild.

the class TestRecorderBlazeCommandRunConfigurationTest method doSetup.

@Before
public final void doSetup() {
    runManager = RunManagerImpl.getInstanceImpl(getProject());
    // Without BlazeProjectData, the configuration editor is always disabled.
    BlazeProjectDataManager mockProjectDataManager = new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).build());
    registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager);
    BlazeCommandRunConfigurationHandlerProvider mockHandler = new MockBlazeAndroidBinaryRunConfigurationHandlerProvider();
    ExtensionPoint<BlazeCommandRunConfigurationHandlerProvider> ep = Extensions.getRootArea().getExtensionPoint(BlazeCommandRunConfigurationHandlerProvider.EP_NAME);
    ep.registerExtension(mockHandler, LoadingOrder.FIRST);
    Disposer.register(getTestRootDisposable(), () -> ep.unregisterExtension(mockHandler));
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind(Kind.ANDROID_BINARY).setLabel("//label:android_binary_rule").build()).addTarget(TargetIdeInfo.builder().setKind(Kind.ANDROID_TEST).setLabel("//label:android_test_rule").build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
}
Also used : BlazeCommandRunConfigurationHandlerProvider(com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationHandlerProvider) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Before(org.junit.Before)

Aggregations

MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)42 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)42 Test (org.junit.Test)40 PsiFile (com.intellij.psi.PsiFile)37 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)23 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)21 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)10 BlazeRunConfiguration (com.google.idea.blaze.base.run.BlazeRunConfiguration)8 PsiClass (com.intellij.psi.PsiClass)7 PsiDirectory (com.intellij.psi.PsiDirectory)4 ScalaFile (org.jetbrains.plugins.scala.lang.psi.api.ScalaFile)3 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)2 PsiMethod (com.intellij.psi.PsiMethod)2 GoFunctionDeclaration (com.goide.psi.GoFunctionDeclaration)1 BlazeCommandRunConfigurationHandlerProvider (com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationHandlerProvider)1 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)1 AutoImportQuickFix (com.jetbrains.python.codeInsight.imports.AutoImportQuickFix)1 PyClass (com.jetbrains.python.psi.PyClass)1