本文整理汇总了Java中javassist.bytecode.AnnotationsAttribute.getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationsAttribute.getAnnotations方法的具体用法?Java AnnotationsAttribute.getAnnotations怎么用?Java AnnotationsAttribute.getAnnotations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.AnnotationsAttribute
的用法示例。
在下文中一共展示了AnnotationsAttribute.getAnnotations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAnnotationDescriptors
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private List<AnnotationDescriptor> getAnnotationDescriptors(AnnotationsAttribute annotationsAttr) {
List<AnnotationDescriptor> annotationDescriptors = new ArrayList<>(annotationsAttr.numAnnotations());
for (javassist.bytecode.annotation.Annotation annotation : annotationsAttr.getAnnotations()) {
// Sigh: javassist uses raw collections (is this 2002?)
@SuppressWarnings("unchecked")
Set<String> memberNames = annotation.getMemberNames();
List<AttributeDescriptor> attributes = new ArrayList<>();
if (memberNames != null) {
for (String name : memberNames) {
MemberValue memberValue = annotation.getMemberValue(name);
final List<String> values = new ArrayList<>();
memberValue.accept(new ListingMemberValueVisitor(values));
attributes.add(new AttributeDescriptor(name, values));
}
}
annotationDescriptors.add(new AnnotationDescriptor(annotation.getTypeName(), attributes));
}
return annotationDescriptors;
}
示例2: scan
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
@Override
public void scan(final Object cls) {
final ClassFile classFile = (ClassFile)cls;
AnnotationsAttribute annotations = ((AnnotationsAttribute)classFile.getAttribute(AnnotationsAttribute.visibleTag));
if (annotations != null) {
boolean isAnnotated = false;
for (javassist.bytecode.annotation.Annotation a : annotations.getAnnotations()) {
if (annotationsToScan.contains(a.getTypeName())) {
isAnnotated = true;
}
}
if (isAnnotated) {
List<AnnotationDescriptor> classAnnotations = getAnnotationDescriptors(annotations);
@SuppressWarnings("unchecked")
List<FieldInfo> classFields = classFile.getFields();
List<FieldDescriptor> fieldDescriptors = new ArrayList<>(classFields.size());
for (FieldInfo field : classFields) {
String fieldName = field.getName();
AnnotationsAttribute fieldAnnotations = ((AnnotationsAttribute)field.getAttribute(AnnotationsAttribute.visibleTag));
fieldDescriptors.add(new FieldDescriptor(fieldName, field.getDescriptor(), getAnnotationDescriptors(fieldAnnotations)));
}
functions.add(new AnnotatedClassDescriptor(classFile.getName(), classAnnotations, fieldDescriptors));
}
}
}
示例3: addAnnotations
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private void addAnnotations(Collection<String> imports, AnnotationsAttribute annotations) {
if (annotations != null) {
for (Annotation each : annotations.getAnnotations()) {
imports.add(each.getTypeName());
}
}
}
示例4: scan
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
@Override
public void scan(final Object cls) {
final ClassFile classFile = (ClassFile)cls;
AnnotationsAttribute annotations = ((AnnotationsAttribute)classFile.getAttribute(AnnotationsAttribute.visibleTag));
if (annotations != null) {
boolean isAnnotated = false;
for (javassist.bytecode.annotation.Annotation a : annotations.getAnnotations()) {
if (annotationsToScan.contains(a.getTypeName())) {
isAnnotated = true;
}
}
if (isAnnotated) {
List<AnnotationDescriptor> classAnnotations = getAnnotationDescriptors(annotations);
@SuppressWarnings("unchecked")
List<FieldInfo> classFields = classFile.getFields();
List<FieldDescriptor> fieldDescriptors = new ArrayList<>(classFields.size());
for (FieldInfo field : classFields) {
String fieldName = field.getName();
AnnotationsAttribute fieldAnnotations = ((AnnotationsAttribute)field.getAttribute(AnnotationsAttribute.visibleTag));
final List<AnnotationDescriptor> annotationDescriptors =
(fieldAnnotations != null) ? getAnnotationDescriptors(fieldAnnotations) : Collections.<AnnotationDescriptor>emptyList();
fieldDescriptors.add(new FieldDescriptor(fieldName, field.getDescriptor(), annotationDescriptors));
}
functions.add(new AnnotatedClassDescriptor(classFile.getName(), classAnnotations, fieldDescriptors));
}
}
}
示例5: hasAnnotationType
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
static boolean hasAnnotationType(Class<?> clz, ClassPool cp,
AnnotationsAttribute a1, AnnotationsAttribute a2)
{
Annotation[] anno1, anno2;
if (a1 == null)
anno1 = null;
else
anno1 = a1.getAnnotations();
if (a2 == null)
anno2 = null;
else
anno2 = a2.getAnnotations();
String typeName = clz.getName();
if (anno1 != null)
for (int i = 0; i < anno1.length; i++)
if (anno1[i].getTypeName().equals(typeName))
return true;
if (anno2 != null)
for (int i = 0; i < anno2.length; i++)
if (anno2[i].getTypeName().equals(typeName))
return true;
return false;
}
示例6: getAnnotationType
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
static Object getAnnotationType(Class<?> clz, ClassPool cp,
AnnotationsAttribute a1, AnnotationsAttribute a2)
throws ClassNotFoundException
{
Annotation[] anno1, anno2;
if (a1 == null)
anno1 = null;
else
anno1 = a1.getAnnotations();
if (a2 == null)
anno2 = null;
else
anno2 = a2.getAnnotations();
String typeName = clz.getName();
if (anno1 != null)
for (int i = 0; i < anno1.length; i++)
if (anno1[i].getTypeName().equals(typeName))
return toAnnoType(anno1[i], cp);
if (anno2 != null)
for (int i = 0; i < anno2.length; i++)
if (anno2[i].getTypeName().equals(typeName))
return toAnnoType(anno2[i], cp);
return null;
}
示例7: isAnnotationPresent
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
protected boolean isAnnotationPresent(AnnotationsAttribute attr) {
if (attr != null) {
Annotation[] annotations = attr.getAnnotations();
if (annotations != null) {
for (Annotation ann : annotations) {
if (ann.getTypeName().equals(Iri.class.getName()))
return true;
if (ann.getTypeName().equals(Matching.class.getName()))
return true;
}
}
}
return false;
}
示例8: analyzeClassAnnotations
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private void analyzeClassAnnotations(AnalyzedClass analyzedClass, CtClass ctClass) {
List<AnalyzedAnnotation> annotations = new ArrayList<>();
for (Object o : ctClass.getClassFile2().getAttributes()) {
if (o instanceof AnnotationsAttribute) {
AnnotationsAttribute attribute = (AnnotationsAttribute) o;
for (Annotation analyzedAnnotation : attribute.getAnnotations()) {
annotations.add(new AnalyzedAnnotation(analyzedAnnotation.toString()));
}
}
}
analyzedClass.setAnnotations(annotations);
}
示例9: checkAnnotation
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
/**
* Checks for an annotation, returns the assigned annotation object and
* removes the annotation if required.
*
* @param attribute the attribute to be searched for the annotation
* @param typeName the type name of the annotation to be returned
* @param cp the current class pool (needed for type conversion)
* @param remove if <code>true</code> remove the found annotation as a
* side effect, <code>false</code> do not modify anything
*
* @return the attached annotation or <b>null</b> if none of the given
* type is attached
* @throws ClassNotFoundException in case that the target class for casting
* cannot be found
*
* @since 1.00
*/
private static Object checkAnnotation(AnnotationsAttribute attribute,
String typeName, javassist.ClassPool cp, boolean remove)
throws ClassNotFoundException {
Object result = null;
if (attribute != null) {
javassist.bytecode.annotation.Annotation[] annotations
= attribute.getAnnotations();
if (annotations != null) {
for (int i = 0; i < annotations.length; i++) {
if (annotations[i].getTypeName().equals(typeName)) {
result = toAnnoType(annotations[i], cp);
if (remove) {
javassist.bytecode.annotation.Annotation[] tmp
= new javassist.bytecode.annotation.Annotation[
annotations.length - 1];
int pos = 0;
for (int j = 0; j < annotations.length; j++) {
if (i != j) {
tmp[pos++] = annotations[j];
}
}
attribute.setAnnotations(tmp);
}
}
}
}
}
return result;
}
示例10: analizePotentialPlugins
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private static void analizePotentialPlugins(InputStream input, Set<DiscoveredPlugin> discovered, boolean isClasspath, File file) throws IOException {
DataInputStream in;
if(input instanceof DataInputStream){
in = ((DataInputStream) input);
}else{
in = new DataInputStream(input);
}
ClassFile classFile = new ClassFile(in);
AnnotationsAttribute annotations = ((AnnotationsAttribute) classFile.getAttribute(AnnotationsAttribute.visibleTag));
if(annotations == null){
return;
}
for(Annotation annotation : annotations.getAnnotations()){
String annName = annotation.getTypeName();
if(annName.equals("jk_5.nailed.api.plugin.Plugin")){
StringMemberValue idValue = ((StringMemberValue) annotation.getMemberValue("id"));
String id = idValue == null ? null : idValue.getValue();
StringMemberValue nameValue = ((StringMemberValue) annotation.getMemberValue("name"));
String name = nameValue == null ? null : nameValue.getValue();
StringMemberValue versionValue = ((StringMemberValue) annotation.getMemberValue("version"));
String version = versionValue == null ? "unknown" : versionValue.getValue();
discovered.add(new DiscoveredPlugin(classFile.getName(), id, name, version, isClasspath, file));
}
}
}
示例11: hasAnnotationType
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
static boolean hasAnnotationType(Class clz, ClassPool cp,
AnnotationsAttribute a1, AnnotationsAttribute a2)
{
Annotation[] anno1, anno2;
if (a1 == null)
anno1 = null;
else
anno1 = a1.getAnnotations();
if (a2 == null)
anno2 = null;
else
anno2 = a2.getAnnotations();
String typeName = clz.getName();
if (anno1 != null)
for (int i = 0; i < anno1.length; i++)
if (anno1[i].getTypeName().equals(typeName))
return true;
if (anno2 != null)
for (int i = 0; i < anno2.length; i++)
if (anno2[i].getTypeName().equals(typeName))
return true;
return false;
}
示例12: getAnnotationType
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
static Object getAnnotationType(Class clz, ClassPool cp,
AnnotationsAttribute a1, AnnotationsAttribute a2)
throws ClassNotFoundException
{
Annotation[] anno1, anno2;
if (a1 == null)
anno1 = null;
else
anno1 = a1.getAnnotations();
if (a2 == null)
anno2 = null;
else
anno2 = a2.getAnnotations();
String typeName = clz.getName();
if (anno1 != null)
for (int i = 0; i < anno1.length; i++)
if (anno1[i].getTypeName().equals(typeName))
return toAnnoType(anno1[i], cp);
if (anno2 != null)
for (int i = 0; i < anno2.length; i++)
if (anno2[i].getTypeName().equals(typeName))
return toAnnoType(anno2[i], cp);
return null;
}
示例13: disableBooleanMember
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
/**
* Iterate the annotations, look for a 'required' parameter, and set it to
* false.
*
* @param field
* @param prefix
*/
private void disableBooleanMember(
String booleanMemberName,
CtField field ) {
// This is the JCommander package name
String packageName = JCommander.class.getPackage().getName();
AnnotationsAttribute fieldAttributes = (AnnotationsAttribute) field.getFieldInfo().getAttribute(
AnnotationsAttribute.visibleTag);
// Look for annotations that have a 'names' attribute, and whose package
// starts with the expected JCommander package.
for (Annotation annotation : fieldAttributes.getAnnotations()) {
if (annotation.getTypeName().startsWith(
packageName)) {
// See if it has a 'names' member variable.
MemberValue requiredMember = annotation.getMemberValue(booleanMemberName);
// We have a names member!!!
if (requiredMember != null) {
BooleanMemberValue booleanRequiredMember = (BooleanMemberValue) requiredMember;
// Set it to not required.
booleanRequiredMember.setValue(false);
// This is KEY! For some reason, the existing annotation
// will not be modified unless
// you call 'setAnnotation' here. I'm guessing
// 'getAnnotation()' creates a copy.
fieldAttributes.setAnnotation(annotation);
// Finished processing names.
break;
}
}
}
}
示例14: findAnnotationsForAnnotationsAttribute
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
private static Set<Annotation> findAnnotationsForAnnotationsAttribute(AnnotationsAttribute attr) {
if (attr != null) {
javassist.bytecode.annotation.Annotation[] anns = attr.getAnnotations();
return findAnnotationsForAnnotationsArray(anns);
}
return Collections.emptySet();
}
示例15: hasAnnotation
import javassist.bytecode.AnnotationsAttribute; //导入方法依赖的package包/类
public static boolean hasAnnotation(List attributes, String annotationClassName) {
for (Object obj : attributes) {
if (obj instanceof AnnotationsAttribute) {
AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) obj;
Annotation[] annotations = annotationsAttribute.getAnnotations();
for (Annotation annotation : annotations) {
if (annotation.getTypeName().equals(annotationClassName)) {
return true;
}
}
}
}
return false;
}