Implemented annotation encoded values

git-svn-id: https://smali.googlecode.com/svn/trunk@165 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-06-18 04:19:05 +00:00
parent 8c8cec655d
commit 1080561460
6 changed files with 123 additions and 5 deletions

View File

@ -0,0 +1,82 @@
/*
* [The "BSD licence"]
* Copyright (c) 2009 Ben Gruver
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.baksmali.Adaptors.EncodedValue;
import org.jf.dexlib.EncodedValue.AnnotationEncodedValueSubField;
import org.jf.dexlib.EncodedValue.AnnotationElement;
import org.jf.baksmali.Adaptors.Reference.TypeReference;
import java.util.List;
import java.util.ArrayList;
public class AnnotationEncodedValueAdaptor extends EncodedValueAdaptor {
private AnnotationEncodedValueSubField encodedAnnotation;
public AnnotationEncodedValueAdaptor(AnnotationEncodedValueSubField encodedAnnotation) {
this.encodedAnnotation = encodedAnnotation;
}
public String getFormat() {
return "AnnotationEncodedValue";
}
public Object getValue() {
return this;
}
public TypeReference getAnnotationType() {
return new TypeReference(encodedAnnotation.getAnnotationType());
}
public List<AnnotationElementAdaptor> getElements() {
List<AnnotationElementAdaptor> elements = new ArrayList<AnnotationElementAdaptor>();
for (AnnotationElement annotationElement: encodedAnnotation.getAnnotationElements()) {
elements.add(new AnnotationElementAdaptor(annotationElement));
}
return elements;
}
public static class AnnotationElementAdaptor {
private AnnotationElement annotationElement;
public AnnotationElementAdaptor(AnnotationElement annotationElement) {
this.annotationElement = annotationElement;
}
public String getName() {
return annotationElement.getName().getStringValue();
}
public EncodedValueAdaptor getValue() {
return EncodedValueAdaptor.make(annotationElement.getEncodedValue());
}
}
}

View File

@ -39,11 +39,11 @@ public abstract class EncodedValueAdaptor {
public static EncodedValueAdaptor make(EncodedValue encodedValue) {
switch (encodedValue.getValueType()) {
case VALUE_ANNOTATION:
return null;
return new AnnotationEncodedValueAdaptor((AnnotationEncodedValueSubField)encodedValue.getValue());
case VALUE_ARRAY:
return new ArrayEncodedValueAdaptor(((ArrayEncodedValueSubField)encodedValue.getValue()));
return new ArrayEncodedValueAdaptor((ArrayEncodedValueSubField)encodedValue.getValue());
case VALUE_BOOLEAN:
return new SimpleEncodedValueAdaptor(((BoolEncodedValueSubField)encodedValue.getValue()).getValue());
return new SimpleEncodedValueAdaptor(((BoolEncodedValueSubField)encodedValue.getValue()).getValue());
case VALUE_BYTE:
return new SimpleEncodedValueAdaptor(((ByteEncodedValueSubField)encodedValue.getValue()).getValue());
case VALUE_CHAR:

View File

@ -279,12 +279,24 @@ EncodedIndexedItemReference(EncodedValue) ::=
ArrayEncodedValue(EncodedValue) ::=
<<
{<EncodedValue.Value: {
<EncodedValue(it)>}; separator=",">
{
<EncodedValue.Value: EncodedValue(it); separator=",\n">
}
>>
EnumEncodedValue(EncodedValue) ::=
<<
.enum <Reference(EncodedValue.Value)>
>>
AnnotationEncodedValue(EncodedValue) ::=
<<
.subannotation EncodedValue.Type
<EncodedValue.Elements: AnnotationElement(it); separator="\n">
.end subannotation
>>
AnnotationElement(AnnotationElement) ::=
<<
<AnnotationElement.Name> = <EncodedValue(AnnotationElement.Value)>
>>

View File

@ -43,6 +43,14 @@
.field public static enumStaticField:Lsome/enum; = .enum Lsome/enum;->someEnumValue:Lsome/enum;
.field public static annotationStaticField:Lsome/annotation; = .subannotation Lsome/annotation;
value1 = "test"
value2 = .subannotation Lsome/annotation;
value1 = "test2"
value2 = Lsome/enum;
.end subannotation
.end subannotation
.field public instanceField:Ljava/lang/String;

View File

@ -56,4 +56,12 @@ public class AnnotationElement extends CompositeField<AnnotationElement>
public int compareTo(AnnotationElement annotationElement) {
return elementName.compareTo(annotationElement.elementName);
}
public StringIdItem getName() {
return elementName.getReference();
}
public EncodedValue getEncodedValue() {
return encodedValue;
}
}

View File

@ -80,4 +80,12 @@ public class AnnotationEncodedValueSubField extends CompositeField<AnnotationEnc
public ValueType getValueType() {
return ValueType.VALUE_ANNOTATION;
}
public TypeIdItem getAnnotationType() {
return annotationType.getReference();
}
public List<AnnotationElement> getAnnotationElements() {
return (List<AnnotationElement>)annotationElementList.clone();
}
}