Class: CIAT::Compilers::Java

Inherits:
Object
  • Object
show all
Includes:
Differs::HtmlDiffer, Processors::BasicProcessing
Defined in:
lib/ciat/compilers/java.rb

Overview

Implements a processor written in Java.

It requires source and compilation elements.

  • source is used as source to the Java compiler.

  • compilation is used for comparsion.

Best Practices

Suppose you use Eclipse to develop your compiler or interpreter, and you have this folder structure:

  • bin stores your compiled classes (under test)

  • lib contains support JAR files

  • acceptance is a root folder for your CIAT tests with your Rakefile

You may find this classpath useful:

Dir.glob('../lib/*.jar').join(':') + ":../bin"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Differs::HtmlDiffer

#diff_options, #html_diff

Methods included from Processors::BasicProcessing

#command_line_args, #diff, #error_file, #execute, #for_test, #input_file, #output_file, #process, #relevant_element_names, #relevant_elements

Constructor Details

#initialize(classpath, compiler_class, options = {}) ⇒ Java

Constructs a “Java compiler” object. classpath is the complete classpath to execute the compiler. compiler_class is the fully qualified name of the class that executes your compiler; this driver should take two command-line arguments: the name of the source file and the name of the generated target-code file.

Possible options:

  • description specifies a descriptive name for your compiler; used in the HTML report.



35
36
37
38
39
40
41
42
# File 'lib/ciat/compilers/java.rb', line 35

def initialize(classpath, compiler_class, options={})
  @processor_kind = options[:processor_kind] || CIAT::Processors::Compiler.new
  @classpath = classpath
  @compiler_class = compiler_class
  @descriptions = {}
  @description = options[:description] || "compiler (implemented in Java)"
  @light = options[:light] || TrafficLight.new
end

Instance Attribute Details

#lightObject

The traffic light to indicate the success or failure of the processor.



23
24
25
# File 'lib/ciat/compilers/java.rb', line 23

def light
  @light
end

#processor_kindObject (readonly)

Returns the value of attribute processor_kind.



24
25
26
# File 'lib/ciat/compilers/java.rb', line 24

def processor_kind
  @processor_kind
end

Instance Method Details

#describeObject

Return a description of the processor.



45
46
47
# File 'lib/ciat/compilers/java.rb', line 45

def describe
  @description
end

#executableObject



49
50
51
# File 'lib/ciat/compilers/java.rb', line 49

def executable
  "java -cp '#{@classpath}' #{@compiler_class}"
end