Java Code Examples for java.lang.reflect.Constructor#getName()

The following examples show how to use java.lang.reflect.Constructor#getName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: baleen   File: TableRelation.java    License: Apache License 2.0 6 votes vote down vote up
private Entity getEntity(JCas jCas, TableCell cell, Constructor<? extends Entity> type) {
  List<? extends Entity> covered = JCasUtil.selectCovered(type.getDeclaringClass(), cell);
  if (!covered.isEmpty()) {
    return covered.get(0);
  } else {
    Entity entity;
    try {
      entity = type.newInstance(jCas);
      entity.setBegin(cell.getBegin());
      entity.setEnd(cell.getEnd());
      entity.setValue(cell.getCoveredText());
      if (!Strings.isNullOrEmpty(subType)) {
        entity.setSubType(subType);
      }
      addToJCasIndex(entity);
      return entity;
    } catch (InstantiationException
        | IllegalAccessException
        | IllegalArgumentException
        | InvocationTargetException e) {
      throw new BaleenRuntimeException("Can not create entity type " + type.getName(), e);
    }
  }
}
 
Example 2
static Object invokeConstuctor(Constructor<?> constuctor, Object... args) {
	try {
		return constuctor.newInstance(args);
	} catch (Exception e) {
		throw new RuntimeException("Error while invoking " + constuctor.getName() + ".", e);
	}
}
 
Example 3
Source Project: groovy   File: Inspector.java    License: Apache License 2.0 5 votes vote down vote up
protected String[] methodInfo(Constructor ctor) {
    String[] result = new String[MEMBER_EXCEPTIONS_IDX + 1];
    result[MEMBER_ORIGIN_IDX] = JAVA;
    result[MEMBER_MODIFIER_IDX] = Modifier.toString(ctor.getModifiers());
    result[MEMBER_DECLARER_IDX] = shortName(ctor.getDeclaringClass());
    result[MEMBER_TYPE_IDX] = shortName(ctor.getDeclaringClass());
    result[MEMBER_NAME_IDX] = ctor.getName();
    result[MEMBER_PARAMS_IDX] = makeParamsInfo(ctor.getParameterTypes());
    result[MEMBER_EXCEPTIONS_IDX] = makeExceptionInfo(ctor.getExceptionTypes());

    return withoutNulls(result);
}
 
Example 4
public LambdaExecutable(Constructor<?> constructor) {
	this.parameterTypes = constructor.getGenericParameterTypes();
	this.returnType = constructor.getDeclaringClass();
	this.name = constructor.getName();
	this.executable = constructor;
}
 
Example 5
public MemberSignature(Constructor<?> cons) {
    member = cons;
    name = cons.getName();
    signature = getMethodSignature(
        cons.getParameterTypes(), Void.TYPE);
}
 
Example 6
Source Project: Poseidon   File: PoseidonLegoSet.java    License: Apache License 2.0 4 votes vote down vote up
private void resolveInjectableConstructorDependencies(Constructor<?> constructor, Object[] initParams, int offset, Optional<Request> request) throws MissingInformationException, ElementNotFoundException {
    for (int i = offset; i < constructor.getParameterCount(); i++) {
        final Parameter constructorParameter = constructor.getParameters()[i];
        final RequestAttribute requestAttribute = constructorParameter.getAnnotation(RequestAttribute.class);
        final com.flipkart.poseidon.datasources.ServiceClient serviceClientAttribute = constructorParameter.getAnnotation(com.flipkart.poseidon.datasources.ServiceClient.class);
        final SystemDataSource systemDataSourceAttribute = constructorParameter.getAnnotation(SystemDataSource.class);
        if (requestAttribute != null) {
            final String attributeName = StringUtils.isNullOrEmpty(requestAttribute.value()) ? constructorParameter.getName() : requestAttribute.value();
            initParams[i] = request.map(r -> r.getAttribute(attributeName)).map(attr -> {
                if (constructorParameter.getType().isAssignableFrom(attr.getClass())) {
                    return attr;
                } else {
                    return mapper.convertValue(attr, mapper.constructType(constructorParameter.getParameterizedType()));
                }
            }).orElse(null);
        } else if (serviceClientAttribute != null) {
            ServiceClient serviceClient = serviceClientsByName.get(constructor.getParameterTypes()[i].getName());
            if (serviceClient == null) {
                throw new ElementNotFoundException("Unable to find ServiceClient for class = " + constructor.getParameterTypes()[i]);
            }
            initParams[i] = serviceClient;
        } else if (systemDataSourceAttribute != null) {
            final DataSource<?> systemDataSource = systemDataSources.get(systemDataSourceAttribute.value());
            if (systemDataSource == null) {
                throw new ElementNotFoundException("Unable to find SystemDataSource for id = " + systemDataSourceAttribute.value());
            }
            initParams[i] = systemDataSource;
        } else {
            final Qualifier qualifier = constructorParameter.getAnnotation(Qualifier.class);
            String beanName = null;
            if (qualifier != null && !StringUtils.isNullOrEmpty(qualifier.value())) {
                beanName = qualifier.value();
            }

            initParams[i] = beanName == null ? context.getBean(constructor.getParameterTypes()[i]) : context.getBean(beanName, constructor.getParameterTypes()[i]);
            if (initParams[i] == null) {
                throw new MissingInformationException("Unmet dependency for constructor " + constructor.getName() + ": " + constructor.getParameterTypes()[i].getCanonicalName());
            }
        }
    }
}
 
Example 7
public MemberSignature(Constructor<?> cons) {
    member = cons;
    name = cons.getName();
    signature = getMethodSignature(
        cons.getParameterTypes(), Void.TYPE);
}
 
Example 8
public String[] lookupParameterNames(AccessibleObject methodOrConstructor, boolean throwExceptionIfMissing) {
	if (methodOrConstructor == null)
		throw new NullPointerException();

	Class<?> klass;
	String name;
	Class<?>[] types;

	if (methodOrConstructor instanceof Constructor<?>) {
		Constructor<?> constructor = (Constructor<?>) methodOrConstructor;
		klass = constructor.getDeclaringClass();
		name = constructor.getName();
		types = constructor.getParameterTypes();
	} else if (methodOrConstructor instanceof Method) {
		Method method = (Method) methodOrConstructor;
		klass = method.getDeclaringClass();
		name = method.getName();
		types = method.getParameterTypes();
	} else
		throw new IllegalArgumentException();

	// quick check to see if we support the package
	if (!packages.contains(klass.getPackage().getName()))
		throw CLASS_NOT_SUPPORTED;

	try {
		String[] names = getParameterNames(klass, name, types);
		if (names == null) {
               if (throwExceptionIfMissing) {
                   throw new ParameterNamesNotFoundException(
				    methodOrConstructor.toString());
               } else {
                   return Paranamer.EMPTY_NAMES;
               }
           }
           return names;
	} catch (IOException e) {
           if (throwExceptionIfMissing) {
               throw new ParameterNamesNotFoundException(
    			methodOrConstructor.toString() + " due to an I/O error: "
	    				+ e.getMessage());
           } else {
               return Paranamer.EMPTY_NAMES;
           }
       }
}
 
Example 9
Source Project: JDKSourceCode1.8   File: ObjectStreamClass.java    License: MIT License 4 votes vote down vote up
public MemberSignature(Constructor<?> cons) {
    member = cons;
    name = cons.getName();
    signature = getMethodSignature(
        cons.getParameterTypes(), Void.TYPE);
}
 
Example 10
public MemberSignature(Constructor<?> cons) {
    member = cons;
    name = cons.getName();
    signature = getMethodSignature(
        cons.getParameterTypes(), Void.TYPE);
}
 
Example 11
Source Project: groovy   File: AccessPermissionChecker.java    License: Apache License 2.0 4 votes vote down vote up
private static CacheAccessControlException createCacheAccessControlExceptionOf(Constructor constructor, AccessControlException e) {
    return new CacheAccessControlException(
            "Groovy object can not access constructor " + constructor.getName()
                    + " cacheAccessControlExceptionOf class " + constructor.getDeclaringClass().getName()
                    + " with modifiers \"" + Modifier.toString(constructor.getModifiers()) + "\"", e);
}
 
Example 12
public MemberSignature(Constructor cons) {
    member = cons;
    name = cons.getName();
    signature = getMethodSignature(
        cons.getParameterTypes(), Void.TYPE);
}
 
Example 13
Source Project: Java8CN   File: ObjectStreamClass.java    License: Apache License 2.0 4 votes vote down vote up
public MemberSignature(Constructor<?> cons) {
    member = cons;
    name = cons.getName();
    signature = getMethodSignature(
        cons.getParameterTypes(), Void.TYPE);
}
 
Example 14
Source Project: Bytecoder   File: ObjectStreamClass.java    License: Apache License 2.0 4 votes vote down vote up
public MemberSignature(Constructor<?> cons) {
    member = cons;
    name = cons.getName();
    signature = getMethodSignature(
        cons.getParameterTypes(), Void.TYPE);
}
 
Example 15
public MemberSignature(Constructor<?> cons) {
    member = cons;
    name = cons.getName();
    signature = getMethodSignature(
        cons.getParameterTypes(), Void.TYPE);
}
 
Example 16
/**
 * Constructs an <CODE>MBeanConstructorInfo</CODE> object.  The
 * {@link Descriptor} of the constructed object will include
 * fields contributed by any annotations on the {@code
 * Constructor} object that contain the {@link DescriptorKey}
 * meta-annotation.
 *
 * @param description A human readable description of the operation.
 * @param constructor The <CODE>java.lang.reflect.Constructor</CODE>
 * object describing the MBean constructor.
 */
public MBeanConstructorInfo(String description, Constructor<?> constructor) {
    this(constructor.getName(), description,
         constructorSignature(constructor),
         Introspector.descriptorForElement(constructor));
}
 
Example 17
/**
 * Constructs an <CODE>MBeanConstructorInfo</CODE> object.  The
 * {@link Descriptor} of the constructed object will include
 * fields contributed by any annotations on the {@code
 * Constructor} object that contain the {@link DescriptorKey}
 * meta-annotation.
 *
 * @param description A human readable description of the operation.
 * @param constructor The <CODE>java.lang.reflect.Constructor</CODE>
 * object describing the MBean constructor.
 */
public MBeanConstructorInfo(String description, Constructor<?> constructor) {
    this(constructor.getName(), description,
         constructorSignature(constructor),
         Introspector.descriptorForElement(constructor));
}
 
Example 18
/**
 * Constructs an <CODE>MBeanConstructorInfo</CODE> object.  The
 * {@link Descriptor} of the constructed object will include
 * fields contributed by any annotations on the {@code
 * Constructor} object that contain the {@link DescriptorKey}
 * meta-annotation.
 *
 * @param description A human readable description of the operation.
 * @param constructor The <CODE>java.lang.reflect.Constructor</CODE>
 * object describing the MBean constructor.
 */
public MBeanConstructorInfo(String description, Constructor<?> constructor) {
    this(constructor.getName(), description,
         constructorSignature(constructor),
         Introspector.descriptorForElement(constructor));
}
 
Example 19
/**
 * Constructs an <CODE>MBeanConstructorInfo</CODE> object.  The
 * {@link Descriptor} of the constructed object will include
 * fields contributed by any annotations on the {@code
 * Constructor} object that contain the {@link DescriptorKey}
 * meta-annotation.
 *
 * @param description A human readable description of the operation.
 * @param constructor The <CODE>java.lang.reflect.Constructor</CODE>
 * object describing the MBean constructor.
 */
public MBeanConstructorInfo(String description, Constructor<?> constructor) {
    this(constructor.getName(), description,
         constructorSignature(constructor),
         Introspector.descriptorForElement(constructor));
}
 
Example 20
/**
 * Constructs an <CODE>MBeanConstructorInfo</CODE> object.  The
 * {@link Descriptor} of the constructed object will include
 * fields contributed by any annotations on the {@code
 * Constructor} object that contain the {@link DescriptorKey}
 * meta-annotation.
 *
 * @param description A human readable description of the operation.
 * @param constructor The <CODE>java.lang.reflect.Constructor</CODE>
 * object describing the MBean constructor.
 */
public MBeanConstructorInfo(String description, Constructor<?> constructor) {
    this(constructor.getName(), description,
         constructorSignature(constructor),
         Introspector.descriptorForElement(constructor));
}