Пример #1
0
 @SuppressWarnings("unchecked")
 public static <T> T overrideService(
     @NotNull Project project, Class<? super T> serviceInterface, Class<T> serviceImplementation) {
   String key = serviceInterface.getName();
   MutablePicoContainer picoContainer = (MutablePicoContainer) project.getPicoContainer();
   picoContainer.unregisterComponent(key);
   picoContainer.registerComponentImplementation(key, serviceImplementation);
   return (T) ServiceManager.getService(project, serviceInterface);
 }
  public CoreModule(
      @NotNull Disposable parentDisposable, @NotNull Project project, String moduleFilePath) {
    super(project.getPicoContainer(), parentDisposable);
    myLifetime = parentDisposable;
    myProject = project;
    myPath = moduleFilePath;

    Extensions.instantiateArea(ExtensionAreas.IDEA_MODULE, this, null);
    CoreApplicationEnvironment.registerExtensionPoint(
        Extensions.getArea(this), ModuleExtension.EP_NAME, ModuleExtension.class);
    Disposer.register(
        parentDisposable,
        new Disposable() {
          @Override
          public void dispose() {
            Extensions.disposeArea(CoreModule.this);
          }
        });
    initModuleExtensions();

    final ModuleRootManagerImpl moduleRootManager =
        new ModuleRootManagerImpl(
            this,
            ProjectRootManagerImpl.getInstanceImpl(project),
            VirtualFilePointerManager.getInstance()) {
          @Override
          public void loadState(ModuleRootManagerState object) {
            loadState(object, false);
          }
        };
    Disposer.register(
        parentDisposable,
        new Disposable() {
          @Override
          public void dispose() {
            moduleRootManager.disposeComponent();
          }
        });
    getPicoContainer().registerComponentInstance(ModuleRootManager.class, moduleRootManager);
    getPicoContainer()
        .registerComponentInstance(
            PathMacroManager.class, new ModulePathMacroManager(PathMacros.getInstance(), this));
    getPicoContainer()
        .registerComponentInstance(
            ModuleFileIndex.class,
            new ModuleFileIndexImpl(this, DirectoryIndex.getInstance(project)));
    myModuleScopeProvider = createModuleScopeProvider();
  }
 private Object newClassInstance(final Project project, final String className) {
   try {
     final Class<?> aClass =
         Class.forName(
             className,
             true,
             myPluginDescriptor == null
                 ? getClass().getClassLoader()
                 : myPluginDescriptor.getPluginClassLoader());
     return new ConstructorInjectionComponentAdapter(className, aClass)
         .getComponentInstance(project.getPicoContainer());
   } catch (Exception e) {
     LOG.error(e);
     return null;
   }
 }
 @Nullable
 public FindUsagesHandler getNewFindUsagesHandler(
     @NotNull PsiElement element, final boolean forHighlightUsages) {
   for (FindUsagesHandlerFactory factory :
       Extensions.getExtensions(FindUsagesHandlerFactory.EP_NAME, myProject)) {
     if (factory.canFindUsages(element)) {
       Class<? extends FindUsagesHandlerFactory> aClass = factory.getClass();
       FindUsagesHandlerFactory copy =
           (FindUsagesHandlerFactory)
               new ConstructorInjectionComponentAdapter(aClass.getName(), aClass)
                   .getComponentInstance(myProject.getPicoContainer());
       final FindUsagesHandler handler = copy.createFindUsagesHandler(element, forHighlightUsages);
       if (handler == FindUsagesHandler.NULL_HANDLER) return null;
       if (handler != null) {
         return handler;
       }
     }
   }
   return null;
 }
 @Nullable
 public DomExtensionsRegistrarImpl extend(
     @NotNull final Project project,
     @NotNull final DomInvocationHandler handler,
     @Nullable DomExtensionsRegistrarImpl registrar) {
   if (myExtender == null) {
     try {
       myDomClass = findClass(domClassName);
       myExtender = instantiate(extenderClassName, project.getPicoContainer());
     } catch (Exception e) {
       LOG.error(e);
       return null;
     }
   }
   if (myDomClass.isAssignableFrom(handler.getRawType())) {
     if (!myExtender.supportsStubs() && XmlUtil.isStubBuilding()) return registrar;
     if (registrar == null) {
       registrar = new DomExtensionsRegistrarImpl();
     }
     //noinspection unchecked
     myExtender.registerExtensions(handler.getProxy(), registrar);
   }
   return registrar;
 }