use of org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject in project intellij by bazelbuild.
the class BlazeScalaMainClassRunConfigurationProducer method getTarget.
@Nullable
private static TargetIdeInfo getTarget(Project project, ScObject mainObject) {
File mainObjectFile = RunUtil.getFileForClass(mainObject);
if (mainObjectFile == null) {
return null;
}
Collection<TargetIdeInfo> scalaBinaryTargets = findScalaBinaryTargets(project, mainObjectFile);
// Scala objects are basically singletons with a '$' appended to the class name.
// The trunced qualified name removes the '$',
// so it matches the main class specified in the scala_binary rule.
String qualifiedName = mainObject.getTruncedQualifiedName();
if (qualifiedName == null) {
// out of date psi element; just take the first match
return Iterables.getFirst(scalaBinaryTargets, null);
}
// Can't use getName because of the '$'.
String className = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1);
// first look for a matching main_class
TargetIdeInfo match = scalaBinaryTargets.stream().filter(target -> target.javaIdeInfo != null && qualifiedName.equals(target.javaIdeInfo.javaBinaryMainClass)).findFirst().orElse(null);
if (match != null) {
return match;
}
match = scalaBinaryTargets.stream().filter(target -> className.equals(target.key.label.targetName().toString())).findFirst().orElse(null);
if (match != null) {
return match;
}
return Iterables.getFirst(scalaBinaryTargets, null);
}
use of org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject 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;
}
use of org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject 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);
}
Aggregations