@NotNull
  public static Collection<String> collectPythonPath(
      @Nullable Module module, boolean addContentRoots, boolean addSourceRoots) {
    Collection<String> pythonPathList = Sets.newLinkedHashSet();
    if (module != null) {
      Set<Module> dependencies = new HashSet<Module>();
      ModuleUtilCore.getDependencies(module, dependencies);

      if (addContentRoots) {
        addRoots(pythonPathList, ModuleRootManager.getInstance(module).getContentRoots());
        for (Module dependency : dependencies) {
          addRoots(pythonPathList, ModuleRootManager.getInstance(dependency).getContentRoots());
        }
      }
      if (addSourceRoots) {
        addRoots(pythonPathList, ModuleRootManager.getInstance(module).getSourceRoots());
        for (Module dependency : dependencies) {
          addRoots(pythonPathList, ModuleRootManager.getInstance(dependency).getSourceRoots());
        }
      }

      addLibrariesFromModule(module, pythonPathList);
      addRootsFromModule(module, pythonPathList);
      for (Module dependency : dependencies) {
        addLibrariesFromModule(dependency, pythonPathList);
        addRootsFromModule(dependency, pythonPathList);
      }
    }
    return pythonPathList;
  }
  @Override
  public void invoke(@NotNull Project project, Editor editor, PsiFile file)
      throws IncorrectOperationException {
    if (!(file instanceof GroovyFile)) return;

    VirtualFile vfile = file.getVirtualFile();
    if (vfile == null) return;

    final Module module = ModuleUtilCore.findModuleForFile(vfile, project);
    if (module == null) return;

    final String packageName = ((GroovyFile) file).getPackageName();
    PsiDirectory directory =
        PackageUtil.findOrCreateDirectoryForPackage(module, packageName, null, true);
    if (directory == null) return;

    String error = RefactoringMessageUtil.checkCanCreateFile(directory, file.getName());
    if (error != null) {
      Messages.showMessageDialog(
          project, error, CommonBundle.getErrorTitle(), Messages.getErrorIcon());
      return;
    }
    new MoveFilesOrDirectoriesProcessor(
            project, new PsiElement[] {file}, directory, false, false, false, null, null)
        .run();
  }
 public boolean isVersionAtLeast(PsiElement psiElement, String version, boolean unknownResult) {
   Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
   if (module == null) return unknownResult;
   final String sdkVersion = getSDKVersion(module);
   if (sdkVersion == null) return unknownResult;
   return sdkVersion.compareTo(version) >= 0;
 }
  @Nullable
  @Override
  public PsiPackage resolvePackage(
      @NotNull PsiPackageManager packageManager,
      @NotNull VirtualFile virtualFile,
      @NotNull Class<? extends ModuleExtension> extensionClass,
      String qualifiedName) {
    ProjectFileIndex fileIndexFacade =
        ProjectFileIndex.SERVICE.getInstance(packageManager.getProject());
    PsiManager psiManager = PsiManager.getInstance(packageManager.getProject());
    if (fileIndexFacade.isInLibraryClasses(virtualFile)) {

      List<OrderEntry> orderEntriesForFile = fileIndexFacade.getOrderEntriesForFile(virtualFile);
      for (OrderEntry orderEntry : orderEntriesForFile) {
        Module ownerModule = orderEntry.getOwnerModule();
        ModuleExtension extension = ModuleUtilCore.getExtension(ownerModule, extensionClass);
        if (extension != null) {
          for (PsiPackageSupportProvider p : PsiPackageSupportProvider.EP_NAME.getExtensions()) {
            if (p.isSupported(extension)) {
              return p.createPackage(psiManager, packageManager, extensionClass, qualifiedName);
            }
          }
        }
      }
    }
    return null;
  }
  private void resetFromFile(@NotNull VirtualFile file, @NotNull Project project) {
    final Module moduleForFile = ModuleUtilCore.findModuleForFile(file, project);
    if (moduleForFile == null) {
      return;
    }

    final VirtualFile parent = file.getParent();
    if (parent == null) {
      return;
    }

    if (myModule == null) {
      final Object prev = myModuleCombo.getSelectedItem();
      myModuleCombo.setSelectedItem(moduleForFile);

      if (!moduleForFile.equals(myModuleCombo.getSelectedItem())) {
        myModuleCombo.setSelectedItem(prev);
        return;
      }
    } else if (!myModule.equals(moduleForFile)) {
      return;
    }

    final JCheckBox checkBox = myCheckBoxes.get(parent.getName());
    if (checkBox == null) {
      return;
    }

    for (JCheckBox checkBox1 : myCheckBoxes.values()) {
      checkBox1.setSelected(false);
    }
    checkBox.setSelected(true);
    myFileNameCombo.getEditor().setItem(file.getName());
  }
  @Nullable
  static HighlightInfo checkFileDuplicates(@NotNull PsiJavaModule element, @NotNull PsiFile file) {
    Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (module != null) {
      Project project = file.getProject();
      Collection<VirtualFile> others =
          FilenameIndex.getVirtualFilesByName(project, MODULE_INFO_FILE, new ModulesScope(module));
      if (others.size() > 1) {
        String message = JavaErrorMessages.message("module.file.duplicate");
        HighlightInfo info =
            HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
                .range(range(element))
                .description(message)
                .create();
        others
            .stream()
            .map(f -> PsiManager.getInstance(project).findFile(f))
            .filter(f -> f != file)
            .findFirst()
            .ifPresent(
                duplicate ->
                    QuickFixAction.registerQuickFixAction(
                        info,
                        new GoToSymbolFix(
                            duplicate, JavaErrorMessages.message("module.open.duplicate.text"))));
        return info;
      }
    }

    return null;
  }
  private void initPubListPackageDirsMap(final @NotNull VirtualFile contextFile) {
    final Module module = ModuleUtilCore.findModuleForFile(contextFile, myProject);

    final List<OrderEntry> orderEntries =
        module != null
            ? Arrays.asList(ModuleRootManager.getInstance(module).getOrderEntries())
            : ProjectRootManager.getInstance(myProject)
                .getFileIndex()
                .getOrderEntriesForFile(contextFile);
    for (OrderEntry orderEntry : orderEntries) {
      if (orderEntry instanceof LibraryOrderEntry
          && LibraryTablesRegistrar.PROJECT_LEVEL.equals(
              ((LibraryOrderEntry) orderEntry).getLibraryLevel())
          && PubListPackageDirsAction.PUB_LIST_PACKAGE_DIRS_LIB_NAME.equals(
              ((LibraryOrderEntry) orderEntry).getLibraryName())) {
        final LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
        final LibraryProperties properties = library == null ? null : library.getProperties();

        if (properties instanceof DartListPackageDirsLibraryProperties) {
          myPubListPackageDirsMap.putAll(
              ((DartListPackageDirsLibraryProperties) properties).getPackageNameToDirsMap());
          return;
        }
      }
    }
  }
  @Override
  public void setDefaultParameters(
      @NotNull Project project,
      @NotNull VirtualFile virtualFile,
      @NotNull BackgroundTaskByVfsParameters backgroundTaskByVfsParameters) {
    Sdk sdk = null;
    Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
    if (module != null) {
      sdk = ModuleUtilCore.getSdk(module, JavaModuleExtension.class);
    }

    if (sdk == null) {
      sdk = SdkTable.getInstance().findPredefinedSdkByType(JavaSdk.getInstance());
    }

    if (sdk == null) {
      sdk = SdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
    }

    List<String> parameters = new ArrayList<String>();
    if (sdk != null) {
      GeneralCommandLine generalCommandLine = new GeneralCommandLine();

      ((JavaSdkType) sdk.getSdkType()).setupCommandLine(generalCommandLine, sdk);
      backgroundTaskByVfsParameters.setExePath(generalCommandLine.getExePath());
      parameters.addAll(generalCommandLine.getParametersList().getList());
    } else {
      backgroundTaskByVfsParameters.setExePath(SystemInfo.isWindows ? "java.exe" : "java");
    }

    PluginClassLoader classLoader =
        (PluginClassLoader) JFlexBackgroundTaskProvider.class.getClassLoader();
    IdeaPluginDescriptor plugin = PluginManager.getPlugin(classLoader.getPluginId());
    assert plugin != null;
    parameters.add("-jar");
    parameters.add(new File(plugin.getPath(), "jflex/jflex.jar").getAbsolutePath());
    parameters.add("--charat");
    parameters.add("--noconstr");
    parameters.add("--nobak");
    parameters.add("--skel");
    parameters.add(new File(plugin.getPath(), "jflex/idea-flex.skeleton").getAbsolutePath());
    parameters.add("$FilePath$");

    backgroundTaskByVfsParameters.setProgramParameters(StringUtil.join(parameters, " "));
    backgroundTaskByVfsParameters.setWorkingDirectory("$FileParentPath$");
    backgroundTaskByVfsParameters.setOutPath("$FileParentPath$");
  }
 @Override
 public boolean isAvailable(
     @NotNull final Project project, final Editor editor, final PsiFile file) {
   final VirtualFile virtualFile = file.getVirtualFile();
   if (virtualFile == null) return false;
   final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
   return isLanguageLevelAcceptable(project, module, myLevel);
 }
 @NotNull
 private GlobalSearchScope getSearchScope() {
   Project project = myElement.getProject();
   Module module = ModuleUtilCore.findModuleForPsiElement(myElement);
   return module != null
       ? module.getModuleWithDependenciesAndLibrariesScope(true)
       : new ProjectAndLibrariesScope(project);
 }
 @Nullable
 protected Module getNodeModule(@Nullable final Object element) {
   if (element instanceof PsiElement) {
     PsiElement psiElement = (PsiElement) element;
     return ModuleUtilCore.findModuleForPsiElement(psiElement);
   }
   return null;
 }
 @NotNull
 public String getSDKVersion(PsiElement psiElement) {
   final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
   if (module == null) {
     return NO_VERSION;
   }
   final String s = getSDKVersion(module);
   return s != null ? s : NO_VERSION;
 }
示例#13
0
  @Override
  protected void buildDialog(
      final Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) {
    builder
        .setTitle(JavaCoreBundle.message("action.create.new.class"))
        .addKind("Class", PlatformIcons.CLASS_ICON, JavaTemplateUtil.INTERNAL_CLASS_TEMPLATE_NAME)
        .addKind(
            "Interface",
            PlatformIcons.INTERFACE_ICON,
            JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME);

    Module module = ModuleUtilCore.findModuleForPsiElement(directory);
    assert module != null;
    JavaModuleExtensionImpl moduleExtension =
        ModuleRootManager.getInstance(module).getExtension(JavaModuleExtensionImpl.class);

    assert moduleExtension != null;
    if (moduleExtension.getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5)) {
      builder.addKind(
          "Enum", PlatformIcons.ENUM_ICON, JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME);
      builder.addKind(
          "Annotation",
          PlatformIcons.ANNOTATION_TYPE_ICON,
          JavaTemplateUtil.INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME);
    }

    for (FileTemplate template : FileTemplateManager.getInstance().getAllTemplates()) {
      final JavaCreateFromTemplateHandler handler = new JavaCreateFromTemplateHandler();
      if (handler.handlesTemplate(template) && JavaCreateFromTemplateHandler.canCreate(directory)) {
        builder.addKind(template.getName(), JavaFileType.INSTANCE.getIcon(), template.getName());
      }
    }

    builder.setValidator(
        new InputValidatorEx() {
          @Override
          public String getErrorText(String inputString) {
            if (inputString.length() > 0
                && !JavaPsiFacade.getInstance(project)
                    .getNameHelper()
                    .isQualifiedName(inputString)) {
              return "This is not a valid Java qualified name";
            }
            return null;
          }

          @Override
          public boolean checkInput(String inputString) {
            return true;
          }

          @Override
          public boolean canClose(String inputString) {
            return !StringUtil.isEmptyOrSpaces(inputString) && getErrorText(inputString) == null;
          }
        });
  }
 @Override
 public Module getModule() {
   final DomFileElement<DomElement> fileElement = DomUtil.getFileElement(getInvocationElement());
   if (fileElement == null) {
     final XmlElement xmlElement = getInvocationElement().getXmlElement();
     return xmlElement == null ? null : ModuleUtilCore.findModuleForPsiElement(xmlElement);
   }
   return fileElement.isValid() ? fileElement.getRootElement().getModule() : null;
 }
 @Override
 public String getElementModuleName(final Object element) {
   if (element instanceof PsiClass) {
     PsiClass aClass = (PsiClass) element;
     Module module = ModuleUtilCore.findModuleForPsiElement(aClass);
     return module != null ? module.getName() : null;
   }
   return null;
 }
 @Override
 public Collection<Module> getValidModules() {
   val list = new ArrayList<Module>();
   for (val module : ModuleManager.getInstance(getProject()).getModules()) {
     if (ModuleUtilCore.getExtension(module, DotNetModuleExtension.class) != null) {
       list.add(module);
     }
   }
   return list;
 }
 public static boolean isAtLeast(PsiElement element, JavaSdkVersion minVersion) {
   final Module module = ModuleUtilCore.findModuleForPsiElement(element);
   if (module != null) {
     final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
     if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
       final JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
       return version != null && version.isAtLeast(minVersion);
     }
   }
   return true;
 }
 @Override
 public EditorNotificationPanel createNotificationPanel(
     @NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
   if (file.getFileType() != RESOLVEFileType.INSTANCE) return null;
   Module module = ModuleUtilCore.findModuleForFile(file, project);
   return module == null
           || RESOLVESdkService.getInstance(project).isRESOLVEModule(module)
           || getIgnoredModules(project).contains(module.getName())
       ? null
       : createPanel(project, module);
 }
 @Override
 public void doFix(@NotNull Project project, @NotNull VirtualFile file) {
   final String javaErrorMessage =
       JavaProjectSdkSetupValidator.INSTANCE.getErrorMessage(project, file);
   if (javaErrorMessage != null) {
     JavaProjectSdkSetupValidator.INSTANCE.doFix(project, file);
     return;
   }
   final Module module = ModuleUtilCore.findModuleForFile(file, project);
   final String moduleName = module != null && !module.isDisposed() ? module.getName() : null;
   ProjectSettingsService.getInstance(project)
       .showModuleConfigurationDialog(moduleName, ClasspathEditor.NAME);
 }
  @Nullable
  static String getID(PsiElement place, String alternativeID) {
    if (alternativeID != null) {
      final Module module = ModuleUtilCore.findModuleForPsiElement(place);
      if (module != null) {
        if (!ClasspathStorage.getStorageType(module).equals(ClasspathStorage.DEFAULT_STORAGE)) {
          return alternativeID;
        }
      }
    }

    return null;
  }
 @Nullable
 static PythonPathCache getPathCache(PsiElement foothold) {
   PythonPathCache cache = null;
   final Module module = ModuleUtilCore.findModuleForPsiElement(foothold);
   if (module != null) {
     cache = PythonModulePathCache.getInstance(module);
   } else {
     final Sdk sdk = PyBuiltinCache.findSdkForFile(foothold.getContainingFile());
     if (sdk != null) {
       cache = PythonSdkPathCache.getInstance(foothold.getProject(), sdk);
     }
   }
   return cache;
 }
  @Override
  public ProblemDescriptor[] checkClass(
      @NotNull PsiClass aClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
    final Project project = aClass.getProject();
    final PsiIdentifier nameIdentifier = aClass.getNameIdentifier();
    final Module module = ModuleUtilCore.findModuleForPsiElement(aClass);

    if (nameIdentifier == null || module == null || !PsiUtil.isInstantiable(aClass)) return null;

    final PsiClass base =
        JavaPsiFacade.getInstance(project).findClass(getClassName(), aClass.getResolveScope());
    if (base == null || !aClass.isInheritor(base, true)) return null;

    String descriptionDir = DescriptionCheckerUtil.getDescriptionDirName(aClass);
    if (StringUtil.isEmptyOrSpaces(descriptionDir)) {
      return null;
    }

    for (PsiDirectory description : getDescriptionsDirs(module)) {
      PsiDirectory dir = description.findSubdirectory(descriptionDir);
      if (dir == null) continue;
      final PsiFile descr = dir.findFile("description.html");
      if (descr != null) {
        if (!hasBeforeAndAfterTemplate(dir.getVirtualFile())) {
          PsiElement problem = aClass.getNameIdentifier();
          ProblemDescriptor problemDescriptor =
              manager.createProblemDescriptor(
                  problem == null ? nameIdentifier : problem,
                  getHasNotBeforeAfterError(),
                  isOnTheFly,
                  ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
                  false);
          return new ProblemDescriptor[] {problemDescriptor};
        }

        return null;
      }
    }

    final PsiElement problem = aClass.getNameIdentifier();
    final ProblemDescriptor problemDescriptor =
        manager.createProblemDescriptor(
            problem == null ? nameIdentifier : problem,
            getHasNotDescriptionError(),
            isOnTheFly,
            new LocalQuickFix[] {getFix(module, descriptionDir)},
            ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
    return new ProblemDescriptor[] {problemDescriptor};
  }
示例#23
0
  public static void addJavaHome(@NotNull JavaParameters params, @NotNull Module module) {
    final Sdk sdk = ModuleUtilCore.getSdk(module, JavaModuleExtensionImpl.class);
    if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
      String path = StringUtil.trimEnd(sdk.getHomePath(), File.separator);
      if (StringUtil.isNotEmpty(path)) {
        Map<String, String> env = params.getEnv();
        if (env == null) {
          env = new HashMap<String, String>();
          params.setEnv(env);
        }

        env.put("JAVA_HOME", FileUtil.toSystemDependentName(path));
      }
    }
  }
  @NotNull
  public static String getStorageRootFromOptions(@NotNull Module module) {
    String moduleRoot = ModuleUtilCore.getModuleDirPath(module);
    String storageRef = module.getOptionValue(JpsProjectLoader.CLASSPATH_DIR_ATTRIBUTE);
    if (storageRef == null) {
      return moduleRoot;
    }

    storageRef = FileUtil.toSystemIndependentName(storageRef);
    if (SystemInfo.isWindows
        ? FileUtil.isAbsolutePlatformIndependent(storageRef)
        : FileUtil.isUnixAbsolutePath(storageRef)) {
      return storageRef;
    } else {
      return moduleRoot + '/' + storageRef;
    }
  }
  @Nullable
  @Override
  public RunProfileState getState(
      @NotNull Executor executor, @NotNull final ExecutionEnvironment executionEnvironment)
      throws ExecutionException {
    val module = getConfigurationModule().getModule();
    if (module == null) {
      throw new ExecutionException("Module is null");
    }

    DotNetModuleExtension<?> extension =
        ModuleUtilCore.getExtension(module, DotNetModuleExtension.class);

    if (extension == null) {
      throw new ExecutionException("Module don't have .NET extension");
    }

    Sdk sdk = extension.getSdk();
    if (sdk == null) {
      throw new ExecutionException("SDK for module is not defined");
    }

    DebugConnectionInfo debugConnectionInfo = null;
    if (executor instanceof DefaultDebugExecutor) {
      debugConnectionInfo = new DebugConnectionInfo("127.0.0.1", -1, true);
    }

    DotNetConfiguration runProfile = (DotNetConfiguration) executionEnvironment.getRunProfile();
    GeneralCommandLine runCommandLine =
        extension.createDefaultCommandLine(sdk, debugConnectionInfo);
    String programParameters = runProfile.getProgramParameters();
    if (!StringUtil.isEmpty(programParameters)) {
      runCommandLine.addParameters(StringUtil.split(programParameters, " "));
    }
    runCommandLine.setPassParentEnvironment(runProfile.isPassParentEnvs());
    runCommandLine.getEnvironment().putAll(runProfile.getEnvs());
    runCommandLine.setWorkDirectory(
        DotNetMacroUtil.expand(module, runProfile.getWorkingDirectory(), false));

    DotNetRunProfileState state = new DotNetRunProfileState(executionEnvironment, runCommandLine);
    if (debugConnectionInfo != null) {
      state.putUserData(DotNetRunKeys.DEBUG_CONNECTION_INFO_KEY, debugConnectionInfo);
    }

    return state;
  }
  private static void collectAllAndroidDependencies(
      Module module,
      boolean androidLibrariesOnly,
      List<AndroidModuleExtension> result,
      Set<AndroidModuleExtension> visited) {
    final OrderEntry[] entries = ModuleRootManager.getInstance(module).getOrderEntries();
    // loop in the inverse order to resolve dependencies on the libraries, so that if a library
    // is required by two higher level libraries it can be inserted in the correct place

    for (int i = entries.length - 1; i >= 0; i--) {
      final OrderEntry orderEntry = entries[i];
      if (orderEntry instanceof ModuleOrderEntry) {
        final ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry) orderEntry;

        if (moduleOrderEntry.getScope() == DependencyScope.COMPILE) {
          final Module depModule = moduleOrderEntry.getModule();

          if (depModule != null) {
            final AndroidModuleExtension depFacet =
                ModuleUtilCore.getExtension(depModule, AndroidModuleExtension.class);

            if (depFacet != null
                && (!androidLibrariesOnly || depFacet.isLibraryProject())
                && visited.add(depFacet)) {
              final List<WeakReference<AndroidModuleExtension>> cachedDepDeps =
                  getInstance(depModule).getListRef(androidLibrariesOnly).get();

              if (cachedDepDeps != null) {
                final List<AndroidModuleExtension> depDeps = dereference(cachedDepDeps);

                for (AndroidModuleExtension depDepFacet : depDeps) {
                  if (visited.add(depDepFacet)) {
                    result.add(depDepFacet);
                  }
                }
              } else {
                collectAllAndroidDependencies(depModule, androidLibrariesOnly, result, visited);
              }
              result.add(depFacet);
            }
          }
        }
      }
    }
  }
示例#27
0
  public void createApplicationIfNeeded(@NotNull final Module module) {
    if (findAppRoot(module) == null && module.getUserData(CREATE_APP_STRUCTURE) == Boolean.TRUE) {
      while (ModuleUtilCore.getSdk(module, JavaModuleExtensionImpl.class) == null) {
        if (Messages.showYesNoDialog(
                module.getProject(),
                "Cannot generate "
                    + getDisplayName()
                    + " project structure because JDK is not specified for module \""
                    + module.getName()
                    + "\".\n"
                    + getDisplayName()
                    + " project will not be created if you don't specify JDK.\nDo you want to specify JDK?",
                "Error",
                Messages.getErrorIcon())
            == 1) {
          return;
        }
        ProjectSettingsService.getInstance(module.getProject())
            .showModuleConfigurationDialog(module.getName(), ClasspathEditor.NAME);
      }
      module.putUserData(CREATE_APP_STRUCTURE, null);
      final GeneralCommandLine commandLine = getCreationCommandLine(module);
      if (commandLine == null) return;

      MvcConsole.executeProcess(
          module,
          commandLine,
          new Runnable() {
            public void run() {
              VirtualFile root = findAppRoot(module);
              if (root == null) return;

              PsiDirectory psiDir = PsiManager.getInstance(module.getProject()).findDirectory(root);
              IdeView ide =
                  LangDataKeys.IDE_VIEW.getData(DataManager.getInstance().getDataContext());
              if (ide != null) ide.selectElement(psiDir);

              // also here comes fileCreated(application.properties) which manages roots and run
              // configuration
            }
          },
          true);
    }
  }
  public void search() {
    myFiles.clear();
    myJars.clear();

    PsiManager psiManager = PsiManager.getInstance(myProject);
    for (PsiFile file : search(myModule, myProject)) {
      VirtualFile jar = JarFileSystem.getInstance().getVirtualFileForJar(file.getVirtualFile());
      if (jar != null) {
        myJars.putValue(jar, file);
      } else {
        Module module = ModuleUtilCore.findModuleForPsiElement(file);
        if (module != null) {
          myFiles.putValue(module, file);
        } else {
          VirtualFile virtualFile = file.getVirtualFile();
          myVirtualFiles.putValue(virtualFile.getParent(), psiManager.findFile(virtualFile));
        }
      }
    }
  }
  @Override
  public void invoke(
      @NotNull final Project project, final Editor editor, PsiFile file, DataContext dataContext) {
    final int offset = editor.getCaretModel().getOffset();
    final PsiElement element = file.findElementAt(offset);
    final PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class);
    final String cannotRefactorMessage = getCannotRefactorMessage(member);
    if (cannotRefactorMessage != null) {
      String message = RefactoringBundle.getCannotRefactorMessage(cannotRefactorMessage);
      showErrorMessage(message, project, editor);
      return;
    }

    final AnalysisScope scope = new AnalysisScope(file);
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    final BaseAnalysisActionDialog dlg =
        new BaseAnalysisActionDialog(
            RefactoringBundle.message(
                "replace.method.duplicates.scope.chooser.title", REFACTORING_NAME),
            RefactoringBundle.message("replace.method.duplicates.scope.chooser.message"),
            project,
            scope,
            module != null ? module.getName() : null,
            false,
            AnalysisUIOptions.getInstance(project),
            element);
    if (dlg.showAndGet()) {
      ProgressManager.getInstance()
          .run(
              new Task.Backgroundable(project, "Locate duplicates", true) {
                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                  indicator.setIndeterminate(true);
                  invokeOnScope(
                      project,
                      member,
                      dlg.getScope(AnalysisUIOptions.getInstance(project), scope, project, module));
                }
              });
    }
  }
 @Override
 public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file)
     throws IncorrectOperationException {
   final VirtualFile virtualFile = file.getVirtualFile();
   LOG.assertTrue(virtualFile != null);
   final Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
   final LanguageLevel moduleLevel =
       module == null
           ? null
           : LanguageLevelModuleExtensionImpl.getInstance(module).getLanguageLevel();
   if (moduleLevel != null && isLanguageLevelAcceptable(project, module, myLevel)) {
     final ModifiableRootModel rootModel =
         ModuleRootManager.getInstance(module).getModifiableModel();
     rootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLevel);
     rootModel.commit();
   } else {
     LanguageLevelProjectExtension.getInstance(project).setLanguageLevel(myLevel);
     ProjectRootManagerEx.getInstanceEx(project)
         .makeRootsChange(EmptyRunnable.INSTANCE, false, true);
   }
 }