本文整理了Java中java.lang.Class.getDeclaringClass()
方法的一些代码示例,展示了Class.getDeclaringClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.getDeclaringClass()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:getDeclaringClass
[英]Returns the declaring Class of this Class. Returns null if the class is not a member of another class or if this Class represents an array class, a primitive type, or void.
[中]返回该类的声明类。如果该类不是另一个类的成员,或者该类表示数组类、基元类型或void,则返回null。
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean isIndependent() {
return (!hasEnclosingClass() ||
(this.introspectedClass.getDeclaringClass() != null &&
Modifier.isStatic(this.introspectedClass.getModifiers())));
}
代码示例来源:origin: apache/flink
/**
* Checks, whether the class is an inner class that is not statically accessible. That is especially true for
* anonymous inner classes.
*
* @param clazz The class to check.
* @return True, if the class is a non-statically accessible inner class.
*/
public static boolean isNonStaticInnerClass(Class<?> clazz) {
return clazz.getEnclosingClass() != null &&
(clazz.getDeclaringClass() == null || !Modifier.isStatic(clazz.getModifiers()));
}
代码示例来源:origin: neo4j/neo4j
@Override
public String getDiagnosticsIdentifier()
{
return getClass().getDeclaringClass().getSimpleName() + ":" + getClass().getSimpleName();
}
代码示例来源:origin: prestodb/presto
/**
* @since 2.7
*/
public static Class<?> getDeclaringClass(Class<?> cls) {
return isObjectOrPrimitive(cls) ? null : cls.getDeclaringClass();
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public TypeDescription getDeclaringType() {
Class<?> declaringType = type.getDeclaringClass();
return declaringType == null
? TypeDescription.UNDEFINED
: ForLoadedType.of(declaringType);
}
代码示例来源:origin: redisson/redisson
/**
* @since 2.7
*/
public static Class<?> getDeclaringClass(Class<?> cls) {
return isObjectOrPrimitive(cls) ? null : cls.getDeclaringClass();
}
代码示例来源:origin: alibaba/fastjson
static Constructor<?> getDefaultConstructor(Class<?> clazz, final Constructor<?>[] constructors) {
if (Modifier.isAbstract(clazz.getModifiers())) {
return null;
}
Constructor<?> defaultConstructor = null;
for (Constructor<?> constructor : constructors) {
if (constructor.getParameterTypes().length == 0) {
defaultConstructor = constructor;
break;
}
}
if (defaultConstructor == null) {
if (clazz.isMemberClass() && !Modifier.isStatic(clazz.getModifiers())) {
Class<?>[] types;
for (Constructor<?> constructor : constructors) {
if ((types = constructor.getParameterTypes()).length == 1
&& types[0].equals(clazz.getDeclaringClass())) {
defaultConstructor = constructor;
break;
}
}
}
}
return defaultConstructor;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine the class to use for naming a variable containing the given value.
* <p>Will return the class of the given value, except when encountering a
* JDK proxy, in which case it will determine the 'primary' interface
* implemented by that proxy.
* @param value the value to check
* @return the class to use for naming a variable
*/
private static Class<?> getClassForValue(Object value) {
Class<?> valueClass = value.getClass();
if (Proxy.isProxyClass(valueClass)) {
Class<?>[] ifcs = valueClass.getInterfaces();
for (Class<?> ifc : ifcs) {
if (!ClassUtils.isJavaLanguageInterface(ifc)) {
return ifc;
}
}
}
else if (valueClass.getName().lastIndexOf('$') != -1 && valueClass.getDeclaringClass() == null) {
// '$' in the class name but no inner class -
// assuming it's a special subclass (e.g. by OpenJPA)
valueClass = valueClass.getSuperclass();
}
return valueClass;
}
代码示例来源:origin: gocd/gocd
private Object createInstance(Class candidateGoExtensionClass) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
if (isANonStaticInnerClass(candidateGoExtensionClass)) {
Class declaringClass = candidateGoExtensionClass.getDeclaringClass();
Object declaringClassInstance = createInstance(candidateGoExtensionClass.getDeclaringClass());
return candidateGoExtensionClass.getConstructor(declaringClass).newInstance(declaringClassInstance);
}
Constructor constructor = candidateGoExtensionClass.getConstructor();
return constructor.newInstance();
}
代码示例来源:origin: gocd/gocd
private boolean isInstantiable(Class<?> candidateClass) throws NoSuchMethodException {
if (!isANonStaticInnerClass(candidateClass)) {
boolean hasPublicDefaultConstructor = candidateClass.getConstructor() != null;
return hasPublicDefaultConstructor;
}
boolean hasAConstructorWhichTakesMyOuterClass = candidateClass.getConstructor(candidateClass.getDeclaringClass()) != null;
return hasAConstructorWhichTakesMyOuterClass && isInstantiable(candidateClass.getDeclaringClass());
}
代码示例来源:origin: org.springframework/spring-core
@Override
public boolean isIndependent() {
return (!hasEnclosingClass() ||
(this.introspectedClass.getDeclaringClass() != null &&
Modifier.isStatic(this.introspectedClass.getModifiers())));
}
代码示例来源:origin: ronmamo/reflections
public static Class<?> resolveClassOf(final Class element) throws ClassNotFoundException {
Class<?> cursor = element;
LinkedList<String> ognl = Lists.newLinkedList();
while (cursor != null) {
ognl.addFirst(cursor.getSimpleName());
cursor = cursor.getDeclaringClass();
}
String classOgnl = Joiner.on(".").join(ognl.subList(1, ognl.size())).replace(".$", "$");
return Class.forName(classOgnl);
}
代码示例来源:origin: ronmamo/reflections
public static Field resolveField(final Class aField) {
try {
String name = aField.getSimpleName();
Class<?> declaringClass = aField.getDeclaringClass().getDeclaringClass();
return resolveClassOf(declaringClass).getDeclaredField(name);
} catch (Exception e) {
throw new ReflectionsException("could not resolve to field " + aField.getName(), e);
}
}
代码示例来源:origin: org.reflections/reflections
public static Class<?> resolveClassOf(final Class element) throws ClassNotFoundException {
Class<?> cursor = element;
LinkedList<String> ognl = Lists.newLinkedList();
while (cursor != null) {
ognl.addFirst(cursor.getSimpleName());
cursor = cursor.getDeclaringClass();
}
String classOgnl = Joiner.on(".").join(ognl.subList(1, ognl.size())).replace(".$", "$");
return Class.forName(classOgnl);
}
代码示例来源:origin: ronmamo/reflections
public static Annotation resolveAnnotation(Class annotation) {
try {
String name = annotation.getSimpleName().replace(pathSeparator, dotSeparator);
Class<?> declaringClass = annotation.getDeclaringClass().getDeclaringClass();
Class<?> aClass = resolveClassOf(declaringClass);
Class<? extends Annotation> aClass1 = (Class<? extends Annotation>) ReflectionUtils.forName(name);
Annotation annotation1 = aClass.getAnnotation(aClass1);
return annotation1;
} catch (Exception e) {
throw new ReflectionsException("could not resolve to annotation " + annotation.getName(), e);
}
}
代码示例来源:origin: org.reflections/reflections
public static Annotation resolveAnnotation(Class annotation) {
try {
String name = annotation.getSimpleName().replace(pathSeparator, dotSeparator);
Class<?> declaringClass = annotation.getDeclaringClass().getDeclaringClass();
Class<?> aClass = resolveClassOf(declaringClass);
Class<? extends Annotation> aClass1 = (Class<? extends Annotation>) ReflectionUtils.forName(name);
Annotation annotation1 = aClass.getAnnotation(aClass1);
return annotation1;
} catch (Exception e) {
throw new ReflectionsException("could not resolve to annotation " + annotation.getName(), e);
}
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public Generic getOwnerType() {
Class<?> declaringClass = this.type.getDeclaringClass();
return declaringClass == null
? Generic.UNDEFINED
: new ForLoadedType(declaringClass, annotationReader.ofOuterClass());
}
代码示例来源:origin: oracle/opengrok
private boolean isConditionTypeDeclaredInTarget(Class<? extends RunCondition> clazz) {
return mTestClass.getClass().isAssignableFrom(clazz.getDeclaringClass());
}
}
代码示例来源:origin: org.junit.jupiter/junit-jupiter-engine
private Set<TestDescriptor> resolveContainerWithParents(Class<?> testClass) {
if (isInnerClass.test(testClass)) {
Set<TestDescriptor> potentialParents = resolveContainerWithParents(testClass.getDeclaringClass());
return resolveForAllParents(testClass, potentialParents);
}
else {
return resolveForAllParents(testClass, Collections.singleton(this.engineDescriptor));
}
}
代码示例来源:origin: google/guava
rootLocaleFormat(
"%s.%s() must return an array of %s.",
annotationClass, propertyName, annotationClass.getDeclaringClass()),
annotationClass.getDeclaringClass(),
returnType.getComponentType());
内容来源于网络,如有侵权,请联系作者删除!