<commit_before>/**
 * @license
 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
 * This code may only be used under the BSD style license found at
 * http://polymer.github.io/LICENSE.txt
 * The complete set of authors may be found at
 * http://polymer.github.io/AUTHORS.txt
 * The complete set of contributors may be found at
 * http://polymer.github.io/CONTRIBUTORS.txt
 * Code distributed by Google as part of the polymer project is also
 * subject to an additional IP rights grant found at
 * http://polymer.github.io/PATENTS.txt
 */

import * as dom5 from 'dom5';
import * as parse5 from 'parse5';

import {Descriptor, EventDescriptor, Property} from '../ast/ast';
import * as jsdoc from '../javascript/jsdoc';

import {FeatureDescriptor} from './feature-descriptor';
import {BehaviorDescriptor} from './behavior-descriptor';
import {FunctionDescriptor, PolymerElementDescriptor, PolymerProperty} from './element-descriptor';



/** Properties on element prototypes that are purely configuration. */
const ELEMENT_CONFIGURATION = [
  'attached', 'attributeChanged', 'beforeRegister', 'configure', 'constructor',
  'created', 'detached', 'enableCustomStyleProperties', 'extends',
  'hostAttributes', 'is', 'listeners', 'mixins', 'properties', 'ready',
  'registered'
];

/** Tags understood by the annotation process, to be removed during `clean`. */
const HANDLED_TAGS = [
  'param',
  'return',
  'type',
];

/**
 * Annotates Hydrolysis descriptors, processing any `desc` properties as JSDoc.
 *
 * You probably want to use a more specialized version of this, such as
 * `annotateElement`.
 *
 * Processed JSDoc values will be made available via the `jsdoc` property on a
 * descriptor node.
 *
 * @param {Object} descriptor The descriptor node to process.
 * @return {Object} The descriptor that was given.
 */
export function annotate(descriptor: Descriptor): Descriptor {
  if (!descriptor || descriptor.jsdoc)
    return descriptor;

  if (typeof descriptor.description === 'string') {
    descriptor.jsdoc = jsdoc.parseJsdoc(descriptor.description);
    // We want to present the normalized form of a descriptor.
    descriptor.jsdoc.orig = descriptor.description;
    descriptor.description = descriptor.jsdoc.description;
  }

  return descriptor;
}

/**
 * Annotates @event, @hero, & @demo tags
 */
export function annotateElementHeader(descriptor: PolymerElementDescriptor) {
  descriptor.demos = [];
  if (descriptor.jsdoc && descriptor.jsdoc.tags) {
    descriptor.jsdoc.tags.forEach(function(tag) {
      switch (tag.tag) {
        case 'demo':
          descriptor.demos.push({
            desc: tag.description || 'demo',
            path: tag.name || 'demo/index.html'
          });
          break;
      }
    });
  }
}

/**
 * Annotates behavior descriptor.
 * @param {Object} descriptor behavior descriptor
 * @return {Object} descriptor passed in as param
 */
export function annotateBehavior(descriptor: BehaviorDescriptor):
    BehaviorDescriptor {
  annotate(descriptor);
  annotateElementHeader(descriptor);

  return descriptor;
}

export interface PartialEvent {
  description: string;
  jsdoc: jsdoc.Annotation;
}
/**
 * Annotates event documentation
 */
export function annotateEvent(annotation: jsdoc.Annotation): EventDescriptor {
  const eventTag = jsdoc.getTag(annotation, 'event');
  const eventDescriptor: EventDescriptor = {
    name: (eventTag && eventTag.description) ?
        (eventTag.description || '').match(/^\S*/)[0] :
        'N/A',
    description: eventTag.description || annotation.description,
    jsdoc: annotation
  };

  const tags = (annotation && annotation.tags || []);
  // process @params
  eventDescriptor.params =
      tags.filter((tag) => tag.tag === 'param').map(function(param) {
        return {
          type: param.type || 'N/A',
          desc: param.description || '',
          name: param.name || 'N/A'
        };
      });
  // process @params<commit_msg>Remove unused interface<commit_after>/**
 * @license
 * Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
 * This code may only be used under the BSD style license found at
 * http://polymer.github.io/LICENSE.txt
 * The complete set of authors may be found at
 * http://polymer.github.io/AUTHORS.txt
 * The complete set of contributors may be found at
 * http://polymer.github.io/CONTRIBUTORS.txt
 * Code distributed by Google as part of the polymer project is also
 * subject to an additional IP rights grant found at
 * http://polymer.github.io/PATENTS.txt
 */

import * as dom5 from 'dom5';
import * as parse5 from 'parse5';

import {Descriptor, EventDescriptor, Property} from '../ast/ast';
import * as jsdoc from '../javascript/jsdoc';

import {BehaviorDescriptor} from './behavior-descriptor';
import {FunctionDescriptor, PolymerElementDescriptor, PolymerProperty} from './element-descriptor';
import {FeatureDescriptor} from './feature-descriptor';


/** Properties on element prototypes that are purely configuration. */
const ELEMENT_CONFIGURATION = [
  'attached', 'attributeChanged', 'beforeRegister', 'configure', 'constructor',
  'created', 'detached', 'enableCustomStyleProperties', 'extends',
  'hostAttributes', 'is', 'listeners', 'mixins', 'properties', 'ready',
  'registered'
];

/** Tags understood by the annotation process, to be removed during `clean`. */
const HANDLED_TAGS = [
  'param',
  'return',
  'type',
];

/**
 * Annotates Hydrolysis descriptors, processing any `desc` properties as JSDoc.
 *
 * You probably want to use a more specialized version of this, such as
 * `annotateElement`.
 *
 * Processed JSDoc values will be made available via the `jsdoc` property on a
 * descriptor node.
 *
 * @param {Object} descriptor The descriptor node to process.
 * @return {Object} The descriptor that was given.
 */
export function annotate(descriptor: Descriptor): Descriptor {
  if (!descriptor || descriptor.jsdoc)
    return descriptor;

  if (typeof descriptor.description === 'string') {
    descriptor.jsdoc = jsdoc.parseJsdoc(descriptor.description);
    // We want to present the normalized form of a descriptor.
    descriptor.jsdoc.orig = descriptor.description;
    descriptor.description = descriptor.jsdoc.description;
  }

  return descriptor;
}

/**
 * Annotates @event, @hero, & @demo tags
 */
export function annotateElementHeader(descriptor: PolymerElementDescriptor) {
  descriptor.demos = [];
  if (descriptor.jsdoc && descriptor.jsdoc.tags) {
    descriptor.jsdoc.tags.forEach(function(tag) {
      switch (tag.tag) {
        case 'demo':
          descriptor.demos.push({
            desc: tag.description || 'demo',
            path: tag.name || 'demo/index.html'
          });
          break;
      }
    });
  }
}

/**
 * Annotates behavior descriptor.
 * @param {Object} descriptor behavior descriptor
 * @return {Object} descriptor passed in as param
 */
export function annotateBehavior(descriptor: BehaviorDescriptor):
    BehaviorDescriptor {
  annotate(descriptor);
  annotateElementHeader(descriptor);

  return descriptor;
}

/**
 * Annotates event documentation
 */
export function annotateEvent(annotation: jsdoc.Annotation): EventDescriptor {
  const eventTag = jsdoc.getTag(annotation, 'event');
  const eventDescriptor: EventDescriptor = {
    name: (eventTag && eventTag.description) ?
        (eventTag.description || '').match(/^\S*/)[0] :
        'N/A',
    description: eventTag.description || annotation.description,
    jsdoc: annotation
  };

  const tags = (annotation && annotation.tags || []);
  // process @params
  eventDescriptor.params =
      tags.filter((tag) => tag.tag === 'param').map(function(param) {
        return {
          type: param.type || 'N/A',
          desc: param.description || '',
          name: param.name || 'N/A'
        };
      });
  // process @params
{'fraction_non_alphanumeric': 0.12546266751754945, 'fraction_numerical': 0.002297383535417996, 'mean_word_length': 3.664285714285714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3906342', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2112, 'n_words': 662}