Search in sources :

Example 6 with Extension

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());
}
Also used : Extension(org.jetbrains.idea.devkit.dom.Extension) Extensions(org.jetbrains.idea.devkit.dom.Extensions) XmlTag(com.intellij.psi.xml.XmlTag)

Example 7 with Extension

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;
}
Also used : Extension(org.jetbrains.idea.devkit.dom.Extension) XmlTag(com.intellij.psi.xml.XmlTag)

Example 8 with 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;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) DomFileElement(com.intellij.util.xml.DomFileElement) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Extension(org.jetbrains.idea.devkit.dom.Extension) Project(com.intellij.openapi.project.Project) DomElement(com.intellij.util.xml.DomElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Extension (org.jetbrains.idea.devkit.dom.Extension)8 XmlTag (com.intellij.psi.xml.XmlTag)5 DomElement (com.intellij.util.xml.DomElement)3 ExtensionPoint (org.jetbrains.idea.devkit.dom.ExtensionPoint)3 Project (com.intellij.openapi.project.Project)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 XmlAttribute (com.intellij.psi.xml.XmlAttribute)2 Extensions (org.jetbrains.idea.devkit.dom.Extensions)2 PsiElement (com.intellij.psi.PsiElement)1 XmlElementVisitor (com.intellij.psi.XmlElementVisitor)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 PsiNonJavaFileReferenceProcessor (com.intellij.psi.search.PsiNonJavaFileReferenceProcessor)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlToken (com.intellij.psi.xml.XmlToken)1 DomFileElement (com.intellij.util.xml.DomFileElement)1 HashSet (java.util.HashSet)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1