Search in sources :

Example 16 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.

the class XmlParameterInfoHandler method findElementForParameterInfo.

@Override
public XmlTag findElementForParameterInfo(@NotNull final CreateParameterInfoContext context) {
    final XmlTag tag = findXmlTag(context.getFile(), context.getOffset());
    final XmlElementDescriptor descriptor = tag != null ? tag.getDescriptor() : null;
    if (descriptor == null) {
        DaemonCodeAnalyzer.getInstance(context.getProject()).updateVisibleHighlighters(context.getEditor());
        return null;
    }
    context.setItemsToShow(new Object[] { descriptor });
    return tag;
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 17 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.

the class MavenPropertyPsiReference method collectVariants.

protected void collectVariants(final List<Object> result, Set<String> variants) {
    int prefixLength = 0;
    if (myText.startsWith("pom.")) {
        prefixLength = "pom.".length();
    } else if (myText.startsWith("project.")) {
        prefixLength = "project.".length();
    }
    MavenProject mavenProject = myMavenProject;
    while (myText.startsWith("parent.", prefixLength)) {
        MavenId parentId = mavenProject.getParentId();
        if (parentId == null)
            return;
        mavenProject = myProjectsManager.findProject(parentId);
        if (mavenProject == null)
            return;
        prefixLength += "parent.".length();
    }
    final String prefix = prefixLength == 0 ? null : myText.substring(0, prefixLength);
    PsiDirectory baseDir = getBaseDir(mavenProject);
    addVariant(result, "basedir", baseDir, prefix, MavenIcons.MavenLogo);
    if (prefix == null) {
        result.add(createLookupElement(baseDir, "project.baseUri", MavenIcons.MavenLogo));
        result.add(createLookupElement(baseDir, "pom.baseUri", MavenIcons.MavenLogo));
        result.add(LookupElementBuilder.create(TIMESTAMP_PROP).withIcon(MavenIcons.MavenLogo));
    }
    processSchema(MavenSchemaProvider.MAVEN_PROJECT_SCHEMA_URL, new SchemaProcessor<Object>() {

        @Override
        public Object process(@NotNull String property, XmlElementDescriptor descriptor) {
            if (property.startsWith("project.")) {
                addVariant(result, property.substring("project.".length()), descriptor, prefix, MavenIcons.MavenLogo);
            }
            return null;
        }
    });
    processSchema(MavenSchemaProvider.MAVEN_SETTINGS_SCHEMA_URL, new SchemaProcessor<Object>() {

        @Override
        public Object process(@NotNull String property, XmlElementDescriptor descriptor) {
            result.add(createLookupElement(descriptor, property, MavenIcons.MavenLogo));
            return null;
        }
    });
    collectPropertiesVariants(result, variants);
    collectSystemEnvProperties(MavenPropertiesVirtualFileSystem.SYSTEM_PROPERTIES_FILE, null, result, variants);
    collectSystemEnvProperties(MavenPropertiesVirtualFileSystem.ENV_PROPERTIES_FILE, "env.", result, variants);
    MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings();
    for (String prop : runnerSettings.getMavenProperties().keySet()) {
        if (variants.add(prefix)) {
            result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
        }
    }
    for (String prop : MavenUtil.getPropertiesFromMavenOpts().keySet()) {
        if (variants.add(prop)) {
            result.add(LookupElementBuilder.create(prop).withIcon(PlatformIcons.PROPERTY_ICON));
        }
    }
    for (Object key : myMavenProject.getProperties().keySet()) {
        if (key instanceof String) {
            String property = (String) key;
            if (variants.add(property)) {
                result.add(LookupElementBuilder.create(property).withIcon(PlatformIcons.PROPERTY_ICON));
            }
        }
    }
    MavenDomConfiguration pluginCfg = DomUtil.findDomElement(myElement, MavenDomConfiguration.class);
    if (pluginCfg != null) {
        MavenPluginDescriptor.processDescriptors(descriptor -> {
            if (descriptor.properties != null) {
                for (MavenPluginDescriptor.ModelProperty property : descriptor.properties) {
                    if (property.insideConfigurationOnly) {
                        result.add(LookupElementBuilder.create(property.name).withIcon(PlatformIcons.PROPERTY_ICON));
                    }
                }
            }
            return true;
        }, pluginCfg);
    }
}
Also used : MavenRunnerSettings(org.jetbrains.idea.maven.execution.MavenRunnerSettings) MavenId(org.jetbrains.idea.maven.model.MavenId) MavenDomConfiguration(org.jetbrains.idea.maven.dom.model.MavenDomConfiguration) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenPluginDescriptor(org.jetbrains.idea.maven.plugins.api.MavenPluginDescriptor) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 18 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.

the class MavenPropertyPsiReference method doProcessSchema.

private static <T> T doProcessSchema(XmlElementDescriptor[] descriptors, String prefix, SchemaProcessor<T> processor, Set<XmlElementDescriptor> recursionGuard) {
    for (XmlElementDescriptor each : descriptors) {
        if (isCollection(each))
            continue;
        if (!recursionGuard.add(each))
            continue;
        try {
            String name = each.getName();
            if (prefix != null)
                name = prefix + "." + name;
            T result = processor.process(name, each);
            if (result != null)
                return result;
            result = doProcessSchema(each.getElementsDescriptors(null), name, processor, recursionGuard);
            if (result != null)
                return result;
        } finally {
            recursionGuard.remove(each);
        }
    }
    return null;
}
Also used : XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 19 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.

the class XsContentDFA method getPossibleElements.

@Override
public List<XmlElementDescriptor> getPossibleElements() {
    final List vector = myContentModel.whatCanGoHere(myState);
    ArrayList<XmlElementDescriptor> list = new ArrayList<>();
    for (Object o : vector) {
        if (o instanceof XSElementDecl) {
            final XSElementDecl elementDecl = (XSElementDecl) o;
            XmlElementDescriptor descriptor = ContainerUtil.find(myElementDescriptors, elementDescriptor -> elementDecl.getName().equals(elementDescriptor.getName()));
            ContainerUtil.addIfNotNull(list, descriptor);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor)

Example 20 with XmlElementDescriptor

use of com.intellij.xml.XmlElementDescriptor in project intellij-community by JetBrains.

the class GenerateXmlTagAction method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
    if (!EditorModificationUtil.checkModificationAllowed(editor))
        return;
    try {
        final XmlTag contextTag = getContextTag(editor, file);
        if (contextTag == null) {
            throw new CommonRefactoringUtil.RefactoringErrorHintException("Caret should be positioned inside a tag");
        }
        XmlElementDescriptor currentTagDescriptor = contextTag.getDescriptor();
        assert currentTagDescriptor != null;
        final XmlElementDescriptor[] descriptors = currentTagDescriptor.getElementsDescriptors(contextTag);
        Arrays.sort(descriptors, Comparator.comparing(PsiMetaData::getName));
        final JBList list = new JBList(descriptors);
        list.setCellRenderer(new MyListCellRenderer());
        Runnable runnable = () -> {
            final XmlElementDescriptor selected = (XmlElementDescriptor) list.getSelectedValue();
            new WriteCommandAction.Simple(project, "Generate XML Tag", file) {

                @Override
                protected void run() {
                    if (selected == null)
                        return;
                    XmlTag newTag = createTag(contextTag, selected);
                    PsiElement anchor = getAnchor(contextTag, editor, selected);
                    if (anchor == null) {
                        // insert it in the cursor position
                        int offset = editor.getCaretModel().getOffset();
                        Document document = editor.getDocument();
                        document.insertString(offset, newTag.getText());
                        PsiDocumentManager.getInstance(project).commitDocument(document);
                        newTag = PsiTreeUtil.getParentOfType(file.findElementAt(offset + 1), XmlTag.class, false);
                    } else {
                        newTag = (XmlTag) contextTag.addAfter(newTag, anchor);
                    }
                    if (newTag != null) {
                        generateTag(newTag, editor);
                    }
                }
            }.execute();
        };
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            XmlElementDescriptor descriptor = ContainerUtil.find(descriptors, xmlElementDescriptor -> xmlElementDescriptor.getName().equals(TEST_THREAD_LOCAL.get()));
            list.setSelectedValue(descriptor, false);
            runnable.run();
        } else {
            JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose Tag Name").setItemChoosenCallback(runnable).setFilteringEnabled(o -> ((XmlElementDescriptor) o).getName()).createPopup().showInBestPositionFor(editor);
        }
    } catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
        HintManager.getInstance().showErrorHint(editor, e.getMessage());
    }
}
Also used : Document(com.intellij.openapi.editor.Document) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) JBList(com.intellij.ui.components.JBList) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) PsiElement(com.intellij.psi.PsiElement)

Aggregations

XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)159 XmlTag (com.intellij.psi.xml.XmlTag)88 XmlNSDescriptor (com.intellij.xml.XmlNSDescriptor)60 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)54 PsiElement (com.intellij.psi.PsiElement)23 XmlFile (com.intellij.psi.xml.XmlFile)23 Nullable (org.jetbrains.annotations.Nullable)23 AnyXmlElementDescriptor (com.intellij.xml.impl.schema.AnyXmlElementDescriptor)22 PsiFile (com.intellij.psi.PsiFile)11 ArrayList (java.util.ArrayList)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 NotNull (org.jetbrains.annotations.NotNull)10 ClassBackedElementDescriptor (com.intellij.javascript.flex.mxml.schema.ClassBackedElementDescriptor)7 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)7 Project (com.intellij.openapi.project.Project)7 HtmlTag (com.intellij.psi.html.HtmlTag)7 AnnotationBackedDescriptor (com.intellij.lang.javascript.flex.AnnotationBackedDescriptor)5 XmlDocument (com.intellij.psi.xml.XmlDocument)5 DElementPattern (org.kohsuke.rngom.digested.DElementPattern)5 InvalidPropertyException (com.intellij.flex.uiDesigner.InvalidPropertyException)4