List of usage examples for java.lang.reflect Member getName
public String getName();
From source file:org.candlepin.swagger.CandlepinSwaggerModelConverter.java
private String getPropName(BeanPropertyDefinition propDef, String propName) { // hack to avoid clobbering properties with get/is names // it's ugly but gets around // https://github.com/swagger-api/swagger-core/issues/415 if (propDef.getPrimaryMember() != null) { java.lang.reflect.Member member = propDef.getPrimaryMember().getMember(); if (member != null) { String altName = member.getName(); if (altName != null) { final int length = altName.length(); for (String prefix : Arrays.asList("get", "is")) { final int offset = prefix.length(); if (altName.startsWith(prefix) && length > offset && !Character.isUpperCase(altName.charAt(offset))) { propName = altName; break; }// w ww . j ava2 s. c om } } } } return propName; }
From source file:org.dhatim.cdr.annotation.Configurator.java
private static <U> void applyConfigParam(ConfigParam configParam, Member member, Class type, U instance, SmooksResourceConfiguration config) throws SmooksConfigurationException { String name = configParam.name(); String paramValue;/*from ww w .ja va 2 s .co m*/ // Work out the property name, if not specified via the annotation.... if (AnnotationConstants.NULL_STRING.equals(name)) { // "name" not defined. Use the field/method name... if (member instanceof Method) { name = getPropertyName((Method) member); if (name == null) { throw new SmooksConfigurationException("Unable to determine the property name associated with '" + getLongMemberName(member) + "'. " + "Setter methods that specify the @ConfigParam annotation " + "must either follow the Javabean naming convention ('setX' for propert 'x'), or specify the " + "propery name via the 'name' parameter on the @ConfigParam annotation."); } } else { name = member.getName(); } } paramValue = config.getStringParameter(name); if (paramValue == null) { paramValue = configParam.defaultVal(); if (AnnotationConstants.NULL_STRING.equals(paramValue)) { // A null default was assigned... String[] choices = configParam.choice(); assertValidChoice(choices, name, AnnotationConstants.NULL_STRING); setMember(member, instance, null); return; } else if (AnnotationConstants.UNASSIGNED.equals(paramValue)) { // No default was assigned... paramValue = null; } } if (paramValue != null) { String[] choices = configParam.choice(); Class<? extends DataDecoder> decoderClass; DataDecoder decoder; assertValidChoice(choices, name, paramValue); decoderClass = configParam.decoder(); decoder = createDecoder(member, type, decoderClass); try { setMember(member, instance, decoder.decode(paramValue)); } catch (DataDecodeException e) { throw new SmooksConfigurationException( "Failed to set paramater configuration value on '" + getLongMemberName(member) + "'.", e); } } else if (configParam.use() == ConfigParam.Use.REQUIRED) { throw new SmooksConfigurationException( "<param> '" + name + "' not specified on resource configuration:\n" + config); } }
From source file:org.dhatim.cdr.annotation.Configurator.java
private static String getLongMemberName(Member field) { return field.getDeclaringClass().getName() + "#" + field.getName(); }
From source file:org.dozer.classmap.ClassMapBuilder.java
private static void validate(Mapping annotation, Member member) { if (annotation.value().trim().equals("")) { throw new MappingException("Mapping annotation value missing at " + member.getDeclaringClass().getName() + "." + member.getName()); }/*w ww . j a v a 2 s. c o m*/ }
From source file:org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.java
public void processAnnotations(DescriptorPolicy descriptorPolicy, ScoreDefinition deprecatedScoreDefinition, List<Class<?>> entityClassList) { processSolutionAnnotations(descriptorPolicy); ArrayList<Method> potentiallyOverwritingMethodList = new ArrayList<>(); // Iterate inherited members too (unlike for EntityDescriptor where each one is declared) // to make sure each one is registered for (Class<?> lineageClass : ConfigUtils.getAllAnnotatedLineageClasses(solutionClass, PlanningSolution.class)) { List<Member> memberList = ConfigUtils.getDeclaredMembers(lineageClass); for (Member member : memberList) { if (member instanceof Method && potentiallyOverwritingMethodList.stream() .anyMatch(m -> member.getName().equals(m.getName()) // Short cut to discard negatives faster && ReflectionHelper.isMethodOverwritten((Method) member, m.getDeclaringClass()))) { // Ignore member because it is an overwritten method continue; }/*from w w w .j a v a 2 s . com*/ processValueRangeProviderAnnotation(descriptorPolicy, member); processFactEntityOrScoreAnnotation(descriptorPolicy, member, deprecatedScoreDefinition, entityClassList); } potentiallyOverwritingMethodList .ensureCapacity(potentiallyOverwritingMethodList.size() + memberList.size()); memberList.stream().filter(member -> member instanceof Method) .forEach(member -> potentiallyOverwritingMethodList.add((Method) member)); } if (entityCollectionMemberAccessorMap.isEmpty() && entityMemberAccessorMap.isEmpty()) { throw new IllegalStateException( "The solutionClass (" + solutionClass + ") must have at least 1 member with a " + PlanningEntityCollectionProperty.class.getSimpleName() + " annotation or a " + PlanningEntityProperty.class.getSimpleName() + " annotation."); } if (Solution.class.isAssignableFrom(solutionClass)) { processLegacySolution(descriptorPolicy, deprecatedScoreDefinition); return; } // Do not check if problemFactCollectionMemberAccessorMap and problemFactMemberAccessorMap are empty // because they are only required for Drools score calculation. if (scoreMemberAccessor == null) { throw new IllegalStateException("The solutionClass (" + solutionClass + ") must have 1 member with a " + PlanningScore.class.getSimpleName() + " annotation.\n" + "Maybe add a getScore() method with a " + PlanningScore.class.getSimpleName() + " annotation."); } }
From source file:org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.java
private Class<? extends Annotation> extractFactEntityOrScoreAnnotationClassOrAutoDiscover(Member member, List<Class<?>> entityClassList) { Class<? extends Annotation> annotationClass = ConfigUtils.extractAnnotationClass(member, ProblemFactProperty.class, ProblemFactCollectionProperty.class, PlanningEntityProperty.class, PlanningEntityCollectionProperty.class, PlanningScore.class); if (annotationClass == null) { Class<?> type;// w ww . java 2s. c om if (autoDiscoverMemberType == AutoDiscoverMemberType.FIELD && member instanceof Field) { Field field = (Field) member; type = field.getType(); } else if (autoDiscoverMemberType == AutoDiscoverMemberType.GETTER && (member instanceof Method) && ReflectionHelper.isGetterMethod((Method) member)) { Method method = (Method) member; type = method.getReturnType(); } else { type = null; } if (type != null) { if (Score.class.isAssignableFrom(type)) { annotationClass = PlanningScore.class; } else if (Collection.class.isAssignableFrom(type)) { Type genericType = (member instanceof Field) ? ((Field) member).getGenericType() : ((Method) member).getGenericReturnType(); Class<?> elementType = ConfigUtils.extractCollectionGenericTypeParameter("solutionClass", solutionClass, type, genericType, null, member.getName()); if (entityClassList.stream() .anyMatch(entityClass -> entityClass.isAssignableFrom(elementType))) { annotationClass = PlanningEntityCollectionProperty.class; } else { annotationClass = ProblemFactCollectionProperty.class; } } else if (type.isArray()) { Class<?> elementType = type.getComponentType(); if (entityClassList.stream() .anyMatch(entityClass -> entityClass.isAssignableFrom(elementType))) { annotationClass = PlanningEntityCollectionProperty.class; } else { annotationClass = ProblemFactCollectionProperty.class; } } else if (Map.class.isAssignableFrom(type)) { throw new IllegalStateException("The autoDiscoverMemberType (" + autoDiscoverMemberType + ") does not yet support the member (" + member + ") of type (" + type + ") which is an implementation of " + Map.class.getSimpleName() + "."); } else if (entityClassList.stream().anyMatch(entityClass -> entityClass.isAssignableFrom(type))) { annotationClass = PlanningEntityProperty.class; } else { annotationClass = ProblemFactProperty.class; } } } return annotationClass; }
From source file:org.pircbotx.TestUtils.java
public static boolean isRealMember(Member member) { return !member.isSynthetic() && !member.getName().startsWith("__"); }
From source file:org.saiku.olap.util.ObjectUtil.java
@NotNull public static SaikuMember convert(@NotNull Member m) { return new SaikuMember(m.getName(), m.getUniqueName(), m.getCaption(), m.getDescription(), m.getDimension().getUniqueName(), m.getHierarchy().getUniqueName(), m.getLevel().getUniqueName(), m.isCalculated());//from w w w.j a v a 2s . co m }