code
stringlengths 23
201k
| docstring
stringlengths 17
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
72
| path
stringlengths 11
317
| url
stringlengths 57
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
@Override
public Boolean visitDouble() {
return true;
}
|
Returns whether the type allows safety information.
|
visitDouble
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public Boolean visitSafelong() {
return true;
}
|
Returns whether the type allows safety information.
|
visitSafelong
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public Boolean visitBinary() {
return true;
}
|
Returns whether the type allows safety information.
|
visitBinary
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public Boolean visitAny() {
return true;
}
|
Returns whether the type allows safety information.
|
visitAny
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public Boolean visitBoolean() {
return true;
}
|
Returns whether the type allows safety information.
|
visitBoolean
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public Boolean visitUuid() {
return true;
}
|
Returns whether the type allows safety information.
|
visitUuid
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public Boolean visitRid() {
return true;
}
|
Returns whether the type allows safety information.
|
visitRid
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public Boolean visitBearertoken() {
return false;
}
|
Returns whether the type allows safety information.
|
visitBearertoken
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public Boolean visitUnknown(String unknownValue) {
throw new ConjureIllegalStateException("Unknown primitive type: " + unknownValue);
}
|
Returns whether the type allows safety information.
|
visitUnknown
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/SafetyValidator.java
|
Apache-2.0
|
@Override
public void validate(ServiceDefinition definition) {
Preconditions.checkState(
!definition.getServiceName().getName().endsWith(RETROFIT_SUFFIX),
"Service name must not end in %s: %s",
RETROFIT_SUFFIX,
definition.getServiceName().getName());
}
|
This ensures that ExperimentalFeatures.DisambiguateRetrofitServices won't cause collisions.
|
validate
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/ServiceDefinitionValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/ServiceDefinitionValidator.java
|
Apache-2.0
|
@Override
public void validate(Set<FieldName> args) {
Map<FieldName, FieldName> seenNormalizedToOriginal = new HashMap<>();
for (FieldName argName : args) {
FieldName normalizedName = FieldNameValidator.toCase(argName, CaseConverter.Case.LOWER_CAMEL_CASE);
FieldName seenName = seenNormalizedToOriginal.get(normalizedName);
Preconditions.checkArgument(
seenName == null,
"%s must not contain duplicate field names (modulo case normalization): %s vs %s",
classSimpleName,
argName.get(),
seenName == null ? "" : seenName.get());
seenNormalizedToOriginal.put(normalizedName, argName);
}
}
|
Verifies that field names are unique modulo normalization to
{@link CaseConverter.Case#LOWER_CAMEL_CASE lower camel case}.
|
validate
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/defs/validator/UniqueFieldNamesValidator.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/defs/validator/UniqueFieldNamesValidator.java
|
Apache-2.0
|
public static ConjureSourceFile parse(File file) {
CachingParser parser = new CachingParser();
return parser.parse(file);
}
|
Deserializes a {@link ConjureSourceFile} from its YAML representation in the given file.
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
Apache-2.0
|
public static Map<String, AnnotatedConjureSourceFile> parseAnnotated(File file) {
return parseAnnotated(ImmutableList.of(file));
}
|
Parse file {@literal &} all imports (breadth-first).
|
parseAnnotated
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
Apache-2.0
|
public static Map<String, AnnotatedConjureSourceFile> parseAnnotated(Collection<File> files) {
CachingParser parser = new CachingParser();
Map<String, AnnotatedConjureSourceFile> parsed = new HashMap<>();
Queue<FileWithProvenance> toProcess =
new ArrayDeque<>(files.stream().map(FileWithProvenance::of).collect(Collectors.toList()));
while (!toProcess.isEmpty()) {
FileWithProvenance nextFileWithProvenance = toProcess.poll();
File nextFile;
try {
nextFile = nextFileWithProvenance.file().getCanonicalFile();
} catch (IOException e) {
throw new SafeRuntimeException("Couldn't canonicalize file path", e);
}
String key = nextFile.getAbsolutePath();
if (!parsed.containsKey(key)) {
AnnotatedConjureSourceFile annotatedConjureSourceFile =
parseSingleFile(parser, nextFile, nextFileWithProvenance.importedFrom());
parsed.put(key, annotatedConjureSourceFile);
// Add all imports as files to be parsed
annotatedConjureSourceFile.importProviders().values().stream()
.map(File::new)
.forEach(file -> toProcess.add(FileWithProvenance.of(file, nextFile)));
}
}
return parsed;
}
|
Parse all files {@literal &} imports (breadth-first).
|
parseAnnotated
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
Apache-2.0
|
private static AnnotatedConjureSourceFile parseSingleFile(
CachingParser parser, File file, Optional<File> importedFrom) {
ConjureSourceFile parsed = parser.parse(file, importedFrom);
return AnnotatedConjureSourceFile.builder()
.conjureSourceFile(parsed)
.sourceFile(file)
// Hoist imports
.importProviders(parsed.types().conjureImports().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue()
.absoluteFile()
.orElseThrow(() -> new SafeIllegalStateException(
"Absolute file MUST be resolved as part of parsing stage"))
.getAbsolutePath())))
.build();
}
|
Parse all files {@literal &} imports (breadth-first).
|
parseSingleFile
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
Apache-2.0
|
ConjureSourceFile parse(File file) {
return parse(file, Optional.empty());
}
|
Parse all files {@literal &} imports (breadth-first).
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
Apache-2.0
|
ConjureSourceFile parse(File file, Optional<File> importedFrom) {
// HashMap.computeIfAbsent does not work with recursion; the size of the map gets corrupted,
// and if the map gets resized during the recursion, some of the new nodes can be put in wrong
// buckets. Therefore don't use computeIfAbsent in parse/parseInternal
// See https://bugs.java.com/view_bug.do?bug_id=JDK-8071667
ConjureSourceFile result = cache.get(file.getAbsolutePath());
if (result != null) {
return result;
}
result = parseInternal(file, importedFrom);
cache.put(file.getAbsolutePath(), result);
return result;
}
|
Parse all files {@literal &} imports (breadth-first).
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
Apache-2.0
|
private ConjureSourceFile parseInternal(File file, Optional<File> importedFrom) {
if (!Files.exists(file.toPath())) {
throw new ImportNotFoundException(file, importedFrom);
}
try {
ConjureSourceFile definition = MAPPER.readValue(file, ConjureSourceFile.class);
// For ease of book-keeping, resolve the import paths here
Path baseDir = file.toPath().getParent();
return ConjureSourceFile.builder()
.from(definition)
.types(TypesDefinition.builder()
.from(definition.types())
.conjureImports(definition.types().conjureImports().entrySet().stream()
.collect(Collectors.toMap(
Entry::getKey,
// Resolve absolute path to ensure we don't need to track this anymore
conjureImport ->
conjureImport.getValue().resolve(baseDir))))
.build())
.build();
} catch (IOException e) {
throw new ConjureRuntimeException(String.format("Error while parsing %s:", file), e);
}
}
|
Parse all files {@literal &} imports (breadth-first).
|
parseInternal
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
Apache-2.0
|
@VisibleForTesting
static ObjectMapper createConjureParserObjectMapper() {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory())
.registerModule(new Jdk8Module())
.setAnnotationIntrospector(AnnotationIntrospector.pair(
new KebabCaseEnforcingAnnotationInspector(), // needs to come first.
new JacksonAnnotationIntrospector()));
mapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION);
return mapper;
}
|
Parse all files {@literal &} imports (breadth-first).
|
createConjureParserObjectMapper
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/ConjureParser.java
|
Apache-2.0
|
static FileWithProvenance of(File file) {
return ImmutableFileWithProvenance.builder().file(file).build();
}
|
The conjure source file this file was imported from, if known.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/FileWithProvenance.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/FileWithProvenance.java
|
Apache-2.0
|
static FileWithProvenance of(File file, File importedFrom) {
return ImmutableFileWithProvenance.builder()
.file(file)
.importedFrom(importedFrom)
.build();
}
|
The conjure source file this file was imported from, if known.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/FileWithProvenance.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/FileWithProvenance.java
|
Apache-2.0
|
@Override
public Version version() {
return VersionUtil.parseVersion("0.0.1", "foo", "bar");
}
|
An {@link AnnotationIntrospector} that is no-op except for the
{@link AnnotationIntrospector#findNameForDeserialization(Annotated)}
method: verifies that any {@link JsonProperty} specified on the deserialization target stipulates {@code kebab-case}
JSON field names.
|
version
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/KebabCaseEnforcingAnnotationInspector.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/KebabCaseEnforcingAnnotationInspector.java
|
Apache-2.0
|
@Override
public PropertyName findNameForDeserialization(Annotated annotatedEntity) {
// This logic relies on the fact that Immutables generates setters annotated with @JsonProperty.
// It thus becomes obsolete whenever we move away from Immutables and the deserialization target no longer
// carries those annotations.
JsonProperty propertyAnnotation = _findAnnotation(annotatedEntity, JsonProperty.class);
if (propertyAnnotation != null) {
String jsonFieldName = propertyAnnotation.value();
Preconditions.checkArgument(
KEBAB_CASE_PATTERN.matcher(jsonFieldName).matches(),
"Conjure grammar requires kebab-case field names: %s",
jsonFieldName);
}
if (annotatedEntity instanceof AnnotatedMethod maybeSetter) {
if (maybeSetter.getName().startsWith("set")) {
// As a pre-caution, require that all setters have a JsonProperty annotation.
Preconditions.checkArgument(
_findAnnotation(annotatedEntity, JsonProperty.class) != null,
"All setter ({@code set*}) deserialization targets require @JsonProperty annotations: %s",
maybeSetter.getName());
}
}
return null; // delegate to the next introspector in an AnnotationIntrospectorPair.
}
|
An {@link AnnotationIntrospector} that is no-op except for the
{@link AnnotationIntrospector#findNameForDeserialization(Annotated)}
method: verifies that any {@link JsonProperty} specified on the deserialization target stipulates {@code kebab-case}
JSON field names.
|
findNameForDeserialization
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/KebabCaseEnforcingAnnotationInspector.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/KebabCaseEnforcingAnnotationInspector.java
|
Apache-2.0
|
public static ConjureDefinition normalize(ConjureDefinition input) {
return ConjureDefinition.builder()
.version(input.getVersion())
.types(sortTypeDefinitions(input.getTypes()))
.services(sortServiceDefinitions(input.getServices()))
.errors(sortErrorDefinitions(input.getErrors()))
.build();
}
|
Ensures the order of types, services and endpoints is sorted.
|
normalize
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/NormalizeDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/NormalizeDefinition.java
|
Apache-2.0
|
private static List<TypeDefinition> sortTypeDefinitions(List<TypeDefinition> types) {
return types.stream()
.sorted(Comparator.comparing(def -> def.accept(TypeDefinitionVisitor.TYPE_NAME), TYPE_NAME_COMPARATOR))
.collect(Collectors.toList());
}
|
Ensures the order of types, services and endpoints is sorted.
|
sortTypeDefinitions
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/NormalizeDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/NormalizeDefinition.java
|
Apache-2.0
|
private static List<ServiceDefinition> sortServiceDefinitions(List<ServiceDefinition> services) {
// we intentionally don't sort the Endpoints _within_ a ServiceDefinition, because we want to preserve
// the endpoint order that the API author wrote in their source.yml
return services.stream()
.sorted(Comparator.comparing(ServiceDefinition::getServiceName, TYPE_NAME_COMPARATOR))
.collect(Collectors.toList());
}
|
Ensures the order of types, services and endpoints is sorted.
|
sortServiceDefinitions
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/NormalizeDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/NormalizeDefinition.java
|
Apache-2.0
|
private static List<ErrorDefinition> sortErrorDefinitions(List<ErrorDefinition> errors) {
return errors.stream()
.sorted(Comparator.comparing(ErrorDefinition::getErrorName, TYPE_NAME_COMPARATOR))
.collect(Collectors.toList());
}
|
Ensures the order of types, services and endpoints is sorted.
|
sortErrorDefinitions
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/NormalizeDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/NormalizeDefinition.java
|
Apache-2.0
|
@JsonCreator
public static ParameterName of(String name) {
return ImmutableParameterName.builder().name(name).build();
}
|
Represents the name of an argument in an {@link EndpointDefinition}.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/ParameterName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/ParameterName.java
|
Apache-2.0
|
@Override
public final String toString() {
return name();
}
|
Represents the name of an argument in an {@link EndpointDefinition}.
|
toString
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/ParameterName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/ParameterName.java
|
Apache-2.0
|
public PathString resolve(PathString other) {
final Path newPath;
if (other.path().equals(Path.ROOT_PATH)) {
// special-case since Path#relativize() only works on proper prefixes
newPath = path();
} else {
newPath = path().resolve(Path.ROOT_PATH.relativize(other.path()));
}
return ImmutablePathString.builder().path(newPath).build();
}
|
Returns this path "concatenated" with the given other path. For example, {@code "/abc".resolve("/def")} is the
path {@code /abc/def}.
|
resolve
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/PathString.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/PathString.java
|
Apache-2.0
|
@JsonCreator
public static PathString of(String path) {
Path parsed = Paths.get(path);
return ImmutablePathString.builder().path(parsed).build();
}
|
Creates a new {@link PathString} from the given string, or throws an exception if it fails to validate.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/PathString.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/PathString.java
|
Apache-2.0
|
@Unsafe
@Override
public final String toString() {
return path().toString();
}
|
Creates a new {@link PathString} from the given string, or throws an exception if it fails to validate.
|
toString
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/PathString.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/PathString.java
|
Apache-2.0
|
@Deprecated
@JsonProperty("name")
@Value.Default
default String doNotUseName() {
return "";
}
|
Human-readable name of the service.
@deprecated unused and will be removed in the future
|
doNotUseName
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/ServiceDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/ServiceDefinition.java
|
Apache-2.0
|
@JsonProperty("default-auth")
@Value.Default
default AuthDefinition defaultAuth() {
return AuthDefinition.none();
}
|
Human-readable name of the service.
@deprecated unused and will be removed in the future
|
defaultAuth
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/ServiceDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/ServiceDefinition.java
|
Apache-2.0
|
@JsonProperty("base-path")
@Value.Default
default PathString basePath() {
return PathString.of("/");
}
|
Human-readable name of the service.
@deprecated unused and will be removed in the future
|
basePath
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/ServiceDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/ServiceDefinition.java
|
Apache-2.0
|
static Builder builder() {
return new Builder();
}
|
Human-readable name of the service.
@deprecated unused and will be removed in the future
|
builder
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/services/ServiceDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/services/ServiceDefinition.java
|
Apache-2.0
|
static ConjureType fromString(String value) throws ParseException {
return TypeParser.INSTANCE.parse(value);
}
|
A marker interface for the type system.
|
fromString
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/ConjureType.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/ConjureType.java
|
Apache-2.0
|
@Value.Default
default NamedTypesDefinition definitions() {
return NamedTypesDefinition.builder().build();
}
|
A list of Conjure definitions from which Conjure types are made available ("imported") for this Conjure
definition. For each import entry {@code <namespace>:<import-path>}, the Conjure compiler expects the existence
of a Conjure file {@code <import-path>} and makes each {@code <type>} imported from this Conjure definition
available as {@code <namespace>.<type>}.
|
definitions
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/TypesDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/TypesDefinition.java
|
Apache-2.0
|
static Builder builder() {
return new Builder();
}
|
A list of Conjure definitions from which Conjure types are made available ("imported") for this Conjure
definition. For each import entry {@code <namespace>:<import-path>}, the Conjure compiler expects the existence
of a Conjure file {@code <import-path>} and makes each {@code <type>} imported from this Conjure definition
available as {@code <namespace>.<type>}.
|
builder
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/TypesDefinition.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/TypesDefinition.java
|
Apache-2.0
|
@Value.Lazy
public List<String> components() {
return ImmutableList.copyOf(Splitter.on('.').split(name()));
}
|
Returns the components of the package, i.e. return {@code {abc, efg}} for package {@code abc.efg}.
|
components
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java
|
Apache-2.0
|
@Value.Check
protected final void check() {
// TODO(rfink): NPE when the pattern is static !?!?
@SuppressWarnings("for-rollout:ConstantPatternCompile")
Pattern validPackage = Pattern.compile("^([a-z][a-z0-9]+(\\.[a-z][a-z0-9]*)*)?$");
Preconditions.checkArgument(
validPackage.matcher(name()).matches(),
"Conjure package names must match pattern %s: %s",
validPackage.pattern(),
name());
}
|
Returns the components of the package, i.e. return {@code {abc, efg}} for package {@code abc.efg}.
|
check
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java
|
Apache-2.0
|
@JsonCreator
public static ConjurePackage of(String name) {
return ImmutableConjurePackage.builder().name(name).build();
}
|
Returns the components of the package, i.e. return {@code {abc, efg}} for package {@code abc.efg}.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java
|
Apache-2.0
|
public static ConjurePackage of(Iterable<String> components) {
return of(Joiner.on('.').join(components));
}
|
Returns the components of the package, i.e. return {@code {abc, efg}} for package {@code abc.efg}.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ConjurePackage.java
|
Apache-2.0
|
@Auxiliary
public final com.palantir.conjure.spec.ErrorCode asSpecErrorCode() {
return com.palantir.conjure.spec.ErrorCode.valueOf(name());
}
|
Represents the code of a conjure {@link ErrorTypeDefinition#code() error}. Must be the UpperCamel version of one of
the {@link com.palantir.conjure.spec.ErrorCode error codes}.
|
asSpecErrorCode
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java
|
Apache-2.0
|
@Value.Check
protected final void check() {
Preconditions.checkArgument(
VALID_ERROR_CODE_NAMES.contains(name()),
"Invalid error code %s. Must be one of: %s",
name(),
VALID_ERROR_CODE_NAMES);
}
|
Represents the code of a conjure {@link ErrorTypeDefinition#code() error}. Must be the UpperCamel version of one of
the {@link com.palantir.conjure.spec.ErrorCode error codes}.
|
check
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java
|
Apache-2.0
|
@JsonCreator
public static ErrorCode of(String name) {
return ImmutableErrorCode.builder().name(name).build();
}
|
Represents the code of a conjure {@link ErrorTypeDefinition#code() error}. Must be the UpperCamel version of one of
the {@link com.palantir.conjure.spec.ErrorCode error codes}.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorCode.java
|
Apache-2.0
|
@Value.Check
protected final void check() {
Preconditions.checkArgument(
UPPER_CAMEL_CASE.matcher(name()).matches(),
"Namespace for errors must match pattern %s: %s",
UPPER_CAMEL_CASE,
name());
}
|
Represents the namespace of a Conjure {@link ErrorTypeDefinition#code() error}.
|
check
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorNamespace.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorNamespace.java
|
Apache-2.0
|
@JsonCreator
public static ErrorNamespace of(String name) {
return ImmutableErrorNamespace.builder().name(name).build();
}
|
Represents the namespace of a Conjure {@link ErrorTypeDefinition#code() error}.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorNamespace.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/ErrorNamespace.java
|
Apache-2.0
|
@Value.Check
@SuppressWarnings("Slf4jLogsafeArgs")
protected final void check() {
CaseConverter.Case lowerCamelCase = CaseConverter.Case.LOWER_CAMEL_CASE;
CaseConverter.Case kebabCase = CaseConverter.Case.KEBAB_CASE;
CaseConverter.Case snakeCase = CaseConverter.Case.SNAKE_CASE;
boolean nameIsCamelCase = lowerCamelCase.getPattern().matches(name());
Preconditions.checkArgument(
nameIsCamelCase
|| kebabCase.getPattern().matches(name())
|| snakeCase.getPattern().matches(name()),
"FieldName \"%s\" must follow one of the following patterns: %s %s %s",
name(),
lowerCamelCase,
kebabCase,
snakeCase);
if (!nameIsCamelCase) {
log.warn(
"{} should be specified in lowerCamelCase. kebab-case and snake_case are supported for "
+ "legacy endpoints only: {}",
FieldName.class,
name());
}
}
|
Represents the name of an {@link ObjectTypeDefinition#fields() field} of an {@link ObjectTypeDefinition}.
|
check
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
Apache-2.0
|
@Value.Lazy
protected CaseConverter.Case nameCase() {
for (CaseConverter.Case nameCase : CaseConverter.Case.values()) {
if (nameCase.getPattern().matches(name())) {
return nameCase;
}
}
throw new IllegalStateException("Could not find case for FieldName, this is a bug: " + name());
}
|
Returns the case of this field name.
|
nameCase
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
Apache-2.0
|
@JsonCreator
public static FieldName of(String name) {
return ImmutableFieldName.builder().name(name).build();
}
|
Returns the case of this field name.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
Apache-2.0
|
public final FieldName toCase(CaseConverter.Case targetCase) {
return FieldName.of(nameCase().convertTo(this.name(), targetCase));
}
|
Converts this {@link FieldName} to a {@link FieldName} with the given case.
|
toCase
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
Apache-2.0
|
public final String capitalize() {
return StringUtils.capitalize(name());
}
|
Converts this {@link FieldName} to an upper camel case string (e.g. myVariant -> MyVariant).
Note that the resultant string is no longer a valid {@link FieldName}.
|
capitalize
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/FieldName.java
|
Apache-2.0
|
@Value.Check
protected final void check() {
Preconditions.checkArgument(
NAMESPACE_PATTERN.matcher(name()).matches(),
"Namespaces must match pattern %s: %s",
NAMESPACE_PATTERN,
name());
}
|
Represents the name of a namespace for conjure imports, cf. {@link TypesDefinition#conjureImports()}.
|
check
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Namespace.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Namespace.java
|
Apache-2.0
|
@JsonCreator
public static Namespace of(String name) {
return ImmutableNamespace.builder().name(name).build();
}
|
Represents the name of a namespace for conjure imports, cf. {@link TypesDefinition#conjureImports()}.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Namespace.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/Namespace.java
|
Apache-2.0
|
@Value.Check
protected final void check() {
Preconditions.checkArgument(
CUSTOM_TYPE_PATTERN.matcher(name()).matches() || PRIMITIVE_TYPES.contains(name()),
"TypeNames must be a primitive type %s or match pattern %s: %s",
PRIMITIVE_TYPES,
CUSTOM_TYPE_PATTERN,
name());
}
|
Represents the name of a conjure {@link NamedTypesDefinition#objects() object}.
|
check
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/TypeName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/TypeName.java
|
Apache-2.0
|
@JsonCreator
public static TypeName of(String name) {
return ImmutableTypeName.builder().name(name).build();
}
|
Represents the name of a conjure {@link NamedTypesDefinition#objects() object}.
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/names/TypeName.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/names/TypeName.java
|
Apache-2.0
|
@JsonCreator
static ConjureImports relativeFile(String file) {
return ImmutableConjureImports.builder().file(file).build();
}
|
The resolved file from which types are to be imported.
|
relativeFile
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/reference/ConjureImports.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/reference/ConjureImports.java
|
Apache-2.0
|
@Value.Auxiliary
@JsonIgnore
default ConjureImports resolve(Path baseDir) {
try {
return ImmutableConjureImports.builder()
.file(file())
.absoluteFile(baseDir.resolve(file()).toFile().getCanonicalFile())
.build();
} catch (IOException e) {
throw new SafeRuntimeException("Couldn't canonicalize file path", e);
}
}
|
The resolved file from which types are to be imported.
|
resolve
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/reference/ConjureImports.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/reference/ConjureImports.java
|
Apache-2.0
|
@Override
default <T> T visit(ConjureTypeVisitor<T> visitor) {
return visitor.visitLocalReference(this);
}
|
Represents a reference to a builtin type or a type defined local to the containing {@link ConjureSourceFile} (as
opposed to a {@link ForeignReferenceType} which references a type defined in an {@link
com.palantir.conjure.parser.types.TypesDefinition#conjureImports imported type}).
|
visit
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/reference/LocalReferenceType.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/reference/LocalReferenceType.java
|
Apache-2.0
|
static LocalReferenceType of(TypeName type) {
Optional<PrimitiveType> primitiveType = PrimitiveType.fromTypeName(type);
if (primitiveType.isPresent()) {
return primitiveType.get();
}
return ImmutableLocalReferenceType.builder().type(type).build();
}
|
Represents a reference to a builtin type or a type defined local to the containing {@link ConjureSourceFile} (as
opposed to a {@link ForeignReferenceType} which references a type defined in an {@link
com.palantir.conjure.parser.types.TypesDefinition#conjureImports imported type}).
|
of
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/conjure/parser/types/reference/LocalReferenceType.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/conjure/parser/types/reference/LocalReferenceType.java
|
Apache-2.0
|
public static <T> Parser<T> prefix(final Parser<?> prefix, final Parser<T> parser) {
return new Parser<T>() {
@Override
public T parse(ParserState input) throws ParseException {
prefix.parse(input);
return parser.parse(input);
}
@Override
public String description() {
return parser.description();
}
};
}
|
Runs the prefix parser, followed by the `parser`, returning result of the latter.
@param <T> the type the target parser returns
@param prefix a parser to consume some prefix
@param parser the target parser to run
@return the specified parser
|
prefix
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@Override
public T parse(ParserState input) throws ParseException {
prefix.parse(input);
return parser.parse(input);
}
|
Runs the prefix parser, followed by the `parser`, returning result of the latter.
@param <T> the type the target parser returns
@param prefix a parser to consume some prefix
@param parser the target parser to run
@return the specified parser
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@Override
public String description() {
return parser.description();
}
|
Runs the prefix parser, followed by the `parser`, returning result of the latter.
@param <T> the type the target parser returns
@param prefix a parser to consume some prefix
@param parser the target parser to run
@return the specified parser
|
description
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static Parser<String> whitespace() {
return WHITESPACE;
}
|
Returns a whitespace parser.
@return canonical whitespace parser
|
whitespace
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static <T> Parser<T> whitespace(Parser<T> parser) {
return prefix(whitespace(), parser);
}
|
Runs the whitespace parser followed by `parser`, returning result of the latter.
@param <T> the type the target parser returns
@param parser the target parser to run
@return the specified parser
|
whitespace
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static <T> Parser<T> gingerly(final Parser<T> parser) {
return new Parser<T>() {
@Override
public T parse(ParserState input) throws ParseException {
MarkedLocation mark = input.mark();
T result = parser.parse(input);
if (nullOrUnexpected(result)) {
mark.rewind();
}
return result;
}
@Override
public String description() {
return parser.description();
}
};
}
|
Attempts to parse using parser; if the parser returns null or is a expectant parser and returns false, then the
CompilerInput state is reset. Otherwise, the state remains unchanged.
@param <T> the type the target parser returns
@param parser the target parser to run
@return the specified parser
|
gingerly
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@Override
public T parse(ParserState input) throws ParseException {
MarkedLocation mark = input.mark();
T result = parser.parse(input);
if (nullOrUnexpected(result)) {
mark.rewind();
}
return result;
}
|
Attempts to parse using parser; if the parser returns null or is a expectant parser and returns false, then the
CompilerInput state is reset. Otherwise, the state remains unchanged.
@param <T> the type the target parser returns
@param parser the target parser to run
@return the specified parser
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@Override
public String description() {
return parser.description();
}
|
Attempts to parse using parser; if the parser returns null or is a expectant parser and returns false, then the
CompilerInput state is reset. Otherwise, the state remains unchanged.
@param <T> the type the target parser returns
@param parser the target parser to run
@return the specified parser
|
description
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@SafeVarargs
public static <T> Parser<T> or(
final String description,
final Parser<? extends T> firstOption,
final Parser<? extends T>... otherOptions) {
return new Parser<T>() {
@Override
public T parse(ParserState input) throws ParseException {
T result;
Exception exception = null;
MarkedLocation mark = input.mark();
try {
result = gingerly(firstOption).parse(input);
} catch (RuntimeException | ParseException e) {
exception = e;
mark.rewind();
result = null;
}
if (result != null) {
return result;
}
for (Parser<? extends T> nextOption : otherOptions) {
mark = input.mark();
try {
result = gingerly(nextOption).parse(input);
} catch (RuntimeException | ParseException e) {
if (exception == null) {
exception = e;
} else {
exception.addSuppressed(e);
}
mark.rewind();
}
if (result != null) {
return result;
}
}
if (exception != null) {
if (exception instanceof ParseException) {
throw (ParseException) exception;
}
throw new ParseException(exception.getMessage(), input, exception);
}
return null;
}
@Override
public String description() {
return description;
}
};
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
or
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@Override
public T parse(ParserState input) throws ParseException {
T result;
Exception exception = null;
MarkedLocation mark = input.mark();
try {
result = gingerly(firstOption).parse(input);
} catch (RuntimeException | ParseException e) {
exception = e;
mark.rewind();
result = null;
}
if (result != null) {
return result;
}
for (Parser<? extends T> nextOption : otherOptions) {
mark = input.mark();
try {
result = gingerly(nextOption).parse(input);
} catch (RuntimeException | ParseException e) {
if (exception == null) {
exception = e;
} else {
exception.addSuppressed(e);
}
mark.rewind();
}
if (result != null) {
return result;
}
}
if (exception != null) {
if (exception instanceof ParseException) {
throw (ParseException) exception;
}
throw new ParseException(exception.getMessage(), input, exception);
}
return null;
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@Override
public String description() {
return description;
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
description
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static ExpectantParser expect(String expectation) {
return new ExpectantParser(expectation);
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
expect
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static <T> BetweenParser<T> between(
ExpectantParser start, Parser<T> parser, ExpectantParser end, String description) {
return new BetweenParser<T>(start, parser, end, description);
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
between
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static <T> BetweenParser<T> between(String start, Parser<T> parser, String end, String description) {
return new BetweenParser<T>(expect(start), parser, expect(end), description);
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
between
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static <T> BetweenParser<T> liberalBetween(String start, Parser<T> parser, String end, String description) {
return new BetweenParser<T>(
whitespace(expect(start)), whitespace(parser), whitespace(expect(end)), description);
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
liberalBetween
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static <T> Parser<T> eof(Parser<T> parser) {
return new Parser<T>() {
@Override
public T parse(ParserState input) throws ParseException {
T result = parser.parse(input);
if (input.curr() != -1) {
return null;
}
return result;
}
@Override
public String description() {
return "end-of-file";
}
};
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
eof
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@Override
public T parse(ParserState input) throws ParseException {
T result = parser.parse(input);
if (input.curr() != -1) {
return null;
}
return result;
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
@Override
public String description() {
return "end-of-file";
}
|
Parse either firstOption or iterate through otherOptions and return result.
Exceptions are caught while trying options - if no options succeed, then the last exception thrown is re-thrown
as a {@code ParseError}.
@param <T> the type the parsers return
@param firstOption the first parser to try
@param otherOptions additional parsers to try
@return the specified parser
|
description
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static boolean nullOrUnexpected(Object obj) {
return obj == null || ExpectationResult.INCORRECT.equals(obj);
}
|
Returns true when the argument is null or is equal to {@link ExpectationResult#INCORRECT}.
@param obj object to compare
@return true when the argument is null or is equal to {@link ExpectationResult#INCORRECT}
|
nullOrUnexpected
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public static boolean nullOrEmpty(String string) {
return string == null || string.isEmpty();
}
|
Returns true when the argument is null or is a String and is empty.
@param string the string to test
@return true when {@code string} is null or empty
|
nullOrEmpty
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/Parsers.java
|
Apache-2.0
|
public void setDefaultParser(Parser<T> defaultParser) {
this.defaultParser = defaultParser;
}
|
Allows for graceful handling of unknown directives. Because the default parser will need to know what the
directive was, it will handle the entire line.
@param defaultParser the default parser to apply
|
setDefaultParser
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/DefaultingDispatchingParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/DefaultingDispatchingParser.java
|
Apache-2.0
|
@Override
public T parse(ParserState input) throws ParseException {
T lastResult = null;
while (input.curr() != -1) {
MarkedLocation mark = input.mark();
// Mark is now before directive.
// Gingerly will put its own mark at the exact same location.
String directive = Parsers.gingerly(inputStringParser).parse(input);
if (Parsers.nullOrEmpty(directive)) {
// If we get here, we couldn't parse a directive.
// Gingerly rewound to its mark; we should rewind too.
mark.rewind();
break;
} else {
// If we get here, directive was parsed okay.
if (map.containsKey(directive)) {
// Gingerly's mark is already released;
lastResult = map.get(directive).parse(input);
} else if (defaultParser != null) {
// If we don't recognize this directive, let the default parser try it.
// The default parser has to handle the entire line, so
// rewind to before the directive.
mark.rewind();
// lastResult = Parsers.gingerly(defaultParser).parse(input);
lastResult = defaultParser.parse(input);
// // Gingerly will have either released the mark or rewound to
// // it, so we don't need to do either. We can just handle the result.
// if (lastResult == null) {
// // We don't know what T is, so assume null is the only invalid return.
// return null;
// } else {
// return lastResult;
// }
} else {
throw new ParseException(
"Unknown directive '" + directive + "' and no default parser specified.", input);
}
}
}
// If we get here, either a dispatched parser or the default parser
// managed to run. Its result still might have been null, but that's
// not our problem.
return lastResult;
}
|
Allows for graceful handling of unknown directives. Because the default parser will need to know what the
directive was, it will handle the entire line.
@param defaultParser the default parser to apply
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/DefaultingDispatchingParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/DefaultingDispatchingParser.java
|
Apache-2.0
|
@Override
public String description() {
return description;
}
|
Allows for graceful handling of unknown directives. Because the default parser will need to know what the
directive was, it will handle the entire line.
@param defaultParser the default parser to apply
|
description
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/DefaultingDispatchingParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/DefaultingDispatchingParser.java
|
Apache-2.0
|
@Override
public String parse(ParserState input) {
StringBuilder sb = new StringBuilder();
int curr = input.curr();
boolean firstChar = true;
// not at end of the file and character is explicitly allowed
while (curr != -1 && condition.isAllowed((char) curr)) {
if (firstChar) {
if (condition.notAllowedToStartWith((char) curr)) {
return null;
}
firstChar = false;
}
sb.append((char) curr);
curr = input.next();
}
return sb.length() > 0 ? sb.toString() : null;
}
|
Parses a "raw" string where raw is specified by the supplied condition.
@param condition specifies the allowable characters in this string
|
parse
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
Apache-2.0
|
@Override
public String description() {
return "raw string";
}
|
Parses a "raw" string where raw is specified by the supplied condition.
@param condition specifies the allowable characters in this string
|
description
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
Apache-2.0
|
@Override
public String toString() {
return "RawStringParser(" + condition + ")";
}
|
Parses a "raw" string where raw is specified by the supplied condition.
@param condition specifies the allowable characters in this string
|
toString
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
Apache-2.0
|
default boolean notAllowedToStartWith(char _character) {
return false;
}
|
Parses a "raw" string where raw is specified by the supplied condition.
@param condition specifies the allowable characters in this string
|
notAllowedToStartWith
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
Apache-2.0
|
@Override
public boolean isAllowed(char character) {
return !Character.isWhitespace(character);
}
|
Parses a "raw" string where raw is specified by the supplied condition.
@param condition specifies the allowable characters in this string
|
isAllowed
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
Apache-2.0
|
@Override
public String getDescription() {
return "NO_WHITESPACE";
}
|
Parses a "raw" string where raw is specified by the supplied condition.
@param condition specifies the allowable characters in this string
|
getDescription
|
java
|
palantir/conjure
|
conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
https://github.com/palantir/conjure/blob/master/conjure-core/src/main/java/com/palantir/parsec/parsers/RawStringParser.java
|
Apache-2.0
|
public Either<TypeDefinition, Type> dealias(Type type) {
return type.accept(this);
}
|
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>}.
|
dealias
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitReference(TypeName value) {
TypeDefinition typeDefinition = objects.get(value);
Preconditions.checkState(
typeDefinition != null, "Referenced TypeDefinition not found in map of types for TypeName: %s", value);
return typeDefinition.accept(new TypeDefinition.Visitor<Either<TypeDefinition, Type>>() {
@Override
public Either<TypeDefinition, Type> visitAlias(AliasDefinition value) {
// Recursively visit target of alias
return value.getAlias().accept(DealiasingTypeVisitor.this);
}
@Override
public Either<TypeDefinition, Type> visitEnum(EnumDefinition value) {
return Either.left(TypeDefinition.enum_(value));
}
@Override
public Either<TypeDefinition, Type> visitObject(ObjectDefinition value) {
return Either.left(TypeDefinition.object(value));
}
@Override
public Either<TypeDefinition, Type> visitUnion(UnionDefinition value) {
return Either.left(TypeDefinition.union(value));
}
@Override
public Either<TypeDefinition, Type> visitUnknown(String unknownType) {
throw new IllegalStateException("Unsupported type: " + unknownType);
}
});
}
|
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>}.
|
visitReference
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitAlias(AliasDefinition value) {
// Recursively visit target of alias
return value.getAlias().accept(DealiasingTypeVisitor.this);
}
|
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>}.
|
visitAlias
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitEnum(EnumDefinition value) {
return Either.left(TypeDefinition.enum_(value));
}
|
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>}.
|
visitEnum
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitObject(ObjectDefinition value) {
return Either.left(TypeDefinition.object(value));
}
|
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>}.
|
visitObject
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitUnion(UnionDefinition value) {
return Either.left(TypeDefinition.union(value));
}
|
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>}.
|
visitUnion
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitUnknown(String unknownType) {
throw new IllegalStateException("Unsupported type: " + unknownType);
}
|
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>}.
|
visitUnknown
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitPrimitive(PrimitiveType value) {
return Either.right(Type.primitive(value));
}
|
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>}.
|
visitPrimitive
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitOptional(OptionalType value) {
return Either.right(Type.optional(value));
}
|
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>}.
|
visitOptional
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
@Override
public Either<TypeDefinition, Type> visitList(ListType value) {
return Either.right(Type.list(value));
}
|
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>}.
|
visitList
|
java
|
palantir/conjure
|
conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
https://github.com/palantir/conjure/blob/master/conjure-generator-common/src/main/java/com/palantir/conjure/visitor/DealiasingTypeVisitor.java
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.