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);
}
}
}
}
}
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();
}
}
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);
}
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()]);
}
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);
}
Aggregations