codemodels 0.2.5-java → 0.2.6-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db4711f37b0bf8dbdc6c9cc22e232312889dcd17
4
- data.tar.gz: 55535f102297a1c548586fb5016f9b27abcb7198
3
+ metadata.gz: f078cf79663958cdc1389096405686a03dff12fc
4
+ data.tar.gz: e7890ba70b6e10f9167feecb8ac24e8f43f7c3a2
5
5
  SHA512:
6
- metadata.gz: 60e734f24988aafcf5d07dc7524e74dfbc0010a37aab4ec32f38fa594afd4f60650eede7cd147c8bdede81e9dfb536ea4a5a00d81bd385950bd6a0b8216b9db4
7
- data.tar.gz: 8bd823ea12998d2bfaa51da2352c256c29936c75349273b49d608c85c40a8f84efbdbf16824fe0e7154516321f616cb94c924f9e95358836bdaef8cfdd536f98
6
+ metadata.gz: bdc1e5a07416951f7c2b21467e1a4c0f5d0dd376492288204226dbe8ebea9d64bc86ed78cf270b9320d39965ba43c211294c41c037e86fc1309bcb71655d0b57
7
+ data.tar.gz: 0d70721939e39ea3be3d2a2be7b36a0c473e045c73798d213f75b9286bae3b69bae521b8f5fa096cffb6e55d6f4519324c43ce370874445e110185993671a03a
data/README.md CHANGED
@@ -1,19 +1,21 @@
1
1
  codemodels
2
2
  ===========
3
3
 
4
- codemodels is a library to create and manipulate models. A serialization format (based on JSON) is defined.
4
+ codemodels is a library to represent and manipulate homogeneously Abstract Syntax Trees of different languages models.
5
5
 
6
- It is based on [RGen](http://github.com/mthiede/rgen) and it supportes the conversion of EMF models through [emf_jruby](http://github.com/ftomassetti/emf_jruby).
6
+ It is based on [RGen](http://github.com/mthiede/rgen) and [RGen-Ext](https://github.com/ftomassetti/rgen_ext).
7
7
 
8
8
  There are different gems which transform source code in models of the code. Currently they are:
9
- * [html-lightmodels](http://github.com/ftomassetti/html-lightmodels)
9
+ * [codemodels-html](http://github.com/ftomassetti/codemodels-html)
10
10
  * [codemodels-java](http://github.com/ftomassetti/codemodels-java)
11
- * [js-lightmodels](http://github.com/ftomassetti/js-lightmodels)
12
- * [properties-lightmodels](http://github.com/ftomassetti/properties-lightmodels)
11
+ * [codemodels-js](http://github.com/ftomassetti/codemodels-js)
12
+ * [codemodels-properties](http://github.com/ftomassetti/codemodels-properties)
13
13
  * [codemodels-ruby](http://github.com/ftomassetti/codemodels-ruby)
14
- * [xml-lightmodels](http://github.com/ftomassetti/xml-lightmodels)
14
+ * [codemodels-xml](http://github.com/ftomassetti/codemodels-xml)
15
15
 
16
- Therefore it can be used to perform analysis on different languages.
16
+ DSLs based on EMF are planned to by supported using [emf_jruby](http://github.com/ftomassetti/emf_jruby).
17
+
18
+ Codemodels can be used to perform analysis on different languages.
17
19
 
18
20
  Features
19
21
  ========
data/Rakefile CHANGED
@@ -1,9 +1,13 @@
1
- require "bundler/gem_tasks"
2
1
  require 'rake/testtask'
2
+ require 'rubygems/tasks'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'test'
6
6
  end
7
7
 
8
+ Gem::Tasks.new do |tasks|
9
+ tasks.console.command = 'jruby'
10
+ end
11
+
8
12
  desc "Run tests"
9
13
  task :default => :test
data/codemodels.gemspec CHANGED
@@ -21,9 +21,10 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency('json')
23
23
  s.add_dependency('rgen')
24
- s.add_dependency('rgen_ext')
24
+ s.add_dependency('rgen_ext','0.0.2')
25
25
 
26
- s.add_development_dependency "bundler", "1.3.5"
26
+ s.add_development_dependency "bundler"
27
27
  s.add_development_dependency "rake"
28
28
  s.add_development_dependency "simplecov"
29
+ s.add_development_dependency "rubygems-tasks"
29
30
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'codemodels/position'
2
3
 
3
4
  module CodeModels
@@ -60,6 +61,10 @@ class EmbeddedArtifact < AbstractArtifact
60
61
  @host_artifact.embedding_level+1
61
62
  end
62
63
 
64
+ def name
65
+ '<embedded>'
66
+ end
67
+
63
68
  end
64
69
 
65
70
  class FileArtifact < AbstractArtifact
@@ -102,6 +107,55 @@ class FileArtifact < AbstractArtifact
102
107
  def ==(other)
103
108
  self.eql?(other)
104
109
  end
110
+
111
+ def name
112
+ filename
113
+ end
114
+
115
+ end
116
+
117
+ class StringArtifact < AbstractArtifact
118
+ attr_reader :code
119
+
120
+ def initialize(code)
121
+ @code = code
122
+ end
123
+
124
+ def absolute_start
125
+ sp = SourcePoint.new
126
+ sp.line = 1
127
+ sp.column = 1
128
+ sp
129
+ end
130
+
131
+ def to_s
132
+ "<StringArtifact>"
133
+ end
134
+
135
+ def final_host
136
+ self
137
+ end
138
+
139
+ def embedded?
140
+ false
141
+ end
142
+
143
+ def embedding_level
144
+ 0
145
+ end
146
+
147
+ def eql?(other)
148
+ return false unless other.is_a?(StringArtifact)
149
+ self.code==other.code
150
+ end
151
+
152
+ def ==(other)
153
+ self.eql?(other)
154
+ end
155
+
156
+ def name
157
+ '<string>'
158
+ end
105
159
 
106
160
  end
107
161
 
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module CodeModels
2
3
 
3
4
  module ComparisonModule
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'rgen/metamodel_builder'
2
3
 
3
4
  module CodeModels
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module CodeModels
2
3
 
3
4
  @@languages = []
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'rgen/metamodel_builder'
2
3
  require 'rgen/ext'
3
4
  require 'codemodels/source_info'
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  require 'codemodels/serialization'
2
3
 
3
4
  module CodeModels
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  class Module
2
3
 
3
4
  def simple_name
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module CodeModels
2
3
 
3
4
  module NavigationExtensions
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ require 'codemodels/monkey_patching'
4
+
5
+ module CodeModels
6
+
7
+ class Parser
8
+
9
+ DEFAULT_INTERNAL_ENCODING = 'UTF-8'
10
+
11
+ attr_reader :internal_encoding
12
+
13
+ def initialize(internal_encoding=DEFAULT_INTERNAL_ENCODING)
14
+ @internal_encoding = internal_encoding
15
+ puts "WARN using an internal encoding different from the local encoding..." if "".encoding.name!=internal_encoding
16
+ end
17
+
18
+ def parse_artifact(artifact)
19
+ internal_parse_artifact(artifact)
20
+ end
21
+
22
+ def parse_file(path,file_encoding=nil)
23
+ file_encoding = internal_encoding unless file_encoding
24
+ code = IO.read(path,{ :encoding => file_encoding, :mode => 'rb'})
25
+ code = code.encode(internal_encoding)
26
+ artifact = FileArtifact.new(path,code)
27
+ internal_parse_artifact(artifact)
28
+ end
29
+
30
+ # Deprecated: use parse_string
31
+ def parse_code(code)
32
+ parse_string(code)
33
+ end
34
+
35
+ def parse_string(code)
36
+ raise "Wrong encoding: it is #{code.encoding.name}, internally expected #{internal_encoding}" unless code.encoding.name==internal_encoding
37
+ artifact = StringArtifact.new(code)
38
+ internal_parse_artifact(artifact)
39
+ end
40
+
41
+ end
42
+
43
+ class ParsingError < Exception
44
+ attr_reader :node
45
+ attr_reader :line
46
+
47
+ def initialize(node,msg,line=nil)
48
+ @node = node
49
+ @msg = msg
50
+ @line = line
51
+ end
52
+
53
+ def to_s
54
+ "#{@msg}, start line: #{@line}"
55
+ end
56
+
57
+ end
58
+
59
+ # Most CodeModels parser are actually
60
+ # wrapping another parser and adapting it
61
+ # to CodeModels. When they encounter a node type
62
+ # they do not know how to wrap this error is thrown.
63
+ # This is not just for java based parsers, so it should
64
+ # be not moved to codemodels-javaparserwrapper
65
+ class UnknownNodeType < ParsingError
66
+
67
+ def initialize(node,line=nil,node_type=nil,where=nil)
68
+ super(node,"UnknownNodeType: type=#{node_type} , where: #{where}")
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module CodeModels
2
4
 
3
5
  class SourcePoint
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  # This code permit to transform AstNode in Hash objects
2
4
  # containing lists and single values
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rgen/metamodel_builder'
2
4
  require 'codemodels/language'
3
5
  require 'codemodels/position'
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module CodeModels
2
- VERSION = "0.2.5"
4
+ VERSION = "0.2.6"
3
5
  end
data/lib/codemodels.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  curr_dir = File.dirname(__FILE__)
2
4
 
3
5
  Dir["#{curr_dir}/codemodels/*.rb"].each { |rb| require rb }
@@ -0,0 +1 @@
1
+ F��e laiss� fen�tre
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ Füße laissé fenêtre Miško Minár ă î Timișoara
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class TestParser < Test::Unit::TestCase
5
+
6
+ module Metamodel
7
+
8
+ class SimpleText < CodeModels::CodeModelsAstNode
9
+ has_attr 'text', String
10
+ end
11
+ end
12
+
13
+ class SimpleTextParser < CodeModels::Parser
14
+
15
+ def internal_parse_artifact(artifact)
16
+ Metamodel::SimpleText.build(artifact.code)
17
+ end
18
+
19
+ end
20
+
21
+ def test_encoding
22
+ text1 = "Füße laissé fenêtre Miško Minár ă î Timișoara"
23
+ # ISO 8859-1 does not support all characters, so it is shorter
24
+ # then other examples
25
+ text2 = "Füße laissé fenêtre"
26
+
27
+ text_utf8 = SimpleTextParser.new.parse_file('test/data/text_utf8','UTF-8').text
28
+ text_utf16le = SimpleTextParser.new.parse_file('test/data/text_utf16LE','UTF-16LE').text
29
+ text_utf16be = SimpleTextParser.new.parse_file('test/data/text_utf16BE','UTF-16BE').text
30
+ text_iso8859_1 = SimpleTextParser.new.parse_file('test/data/text_iso_8859_1', 'ISO-8859-1').text
31
+
32
+ # ISO 8859 16 seems to be not fully supported in
33
+ # Ruby 1.9 and JRuby 1.7, while it is in Ruby 2.0
34
+ # This part of the test will be re-enabled later
35
+
36
+ #text_iso8859_16 = SimpleTextParser.new.parse_file('test/data/text_iso_8859_16','ISO-8859-16')
37
+
38
+ assert_equal text1,text_utf8
39
+ assert_equal text1,text_utf16le
40
+ assert_equal text1,text_utf16be
41
+ assert_equal text2,text_iso8859_1
42
+
43
+ #assert_equal text1,text_iso8859_16
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codemodels
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: java
6
6
  authors:
7
7
  - Federico Tomassetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-09 00:00:00.000000000 Z
11
+ date: 2014-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -42,28 +42,28 @@ dependencies:
42
42
  name: rgen_ext
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.0.2
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - '>='
50
+ - - '='
51
51
  - !ruby/object:Gem::Version
52
- version: '0'
52
+ version: 0.0.2
53
53
  prerelease: false
54
54
  type: :runtime
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.5
61
+ version: '0'
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - '='
64
+ - - '>='
65
65
  - !ruby/object:Gem::Version
66
- version: 1.3.5
66
+ version: '0'
67
67
  prerelease: false
68
68
  type: :development
69
69
  - !ruby/object:Gem::Dependency
@@ -94,6 +94,20 @@ dependencies:
94
94
  version: '0'
95
95
  prerelease: false
96
96
  type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubygems-tasks
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ prerelease: false
110
+ type: :development
97
111
  description: Library to build models of code of different languages in a uniform way.
98
112
  email: f.tomassetti@gmail.com
99
113
  executables: []
@@ -115,12 +129,17 @@ files:
115
129
  - lib/codemodels/model_building.rb
116
130
  - lib/codemodels/monkey_patching.rb
117
131
  - lib/codemodels/navigation.rb
118
- - lib/codemodels/parsing.rb
132
+ - lib/codemodels/parser.rb
119
133
  - lib/codemodels/position.rb
120
134
  - lib/codemodels/serialization.rb
121
135
  - lib/codemodels/source_info.rb
122
136
  - lib/codemodels/version.rb
123
137
  - test/data/node_setCompleted.json
138
+ - test/data/text_iso_8859_1
139
+ - test/data/text_iso_8859_16
140
+ - test/data/text_utf16BE
141
+ - test/data/text_utf16LE
142
+ - test/data/text_utf8
124
143
  - test/test_foreign_navigation.rb
125
144
  - test/test_helper.rb
126
145
  - test/test_info_extraction.rb
@@ -128,6 +147,7 @@ files:
128
147
  - test/test_metamodel.rb
129
148
  - test/test_model_building.rb
130
149
  - test/test_monkey_patching.rb
150
+ - test/test_parser.rb
131
151
  - test/test_rgen_ext.rb
132
152
  - test/test_serialization.rb
133
153
  - test/test_source_info.rb
@@ -151,12 +171,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
171
  version: '0'
152
172
  requirements: []
153
173
  rubyforge_project:
154
- rubygems_version: 2.1.9
174
+ rubygems_version: 2.2.0
155
175
  signing_key:
156
176
  specification_version: 4
157
177
  summary: Library to build models of code
158
178
  test_files:
159
179
  - test/data/node_setCompleted.json
180
+ - test/data/text_iso_8859_1
181
+ - test/data/text_iso_8859_16
182
+ - test/data/text_utf16BE
183
+ - test/data/text_utf16LE
184
+ - test/data/text_utf8
160
185
  - test/test_foreign_navigation.rb
161
186
  - test/test_helper.rb
162
187
  - test/test_info_extraction.rb
@@ -164,6 +189,7 @@ test_files:
164
189
  - test/test_metamodel.rb
165
190
  - test/test_model_building.rb
166
191
  - test/test_monkey_patching.rb
192
+ - test/test_parser.rb
167
193
  - test/test_rgen_ext.rb
168
194
  - test/test_serialization.rb
169
195
  - test/test_source_info.rb
@@ -1,37 +0,0 @@
1
- require 'codemodels/monkey_patching'
2
-
3
- module CodeModels
4
-
5
- class Parser
6
-
7
- def parse_file(path)
8
- parse_code(IO.read(path))
9
- end
10
-
11
- end
12
-
13
- class ParsingError < Exception
14
- attr_reader :node
15
- attr_reader :line
16
-
17
- def initialize(node,msg,line=nil)
18
- @node = node
19
- @msg = msg
20
- @line = line
21
- end
22
-
23
- def to_s
24
- "#{@msg}, start line: #{@line}"
25
- end
26
-
27
- end
28
-
29
- class UnknownNodeType < ParsingError
30
-
31
- def initialize(node,line=nil,node_type=nil,where=nil)
32
- super(node,"UnknownNodeType: type=#{node_type} , where: #{where}")
33
- end
34
-
35
- end
36
-
37
- end