Java Code Examples for com.intellij.execution.Location#getVirtualFile()

The following examples show how to use com.intellij.execution.Location#getVirtualFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BashRunConfigProducer.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isConfigurationFromContext(BashRunConfiguration configuration, ConfigurationContext context) {
    Location location = context.getLocation();
    if (location == null) {
        return false;
    }

    //fixme file checks needs to check the properties

    VirtualFile file = location.getVirtualFile();
    return file != null && FileUtil.pathsEqual(file.getPath(), configuration.getScriptName());
}
 
Example 2
Source File: GaugeExecutionProducer.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context) {
    if (!(configuration.getType() instanceof GaugeRunTaskConfigurationType)) return false;
    Location location = context.getLocation();
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context.getDataContext());
    if (location == null || location.getVirtualFile() == null || element == null) return false;
    if (!isInSpecScope(context.getPsiLocation())) return false;
    String specsToExecute = ((GaugeRunConfiguration) configuration).getSpecsToExecute();
    return specsToExecute != null && (specsToExecute.equals(location.getVirtualFile().getPath()));
}
 
Example 3
Source File: ScenarioExecutionProducer.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context) {
    if (!(configuration.getType() instanceof GaugeRunTaskConfigurationType)) return false;
    Location location = context.getLocation();
    if (location == null || location.getVirtualFile() == null || context.getPsiLocation() == null) return false;
    String specsToExecute = ((GaugeRunConfiguration) configuration).getSpecsToExecute();
    int identifier = getScenarioIdentifier(context, context.getPsiLocation().getContainingFile());
    return specsToExecute != null && specsToExecute.equals(location.getVirtualFile().getPath() + Constants.SPEC_SCENARIO_DELIMITER + identifier);
}
 
Example 4
Source File: XQueryRunConfigurationProducer.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean setupConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context, Ref sourceElement) {
    if (!(configuration instanceof XQueryRunConfiguration)) return false;
    XQueryRunConfiguration appConfiguration = (XQueryRunConfiguration) configuration;
    Location location = context.getLocation();
    PsiElement psiElement = location.getPsiElement();
    PsiFile psiFile = psiElement.getContainingFile();
    if (isUnsupportedFile(psiFile)) return false;
    XQueryFile containingFile = (XQueryFile) psiFile;
    if (containingFile.isLibraryModule()) return false;
    final VirtualFile vFile = location.getVirtualFile();
    if (vFile == null) return false;
    prepareSettings(appConfiguration, context, vFile, containingFile);
    return true;
}
 
Example 5
Source File: KotlinBinaryContextProvider.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
private static TargetIdeInfo getTargetIdeInfo(ConfigurationContext context) {
  Location<?> location = context.getLocation();
  if (location == null) {
    return null;
  }
  VirtualFile virtualFile = location.getVirtualFile();
  if (virtualFile == null) {
    return null;
  }
  KtDeclarationContainer entryPointContainer =
      KotlinRunConfigurationProducer.Companion.getEntryPointContainer(location.getPsiElement());
  if (entryPointContainer == null) {
    return null;
  }
  String startClassFqName =
      KotlinRunConfigurationProducer.Companion.getStartClassFqName(entryPointContainer);
  if (startClassFqName == null) {
    return null;
  }
  Collection<TargetIdeInfo> kotlinBinaryTargets =
      findKotlinBinaryTargets(context.getProject(), VfsUtil.virtualToIoFile(virtualFile));

  // first look for a matching main_class
  TargetIdeInfo match =
      kotlinBinaryTargets.stream()
          .filter(
              target ->
                  target.getJavaIdeInfo() != null
                      && startClassFqName.equals(
                          target.getJavaIdeInfo().getJavaBinaryMainClass()))
          .findFirst()
          .orElse(null);
  if (match != null) {
    return match;
  }

  match =
      kotlinBinaryTargets.stream()
          .filter(
              target ->
                  startClassFqName.equals(target.getKey().getLabel().targetName().toString()))
          .findFirst()
          .orElse(null);
  if (match != null) {
    return match;
  }

  return Iterables.getFirst(kotlinBinaryTargets, null);
}
 
Example 6
Source File: BashRunConfigProducer.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean setupConfigurationFromContext(BashRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    Location location = context.getLocation();
    if (location == null) {
        return false;
    }

    PsiElement psiElement = location.getPsiElement();
    if (!psiElement.isValid()) {
        return false;
    }

    PsiFile psiFile = psiElement.getContainingFile();
    if (!(psiFile instanceof BashFile)) {
        return false;
    }
    sourceElement.set(psiFile);

    VirtualFile file = location.getVirtualFile();
    if (file == null) {
        return false;
    }

    configuration.setName(file.getPresentableName());
    configuration.setScriptName(VfsUtilCore.virtualToIoFile(file).getAbsolutePath());

    if (file.getParent() != null) {
        configuration.setWorkingDirectory(VfsUtilCore.virtualToIoFile(file.getParent()).getAbsolutePath());
    }

    Module module = context.getModule();
    if (module != null) {
        configuration.setModule(module);
    }

    // check the location given by the shebang line
    // do this only if the project interpreter isn't used because we don't want to add the options
    // because it would mess up the execution when the project interpreter was used.
    // options might be added by a shebang like "/usr/bin/env bash".
    // also, we don't want to override the defaults of the template run configuration
    if (!configuration.isUseProjectInterpreter() && configuration.getInterpreterPath().isEmpty()) {
        BashFile bashFile = (BashFile) psiFile;
        BashShebang shebang = bashFile.findShebang();
        if (shebang != null) {
            String shebandShell = shebang.shellCommand(false);

            if ((BashInterpreterDetection.instance().isSuitable(shebandShell))) {
                configuration.setInterpreterPath(shebandShell);
                configuration.setInterpreterOptions(shebang.shellCommandParams());
            }
        }
    }

    return true;
}