Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4a6bcbd

Browse files
authoredMay 31, 2023
Merge pull request #611 from soot-oss/VisibleAnnotation
Store Visible Annotations
2 parents 62f9959 + 4a429a2 commit 4a6bcbd

File tree

7 files changed

+59
-2
lines changed

7 files changed

+59
-2
lines changed
 
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.lang.annotation.Retention;
2+
import java.lang.annotation.RetentionPolicy;
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Target;
5+
6+
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.TYPE)
10+
@interface InterfaceVisibleAnnotation {
11+
12+
}
13+
14+
@InterfaceVisibleAnnotation
15+
public class VisibleAnnotation{
16+
17+
}
18+
19+

‎sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmAnnotationClassSource.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,20 @@ private static Stream<JavaAnnotationSootMethod> resolveMethods(
115115
MethodSignature methodSignature =
116116
signatureFactory.getMethodSignature(cs, methodName, retType, sigTypes);
117117

118+
List<AnnotationNode> annotations = new ArrayList<>();
119+
if (methodSource.visibleAnnotations != null)
120+
annotations.addAll(methodSource.visibleAnnotations);
121+
if (methodSource.invisibleAnnotations != null)
122+
annotations.addAll(methodSource.invisibleAnnotations);
123+
118124
// TODO: position/line numbers if possible
119125

120126
return new JavaAnnotationSootMethod(
121127
asmClassClassSourceContent,
122128
methodSignature,
123129
modifiers,
124130
exceptions,
125-
convertAnnotation(methodSource.invisibleAnnotations),
131+
convertAnnotation(annotations),
126132
NoPositionInformation.getInstance());
127133
});
128134
}

‎sootup.java.bytecode/src/main/java/sootup/java/bytecode/frontend/AsmClassSource.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,19 @@ public Collection<? extends SootMethod> resolveMethods() throws ResolveException
128128
identifierFactory.getMethodSignature(
129129
classSignature, methodName, retType, sigTypes);
130130

131+
List<AnnotationNode> annotations = new ArrayList<>();
132+
if (methodSource.visibleAnnotations != null)
133+
annotations.addAll(methodSource.visibleAnnotations);
134+
if (methodSource.invisibleAnnotations != null)
135+
annotations.addAll(methodSource.invisibleAnnotations);
136+
131137
// TODO: position/line numbers if possible
132138
return new JavaSootMethod(
133139
asmClassClassSourceContent,
134140
methodSignature,
135141
modifiers,
136142
exceptions,
137-
convertAnnotation(methodSource.invisibleAnnotations),
143+
convertAnnotation(annotations),
138144
NoPositionInformation.getInstance());
139145
})
140146
.collect(Collectors.toSet());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package sootup.java.bytecode.minimaltestsuite.java6;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import java.util.*;
6+
import org.junit.Test;
7+
import sootup.core.signatures.PackageName;
8+
import sootup.java.bytecode.minimaltestsuite.MinimalBytecodeTestSuiteBase;
9+
import sootup.java.core.AnnotationUsage;
10+
import sootup.java.core.JavaSootClass;
11+
import sootup.java.core.types.AnnotationType;
12+
13+
public class VisibleAnnotationTest extends MinimalBytecodeTestSuiteBase {
14+
15+
@Test
16+
public void testVisibleAnnotationOnClassOrAnnotation() {
17+
JavaSootClass sootClass = loadClass(getDeclaredClassSignature());
18+
19+
assertEquals(
20+
Arrays.asList(
21+
new AnnotationUsage(
22+
new AnnotationType("InterfaceVisibleAnnotation", new PackageName(""), false),
23+
Collections.emptyMap())),
24+
sootClass.getAnnotations(Optional.of(customTestWatcher.getJavaView())));
25+
}
26+
}

0 commit comments

Comments
 (0)
Failed to load comments.