Sha256: 8e4752654cd19fe45a9ce0136b785571f42e02bfb5f7dd4d3f6352b9069418c8

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require 'codemodels'

module CodeModels
module Java

class << self
	include ParserWrapper
end

java_import 'japa.parser.JavaParser'
java_import 'java.io.FileInputStream'
java_import 'java.io.ByteArrayInputStream'

def self.containment_pos(node)
	container = node.eContainer
	children  = node.eContainer.send(node.eContainingFeature)
	if children.respond_to?(:each)
		children.each_with_index do |c,i|
			return i if c==node
		end
		raise "Not found"
	else
		raise "Not found" unless children==node
		0
	end
end

# node tree contains the original 
def self.corresponding_node(model_element,node_tree)
	return node_tree unless model_element.eContainer
	corresponding_parent_node = corresponding_node(model_element.eContainer,node_tree)
	containment_pos = containment_pos(model_element)
	containing_feat = model_element.eContainingFeature

	children = corresponding_parent_node.send(containing_feat)
	if children.respond_to?(:each)
		children[containment_pos]
	else
		children
	end
end

def self.node_tree_from_code(code)
	sis = ByteArrayInputStream.new(code.to_java_bytes)
	node_tree = JavaParser.parse(sis)
	sis.close
	node_tree
end

def self.corresponding_node_from_code(model_element,code)
	sis = ByteArrayInputStream.new(code.to_java_bytes)
	node_tree = JavaParser.parse(sis)
	sis.close
	corresponding_node(model_element,node_tree)
end

def self.parse_code(code)	
	node_to_model(node_tree_from_code(code))
end

class Parser < CodeModels::Parser

	def parse_code(code)
		CodeModels::Java.parse_code(code)
	end

end

DefaultParser = Parser.new

def self.parse_file(path)	
	DefaultParser.parse_file(path)
end

private

def self.adapter_specific_class(model_class,ref)
	return nil unless CodeModels::Java::PROP_ADAPTERS[model_class]
	CodeModels::Java::PROP_ADAPTERS[model_class][ref.name]
end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codemodels-java-0.2.0-java lib/codemodels/java/parser.rb