//////////////////////////////////////////////////////////////////////////// // // IDescriptionProcessor // //////////////////////////////////////////////////////////////////////////// public void process(EditorContext context, ComponentDescription componentDescription) throws Exception { if (isAndroid(context)) { // remove java-based properties List<GenericPropertyDescription> properties = componentDescription.getProperties(); for (GenericPropertyDescription property : properties) { if (!(property.getAccessor() instanceof AndroidExpressionAccessor)) { // looks like this is unknown property, remove it // removing the editor removes the property from description property.setEditor(null); } IAttributeInfo attribute = (IAttributeInfo) property.getArbitraryValue(IPropertiesConstants.KEY_ATTRIBUTE); if (attribute != null) { // setup default value if no getter found and default value is not yet set in description AndroidExpressionAccessor accessor = (AndroidExpressionAccessor) property.getAccessor(); if (!accessor.hasGetter() && Property.UNKNOWN_VALUE == property.getDefaultValue()) { setupDefaultValue(property, attribute.getFormats()); } } // promote 'id' property category to system String ns = (String) property.getArbitraryValue(IPropertiesConstants.KEY_ATTRIBUTE_NAMESPACE_URI); String localName = (String) property.getArbitraryValue(IPropertiesConstants.KEY_ATTRIBUTE_LOCAL_NAME); if (LayoutConstants.ATTR_ID.equals(localName) && SdkConstants.NS_RESOURCES.equals(ns)) { property.setCategory(PropertyCategory.system(9)); } } } }
private static boolean canBeExtracted(@NotNull XmlAttribute attribute) { if (!(SdkConstants.NS_RESOURCES.equals(attribute.getNamespace()))) { return false; } final String name = attribute.getLocalName(); if (ArrayUtil.find(NON_EXTRACTABLE_ATTRIBUTES, name) >= 0) { return false; } if (name.startsWith(AndroidDomUtil.ATTR_STYLE)) { return false; } return true; }
private static void inlineSingleTag( XmlTag includeTag, XmlTag includeParentTag, XmlTag layoutRootTag) { final Map<String, String> attributesToAdd = new HashMap<String, String>(); for (XmlAttribute attribute : includeTag.getAttributes()) { final String namespace = attribute.getNamespace(); if (SdkConstants.NS_RESOURCES.equals(namespace)) { attributesToAdd.put(attribute.getLocalName(), attribute.getValue()); } } final XmlTag newTag = (XmlTag) includeTag.replace(layoutRootTag.copy()); final List<XmlAttribute> toDelete = new ArrayList<XmlAttribute>(); for (XmlAttribute attribute : newTag.getAttributes()) { if (attribute.isNamespaceDeclaration()) { final String localName = attribute.getLocalName(); final String prefix = localName.equals(attribute.getName()) ? "" : localName; final String namespace = attribute.getValue(); if (includeParentTag != null && namespace.equals(includeParentTag.getNamespaceByPrefix(prefix))) { toDelete.add(attribute); } } } for (XmlAttribute attribute : toDelete) { attribute.delete(); } for (Map.Entry<String, String> entry : attributesToAdd.entrySet()) { final String localName = entry.getKey(); final String value = entry.getValue(); newTag.setAttribute(localName, SdkConstants.NS_RESOURCES, value); } CodeStyleManager.getInstance(newTag.getManager()).reformat(newTag); }