All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.api.generator.gapic.model.MethodArgument Maven / Gradle / Ivy

There is a newer version: 2.50.0
Show newest version
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.generator.gapic.model;

import com.google.api.generator.engine.ast.TypeNode;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import java.util.List;

@AutoValue
public abstract class MethodArgument implements Comparable {
  // The method argument name.
  public abstract String name();

  // The type. This can be different from the associated field (e.g. for resource references).
  public abstract TypeNode type();

  // Additional metadata.
  public abstract Field field();

  // Records the path of nested fields in descending order, excluding type() (which would have
  // appeared as the last element).
  public abstract ImmutableList nestedFields();

  // Returns true if this is a resource name helper method argument.
  public abstract boolean isResourceNameHelper();

  @Override
  public int compareTo(MethodArgument other) {
    int compareVal = type().compareTo(other.type());
    if (compareVal == 0) {
      compareVal = name().compareTo(other.name());
    }
    return compareVal;
  }

  @Override
  public boolean equals(Object o) {
    if (!(o instanceof MethodArgument)) {
      return false;
    }

    MethodArgument other = (MethodArgument) o;
    return name().equals(other.name())
        && type().equals(other.type())
        && field().equals(other.field()) & nestedFields().equals(other.nestedFields())
        && isResourceNameHelper() == other.isResourceNameHelper();
  }

  @Override
  public int hashCode() {
    return 17 * name().hashCode()
        + 19 * type().hashCode()
        + 23 * field().hashCode()
        + 29 * nestedFields().hashCode()
        + (isResourceNameHelper() ? 1 : 0) * 31;
  }

  public static Builder builder() {
    return new AutoValue_MethodArgument.Builder()
        .setNestedFields(ImmutableList.of())
        .setIsResourceNameHelper(false);
  }

  @AutoValue.Builder
  public abstract static class Builder {
    public abstract Builder setName(String name);

    public abstract Builder setType(TypeNode type);

    public abstract Builder setField(Field field);

    public abstract Builder setNestedFields(List nestedFields);

    public abstract Builder setIsResourceNameHelper(boolean isResourceNameHelper);

    public abstract MethodArgument build();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy