mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-25622 full support for completion/highlighting in drawable xml files
This commit is contained in:
@@ -61,10 +61,13 @@
|
||||
<errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.drawable.DrawableStateListDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.drawable.BitmapOrNinePatchDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.drawable.LayerListDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.drawable.LevelListDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.drawable.InsetOrClipOrScaleDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.drawable.ShapeDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.color.ColorDomFileDescription"/>
|
||||
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.manifest.ManifestDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.drawable.DrawableDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.layout.LayoutDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.animation.AnimationDomFileDescription"/>
|
||||
<dom.fileDescription implementation="org.jetbrains.android.dom.menu.MenuDomFileDescription"/>
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.util.AndroidUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -84,10 +85,12 @@ public class AndroidCompletionContributor extends CompletionContributor {
|
||||
addAll(AndroidXmlResourcesUtil.getPossibleRoots(facet), resultSet);
|
||||
return false;
|
||||
}
|
||||
else if (AndroidDrawableDomUtil.isDrawableResourceFile(xmlFile) ||
|
||||
ColorDomFileDescription.isColorResourceFile(xmlFile)) {
|
||||
else if (AndroidDrawableDomUtil.isDrawableResourceFile(xmlFile)) {
|
||||
addAll(AndroidDrawableDomUtil.getPossibleRoots(), resultSet);
|
||||
}
|
||||
else if (ColorDomFileDescription.isColorResourceFile(xmlFile)) {
|
||||
addAll(Arrays.asList(DrawableStateListDomFileDescription.SELECTOR_TAG_NAME), resultSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,12 +100,16 @@ public class AndroidDomExtender extends DomExtender<AndroidDomElement> {
|
||||
String... skipNames) {
|
||||
Set<String> skippedAttrSet = new HashSet<String>();
|
||||
Collections.addAll(skippedAttrSet, skipNames);
|
||||
XmlAttribute[] existingAttrs = element.getXmlTag().getAttributes();
|
||||
for (XmlAttribute attr : existingAttrs) {
|
||||
if (attr.getNamespace().equals(namespace)) {
|
||||
skippedAttrSet.add(attr.getLocalName());
|
||||
|
||||
if (!shouldValidateAttributes(element)) {
|
||||
XmlAttribute[] existingAttrs = element.getXmlTag().getAttributes();
|
||||
for (XmlAttribute attr : existingAttrs) {
|
||||
if (attr.getNamespace().equals(namespace)) {
|
||||
skippedAttrSet.add(attr.getLocalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (StyleableDefinition styleable : styleables) {
|
||||
for (AttributeDefinition attrDef : styleable.getAttributes()) {
|
||||
String attrName = attrDef.getName();
|
||||
@@ -117,6 +121,10 @@ public class AndroidDomExtender extends DomExtender<AndroidDomElement> {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldValidateAttributes(DomElement element) {
|
||||
return element instanceof DrawableDomElement;
|
||||
}
|
||||
|
||||
private static boolean mustBeSoft(@NotNull Converter converter, Collection<AttributeFormat> formats) {
|
||||
if (converter instanceof CompositeConverter || converter instanceof ResourceReferenceConverter) {
|
||||
return false;
|
||||
@@ -494,7 +502,11 @@ public class AndroidDomExtender extends DomExtender<AndroidDomElement> {
|
||||
AndroidFacet facet = AndroidFacet.getInstance(element);
|
||||
if (facet == null) return;
|
||||
XmlTag tag = element.getXmlTag();
|
||||
registerExistingAttributes(facet, tag, registrar, element);
|
||||
|
||||
if (!shouldValidateAttributes(element)) {
|
||||
registerExistingAttributes(facet, tag, registrar, element);
|
||||
}
|
||||
|
||||
String tagName = tag.getName();
|
||||
Set<String> registeredSubtags = new HashSet<String>();
|
||||
if (element instanceof ManifestElement) {
|
||||
@@ -517,13 +529,13 @@ public class AndroidDomExtender extends DomExtender<AndroidDomElement> {
|
||||
registerExtensionsForXmlResources(facet, tagName, (XmlResourceElement)element, registrar, registeredSubtags);
|
||||
}
|
||||
else if (element instanceof DrawableDomElement || element instanceof ColorDomElement) {
|
||||
registerExtensionsForStateList(facet, tagName, element, registrar);
|
||||
registerExtensionsForDrawable(facet, tagName, element, registrar);
|
||||
}
|
||||
Collections.addAll(registeredSubtags, AndroidDomUtil.getStaticallyDefinedSubtags(element));
|
||||
|
||||
if (!(element instanceof LayoutElement) &&
|
||||
!(element instanceof ColorDomElement) &&
|
||||
(!(element instanceof DrawableDomElement) || element instanceof UnknownDrawableDomElement)) {
|
||||
!(element instanceof DrawableDomElement)) {
|
||||
Processor<String> existingSubtagsFilter = element instanceof XmlResourceElement ?
|
||||
new Processor<String>() {
|
||||
public boolean process(String s) {
|
||||
@@ -534,10 +546,10 @@ public class AndroidDomExtender extends DomExtender<AndroidDomElement> {
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerExtensionsForStateList(AndroidFacet facet,
|
||||
String tagName,
|
||||
AndroidDomElement element,
|
||||
DomExtensionsRegistrar registrar) {
|
||||
private static void registerExtensionsForDrawable(AndroidFacet facet,
|
||||
String tagName,
|
||||
AndroidDomElement element,
|
||||
DomExtensionsRegistrar registrar) {
|
||||
final String specialStyleableName = AndroidDrawableDomUtil.SPECIAL_STYLEABLE_NAMES.get(tagName);
|
||||
if (specialStyleableName != null) {
|
||||
registerAttributes(facet, element, specialStyleableName, SYSTEM_RESOURCE_PACKAGE, registrar);
|
||||
@@ -551,6 +563,12 @@ public class AndroidDomExtender extends DomExtender<AndroidDomElement> {
|
||||
registerAttributes(facet, element, attrDefs.getStateStyleables(), SYSTEM_RESOURCE_PACKAGE, registrar, null);
|
||||
}
|
||||
}
|
||||
else if (element instanceof LayerListItem) {
|
||||
registerAttributes(facet, element, "LayerDrawableItem", SYSTEM_RESOURCE_PACKAGE, registrar);
|
||||
}
|
||||
else if (element instanceof LevelListItem) {
|
||||
registerAttributes(facet, element, "LevelListDrawableItem", SYSTEM_RESOURCE_PACKAGE, registrar);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -29,12 +29,25 @@ import java.util.Map;
|
||||
*/
|
||||
public class AndroidDrawableDomUtil {
|
||||
public static final Map<String, String> SPECIAL_STYLEABLE_NAMES = new HashMap<String, String>();
|
||||
private static final String[] POSSIBLE_DRAWABLE_ROOTS = new String[] {"selector", "bitmap", "nine-patch"};
|
||||
private static final String[] POSSIBLE_DRAWABLE_ROOTS =
|
||||
new String[]{"selector", "bitmap", "nine-patch", "layer-list", "level-list", "transition", "inset", "clip", "scale", "shape"};
|
||||
|
||||
static {
|
||||
SPECIAL_STYLEABLE_NAMES.put("selector", "StateListDrawable");
|
||||
SPECIAL_STYLEABLE_NAMES.put("bitmap", "BitmapDrawable");
|
||||
SPECIAL_STYLEABLE_NAMES.put("nine-patch", "NinePatchDrawable");
|
||||
SPECIAL_STYLEABLE_NAMES.put("layer-list", "LayerDrawable");
|
||||
SPECIAL_STYLEABLE_NAMES.put("inset", "InsetDrawable");
|
||||
SPECIAL_STYLEABLE_NAMES.put("clip", "ClipDrawable");
|
||||
SPECIAL_STYLEABLE_NAMES.put("scale", "ScaleDrawable");
|
||||
|
||||
SPECIAL_STYLEABLE_NAMES.put("shape", "GradientDrawable");
|
||||
SPECIAL_STYLEABLE_NAMES.put("corners", "DrawableCorners");
|
||||
SPECIAL_STYLEABLE_NAMES.put("gradient", "GradientDrawableGradient");
|
||||
SPECIAL_STYLEABLE_NAMES.put("padding", "GradientDrawablePadding");
|
||||
SPECIAL_STYLEABLE_NAMES.put("size", "GradientDrawableSize");
|
||||
SPECIAL_STYLEABLE_NAMES.put("solid", "GradientDrawableSolid");
|
||||
SPECIAL_STYLEABLE_NAMES.put("stroke", "GradientDrawableStroke");
|
||||
}
|
||||
|
||||
private AndroidDrawableDomUtil() {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.drawable;
|
||||
|
||||
import com.intellij.util.xml.Convert;
|
||||
import com.intellij.util.xml.DefinesXml;
|
||||
import com.intellij.util.xml.Required;
|
||||
import org.jetbrains.android.dom.AndroidAttributeValue;
|
||||
import org.jetbrains.android.dom.ResourceType;
|
||||
import org.jetbrains.android.dom.converters.ResourceReferenceConverter;
|
||||
import org.jetbrains.android.dom.resources.ResourceValue;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
@DefinesXml
|
||||
public interface InsetOrClipOrScale extends DrawableDomElement {
|
||||
@Convert(ResourceReferenceConverter.class)
|
||||
@Required
|
||||
@ResourceType("drawable")
|
||||
AndroidAttributeValue<ResourceValue> getDrawable();
|
||||
}
|
||||
+9
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.android.dom.drawable;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -21,20 +20,19 @@ import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.android.dom.AndroidResourceDomFileDescription;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: Eugene.Kudelevsky
|
||||
* Date: Aug 21, 2009
|
||||
* Time: 9:42:38 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class DrawableDomFileDescription extends AndroidResourceDomFileDescription<UnknownDrawableDomElement> {
|
||||
public class InsetOrClipOrScaleDomFileDescription extends AndroidResourceDomFileDescription<InsetOrClipOrScale> {
|
||||
|
||||
public DrawableDomFileDescription() {
|
||||
super(UnknownDrawableDomElement.class, "shape", "bitmap", "nine-patch", "drawable");
|
||||
@NonNls private static final String[] ROOT_TAGS = new String[] {"inset", "clip", "scale"};
|
||||
|
||||
public InsetOrClipOrScaleDomFileDescription() {
|
||||
super(InsetOrClipOrScale.class, ROOT_TAGS[0], "drawable");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,8 +51,6 @@ public class DrawableDomFileDescription extends AndroidResourceDomFileDescriptio
|
||||
return false;
|
||||
}
|
||||
|
||||
final String rootTagName = rootTag.getName();
|
||||
return !DrawableStateListDomFileDescription.SELECTOR_TAG_NAME.equals(rootTagName) &&
|
||||
ArrayUtil.find(BitmapOrNinePatchDomFileDescription.ROOT_TAG_NAMES, rootTag) < 0;
|
||||
return ArrayUtil.find(ROOT_TAGS, rootTag.getName()) >= 0;
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -17,9 +17,12 @@ package org.jetbrains.android.dom.drawable;
|
||||
|
||||
import com.intellij.util.xml.DefinesXml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
@DefinesXml
|
||||
public interface UnknownDrawableDomElement extends DrawableDomElement {
|
||||
public interface LayerList extends DrawableDomElement {
|
||||
List<LayerListItem> getItems();
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.drawable;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.android.dom.AndroidResourceDomFileDescription;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class LayerListDomFileDescription extends AndroidResourceDomFileDescription<LayerList> {
|
||||
@NonNls static final String[] POSSIBLE_ROOT_TAGS = {"layer-list", "transition"};
|
||||
|
||||
public LayerListDomFileDescription() {
|
||||
super(LayerList.class, POSSIBLE_ROOT_TAGS[0], "drawable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsOtherRootTagNames() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) {
|
||||
if (!super.isMyFile(file, module)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final XmlTag rootTag = file.getRootTag();
|
||||
if (rootTag == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ArrayUtil.find(POSSIBLE_ROOT_TAGS, rootTag.getName()) >= 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.drawable;
|
||||
|
||||
import com.intellij.util.xml.Convert;
|
||||
import org.jetbrains.android.dom.AndroidAttributeValue;
|
||||
import org.jetbrains.android.dom.ResourceType;
|
||||
import org.jetbrains.android.dom.converters.ResourceReferenceConverter;
|
||||
import org.jetbrains.android.dom.resources.ResourceValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public interface LayerListItem extends DrawableDomElement {
|
||||
@Convert(ResourceReferenceConverter.class)
|
||||
@ResourceType("drawable")
|
||||
AndroidAttributeValue<ResourceValue> getDrawable();
|
||||
|
||||
List<BitmapOrNinePatchElement> getBitmaps();
|
||||
}
|
||||
+8
-7
@@ -13,15 +13,16 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.android.dom.drawable;
|
||||
|
||||
import com.intellij.util.xml.DefinesXml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: Eugene.Kudelevsky
|
||||
* Date: Aug 22, 2009
|
||||
* Time: 1:36:56 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public interface DrawableStateListElement extends DrawableDomElement {
|
||||
@DefinesXml
|
||||
public interface LevelList extends DrawableDomElement {
|
||||
List<LevelListItem> getItems();
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.drawable;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import org.jetbrains.android.dom.AndroidResourceDomFileDescription;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class LevelListDomFileDescription extends AndroidResourceDomFileDescription<LevelList> {
|
||||
@NonNls static final String LEVEL_LIST_TAG = "level-list";
|
||||
|
||||
public LevelListDomFileDescription() {
|
||||
super(LevelList.class, LEVEL_LIST_TAG, "drawable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) {
|
||||
if (!super.isMyFile(file, module)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final XmlTag rootTag = file.getRootTag();
|
||||
if (rootTag == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return LEVEL_LIST_TAG.equals(rootTag.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.drawable;
|
||||
|
||||
import com.intellij.util.xml.Convert;
|
||||
import com.intellij.util.xml.Required;
|
||||
import org.jetbrains.android.dom.AndroidAttributeValue;
|
||||
import org.jetbrains.android.dom.ResourceType;
|
||||
import org.jetbrains.android.dom.converters.ResourceReferenceConverter;
|
||||
import org.jetbrains.android.dom.resources.ResourceValue;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public interface LevelListItem extends DrawableDomElement {
|
||||
@Convert(ResourceReferenceConverter.class)
|
||||
@ResourceType("drawable")
|
||||
@Required
|
||||
AndroidAttributeValue<ResourceValue> getDrawable();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.drawable;
|
||||
|
||||
import com.intellij.util.xml.DefinesXml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
@DefinesXml
|
||||
public interface Shape extends DrawableDomElement {
|
||||
List<DrawableDomElement> getCornerss();
|
||||
List<DrawableDomElement> getGradients();
|
||||
List<DrawableDomElement> getPaddings();
|
||||
List<DrawableDomElement> getSizes();
|
||||
List<DrawableDomElement> getSolids();
|
||||
List<DrawableDomElement> getStrokes();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.drawable;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import org.jetbrains.android.dom.AndroidResourceDomFileDescription;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class ShapeDomFileDescription extends AndroidResourceDomFileDescription<Shape> {
|
||||
@NonNls static final String SHAPE_ROOT_TAG = "shape";
|
||||
|
||||
public ShapeDomFileDescription() {
|
||||
super(Shape.class, SHAPE_ROOT_TAG, "drawable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsOtherRootTagNames() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMyFile(@NotNull XmlFile file, @Nullable Module module) {
|
||||
if (!super.isMyFile(file, module)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final XmlTag rootTag = file.getRootTag();
|
||||
if (rootTag == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return SHAPE_ROOT_TAG.equals(rootTag.getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<<caret>
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/myDrawable" <error>android:aba</error>="" />
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<clip xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:clipOrien<caret>/>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<clip xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:clipOrientation=""/>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<clip xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@<caret>"/>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<clip xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="<error>@drawable/myDrawa</error>"
|
||||
android:clipOrientation="horizontal"
|
||||
android:gravity="left" <error>android:aba</error>=""/>
|
||||
@@ -0,0 +1,3 @@
|
||||
<<error>resources</error>>
|
||||
|
||||
</<error>resources</error>>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:insetLe<caret>/>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:insetLeft=""/>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@<caret>"/>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@drawable/myDrawable"
|
||||
android:insetTop="10dp"
|
||||
android:insetLeft="10dp" <error>android:aba</error>=""/>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<<error>inset</error> xmlns:android="http://schemas.android.com/apk/res/android"/>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item lef<caret>/>
|
||||
</layer-list>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:left=""/>
|
||||
</layer-list>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@<caret>"/>
|
||||
</layer-list>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap android:src="@drawable/android_red"
|
||||
android:grav<caret>/>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap android:src="@drawable/android_red"
|
||||
android:gravity=""/>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap android:src="@drawable/myDrawable"
|
||||
android:gravity="center"/>
|
||||
</item>
|
||||
<item android:top="10dp" android:left="10dp">
|
||||
<bitmap android:src="<error>@drawable/aba</error>"
|
||||
android:gravity="center"/>
|
||||
</item>
|
||||
<item android:drawable="@drawable/myDrawable"/>
|
||||
<item android:drawable="<error>@drawable/aba</error>"/>
|
||||
<item>
|
||||
<bitmap android:src="@drawable/myDrawable"
|
||||
android:gravity="center"/>
|
||||
</item>
|
||||
</layer-list>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@<caret>"/>
|
||||
</level-list>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ite<caret>
|
||||
</level-list>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
</level-list>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:maxLev<caret>/>
|
||||
</level-list>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:maxLevel=""/>
|
||||
</level-list>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/myDrawable"/>
|
||||
<item android:drawable="<error>@drawable/aba</error>" android:maxLevel="1"/>
|
||||
<<error>item</error>/>
|
||||
</level-list>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<scale xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:scaleGravity="center_vertical|center_horiz<caret>"/>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<scale xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:scaleGravity="center_vertical|center_horizontal"/>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<scale xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@<caret>"/>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<scale xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="@drawable/myDrawable"
|
||||
android:scaleGravity="center_vertical|center_horizontal"
|
||||
<error>android:aba</error>=""/>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<scale xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:drawable="<error>@drawable/myDrawab</error>"
|
||||
<error>android:aba</error>=""/>
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<<error>scale</error> xmlns:android="http://schemas.android.com/apk/res/android"/>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:sha<caret>/>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape=""/>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<<caret>
|
||||
</shape>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:startColor="#FFFF0000"
|
||||
android:endColor="#80FF00FF"
|
||||
android:angle="45"/>
|
||||
<padding android:left="7dp"
|
||||
android:top="7dp"
|
||||
android:right="7dp"
|
||||
android:bottom="7dp"/>
|
||||
<corners android:radius="8dp"/>
|
||||
<size android:width="2dp" <error>android:dashWidth</error>=""/>
|
||||
<solid/>
|
||||
<stroke android:width="integer"
|
||||
android:color="color"
|
||||
android:dashWidth="integer"
|
||||
android:dashGap="integer"
|
||||
<error>android:aba</error>=""/>
|
||||
<<error>aba</error>/>
|
||||
</shape>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<transition xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:rig<caret>
|
||||
</transition>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<transition xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:right=""
|
||||
</transition>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<transition xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bit<caret>
|
||||
</item>
|
||||
</transition>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<transition xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap
|
||||
</item>
|
||||
</transition>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<transition xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/myDrawable"/>
|
||||
<item android:drawable="<error>@drawable/aba</error>"/>
|
||||
</transition>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<transition xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap android:src="@drawable/myDrawable"/>
|
||||
</item>
|
||||
<item>
|
||||
<<error>bitmap</error>/>
|
||||
</item>
|
||||
</transition>
|
||||
@@ -57,5 +57,9 @@ public class AndroidColorStateListDomTest extends AndroidDomTest {
|
||||
public void testStateListCompletion5() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testRootTagCompletion() throws Throwable {
|
||||
doTestCompletionVariants(getTestName(false) + ".xml", "selector");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+122
-5
@@ -73,6 +73,10 @@ public class AndroidDrawableResourcesDomTest extends AndroidDomTest {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testBitmapHighlighting3() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testBitmapCompletion1() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
@@ -97,6 +101,123 @@ public class AndroidDrawableResourcesDomTest extends AndroidDomTest {
|
||||
doTestOnlyDrawableReferences();
|
||||
}
|
||||
|
||||
public void testLayerListHighlighting() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testLayerListCompletion1() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testLayerListCompletion2() throws Throwable {
|
||||
doTestOnlyDrawableReferences();
|
||||
}
|
||||
|
||||
public void testLayerListCompletion3() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testLevelListHighlighting() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testLevelListCompletion1() throws Throwable {
|
||||
doTestOnlyDrawableReferences();
|
||||
}
|
||||
|
||||
public void testLevelListCompletion2() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testLevelListCompletion3() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testTransitionHighlighting1() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testTransitionHighlighting2() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testTransitionCompletion1() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testTransitionCompletion2() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testInsetHighlighting1() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testInsetHighlighting2() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testInsetCompletion1() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testInsetCompletion2() throws Throwable {
|
||||
doTestOnlyDrawableReferences();
|
||||
}
|
||||
|
||||
public void testClipHighlighting() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testClipCompletion1() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testClipCompletion2() throws Throwable {
|
||||
doTestOnlyDrawableReferences();
|
||||
}
|
||||
|
||||
public void testScaleHighlighting1() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testScaleHighlighting2() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testScaleHighlighting3() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testScaleCompletion1() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testScaleCompletion2() throws Throwable {
|
||||
doTestOnlyDrawableReferences();
|
||||
}
|
||||
|
||||
public void testShapeHighlighting() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testShapeCompletion1() throws Throwable {
|
||||
doTestCompletion();
|
||||
}
|
||||
|
||||
public void testShapeCompletion2() throws Throwable {
|
||||
doTestCompletionVariants(getTestName(true) + ".xml", "gradient", "solid", "size", "stroke", "padding", "corners");
|
||||
}
|
||||
|
||||
public void testIncorrectRootTag() throws Throwable {
|
||||
doTestHighlighting();
|
||||
}
|
||||
|
||||
public void testRootTagCompletion() throws Throwable {
|
||||
doTestCompletionVariants(getTestName(true) + ".xml", "selector", "bitmap", "nine-patch", "layer-list", "level-list", "transition",
|
||||
"inset", "clip", "scale", "shape");
|
||||
}
|
||||
|
||||
private void doTestOnlyDrawableReferences() throws IOException {
|
||||
VirtualFile file = copyFileToProject(getTestName(true) + ".xml");
|
||||
myFixture.configureFromExistingVirtualFile(file);
|
||||
@@ -104,13 +225,9 @@ public class AndroidDrawableResourcesDomTest extends AndroidDomTest {
|
||||
List<String> lookupElementStrings = myFixture.getLookupElementStrings();
|
||||
assertNotNull(lookupElementStrings);
|
||||
for (String s : lookupElementStrings) {
|
||||
if (!s.startsWith("@android") && !s.startsWith("@drawable")) {
|
||||
if (!s.startsWith("@android") && !s.startsWith("@drawable") && !s.startsWith("@color")) {
|
||||
fail("Variant " + s + " shouldn't be threre");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testRootTagCompletion() throws Throwable {
|
||||
doTestCompletionVariants(getTestName(true) + ".xml", "selector", "bitmap", "nine-patch");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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;
|
||||
|
||||
import com.android.sdklib.SdkConstants;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class AndroidDrawableResourcesTest extends AndroidDomTest {
|
||||
public AndroidDrawableResourcesTest() {
|
||||
super(true, "dom/other");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, SdkConstants.FN_ANDROID_MANIFEST_XML);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPathToCopy(String testFileName) {
|
||||
return "res/drawable/" + testFileName;
|
||||
}
|
||||
|
||||
public void testHighlighting() throws Throwable {
|
||||
doTestHighlighting("1.xml");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user