Java 类com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl 实例源码

项目:GravSupport    文件:SystemSettingsToolWindowFactory.java   
private SmartPsiElementPointer<YAMLFile> getSystemFile(@NotNull Project project) {
    String prefix = "";
    try {
        prefix = GravProjectSettings.getInstance(project).withSrcDirectory ? "src/" + "" : "";
    } catch (NullPointerException ignored) {
    }

    String path = prefix + SYSTEM_SYSTEM_CONFIG_FILE;
    VirtualFile systemFile = project.getBaseDir().findFileByRelativePath(path);
    if (systemFile != null) {
        PsiFile psiFile = PsiManager.getInstance(project).findFile(systemFile);
        if (psiFile != null && psiFile instanceof YAMLFile) {
            systemYamlFile = SmartPointerManagerImpl.getInstance(project).createSmartPsiElementPointer((YAMLFile) psiFile);
            return systemYamlFile;
        }
    }
    return null;
}
项目:GravSupport    文件:SystemSettingsToolWindowFactory.java   
private void refreshComponents(boolean addListener) {
    Project firstProject = ProjectChecker.getFirstOpenedProject();
    if (firstProject == null) return;
    systemYamlFile = getSystemFile(firstProject);
    if (systemYamlFile != null && systemYamlFile.getElement() != null && systemYamlFile.getElement().getDocuments().size() > 0) {
        systemDocument = SmartPointerManagerImpl.getInstance(firstProject)
                .createSmartPsiElementPointer(systemYamlFile.getElement().getDocuments().get(0), systemYamlFile.getElement());
    }

    for (Triple<String[], Class, JComponent> each : componentList) {
        applyGravSettings(each.getFirst(), each.getSecond(), each.getThird(), firstProject, addListener);
    }
}
项目:GravSupport    文件:SystemSettingsToolWindowFactory.java   
@Override
public boolean shouldBeAvailable(@NotNull Project project) {
    systemYamlFile = null;
    boolean pluginEnabled = GravProjectComponent.isEnabled(project);
    generator = YAMLElementGenerator.getInstance(project);
    if (pluginEnabled) {
        systemYamlFile = getSystemFile(project);
        if (systemYamlFile != null && systemYamlFile.getElement() != null && systemYamlFile.getElement().getDocuments().size() > 0) {
            PsiManager.getInstance(project).addPsiTreeChangeListener(this);
            systemDocument = SmartPointerManagerImpl.getInstance(project).createSmartPsiElementPointer(systemYamlFile.getElement().getDocuments().get(0), systemYamlFile.getElement());
        }
    }
    return pluginEnabled && systemYamlFile != null && systemDocument != null;
}
项目:intellij-ce-playground    文件:PomModelImpl.java   
private void startTransaction(@NotNull PomTransaction transaction) {
  final ProgressIndicator progressIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
  if(progressIndicator != null) progressIndicator.startNonCancelableSection();
  final PsiDocumentManagerBase manager = (PsiDocumentManagerBase)PsiDocumentManager.getInstance(myProject);
  final PsiToDocumentSynchronizer synchronizer = manager.getSynchronizer();
  final PsiElement changeScope = transaction.getChangeScope();
  LOG.assertTrue(changeScope != null);

  final PsiFile containingFileByTree = getContainingFileByTree(changeScope);
  boolean physical = changeScope.isPhysical();
  if (physical && synchronizer.toProcessPsiEvent() && isDocumentUncommitted(containingFileByTree)) {
    // fail-fast to prevent any psi modifications that would cause psi/document text mismatch
    // PsiToDocumentSynchronizer assertions happen inside event processing and are logged by PsiManagerImpl.fireEvent instead of being rethrown
    // so it's important to throw something outside event processing
    throw new IllegalStateException("Attempt to modify PSI for non-committed Document!");
  }

  if (containingFileByTree != null) {
    ((SmartPointerManagerImpl) SmartPointerManager.getInstance(myProject)).fastenBelts(containingFileByTree.getViewProvider().getVirtualFile());
  }

  BlockSupportImpl.sendBeforeChildrenChangeEvent((PsiManagerImpl)PsiManager.getInstance(myProject), changeScope, true);
  Document document = containingFileByTree == null ? null : 
                      physical ? manager.getDocument(containingFileByTree) : 
                      manager.getCachedDocument(containingFileByTree);
  if(document != null) {
    synchronizer.startTransaction(myProject, document, changeScope);
  }
}
项目:intellij-ce-playground    文件:CoreProjectEnvironment.java   
public CoreProjectEnvironment(@NotNull Disposable parentDisposable, @NotNull CoreApplicationEnvironment applicationEnvironment) {
  myParentDisposable = parentDisposable;
  myEnvironment = applicationEnvironment;
  myProject = createProject(myEnvironment.getApplication().getPicoContainer(), myParentDisposable);

  preregisterServices();

  myFileIndexFacade = createFileIndexFacade();
  myMessageBus = MessageBusFactory.newMessageBus("CoreProjectEnvironment");

  PsiModificationTrackerImpl modificationTracker = new PsiModificationTrackerImpl(myProject);
  myProject.registerService(PsiModificationTracker.class, modificationTracker);
  myProject.registerService(FileIndexFacade.class, myFileIndexFacade);
  myProject.registerService(ResolveCache.class, new ResolveCache(myMessageBus));

  myPsiManager = new PsiManagerImpl(myProject, null, null, myFileIndexFacade, myMessageBus, modificationTracker);
  ((FileManagerImpl) myPsiManager.getFileManager()).markInitialized();
  registerProjectComponent(PsiManager.class, myPsiManager);
  myProject.registerService(SmartPointerManager.class, SmartPointerManagerImpl.class);
  registerProjectComponent(PsiDocumentManager.class, new CorePsiDocumentManager(myProject, myPsiManager,
                                                                                myMessageBus,
                                                                                new MockDocumentCommitProcessor()));

  myProject.registerService(ResolveScopeManager.class, createResolveScopeManager(myPsiManager));

  myProject.registerService(PsiFileFactory.class, new PsiFileFactoryImpl(myPsiManager));
  myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager)));
  myProject.registerService(PsiDirectoryFactory.class, new PsiDirectoryFactoryImpl(myPsiManager));
  myProject.registerService(ProjectScopeBuilder.class, createProjectScopeBuilder());
  myProject.registerService(DumbService.class, new MockDumbService(myProject));
  myProject.registerService(CoreEncodingProjectManager.class, CoreEncodingProjectManager.class);
}
项目:tools-idea    文件:PsiDocumentManagerBase.java   
public PsiDocumentManagerBase(@NotNull final Project project,
                              @NotNull PsiManager psiManager,
                              @NotNull SmartPointerManager smartPointerManager,
                              @NotNull MessageBus bus,
                              @NonNls @NotNull final DocumentCommitProcessor documentCommitProcessor) {
  myProject = project;
  myPsiManager = psiManager;
  myDocumentCommitProcessor = documentCommitProcessor;
  mySmartPointerManager = (SmartPointerManagerImpl)smartPointerManager;
  mySynchronizer = new PsiToDocumentSynchronizer(this, bus);
  myPsiManager.addPsiTreeChangeListener(mySynchronizer);
}
项目:consulo    文件:InjectionRegistrarImpl.java   
@Nonnull
private static ShredImpl createShred(@Nonnull PlaceInfo info, @Nonnull StringBuilder outChars, @Nonnull PsiFile hostPsiFile) {
  decode(info, outChars);

  TextRange relevantRange = info.rangeInHostElement;

  TextRange hostTextRange = info.host.getTextRange();
  TextRange relevantRangeInHostFile = relevantRange.shiftRight(hostTextRange.getStartOffset());
  SmartPointerManagerImpl manager = (SmartPointerManagerImpl)SmartPointerManager.getInstance(hostPsiFile.getProject());
  return new ShredImpl(manager.createSmartPsiFileRangePointer(hostPsiFile, relevantRangeInHostFile, true), manager.createSmartPsiElementPointer(info.host, hostPsiFile, true), info.prefix,
                       info.suffix, info.rangeInDecodedPSI, false, info.myEscaper.isOneLine());
}
项目:consulo    文件:ShredImpl.java   
@Nonnull
ShredImpl withRange(@Nonnull TextRange rangeInDecodedPSI, @Nonnull TextRange rangeInHostElementPSI, @Nonnull PsiLanguageInjectionHost newHost) {
  SmartPsiFileRange rangeMarker = relevantRangeInHost;
  Segment oldRangeInHostElementPSI = calcRangeInsideHostElement(false);
  SmartPointerManager pointerManager = SmartPointerManager.getInstance(rangeMarker.getProject());
  SmartPsiElementPointer<PsiLanguageInjectionHost> newHostPointer = pointerManager.createSmartPsiElementPointer(newHost);

  if (!rangeInHostElementPSI.equals(TextRange.create(oldRangeInHostElementPSI))) {
    Segment hostElementRange = newHostPointer.getRange();
    rangeMarker =
            ((SmartPointerManagerImpl)pointerManager).createSmartPsiFileRangePointer(rangeMarker.getContainingFile(), rangeInHostElementPSI.shiftRight(hostElementRange.getStartOffset()), true);
  }
  return new ShredImpl(rangeMarker, newHostPointer, prefix, suffix, rangeInDecodedPSI, usePsiRange, isOneLine);
}
项目:intellij-ce-playground    文件:PsiDocumentManagerBase.java   
private SmartPointerManagerImpl getSmartPointerManager() {
  return (SmartPointerManagerImpl)SmartPointerManager.getInstance(myProject);
}
项目:consulo    文件:PomModelImpl.java   
private void startTransaction(@Nonnull PomTransaction transaction) {
  final ProgressIndicator progressIndicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
  if(progressIndicator != null) progressIndicator.startNonCancelableSection();
  final PsiDocumentManagerBase manager = (PsiDocumentManagerBase)PsiDocumentManager.getInstance(myProject);
  final PsiToDocumentSynchronizer synchronizer = manager.getSynchronizer();
  final PsiElement changeScope = transaction.getChangeScope();

  final PsiFile containingFileByTree = getContainingFileByTree(changeScope);
  if (containingFileByTree != null && !(containingFileByTree instanceof DummyHolder) && !manager.isCommitInProgress()) {
    PsiUtilCore.ensureValid(containingFileByTree);
  }

  boolean physical = changeScope.isPhysical();
  if (synchronizer.toProcessPsiEvent()) {
    // fail-fast to prevent any psi modifications that would cause psi/document text mismatch
    // PsiToDocumentSynchronizer assertions happen inside event processing and are logged by PsiManagerImpl.fireEvent instead of being rethrown
    // so it's important to throw something outside event processing
    if (isDocumentUncommitted(containingFileByTree)) {
      throw new IllegalStateException("Attempt to modify PSI for non-committed Document!");
    }
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    if (physical && !commandProcessor.isUndoTransparentActionInProgress() && commandProcessor.getCurrentCommand() == null) {
      throw new IncorrectOperationException("Must not change PSI outside command or undo-transparent action. See com.intellij.openapi.command.WriteCommandAction or com.intellij.openapi.command.CommandProcessor");
    }
  }

  if (containingFileByTree != null) {
    ((SmartPointerManagerImpl) SmartPointerManager.getInstance(myProject)).fastenBelts(containingFileByTree.getViewProvider().getVirtualFile());
    if (containingFileByTree instanceof PsiFileImpl) {
      ((PsiFileImpl)containingFileByTree).beforeAstChange();
    }
  }

  BlockSupportImpl.sendBeforeChildrenChangeEvent((PsiManagerImpl)PsiManager.getInstance(myProject), changeScope, true);
  Document document = containingFileByTree == null ? null :
                      physical ? manager.getDocument(containingFileByTree) :
                      manager.getCachedDocument(containingFileByTree);
  if(document != null) {
    synchronizer.startTransaction(myProject, document, changeScope);
  }
}
项目:consulo    文件:PsiDocumentManagerBase.java   
private SmartPointerManagerImpl getSmartPointerManager() {
  return (SmartPointerManagerImpl)SmartPointerManager.getInstance(myProject);
}