Search in sources :

Example 1 with Extension

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

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

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

the class InspectionDescriptionInfo method create.

public static InspectionDescriptionInfo create(Module module, PsiClass psiClass) {
    PsiMethod method = PsiUtil.findNearestMethod("getShortName", psiClass);
    if (method != null && method.getContainingClass().hasModifierProperty(PsiModifier.ABSTRACT)) {
        method = null;
    }
    String filename = null;
    if (method == null) {
        String className = psiClass.getQualifiedName();
        if (className != null) {
            Extension extension = findExtension(module, psiClass);
            if (extension != null) {
                filename = extension.getXmlTag().getAttributeValue("shortName");
            }
        }
    } else {
        filename = PsiUtil.getReturnedLiteral(method, psiClass);
    }
    if (filename == null) {
        final String className = psiClass.getName();
        LOG.assertTrue(className != null, psiClass);
        filename = InspectionProfileEntry.getShortName(className);
    }
    PsiFile descriptionFile = resolveInspectionDescriptionFile(module, filename);
    return new InspectionDescriptionInfo(filename, method, descriptionFile);
}
Also used : Extension(org.jetbrains.idea.devkit.dom.Extension)

Example 4 with Extension

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

the class ExtensionPointLocator method isRegisteredExtension.

public static boolean isRegisteredExtension(@NotNull PsiClass psiClass) {
    String name = psiClass.getQualifiedName();
    if (name == null)
        return false;
    Project project = psiClass.getProject();
    GlobalSearchScope scope = getCandidatesScope(project);
    return !PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() {

        @Override
        public boolean process(PsiFile file, int startOffset, int endOffset) {
            PsiElement at = file.findElementAt(startOffset);
            String tokenText = at instanceof XmlToken ? at.getText() : null;
            if (!StringUtil.equals(name, tokenText))
                return true;
            XmlTag tag = PsiTreeUtil.getParentOfType(at, XmlTag.class);
            if (tag == null)
                return true;
            DomElement dom = DomUtil.getDomElement(tag);
            return !(dom instanceof Extension && ((Extension) dom).getExtensionPoint() != null);
        }
    }, scope);
}
Also used : 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) PsiNonJavaFileReferenceProcessor(com.intellij.psi.search.PsiNonJavaFileReferenceProcessor) XmlToken(com.intellij.psi.xml.XmlToken) XmlTag(com.intellij.psi.xml.XmlTag)

Example 5 with Extension

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

the class RegisterExtensionFix method registerExtension.

private void registerExtension(final DomFileElement<IdeaPlugin> selectedValue, final ExtensionPointCandidate candidate) {
    PsiElement navTarget = new WriteCommandAction<PsiElement>(selectedValue.getFile().getProject(), selectedValue.getFile()) {

        @Override
        protected void run(@NotNull Result<PsiElement> result) throws Throwable {
            Extensions extensions = PluginDescriptorChooser.findOrCreateExtensionsForEP(selectedValue, candidate.epName);
            Extension extension = extensions.addExtension(candidate.epName);
            XmlTag tag = extension.getXmlTag();
            PsiElement navTarget = null;
            String keyAttrName = KEY_MAP.get(candidate.beanClassName);
            if (keyAttrName != null) {
                XmlAttribute attr = tag.setAttribute(keyAttrName, "");
                navTarget = attr.getValueElement();
            }
            if (candidate.attributeName != null) {
                tag.setAttribute(candidate.attributeName, myExtensionClass.getQualifiedName());
            } else {
                XmlTag subTag = tag.createChildTag(candidate.tagName, null, myExtensionClass.getQualifiedName(), false);
                tag.addSubTag(subTag, false);
            }
            result.setResult(navTarget != null ? navTarget : extension.getXmlTag());
        }
    }.execute().throwException().getResultObject();
    PsiNavigateUtil.navigate(navTarget);
}
Also used : Extension(org.jetbrains.idea.devkit.dom.Extension) XmlAttribute(com.intellij.psi.xml.XmlAttribute) Extensions(org.jetbrains.idea.devkit.dom.Extensions) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

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