use of org.jetbrains.idea.devkit.dom.Extension in project intellij-community by JetBrains.
the class RegisterInspectionFix method doFix.
private void doFix(final DomFileElement<IdeaPlugin> selectedValue, final Project project, final PsiFile file) {
Extension extension = new WriteCommandAction<Extension>(project, file) {
@Override
protected void run(@NotNull Result<Extension> result) throws Throwable {
final Extensions extensions = PluginDescriptorChooser.findOrCreateExtensionsForEP(selectedValue, myEp.getName());
Extension extension = extensions.addExtension(myEp.getName());
XmlTag tag = extension.getXmlTag();
tag.setAttribute("implementationClass", myPsiClass.getQualifiedName());
result.setResult(extension);
}
}.execute().throwException().getResultObject();
PsiNavigateUtil.navigate(extension.getXmlTag());
}
use of org.jetbrains.idea.devkit.dom.Extension in project intellij-community by JetBrains.
the class ExtensionsImpl method addExtension.
@Override
public Extension addExtension(String qualifiedEPName) {
Extension extension = addExtension();
XmlTag tag = extension.getXmlTag();
tag.setName(StringUtil.trimStart(qualifiedEPName, getEpPrefix()));
return extension;
}
use of org.jetbrains.idea.devkit.dom.Extension in project intellij-community by JetBrains.
the class InspectionDescriptionInfo method doFindExtension.
@Nullable
private static Extension doFindExtension(Module module, PsiClass psiClass) {
// Try search in narrow scopes first
Project project = module.getProject();
Set<DomFileElement<IdeaPlugin>> processed = new HashSet<>();
for (GlobalSearchScope scope : DescriptionCheckerUtil.searchScopes(module)) {
List<DomFileElement<IdeaPlugin>> origElements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, scope);
origElements.removeAll(processed);
List<DomFileElement<IdeaPlugin>> elements = PluginDescriptorChooser.findAppropriateIntelliJModule(module.getName(), origElements);
Query<PsiReference> query = ReferencesSearch.search(psiClass, new LocalSearchScope(elements.stream().map(DomFileElement::getFile).toArray(PsiElement[]::new)));
Ref<Extension> result = Ref.create(null);
query.forEach(ref -> {
PsiElement element = ref.getElement();
if (element instanceof XmlAttributeValue) {
PsiElement parent = element.getParent();
if (parent instanceof XmlAttribute && "implementationClass".equals(((XmlAttribute) parent).getName())) {
DomElement domElement = DomUtil.getDomElement(parent.getParent());
if (domElement instanceof Extension) {
Extension extension = (Extension) domElement;
ExtensionPoint extensionPoint = extension.getExtensionPoint();
if (extensionPoint != null && InheritanceUtil.isInheritor(extensionPoint.getBeanClass().getValue(), InspectionEP.class.getName())) {
result.set(extension);
return false;
}
}
}
}
return true;
});
Extension extension = result.get();
if (extension != null)
return extension;
processed.addAll(origElements);
}
return null;
}
Aggregations