本文整理了Java中java.lang.reflect.Constructor.getDeclaringClass()
方法的一些代码示例,展示了Constructor.getDeclaringClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Constructor.getDeclaringClass()
方法的具体详情如下:
包路径:java.lang.reflect.Constructor
类名称:Constructor
方法名:getDeclaringClass
[英]Returns the class that declares this constructor.
[中]返回声明此构造函数的类。
代码示例来源:origin: libgdx/libgdx
/** Returns the Class object representing the class or interface that declares the constructor. */
public Class getDeclaringClass () {
return constructor.getDeclaringClass();
}
代码示例来源:origin: libgdx/libgdx
/** Returns the Class object representing the class or interface that declares the constructor. */
public Class getDeclaringClass () {
return constructor.getDeclaringClass();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new BeanInstantiationException.
* @param constructor the offending constructor
* @param msg the detail message
* @param cause the root cause
* @since 4.3
*/
public BeanInstantiationException(Constructor<?> constructor, String msg, @Nullable Throwable cause) {
super("Failed to instantiate [" + constructor.getDeclaringClass().getName() + "]: " + msg, cause);
this.beanClass = constructor.getDeclaringClass();
this.constructor = constructor;
this.constructingMethod = null;
}
代码示例来源:origin: prestodb/presto
public Serialization(Constructor<?> ctor) {
clazz = ctor.getDeclaringClass();
args = ctor.getParameterTypes();
}
}
代码示例来源:origin: redisson/redisson
public Serialization(Constructor<?> ctor) {
clazz = ctor.getDeclaringClass();
args = ctor.getParameterTypes();
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Make the given constructor accessible, explicitly setting it accessible
* if necessary. The {@code setAccessible(true)} method is only called
* when actually necessary, to avoid unnecessary conflicts with a JVM
* SecurityManager (if active).
* @param ctor the constructor to make accessible
* @see java.lang.reflect.Constructor#setAccessible
*/
@SuppressWarnings("deprecation") // on JDK 9
public static void makeAccessible(Constructor<?> ctor) {
if ((!Modifier.isPublic(ctor.getModifiers()) ||
!Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) {
ctor.setAccessible(true);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
Class<?> declaringClass = ctor.getDeclaringClass();
Map<Member, String[]> map = this.parameterNamesCache.get(declaringClass);
if (map == null) {
map = inspectClass(declaringClass);
this.parameterNamesCache.put(declaringClass, map);
}
if (map != NO_DEBUG_INFO_MAP) {
return map.get(ctor);
}
return null;
}
代码示例来源:origin: netty/netty
@Override
public T newChannel() {
try {
return constructor.newInstance();
} catch (Throwable t) {
throw new ChannelException("Unable to create Channel from class " + constructor.getDeclaringClass(), t);
}
}
代码示例来源:origin: spring-projects/spring-framework
protected Constructor<?> getUserDeclaredConstructor(Constructor<?> constructor) {
Class<?> declaringClass = constructor.getDeclaringClass();
Class<?> userClass = ClassUtils.getUserClass(declaringClass);
if (userClass != declaringClass) {
try {
return userClass.getDeclaredConstructor(constructor.getParameterTypes());
}
catch (NoSuchMethodException ex) {
// No equivalent constructor on user class (superclass)...
// Let's proceed with the given constructor as we usually would.
}
}
return constructor;
}
代码示例来源:origin: google/guava
/**
* Verifies that {@code ctor} produces a {@link NullPointerException} or {@link
* UnsupportedOperationException} whenever <i>any</i> of its non-nullable parameters are null.
*/
public void testConstructor(Constructor<?> ctor) {
Class<?> declaringClass = ctor.getDeclaringClass();
checkArgument(
Modifier.isStatic(declaringClass.getModifiers())
|| declaringClass.getEnclosingClass() == null,
"Cannot test constructor of non-static inner class: %s",
declaringClass.getName());
Class<?>[] types = ctor.getParameterTypes();
for (int nullIndex = 0; nullIndex < types.length; nullIndex++) {
testConstructorParameter(ctor, nullIndex);
}
}
代码示例来源:origin: redisson/redisson
@Override
public T newChannel() {
try {
return constructor.newInstance();
} catch (Throwable t) {
throw new ChannelException("Unable to create Channel from class " + constructor.getDeclaringClass(), t);
}
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public TypeDescription getDeclaringType() {
return TypeDescription.ForLoadedType.of(constructor.getDeclaringClass());
}
代码示例来源:origin: google/guava
/**
* Verifies that {@code ctor} produces a {@link NullPointerException} or {@link
* UnsupportedOperationException} when the parameter in position {@code paramIndex} is null. If
* this parameter is marked nullable, this method does nothing.
*/
public void testConstructorParameter(Constructor<?> ctor, int paramIndex) {
ctor.setAccessible(true);
testParameter(null, Invokable.from(ctor), paramIndex, ctor.getDeclaringClass());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
if (ctor.getDeclaringClass().isEnum() || !KotlinDetector.isKotlinType(ctor.getDeclaringClass())) {
return null;
}
try {
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
return (function != null ? getParameterNames(function.getParameters()) : null);
}
catch (UnsupportedOperationException ex) {
return null;
}
}
代码示例来源:origin: google/guava
private boolean mayNeedHiddenThis() {
Class<?> declaringClass = constructor.getDeclaringClass();
if (declaringClass.getEnclosingConstructor() != null) {
// Enclosed in a constructor, needs hidden this
return true;
}
Method enclosingMethod = declaringClass.getEnclosingMethod();
if (enclosingMethod != null) {
// Enclosed in a method, if it's not static, must need hidden this.
return !Modifier.isStatic(enclosingMethod.getModifiers());
} else {
// Strictly, this doesn't necessarily indicate a hidden 'this' in the case of
// static initializer. But there seems no way to tell in that case. :(
// This may cause issues when an anonymous class is created inside a static initializer,
// and the class's constructor's first parameter happens to be the enclosing class.
// In such case, we may mistakenly think that the class is within a non-static context
// and the first parameter is the hidden 'this'.
return declaringClass.getEnclosingClass() != null
&& !Modifier.isStatic(declaringClass.getModifiers());
}
}
}
代码示例来源:origin: netty/netty
@Override
public String toString() {
return StringUtil.simpleClassName(ReflectiveChannelFactory.class) +
'(' + StringUtil.simpleClassName(constructor.getDeclaringClass()) + ".class)";
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean isCompilable() {
if (!(this.cachedExecutor instanceof ReflectiveConstructorExecutor) ||
this.exitTypeDescriptor == null) {
return false;
}
if (getChildCount() > 1) {
for (int c = 1, max = getChildCount();c < max; c++) {
if (!this.children[c].isCompilable()) {
return false;
}
}
}
ReflectiveConstructorExecutor executor = (ReflectiveConstructorExecutor) this.cachedExecutor;
if (executor == null) {
return false;
}
Constructor<?> constructor = executor.getConstructor();
return (Modifier.isPublic(constructor.getModifiers()) &&
Modifier.isPublic(constructor.getDeclaringClass().getModifiers()));
}
代码示例来源:origin: apache/incubator-dubbo
private CtConstructor getCtConstructor(Constructor<?> c) throws NotFoundException {
return getCtClass(c.getDeclaringClass()).getConstructor(ReflectUtils.getDesc(c));
}
代码示例来源:origin: apache/incubator-dubbo
private CtConstructor getCtConstructor(Constructor<?> c) throws NotFoundException {
return getCtClass(c.getDeclaringClass()).getConstructor(ReflectUtils.getDesc(c));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
ReflectiveConstructorExecutor executor = ((ReflectiveConstructorExecutor) this.cachedExecutor);
Assert.state(executor != null, "No cached executor");
Constructor<?> constructor = executor.getConstructor();
String classDesc = constructor.getDeclaringClass().getName().replace('.', '/');
mv.visitTypeInsn(NEW, classDesc);
mv.visitInsn(DUP);
// children[0] is the type of the constructor, don't want to include that in argument processing
SpelNodeImpl[] arguments = new SpelNodeImpl[this.children.length - 1];
System.arraycopy(this.children, 1, arguments, 0, this.children.length - 1);
generateCodeForArguments(mv, cf, constructor, arguments);
mv.visitMethodInsn(INVOKESPECIAL, classDesc, "<init>", CodeFlow.createSignatureDescriptor(constructor), false);
cf.pushDescriptor(this.exitTypeDescriptor);
}
内容来源于网络,如有侵权,请联系作者删除!