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

项目:intellij-ce-playground    文件:TreeViewUtil.java   
private static boolean shouldAbbreviateName(PsiPackage aPackage) {
  final Project project = aPackage.getProject();
  ConcurrentMap<PsiPackage, Boolean> map = project.getUserData(SHOULD_ABBREV_PACK_KEY);
  if (map == null) {
    final ConcurrentMap<PsiPackage, Boolean> newMap = ContainerUtil.createConcurrentWeakMap();
    map = ((UserDataHolderEx)project).putUserDataIfAbsent(SHOULD_ABBREV_PACK_KEY, newMap);
    if (map == newMap) {
      ((PsiManagerEx)PsiManager.getInstance(project)).registerRunnableToRunOnChange(new Runnable() {
        @Override
        public void run() {
          newMap.clear();
        }
      });
    }
  }

  Boolean ret = map.get(aPackage);
  if (ret != null) return ret;
  ret = scanPackages(aPackage, 1);
  map.put(aPackage, ret);
  return ret;
}
项目:intellij-ce-playground    文件:HighlightStressTest.java   
public void testAllTheseConcurrentThreadsDoNotCrashAnything() throws Exception {
  long time = System.currentTimeMillis();
  for (int i = 0; i < 20/*00000*/; i++) {
    //System.out.println("i = " + i);
    getPsiManager().dropResolveCaches();
    ((PsiManagerEx)getPsiManager()).getFileManager().cleanupForNextTest();
    DaemonCodeAnalyzer.getInstance(getProject()).restart();

    configureFromFileText("Stress.java", text);
    List<HighlightInfo> infos = doHighlighting();
    assertEmpty(DaemonAnalyzerTestCase.filter(infos, HighlightSeverity.ERROR));
    UIUtil.dispatchAllInvocationEvents();
    FileEditorManagerEx.getInstanceEx(getProject()).closeAllFiles();
  }
  System.out.println(System.currentTimeMillis() - time+"ms");
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTest.java   
public void testClassShouldNotDisappearWithoutEvents_NoDocument() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());

  final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();

  // gc softly-referenced file and document
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));

  VfsUtil.saveText(file, "");
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));

  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTest.java   
public void testClassShouldNotDisappearWithoutEvents_VirtualFileDeleted() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());

  final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();

  // gc softly-referenced file and document
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));
  file.delete(this);

  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTest.java   
public void testClassShouldNotDisappearWithoutEvents_ParentVirtualDirectoryDeleted() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());

  final VirtualFile file = myFixture.addFileToProject("foo/Foo.java", "package foo; class Foo {}").getVirtualFile();
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();

  // gc softly-referenced file and document
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  assertNull(FileDocumentManager.getInstance().getCachedDocument(file));
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));
  file.getParent().delete(this);

  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count1 == tracker.getJavaStructureModificationCount());
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTest.java   
public void testVirtualFileRename_WithPsi() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());
  GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());

  final VirtualFile file = myFixture.addFileToProject("foo/Foo.java", "package foo; class Foo {}").getVirtualFile();
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", scope));
  long count1 = tracker.getModificationCount();
  long hc = psiManager.findFile(file).hashCode();
  long stamp1 = psiManager.findFile(file).getModificationStamp();

  file.rename(this, "Bar.java");

  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", scope));
  assertTrue(count1 != tracker.getModificationCount());
  assertTrue(stamp1 != psiManager.findFile(file).getModificationStamp());
  assertEquals(hc, psiManager.findFile(file).hashCode());
}
项目:intellij-ce-playground    文件:PsiErrorElementUtil.java   
public static boolean hasErrors(@NotNull final Project project, @NotNull final VirtualFile virtualFile) {
  if (project.isDisposed() || !virtualFile.isValid()) {
    return false;
  }
  return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
    @Override
    public Boolean compute() {
      if (project.isDisposed()) {
        return false;
      }
      PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(project);
      PsiFile psiFile = psiManager.getFileManager().findFile(virtualFile);
      return psiFile != null && hasErrors(psiFile);
    }
  });
}
项目:intellij-ce-playground    文件:TreeElement.java   
public PsiManagerEx getManager() {
  Project project = ProjectCoreUtil.theOnlyOpenProject();
  if (project != null) {
    return (PsiManagerEx)PsiManager.getInstance(project);
  }
  TreeElement element;
  for (element = this; element.getTreeParent() != null; element = element.getTreeParent()) {
  }

  if (element instanceof FileElement) { //TODO!!
    return element.getManager();
  }
  else {
    if (getTreeParent() != null) {
      return getTreeParent().getManager();
    }
    return null;
  }
}
项目:intellij-ce-playground    文件:DiffLog.java   
@Override
void doActualPsiChange(@NotNull PsiFile file, @NotNull ASTDiffBuilder astDiffBuilder) {
  ASTNode child = myOldNode;
  ASTNode parent = myOldParent;

  PsiElement psiParent = parent.getPsi();
  PsiElement psiChild = file.isPhysical() ? child.getPsi() : null;

  if (psiParent != null && psiChild != null) {
    PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(file.getManager());
    event.setParent(psiParent);
    event.setChild(psiChild);
    event.setFile(file);
    ((PsiManagerEx)file.getManager()).beforeChildRemoval(event);
  }

  astDiffBuilder.nodeDeleted(parent, child);

  ((TreeElement)child).rawRemove();
  ((CompositeElement)parent).subtreeChanged();

  DebugUtil.checkTreeStructure(parent);
}
项目:intellij-ce-playground    文件:PushedFilePropertiesUpdaterImpl.java   
private static void reloadPsi(final VirtualFile file, final Project project) {
  final FileManagerImpl fileManager = (FileManagerImpl)((PsiManagerEx)PsiManager.getInstance(project)).getFileManager();
  if (fileManager.findCachedViewProvider(file) != null) {
    UIUtil.invokeLaterIfNeeded(new Runnable() {
      @Override
      public void run() {
        if (project.isDisposed()) {
          return;
        }
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            fileManager.forceReload(file);
          }
        });
      }
    });
  }
}
项目:intellij-ce-playground    文件:GrDocMethodParamsImpl.java   
@Override
public PsiType[] getParameterTypes() {
  ArrayList<PsiType> types = new ArrayList<PsiType>();
  PsiManagerEx manager = getManager();
  GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
  PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
  for (GrDocMethodParameter parameter : getParameters()) {
    GrDocReferenceElement typeElement = parameter.getTypeElement();
    try {
      PsiType type = factory.createTypeFromText(typeElement.getText(), this);
      type = TypesUtil.boxPrimitiveType(type, manager, scope);
      types.add(type);
    } catch (IncorrectOperationException e) {
      LOG.info(e);
      types.add(null);
    }
  }
  return types.toArray(PsiType.createArray(types.size()));
}
项目:intellij-ce-playground    文件:GrThrowsClauseImpl.java   
@Override
@NotNull
public PsiJavaCodeReferenceElement[] getReferenceElements() {
  PsiClassType[] types = getReferencedTypes();
  if (types.length == 0) return PsiJavaCodeReferenceElement.EMPTY_ARRAY;

  PsiManagerEx manager = getManager();

  List<PsiJavaCodeReferenceElement> result = ContainerUtil.newArrayList();
  for (PsiClassType type : types) {
    PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
    PsiClass resolved = resolveResult.getElement();
    if (resolved != null) {
      result.add(new LightClassReference(manager, type.getCanonicalText(), resolved, resolveResult.getSubstitutor()));
    }
  }
  return result.toArray(new PsiJavaCodeReferenceElement[result.size()]);
}
项目:intellij    文件:GlobFindUsagesTest.java   
@Test
public void testInMemoryFileHandledGracefully() {
  createBuildFile(new WorkspacePath("java/com/google/BUILD"), "glob(['**/*.java'])");

  LightVirtualFile inMemoryFile =
      new LightVirtualFile("mockProjectViewFile", ProjectViewLanguage.INSTANCE, "");

  FileManager fileManager =
      ((PsiManagerEx) PsiManager.getInstance(getProject())).getFileManager();
  fileManager.setViewProvider(
      inMemoryFile, fileManager.createFileViewProvider(inMemoryFile, true));

  PsiFile psiFile = fileManager.findFile(inMemoryFile);

  FindUsages.findAllReferences(psiFile);
}
项目:intellij    文件:StubOCWorkspaceManager.java   
private static void enableLanguageSupport(Project project) {
  OCLanguage.LANGUAGE_SUPPORT_DISABLED.set(project, false);
  UIUtil.invokeLaterIfNeeded(
      () ->
          ApplicationManager.getApplication()
              .runWriteAction(
                  () -> {
                    if (project.isDisposed()) {
                      return;
                    }
                    Language langToReset = PlainTextLanguage.INSTANCE;
                    FileManager fileManager =
                        ((PsiManagerEx) PsiManager.getInstance(project)).getFileManager();
                    for (PsiFile file : fileManager.getAllCachedFiles()) {
                      if (file.getLanguage() == langToReset) {
                        VirtualFile vf = OCInclusionContextUtil.getVirtualFile(file);
                        if (vf != null) {
                          fileManager.setViewProvider(vf, 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    文件:PsiJavaCodeReferenceElementImpl.java   
@Override
@NotNull
public JavaResolveResult[] multiResolve(final boolean incompleteCode) {
  FileElement fileElement = SharedImplUtil.findFileElement(this);
  if (fileElement == null) {
    LOG.error("fileElement == null!");
    return JavaResolveResult.EMPTY_ARRAY;
  }
  final PsiManagerEx manager = fileElement.getManager();
  if (manager == null) {
    LOG.error("getManager() == null!");
    return JavaResolveResult.EMPTY_ARRAY;
  }
  PsiFile file = SharedImplUtil.getContainingFile(fileElement);
  boolean valid = file != null && file.isValid();
  if (!valid) {
    LOG.error("invalid!");
    return JavaResolveResult.EMPTY_ARRAY;
  }
  Project project = manager.getProject();

  final ResolveCache resolveCache = ResolveCache.getInstance(project);
  final ResolveResult[] results = resolveCache.resolveWithCaching(this, OurGenericsResolver.INSTANCE, true, incompleteCode, file);
  return results.length == 0 ? JavaResolveResult.EMPTY_ARRAY : (JavaResolveResult[])results;
}
项目:tools-idea    文件:PsiReferenceExpressionImpl.java   
@Override
@NotNull
public JavaResolveResult[] multiResolve(boolean incompleteCode) {
  FileElement fileElement = SharedImplUtil.findFileElement(this);
  if (fileElement == null) {
    LOG.error("fileElement == null!");
    return JavaResolveResult.EMPTY_ARRAY;
  }
  final PsiManagerEx manager = fileElement.getManager();
  if (manager == null) {
    LOG.error("getManager() == null!");
    return JavaResolveResult.EMPTY_ARRAY;
  }
  PsiFile file = SharedImplUtil.getContainingFile(fileElement);
  boolean valid = file != null && file.isValid();
  if (!valid) {
    LOG.error("invalid!");
    return JavaResolveResult.EMPTY_ARRAY;
  }
  Project project = manager.getProject();
  ResolveResult[] results = ResolveCache.getInstance(project).resolveWithCaching(this, OurGenericsResolver.INSTANCE, true, incompleteCode, file);
  return results.length == 0 ? JavaResolveResult.EMPTY_ARRAY : (JavaResolveResult[])results;
}
项目:tools-idea    文件:JavaFileManagerImpl.java   
public JavaFileManagerImpl(final PsiManagerEx manager, final ProjectRootManager projectRootManager, MessageBus bus,
                           final StartupManager startupManager) {
  super(manager, projectRootManager, bus);

  myConnection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
    @Override
    public void fileWithNoDocumentChanged(@NotNull final VirtualFile file) {
      clearNonRepositoryMaps();
    }
  });



  startupManager.registerStartupActivity(
    new Runnable() {
      @Override
      public void run() {
        initialize();
      }
    }
  );

}
项目:tools-idea    文件:TreeViewUtil.java   
private static boolean shouldAbbreviateName(PsiPackage aPackage) {
  final Project project = aPackage.getProject();
  ConcurrentMap<PsiPackage, Boolean> map = project.getUserData(SHOULD_ABBREV_PACK_KEY);
  if (map == null) {
    final ConcurrentWeakHashMap<PsiPackage, Boolean> newMap = new ConcurrentWeakHashMap<PsiPackage, Boolean>();
    map = ((UserDataHolderEx)project).putUserDataIfAbsent(SHOULD_ABBREV_PACK_KEY, newMap);
    if (map == newMap) {
      ((PsiManagerEx)PsiManager.getInstance(project)).registerRunnableToRunOnChange(new Runnable() {
        @Override
        public void run() {
          newMap.clear();
        }
      });
    }
  }

  Boolean ret = map.get(aPackage);
  if (ret != null) return ret;
  ret = scanPackages(aPackage, 1);
  map.put(aPackage, ret);
  return ret;
}
项目:tools-idea    文件: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();

    ((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().cleanupForNextTest();
  }

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

  LocalHistoryImpl.getInstanceImpl().cleanupForNextTest();

  PatchedWeakReference.clearAll();
}
项目:tools-idea    文件:DiffLog.java   
@Override
void doActualPsiChange(@NotNull PsiFile file, @NotNull ASTDiffBuilder astDiffBuilder) {
  ASTNode child = myOldNode;
  ASTNode parent = myOldParent;

  PsiElement psiParent = parent.getPsi();
  PsiElement psiChild = file.isPhysical() ? child.getPsi() : null;

  if (psiParent != null && psiChild != null) {
    PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(file.getManager());
    event.setParent(psiParent);
    event.setChild(psiChild);
    event.setFile(file);
    ((PsiManagerEx)file.getManager()).beforeChildRemoval(event);
  }

  astDiffBuilder.nodeDeleted(parent, child);

  ((TreeElement)child).rawRemove();
  ((CompositeElement)parent).subtreeChanged();

  DebugUtil.checkTreeStructure(parent);

}
项目:tools-idea    文件:GrDocMethodParamsImpl.java   
public PsiType[] getParameterTypes() {
  ArrayList<PsiType> types = new ArrayList<PsiType>();
  PsiManagerEx manager = getManager();
  GlobalSearchScope scope = GlobalSearchScope.allScope(getProject());
  PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
  for (GrDocMethodParameter parameter : getParameters()) {
    GrDocReferenceElement typeElement = parameter.getTypeElement();
    try {
      PsiType type = factory.createTypeFromText(typeElement.getText(), this);
      type = TypesUtil.boxPrimitiveType(type, manager, scope);
      types.add(type);
    } catch (IncorrectOperationException e) {
      LOG.info(e);
      types.add(null);
    }
  }
  return types.toArray(new PsiType[types.size()]);
}
项目:consulo    文件: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();

    ((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().cleanupForNextTest();
  }

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

  LocalHistory.getInstance().cleanupForNextTest();
}
项目:consulo    文件:ASTDelegatePsiElement.java   
@Override
public PsiManagerEx getManager() {
  Project project = ProjectCoreUtil.theOnlyOpenProject();
  if (project != null) {
    return PsiManagerEx.getInstanceEx(project);
  }
  PsiElement parent = this;

  while (parent instanceof ASTDelegatePsiElement) {
    parent = parent.getParent();
  }

  if (parent == null) {
    throw new PsiInvalidElementAccessException(this);
  }

  return (PsiManagerEx)parent.getManager();
}
项目:consulo    文件:TreeElement.java   
public PsiManagerEx getManager() {
  Project project = ProjectCoreUtil.theOnlyOpenProject();
  if (project != null) {
    return PsiManagerEx.getInstanceEx(project);
  }
  TreeElement element;
  for (element = this; element.getTreeParent() != null; element = element.getTreeParent()) {
  }

  if (element instanceof FileElement) { //TODO!!
    return element.getManager();
  }
  else {
    if (getTreeParent() != null) {
      return getTreeParent().getManager();
    }
    return null;
  }
}
项目:consulo    文件:PushedFilePropertiesUpdaterImpl.java   
private static void reloadPsi(final VirtualFile file, final Project project) {
  final FileManagerImpl fileManager = (FileManagerImpl)((PsiManagerEx)PsiManager.getInstance(project)).getFileManager();
  if (fileManager.findCachedViewProvider(file) != null) {
    Runnable runnable = new Runnable() {
      @Override
      public void run() {
        WriteAction.run(new ThrowableRunnable<RuntimeException>() {
          @Override
          public void run() throws RuntimeException {
            fileManager.forceReload(file);
          }
        });
      }
    };
    if (ApplicationManager.getApplication().isDispatchThread()) {
      runnable.run();
    } else {
      TransactionGuard.submitTransaction(project, runnable);
    }
  }
}
项目:consulo    文件:SemServiceImpl.java   
public SemServiceImpl(Project project, PsiManager psiManager) {
  myProject = project;
  final MessageBusConnection connection = project.getMessageBus().connect();
  connection.subscribe(PsiModificationTracker.TOPIC, new PsiModificationTracker.Listener() {
    @Override
    public void modificationCountChanged() {
      if (!isInsideAtomicChange()) {
        clearCache();
      }
    }
  });

  ((PsiManagerEx)psiManager).registerRunnableToRunOnChange(() -> {
    if (!isInsideAtomicChange()) {
      clearCache();
    }
  });


  LowMemoryWatcher.register(() -> {
    if (myCreatingSem.get() == 0) {
      clearCache();
    }
    //System.out.println("SemService cache flushed");
  }, project);
}
项目:consulo    文件:TreeViewUtil.java   
private static boolean shouldAbbreviateName(PsiPackage aPackage) {
  final Project project = aPackage.getProject();
  ConcurrentMap<PsiPackage, Boolean> map = project.getUserData(SHOULD_ABBREV_PACK_KEY);
  if (map == null) {
    final ConcurrentWeakHashMap<PsiPackage, Boolean> newMap = new ConcurrentWeakHashMap<PsiPackage, Boolean>();
    map = ((UserDataHolderEx)project).putUserDataIfAbsent(SHOULD_ABBREV_PACK_KEY, newMap);
    if (map == newMap) {
      ((PsiManagerEx)PsiManager.getInstance(project)).registerRunnableToRunOnChange(new Runnable() {
        @Override
        public void run() {
          newMap.clear();
        }
      });
    }
  }

  Boolean ret = map.get(aPackage);
  if (ret != null) return ret;
  ret = scanPackages(aPackage, 1);
  map.put(aPackage, ret);
  return ret;
}
项目:lua-for-idea    文件:LuaCodeFragment.java   
public LuaCodeFragment(Project project,
                           IElementType contentElementType,
                           boolean isPhysical,
                           @NonNls String name,
                           CharSequence text,
                           @Nullable PsiElement context) {
    super(TokenType.CODE_FRAGMENT,
            contentElementType,
            PsiManagerEx.getInstanceEx(project).getFileManager().createFileViewProvider(
                    new LightVirtualFile(name, FileTypeManager.getInstance().getFileTypeByFileName(name), text), isPhysical)
    );
    setContext(context);
    ((SingleRootFileViewProvider)getViewProvider()).forceCachedPsi(this);
}
项目:intellij-ce-playground    文件:JavaFileManagerImpl.java   
public JavaFileManagerImpl(Project project) {
  myManager = (PsiManagerEx)PsiManager.getInstance(project);
  myPackageIndex = PackageIndex.getInstance(myManager.getProject());
  project.getMessageBus().connect().subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
    @Override
    public void rootsChanged(final ModuleRootEvent event) {
      myNontrivialPackagePrefixes = null;
    }
  });
}
项目:intellij-ce-playground    文件:ControlFlowFactory.java   
public ControlFlowFactory(PsiManagerEx psiManager) {
  psiManager.registerRunnableToRunOnChange(new Runnable(){
    @Override
    public void run() {
      clearCache();
    }
  });
}
项目:intellij-ce-playground    文件:PsiLiteralExpressionImpl.java   
@Override
public PsiType getType() {
  final IElementType type = getLiteralElementType();
  if (type == JavaTokenType.INTEGER_LITERAL) {
    return PsiType.INT;
  }
  if (type == JavaTokenType.LONG_LITERAL) {
    return PsiType.LONG;
  }
  if (type == JavaTokenType.FLOAT_LITERAL) {
    return PsiType.FLOAT;
  }
  if (type == JavaTokenType.DOUBLE_LITERAL) {
    return PsiType.DOUBLE;
  }
  if (type == JavaTokenType.CHARACTER_LITERAL) {
    return PsiType.CHAR;
  }
  if (type == JavaTokenType.STRING_LITERAL) {
    PsiManagerEx manager = getManager();
    GlobalSearchScope resolveScope = ResolveScopeManager.getElementResolveScope(this);
    return PsiType.getJavaLangString(manager, resolveScope);
  }
  if (type == JavaTokenType.TRUE_KEYWORD || type == JavaTokenType.FALSE_KEYWORD) {
    return PsiType.BOOLEAN;
  }
  if (type == JavaTokenType.NULL_KEYWORD) {
    return PsiType.NULL;
  }
  return null;
}
项目:intellij-ce-playground    文件:PsiMigrationManager.java   
public void migrationModified(boolean terminated) {
  if (terminated) {
    myCurrentMigration = null;
  }

  ((PsiManagerEx)PsiManager.getInstance(myProject)).beforeChange(true);
}
项目:intellij-ce-playground    文件:PsiCodeFragmentImpl.java   
public PsiCodeFragmentImpl(Project project,
                           IElementType contentElementType,
                           boolean isPhysical,
                           @NonNls String name,
                           CharSequence text,
                           @Nullable PsiElement context) {
  super(TokenType.CODE_FRAGMENT,
        contentElementType,
        ((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().createFileViewProvider(
          new LightVirtualFile(name, FileTypeManager.getInstance().getFileTypeByFileName(name), text), isPhysical)
  );
  myContext = context;
  ((SingleRootFileViewProvider)getViewProvider()).forceCachedPsi(this);
  myPhysical = isPhysical;
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTest.java   
public void testClassShouldNotDisappearWithoutEvents() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  long count0 = tracker.getJavaStructureModificationCount();

  final VirtualFile file = myFixture.addFileToProject("Foo.java", "class Foo {}").getVirtualFile();
  final Document document = FileDocumentManager.getInstance().getDocument(file);
  assertNotNull(document);

  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  long count1 = tracker.getJavaStructureModificationCount();
  assertFalse(count1 == count0);

  document.deleteString(0, document.getTextLength());

  // gc softly-referenced file and AST
  PlatformTestUtil.tryGcSoftlyReachableObjects();
  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());
  assertNull(psiManager.getFileManager().getCachedPsiFile(file));

  assertEquals(count1, tracker.getJavaStructureModificationCount()); // no PSI changes yet
  //so the class should still be there
  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertSize(1, ((PsiJavaFile)psiManager.findFile(file)).getClasses());
  assertEquals("class Foo {}", psiManager.findFile(file).getText());
  PlatformTestUtil.tryGcSoftlyReachableObjects();

  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  assertFalse(count1 == tracker.getJavaStructureModificationCount());
  assertNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTest.java   
public void testClassShouldNotAppearWithoutEvents_NoPsiDirectory() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  long count0 = tracker.getJavaStructureModificationCount();

  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());
  VirtualFile parentDir = myFixture.getTempDirFixture().getFile("");
  assertNull(((FileManagerImpl)psiManager.getFileManager()).getCachedDirectory(parentDir));

  File file = new File(myFixture.getTempDirPath(), "Foo.java");
  FileUtil.writeToFile(file, "class Foo {}");
  assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file));

  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count0 == tracker.getJavaStructureModificationCount());
}
项目:intellij-ce-playground    文件:PsiModificationTrackerTest.java   
public void testClassShouldNotAppearWithoutEvents_NoPsiGrandParentDirectory() throws IOException {
  PsiModificationTracker tracker = PsiManager.getInstance(getProject()).getModificationTracker();
  long count0 = tracker.getJavaStructureModificationCount();

  final PsiManagerEx psiManager = (PsiManagerEx)PsiManager.getInstance(getProject());
  VirtualFile parentDir = myFixture.getTempDirFixture().getFile("");
  assertNull(((FileManagerImpl)psiManager.getFileManager()).getCachedDirectory(parentDir));

  File file = new File(myFixture.getTempDirPath() + "/foo", "Foo.java");
  FileUtil.writeToFile(file, "package foo; class Foo {}");
  assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file));

  assertNotNull(JavaPsiFacade.getInstance(getProject()).findClass("foo.Foo", GlobalSearchScope.allScope(getProject())));
  assertFalse(count0 == tracker.getJavaStructureModificationCount());
}
项目:intellij-ce-playground    文件:FileTypeChooser.java   
/**
 * If fileName is already associated any known file type returns it.
 * Otherwise asks user to select file type and associates it with fileName extension if any selected.
 * @return Known file type or null. Never returns {@link com.intellij.openapi.fileTypes.FileTypes#UNKNOWN}.
 */
@Nullable
public static FileType getKnownFileTypeOrAssociate(@NotNull VirtualFile file, @Nullable Project project) {
  if (project != null && !(file instanceof FakeVirtualFile)) {
    ((PsiManagerEx)PsiManager.getInstance(project)).getFileManager().findFile(file); // autodetect text file if needed
  }
  FileType type = file.getFileType();
  if (type == FileTypes.UNKNOWN) {
    type = getKnownFileTypeOrAssociate(file.getName());
  }
  return type;
}
项目:intellij-ce-playground    文件:FileTypesTest.java   
public void testAutoDetectTextFileFromContents() throws IOException {
  File dir = createTempDirectory();
  VirtualFile vDir = getVirtualFile(dir);
  VirtualFile vFile = createChildData(vDir, "test.xxxxxxxx");
  setFileText(vFile, "text");
  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();

  assertEquals(PlainTextFileType.INSTANCE, vFile.getFileType()); // type autodetected during indexing

  PsiFile psiFile = ((PsiManagerEx)PsiManager.getInstance(getProject())).getFileManager().findFile(vFile); // autodetect text file if needed
  assertNotNull(psiFile);
  assertEquals(PlainTextFileType.INSTANCE, psiFile.getFileType());
}
项目:intellij-ce-playground    文件:ASTDelegatePsiElement.java   
@Override
public PsiManagerEx getManager() {
  PsiElement parent = this;

  while (parent instanceof ASTDelegatePsiElement) {
    parent = parent.getParent();
  }

  if (parent == null) {
    throw new PsiInvalidElementAccessException(this);
  }

  return (PsiManagerEx)parent.getManager();
}