<commit_before>/*
 * Copyright 2006-2008 Web Cohesion
 *
 * 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.webcohesion.enunciate.modules.jackson.model;

import com.fasterxml.jackson.annotation.*;
import com.webcohesion.enunciate.EnunciateException;
import com.webcohesion.enunciate.facets.Facet;
import com.webcohesion.enunciate.facets.HasFacets;
import com.webcohesion.enunciate.javac.decorations.element.DecoratedElement;
import com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement;
import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement;
import com.webcohesion.enunciate.javac.decorations.element.PropertyElement;
import com.webcohesion.enunciate.metadata.ClientName;
import com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext;
import com.webcohesion.enunciate.modules.jackson.model.types.JsonType;

import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementFilter;
import java.util.*;

/**
 * A json type definition.
 *
 * @author <NAME>
 */
public abstract class TypeDefinition extends DecoratedTypeElement implements HasFacets {

  private final SortedSet<Member> members;
  private final Value value;
  private final WildcardMember wildcardMember;
  private final LinkedList<javax.lang.model.element.Element> referencedFrom = new LinkedList<javax.lang.model.element.Element>();
  private final Set<Facet> facets = new TreeSet<Facet>();
  protected final EnunciateJacksonContext context;

  protected TypeDefinition(TypeElement delegate, EnunciateJacksonContext context) {
    super(delegate, context.getContext().getProcessingEnvironment());

    MemberComparator comparator = new MemberComparator(getAnnotation(JsonPropertyOrder.class), env);
    SortedSet<Member> memberAccessors = new TreeSet<Member>(comparator);
    AccessorFilter filter = new AccessorFilter(getAnnotation(JsonAutoDetect.class), getAnnotation(JsonIgnoreProperties.class));
    Value value = null;

    WildcardMember wildcardMember = null;
    for (javax.lang.model.element.Element accessor : loadPotentialAccessors(filter)) {
      if (isValue(accessor)) {
        if (value != null) {
          throw new EnunciateException("Accessor " + accessor.getSimpleName() + " of " + getQualifiedName() + ": a type definition cannot have more than one json value.");
        }

        value = new Value(accessor, this, context);
      }
      else if (isWildcardProperty(accessor)) {
        wildcardMember = new WildcardMember(accessor, this, context);
      }
      else {
        //its an property accessor.

        if (accessor instanceof PropertyElement) {
          //if the accessor is a property and either the getter or setter overrides ANY method of ANY superclass, exclude it.
          if (overridesAnother(((PropertyElement) accessor).getGetter()) || overridesAnother(((PropertyElement) accessor).getSetter())) {
            continue;
          }
        }

        memberAccessors.add(new Member(accessor, this, context));
      }
    }

    this.members = Collections.unmodifiableSortedSet(memberAccessors);
    this.value = value;
    this.wildcardMember = wildcardMember;
    this.facets.addAll(Facet.gatherFacets(delegate));
    this.facets.addAll(Facet.gatherFacets(this.env.getElementUtils().getPackageOf(delegate)));
    this.context = context;
  }<commit_msg>support for @JsonIgnoreType<commit_after>/*
 * Copyright 2006-2008 Web Cohesion
 *
 * 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.webcohesion.enunciate.modules.jackson.model;

import com.fasterxml.jackson.annotation.*;
import com.webcohesion.enunciate.EnunciateException;
import com.webcohesion.enunciate.facets.Facet;
import com.webcohesion.enunciate.facets.HasFacets;
import com.webcohesion.enunciate.javac.decorations.element.DecoratedElement;
import com.webcohesion.enunciate.javac.decorations.element.DecoratedExecutableElement;
import com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement;
import com.webcohesion.enunciate.javac.decorations.element.PropertyElement;
import com.webcohesion.enunciate.metadata.ClientName;
import com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext;
import com.webcohesion.enunciate.modules.jackson.model.types.JsonType;

import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementFilter;
import java.util.*;

/**
 * A json type definition.
 *
 * @author <NAME>
 */
public abstract class TypeDefinition extends DecoratedTypeElement implements HasFacets {

  private final SortedSet<Member> members;
  private final Value value;
  private final WildcardMember wildcardMember;
  private final LinkedList<javax.lang.model.element.Element> referencedFrom = new LinkedList<javax.lang.model.element.Element>();
  private final Set<Facet> facets = new TreeSet<Facet>();
  protected final EnunciateJacksonContext context;

  protected TypeDefinition(TypeElement delegate, EnunciateJacksonContext context) {
    super(delegate, context.getContext().getProcessingEnvironment());

    MemberComparator comparator = new MemberComparator(getAnnotation(JsonPropertyOrder.class), env);
    SortedSet<Member> memberAccessors = new TreeSet<Member>(comparator);
    Value value = null;
    WildcardMember wildcardMember = null;
    JsonIgnoreType ignoreType = getAnnotation(JsonIgnoreType.class);
    if (ignoreType == null || !ignoreType.value()) {
      AccessorFilter filter = new AccessorFilter(getAnnotation(JsonAutoDetect.class), getAnnotation(JsonIgnoreProperties.class));
      value = null;

      wildcardMember = null;
      for (javax.lang.model.element.Element accessor : loadPotentialAccessors(filter)) {
        if (isValue(accessor)) {
          if (value != null) {
            throw new EnunciateException("Accessor " + accessor.getSimpleName() + " of " + getQualifiedName() + ": a type definition cannot have more than one json value.");
          }

          value = new Value(accessor, this, context);
        }
        else if (isWildcardProperty(accessor)) {
          wildcardMember = new WildcardMember(accessor, this, context);
        }
        else {
          //its an property accessor.

          if (accessor instanceof PropertyElement) {
            //if the accessor is a property and either the getter or setter overrides ANY method of ANY superclass, exclude it.
            if (overridesAnother(((PropertyElement) accessor).getGetter()) || overridesAnother(((PropertyElement) accessor).getSetter())) {
              continue;
            }
          }

          memberAccessors.add(new Member(accessor, this, context));
        }
      }
    }

    this.members = Collections.unmodifiableSortedSet(memberAccessors);
    this.value = value;
    this.wildcardMember = wildcardMember;
    this.facets.addAll(Facet.gatherFacets(delegate));
    this.facets.addAll(Facet.gatherFacets(this.env.getElementUtils().getPackageOf(delegate)));
    this.context = context;
  }
{'fraction_non_alphanumeric': 0.09486456673611962, 'fraction_numerical': 0.0029415369530579726, 'mean_word_length': 4.288399222294232, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1797949', 'n_tokens_mistral': 2294, 'n_tokens_neox': 2242, 'n_words': 561}