<commit_before>#
# 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.
#

module Domgen
  module GwtRpc
    class GwtService < Domgen.ParentedElement(:service)

      def use_autobean_structs?
        service.data_module.facet_enabled?(:auto_bean)
      end

      attr_writer :xsrf_protected

      def xsrf_protected?
        @xsrf_protected.nil? ? false : @xsrf_protected
      end

      attr_writer :facade_service_name

      def facade_service_name
        @facade_service_name || service.imit? ? "GwtRpc#{service.name}" : service.name
      end

      def qualified_facade_service_name
        "#{service.data_module.gwt_rpc.client_service_package}.#{facade_service_name}"
      end

      def proxy_name
        "#{facade_service_name}Proxy"
      end

      def qualified_proxy_name
        "#{qualified_facade_service_name}Proxy"
      end

      attr_writer :rpc_service_name

      def rpc_service_name
        @rpc_service_name || "Gwt#{service.name}"
      end

      def qualified_service_name
        "#{service.data_module.gwt_rpc.shared_service_package}.#{rpc_service_name}"
      end

      def async_rpc_service_name
        "#{rpc_service_name}Async"
      end

      def qualified_async_rpc_service_name
        "#{service.data_module.gwt_rpc.shared_service_package}.#{async_rpc_service_name}"
      end

      def servlet_name
        @servlet_name || "#{rpc_service_name}Servlet"
      end

      def qualified_servlet_name
        "#{service.data_module.gwt_rpc.server_servlet_package}.#{servlet_name}"
      end
    end

    class GwtMethod < Domgen.ParentedElement(:method)
      def name
        Domgen::Naming.camelize(method.name)
      end

      attr_writer :cancelable

      def cancelable?
        @cancelable.nil? ? false : @cancelable
      end
    end

    class GwtModule < Domgen.ParentedElement(:data_module)
      include Domgen::Java::ClientServerJavaPackage

      attr_writer :server_servlet_package

      def server_servlet_package
        @server_servlet_package || "#{data_module.repository.gwt_rpc.server_servlet_package}.#{package_key}"
      end

      protected

      def facet_key
        :gwt
      end
    end

    class GwtReturn < Domgen.ParentedElement(:result)

      include Domgen::Java::ImitJavaCharacteristic

      protected

      def characteristic
        result
      end
    end

    class GwtParameter < Domgen.ParentedElement(:parameter)
      include Domgen::Java::ImitJavaCharacteristic

      # Does the parameter come from the environment?
      def environmental?
        !!@environment_key
      end

      attr_reader :environment_key

      def environment_key=(environment_key)
        raise "Unknown environment_key #{environment_key}" unless self.class.environment_key_set.include?(environment_key)
        @environment_key = environment_key
      end

      def environment_value
        raise "environment_value invoked for non-environmental value" unless environmental?
        self.class.environment_key_set[environment_key]
      end

      def self.environment_key_set
        {
          "request:session:id" => 'getThreadLocalRequest().getSession(true).getId()',
          "request:permutation-strong-name" => 'getPermutationStrongName()',
          "request:locale" => 'getThreadLocalRequest().getLocale().toString()',
          "request:remote-host" => 'getThreadLocalRequest().getRemoteHost()',
          "request:remote-address" => 'getThreadLocalRequest().getRemoteAddr()',
          "request:remote-port" => 'getThreadLocalRequest().getRemotePort()',
          "request:remote-user" => 'getThreadLocalRequest().getRemoteUser()',
        }
      end
      protected

      def characteristic
        parameter
      end
    end

    class GwtException < Domgen.ParentedElement(:exception)
      def name
        exception.name.to_s =~ /Exception$/ ? exception.name.to_s : "#{exception.name}Exception"
      end

      def qualified_name
        "#{exception.data_module.gwt_rpc.shared_data_type_package}.#{name}"
      end
    end

    class GwtApplication < Domgen.ParentedElement(:repository)
      include Domgen::Java::JavaClientServerApplication

      attr_writer :module_name

      def module_name
        @module_name || Domgen::Naming.underscore(repository.name)
      end

      attr_writer :rpc_services_module_name

      def rpc_services_module_name
        @rpc_services_module_name || "#{repository.name}GwtRpcServicesModule"
      end

      def qualified_rpc_services_module_name
        "#{client_ioc_package}.#{rpc_services_module_name}"
      end

      attr_writer :async_callback_name

      def async_callback_name
        @async_callback_name || "#{repository.name}AsyncCallback"
      end

      def qualified_async_callback_name
        "#{client_service_package}.#{async_callback_name}"
      end

      attr_writer :async_error_callback_name

      def async_error_callback_name
        @async_error_callback_name || "#{repository.name}AsyncErrorCallback"
      end

      def qualified_async_error_callback_name
        "#{client_service_package}.#{async_error_callback_name}"<commit_msg>Make sure callbacks are named with GwtRpc prefix<commit_after>#
# 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.
#

module Domgen
  module GwtRpc
    class GwtService < Domgen.ParentedElement(:service)

      def use_autobean_structs?
        service.data_module.facet_enabled?(:auto_bean)
      end

      attr_writer :xsrf_protected

      def xsrf_protected?
        @xsrf_protected.nil? ? false : @xsrf_protected
      end

      attr_writer :facade_service_name

      def facade_service_name
        @facade_service_name || service.imit? ? "GwtRpc#{service.name}" : service.name
      end

      def qualified_facade_service_name
        "#{service.data_module.gwt_rpc.client_service_package}.#{facade_service_name}"
      end

      def proxy_name
        "#{facade_service_name}Proxy"
      end

      def qualified_proxy_name
        "#{qualified_facade_service_name}Proxy"
      end

      attr_writer :rpc_service_name

      def rpc_service_name
        @rpc_service_name || "Gwt#{service.name}"
      end

      def qualified_service_name
        "#{service.data_module.gwt_rpc.shared_service_package}.#{rpc_service_name}"
      end

      def async_rpc_service_name
        "#{rpc_service_name}Async"
      end

      def qualified_async_rpc_service_name
        "#{service.data_module.gwt_rpc.shared_service_package}.#{async_rpc_service_name}"
      end

      def servlet_name
        @servlet_name || "#{rpc_service_name}Servlet"
      end

      def qualified_servlet_name
        "#{service.data_module.gwt_rpc.server_servlet_package}.#{servlet_name}"
      end
    end

    class GwtMethod < Domgen.ParentedElement(:method)
      def name
        Domgen::Naming.camelize(method.name)
      end

      attr_writer :cancelable

      def cancelable?
        @cancelable.nil? ? false : @cancelable
      end
    end

    class GwtModule < Domgen.ParentedElement(:data_module)
      include Domgen::Java::ClientServerJavaPackage

      attr_writer :server_servlet_package

      def server_servlet_package
        @server_servlet_package || "#{data_module.repository.gwt_rpc.server_servlet_package}.#{package_key}"
      end

      protected

      def facet_key
        :gwt
      end
    end

    class GwtReturn < Domgen.ParentedElement(:result)

      include Domgen::Java::ImitJavaCharacteristic

      protected

      def characteristic
        result
      end
    end

    class GwtParameter < Domgen.ParentedElement(:parameter)
      include Domgen::Java::ImitJavaCharacteristic

      # Does the parameter come from the environment?
      def environmental?
        !!@environment_key
      end

      attr_reader :environment_key

      def environment_key=(environment_key)
        raise "Unknown environment_key #{environment_key}" unless self.class.environment_key_set.include?(environment_key)
        @environment_key = environment_key
      end

      def environment_value
        raise "environment_value invoked for non-environmental value" unless environmental?
        self.class.environment_key_set[environment_key]
      end

      def self.environment_key_set
        {
          "request:session:id" => 'getThreadLocalRequest().getSession(true).getId()',
          "request:permutation-strong-name" => 'getPermutationStrongName()',
          "request:locale" => 'getThreadLocalRequest().getLocale().toString()',
          "request:remote-host" => 'getThreadLocalRequest().getRemoteHost()',
          "request:remote-address" => 'getThreadLocalRequest().getRemoteAddr()',
          "request:remote-port" => 'getThreadLocalRequest().getRemotePort()',
          "request:remote-user" => 'getThreadLocalRequest().getRemoteUser()',
        }
      end
      protected

      def characteristic
        parameter
      end
    end

    class GwtException < Domgen.ParentedElement(:exception)
      def name
        exception.name.to_s =~ /Exception$/ ? exception.name.to_s : "#{exception.name}Exception"
      end

      def qualified_name
        "#{exception.data_module.gwt_rpc.shared_data_type_package}.#{name}"
      end
    end

    class GwtApplication < Domgen.ParentedElement(:repository)
      include Domgen::Java::JavaClientServerApplication

      attr_writer :module_name

      def module_name
        @module_name || Domgen::Naming.underscore(repository.name)
      end

      attr_writer :rpc_services_module_name

      def rpc_services_module_name
        @rpc_services_module_name || "#{repository.name}GwtRpcServicesModule"
      end

      def qualified_rpc_services_module_name
        "#{client_ioc_package}.#{rpc_services_module_name}"
      end

      attr_writer :async_callback_name

      def async_callback_name
        @async_callback_name || "#{repository.name}GwtRpcAsyncCallback"
      end

      def qualified_async_callback_name
        "#{client_service_package}.#{async_callback_name}"
      end

      attr_writer :async_error_callback_name

      def async_error_callback_name
        @async_error_callback_name || "#{repository.name}GwtRpcAsyncErrorCallback"
      end

      def qualified_async_error_callback_name
        "#{client_service_package}.#{async_error_callback_name}"
{'fraction_non_alphanumeric': 0.08242295052846611, 'fraction_numerical': 0.0007105426769695354, 'mean_word_length': 3.085631349782293, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3683010', 'n_tokens_mistral': 3252, 'n_tokens_neox': 3191, 'n_words': 638}