本文整理汇总了Java中java.lang.reflect.Member.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Member.getName方法的具体用法?Java Member.getName怎么用?Java Member.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.Member
的用法示例。
在下文中一共展示了Member.getName方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPropertyName
import java.lang.reflect.Member; //导入方法依赖的package包/类
/**
* Process bean properties getter by applying the JavaBean naming conventions.
*
* @param member the member for which to get the property name.
*
* @return The bean method name with the "is" or "get" prefix stripped off, {@code null}
* the method name id not according to the JavaBeans standard.
*/
public static String getPropertyName(Member member) {
String name = null;
if ( member instanceof Field ) {
name = member.getName();
}
if ( member instanceof Method ) {
String methodName = member.getName();
if ( methodName.startsWith( "is" ) ) {
name = Introspector.decapitalize( methodName.substring( 2 ) );
}
else if ( methodName.startsWith( "has" ) ) {
name = Introspector.decapitalize( methodName.substring( 3 ) );
}
else if ( methodName.startsWith( "get" ) ) {
name = Introspector.decapitalize( methodName.substring( 3 ) );
}
}
return name;
}
示例2: createDynamicMethod
import java.lang.reflect.Member; //导入方法依赖的package包/类
/**
* Given a reflective method or a constructor, creates a dynamic method that represents it. This method will
* distinguish between caller sensitive and ordinary methods/constructors, and create appropriate caller sensitive
* dynamic method when needed.
* @param m the reflective member
* @return the single dynamic method representing the reflective member
*/
private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
if(CallerSensitiveDetector.isCallerSensitive(m)) {
// Method has @CallerSensitive annotation
return new CallerSensitiveDynamicMethod(m);
}
// Method has no @CallerSensitive annotation
final MethodHandle mh;
try {
mh = unreflectSafely(m);
} catch (final IllegalAccessError e) {
// java.lang.invoke can in some case conservatively treat as caller sensitive methods that aren't
// marked with the annotation. In this case, we'll fall back to treating it as caller sensitive.
return new CallerSensitiveDynamicMethod(m);
}
// Proceed with non-caller sensitive
final Member member = (Member)m;
return new SimpleDynamicMethod(mh, member.getDeclaringClass(), member.getName(), m instanceof Constructor);
}
示例3: forMember
import java.lang.reflect.Member; //导入方法依赖的package包/类
public static Object forMember(Member member) {
if (member == null) {
return SourceProvider.UNKNOWN_SOURCE;
}
Class declaringClass = member.getDeclaringClass();
/*if[AOP]*/
LineNumbers lineNumbers = lineNumbersCache.getUnchecked(declaringClass);
String fileName = lineNumbers.getSource();
Integer lineNumberOrNull = lineNumbers.getLineNumber(member);
int lineNumber = lineNumberOrNull == null ? lineNumbers.getFirstLine() : lineNumberOrNull;
/*end[AOP]*/
/*if[NO_AOP]
String fileName = null;
int lineNumber = -1;
end[NO_AOP]*/
Class<? extends Member> memberType = Classes.memberType(member);
String memberName = memberType == Constructor.class ? "<init>" : member.getName();
return new StackTraceElement(declaringClass.getName(), memberName, fileName, lineNumber);
}
示例4: memberKey
import java.lang.reflect.Member; //导入方法依赖的package包/类
private String memberKey(Member member) {
checkNotNull(member, "member");
/*if[AOP]*/
if (member instanceof Field) {
return member.getName();
} else if (member instanceof Method) {
return member.getName() + org.objectweb.asm.Type.getMethodDescriptor((Method) member);
} else if (member instanceof Constructor) {
StringBuilder sb = new StringBuilder().append("<init>(");
for (Class param : ((Constructor) member).getParameterTypes()) {
sb.append(org.objectweb.asm.Type.getDescriptor(param));
}
return sb.append(")V").toString();
} else {
throw new IllegalArgumentException(
"Unsupported implementation class for Member, " + member.getClass());
}
/*end[AOP]*/
/*if[NO_AOP]
return "<NO_MEMBER_KEY>";
end[NO_AOP]*/
}
示例5: createDynamicMethod
import java.lang.reflect.Member; //导入方法依赖的package包/类
/**
* Given a reflective method or a constructor, creates a dynamic method that represents it. This method will
* distinguish between caller sensitive and ordinary methods/constructors, and create appropriate caller sensitive
* dynamic method when needed.
* @param m the reflective member
* @return the single dynamic method representing the reflective member
*/
private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
if (m.isAnnotationPresent(CallerSensitive.class)) {
// Method has @CallerSensitive annotation
return new CallerSensitiveDynamicMethod(m);
}
// Method has no @CallerSensitive annotation
final MethodHandle mh;
try {
mh = unreflectSafely(m);
} catch (final IllegalAccessError e) {
// java.lang.invoke can in some case conservatively treat as caller sensitive methods that aren't
// marked with the annotation. In this case, we'll fall back to treating it as caller sensitive.
return new CallerSensitiveDynamicMethod(m);
}
// Proceed with non-caller sensitive
final Member member = (Member)m;
return new SimpleDynamicMethod(mh, member.getDeclaringClass(), member.getName(), m instanceof Constructor);
}
示例6: forMember
import java.lang.reflect.Member; //导入方法依赖的package包/类
public static Object forMember(Member member) {
if (member == null) {
return SourceProvider.UNKNOWN_SOURCE;
}
Class declaringClass = member.getDeclaringClass();
String fileName = null;
int lineNumber = -1;
Class<? extends Member> memberType = MoreTypes.memberType(member);
String memberName = memberType == Constructor.class ? "<init>" : member.getName();
return new StackTraceElement(declaringClass.getName(), memberName, fileName, lineNumber);
}
示例7: toString
import java.lang.reflect.Member; //导入方法依赖的package包/类
/**
* Formats a member as concise string, such as {@code java.util.ArrayList.size},
* {@code java.util.ArrayList<init>()} or {@code java.util.List.remove()}.
*/
public static String toString(Member member) {
Class<? extends Member> memberType = memberType(member);
if (memberType == Method.class) {
return member.getDeclaringClass().getName() + "." + member.getName() + "()";
} else if (memberType == Field.class) {
return member.getDeclaringClass().getName() + "." + member.getName();
} else if (memberType == Constructor.class) {
return member.getDeclaringClass().getName() + ".<init>()";
} else {
throw new AssertionError();
}
}
示例8: MemberImpl
import java.lang.reflect.Member; //导入方法依赖的package包/类
private MemberImpl(Member member) {
this.declaringClass = member.getDeclaringClass();
this.name = member.getName();
this.modifiers = member.getModifiers();
this.synthetic = member.isSynthetic();
this.memberType = memberType(member);
this.memberKey = memberKey(member);
}
示例9: serializedName
import java.lang.reflect.Member; //导入方法依赖的package包/类
private static String serializedName(Member member) {
if(member instanceof AnnotatedElement) {
SerializedName nameAnnot = ((AnnotatedElement) member).getAnnotation(SerializedName.class);
if(nameAnnot != null) return nameAnnot.value();
}
return member.getName();
}
示例10: multilineDescription
import java.lang.reflect.Member; //导入方法依赖的package包/类
public static String multilineDescription(Member member) {
return member.getClass().getSimpleName().toLowerCase() +
" " + member.getName() +
" of " + multilineDescription(member.getDeclaringClass());
}
示例11: error
import java.lang.reflect.Member; //导入方法依赖的package包/类
public static void error(Member member, String description) {
throw new IllegalArgumentException(member.getDeclaringClass().getName() + "#" + member.getName() + " " + description);
}
示例12: gerQualifiedName
import java.lang.reflect.Member; //导入方法依赖的package包/类
public String gerQualifiedName() {
Member member = getMember();
return member.getDeclaringClass().getName() + "." + member.getName();
}