Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

…lines 1–55 unchanged (55 lines)
56
57 /** The type of {@code this} in the current scope. */
58 private final ObjectType thisType;
59
60 /** Whether this is a bottom scope for the purposes of type inference. */
61 private final boolean isBottom;
62
63
64 /** Stores info about a variable */
65 public static class Var implements StaticSlot<JSType> {
66 /** name */
67 final String name;
68
…lines 69–283 unchanged (215 lines)
284
285 /**
286 * A special subclass of Var used to distinguish "arguments" in the current
287 * scope.
288 */
289 // TODO(johnlenz): Include this the list of Vars for the scope.
290 // TODO(johnlenz): provide the type of "Arguments".
291
292
293
294
295 /**
296 * Creates a Scope given the parent Scope and the root node of the scope.
297 * @param parent The parent Scope. Cannot be null.
…lines 298–452 unchanged (155 lines)
453 }
454 }
455
456 /**
457 * Get a unique VAR object to represents "arguments" within this scope
458 */
459
460 /**
461 * Returns true if a variable is declared.
462 */
463 public boolean isDeclared(String name, boolean recurse) {
464 Scope scope = this;
465 if (scope.vars.containsKey(name))
…lines 466–502 unchanged (37 lines)

After

…lines 1–56 unchanged (56 lines)
57 /** The type of {@code this} in the current scope. */
58 private final ObjectType thisType;
59
60 /** Whether this is a bottom scope for the purposes of type inference. */
61 private final boolean isBottom;
62
63 private Var arguments;
64
65 /** Stores info about a variable */
66 public static class Var implements StaticSlot<JSType> {
67 /** name */
68 final String name;
69
…lines 70–284 unchanged (215 lines)
285
286 /**
287 * A special subclass of Var used to distinguish "arguments" in the current
288 * scope.
289 */
290 // TODO(johnlenz): Include this the list of Vars for the scope.
291 public static class Arguments extends Var {
292 Arguments(Scope scope) {
293 super(
294 false, // no inferred
295 "arguments", // always arguments
296 null, // no declaration node
297 // TODO(johnlenz): provide the type of "Arguments".
298 null, // no type info
299 scope,
300 -1, // no variable index
301 null, // input,
302 false, // not a define
303 null // no jsdoc
304 );
305 }
306
307 @Override public boolean equals(Object other) {
308 if (!(other instanceof Arguments)) {
309 return false;
310 }
311
312 Arguments otherVar = (Arguments) other;
313 return otherVar.scope.getRootNode() == scope.getRootNode();
314 }
315
316 @Override public int hashCode() {
317 return System.identityHashCode(this);
318 }
319 }
320
321 /**
322 * Creates a Scope given the parent Scope and the root node of the scope.
323 * @param parent The parent Scope. Cannot be null.
324 * @param rootNode Typically the FUNCTION node.
325 */
…lines 326–478 unchanged (153 lines)
479 }
480 }
481
482 /**
483 * Get a unique VAR object to represents "arguments" within this scope
484 */
485 public Var getArgumentsVar() {
486 if (arguments == null) {
487 arguments = new Arguments(this);
488 }
489 return arguments;
490 }
491
492 /**
493 * Returns true if a variable is declared.
494 */
495 public boolean isDeclared(String name, boolean recurse) {
496 Scope scope = this;
…lines 497–534 unchanged (38 lines)

Before

program
block_comment "/*\n * Copyright 2004 The Closure Compiler Authors.\n *\n * Lic"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
; ";"
import_declaration (+23 nodes collapsed)
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "base"
. "."
identifier "Preconditions"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "ErrorReporter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "JSDocInfo"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "Node"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "Token"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "FunctionType"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "JSType"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "ObjectType"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "StaticScope"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "StaticSlot"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Iterator"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "LinkedHashMap"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Map"
; ";"
block_comment "/**\n * Scope contains information about a variable scope in "...
class_declaration
modifiers
public "public"
class "class"
identifier "Scope"
super_interfaces
implements "implements"
type_list
generic_type
type_identifier "StaticScope"
type_arguments
< "<"
type_identifier "JSType"
> ">"
class_body
{ "{"
field_declaration (+29 nodes collapsed)
field_declaration
modifiers
private "private"
final "final"
type_identifier "Scope"
variable_declarator
identifier "parent"
; ";"
field_declaration
modifiers
private "private"
final "final"
integral_type
int "int"
variable_declarator
identifier "depth"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "Node"
variable_declarator
identifier "rootNode"
; ";"
block_comment "/** The type of {@code this} in the current scope. */"
field_declaration
modifiers
private "private"
final "final"
type_identifier "ObjectType"
variable_declarator
identifier "thisType"
; ";"
block_comment "/** Whether this is a bottom scope for the purposes of type "...
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "isBottom"
; ";"
block_comment "/** Stores info about a variable */"
class_declaration (+868 nodes collapsed)
block_comment "/**\n * A special subclass of Var used to distinguish \"argu"...
line_comment "// TODO(johnlenz): Include this the list of Vars for the sco"...
line_comment "// TODO(johnlenz): provide the type of \"Arguments\"."
block_comment "/**\n * Creates a Scope given the parent Scope and the root"...
constructor_declaration (+146 nodes collapsed)
block_comment "/**\n * Creates a global Scope.\n * @param rootNode Typic"...
constructor_declaration (+70 nodes collapsed)
block_comment "/**\n * Creates a empty Scope (bottom of the lattice).\n *"...
constructor_declaration (+60 nodes collapsed)
block_comment "/** The depth of the scope. The global scope has depth 0. */"
method_declaration
integral_type
int "int"
identifier "getDepth"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "depth"
; ";"
} "}"
block_comment "/** Whether this is the bottom of the lattice. */"
method_declaration
boolean_type "boolean"
identifier "isBottom"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "isBottom"
; ";"
} "}"
block_comment "/**\n * Gets the container node of the scope. This is typic"...
method_declaration
modifiers
public "public"
type_identifier "Node"
identifier "getRootNode"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "rootNode"
; ";"
} "}"
method_declaration
modifiers
public "public"
type_identifier "Scope"
identifier "getParent"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "parent"
; ";"
} "}"
method_declaration (+50 nodes collapsed)
method_declaration (+23 nodes collapsed)
block_comment "/**\n * Gets the type of {@code this} in the current scope."...
method_declaration
modifiers
public "public"
type_identifier "ObjectType"
identifier "getTypeOfThis"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "thisType"
; ";"
} "}"
block_comment "/**\n * Declares a variable whose type is inferred.\n *\n "...
method_declaration (+41 nodes collapsed)
block_comment "/**\n * Declares a variable.\n *\n * @param name name of "...
method_declaration (+153 nodes collapsed)
block_comment "/**\n * Undeclares a variable, to be used when the compiler"...
method_declaration (+64 nodes collapsed)
method_declaration (+28 nodes collapsed)
method_declaration (+30 nodes collapsed)
block_comment "/**\n * Returns the variable, may be null\n */"
method_declaration (+77 nodes collapsed)
block_comment "/**\n * Get a unique VAR object to represents \"arguments\" w"...
block_comment "/**\n * Returns true if a variable is declared.\n */"
method_declaration (+83 nodes collapsed)
block_comment "/**\n * Return an iterator over all of the variables declar"...
method_declaration (+32 nodes collapsed)
block_comment "/**\n * Returns number of variables in this scope\n */"
method_declaration (+22 nodes collapsed)
block_comment "/**\n * Returns whether this is the global scope.\n */"
method_declaration
modifiers
public "public"
boolean_type "boolean"
identifier "isGlobal"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
binary_expression
identifier "parent"
== "=="
null_literal "null"
; ";"
} "}"
block_comment "/**\n * Returns whether this is a local scope (i.e. not the"...
method_declaration (+21 nodes collapsed)
} "}"

After

program
block_comment "/*\n * Copyright 2004 The Closure Compiler Authors.\n *\n * Lic"...
package_declaration
package "package"
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "jscomp"
; ";"
import_declaration (+23 nodes collapsed)
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "common"
. "."
identifier "base"
. "."
identifier "Preconditions"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "ErrorReporter"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "JSDocInfo"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "Node"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "Token"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "FunctionType"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "JSType"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "ObjectType"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "StaticScope"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
scoped_identifier
identifier "com"
. "."
identifier "google"
. "."
identifier "javascript"
. "."
identifier "rhino"
. "."
identifier "jstype"
. "."
identifier "StaticSlot"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Iterator"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "LinkedHashMap"
; ";"
import_declaration
import "import"
scoped_identifier
scoped_identifier
identifier "java"
. "."
identifier "util"
. "."
identifier "Map"
; ";"
block_comment "/**\n * Scope contains information about a variable scope in "...
class_declaration
modifiers
public "public"
class "class"
identifier "Scope"
super_interfaces
implements "implements"
type_list
generic_type
type_identifier "StaticScope"
type_arguments
< "<"
type_identifier "JSType"
> ">"
class_body
{ "{"
field_declaration (+29 nodes collapsed)
field_declaration
modifiers
private "private"
final "final"
type_identifier "Scope"
variable_declarator
identifier "parent"
; ";"
field_declaration
modifiers
private "private"
final "final"
integral_type
int "int"
variable_declarator
identifier "depth"
; ";"
field_declaration
modifiers
private "private"
final "final"
type_identifier "Node"
variable_declarator
identifier "rootNode"
; ";"
block_comment "/** The type of {@code this} in the current scope. */"
field_declaration
modifiers
private "private"
final "final"
type_identifier "ObjectType"
variable_declarator
identifier "thisType"
; ";"
block_comment "/** Whether this is a bottom scope for the purposes of type "...
field_declaration
modifiers
private "private"
final "final"
boolean_type "boolean"
variable_declarator
identifier "isBottom"
; ";"
field_declaration
modifiers
private "private"
type_identifier "Var"
variable_declarator
identifier "arguments"
; ";"
block_comment "/** Stores info about a variable */"
class_declaration (+868 nodes collapsed)
block_comment "/**\n * A special subclass of Var used to distinguish \"argu"...
line_comment "// TODO(johnlenz): Include this the list of Vars for the sco"...
class_declaration
modifiers
public "public"
static "static"
class "class"
identifier "Arguments"
superclass
extends "extends"
type_identifier "Var"
class_body
{ "{"
constructor_declaration
identifier "Arguments"
formal_parameters
( "("
formal_parameter
type_identifier "Scope"
identifier "scope"
) ")"
constructor_body
{ "{"
explicit_constructor_invocation
super "super"
argument_list
( "("
false "false"
, ","
line_comment "// no inferred"
string_literal
" "\""
string_fragment "arguments"
" "\""
, ","
line_comment "// always arguments"
null_literal "null"
, ","
line_comment "// no declaration node"
line_comment "// TODO(johnlenz): provide the type of \"Arguments\"."
null_literal "null"
, ","
line_comment "// no type info"
identifier "scope"
, ","
unary_expression
- "-"
decimal_integer_literal "1"
, ","
line_comment "// no variable index"
null_literal "null"
, ","
line_comment "// input,"
false "false"
, ","
line_comment "// not a define"
null_literal "null"
line_comment "// no jsdoc"
) ")"
; ";"
} "}"
method_declaration
modifiers
marker_annotation
@ "@"
identifier "Override"
public "public"
boolean_type "boolean"
identifier "equals"
formal_parameters
( "("
formal_parameter
type_identifier "Object"
identifier "other"
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
unary_expression
! "!"
parenthesized_expression
( "("
instanceof_expression
identifier "other"
instanceof "instanceof"
type_identifier "Arguments"
) ")"
) ")"
block
{ "{"
return_statement
return "return"
false "false"
; ";"
} "}"
local_variable_declaration
type_identifier "Arguments"
variable_declarator
identifier "otherVar"
= "="
cast_expression
( "("
type_identifier "Arguments"
) ")"
identifier "other"
; ";"
return_statement
return "return"
binary_expression
method_invocation
field_access
identifier "otherVar"
. "."
identifier "scope"
. "."
identifier "getRootNode"
argument_list
( "("
) ")"
== "=="
method_invocation
identifier "scope"
. "."
identifier "getRootNode"
argument_list
( "("
) ")"
; ";"
} "}"
method_declaration
modifiers
marker_annotation
@ "@"
identifier "Override"
public "public"
integral_type
int "int"
identifier "hashCode"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
method_invocation
identifier "System"
. "."
identifier "identityHashCode"
argument_list
( "("
this "this"
) ")"
; ";"
} "}"
} "}"
block_comment "/**\n * Creates a Scope given the parent Scope and the root"...
constructor_declaration (+146 nodes collapsed)
block_comment "/**\n * Creates a global Scope.\n * @param rootNode Typic"...
constructor_declaration (+70 nodes collapsed)
block_comment "/**\n * Creates a empty Scope (bottom of the lattice).\n *"...
constructor_declaration (+60 nodes collapsed)
block_comment "/** The depth of the scope. The global scope has depth 0. */"
method_declaration
integral_type
int "int"
identifier "getDepth"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "depth"
; ";"
} "}"
block_comment "/** Whether this is the bottom of the lattice. */"
method_declaration
boolean_type "boolean"
identifier "isBottom"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "isBottom"
; ";"
} "}"
block_comment "/**\n * Gets the container node of the scope. This is typic"...
method_declaration
modifiers
public "public"
type_identifier "Node"
identifier "getRootNode"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "rootNode"
; ";"
} "}"
method_declaration
modifiers
public "public"
type_identifier "Scope"
identifier "getParent"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "parent"
; ";"
} "}"
method_declaration (+50 nodes collapsed)
method_declaration (+23 nodes collapsed)
block_comment "/**\n * Gets the type of {@code this} in the current scope."...
method_declaration
modifiers
public "public"
type_identifier "ObjectType"
identifier "getTypeOfThis"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
identifier "thisType"
; ";"
} "}"
block_comment "/**\n * Declares a variable whose type is inferred.\n *\n "...
method_declaration (+41 nodes collapsed)
block_comment "/**\n * Declares a variable.\n *\n * @param name name of "...
method_declaration (+153 nodes collapsed)
block_comment "/**\n * Undeclares a variable, to be used when the compiler"...
method_declaration (+64 nodes collapsed)
method_declaration (+28 nodes collapsed)
method_declaration (+30 nodes collapsed)
block_comment "/**\n * Returns the variable, may be null\n */"
method_declaration (+77 nodes collapsed)
block_comment "/**\n * Get a unique VAR object to represents \"arguments\" w"...
method_declaration
modifiers
public "public"
type_identifier "Var"
identifier "getArgumentsVar"
formal_parameters
( "("
) ")"
block
{ "{"
if_statement
if "if"
parenthesized_expression
( "("
binary_expression
identifier "arguments"
== "=="
null_literal "null"
) ")"
block
{ "{"
expression_statement
assignment_expression
identifier "arguments"
= "="
object_creation_expression
new "new"
type_identifier "Arguments"
argument_list
( "("
this "this"
) ")"
; ";"
} "}"
return_statement
return "return"
identifier "arguments"
; ";"
} "}"
block_comment "/**\n * Returns true if a variable is declared.\n */"
method_declaration (+83 nodes collapsed)
block_comment "/**\n * Return an iterator over all of the variables declar"...
method_declaration (+32 nodes collapsed)
block_comment "/**\n * Returns number of variables in this scope\n */"
method_declaration (+22 nodes collapsed)
block_comment "/**\n * Returns whether this is the global scope.\n */"
method_declaration
modifiers
public "public"
boolean_type "boolean"
identifier "isGlobal"
formal_parameters
( "("
) ")"
block
{ "{"
return_statement
return "return"
binary_expression
identifier "parent"
== "=="
null_literal "null"
; ";"
} "}"
block_comment "/**\n * Returns whether this is a local scope (i.e. not the"...
method_declaration (+21 nodes collapsed)
} "}"