ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Ljava/lang/Deprecated;", Collections.<AnnotationElement>emptySet()); annotations.add(ann); = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Signature;", elements); annotations.add(ann); skipList.add("Ldalvik/annotation/Signature;");
private Set<Annotation> buildMethodAnnotations(SootMethod m) { Set<String> skipList = new HashSet<String>(); Set<Annotation> annotations = buildCommonAnnotations(m, skipList); for (Tag t : m.getTags()) { if (t.getName().equals("VisibilityAnnotationTag")) { List<ImmutableAnnotation> visibilityItems = buildVisibilityAnnotationTag((VisibilityAnnotationTag) t, skipList); annotations.addAll(visibilityItems); } } List<SootClass> exceptionList = m.getExceptionsUnsafe(); if (exceptionList != null && !exceptionList.isEmpty()) { List<ImmutableEncodedValue> valueList = new ArrayList<ImmutableEncodedValue>(exceptionList.size()); for (SootClass exceptionClass : exceptionList) { valueList.add(new ImmutableTypeEncodedValue(DexType.toDalvikICAT(exceptionClass.getName()).replace(".", "/"))); } ImmutableArrayEncodedValue valueValue = new ImmutableArrayEncodedValue(valueList); ImmutableAnnotationElement valueElement = new ImmutableAnnotationElement("value", valueValue); Set<ImmutableAnnotationElement> elements = Collections.singleton(valueElement); ImmutableAnnotation ann = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/Throws;", elements); annotations.add(ann); } return annotations; }
private Annotation buildEnclosingMethodTag(EnclosingMethodTag t, Set<String> skipList) { if (!skipList.add("Ldalvik/annotation/EnclosingMethod;")) { return null; } if (t.getEnclosingMethod() == null) { return null; } String[] split1 = t.getEnclosingMethodSig().split("\\)"); String parametersS = split1[0].replaceAll("\\(", ""); String returnTypeS = split1[1]; List<String> typeList = new ArrayList<String>(); if (!parametersS.equals("")) { for (String p : Util.splitParameters(parametersS)) { if (!p.isEmpty()) { typeList.add(p); } } } ImmutableMethodReference mRef = new ImmutableMethodReference(SootToDexUtils.getDexClassName(t.getEnclosingClass()), t.getEnclosingMethod(), typeList, returnTypeS); ImmutableMethodEncodedValue methodRef = new ImmutableMethodEncodedValue(mRef); AnnotationElement methodElement = new ImmutableAnnotationElement("value", methodRef); return new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/EnclosingMethod;", Collections.singleton(methodElement)); }
ImmutableAnnotation memberAnnotation = new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/MemberClasses;", Collections.singletonList(element)); if (anns == null) {
ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(t.getVisibility()), typeName, elements); annotations.add(ann);
ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(vat.getVisibility()), SootToDexUtils.getDexClassName(at.getType()), elements); annotations.add(ann);
anns = new ArrayList<Annotation>(); anns.add(new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/InnerClass;", elements));
annotations.add(new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/EnclosingClass;", Collections.singleton(enclosingElement)));
public final Annotation annotation() throws RecognitionException { Annotation annotation = null; CommonTree ANNOTATION_VISIBILITY235=null; TreeRuleReturnScope subannotation236 =null; try { // smaliTreeWalker.g:1391:3: ( ^( I_ANNOTATION ANNOTATION_VISIBILITY subannotation ) ) // smaliTreeWalker.g:1391:5: ^( I_ANNOTATION ANNOTATION_VISIBILITY subannotation ) { match(input,I_ANNOTATION,FOLLOW_I_ANNOTATION_in_annotation3897); match(input, Token.DOWN, null); ANNOTATION_VISIBILITY235=(CommonTree)match(input,ANNOTATION_VISIBILITY,FOLLOW_ANNOTATION_VISIBILITY_in_annotation3899); pushFollow(FOLLOW_subannotation_in_annotation3901); subannotation236=subannotation(); state._fsp--; match(input, Token.UP, null); int visibility = AnnotationVisibility.getVisibility((ANNOTATION_VISIBILITY235!=null?ANNOTATION_VISIBILITY235.getText():null)); annotation = new ImmutableAnnotation(visibility, (subannotation236!=null?((smaliTreeWalker.subannotation_return)subannotation236).annotationType:null), (subannotation236!=null?((smaliTreeWalker.subannotation_return)subannotation236).elements:null)); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { // do for sure before leaving } return annotation; } // $ANTLR end "annotation"
public static ImmutableAnnotation of(Annotation annotation) { if (annotation instanceof ImmutableAnnotation) { return (ImmutableAnnotation)annotation; } return new ImmutableAnnotation( annotation.getVisibility(), annotation.getType(), annotation.getElements()); }
public static ImmutableAnnotation of(Annotation annotation) { if (annotation instanceof ImmutableAnnotation) { return (ImmutableAnnotation)annotation; } return new ImmutableAnnotation( annotation.getVisibility(), annotation.getType(), annotation.getElements()); }
public static ImmutableAnnotation of(Annotation annotation) { if (annotation instanceof ImmutableAnnotation) { return (ImmutableAnnotation)annotation; } return new ImmutableAnnotation( annotation.getVisibility(), annotation.getType(), annotation.getElements()); }
ImmutableAnnotation immutableAnnotation = new ImmutableAnnotation(annotation.getVisibility(), newType, newAnnotationElement); newAnnotations.add(immutableAnnotation);
return new ImmutableAnnotation(annotation.getVisibility(), newType, newAnnotationElement);
@Test public void testAnnotationElementOrder() { // Elements are out of order wrt to the element name ImmutableSet<ImmutableAnnotationElement> elements = ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE)); ImmutableAnnotation annotation = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lorg/test/anno;", elements); ImmutableClassDef classDef = new ImmutableClassDef("Lorg/test/blah;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.of(annotation), null, null); MemoryDataStore dataStore = new MemoryDataStore(); try { DexPool.writeTo(dataStore, new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of(classDef))); } catch (IOException ex) { throw new RuntimeException(ex); } DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer()); ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null); Assert.assertNotNull(dbClassDef); Annotation dbAnnotation = Iterables.getFirst(dbClassDef.getAnnotations(), null); Assert.assertNotNull(dbAnnotation); List<AnnotationElement> dbElements = Lists.newArrayList(dbAnnotation.getElements()); // Ensure that the elements were written out in sorted order Assert.assertEquals(2, dbElements.size()); Assert.assertEquals("blah", dbElements.get(0).getName()); Assert.assertEquals("zabaglione", dbElements.get(1).getName()); }
ImmutableSet.of(new ImmutableAnnotationElement("encoded_annotation", encodedAnnotations)); ImmutableAnnotation annotation = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lorg/test/anno;", elements);
public final Annotation annotation() throws RecognitionException { Annotation annotation = null; CommonTree ANNOTATION_VISIBILITY202=null; TreeRuleReturnScope subannotation203 =null; try { // D:\\decomplier_tools\\smali\\smali\\smali\\src\\main\\antlr3\\smaliTreeWalker.g:1235:3: ( ^( I_ANNOTATION ANNOTATION_VISIBILITY subannotation ) ) // D:\\decomplier_tools\\smali\\smali\\smali\\src\\main\\antlr3\\smaliTreeWalker.g:1235:5: ^( I_ANNOTATION ANNOTATION_VISIBILITY subannotation ) { match(input,I_ANNOTATION,FOLLOW_I_ANNOTATION_in_annotation3453); match(input, Token.DOWN, null); ANNOTATION_VISIBILITY202=(CommonTree)match(input,ANNOTATION_VISIBILITY,FOLLOW_ANNOTATION_VISIBILITY_in_annotation3455); pushFollow(FOLLOW_subannotation_in_annotation3457); subannotation203=subannotation(); state._fsp--; match(input, Token.UP, null); int visibility = AnnotationVisibility.getVisibility((ANNOTATION_VISIBILITY202!=null?ANNOTATION_VISIBILITY202.getText():null)); annotation = new ImmutableAnnotation(visibility, (subannotation203!=null?((smaliTreeWalker.subannotation_return)subannotation203).annotationType:null), (subannotation203!=null?((smaliTreeWalker.subannotation_return)subannotation203).elements:null)); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { // do for sure before leaving } return annotation; } // $ANTLR end "annotation"
public final Annotation annotation() throws RecognitionException { Annotation annotation = null; CommonTree ANNOTATION_VISIBILITY235=null; TreeRuleReturnScope subannotation236 =null; try { // smaliTreeWalker.g:1391:3: ( ^( I_ANNOTATION ANNOTATION_VISIBILITY subannotation ) ) // smaliTreeWalker.g:1391:5: ^( I_ANNOTATION ANNOTATION_VISIBILITY subannotation ) { match(input,I_ANNOTATION,FOLLOW_I_ANNOTATION_in_annotation3897); match(input, Token.DOWN, null); ANNOTATION_VISIBILITY235=(CommonTree)match(input,ANNOTATION_VISIBILITY,FOLLOW_ANNOTATION_VISIBILITY_in_annotation3899); pushFollow(FOLLOW_subannotation_in_annotation3901); subannotation236=subannotation(); state._fsp--; match(input, Token.UP, null); int visibility = AnnotationVisibility.getVisibility((ANNOTATION_VISIBILITY235!=null?ANNOTATION_VISIBILITY235.getText():null)); annotation = new ImmutableAnnotation(visibility, (subannotation236!=null?((smaliTreeWalker.subannotation_return)subannotation236).annotationType:null), (subannotation236!=null?((smaliTreeWalker.subannotation_return)subannotation236).elements:null)); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { // do for sure before leaving } return annotation; } // $ANTLR end "annotation"
new ImmutableIntEncodedValue(AccessFlags.FINAL.getValue()))); ImmutableAnnotation annotation = new ImmutableAnnotation(0, "Ldalvik/annotation/InnerClass;", elements); ImmutableClassDef def = new ImmutableClassDef("Lfoo/Bar;", 0,
@Test public void testRollback() throws IOException { ClassDef class1 = new ImmutableClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, Lists.newArrayList(new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lannotation;", null)), Lists.<Field>newArrayList( new ImmutableField("Lcls1;", "field1", "I", AccessFlags.PUBLIC.getValue(), null, null) Lists.newArrayList(new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lannotation2;", null)), Lists.<Field>newArrayList( new ImmutableField("Lcls2;", "field2", "D", AccessFlags.PUBLIC.getValue(), null, null)