diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java b/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java index d32b893aa4c4..0068cd464a17 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java @@ -180,9 +180,7 @@ public class PropertyParser { "paddingLeft", "left", "paddingTop", "top", "paddingRight", "right", - "paddingBottom", "bottom", - "paddingStart", "start", - "paddingEnd", "end"); + "paddingBottom", "bottom"); if (model != null) { paddingProperty.decorate(model); } diff --git a/plugins/android/src/org/jetbrains/android/dom/attrs/AttributeDefinitions.java b/plugins/android/src/org/jetbrains/android/dom/attrs/AttributeDefinitions.java index 9007ed6030e2..1f13832497eb 100644 --- a/plugins/android/src/org/jetbrains/android/dom/attrs/AttributeDefinitions.java +++ b/plugins/android/src/org/jetbrains/android/dom/attrs/AttributeDefinitions.java @@ -1,247 +1,23 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.jetbrains.android.dom.attrs; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiElement; -import com.intellij.psi.xml.XmlComment; -import com.intellij.psi.xml.XmlDocument; -import com.intellij.psi.xml.XmlFile; -import com.intellij.psi.xml.XmlTag; -import com.intellij.util.containers.HashMap; -import com.intellij.xml.util.XmlUtil; -import com.intellij.xml.util.documentation.XmlDocumentationProvider; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.Set; /** - * @author yole + * @author Eugene.Kudelevsky */ -public class AttributeDefinitions { - private static final Logger LOG = Logger.getInstance("#org.jetbrains.android.dom.attrs.AttributeDefinitions"); - - private Map myAttrs = new HashMap(); - private Map myStyleables = new HashMap(); - - private final List myStateStyleables = new ArrayList(); - private final Map> myEnumMap = new HashMap>(); - - public AttributeDefinitions() { - } - - public AttributeDefinitions(@NotNull XmlFile... files) { - for (XmlFile file : files) { - addAttrsFromFile(file); - } - } - - private void addAttrsFromFile(XmlFile file) { - Map parentMap = new HashMap(); - final XmlDocument document = file.getDocument(); - if (document == null) return; - final XmlTag rootTag = document.getRootTag(); - if (rootTag == null || !"resources".equals(rootTag.getName())) return; - for (XmlTag tag : rootTag.getSubTags()) { - String tagName = tag.getName(); - if (tagName.equals("attr")) { - parseAttrTag(tag); - } - else if (tagName.equals("declare-styleable")) { - parseDeclareStyleableTag(tag, parentMap); - } - } - - for (Map.Entry entry : parentMap.entrySet()) { - StyleableDefinition definition = entry.getKey(); - String[] parentNames = entry.getValue(); - for (String parentName : parentNames) { - StyleableDefinition parent = getStyleableByName(parentName); - if (parent != null) { - definition.addParent(parent); - parent.addChild(definition); - } - else { - LOG.info("Found tag with unknown parent: " + parentName); - } - } - } - } - +public interface AttributeDefinitions { @Nullable - private AttributeDefinition parseAttrTag(XmlTag tag) { - String name = tag.getAttributeValue("name"); - if (name == null) { - LOG.info("Found attr tag with no name: " + tag.getText()); - return null; - } - List parsedFormats; - List formats = new ArrayList(); - String format = tag.getAttributeValue("format"); - if (format != null) { - parsedFormats = parseAttrFormat(format); - if (parsedFormats != null) formats.addAll(parsedFormats); - } - XmlTag[] values = tag.findSubTags("enum"); - if (values.length > 0) { - formats.add(AttributeFormat.Enum); - } - else { - values = tag.findSubTags("flag"); - if (values.length > 0) { - formats.add(AttributeFormat.Flag); - } - } - AttributeDefinition def = myAttrs.get(name); - if (def == null) { - def = new AttributeDefinition(name); - myAttrs.put(def.getName(), def); - } - def.addFormats(formats); - parseDocComment(tag, def); - parseAndAddValues(def, values); - return def; - } - - private static void parseDocComment(XmlTag tag, AttributeDefinition def) { - PsiElement comment = XmlDocumentationProvider.findPreviousComment(tag); - if (comment != null) { - String docValue = XmlUtil.getCommentText((XmlComment)comment); - if (!StringUtil.isEmpty(docValue)) { - def.addDocValue(docValue); - } - } - } - - private static List parseAttrFormat(String formatString) { - List result = new ArrayList(); - final String[] formats = formatString.split("\\|"); - for (String format : formats) { - final AttributeFormat attributeFormat; - try { - attributeFormat = AttributeFormat.valueOf(StringUtil.capitalize(format)); - } - catch (IllegalArgumentException e) { - return null; - } - result.add(attributeFormat); - } - return result; - } - - private void parseAndAddValues(AttributeDefinition def, XmlTag[] values) { - for (XmlTag value : values) { - final String valueName = value.getAttributeValue("name"); - if (valueName == null) { - LOG.info("Unknown value for tag: " + value.getText()); - } - else { - def.addValue(valueName); - - final String strIntValue = value.getAttributeValue("value"); - if (strIntValue != null) { - try { - int intValue = strIntValue.startsWith("0x") - ? Integer.parseInt(strIntValue.substring(2), 16) - : Integer.parseInt(strIntValue); - Map value2Int = myEnumMap.get(def.getName()); - if (value2Int == null) { - value2Int = new HashMap(); - myEnumMap.put(def.getName(), value2Int); - } - value2Int.put(valueName, intValue); - } - catch (NumberFormatException ignored) { - } - } - } - } - } - - private void parseDeclareStyleableTag(XmlTag tag, Map parentMap) { - String name = tag.getAttributeValue("name"); - if (name == null) { - LOG.info("Found declare-styleable tag with no name: " + tag.getText()); - return; - } - StyleableDefinition def = new StyleableDefinition(name); - String parentNameAttributeValue = tag.getAttributeValue("parent"); - if (parentNameAttributeValue != null) { - String[] parentNames = parentNameAttributeValue.split("\\s+"); - parentMap.put(def, parentNames); - } - myStyleables.put(name, def); - - if (name.endsWith("State")) { - myStateStyleables.add(def); - } - - for (XmlTag subTag : tag.findSubTags("attr")) { - parseStyleableAttr(def, subTag); - } - } - - private void parseStyleableAttr(StyleableDefinition def, XmlTag tag) { - String name = tag.getAttributeValue("name"); - if (name == null) { - LOG.info("Found attr tag with no name: " + tag.getText()); - return; - } - - final AttributeDefinition attr = parseAttrTag(tag); - if (attr != null) { - def.addAttribute(attr); - } - } - - public void addStyleable(@NotNull StyleableDefinition styleable) { - myStyleables.put(styleable.getName(), styleable); - } - - public void addAttrDef(@NotNull AttributeDefinition attr) { - myAttrs.put(attr.getName(), attr); - } - - @Nullable - public StyleableDefinition getStyleableByName(@NotNull String name) { - return myStyleables.get(name); - } - - public Set getAttributeNames() { - return myAttrs.keySet(); - } - - @Nullable - public AttributeDefinition getAttrDefByName(@NotNull String name) { - return myAttrs.get(name); - } + StyleableDefinition getStyleableByName(@NotNull String name); @NotNull - public Set getStyleableNames() { - return myStyleables.keySet(); - } + Set getAttributeNames(); - public StyleableDefinition[] getStateStyleables() { - return myStateStyleables.toArray(new StyleableDefinition[myStateStyleables.size()]); - } + @Nullable + AttributeDefinition getAttrDefByName(@NotNull String name); @NotNull - public Map> getEnumMap() { - return myEnumMap; - } + StyleableDefinition[] getStateStyleables(); } diff --git a/plugins/android/src/org/jetbrains/android/dom/attrs/AttributeDefinitionsImpl.java b/plugins/android/src/org/jetbrains/android/dom/attrs/AttributeDefinitionsImpl.java new file mode 100644 index 000000000000..f800a49a164a --- /dev/null +++ b/plugins/android/src/org/jetbrains/android/dom/attrs/AttributeDefinitionsImpl.java @@ -0,0 +1,237 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.android.dom.attrs; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiElement; +import com.intellij.psi.xml.XmlComment; +import com.intellij.psi.xml.XmlDocument; +import com.intellij.psi.xml.XmlFile; +import com.intellij.psi.xml.XmlTag; +import com.intellij.util.containers.HashMap; +import com.intellij.xml.util.XmlUtil; +import com.intellij.xml.util.documentation.XmlDocumentationProvider; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; + +/** + * @author yole + */ +public class AttributeDefinitionsImpl implements AttributeDefinitions { + private static final Logger LOG = Logger.getInstance("#org.jetbrains.android.dom.attrs.AttributeDefinitionsImpl"); + + private Map myAttrs = new HashMap(); + private Map myStyleables = new HashMap(); + + private final List myStateStyleables = new ArrayList(); + private final Map> myEnumMap = new HashMap>(); + + public AttributeDefinitionsImpl(@NotNull XmlFile... files) { + for (XmlFile file : files) { + addAttrsFromFile(file); + } + } + + private void addAttrsFromFile(XmlFile file) { + Map parentMap = new HashMap(); + final XmlDocument document = file.getDocument(); + if (document == null) return; + final XmlTag rootTag = document.getRootTag(); + if (rootTag == null || !"resources".equals(rootTag.getName())) return; + for (XmlTag tag : rootTag.getSubTags()) { + String tagName = tag.getName(); + if (tagName.equals("attr")) { + parseAttrTag(tag); + } + else if (tagName.equals("declare-styleable")) { + parseDeclareStyleableTag(tag, parentMap); + } + } + + for (Map.Entry entry : parentMap.entrySet()) { + StyleableDefinitionImpl definition = entry.getKey(); + String[] parentNames = entry.getValue(); + for (String parentName : parentNames) { + StyleableDefinitionImpl parent = getStyleableByName(parentName); + if (parent != null) { + definition.addParent(parent); + parent.addChild(definition); + } + else { + LOG.info("Found tag with unknown parent: " + parentName); + } + } + } + } + + @Nullable + private AttributeDefinition parseAttrTag(XmlTag tag) { + String name = tag.getAttributeValue("name"); + if (name == null) { + LOG.info("Found attr tag with no name: " + tag.getText()); + return null; + } + List parsedFormats; + List formats = new ArrayList(); + String format = tag.getAttributeValue("format"); + if (format != null) { + parsedFormats = parseAttrFormat(format); + if (parsedFormats != null) formats.addAll(parsedFormats); + } + XmlTag[] values = tag.findSubTags("enum"); + if (values.length > 0) { + formats.add(AttributeFormat.Enum); + } + else { + values = tag.findSubTags("flag"); + if (values.length > 0) { + formats.add(AttributeFormat.Flag); + } + } + AttributeDefinition def = myAttrs.get(name); + if (def == null) { + def = new AttributeDefinition(name); + myAttrs.put(def.getName(), def); + } + def.addFormats(formats); + parseDocComment(tag, def); + parseAndAddValues(def, values); + return def; + } + + private static void parseDocComment(XmlTag tag, AttributeDefinition def) { + PsiElement comment = XmlDocumentationProvider.findPreviousComment(tag); + if (comment != null) { + String docValue = XmlUtil.getCommentText((XmlComment)comment); + if (!StringUtil.isEmpty(docValue)) { + def.addDocValue(docValue); + } + } + } + + private static List parseAttrFormat(String formatString) { + List result = new ArrayList(); + final String[] formats = formatString.split("\\|"); + for (String format : formats) { + final AttributeFormat attributeFormat; + try { + attributeFormat = AttributeFormat.valueOf(StringUtil.capitalize(format)); + } + catch (IllegalArgumentException e) { + return null; + } + result.add(attributeFormat); + } + return result; + } + + private void parseAndAddValues(AttributeDefinition def, XmlTag[] values) { + for (XmlTag value : values) { + final String valueName = value.getAttributeValue("name"); + if (valueName == null) { + LOG.info("Unknown value for tag: " + value.getText()); + } + else { + def.addValue(valueName); + + final String strIntValue = value.getAttributeValue("value"); + if (strIntValue != null) { + try { + int intValue = strIntValue.startsWith("0x") + ? Integer.parseInt(strIntValue.substring(2), 16) + : Integer.parseInt(strIntValue); + Map value2Int = myEnumMap.get(def.getName()); + if (value2Int == null) { + value2Int = new HashMap(); + myEnumMap.put(def.getName(), value2Int); + } + value2Int.put(valueName, intValue); + } + catch (NumberFormatException ignored) { + } + } + } + } + } + + private void parseDeclareStyleableTag(XmlTag tag, Map parentMap) { + String name = tag.getAttributeValue("name"); + if (name == null) { + LOG.info("Found declare-styleable tag with no name: " + tag.getText()); + return; + } + StyleableDefinitionImpl def = new StyleableDefinitionImpl(name); + String parentNameAttributeValue = tag.getAttributeValue("parent"); + if (parentNameAttributeValue != null) { + String[] parentNames = parentNameAttributeValue.split("\\s+"); + parentMap.put(def, parentNames); + } + myStyleables.put(name, def); + + if (name.endsWith("State")) { + myStateStyleables.add(def); + } + + for (XmlTag subTag : tag.findSubTags("attr")) { + parseStyleableAttr(def, subTag); + } + } + + private void parseStyleableAttr(StyleableDefinitionImpl def, XmlTag tag) { + String name = tag.getAttributeValue("name"); + if (name == null) { + LOG.info("Found attr tag with no name: " + tag.getText()); + return; + } + + final AttributeDefinition attr = parseAttrTag(tag); + if (attr != null) { + def.addAttribute(attr); + } + } + + @Override + @Nullable + public StyleableDefinitionImpl getStyleableByName(@NotNull String name) { + return myStyleables.get(name); + } + + @NotNull + @Override + public Set getAttributeNames() { + return myAttrs.keySet(); + } + + @Override + @Nullable + public AttributeDefinition getAttrDefByName(@NotNull String name) { + return myAttrs.get(name); + } + + @NotNull + @Override + public StyleableDefinition[] getStateStyleables() { + return myStateStyleables.toArray(new StyleableDefinition[myStateStyleables.size()]); + } + + @NotNull + public Map> getEnumMap() { + return myEnumMap; + } +} diff --git a/plugins/android/src/org/jetbrains/android/dom/attrs/StyleableDefinition.java b/plugins/android/src/org/jetbrains/android/dom/attrs/StyleableDefinition.java index 3e39eb3e9faf..53ece8a90332 100644 --- a/plugins/android/src/org/jetbrains/android/dom/attrs/StyleableDefinition.java +++ b/plugins/android/src/org/jetbrains/android/dom/attrs/StyleableDefinition.java @@ -1,68 +1,20 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.jetbrains.android.dom.attrs; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** - * @author yole, coyote + * @author Eugene.Kudelevsky */ -public class StyleableDefinition { - private final String myName; - private final List parents = new ArrayList(); - private final List myAttributes = new ArrayList(); - private final List children = new ArrayList(); - - public StyleableDefinition(@NotNull String name) { - myName = name; - } - - public void addChild(@NotNull StyleableDefinition child) { - children.add(child); - } - - public void addParent(@NotNull StyleableDefinition parent) { - parents.add(parent); - } +public interface StyleableDefinition { @NotNull - public List getParents() { - return parents; - } + List getChildren(); @NotNull - public List getChildren() { - return children; - } + String getName(); @NotNull - public String getName() { - return myName; - } - - public void addAttribute(@NotNull AttributeDefinition attrDef) { - myAttributes.add(attrDef); - } - - @NotNull - public List getAttributes() { - return Collections.unmodifiableList(myAttributes); - } + List getAttributes(); } diff --git a/plugins/android/src/org/jetbrains/android/dom/attrs/StyleableDefinitionImpl.java b/plugins/android/src/org/jetbrains/android/dom/attrs/StyleableDefinitionImpl.java new file mode 100644 index 000000000000..855f9c9f7c13 --- /dev/null +++ b/plugins/android/src/org/jetbrains/android/dom/attrs/StyleableDefinitionImpl.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.android.dom.attrs; + +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author yole, coyote + */ +public class StyleableDefinitionImpl implements StyleableDefinition { + private final String myName; + private final List myParents = new ArrayList(); + private final List myAttributes = new ArrayList(); + private final List myChildren = new ArrayList(); + + public StyleableDefinitionImpl(@NotNull String name) { + myName = name; + } + + public void addChild(@NotNull StyleableDefinition child) { + myChildren.add(child); + } + + public void addParent(@NotNull StyleableDefinition parent) { + myParents.add(parent); + } + + @NotNull + public List getParents() { + return myParents; + } + + @Override + @NotNull + public List getChildren() { + return myChildren; + } + + @Override + @NotNull + public String getName() { + return myName; + } + + public void addAttribute(@NotNull AttributeDefinition attrDef) { + myAttributes.add(attrDef); + } + + @Override + @NotNull + public List getAttributes() { + return Collections.unmodifiableList(myAttributes); + } +} diff --git a/plugins/android/src/org/jetbrains/android/resourceManagers/FilteredAttributeDefinitions.java b/plugins/android/src/org/jetbrains/android/resourceManagers/FilteredAttributeDefinitions.java new file mode 100644 index 000000000000..764055401ed7 --- /dev/null +++ b/plugins/android/src/org/jetbrains/android/resourceManagers/FilteredAttributeDefinitions.java @@ -0,0 +1,102 @@ +package org.jetbrains.android.resourceManagers; + +import com.intellij.util.containers.HashSet; +import org.jetbrains.android.dom.attrs.AttributeDefinition; +import org.jetbrains.android.dom.attrs.AttributeDefinitions; +import org.jetbrains.android.dom.attrs.StyleableDefinition; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * @author Eugene.Kudelevsky + */ +public abstract class FilteredAttributeDefinitions implements AttributeDefinitions { + private final AttributeDefinitions myWrappee; + + protected FilteredAttributeDefinitions(@NotNull AttributeDefinitions wrappee) { + myWrappee = wrappee; + } + + protected abstract boolean isAttributeAcceptable(@NotNull String name); + + @Nullable + @Override + public StyleableDefinition getStyleableByName(@NotNull String name) { + final StyleableDefinition styleable = myWrappee.getStyleableByName(name); + return styleable != null ? new MyStyleableDefinition(styleable) : null; + } + + @NotNull + @Override + public Set getAttributeNames() { + final Set result = new HashSet(); + + for (String name : myWrappee.getAttributeNames()) { + if (isAttributeAcceptable(name)) { + result.add(name); + } + } + return result; + } + + @Nullable + @Override + public AttributeDefinition getAttrDefByName(@NotNull String name) { + return isAttributeAcceptable(name) ? myWrappee.getAttrDefByName(name) : null; + } + + @NotNull + @Override + public StyleableDefinition[] getStateStyleables() { + final StyleableDefinition[] styleables = myWrappee.getStateStyleables(); + final StyleableDefinition[] result = new StyleableDefinition[styleables.length]; + + for (int i = 0; i < styleables.length; i++) { + result[i] = new MyStyleableDefinition(styleables[i]); + } + return result; + } + + private class MyStyleableDefinition implements StyleableDefinition { + private final StyleableDefinition myWrappee; + + private MyStyleableDefinition(@NotNull StyleableDefinition wrappee) { + myWrappee = wrappee; + } + + @NotNull + @Override + public List getChildren() { + final List styleables = myWrappee.getChildren(); + final List result = new ArrayList(styleables.size()); + + for (StyleableDefinition styleable : styleables) { + result.add(new MyStyleableDefinition(styleable)); + } + return result; + } + + @NotNull + @Override + public String getName() { + return myWrappee.getName(); + } + + @NotNull + @Override + public List getAttributes() { + final List result = new ArrayList(); + + for (AttributeDefinition definition : myWrappee.getAttributes()) { + if (isAttributeAcceptable(definition.getName())) { + result.add(definition); + } + } + return result; + } + } +} diff --git a/plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java b/plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java index 6549540335e9..acec22c53f36 100644 --- a/plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java +++ b/plugins/android/src/org/jetbrains/android/resourceManagers/LocalResourceManager.java @@ -37,6 +37,7 @@ import com.intellij.util.indexing.FileBasedIndex; import org.jetbrains.android.AndroidFileTemplateProvider; import org.jetbrains.android.AndroidValueResourcesIndex; import org.jetbrains.android.dom.attrs.AttributeDefinitions; +import org.jetbrains.android.dom.attrs.AttributeDefinitionsImpl; import org.jetbrains.android.dom.resources.Attr; import org.jetbrains.android.dom.resources.DeclareStyleable; import org.jetbrains.android.dom.resources.ResourceElement; @@ -181,7 +182,7 @@ public class LocalResourceManager extends ResourceManager { xmlResFiles.add((XmlFile)file); } } - myAttrDefs = new AttributeDefinitions(xmlResFiles.toArray(new XmlFile[xmlResFiles.size()])); + myAttrDefs = new AttributeDefinitionsImpl(xmlResFiles.toArray(new XmlFile[xmlResFiles.size()])); } }); } diff --git a/plugins/android/src/org/jetbrains/android/resourceManagers/SystemResourceManager.java b/plugins/android/src/org/jetbrains/android/resourceManagers/SystemResourceManager.java index 758fe234c1c9..6fb06630121f 100644 --- a/plugins/android/src/org/jetbrains/android/resourceManagers/SystemResourceManager.java +++ b/plugins/android/src/org/jetbrains/android/resourceManagers/SystemResourceManager.java @@ -15,6 +15,7 @@ */ package org.jetbrains.android.resourceManagers; +import com.android.resources.ResourceType; import com.android.sdklib.IAndroidTarget; import com.android.sdklib.SdkConstants; import com.intellij.openapi.application.ApplicationManager; @@ -117,6 +118,21 @@ public class SystemResourceManager extends ResourceManager { @Nullable public synchronized AttributeDefinitions getAttributeDefinitions() { final AndroidTargetData targetData = myPlatform.getSdkData().getTargetData(myPlatform.getTarget()); - return targetData != null ? targetData.getAttrDefs(myModule.getProject()) : null; + if (targetData == null) { + return null; + } + final AttributeDefinitions attrDefs = targetData.getAttrDefs(myModule.getProject()); + return attrDefs != null ? new MyAttributeDefinitions(attrDefs) : null; + } + + private class MyAttributeDefinitions extends FilteredAttributeDefinitions { + protected MyAttributeDefinitions(@NotNull AttributeDefinitions wrappee) { + super(wrappee); + } + + @Override + protected boolean isAttributeAcceptable(@NotNull String name) { + return isResourcePublic(ResourceType.ATTR.getName(), name); + } } } diff --git a/plugins/android/src/org/jetbrains/android/sdk/AndroidTargetData.java b/plugins/android/src/org/jetbrains/android/sdk/AndroidTargetData.java index 9102cd4f0ec0..2c110d6c12d4 100644 --- a/plugins/android/src/org/jetbrains/android/sdk/AndroidTargetData.java +++ b/plugins/android/src/org/jetbrains/android/sdk/AndroidTargetData.java @@ -17,7 +17,7 @@ import com.intellij.psi.XmlRecursiveElementVisitor; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.containers.HashSet; -import org.jetbrains.android.dom.attrs.AttributeDefinitions; +import org.jetbrains.android.dom.attrs.AttributeDefinitionsImpl; import org.jetbrains.android.facet.AndroidFacet; import org.jetbrains.android.resourceManagers.SystemResourceManager; import org.jetbrains.android.uipreview.RenderServiceFactory; @@ -37,7 +37,7 @@ public class AndroidTargetData { private final AndroidSdkData mySdkData; private final IAndroidTarget myTarget; - private volatile AttributeDefinitions myAttrDefs; + private volatile AttributeDefinitionsImpl myAttrDefs; private volatile RenderServiceFactory myRenderServiceFactory; private volatile Set myThemes; private volatile boolean myThemesLoaded; @@ -48,7 +48,7 @@ public class AndroidTargetData { } @Nullable - public AttributeDefinitions getAttrDefs(@NotNull final Project project) { + public AttributeDefinitionsImpl getAttrDefs(@NotNull final Project project) { if (myAttrDefs == null) { ApplicationManager.getApplication().runReadAction(new Runnable() { @Override @@ -57,7 +57,7 @@ public class AndroidTargetData { final String attrsManifestPath = myTarget.getPath(IAndroidTarget.MANIFEST_ATTRIBUTES); final XmlFile[] files = findXmlFiles(project, attrsPath, attrsManifestPath); if (files != null) { - myAttrDefs = new AttributeDefinitions(files); + myAttrDefs = new AttributeDefinitionsImpl(files); } } }); @@ -68,7 +68,7 @@ public class AndroidTargetData { @Nullable public RenderServiceFactory getRenderServiceFactory(@NotNull Project project) throws RenderingException, IOException { if (myRenderServiceFactory == null) { - final AttributeDefinitions attrDefs = getAttrDefs(project); + final AttributeDefinitionsImpl attrDefs = getAttrDefs(project); if (attrDefs == null) { return null; } diff --git a/plugins/android/testData/dom/drawable/animatedRotateCompletion1.xml b/plugins/android/testData/dom/drawable/animatedRotateCompletion1.xml index bc8f02638f24..5f808584e858 100644 --- a/plugins/android/testData/dom/drawable/animatedRotateCompletion1.xml +++ b/plugins/android/testData/dom/drawable/animatedRotateCompletion1.xml @@ -1,4 +1,4 @@ /> \ No newline at end of file + android:visib/> \ No newline at end of file diff --git a/plugins/android/testData/dom/drawable/animatedRotateCompletion1_after.xml b/plugins/android/testData/dom/drawable/animatedRotateCompletion1_after.xml index 5c4384a19d06..dca93dd5f841 100644 --- a/plugins/android/testData/dom/drawable/animatedRotateCompletion1_after.xml +++ b/plugins/android/testData/dom/drawable/animatedRotateCompletion1_after.xml @@ -1,4 +1,4 @@ \ No newline at end of file + android:visible=""/> \ No newline at end of file diff --git a/plugins/android/testData/dom/drawable/animatedRotateHighlighting1.xml b/plugins/android/testData/dom/drawable/animatedRotateHighlighting1.xml index 1148432c8556..98d17c05eeda 100644 --- a/plugins/android/testData/dom/drawable/animatedRotateHighlighting1.xml +++ b/plugins/android/testData/dom/drawable/animatedRotateHighlighting1.xml @@ -3,6 +3,4 @@ \ No newline at end of file + android:pivotY="50%"/> \ No newline at end of file diff --git a/plugins/android/testData/dom/layout/privateAttributesCompletion.xml b/plugins/android/testData/dom/layout/privateAttributesCompletion.xml new file mode 100644 index 000000000000..288540e6fe04 --- /dev/null +++ b/plugins/android/testData/dom/layout/privateAttributesCompletion.xml @@ -0,0 +1,5 @@ +> + \ No newline at end of file diff --git a/plugins/android/testData/dom/layout/privateAttributesCompletion_after.xml b/plugins/android/testData/dom/layout/privateAttributesCompletion_after.xml new file mode 100644 index 000000000000..0ec666dba3fd --- /dev/null +++ b/plugins/android/testData/dom/layout/privateAttributesCompletion_after.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/plugins/android/testData/dom/layout/privateAttributesHighlighting.xml b/plugins/android/testData/dom/layout/privateAttributesHighlighting.xml new file mode 100644 index 000000000000..680b2ee73239 --- /dev/null +++ b/plugins/android/testData/dom/layout/privateAttributesHighlighting.xml @@ -0,0 +1,5 @@ +android:paddingStart=""> + \ No newline at end of file diff --git a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java index 9352d6db7d82..229f9af2442b 100644 --- a/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java +++ b/plugins/android/testSrc/org/jetbrains/android/dom/AndroidLayoutDomTest.java @@ -663,6 +663,14 @@ public class AndroidLayoutDomTest extends AndroidDomTest { doTestHighlighting(); } + public void testPrivateAttributesCompletion() throws Throwable { + doTestCompletion(); + } + + public void testPrivateAttributesHighlighting() throws Throwable { + doTestHighlighting(); + } + public void testAttrReferences1() throws Throwable { copyFileToProject("attrReferences_attrs.xml", "res/values/attrReferences_attrs.xml"); doTestHighlighting();