use of com.google.api.tools.framework.aspects.http.model.HttpAttribute.LiteralSegment in project toolkit by googleapis.
the class CollectionPattern method buildSimpleWildcardEntityName.
/**
* Builds the entity name for collection resource.
*
* <p>Does not handle singular resources or unbounded wildcards.
*
* @param pathSegments the full path containing the wildcard segment at wildcardIndex
* @param wildcardIndex the index of the wildcard segment
* @return the entity name for a collection resource
*/
private static String buildSimpleWildcardEntityName(List<PathSegment> pathSegments, int wildcardIndex) {
PathSegment wildcardSegment = pathSegments.get(wildcardIndex);
if (wildcardIndex == 0) {
return "unknown";
}
PathSegment prevSegment = pathSegments.get(wildcardIndex - 1);
if (!(prevSegment instanceof LiteralSegment)) {
return "unknown";
}
return LanguageUtil.upperCamelToLowerUnderscore(Inflector.singularize(prevSegment.syntax()));
}
use of com.google.api.tools.framework.aspects.http.model.HttpAttribute.LiteralSegment in project toolkit by googleapis.
the class CollectionPattern method isValidCollectionPattern.
private static boolean isValidCollectionPattern(FieldSegment fieldSegment) {
ImmutableList<PathSegment> subPath = fieldSegment.getSubPath();
if (subPath == null) {
return false;
}
if (subPath.size() <= 1) {
return false;
}
boolean containsLiteralWildcardPair = false;
PathSegment lastSegment = null;
for (PathSegment segment : subPath) {
if (segment instanceof WildcardSegment && lastSegment != null && lastSegment instanceof LiteralSegment) {
containsLiteralWildcardPair = true;
break;
}
lastSegment = segment;
}
if (!containsLiteralWildcardPair) {
return false;
}
return true;
}
Aggregations