Class: Norikra::Query::ASTLibFunctionNode

Inherits:
ASTNode
  • Object
show all
Defined in:
lib/norikra/query/ast.rb

Overview

LIB_FUNCTION

Instance Attribute Summary

Attributes inherited from ASTNode

#children, #name, #tree

Instance Method Summary collapse

Methods inherited from ASTNode

#child, #find, #initialize, #listup, #to_a

Constructor Details

This class inherits a constructor from Norikra::Query::ASTNode

Instance Method Details

#fields(default_target = nil, known_targets_aliases = []) ⇒ Object



1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
# File 'lib/norikra/query/ast.rb', line 1074

def fields(default_target=nil, known_targets_aliases=[])
  identifier = self.find("classIdentifier")

  return [] if identifier.nil? # built-in function call (no receivers exists)

  if identifier.children.size == 1 && Norikra::Query.imported_java_class?(identifier.find("escapableStr").child.name)
    # Java imported class name (ex: 'Math.abs(-1)')
    self.listup(:prop).map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
  else
    parts = identifier.listup('escapableStr').map{|node| node.child.name }
    target, fieldname = if parts.size == 1
                          [ default_target, parts.first ]
                        elsif known_targets_aliases.include?( parts.first )
                          [ parts[0], parts[1..-1].join(".") ]
                        else
                          [ default_target, parts.join(".") ]
                        end
    children_list = self.listup(:prop).map{|c| c.fields(default_target, known_targets_aliases)}.reduce(&:+) || []
    [{:f => fieldname, :t => target}] + children_list
  end
end

#nodetype?(*sym) ⇒ Boolean

escaped name access “‘T Table`.param.length()” [“libFunction”,

["libFunctionWithClass",
  ["classIdentifier",
    ["escapableStr", "`T Table`"],
    ".",
    ["escapableStr", "param"]],
  ".",
  ["funcIdentTop", ["escapableIdent", "length"]],
  "(",
  ")"]]

Returns:

  • (Boolean)


1070
1071
1072
# File 'lib/norikra/query/ast.rb', line 1070

def nodetype?(*sym)
  sym.include?(:lib) || sym.include?(:libfunc)
end