Make AnnotationEncodedValue implement BaseAnnotation

This commit is contained in:
Ben Gruver 2012-10-15 22:17:57 -07:00
parent 22eede870f
commit 3019737ed3
6 changed files with 38 additions and 28 deletions

View File

@ -47,7 +47,7 @@ public class DexBackedEncodedValue implements EncodedValue {
}
@Override
public int getType() {
public int getValueType() {
return 0;
}
}

View File

@ -35,6 +35,5 @@ import org.jf.dexlib2.iface.BaseAnnotation;
import javax.annotation.Nonnull;
public interface AnnotationEncodedValue extends EncodedValue {
@Nonnull BaseAnnotation getValue();
public interface AnnotationEncodedValue extends EncodedValue, BaseAnnotation {
}

View File

@ -32,5 +32,5 @@
package org.jf.dexlib2.iface.value;
public interface EncodedValue {
int getType();
int getValueType();
}

View File

@ -31,6 +31,7 @@
package org.jf.dexlib2.immutable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.iface.Annotation;
import org.jf.dexlib2.iface.AnnotationElement;
@ -40,21 +41,25 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableAnnotation extends ImmutableBaseAnnotation implements Annotation {
public class ImmutableAnnotation implements Annotation {
public final int visibility;
@Nonnull public final String type;
@Nonnull public final ImmutableList<? extends ImmutableAnnotationElement> elements;
public ImmutableAnnotation(int visibility,
@Nonnull String type,
@Nullable List<? extends AnnotationElement> elements) {
super(type, elements);
this.visibility = visibility;
this.type = type;
this.elements = ImmutableAnnotationElement.immutableListOf(elements);
}
public ImmutableAnnotation(int visibility,
@Nonnull String type,
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
super(type, elements);
this.visibility = visibility;
this.type = type;
this.elements = Objects.firstNonNull(elements, ImmutableList.<ImmutableAnnotationElement>of());
}
public static ImmutableAnnotation of(Annotation annotation) {
@ -67,10 +72,9 @@ public class ImmutableAnnotation extends ImmutableBaseAnnotation implements Anno
annotation.getElements());
}
@Override
public int getVisibility() {
return visibility;
}
@Override public int getVisibility() { return visibility; }
@Nonnull @Override public String getType() { return type; }
@Nonnull @Override public ImmutableList<? extends ImmutableAnnotationElement> getElements() { return elements; }
@Nonnull
public static ImmutableList<ImmutableAnnotation> immutableListOf(List<? extends Annotation> list) {

View File

@ -31,37 +31,44 @@
package org.jf.dexlib2.immutable.value;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import org.jf.dexlib2.ValueType;
import org.jf.dexlib2.iface.value.EncodedValue;
import org.jf.dexlib2.immutable.ImmutableBaseAnnotation;
import org.jf.dexlib2.iface.BaseAnnotation;
import org.jf.dexlib2.iface.AnnotationElement;
import org.jf.dexlib2.immutable.ImmutableAnnotationElement;
import org.jf.dexlib2.iface.value.AnnotationEncodedValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;
public class ImmutableAnnotationEncodedValue extends ImmutableEncodedValue implements AnnotationEncodedValue {
@Nonnull
public final ImmutableBaseAnnotation value;
@Nonnull public final String type;
@Nonnull public final ImmutableList<? extends ImmutableAnnotationElement> elements;
public ImmutableAnnotationEncodedValue(@Nonnull BaseAnnotation value) {
public ImmutableAnnotationEncodedValue(@Nonnull String type,
@Nullable List<? extends AnnotationElement> elements) {
super(ValueType.ANNOTATION);
this.value = ImmutableBaseAnnotation.of(value);
this.type = type;
this.elements = ImmutableAnnotationElement.immutableListOf(elements);
}
public ImmutableAnnotationEncodedValue(@Nonnull ImmutableBaseAnnotation value) {
public ImmutableAnnotationEncodedValue(@Nonnull String type,
@Nullable ImmutableList<? extends ImmutableAnnotationElement> elements) {
super(ValueType.ANNOTATION);
this.value = value;
this.type = type;
this.elements = Objects.firstNonNull(elements, ImmutableList.<ImmutableAnnotationElement>of());
}
public static ImmutableAnnotationEncodedValue of(@Nonnull AnnotationEncodedValue annotationEncodedValue) {
public static ImmutableAnnotationEncodedValue of(AnnotationEncodedValue annotationEncodedValue) {
if (annotationEncodedValue instanceof ImmutableAnnotationEncodedValue) {
return (ImmutableAnnotationEncodedValue)annotationEncodedValue;
}
return new ImmutableAnnotationEncodedValue(annotationEncodedValue.getValue());
return new ImmutableAnnotationEncodedValue(
annotationEncodedValue.getType(),
annotationEncodedValue.getElements());
}
@Nonnull
public ImmutableBaseAnnotation getValue() {
return value;
}
@Nonnull @Override public String getType() { return type; }
@Nonnull @Override public ImmutableList<? extends ImmutableAnnotationElement> getElements() { return elements; }
}

View File

@ -48,7 +48,7 @@ public class ImmutableEncodedValue implements EncodedValue {
}
public static ImmutableEncodedValue of(EncodedValue encodedValue) {
switch (encodedValue.getType()) {
switch (encodedValue.getValueType()) {
case ValueType.BYTE:
return ImmutableByteEncodedValue.of((ByteEncodedValue)encodedValue);
case ValueType.SHORT:
@ -87,7 +87,7 @@ public class ImmutableEncodedValue implements EncodedValue {
}
}
public int getType() { return type; }
public int getValueType() { return type; }
@Nonnull
public static ImmutableList<ImmutableEncodedValue> immutableListOf(List<? extends EncodedValue> list) {