Search in sources :

Example 41 with XmlElement

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

the class AntResolveInspection method checkDomElement.

protected void checkDomElement(DomElement element, DomElementAnnotationHolder holder, DomHighlightingHelper helper) {
    if (element instanceof GenericDomValue) {
        final XmlElement valueElement = DomUtil.getValueElement(((GenericDomValue) element));
        if (valueElement != null) {
            checkReferences(valueElement, holder, element);
        }
    } else if (element instanceof AntDomTypeDef) {
        final AntDomTypeDef typeDef = (AntDomTypeDef) element;
        final List<String> errors = typeDef.getErrorDescriptions();
        if (!errors.isEmpty()) {
            final StringBuilder builder = new StringBuilder();
            builder.append(AntBundle.message("failed.to.load.types")).append(":");
            for (String error : errors) {
                builder.append("\n").append(error);
            }
            holder.createProblem(typeDef, builder.toString());
        }
    } else if (element instanceof AntDomCustomElement) {
        final AntDomCustomElement custom = (AntDomCustomElement) element;
        if (custom.getDefinitionClass() == null) {
            final AntDomNamedElement declaringElement = custom.getDeclaringElement();
            if (declaringElement instanceof AntDomTypeDef) {
                String failedMessage = AntBundle.message("using.definition.which.type.failed.to.load");
                final String error = custom.getLoadError();
                if (error != null) {
                    failedMessage = failedMessage + ": " + error;
                }
                holder.createProblem(custom, failedMessage);
            }
        }
    }
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) SmartList(com.intellij.util.SmartList) GenericDomValue(com.intellij.util.xml.GenericDomValue)

Example 42 with XmlElement

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

the class DependencyConfigFileConverter method fromString.

@Override
public PathReference fromString(@Nullable String s, ConvertContext context) {
    final XmlElement element = context.getXmlElement();
    final Module module = context.getModule();
    if (s == null || element == null || module == null) {
        return null;
    }
    return PathReferenceManager.getInstance().getCustomPathReference(s, module, element, ourProvider);
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) Module(com.intellij.openapi.module.Module)

Example 43 with XmlElement

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

the class ContextProvider method getQName.

@Nullable
public QName getQName(@NotNull PrefixedName qName, XPathElement context) {
    final String prefix = qName.getPrefix();
    final NamespaceContext namespaceContext = getNamespaceContext();
    if (namespaceContext != null) {
        if (prefix != null) {
            final XmlElement element = PsiTreeUtil.getContextOfType(context, XmlElement.class, true);
            final String namespaceURI = namespaceContext.getNamespaceURI(prefix, element);
            return namespaceURI != null && namespaceURI.length() > 0 ? new QName(namespaceURI, qName.getLocalName(), prefix) : null;
        } else if (context.getXPathVersion() == XPathVersion.V2) {
            if (isDefaultCapableElement(context)) {
                final String namespace = namespaceContext.getDefaultNamespace(getContextElement());
                if (namespace != null) {
                    return new QName(namespace, qName.getLocalName());
                }
            }
        }
        return new QName(null, qName.getLocalName(), "");
    } else if (qName.getPrefix() == null) {
        return QName.valueOf(qName.getLocalName());
    } else {
        return null;
    }
}
Also used : XsltNamespaceContext(org.intellij.lang.xpath.xslt.context.XsltNamespaceContext) QName(javax.xml.namespace.QName) XmlElement(com.intellij.psi.xml.XmlElement) Nullable(org.jetbrains.annotations.Nullable)

Example 44 with XmlElement

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

the class ShowXPathAction method isEnabledAt.

protected boolean isEnabledAt(XmlFile xmlFile, int offset) {
    final PsiElement element = xmlFile.findElementAt(offset);
    if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) {
        return false;
    }
    final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element);
    return node != null;
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 45 with XmlElement

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

the class ShowXPathAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    if (editor == null) {
        return;
    }
    final Project project = editor.getProject();
    if (project == null) {
        return;
    }
    final PsiDocumentManager docmgr = PsiDocumentManager.getInstance(project);
    final Document document = editor.getDocument();
    docmgr.commitDocument(document);
    final PsiFile psiFile = docmgr.getPsiFile(document);
    if (!(psiFile instanceof XmlFile)) {
        return;
    }
    final PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
    if (!(element instanceof XmlElement || element instanceof PsiWhiteSpace)) {
        XPathAppComponent.showEditorHint("No suitable context for an XPath-expression selected.", editor);
        return;
    }
    final PsiElement node = XPathExpressionGenerator.transformToValidShowPathNode(element);
    if (node == null) {
        XPathAppComponent.showEditorHint("No suitable context for an XPath-expression selected.", editor);
        return;
    }
    final Config cfg = XPathAppComponent.getInstance().getConfig();
    final RangeHighlighter h = HighlighterUtil.highlightNode(editor, node, cfg.getContextAttributes(), cfg);
    final String path = XPathSupport.getInstance().getUniquePath((XmlElement) node, null);
    final JTextField label = new JTextField(path);
    label.setPreferredSize(new Dimension(label.getPreferredSize().width + new JLabel("M").getPreferredSize().width, label.getPreferredSize().height));
    label.setOpaque(false);
    label.setEditable(false);
    label.setBorder(null);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    final JPanel p = new NonOpaquePanel(new BorderLayout());
    final JLabel l = new JLabel("XPath:");
    p.add(l, BorderLayout.WEST);
    p.add(label, BorderLayout.CENTER);
    InplaceButton copy = new InplaceButton(ActionsBundle.message("action.EditorCopy.text"), PlatformIcons.COPY_ICON, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            CopyPasteManager.getInstance().setContents(new StringSelection(path));
        }
    });
    p.add(copy, BorderLayout.EAST);
    final LightweightHint hint = new LightweightHint(p) {

        public void hide() {
            super.hide();
            HighlighterUtil.removeHighlighter(editor, h);
        }
    };
    final Point point = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition());
    point.y += editor.getLineHeight() / 2;
    HintHint hintHint = new HintHint(editor, point).setAwtTooltip(true).setContentActive(true).setExplicitClose(true).setShowImmediately(true);
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManager.HIDE_BY_ANY_KEY, 0, false, hintHint);
}
Also used : ActionEvent(java.awt.event.ActionEvent) Document(com.intellij.openapi.editor.Document) StringSelection(java.awt.datatransfer.StringSelection) RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) XmlFile(com.intellij.psi.xml.XmlFile) LightweightHint(com.intellij.ui.LightweightHint) InplaceButton(com.intellij.ui.InplaceButton) Project(com.intellij.openapi.project.Project) HintHint(com.intellij.ui.HintHint) ActionListener(java.awt.event.ActionListener) XmlElement(com.intellij.psi.xml.XmlElement) Editor(com.intellij.openapi.editor.Editor) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Aggregations

XmlElement (com.intellij.psi.xml.XmlElement)69 PsiElement (com.intellij.psi.PsiElement)16 NotNull (org.jetbrains.annotations.NotNull)16 Nullable (org.jetbrains.annotations.Nullable)11 XmlTag (com.intellij.psi.xml.XmlTag)10 PsiFile (com.intellij.psi.PsiFile)7 PsiReference (com.intellij.psi.PsiReference)6 XmlAttribute (com.intellij.psi.xml.XmlAttribute)6 XmlFile (com.intellij.psi.xml.XmlFile)6 Manifest (org.jetbrains.android.dom.manifest.Manifest)5 Module (com.intellij.openapi.module.Module)4 Project (com.intellij.openapi.project.Project)4 DomElement (com.intellij.util.xml.DomElement)4 ArrayList (java.util.ArrayList)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 CompositePsiElement (com.intellij.psi.impl.source.tree.CompositePsiElement)3 SmartList (com.intellij.util.SmartList)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 ResourceType (com.android.resources.ResourceType)2 Result (com.intellij.openapi.application.Result)2