Java 类com.intellij.psi.impl.PsiManagerImpl 实例源码

项目:manifold-ij    文件:ManifoldPsiClass.java   
public void initialize( PsiClass delegate, List<IFile> files, String fqn, DiagnosticCollector issues )
{
  _ifiles = files;
  _fqn = fqn;
  _issues = issues;
  PsiManager manager = PsiManagerImpl.getInstance( delegate.getProject() );
  _files = new ArrayList<>( _ifiles.size() );
  for( IFile ifile : _ifiles )
  {
    VirtualFile vfile = ((IjFile)ifile).getVirtualFile();
    if( vfile != null )
    {
      PsiFile file = manager.findFile( vfile );
      _files.add( file );

      Module module = ModuleUtilCore.findModuleForFile( vfile, delegate.getProject() );
      if( module != null )
      {
        file.putUserData( ModuleUtil.KEY_MODULE, module );
      }
    }
  }
  delegate.getContainingFile().putUserData( KEY_MANIFOLD_PSI_CLASS, this );
}
项目:manifold-ij    文件:ManTypeFinder.java   
@Override
public PsiPackage findPackage( String fqn )
{
  //System.out.println( "findPackage() : " + fqn );

  List<ManModule> modules = ManProject.manProjectFrom( _project ).getModules();
  PsiManager manager = PsiManagerImpl.getInstance( _project );
  for( ManModule mm : modules )
  {
    for( ITypeManifold sp : mm.getTypeManifolds() )
    {
      if( sp.getProducerKind() != Supplemental && sp.isPackage( fqn ) )
      {
        return new NonDirectoryPackage( manager, fqn );
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:CodeInsightTestFixtureImpl.java   
@Override
public void setUp() throws Exception {
  super.setUp();

  TestRunnerUtil.replaceIdeEventQueueSafely();
  EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() {
    @Override
    public void run() throws Throwable {
      myProjectFixture.setUp();
      myTempDirFixture.setUp();

      VirtualFile tempDir = myTempDirFixture.getFile("");
      PlatformTestCase.synchronizeTempDirVfs(tempDir);

      myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject());
      configureInspections(LocalInspectionTool.EMPTY_ARRAY, getProject(), Collections.<String>emptyList(), getTestRootDisposable());

      DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
      daemonCodeAnalyzer.prepareForTest();

      DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
      ensureIndexesUpToDate(getProject());
      ((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities();
    }
  });
}
项目:intellij-ce-playground    文件:PlatformTestCase.java   
public static void cleanupApplicationCaches(Project project) {
  if (project != null && !project.isDisposed()) {
    UndoManagerImpl globalInstance = (UndoManagerImpl)UndoManager.getGlobalInstance();
    if (globalInstance != null) {
      globalInstance.dropHistoryInTests();
    }
    ((UndoManagerImpl)UndoManager.getInstance(project)).dropHistoryInTests();

    ((PsiManagerImpl)PsiManager.getInstance(project)).cleanupForNextTest();
  }

  ProjectManagerImpl projectManager = (ProjectManagerImpl)ProjectManager.getInstance();
  if (projectManager.isDefaultProjectInitialized()) {
    Project defaultProject = projectManager.getDefaultProject();
    ((PsiManagerImpl)PsiManager.getInstance(defaultProject)).cleanupForNextTest();
  }

  LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl)LocalFileSystem.getInstance();
  if (localFileSystem != null) {
    localFileSystem.cleanupForNextTest();
  }

}
项目:intellij-ce-playground    文件:BlockSupportImpl.java   
public static void sendAfterChildrenChangedEvent(@NotNull PsiManagerImpl manager,
                                                 @NotNull PsiFile scope,
                                                 int oldLength,
                                                 boolean isGenericChange) {
  if (!scope.isPhysical()) {
    manager.afterChange(false);
    return;
  }
  PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(manager);
  event.setParent(scope);
  event.setFile(scope);
  event.setOffset(0);
  event.setOldLength(oldLength);
  event.setGenericChange(isGenericChange);
  manager.childrenChanged(event);
}
项目:intellij-ce-playground    文件:PsiFileImplUtil.java   
public static PsiFile setName(@NotNull PsiFile file, @NotNull String newName) throws IncorrectOperationException {
  VirtualFile vFile = file.getViewProvider().getVirtualFile();
  PsiManagerImpl manager = (PsiManagerImpl)file.getManager();

  try{
    final FileType newFileType = FileTypeRegistry.getInstance().getFileTypeByFileName(newName);
    if (UnknownFileType.INSTANCE.equals(newFileType) || newFileType.isBinary()) {
      // before the file becomes unknown or a binary (thus, not openable in the editor), save it to prevent data loss
      final FileDocumentManager fdm = FileDocumentManager.getInstance();
      final Document doc = fdm.getCachedDocument(vFile);
      if (doc != null) {
        fdm.saveDocumentAsIs(doc);
      }
    }

    vFile.rename(manager, newName);
  }
  catch(IOException e){
    throw new IncorrectOperationException(e);
  }

  return file.getViewProvider().isPhysical() ? manager.findFile(vFile) : file;
}
项目:intellij-ce-playground    文件:PsiVFSListener.java   
public PsiVFSListener(Project project) {
  myProject = project;
  myFileTypeManager = FileTypeManager.getInstance();
  myProjectRootManager = ProjectRootManager.getInstance(project);
  myManager = (PsiManagerImpl) PsiManager.getInstance(project);
  myFileManager = (FileManagerImpl) myManager.getFileManager();

  myConnection = project.getMessageBus().connect(project);

  StartupManager.getInstance(project).registerPreStartupActivity(new Runnable() {
    @Override
    public void run() {
      myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener());
      myConnection.subscribe(FileTypeManager.TOPIC, new FileTypeListener.Adapter() {
        @Override
        public void fileTypesChanged(@NotNull FileTypeEvent e) {
          myFileManager.processFileTypesChanged();
        }
      });
      myConnection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new MyFileDocumentManagerAdapter());
      myFileManager.markInitialized();
    }
  });
}
项目:intellij-ce-playground    文件:PyMultiFileResolveTestCase.java   
protected PsiElement doResolve(PsiFile psiFile) {
  final PsiPolyVariantReference ref = PyResolveTestCase.findReferenceByMarker(psiFile);
  final PsiManagerImpl psiManager = (PsiManagerImpl)myFixture.getPsiManager();
  psiManager.setAssertOnFileLoadingFilter(new VirtualFileFilter() {
    @Override
    public boolean accept(VirtualFile file) {
      FileType fileType = file.getFileType();
      return fileType == PythonFileType.INSTANCE;
    }
  }, myTestRootDisposable);
  final ResolveResult[] resolveResults = ref.multiResolve(false);
  psiManager.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
  if (resolveResults.length == 0) {
    return null;
  }
  return resolveResults[0].isValidResult() ? resolveResults[0].getElement() : null;
}
项目:tools-idea    文件:ClsFileImpl.java   
public static String decompile(PsiManager manager, VirtualFile file) {
  ClsFileImpl psiFile = null;

  final FileViewProvider provider = ((PsiManagerEx)manager).getFileManager().findViewProvider(file);
  if (provider != null) {
    final PsiFile psi = provider.getPsi(provider.getBaseLanguage());
    if (psi instanceof ClsFileImpl) {
      psiFile = (ClsFileImpl)psi;
    }
  }

  if (psiFile == null) {
    psiFile = new ClsFileImpl((PsiManagerImpl)manager, new ClassFileViewProvider(manager, file), true);
  }

  final StringBuilder buffer = new StringBuilder();
  psiFile.appendMirrorText(0, buffer);
  return buffer.toString();
}
项目:tools-idea    文件:ClassFileViewProvider.java   
@Override
protected PsiFile createFile(@NotNull final Project project, @NotNull final VirtualFile vFile, @NotNull final FileType fileType) {
  final FileIndexFacade fileIndex = ServiceManager.getService(project, FileIndexFacade.class);
  if (fileIndex.isInLibraryClasses(vFile) || !fileIndex.isInSource(vFile)) {
    String name = vFile.getName();

    // skip inners & anonymous (todo: read actual class name from file)
    int dotIndex = name.lastIndexOf('.');
    if (dotIndex < 0) dotIndex = name.length();
    int index = name.lastIndexOf('$', dotIndex);
    if (index <= 0 || index == dotIndex - 1) {
      return new ClsFileImpl((PsiManagerImpl)PsiManager.getInstance(project), this);
    }
  }

  return null;
}
项目:tools-idea    文件:CodeInsightTestFixtureImpl.java   
@Override
public void setUp() throws Exception {
  super.setUp();

  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      try {
        myProjectFixture.setUp();
        myTempDirFixture.setUp();
      }
      catch (Exception e) {
        throw new RuntimeException(e);
      }
      myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject());
      configureInspections(myInspections == null ? LocalInspectionTool.EMPTY_ARRAY : myInspections);

      DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
      daemonCodeAnalyzer.prepareForTest();

      DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
      ensureIndexesUpToDate(getProject());
      ((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities();
    }
  });
}
项目:tools-idea    文件:SingleRootFileViewProvider.java   
@Nullable
protected PsiFile createFile(@NotNull Project project, @NotNull VirtualFile file, @NotNull FileType fileType) {
  if (fileType.isBinary() || file.is(VFileProperty.SPECIAL)) {
    return new PsiBinaryFileImpl((PsiManagerImpl)getManager(), this);
  }
  if (!isTooLargeForIntelligence(file)) {
    final PsiFile psiFile = createFile(getBaseLanguage());
    if (psiFile != null) return psiFile;
  }

  if (isTooLargeForContentLoading(file)) {
    return new PsiLargeFileImpl((PsiManagerImpl)getManager(), this);
  }

  return new PsiPlainTextFileImpl(this);
}
项目:tools-idea    文件:BlockSupportImpl.java   
public static void sendAfterChildrenChangedEvent(@NotNull PsiManagerImpl manager,
                                                 @NotNull PsiFileImpl scope,
                                                 int oldLength,
                                                 boolean isGenericChange) {
  if(!scope.isPhysical()) {
    manager.afterChange(false);
    return;
  }
  PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(manager);
  event.setParent(scope);
  event.setFile(scope);
  event.setOffset(0);
  event.setOldLength(oldLength);
  event.setGeneric(isGenericChange);
  manager.childrenChanged(event);
}
项目:tools-idea    文件:PsiFileImplUtil.java   
public static PsiFile setName(final PsiFile file, String newName) throws IncorrectOperationException {
  VirtualFile vFile = file.getViewProvider().getVirtualFile();
  PsiManagerImpl manager = (PsiManagerImpl)file.getManager();

  try{
    final FileType newFileType = FileTypeRegistry.getInstance().getFileTypeByFileName(newName);
    if (UnknownFileType.INSTANCE.equals(newFileType) || newFileType.isBinary()) {
      // before the file becomes unknown or a binary (thus, not openable in the editor), save it to prevent data loss
      final FileDocumentManager fdm = FileDocumentManager.getInstance();
      final Document doc = fdm.getCachedDocument(vFile);
      if (doc != null) {
        fdm.saveDocumentAsIs(doc);
      }
    }

    vFile.rename(manager, newName);
  }
  catch(IOException e){
    throw new IncorrectOperationException(e.toString(),e);
  }

  return file.getViewProvider().isPhysical() ? manager.findFile(vFile) : file;
}
项目:tools-idea    文件:FileManagerImpl.java   
public FileManagerImpl(PsiManagerImpl manager, FileDocumentManager fileDocumentManager, FileIndexFacade fileIndex) {
  myManager = manager;
  myFileIndex = fileIndex;
  myConnection = manager.getProject().getMessageBus().connect();

  myFileDocumentManager = fileDocumentManager;

  myConnection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
    @Override
    public void enteredDumbMode() {
      updateAllViewProviders();
    }

    @Override
    public void exitDumbMode() {
      updateAllViewProviders();
    }
  });
  Disposer.register(manager.getProject(), this);
}
项目:tools-idea    文件:FormReferencesSearcher.java   
private static boolean processReferencesInUIFormsInner(String name,
                                                       PsiElement element,
                                                       Processor<PsiReference> processor,
                                                       GlobalSearchScope scope1,
                                                       PsiManagerImpl manager,
                                                       final LocalSearchScope filterScope) {
  GlobalSearchScope scope = GlobalSearchScope.projectScope(manager.getProject()).intersectWith(scope1);
  manager.startBatchFilesProcessingMode();

  try {
    List<PsiFile> files = FormClassIndex.findFormsBoundToClass(manager.getProject(), name, scope);

    for (PsiFile file : files) {
      ProgressManager.checkCanceled();

      if (file.getFileType() != StdFileTypes.GUI_DESIGNER_FORM) continue;
      if (!processReferences(processor, file, name, element, filterScope)) return false;
    }
  }
  finally {
    manager.finishBatchFilesProcessingMode();
  }

  return true;
}
项目:tools-idea    文件:FormReferencesSearcher.java   
private static boolean processReferencesInUIForms(final Processor<PsiReference> processor, final PropertiesFile propFile, final GlobalSearchScope globalSearchScope,
                                                 final LocalSearchScope filterScope) {
  final Project project = propFile.getProject();
  GlobalSearchScope scope = GlobalSearchScope.projectScope(project).intersectWith(globalSearchScope);
  PsiManagerImpl manager = (PsiManagerImpl)propFile.getContainingFile().getManager();
  final String baseName = propFile.getResourceBundle().getBaseName();
  manager.startBatchFilesProcessingMode();

  try {
    PsiFile[] files = CacheManager.SERVICE.getInstance(project).getFilesWithWord(baseName, UsageSearchContext.IN_PLAIN_TEXT, scope, true);

    for (PsiFile file : files) {
      ProgressManager.checkCanceled();

      if (file.getFileType() != StdFileTypes.GUI_DESIGNER_FORM) continue;
      if (!processReferences(processor, file, baseName, propFile.getContainingFile(), filterScope)) return false;
    }
  }
  finally {
    manager.finishBatchFilesProcessingMode();
  }

  return true;
}
项目:consulo-csharp    文件:CSharpPartialElementManager.java   
public CSharpPartialElementManager(@NotNull Project project)
{
    myProject = project;
    project.getMessageBus().connect().subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener.Adapter()
    {
        @Override
        public void beforePsiChanged(boolean isPhysical)
        {
            myCache.clear();
        }
    });

    project.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter()
    {
        @Override
        public void rootsChanged(ModuleRootEvent event)
        {
            myCache.clear();
        }
    });
}
项目:consulo    文件:CodeInsightTestFixtureImpl.java   
@Override
public void setUp() throws Exception {
  super.setUp();

  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      try {
        myProjectFixture.setUp();
        myTempDirFixture.setUp();
      }
      catch (Exception e) {
        throw new RuntimeException(e);
      }
      myPsiManager = (PsiManagerImpl)PsiManager.getInstance(getProject());
      configureInspections(myInspections == null ? LocalInspectionTool.EMPTY_ARRAY : myInspections);

      DaemonCodeAnalyzerImpl daemonCodeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject());
      daemonCodeAnalyzer.prepareForTest();

      DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
      ensureIndexesUpToDate(getProject());
      ((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities();
    }
  });
}
项目:consulo    文件:ResolveScopeManagerImpl.java   
public ResolveScopeManagerImpl(Project project, ProjectRootManager projectRootManager, PsiManager psiManager) {
  myProject = project;
  myProjectRootManager = projectRootManager;
  myManager = psiManager;

  myDefaultResolveScopesCache = ConcurrentFactoryMap.createMap((key) -> {
    GlobalSearchScope scope = null;
    for (ResolveScopeProvider resolveScopeProvider : ResolveScopeProvider.EP_NAME.getExtensions()) {
      scope = resolveScopeProvider.getResolveScope(key, myProject);
      if (scope != null) break;
    }
    if (scope == null) scope = getInherentResolveScope(key);
    for (ResolveScopeEnlarger enlarger : ResolveScopeEnlarger.EP_NAME.getExtensions()) {
      final SearchScope extra = enlarger.getAdditionalResolveScope(key, myProject);
      if (extra != null) {
        scope = scope.union(extra);
      }
    }

    return scope;
  });

  ((PsiManagerImpl)psiManager).registerRunnableToRunOnChange(myDefaultResolveScopesCache::clear);
}
项目:consulo    文件:PsiFileImplUtil.java   
@RequiredDispatchThread
public static PsiFile setName(final PsiFile file, String newName) throws IncorrectOperationException {
  VirtualFile vFile = file.getViewProvider().getVirtualFile();
  PsiManagerImpl manager = (PsiManagerImpl)file.getManager();

  try{
    final FileType newFileType = FileTypeRegistry.getInstance().getFileTypeByFileName(newName);
    if (UnknownFileType.INSTANCE.equals(newFileType) || newFileType.isBinary()) {
      // before the file becomes unknown or a binary (thus, not openable in the editor), save it to prevent data loss
      final FileDocumentManager fdm = FileDocumentManager.getInstance();
      final Document doc = fdm.getCachedDocument(vFile);
      if (doc != null) {
        fdm.saveDocumentAsIs(doc);
      }
    }

    vFile.rename(manager, newName);
  }
  catch(IOException e){
    throw new IncorrectOperationException(e);
  }

  return file.getViewProvider().isPhysical() ? manager.findFile(vFile) : file;
}
项目:consulo    文件:FileManagerImpl.java   
public FileManagerImpl(PsiManagerImpl manager, FileDocumentManager fileDocumentManager, FileIndexFacade fileIndex) {
  myManager = manager;
  myFileIndex = fileIndex;
  myConnection = manager.getProject().getMessageBus().connect();

  myFileDocumentManager = fileDocumentManager;

  Disposer.register(manager.getProject(), this);
  LowMemoryWatcher.register(this::processQueue, this);

  myConnection.subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
    @Override
    public void enteredDumbMode() {
      processFileTypesChanged();
    }

    @Override
    public void exitDumbMode() {
      processFileTypesChanged();
    }
  });
}
项目:consulo    文件:PsiVFSListener.java   
public PsiVFSListener(Project project) {
  installGlobalListener();

  myProject = project;
  myFileTypeManager = FileTypeManager.getInstance();
  myProjectRootManager = ProjectRootManager.getInstance(project);
  myManager = (PsiManagerImpl)PsiManager.getInstance(project);
  myFileManager = (FileManagerImpl)myManager.getFileManager();

  StartupManager.getInstance(project).registerPreStartupActivity(() -> {
    MessageBusConnection connection = project.getMessageBus().connect(project);
    connection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener());
    connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() {
      @Override
      public void fileTypesChanged(@Nonnull FileTypeEvent e) {
        myFileManager.processFileTypesChanged();
      }
    });
    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new MyFileDocumentManagerAdapter());
  });
}
项目:consulo-java    文件:ClassFileViewProvider.java   
@Override
protected PsiFile createFile(@NotNull Project project, @NotNull VirtualFile file, @NotNull FileType fileType)
{
    FileIndexFacade fileIndex = ServiceManager.getService(project, FileIndexFacade.class);
    if(!fileIndex.isInLibraryClasses(file) && fileIndex.isInSource(file) || fileIndex.isExcludedFile(file))
    {
        return new PsiBinaryFileImpl((PsiManagerImpl) getManager(), this);
    }

    // skip inner, anonymous, missing and corrupted classes
    try
    {
        if(!isInnerClass(file))
        {
            return new ClsFileImpl(this);
        }
    }
    catch(Exception e)
    {
        Logger.getInstance(ClassFileViewProvider.class).debug(file.getPath(), e);
    }

    return null;
}
项目:manifold-ij    文件:ManTypeFinder.java   
@Override
public PsiPackage[] getSubPackages( PsiPackage psiPackage, GlobalSearchScope scope )
{
  //System.out.println( "getSubPackages() : " + psiPackage + " : " + scope );

  List<ManModule> modules = findModules( scope );
  if( modules.isEmpty() )
  {
    return PsiPackage.EMPTY_ARRAY;
  }

  String parentPackage = psiPackage.getQualifiedName();
  Set<PsiPackage> children = new HashSet<>();
  PsiManager manager = PsiManagerImpl.getInstance( scope.getProject() );
  for( ManModule mm : modules )
  {
    for( ITypeManifold sp : mm.getTypeManifolds() )
    {
      if( sp.getProducerKind() == Supplemental )
      {
        continue;
      }

      Collection<TypeName> typeNames = sp.getTypeNames( parentPackage );
      for( TypeName child : typeNames )
      {
        if( child.kind == TypeName.Kind.NAMESPACE )
        {
          children.add( new NonDirectoryPackage( manager, parentPackage + '.' + child.name ) );
        }
      }
    }
  }
  if( !children.isEmpty() )
  {
    return children.toArray( new PsiPackage[children.size()] );
  }
  return PsiPackage.EMPTY_ARRAY;
}
项目:manifold-ij    文件:ManifoldPsiClassCache.java   
private PsiClass createPsiClass( ManModule module, String fqn, String source )
{
  PsiManager manager = PsiManagerImpl.getInstance( module.getIjProject() );
  final PsiJavaFile aFile = createDummyJavaFile( fqn, manager, source );
  final PsiClass[] classes = aFile.getClasses();
  if( classes.length == 0 )
  {
    return PsiErrorClassUtil.create( module.getIjProject(), new RuntimeException( "Invalid class: " + fqn ) );
  }
  return classes[0];
}
项目:intellij-ce-playground    文件:JavaResolveCache.java   
public JavaResolveCache(@Nullable("can be null in com.intellij.core.JavaCoreApplicationEnvironment.JavaCoreApplicationEnvironment") MessageBus messageBus) {
  if (messageBus != null) {
    messageBus.connect().subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener.Adapter() {
      @Override
      public void beforePsiChanged(boolean isPhysical) {
        clearCaches(isPhysical);
      }
    });
  }
}
项目:intellij-ce-playground    文件:PsiMigrationManager.java   
/**
 * Initiates a migrate refactoring. The refactoring is finished when
 * {@link com.intellij.psi.PsiMigration#finish()} is called.
 *
 * @return the migrate operation object.
 */
@NotNull
public PsiMigration startMigration() {
  LOG.assertTrue(myCurrentMigration == null);
  myCurrentMigration = new PsiMigrationImpl(this, JavaPsiFacade.getInstance(myProject),
                                            (PsiManagerImpl)PsiManager.getInstance(myProject));
  return myCurrentMigration;
}
项目:intellij-ce-playground    文件:ResolveScopeManagerImpl.java   
public ResolveScopeManagerImpl(Project project, ProjectRootManager projectRootManager, PsiManager psiManager) {
  myProject = project;
  myProjectRootManager = projectRootManager;
  myManager = psiManager;
  myAdditionalIndexableFileSet = new AdditionalIndexableFileSet(project);

  ((PsiManagerImpl) psiManager).registerRunnableToRunOnChange(new Runnable() {
    @Override
    public void run() {
      myDefaultResolveScopesCache.clear();
    }
  });

}
项目:intellij-ce-playground    文件:CodeInsightTestFixtureImpl.java   
private long collectAndCheckHighlighting(@NotNull ExpectedHighlightingData data) {
  final Project project = getProject();
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  PsiFileImpl file = (PsiFileImpl)getHostFile();
  FileElement hardRefToFileElement = file.calcTreeElement();//to load text

  //to initialize caches
  if (!DumbService.isDumb(project)) {
    CacheManager.SERVICE.getInstance(project).getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(project), true);
  }

  final long start = System.currentTimeMillis();
  final VirtualFileFilter fileTreeAccessFilter = myVirtualFileFilter;
  Disposable disposable = Disposer.newDisposable();
  if (fileTreeAccessFilter != null) {
    ((PsiManagerImpl)PsiManager.getInstance(project)).setAssertOnFileLoadingFilter(fileTreeAccessFilter, disposable);
  }

  //    ProfilingUtil.startCPUProfiling();
  List<HighlightInfo> infos;
  try {
    infos = doHighlighting();
    removeDuplicatedRangesForInjected(infos);
  }
  finally {
    Disposer.dispose(disposable);
  }
  //    ProfilingUtil.captureCPUSnapshot("testing");
  final long elapsed = System.currentTimeMillis() - start;

  data.checkResult(infos, file.getText());
  hardRefToFileElement.hashCode(); // use it so gc won't collect it
  return elapsed;
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTreeChangesUpdatesTest.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  // since we want to test PsiModificationTrackerImpl in isolation, we create a separate instance:
  // The existing PsiModificationTrackerImpl is affected by various components.
  myTracker = new PsiModificationTrackerImpl(getProject());
  ((PsiManagerImpl)PsiManager.getInstance(getProject())).addTreeChangePreprocessor(myTracker);
}
项目:intellij-ce-playground    文件:ResolveCache.java   
public ResolveCache(@NotNull MessageBus messageBus) {
  for (int i = 0; i < myMaps.length; i++) {
    myMaps[i] = createWeakMap();
  }
  messageBus.connect().subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener.Adapter() {
    @Override
    public void beforePsiChanged(boolean isPhysical) {
      clearCache(isPhysical);
    }
  });
}
项目:intellij-ce-playground    文件:DiffLog.java   
@Override
void doActualPsiChange(@NotNull PsiFile file, @NotNull ASTDiffBuilder astDiffBuilder) {
  PsiFileImpl fileImpl = (PsiFileImpl)file;
  final int oldLength = myOldNode.getTextLength();
  PsiManagerImpl manager = (PsiManagerImpl)fileImpl.getManager();
  BlockSupportImpl.sendBeforeChildrenChangeEvent(manager, fileImpl, false);
  if (myOldNode.getFirstChildNode() != null) myOldNode.rawRemoveAllChildren();
  final ASTNode firstChildNode = myNewNode.getFirstChildNode();
  if (firstChildNode != null) myOldNode.rawAddChildren((TreeElement)firstChildNode);
  fileImpl.getTreeElement().setCharTable(myNewNode.getCharTable());
  myOldNode.subtreeChanged();
  BlockSupportImpl.sendAfterChildrenChangedEvent(manager,fileImpl, oldLength, false);
}
项目:intellij-ce-playground    文件:BlockSupportImpl.java   
public static void sendBeforeChildrenChangeEvent(@NotNull PsiManagerImpl manager, @NotNull PsiElement scope, boolean isGenericChange) {
  if (!scope.isPhysical()) {
    manager.beforeChange(false);
    return;
  }
  PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(manager);
  event.setParent(scope);
  event.setFile(scope.getContainingFile());
  TextRange range = scope.getTextRange();
  event.setOffset(range == null ? 0 : range.getStartOffset());
  event.setOldLength(scope.getTextLength());
  // the "generic" event is being sent on every PSI change. It does not carry any specific info except the fact that "something has changed"
  event.setGenericChange(isGenericChange);
  manager.beforeChildrenChange(event);
}
项目:intellij-ce-playground    文件:PsiFileImplUtil.java   
public static void doDelete(@NotNull PsiFile file) throws IncorrectOperationException {
  final PsiManagerImpl manager = (PsiManagerImpl)file.getManager();

  final VirtualFile vFile = file.getVirtualFile();
  try{
    vFile.delete(manager);
  }
  catch(IOException e){
    throw new IncorrectOperationException(e);
  }
}
项目:intellij-ce-playground    文件:FileBasedIndexImpl.java   
@Override
public void registerIndexableSet(@NotNull IndexableFileSet set, @Nullable Project project) {
  myIndexableSets.add(set);
  myIndexableSetToProjectMap.put(set, project);
  if (project != null) {
    ((PsiManagerImpl)PsiManager.getInstance(project)).addTreeChangePreprocessor(new PsiTreeChangePreprocessor() {
      @Override
      public void treeChanged(@NotNull PsiTreeChangeEventImpl event) {
        if (event.isGenericChange() &&
            event.getCode() == PsiTreeChangeEventImpl.PsiEventType.CHILDREN_CHANGED) {
          PsiFile file = event.getFile();
          if (file != null) {
            VirtualFile virtualFile = file.getVirtualFile();
            if (!clearUpToDateStateForPsiIndicesOfUnsavedDocuments(virtualFile)) {
              // change in persistent file
              if (virtualFile instanceof VirtualFileWithId) {
                int fileId = ((VirtualFileWithId)virtualFile).getId();
                boolean wasIndexed = false;
                for (ID<?, ?> psiBackedIndex : myPsiDependentIndices) {
                  if (IndexingStamp.isFileIndexedStateCurrent(fileId, psiBackedIndex)) {
                    IndexingStamp.setFileIndexedStateOutdated(fileId, psiBackedIndex);
                    wasIndexed = true;
                  }
                }
                if (wasIndexed) {
                  myChangedFilesCollector.scheduleForUpdate(virtualFile);
                  IndexingStamp.flushCache(fileId);
                }
              }
            }
          }
        }
      }
    });
  }
}
项目:intellij-ce-playground    文件:DomStubUsingTest.java   
public void testFileLoading() throws Exception {
  XmlFile file = prepareFile("foo.xml");
  ((PsiManagerImpl)getPsiManager()).setAssertOnFileLoadingFilter(VirtualFileFilter.ALL, myTestRootDisposable);
  DomFileElement<Foo> element = DomManager.getDomManager(getProject()).getFileElement(file, Foo.class);
  assertNotNull(element);
  GenericDomValue<String> id = element.getRootElement().getId();
  assertEquals("foo", id.getValue());
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLPsiSearchHelper.java   
public JSGraphQLPsiSearchHelper(@NotNull final Project project) {
    myProject = project;
    searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.projectScope(myProject), FILE_TYPES);
    project.getMessageBus().connect().subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener.Adapter() {
        @Override
        public void beforePsiChanged(boolean isPhysical) {
            // clear the cache on each PSI change
            fragmentDefinitionsByName.clear();
        }
    });
}
项目:js-graphql-intellij-plugin    文件:JSGraphQLEndpointNamedTypeRegistry.java   
public JSGraphQLEndpointNamedTypeRegistry(Project project) {
    this.project = project;
    this.configurationProvider = JSGraphQLConfigurationProvider.getService(project);
    project.getMessageBus().connect().subscribe(PsiManagerImpl.ANY_PSI_CHANGE_TOPIC, new AnyPsiChangeListener.Adapter() {
        @Override
        public void beforePsiChanged(boolean isPhysical) {
            // clear the cache on each PSI change
            endpointTypesByName.clear();
            endpointEntryPsiFile.clear();
        }
    });
}
项目:tools-idea    文件:ClsFileImpl.java   
private ClsFileImpl(@NotNull PsiManagerImpl manager, @NotNull FileViewProvider viewProvider, boolean forDecompiling) {
  //noinspection ConstantConditions
  super(null);
  myManager = manager;
  myIsForDecompiling = forDecompiling;
  myViewProvider = viewProvider;
  JavaElementType.CLASS.getIndex();  // initialize Java stubs
}