/** * Gets the current namespace for the given element. * * @param psiElement Current element. * @return {@code null} on XML errors or if {@link #matchesResultType(String)} returns {@code * false}. */ @Nullable protected final String getNamespace(@NotNull final PsiElement psiElement) { final DomElement resultElement = DomUtil.getDomElement(psiElement); if (resultElement == null) { return null; // XML syntax error } assert resultElement instanceof HasResultType : "not instance of HasResultType: " + resultElement + ", text: " + psiElement.getText(); final ResultType effectiveResultType = ((HasResultType) resultElement).getEffectiveResultType(); if (effectiveResultType == null) { return null; } final String resultType = effectiveResultType.getName().getStringValue(); if (resultType == null || !matchesResultType(resultType)) { return null; } final StrutsPackage strutsPackage = resultElement.getParentOfType(StrutsPackage.class, true); if (strutsPackage == null) { return null; // XML syntax error } return strutsPackage.searchNamespace(); }
@Nullable private AntDomMacroDef getParentMacrodef() { final PsiElement element = getElement(); if (element == null) { return null; } final DomElement domElement = DomUtil.getDomElement(element); if (domElement == null) { return null; } return domElement.getParentOfType(AntDomMacroDef.class, false); }
public PsiElement resolve(PsiReference psiReference, boolean incompleteCode) { final PsiElement element = psiReference.getElement(); if (element == null) { return null; } final DomElement domElement = DomUtil.getDomElement(element); if (domElement == null) { return null; } final AntDomMacroDef macrodef = domElement.getParentOfType(AntDomMacroDef.class, false); if (macrodef == null) { return null; } final String name = AntStringResolver.computeString(domElement, psiReference.getCanonicalText()); for (AntDomMacrodefAttribute attribute : macrodef.getMacroAttributes()) { if (name.equals(attribute.getName().getStringValue())) { final DomTarget target = DomTarget.getTarget(attribute); return target != null ? PomService.convertToPsi(target) : null; } } return null; }