Skip to content

Commit

Permalink
deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Kruszewski committed Jun 25, 2020
1 parent ee15309 commit dfef565
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static String parseConjurePackage(com.palantir.conjure.parser.types.names
public static String parsePackageOrElseThrow(
Optional<com.palantir.conjure.parser.types.names.ConjurePackage> conjurePackage,
Optional<String> defaultPackage) {
String packageName = conjurePackage.map(p -> p.name()).orElseGet(() ->
String packageName = conjurePackage.map(ConjurePackage::name).orElseGet(() ->
defaultPackage.orElseThrow(() -> new SafeIllegalArgumentException(
// TODO(rfink): Better errors: Can we provide context on where exactly no package was provided?
"Must provide default conjure package or "
Expand Down Expand Up @@ -296,7 +296,7 @@ static Map<TypeName, TypeDefinition> parseObjects(
static List<ErrorDefinition> parseErrors(
NamedTypesDefinition defs,
ConjureTypeParserVisitor.ReferenceTypeResolver typeResolver) {
Optional<String> defaultPackage = defs.defaultConjurePackage().map(p -> p.name());
Optional<String> defaultPackage = defs.defaultConjurePackage().map(ConjurePackage::name);
ImmutableList.Builder<ErrorDefinition> errorsBuidler = ImmutableList.builder();
errorsBuidler.addAll(defs.errors().entrySet().stream().map(entry -> {
TypeName typeName = TypeName.of(
Expand Down Expand Up @@ -427,14 +427,14 @@ private static ParameterType parseParameterType(
return ParameterType.body(BodyParameterType.of());
}
case HEADER:
String headerParamId = argumentDef.paramId().map(id -> id.name()).orElseGet(() -> argName.get());
String headerParamId = argumentDef.paramId().map(ParameterName::name).orElseGet(argName::get);
return ParameterType.header(HeaderParameterType.of(ParameterId.of(headerParamId)));
case PATH:
return ParameterType.path(PathParameterType.of());
case BODY:
return ParameterType.body(BodyParameterType.of());
case QUERY:
String queryParamId = argumentDef.paramId().map(id -> id.name()).orElseGet(() -> argName.get());
String queryParamId = argumentDef.paramId().map(ParameterName::name).orElseGet(argName::get);
return ParameterType.query(QueryParameterType.of(ParameterId.of(queryParamId)));
default:
throw new IllegalArgumentException("Unknown parameter type: " + argumentDef.paramType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public enum ConjureDefinitionValidator implements ConjureValidator<ConjureDefini
ILLEGAL_MAP_KEYS(new IllegalMapKeyValidator());

public static void validateAll(ConjureDefinition definition) {
for (ConjureValidator validator : values()) {
for (ConjureValidator<ConjureDefinition> validator : values()) {
validator.validate(definition);
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ private static void validateServiceDefinition(ServiceDefinition serviceDef,
endpoint.getArgs().stream()
.filter(arg -> recursivelyFindNestedOptionals(arg.getType(), definitionMap, false))
.findAny()
.ifPresent(arg -> {
.ifPresent(_arg -> {
throw new IllegalStateException(
"Illegal nested optionals found in one of the arguments of endpoint "
+ endpoint.getEndpointName().get());
Expand All @@ -211,7 +211,7 @@ private static void validateErrorDefinition(ErrorDefinition errorDef,
Stream.concat(errorDef.getSafeArgs().stream(), errorDef.getUnsafeArgs().stream())
.filter(arg -> recursivelyFindNestedOptionals(arg.getType(), definitionMap, false))
.findAny()
.ifPresent(arg -> {
.ifPresent(_arg -> {
throw new IllegalStateException(
"Illegal nested optionals found in one of arguments of error "
+ errorDef.getErrorName().getName());
Expand Down Expand Up @@ -239,7 +239,7 @@ public Void visitObject(ObjectDefinition _value) {
.filter(fieldDefinition ->
recursivelyFindNestedOptionals(fieldDefinition.getType(), definitionMap, false))
.findAny()
.ifPresent(found -> {
.ifPresent(_found -> {
throw new IllegalStateException("Illegal nested optionals found in object "
+ objectDefinition.getTypeName().getName());
});
Expand All @@ -253,7 +253,7 @@ public Void visitUnion(UnionDefinition _value) {
.filter(fieldDefinition ->
recursivelyFindNestedOptionals(fieldDefinition.getType(), definitionMap, false))
.findAny()
.ifPresent(found -> {
.ifPresent(_found -> {
throw new IllegalStateException("Illegal nested optionals found in union "
+ unionDefinition.getTypeName().getName());
});
Expand Down Expand Up @@ -311,7 +311,7 @@ private static void validateServiceDefinition(ServiceDefinition serviceDef,
endpoint.getArgs().stream()
.filter(arg -> recursivelyFindIllegalKeys(arg.getType(), definitionMap, false))
.findAny()
.ifPresent(arg -> {
.ifPresent(_arg -> {
throw new IllegalStateException(
"Illegal map key found in one of the arguments of endpoint "
+ endpoint.getEndpointName().get());
Expand All @@ -331,7 +331,7 @@ private static void validateErrorDefinition(ErrorDefinition errorDef,
Stream.concat(errorDef.getSafeArgs().stream(), errorDef.getUnsafeArgs().stream())
.filter(arg -> recursivelyFindIllegalKeys(arg.getType(), definitionMap, false))
.findAny()
.ifPresent(arg -> {
.ifPresent(_arg -> {
throw new IllegalStateException(
"Illegal map key found in one of arguments of error "
+ errorDef.getErrorName().getName());
Expand Down Expand Up @@ -359,7 +359,7 @@ public Void visitObject(ObjectDefinition _value) {
.filter(fieldDefinition -> recursivelyFindIllegalKeys(
fieldDefinition.getType(), definitionMap, false))
.findAny()
.ifPresent(found -> {
.ifPresent(_found -> {
throw new IllegalStateException(
"Illegal map key found in object "
+ objectDefinition.getTypeName().getName());
Expand All @@ -374,7 +374,7 @@ public Void visitUnion(UnionDefinition _value) {
.filter(fieldDefinition -> recursivelyFindIllegalKeys(
fieldDefinition.getType(), definitionMap, false))
.findAny()
.ifPresent(found -> {
.ifPresent(_found -> {
throw new IllegalStateException(
"Illegal map key found in union "
+ unionDefinition.getTypeName().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static void validateAll(EndpointDefinition definition, DealiasingTypeVisi
* Simplified constructor for validators that don't need to look at the context.
*/
EndpointDefinitionValidator(ConjureValidator<EndpointDefinition> validator) {
this.validator = (definition, dealiasingTypeVisitor) -> validator.validate(definition);
this.validator = (definition, _dealiasingTypeVisitor) -> validator.validate(definition);
}

EndpointDefinitionValidator(ConjureContextualValidator<EndpointDefinition> validator) {
Expand Down Expand Up @@ -110,7 +110,7 @@ public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealia

private static boolean validateType(Type input, DealiasingTypeVisitor dealiasingTypeVisitor) {
Optional<Type> dealiased = dealiasingTypeVisitor.dealias(input)
.fold(typeDefinition -> Optional.empty(), Optional::of);
.fold(_typeDefinition -> Optional.empty(), Optional::of);
// typeDef isn't binary
if (!dealiased.isPresent()) {
return true;
Expand Down Expand Up @@ -175,8 +175,8 @@ public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealia
.forEach(entry -> {
boolean isOptionalBinary = dealiasingTypeVisitor.dealias(entry.getType())
.fold(
typeDef -> false, // typeDef cannot resolve to optional<binary>
type -> isOptionalBinary(type));
_typeDef -> false, // typeDef cannot resolve to optional<binary>
NoOptionalBinaryBodyParamValidator::isOptionalBinary);
Preconditions.checkState(
!isOptionalBinary,
"Endpoint BODY argument must not be optional<binary> or alias thereof: %s",
Expand Down Expand Up @@ -356,7 +356,7 @@ public void validate(EndpointDefinition definition, DealiasingTypeVisitor dealia

private static boolean validateType(Type input, DealiasingTypeVisitor dealiasingTypeVisitor) {
Optional<Type> dealiased = dealiasingTypeVisitor.dealias(input)
.fold(typeDefinition -> Optional.empty(), Optional::of);
.fold(_typeDefinition -> Optional.empty(), Optional::of);
// typeDef isn't bearertoken
if (!dealiased.isPresent()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public final class FieldNameValidator {

private static final Logger log = LoggerFactory.getLogger(FieldName.class);
private static final Logger log = LoggerFactory.getLogger(FieldNameValidator.class);

private FieldNameValidator() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static final class UniquePathMethodsValidator implements ConjureValidato
@Override
public void validate(ServiceDefinition definition) {
Multimap<String, String> pathToEndpoints = ArrayListMultimap.create();
definition.getEndpoints().stream().forEach(entry -> {
definition.getEndpoints().forEach(entry -> {
String methodPath = entry.getHttpMethod().get() + " " + entry.getHttpPath().get();
// normalize all path parameter variables and regular expressions because all path args are treated
// as identical for comparisons (paths cannot differ only in the name/regular expression of a path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private TypeNameValidator() {}
private static final Pattern CUSTOM_TYPE_PATTERN = Pattern.compile("^[A-Z][a-z0-9]+([A-Z][a-z0-9]+)*$");

static final List<String> PRIMITIVE_TYPES = Lists.transform(
java.util.Arrays.asList(PrimitiveType.Value.values()), value -> value.name());
java.util.Arrays.asList(PrimitiveType.Value.values()), PrimitiveType.Value::name);

public static void validate(TypeName typeName) {
Preconditions.checkArgument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.palantir.parsec.Parsers;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public final class DefaultingDispatchingParser<T> implements Parser<T> {

Expand All @@ -43,7 +42,7 @@ public DefaultingDispatchingParser(Map<String, Parser<T>> parsers, Parser<String
this.map.putAll(parsers);
} else {
inputStringParser = Parsers.prefix(whitespaceParser, directiveParser);
for (Entry<String, Parser<T>> entry : parsers.entrySet()) {
for (Map.Entry<String, Parser<T>> entry : parsers.entrySet()) {
this.map.put(entry.getKey(), Parsers.prefix(whitespaceParser, entry.getValue()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.palantir.parsec.Parsers;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public final class DispatchingParser<T> implements Parser<T> {

Expand All @@ -45,7 +44,7 @@ public DispatchingParser(Map<String, Parser<T>> parsers, Parser<String> directiv
parserLookup.putAll(parsers);
} else {
inputStringParser = Parsers.prefix(whitespaceParser, directiveParser);
for (Entry<String, Parser<T>> entry : parsers.entrySet()) {
for (Map.Entry<String, Parser<T>> entry : parsers.entrySet()) {
parserLookup.put(entry.getKey(), Parsers.prefix(whitespaceParser, entry.getValue()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.SortedMap;
import org.immutables.value.Value;

@JsonDeserialize(as = ImmutableTestCaseDefinition.class)
Expand All @@ -30,8 +30,8 @@ public interface TestCaseDefinition {
String testCaseName();

@JsonProperty("negative")
Optional<SortedMap<String, NegativeCaseDefinition>> negative();
Optional<NavigableMap<String, NegativeCaseDefinition>> negative();

@JsonProperty("positive")
Optional<SortedMap<String, PositiveCaseDefinition>> positive();
Optional<NavigableMap<String, PositiveCaseDefinition>> positive();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
name = "conjure",
description = "CLI to generate Conjure IR from Conjure YML definitions.",
mixinStandardHelpOptions = true,
subcommands = { ConjureCli.CompileCommand.class })
subcommands = ConjureCli.CompileCommand.class)
public final class ConjureCli implements Runnable {
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
.registerModule(new Jdk8Module())
.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);

public static void main(String[] args) {
CommandLine.run(new ConjureCli(), args);
new CommandLine(new ConjureCli()).execute(args);
}

@Override
Expand Down Expand Up @@ -113,7 +113,8 @@ CliConfiguration getConfiguration() {

static Map<String, Object> parseExtensions(String extensions) {
try {
return OBJECT_MAPPER.readValue(extensions, new TypeReference<Map<String, Object>>() {});
return OBJECT_MAPPER.readValue(extensions, new TypeReference<Map<String, Object>>() {
});
} catch (IOException e) {
throw new SafeIllegalArgumentException("Failed to parse extensions", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void correctlyParseArguments() {
.outputIrFile(outputFile)
.putExtensions("foo", "bar")
.build();
ConjureCli.CompileCommand cmd = new CommandLine(new ConjureCli()).parse(args).get(1).getCommand();
ConjureCli.CompileCommand cmd = new CommandLine(new ConjureCli()).parseArgs(args).asCommandLineList().get(1).getCommand();
assertThat(cmd.getConfiguration()).isEqualTo(expectedConfiguration);
}

Expand Down Expand Up @@ -86,7 +86,7 @@ public void throwsWhenSubCommandIsNotCompile() {
"compiles",
folder.getRoot().getAbsolutePath(),
folder.getRoot().getAbsolutePath(),
};
};
assertThatThrownBy(() -> CommandLine.populateCommand(new ConjureCli(), args))
.isInstanceOf(PicocliException.class)
.hasMessageContaining("Unmatched arguments");
Expand Down

0 comments on commit dfef565

Please sign in to comment.