use of com.intellij.util.xml.DomTarget in project intellij-community by JetBrains.
the class AntDomDocumentationProvider method getQuickNavigateInfo.
@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
// todo!
if (element instanceof PomTargetPsiElement) {
final PomTarget pomTarget = ((PomTargetPsiElement) element).getTarget();
if (pomTarget instanceof DomTarget) {
final DomElement domElement = ((DomTarget) pomTarget).getDomElement();
if (domElement instanceof AntDomTarget) {
final AntDomTarget antTarget = (AntDomTarget) domElement;
final String description = antTarget.getDescription().getRawText();
if (description != null && description.length() > 0) {
final String targetName = antTarget.getName().getRawText();
final StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
builder.append("Target");
if (targetName != null) {
builder.append(" \"").append(targetName).append("\"");
}
final XmlElement xmlElement = antTarget.getXmlElement();
if (xmlElement != null) {
final PsiFile containingFile = xmlElement.getContainingFile();
if (containingFile != null) {
final String fileName = containingFile.getName();
builder.append(" [").append(fileName).append("]");
}
}
return builder.append(" ").append(description).toString();
} finally {
StringBuilderSpinAllocator.dispose(builder);
}
}
}
} else if (pomTarget instanceof DomChildrenDescription) {
final DomChildrenDescription description = (DomChildrenDescription) pomTarget;
Type type = null;
try {
type = description.getType();
} catch (UnsupportedOperationException e) {
LOG.info(e);
}
if (type instanceof Class && AntDomElement.class.isAssignableFrom(((Class) type))) {
final String elemName = description.getName();
if (elemName != null) {
final AntDomElement.Role role = description.getUserData(AntDomElement.ROLE);
final StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
if (role == AntDomElement.Role.TASK) {
builder.append("Task ");
} else if (role == AntDomElement.Role.DATA_TYPE) {
builder.append("Data structure ");
}
builder.append(elemName);
return builder.toString();
} finally {
StringBuilderSpinAllocator.dispose(builder);
}
}
}
}
}
return null;
}
use of com.intellij.util.xml.DomTarget in project intellij-community by JetBrains.
the class AntResolveTest method testPropertyInMacrodefParam.
public void testPropertyInMacrodefParam() throws Exception {
PsiReference ref = configure();
final PsiElement result = ref.resolve();
assertTrue(result instanceof PomTargetPsiElement);
final PsiElement naviElem = ((DomTarget) ((PomTargetPsiElement) result).getTarget()).getNavigationElement();
final DomElement domElement = DomUtil.getDomElement(naviElem);
assertNotNull(domElement);
assertNotNull(domElement.getParentOfType(AntDomMacrodefAttribute.class, false));
}
use of com.intellij.util.xml.DomTarget in project intellij-community by JetBrains.
the class AntDomPropertyDefiningElement method getNavigationElement.
public final PsiElement getNavigationElement(String propertyName) {
for (GenericAttributeValue<String> value : getPropertyDefiningAttributes()) {
if (!propertyName.equals(value.getStringValue())) {
continue;
}
final DomTarget domTarget = DomTarget.getTarget(this, value);
return domTarget != null ? PomService.convertToPsi(domTarget) : null;
}
for (String propName : getImplicitPropertyNames()) {
if (propertyName.equals(propName)) {
final DomTarget domTarget = DomTarget.getTarget(this);
if (domTarget != null) {
return PomService.convertToPsi(domTarget);
}
final XmlElement xmlElement = getXmlElement();
return xmlElement != null ? xmlElement.getNavigationElement() : null;
}
}
return null;
}
use of com.intellij.util.xml.DomTarget in project intellij-community by JetBrains.
the class AntDomProperty method getNavigationElement.
public PsiElement getNavigationElement(final String propertyName) {
DomTarget domTarget = DomTarget.getTarget(this);
if (domTarget == null) {
final GenericAttributeValue<String> environment = getEnvironment();
if (environment.getRawText() != null) {
domTarget = DomTarget.getTarget(this, environment);
}
if (domTarget == null) {
final GenericAttributeValue<String> resource = getResource();
if (resource.getRawText() != null) {
domTarget = DomTarget.getTarget(this, resource);
}
}
}
if (domTarget != null) {
final PsiElement psi = PomService.convertToPsi(domTarget);
if (psi != null) {
return psi;
}
}
final PsiFileSystemItem psiFile = getFile().getValue();
if (psiFile != null) {
final String prefix = getPropertyPrefixValue();
String _propertyName = propertyName;
if (prefix != null) {
if (!propertyName.startsWith(prefix)) {
return null;
}
_propertyName = propertyName.substring(prefix.length());
}
final PropertiesFile pf = toPropertiesFile(psiFile);
if (pf != null) {
final IProperty property = pf.findPropertyByKey(_propertyName);
return property != null ? property.getPsiElement() : null;
}
}
return null;
}
Aggregations