Search in sources :

Example 6 with PomTarget

use of com.intellij.pom.PomTarget in project intellij-community by JetBrains.

the class RenameAliasingPomTargetProcessor method prepareRenaming.

@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {
    PomTarget target = null;
    if (element instanceof PomTargetPsiElement) {
        target = ((PomTargetPsiElement) element).getTarget();
    } else if (element instanceof PomTarget) {
        target = (PomTarget) element;
    }
    if (target != null) {
        for (AliasingPsiTargetMapper mapper : Extensions.getExtensions(AliasingPsiTargetMapper.EP_NAME)) {
            for (AliasingPsiTarget psiTarget : mapper.getTargets(target)) {
                PsiElement psiElement = PomService.convertToPsi(psiTarget);
                String name = psiTarget.getNameAlias(newName);
                String definedName = allRenames.put(psiElement, name);
                if (definedName != null) {
                    LOG.assertTrue(definedName.equals(name), "target: " + psiTarget + "; " + "defined name: " + definedName + "; " + "name: " + name + "; " + "mapper: " + mapper);
                } else {
                    prepareRenaming(psiElement, name, allRenames);
                }
            }
        }
    }
}
Also used : PomTarget(com.intellij.pom.PomTarget) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) AliasingPsiTarget(com.intellij.psi.targets.AliasingPsiTarget) AliasingPsiTargetMapper(com.intellij.psi.targets.AliasingPsiTargetMapper) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 7 with PomTarget

use of com.intellij.pom.PomTarget in project intellij-community by JetBrains.

the class ResourceBundlePropertiesUpdateManager method deletePropertyIfExist.

public void deletePropertyIfExist(String key, PropertiesFile file) {
    final IProperty property = file.findPropertyByKey(key);
    if (property != null && myKeysOrder != null) {
        boolean keyExistInOtherPropertiesFiles = false;
        for (PropertiesFile propertiesFile : myResourceBundle.getPropertiesFiles()) {
            if (!propertiesFile.equals(file) && propertiesFile.findPropertyByKey(key) != null) {
                keyExistInOtherPropertiesFiles = true;
                break;
            }
        }
        if (!keyExistInOtherPropertiesFiles) {
            myKeysOrder.remove(key);
        }
    }
    if (property != null) {
        PsiElement anElement = property.getPsiElement();
        if (anElement instanceof PomTargetPsiElement) {
            final PomTarget xmlProperty = ((PomTargetPsiElement) anElement).getTarget();
            LOG.assertTrue(xmlProperty instanceof XmlProperty);
            anElement = ((XmlProperty) xmlProperty).getNavigationElement();
        }
        anElement.delete();
    }
}
Also used : PomTarget(com.intellij.pom.PomTarget) IProperty(com.intellij.lang.properties.IProperty) XmlProperty(com.intellij.lang.properties.xml.XmlProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement) PsiElement(com.intellij.psi.PsiElement)

Example 8 with PomTarget

use of com.intellij.pom.PomTarget in project intellij-community by JetBrains.

the class AbstractDomChildrenDescriptor method getElementDescriptor.

@Override
@Nullable
public XmlElementDescriptor getElementDescriptor(@NotNull final XmlTag childTag, @Nullable XmlTag contextTag) {
    DomElement domElement = myManager.getDomElement(childTag);
    if (domElement == null) {
        domElement = myManager.getDomElement(contextTag);
        if (domElement != null) {
            AbstractDomChildrenDescription description = myManager.findChildrenDescription(childTag, domElement);
            if (description instanceof DomChildrenDescription) {
                return new DomElementXmlDescriptor((DomChildrenDescription) description, myManager);
            }
        }
        return null;
    }
    final DomElement parent = domElement.getParent();
    if (parent == null)
        return new DomElementXmlDescriptor(domElement);
    final AbstractDomChildrenDescription description = domElement.getChildDescription();
    if (description instanceof CustomDomChildrenDescription) {
        final DomElement finalDomElement = domElement;
        return new AbstractDomChildrenDescriptor(myManager) {

            @Override
            public String getDefaultName() {
                return finalDomElement.getXmlElementName();
            }

            @Override
            @Nullable
            public PsiElement getDeclaration() {
                final PomTarget target = ((CustomDomChildrenDescription) description).getTagNameDescriptor().findDeclaration(finalDomElement);
                if (target == description) {
                    return childTag;
                }
                return target == null ? null : PomService.convertToPsi(childTag.getProject(), target);
            }
        };
    }
    if (!(description instanceof DomChildrenDescription))
        return null;
    return new DomElementXmlDescriptor((DomChildrenDescription) description, myManager);
}
Also used : PomTarget(com.intellij.pom.PomTarget) DomElement(com.intellij.util.xml.DomElement) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with PomTarget

use of com.intellij.pom.PomTarget in project intellij-community by JetBrains.

the class AbstractDomChildrenDescriptor method getElementsDescriptors.

@Override
public XmlElementDescriptor[] getElementsDescriptors(final XmlTag context) {
    final DomElement domElement = myManager.getDomElement(context);
    if (domElement == null)
        return EMPTY_ARRAY;
    List<XmlElementDescriptor> xmlElementDescriptors = new ArrayList<>();
    for (DomCollectionChildDescription childrenDescription : domElement.getGenericInfo().getCollectionChildrenDescriptions()) {
        xmlElementDescriptors.add(new DomElementXmlDescriptor(childrenDescription, myManager));
    }
    for (DomFixedChildDescription childrenDescription : domElement.getGenericInfo().getFixedChildrenDescriptions()) {
        xmlElementDescriptors.add(new DomElementXmlDescriptor(childrenDescription, myManager));
    }
    final List<? extends CustomDomChildrenDescription> customs = domElement.getGenericInfo().getCustomNameChildrenDescription();
    for (final CustomDomChildrenDescription custom : customs) {
        final CustomDomChildrenDescription.TagNameDescriptor tagNameDescriptor = custom.getTagNameDescriptor();
        if (tagNameDescriptor == null)
            continue;
        final XmlTag xmlTag = domElement.getXmlTag();
        for (final EvaluatedXmlName name : tagNameDescriptor.getCompletionVariants(domElement)) {
            AbstractDomChildrenDescriptor descriptor = new AbstractDomChildrenDescriptor(myManager) {

                @Override
                public String getDefaultName() {
                    final String ns = xmlTag != null ? name.getNamespace(xmlTag, (XmlFile) xmlTag.getContainingFile()) : null;
                    if (ns != null) {
                        final String prefix = xmlTag.getPrefixByNamespace(ns);
                        if (prefix != null) {
                            return prefix + ":" + name.getXmlName().getLocalName();
                        }
                    }
                    return name.getXmlName().getLocalName();
                }

                @Override
                @Nullable
                public PsiElement getDeclaration() {
                    final PomTarget target = tagNameDescriptor.findDeclaration(domElement, name);
                    return target == null ? null : PomService.convertToPsi(context.getProject(), target);
                }
            };
            xmlElementDescriptors.add(descriptor);
        }
        xmlElementDescriptors.add(new AnyXmlElementDescriptor(this, getNSDescriptor()));
    }
    return xmlElementDescriptors.toArray(new XmlElementDescriptor[xmlElementDescriptors.size()]);
}
Also used : EvaluatedXmlName(com.intellij.util.xml.EvaluatedXmlName) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) PomTarget(com.intellij.pom.PomTarget) DomElement(com.intellij.util.xml.DomElement) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) AnyXmlElementDescriptor(com.intellij.xml.impl.schema.AnyXmlElementDescriptor) XmlTag(com.intellij.psi.xml.XmlTag)

Example 10 with PomTarget

use of com.intellij.pom.PomTarget in project intellij-community by JetBrains.

the class DomDocumentationProvider method generateDoc.

@Override
public String generateDoc(PsiElement element, final PsiElement originalElement) {
    if (element instanceof PomTargetPsiElement) {
        PomTarget target = ((PomTargetPsiElement) element).getTarget();
        if (target instanceof DelegatePsiTarget) {
            element = ((DelegatePsiTarget) target).getNavigationElement();
        }
    }
    final DomElement domElement = DomUtil.getDomElement(element);
    if (domElement == null) {
        return null;
    }
    ElementPresentationTemplate template = domElement.getChildDescription().getPresentationTemplate();
    if (template != null) {
        String documentation = template.createPresentation(domElement).getDocumentation();
        if (documentation != null)
            return documentation;
    }
    return ElementPresentationManager.getDocumentationForElement(domElement);
}
Also used : PomTarget(com.intellij.pom.PomTarget) DelegatePsiTarget(com.intellij.psi.DelegatePsiTarget) PomTargetPsiElement(com.intellij.pom.PomTargetPsiElement)

Aggregations

PomTarget (com.intellij.pom.PomTarget)10 PomTargetPsiElement (com.intellij.pom.PomTargetPsiElement)6 Nullable (org.jetbrains.annotations.Nullable)4 PsiElement (com.intellij.psi.PsiElement)3 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)2 TextRange (com.intellij.openapi.util.TextRange)2 PomDeclarationSearcher (com.intellij.pom.PomDeclarationSearcher)2 PsiDeclaredTarget (com.intellij.pom.PsiDeclaredTarget)2 DomElement (com.intellij.util.xml.DomElement)2 ResourceUrl (com.android.ide.common.resources.ResourceUrl)1 ResourceType (com.android.resources.ResourceType)1 CompletionUtil (com.intellij.codeInsight.completion.CompletionUtil)1 DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 Lookup (com.intellij.codeInsight.lookup.Lookup)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 EditSourceUtil (com.intellij.ide.util.EditSourceUtil)1 Language (com.intellij.lang.Language)1 LanguageExtension (com.intellij.lang.LanguageExtension)1 AntDomElement (com.intellij.lang.ant.dom.AntDomElement)1