/** * Strips getter prefix from method name. * * @param method the method to be processed * @return the stripped method name with Decapitalized first letter or null if passed method is null or if the method name has no getter prefix. */ public static String getFieldName(final Method method) { if (method != null) { return getFieldName(method.getName()); } else { return null; } }
/** * Strips getter prefix from method name. * * @param methodName the name of the method to be processed * @return the stripped method name with Decapitalized first letter or null if passed method name has no getter prefix. */ public static String getFieldName(final String methodName) { if (isGetterMethod(methodName)) { return decapitalizeFirstCharOfString(stripGetterPrefix(methodName)); } return null; }
/** * Gets the full qualified name of a field or non getter method. * Result has following format : "Full Qualified Classname"."field name for getter methods or method name for non getter methods". * * @param method The method to be processed * @return */ public static String getFullQualifiedFieldName(final Class type, final Method method) { if (method != null) { // get the name of the type from passed type or method final String typeName; if (type != null) { typeName = type.getCanonicalName(); } else { typeName = method.getDeclaringClass().getCanonicalName(); } // get field name from getter method or method name for non getter methods final String fieldName; if (isGetterMethod(method.getName())) { fieldName = getFieldName(method.getName()); } else { fieldName = method.getName(); } return typeName + "." + fieldName; } else { return null; } }
/** * Checks whether the method name starts with a getter prefix. * * @param method the method to check for * @return true if the method name starts with eiher one of values stored in GETTER_PREFIXES */ public static boolean isGetterMethod(final Method method) { if (method != null) { return isGetterMethod(method.getName()); } else { return false; } }
/** * Determines if a method should be processed. This will either be if no * {@link io.tracee.contextlogger.api.TraceeContextProviderMethod} annotation * is present or if an empty property name is defined in the annotation or if passed profileSettings are null * or if the property name is disabled in the {@link io.tracee.contextlogger.profile.ProfileSettings}. * * @param profileSettings The profile sttings object which should be used to check against. * @return true if the result of the method should be processed, otherwise false. */ public boolean shouldBeProcessed(final ProfileSettings profileSettings) { if (profileSettings != null) { String propertyName = GetterUtilities.getFullQualifiedFieldName(baseType, method); Boolean shouldBeProcessed = profileSettings.getPropertyValue(propertyName); if (shouldBeProcessed == null) { propertyName = baseType.getCanonicalName() + "." + method.getName(); shouldBeProcessed = profileSettings.getPropertyValue(propertyName); } if (shouldBeProcessed == null && annotation != null) { shouldBeProcessed = annotation.enabledPerDefault(); } if (shouldBeProcessed != null) { return shouldBeProcessed; } } return true; }
if (isGetterMethod(method.getName())) { fieldName = getFieldName(method.getName());
/** * Checks whether the method name starts with a getter prefix. * * @param method the method to check for * @return true if the method name starts with eiher one of values stored in GETTER_PREFIXES */ public static boolean isGetterMethod(final Method method) { if (method != null) { return isGetterMethod(method.getName()); } else { return false; } }
/** * Strips getter prefix from method name. * * @param methodName the name of the method to be processed * @return the stripped method name with Decapitalized first letter or null if passed method name has no getter prefix. */ public static String getFieldName(final String methodName) { if (isGetterMethod(methodName)) { return decapitalizeFirstCharOfString(stripGetterPrefix(methodName)); } return null; }
/** * Strips getter prefix from method name. * * @param method the method to be processed * @return the stripped method name with Decapitalized first letter or null if passed method is null or if the method name has no getter prefix. */ public static String getFieldName(final Method method) { if (method != null) { return getFieldName(method.getName()); } else { return null; } }
/** * Helper method for getting a corresponsing field for a method * * @param type the type to search the field in * @param method the getter method to search the field for * @return the Field or null if the field for the passed method doesn't exists */ Field getCorrespondingField(Class type, Method method) { try { return type.getDeclaredField(GetterUtilities.getFieldName(method)); } catch (NoSuchFieldException e) { return null; } }
protected void writeToPropertyFile(Profile profile, TypeElement parentElement, Element element, boolean value) throws IOException { FileObjectWrapper fileObject = getOrCreateProfileProperties(filer, profile.getFilename()); String fieldName = GetterUtilities.getFieldName(element.getSimpleName().toString()); if (fieldName == null) { fieldName = element.getSimpleName().toString(); } fileObject.append(((TypeElement) parentElement).getQualifiedName() + "." + fieldName + "=" + value + "\n"); }