@Override public Import addImport(Type<?> type) { return addImport(type.getQualifiedName()); }
private void resolveTypeArguments(List<Type> typeArguments, List<org.kie.workbench.common.services.datamodeller.core.Type> resultTypeArguments) { if (typeArguments != null) { for (Type typeArgument : typeArguments) { org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl resultType = new org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl(typeArgument.getQualifiedName(), new ArrayList<>()); resultTypeArguments.add(resultType); resolveTypeArguments(typeArgument.getTypeArguments(), resultType.getTypeArguments()); } } }
@Override public String getGenericType() { if (this.readMethod != null) { @SuppressWarnings({ "unchecked", "rawtypes" }) List<Type<?>> typeArguments = (List) this.readMethod.getReturnType().getTypeArguments(); if (!typeArguments.isEmpty()) { return typeArguments.get(0).getQualifiedName(); } } if (this.privateField != null) { @SuppressWarnings({ "unchecked", "rawtypes" }) List<Type<?>> typeArguments = (List) this.privateField.getType().getTypeArguments(); if (!typeArguments.isEmpty()) { return typeArguments.get(0).getQualifiedName(); } } return null; }
@Override public String getGenericType() { if (this.readMethod != null) { @SuppressWarnings({ "unchecked", "rawtypes" }) List<Type<?>> typeArguments = (List) this.readMethod.getReturnType().getTypeArguments(); if (!typeArguments.isEmpty()) { return typeArguments.get(0).getQualifiedName(); } } if (this.privateField != null) { @SuppressWarnings({ "unchecked", "rawtypes" }) List<Type<?>> typeArguments = (List) this.privateField.getType().getTypeArguments(); if (!typeArguments.isEmpty()) { return typeArguments.get(0).getQualifiedName(); } } return null; }
/** * Returns whether the given method is a 'getter' method. * * @param method a parameterless method that returns a non-void * @return the property name */ protected String isGetter(final Method<?, ?> method) { String methodName = method.getName(); String propertyName; if (methodName.startsWith(ClassUtils.JAVABEAN_GET_PREFIX)) { propertyName = methodName.substring(ClassUtils.JAVABEAN_GET_PREFIX.length()); } else if (methodName.startsWith(ClassUtils.JAVABEAN_IS_PREFIX) && method.getReturnType() != null && boolean.class.equals(method.getReturnType().getQualifiedName())) { // As per section 8.3.2 (Boolean properties) of The JavaBeans API specification, 'is' // only applies to boolean (little 'b') propertyName = methodName.substring(ClassUtils.JAVABEAN_IS_PREFIX.length()); } else { return null; } return StringUtils.decapitalize(propertyName); }
/** * Returns whether the given method is a 'getter' method. * * @param method a parameterless method that returns a non-void * @return the property name */ protected String isGetter(final Method<?, ?> method) { String methodName = method.getName(); String propertyName; if (methodName.startsWith(ClassUtils.JAVABEAN_GET_PREFIX)) { propertyName = methodName.substring(ClassUtils.JAVABEAN_GET_PREFIX.length()); } else if (methodName.startsWith(ClassUtils.JAVABEAN_IS_PREFIX) && method.getReturnType() != null && boolean.class.equals(method.getReturnType().getQualifiedName())) { // As per section 8.3.2 (Boolean properties) of The JavaBeans API specification, 'is' // only applies to boolean (little 'b') propertyName = methodName.substring(ClassUtils.JAVABEAN_IS_PREFIX.length()); } else { return null; } return StringUtils.decapitalize(propertyName); }
@Override public Import addImport(final Type<?> type) { Import imprt; if (requiresImport(type.getQualifiedName())) { imprt = addImport(type.getQualifiedName()); } else { imprt = getImport(type.getQualifiedName()); } for (Type<?> arg : type.getTypeArguments()) { if (!arg.isWildcard() && arg.isQualified()) { addImport(arg); } } return imprt; }
@Override public Import addImport(final Type<?> type) { Import imprt; if (requiresImport(type.getQualifiedName())) { imprt = addImport(type.getQualifiedName()); } else { imprt = getImport(type.getQualifiedName()); } for (Type<?> arg : type.getTypeArguments()) { if (!arg.isWildcard() && arg.isQualified()) { addImport(arg); } } return imprt; }
@Override public List<PropertySource<O>> getProperties(Class<?> type) { final Set<String> propertyNames = new LinkedHashSet<>(); for (MethodSource<O> method : getMethods()) { if ((isAccessor(method) || isMutator(method)) && method.getReturnType().getQualifiedName().equals(type.getCanonicalName())) { propertyNames.add(extractPropertyName(method)); } } for (FieldSource<O> field : getFields()) { if (!field.isStatic() && field.getType().getQualifiedName().equals(type.getCanonicalName())) { propertyNames.add(field.getName()); } } final List<PropertySource<O>> result = new ArrayList<>(propertyNames.size()); for (String name : propertyNames) { result.add(new PropertyImpl<>(name, getOrigin())); } return result; }
@Override public List<PropertySource<O>> getProperties(Class<?> type) { final Set<String> propertyNames = new LinkedHashSet<String>(); for (MethodSource<O> method : getMethods()) { if ((isAccessor(method) || isMutator(method)) && method.getReturnType().getQualifiedName().equals(type.getCanonicalName())) { propertyNames.add(extractPropertyName(method)); } } for (FieldSource<O> field : getFields()) { if (!field.isStatic() && field.getType().getQualifiedName().equals(type.getCanonicalName())) { propertyNames.add(field.getName()); } } final List<PropertySource<O>> result = new ArrayList<PropertySource<O>>(propertyNames.size()); for (String name : propertyNames) { result.add(new PropertyImpl<O>(name, getOrigin())); } return result; }
private String resolveTypeLiteralName(TypeLiteral typeLiteral) { final Type<O> type = new TypeImpl<O>(getOrigin(), typeLiteral.getType()); if (type.isPrimitive()) { final Class<?>[] primitiveTypes = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class }; for (Class<?> c : primitiveTypes) { if (c.getSimpleName().equals(type.getName())) { return c.getName(); } } return null; } final String classname = type.getQualifiedName(); return getOrigin().resolveType(classname); }
private String resolveTypeLiteralName(TypeLiteral typeLiteral) { final Type<O> type = new TypeImpl<O>(getOrigin(), typeLiteral.getType()); if (type.isPrimitive()) { final Class<?>[] primitiveTypes = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class }; for (Class<?> c : primitiveTypes) { if (c.getSimpleName().equals(type.getName())) { return c.getName(); } } return null; } final String classname = type.getQualifiedName(); return getOrigin().resolveType(classname); }
private Class<?> resolveTypeLiteral(TypeLiteral typeLiteral) { final Type<O> type = new TypeImpl<O>(getOrigin(), typeLiteral.getType()); if (type.isPrimitive()) { final Class<?>[] primitiveTypes = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class }; for (Class<?> c : primitiveTypes) { if (c.getSimpleName().equals(type.getName())) { return c; } } return null; } final String classname = type.getQualifiedName(); try { return Class.forName(getOrigin().resolveType(classname)); } catch (ClassNotFoundException e) { return null; } }
private Class<?> resolveTypeLiteral(TypeLiteral typeLiteral) { final Type<JavaAnnotationSource> type = new TypeImpl<JavaAnnotationSource>(getOrigin(), typeLiteral.getType()); if (type.isPrimitive()) { final Class<?>[] primitiveTypes = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class }; for (Class<?> c : primitiveTypes) { if (c.getSimpleName().equals(type.getName())) { return c; } } return null; } final String classname = type.getQualifiedName(); try { return Class.forName(getOrigin().resolveType(classname)); } catch (ClassNotFoundException e) { return null; } } }
private Class<?> resolveTypeLiteral(TypeLiteral typeLiteral) { final Type<O> type = new TypeImpl<O>(getOrigin(), typeLiteral.getType()); if (type.isPrimitive()) { final Class<?>[] primitiveTypes = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class }; for (Class<?> c : primitiveTypes) { if (c.getSimpleName().equals(type.getName())) { return c; } } return null; } final String classname = type.getQualifiedName(); try { return Class.forName(getOrigin().resolveType(classname)); } catch (ClassNotFoundException e) { return null; } }
private Class<?> resolveTypeLiteral(TypeLiteral typeLiteral) { final Type<O> type = new TypeImpl<O>(getOrigin(), typeLiteral.getType()); if (type.isPrimitive()) { final Class<?>[] primitiveTypes = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class }; for (Class<?> c : primitiveTypes) { if (c.getSimpleName().equals(type.getName())) { return c; } } return null; } final String classname = type.getQualifiedName(); try { return Class.forName(getOrigin().resolveType(classname)); } catch (ClassNotFoundException e) { return null; } } }
private Class<?> resolveTypeLiteral(TypeLiteral typeLiteral) { final Type<JavaAnnotationSource> type = new TypeImpl<JavaAnnotationSource>(getOrigin(), typeLiteral.getType()); if (type.isPrimitive()) { final Class<?>[] primitiveTypes = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class }; for (Class<?> c : primitiveTypes) { if (c.getSimpleName().equals(type.getName())) { return c; } } return null; } final String classname = type.getQualifiedName(); try { return Class.forName(getOrigin().resolveType(classname)); } catch (ClassNotFoundException e) { return null; } } }
private Class<?> resolveTypeLiteral(TypeLiteral typeLiteral) { final Type<JavaAnnotationSource> type = new TypeImpl<JavaAnnotationSource>(getOrigin(), typeLiteral.getType()); if (type.isPrimitive()) { final Class<?>[] primitiveTypes = { boolean.class, byte.class, short.class, int.class, long.class, float.class, double.class }; for (Class<?> c : primitiveTypes) { if (c.getSimpleName().equals(type.getName())) { return c; } } return null; } final String classname = type.getQualifiedName(); try { return Class.forName(getOrigin().resolveType(classname)); } catch (ClassNotFoundException e) { return null; } } }
public void visit(MethodSource<? extends JavaClassSource> methodSource) { for (ParameterSource<? extends JavaClassSource> paramSource : methodSource.getParameters()) { // Method parameters addJavaResourceReference(paramSource.getType().getQualifiedName()); // Method parameter annotations for (AnnotationSource<? extends JavaClassSource> annoSource : paramSource.getAnnotations()) { visit(annoSource); } } Type<? extends JavaClassSource> returnType = methodSource.getReturnType(); if (returnType != null) { String returnTypeQualifiedName = returnType.getQualifiedName(); if (!returnTypeQualifiedName.endsWith(".void")) { addJavaResourceReference(returnTypeQualifiedName); } } // method annotations for (AnnotationSource<? extends JavaClassSource> annoSource : methodSource.getAnnotations()) { visit(annoSource); } }
public void visit(FieldSource<? extends JavaSource> fieldSource) { Type fieldType = fieldSource.getType(); String fieldClassName; // the javadoc for Named.getName() is misleading: // the FieldSource.getName() (which is implemented by FieldImpl.getName()) // returns the (fully-qualified!) name of the field String fieldName = fieldSource.getName(); resParts.addPart(fieldName, PartType.FIELD); if (fieldType.isPrimitive()) { fieldClassName = fieldType.getName(); } else { fieldClassName = fieldType.getQualifiedName(); } addJavaResourceReference(fieldClassName); // Field annotations for (AnnotationSource annoSource : fieldSource.getAnnotations()) { visit(annoSource); } }