com.intellij.openapi.extensions.ExtensionPointName Java Examples

The following examples show how to use com.intellij.openapi.extensions.ExtensionPointName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurableWrapper.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CompositeWrapper(ConfigurableEP ep, Configurable... kids) {
  super(ep);
  if (ep.dynamic) {
    kids = ((Composite)getConfigurable()).getConfigurables();
  }
  else if (ep.getChildren() != null) {
    kids = ContainerUtil.mapNotNull(ep.getChildren(), ep1 -> ep1.isAvailable() ? (ConfigurableWrapper)wrapConfigurable(ep1) : null, EMPTY_ARRAY);
  }
  if (ep.childrenEPName != null) {
    ExtensionPoint<Object> childrenEP = getProject(ep).getExtensionPoint(ExtensionPointName.create(ep.childrenEPName));
    Object[] extensions = childrenEP.getExtensions();
    if (extensions.length > 0) {
      if (extensions[0] instanceof ConfigurableEP) {
        Configurable[] children = ContainerUtil.mapNotNull(((ConfigurableEP<Configurable>[])extensions), CONFIGURABLE_FUNCTION, new Configurable[0]);
        kids = ArrayUtil.mergeArrays(kids, children);
      }
      else {
        kids = ArrayUtil.mergeArrays(kids, ((Composite)getConfigurable()).getConfigurables());
      }
    }
  }
  myKids = kids;
}
 
Example #2
Source File: BuildSystemExtensionPoint.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Get the bound instance of the given extension point that matches the given build system. Any
 * extension point that calls this is expected to provide one extension for each compatible build
 * system that the plugin supports. Failure to do so will result in an IllegalStateException.
 */
static <T extends BuildSystemExtensionPoint> T getInstance(
    ExtensionPointName<T> extensionPointName, BuildSystem buildSystem) {
  ImmutableSet<T> matching =
      Arrays.stream(extensionPointName.getExtensions())
          .filter(f -> f.getSupportedBuildSystems().contains(buildSystem))
          .collect(toImmutableSet());
  checkState(!matching.isEmpty(), "No %s for build system %s", extensionPointName, buildSystem);
  checkState(
      matching.size() == 1,
      "Multiple instances of %s for build system %s: %s",
      extensionPointName,
      buildSystem,
      matching);
  return matching.iterator().next();
}
 
Example #3
Source File: ExtensibleQueryFactory.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected ExtensibleQueryFactory(@NonNls final String epNamespace) {
  myPoint = new NotNullLazyValue<SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>>>() {
    @Override
    @Nonnull
    protected SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>> compute() {
      return new SimpleSmartExtensionPoint<QueryExecutor<Result, Parameters>>(new SmartList<QueryExecutor<Result, Parameters>>()){
        @Override
        @Nonnull
        protected ExtensionPoint<QueryExecutor<Result, Parameters>> getExtensionPoint() {
          String epName = ExtensibleQueryFactory.this.getClass().getName();
          int pos = epName.lastIndexOf('.');
          if (pos >= 0) {
            epName = epName.substring(pos+1);
          }
          epName = epNamespace + "." + StringUtil.decapitalize(epName);
          return Application.get().getExtensionPoint(ExtensionPointName.create(epName));
        }
      };
    }
  };
}
 
Example #4
Source File: BlazeRenderErrorContributorTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTest(Container applicationServices, Container projectServices) {
  super.initTest(applicationServices, projectServices);
  applicationServices.register(FileTypeManager.class, new MockFileTypeManager());

  projectServices.register(ProjectFileIndex.class, mock(ProjectFileIndex.class));
  projectServices.register(BuildReferenceManager.class, new MockBuildReferenceManager(project));
  projectServices.register(TransitiveDependencyMap.class, new TransitiveDependencyMap(project));
  projectServices.register(ProjectScopeBuilder.class, new ProjectScopeBuilderImpl(project));
  projectServices.register(
      AndroidResourceModuleRegistry.class, new AndroidResourceModuleRegistry());

  ExtensionPointImpl<Provider> kindProvider =
      registerExtensionPoint(Kind.Provider.EP_NAME, Kind.Provider.class);
  kindProvider.registerExtension(new AndroidBlazeRules());
  applicationServices.register(Kind.ApplicationState.class, new Kind.ApplicationState());

  BlazeImportSettingsManager importSettingsManager = new BlazeImportSettingsManager(project);
  BlazeImportSettings settings = new BlazeImportSettings("", "", "", "", BuildSystem.Blaze);
  importSettingsManager.setImportSettings(settings);
  projectServices.register(BlazeImportSettingsManager.class, importSettingsManager);

  projectServices.register(JvmPsiConversionHelper.class, new JvmPsiConversionHelperImpl());
  createPsiClassesAndSourceToTargetMap(projectServices);

  projectDataManager = new MockBlazeProjectDataManager();
  projectServices.register(BlazeProjectDataManager.class, projectDataManager);

  ExtensionPoint<RenderErrorContributor.Provider> extensionPoint =
      registerExtensionPoint(
          ExtensionPointName.create("com.android.rendering.renderErrorContributor"),
          RenderErrorContributor.Provider.class);
  extensionPoint.registerExtension(new RenderErrorContributor.Provider());
  extensionPoint.registerExtension(new BlazeRenderErrorContributor.BlazeProvider());

  module = new MockModule(project, () -> {});

  // For the isApplicable tests.
  provider = new BlazeRenderErrorContributor.BlazeProvider();
}
 
Example #5
Source File: ServiceBean.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@SuppressWarnings("unchecked")
public static <T> List<T> loadServicesFromBeans(final ExtensionPointName<ServiceBean> epName, Class<T> componentClass) {
  final List<ServiceBean> exportableBeans = epName.getExtensionList();
  final List<T> components = new ArrayList<>(exportableBeans.size());
  for (ServiceBean exportableBean : exportableBeans) {
    final String serviceClass = exportableBean.serviceInterface;
    if (serviceClass == null) {
      LOG.error("Service interface not specified in " + epName);
      continue;
    }
    try {
      final Class<?> aClass = Class.forName(serviceClass, true, exportableBean.getPluginDescriptor().getPluginClassLoader());
      final Object service = ServiceManager.getService(aClass);
      if (service == null) {
        LOG.error("Can't find service: " + serviceClass);
        continue;
      }
      if (!componentClass.isInstance(service)) {
        LOG.error("Service " + serviceClass + " is registered in " + epName.getName() + " EP, but doesn't implement " + componentClass.getName());
        continue;
      }

      components.add((T)service);
    }
    catch (ClassNotFoundException e) {
      LOG.error(e);
    }
  }
  return components;
}
 
Example #6
Source File: DumbService.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <T> List<T> getDumbAwareExtensions(@Nonnull Project project, @Nonnull ExtensionPointName<T> extensionPoint) {
  List<T> list = extensionPoint.getExtensionList();
  if (list.isEmpty()) {
    return list;
  }

  DumbService dumbService = getInstance(project);
  return dumbService.filterByDumbAwareness(list);
}
 
Example #7
Source File: MixinExtension.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static <T> T getInstance(ExtensionPointName<MixinEP<T>> name, Object key) {
  final List<MixinEP<T>> eps = name.getExtensionList();
  for(MixinEP<T> ep: eps) {
    if (ep.getKey().isInstance(key)) {
      return ep.getInstance();
    }
  }
  return null;
}
 
Example #8
Source File: BuildSystemExtensionPoint.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Get all the bound instances of the given extension point that match the given build system. */
static <T extends BuildSystemExtensionPoint> ImmutableList<T> getInstances(
    ExtensionPointName<T> extensionPointName, BuildSystem buildSystem) {
  return Arrays.stream(extensionPointName.getExtensions())
      .filter(f -> f.getSupportedBuildSystems().contains(buildSystem))
      .collect(toImmutableList());
}
 
Example #9
Source File: ServiceHelper.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static <T> void registerExtensionPoint(
    ExtensionPointName<T> name, Class<T> clazz, Disposable parentDisposable) {
  ExtensionsArea area = Extensions.getRootArea();
  String epName = name.getName();
  area.registerExtensionPoint(epName, clazz.getName());
  Disposer.register(parentDisposable, () -> area.unregisterExtensionPoint(epName));
}
 
Example #10
Source File: ConfigurableWrapper.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static <T extends UnnamedConfigurable> List<T> createConfigurables(ExtensionPointName<? extends ConfigurableEP<T>> name) {
  return ContainerUtil.mapNotNull(name.getExtensionList(), ConfigurableWrapper::wrapConfigurable);
}
 
Example #11
Source File: KeyedExtensionFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public KeyedExtensionFactory(@Nonnull Class<T> interfaceClass, @Nonnull ExtensionPointName<KeyedFactoryEPBean> epName, @Nonnull InjectingContainerOwner owner) {
  myInterfaceClass = interfaceClass;
  myEpName = epName;
  myInjectingContainerOwner = owner;
}
 
Example #12
Source File: BlazeIntegrationTestCase.java    From intellij with Apache License 2.0 4 votes vote down vote up
protected <T> void registerExtension(ExtensionPointName<T> name, T instance) {
  ServiceHelper.registerExtension(name, instance, getTestRootDisposable());
}
 
Example #13
Source File: ComponentManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Deprecated
default <T> T[] getExtensions(@Nonnull ExtensionPointName<T> extensionPointName) {
  return getExtensionPoint(extensionPointName).getExtensions();
}
 
Example #14
Source File: ComponentManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
default <T> List<T> getExtensionList(@Nonnull ExtensionPointName<T> extensionPointName) {
  return getExtensionPoint(extensionPointName).getExtensionList();
}
 
Example #15
Source File: ComponentManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
default <T> ExtensionPoint<T> getExtensionPoint(@Nonnull ExtensionPointName<T> extensionPointName) {
  throw new UnsupportedOperationException();
}
 
Example #16
Source File: ComponentManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
default <T, K extends T> K findExtension(@Nonnull ExtensionPointName<T> extensionPointName, @Nonnull Class<K> extensionClass) {
  return getExtensionPoint(extensionPointName).findExtension(extensionClass);
}
 
Example #17
Source File: BaseApplication.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected ExtensionPointName<ServiceDescriptor> getServiceExtensionPointName() {
  return APP_SERVICES;
}
 
Example #18
Source File: ProjectImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected ExtensionPointName<ServiceDescriptor> getServiceExtensionPointName() {
  return PROJECT_SERVICES;
}
 
Example #19
Source File: IntellijRule.java    From intellij with Apache License 2.0 4 votes vote down vote up
public <T> void registerExtensionPoint(ExtensionPointName<T> name, Class<T> type) {
  ServiceHelper.registerExtensionPoint(name, type, testDisposable);
}
 
Example #20
Source File: EnvironmentVariablesProviderUtil.java    From idea-php-dotenv-plugin with MIT License 4 votes vote down vote up
private static <T> T[] getExtensions(@NotNull String name) {
    ExtensionPointName<T> pointName = new ExtensionPointName<>(name);

    return Extensions.getRootArea().getExtensionPoint(pointName).getExtensions();
}
 
Example #21
Source File: ModuleImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected ExtensionPointName<ServiceDescriptor> getServiceExtensionPointName() {
  return MODULE_SERVICES;
}
 
Example #22
Source File: RunConfigurationExtensionsManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public RunConfigurationExtensionsManager(ExtensionPointName<T> extensionPointName) {
  myExtensionPointName = extensionPointName;
}
 
Example #23
Source File: ExtensionsAreaImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@SuppressWarnings({"unchecked"})
public <T> ExtensionPoint<T> getExtensionPoint(@Nonnull ExtensionPointName<T> extensionPointName) {
  return getExtensionPoint(extensionPointName.getName());
}
 
Example #24
Source File: ComponentManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void loadServices(List<Class> notLazyServices, InjectingContainerBuilder builder) {
  ExtensionPointName<ServiceDescriptor> ep = getServiceExtensionPointName();
  if (ep != null) {
    ExtensionPointImpl<ServiceDescriptor> extensionPoint = (ExtensionPointImpl<ServiceDescriptor>)myExtensionsArea.getExtensionPoint(ep);
    // there no injector at that level - build it via hardcode
    List<Pair<ServiceDescriptor, PluginDescriptor>> descriptorList = extensionPoint.buildUnsafe(aClass -> new ServiceDescriptor());
    // and cache it
    extensionPoint.setExtensionCache(descriptorList);

    for (ServiceDescriptor descriptor : extensionPoint.getExtensionList()) {
      InjectingKey<Object> key = InjectingKey.of(descriptor.getInterface(), getTargetClassLoader(descriptor.getPluginDescriptor()));
      InjectingKey<Object> implKey = InjectingKey.of(descriptor.getImplementation(), getTargetClassLoader(descriptor.getPluginDescriptor()));

      InjectingPoint<Object> point = builder.bind(key);
      // bind to impl class
      point.to(implKey);
      // require singleton
      point.forceSingleton();
      // remap object initialization
      point.factory(objectProvider -> runServiceInitialize(descriptor, objectProvider::get));

      point.injectListener((time, instance) -> {

        if (myChecker.containsKey(key.getTargetClass())) {
          throw new IllegalArgumentException("Duplicate init of " + key.getTargetClass());
        }
        myChecker.put(key.getTargetClass(), instance);

        if (instance instanceof Disposable) {
          Disposer.register(this, (Disposable)instance);
        }

        initializeIfStorableComponent(instance, true, descriptor.isLazy());
      });

      if (!descriptor.isLazy()) {
        // if service is not lazy - add it for init at start
        notLazyServices.add(key.getTargetClass());
      }
    }
  }
}
 
Example #25
Source File: ComponentManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
protected ExtensionPointName<ServiceDescriptor> getServiceExtensionPointName() {
  return null;
}
 
Example #26
Source File: ComponentManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public <T> ExtensionPoint<T> getExtensionPoint(@Nonnull ExtensionPointName<T> extensionPointName) {
  return myExtensionsArea.getExtensionPoint(extensionPointName);
}
 
Example #27
Source File: CoreApplicationEnvironment.java    From consulo with Apache License 2.0 4 votes vote down vote up
public <T> void addExtension(@Nonnull ExtensionPointName<T> name, @Nonnull final T extension) {
}
 
Example #28
Source File: CoreApplicationEnvironment.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static <T> void registerApplicationExtensionPoint(@Nonnull ExtensionPointName<T> extensionPointName, @Nonnull Class<? extends T> aClass) {
}
 
Example #29
Source File: CoreProjectEnvironment.java    From consulo with Apache License 2.0 4 votes vote down vote up
public <T> void registerProjectExtensionPoint(final ExtensionPointName<T> extensionPointName, final Class<? extends T> aClass) {
}
 
Example #30
Source File: KeyedExtensionCollector.java    From consulo with Apache License 2.0 4 votes vote down vote up
public KeyedExtensionCollector(@Nonnull ExtensionPointName<? extends KeyedLazyInstance<T>> epName) {
  myEPName = epName;
}