use of com.intellij.util.xml.reflect.DomExtender in project intellij-community by JetBrains.
the class ExtensionDomExtender method registerField.
private static void registerField(final DomExtensionsRegistrar registrar, @NotNull final PsiField field, With withElement) {
final PsiMethod getter = PropertyUtil.findGetterForField(field);
final PsiMethod setter = PropertyUtil.findSetterForField(field);
if (!field.hasModifierProperty(PsiModifier.PUBLIC) && (getter == null || setter == null)) {
return;
}
final String fieldName = field.getName();
final PsiConstantEvaluationHelper evalHelper = JavaPsiFacade.getInstance(field.getProject()).getConstantEvaluationHelper();
final PsiAnnotation attrAnno = findAnnotation(Attribute.class, field, getter, setter);
if (attrAnno != null) {
final String attrName = getStringAttribute(attrAnno, "value", evalHelper);
if (attrName != null) {
Class clazz = String.class;
if (withElement != null || isClassField(fieldName)) {
clazz = PsiClass.class;
} else if (PsiType.BOOLEAN.equals(field.getType())) {
clazz = Boolean.class;
}
final DomExtension extension = registrar.registerGenericAttributeValueChildExtension(new XmlName(attrName), clazz).setDeclaringElement(field);
markAsClass(extension, fieldName, withElement);
if (clazz.equals(String.class)) {
markAsLanguage(extension, fieldName);
}
}
return;
}
final PsiAnnotation tagAnno = findAnnotation(Tag.class, field, getter, setter);
final PsiAnnotation propAnno = findAnnotation(Property.class, field, getter, setter);
final PsiAnnotation absColAnno = findAnnotation(AbstractCollection.class, field, getter, setter);
//final PsiAnnotation colAnno = modifierList.findAnnotation(Collection.class.getName()); // todo
final String tagName = tagAnno != null ? getStringAttribute(tagAnno, "value", evalHelper) : propAnno != null && getBooleanAttribute(propAnno, "surroundWithTag", evalHelper) ? Constants.OPTION : null;
if (tagName != null) {
if (absColAnno == null) {
final DomExtension extension = registrar.registerFixedNumberChildExtension(new XmlName(tagName), SimpleTagValue.class).setDeclaringElement(field);
markAsClass(extension, fieldName, withElement);
} else {
registrar.registerFixedNumberChildExtension(new XmlName(tagName), DomElement.class).addExtender(new DomExtender() {
@Override
public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) {
registerCollectionBinding(field.getType(), registrar, absColAnno, evalHelper);
}
});
}
} else if (absColAnno != null) {
registerCollectionBinding(field.getType(), registrar, absColAnno, evalHelper);
}
}
use of com.intellij.util.xml.reflect.DomExtender in project intellij-community by JetBrains.
the class ExtensionDomExtender method registerCollectionBinding.
private static void registerCollectionBinding(PsiType type, DomExtensionsRegistrar registrar, PsiAnnotation anno, PsiConstantEvaluationHelper evalHelper) {
final boolean surroundWithTag = getBooleanAttribute(anno, "surroundWithTag", evalHelper);
// todo Set, List, Array
if (surroundWithTag)
return;
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() {
@Override
public void registerExtensions(@NotNull DomElement domElement, @NotNull DomExtensionsRegistrar registrar) {
registerXmlb(registrar, psiClass, Collections.<With>emptyList());
}
});
}
}
}
}
use of com.intellij.util.xml.reflect.DomExtender in project intellij-community by JetBrains.
the class MavenPluginConfigurationDomExtender method registerPluginParameter.
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);
}
Aggregations