com.intellij.psi.util.PsiModificationTracker#com.intellij.openapi.project.ProjectManager源码实例Demo

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

源代码1 项目: lsp4intellij   文件: IntellijLanguageClient.java
@Override
public void initComponent() {
    try {
        // Adds project listener.
        ApplicationManager.getApplication().getMessageBus().connect().subscribe(ProjectManager.TOPIC,
                new LSPProjectManagerListener());
        // Adds editor listener.
        EditorFactory.getInstance().addEditorFactoryListener(new LSPEditorListener(), this);
        // Adds VFS listener.
        VirtualFileManager.getInstance().addVirtualFileListener(new VFSListener());
        // Adds document event listener.
        ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC,
                new LSPFileDocumentManagerListener());

        // in case if JVM forcefully exit.
        Runtime.getRuntime().addShutdownHook(new Thread(() -> projectToLanguageWrappers.values().stream()
                .flatMap(Collection::stream).filter(RUNNING).forEach(s -> s.stop(true))));

        LOG.info("Intellij Language Client initialized successfully");
    } catch (Exception e) {
        LOG.warn("Fatal error occurred when initializing Intellij language client.", e);
    }
}
 
源代码2 项目: consulo   文件: IdeaModifiableModelsProvider.java
@Override
public LibraryTable.ModifiableModel getLibraryTableModifiableModel() {
  final Project[] projects = ProjectManager.getInstance().getOpenProjects();
  for (Project project : projects) {
    if (!project.isInitialized()) {
      continue;
    }
    StructureConfigurableContext context = getProjectStructureContext(project);
    LibraryTableModifiableModelProvider provider = context != null ? context.createModifiableModelProvider(LibraryTablesRegistrar.APPLICATION_LEVEL) : null;
    final LibraryTable.ModifiableModel modifiableModel = provider != null ? provider.getModifiableModel() : null;
    if (modifiableModel != null) {
      return modifiableModel;
    }
  }
  return LibraryTablesRegistrar.getInstance().getLibraryTable().getModifiableModel();
}
 
源代码3 项目: consulo   文件: EventLog.java
@Inject
public EventLog(Application application) {
  myModel = new LogModel(null, application);

  application.getMessageBus().connect().subscribe(Notifications.TOPIC, new NotificationsAdapter() {
    @Override
    public void notify(@Nonnull Notification notification) {
      final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
      if (openProjects.length == 0) {
        myModel.addNotification(notification);
      }
      for (Project p : openProjects) {
        getProjectComponent(p).printNotification(notification);
      }
    }
  });
}
 
源代码4 项目: SmartIM4IntelliJ   文件: IMWindowFactory.java
public File getWorkDir() {
    Project p = this.project;
    if (p == null) {
        p = ProjectManager.getInstance().getDefaultProject();
        Project[] ps = ProjectManager.getInstance().getOpenProjects();
        if (ps != null) {
            for (Project t : ps) {
                if (!t.isDefault()) {
                    p = t;
                }
            }
        }
    }
    File dir = new File(p.getBasePath(), Project.DIRECTORY_STORE_FOLDER);
    return dir;
}
 
源代码5 项目: consulo   文件: ExternalSystemFacadeManager.java
/**
 * @return gradle api facade to use
 * @throws Exception    in case of inability to return the facade
 */
@Nonnull
public RemoteExternalSystemFacade getFacade(@javax.annotation.Nullable Project project,
                                            @Nonnull String externalProjectPath,
                                            @Nonnull ProjectSystemId externalSystemId) throws Exception
{
  if (project == null) {
    project = ProjectManager.getInstance().getDefaultProject();
  }
  IntegrationKey key = new IntegrationKey(project, externalSystemId, externalProjectPath);
  final RemoteExternalSystemFacade facade = myFacadeWrappers.get(key);
  if (facade == null) {
    final RemoteExternalSystemFacade newFacade = (RemoteExternalSystemFacade)Proxy.newProxyInstance(
      ExternalSystemFacadeManager.class.getClassLoader(), new Class[]{RemoteExternalSystemFacade.class, Consumer.class},
      new MyHandler(key)
    );
    myFacadeWrappers.putIfAbsent(key, newFacade);
  }
  return myFacadeWrappers.get(key);
}
 
源代码6 项目: consulo   文件: ExcludeRootsCache.java
@Nonnull
String[] getExcludedUrls() {
  return ReadAction.compute(() -> {
    CachedUrls cache = myCache;
    long actualModCount = Arrays.stream(ProjectManager.getInstance().getOpenProjects()).map(ProjectRootManager::getInstance).mapToLong(ProjectRootManager::getModificationCount).sum();
    String[] urls;
    if (cache != null && actualModCount == cache.myModificationCount) {
      urls = cache.myUrls;
    }
    else {
      Collection<String> excludedUrls = new THashSet<>();
      for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        for (Module module : ModuleManager.getInstance(project).getModules()) {
          urls = ModuleRootManager.getInstance(module).getExcludeRootUrls();
          ContainerUtil.addAll(excludedUrls, urls);
        }
      }
      urls = ArrayUtilRt.toStringArray(excludedUrls);
      Arrays.sort(urls);
      myCache = new CachedUrls(actualModCount, urls);
    }
    return urls;
  });
}
 
源代码7 项目: flutter-intellij   文件: FlutterSdkUtil.java
@NotNull
public static String[] getKnownFlutterSdkPaths() {
  final Set<String> paths = new HashSet<>();

  // scan current projects for existing flutter sdk settings
  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
    if (flutterSdk != null) {
      paths.add(flutterSdk.getHomePath());
    }
  }

  // use the list of paths they've entered in the past
  final String[] knownPaths = PropertiesComponent.getInstance().getValues(FLUTTER_SDK_KNOWN_PATHS);
  if (knownPaths != null) {
    paths.addAll(Arrays.asList(knownPaths));
  }

  // search the user's path
  final String fromUserPath = locateSdkFromPath();
  if (fromUserPath != null) {
    paths.add(fromUserPath);
  }

  return paths.toArray(new String[0]);
}
 
源代码8 项目: flutter-intellij   文件: FlutterSdkUtil.java
@NotNull
public static String[] getKnownFlutterSdkPaths() {
  final Set<String> paths = new HashSet<>();

  // scan current projects for existing flutter sdk settings
  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
    if (flutterSdk != null) {
      paths.add(flutterSdk.getHomePath());
    }
  }

  // use the list of paths they've entered in the past
  final String[] knownPaths = PropertiesComponent.getInstance().getValues(FLUTTER_SDK_KNOWN_PATHS);
  if (knownPaths != null) {
    paths.addAll(Arrays.asList(knownPaths));
  }

  // search the user's path
  final String fromUserPath = locateSdkFromPath();
  if (fromUserPath != null) {
    paths.add(fromUserPath);
  }

  return paths.toArray(new String[0]);
}
 
@Nonnull
private static Document setupFileEditorAndDocument(@Nonnull String fileName, @Nonnull String fileText) throws IOException {
  EncodingProjectManager.getInstance(getProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
  EncodingProjectManager.getInstance(ProjectManager.getInstance().getDefaultProject()).setEncoding(null, CharsetToolkit.UTF8_CHARSET);
  PostprocessReformattingAspect.getInstance(ourProject).doPostponedFormatting();
  deleteVFile();
  myVFile = getSourceRoot().createChildData(null, fileName);
  VfsUtil.saveText(myVFile, fileText);
  final FileDocumentManager manager = FileDocumentManager.getInstance();
  final Document document = manager.getDocument(myVFile);
  assertNotNull("Can't create document for '" + fileName + "'", document);
  manager.reloadFromDisk(document);
  document.insertString(0, " ");
  document.deleteString(0, 1);
  myFile = getPsiManager().findFile(myVFile);
  assertNotNull("Can't create PsiFile for '" + fileName + "'. Unknown file type most probably.", myFile);
  assertTrue(myFile.isPhysical());
  myEditor = createEditor(myVFile);
  myVFile.setCharset(CharsetToolkit.UTF8_CHARSET);

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  return document;
}
 
源代码10 项目: consulo   文件: NamedScopeDescriptor.java
@Override
public boolean matches(@Nonnull PsiFile psiFile) {
  Pair<NamedScopesHolder, NamedScope> resolved = resolveScope(psiFile.getProject());
  if (resolved == null) {
    resolved = resolveScope(ProjectManager.getInstance().getDefaultProject());
  }
  if (resolved != null) {
    PackageSet fileSet = resolved.second.getValue();
    if (fileSet != null) {
      return fileSet.contains(psiFile, resolved.first);
    }
  }
  if (myFileSet != null) {
    NamedScopesHolder holder = DependencyValidationManager.getInstance(psiFile.getProject());
    return myFileSet.contains(psiFile, holder);
  }
  return false;
}
 
源代码11 项目: jetbrains-wakatime   文件: WakaTime.java
private void checkApiKey() {
    ApplicationManager.getApplication().invokeLater(new Runnable(){
        public void run() {
            // prompt for apiKey if it does not already exist
            Project project = null;
            try {
                project = ProjectManager.getInstance().getDefaultProject();
            } catch (Exception e) { }
            ApiKey apiKey = new ApiKey(project);
            if (apiKey.getApiKey().equals("")) {
                apiKey.promptForApiKey();
            }
            log.debug("Api Key: " + obfuscateKey(ApiKey.getApiKey()));
        }
    });
}
 
源代码12 项目: intellij   文件: BlazeProjectOpenProcessor.java
@Nullable
@Override
public Project doOpenProject(
    VirtualFile file, @Nullable Project projectToClose, boolean forceOpenInNewFrame) {
  ProjectManager pm = ProjectManager.getInstance();
  if (projectToClose != null) {
    pm.closeProject(projectToClose);
  }
  try {
    VirtualFile ideaSubdirectory = getIdeaSubdirectory(file);
    if (ideaSubdirectory == null) {
      return null;
    }
    VirtualFile projectSubdirectory = ideaSubdirectory.getParent();
    return pm.loadAndOpenProject(projectSubdirectory.getPath());
  } catch (IOException | JDOMException e) {
    return null;
  }
}
 
源代码13 项目: consulo   文件: DesktopSaveAndSyncHandlerImpl.java
@Override
public void refreshOpenFiles() {
  List<VirtualFile> files = ContainerUtil.newArrayList();

  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    for (VirtualFile file : FileEditorManager.getInstance(project).getSelectedFiles()) {
      if (file instanceof NewVirtualFile) {
        files.add(file);
      }
    }
  }

  if (!files.isEmpty()) {
    // refresh open files synchronously so it doesn't wait for potentially longish refresh request in the queue to finish
    RefreshQueue.getInstance().refresh(false, false, null, files);
  }
}
 
源代码14 项目: aem-ide-tooling-4-intellij   文件: ConsoleLog.java
@Override
public void notify(@NotNull Notification notification) {
    try {
        final ProjectManager projectManager = ProjectManager.getInstance();
        if(projectManager != null) {
            final Project[] openProjects = projectManager.getOpenProjects();
            if(openProjects.length == 0) {
                if(myModel != null) {
                    myModel.addNotification(notification);
                }
            }
            for(Project p : openProjects) {
                ConsoleLogProjectTracker consoleLogProjectTracker = getProjectComponent(p);
                if(consoleLogProjectTracker != null) {
                    consoleLogProjectTracker.printNotification(notification);
                }
            }
        } else {
            PluginManager.getLogger().error("Project Manager could not be retrieved");
        }
    } catch(Exception e) {
        PluginManager.getLogger().error("Could not Notify to Console Log Project Tracker", e);
    }
}
 
源代码15 项目: consulo   文件: LookupDocumentSavingVetoer.java
@Override
public boolean maySaveDocument(@Nonnull Document document, boolean isSaveExplicit) {
  if (ApplicationManager.getApplication().isDisposed() || isSaveExplicit) {
    return true;
  }

  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    if (!project.isInitialized() || project.isDisposed()) {
      continue;
    }
    LookupEx lookup = LookupManager.getInstance(project).getActiveLookup();
    if (lookup != null) {
      Editor editor = InjectedLanguageUtil.getTopLevelEditor(lookup.getEditor());
      if (editor.getDocument() == document) {
        return false;
      }
    }
  }
  return true;
}
 
源代码16 项目: consulo   文件: EnforcedPlainTextFileTypeManager.java
private static void fireRootsChanged(final Collection<VirtualFile> files, final boolean isAdded) {
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        ProjectRootManagerEx.getInstanceEx(project).makeRootsChange(EmptyRunnable.getInstance(), false, true);
        ProjectPlainTextFileTypeManager projectPlainTextFileTypeManager = ProjectPlainTextFileTypeManager.getInstance(project);
        for (VirtualFile file : files) {
          if (projectPlainTextFileTypeManager.hasProjectContaining(file)) {
            if (isAdded) {
              projectPlainTextFileTypeManager.addFile(file);
            }
            else {
              projectPlainTextFileTypeManager.removeFile(file);
            }
          }
        }
      }
    }
  });
}
 
源代码17 项目: consulo   文件: DesktopIdeFrameImpl.java
private void setupCloseAction() {
  myJFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  myJFrame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(@Nonnull final WindowEvent e) {
      if (isTemporaryDisposed()) return;

      final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
      if (openProjects.length > 1 || openProjects.length == 1 && TopApplicationMenuUtil.isMacSystemMenu) {
        if (myProject != null && myProject.isOpen()) {
          ProjectUtil.closeAndDispose(myProject);
        }
        ApplicationManager.getApplication().getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed();
        WelcomeFrame.showIfNoProjectOpened();
      }
      else {
        Application.get().exit();
      }
    }
  });
}
 
源代码18 项目: consulo   文件: FileTemplateManagerImpl.java
@Inject
public FileTemplateManagerImpl(@Nonnull FileTypeManager typeManager,
                               FileTemplateSettings projectSettings,
                               ExportableFileTemplateSettings defaultSettings,
                               ProjectManager pm,
                               final Project project) {
  myTypeManager = (FileTypeManagerEx)typeManager;
  myProjectSettings = projectSettings;
  myDefaultSettings = defaultSettings;
  myProject = project;

  myProjectScheme = project.isDefault() ? null : new FileTemplatesScheme("Project") {
    @Nonnull
    @Override
    public String getTemplatesDir() {
      return FileUtilRt.toSystemDependentName(StorageUtil.getStoreDir(project) + "/" + TEMPLATES_DIR);
    }

    @Nonnull
    @Override
    public Project getProject() {
      return project;
    }
  };
}
 
源代码19 项目: lsp4intellij   文件: FileUtils.java
/**
 * This can be used to instantly apply a language server definition without restarting the IDE.
 */
public static void reloadAllEditors() {
    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : openProjects) {
        reloadEditors(project);
    }
}
 
源代码20 项目: lsp4intellij   文件: FileUtils.java
/**
 * Find projects which contains the given file. This search runs among all open projects.
 */
@NotNull
public static Set<Project> findProjectsFor(@NotNull VirtualFile file) {
    return Arrays.stream(ProjectManager.getInstance().getOpenProjects())
            .flatMap(p -> Arrays.stream(searchFiles(file.getName(), p)))
            .filter(f -> f.getVirtualFile().getPath().equals(file.getPath())).map(PsiElement::getProject)
            .collect(Collectors.toSet());
}
 
源代码21 项目: consulo   文件: GistManagerImpl.java
private static void invalidateDependentCaches() {
  GuiUtils.invokeLaterIfNeeded(() -> {
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
      PsiManager.getInstance(project).dropPsiCaches();
    }
  }, ModalityState.NON_MODAL);
}
 
源代码22 项目: consulo   文件: ExternalSystemFacadeManager.java
@Nonnull
private static Project findProject(@Nonnull IntegrationKey key) {
  final ProjectManager projectManager = ProjectManager.getInstance();
  for (Project project : projectManager.getOpenProjects()) {
    if (key.getIdeProjectName().equals(project.getName()) && key.getIdeProjectLocationHash().equals(project.getLocationHash())) {
      return project;
    }
  }
  return projectManager.getDefaultProject();
}
 
@NotNull
protected List<PsalmValidatorConfiguration> getDefaultProjectSettings() {
    ProjectPsalmValidatorConfigurationBaseManager service = ServiceManager.getService(
        ProjectManager.getInstance().getDefaultProject(),
        ProjectPsalmValidatorConfigurationBaseManager.class
    );

    return service.getSettings();
}
 
@NotNull
protected List<PhpStanValidatorConfiguration> getDefaultProjectSettings() {
    ProjectPhpStanValidatorConfigurationBaseManager service = ServiceManager.getService(
        ProjectManager.getInstance().getDefaultProject(),
        ProjectPhpStanValidatorConfigurationBaseManager.class
    );

    return service.getSettings();
}
 
源代码25 项目: intellij-quarkus   文件: PsiUtilsImpl.java
@Override
public Module getModule(VirtualFile file) {
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        Module module = ProjectFileIndex.getInstance(project).getModuleForFile(file);
        if (module != null) {
            return module;
        }
    }
    return null;
}
 
源代码26 项目: Thinkphp5-Plugin   文件: ShowLog.java
@Override
public boolean value(Object o) {
    Project project = ProjectManager.getInstance().getOpenProjects()[0];
    String root = project.getBasePath();
    Util.setConfig(root+"/"+Setting.fileName);
    return Setting.config.logEnable;
}
 
源代码27 项目: consulo   文件: FlatWelcomeFrame.java
static void setupCloseAction(final JFrame frame) {
  frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  frame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(final WindowEvent e) {
      saveLocation(frame.getBounds());

      frame.dispose();

      if (ProjectManager.getInstance().getOpenProjects().length == 0) {
        Application.get().exit();
      }
    }
  });
}
 
源代码28 项目: consulo   文件: EditorOptionDescription.java
@Override
protected void fireUpdated() {
  Project[] projects = ProjectManager.getInstance().getOpenProjects();
  for (Project project : projects) {
    DaemonCodeAnalyzer.getInstance(project).settingsChanged();
  }

  EditorFactory.getInstance().refreshAllEditors();
}
 
源代码29 项目: intellij-latte   文件: LatteFileListener.java
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
    for (VFileEvent event : events) {
        VirtualFile file = event.getFile();
        if (!(file instanceof XmlFile) || !file.getName().equals("latte-intellij.xml") || file.isValid()) {
            continue;
        }

        XmlDocument document = ((XmlFile) file).getDocument();
        if (document == null || document.getRootTag() == null) {
            continue;
        }

        LatteXmlFileData.VendorResult vendorResult = LatteXmlFileDataFactory.getVendor(document);
        if (vendorResult == null) {
            continue;
        }

        List<Project> projects = new ArrayList<>();
        Project project = ProjectUtil.guessProjectForContentFile(file);
        if (project != null) {
            projects.add(project);
        } else {
            Collections.addAll(projects, ProjectManager.getInstance().getOpenProjects());
        }

        LatteIndexUtil.notifyRemovedFiles(projects);
    }
}
 
源代码30 项目: SmartIM4IntelliJ   文件: VFSUtils.java
public static Project[] getOpenProjects() {
    Project[] openProjects = null;
    if (openProjects == null) {
        openProjects = ProjectManager.getInstance().getOpenProjects();
    }
    return openProjects;
}