org.objectweb.asm.tree.AnnotationNode Java Examples
The following examples show how to use
org.objectweb.asm.tree.AnnotationNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Field.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
private List<Type> resolveAnnotations() { List<Type> results = null; if (node.visibleAnnotations != null) { for (AnnotationNode an : node.visibleAnnotations) { Type annotationType = typeSystem.Lresolve(an.desc, true); if (annotationType != null) { if (results == null) { results = new ArrayList<>(); } results.add(annotationType); } } } return results == null ? Collections.emptyList() : results; }
Example #2
Source File: TypeSystem.java From spring-boot-graal-feature with Apache License 2.0 | 6 votes |
public String toAnnotationString() { StringBuilder sb = new StringBuilder(); if (annotations != null) { for (AnnotationNode an : annotations) { sb.append(an.desc); sb.append("("); List<Object> values = an.values; if (values != null) { for (int j = 0; j < values.size(); j += 2) { sb.append(values.get(j)); sb.append("="); sb.append(values.get(j + 1)); } } sb.append(")"); } } return sb.toString(); }
Example #3
Source File: Type.java From spring-boot-graal-feature with Apache License 2.0 | 6 votes |
private CompilationHint findCompilationHintHelper(HashSet<Type> visited) { if (!visited.add(this)) { return null; } if (node.visibleAnnotations != null) { for (AnnotationNode an : node.visibleAnnotations) { CompilationHint compilationHint = proposedAnnotations.get(an.desc); if (compilationHint != null) { return compilationHint; } Type resolvedAnnotation = typeSystem.Lresolve(an.desc); compilationHint = resolvedAnnotation.findCompilationHintHelper(visited); if (compilationHint != null) { return compilationHint; } } } return null; }
Example #4
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
public void getAnnotationValuesInHierarchy(String lookingFor, List<String> seen, Map<String, String> collector) { if (dimensions > 0) { return; } if (node.visibleAnnotations != null) { for (AnnotationNode anno : node.visibleAnnotations) { if (seen.contains(anno.desc)) continue; seen.add(anno.desc); // System.out.println("Comparing "+anno.desc+" with "+lookingFor); if (anno.desc.equals(lookingFor)) { List<Object> os = anno.values; for (int i = 0; i < os.size(); i += 2) { collector.put(os.get(i).toString(), os.get(i + 1).toString()); } } try { Type resolve = typeSystem.Lresolve(anno.desc); resolve.getAnnotationValuesInHierarchy(lookingFor, seen, collector); } catch (MissingTypeException mte) { // not on classpath, that's ok } } } }
Example #5
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
public boolean hasAnnotationInHierarchy(String lookingFor, List<String> seen) { if (dimensions > 0) { return false; } if (node.visibleAnnotations != null) { for (AnnotationNode anno : node.visibleAnnotations) { if (seen.contains(anno.desc)) continue; seen.add(anno.desc); // System.out.println("Comparing "+anno.desc+" with "+lookingFor); if (anno.desc.equals(lookingFor)) { return true; } try { Type resolve = typeSystem.Lresolve(anno.desc); if (resolve.hasAnnotationInHierarchy(lookingFor, seen)) { return true; } } catch (MissingTypeException mte) { // not on classpath, that's ok } } } return false; }
Example #6
Source File: Type.java From spring-boot-graal-feature with Apache License 2.0 | 6 votes |
private void collectHints(AnnotationNode an, Map<HintDescriptor, List<String>> hints, Set<AnnotationNode> visited, Stack<Type> annotationChain) { if (!visited.add(an)) { return; } try { annotationChain.push(this); // Am I a compilation hint? CompilationHint hint = proposedAnnotations.get(an.desc); if (hint !=null) { hints.put(new HintDescriptor(new ArrayList<>(annotationChain), hint.skipIfTypesMissing, hint.follow, hint.name), collectTypes(an)); } // check for meta annotation if (node.visibleAnnotations != null) { for (AnnotationNode an2: node.visibleAnnotations) { Type annotationType = typeSystem.Lresolve(an2.desc, true); if (annotationType == null) { System.out.println("Couldn't resolve "+an2.desc); } else { annotationType.collectHints(an2, hints, visited, annotationChain); } } } } finally { annotationChain.pop(); } }
Example #7
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
public boolean isAnnotated(String Ldescriptor, boolean checkMetaUsage) { if (dimensions > 0) { return false; } if (checkMetaUsage) { return isMetaAnnotated(Ldescriptor); } if (node.visibleAnnotations != null) { for (AnnotationNode an : node.visibleAnnotations) { if (an.desc.equals(Ldescriptor)) { return true; } } } return false; }
Example #8
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
private List<Type> getJavaxAnnotations(Set<String> seen) { if (dimensions > 0) return Collections.emptyList(); List<Type> result = new ArrayList<>(); if (node.visibleAnnotations != null) { for (AnnotationNode an : node.visibleAnnotations) { if (seen.add(an.desc)) { Type annoType = typeSystem.Lresolve(an.desc, true); if (annoType != null) { if (annoType.getDottedName().startsWith("javax.")) { result.add(annoType); } else { List<Type> ts = annoType.getJavaxAnnotations(seen); result.addAll(ts); } } } } } return result; }
Example #9
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
private List<CompilationHint> findCompilationHintHelper(HashSet<Type> visited) { if (!visited.add(this)) { return null; } if (node.visibleAnnotations != null) { for (AnnotationNode an : node.visibleAnnotations) { List<CompilationHint> compilationHints = typeSystem.findHints(an.desc);// SpringConfiguration.findProposedHints(an.desc); if (compilationHints.size() != 0) { return compilationHints; } Type resolvedAnnotation = typeSystem.Lresolve(an.desc); compilationHints = resolvedAnnotation.findCompilationHintHelper(visited); if (compilationHints.size() != 0) { return compilationHints; } } } return null; }
Example #10
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private List<String> collectTypes(AnnotationNode an) { List<Object> values = an.values; if (values != null) { for (int i = 0; i < values.size(); i += 2) { if (values.get(i).equals("value")) { // For some annotations it is a list, for some a single class (e.g. // @ConditionalOnSingleCandidate) Object object = values.get(i + 1); List<String> importedReferences = null; if (object instanceof List) { importedReferences = ((List<org.objectweb.asm.Type>) object).stream() .map(t -> t.getDescriptor()).collect(Collectors.toList()); } else { importedReferences = new ArrayList<>(); importedReferences.add(((org.objectweb.asm.Type) object).getDescriptor()); } return importedReferences; } } } return Collections.emptyList(); }
Example #11
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
public void collectMissingAnnotationTypesHelper(Set<String> missingAnnotationTypes, HashSet<Type> visited) { if (dimensions > 0) return; if (!visited.add(this)) { return; } if (node.visibleAnnotations != null) { for (AnnotationNode an : node.visibleAnnotations) { Type annotationType = typeSystem.Lresolve(an.desc, true); if (annotationType == null) { missingAnnotationTypes.add(an.desc.substring(0, an.desc.length() - 1).replace("/", ".")); } else { annotationType.collectMissingAnnotationTypesHelper(missingAnnotationTypes, visited); } } } }
Example #12
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public List<Type> getAutoConfigureBeforeOrAfter() { if (dimensions > 0) return Collections.emptyList(); List<Type> result = new ArrayList<>(); for (AnnotationNode an : node.visibleAnnotations) { if (an.desc.equals("Lorg/springframework/boot/autoconfigure/AutoConfigureAfter;") || an.desc.equals("Lorg/springframework/boot/autoconfigure/AutoConfigureBefore;")) { List<Object> values = an.values; if (values != null) { for (int i = 0; i < values.size(); i += 2) { if (values.get(i).equals("value")) { List<org.objectweb.asm.Type> types = (List<org.objectweb.asm.Type>) values.get(i + 1); for (org.objectweb.asm.Type type : types) { Type t = typeSystem.Lresolve(type.getDescriptor(), true); if (t != null) { result.add(t); } } } } } } } return result; }
Example #13
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
/** * Find the @ConfigurationHint annotations on this type (may be more than one) * and from them build CompilationHints, taking care to convert class references * to strings because they may not be resolvable. TODO ok to discard those that * aren't resolvable at this point? * * @return */ public List<CompilationHint> unpackConfigurationHints() { if (dimensions > 0) return Collections.emptyList(); List<CompilationHint> hints = null; if (node.visibleAnnotations != null) { for (AnnotationNode an : node.visibleAnnotations) { if (fromLdescriptorToDotted(an.desc).equals(NativeImageHint.class.getName())) { CompilationHint hint = fromConfigurationHintToCompilationHint(an); if (hints == null) { hints = new ArrayList<>(); } hints.add(hint); } else if (fromLdescriptorToDotted(an.desc).equals(NativeImageHints.class.getName())) { List<CompilationHint> chints = fromConfigurationHintsToCompilationHints(an); if (hints == null) { hints = new ArrayList<>(); } hints.addAll(chints); } } } // TODO support repeatable version return hints == null ? Collections.emptyList() : hints; }
Example #14
Source File: Type.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private List<CompilationHint> fromConfigurationHintsToCompilationHints(AnnotationNode an) { List<CompilationHint> chs = new ArrayList<>(); List<Object> values = an.values; for (int i = 0; i < values.size(); i += 2) { String key = (String) values.get(i); Object value = values.get(i + 1); if (key.equals("value")) { // value=[org.objectweb.asm.tree.AnnotationNode@63e31ee, // org.objectweb.asm.tree.AnnotationNode@68fb2c38] List<AnnotationNode> annotationNodes = (List<AnnotationNode>) value; for (int j = 0; j < annotationNodes.size(); j++) { chs.add(fromConfigurationHintToCompilationHint(annotationNodes.get(j))); } } } return chs; }
Example #15
Source File: Method.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
public List<Hint> getHints() { List<Hint> hints = new ArrayList<>(); if (mn.visibleAnnotations != null) { for (AnnotationNode an: mn.visibleAnnotations) { Type annotationType = typeSystem.Lresolve(an.desc, true); if (annotationType == null) { SpringFeature.log("Couldn't resolve "+an.desc+" annotation type whilst searching for hints on "+getName()); } else { Stack<Type> s = new Stack<>(); // s.push(this); annotationType.collectHints(an, hints, new HashSet<>(), s); } } } return hints.size()==0?Collections.emptyList():hints; }
Example #16
Source File: Type.java From spring-boot-graal-feature with Apache License 2.0 | 6 votes |
public boolean hasAnnotationInHierarchy(String lookingFor, List<String> seen) { if (node.visibleAnnotations != null) { for (AnnotationNode anno : node.visibleAnnotations) { if (seen.contains(anno.desc)) continue; seen.add(anno.desc); // System.out.println("Comparing "+anno.desc+" with "+lookingFor); if (anno.desc.equals(lookingFor)) { return true; } try { Type resolve = typeSystem.Lresolve(anno.desc); if (resolve.hasAnnotationInHierarchy(lookingFor, seen)) { return true; } } catch (MissingTypeException mte) { // not on classpath, that's ok } } } return false; }
Example #17
Source File: TypeSystem.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
public String toAnnotationString() { StringBuilder sb = new StringBuilder(); if (annotations != null) { for (AnnotationNode an : annotations) { sb.append(an.desc); sb.append("("); List<Object> values = an.values; if (values != null) { for (int j = 0; j < values.size(); j += 2) { sb.append(values.get(j)); sb.append("="); sb.append(values.get(j + 1)); } } sb.append(")"); } } return sb.toString(); }
Example #18
Source File: TypeSystem.java From spring-graalvm-native with Apache License 2.0 | 6 votes |
private void collectMetaAnnotations() { for (AnnotationNode an : annotations) { // Go through our annotations and grab their meta annotations AnnotationInfo ai = typeSystem.annotatedTypes.get(an.desc.substring(1, an.desc.length() - 1)); if (ai != null && ai.hasData()) { metaAnnotationsList.addAll(ai.getAnnotations()); metaAnnotationsList.addAll(ai.getMetaAnnotations()); if (name.endsWith("DemoApplication")) { System.out.println("111"); for (AnnotationNode ann : metaAnnotationsList) { System.out.println(ann.desc); } System.out.println("222"); } } } }
Example #19
Source File: CustomMethodVisitor.java From custom-bytecode-analyzer with GNU General Public License v3.0 | 6 votes |
private boolean isParameterAnnotationFound(List<Annotation> annotationRules, MethodNode methodNode) { boolean annotationFound = true; List<AnnotationNode> allParameterAnnotations = new ArrayList<>(); List<AnnotationNode>[] visibleParameterAnnotations = methodNode.visibleParameterAnnotations; if (visibleParameterAnnotations != null && visibleParameterAnnotations.length != 0) { addIfNotNull(allParameterAnnotations, visibleParameterAnnotations); } List<AnnotationNode>[] inVisibleParameterAnnotations = methodNode.invisibleParameterAnnotations; if (inVisibleParameterAnnotations != null && inVisibleParameterAnnotations.length != 0) { addIfNotNull(allParameterAnnotations, inVisibleParameterAnnotations); } if (annotationRules != null && !annotationRules.isEmpty()) { for (Annotation annotationRule : annotationRules) { annotationFound &= RuleHelper.containsAnnotation(annotationRule, allParameterAnnotations); } } return annotationFound; }
Example #20
Source File: MethodFlow.java From Concurnas with MIT License | 6 votes |
public static void acceptAnnotation(final AnnotationVisitor av, final String name, final Object value) { if (value instanceof String[]) { String[] typeconst = (String[]) value; av.visitEnum(name, typeconst[0], typeconst[1]); } else if (value instanceof AnnotationNode) { AnnotationNode an = (AnnotationNode) value; an.accept(av.visitAnnotation(name, an.desc)); } else if (value instanceof List<?>) { AnnotationVisitor v = av.visitArray(name); List<?> array = (List<?>) value; for (int j = 0; j < array.size(); ++j) { acceptAnnotation(v, null, array.get(j)); } v.visitEnd(); } else { av.visit(name, value); } }
Example #21
Source File: Fiberizer.java From Concurnas with MIT License | 6 votes |
boolean needsWeaving(MethodFlow mf) { List<AnnotationNode> methodAnnotations = mf.visibleAnnotations; boolean forceFiber = false; if(methodAnnotations != null){ for(AnnotationNode an : methodAnnotations){ if(an.desc.equals("Lcom/concurnas/runtime/ForceCPS;")){ forceFiber = true; } break; } } if ( (!mf.isPausable() || mf.name.equals("<clinit>") || mf.name.equals("<init>") || mf.desc.endsWith(FIBER_SUFFIX)) && !forceFiber ){ return false; } String fdesc = mf.desc.replace(")", FIBER_SUFFIX); for (MethodFlow omf : classFlow.getMethodFlows()) { if (omf == mf){ continue; } if (mf.name.equals(omf.name) && fdesc.equals(omf.desc)) { return false; } } return true; }
Example #22
Source File: AsmUtils.java From Stark with Apache License 2.0 | 6 votes |
@NonNull public static List<AnnotationNode> getInvisibleAnnotationsOnClassOrOuterClasses( @NonNull ClassNodeProvider classReader, @NonNull ClassNode classNode) throws IOException { ImmutableList.Builder<AnnotationNode> listBuilder = ImmutableList.builder(); do { @SuppressWarnings("unchecked") List<AnnotationNode> invisibleAnnotations = classNode.invisibleAnnotations; if (invisibleAnnotations != null) { listBuilder.addAll(invisibleAnnotations); } String outerClassName = getOuterClassName(classNode); classNode = outerClassName != null ? classReader.loadClassNode(outerClassName) : null; } while (classNode != null); return listBuilder.build(); }
Example #23
Source File: MonitorVisitor.java From Stark with Apache License 2.0 | 6 votes |
static boolean isClassTargetingNewerPlatform( int targetApiLevel, @NonNull Type targetApiAnnotationType, @NonNull AsmUtils.ClassNodeProvider locator, @NonNull ClassNode classNode) throws IOException { List<AnnotationNode> invisibleAnnotations = AsmUtils.getInvisibleAnnotationsOnClassOrOuterClasses(locator, classNode); for (AnnotationNode classAnnotation : invisibleAnnotations) { if (classAnnotation.desc.equals(targetApiAnnotationType.getDescriptor())) { int valueIndex = 0; List values = classAnnotation.values; while (valueIndex < values.size()) { String name = (String) values.get(valueIndex); if (name.equals("value")) { Object value = values.get(valueIndex + 1); return Integer.class.cast(value) > targetApiLevel; } valueIndex = valueIndex + 2; } } } return false; }
Example #24
Source File: MainBuildTask.java From Launcher with GNU General Public License v3.0 | 6 votes |
@Override public void transform(ClassNode cn, String classname, BuildContext context) { for (FieldNode fn : cn.fields) { if (fn.invisibleAnnotations == null || fn.invisibleAnnotations.isEmpty()) continue; AnnotationNode found = null; for (AnnotationNode an : fn.invisibleAnnotations) { if (an == null) continue; if (desc.equals(an.desc)) { found = an; break; } } if (found != null) { transformField(found, fn, cn, classname, context); } } }
Example #25
Source File: CustomClassAnnotationVisitor.java From custom-bytecode-analyzer with GNU General Public License v3.0 | 6 votes |
@Override public void process() { boolean issueFound; List<AnnotationNode> allAnnotations = new ArrayList<>(); List<AnnotationNode> visibleAnnotations = getClassNode().visibleAnnotations; if (visibleAnnotations != null) { allAnnotations.addAll(visibleAnnotations); } List<AnnotationNode> invisibleAnnotations = getClassNode().invisibleAnnotations; if (invisibleAnnotations != null) { allAnnotations.addAll(invisibleAnnotations); } for (AnnotationNode annotationNode : allAnnotations) { String desc = annotationNode.desc; boolean visible = visibleAnnotations == null ? false : visibleAnnotations.contains(annotationNode); logger.trace("visitAnnotation: desc={}, visible={}", desc, visible); issueFound = StringsHelper.simpleDescriptorToHuman(desc).equals(StringsHelper.dotsToSlashes(annotation.getType())); if (issueFound) { ReportItem reportItem = new ReportItem(getRuleName(), showInReport()); this.itemsFound().add(reportItem); this.setIssueFound(true); } } }
Example #26
Source File: DetourLoader.java From android-perftracking with MIT License | 6 votes |
private Detour callDetour(ClassNode cn, MethodNode mn, AnnotationNode a) { String owner = getFirstParameter(mn); if (owner == null) { _log.debug("Could not get parameter type for detour " + mn.name + mn.desc); return null; } MethodInsnNode mi = getMethodInstruction(mn, owner, mn.name); if (mi == null) { _log.debug("Could not get method instruction for detour " + mn.name + mn.desc); return null; } CallDetour detour = new CallDetour(_log); detour.matchMethod = mn.name; detour.matchDesc = mi.desc; detour.owner = owner.replace('/', '.'); detour.detourOwner = cn.name; detour.detourDesc = mn.desc; return detour; }
Example #27
Source File: CustomMethodVisitor.java From custom-bytecode-analyzer with GNU General Public License v3.0 | 6 votes |
private boolean isMethodAnnotationFound(List<Annotation> annotationRules, MethodNode methodNode) { boolean annotationFound = true; List<AnnotationNode> allMethodAnnotations = new ArrayList<>(); List<AnnotationNode> invisibleAnnotations = methodNode.invisibleAnnotations; if (invisibleAnnotations != null) { allMethodAnnotations.addAll(invisibleAnnotations); } List<AnnotationNode> visibleAnnotations = methodNode.visibleAnnotations; if (visibleAnnotations != null) { allMethodAnnotations.addAll(visibleAnnotations); } for (Annotation annotationRule : annotationRules) { annotationFound &= RuleHelper.containsAnnotation(annotationRule, allMethodAnnotations); } return annotationFound; }
Example #28
Source File: ClassTrimmer.java From android-perftracking with MIT License | 6 votes |
private boolean checkAnnotation(AnnotationNode a) { if (a.desc.equals("Lcom/rakuten/tech/mobile/perf/core/annotations/Exists;")) { if (!exists(((Type) a.values.get(1)).getClassName())) { return false; } } else if (a.desc .equals("Lcom/rakuten/tech/mobile/perf/core/annotations/MinCompileSdkVersion;")) { if (_compileSdkVersion < (int) a.values.get(1)) { return false; } } else if (a.desc .equals("Lcom/rakuten/tech/mobile/perf/core/annotations/MaxCompileSdkVersion;")) { if (_compileSdkVersion > (int) a.values.get(1)) { return false; } } return true; }
Example #29
Source File: TBIncrementalVisitor.java From atlas with Apache License 2.0 | 6 votes |
@VisibleForTesting static boolean isClassTargetingNewerPlatform( int targetApiLevel, @NonNull Type targetApiAnnotationType, @NonNull AsmUtils.ClassReaderProvider locator, @NonNull ClassNode classNode, @NonNull ILogger logger) throws IOException { List<AnnotationNode> invisibleAnnotations = AsmUtils.getInvisibleAnnotationsOnClassOrOuterClasses(locator, classNode, logger); for (AnnotationNode classAnnotation : invisibleAnnotations) { if (classAnnotation.desc.equals(targetApiAnnotationType.getDescriptor())) { int valueIndex = 0; List values = classAnnotation.values; while (valueIndex < values.size()) { String name = (String) values.get(valueIndex); if (name.equals("value")) { Object value = values.get(valueIndex + 1); return Integer.class.cast(value) > targetApiLevel; } valueIndex = valueIndex + 2; } } } return false; }
Example #30
Source File: ApiDetector.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Returns the minimum SDK to use according to the given annotation list, or * -1 if no annotation was found. * * @param annotations a list of annotation nodes from ASM * @return the API level to use for this node, or -1 */ @SuppressWarnings({"unchecked", "rawtypes"}) private static int getLocalMinSdk(List annotations) { if (annotations != null) { for (AnnotationNode annotation : (List<AnnotationNode>)annotations) { String desc = annotation.desc; if (desc.endsWith(TARGET_API_VMSIG)) { if (annotation.values != null) { for (int i = 0, n = annotation.values.size(); i < n; i += 2) { String key = (String) annotation.values.get(i); if (key.equals("value")) { //$NON-NLS-1$ Object value = annotation.values.get(i + 1); if (value instanceof Integer) { return (Integer) value; } } } } } } } return -1; }