Search in sources :

Example 1 with CanonicalName

use of com.github.havardh.javaflow.model.CanonicalName in project javaflow by havardh.

the class MemberFieldsPresentVerifier method verify.

/**
 * Verifies that there are no missing types referenced
 * in the list of {@code Type}.
 *
 * A missing type is found when a type is referenced which is not
 * in the given set of types of in the {@code TypeMap} of the verifier
 * If a any missing types are discovered a {@code MissingTypeException}
 * is thrown containing the complete list of missing types.
 *
 * @param types list of {@code Type} to verify
 * @throws MissingTypeException when a missing type is found
 */
@Override
public void verify(List<Type> types) {
    Set<CanonicalName> nameSet = types.stream().map(Type::getCanonicalName).collect(toSet());
    Map<Type, List<Field>> missingTypes = new HashMap<>();
    for (Type type : types.stream().filter(t -> t instanceof Class).collect(toList())) {
        ((Class) type).getFields().stream().filter(field -> !nameSet.contains(field.getType().getCanonicalName())).filter(field -> !isObject(field.getType().toString())).filter(field -> !isPrimitive(field.getType().toString())).filter(field -> !customTypes.containsKey(field.getType().toString())).forEach(field -> missingTypes.compute(type, (ignored, fields) -> fields == null ? singletonList(field) : concat(fields, singletonList(field))));
    }
    if (!missingTypes.isEmpty()) {
        throw new MissingTypeException(missingTypes);
    }
}
Also used : Objects.isObject(com.github.havardh.javaflow.phases.writer.flow.converter.definitions.Objects.isObject) Lists.concat(com.github.havardh.javaflow.util.Lists.concat) CanonicalName(com.github.havardh.javaflow.model.CanonicalName) Set(java.util.Set) HashMap(java.util.HashMap) Field(com.github.havardh.javaflow.ast.Field) Collections.singletonList(java.util.Collections.singletonList) MissingTypeException(com.github.havardh.javaflow.exceptions.MissingTypeException) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Class(com.github.havardh.javaflow.ast.Class) Map(java.util.Map) Primitives.isPrimitive(com.github.havardh.javaflow.phases.writer.flow.converter.definitions.Primitives.isPrimitive) Type(com.github.havardh.javaflow.ast.Type) TypeMap(com.github.havardh.javaflow.model.TypeMap) Collectors.toSet(java.util.stream.Collectors.toSet) Type(com.github.havardh.javaflow.ast.Type) MissingTypeException(com.github.havardh.javaflow.exceptions.MissingTypeException) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Class(com.github.havardh.javaflow.ast.Class) CanonicalName(com.github.havardh.javaflow.model.CanonicalName)

Aggregations

Class (com.github.havardh.javaflow.ast.Class)1 Field (com.github.havardh.javaflow.ast.Field)1 Type (com.github.havardh.javaflow.ast.Type)1 MissingTypeException (com.github.havardh.javaflow.exceptions.MissingTypeException)1 CanonicalName (com.github.havardh.javaflow.model.CanonicalName)1 TypeMap (com.github.havardh.javaflow.model.TypeMap)1 Objects.isObject (com.github.havardh.javaflow.phases.writer.flow.converter.definitions.Objects.isObject)1 Primitives.isPrimitive (com.github.havardh.javaflow.phases.writer.flow.converter.definitions.Primitives.isPrimitive)1 Lists.concat (com.github.havardh.javaflow.util.Lists.concat)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toSet (java.util.stream.Collectors.toSet)1