use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.
the class AbstractJasminClass method emitMethod.
protected void emitMethod(SootMethod method) {
if (method.isPhantom())
return;
// Emit prologue
emit(".method " + Modifier.toString(method.getModifiers()) + " " + method.getName() + jasminDescriptorOf(method.makeRef()));
Iterator<SootClass> throwsIt = method.getExceptions().iterator();
while (throwsIt.hasNext()) {
SootClass exceptClass = throwsIt.next();
emit(".throws " + exceptClass.getName());
}
if (method.hasTag("SyntheticTag") || Modifier.isSynthetic(method.getModifiers())) {
emit(".synthetic");
}
if (method.hasTag("DeprecatedTag")) {
emit(".deprecated");
}
if (method.hasTag("SignatureTag")) {
String sigAttr = ".signature_attr ";
SignatureTag sigTag = (SignatureTag) method.getTag("SignatureTag");
sigAttr += "\"" + sigTag.getSignature() + "\"";
emit(sigAttr);
}
if (method.hasTag("AnnotationDefaultTag")) {
String annotDefAttr = ".annotation_default ";
AnnotationDefaultTag annotDefTag = (AnnotationDefaultTag) method.getTag("AnnotationDefaultTag");
annotDefAttr += getElemAttr(annotDefTag.getDefaultVal());
annotDefAttr += ".end .annotation_default";
emit(annotDefAttr);
}
Iterator<Tag> vit = method.getTags().iterator();
while (vit.hasNext()) {
Tag t = (Tag) vit.next();
if (t.getName().equals("VisibilityAnnotationTag")) {
emit(getVisibilityAnnotationAttr((VisibilityAnnotationTag) t));
}
if (t.getName().equals("VisibilityParameterAnnotationTag")) {
emit(getVisibilityParameterAnnotationAttr((VisibilityParameterAnnotationTag) t));
}
}
if (method.isConcrete()) {
if (!method.hasActiveBody())
throw new RuntimeException("method: " + method.getName() + " has no active body!");
else
emitMethodBody(method);
}
// Emit epilogue
emit(".end method");
Iterator<Tag> it = method.getTags().iterator();
while (it.hasNext()) {
Tag tag = (Tag) it.next();
if (tag instanceof Attribute)
emit(".method_attribute " + tag.getName() + " \"" + new String(Base64.encode(tag.getValue())) + "\"");
}
}
use of soot.tagkit.VisibilityParameterAnnotationTag in project robovm by robovm.
the class Annotations method getParameterAnnotations.
public static List<AnnotationTag>[] getParameterAnnotations(SootMethod method, Visibility visibility) {
@SuppressWarnings("unchecked") ArrayList<AnnotationTag>[] result = new ArrayList[method.getParameterCount()];
for (int i = 0; i < result.length; i++) {
result[i] = new ArrayList<>();
}
for (Tag tag : method.getTags()) {
if (tag instanceof VisibilityParameterAnnotationTag) {
if (visibility == Visibility.Any || ((VisibilityParameterAnnotationTag) tag).getKind() == visibility.ordinal()) {
ArrayList<VisibilityAnnotationTag> l = ((VisibilityParameterAnnotationTag) tag).getVisibilityAnnotations();
if (l != null) {
int i = 0;
for (VisibilityAnnotationTag t : l) {
ArrayList<AnnotationTag> annotations = t.getAnnotations();
if (annotations != null) {
result[i].addAll(annotations);
}
i++;
}
}
}
}
}
return result;
}
use of soot.tagkit.VisibilityParameterAnnotationTag in project robovm by robovm.
the class Annotations method copyParameterAnnotations.
private static void copyParameterAnnotations(SootMethod fromMethod, SootMethod toMethod, int start, int end, int shift, int visibility) {
List<AnnotationTag>[] fromAnnos = getParameterAnnotations(fromMethod, Visibility.values()[visibility]);
List<AnnotationTag>[] toAnnos = getParameterAnnotations(toMethod, Visibility.values()[visibility]);
for (int i = start; i < end; i++) {
toAnnos[i + shift].addAll(fromAnnos[i]);
}
for (Iterator<Tag> it = toMethod.getTags().iterator(); it.hasNext(); ) {
Tag tag = it.next();
if (tag instanceof VisibilityParameterAnnotationTag) {
if (((VisibilityParameterAnnotationTag) tag).getKind() == visibility) {
it.remove();
}
}
}
VisibilityParameterAnnotationTag vpaTag = new VisibilityParameterAnnotationTag(toAnnos.length, visibility);
for (List<AnnotationTag> annos : toAnnos) {
VisibilityAnnotationTag vaTag = new VisibilityAnnotationTag(visibility);
for (AnnotationTag anno : annos) {
vaTag.addAnnotation(anno);
}
vpaTag.addVisibilityAnnotation(vaTag);
}
toMethod.addTag(vpaTag);
}
use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.
the class DexPrinter method buildVisibilityParameterAnnotationTag.
private List<ImmutableAnnotation> buildVisibilityParameterAnnotationTag(VisibilityParameterAnnotationTag t, Set<String> skipList, int paramIdx) {
if (t.getVisibilityAnnotations() == null)
return Collections.emptyList();
int paramTagIdx = 0;
List<ImmutableAnnotation> annotations = new ArrayList<ImmutableAnnotation>();
for (VisibilityAnnotationTag vat : t.getVisibilityAnnotations()) {
if (paramTagIdx == paramIdx && vat != null && vat.getAnnotations() != null)
for (AnnotationTag at : vat.getAnnotations()) {
String type = at.getType();
if (!skipList.add(type))
continue;
Set<String> alreadyWritten = new HashSet<String>();
List<AnnotationElement> elements = null;
if (!at.getElems().isEmpty()) {
elements = new ArrayList<AnnotationElement>();
for (AnnotationElem ae : at.getElems()) {
if (ae.getName() == null || ae.getName().isEmpty())
throw new RuntimeException("Null or empty annotation name encountered");
if (!alreadyWritten.add(ae.getName()))
throw new RuntimeException("Duplicate annotation attribute: " + ae.getName());
EncodedValue value = buildEncodedValueForAnnotation(ae);
ImmutableAnnotationElement element = new ImmutableAnnotationElement(ae.getName(), value);
elements.add(element);
}
}
ImmutableAnnotation ann = new ImmutableAnnotation(getVisibility(vat.getVisibility()), SootToDexUtils.getDexClassName(at.getType()), elements);
annotations.add(ann);
}
paramTagIdx++;
}
return annotations;
}
use of soot.tagkit.VisibilityParameterAnnotationTag in project soot by Sable.
the class MethodBuilder method visitEnd.
@Override
public void visitEnd() {
super.visitEnd();
if (visibleParamAnnotations != null) {
VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(visibleParamAnnotations.length, AnnotationConstants.RUNTIME_VISIBLE);
for (VisibilityAnnotationTag vat : visibleParamAnnotations) {
tag.addVisibilityAnnotation(vat);
}
method.addTag(tag);
}
if (invisibleParamAnnotations != null) {
VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(invisibleParamAnnotations.length, AnnotationConstants.RUNTIME_INVISIBLE);
for (VisibilityAnnotationTag vat : invisibleParamAnnotations) {
tag.addVisibilityAnnotation(vat);
}
method.addTag(tag);
}
if (method.isConcrete()) {
method.setSource(new AsmMethodSource(maxLocals, instructions, localVariables, tryCatchBlocks));
}
}
Aggregations