Java Code Examples for com.intellij.openapi.module.ModuleUtilCore#findModuleForFile()
The following examples show how to use
com.intellij.openapi.module.ModuleUtilCore#findModuleForFile() .
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: FindPopupScopeUIImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public ScopeType initByModel(@Nonnull FindModel findModel) { myDirectoryChooser.initByModel(findModel); final String dirName = findModel.getDirectoryName(); if (!StringUtil.isEmptyOrSpaces(dirName)) { VirtualFile dir = LocalFileSystem.getInstance().findFileByPath(dirName); if (dir != null) { Module module = ModuleUtilCore.findModuleForFile(dir, myProject); if (module != null) { myModuleComboBox.setSelectedItem(module.getName()); } } } ScopeType scope = getScope(findModel); ScopeType selectedScope = Arrays.stream(myComponents).filter(o -> o.first == scope).findFirst().orElse(null) == null ? myComponents[0].first : scope; if (selectedScope == MODULE) { myModuleComboBox.setSelectedItem(findModel.getModuleName()); } return selectedScope; }
Example 2
Source File: HaxeProjectSdkSetupValidator.java From intellij-haxe with Apache License 2.0 | 6 votes |
private void pruneExcessiveRoots(Project project, VirtualFile file) { final Module module = ModuleUtilCore.findModuleForFile(file, project); if (module != null && !module.isDisposed()) { final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk != null) { final SdkModificator modificator = sdk.getSdkModificator(); final VirtualFile stdRoot = getDistinctRootsStream(sdk) .filter(root -> root.findChild(STD_TYPES_HX) != null) .findFirst() .orElse(null); if (stdRoot != null) { modificator.removeAllRoots(); modificator.addRoot(stdRoot, OrderRootType.CLASSES); modificator.addRoot(stdRoot, OrderRootType.SOURCES); WriteAction.run(modificator::commitChanges); } } } }
Example 3
Source File: HaxeProjectSdkSetupValidator.java From intellij-haxe with Apache License 2.0 | 6 votes |
private SdkValidationResult validateSdk(Project project, VirtualFile file) { final Module module = ModuleUtilCore.findModuleForFile(file, project); if (module != null && !module.isDisposed()) { final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk == null) { if (ModuleRootManager.getInstance(module).isSdkInherited()) { return PROJECT_SDK_NOT_DEFINED; } else { return MODULE_SDK_NOT_DEFINED; } } else { return validateSdkRoots(sdk); } } return null; }
Example 4
Source File: CSharpFileStubElementType.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nullable @RequiredReadAction private static List<String> findVariables(@Nonnull VirtualFile virtualFile, @Nonnull Project project) { Module module = ModuleUtilCore.findModuleForFile(virtualFile, project); if(module == null) { return null; } DotNetSimpleModuleExtension<?> extension = ModuleUtilCore.getExtension(module, DotNetSimpleModuleExtension.class); if(extension != null) { return extension.getVariables(); } return null; }
Example 5
Source File: ModuleLayerWidget.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private ListWithSelection<String> getLayers() { VirtualFile file = getSelectedFile(); Project project = getProject(); Module moduleForFile = file == null ? null : ModuleUtilCore.findModuleForFile(file, project); if (moduleForFile == null) { return null; } ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForFile); Map<String, ModuleRootLayer> layers = moduleRootManager.getLayers(); if (layers.size() == 1) { return null; } String currentLayerName = moduleRootManager.getCurrentLayerName(); return new ListWithSelection<>(layers.keySet(), currentLayerName); }
Example 6
Source File: FlutterBuildActionGroup.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static Module findFlutterModule(@NotNull Project project, @NotNull VirtualFile file) { Module module = ModuleUtilCore.findModuleForFile(file, project); if (module == null) { return null; } if (FlutterModuleUtils.declaresFlutter(module)) { return module; } // We may get here if the file is in the Android module of a Flutter module project. VirtualFile parent = ModuleRootManager.getInstance(module).getContentRoots()[0].getParent(); module = ModuleUtilCore.findModuleForFile(parent, project); if (module == null) { return null; } return FlutterModuleUtils.declaresFlutter(module) ? module : null; }
Example 7
Source File: FlutterBuildActionGroup.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static Module findFlutterModule(@NotNull Project project, @NotNull VirtualFile file) { Module module = ModuleUtilCore.findModuleForFile(file, project); if (module == null) { return null; } if (FlutterModuleUtils.declaresFlutter(module)) { return module; } // We may get here if the file is in the Android module of a Flutter module project. VirtualFile parent = ModuleRootManager.getInstance(module).getContentRoots()[0].getParent(); module = ModuleUtilCore.findModuleForFile(parent, project); if (module == null) { return null; } return FlutterModuleUtils.declaresFlutter(module) ? module : null; }
Example 8
Source File: ModuleVcsPathPresenter.java From consulo with Apache License 2.0 | 6 votes |
@Override public String getPresentableRelativePath(@Nonnull final ContentRevision fromRevision, @Nonnull final ContentRevision toRevision) { // need to use parent path because the old file is already not there FilePath fromPath = fromRevision.getFile(); FilePath toPath = toRevision.getFile(); if ((fromPath.getParentPath() == null) || (toPath.getParentPath() == null)) { return null; } final VirtualFile oldFile = fromPath.getParentPath().getVirtualFile(); final VirtualFile newFile = toPath.getParentPath().getVirtualFile(); if (oldFile != null && newFile != null) { Module oldModule = ModuleUtilCore.findModuleForFile(oldFile, myProject); Module newModule = ModuleUtilCore.findModuleForFile(newFile, myProject); if (oldModule != newModule) { return getPresentableRelativePathFor(oldFile); } } final RelativePathCalculator calculator = new RelativePathCalculator(toPath.getIOFile().getAbsolutePath(), fromPath.getIOFile().getAbsolutePath()); calculator.execute(); final String result = calculator.getResult(); return (result == null) ? null : result.replace("/", File.separator); }
Example 9
Source File: FlutterDependencyInspection.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable @Override public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) { if (!isOnTheFly) return null; if (!(psiFile instanceof DartFile)) return null; if (DartPlugin.isPubActionInProgress()) return null; final VirtualFile file = FlutterUtils.getRealVirtualFile(psiFile); if (file == null || !file.isInLocalFileSystem()) return null; final Project project = psiFile.getProject(); // If the project should use bazel instead of pub, don't surface this warning. if (WorkspaceCache.getInstance(project).isBazel()) return null; if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) return null; final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); final Module module = ModuleUtilCore.findModuleForFile(file, project); if (!FlutterModuleUtils.isFlutterModule(module)) return null; final PubRoot root = PubRootCache.getInstance(project).getRoot(psiFile); if (root == null || myIgnoredPubspecPaths.contains(root.getPubspec().getPath())) return null; // TODO(pq): consider validating package name here (`get` will fail if it's invalid). if (root.getPackagesFile() == null) { return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("pub.get.not.run")); } if (!root.hasUpToDatePackages()) { return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("pubspec.edited")); } return null; }
Example 10
Source File: FlutterDependencyInspection.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nullable @Override public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile, @NotNull final InspectionManager manager, final boolean isOnTheFly) { if (!isOnTheFly) return null; if (!(psiFile instanceof DartFile)) return null; if (DartPlugin.isPubActionInProgress()) return null; final VirtualFile file = FlutterUtils.getRealVirtualFile(psiFile); if (file == null || !file.isInLocalFileSystem()) return null; final Project project = psiFile.getProject(); // If the project should use bazel instead of pub, don't surface this warning. if (WorkspaceCache.getInstance(project).isBazel()) return null; if (!ProjectRootManager.getInstance(project).getFileIndex().isInContent(file)) return null; final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); final Module module = ModuleUtilCore.findModuleForFile(file, project); if (!FlutterModuleUtils.isFlutterModule(module)) return null; final PubRoot root = PubRootCache.getInstance(project).getRoot(psiFile); if (root == null || myIgnoredPubspecPaths.contains(root.getPubspec().getPath())) return null; // TODO(pq): consider validating package name here (`get` will fail if it's invalid). if (root.getPackagesFile() == null) { return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("pub.get.not.run")); } if (!root.hasUpToDatePackages()) { return createProblemDescriptors(manager, psiFile, root, FlutterBundle.message("pubspec.edited")); } return null; }
Example 11
Source File: QuarkusIconProvider.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
static boolean isQuarkusPropertiesFile(VirtualFile file, Project project) { if ("application.properties".equals("application.properties")) { Module module = ModuleUtilCore.findModuleForFile(file, project); return module != null && FacetManager.getInstance(module).getFacetByType(QuarkusFacet.FACET_TYPE_ID) != null; } return false; }
Example 12
Source File: GlobalConfigsTreeStructure.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
public MuleConfigNode(SimpleNode aParent, PsiFile xmlFile) { super(aParent, xmlFile.getName()); myXmlFile = xmlFile; myProject = xmlFile.getProject(); myClosedIcon = MuleIcons.MuleFileType; myModule = ModuleUtilCore.findModuleForFile(myXmlFile.getVirtualFile(), myProject); updatePresentation(); }
Example 13
Source File: TypeInfoUtil.java From intellij-haskforce with Apache License 2.0 | 5 votes |
@Nullable public static String getTypeInfo(Project project) { FileEditorManager fileEditorManager = FileEditorManager.getInstance( project); if (fileEditorManager == null){ return null; } Editor textEditor = fileEditorManager.getSelectedTextEditor(); if (textEditor == null){ return null; } VisualPosition blockStart = correctFor0BasedVS1Based(textEditor.getSelectionModel().getSelectionStartPosition()); VisualPosition blockEnd = correctFor0BasedVS1Based(textEditor.getSelectionModel().getSelectionEndPosition()); if (blockStart == null || blockEnd == null){ return null; } PsiFile psiFileInEditor = PsiUtilBase.getPsiFileInEditor(textEditor, project); if(psiFileInEditor == null){ return "no psi file found"; } VirtualFile projectFile = psiFileInEditor.getVirtualFile(); if (projectFile == null){ return "project file is null"; } Module module = ModuleUtilCore.findModuleForFile(projectFile, project); return getTypeInfo(module, blockStart, blockEnd, projectFile); }
Example 14
Source File: DesktopPsiAwareTextEditorImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public Object getData(@Nonnull final Key<?> dataId) { if (PlatformDataKeys.DOMINANT_HINT_AREA_RECTANGLE == dataId) { final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(myProject).getActiveLookup(); if (lookup != null && lookup.isVisible()) { return lookup.getBounds(); } } if (LangDataKeys.MODULE == dataId) { return ModuleUtilCore.findModuleForFile(myFile, myProject); } return super.getData(dataId); }
Example 15
Source File: MuleConfigUtils.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
@NotNull public static Breakpoint toMuleBreakpoint(Project project, @NotNull XSourcePosition sourcePosition, XExpression conditionExpression, @Nullable Map<String, String> modulesToAppsMap) { VirtualFile file = sourcePosition.getFile(); Module module = ModuleUtilCore.findModuleForFile(file, project); String deployableName = module.getName(); if (modulesToAppsMap != null && !StringUtils.isEmpty(modulesToAppsMap.get(deployableName))) deployableName = modulesToAppsMap.get(deployableName); final String conditionScript = conditionExpression != null ? asMelScript(conditionExpression.getExpression()) : null; final XmlTag tag = getXmlTagAt(module.getProject(), sourcePosition); if (tag != null) { //TODO - Module name is an app name - but can I get it from Maven? Or override it by using the additional param? return new Breakpoint(getMulePath(tag), conditionScript, deployableName); } else { final int line = sourcePosition.getLine(); final Document document = FileDocumentManager.getInstance().getDocument(sourcePosition.getFile()); final PsiElement xmlElement = WeavePsiUtils.getFirstWeaveElement(module.getProject(), document, line); if (xmlElement != null) { PsiLanguageInjectionHost parent = PsiTreeUtil.getParentOfType(xmlElement, PsiLanguageInjectionHost.class); if (parent != null) { final XmlTag weavePart = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class); final XmlTag weaveTag = PsiTreeUtil.getParentOfType(weavePart, XmlTag.class); int lineNumber = line + 1 - XSourcePositionImpl.createByElement(xmlElement).getLine(); final String mulePath = getMulePath(weaveTag); //TODO - Module name is an app name - but can I get it from Maven? Or override it by using the additional param? return new Breakpoint(mulePath, getPrefix(weavePart) + "/" + (lineNumber + 1), conditionScript, deployableName); } } } return new Breakpoint("", conditionScript, deployableName); }
Example 16
Source File: PsiAwareFileEditorManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public String getFileTooltipText(@Nonnull final VirtualFile file) { final StringBuilder tooltipText = new StringBuilder(); final Module module = ModuleUtilCore.findModuleForFile(file, getProject()); if (module != null) { tooltipText.append("["); tooltipText.append(module.getName()); tooltipText.append("] "); } tooltipText.append(FileUtil.getLocationRelativeToUserHome(file.getPresentableUrl())); return tooltipText.toString(); }
Example 17
Source File: SdkAttachConfig.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
@NotNull @Override public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException { try { checkRunnable(env.getProject()); } catch (RuntimeConfigurationError e) { throw new ExecutionException(e); } final SdkFields launchFields = getFields(); final MainFile mainFile = MainFile.verify(launchFields.getFilePath(), env.getProject()).get(); final Project project = env.getProject(); final RunMode mode = RunMode.fromEnv(env); final Module module = ModuleUtilCore.findModuleForFile(mainFile.getFile(), env.getProject()); final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> { if (device == null) return null; final GeneralCommandLine command = getCommand(env, device); final FlutterApp app = FlutterApp.start(env, project, module, mode, device, command, StringUtil.capitalize(mode.mode()) + "App", "StopApp"); // Stop the app if the Flutter SDK changes. final FlutterSdkManager.Listener sdkListener = new FlutterSdkManager.Listener() { @Override public void flutterSdkRemoved() { app.shutdownAsync(); } }; FlutterSdkManager.getInstance(project).addListener(sdkListener); Disposer.register(project, () -> FlutterSdkManager.getInstance(project).removeListener(sdkListener)); return app; }; final LaunchState launcher = new AttachState(env, mainFile.getAppDir(), mainFile.getFile(), this, createAppCallback); addConsoleFilters(launcher, env, mainFile, module); return launcher; }
Example 18
Source File: ExecUtil.java From intellij-haskforce with Apache License 2.0 | 4 votes |
@NotNull public static String guessWorkDir(@NotNull Project project, @NotNull VirtualFile file) { final Module module = ModuleUtilCore.findModuleForFile(file, project); if (module != null) return guessWorkDir(module); return getProjectPath(project); }
Example 19
Source File: FileReferenceQuickFixProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nullable private static Module getModuleForContext(@Nonnull PsiFileSystemItem context) { VirtualFile file = context.getVirtualFile(); return file != null ? ModuleUtilCore.findModuleForFile(file, context.getProject()) : null; }
Example 20
Source File: CSharpLocationUtil.java From consulo-csharp with Apache License 2.0 | 4 votes |
public static boolean isValidLocation(@Nonnull Project project, @Nullable VirtualFile virtualFile) { if(virtualFile == null || virtualFile.getFileType() != CSharpFileType.INSTANCE) { // if not virtual file - we dont need break highlight return true; } // msil representation highlight always if(virtualFile instanceof MsilFileRepresentationVirtualFile) { return true; } Module moduleForFile = ModuleUtilCore.findModuleForFile(virtualFile, project); if(moduleForFile == null) { return false; } DotNetSimpleModuleExtension extension = ModuleUtilCore.getExtension(moduleForFile, DotNetSimpleModuleExtension.class); if(extension == null) { return false; } if(ModuleUtilCore.getExtension(moduleForFile, CSharpSimpleModuleExtension.class) == null) { return false; } if(extension instanceof DotNetModuleExtension) { if(!((DotNetModuleExtension) extension).isAllowSourceRoots()) { return true; } else { ModuleFileIndex fileIndex = ModuleRootManager.getInstance(moduleForFile).getFileIndex(); return fileIndex.isInSourceContent(virtualFile) || fileIndex.isInTestSourceContent(virtualFile); } } else { return true; } }