diff options
author | Diego Perez <diegoperez@google.com> | 2017-06-01 12:59:40 +0100 |
---|---|---|
committer | Diego Perez <diegoperez@google.com> | 2017-06-01 13:01:25 +0100 |
commit | 3780b5f90d3b967c2b02b50a27ad315ee86de090 (patch) | |
tree | eff7dc09c7d26a79d54bcc167904caad2e857a9b | |
parent | 49c7781a307dd8a43092928f445d95c9a7d6e718 (diff) | |
download | layoutlib-3780b5f90d3b967c2b02b50a27ad315ee86de090.tar.gz |
Address warnings in BridgeXmlBlockParser + annotations
Test: N/A
Change-Id: I3c56858ad9d86c41e1b5709bd4868b716f6255a1
3 files changed, 153 insertions, 13 deletions
diff --git a/bridge/src/android/util/BridgeXmlPullAttributes.java b/bridge/src/android/util/BridgeXmlPullAttributes.java index 9fd1e15575..f1af1d1082 100644 --- a/bridge/src/android/util/BridgeXmlPullAttributes.java +++ b/bridge/src/android/util/BridgeXmlPullAttributes.java @@ -295,7 +295,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes { private int resolveResourceValue(String value, int defaultValue) { ResourceValue resource = getResourceValue(value); if (resource != null) { - Integer id = null; + Integer id; if (mPlatformFile || resource.isFramework()) { id = Bridge.getResourceId(resource.getResourceType(), resource.getName()); } else { diff --git a/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java b/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java index ac8712eaa0..f18cd4890e 100644 --- a/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java +++ b/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java @@ -23,6 +23,8 @@ import com.android.layoutlib.bridge.impl.ParserFactory; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.content.res.XmlResourceParser; import android.util.AttributeSet; import android.util.BridgeXmlPullAttributes; @@ -39,7 +41,7 @@ import java.io.Reader; public class BridgeXmlBlockParser implements XmlResourceParser { private final XmlPullParser mParser; - private final BridgeXmlPullAttributes mAttrib; + private final AttributeSet mAttrib; private final BridgeContext mContext; private final boolean mPlatformFile; @@ -54,7 +56,8 @@ public class BridgeXmlBlockParser implements XmlResourceParser { * @param context the Context. * @param platformFile Indicates whether the the file is a platform file or not. */ - public BridgeXmlBlockParser(XmlPullParser parser, BridgeContext context, boolean platformFile) { + public BridgeXmlBlockParser(@NonNull XmlPullParser parser, @Nullable BridgeContext context, + boolean platformFile) { if (ParserFactory.LOG_PARSER) { System.out.println("CRTE " + parser.toString()); } @@ -62,12 +65,15 @@ public class BridgeXmlBlockParser implements XmlResourceParser { mParser = parser; mContext = context; mPlatformFile = platformFile; - mAttrib = new BridgeXmlPullAttributes(parser, context, mPlatformFile); if (mContext != null) { + mAttrib = new BridgeXmlPullAttributes(parser, context, mPlatformFile); mContext.pushParser(this); mPopped = false; } + else { + mAttrib = new NopAttributeSet(); + } } public XmlPullParser getParser() { @@ -87,7 +93,7 @@ public class BridgeXmlBlockParser implements XmlResourceParser { } public void ensurePopped() { - if (mContext != null && mPopped == false) { + if (mContext != null && !mPopped) { mContext.popParser(); mPopped = true; } @@ -109,13 +115,8 @@ public class BridgeXmlBlockParser implements XmlResourceParser { @Override public boolean getFeature(String name) { - if (FEATURE_PROCESS_NAMESPACES.equals(name)) { - return true; - } - if (FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) { - return true; - } - return false; + return FEATURE_PROCESS_NAMESPACES.equals(name) || + FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name); } @Override @@ -318,7 +319,7 @@ public class BridgeXmlBlockParser implements XmlResourceParser { return ev; } - public static String eventTypeToString(int eventType) { + private static String eventTypeToString(int eventType) { switch (eventType) { case START_DOCUMENT: return "START_DOC"; @@ -491,4 +492,5 @@ public class BridgeXmlBlockParser implements XmlResourceParser { public int getStyleAttribute() { return mAttrib.getStyleAttribute(); } + } diff --git a/bridge/src/com/android/layoutlib/bridge/android/NopAttributeSet.java b/bridge/src/com/android/layoutlib/bridge/android/NopAttributeSet.java new file mode 100644 index 0000000000..fbb12d5de6 --- /dev/null +++ b/bridge/src/com/android/layoutlib/bridge/android/NopAttributeSet.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * 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 com.android.layoutlib.bridge.android; + +import android.util.AttributeSet; + +/** + * Empty {@link AttributeSet} + */ +class NopAttributeSet implements AttributeSet { + @Override + public int getAttributeCount() { + return 0; + } + + @Override + public String getAttributeName(int index) { + return null; + } + + @Override + public String getAttributeValue(int index) { + return null; + } + + @Override + public String getAttributeValue(String namespace, String name) { + return null; + } + + @Override + public String getPositionDescription() { + return null; + } + + @Override + public int getAttributeNameResource(int index) { + return 0; + } + + @Override + public int getAttributeListValue(String namespace, String attribute, String[] options, int + defaultValue) { + return 0; + } + + @Override + public boolean getAttributeBooleanValue(String namespace, String attribute, + boolean defaultValue) { + return false; + } + + @Override + public int getAttributeResourceValue(String namespace, String attribute, int defaultValue) { + return 0; + } + + @Override + public int getAttributeIntValue(String namespace, String attribute, int defaultValue) { + return 0; + } + + @Override + public int getAttributeUnsignedIntValue(String namespace, String attribute, + int defaultValue) { + return 0; + } + + @Override + public float getAttributeFloatValue(String namespace, String attribute, + float defaultValue) { + return 0; + } + + @Override + public int getAttributeListValue(int index, String[] options, int defaultValue) { + return 0; + } + + @Override + public boolean getAttributeBooleanValue(int index, boolean defaultValue) { + return false; + } + + @Override + public int getAttributeResourceValue(int index, int defaultValue) { + return 0; + } + + @Override + public int getAttributeIntValue(int index, int defaultValue) { + return 0; + } + + @Override + public int getAttributeUnsignedIntValue(int index, int defaultValue) { + return 0; + } + + @Override + public float getAttributeFloatValue(int index, float defaultValue) { + return 0; + } + + @Override + public String getIdAttribute() { + return null; + } + + @Override + public String getClassAttribute() { + return null; + } + + @Override + public int getIdAttributeResourceValue(int defaultValue) { + return 0; + } + + @Override + public int getStyleAttribute() { + return 0; + } +} |