Search in sources :

Example 1 with Namespace

use of com.palantir.conjure.parser.types.names.Namespace in project conjure by palantir.

the class ConjureParserUtils method innerParseImportObjects.

private static Map<TypeName, TypeDefinition> innerParseImportObjects(Map<Namespace, ConjureImports> conjureImports, Map<String, AnnotatedConjureSourceFile> externalTypes, Set<String> loadedFiles) {
    Map<TypeName, TypeDefinition> allDefinitions = new HashMap<>();
    conjureImports.values().forEach(conjureImport -> {
        String pathKey = conjureImport.absoluteFile().orElseThrow(() -> new SafeIllegalStateException("Absolute file MUST be resolved as part of parsing stage")).getAbsolutePath();
        // These structures are potentially recursive; load in any given conjure file once
        if (loadedFiles.contains(pathKey)) {
            return;
        }
        loadedFiles.add(pathKey);
        AnnotatedConjureSourceFile annotatedConjureSourceFile = externalTypes.get(pathKey);
        Preconditions.checkNotNull(annotatedConjureSourceFile, "Couldn't find import", UnsafeArg.of("file", conjureImport.file()));
        ConjureSourceFile conjureDef = annotatedConjureSourceFile.conjureSourceFile();
        Map<Namespace, String> importProviders = annotatedConjureSourceFile.importProviders();
        ReferenceTypeResolver importTypeResolver = new ConjureTypeParserVisitor.ByParsedRepresentationTypeNameResolver(conjureDef.types(), importProviders, externalTypes);
        allDefinitions.putAll(parseObjects(conjureDef.types(), importTypeResolver));
        allDefinitions.putAll(innerParseImportObjects(conjureDef.types().conjureImports(), externalTypes, loadedFiles));
    });
    return allDefinitions;
}
Also used : TypeName(com.palantir.conjure.spec.TypeName) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) ConjureSourceFile(com.palantir.conjure.parser.ConjureSourceFile) ReferenceTypeResolver(com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver) HashMap(java.util.HashMap) AnnotatedConjureSourceFile(com.palantir.conjure.parser.AnnotatedConjureSourceFile) PathString(com.palantir.conjure.parser.services.PathString) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) Namespace(com.palantir.conjure.parser.types.names.Namespace) ErrorNamespace(com.palantir.conjure.spec.ErrorNamespace) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Aggregations

ReferenceTypeResolver (com.palantir.conjure.defs.ConjureTypeParserVisitor.ReferenceTypeResolver)1 AnnotatedConjureSourceFile (com.palantir.conjure.parser.AnnotatedConjureSourceFile)1 ConjureSourceFile (com.palantir.conjure.parser.ConjureSourceFile)1 PathString (com.palantir.conjure.parser.services.PathString)1 Namespace (com.palantir.conjure.parser.types.names.Namespace)1 ErrorNamespace (com.palantir.conjure.spec.ErrorNamespace)1 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)1 TypeName (com.palantir.conjure.spec.TypeName)1 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)1 HashMap (java.util.HashMap)1