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());
}
Aggregations