mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DevKit: add Extensions#getEpPrefix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,19 +26,24 @@ import org.jetbrains.idea.devkit.dom.impl.ExtensionNsConverter;
|
||||
import java.util.List;
|
||||
|
||||
public interface Extensions extends DomElement {
|
||||
|
||||
@NotNull
|
||||
@Attribute("defaultExtensionNs")
|
||||
@Convert(value=ExtensionNsConverter.class, soft=true)
|
||||
@Convert(value = ExtensionNsConverter.class, soft = true)
|
||||
@Stubbed
|
||||
GenericAttributeValue<IdeaPlugin> getDefaultExtensionNs();
|
||||
|
||||
@NotNull
|
||||
@Convert(value=ExtensionNsConverter.class, soft=true)
|
||||
@Convert(value = ExtensionNsConverter.class, soft = true)
|
||||
@Stubbed
|
||||
GenericAttributeValue<IdeaPlugin> getXmlns();
|
||||
|
||||
List<Extension> getExtensions();
|
||||
|
||||
Extension addExtension();
|
||||
|
||||
Extension addExtension(String name);
|
||||
|
||||
@NotNull
|
||||
String getEpPrefix();
|
||||
}
|
||||
|
||||
@@ -136,23 +136,17 @@ public class ExtensionDomExtender extends DomExtender<Extensions> {
|
||||
|
||||
if (ideaPlugin == null) return;
|
||||
|
||||
String prefix = getEpPrefix(extensions);
|
||||
String epPrefix = extensions.getEpPrefix();
|
||||
for (IdeaPlugin plugin : getVisiblePlugins(ideaPlugin)) {
|
||||
final String pluginId = StringUtil.notNullize(plugin.getPluginId(), "com.intellij");
|
||||
for (ExtensionPoints points : plugin.getExtensionPoints()) {
|
||||
for (ExtensionPoint point : points.getExtensionPoints()) {
|
||||
registerExtensionPoint(registrar, point, prefix, pluginId);
|
||||
registerExtensionPoint(registrar, point, epPrefix, pluginId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getEpPrefix(Extensions extensions) {
|
||||
String prefix = extensions.getDefaultExtensionNs().getStringValue();
|
||||
if (prefix == null) prefix = extensions.getXmlns().getStringValue();
|
||||
return prefix != null ? prefix + "." : "";
|
||||
}
|
||||
|
||||
private static Set<IdeaPlugin> getVisiblePlugins(IdeaPlugin ideaPlugin) {
|
||||
Set<IdeaPlugin> result = ContainerUtil.newHashSet();
|
||||
MultiMap<String, IdeaPlugin> byId = getPluginMap(ideaPlugin.getManager().getProject());
|
||||
@@ -184,15 +178,15 @@ public class ExtensionDomExtender extends DomExtender<Extensions> {
|
||||
|
||||
private static void registerExtensionPoint(final DomExtensionsRegistrar registrar,
|
||||
final ExtensionPoint extensionPoint,
|
||||
String prefix,
|
||||
String epPrefix,
|
||||
@Nullable String pluginId) {
|
||||
String epName = extensionPoint.getName().getStringValue();
|
||||
if (epName != null && StringUtil.isNotEmpty(pluginId)) epName = pluginId + "." + epName;
|
||||
if (epName == null) epName = extensionPoint.getQualifiedName().getStringValue();
|
||||
if (epName == null) return;
|
||||
if (!epName.startsWith(prefix)) return;
|
||||
if (!epName.startsWith(epPrefix)) return;
|
||||
|
||||
final DomExtension domExtension = registrar.registerCollectionChildrenExtension(new XmlName(epName.substring(prefix.length())), Extension.class);
|
||||
final DomExtension domExtension = registrar.registerCollectionChildrenExtension(new XmlName(epName.substring(epPrefix.length())), Extension.class);
|
||||
domExtension.setDeclaringElement(extensionPoint);
|
||||
domExtension.addExtender(EXTENSION_EXTENDER);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.devkit.dom.impl;
|
||||
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.devkit.dom.Extension;
|
||||
import org.jetbrains.idea.devkit.dom.Extensions;
|
||||
|
||||
@@ -32,4 +33,11 @@ public abstract class ExtensionsImpl implements Extensions {
|
||||
tag.setName(name.substring(getDefaultExtensionNs().getStringValue().length() + 1));
|
||||
return extension;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getEpPrefix() {
|
||||
String prefix = getDefaultExtensionNs().getStringValue();
|
||||
if (prefix == null) prefix = getXmlns().getStringValue();
|
||||
return prefix != null ? prefix + "." : "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user