本文整理匯總了Java中javassist.bytecode.annotation.Annotation.getTypeName方法的典型用法代碼示例。如果您正苦於以下問題:Java Annotation.getTypeName方法的具體用法?Java Annotation.getTypeName怎麽用?Java Annotation.getTypeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javassist.bytecode.annotation.Annotation
的用法示例。
在下文中一共展示了Annotation.getTypeName方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addAnnotation
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
* Adds an annotation. If there is an annotation with the same type,
* it is removed before the new annotation is added.
*
* @param annotation the added annotation.
*/
public void addAnnotation(Annotation annotation) {
String type = annotation.getTypeName();
Annotation[] annotations = getAnnotations();
for (int i = 0; i < annotations.length; i++) {
if (annotations[i].getTypeName().equals(type)) {
annotations[i] = annotation;
setAnnotations(annotations);
return;
}
}
Annotation[] newlist = new Annotation[annotations.length + 1];
System.arraycopy(annotations, 0, newlist, 0, annotations.length);
newlist[annotations.length] = annotation;
setAnnotations(newlist);
}
示例2: analizePotentialPlugins
import javassist.bytecode.annotation.Annotation; //導入方法依賴的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));
}
}
}
示例3: addAnnotations
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
private void addAnnotations(@Nonnull CtClass clazz, Set<String> knownAnnotations) {
for (Annotation annotation : getAnnotations(clazz, PACKAGE, TYPE)) {
String annotationClassName = annotation.getTypeName();
if (!knownAnnotations.add(annotationClassName)) {
continue;
}
if (DEAD_ENDS.contains(annotationClassName)) {
continue;
}
CtClass annotationClazz = getCtClass(clazz.getClassPool(), annotationClassName);
if (annotationClazz != null) {
addAnnotations(annotationClazz, knownAnnotations);
}
}
}
示例4: cloneAnnotationsAttribute
import javassist.bytecode.annotation.Annotation; //導入方法依賴的package包/類
/**
* This function will take the given annotations attribute and create a new
* attribute, cloning all the annotations and specified values within the
* attribute. The annotations attribute can then be set on a method, class,
* or field.
*
* @param attr
* @return
*/
public static AnnotationsAttribute cloneAnnotationsAttribute(
ConstPool constPool,
AnnotationsAttribute attr,
ElementType validElementType ) {
// We can use system class loader here because the annotations for
// Target
// are part of the Java System.
ClassLoader cl = ClassLoader.getSystemClassLoader();
AnnotationsAttribute attrNew = new AnnotationsAttribute(
constPool,
AnnotationsAttribute.visibleTag);
if (attr != null) {
for (Annotation annotation : attr.getAnnotations()) {
Annotation newAnnotation = new Annotation(
annotation.getTypeName(),
constPool);
// If this must target a certain type of field, then ensure we
// only
// copy over annotations that can target that type of field.
// For instances, a METHOD annotation can't be applied to a
// FIELD or TYPE.
Class<?> annoClass;
try {
annoClass = cl.loadClass(annotation.getTypeName());
Target target = annoClass.getAnnotation(Target.class);
if (target != null && !Arrays.asList(
target.value()).contains(
validElementType)) {
continue;
}
}
catch (ClassNotFoundException e) {
// Cannot apply this annotation because its type cannot be
// found.
LOGGER.error(
"Cannot apply this annotation because it's type cannot be found",
e);
continue;
}
// Copy over the options for this annotation. For example:
// @Parameter(names = "-blah")
// For this, a member value would be "names" which would be a
// StringMemberValue
if (annotation.getMemberNames() != null) {
for (Object memberName : annotation.getMemberNames()) {
MemberValue memberValue = annotation.getMemberValue((String) memberName);
if (memberValue != null) {
newAnnotation.addMemberValue(
(String) memberName,
memberValue);
}
}
}
attrNew.addAnnotation(newAnnotation);
}
}
return attrNew;
}