com.intellij.openapi.extensions.ExtensionPoint Java Examples

The following examples show how to use com.intellij.openapi.extensions.ExtensionPoint. 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: ExtensionsAreaImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void registerExtension(@Nonnull final PluginDescriptor pluginDescriptor, @Nonnull ExtensionInfo extensionInfo) {
  final PluginId pluginId = pluginDescriptor.getPluginId();

  String epName = extractEPName(extensionInfo);

  SimpleXmlElement element = extensionInfo.getElement();

  ExtensionComponentAdapter adapter;
  final ExtensionPointImpl extensionPoint = getExtensionPoint(epName);
  if (extensionPoint.getKind() == ExtensionPoint.Kind.INTERFACE) {
    String implClass = element.getAttributeValue("implementation");
    if (implClass == null) {
      throw new RuntimeException("'implementation' attribute not specified for '" + epName + "' extension in '" + pluginId.getIdString() + "' plugin");
    }
    adapter = new ExtensionComponentAdapter(implClass, mapElement(element), pluginDescriptor, shouldDeserializeInstance(element));
  }
  else {
    adapter = new ExtensionComponentAdapter(extensionPoint.getClassName(), mapElement(element), pluginDescriptor, true);
  }
  extensionPoint.registerExtensionAdapter(adapter);
}
 
Example #2
Source File: BlazeSyncManagerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
protected void initTest(Container applicationServices, Container projectServices) {
  super.initTest(applicationServices, projectServices);
  manager = new BlazeSyncManager(project);
  MockitoAnnotations.initMocks(this);
  applicationServices.register(BlazeUserSettings.class, new BlazeUserSettings());
  applicationServices.register(ExperimentService.class, new MockExperimentService());

  projectServices.register(
      BlazeImportSettingsManager.class, new BlazeImportSettingsManager(project));
  projectServices.register(ProjectViewManager.class, new MockProjectViewManager());
  ExtensionPoint<BuildSystemProvider> ep =
      registerExtensionPoint(BuildSystemProvider.EP_NAME, BuildSystemProvider.class);
  ep.registerExtension(new BazelBuildSystemProvider());

  doNothing().when(manager).requestProjectSync(any());
  projectServices.register(BlazeSyncManager.class, manager);
  assertThat(BlazeSyncManager.getInstance(project)).isSameAs(manager);
}
 
Example #3
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 #4
Source File: BlazeCompilerSettingsTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
protected void initTest(Container applicationServices, Container projectServices) {
  ExtensionPoint<BuildSystemProvider> extensionPoint =
      registerExtensionPoint(BuildSystemProvider.EP_NAME, BuildSystemProvider.class);
  extensionPoint.registerExtension(new BazelBuildSystemProvider());

  ExtensionPointImpl<BlazeCompilerFlagsProcessor.Provider> ep =
      registerExtensionPoint(
          BlazeCompilerFlagsProcessor.EP_NAME, BlazeCompilerFlagsProcessor.Provider.class);
  ep.registerExtension(new IncludeRootFlagsProcessor.Provider());
  ep.registerExtension(new SysrootFlagsProcessor.Provider());

  BlazeImportSettingsManager importSettingsManager = new BlazeImportSettingsManager(project);
  BlazeImportSettings importSettings =
      new BlazeImportSettings("/root", "", "", "", BuildSystem.Bazel);
  importSettingsManager.setImportSettings(importSettings);
  projectServices.register(BlazeImportSettingsManager.class, importSettingsManager);

  workspaceRoot = WorkspaceRoot.fromImportSettings(importSettings);
  blazeProjectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).build();
  projectServices.register(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(blazeProjectData));
}
 
Example #5
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 #6
Source File: ScalaSourceDirectoryCalculatorTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
protected void initTest(Container applicationServices, Container projectServices) {
  super.initTest(applicationServices, projectServices);

  mockInputStreamProvider = new MockInputStreamProvider();
  applicationServices.register(InputStreamProvider.class, mockInputStreamProvider);
  applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader());
  applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
  applicationServices.register(PrefetchService.class, new MockPrefetchService());
  applicationServices.register(FileOperationProvider.class, new FileOperationProvider());
  applicationServices.register(
      RemoteArtifactPrefetcher.class, new MockRemoteArtifactPrefetcher());

  ExtensionPoint<JavaLikeLanguage> javaLikeLanguages =
      registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class);
  javaLikeLanguages.registerExtension(new JavaLikeLanguage.Java());
  javaLikeLanguages.registerExtension(new ScalaJavaLikeLanguage());

  context.addOutputSink(IssueOutput.class, issues);
  sourceDirectoryCalculator = new SourceDirectoryCalculator();
}
 
Example #7
Source File: UsageGroupingRuleProviderOverride.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void initComponent() {
  // remove UsageGroupingRuleProviderImpl from the list of EPs, effectively replacing it with
  // this class
  ExtensionPoint<UsageGroupingRuleProvider> ep =
      Extensions.getRootArea().getExtensionPoint(UsageGroupingRuleProvider.EP_NAME);
  ep.unregisterExtension(UsageGroupingRuleProviderImpl.class);
}
 
Example #8
Source File: XDebuggerTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void initApplication() throws Exception {
  super.initApplication();
  final ExtensionPoint<XBreakpointType> point = getBreakpointTypes();
 // point.registerExtension(MY_LINE_BREAKPOINT_TYPE);
 // point.registerExtension(MY_SIMPLE_BREAKPOINT_TYPE);
}
 
Example #9
Source File: ExtensionsAreaImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void registerExtensionPoint(@Nonnull String extensionPointName, @Nonnull String extensionPointBeanClass, @Nonnull PluginDescriptor descriptor, @Nonnull ExtensionPoint.Kind kind) {
  if (hasExtensionPoint(extensionPointName)) {
    if (DEBUG_REGISTRATION) {
      final ExtensionPointImpl oldEP = getExtensionPoint(extensionPointName);
      LOG.error("Duplicate registration for EP: " + extensionPointName + ": original plugin " + oldEP.getDescriptor().getPluginId() + ", new plugin " + descriptor.getPluginId(),
                myEPTraces.get(extensionPointName));
    }
    throw new RuntimeException("Duplicate registration for EP: " + extensionPointName);
  }

  registerExtensionPoint(new ExtensionPointImpl(extensionPointName, extensionPointBeanClass, kind, myAreaInstance, descriptor));
}
 
Example #10
Source File: ExtensionsAreaImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void registerExtensionPoint(@Nonnull PluginDescriptor pluginDescriptor, @Nonnull SimpleXmlElement extensionPointElement) {
  final String pluginId = pluginDescriptor.getPluginId().getIdString();
  String epName = extensionPointElement.getAttributeValue("qualifiedName");
  if (epName == null) {
    final String name = extensionPointElement.getAttributeValue("name");
    if (name == null) {
      throw new RuntimeException("'name' attribute not specified for extension point in '" + pluginId + "' plugin");
    }
    epName = pluginId + '.' + name;
  }
  else {
    LOG.warn("Using 'qualifiedName' which is deprecated. " + extensionPointElement + ". PluginId: " + pluginId);
  }

  String beanClassName = extensionPointElement.getAttributeValue("beanClass");
  String interfaceClassName = extensionPointElement.getAttributeValue("interface");
  if (beanClassName == null && interfaceClassName == null) {
    throw new RuntimeException("Neither 'beanClass' nor 'interface' attribute is specified for extension point '" + epName + "' in '" + pluginId + "' plugin");
  }
  if (beanClassName != null && interfaceClassName != null) {
    throw new RuntimeException("Both 'beanClass' and 'interface' attributes are specified for extension point '" + epName + "' in '" + pluginId + "' plugin");
  }

  ExtensionPoint.Kind kind;
  String className;
  if (interfaceClassName != null) {
    className = interfaceClassName;
    kind = ExtensionPoint.Kind.INTERFACE;
  }
  else {
    className = beanClassName;
    kind = ExtensionPoint.Kind.BEAN_CLASS;
  }
  registerExtensionPoint(epName, className, pluginDescriptor, kind);
}
 
Example #11
Source File: UsageNodeTreeBuilderTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private GroupNode buildUsageTree(int[] indices, UsageGroupingRule[] rules) {
  Usage[] usages = new Usage[indices.length];
  for (int i = 0; i < usages.length; i++) {
    usages[i] = createUsage(indices[i]);
  }

  UsageViewPresentation presentation = new UsageViewPresentation();
  presentation.setUsagesString("searching for mock usages");

  ExtensionPoint<UsageGroupingRuleProvider> point = Application.get().getExtensionPoint(UsageGroupingRuleProvider.EP_NAME);
  UsageGroupingRuleProvider provider = new UsageGroupingRuleProvider() {
    @Nonnull
    @Override
    public UsageGroupingRule[] getActiveRules(Project project) {
      return rules;
    }

    @Nonnull
    @Override
    public AnAction[] createGroupingActions(UsageView view) {
      return AnAction.EMPTY_ARRAY;
    }
  };
 // point.registerExtension(provider);
  try {
    UsageViewImpl usageView = new UsageViewImpl(getProject(), presentation, UsageTarget.EMPTY_ARRAY, null);
    Disposer.register(getTestRootDisposable(), usageView);
    for (Usage usage : usages) {
      usageView.appendUsage(usage);
    }
    UIUtil.dispatchAllInvocationEvents();

    return usageView.getRoot();
  }
  finally {
   // point.unregisterExtension(provider);
  }
}
 
Example #12
Source File: ServiceHelper.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Unregister all extensions of the given class, for the given extension point. */
public static <T> void unregisterLanguageExtensionPoint(
    String extensionPointKey, Class<T> clazz, Disposable parentDisposable) {
  ExtensionPoint<LanguageExtensionPoint<T>> ep =
      Extensions.getRootArea().getExtensionPoint(extensionPointKey);
  LanguageExtensionPoint<T>[] existingExtensions = ep.getExtensions();
  for (LanguageExtensionPoint<T> ext : existingExtensions) {
    if (clazz.getName().equals(ext.implementationClass)) {
      ep.unregisterExtension(ext);
      Disposer.register(parentDisposable, () -> ep.registerExtension(ext));
    }
  }
}
 
Example #13
Source File: PyDynamicImportResolverInitializer.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static void registerImportCandidateProviders() {
  ExtensionPoint<PyImportCandidateProvider> ep =
      Extensions.getRootArea().getExtensionPoint(PyImportCandidateProvider.EP_NAME);

  for (PyImportResolverStrategy provider : PyImportResolverStrategy.EP_NAME.getExtensions()) {
    ep.registerExtension(
        (reference, name, quickFix) -> {
          if (!providerEnabled(reference.getElement().getProject(), provider)) {
            return;
          }
          provider.addImportCandidates(reference, name, quickFix);
        });
  }
}
 
Example #14
Source File: DelegatingSwitchToHeaderOrSourceProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void initComponent() {
  ExtensionPoint<GotoRelatedProvider> ep =
      Extensions.getRootArea().getExtensionPoint(GotoRelatedProvider.EP_NAME);
  for (GotoRelatedProvider provider : ep.getExtensions()) {
    if (provider.getClass().equals(OCSwitchToHeaderOrSourceRelatedProvider.class)) {
      ep.unregisterExtension(provider);
    }
  }
}
 
Example #15
Source File: CMakeNotificationFilter.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static void overrideProjectExtension(Project project) {
  ExtensionPoint<EditorNotifications.Provider> ep =
      Extensions.getArea(project).getExtensionPoint(EDITOR_NOTIFICATIONS_EPNAME);
  for (EditorNotifications.Provider<?> editorNotificationsProvider : ep.getExtensions()) {
    if (editorNotificationsProvider instanceof CMakeNotificationProvider) {
      ep.unregisterExtension(editorNotificationsProvider);
    }
  }
  ep.registerExtension(new CMakeNotificationFilter(project));
}
 
Example #16
Source File: ExecutionRootPathResolverTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
protected void initTest(Container applicationServices, Container projectServices) {
  ExtensionPoint<BuildSystemProvider> extensionPoint =
      registerExtensionPoint(BuildSystemProvider.EP_NAME, BuildSystemProvider.class);
  extensionPoint.registerExtension(new BazelBuildSystemProvider());

  pathResolver =
      new ExecutionRootPathResolver(
          BuildSystem.Bazel,
          WORKSPACE_ROOT,
          new File(EXECUTION_ROOT),
          new WorkspacePathResolverImpl(WORKSPACE_ROOT));
}
 
Example #17
Source File: BuildTargetFinderTest.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(FileOperationProvider.class, fileOperationProvider);
  applicationServices.register(ExperimentService.class, new MockExperimentService());
  projectServices.register(
      BlazeImportSettingsManager.class, mock(BlazeImportSettingsManager.class));
  ExtensionPoint<BuildSystemProvider> extensionPoint =
      registerExtensionPoint(BuildSystemProvider.EP_NAME, BuildSystemProvider.class);
  extensionPoint.registerExtension(new BazelBuildSystemProvider());
}
 
Example #18
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 #19
Source File: LightExtensionRegistrator.java    From consulo with 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 File: ServiceHelper.java    From intellij with 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 #21
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 #22
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 #23
Source File: ExtensionsAreaImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public ExtensionPoint[] getExtensionPoints() {
  return myExtensionPoints.values().toArray(new ExtensionPoint[myExtensionPoints.size()]);
}
 
Example #24
Source File: ComponentManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public ExtensionPoint[] getExtensionPoints() {
  return myExtensionsArea.getExtensionPoints();
}
 
Example #25
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 #26
Source File: XDebuggerTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static ExtensionPoint<XBreakpointType> getBreakpointTypes() {
  return Application.get().getExtensionPoint(XBreakpointType.EXTENSION_POINT_NAME);
}