Search in sources :

Example 1 with ExtensionPoint

use of org.jetbrains.idea.devkit.dom.ExtensionPoint in project intellij-community by JetBrains.

the class InspectionMappingConsistencyInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
    return new XmlElementVisitor() {

        @Override
        public void visitXmlTag(XmlTag tag) {
            DomElement element = DomUtil.getDomElement(tag);
            if (element instanceof Extension) {
                ExtensionPoint extensionPoint = ((Extension) element).getExtensionPoint();
                if (extensionPoint != null && InheritanceUtil.isInheritor(extensionPoint.getBeanClass().getValue(), "com.intellij.codeInspection.InspectionEP")) {
                    boolean key = tag.getAttribute("key") != null;
                    boolean groupKey = tag.getAttribute("groupKey") != null;
                    if (key) {
                        if (tag.getAttribute("bundle") == null) {
                            checkDefaultBundle(element, holder);
                        }
                    } else if (tag.getAttribute("displayName") == null) {
                        registerProblem(element, holder, "displayName or key should be specified", "displayName", "key");
                    }
                    if (groupKey) {
                        if (tag.getAttribute("bundle") == null && tag.getAttribute("groupBundle") == null) {
                            checkDefaultBundle(element, holder);
                        }
                    } else if (tag.getAttribute("groupName") == null) {
                        registerProblem(element, holder, "groupName or groupKey should be specified", "groupName", "groupKey");
                    }
                }
            }
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) Extension(org.jetbrains.idea.devkit.dom.Extension) DomElement(com.intellij.util.xml.DomElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ExtensionPoint

use of org.jetbrains.idea.devkit.dom.ExtensionPoint in project intellij-community by JetBrains.

the class LanguageResolvingUtil method calculateAnyLanguageId.

private static String calculateAnyLanguageId(ConvertContext context) {
    final Extension extension = context.getInvocationElement().getParentOfType(Extension.class, true);
    if (extension == null) {
        return ANY_LANGUAGE_DEFAULT_ID;
    }
    final ExtensionPoint extensionPoint = extension.getExtensionPoint();
    if (extensionPoint == null) {
        return ANY_LANGUAGE_DEFAULT_ID;
    }
    final GenericAttributeValue<PsiClass> epBeanClass = extensionPoint.getBeanClass();
    if (EP_WITH_ANY_LANGUAGE_ID.contains(epBeanClass.getStringValue())) {
        return "any";
    }
    return ANY_LANGUAGE_DEFAULT_ID;
}
Also used : Extension(org.jetbrains.idea.devkit.dom.Extension) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint)

Example 3 with ExtensionPoint

use of org.jetbrains.idea.devkit.dom.ExtensionPoint in project intellij-community by JetBrains.

the class PluginFieldNameConverter method getEPBeanClass.

@Nullable
private static PsiClass getEPBeanClass(ConvertContext context) {
    ExtensionPoint ep = context.getInvocationElement().getParentOfType(ExtensionPoint.class, true);
    if (ep == null)
        return null;
    PsiClass value = ep.getBeanClass().getValue();
    if (value == null)
        return null;
    return value;
}
Also used : ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ExtensionPoint

use of org.jetbrains.idea.devkit.dom.ExtensionPoint 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)

Example 5 with ExtensionPoint

use of org.jetbrains.idea.devkit.dom.ExtensionPoint in project intellij-community by JetBrains.

the class AddWithTagFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    DomElement element = DomUtil.getDomElement(descriptor.getPsiElement());
    if (!(element instanceof ExtensionPoint)) {
        return;
    }
    ExtensionPoint extensionPoint = (ExtensionPoint) element;
    List<PsiField> fields = extensionPoint.collectMissingWithTags();
    PsiElement navTarget = null;
    for (PsiField field : fields) {
        With with = extensionPoint.addWith();
        String tagName = PluginFieldNameConverter.getAnnotationValue(field, Tag.class);
        if (tagName != null) {
            with.getTag().setStringValue(tagName);
        } else {
            String attributeName = PluginFieldNameConverter.getAttributeAnnotationValue(field);
            if (attributeName == null) {
                attributeName = field.getName();
            }
            if (attributeName.equals("forClass")) {
                continue;
            }
            with.getAttribute().setStringValue(attributeName);
        }
        String epName = extensionPoint.getName().getStringValue();
        String className = "";
        if (epName != null) {
            int pos = epName.lastIndexOf('.');
            epName = StringUtil.capitalize(pos >= 0 ? epName.substring(pos + 1) : epName);
            PsiClass[] classesByName = PsiShortNamesCache.getInstance(project).getClassesByName(epName, ProjectScope.getAllScope(project));
            if (classesByName.length == 1) {
                className = classesByName[0].getQualifiedName();
            }
        }
        with.getImplements().setStringValue(className);
        if (navTarget == null) {
            navTarget = with.getImplements().getXmlAttributeValue();
        }
    }
    if (navTarget != null) {
        PsiNavigateUtil.navigate(navTarget);
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) With(org.jetbrains.idea.devkit.dom.With)

Aggregations

ExtensionPoint (org.jetbrains.idea.devkit.dom.ExtensionPoint)7 PsiClass (com.intellij.psi.PsiClass)3 DomElement (com.intellij.util.xml.DomElement)3 Extension (org.jetbrains.idea.devkit.dom.Extension)3 Nullable (org.jetbrains.annotations.Nullable)2 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 PsiField (com.intellij.psi.PsiField)1 XmlElementVisitor (com.intellij.psi.XmlElementVisitor)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 DomFileElement (com.intellij.util.xml.DomFileElement)1 HashSet (java.util.HashSet)1 NotNull (org.jetbrains.annotations.NotNull)1 With (org.jetbrains.idea.devkit.dom.With)1