Set<XmlName> (AntDomElement parentElement) { if (parentElement instanceof AntDomCustomElement) { // this case is already handled in AntDomExtender when defining children return Collections.emptySet(); } final Set<XmlName> result = new HashSet<>(); final Pair<AntDomMacroDef, AntDomScriptDef> contextMacroOrScriptDef = getContextMacroOrScriptDef(parentElement); final AntDomMacroDef restrictToMacroDef = Pair.getFirst(contextMacroOrScriptDef); final AntDomScriptDef restrictToScriptDef = Pair.getSecond(contextMacroOrScriptDef); final boolean parentIsDataType = parentElement.isDataType(); for (final XmlName xmlName : myCustomElements.keySet()) { final AntDomNamedElement declaringElement = myDeclarations.get(xmlName); if (declaringElement instanceof AntDomMacrodefElement) { if (restrictToMacroDef == null || !restrictToMacroDef.equals(declaringElement.getParentOfType(AntDomMacroDef.class, true))) { continue; } } else if (declaringElement instanceof AntDomScriptdefElement) { if (restrictToScriptDef == null || !restrictToScriptDef.equals(declaringElement.getParentOfType(AntDomScriptDef.class, true))) { continue; } } if (declaringElement != null) { if (declaringElement.equals(restrictToMacroDef) || declaringElement.equals(restrictToScriptDef)) { continue; } } if (parentIsDataType) { if (declaringElement instanceof AntDomMacroDef || declaringElement instanceof AntDomScriptDef || declaringElement instanceof AntDomTaskdef) { continue; } if (declaringElement instanceof AntDomTypeDef typedef) { Class<?> clazz = lookupClass(xmlName); if (clazz != null && typedef.isTask(clazz)) { continue; } } } result.add(xmlName); } return result; }