Search in sources :

Example 1 with LiteralSegment

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()));
}
Also used : LiteralSegment(com.google.api.tools.framework.aspects.http.model.HttpAttribute.LiteralSegment) PathSegment(com.google.api.tools.framework.aspects.http.model.HttpAttribute.PathSegment)

Example 2 with LiteralSegment

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;
}
Also used : LiteralSegment(com.google.api.tools.framework.aspects.http.model.HttpAttribute.LiteralSegment) PathSegment(com.google.api.tools.framework.aspects.http.model.HttpAttribute.PathSegment) WildcardSegment(com.google.api.tools.framework.aspects.http.model.HttpAttribute.WildcardSegment)

Aggregations

LiteralSegment (com.google.api.tools.framework.aspects.http.model.HttpAttribute.LiteralSegment)2 PathSegment (com.google.api.tools.framework.aspects.http.model.HttpAttribute.PathSegment)2 WildcardSegment (com.google.api.tools.framework.aspects.http.model.HttpAttribute.WildcardSegment)1