Search in sources :

Example 1 with ScalaRunLineMarkerContributor

use of org.jetbrains.plugins.scala.runner.ScalaRunLineMarkerContributor in project intellij by bazelbuild.

the class BlazeScalaRunLineMarkerContributorTest method testGetMainInfo.

@Test
public void testGetMainInfo() {
    BlazeScalaRunLineMarkerContributor markerContributor = new BlazeScalaRunLineMarkerContributor();
    ScalaRunLineMarkerContributor replacedContributor = new ScalaRunLineMarkerContributor();
    PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary {", "  object MainClass {", "    def main(args: Array[String]) {}", "    def foo() {}", "  }", "}", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
    List<LeafPsiElement> elements = PsiUtils.findAllChildrenOfClassRecursive(scalaFile, LeafPsiElement.class);
    LeafPsiElement objectIdentifier = elements.stream().filter(e -> Objects.equal(e.getText(), "MainClass")).findFirst().orElse(null);
    LeafPsiElement methodIdentifier = elements.stream().filter(e -> Objects.equal(e.getText(), "main")).findFirst().orElse(null);
    assertThat(objectIdentifier).isNotNull();
    assertThat(methodIdentifier).isNotNull();
    // Have main object info.
    Info objectInfo = markerContributor.getInfo(objectIdentifier);
    assertThat(objectInfo).isNotNull();
    assertThat(objectInfo.icon).isEqualTo(AllIcons.RunConfigurations.TestState.Run);
    assertThat(objectInfo.actions).hasLength(2);
    assertThat(objectInfo.actions[0].getTemplatePresentation().getText()).startsWith("Run ");
    assertThat(objectInfo.actions[1].getTemplatePresentation().getText()).startsWith("Debug ");
    // Main object info replaces the one from the scala plugin
    Info replacedObjectInfo = replacedContributor.getInfo(objectIdentifier);
    assertThat(replacedObjectInfo).isNotNull();
    assertThat(objectInfo.shouldReplace(replacedObjectInfo)).isTrue();
    // Hae main method info
    Info methodInfo = markerContributor.getInfo(methodIdentifier);
    assertThat(methodInfo).isNotNull();
    assertThat(methodInfo.icon).isEqualTo(AllIcons.RunConfigurations.TestState.Run);
    assertThat(methodInfo.actions).hasLength(2);
    assertThat(methodInfo.actions[0].getTemplatePresentation().getText()).startsWith("Run ");
    assertThat(methodInfo.actions[1].getTemplatePresentation().getText()).startsWith("Debug ");
    // Main method info replaces the one from the scala plugin
    Info replacedMethodInfo = replacedContributor.getInfo(methodIdentifier);
    assertThat(replacedMethodInfo).isNotNull();
    assertThat(methodInfo.shouldReplace(replacedMethodInfo)).isTrue();
    // No other element should get an info
    elements.stream().filter(e -> !Objects.equal(e, objectIdentifier) && !Objects.equal(e, methodIdentifier)).forEach(e -> assertThat(markerContributor.getInfo(e)).isNull());
}
Also used : AllIcons(com.intellij.icons.AllIcons) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) RunWith(org.junit.runner.RunWith) PsiUtils(com.google.idea.blaze.base.lang.buildfile.psi.util.PsiUtils) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) List(java.util.List) ScalaRunLineMarkerContributor(org.jetbrains.plugins.scala.runner.ScalaRunLineMarkerContributor) PsiFile(com.intellij.psi.PsiFile) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Objects(com.google.common.base.Objects) BlazeRunConfigurationProducerTestCase(com.google.idea.blaze.base.run.producer.BlazeRunConfigurationProducerTestCase) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiFile(com.intellij.psi.PsiFile) ScalaRunLineMarkerContributor(org.jetbrains.plugins.scala.runner.ScalaRunLineMarkerContributor) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) Test(org.junit.Test)

Aggregations

Objects (com.google.common.base.Objects)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 PsiUtils (com.google.idea.blaze.base.lang.buildfile.psi.util.PsiUtils)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1 BlazeRunConfigurationProducerTestCase (com.google.idea.blaze.base.run.producer.BlazeRunConfigurationProducerTestCase)1 Info (com.intellij.execution.lineMarker.RunLineMarkerContributor.Info)1 AllIcons (com.intellij.icons.AllIcons)1 PsiFile (com.intellij.psi.PsiFile)1 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)1 List (java.util.List)1 ScalaRunLineMarkerContributor (org.jetbrains.plugins.scala.runner.ScalaRunLineMarkerContributor)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 JUnit4 (org.junit.runners.JUnit4)1