@Test public void findSetterNonCollection() throws NoSuchMethodException, OslcCoreMissingSetMethodException { ResourceShapeFactory.validateSetMethodExists(Dummy.class, Dummy.class.getMethod("getValue2")); }
protected static void validateSetMethodExists(final Class<?> resourceClass, final Method getMethod) throws OslcCoreMissingSetMethodException { final String getMethodName = getMethod.getName(); final String setMethodName; if (getMethodName.startsWith(METHOD_NAME_START_GET)) { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_GET_LENGTH); } else { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_IS_LENGTH); } final Class<?> returnType = getMethod.getReturnType(); if(!isCollectionType(returnType)) { try { resourceClass.getMethod(setMethodName, returnType); } catch (final NoSuchMethodException exception) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, exception); } } else { final List<Method> methods = Arrays.stream(resourceClass.getMethods()) .filter(m -> m.getName().equals(setMethodName)) .collect(Collectors.toList()); if (methods.size() == 0) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } if (methods.size() > 1) { throw new IllegalArgumentException( "Multiple setters on the same RDF property are not yet supported"); } final Method method = methods.get(0); final Type[] parameterTypes = method.getGenericParameterTypes(); if (parameterTypes == null || parameterTypes.length == 0 || parameterTypes.length > 1) { throw new IllegalArgumentException( String.format("Method '%s' shall have exactly one argument", method.getName() )); } final ParameterizedType setterArgumentType = (ParameterizedType) parameterTypes[0]; final ParameterizedType genericReturnType = (ParameterizedType) getMethod.getGenericReturnType(); if (!genericReturnType.getActualTypeArguments()[0].equals(setterArgumentType.getActualTypeArguments()[0])) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } } }
ResourceShapeFactory { protected static void validateSetMethodExists(final Class<?> resourceClass, final Method getMethod) throws OslcCoreMissingSetMethodException { final String getMethodName = getMethod.getName(); final String setMethodName; if (getMethodName.startsWith(METHOD_NAME_START_GET)) { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_GET_LENGTH); } else { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_IS_LENGTH); } final Class<?> returnType = getMethod.getReturnType(); if(!isCollectionType(returnType)) { try { resourceClass.getMethod(setMethodName, returnType); } catch (final NoSuchMethodException exception) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, exception); } } else { final List<Method> methods = Arrays.stream(resourceClass.getMethods()) .filter(m -> m.getName().equals(setMethodName)) .collect(Collectors.toList()); if (methods.size() == 0) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } if (methods.size() > 1) { throw new IllegalArgumentException( "Multiple setters on the same RDF property are not yet supported"); } final Method method = methods.get(0); final Type[] parameterTypes = method.getGenericParameterTypes(); if (parameterTypes == null || parameterTypes.length == 0 || parameterTypes.length > 1) { throw new IllegalArgumentException( String.format("Method '%s' shall have exactly one argument", method.getName() )); } final ParameterizedType setterArgumentType = (ParameterizedType) parameterTypes[0]; final ParameterizedType genericReturnType = (ParameterizedType) getMethod.getGenericReturnType(); if (!genericReturnType.getActualTypeArguments()[0].equals(setterArgumentType.getActualTypeArguments()[0])) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } } } }
ResourceShapeFactory { protected static void validateSetMethodExists(final Class<?> resourceClass, final Method getMethod) throws OslcCoreMissingSetMethodException { final String getMethodName = getMethod.getName(); final String setMethodName; if (getMethodName.startsWith(METHOD_NAME_START_GET)) { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_GET_LENGTH); } else { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_IS_LENGTH); } final Class<?> returnType = getMethod.getReturnType(); if(!isCollectionType(returnType)) { try { resourceClass.getMethod(setMethodName, returnType); } catch (final NoSuchMethodException exception) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, exception); } } else { final List<Method> methods = Arrays.stream(resourceClass.getMethods()) .filter(m -> m.getName().equals(setMethodName)) .collect(Collectors.toList()); if (methods.size() == 0) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } if (methods.size() > 1) { throw new IllegalArgumentException( "Multiple setters on the same RDF property are not yet supported"); } final Method method = methods.get(0); final Type[] parameterTypes = method.getGenericParameterTypes(); if (parameterTypes == null || parameterTypes.length == 0 || parameterTypes.length > 1) { throw new IllegalArgumentException( String.format("Method '%s' shall have exactly one argument", method.getName() )); } final ParameterizedType setterArgumentType = (ParameterizedType) parameterTypes[0]; final ParameterizedType genericReturnType = (ParameterizedType) getMethod.getGenericReturnType(); if (!genericReturnType.getActualTypeArguments()[0].equals(setterArgumentType.getActualTypeArguments()[0])) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } } } protected  ResourceShapeFactory(); }
ResourceShapeFactory { protected static void validateSetMethodExists(final Class<?> resourceClass, final Method getMethod) throws OslcCoreMissingSetMethodException { final String getMethodName = getMethod.getName(); final String setMethodName; if (getMethodName.startsWith(METHOD_NAME_START_GET)) { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_GET_LENGTH); } else { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_IS_LENGTH); } final Class<?> returnType = getMethod.getReturnType(); if(!isCollectionType(returnType)) { try { resourceClass.getMethod(setMethodName, returnType); } catch (final NoSuchMethodException exception) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, exception); } } else { final List<Method> methods = Arrays.stream(resourceClass.getMethods()) .filter(m -> m.getName().equals(setMethodName)) .collect(Collectors.toList()); if (methods.size() == 0) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } if (methods.size() > 1) { throw new IllegalArgumentException( "Multiple setters on the same RDF property are not yet supported"); } final Method method = methods.get(0); final Type[] parameterTypes = method.getGenericParameterTypes(); if (parameterTypes == null || parameterTypes.length == 0 || parameterTypes.length > 1) { throw new IllegalArgumentException( String.format("Method '%s' shall have exactly one argument", method.getName() )); } final ParameterizedType setterArgumentType = (ParameterizedType) parameterTypes[0]; final ParameterizedType genericReturnType = (ParameterizedType) getMethod.getGenericReturnType(); if (!genericReturnType.getActualTypeArguments()[0].equals(setterArgumentType.getActualTypeArguments()[0])) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } } } protected  ResourceShapeFactory(); static ResourceShape createResourceShape(final String baseURI,
													final String resourceShapesPath,
													final String resourceShapePath,
													final Class<?> resourceClass); }
ResourceShapeFactory { protected static void validateSetMethodExists(final Class<?> resourceClass, final Method getMethod) throws OslcCoreMissingSetMethodException { final String getMethodName = getMethod.getName(); final String setMethodName; if (getMethodName.startsWith(METHOD_NAME_START_GET)) { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_GET_LENGTH); } else { setMethodName = METHOD_NAME_START_SET + getMethodName.substring(METHOD_NAME_START_IS_LENGTH); } final Class<?> returnType = getMethod.getReturnType(); if(!isCollectionType(returnType)) { try { resourceClass.getMethod(setMethodName, returnType); } catch (final NoSuchMethodException exception) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, exception); } } else { final List<Method> methods = Arrays.stream(resourceClass.getMethods()) .filter(m -> m.getName().equals(setMethodName)) .collect(Collectors.toList()); if (methods.size() == 0) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } if (methods.size() > 1) { throw new IllegalArgumentException( "Multiple setters on the same RDF property are not yet supported"); } final Method method = methods.get(0); final Type[] parameterTypes = method.getGenericParameterTypes(); if (parameterTypes == null || parameterTypes.length == 0 || parameterTypes.length > 1) { throw new IllegalArgumentException( String.format("Method '%s' shall have exactly one argument", method.getName() )); } final ParameterizedType setterArgumentType = (ParameterizedType) parameterTypes[0]; final ParameterizedType genericReturnType = (ParameterizedType) getMethod.getGenericReturnType(); if (!genericReturnType.getActualTypeArguments()[0].equals(setterArgumentType.getActualTypeArguments()[0])) { throw new OslcCoreMissingSetMethodException(resourceClass, getMethod, null); } } } protected  ResourceShapeFactory(); static ResourceShape createResourceShape(final String baseURI,
													final String resourceShapesPath,
													final String resourceShapePath,
													final Class<?> resourceClass);  }