<commit_before>package com.mysema.scalagen

import japa.parser.ast.BlockComment
import japa.parser.ast.CompilationUnit
import japa.parser.ast.ImportDeclaration
import japa.parser.ast.LineComment
import japa.parser.ast.Node
import japa.parser.ast.PackageDeclaration
import japa.parser.ast.TypeParameter
import japa.parser.ast.body._
import japa.parser.ast.expr._
import japa.parser.ast.stmt._
import japa.parser.ast.`type`.ClassOrInterfaceType
import japa.parser.ast.`type`.PrimitiveType
import japa.parser.ast.`type`.ReferenceType
import japa.parser.ast.`type`.Type
import japa.parser.ast.`type`.VoidType
import japa.parser.ast.`type`.WildcardType
import japa.parser.ast.visitor.GenericVisitor
import java.util.Collections

/**
 * 
 */
abstract class ModifierVisitor[A] extends GenericVisitor[Node, A] {
  
  protected def filter[T <: Node](node: T, arg: A): T = {
    if (node != null) node.accept(this, arg).asInstanceOf[T] else node
  } 
  
  protected def filter[T <: Node](list: JavaList[T], arg: A): JavaList[T]  = {
    if (list == null) {
      return null
    } else if (list.isEmpty) {
       Collections.emptyList[T]() 
    } else {
      list.map(_.accept(this, arg).asInstanceOf[T]).filter(_ != null)  
    }    
  }
  
  def visit(n: AnnotationDeclaration, arg: A) : Node = {
    val rv = new AnnotationDeclaration()
    rv.setAnnotations(filter(n.getAnnotations, arg))
    rv.setJavaDoc(filter(n.getJavaDoc, arg))    
    rv.setMembers(filter(n.getMembers, arg))
    rv.setModifiers(n.getModifiers)<commit_msg>#26 : improved equals handling<commit_after>package com.mysema.scalagen

import japa.parser.ast.BlockComment
import japa.parser.ast.CompilationUnit
import japa.parser.ast.ImportDeclaration
import japa.parser.ast.LineComment
import japa.parser.ast.Node
import japa.parser.ast.PackageDeclaration
import japa.parser.ast.TypeParameter
import japa.parser.ast.body._
import japa.parser.ast.expr._
import japa.parser.ast.stmt._
import japa.parser.ast.`type`.ClassOrInterfaceType
import japa.parser.ast.`type`.PrimitiveType
import japa.parser.ast.`type`.ReferenceType
import japa.parser.ast.`type`.Type
import japa.parser.ast.`type`.VoidType
import japa.parser.ast.`type`.WildcardType
import japa.parser.ast.visitor.GenericVisitor
import java.util.{ArrayList, Collections}

/**
 * 
 */
abstract class ModifierVisitor[A] extends GenericVisitor[Node, A] {
  
  protected def filter[T <: Node](node: T, arg: A): T = {
    if (node != null) node.accept(this, arg).asInstanceOf[T] else node
  } 
  
  protected def filter[T <: Node](list: JavaList[T], arg: A): JavaList[T]  = {
    if (list == null) {
      return null
    } else if (list.isEmpty) {
       Collections.emptyList[T]() 
    } else {
      // XXX this has too high overhead since it is twice converted (from and to java.util.List)
      //list.map(_.accept(this, arg).asInstanceOf[T]).filter(_ != null)
      val rv = new ArrayList[T](list.size)
      val it = list.iterator()
      while (it.hasNext) {
        val node = it.next().accept(this, arg).asInstanceOf[T]
        if (node != null) rv.add(node)
      }
      rv
    }    
  }
  
  def visit(n: AnnotationDeclaration, arg: A) : Node = {
    val rv = new AnnotationDeclaration()
    rv.setAnnotations(filter(n.getAnnotations, arg))
    rv.setJavaDoc(filter(n.getJavaDoc, arg))    
    rv.setMembers(filter(n.getMembers, arg))
    rv.setModifiers(n.getModifiers)
{'fraction_non_alphanumeric': 0.13246982631733883, 'fraction_numerical': 0.0005887547836326171, 'mean_word_length': 3.7926657263751764, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2276249', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1134, 'n_words': 230}