Declare inspection extension after startup

Hello, I'm looking at adding some API-specific inspections to Android Studio. Studio already has many inspections, and many projects won't even use the API's I'm working on, so I'm curious if I can lazily add these inspections only after I've detected the developer is using these API's.

I didn't see a way to do this in the extensions docs I found, but it seems like there may be a way to programmatically instantiate the extension. There may also be better approaches, such as declaring these inspections enabledByDefault="false" and then programmatically enabling them once we detect the user is using these API's.

1 comment
Comment actions Permalink
public <T> void addProjectExtension(final ExtensionPointName<T> name, final T extension) {
  final ExtensionPoint<T> extensionPoint = Extensions.getArea(myProject).getExtensionPoint(name);
  extensionPoint.registerExtension(extension);
  Disposer.register(myParentDisposable, new Disposable() {
    @Override
    public void dispose() {
      extensionPoint.unregisterExtension(extension);
    }
  });
}

Or:

public <T> void addExtension(ExtensionPointName<T> name, final T extension) {
  final ExtensionPoint<T> extensionPoint = Extensions.getRootArea().getExtensionPoint(name);
  extensionPoint.registerExtension(extension);
  Disposer.register(myParentDisposable, new Disposable() {
    @Override
    public void dispose() {
      extensionPoint.unregisterExtension(extension);
    }
  });
}

 

 

0

Please sign in to leave a comment.