use of com.intellij.util.xml.reflect.DomExtension 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.DomExtension in project intellij-community by JetBrains.
the class ExtensionDomExtender method registerExtensionPoint.
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);
}
use of com.intellij.util.xml.reflect.DomExtension 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);
}
use of com.intellij.util.xml.reflect.DomExtension in project android by JetBrains.
the class AttributeProcessingUtil method registerAttribute.
private static void registerAttribute(@NotNull AttributeDefinition attrDef, @Nullable String parentStyleableName, @Nullable String namespaceKey, @NotNull DomElement element, @NotNull AttributeProcessor callback) {
String name = attrDef.getName();
if (!NS_RESOURCES.equals(namespaceKey) && name.startsWith(PREFIX_ANDROID)) {
// A styleable-definition in the app namespace (user specified or from a library) can include
// a reference to a platform attribute. In such a case, register it under the android namespace
// as opposed to the app namespace. See https://code.google.com/p/android/issues/detail?id=171162
name = name.substring(PREFIX_ANDROID.length());
namespaceKey = NS_RESOURCES;
}
XmlName xmlName = new XmlName(name, namespaceKey);
final DomExtension extension = callback.processAttribute(xmlName, attrDef, parentStyleableName);
if (extension == null) {
return;
}
Converter converter = AndroidDomUtil.getSpecificConverter(xmlName, element);
if (converter == null) {
if (TOOLS_URI.equals(namespaceKey)) {
converter = ToolsAttributeUtil.getConverter(attrDef);
} else {
converter = AndroidDomUtil.getConverter(attrDef);
if (converter != null && element.getParentOfType(Manifest.class, true) != null) {
converter = new ManifestPlaceholderConverter(converter);
}
}
}
if (converter != null) {
extension.setConverter(converter, mustBeSoft(converter, attrDef.getFormats()));
}
// tag completion. If attribute is not required, no additional action is needed.
if (element instanceof LayoutElement && isLayoutAttributeRequired(xmlName, element) || element instanceof ManifestElement && AndroidManifestUtils.isRequiredAttribute(xmlName, element)) {
extension.addCustomAnnotation(new RequiredImpl());
}
}
use of com.intellij.util.xml.reflect.DomExtension in project android by JetBrains.
the class AttributeProcessingUtil method registerToolsAttribute.
private static void registerToolsAttribute(@NotNull String attributeName, @NotNull AttributeProcessor callback) {
final AttributeDefinition definition = ToolsAttributeUtil.getAttrDefByName(attributeName);
if (definition != null) {
final XmlName name = new XmlName(attributeName, TOOLS_URI);
final DomExtension domExtension = callback.processAttribute(name, definition, null);
final ResolvingConverter converter = ToolsAttributeUtil.getConverter(definition);
if (domExtension != null && converter != null) {
domExtension.setConverter(converter);
}
} else {
getLog().warn("No attribute definition for tools attribute " + attributeName);
}
}
Aggregations