static String getQualifiedAttributeName(PsiElement context, XmlName xmlName) { final String localName = xmlName.getLocalName(); if (context instanceof XmlTag) { final XmlTag tag = (XmlTag)context; final DomInvocationHandler handler = DomManagerImpl.getDomManager(context.getProject()).getDomHandler(tag); if (handler != null) { final String ns = handler.createEvaluatedXmlName(xmlName).getNamespace(tag, handler.getFile()); if (!ns.equals(XmlUtil.EMPTY_URI) && !ns.equals(tag.getNamespace())) { final String prefix = tag.getPrefixByNamespace(ns); if (StringUtil.isNotEmpty(prefix)) { return prefix + ":" + localName; } } } } return localName; }
@Nullable public AttributeStub getAttributeStub(final XmlName name) { final List<DomStub> stubs = getChildrenStubs(); if (stubs.isEmpty()) { return null; } //noinspection ForLoopReplaceableByForEach for (int i = 0, size = stubs.size(); i < size; i++) { final DomStub stub = stubs.get(i); if (stub instanceof AttributeStub && stub.getName().equals(name.getLocalName())) { return (AttributeStub)stub; } } return null; }
@Nullable private static <T extends DomChildrenDescription> T findChildrenDescription(List<T> descriptions, XmlTag tag, DomInvocationHandler parent) { final String localName = tag.getLocalName(); String namespace = null; final String qName = tag.getName(); final XmlFile file = parent.getFile(); //noinspection ForLoopReplaceableByForEach for (int i = 0, size = descriptions.size(); i < size; i++) { final T description = descriptions.get(i); final XmlName xmlName = description.getXmlName(); if (localName.equals(xmlName.getLocalName()) || qName.equals(xmlName.getLocalName())) { final EvaluatedXmlName evaluatedXmlName = parent.createEvaluatedXmlName(xmlName); if (DomImplUtil.isNameSuitable(evaluatedXmlName, localName, qName, namespace == null ? namespace = tag.getNamespace() : namespace, file)) { return description; } } } return null; }
private static void registerPluginParameter(boolean isInPluginManagement, DomExtensionsRegistrar r, final ParameterData data, final String parameterName) { DomExtension e = r.registerFixedNumberChildExtension(new XmlName(parameterName), MavenDomConfigurationParameter.class); if (isCollection(data.parameter)) { e.addExtender(new DomExtender() { public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) { for (String each : collectPossibleNameForCollectionParameter(parameterName)) { DomExtension inner = registrar.registerCollectionChildrenExtension(new XmlName(each), MavenDomConfigurationParameter.class); inner.setDeclaringElement(data.parameter); } } }); } else { addValueConverter(e, data.parameter); if (!isInPluginManagement) { addRequiredAnnotation(e, data); } } e.setDeclaringElement(data.parameter); data.parameter.getXmlElement().putUserData(PLUGIN_PARAMETER_KEY, data); }
public List<String> getTypeLoadingErrors(AntDomTypeDef typedef) { final String generalError = myTypeDefErrors.get(typedef); if (generalError != null) { return Collections.singletonList(generalError); } List<String> errors = null; for (Map.Entry<XmlName, AntDomNamedElement> entry : myDeclarations.entrySet()) { if (typedef.equals(entry.getValue())) { final String err = lookupError(entry.getKey()); if (err != null) { if (errors == null) { errors = new ArrayList<String>(); } errors.add(err); } } } return errors == null? Collections.<String>emptyList() : errors; }
public Set<EvaluatedXmlName> getCompletionVariants(@NotNull DomElement parent) { if (!(parent instanceof AntDomElement)) { return Collections.emptySet(); } final AntDomElement element = (AntDomElement)parent; final AntDomProject antDomProject = element.getAntProject(); if (antDomProject == null) { return Collections.emptySet(); } final CustomAntElementsRegistry registry = CustomAntElementsRegistry.getInstance(antDomProject); final Set<EvaluatedXmlName> result = new HashSet<EvaluatedXmlName>(); for (XmlName variant : registry.getCompletionVariants(element)) { final String ns = variant.getNamespaceKey(); result.add(new DummyEvaluatedXmlName(variant, ns != null? ns : "")); } return result; }
@Nullable public AttributeStub getAttributeStub(final XmlName name) { final List<DomStub> stubs = getChildrenStubs(); if(stubs.isEmpty()) { return null; } //noinspection ForLoopReplaceableByForEach for(int i = 0, size = stubs.size(); i < size; i++) { final DomStub stub = stubs.get(i); if(stub instanceof AttributeStub && stub.getName().equals(name.getLocalName())) { return (AttributeStub) stub; } } return null; }
@Nullable final T findDescription(@NotNull final String localName) { for (final XmlName xmlName : myMap.keySet()) { if (xmlName.getLocalName().equals(localName)) return myMap.get(xmlName); } return myDelegate != null ? myDelegate.findDescription(localName) : null; }
public static boolean isRequiredAttribute(XmlName attrName, DomElement element) { if (element instanceof CompatibleScreensScreen && SdkConstants.NS_RESOURCES.equals(attrName.getNamespaceKey())) { final String localName = attrName.getLocalName(); return "screenSize".equals(localName) || "screenDensity".equals(localName); } return false; }
@Override public void registerExtensions(@NotNull MavenDomConfigurationParameter param, @NotNull DomExtensionsRegistrar r) { for (XmlAttribute each : param.getXmlTag().getAttributes()) { String name = each.getName(); if (CompletionUtil.DUMMY_IDENTIFIER_TRIMMED.equals(name)) continue; r.registerGenericAttributeValueChildExtension(new XmlName(name), String.class); } }
public boolean hasTypeLoadingErrors(AntDomTypeDef typedef) { final String generalError = myTypeDefErrors.get(typedef); if (generalError != null) { return true; } for (Map.Entry<XmlName, AntDomNamedElement> entry : myDeclarations.entrySet()) { if (typedef.equals(entry.getValue())) { if (lookupError(entry.getKey()) != null) { return true; } } } return false; }
private static void addInternalAttribute(@NotNull DomExtensionsRegistrar registrar, Class clazz) { if (!ApplicationManager.getApplication().isInternal()) { return; } registrar.registerGenericAttributeValueChildExtension(new XmlName("internal"), clazz) .setConverter(BooleanValueConverter.getInstance(false)); registrar.registerGenericAttributeValueChildExtension(new XmlName("overrides"), clazz) .setConverter(BooleanValueConverter.getInstance(false)); }
private static void addInternalAttribute(@NotNull DomExtensionsRegistrar registrar, Class clazz) { if (!ApplicationManager.getApplication().isInternal()) { return; } registrar.registerGenericAttributeValueChildExtension(new XmlName("internal"), clazz) .setConverter(BooleanValueConverter.getInstance(false)); }
@Nullable private static DomExtension registerChild(DomExtensionsRegistrar registrar, DomGenericInfo elementInfo, String childName) { if (elementInfo.getCollectionChildDescription(childName) == null) { // register if not yet defined statically Class<? extends AntDomElement> modelClass = getModelClass(childName); if (modelClass == null) { modelClass = AntDomElement.class; } return registrar.registerCollectionChildrenExtension(new XmlName(childName), modelClass); } return null; }
@Nullable private static PomTarget doFindDeclaration(DomElement parent, XmlName xmlName) { if (!(parent instanceof AntDomElement)) { return null; } final AntDomElement parentElement = (AntDomElement)parent; final AntDomProject antDomProject = parentElement.getAntProject(); if (antDomProject == null) { return null; } final CustomAntElementsRegistry registry = CustomAntElementsRegistry.getInstance(antDomProject); final AntDomElement declaringElement = registry.findDeclaringElement(parentElement, xmlName); if (declaringElement == null) { return null; } DomTarget target = DomTarget.getTarget(declaringElement); if (target == null && declaringElement instanceof AntDomTypeDef) { final AntDomTypeDef typedef = (AntDomTypeDef)declaringElement; final GenericAttributeValue<PsiFileSystemItem> resource = typedef.getResource(); if (resource != null) { target = DomTarget.getTarget(declaringElement, resource); } if (target == null) { final GenericAttributeValue<PsiFileSystemItem> file = typedef.getFile(); if (file != null) { target = DomTarget.getTarget(declaringElement, file); } } } return target; }
public DomExtensionImpl(final Type type, final XmlName xmlName) { myType = type; myXmlName = xmlName; }
@NotNull public XmlName getXmlName() { return myXmlName; }
@NotNull public final DomExtension registerFixedNumberChildrenExtension(@NotNull final XmlName name, @NotNull final Type type, final int count) { assert count > 0; return addExtension(myFixeds, name, type).setCount(count); }
@Override @NotNull public DomExtension registerFixedNumberChildExtension(@NotNull final XmlName name, @NotNull final Type type) { return registerFixedNumberChildrenExtension(name, type, 1); }
@Override @NotNull public DomExtension registerCollectionChildrenExtension(@NotNull final XmlName name, @NotNull final Type type) { return addExtension(myCollections, name, type); }
@Override @NotNull public DomExtension registerGenericAttributeValueChildExtension(@NotNull final XmlName name, final Type parameterType) { return addExtension(myAttributes, name, new ParameterizedTypeImpl(GenericAttributeValue.class, parameterType)); }
@Override @NotNull public DomExtension registerAttributeChildExtension(@NotNull final XmlName name, @NotNull final Type type) { assert GenericAttributeValue.class.isAssignableFrom(ReflectionUtil.getRawType(type)); return addExtension(myAttributes, name, type); }
private static DomExtensionImpl addExtension(final List<DomExtensionImpl> list, @Nullable final XmlName name, final Type type) { final DomExtensionImpl extension = new DomExtensionImpl(type, name); list.add(extension); return extension; }
protected DomChildDescriptionImpl(final XmlName tagName, @NotNull final Type type) { super(type); myTagName = tagName; }
@Override @NotNull public final XmlName getXmlName() { return myTagName; }
@Nullable final T getDescription(final XmlName name) { final T t = myMap.get(name); if (t != null) return t; return myDelegate != null ? myDelegate.getDescription(name) : null; }
@Nullable final T getDescription(@NotNull final String localName, String namespaceKey) { return getDescription(new XmlName(localName, namespaceKey)); }