Add and use ImmutabeleListUtils.nullToEmptyList()

This commit is contained in:
Ben Gruver 2012-11-04 13:53:41 -08:00
parent a8e05220c1
commit b0383884fa
19 changed files with 95 additions and 44 deletions

View File

@ -31,11 +31,11 @@
package org.jf.dexlib2.immutable; package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.Annotation; import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.AnnotationElement; import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -59,7 +59,7 @@ public class ImmutableAnnotation implements Annotation {
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) { @Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
this.visibility = visibility; this.visibility = visibility;
this.type = type; this.type = type;
this.elements = Objects.firstNonNull(elements, ImmutableList.<ImmutableAnnotationElement>of()); this.elements = ImmutableListUtils.nullToEmptyList(elements);
} }
public static ImmutableAnnotation of(Annotation annotation) { public static ImmutableAnnotation of(Annotation annotation) {
@ -77,7 +77,7 @@ public class ImmutableAnnotation implements Annotation {
@Nonnull @Override public ImmutableList<? extends ImmutableAnnotationElement> getElements() { return elements; } @Nonnull @Override public ImmutableList<? extends ImmutableAnnotationElement> getElements() { return elements; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableAnnotation> immutableListOf(List<? extends Annotation> list) { public static ImmutableList<ImmutableAnnotation> immutableListOf(@Nullable List<? extends Annotation> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -38,6 +38,7 @@ import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class ImmutableAnnotationElement implements AnnotationElement { public class ImmutableAnnotationElement implements AnnotationElement {
@ -69,7 +70,8 @@ public class ImmutableAnnotationElement implements AnnotationElement {
@Nonnull @Override public EncodedValue getValue() { return value; } @Nonnull @Override public EncodedValue getValue() { return value; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableAnnotationElement> immutableListOf(List<? extends AnnotationElement> list) { public static ImmutableList<ImmutableAnnotationElement> immutableListOf(
@Nullable List<? extends AnnotationElement> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -31,10 +31,10 @@
package org.jf.dexlib2.immutable; package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.AnnotationElement; import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.iface.BaseAnnotation; import org.jf.dexlib2.iface.BaseAnnotation;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -53,7 +53,7 @@ public class ImmutableBaseAnnotation implements BaseAnnotation {
public ImmutableBaseAnnotation(@Nonnull String type, public ImmutableBaseAnnotation(@Nonnull String type,
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) { @Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
this.type = type; this.type = type;
this.elements = Objects.firstNonNull(elements, ImmutableList.<ImmutableAnnotationElement>of()); this.elements = ImmutableListUtils.nullToEmptyList(elements);
} }
public static ImmutableBaseAnnotation of(BaseAnnotation baseAnnotation) { public static ImmutableBaseAnnotation of(BaseAnnotation baseAnnotation) {

View File

@ -38,6 +38,7 @@ import org.jf.dexlib2.iface.ClassDef;
import org.jf.dexlib2.iface.Field; import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.Method; import org.jf.dexlib2.iface.Method;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -82,11 +83,11 @@ public class ImmutableClassDef implements ClassDef {
this.name = name; this.name = name;
this.accessFlags = accessFlags; this.accessFlags = accessFlags;
this.superclass = superclass; this.superclass = superclass;
this.interfaces = Objects.firstNonNull(interfaces, ImmutableList.<String>of()); this.interfaces = ImmutableListUtils.nullToEmptyList(interfaces);
this.sourceFile = sourceFile; this.sourceFile = sourceFile;
this.annotations = Objects.firstNonNull(annotations, ImmutableList.<ImmutableAnnotation>of()); this.annotations = ImmutableListUtils.nullToEmptyList(annotations);
this.fields = Objects.firstNonNull(fields, ImmutableList.<ImmutableField>of()); this.fields = ImmutableListUtils.nullToEmptyList(fields);
this.methods = Objects.firstNonNull(methods, ImmutableList.<ImmutableMethod>of()); this.methods = ImmutableListUtils.nullToEmptyList(methods);
} }
public static ImmutableClassDef of(ClassDef classDef) { public static ImmutableClassDef of(ClassDef classDef) {
@ -114,7 +115,7 @@ public class ImmutableClassDef implements ClassDef {
@Nonnull @Override public ImmutableList<? extends ImmutableMethod> getMethods() { return methods; } @Nonnull @Override public ImmutableList<? extends ImmutableMethod> getMethods() { return methods; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableClassDef> immutableListOf(List<? extends ClassDef> list) { public static ImmutableList<ImmutableClassDef> immutableListOf(@Nullable List<? extends ClassDef> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -31,9 +31,9 @@
package org.jf.dexlib2.immutable; package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.*; import org.jf.dexlib2.iface.*;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -47,7 +47,7 @@ public class ImmutableDexFile implements DexFile {
} }
public ImmutableDexFile(@Nullable ImmutableList<? extends ImmutableClassDef> classes) { public ImmutableDexFile(@Nullable ImmutableList<? extends ImmutableClassDef> classes) {
this.classes = Objects.firstNonNull(classes, ImmutableList.<ImmutableClassDef>of()); this.classes = ImmutableListUtils.nullToEmptyList(classes);
} }
public static ImmutableDexFile of(DexFile dexFile) { public static ImmutableDexFile of(DexFile dexFile) {

View File

@ -62,7 +62,8 @@ public class ImmutableExceptionHandler implements ExceptionHandler {
@Override public int getHandlerCodeOffset() { return handlerCodeOffset; } @Override public int getHandlerCodeOffset() { return handlerCodeOffset; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableExceptionHandler> immutableListOf(List<? extends ExceptionHandler> list) { public static ImmutableList<ImmutableExceptionHandler> immutableListOf(
@Nullable List<? extends ExceptionHandler> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -31,13 +31,13 @@
package org.jf.dexlib2.immutable; package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.immutable.value.ImmutableEncodedValue; import org.jf.dexlib2.immutable.value.ImmutableEncodedValue;
import org.jf.dexlib2.iface.Annotation; import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.Field; import org.jf.dexlib2.iface.Field;
import org.jf.dexlib2.iface.value.EncodedValue; import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -76,7 +76,7 @@ public class ImmutableField implements Field {
this.type = type; this.type = type;
this.accessFlags = accessFlags; this.accessFlags = accessFlags;
this.initialValue = initialValue; this.initialValue = initialValue;
this.annotations = Objects.firstNonNull(annotations, ImmutableList.<ImmutableAnnotation>of()); this.annotations = ImmutableListUtils.nullToEmptyList(annotations);
} }
public static ImmutableField of(Field field) { public static ImmutableField of(Field field) {
@ -100,7 +100,7 @@ public class ImmutableField implements Field {
@Nonnull @Override public ImmutableList<? extends ImmutableAnnotation> getAnnotations() { return annotations; } @Nonnull @Override public ImmutableList<? extends ImmutableAnnotation> getAnnotations() { return annotations; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableField> immutableListOf(List<? extends Field> list) { public static ImmutableList<ImmutableField> immutableListOf(@Nullable List<? extends Field> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -31,10 +31,10 @@
package org.jf.dexlib2.immutable; package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.*; import org.jf.dexlib2.iface.*;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -74,10 +74,10 @@ public class ImmutableMethod implements Method {
@Nullable ImmutableMethodImplementation methodImplementation) { @Nullable ImmutableMethodImplementation methodImplementation) {
this.containingClass = containingClass; this.containingClass = containingClass;
this.name = name; this.name = name;
this.parameters = Objects.firstNonNull(parameters, ImmutableList.<ImmutableMethodParameter>of()); this.parameters = ImmutableListUtils.nullToEmptyList(parameters);
this.returnType = returnType; this.returnType = returnType;
this.accessFlags = accessFlags; this.accessFlags = accessFlags;
this.annotations = Objects.firstNonNull(annotations, ImmutableList.<ImmutableAnnotation>of()); this.annotations = ImmutableListUtils.nullToEmptyList(annotations);
this.methodImplementation = methodImplementation; this.methodImplementation = methodImplementation;
} }
@ -104,7 +104,7 @@ public class ImmutableMethod implements Method {
@Nullable public ImmutableMethodImplementation getImplementation() { return methodImplementation; } @Nullable public ImmutableMethodImplementation getImplementation() { return methodImplementation; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableMethod> immutableListOf(List<? extends Method> list) { public static ImmutableList<ImmutableMethod> immutableListOf(@Nullable List<? extends Method> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -31,7 +31,6 @@
package org.jf.dexlib2.immutable; package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.MethodImplementation; import org.jf.dexlib2.iface.MethodImplementation;
import org.jf.dexlib2.iface.TryBlock; import org.jf.dexlib2.iface.TryBlock;
@ -39,6 +38,7 @@ import org.jf.dexlib2.iface.debug.DebugItem;
import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.Instruction;
import org.jf.dexlib2.immutable.debug.ImmutableDebugItem; import org.jf.dexlib2.immutable.debug.ImmutableDebugItem;
import org.jf.dexlib2.immutable.instruction.ImmutableInstruction; import org.jf.dexlib2.immutable.instruction.ImmutableInstruction;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -65,9 +65,9 @@ public class ImmutableMethodImplementation implements MethodImplementation {
@Nullable ImmutableList<? extends ImmutableTryBlock> tryBlocks, @Nullable ImmutableList<? extends ImmutableTryBlock> tryBlocks,
@Nullable ImmutableList<? extends ImmutableDebugItem> debugItems) { @Nullable ImmutableList<? extends ImmutableDebugItem> debugItems) {
this.registerCount = registerCount; this.registerCount = registerCount;
this.instructions = Objects.firstNonNull(instructions, ImmutableList.<ImmutableInstruction>of()); this.instructions = ImmutableListUtils.nullToEmptyList(instructions);
this.tryBlocks = Objects.firstNonNull(tryBlocks, ImmutableList.<ImmutableTryBlock>of()); this.tryBlocks = ImmutableListUtils.nullToEmptyList(tryBlocks);
this.debugItems = Objects.firstNonNull(debugItems, ImmutableList.<ImmutableDebugItem>of()); this.debugItems = ImmutableListUtils.nullToEmptyList(debugItems);
} }
@Nullable @Nullable

View File

@ -31,11 +31,11 @@
package org.jf.dexlib2.immutable; package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.Annotation; import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.MethodParameter; import org.jf.dexlib2.iface.MethodParameter;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -58,7 +58,7 @@ public class ImmutableMethodParameter implements MethodParameter {
@Nullable ImmutableList<? extends ImmutableAnnotation> annotations, @Nullable ImmutableList<? extends ImmutableAnnotation> annotations,
@Nullable String name) { @Nullable String name) {
this.type = type; this.type = type;
this.annotations = Objects.firstNonNull(annotations, ImmutableList.<ImmutableAnnotation>of()); this.annotations = ImmutableListUtils.nullToEmptyList(annotations);
this.name = name; this.name = name;
} }
@ -80,7 +80,8 @@ public class ImmutableMethodParameter implements MethodParameter {
@Nullable @Override public String getSignature() { return null; } @Nullable @Override public String getSignature() { return null; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableMethodParameter> immutableListOf(List<? extends MethodParameter> list) { public static ImmutableList<ImmutableMethodParameter> immutableListOf(
@Nullable List<? extends MethodParameter> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -31,11 +31,11 @@
package org.jf.dexlib2.immutable; package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.ExceptionHandler; import org.jf.dexlib2.iface.ExceptionHandler;
import org.jf.dexlib2.iface.TryBlock; import org.jf.dexlib2.iface.TryBlock;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -59,7 +59,7 @@ public class ImmutableTryBlock implements TryBlock {
@Nullable ImmutableList<? extends ImmutableExceptionHandler> exceptionHandlers) { @Nullable ImmutableList<? extends ImmutableExceptionHandler> exceptionHandlers) {
this.startCodeOffset = startCodeOffset; this.startCodeOffset = startCodeOffset;
this.codeUnitCount = codeUnitCount; this.codeUnitCount = codeUnitCount;
this.exceptionHandlers = Objects.firstNonNull(exceptionHandlers, ImmutableList.<ImmutableExceptionHandler>of()); this.exceptionHandlers = ImmutableListUtils.nullToEmptyList(exceptionHandlers);
} }
public static ImmutableTryBlock of(TryBlock tryBlock) { public static ImmutableTryBlock of(TryBlock tryBlock) {
@ -80,7 +80,7 @@ public class ImmutableTryBlock implements TryBlock {
} }
@Nonnull @Nonnull
public static ImmutableList<ImmutableTryBlock> immutableListOf(List<? extends TryBlock> list) { public static ImmutableList<ImmutableTryBlock> immutableListOf(@Nullable List<? extends TryBlock> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -31,11 +31,11 @@
package org.jf.dexlib2.immutable.instruction; package org.jf.dexlib2.immutable.instruction;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.Format; import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode; import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.formats.ArrayPayload; import org.jf.dexlib2.iface.instruction.formats.ArrayPayload;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -60,7 +60,7 @@ public class ImmutableArrayPayload extends ImmutableInstruction implements Array
//TODO: need to ensure this is a valid width (1, 2, 4, 8) //TODO: need to ensure this is a valid width (1, 2, 4, 8)
this.elementWidth = elementWidth; this.elementWidth = elementWidth;
//TODO: need to validate the elements fit within the width //TODO: need to validate the elements fit within the width
this.arrayElements = Objects.firstNonNull(arrayElements, ImmutableList.<Number>of()); this.arrayElements = ImmutableListUtils.nullToEmptyList(arrayElements);
} }
@Nonnull @Nonnull

View File

@ -31,12 +31,12 @@
package org.jf.dexlib2.immutable.instruction; package org.jf.dexlib2.immutable.instruction;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.Format; import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode; import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.SwitchElement; import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload; import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -56,7 +56,7 @@ public class ImmutablePackedSwitchPayload extends ImmutableInstruction implement
public ImmutablePackedSwitchPayload( public ImmutablePackedSwitchPayload(
@Nullable ImmutableList<? extends ImmutableSwitchElement> switchElements) { @Nullable ImmutableList<? extends ImmutableSwitchElement> switchElements) {
super(OPCODE); super(OPCODE);
this.switchElements = Objects.firstNonNull(switchElements, ImmutableList.<ImmutableSwitchElement>of()); this.switchElements = ImmutableListUtils.nullToEmptyList(switchElements);
} }
@Nonnull @Nonnull

View File

@ -31,13 +31,12 @@
package org.jf.dexlib2.immutable.instruction; package org.jf.dexlib2.immutable.instruction;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.Format; import org.jf.dexlib2.Format;
import org.jf.dexlib2.Opcode; import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.iface.instruction.SwitchElement; import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload; import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload;
import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload; import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -56,7 +55,7 @@ public class ImmutableSparseSwitchPayload extends ImmutableInstruction implement
public ImmutableSparseSwitchPayload( public ImmutableSparseSwitchPayload(
@Nullable ImmutableList<? extends ImmutableSwitchElement> switchElements) { @Nullable ImmutableList<? extends ImmutableSwitchElement> switchElements) {
super(OPCODE); super(OPCODE);
this.switchElements = Objects.firstNonNull(switchElements, ImmutableList.<ImmutableSwitchElement>of()); this.switchElements = ImmutableListUtils.nullToEmptyList(switchElements);
} }
@Nonnull @Nonnull

View File

@ -36,6 +36,7 @@ import org.jf.dexlib2.iface.instruction.SwitchElement;
import org.jf.util.ImmutableListConverter; import org.jf.util.ImmutableListConverter;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class ImmutableSwitchElement implements SwitchElement { public class ImmutableSwitchElement implements SwitchElement {
@ -62,7 +63,7 @@ public class ImmutableSwitchElement implements SwitchElement {
@Override public int getOffset() { return offset; } @Override public int getOffset() { return offset; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableSwitchElement> immutableListOf(List<? extends SwitchElement> list) { public static ImmutableList<ImmutableSwitchElement> immutableListOf(@Nullable List<? extends SwitchElement> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -31,10 +31,10 @@
package org.jf.dexlib2.immutable.reference; package org.jf.dexlib2.immutable.reference;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.reference.BasicMethodParameter; import org.jf.dexlib2.iface.reference.BasicMethodParameter;
import org.jf.dexlib2.iface.reference.MethodReference; import org.jf.dexlib2.iface.reference.MethodReference;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -62,7 +62,7 @@ public class ImmutableMethodReference extends ImmutableReference implements Meth
@Nonnull String returnType) { @Nonnull String returnType) {
this.containingClass = containingClass; this.containingClass = containingClass;
this.name = name; this.name = name;
this.parameters = Objects.firstNonNull(parameters, ImmutableList.<ImmutableBasicMethodParameter>of()); this.parameters = ImmutableListUtils.nullToEmptyList(parameters);
this.returnType = returnType; this.returnType = returnType;
} }

View File

@ -31,12 +31,12 @@
package org.jf.dexlib2.immutable.value; package org.jf.dexlib2.immutable.value;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.ValueType; import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.AnnotationElement; import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.immutable.ImmutableAnnotationElement; import org.jf.dexlib2.immutable.ImmutableAnnotationElement;
import org.jf.dexlib2.iface.value.AnnotationEncodedValue; import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import org.jf.util.ImmutableListUtils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -57,7 +57,7 @@ public class ImmutableAnnotationEncodedValue extends ImmutableEncodedValue imple
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) { @Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
super(ValueType.ANNOTATION); super(ValueType.ANNOTATION);
this.type = type; this.type = type;
this.elements = Objects.firstNonNull(elements, ImmutableList.<ImmutableAnnotationElement>of()); this.elements = ImmutableListUtils.nullToEmptyList(elements);
} }
public static ImmutableAnnotationEncodedValue of(AnnotationEncodedValue annotationEncodedValue) { public static ImmutableAnnotationEncodedValue of(AnnotationEncodedValue annotationEncodedValue) {

View File

@ -95,7 +95,7 @@ public class ImmutableEncodedValue implements EncodedValue {
public int getValueType() { return type; } public int getValueType() { return type; }
@Nonnull @Nonnull
public static ImmutableList<ImmutableEncodedValue> immutableListOf(List<? extends EncodedValue> list) { public static ImmutableList<ImmutableEncodedValue> immutableListOf(@Nullable List<? extends EncodedValue> list) {
return CONVERTER.convert(list); return CONVERTER.convert(list);
} }

View File

@ -0,0 +1,46 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.util;
import com.google.common.collect.ImmutableList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ImmutableListUtils {
@Nonnull public static <T> ImmutableList<T> nullToEmptyList(@Nullable ImmutableList<T> list) {
if (list == null) {
return ImmutableList.of();
}
return list;
}
}