Java Code Examples for com.intellij.openapi.extensions.ExtensionPointName

The following examples show how to use com.intellij.openapi.extensions.ExtensionPointName. These examples are extracted from open source projects. 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 Project: intellij   Source File: BuildSystemExtensionPoint.java    License: 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 2
Source Project: consulo   Source File: ExtensibleQueryFactory.java    License: 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 3
Source Project: consulo   Source File: ConfigurableWrapper.java    License: 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 4
Source Project: intellij   Source File: BlazeRenderErrorContributorTest.java    License: 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 Project: intellij   Source File: BuildSystemExtensionPoint.java    License: 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 6
Source Project: intellij   Source File: ServiceHelper.java    License: 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 7
Source Project: consulo   Source File: MixinExtension.java    License: 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 Project: consulo   Source File: DumbService.java    License: 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 9
Source Project: consulo   Source File: ServiceBean.java    License: 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 10
private static <T> T[] getExtensions(@NotNull String name) {
    ExtensionPointName<T> pointName = new ExtensionPointName<>(name);

    return Extensions.getRootArea().getExtensionPoint(pointName).getExtensions();
}
 
Example 11
Source Project: intellij   Source File: BlazeIntegrationTestCase.java    License: 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 12
Source Project: intellij   Source File: BlazeTestCase.java    License: Apache License 2.0 4 votes vote down vote up
protected <T> ExtensionPointImpl<T> registerExtensionPoint(
    ExtensionPointName<T> name, Class<T> type) {
  extensionsArea.registerExtensionPoint(name.getName(), type.getName());
  return extensionsArea.getExtensionPoint(name.getName());
}
 
Example 13
Source Project: intellij   Source File: ServiceHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> void registerExtension(
    ExtensionPointName<T> name, T instance, Disposable parentDisposable) {
  ExtensionPoint<T> ep = Extensions.getRootArea().getExtensionPoint(name);
  ep.registerExtension(instance);
  Disposer.register(parentDisposable, () -> ep.unregisterExtension(instance));
}
 
Example 14
Source Project: intellij   Source File: IntellijRule.java    License: 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 15
Source Project: intellij   Source File: IntellijRule.java    License: Apache License 2.0 4 votes vote down vote up
public <T> void registerExtension(ExtensionPointName<T> name, T instance) {
  ServiceHelper.registerExtension(name, instance, testDisposable);
}
 
Example 16
Source Project: aem-ide-tooling-4-intellij   Source File: MockProject.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public <T> T[] getExtensions(@NotNull ExtensionPointName<T> extensionPointName) {
    return null;
}
 
Example 17
Source Project: EclipseCodeFormatter   Source File: StringUtilsTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public <T> T[] getExtensions(final ExtensionPointName<T> extensionPointName) {
	throw new UnsupportedOperationException("getExtensions()");
}
 
Example 18
Source Project: consulo   Source File: LightExtensionRegistrator.java    License: Apache License 2.0 4 votes vote down vote up
protected <T> void registerExtension(ExtensionsAreaImpl area, ExtensionPointName<T> extensionPointName, T value) {
  ExtensionPointImpl<T> point = (ExtensionPointImpl<T>)area.getExtensionPoint(extensionPointName);
  point.registerExtensionAdapter(new SimpleInstanceComponentAdapter<>(value));
}
 
Example 19
Source Project: consulo   Source File: LightExtensionRegistrator.java    License: Apache License 2.0 4 votes vote down vote up
protected void registerExtensionPoint(ExtensionsAreaImpl area, ExtensionPointName<?> name, Class aClass) {
  ExtensionPoint.Kind kind = aClass.isInterface() || (aClass.getModifiers() & Modifier.ABSTRACT) != 0 ? ExtensionPoint.Kind.INTERFACE : ExtensionPoint.Kind.BEAN_CLASS;
  area.registerExtensionPoint(name.getName(), aClass.getName(), myDescriptor, kind);
}
 
Example 20
Source Project: consulo   Source File: UnknownExtension.java    License: Apache License 2.0 4 votes vote down vote up
public UnknownExtension(ExtensionPointName<?> pointName, String value) {
  this(pointName.getName(), value);
}
 
Example 21
Source Project: consulo   Source File: PsiTestExtensionUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> void registerExtension(final ExtensionPointName<T> name, final T t, final Disposable parentDisposable) {
}
 
Example 22
Source Project: consulo   Source File: PsiTestExtensionUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> void registerExtensionPointIfNeed(final ExtensionPointName<T> extensionPointName, final Class<T> aClass) {
}
 
Example 23
Source Project: consulo   Source File: PlatformLiteFixture.java    License: Apache License 2.0 4 votes vote down vote up
protected <T> void registerExtension(final ExtensionPointName<T> extensionPointName, @Nonnull final T t) {
}
 
Example 24
Source Project: consulo   Source File: PlatformLiteFixture.java    License: Apache License 2.0 4 votes vote down vote up
protected <T> void registerExtension(final ExtensionPointName<T> extensionPointName, @Nonnull final T t, @Nonnull LoadingOrder loadingOrder) {
}
 
Example 25
Source Project: consulo   Source File: PlatformLiteFixture.java    License: Apache License 2.0 4 votes vote down vote up
protected <T> void registerExtensionPoint(final ExtensionPointName<T> extensionPointName, final Class<T> aClass) {
}
 
Example 26
Source Project: consulo   Source File: CompositeExtensionPointName.java    License: Apache License 2.0 4 votes vote down vote up
public MyInvocationHandler(ExtensionPointName<T> name, List<T> extensions) {
  myName = name;
  myExtensions = extensions;
}
 
Example 27
Source Project: consulo   Source File: CompositeExtensionPointName.java    License: Apache License 2.0 4 votes vote down vote up
protected CompositeExtensionPointName(@Nonnull String name, @Nonnull Class<T> clazz) {
  myName = ExtensionPointName.create(name);
  myClazz = clazz;
}
 
Example 28
private ElementTypeEntryExtensionCollector(@Nonnull String epName) {
  myExtensionPointName = ExtensionPointName.create(epName);
}
 
Example 29
@Nonnull
public ExtensionPointName<E> getExtensionPointName() {
  return myExtensionPointName;
}
 
Example 30
Source Project: consulo   Source File: FileTypeExtensionFactory.java    License: Apache License 2.0 4 votes vote down vote up
public FileTypeExtensionFactory(@Nonnull final Class<T> interfaceClass, @NonNls @Nonnull final ExtensionPointName<KeyedFactoryEPBean> epName) {
  super(interfaceClass, epName, Application.get());
}