Search in sources :

Example 96 with XmlAttributeValue

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

the class ReplaceWithXslAttribute method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final int offset = editor.getCaretModel().getOffset();
    final PsiElement element = file.findElementAt(offset);
    final XmlAttribute attr = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    assert attr != null;
    final XmlAttributeValue valueElement = attr.getValueElement();
    assert valueElement != null;
    final String s = attr.getValueTextRange().substring(valueElement.getText());
    final List<Pair<String, Boolean>> chunks = new ArrayList<>();
    final StringBuilder builder = new StringBuilder(s.length());
    final PsiFile[] files = XsltSupport.getFiles(attr);
    int i = 0, j = 0;
    while (i < s.length()) {
        final char c = s.charAt(i++);
        if (c == '{' && j < files.length) {
            if (i < s.length() - 1 && s.charAt(i) != '{') {
                final PsiFile f = files[j++];
                if (builder.length() > 0) {
                    chunks.add(Pair.create(builder.toString(), Boolean.FALSE));
                    builder.setLength(0);
                }
                chunks.add(Pair.create(f.getText(), Boolean.TRUE));
                i += f.getTextLength();
                if (s.charAt(i) == '}')
                    i++;
            } else {
                builder.append(c);
                i++;
            }
        } else {
            builder.append(c);
        }
    }
    if (builder.length() > 0) {
        chunks.add(Pair.create(builder.toString(), Boolean.FALSE));
    }
    final XmlTag parent = attr.getParent();
    final XmlTag attrTag = parent.createChildTag("attribute", XsltSupport.XSLT_NS, null, false);
    // local name?
    attrTag.setAttribute("name", attr.getName());
    final String value = attr.getNamespace();
    if (value.length() > 0) {
        attrTag.setAttribute("namespace", value);
    }
    for (Pair<String, Boolean> chunk : chunks) {
        final XmlTag child;
        if (chunk.second) {
            child = parent.createChildTag("value-of", XsltSupport.XSLT_NS, null, false);
            child.setAttribute("select", chunk.first);
        //            } else if (chunks.size() == 1) {
        // TODO: really? or always create an xsl:text?
        //                attrTag.add(attrTag.getManager().getElementFactory().createDisplayText(chunk.first));
        //                continue;
        } else {
            child = parent.createChildTag("text", XsltSupport.XSLT_NS, null, false);
            child.add(XmlElementFactory.getInstance(child.getProject()).createDisplayText(chunk.first));
        }
        attrTag.add(child);
    }
    final PsiElement child = XsltCodeInsightUtil.findFirstRealTagChild(parent);
    if (child != null) {
        parent.addBefore(attrTag, child);
    } else {
        parent.add(attrTag);
    }
    attr.delete();
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) ArrayList(java.util.ArrayList) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair) XmlTag(com.intellij.psi.xml.XmlTag)

Example 97 with XmlAttributeValue

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

the class XsltElementImpl method navigate.

@Override
public void navigate(boolean b) {
    final XmlAttributeValue nameElement = getNameElement();
    assert nameElement != null;
    ((NavigationItem) nameElement).navigate(b);
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 98 with XmlAttributeValue

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

the class ExternalResourceReference method handleElementRename.

public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
    myAttribute.setValue(newElementName);
    final XmlAttributeValue value = myAttribute.getValueElement();
    assert value != null;
    return value;
}
Also used : XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 99 with XmlAttributeValue

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

the class SimpleAttributeReference method handleElementRename.

public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
    myAttribute.setValue(getTextRange().replace(myAttribute.getValue(), newElementName));
    final XmlAttributeValue value = myAttribute.getValueElement();
    assert value != null;
    return value;
}
Also used : XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 100 with XmlAttributeValue

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

the class JavaFxRelatedItemLineMarkerProvider method collectTargets.

private static <T> void collectTargets(PsiField field, final ArrayList<T> targets, final Function<PsiElement, T> fun, final boolean stopAtFirst) {
    final PsiClass containingClass = field.getContainingClass();
    LOG.assertTrue(containingClass != null);
    final String qualifiedName = containingClass.getQualifiedName();
    LOG.assertTrue(qualifiedName != null);
    final List<VirtualFile> fxmls = JavaFxControllerClassIndex.findFxmlsWithController(field.getProject(), qualifiedName);
    if (fxmls.isEmpty())
        return;
    ReferencesSearch.search(field, GlobalSearchScope.filesScope(field.getProject(), fxmls)).forEach(reference -> {
        final PsiElement referenceElement = reference.getElement();
        if (referenceElement == null)
            return true;
        final PsiFile containingFile = referenceElement.getContainingFile();
        if (containingFile == null)
            return true;
        if (!JavaFxFileTypeFactory.isFxml(containingFile))
            return true;
        if (!(referenceElement instanceof XmlAttributeValue))
            return true;
        final XmlAttributeValue attributeValue = (XmlAttributeValue) referenceElement;
        final PsiElement parent = attributeValue.getParent();
        if (!(parent instanceof XmlAttribute))
            return true;
        if (!FxmlConstants.FX_ID.equals(((XmlAttribute) parent).getName()))
            return true;
        targets.add(fun.fun(parent));
        return !stopAtFirst;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Aggregations

XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)127 XmlAttribute (com.intellij.psi.xml.XmlAttribute)57 XmlTag (com.intellij.psi.xml.XmlTag)50 NotNull (org.jetbrains.annotations.NotNull)38 PsiElement (com.intellij.psi.PsiElement)31 Nullable (org.jetbrains.annotations.Nullable)24 PsiReference (com.intellij.psi.PsiReference)20 XmlFile (com.intellij.psi.xml.XmlFile)19 TextRange (com.intellij.openapi.util.TextRange)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)15 ArrayList (java.util.ArrayList)13 Project (com.intellij.openapi.project.Project)12 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 DomElement (com.intellij.util.xml.DomElement)9 PsiFile (com.intellij.psi.PsiFile)8 LazyValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.LazyValueResourceElementWrapper)7 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 Module (com.intellij.openapi.module.Module)5 ValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.ValueResourceElementWrapper)5