Skip to content

Commit

Permalink
Turn @static into builtin Tag class.
Browse files Browse the repository at this point in the history
Lots of changes, but they're all pretty much the same - replacing
foo[:meta][:static] with foo[:static].
  • Loading branch information
nene committed Jan 3, 2013
1 parent ddc0097 commit 1339d1e
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/jsduck/ast.rb
Expand Up @@ -260,7 +260,7 @@ def make_statics(ast, defaults={})
s = make_property(name, value)
end

s[:meta] = {:static => true}
s[:static] = true
s.merge!(defaults)

statics << s if apply_autodetected(s, pair, defaults[:inheritable])
Expand Down
11 changes: 11 additions & 0 deletions lib/jsduck/builtins/static.rb
@@ -0,0 +1,11 @@
require "jsduck/builtins/boolean_tag"

module JsDuck::Builtins
class Static < BooleanTag
def initialize
@key = :static
@signature = {:long => "static", :short => "STA"}
super
end
end
end
6 changes: 3 additions & 3 deletions lib/jsduck/class.rb
Expand Up @@ -162,9 +162,9 @@ def find_members(query={})
end

if query[:static] == true
ms = ms.find_all {|m| m[:meta] && m[:meta][:static] }
ms = ms.find_all {|m| m[:static] }
elsif query[:static] == false
ms = ms.reject {|m| m[:meta] && m[:meta][:static] }
ms = ms.reject {|m| m[:static] }
end

ms
Expand All @@ -190,7 +190,7 @@ def all_local_members
def self.member_id(m)
# Sanitize $ in member names with something safer
name = m[:name].gsub(/\$/, 'S-')
"#{m[:meta][:static] ? 'static-' : ''}#{m[:tagname]}-#{name}"
"#{m[:static] ? 'static-' : ''}#{m[:tagname]}-#{name}"
end

# Loops through all available member types,
Expand Down
2 changes: 1 addition & 1 deletion lib/jsduck/inherit_doc.rb
Expand Up @@ -129,7 +129,7 @@ def lookup_member(cls, m)
inherit = m[:inheritdoc] || {}
name = inherit[:member] || m[:name]
tagname = inherit[:type] || m[:tagname]
static = inherit[:static] || m[:meta][:static]
static = inherit[:static] || m[:static]

if m[:autodetected]
# Auto-detected properties can override either a property or a
Expand Down
8 changes: 4 additions & 4 deletions lib/jsduck/inline/link.rb
Expand Up @@ -96,12 +96,12 @@ def apply_tpl(target, text, full_link)
# one when we ignore the static members. If there's more,
# report ambiguity. If there's only static members, also
# report ambiguity.
instance_ms = ms.find_all {|m| !m[:meta][:static] }
instance_ms = ms.find_all {|m| !m[:static] }
if instance_ms.length > 1
alternatives = instance_ms.map {|m| "#{m[:tagname]} in #{m[:owner]}" }.join(", ")
Logger.warn(:link_ambiguous, "#{full_link} is ambiguous: "+alternatives, file, line)
elsif instance_ms.length == 0
static_ms = ms.find_all {|m| m[:meta][:static] }
static_ms = ms.find_all {|m| m[:static] }
alternatives = static_ms.map {|m| "static " + m[:tagname].to_s }.join(", ")
Logger.warn(:link_ambiguous, "#{full_link} is ambiguous: "+alternatives, file, line)
end
Expand Down Expand Up @@ -210,8 +210,8 @@ def link(cls, member, anchor_text, type=nil, static=nil)
def get_matching_member(cls, query)
ms = find_members(cls, query)
if ms.length > 1
instance_ms = ms.find_all {|m| !m[:meta][:static] }
instance_ms.length > 0 ? instance_ms[0] : ms.find_all {|m| m[:meta][:static] }[0]
instance_ms = ms.find_all {|m| !m[:static] }
instance_ms.length > 0 ? instance_ms[0] : ms.find_all {|m| m[:static] }[0]
else
ms[0]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jsduck/lint.rb
Expand Up @@ -85,7 +85,7 @@ def warn_duplicate_members
@relations.each do |cls|
members = {:members => {}, :statics => {}}
cls.all_local_members.each do |m|
group = (m[:meta] && m[:meta][:static]) ? :statics : :members
group = m[:static] ? :statics : :members
type = m[:tagname]
name = m[:name]
hash = members[group][type] || {}
Expand Down
2 changes: 1 addition & 1 deletion lib/jsduck/members_index.rb
Expand Up @@ -43,7 +43,7 @@ def global_by_id
end

# Exclude all non-inheritable static members
@global_map_by_id.delete_if {|id, m| m[:meta][:static] && !m[:inheritable] }
@global_map_by_id.delete_if {|id, m| m[:static] && !m[:inheritable] }

merge!(@global_map_by_id, local_by_id)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jsduck/merger.rb
Expand Up @@ -90,7 +90,7 @@ def do_merge(docs, code, defaults={})
h[:id] = JsDuck::Class.member_id(h)

# Copy :static and :inheritable flags from code if present
h[:meta][:static] = true if code[:meta] && code[:meta][:static]
h[:static] = true if code[:static]
h[:inheritable] = true if code[:inheritable]

# Remember auto-detection info
Expand Down
14 changes: 0 additions & 14 deletions lib/jsduck/tag/static.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/aggregator_attributes_spec.rb
Expand Up @@ -34,7 +34,7 @@ def parse(string)
end

it "gets static attribute" do
@doc[:meta][:static].should == true
@doc[:static].should == true
end
end

Expand Down
14 changes: 7 additions & 7 deletions spec/aggregator_static_spec.rb
Expand Up @@ -20,7 +20,7 @@ def parse(string)
end

it "labels that method as static" do
@doc[:meta][:static].should == true
@doc[:static].should == true
end

it "doesn't detect inheritable property" do
Expand All @@ -41,7 +41,7 @@ def parse(string)
end

it "labels that method as static" do
@doc[:meta][:static].should == true
@doc[:static].should == true
end

it "detects the @inheritable property" do
Expand Down Expand Up @@ -93,7 +93,7 @@ def parse(string)
end

it "with :static flag" do
member[:meta][:static].should == true
member[:static].should == true
end

it "with :autodetected flag" do
Expand Down Expand Up @@ -135,7 +135,7 @@ def parse(string)
end

it "with :static flag" do
member[:meta][:static].should == true
member[:static].should == true
end

it "with docs" do
Expand Down Expand Up @@ -176,7 +176,7 @@ def parse(string)
end

it "with :static flag" do
member[:meta][:static].should == true
member[:static].should == true
end

it "with :inheritable flag" do
Expand Down Expand Up @@ -205,7 +205,7 @@ def parse(string)
end

it "detects a static" do
member[:meta][:static].should == true
member[:static].should == true
end

it "detects a method" do
Expand Down Expand Up @@ -236,7 +236,7 @@ def parse(string)
end

it "detects a static" do
member[:meta][:static].should == true
member[:static].should == true
end

it "detects a method" do
Expand Down
4 changes: 2 additions & 2 deletions spec/ast_statics_spec.rb
Expand Up @@ -32,7 +32,7 @@ def detect(string)
members[0][:name].should == "foo"
end
it "with :static flag" do
members[0][:meta][:static].should == true
members[0][:static].should == true
end
end

Expand All @@ -44,7 +44,7 @@ def detect(string)
members[1][:name].should == "bar"
end
it "with :static flag" do
members[1][:meta][:static].should == true
members[1][:static].should == true
end
end

Expand Down
1 change: 0 additions & 1 deletion spec/class_factory.rb
Expand Up @@ -10,7 +10,6 @@ def self.create(cfg)
m[:tagname] = :property unless m[:tagname]
m[:owner] = cfg[:name]
m[:meta] = {} unless m[:meta]
m[:meta][:static] = true if m[:static]
m[:id] = JsDuck::Class.member_id(m)
end

Expand Down
6 changes: 3 additions & 3 deletions spec/doc_formatter_spec.rb
Expand Up @@ -14,7 +14,7 @@
:members => [
{:tagname => :method, :name => "bar", :id => "method-bar"},
{:tagname => :method, :name => "id", :id => "static-method-id",
:meta => {:static => true}},
:static => true},
],
}),
JsDuck::Class.new({
Expand All @@ -25,7 +25,7 @@
:members => [
{:tagname => :cfg, :name => "bar", :id => "cfg-bar"},
{:tagname => :method, :name => "id", :id => "static-method-id",
:meta => {:static => true}},
:static => true},
{:tagname => :method, :name => "privMeth", :id => "method-privMeth", :private => true},
],
:alternateClassNames => ["FooBar"]
Expand Down Expand Up @@ -337,7 +337,7 @@
:members => [
{:tagname => :method, :name => "select", :id => "method-select", :meta => {}},
{:tagname => :method, :name => "select", :id => "static-method-select",
:meta => {:static => true}},
:static => true},
]
})
])
Expand Down

0 comments on commit 1339d1e

Please sign in to comment.