com.intellij.psi.search.EverythingGlobalScope#com.intellij.openapi.module.ModuleUtil源码实例Demo

下面列出了com.intellij.psi.search.EverythingGlobalScope#com.intellij.openapi.module.ModuleUtil 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: flutter-intellij   文件: BazelRunConfig.java
@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
  final BazelFields launchFields = fields.copy();
  try {
    launchFields.checkRunnable(env.getProject());
  }
  catch (RuntimeConfigurationError e) {
    throw new ExecutionException(e);
  }

  final Workspace workspace = fields.getWorkspace(getProject());
  final VirtualFile workspaceRoot = workspace.getRoot();
  final RunMode mode = RunMode.fromEnv(env);
  final Module module = ModuleUtil.findModuleForFile(workspaceRoot, env.getProject());

  final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> {
    if (device == null) return null;

    final GeneralCommandLine command = getCommand(env, device);
    return FlutterApp.start(env, env.getProject(), module, mode, device, command,
                            StringUtil.capitalize(mode.mode()) + "BazelApp", "StopBazelApp");
  };

  return new LaunchState(env, workspaceRoot, workspaceRoot, this, createAppCallback);
}
 
源代码2 项目: flutter-intellij   文件: TestLaunchState.java
@Nullable
@Override
protected ConsoleView createConsole(@NotNull Executor executor) throws ExecutionException {
  if (!testConsoleEnabled) {
    return super.createConsole(executor);
  }

  // Create a console showing a test tree.
  final Project project = getEnvironment().getProject();
  final DartUrlResolver resolver = DartUrlResolver.getInstance(project, testFileOrDir);
  final ConsoleProps props = ConsoleProps.forPub(config, executor, resolver);
  final BaseTestsOutputConsoleView console = SMTestRunnerConnectionUtil.createConsole(ConsoleProps.pubFrameworkName, props);

  final Module module = ModuleUtil.findModuleForFile(testFileOrDir, project);
  console.addMessageFilter(new DartConsoleFilter(project, getTestFileOrDir()));
  final String baseDir = getBaseDir();
  if (baseDir != null) {
    console.addMessageFilter(new DartRelativePathsConsoleFilter(project, baseDir));
  }
  console.addMessageFilter(new UrlFilter());

  return console;
}
 
源代码3 项目: flutter-intellij   文件: BazelRunConfig.java
@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
  final BazelFields launchFields = fields.copy();
  try {
    launchFields.checkRunnable(env.getProject());
  }
  catch (RuntimeConfigurationError e) {
    throw new ExecutionException(e);
  }

  final Workspace workspace = fields.getWorkspace(getProject());
  final VirtualFile workspaceRoot = workspace.getRoot();
  final RunMode mode = RunMode.fromEnv(env);
  final Module module = ModuleUtil.findModuleForFile(workspaceRoot, env.getProject());

  final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> {
    if (device == null) return null;

    final GeneralCommandLine command = getCommand(env, device);
    return FlutterApp.start(env, env.getProject(), module, mode, device, command,
                            StringUtil.capitalize(mode.mode()) + "BazelApp", "StopBazelApp");
  };

  return new LaunchState(env, workspaceRoot, workspaceRoot, this, createAppCallback);
}
 
源代码4 项目: flutter-intellij   文件: TestLaunchState.java
@Nullable
@Override
protected ConsoleView createConsole(@NotNull Executor executor) throws ExecutionException {
  if (!testConsoleEnabled) {
    return super.createConsole(executor);
  }

  // Create a console showing a test tree.
  final Project project = getEnvironment().getProject();
  final DartUrlResolver resolver = DartUrlResolver.getInstance(project, testFileOrDir);
  final ConsoleProps props = ConsoleProps.forPub(config, executor, resolver);
  final BaseTestsOutputConsoleView console = SMTestRunnerConnectionUtil.createConsole(ConsoleProps.pubFrameworkName, props);

  final Module module = ModuleUtil.findModuleForFile(testFileOrDir, project);
  console.addMessageFilter(new DartConsoleFilter(project, getTestFileOrDir()));
  final String baseDir = getBaseDir();
  if (baseDir != null) {
    console.addMessageFilter(new DartRelativePathsConsoleFilter(project, baseDir));
  }
  console.addMessageFilter(new UrlFilter());

  return console;
}
 
源代码5 项目: arma-intellij-plugin   文件: ArmaPluginUserData.java
@Nullable
public XmlFile getStringTableXml(@NotNull PsiElement elementFromModule) {
	Module module = ModuleUtil.findModuleForPsiElement(elementFromModule);
	if (module == null) {
		return null;
	}
	ArmaPluginModuleData data = moduleMap.computeIfAbsent(module, module1 -> {
		return new ArmaPluginModuleData(module);
	});
	XmlFile f = data.getStringTableXmlFile();
	if (f == null) {
		VirtualFile virtFile = ArmaPluginUtil.getStringTableXmlFile(module);
		if (virtFile == null) {
			return null;
		}
		XmlFile file = (XmlFile) PsiManager.getInstance(elementFromModule.getProject()).findFile(virtFile);
		data.setStringTableXmlFile(file);
		return file;
	} else {
		if (!f.getVirtualFile().exists()) {
			data.setStringTableXmlFile(null);
			return null;
		}
		return f;
	}
}
 
源代码6 项目: arma-intellij-plugin   文件: ArmaPluginUserData.java
@Nullable
public XmlFile getStringTableXml(@NotNull PsiElement elementFromModule) {
	Module module = ModuleUtil.findModuleForPsiElement(elementFromModule);
	if (module == null) {
		return null;
	}
	ArmaPluginModuleData data = moduleMap.computeIfAbsent(module, module1 -> {
		return new ArmaPluginModuleData(module);
	});
	XmlFile f = data.getStringTableXmlFile();
	if (f == null) {
		VirtualFile virtFile = ArmaPluginUtil.getStringTableXmlFile(module);
		if (virtFile == null) {
			return null;
		}
		XmlFile file = (XmlFile) PsiManager.getInstance(elementFromModule.getProject()).findFile(virtFile);
		data.setStringTableXmlFile(file);
		return file;
	} else {
		if (!f.getVirtualFile().exists()) {
			data.setStringTableXmlFile(null);
			return null;
		}
		return f;
	}
}
 
@NotNull
@Override
public Collection<? extends AbstractTreeNode<?>> getChildren() {
  final PsiManager psiManager = PsiManager.getInstance(myProject);
  final VirtualFile virtualFile = getValue();
  return ContainerUtil.mapNotNull(
    virtualFile.isValid() && virtualFile.isDirectory() ? virtualFile.getChildren() : VirtualFile.EMPTY_ARRAY,
    new Function<VirtualFile, AbstractTreeNode<?>>() {
      @Override
      public AbstractTreeNode<?> fun(VirtualFile file) {
        final PsiElement psiElement = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file);
        if (psiElement instanceof PsiDirectory && ModuleUtil.findModuleForPsiElement(psiElement) != null) {
          // PsiDirectoryNode doesn't render files outside of a project
          // let's use PsiDirectoryNode only for folders in a modules
          return new PsiDirectoryNode(myProject, (PsiDirectory)psiElement, getSettings());
        }
        else if (psiElement instanceof PsiFile) {
          return new PsiFileNode(myProject, (PsiFile)psiElement, getSettings());
        }
        else {
          return shouldShow(file) ? new VirtualFileTreeNode(myProject, file, getSettings()) : null;
        }
      }
    }
  );
}
 
private boolean shouldAddPythonSdk(@NotNull PsiFile file) {
  if (!PantsUtil.isPantsProject(file.getProject())) {
    return false;
  }

  if (!PantsUtil.isBUILDFileName(file.getName())) {
    return false;
  }

  final Module module = ModuleUtil.findModuleForPsiElement(file);
  if (module == null) {
    return false;
  }

  return PantsPythonSdkUtil.hasNoPythonSdk(module);
}
 
@Nullable
private Sdk resolveSdk(Project project, PsiFile file) {
  final AtomicReference<Sdk> pythonSdk = new AtomicReference<>();
  final ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
  List<Sdk> sdks = jdkTable.getSdksOfType(PythonSdkType.getInstance());

  if (sdks.isEmpty()) {
    final Module module = ModuleUtil.findModuleForPsiElement(file);
    PyAddSdkDialog.show(project, module, sdks, pythonSdk::set);
    if (pythonSdk.get() != null) {
      ApplicationManager.getApplication().runWriteAction(() -> {
        jdkTable.addJdk(pythonSdk.get());
      });
    }

    return pythonSdk.get();
  }
  else {
    return sdks.get(0);
  }
}
 
@Nullable
@Override
protected RunnerAndConfigurationSettings createConfigurationByElement(Location location, ConfigurationContext configurationContext) {
    sourceFile = location.getPsiElement().getContainingFile();
    if (sourceFile != null && sourceFile.getFileType().getName().toLowerCase().contains("javascript")) {
        Project project = sourceFile.getProject();

        VirtualFile file = sourceFile.getVirtualFile();

        RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(project, configurationContext);

        MongoRunConfiguration runConfiguration = (MongoRunConfiguration) settings.getConfiguration();
        runConfiguration.setName(file.getName());

        runConfiguration.setScriptPath(file.getPath());

        Module module = ModuleUtil.findModuleForPsiElement(location.getPsiElement());
        if (module != null) {
            runConfiguration.setModule(module);
        }

        return settings;
    }
    return null;
}
 
源代码11 项目: intellij-haxe   文件: HaxeCompiler.java
private static boolean compileModule(final CompileContext context,
                                     Module module,
                                     @NotNull final HaxeCommonCompilerUtil.CompilationContext compilationContext) {

  /*
  if ((skipBuildMap.get(module) != null) && (skipBuildMap.get(module).booleanValue())) {
    return false;
  }
  */

  if (!ModuleUtil.getModuleType(module).equals(HaxeModuleType.getInstance())) {
    return true;
  }

  boolean compiled = HaxeCommonCompilerUtil.compile(compilationContext);

  if (!compiled) {
    context.addMessage(CompilerMessageCategory.ERROR, "Compilation failed", null, 0, 0);
  }

  return compiled;
}
 
源代码12 项目: consulo   文件: PsiPackageManagerImpl.java
@Nullable
private PsiPackage createPackageFromProviders(@Nonnull VirtualFile virtualFile,
                                              @Nonnull Class<? extends ModuleExtension> extensionClass,
                                              @Nonnull String qualifiedName) {
  final Module moduleForFile = ModuleUtil.findModuleForFile(virtualFile, myProject);
  if (moduleForFile == null) {
    return null;
  }

  ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForFile);

  final ModuleExtension extension = moduleRootManager.getExtension(extensionClass);
  if (extension == null) {
    return null;
  }

  for (PsiPackageSupportProvider p : PsiPackageSupportProvider.EP_NAME.getExtensionList()) {
    if (p.isSupported(extension) && p.acceptVirtualFile(moduleForFile, virtualFile)) {
      return p.createPackage(myPsiManager, this, extensionClass, qualifiedName);
    }
  }
  return null;
}
 
源代码13 项目: consulo   文件: LogicalRootsManagerImpl.java
@Override
@Nullable
public LogicalRoot findLogicalRoot(@Nonnull final VirtualFile file) {
  final Module module = ModuleUtil.findModuleForFile(file, myProject);
  if (module == null) return null;

  LogicalRoot result = null;
  final List<LogicalRoot> list = getLogicalRoots(module);
  for (final LogicalRoot root : list) {
    final VirtualFile rootFile = root.getVirtualFile();
    if (rootFile != null && VfsUtil.isAncestor(rootFile, file, false)) {
      result = root;
      break;
    }
  }

  return result;
}
 
源代码14 项目: consulo   文件: PsiDirectoryNode.java
@Override
@RequiredUIAccess
public void navigate(final boolean requestFocus) {
  Module module = ModuleUtil.findModuleForPsiElement(getValue());
  if (module != null) {
    final VirtualFile file = getVirtualFile();
    final Project project = getProject();
    ProjectSettingsService service = ProjectSettingsService.getInstance(myProject);
    if (ProjectRootsUtil.isModuleContentRoot(file, project)) {
      service.openModuleSettings(module);
    }
    else if (ProjectRootsUtil.isLibraryRoot(file, project)) {
      final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, module.getProject());
      if (orderEntry != null) {
        service.openLibraryOrSdkSettings(orderEntry);
      }
    }
    else {
      service.openContentEntriesSettings(module);
    }
  }
}
 
源代码15 项目: EasyCode   文件: ModuleUtils.java
/**
 * 获取模块的源代码文件夹,不存在
 *
 * @param module 模块对象
 * @return 文件夹路径
 */
public static VirtualFile getSourcePath(@NotNull Module module) {
    List<VirtualFile> virtualFileList = ModuleRootManager.getInstance(module).getSourceRoots(JavaSourceRootType.SOURCE);
    if (CollectionUtil.isEmpty(virtualFileList)) {
        return VirtualFileManager.getInstance().findFileByUrl(String.format("file://%s", ModuleUtil.getModuleDirPath(module)));
    }
    return virtualFileList.get(0);
}
 
源代码16 项目: EasyCode   文件: CodeGenerateServiceImpl.java
/**
 * 设置模型路径与导包列表
 *
 * @param param     参数
 * @param tableInfo 表信息对象
 */
private void setModulePathAndImportList(Map<String, Object> param, TableInfo tableInfo) {
    Module module = null;
    if (!StringUtils.isEmpty(tableInfo.getSaveModelName())) {
        module = this.moduleManager.findModuleByName(tableInfo.getSaveModelName());
    }
    if (module != null) {
        // 设置modulePath
        param.put("modulePath", ModuleUtil.getModuleDirPath(module));
    }
    // 设置要导入的包
    param.put("importList", getImportList(tableInfo));
}
 
源代码17 项目: OkHttpParamsGet   文件: Utils.java
/**
 * Check whether classpath of a module that corresponds to a {@link PsiElement} contains given class.
 *
 * @param project    Project
 * @param psiElement Element for which we check the class
 * @param className  Class name of the searched class
 * @return True if the class is present on the classpath
 * @since 1.3
 */
public static boolean isClassAvailableForPsiFile(@NotNull Project project, @NotNull PsiElement psiElement, @NotNull String className) {
    Module module = ModuleUtil.findModuleForPsiElement(psiElement);
    if (module == null) {
        return false;
    }
    GlobalSearchScope moduleScope = module.getModuleWithDependenciesAndLibrariesScope(false);
    PsiClass classInModule = JavaPsiFacade.getInstance(project).findClass(className, moduleScope);
    return classInModule != null;
}
 
private static void handleBsConfigContentChange(VirtualFile bsConfigFile) {
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        Module module = ModuleUtil.findModuleForFile(bsConfigFile, project);
        if (module != null) {
            ServiceManager.getService(project, InsightManager.class).downloadRincewindIfNeeded(bsConfigFile);
            OREditorTracker.getInstance(project).updateQueues();
        }
    }
}
 
源代码19 项目: SmartTomcat   文件: TomcatRunConfiguration.java
@Override
public void onNewConfigurationCreated() {
    super.onNewConfigurationCreated();

    try {
        Project project = getProject();

        ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
        VirtualFile[] sourceRoots = rootManager.getContentSourceRoots();

        Optional<VirtualFile> webinfFile = Stream.of(sourceRoots).map(VirtualFile::getParent).distinct().flatMap(f ->
                Stream.of(f.getChildren()).filter(c -> {
                    Path path = Paths.get(c.getCanonicalPath(), "WEB-INF");
                    return path.toFile().exists();
                })).distinct().findFirst();


        if (webinfFile.isPresent()) {
            VirtualFile file = webinfFile.get();
            docBase = file.getCanonicalPath();
            moduleName = ModuleUtil.findModuleForFile(file, project).getName();
            contextPath = "/" + moduleName;
        }
    } catch (Exception e) {
        //do nothing.
    }

}
 
源代码20 项目: mule-intellij-plugins   文件: MuleSchemaProvider.java
@Override
@NotNull
public Set<String> getAvailableNamespaces(@NotNull XmlFile file, @Nullable String tagName) {
    final Module module = ModuleUtil.findModuleForPsiElement(file);
    Map<String, XmlFile> schemas = getSchemas(module);
    Set<String> namespaces = new HashSet<>();

    try {
        for (XmlFile xsd : schemas.values()) {
            final XmlDocument document = xsd.getDocument();
            if (document != null) {
                final PsiMetaData metaData = document.getMetaData();
                if (metaData instanceof XmlNSDescriptorImpl) {
                    XmlNSDescriptorImpl descriptor = (XmlNSDescriptorImpl) metaData;
                    String defaultNamespace = descriptor.getDefaultNamespace();

                    //Stupid HTTP module XSD weirdo
                    if (xsd.getName().contains("mule-httpn"))
                        defaultNamespace = "http://www.mulesoft.org/schema/mule/http";
                    /////

                    if (StringUtils.isNotEmpty(defaultNamespace)) {
                        if (StringUtils.isNotEmpty(tagName)) {
                            XmlElementDescriptor elementDescriptor = descriptor.getElementDescriptor(tagName, defaultNamespace);
                            if (elementDescriptor != null) {
                                namespaces.add(defaultNamespace);
                            }
                        } else {
                            namespaces.add(defaultNamespace);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        //e.printStackTrace();
    }
    return namespaces;
}
 
源代码21 项目: mule-intellij-plugins   文件: MuleSchemaProvider.java
@Override
public Set<String> getLocations(@NotNull @NonNls final String namespace, @NotNull final XmlFile context) throws ProcessCanceledException {
    Set<String> locations = new HashSet<>();
    final Module module = ModuleUtil.findModuleForPsiElement(context);
    if (module == null) {
        return null;
    }
    try {
        final Map<String, XmlFile> schemas = getSchemas(module);
        for (Map.Entry<String, XmlFile> entry : schemas.entrySet()) {
            final String s = getNamespace(entry.getValue(), context.getProject());
            if (s != null && s.equals(namespace)) {
                if (!entry.getKey().contains("mule-httpn.xsd")) {
                    locations.add(entry.getKey()); //Observe the formatting rules
                    XmlFile schemaFile = entry.getValue();
                    try {
                        String url = schemaFile.getVirtualFile().getUrl();
                        if (url != null) {
                            if (url.startsWith("jar://"))
                                url = url.substring(6);
                            ExternalResourceManager.getInstance().addResource(namespace, url);
                        }
                    } catch (Throwable ex) {
                        Notifications.Bus.notify(new Notification("Schema Provider", "Schema Provider", ex.toString(),
                                NotificationType.ERROR));
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return locations;
}
 
源代码22 项目: arma-intellij-plugin   文件: ArmaPluginUtil.java
/**
 * Invokes {@link #getConfigVirtualFiles(Module)} by first getting a {@link Module} instance for the the provided PsiElement.
 *
 * @param elementFromModule a PsiElement used to determine what module the root config file is located in
 * @return a list of VirtualFile instances, or an empty list
 */
@NotNull
public static List<VirtualFile> getConfigVirtualFiles(@NotNull PsiElement elementFromModule) {
	Module module = ModuleUtil.findModuleForPsiElement(elementFromModule);
	if (module == null) {
		return Collections.emptyList();
	}
	return getConfigVirtualFiles(module);
}
 
源代码23 项目: arma-intellij-plugin   文件: ArmaPluginUserData.java
@Nullable
private ArmaPluginModuleData getModuleData(@NotNull PsiElement elementFromModule) {
	Module module = ModuleUtil.findModuleForPsiElement(elementFromModule);
	if (module == null) {
		return null;
	}
	return getModuleData(module);
}
 
源代码24 项目: arma-intellij-plugin   文件: ArmaPluginUserData.java
/**
 * Invoke when the root config file ({@link #parseAndGetConfigHeaderFiles(PsiElement)}) or included files for it has been edited.
 * Note that this doesn't do any reparsing and instead tells {@link #parseAndGetConfigHeaderFiles(PsiElement)} that it's cached
 * {@link HeaderFile} is no longer valid and it should reparse.
 */
public void reparseConfigs(@NotNull PsiFile fileFromModule) {
	Module module = ModuleUtil.findModuleForPsiElement(fileFromModule);
	if (module == null) {
		return;
	}
	ArmaPluginModuleData moduleData = moduleMap.computeIfAbsent(module, module1 -> {
		return new ArmaPluginModuleData(module);
	});
	moduleData.setReparseConfigHeaderFiles(true);
}
 
/**
 * Adds all {@link SQFCommand} instances in the current module that is equal to findCommand into a list and returns it
 *
 * @param project     project
 * @param findCommand the command
 * @return list
 */
@NotNull
public static List<SQFCommand> findAllCommandInstances(@NotNull Project project, @NotNull SQFCommand findCommand) {
	List<SQFCommand> result = new ArrayList<>();
	Module m = ModuleUtil.findModuleForPsiElement(findCommand);
	if (m == null) {
		return result;
	}
	GlobalSearchScope searchScope = m.getModuleContentScope();
	Collection<VirtualFile> files = FileTypeIndex.getFiles(SQFFileType.INSTANCE, searchScope);
	for (VirtualFile virtualFile : files) {
		PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
		if (!(file instanceof SQFFile)) {
			continue;
		}
		SQFFile sqfFile = (SQFFile) file;
		PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
			PsiElement nodeAsElement = astNode.getPsi();
			if (nodeAsElement instanceof SQFCommand) {
				SQFCommand command = (SQFCommand) nodeAsElement;
				if (command.commandNameEquals(findCommand.getCommandName())) {
					result.add(command);
				}
			}
			return false;
		});
	}
	return result;
}
 
/**
 * Adds all {@link SQFVariable}s in the current module that is equal to findVar into a list and returns it
 * <p>
 * If findVar is a local variable, the list returned will be empty.
 *
 * @param project project
 * @param findVar variable
 * @return list
 */
@NotNull
public static List<SQFVariable> findGlobalVariables(@NotNull Project project, @NotNull SQFVariable findVar) {
	List<SQFVariable> result = new ArrayList<>();
	if (findVar.isLocal()) {
		return result;
	}
	Module m = ModuleUtil.findModuleForPsiElement(findVar);
	if (m == null) {
		return result;
	}
	GlobalSearchScope searchScope = m.getModuleContentScope();
	Collection<VirtualFile> files = FileTypeIndex.getFiles(SQFFileType.INSTANCE, searchScope);
	for (VirtualFile virtualFile : files) {
		PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
		if (!(file instanceof SQFFile)) {
			continue;
		}
		SQFFile sqfFile = (SQFFile) file;
		PsiUtil.traverseBreadthFirstSearch(sqfFile.getNode(), astNode -> {
			PsiElement nodeAsElement = astNode.getPsi();
			if (nodeAsElement instanceof SQFVariable) {
				SQFVariable var = (SQFVariable) nodeAsElement;
				if (var.isLocal()) {
					return false;
				}
				if (SQFVariableName.nameEquals(var.getVarName(), findVar.getVarName())) {
					result.add(var);
				}
			}
			return false;
		});
	}
	return result;
}
 
protected ConfigurationContext createContextFromPsi(PsiElement element) {
  final MapDataContext dataContext = new MapDataContext();
  dataContext.put(CommonDataKeys.PROJECT, getProject());
  dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(element));
  dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(element));
  return ConfigurationContext.getFromContext(dataContext);
}
 
protected ConfigurationContext createContextFromMultipleElements(PsiElement[] elements) {
  final MapDataContext dataContext = new MapDataContext();
  dataContext.put(CommonDataKeys.PROJECT, getProject());
  dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(elements[0]));
  dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(elements[0]));
  dataContext.put(
      Location.DATA_KEYS,
      Arrays.stream(elements).map(PsiLocation::fromPsiElement).toArray(Location[]::new));
  dataContext.put(LangDataKeys.PSI_ELEMENT_ARRAY, elements);
  return ConfigurationContext.getFromContext(dataContext);
}
 
@Nullable
protected RunConfiguration createConfigurationFromLocation(PsiFile psiFile) {
  MapDataContext dataContext = new MapDataContext();
  dataContext.put(CommonDataKeys.PROJECT, getProject());
  dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(psiFile));
  dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiFile));
  RunnerAndConfigurationSettings settings =
      ConfigurationContext.getFromContext(dataContext).getConfiguration();
  return settings != null ? settings.getConfiguration() : null;
}
 
源代码30 项目: OpenInTerminal   文件: OpenInModuleDirAction.java
@NotNull
@Override
protected String getPath(AnActionEvent e, VirtualFile file, OpenInTerminalSettingsState openInTerminalSettingsState) {
    Module moduleForFile = ModuleUtil.findModuleForFile(file, e.getProject());

    if(moduleForFile != null) {
        VirtualFile[] contentRoots = ModuleRootManager.getInstance(moduleForFile).getContentRoots();
        if(contentRoots.length > 0) {
            return ModuleRootManager.getInstance(moduleForFile).getContentRoots()[0].getPath();
        }
    }

    return e.getProject().getBasePath();
}