Tabnine Logo
Type
Code IndexAdd Tabnine to your IDE (free)

How to use
Type
in
com.palantir.conjure.spec

Best Java code snippets using com.palantir.conjure.spec.Type (Showing top 20 results out of 315)

origin: com.palantir.conjure/conjure-generator-common

@Override
public Either<TypeDefinition, Type> visitList(ListType value) {
  return Either.right(Type.list(value));
}
origin: com.palantir.conjure/conjure-generator-common

@Override
public Either<TypeDefinition, Type> visitMap(MapType value) {
  return Either.right(Type.map(value));
}
origin: palantir/conjure

@Override
public Either<TypeDefinition, Type> visitOptional(OptionalType value) {
  return Either.right(Type.optional(value));
}
origin: palantir/conjure

@Test
public void testRecursiveTypeOkInReference() {
  Type referenceType = Type.reference(FOO);
  TypeDefinition objectDefinition = TypeDefinition.object(
      ObjectDefinition.builder()
          .typeName(TypeName.of("Foo", "bar"))
          .addAllFields(ImmutableList.of(
              FieldDefinition.of(FieldName.of("selfOptional"),
                  Type.optional(OptionalType.of(Type.reference(FOO))), DOCS),
              FieldDefinition.of(FieldName.of("selfMap"),
                  Type.map(MapType.of(referenceType, referenceType)), DOCS),
              FieldDefinition.of(FieldName.of("selfSet"),
                  Type.set(SetType.of(referenceType)), DOCS),
              FieldDefinition.of(FieldName.of("selfList"),
                  Type.list(ListType.of(referenceType)), DOCS)))
          .build());
  ConjureDefinition conjureDef = ConjureDefinition.builder()
      .version(1)
      .types(ImmutableList.of(objectDefinition))
      .build();
  ConjureDefinitionValidator.NO_RECURSIVE_TYPES.validate(conjureDef);
}
origin: palantir/conjure

  @Test
  public void testNoComplexKeysInMaps() {
    String illegalFieldName = "asdf";
    Type complexKeyType = Type.list(ListType.of(Type.primitive(PrimitiveType.STRING)));
    FieldDefinition fieldDefinition = FieldDefinition.of(
        FieldName.of(illegalFieldName),
        Type.map(MapType.of(complexKeyType, Type.primitive(PrimitiveType.STRING))),
        Documentation.of("docs"));
    assertThatThrownBy(() -> FieldDefinitionValidator.validate(fieldDefinition))
        .isInstanceOf(IllegalStateException.class)
        .hasMessageContaining(illegalFieldName)
        .hasMessageContaining(complexKeyType.toString());
  }
}
origin: palantir/conjure

@Override
public Type visitAny(AnyType type) {
  return Type.primitive(com.palantir.conjure.spec.PrimitiveType.ANY);
}
origin: palantir/conjure

/**
 * Inlines outer-level aliases and references, but not within objects or container types.
 * <p>
 * For example, a reference to an alias A which wraps another alias B which wraps a {@code list<integer>}, we'll
 * return {@code list<integer>}. Note that these are outer-level references being resolved.
 * However, if the aforementioned list's inner type was also a reference e.g. {@code list<C>}, we
 * wouldn't unwrap that, so we'd just return the same {@code list<C>}.
 */
public Either<TypeDefinition, Type> dealias(Type type) {
  return type.accept(this);
}
origin: palantir/conjure

@Test
public void testComplexHeader() {
  EndpointDefinition.Builder definition = EndpointDefinition.builder()
      .args(ArgumentDefinition.builder()
          .argName(ArgumentName.of("someName"))
          .type(Type.list(ListType.builder().itemType(Type.primitive(PrimitiveType.STRING)).build()))
          .paramType(ParameterType.header(HeaderParameterType.of(ParameterId.of("someId"))))
          .build())
      .endpointName(ENDPOINT_NAME)
      .httpMethod(HttpMethod.GET)
      .httpPath(HttpPath.of("/a/path"));
  assertThatThrownBy(() -> EndpointDefinitionValidator.validateAll(definition.build(), emptyDealiasingVisitor))
      .isInstanceOf(IllegalStateException.class)
      .hasMessage("Header parameters must be enums, primitives, aliases or optional primitive:"
          + " \"someName\" is not allowed");
}
origin: com.palantir.conjure/conjure-generator-common

@Override
public Either<TypeDefinition, Type> visitSet(SetType value) {
  return Either.right(Type.set(value));
}
origin: palantir/conjure

  private static Type resolveFromTypeName(
      com.palantir.conjure.parser.types.names.TypeName name, TypesDefinition types) {
    Optional<String> defaultPackage =
        types.definitions().defaultConjurePackage().map(ConjureParserUtils::parseConjurePackage);
    BaseObjectTypeDefinition maybeDirectDef = types.definitions().objects().get(name);
    String conjurePackage;
    String typeName;
    if (maybeDirectDef == null) {
      ExternalTypeDefinition maybeExternalDef = types.imports().get(name);
      if (maybeExternalDef == null) {
        throw new IllegalStateException("Unknown LocalReferenceType: " + name);
      }
      String externalPath = maybeExternalDef.external().java();
      int lastIndex = externalPath.lastIndexOf(".");
      conjurePackage = externalPath.substring(0, lastIndex);
      typeName = externalPath.substring(lastIndex + 1);
      return Type.external(ExternalReference.builder()
          .externalReference(TypeName.of(typeName, conjurePackage))
          .fallback(ConjureParserUtils.parsePrimitiveType(maybeExternalDef.baseType()))
          .build());
    } else {
      // Conjure-defined object
      conjurePackage = ConjureParserUtils.parsePackageOrElseThrow(
          maybeDirectDef.conjurePackage(), defaultPackage);
      return Type.reference(TypeName.of(name.name(), conjurePackage));
    }
  }
}
origin: palantir/conjure

  private FieldDefinition field(FieldName name, String type) {
    return FieldDefinition.of(name, Type.reference(TypeName.of(type, PACKAGE)), DOCS);
  }
}
origin: palantir/conjure

  @Override
  public Type visitDateTime(DateTimeType type) {
    return Type.primitive(com.palantir.conjure.spec.PrimitiveType.DATETIME);
  }
}
origin: com.palantir.conjure/conjure-generator-common

/**
 * Inlines outer-level aliases and references, but not within objects or container types.
 * <p>
 * For example, a reference to an alias A which wraps another alias B which wraps a {@code list<integer>}, we'll
 * return {@code list<integer>}. Note that these are outer-level references being resolved.
 * However, if the aforementioned list's inner type was also a reference e.g. {@code list<C>}, we
 * wouldn't unwrap that, so we'd just return the same {@code list<C>}.
 */
public Either<TypeDefinition, Type> dealias(Type type) {
  return type.accept(this);
}
origin: palantir/conjure

@Override
public Either<TypeDefinition, Type> visitSet(SetType value) {
  return Either.right(Type.set(value));
}
origin: palantir/conjure

@Test
public void testNoSelfRecursiveType() {
  ConjureDefinition conjureDef = ConjureDefinition.builder()
      .version(1)
      .types(ImmutableList.of(TypeDefinition.object(
          ObjectDefinition.builder()
              .typeName(FOO)
              .fields(FieldDefinition.of(FieldName.of("self"), Type.reference(FOO), DOCS))
              .build())))
      .build();
  assertThatThrownBy(() -> ConjureDefinitionValidator.NO_RECURSIVE_TYPES.validate(conjureDef))
      .isInstanceOf(IllegalStateException.class)
      .hasMessage("Illegal recursive data type: Foo -> Foo");
}
origin: palantir/conjure

@Override
public Type visitBinary(BinaryType type) {
  return Type.primitive(com.palantir.conjure.spec.PrimitiveType.BINARY);
}
origin: palantir/conjure

private static Optional<TypeName> resolveReferenceType(Type type) {
  if (type.accept(TypeVisitor.IS_REFERENCE)) {
    return Optional.of(type.accept(TypeVisitor.REFERENCE));
  } else if (type.accept(TypeVisitor.IS_PRIMITIVE)) {
    return Optional.of(
        TypeName.of(type.accept(TypeVisitor.PRIMITIVE).get().name(), ""));
  }
  return Optional.empty();
}
origin: palantir/conjure

@Override
public Either<TypeDefinition, Type> visitList(ListType value) {
  return Either.right(Type.list(value));
}
origin: com.palantir.conjure/conjure-generator-common

@Override
public Either<TypeDefinition, Type> visitOptional(OptionalType value) {
  return Either.right(Type.optional(value));
}
origin: palantir/conjure

@Override
public Either<TypeDefinition, Type> visitMap(MapType value) {
  return Either.right(Type.map(value));
}
com.palantir.conjure.specType

Most used methods

  • list
  • map
  • optional
  • primitive
  • set
  • accept
  • reference
  • external
  • toString

Popular in Java

  • Start an intent from android
  • getResourceAsStream (ClassLoader)
  • getContentResolver (Context)
  • runOnUiThread (Activity)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now