@Override public void registerExtensions(@NotNull MyAllCustomElement element, @NotNull DomExtensionsRegistrar registrar) { try { DomElement parent = element; while (parent != null) { for (DomElement child : DomUtil.getDefinedChildren(parent, true, true)) { DomElement childParent = child.getParent(); if (!parent.equals(childParent)) { String parentText = parent.getXmlTag().getText(); String childText = child.getXmlElement().getText(); child.getParent(); parent.equals(childParent); throw new AssertionError(parent.getXmlElement() + "; " + childParent + "; " + child.getXmlElement().getText()); } } parent = parent.getParent(); } } catch (StackOverflowError e) { System.out.println(Thread.currentThread() + ": " + element.getXmlTag().getName() + element.getXmlTag().hashCode()); throw e; } registrar.registerCustomChildrenExtension(MyAllCustomElement.class); }
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 void registerExtensions(@NotNull final Extensions extensions, @NotNull final DomExtensionsRegistrar registrar) { final XmlElement xmlElement = extensions.getXmlElement(); if (xmlElement == null) return; IdeaPlugin ideaPlugin = extensions.getParentOfType(IdeaPlugin.class, true); if (ideaPlugin == null) return; String epPrefix = extensions.getEpPrefix(); for (IdeaPlugin plugin : getVisiblePlugins(ideaPlugin)) { final String pluginId = StringUtil.notNullize(plugin.getPluginId(), "com.intellij"); for (ExtensionPoints points : plugin.getExtensionPoints()) { for (ExtensionPoint point : points.getExtensionPoints()) { registerExtensionPoint(registrar, point, epPrefix, pluginId); } } } }
@Override public void registerExtensions(@NotNull MyElement myElement, @NotNull DomExtensionsRegistrar registrar) { for (MyElement element : myElement.getFooElements()) { element.getFooElements(); } if (myRandom.nextInt(20) < 2) { try { Thread.sleep(1); } catch (InterruptedException ignored) { } } registrar.registerFixedNumberChildExtension(new XmlName("custom-foo", null), MyElement.class); myElement.getSomeChild().getFooElements(); myElement.getFooChild().getFooChild().getAttr(); myElement.getAttr(); registrar.registerCollectionChildrenExtension(new XmlName("custom-bar", null), MyElement.class); }
public void registerExtensions(@NotNull final Extensions extensions, @NotNull final DomExtensionsRegistrar registrar) { final XmlElement xmlElement = extensions.getXmlElement(); if (xmlElement == null) return; IdeaPlugin ideaPlugin = extensions.getParentOfType(IdeaPlugin.class, true); if (ideaPlugin == null) return; String prefix = getEpPrefix(extensions); for (IdeaPlugin plugin : getVisiblePlugins(ideaPlugin)) { final String pluginId = StringUtil.notNullize(plugin.getPluginId(), "com.intellij"); for (ExtensionPoints points : plugin.getExtensionPoints()) { for (ExtensionPoint point : points.getExtensionPoints()) { registerExtensionPoint(registrar, point, prefix, pluginId); } } } }
@Override public void registerExtensions(@NotNull MyElement myElement, @NotNull DomExtensionsRegistrar registrar) { for (MyElement element : myElement.getFooElements()) { element.getFooElements(); } if (myRandom.nextInt(20) < 2) { TimeoutUtil.sleep(1); } registrar.registerFixedNumberChildExtension(new XmlName("custom-foo", null), MyElement.class); myElement.getSomeChild().getFooElements(); myElement.getFooChild().getFooChild().getAttr(); myElement.getAttr(); registrar.registerCollectionChildrenExtension(new XmlName("custom-bar", null), MyElement.class); }
@Override public void registerExtensions(@NotNull MavenDomConfiguration config, @NotNull DomExtensionsRegistrar r) { MavenDomPluginModel pluginModel = MavenPluginDomUtil.getMavenPluginModel(config); if (pluginModel == null) { r.registerCustomChildrenExtension(MavenDomConfigurationParameter.class); return; } boolean isInPluginManagement = isInPluginManagement(config); for (ParameterData each : collectParameters(pluginModel, config)) { registerPluginParameter(isInPluginManagement, r, each); } }
private static void registerPluginParameter(boolean isInPluginManagement, DomExtensionsRegistrar r, final ParameterData parameter) { String paramName = parameter.parameter.getName().getStringValue(); String alias = parameter.parameter.getAlias().getStringValue(); registerPluginParameter(isInPluginManagement, r, parameter, paramName); if (alias != null) registerPluginParameter(isInPluginManagement, r, parameter, alias); }
@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); } }
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 registerExtensionPoint(final DomExtensionsRegistrar registrar, final ExtensionPoint extensionPoint, String epPrefix, @Nullable String pluginId) { String epName = extensionPoint.getName().getStringValue(); if (epName != null && StringUtil.isNotEmpty(pluginId)) epName = pluginId + "." + epName; if (epName == null) epName = extensionPoint.getQualifiedName().getStringValue(); if (epName == null) return; if (!epName.startsWith(epPrefix)) return; final DomExtension domExtension = registrar.registerCollectionChildrenExtension(new XmlName(epName.substring(epPrefix.length())), Extension.class); domExtension.setDeclaringElement(extensionPoint); domExtension.addExtender(EXTENSION_EXTENDER); }
private static void registerXmlb(final DomExtensionsRegistrar registrar, @Nullable final PsiClass beanClass, @NotNull List<With> elements) { if (beanClass == null) return; for (PsiField field : beanClass.getAllFields()) { registerField(registrar, field, findWithElement(elements, field)); } }
private static void registerCollectionBinding(PsiType type, DomExtensionsRegistrar registrar, PsiAnnotation anno, PsiConstantEvaluationHelper evalHelper) { final boolean surroundWithTag = getBooleanAttribute(anno, "surroundWithTag", evalHelper); if (surroundWithTag) return; // todo Set, List, Array final String tagName = getStringAttribute(anno, "elementTag", evalHelper); final String attrName = getStringAttribute(anno, "elementValueAttribute", evalHelper); final PsiType elementType = getElementType(type); if (elementType == null || TypeConversionUtil.isPrimitiveAndNotNullOrWrapper(elementType) || CommonClassNames.JAVA_LANG_STRING.equals(elementType.getCanonicalText()) || TypeConversionUtil.isEnumType(elementType)) { if (tagName != null && attrName == null) { registrar.registerCollectionChildrenExtension(new XmlName(tagName), SimpleTagValue.class); } else if (tagName != null) { registrar.registerCollectionChildrenExtension(new XmlName(tagName), DomElement.class).addExtender(new DomExtender() { @Override public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) { registrar.registerGenericAttributeValueChildExtension(new XmlName(attrName), String.class); } }); } } else { final PsiClass psiClass = PsiTypesUtil.getPsiClass(elementType); if (psiClass != null) { final PsiModifierList modifierList = psiClass.getModifierList(); final PsiAnnotation tagAnno = modifierList == null? null : modifierList.findAnnotation(Tag.class.getName()); final String classTagName = tagAnno == null? psiClass.getName() : getStringAttribute(tagAnno, "value", evalHelper); if (classTagName != null) { registrar.registerCollectionChildrenExtension(new XmlName(classTagName), DomElement.class).addExtender(new DomExtender() {
private static void addInternalAttribute(@NotNull DomExtensionsRegistrar registrar, Class clazz) { if (!ApplicationManager.getApplication().isInternal()) { return; } registrar.registerGenericAttributeValueChildExtension(new XmlName("internal"), clazz) .setConverter(BooleanValueConverter.getInstance(false)); }
private static void registerExtensionPoint(final DomExtensionsRegistrar registrar, final ExtensionPoint extensionPoint, String prefix, @Nullable String pluginId) { String epName = extensionPoint.getName().getStringValue(); if (epName != null && StringUtil.isNotEmpty(pluginId)) epName = pluginId + "." + epName; if (epName == null) epName = extensionPoint.getQualifiedName().getStringValue(); if (epName == null) return; if (!epName.startsWith(prefix)) return; final DomExtension domExtension = registrar.registerCollectionChildrenExtension(new XmlName(epName.substring(prefix.length())), Extension.class); domExtension.setDeclaringElement(extensionPoint); domExtension.addExtender(EXTENSION_EXTENDER); }
private static void registerCollectionBinding(PsiType type, DomExtensionsRegistrar registrar, PsiAnnotation anno, PsiConstantEvaluationHelper evalHelper) { final boolean surroundWithTag = getBooleanAttribute(anno, "surroundWithTag", evalHelper); if (surroundWithTag) return; // todo Set, List, Array final String tagName = getStringAttribute(anno, "elementTag", evalHelper); final String attrName = getStringAttribute(anno, "elementValueAttribute", evalHelper); final PsiClass psiClass = getElementType(type); if (tagName != null && attrName == null) { registrar.registerCollectionChildrenExtension(new XmlName(tagName), SimpleTagValue.class); } else if (tagName != null) { registrar.registerCollectionChildrenExtension(new XmlName(tagName), DomElement.class).addExtender(new DomExtender() { @Override public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) { registrar.registerGenericAttributeValueChildExtension(new XmlName(attrName), String.class); } }); } else if (psiClass != null) { final PsiModifierList modifierList = psiClass.getModifierList(); final PsiAnnotation tagAnno = modifierList == null? null : modifierList.findAnnotation(Tag.class.getName()); final String classTagName = tagAnno == null? psiClass.getName() : getStringAttribute(tagAnno, "value", evalHelper); if (classTagName != null) { registrar.registerCollectionChildrenExtension(new XmlName(classTagName), DomElement.class).addExtender(new DomExtender() {
@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; }
@Override public void registerExtensions(@NotNull final MyElement element, @NotNull final DomExtensionsRegistrar registrar) { final String value = element.getAttr().getValue(); if (value != null) { registrar.registerGenericAttributeValueChildExtension(new XmlName(value), Boolean.class); } }
@Override public void registerExtensions(@NotNull final MyElement element, @NotNull final DomExtensionsRegistrar registrar) { final String value = element.getAttr().getValue(); if (value != null) { registrar.registerGenericAttributeValueChildExtension(new XmlName(value), StringBuffer.class).setConverter(new StringBufferConverter(), true); registrar.registerGenericAttributeValueChildExtension(new XmlName("yyy"), StringBuffer.class).setConverter(new StringBufferConverter(), false); } }
@Override public void registerExtensions(@NotNull final MyElement element, @NotNull final DomExtensionsRegistrar registrar) { final String value = element.getAttr().getValue(); if (value != null) { registrar.registerAttributeChildExtension(new XmlName(value), MyAttribute.class).putUserData(BOOL_KEY, Boolean.TRUE); } }
@Override public void registerExtensions(@NotNull final MyElement element, @NotNull final DomExtensionsRegistrar registrar) { final String value = element.getAttr().getValue(); if (value != null) { registrar.registerCollectionChildrenExtension(new XmlName(value), MyElement.class).setConverter(new MyStringBufferConverter(true), true); } }
@Override public void registerExtensions(@NotNull Bar bar, @NotNull DomExtensionsRegistrar registrar) { registrar.registerAttributeChildExtension(new XmlName("extend"), Custom.class); }
@Override public void registerExtensions(@NotNull Action action, @NotNull DomExtensionsRegistrar registrar) { addInternalAttribute(registrar, Action.class); }
@Override public void registerExtensions(@NotNull Group group, @NotNull DomExtensionsRegistrar registrar) { addInternalAttribute(registrar, Group.class); registrar.registerGenericAttributeValueChildExtension(new XmlName("keep-content"), Group.class) .setConverter(BooleanValueConverter.getInstance(false)); }
@Override public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) { registerXmlb(registrar, psiClass, Collections.<With>emptyList()); }
@Override public void registerExtensions(@NotNull Group group, @NotNull DomExtensionsRegistrar registrar) { addInternalAttribute(registrar, Group.class); }
private static void defineAttributes(XmlTag xmlTag, DomExtensionsRegistrar registrar, DomGenericInfo genericInfo, AbstractIntrospector parentIntrospector) { final Map<String, Pair<Type, Class>> registeredAttribs = getStaticallyRegisteredAttributes(genericInfo); // define attributes discovered by introspector and not yet defined statically final Iterator<String> introspectedAttributes = parentIntrospector.getAttributesIterator(); while (introspectedAttributes.hasNext()) { final String attribName = introspectedAttributes.next(); if (genericInfo.getAttributeChildDescription(attribName) == null) { // if not defined yet final String _attribName = attribName.toLowerCase(Locale.US); final Pair<Type, Class> types = registeredAttribs.get(_attribName); Type type = types != null? types.getFirst() : null; Class converterClass = types != null ? types.getSecond() : null; if (type == null) { type = String.class; // use String by default final Class attributeType = parentIntrospector.getAttributeType(attribName); if (attributeType != null) { // handle well-known types if (File.class.isAssignableFrom(attributeType)) { type = PsiFileSystemItem.class; converterClass = AntPathConverter.class; } else if (Boolean.class.isAssignableFrom(attributeType)){ type = Boolean.class; converterClass = AntBooleanConverter.class; } else if (isAssignableFrom(ApacheAntClasses.Reference, attributeType)) { converterClass = AntDomRefIdConverter.class; } } } LOG.assertTrue(type != null); registerAttribute(registrar, attribName, type, converterClass); if (types == null) { // augment the map if this was a newly added attribute registeredAttribs.put(_attribName, new Pair<Type, Class>(type, converterClass)); } } } // handle attribute case problems: // additionaly register all attributes that exist in XML but differ from the registered ones only in case for (XmlAttribute xmlAttribute : xmlTag.getAttributes()) { final String existingAttribName = xmlAttribute.getName(); if (genericInfo.getAttributeChildDescription(existingAttribName) == null) { final Pair<Type, Class> pair = registeredAttribs.get(existingAttribName.toLowerCase(Locale.US)); if (pair != null) { // if such attribute should actually be here registerAttribute(registrar, existingAttribName, pair.getFirst(), pair.getSecond()); } } } }
@Override public void registerExtensions(@NotNull final MyCustomChildrenElement element, @NotNull final DomExtensionsRegistrar registrar) { assertEmpty(element.getCustomChidren()); registrar.registerCollectionChildrenExtension(new XmlName("xx"), MyDynamicElement.class); }
@Override public void registerExtensions(@NotNull final MyCustomChildrenElement element, @NotNull final DomExtensionsRegistrar registrar) { registrar.registerCollectionChildrenExtension(new XmlName("xx"), MyDynamicElement.class); }