id int32 0 165k | repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 |
|---|---|---|---|---|---|---|---|---|---|---|---|
23,900 | google/closure-compiler | src/com/google/javascript/jscomp/AngularPass.java | AngularPass.createDependenciesList | private List<Node> createDependenciesList(Node n) {
checkArgument(n.isFunction());
Node params = NodeUtil.getFunctionParameters(n);
if (params != null) {
return createStringsFromParamList(params);
}
return new ArrayList<>();
} | java | private List<Node> createDependenciesList(Node n) {
checkArgument(n.isFunction());
Node params = NodeUtil.getFunctionParameters(n);
if (params != null) {
return createStringsFromParamList(params);
}
return new ArrayList<>();
} | [
"private",
"List",
"<",
"Node",
">",
"createDependenciesList",
"(",
"Node",
"n",
")",
"{",
"checkArgument",
"(",
"n",
".",
"isFunction",
"(",
")",
")",
";",
"Node",
"params",
"=",
"NodeUtil",
".",
"getFunctionParameters",
"(",
"n",
")",
";",
"if",
"(",
"params",
"!=",
"null",
")",
"{",
"return",
"createStringsFromParamList",
"(",
"params",
")",
";",
"}",
"return",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"}"
] | Given a FUNCTION node returns array of STRING nodes representing function
parameters.
@param n the FUNCTION node.
@return STRING nodes. | [
"Given",
"a",
"FUNCTION",
"node",
"returns",
"array",
"of",
"STRING",
"nodes",
"representing",
"function",
"parameters",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AngularPass.java#L168-L175 |
23,901 | google/closure-compiler | src/com/google/javascript/jscomp/AngularPass.java | AngularPass.createStringsFromParamList | private List<Node> createStringsFromParamList(Node params) {
Node param = params.getFirstChild();
ArrayList<Node> names = new ArrayList<>();
while (param != null) {
if (param.isName()) {
names.add(IR.string(param.getString()).srcref(param));
} else if (param.isDestructuringPattern()) {
compiler.report(JSError.make(param,
INJECTED_FUNCTION_HAS_DESTRUCTURED_PARAM));
return new ArrayList<>();
} else if (param.isDefaultValue()) {
compiler.report(JSError.make(param,
INJECTED_FUNCTION_HAS_DEFAULT_VALUE));
return new ArrayList<>();
}
param = param.getNext();
}
return names;
} | java | private List<Node> createStringsFromParamList(Node params) {
Node param = params.getFirstChild();
ArrayList<Node> names = new ArrayList<>();
while (param != null) {
if (param.isName()) {
names.add(IR.string(param.getString()).srcref(param));
} else if (param.isDestructuringPattern()) {
compiler.report(JSError.make(param,
INJECTED_FUNCTION_HAS_DESTRUCTURED_PARAM));
return new ArrayList<>();
} else if (param.isDefaultValue()) {
compiler.report(JSError.make(param,
INJECTED_FUNCTION_HAS_DEFAULT_VALUE));
return new ArrayList<>();
}
param = param.getNext();
}
return names;
} | [
"private",
"List",
"<",
"Node",
">",
"createStringsFromParamList",
"(",
"Node",
"params",
")",
"{",
"Node",
"param",
"=",
"params",
".",
"getFirstChild",
"(",
")",
";",
"ArrayList",
"<",
"Node",
">",
"names",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"while",
"(",
"param",
"!=",
"null",
")",
"{",
"if",
"(",
"param",
".",
"isName",
"(",
")",
")",
"{",
"names",
".",
"add",
"(",
"IR",
".",
"string",
"(",
"param",
".",
"getString",
"(",
")",
")",
".",
"srcref",
"(",
"param",
")",
")",
";",
"}",
"else",
"if",
"(",
"param",
".",
"isDestructuringPattern",
"(",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"param",
",",
"INJECTED_FUNCTION_HAS_DESTRUCTURED_PARAM",
")",
")",
";",
"return",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"}",
"else",
"if",
"(",
"param",
".",
"isDefaultValue",
"(",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"param",
",",
"INJECTED_FUNCTION_HAS_DEFAULT_VALUE",
")",
")",
";",
"return",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"}",
"param",
"=",
"param",
".",
"getNext",
"(",
")",
";",
"}",
"return",
"names",
";",
"}"
] | Given a PARAM_LIST node creates an array of corresponding STRING nodes.
@param params PARAM_LIST node.
@return array of STRING nodes. | [
"Given",
"a",
"PARAM_LIST",
"node",
"creates",
"an",
"array",
"of",
"corresponding",
"STRING",
"nodes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AngularPass.java#L182-L200 |
23,902 | google/closure-compiler | src/com/google/javascript/jscomp/AngularPass.java | AngularPass.addNode | private void addNode(Node n) {
Node target = null;
Node fn = null;
String name = null;
switch (n.getToken()) {
// handles assignment cases like:
// a = function() {}
// a = b = c = function() {}
case ASSIGN:
if (!n.getFirstChild().isQualifiedName()) {
compiler.report(JSError.make(n, INJECTED_FUNCTION_ON_NON_QNAME));
return;
}
name = n.getFirstChild().getQualifiedName();
// last node of chained assignment.
fn = n;
while (fn.isAssign()) {
fn = fn.getLastChild();
}
target = n.getParent();
break;
// handles function case:
// function fnName() {}
case FUNCTION:
name = NodeUtil.getName(n);
fn = n;
target = n;
if (n.getParent().isAssign()
&& n.getParent().getJSDocInfo().isNgInject()) {
// This is a function assigned into a symbol, e.g. a regular function
// declaration in a goog.module or goog.scope.
// Skip in this traversal, it is handled when visiting the assign.
return;
}
break;
// handles var declaration cases like:
// var a = function() {}
// var a = b = function() {}
case VAR:
case LET:
case CONST:
name = n.getFirstChild().getString();
// looks for a function node.
fn = getDeclarationRValue(n);
target = n;
break;
// handles class method case:
// class clName(){
// constructor(){}
// someMethod(){} <===
// }
case MEMBER_FUNCTION_DEF:
Node parent = n.getParent();
if (parent.isClassMembers()){
Node classNode = parent.getParent();
String midPart = n.isStaticMember() ? "." : ".prototype.";
name = NodeUtil.getName(classNode) + midPart + n.getString();
if (NodeUtil.isEs6ConstructorMemberFunctionDef(n)) {
name = NodeUtil.getName(classNode);
}
fn = n.getFirstChild();
if (classNode.getParent().isAssign() || classNode.getParent().isName()) {
target = classNode.getGrandparent();
} else {
target = classNode;
}
}
break;
default:
break;
}
if (fn == null || !fn.isFunction()) {
compiler.report(JSError.make(n, INJECT_NON_FUNCTION_ERROR));
return;
}
// report an error if the function declaration did not take place in a block or global scope
if (!target.getParent().isScript()
&& !target.getParent().isBlock()
&& !target.getParent().isModuleBody()) {
compiler.report(JSError.make(n, INJECT_IN_NON_GLOBAL_OR_BLOCK_ERROR));
return;
}
// checks that name is present, which must always be the case unless the
// compiler allowed a syntax error or a dangling anonymous function
// expression.
checkNotNull(name);
// registers the node.
injectables.add(new NodeContext(name, n, fn, target));
} | java | private void addNode(Node n) {
Node target = null;
Node fn = null;
String name = null;
switch (n.getToken()) {
// handles assignment cases like:
// a = function() {}
// a = b = c = function() {}
case ASSIGN:
if (!n.getFirstChild().isQualifiedName()) {
compiler.report(JSError.make(n, INJECTED_FUNCTION_ON_NON_QNAME));
return;
}
name = n.getFirstChild().getQualifiedName();
// last node of chained assignment.
fn = n;
while (fn.isAssign()) {
fn = fn.getLastChild();
}
target = n.getParent();
break;
// handles function case:
// function fnName() {}
case FUNCTION:
name = NodeUtil.getName(n);
fn = n;
target = n;
if (n.getParent().isAssign()
&& n.getParent().getJSDocInfo().isNgInject()) {
// This is a function assigned into a symbol, e.g. a regular function
// declaration in a goog.module or goog.scope.
// Skip in this traversal, it is handled when visiting the assign.
return;
}
break;
// handles var declaration cases like:
// var a = function() {}
// var a = b = function() {}
case VAR:
case LET:
case CONST:
name = n.getFirstChild().getString();
// looks for a function node.
fn = getDeclarationRValue(n);
target = n;
break;
// handles class method case:
// class clName(){
// constructor(){}
// someMethod(){} <===
// }
case MEMBER_FUNCTION_DEF:
Node parent = n.getParent();
if (parent.isClassMembers()){
Node classNode = parent.getParent();
String midPart = n.isStaticMember() ? "." : ".prototype.";
name = NodeUtil.getName(classNode) + midPart + n.getString();
if (NodeUtil.isEs6ConstructorMemberFunctionDef(n)) {
name = NodeUtil.getName(classNode);
}
fn = n.getFirstChild();
if (classNode.getParent().isAssign() || classNode.getParent().isName()) {
target = classNode.getGrandparent();
} else {
target = classNode;
}
}
break;
default:
break;
}
if (fn == null || !fn.isFunction()) {
compiler.report(JSError.make(n, INJECT_NON_FUNCTION_ERROR));
return;
}
// report an error if the function declaration did not take place in a block or global scope
if (!target.getParent().isScript()
&& !target.getParent().isBlock()
&& !target.getParent().isModuleBody()) {
compiler.report(JSError.make(n, INJECT_IN_NON_GLOBAL_OR_BLOCK_ERROR));
return;
}
// checks that name is present, which must always be the case unless the
// compiler allowed a syntax error or a dangling anonymous function
// expression.
checkNotNull(name);
// registers the node.
injectables.add(new NodeContext(name, n, fn, target));
} | [
"private",
"void",
"addNode",
"(",
"Node",
"n",
")",
"{",
"Node",
"target",
"=",
"null",
";",
"Node",
"fn",
"=",
"null",
";",
"String",
"name",
"=",
"null",
";",
"switch",
"(",
"n",
".",
"getToken",
"(",
")",
")",
"{",
"// handles assignment cases like:",
"// a = function() {}",
"// a = b = c = function() {}",
"case",
"ASSIGN",
":",
"if",
"(",
"!",
"n",
".",
"getFirstChild",
"(",
")",
".",
"isQualifiedName",
"(",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"INJECTED_FUNCTION_ON_NON_QNAME",
")",
")",
";",
"return",
";",
"}",
"name",
"=",
"n",
".",
"getFirstChild",
"(",
")",
".",
"getQualifiedName",
"(",
")",
";",
"// last node of chained assignment.",
"fn",
"=",
"n",
";",
"while",
"(",
"fn",
".",
"isAssign",
"(",
")",
")",
"{",
"fn",
"=",
"fn",
".",
"getLastChild",
"(",
")",
";",
"}",
"target",
"=",
"n",
".",
"getParent",
"(",
")",
";",
"break",
";",
"// handles function case:",
"// function fnName() {}",
"case",
"FUNCTION",
":",
"name",
"=",
"NodeUtil",
".",
"getName",
"(",
"n",
")",
";",
"fn",
"=",
"n",
";",
"target",
"=",
"n",
";",
"if",
"(",
"n",
".",
"getParent",
"(",
")",
".",
"isAssign",
"(",
")",
"&&",
"n",
".",
"getParent",
"(",
")",
".",
"getJSDocInfo",
"(",
")",
".",
"isNgInject",
"(",
")",
")",
"{",
"// This is a function assigned into a symbol, e.g. a regular function",
"// declaration in a goog.module or goog.scope.",
"// Skip in this traversal, it is handled when visiting the assign.",
"return",
";",
"}",
"break",
";",
"// handles var declaration cases like:",
"// var a = function() {}",
"// var a = b = function() {}",
"case",
"VAR",
":",
"case",
"LET",
":",
"case",
"CONST",
":",
"name",
"=",
"n",
".",
"getFirstChild",
"(",
")",
".",
"getString",
"(",
")",
";",
"// looks for a function node.",
"fn",
"=",
"getDeclarationRValue",
"(",
"n",
")",
";",
"target",
"=",
"n",
";",
"break",
";",
"// handles class method case:",
"// class clName(){",
"// constructor(){}",
"// someMethod(){} <===",
"// }",
"case",
"MEMBER_FUNCTION_DEF",
":",
"Node",
"parent",
"=",
"n",
".",
"getParent",
"(",
")",
";",
"if",
"(",
"parent",
".",
"isClassMembers",
"(",
")",
")",
"{",
"Node",
"classNode",
"=",
"parent",
".",
"getParent",
"(",
")",
";",
"String",
"midPart",
"=",
"n",
".",
"isStaticMember",
"(",
")",
"?",
"\".\"",
":",
"\".prototype.\"",
";",
"name",
"=",
"NodeUtil",
".",
"getName",
"(",
"classNode",
")",
"+",
"midPart",
"+",
"n",
".",
"getString",
"(",
")",
";",
"if",
"(",
"NodeUtil",
".",
"isEs6ConstructorMemberFunctionDef",
"(",
"n",
")",
")",
"{",
"name",
"=",
"NodeUtil",
".",
"getName",
"(",
"classNode",
")",
";",
"}",
"fn",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"classNode",
".",
"getParent",
"(",
")",
".",
"isAssign",
"(",
")",
"||",
"classNode",
".",
"getParent",
"(",
")",
".",
"isName",
"(",
")",
")",
"{",
"target",
"=",
"classNode",
".",
"getGrandparent",
"(",
")",
";",
"}",
"else",
"{",
"target",
"=",
"classNode",
";",
"}",
"}",
"break",
";",
"default",
":",
"break",
";",
"}",
"if",
"(",
"fn",
"==",
"null",
"||",
"!",
"fn",
".",
"isFunction",
"(",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"INJECT_NON_FUNCTION_ERROR",
")",
")",
";",
"return",
";",
"}",
"// report an error if the function declaration did not take place in a block or global scope",
"if",
"(",
"!",
"target",
".",
"getParent",
"(",
")",
".",
"isScript",
"(",
")",
"&&",
"!",
"target",
".",
"getParent",
"(",
")",
".",
"isBlock",
"(",
")",
"&&",
"!",
"target",
".",
"getParent",
"(",
")",
".",
"isModuleBody",
"(",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"INJECT_IN_NON_GLOBAL_OR_BLOCK_ERROR",
")",
")",
";",
"return",
";",
"}",
"// checks that name is present, which must always be the case unless the",
"// compiler allowed a syntax error or a dangling anonymous function",
"// expression.",
"checkNotNull",
"(",
"name",
")",
";",
"// registers the node.",
"injectables",
".",
"add",
"(",
"new",
"NodeContext",
"(",
"name",
",",
"n",
",",
"fn",
",",
"target",
")",
")",
";",
"}"
] | Add node to the list of injectables.
@param n node to add. | [
"Add",
"node",
"to",
"the",
"list",
"of",
"injectables",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AngularPass.java#L215-L308 |
23,903 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.isOutputInJson | @GwtIncompatible("Unnecessary")
private boolean isOutputInJson() {
return config.jsonStreamMode == JsonStreamMode.OUT
|| config.jsonStreamMode == JsonStreamMode.BOTH;
} | java | @GwtIncompatible("Unnecessary")
private boolean isOutputInJson() {
return config.jsonStreamMode == JsonStreamMode.OUT
|| config.jsonStreamMode == JsonStreamMode.BOTH;
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"boolean",
"isOutputInJson",
"(",
")",
"{",
"return",
"config",
".",
"jsonStreamMode",
"==",
"JsonStreamMode",
".",
"OUT",
"||",
"config",
".",
"jsonStreamMode",
"==",
"JsonStreamMode",
".",
"BOTH",
";",
"}"
] | Returns whether output should be a JSON stream. | [
"Returns",
"whether",
"output",
"should",
"be",
"a",
"JSON",
"stream",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L269-L273 |
23,904 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.createInputs | @GwtIncompatible("Unnecessary")
private List<SourceFile> createInputs(
List<FlagEntry<JsSourceType>> files, boolean allowStdIn, List<JsModuleSpec> jsModuleSpecs)
throws IOException {
return createInputs(files, /* jsonFiles= */ null, allowStdIn, jsModuleSpecs);
} | java | @GwtIncompatible("Unnecessary")
private List<SourceFile> createInputs(
List<FlagEntry<JsSourceType>> files, boolean allowStdIn, List<JsModuleSpec> jsModuleSpecs)
throws IOException {
return createInputs(files, /* jsonFiles= */ null, allowStdIn, jsModuleSpecs);
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"List",
"<",
"SourceFile",
">",
"createInputs",
"(",
"List",
"<",
"FlagEntry",
"<",
"JsSourceType",
">",
">",
"files",
",",
"boolean",
"allowStdIn",
",",
"List",
"<",
"JsModuleSpec",
">",
"jsModuleSpecs",
")",
"throws",
"IOException",
"{",
"return",
"createInputs",
"(",
"files",
",",
"/* jsonFiles= */",
"null",
",",
"allowStdIn",
",",
"jsModuleSpecs",
")",
";",
"}"
] | Creates inputs from a list of files.
@param files A list of flag entries indicates js and zip file names.
@param allowStdIn Whether '-' is allowed appear as a filename to represent stdin. If true, '-'
is only allowed to appear once.
@param jsModuleSpecs A list js module specs.
@return An array of inputs | [
"Creates",
"inputs",
"from",
"a",
"list",
"of",
"files",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L559-L564 |
23,905 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.createInputs | @GwtIncompatible("Unnecessary")
private List<SourceFile> createInputs(
List<FlagEntry<JsSourceType>> files,
List<JsonFileSpec> jsonFiles,
List<JsModuleSpec> jsModuleSpecs)
throws IOException {
return createInputs(files, jsonFiles, /* allowStdIn= */ false, jsModuleSpecs);
} | java | @GwtIncompatible("Unnecessary")
private List<SourceFile> createInputs(
List<FlagEntry<JsSourceType>> files,
List<JsonFileSpec> jsonFiles,
List<JsModuleSpec> jsModuleSpecs)
throws IOException {
return createInputs(files, jsonFiles, /* allowStdIn= */ false, jsModuleSpecs);
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"List",
"<",
"SourceFile",
">",
"createInputs",
"(",
"List",
"<",
"FlagEntry",
"<",
"JsSourceType",
">",
">",
"files",
",",
"List",
"<",
"JsonFileSpec",
">",
"jsonFiles",
",",
"List",
"<",
"JsModuleSpec",
">",
"jsModuleSpecs",
")",
"throws",
"IOException",
"{",
"return",
"createInputs",
"(",
"files",
",",
"jsonFiles",
",",
"/* allowStdIn= */",
"false",
",",
"jsModuleSpecs",
")",
";",
"}"
] | Creates inputs from a list of source files and json files.
@param files A list of flag entries indicates js and zip file names.
@param jsonFiles A list of json encoded files.
@param jsModuleSpecs A list js module specs.
@return An array of inputs | [
"Creates",
"inputs",
"from",
"a",
"list",
"of",
"source",
"files",
"and",
"json",
"files",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L574-L581 |
23,906 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.createSourceInputs | @GwtIncompatible("Unnecessary")
private List<SourceFile> createSourceInputs(
List<JsModuleSpec> jsModuleSpecs,
List<FlagEntry<JsSourceType>> files,
List<JsonFileSpec> jsonFiles,
List<String> moduleRoots)
throws IOException {
if (isInTestMode()) {
return inputsSupplierForTesting != null ? inputsSupplierForTesting.get()
: null;
}
if (files.isEmpty() && jsonFiles == null) {
// Request to read from stdin.
files = ImmutableList.of(new FlagEntry<JsSourceType>(JsSourceType.JS, "-"));
}
for (JSError error : deduplicateIjsFiles(files, moduleRoots, !jsModuleSpecs.isEmpty())) {
compiler.report(error);
}
try {
if (jsonFiles != null) {
return createInputs(files, jsonFiles, jsModuleSpecs);
} else {
return createInputs(files, true, jsModuleSpecs);
}
} catch (FlagUsageException e) {
throw new FlagUsageException("Bad --js flag. " + e.getMessage());
}
} | java | @GwtIncompatible("Unnecessary")
private List<SourceFile> createSourceInputs(
List<JsModuleSpec> jsModuleSpecs,
List<FlagEntry<JsSourceType>> files,
List<JsonFileSpec> jsonFiles,
List<String> moduleRoots)
throws IOException {
if (isInTestMode()) {
return inputsSupplierForTesting != null ? inputsSupplierForTesting.get()
: null;
}
if (files.isEmpty() && jsonFiles == null) {
// Request to read from stdin.
files = ImmutableList.of(new FlagEntry<JsSourceType>(JsSourceType.JS, "-"));
}
for (JSError error : deduplicateIjsFiles(files, moduleRoots, !jsModuleSpecs.isEmpty())) {
compiler.report(error);
}
try {
if (jsonFiles != null) {
return createInputs(files, jsonFiles, jsModuleSpecs);
} else {
return createInputs(files, true, jsModuleSpecs);
}
} catch (FlagUsageException e) {
throw new FlagUsageException("Bad --js flag. " + e.getMessage());
}
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"List",
"<",
"SourceFile",
">",
"createSourceInputs",
"(",
"List",
"<",
"JsModuleSpec",
">",
"jsModuleSpecs",
",",
"List",
"<",
"FlagEntry",
"<",
"JsSourceType",
">",
">",
"files",
",",
"List",
"<",
"JsonFileSpec",
">",
"jsonFiles",
",",
"List",
"<",
"String",
">",
"moduleRoots",
")",
"throws",
"IOException",
"{",
"if",
"(",
"isInTestMode",
"(",
")",
")",
"{",
"return",
"inputsSupplierForTesting",
"!=",
"null",
"?",
"inputsSupplierForTesting",
".",
"get",
"(",
")",
":",
"null",
";",
"}",
"if",
"(",
"files",
".",
"isEmpty",
"(",
")",
"&&",
"jsonFiles",
"==",
"null",
")",
"{",
"// Request to read from stdin.",
"files",
"=",
"ImmutableList",
".",
"of",
"(",
"new",
"FlagEntry",
"<",
"JsSourceType",
">",
"(",
"JsSourceType",
".",
"JS",
",",
"\"-\"",
")",
")",
";",
"}",
"for",
"(",
"JSError",
"error",
":",
"deduplicateIjsFiles",
"(",
"files",
",",
"moduleRoots",
",",
"!",
"jsModuleSpecs",
".",
"isEmpty",
"(",
")",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"error",
")",
";",
"}",
"try",
"{",
"if",
"(",
"jsonFiles",
"!=",
"null",
")",
"{",
"return",
"createInputs",
"(",
"files",
",",
"jsonFiles",
",",
"jsModuleSpecs",
")",
";",
"}",
"else",
"{",
"return",
"createInputs",
"(",
"files",
",",
"true",
",",
"jsModuleSpecs",
")",
";",
"}",
"}",
"catch",
"(",
"FlagUsageException",
"e",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"Bad --js flag. \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Creates JS source code inputs from a list of files. | [
"Creates",
"JS",
"source",
"code",
"inputs",
"from",
"a",
"list",
"of",
"files",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L787-L816 |
23,907 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.createExternInputs | @GwtIncompatible("Unnecessary")
private List<SourceFile> createExternInputs(List<String> files) throws IOException {
List<FlagEntry<JsSourceType>> externFiles = new ArrayList<>();
for (String file : files) {
externFiles.add(new FlagEntry<JsSourceType>(JsSourceType.EXTERN, file));
}
try {
return createInputs(externFiles, false, new ArrayList<JsModuleSpec>());
} catch (FlagUsageException e) {
throw new FlagUsageException("Bad --externs flag. " + e.getMessage());
}
} | java | @GwtIncompatible("Unnecessary")
private List<SourceFile> createExternInputs(List<String> files) throws IOException {
List<FlagEntry<JsSourceType>> externFiles = new ArrayList<>();
for (String file : files) {
externFiles.add(new FlagEntry<JsSourceType>(JsSourceType.EXTERN, file));
}
try {
return createInputs(externFiles, false, new ArrayList<JsModuleSpec>());
} catch (FlagUsageException e) {
throw new FlagUsageException("Bad --externs flag. " + e.getMessage());
}
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"List",
"<",
"SourceFile",
">",
"createExternInputs",
"(",
"List",
"<",
"String",
">",
"files",
")",
"throws",
"IOException",
"{",
"List",
"<",
"FlagEntry",
"<",
"JsSourceType",
">>",
"externFiles",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"file",
":",
"files",
")",
"{",
"externFiles",
".",
"add",
"(",
"new",
"FlagEntry",
"<",
"JsSourceType",
">",
"(",
"JsSourceType",
".",
"EXTERN",
",",
"file",
")",
")",
";",
"}",
"try",
"{",
"return",
"createInputs",
"(",
"externFiles",
",",
"false",
",",
"new",
"ArrayList",
"<",
"JsModuleSpec",
">",
"(",
")",
")",
";",
"}",
"catch",
"(",
"FlagUsageException",
"e",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"Bad --externs flag. \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Creates JS extern inputs from a list of files. | [
"Creates",
"JS",
"extern",
"inputs",
"from",
"a",
"list",
"of",
"files",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L819-L830 |
23,908 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.createJsModules | public static List<JSModule> createJsModules(List<JsModuleSpec> specs, List<SourceFile> inputs)
throws IOException {
checkState(specs != null);
checkState(!specs.isEmpty());
checkState(inputs != null);
List<String> moduleNames = new ArrayList<>(specs.size());
Map<String, JSModule> modulesByName = new LinkedHashMap<>();
Map<String, Integer> modulesFileCountMap = new LinkedHashMap<>();
int numJsFilesExpected = 0;
int minJsFilesRequired = 0;
for (JsModuleSpec spec : specs) {
if (modulesByName.containsKey(spec.name)) {
throw new FlagUsageException("Duplicate module name: " + spec.name);
}
JSModule module = new JSModule(spec.name);
for (String dep : spec.deps) {
JSModule other = modulesByName.get(dep);
if (other == null) {
throw new FlagUsageException(
"Module '"
+ spec.name
+ "' depends on unknown module '"
+ dep
+ "'. Be sure to list modules in dependency order.");
}
module.addDependency(other);
}
// We will allow modules of zero input.
if (spec.numJsFiles < 0) {
numJsFilesExpected = -1;
} else {
minJsFilesRequired += spec.numJsFiles;
}
if (numJsFilesExpected >= 0) {
numJsFilesExpected += spec.numJsFiles;
}
// Add modules in reverse order so that source files are allocated to
// modules in reverse order. This allows the first module
// (presumably the base module) to have a size of 'auto'
moduleNames.add(0, spec.name);
modulesFileCountMap.put(spec.name, spec.numJsFiles);
modulesByName.put(spec.name, module);
}
final int totalNumJsFiles = inputs.size();
if (numJsFilesExpected >= 0 || minJsFilesRequired > totalNumJsFiles) {
if (minJsFilesRequired > totalNumJsFiles) {
numJsFilesExpected = minJsFilesRequired;
}
if (numJsFilesExpected > totalNumJsFiles) {
throw new FlagUsageException(
"Not enough JS files specified. Expected "
+ numJsFilesExpected
+ " but found "
+ totalNumJsFiles);
} else if (numJsFilesExpected < totalNumJsFiles) {
throw new FlagUsageException(
"Too many JS files specified. Expected "
+ numJsFilesExpected
+ " but found "
+ totalNumJsFiles);
}
}
int numJsFilesLeft = totalNumJsFiles;
int moduleIndex = 0;
for (String moduleName : moduleNames) {
// Parse module inputs.
int numJsFiles = modulesFileCountMap.get(moduleName);
JSModule module = modulesByName.get(moduleName);
// Check if the first js module specified 'auto' for the number of files
if (moduleIndex == moduleNames.size() - 1 && numJsFiles == -1) {
numJsFiles = numJsFilesLeft;
}
List<SourceFile> moduleFiles = inputs.subList(numJsFilesLeft - numJsFiles, numJsFilesLeft);
for (SourceFile input : moduleFiles) {
module.add(input);
}
numJsFilesLeft -= numJsFiles;
moduleIndex++;
}
return new ArrayList<>(modulesByName.values());
} | java | public static List<JSModule> createJsModules(List<JsModuleSpec> specs, List<SourceFile> inputs)
throws IOException {
checkState(specs != null);
checkState(!specs.isEmpty());
checkState(inputs != null);
List<String> moduleNames = new ArrayList<>(specs.size());
Map<String, JSModule> modulesByName = new LinkedHashMap<>();
Map<String, Integer> modulesFileCountMap = new LinkedHashMap<>();
int numJsFilesExpected = 0;
int minJsFilesRequired = 0;
for (JsModuleSpec spec : specs) {
if (modulesByName.containsKey(spec.name)) {
throw new FlagUsageException("Duplicate module name: " + spec.name);
}
JSModule module = new JSModule(spec.name);
for (String dep : spec.deps) {
JSModule other = modulesByName.get(dep);
if (other == null) {
throw new FlagUsageException(
"Module '"
+ spec.name
+ "' depends on unknown module '"
+ dep
+ "'. Be sure to list modules in dependency order.");
}
module.addDependency(other);
}
// We will allow modules of zero input.
if (spec.numJsFiles < 0) {
numJsFilesExpected = -1;
} else {
minJsFilesRequired += spec.numJsFiles;
}
if (numJsFilesExpected >= 0) {
numJsFilesExpected += spec.numJsFiles;
}
// Add modules in reverse order so that source files are allocated to
// modules in reverse order. This allows the first module
// (presumably the base module) to have a size of 'auto'
moduleNames.add(0, spec.name);
modulesFileCountMap.put(spec.name, spec.numJsFiles);
modulesByName.put(spec.name, module);
}
final int totalNumJsFiles = inputs.size();
if (numJsFilesExpected >= 0 || minJsFilesRequired > totalNumJsFiles) {
if (minJsFilesRequired > totalNumJsFiles) {
numJsFilesExpected = minJsFilesRequired;
}
if (numJsFilesExpected > totalNumJsFiles) {
throw new FlagUsageException(
"Not enough JS files specified. Expected "
+ numJsFilesExpected
+ " but found "
+ totalNumJsFiles);
} else if (numJsFilesExpected < totalNumJsFiles) {
throw new FlagUsageException(
"Too many JS files specified. Expected "
+ numJsFilesExpected
+ " but found "
+ totalNumJsFiles);
}
}
int numJsFilesLeft = totalNumJsFiles;
int moduleIndex = 0;
for (String moduleName : moduleNames) {
// Parse module inputs.
int numJsFiles = modulesFileCountMap.get(moduleName);
JSModule module = modulesByName.get(moduleName);
// Check if the first js module specified 'auto' for the number of files
if (moduleIndex == moduleNames.size() - 1 && numJsFiles == -1) {
numJsFiles = numJsFilesLeft;
}
List<SourceFile> moduleFiles = inputs.subList(numJsFilesLeft - numJsFiles, numJsFilesLeft);
for (SourceFile input : moduleFiles) {
module.add(input);
}
numJsFilesLeft -= numJsFiles;
moduleIndex++;
}
return new ArrayList<>(modulesByName.values());
} | [
"public",
"static",
"List",
"<",
"JSModule",
">",
"createJsModules",
"(",
"List",
"<",
"JsModuleSpec",
">",
"specs",
",",
"List",
"<",
"SourceFile",
">",
"inputs",
")",
"throws",
"IOException",
"{",
"checkState",
"(",
"specs",
"!=",
"null",
")",
";",
"checkState",
"(",
"!",
"specs",
".",
"isEmpty",
"(",
")",
")",
";",
"checkState",
"(",
"inputs",
"!=",
"null",
")",
";",
"List",
"<",
"String",
">",
"moduleNames",
"=",
"new",
"ArrayList",
"<>",
"(",
"specs",
".",
"size",
"(",
")",
")",
";",
"Map",
"<",
"String",
",",
"JSModule",
">",
"modulesByName",
"=",
"new",
"LinkedHashMap",
"<>",
"(",
")",
";",
"Map",
"<",
"String",
",",
"Integer",
">",
"modulesFileCountMap",
"=",
"new",
"LinkedHashMap",
"<>",
"(",
")",
";",
"int",
"numJsFilesExpected",
"=",
"0",
";",
"int",
"minJsFilesRequired",
"=",
"0",
";",
"for",
"(",
"JsModuleSpec",
"spec",
":",
"specs",
")",
"{",
"if",
"(",
"modulesByName",
".",
"containsKey",
"(",
"spec",
".",
"name",
")",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"Duplicate module name: \"",
"+",
"spec",
".",
"name",
")",
";",
"}",
"JSModule",
"module",
"=",
"new",
"JSModule",
"(",
"spec",
".",
"name",
")",
";",
"for",
"(",
"String",
"dep",
":",
"spec",
".",
"deps",
")",
"{",
"JSModule",
"other",
"=",
"modulesByName",
".",
"get",
"(",
"dep",
")",
";",
"if",
"(",
"other",
"==",
"null",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"Module '\"",
"+",
"spec",
".",
"name",
"+",
"\"' depends on unknown module '\"",
"+",
"dep",
"+",
"\"'. Be sure to list modules in dependency order.\"",
")",
";",
"}",
"module",
".",
"addDependency",
"(",
"other",
")",
";",
"}",
"// We will allow modules of zero input.",
"if",
"(",
"spec",
".",
"numJsFiles",
"<",
"0",
")",
"{",
"numJsFilesExpected",
"=",
"-",
"1",
";",
"}",
"else",
"{",
"minJsFilesRequired",
"+=",
"spec",
".",
"numJsFiles",
";",
"}",
"if",
"(",
"numJsFilesExpected",
">=",
"0",
")",
"{",
"numJsFilesExpected",
"+=",
"spec",
".",
"numJsFiles",
";",
"}",
"// Add modules in reverse order so that source files are allocated to",
"// modules in reverse order. This allows the first module",
"// (presumably the base module) to have a size of 'auto'",
"moduleNames",
".",
"add",
"(",
"0",
",",
"spec",
".",
"name",
")",
";",
"modulesFileCountMap",
".",
"put",
"(",
"spec",
".",
"name",
",",
"spec",
".",
"numJsFiles",
")",
";",
"modulesByName",
".",
"put",
"(",
"spec",
".",
"name",
",",
"module",
")",
";",
"}",
"final",
"int",
"totalNumJsFiles",
"=",
"inputs",
".",
"size",
"(",
")",
";",
"if",
"(",
"numJsFilesExpected",
">=",
"0",
"||",
"minJsFilesRequired",
">",
"totalNumJsFiles",
")",
"{",
"if",
"(",
"minJsFilesRequired",
">",
"totalNumJsFiles",
")",
"{",
"numJsFilesExpected",
"=",
"minJsFilesRequired",
";",
"}",
"if",
"(",
"numJsFilesExpected",
">",
"totalNumJsFiles",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"Not enough JS files specified. Expected \"",
"+",
"numJsFilesExpected",
"+",
"\" but found \"",
"+",
"totalNumJsFiles",
")",
";",
"}",
"else",
"if",
"(",
"numJsFilesExpected",
"<",
"totalNumJsFiles",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"Too many JS files specified. Expected \"",
"+",
"numJsFilesExpected",
"+",
"\" but found \"",
"+",
"totalNumJsFiles",
")",
";",
"}",
"}",
"int",
"numJsFilesLeft",
"=",
"totalNumJsFiles",
";",
"int",
"moduleIndex",
"=",
"0",
";",
"for",
"(",
"String",
"moduleName",
":",
"moduleNames",
")",
"{",
"// Parse module inputs.",
"int",
"numJsFiles",
"=",
"modulesFileCountMap",
".",
"get",
"(",
"moduleName",
")",
";",
"JSModule",
"module",
"=",
"modulesByName",
".",
"get",
"(",
"moduleName",
")",
";",
"// Check if the first js module specified 'auto' for the number of files",
"if",
"(",
"moduleIndex",
"==",
"moduleNames",
".",
"size",
"(",
")",
"-",
"1",
"&&",
"numJsFiles",
"==",
"-",
"1",
")",
"{",
"numJsFiles",
"=",
"numJsFilesLeft",
";",
"}",
"List",
"<",
"SourceFile",
">",
"moduleFiles",
"=",
"inputs",
".",
"subList",
"(",
"numJsFilesLeft",
"-",
"numJsFiles",
",",
"numJsFilesLeft",
")",
";",
"for",
"(",
"SourceFile",
"input",
":",
"moduleFiles",
")",
"{",
"module",
".",
"add",
"(",
"input",
")",
";",
"}",
"numJsFilesLeft",
"-=",
"numJsFiles",
";",
"moduleIndex",
"++",
";",
"}",
"return",
"new",
"ArrayList",
"<>",
"(",
"modulesByName",
".",
"values",
"(",
")",
")",
";",
"}"
] | Creates module objects from a list of js module specifications.
@param specs A list of js module specifications, not null or empty.
@param inputs A list of JS file paths, not null
@return An array of module objects | [
"Creates",
"module",
"objects",
"from",
"a",
"list",
"of",
"js",
"module",
"specifications",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L839-L931 |
23,909 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.parseModuleWrappers | public static Map<String, String> parseModuleWrappers(
List<String> specs, Iterable<JSModule> chunks) {
checkState(specs != null);
Map<String, String> wrappers = new HashMap<>();
// Prepopulate the map with module names.
for (JSModule c : chunks) {
wrappers.put(c.getName(), "");
}
for (String spec : specs) {
// Format is "<name>:<wrapper>".
int pos = spec.indexOf(':');
if (pos == -1) {
throw new FlagUsageException(
"Expected module wrapper to have " + "<name>:<wrapper> format: " + spec);
}
// Parse module name.
String name = spec.substring(0, pos);
if (!wrappers.containsKey(name)) {
throw new FlagUsageException("Unknown module: '" + name + "'");
}
String wrapper = spec.substring(pos + 1);
// Support for %n% and %output%
wrapper = wrapper.replace("%output%", "%s").replace("%n%", "\n");
if (!wrapper.contains("%s")) {
throw new FlagUsageException("No %s placeholder in module wrapper: '" + wrapper + "'");
}
wrappers.put(name, wrapper);
}
return wrappers;
} | java | public static Map<String, String> parseModuleWrappers(
List<String> specs, Iterable<JSModule> chunks) {
checkState(specs != null);
Map<String, String> wrappers = new HashMap<>();
// Prepopulate the map with module names.
for (JSModule c : chunks) {
wrappers.put(c.getName(), "");
}
for (String spec : specs) {
// Format is "<name>:<wrapper>".
int pos = spec.indexOf(':');
if (pos == -1) {
throw new FlagUsageException(
"Expected module wrapper to have " + "<name>:<wrapper> format: " + spec);
}
// Parse module name.
String name = spec.substring(0, pos);
if (!wrappers.containsKey(name)) {
throw new FlagUsageException("Unknown module: '" + name + "'");
}
String wrapper = spec.substring(pos + 1);
// Support for %n% and %output%
wrapper = wrapper.replace("%output%", "%s").replace("%n%", "\n");
if (!wrapper.contains("%s")) {
throw new FlagUsageException("No %s placeholder in module wrapper: '" + wrapper + "'");
}
wrappers.put(name, wrapper);
}
return wrappers;
} | [
"public",
"static",
"Map",
"<",
"String",
",",
"String",
">",
"parseModuleWrappers",
"(",
"List",
"<",
"String",
">",
"specs",
",",
"Iterable",
"<",
"JSModule",
">",
"chunks",
")",
"{",
"checkState",
"(",
"specs",
"!=",
"null",
")",
";",
"Map",
"<",
"String",
",",
"String",
">",
"wrappers",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"// Prepopulate the map with module names.",
"for",
"(",
"JSModule",
"c",
":",
"chunks",
")",
"{",
"wrappers",
".",
"put",
"(",
"c",
".",
"getName",
"(",
")",
",",
"\"\"",
")",
";",
"}",
"for",
"(",
"String",
"spec",
":",
"specs",
")",
"{",
"// Format is \"<name>:<wrapper>\".",
"int",
"pos",
"=",
"spec",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"pos",
"==",
"-",
"1",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"Expected module wrapper to have \"",
"+",
"\"<name>:<wrapper> format: \"",
"+",
"spec",
")",
";",
"}",
"// Parse module name.",
"String",
"name",
"=",
"spec",
".",
"substring",
"(",
"0",
",",
"pos",
")",
";",
"if",
"(",
"!",
"wrappers",
".",
"containsKey",
"(",
"name",
")",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"Unknown module: '\"",
"+",
"name",
"+",
"\"'\"",
")",
";",
"}",
"String",
"wrapper",
"=",
"spec",
".",
"substring",
"(",
"pos",
"+",
"1",
")",
";",
"// Support for %n% and %output%",
"wrapper",
"=",
"wrapper",
".",
"replace",
"(",
"\"%output%\"",
",",
"\"%s\"",
")",
".",
"replace",
"(",
"\"%n%\"",
",",
"\"\\n\"",
")",
";",
"if",
"(",
"!",
"wrapper",
".",
"contains",
"(",
"\"%s\"",
")",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"No %s placeholder in module wrapper: '\"",
"+",
"wrapper",
"+",
"\"'\"",
")",
";",
"}",
"wrappers",
".",
"put",
"(",
"name",
",",
"wrapper",
")",
";",
"}",
"return",
"wrappers",
";",
"}"
] | Parses module wrapper specifications.
@param specs A list of module wrapper specifications, not null. The spec format is: <code>
name:wrapper</code>. Wrappers.
@param chunks The JS chunks whose wrappers are specified
@return A map from module name to module wrapper. Modules with no wrapper will have the empty
string as their value in this map. | [
"Parses",
"module",
"wrapper",
"specifications",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L954-L988 |
23,910 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.maybeCreateDirsForPath | @GwtIncompatible("Unnecessary")
private static void maybeCreateDirsForPath(String pathPrefix) {
if (!Strings.isNullOrEmpty(pathPrefix)) {
String dirName =
pathPrefix.charAt(pathPrefix.length() - 1) == File.separatorChar
? pathPrefix.substring(0, pathPrefix.length() - 1)
: new File(pathPrefix).getParent();
if (dirName != null) {
new File(dirName).mkdirs();
}
}
} | java | @GwtIncompatible("Unnecessary")
private static void maybeCreateDirsForPath(String pathPrefix) {
if (!Strings.isNullOrEmpty(pathPrefix)) {
String dirName =
pathPrefix.charAt(pathPrefix.length() - 1) == File.separatorChar
? pathPrefix.substring(0, pathPrefix.length() - 1)
: new File(pathPrefix).getParent();
if (dirName != null) {
new File(dirName).mkdirs();
}
}
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"static",
"void",
"maybeCreateDirsForPath",
"(",
"String",
"pathPrefix",
")",
"{",
"if",
"(",
"!",
"Strings",
".",
"isNullOrEmpty",
"(",
"pathPrefix",
")",
")",
"{",
"String",
"dirName",
"=",
"pathPrefix",
".",
"charAt",
"(",
"pathPrefix",
".",
"length",
"(",
")",
"-",
"1",
")",
"==",
"File",
".",
"separatorChar",
"?",
"pathPrefix",
".",
"substring",
"(",
"0",
",",
"pathPrefix",
".",
"length",
"(",
")",
"-",
"1",
")",
":",
"new",
"File",
"(",
"pathPrefix",
")",
".",
"getParent",
"(",
")",
";",
"if",
"(",
"dirName",
"!=",
"null",
")",
"{",
"new",
"File",
"(",
"dirName",
")",
".",
"mkdirs",
"(",
")",
";",
"}",
"}",
"}"
] | Creates any directories necessary to write a file that will have a given path prefix. | [
"Creates",
"any",
"directories",
"necessary",
"to",
"write",
"a",
"file",
"that",
"will",
"have",
"a",
"given",
"path",
"prefix",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1083-L1094 |
23,911 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.processResults | @GwtIncompatible("Unnecessary")
int processResults(Result result, List<JSModule> modules, B options) throws IOException {
if (config.printPassGraph) {
if (compiler.getRoot() == null) {
return 1;
} else {
Appendable jsOutput = createDefaultOutput();
jsOutput.append(
DotFormatter.toDot(compiler.getPassConfig().getPassGraph()));
jsOutput.append('\n');
closeAppendable(jsOutput);
return 0;
}
}
if (config.printAst) {
if (compiler.getRoot() == null) {
return 1;
} else {
Appendable jsOutput = createDefaultOutput();
ControlFlowGraph<Node> cfg = compiler.computeCFG();
DotFormatter.appendDot(
compiler.getRoot().getLastChild(), cfg, jsOutput);
jsOutput.append('\n');
closeAppendable(jsOutput);
return 0;
}
}
if (config.printTree) {
if (compiler.getRoot() == null) {
compiler.report(JSError.make(NO_TREE_GENERATED_ERROR));
return 1;
} else {
Appendable jsOutput = createDefaultOutput();
compiler.getRoot().appendStringTree(jsOutput);
jsOutput.append("\n");
closeAppendable(jsOutput);
return 0;
}
}
if (config.skipNormalOutputs) {
// Output the manifest and bundle files if requested.
outputManifest();
outputBundle();
outputModuleGraphJson();
return 0;
} else if (options.outputJs != OutputJs.NONE && result.success) {
outputModuleGraphJson();
if (modules == null) {
outputSingleBinary(options);
// Output the source map if requested.
// If output files are being written to stdout as a JSON string,
// outputSingleBinary will have added the sourcemap to the output file
if (!isOutputInJson()) {
outputSourceMap(options, config.jsOutputFile);
}
} else {
DiagnosticType error = outputModuleBinaryAndSourceMaps(compiler.getModules(), options);
if (error != null) {
compiler.report(JSError.make(error));
return 1;
}
}
// Output the externs if required.
if (options.externExportsPath != null) {
try (Writer eeOut = openExternExportsStream(options, config.jsOutputFile)) {
eeOut.append(result.externExport);
}
}
// Output the variable and property name maps if requested.
outputNameMaps();
// Output the ReplaceStrings map if requested
outputStringMap();
// Output the manifest and bundle files if requested.
outputManifest();
outputBundle();
if (isOutputInJson()) {
outputJsonStream();
}
}
// return 0 if no errors, the error count otherwise
return Math.min(result.errors.size(), 0x7f);
} | java | @GwtIncompatible("Unnecessary")
int processResults(Result result, List<JSModule> modules, B options) throws IOException {
if (config.printPassGraph) {
if (compiler.getRoot() == null) {
return 1;
} else {
Appendable jsOutput = createDefaultOutput();
jsOutput.append(
DotFormatter.toDot(compiler.getPassConfig().getPassGraph()));
jsOutput.append('\n');
closeAppendable(jsOutput);
return 0;
}
}
if (config.printAst) {
if (compiler.getRoot() == null) {
return 1;
} else {
Appendable jsOutput = createDefaultOutput();
ControlFlowGraph<Node> cfg = compiler.computeCFG();
DotFormatter.appendDot(
compiler.getRoot().getLastChild(), cfg, jsOutput);
jsOutput.append('\n');
closeAppendable(jsOutput);
return 0;
}
}
if (config.printTree) {
if (compiler.getRoot() == null) {
compiler.report(JSError.make(NO_TREE_GENERATED_ERROR));
return 1;
} else {
Appendable jsOutput = createDefaultOutput();
compiler.getRoot().appendStringTree(jsOutput);
jsOutput.append("\n");
closeAppendable(jsOutput);
return 0;
}
}
if (config.skipNormalOutputs) {
// Output the manifest and bundle files if requested.
outputManifest();
outputBundle();
outputModuleGraphJson();
return 0;
} else if (options.outputJs != OutputJs.NONE && result.success) {
outputModuleGraphJson();
if (modules == null) {
outputSingleBinary(options);
// Output the source map if requested.
// If output files are being written to stdout as a JSON string,
// outputSingleBinary will have added the sourcemap to the output file
if (!isOutputInJson()) {
outputSourceMap(options, config.jsOutputFile);
}
} else {
DiagnosticType error = outputModuleBinaryAndSourceMaps(compiler.getModules(), options);
if (error != null) {
compiler.report(JSError.make(error));
return 1;
}
}
// Output the externs if required.
if (options.externExportsPath != null) {
try (Writer eeOut = openExternExportsStream(options, config.jsOutputFile)) {
eeOut.append(result.externExport);
}
}
// Output the variable and property name maps if requested.
outputNameMaps();
// Output the ReplaceStrings map if requested
outputStringMap();
// Output the manifest and bundle files if requested.
outputManifest();
outputBundle();
if (isOutputInJson()) {
outputJsonStream();
}
}
// return 0 if no errors, the error count otherwise
return Math.min(result.errors.size(), 0x7f);
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"int",
"processResults",
"(",
"Result",
"result",
",",
"List",
"<",
"JSModule",
">",
"modules",
",",
"B",
"options",
")",
"throws",
"IOException",
"{",
"if",
"(",
"config",
".",
"printPassGraph",
")",
"{",
"if",
"(",
"compiler",
".",
"getRoot",
"(",
")",
"==",
"null",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"Appendable",
"jsOutput",
"=",
"createDefaultOutput",
"(",
")",
";",
"jsOutput",
".",
"append",
"(",
"DotFormatter",
".",
"toDot",
"(",
"compiler",
".",
"getPassConfig",
"(",
")",
".",
"getPassGraph",
"(",
")",
")",
")",
";",
"jsOutput",
".",
"append",
"(",
"'",
"'",
")",
";",
"closeAppendable",
"(",
"jsOutput",
")",
";",
"return",
"0",
";",
"}",
"}",
"if",
"(",
"config",
".",
"printAst",
")",
"{",
"if",
"(",
"compiler",
".",
"getRoot",
"(",
")",
"==",
"null",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"Appendable",
"jsOutput",
"=",
"createDefaultOutput",
"(",
")",
";",
"ControlFlowGraph",
"<",
"Node",
">",
"cfg",
"=",
"compiler",
".",
"computeCFG",
"(",
")",
";",
"DotFormatter",
".",
"appendDot",
"(",
"compiler",
".",
"getRoot",
"(",
")",
".",
"getLastChild",
"(",
")",
",",
"cfg",
",",
"jsOutput",
")",
";",
"jsOutput",
".",
"append",
"(",
"'",
"'",
")",
";",
"closeAppendable",
"(",
"jsOutput",
")",
";",
"return",
"0",
";",
"}",
"}",
"if",
"(",
"config",
".",
"printTree",
")",
"{",
"if",
"(",
"compiler",
".",
"getRoot",
"(",
")",
"==",
"null",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"NO_TREE_GENERATED_ERROR",
")",
")",
";",
"return",
"1",
";",
"}",
"else",
"{",
"Appendable",
"jsOutput",
"=",
"createDefaultOutput",
"(",
")",
";",
"compiler",
".",
"getRoot",
"(",
")",
".",
"appendStringTree",
"(",
"jsOutput",
")",
";",
"jsOutput",
".",
"append",
"(",
"\"\\n\"",
")",
";",
"closeAppendable",
"(",
"jsOutput",
")",
";",
"return",
"0",
";",
"}",
"}",
"if",
"(",
"config",
".",
"skipNormalOutputs",
")",
"{",
"// Output the manifest and bundle files if requested.",
"outputManifest",
"(",
")",
";",
"outputBundle",
"(",
")",
";",
"outputModuleGraphJson",
"(",
")",
";",
"return",
"0",
";",
"}",
"else",
"if",
"(",
"options",
".",
"outputJs",
"!=",
"OutputJs",
".",
"NONE",
"&&",
"result",
".",
"success",
")",
"{",
"outputModuleGraphJson",
"(",
")",
";",
"if",
"(",
"modules",
"==",
"null",
")",
"{",
"outputSingleBinary",
"(",
"options",
")",
";",
"// Output the source map if requested.",
"// If output files are being written to stdout as a JSON string,",
"// outputSingleBinary will have added the sourcemap to the output file",
"if",
"(",
"!",
"isOutputInJson",
"(",
")",
")",
"{",
"outputSourceMap",
"(",
"options",
",",
"config",
".",
"jsOutputFile",
")",
";",
"}",
"}",
"else",
"{",
"DiagnosticType",
"error",
"=",
"outputModuleBinaryAndSourceMaps",
"(",
"compiler",
".",
"getModules",
"(",
")",
",",
"options",
")",
";",
"if",
"(",
"error",
"!=",
"null",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"error",
")",
")",
";",
"return",
"1",
";",
"}",
"}",
"// Output the externs if required.",
"if",
"(",
"options",
".",
"externExportsPath",
"!=",
"null",
")",
"{",
"try",
"(",
"Writer",
"eeOut",
"=",
"openExternExportsStream",
"(",
"options",
",",
"config",
".",
"jsOutputFile",
")",
")",
"{",
"eeOut",
".",
"append",
"(",
"result",
".",
"externExport",
")",
";",
"}",
"}",
"// Output the variable and property name maps if requested.",
"outputNameMaps",
"(",
")",
";",
"// Output the ReplaceStrings map if requested",
"outputStringMap",
"(",
")",
";",
"// Output the manifest and bundle files if requested.",
"outputManifest",
"(",
")",
";",
"outputBundle",
"(",
")",
";",
"if",
"(",
"isOutputInJson",
"(",
")",
")",
"{",
"outputJsonStream",
"(",
")",
";",
"}",
"}",
"// return 0 if no errors, the error count otherwise",
"return",
"Math",
".",
"min",
"(",
"result",
".",
"errors",
".",
"size",
"(",
")",
",",
"0x7f",
")",
";",
"}"
] | Processes the results of the compile job, and returns an error code. | [
"Processes",
"the",
"results",
"of",
"the",
"compile",
"job",
"and",
"returns",
"an",
"error",
"code",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1340-L1431 |
23,912 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.createJsonFile | @GwtIncompatible("Unnecessary")
JsonFileSpec createJsonFile(B options, String outputMarker, Function<String, String> escaper)
throws IOException {
Appendable jsOutput = new StringBuilder();
writeOutput(
jsOutput, compiler, (JSModule) null, config.outputWrapper,
outputMarker, escaper);
JsonFileSpec jsonOutput = new JsonFileSpec(jsOutput.toString(),
Strings.isNullOrEmpty(config.jsOutputFile) ?
"compiled.js" : config.jsOutputFile);
if (!Strings.isNullOrEmpty(options.sourceMapOutputPath)) {
StringBuilder sourcemap = new StringBuilder();
compiler.getSourceMap().appendTo(sourcemap, jsonOutput.getPath());
jsonOutput.setSourceMap(sourcemap.toString());
}
return jsonOutput;
} | java | @GwtIncompatible("Unnecessary")
JsonFileSpec createJsonFile(B options, String outputMarker, Function<String, String> escaper)
throws IOException {
Appendable jsOutput = new StringBuilder();
writeOutput(
jsOutput, compiler, (JSModule) null, config.outputWrapper,
outputMarker, escaper);
JsonFileSpec jsonOutput = new JsonFileSpec(jsOutput.toString(),
Strings.isNullOrEmpty(config.jsOutputFile) ?
"compiled.js" : config.jsOutputFile);
if (!Strings.isNullOrEmpty(options.sourceMapOutputPath)) {
StringBuilder sourcemap = new StringBuilder();
compiler.getSourceMap().appendTo(sourcemap, jsonOutput.getPath());
jsonOutput.setSourceMap(sourcemap.toString());
}
return jsonOutput;
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"JsonFileSpec",
"createJsonFile",
"(",
"B",
"options",
",",
"String",
"outputMarker",
",",
"Function",
"<",
"String",
",",
"String",
">",
"escaper",
")",
"throws",
"IOException",
"{",
"Appendable",
"jsOutput",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"writeOutput",
"(",
"jsOutput",
",",
"compiler",
",",
"(",
"JSModule",
")",
"null",
",",
"config",
".",
"outputWrapper",
",",
"outputMarker",
",",
"escaper",
")",
";",
"JsonFileSpec",
"jsonOutput",
"=",
"new",
"JsonFileSpec",
"(",
"jsOutput",
".",
"toString",
"(",
")",
",",
"Strings",
".",
"isNullOrEmpty",
"(",
"config",
".",
"jsOutputFile",
")",
"?",
"\"compiled.js\"",
":",
"config",
".",
"jsOutputFile",
")",
";",
"if",
"(",
"!",
"Strings",
".",
"isNullOrEmpty",
"(",
"options",
".",
"sourceMapOutputPath",
")",
")",
"{",
"StringBuilder",
"sourcemap",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"compiler",
".",
"getSourceMap",
"(",
")",
".",
"appendTo",
"(",
"sourcemap",
",",
"jsonOutput",
".",
"getPath",
"(",
")",
")",
";",
"jsonOutput",
".",
"setSourceMap",
"(",
"sourcemap",
".",
"toString",
"(",
")",
")",
";",
"}",
"return",
"jsonOutput",
";",
"}"
] | Save the compiler output to a JsonFileSpec to be later written to stdout | [
"Save",
"the",
"compiler",
"output",
"to",
"a",
"JsonFileSpec",
"to",
"be",
"later",
"written",
"to",
"stdout"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1463-L1482 |
23,913 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.createJsonFileFromModule | @GwtIncompatible("Unnecessary")
private JsonFileSpec createJsonFileFromModule(JSModule module) throws IOException {
compiler.resetAndIntitializeSourceMap();
StringBuilder output = new StringBuilder();
writeModuleOutput(output, module);
JsonFileSpec jsonFile = new JsonFileSpec(output.toString(),
getModuleOutputFileName(module));
StringBuilder moduleSourceMap = new StringBuilder();
compiler.getSourceMap().appendTo(moduleSourceMap,
getModuleOutputFileName(module));
jsonFile.setSourceMap(moduleSourceMap.toString());
return jsonFile;
} | java | @GwtIncompatible("Unnecessary")
private JsonFileSpec createJsonFileFromModule(JSModule module) throws IOException {
compiler.resetAndIntitializeSourceMap();
StringBuilder output = new StringBuilder();
writeModuleOutput(output, module);
JsonFileSpec jsonFile = new JsonFileSpec(output.toString(),
getModuleOutputFileName(module));
StringBuilder moduleSourceMap = new StringBuilder();
compiler.getSourceMap().appendTo(moduleSourceMap,
getModuleOutputFileName(module));
jsonFile.setSourceMap(moduleSourceMap.toString());
return jsonFile;
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"JsonFileSpec",
"createJsonFileFromModule",
"(",
"JSModule",
"module",
")",
"throws",
"IOException",
"{",
"compiler",
".",
"resetAndIntitializeSourceMap",
"(",
")",
";",
"StringBuilder",
"output",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"writeModuleOutput",
"(",
"output",
",",
"module",
")",
";",
"JsonFileSpec",
"jsonFile",
"=",
"new",
"JsonFileSpec",
"(",
"output",
".",
"toString",
"(",
")",
",",
"getModuleOutputFileName",
"(",
"module",
")",
")",
";",
"StringBuilder",
"moduleSourceMap",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"compiler",
".",
"getSourceMap",
"(",
")",
".",
"appendTo",
"(",
"moduleSourceMap",
",",
"getModuleOutputFileName",
"(",
"module",
")",
")",
";",
"jsonFile",
".",
"setSourceMap",
"(",
"moduleSourceMap",
".",
"toString",
"(",
")",
")",
";",
"return",
"jsonFile",
";",
"}"
] | Given an output module, convert it to a JSONFileSpec with associated sourcemap | [
"Given",
"an",
"output",
"module",
"convert",
"it",
"to",
"a",
"JSONFileSpec",
"with",
"associated",
"sourcemap"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1557-L1575 |
23,914 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.getInputCharset | @GwtIncompatible("Unnecessary")
private Charset getInputCharset() {
if (!config.charset.isEmpty()) {
if (!Charset.isSupported(config.charset)) {
throw new FlagUsageException(config.charset +
" is not a valid charset name.");
}
return Charset.forName(config.charset);
}
return UTF_8;
} | java | @GwtIncompatible("Unnecessary")
private Charset getInputCharset() {
if (!config.charset.isEmpty()) {
if (!Charset.isSupported(config.charset)) {
throw new FlagUsageException(config.charset +
" is not a valid charset name.");
}
return Charset.forName(config.charset);
}
return UTF_8;
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"Charset",
"getInputCharset",
"(",
")",
"{",
"if",
"(",
"!",
"config",
".",
"charset",
".",
"isEmpty",
"(",
")",
")",
"{",
"if",
"(",
"!",
"Charset",
".",
"isSupported",
"(",
"config",
".",
"charset",
")",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"config",
".",
"charset",
"+",
"\" is not a valid charset name.\"",
")",
";",
"}",
"return",
"Charset",
".",
"forName",
"(",
"config",
".",
"charset",
")",
";",
"}",
"return",
"UTF_8",
";",
"}"
] | Query the flag for the input charset, and return a Charset object representing the selection.
@return Charset to use when reading inputs
@throws FlagUsageException if flag is not a valid Charset name. | [
"Query",
"the",
"flag",
"for",
"the",
"input",
"charset",
"and",
"return",
"a",
"Charset",
"object",
"representing",
"the",
"selection",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1583-L1593 |
23,915 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.getLegacyOutputCharset | @GwtIncompatible("Unnecessary")
private Charset getLegacyOutputCharset() {
if (!config.charset.isEmpty()) {
if (!Charset.isSupported(config.charset)) {
throw new FlagUsageException(config.charset + " is not a valid charset name.");
}
return Charset.forName(config.charset);
}
return US_ASCII;
} | java | @GwtIncompatible("Unnecessary")
private Charset getLegacyOutputCharset() {
if (!config.charset.isEmpty()) {
if (!Charset.isSupported(config.charset)) {
throw new FlagUsageException(config.charset + " is not a valid charset name.");
}
return Charset.forName(config.charset);
}
return US_ASCII;
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"Charset",
"getLegacyOutputCharset",
"(",
")",
"{",
"if",
"(",
"!",
"config",
".",
"charset",
".",
"isEmpty",
"(",
")",
")",
"{",
"if",
"(",
"!",
"Charset",
".",
"isSupported",
"(",
"config",
".",
"charset",
")",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"config",
".",
"charset",
"+",
"\" is not a valid charset name.\"",
")",
";",
"}",
"return",
"Charset",
".",
"forName",
"(",
"config",
".",
"charset",
")",
";",
"}",
"return",
"US_ASCII",
";",
"}"
] | Query the flag for the output charset.
<p>Let the outputCharset be the same as the input charset... except if we're reading in UTF-8
by default. By tradition, we've always output ASCII to avoid various hiccups with different
browsers, proxies and firewalls.
@return Name of the charset to use when writing outputs. Guaranteed to be a supported charset.
@throws FlagUsageException if flag is not a valid Charset name. | [
"Query",
"the",
"flag",
"for",
"the",
"output",
"charset",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1605-L1614 |
23,916 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.shouldGenerateMapPerModule | @GwtIncompatible("Unnecessary")
private boolean shouldGenerateMapPerModule(B options) {
return options.sourceMapOutputPath != null
&& options.sourceMapOutputPath.contains("%outname%");
} | java | @GwtIncompatible("Unnecessary")
private boolean shouldGenerateMapPerModule(B options) {
return options.sourceMapOutputPath != null
&& options.sourceMapOutputPath.contains("%outname%");
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"boolean",
"shouldGenerateMapPerModule",
"(",
"B",
"options",
")",
"{",
"return",
"options",
".",
"sourceMapOutputPath",
"!=",
"null",
"&&",
"options",
".",
"sourceMapOutputPath",
".",
"contains",
"(",
"\"%outname%\"",
")",
";",
"}"
] | Returns true if and only if a source map file should be generated for each module, as opposed
to one unified map. This is specified by having the source map pattern include the %outname%
variable. | [
"Returns",
"true",
"if",
"and",
"only",
"if",
"a",
"source",
"map",
"file",
"should",
"be",
"generated",
"for",
"each",
"module",
"as",
"opposed",
"to",
"one",
"unified",
"map",
".",
"This",
"is",
"specified",
"by",
"having",
"the",
"source",
"map",
"pattern",
"include",
"the",
"%outname%",
"variable",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1643-L1647 |
23,917 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.openExternExportsStream | @GwtIncompatible("Unnecessary")
private Writer openExternExportsStream(B options, String path) throws IOException {
if (options.externExportsPath == null) {
return null;
}
String exPath = options.externExportsPath;
if (!exPath.contains(File.separator)) {
File outputFile = new File(path);
exPath = outputFile.getParent() + File.separatorChar + exPath;
}
return fileNameToOutputWriter2(exPath);
} | java | @GwtIncompatible("Unnecessary")
private Writer openExternExportsStream(B options, String path) throws IOException {
if (options.externExportsPath == null) {
return null;
}
String exPath = options.externExportsPath;
if (!exPath.contains(File.separator)) {
File outputFile = new File(path);
exPath = outputFile.getParent() + File.separatorChar + exPath;
}
return fileNameToOutputWriter2(exPath);
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"Writer",
"openExternExportsStream",
"(",
"B",
"options",
",",
"String",
"path",
")",
"throws",
"IOException",
"{",
"if",
"(",
"options",
".",
"externExportsPath",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"String",
"exPath",
"=",
"options",
".",
"externExportsPath",
";",
"if",
"(",
"!",
"exPath",
".",
"contains",
"(",
"File",
".",
"separator",
")",
")",
"{",
"File",
"outputFile",
"=",
"new",
"File",
"(",
"path",
")",
";",
"exPath",
"=",
"outputFile",
".",
"getParent",
"(",
")",
"+",
"File",
".",
"separatorChar",
"+",
"exPath",
";",
"}",
"return",
"fileNameToOutputWriter2",
"(",
"exPath",
")",
";",
"}"
] | Returns a stream for outputting the generated externs file.
@param options The options to the Compiler.
@param path The path of the generated JS source file.
@return The stream or null if no extern-ed exports are being generated. | [
"Returns",
"a",
"stream",
"for",
"outputting",
"the",
"generated",
"externs",
"file",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1656-L1670 |
23,918 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.expandCommandLinePath | @GwtIncompatible("Unnecessary")
private String expandCommandLinePath(String path, JSModule forModule) {
String sub;
if (forModule != null) {
sub = config.moduleOutputPathPrefix + forModule.getName() + ".js";
} else if (!config.module.isEmpty()) {
sub = config.moduleOutputPathPrefix;
} else {
sub = config.jsOutputFile;
}
return path.replace("%outname%", sub);
} | java | @GwtIncompatible("Unnecessary")
private String expandCommandLinePath(String path, JSModule forModule) {
String sub;
if (forModule != null) {
sub = config.moduleOutputPathPrefix + forModule.getName() + ".js";
} else if (!config.module.isEmpty()) {
sub = config.moduleOutputPathPrefix;
} else {
sub = config.jsOutputFile;
}
return path.replace("%outname%", sub);
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"String",
"expandCommandLinePath",
"(",
"String",
"path",
",",
"JSModule",
"forModule",
")",
"{",
"String",
"sub",
";",
"if",
"(",
"forModule",
"!=",
"null",
")",
"{",
"sub",
"=",
"config",
".",
"moduleOutputPathPrefix",
"+",
"forModule",
".",
"getName",
"(",
")",
"+",
"\".js\"",
";",
"}",
"else",
"if",
"(",
"!",
"config",
".",
"module",
".",
"isEmpty",
"(",
")",
")",
"{",
"sub",
"=",
"config",
".",
"moduleOutputPathPrefix",
";",
"}",
"else",
"{",
"sub",
"=",
"config",
".",
"jsOutputFile",
";",
"}",
"return",
"path",
".",
"replace",
"(",
"\"%outname%\"",
",",
"sub",
")",
";",
"}"
] | Expand a file path specified on the command-line.
<p>Most file paths on the command-line allow an %outname% placeholder. The placeholder will
expand to a different value depending on the current output mode. There are three scenarios:
<p>1) Single JS output, single extra output: sub in jsOutputPath. 2) Multiple JS output, single
extra output: sub in the base module name. 3) Multiple JS output, multiple extra output: sub in
the module output file.
<p>Passing a JSModule to this function automatically triggers case #3. Otherwise, we'll use
strategy #1 or #2 based on the current output mode. | [
"Expand",
"a",
"file",
"path",
"specified",
"on",
"the",
"command",
"-",
"line",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1685-L1696 |
23,919 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.expandSourceMapPath | @VisibleForTesting
@GwtIncompatible("Unnecessary")
String expandSourceMapPath(B options, JSModule forModule) {
if (Strings.isNullOrEmpty(options.sourceMapOutputPath)) {
return null;
}
return expandCommandLinePath(options.sourceMapOutputPath, forModule);
} | java | @VisibleForTesting
@GwtIncompatible("Unnecessary")
String expandSourceMapPath(B options, JSModule forModule) {
if (Strings.isNullOrEmpty(options.sourceMapOutputPath)) {
return null;
}
return expandCommandLinePath(options.sourceMapOutputPath, forModule);
} | [
"@",
"VisibleForTesting",
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"String",
"expandSourceMapPath",
"(",
"B",
"options",
",",
"JSModule",
"forModule",
")",
"{",
"if",
"(",
"Strings",
".",
"isNullOrEmpty",
"(",
"options",
".",
"sourceMapOutputPath",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"expandCommandLinePath",
"(",
"options",
".",
"sourceMapOutputPath",
",",
"forModule",
")",
";",
"}"
] | Expansion function for source map. | [
"Expansion",
"function",
"for",
"source",
"map",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1699-L1706 |
23,920 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.filenameToOutputStream | @GwtIncompatible("Unnecessary")
protected OutputStream filenameToOutputStream(String fileName) throws IOException {
if (fileName == null){
return null;
}
return new FileOutputStream(fileName);
} | java | @GwtIncompatible("Unnecessary")
protected OutputStream filenameToOutputStream(String fileName) throws IOException {
if (fileName == null){
return null;
}
return new FileOutputStream(fileName);
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"protected",
"OutputStream",
"filenameToOutputStream",
"(",
"String",
"fileName",
")",
"throws",
"IOException",
"{",
"if",
"(",
"fileName",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"FileOutputStream",
"(",
"fileName",
")",
";",
"}"
] | Converts a file name into a Outputstream. Returns null if the file name is null. | [
"Converts",
"a",
"file",
"name",
"into",
"a",
"Outputstream",
".",
"Returns",
"null",
"if",
"the",
"file",
"name",
"is",
"null",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1741-L1747 |
23,921 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.streamToLegacyOutputWriter | @GwtIncompatible("Unnecessary")
private Writer streamToLegacyOutputWriter(OutputStream stream) throws IOException {
if (legacyOutputCharset == null) {
return new BufferedWriter(new OutputStreamWriter(stream, UTF_8));
} else {
return new BufferedWriter(
new OutputStreamWriter(stream, legacyOutputCharset));
}
} | java | @GwtIncompatible("Unnecessary")
private Writer streamToLegacyOutputWriter(OutputStream stream) throws IOException {
if (legacyOutputCharset == null) {
return new BufferedWriter(new OutputStreamWriter(stream, UTF_8));
} else {
return new BufferedWriter(
new OutputStreamWriter(stream, legacyOutputCharset));
}
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"Writer",
"streamToLegacyOutputWriter",
"(",
"OutputStream",
"stream",
")",
"throws",
"IOException",
"{",
"if",
"(",
"legacyOutputCharset",
"==",
"null",
")",
"{",
"return",
"new",
"BufferedWriter",
"(",
"new",
"OutputStreamWriter",
"(",
"stream",
",",
"UTF_8",
")",
")",
";",
"}",
"else",
"{",
"return",
"new",
"BufferedWriter",
"(",
"new",
"OutputStreamWriter",
"(",
"stream",
",",
"legacyOutputCharset",
")",
")",
";",
"}",
"}"
] | Create a writer with the legacy output charset. | [
"Create",
"a",
"writer",
"with",
"the",
"legacy",
"output",
"charset",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1750-L1758 |
23,922 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.streamToOutputWriter2 | @GwtIncompatible("Unnecessary")
private Writer streamToOutputWriter2(OutputStream stream) {
if (outputCharset2 == null) {
return new BufferedWriter(new OutputStreamWriter(stream, UTF_8));
} else {
return new BufferedWriter(
new OutputStreamWriter(stream, outputCharset2));
}
} | java | @GwtIncompatible("Unnecessary")
private Writer streamToOutputWriter2(OutputStream stream) {
if (outputCharset2 == null) {
return new BufferedWriter(new OutputStreamWriter(stream, UTF_8));
} else {
return new BufferedWriter(
new OutputStreamWriter(stream, outputCharset2));
}
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"Writer",
"streamToOutputWriter2",
"(",
"OutputStream",
"stream",
")",
"{",
"if",
"(",
"outputCharset2",
"==",
"null",
")",
"{",
"return",
"new",
"BufferedWriter",
"(",
"new",
"OutputStreamWriter",
"(",
"stream",
",",
"UTF_8",
")",
")",
";",
"}",
"else",
"{",
"return",
"new",
"BufferedWriter",
"(",
"new",
"OutputStreamWriter",
"(",
"stream",
",",
"outputCharset2",
")",
")",
";",
"}",
"}"
] | Create a writer with the newer output charset. | [
"Create",
"a",
"writer",
"with",
"the",
"newer",
"output",
"charset",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1761-L1769 |
23,923 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.outputSourceMap | @GwtIncompatible("Unnecessary")
private void outputSourceMap(B options, String associatedName) throws IOException {
if (Strings.isNullOrEmpty(options.sourceMapOutputPath)
|| options.sourceMapOutputPath.equals("/dev/null")) {
return;
}
String outName = expandSourceMapPath(options, null);
maybeCreateDirsForPath(outName);
try (Writer out = fileNameToOutputWriter2(outName)) {
compiler.getSourceMap().appendTo(out, associatedName);
}
} | java | @GwtIncompatible("Unnecessary")
private void outputSourceMap(B options, String associatedName) throws IOException {
if (Strings.isNullOrEmpty(options.sourceMapOutputPath)
|| options.sourceMapOutputPath.equals("/dev/null")) {
return;
}
String outName = expandSourceMapPath(options, null);
maybeCreateDirsForPath(outName);
try (Writer out = fileNameToOutputWriter2(outName)) {
compiler.getSourceMap().appendTo(out, associatedName);
}
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"void",
"outputSourceMap",
"(",
"B",
"options",
",",
"String",
"associatedName",
")",
"throws",
"IOException",
"{",
"if",
"(",
"Strings",
".",
"isNullOrEmpty",
"(",
"options",
".",
"sourceMapOutputPath",
")",
"||",
"options",
".",
"sourceMapOutputPath",
".",
"equals",
"(",
"\"/dev/null\"",
")",
")",
"{",
"return",
";",
"}",
"String",
"outName",
"=",
"expandSourceMapPath",
"(",
"options",
",",
"null",
")",
";",
"maybeCreateDirsForPath",
"(",
"outName",
")",
";",
"try",
"(",
"Writer",
"out",
"=",
"fileNameToOutputWriter2",
"(",
"outName",
")",
")",
"{",
"compiler",
".",
"getSourceMap",
"(",
")",
".",
"appendTo",
"(",
"out",
",",
"associatedName",
")",
";",
"}",
"}"
] | Outputs the source map found in the compiler to the proper path if one exists.
@param options The options to the Compiler. | [
"Outputs",
"the",
"source",
"map",
"found",
"in",
"the",
"compiler",
"to",
"the",
"proper",
"path",
"if",
"one",
"exists",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1776-L1788 |
23,924 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.outputNameMaps | @GwtIncompatible("Unnecessary")
private void outputNameMaps() throws IOException {
String propertyMapOutputPath = null;
String variableMapOutputPath = null;
// Check the create_name_map_files FLAG.
if (config.createNameMapFiles) {
String basePath = getMapPath(config.jsOutputFile);
propertyMapOutputPath = basePath + "_props_map.out";
variableMapOutputPath = basePath + "_vars_map.out";
}
// Check the individual FLAGS.
if (!config.variableMapOutputFile.isEmpty()) {
if (variableMapOutputPath != null) {
throw new FlagUsageException("The flags variable_map_output_file and "
+ "create_name_map_files cannot both be used simultaneously.");
}
variableMapOutputPath = config.variableMapOutputFile;
}
if (!config.propertyMapOutputFile.isEmpty()) {
if (propertyMapOutputPath != null) {
throw new FlagUsageException("The flags property_map_output_file and "
+ "create_name_map_files cannot both be used simultaneously.");
}
propertyMapOutputPath = config.propertyMapOutputFile;
}
// Output the maps.
if (variableMapOutputPath != null && compiler.getVariableMap() != null) {
compiler.getVariableMap().save(variableMapOutputPath);
}
if (propertyMapOutputPath != null && compiler.getPropertyMap() != null) {
compiler.getPropertyMap().save(propertyMapOutputPath);
}
} | java | @GwtIncompatible("Unnecessary")
private void outputNameMaps() throws IOException {
String propertyMapOutputPath = null;
String variableMapOutputPath = null;
// Check the create_name_map_files FLAG.
if (config.createNameMapFiles) {
String basePath = getMapPath(config.jsOutputFile);
propertyMapOutputPath = basePath + "_props_map.out";
variableMapOutputPath = basePath + "_vars_map.out";
}
// Check the individual FLAGS.
if (!config.variableMapOutputFile.isEmpty()) {
if (variableMapOutputPath != null) {
throw new FlagUsageException("The flags variable_map_output_file and "
+ "create_name_map_files cannot both be used simultaneously.");
}
variableMapOutputPath = config.variableMapOutputFile;
}
if (!config.propertyMapOutputFile.isEmpty()) {
if (propertyMapOutputPath != null) {
throw new FlagUsageException("The flags property_map_output_file and "
+ "create_name_map_files cannot both be used simultaneously.");
}
propertyMapOutputPath = config.propertyMapOutputFile;
}
// Output the maps.
if (variableMapOutputPath != null && compiler.getVariableMap() != null) {
compiler.getVariableMap().save(variableMapOutputPath);
}
if (propertyMapOutputPath != null && compiler.getPropertyMap() != null) {
compiler.getPropertyMap().save(propertyMapOutputPath);
}
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"void",
"outputNameMaps",
"(",
")",
"throws",
"IOException",
"{",
"String",
"propertyMapOutputPath",
"=",
"null",
";",
"String",
"variableMapOutputPath",
"=",
"null",
";",
"// Check the create_name_map_files FLAG.",
"if",
"(",
"config",
".",
"createNameMapFiles",
")",
"{",
"String",
"basePath",
"=",
"getMapPath",
"(",
"config",
".",
"jsOutputFile",
")",
";",
"propertyMapOutputPath",
"=",
"basePath",
"+",
"\"_props_map.out\"",
";",
"variableMapOutputPath",
"=",
"basePath",
"+",
"\"_vars_map.out\"",
";",
"}",
"// Check the individual FLAGS.",
"if",
"(",
"!",
"config",
".",
"variableMapOutputFile",
".",
"isEmpty",
"(",
")",
")",
"{",
"if",
"(",
"variableMapOutputPath",
"!=",
"null",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"The flags variable_map_output_file and \"",
"+",
"\"create_name_map_files cannot both be used simultaneously.\"",
")",
";",
"}",
"variableMapOutputPath",
"=",
"config",
".",
"variableMapOutputFile",
";",
"}",
"if",
"(",
"!",
"config",
".",
"propertyMapOutputFile",
".",
"isEmpty",
"(",
")",
")",
"{",
"if",
"(",
"propertyMapOutputPath",
"!=",
"null",
")",
"{",
"throw",
"new",
"FlagUsageException",
"(",
"\"The flags property_map_output_file and \"",
"+",
"\"create_name_map_files cannot both be used simultaneously.\"",
")",
";",
"}",
"propertyMapOutputPath",
"=",
"config",
".",
"propertyMapOutputFile",
";",
"}",
"// Output the maps.",
"if",
"(",
"variableMapOutputPath",
"!=",
"null",
"&&",
"compiler",
".",
"getVariableMap",
"(",
")",
"!=",
"null",
")",
"{",
"compiler",
".",
"getVariableMap",
"(",
")",
".",
"save",
"(",
"variableMapOutputPath",
")",
";",
"}",
"if",
"(",
"propertyMapOutputPath",
"!=",
"null",
"&&",
"compiler",
".",
"getPropertyMap",
"(",
")",
"!=",
"null",
")",
"{",
"compiler",
".",
"getPropertyMap",
"(",
")",
".",
"save",
"(",
"propertyMapOutputPath",
")",
";",
"}",
"}"
] | Outputs the variable and property name maps for the specified compiler if the proper FLAGS are
set. | [
"Outputs",
"the",
"variable",
"and",
"property",
"name",
"maps",
"for",
"the",
"specified",
"compiler",
"if",
"the",
"proper",
"FLAGS",
"are",
"set",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1835-L1876 |
23,925 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.createDefineOrTweakReplacements | @VisibleForTesting
public static void createDefineOrTweakReplacements(
List<String> definitions, CompilerOptions options, boolean tweaks) {
// Parse the definitions
for (String override : definitions) {
String[] assignment = override.split("=", 2);
String defName = assignment[0];
if (defName.length() > 0) {
String defValue = assignment.length == 1 ? "true" : assignment[1];
boolean isTrue = defValue.equals("true");
boolean isFalse = defValue.equals("false");
if (isTrue || isFalse) {
if (tweaks) {
options.setTweakToBooleanLiteral(defName, isTrue);
} else {
options.setDefineToBooleanLiteral(defName, isTrue);
}
continue;
} else if (defValue.length() > 1
&& ((defValue.charAt(0) == '\'' &&
defValue.charAt(defValue.length() - 1) == '\'')
|| (defValue.charAt(0) == '\"' &&
defValue.charAt(defValue.length() - 1) == '\"'))) {
// If the value starts and ends with a single quote,
// we assume that it's a string.
String maybeStringVal =
defValue.substring(1, defValue.length() - 1);
if (maybeStringVal.indexOf(defValue.charAt(0)) == -1) {
if (tweaks) {
options.setTweakToStringLiteral(defName, maybeStringVal);
} else {
options.setDefineToStringLiteral(defName, maybeStringVal);
}
continue;
}
} else {
try {
double value = Double.parseDouble(defValue);
if (tweaks) {
options.setTweakToDoubleLiteral(defName, value);
} else {
options.setDefineToDoubleLiteral(defName, value);
}
continue;
} catch (NumberFormatException e) {
// do nothing, it will be caught at the end
}
if (defValue.length() > 0) {
if (tweaks) {
options.setTweakToStringLiteral(defName, defValue);
} else {
options.setDefineToStringLiteral(defName, defValue);
}
continue;
}
}
}
if (tweaks) {
throw new RuntimeException(
"--tweak flag syntax invalid: " + override);
}
throw new RuntimeException(
"--define flag syntax invalid: " + override);
}
} | java | @VisibleForTesting
public static void createDefineOrTweakReplacements(
List<String> definitions, CompilerOptions options, boolean tweaks) {
// Parse the definitions
for (String override : definitions) {
String[] assignment = override.split("=", 2);
String defName = assignment[0];
if (defName.length() > 0) {
String defValue = assignment.length == 1 ? "true" : assignment[1];
boolean isTrue = defValue.equals("true");
boolean isFalse = defValue.equals("false");
if (isTrue || isFalse) {
if (tweaks) {
options.setTweakToBooleanLiteral(defName, isTrue);
} else {
options.setDefineToBooleanLiteral(defName, isTrue);
}
continue;
} else if (defValue.length() > 1
&& ((defValue.charAt(0) == '\'' &&
defValue.charAt(defValue.length() - 1) == '\'')
|| (defValue.charAt(0) == '\"' &&
defValue.charAt(defValue.length() - 1) == '\"'))) {
// If the value starts and ends with a single quote,
// we assume that it's a string.
String maybeStringVal =
defValue.substring(1, defValue.length() - 1);
if (maybeStringVal.indexOf(defValue.charAt(0)) == -1) {
if (tweaks) {
options.setTweakToStringLiteral(defName, maybeStringVal);
} else {
options.setDefineToStringLiteral(defName, maybeStringVal);
}
continue;
}
} else {
try {
double value = Double.parseDouble(defValue);
if (tweaks) {
options.setTweakToDoubleLiteral(defName, value);
} else {
options.setDefineToDoubleLiteral(defName, value);
}
continue;
} catch (NumberFormatException e) {
// do nothing, it will be caught at the end
}
if (defValue.length() > 0) {
if (tweaks) {
options.setTweakToStringLiteral(defName, defValue);
} else {
options.setDefineToStringLiteral(defName, defValue);
}
continue;
}
}
}
if (tweaks) {
throw new RuntimeException(
"--tweak flag syntax invalid: " + override);
}
throw new RuntimeException(
"--define flag syntax invalid: " + override);
}
} | [
"@",
"VisibleForTesting",
"public",
"static",
"void",
"createDefineOrTweakReplacements",
"(",
"List",
"<",
"String",
">",
"definitions",
",",
"CompilerOptions",
"options",
",",
"boolean",
"tweaks",
")",
"{",
"// Parse the definitions",
"for",
"(",
"String",
"override",
":",
"definitions",
")",
"{",
"String",
"[",
"]",
"assignment",
"=",
"override",
".",
"split",
"(",
"\"=\"",
",",
"2",
")",
";",
"String",
"defName",
"=",
"assignment",
"[",
"0",
"]",
";",
"if",
"(",
"defName",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"String",
"defValue",
"=",
"assignment",
".",
"length",
"==",
"1",
"?",
"\"true\"",
":",
"assignment",
"[",
"1",
"]",
";",
"boolean",
"isTrue",
"=",
"defValue",
".",
"equals",
"(",
"\"true\"",
")",
";",
"boolean",
"isFalse",
"=",
"defValue",
".",
"equals",
"(",
"\"false\"",
")",
";",
"if",
"(",
"isTrue",
"||",
"isFalse",
")",
"{",
"if",
"(",
"tweaks",
")",
"{",
"options",
".",
"setTweakToBooleanLiteral",
"(",
"defName",
",",
"isTrue",
")",
";",
"}",
"else",
"{",
"options",
".",
"setDefineToBooleanLiteral",
"(",
"defName",
",",
"isTrue",
")",
";",
"}",
"continue",
";",
"}",
"else",
"if",
"(",
"defValue",
".",
"length",
"(",
")",
">",
"1",
"&&",
"(",
"(",
"defValue",
".",
"charAt",
"(",
"0",
")",
"==",
"'",
"'",
"&&",
"defValue",
".",
"charAt",
"(",
"defValue",
".",
"length",
"(",
")",
"-",
"1",
")",
"==",
"'",
"'",
")",
"||",
"(",
"defValue",
".",
"charAt",
"(",
"0",
")",
"==",
"'",
"'",
"&&",
"defValue",
".",
"charAt",
"(",
"defValue",
".",
"length",
"(",
")",
"-",
"1",
")",
"==",
"'",
"'",
")",
")",
")",
"{",
"// If the value starts and ends with a single quote,",
"// we assume that it's a string.",
"String",
"maybeStringVal",
"=",
"defValue",
".",
"substring",
"(",
"1",
",",
"defValue",
".",
"length",
"(",
")",
"-",
"1",
")",
";",
"if",
"(",
"maybeStringVal",
".",
"indexOf",
"(",
"defValue",
".",
"charAt",
"(",
"0",
")",
")",
"==",
"-",
"1",
")",
"{",
"if",
"(",
"tweaks",
")",
"{",
"options",
".",
"setTweakToStringLiteral",
"(",
"defName",
",",
"maybeStringVal",
")",
";",
"}",
"else",
"{",
"options",
".",
"setDefineToStringLiteral",
"(",
"defName",
",",
"maybeStringVal",
")",
";",
"}",
"continue",
";",
"}",
"}",
"else",
"{",
"try",
"{",
"double",
"value",
"=",
"Double",
".",
"parseDouble",
"(",
"defValue",
")",
";",
"if",
"(",
"tweaks",
")",
"{",
"options",
".",
"setTweakToDoubleLiteral",
"(",
"defName",
",",
"value",
")",
";",
"}",
"else",
"{",
"options",
".",
"setDefineToDoubleLiteral",
"(",
"defName",
",",
"value",
")",
";",
"}",
"continue",
";",
"}",
"catch",
"(",
"NumberFormatException",
"e",
")",
"{",
"// do nothing, it will be caught at the end",
"}",
"if",
"(",
"defValue",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"if",
"(",
"tweaks",
")",
"{",
"options",
".",
"setTweakToStringLiteral",
"(",
"defName",
",",
"defValue",
")",
";",
"}",
"else",
"{",
"options",
".",
"setDefineToStringLiteral",
"(",
"defName",
",",
"defValue",
")",
";",
"}",
"continue",
";",
"}",
"}",
"}",
"if",
"(",
"tweaks",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"--tweak flag syntax invalid: \"",
"+",
"override",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"--define flag syntax invalid: \"",
"+",
"override",
")",
";",
"}",
"}"
] | Create a map of constant names to constant values from a textual description of the map.
@param definitions A list of overriding definitions for defines in the form {@code
<name>[=<val>]}, where {@code <val>} is a number, boolean, or single-quoted string without
single quotes. | [
"Create",
"a",
"map",
"of",
"constant",
"names",
"to",
"constant",
"values",
"from",
"a",
"textual",
"description",
"of",
"the",
"map",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1903-L1971 |
23,926 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.shouldGenerateOutputPerModule | @GwtIncompatible("Unnecessary")
private boolean shouldGenerateOutputPerModule(String output) {
return !config.module.isEmpty()
&& output != null && output.contains("%outname%");
} | java | @GwtIncompatible("Unnecessary")
private boolean shouldGenerateOutputPerModule(String output) {
return !config.module.isEmpty()
&& output != null && output.contains("%outname%");
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"boolean",
"shouldGenerateOutputPerModule",
"(",
"String",
"output",
")",
"{",
"return",
"!",
"config",
".",
"module",
".",
"isEmpty",
"(",
")",
"&&",
"output",
"!=",
"null",
"&&",
"output",
".",
"contains",
"(",
"\"%outname%\"",
")",
";",
"}"
] | Returns true if and only if a manifest or bundle should be generated for each module, as
opposed to one unified manifest. | [
"Returns",
"true",
"if",
"and",
"only",
"if",
"a",
"manifest",
"or",
"bundle",
"should",
"be",
"generated",
"for",
"each",
"module",
"as",
"opposed",
"to",
"one",
"unified",
"manifest",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L1977-L1981 |
23,927 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.outputModuleGraphJson | @GwtIncompatible("Unnecessary")
private void outputModuleGraphJson() throws IOException {
if (config.outputModuleDependencies != null &&
config.outputModuleDependencies.length() != 0) {
try (Writer out = fileNameToOutputWriter2(config.outputModuleDependencies)) {
printModuleGraphJsonTo(out);
}
}
} | java | @GwtIncompatible("Unnecessary")
private void outputModuleGraphJson() throws IOException {
if (config.outputModuleDependencies != null &&
config.outputModuleDependencies.length() != 0) {
try (Writer out = fileNameToOutputWriter2(config.outputModuleDependencies)) {
printModuleGraphJsonTo(out);
}
}
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"void",
"outputModuleGraphJson",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"config",
".",
"outputModuleDependencies",
"!=",
"null",
"&&",
"config",
".",
"outputModuleDependencies",
".",
"length",
"(",
")",
"!=",
"0",
")",
"{",
"try",
"(",
"Writer",
"out",
"=",
"fileNameToOutputWriter2",
"(",
"config",
".",
"outputModuleDependencies",
")",
")",
"{",
"printModuleGraphJsonTo",
"(",
"out",
")",
";",
"}",
"}",
"}"
] | Creates a file containing the current module graph in JSON serialization. | [
"Creates",
"a",
"file",
"containing",
"the",
"current",
"module",
"graph",
"in",
"JSON",
"serialization",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L2039-L2047 |
23,928 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.printModuleGraphJsonTo | @VisibleForTesting
@GwtIncompatible("Unnecessary")
void printModuleGraphJsonTo(Appendable out) throws IOException {
out.append(compiler.getModuleGraph().toJson().toString());
} | java | @VisibleForTesting
@GwtIncompatible("Unnecessary")
void printModuleGraphJsonTo(Appendable out) throws IOException {
out.append(compiler.getModuleGraph().toJson().toString());
} | [
"@",
"VisibleForTesting",
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"void",
"printModuleGraphJsonTo",
"(",
"Appendable",
"out",
")",
"throws",
"IOException",
"{",
"out",
".",
"append",
"(",
"compiler",
".",
"getModuleGraph",
"(",
")",
".",
"toJson",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"}"
] | Prints the current module graph as JSON. | [
"Prints",
"the",
"current",
"module",
"graph",
"as",
"JSON",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L2050-L2054 |
23,929 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.printModuleGraphManifestOrBundleTo | @VisibleForTesting
@GwtIncompatible("Unnecessary")
void printModuleGraphManifestOrBundleTo(JSModuleGraph graph, Appendable out, boolean isManifest)
throws IOException {
Joiner commas = Joiner.on(",");
boolean requiresNewline = false;
for (JSModule module : graph.getAllModules()) {
if (requiresNewline) {
out.append("\n");
}
if (isManifest) {
// See CommandLineRunnerTest to see what the format of this
// manifest looks like.
String dependencies = commas.join(module.getSortedDependencyNames());
out.append(
String.format("{%s%s}\n",
module.getName(),
dependencies.isEmpty() ? "" : ":" + dependencies));
printManifestTo(module.getInputs(), out);
} else {
printBundleTo(module.getInputs(), out);
}
requiresNewline = true;
}
} | java | @VisibleForTesting
@GwtIncompatible("Unnecessary")
void printModuleGraphManifestOrBundleTo(JSModuleGraph graph, Appendable out, boolean isManifest)
throws IOException {
Joiner commas = Joiner.on(",");
boolean requiresNewline = false;
for (JSModule module : graph.getAllModules()) {
if (requiresNewline) {
out.append("\n");
}
if (isManifest) {
// See CommandLineRunnerTest to see what the format of this
// manifest looks like.
String dependencies = commas.join(module.getSortedDependencyNames());
out.append(
String.format("{%s%s}\n",
module.getName(),
dependencies.isEmpty() ? "" : ":" + dependencies));
printManifestTo(module.getInputs(), out);
} else {
printBundleTo(module.getInputs(), out);
}
requiresNewline = true;
}
} | [
"@",
"VisibleForTesting",
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"void",
"printModuleGraphManifestOrBundleTo",
"(",
"JSModuleGraph",
"graph",
",",
"Appendable",
"out",
",",
"boolean",
"isManifest",
")",
"throws",
"IOException",
"{",
"Joiner",
"commas",
"=",
"Joiner",
".",
"on",
"(",
"\",\"",
")",
";",
"boolean",
"requiresNewline",
"=",
"false",
";",
"for",
"(",
"JSModule",
"module",
":",
"graph",
".",
"getAllModules",
"(",
")",
")",
"{",
"if",
"(",
"requiresNewline",
")",
"{",
"out",
".",
"append",
"(",
"\"\\n\"",
")",
";",
"}",
"if",
"(",
"isManifest",
")",
"{",
"// See CommandLineRunnerTest to see what the format of this",
"// manifest looks like.",
"String",
"dependencies",
"=",
"commas",
".",
"join",
"(",
"module",
".",
"getSortedDependencyNames",
"(",
")",
")",
";",
"out",
".",
"append",
"(",
"String",
".",
"format",
"(",
"\"{%s%s}\\n\"",
",",
"module",
".",
"getName",
"(",
")",
",",
"dependencies",
".",
"isEmpty",
"(",
")",
"?",
"\"\"",
":",
"\":\"",
"+",
"dependencies",
")",
")",
";",
"printManifestTo",
"(",
"module",
".",
"getInputs",
"(",
")",
",",
"out",
")",
";",
"}",
"else",
"{",
"printBundleTo",
"(",
"module",
".",
"getInputs",
"(",
")",
",",
"out",
")",
";",
"}",
"requiresNewline",
"=",
"true",
";",
"}",
"}"
] | Prints a set of modules to the manifest or bundle file. | [
"Prints",
"a",
"set",
"of",
"modules",
"to",
"the",
"manifest",
"or",
"bundle",
"file",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L2057-L2082 |
23,930 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractCommandLineRunner.java | AbstractCommandLineRunner.constructRootRelativePathsMap | @GwtIncompatible("Unnecessary")
private Map<String, String> constructRootRelativePathsMap() {
Map<String, String> rootRelativePathsMap = new LinkedHashMap<>();
for (String mapString : config.manifestMaps) {
int colonIndex = mapString.indexOf(':');
checkState(colonIndex > 0);
String execPath = mapString.substring(0, colonIndex);
String rootRelativePath = mapString.substring(colonIndex + 1);
checkState(rootRelativePath.indexOf(':') == -1);
rootRelativePathsMap.put(execPath, rootRelativePath);
}
return rootRelativePathsMap;
} | java | @GwtIncompatible("Unnecessary")
private Map<String, String> constructRootRelativePathsMap() {
Map<String, String> rootRelativePathsMap = new LinkedHashMap<>();
for (String mapString : config.manifestMaps) {
int colonIndex = mapString.indexOf(':');
checkState(colonIndex > 0);
String execPath = mapString.substring(0, colonIndex);
String rootRelativePath = mapString.substring(colonIndex + 1);
checkState(rootRelativePath.indexOf(':') == -1);
rootRelativePathsMap.put(execPath, rootRelativePath);
}
return rootRelativePathsMap;
} | [
"@",
"GwtIncompatible",
"(",
"\"Unnecessary\"",
")",
"private",
"Map",
"<",
"String",
",",
"String",
">",
"constructRootRelativePathsMap",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"String",
">",
"rootRelativePathsMap",
"=",
"new",
"LinkedHashMap",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"mapString",
":",
"config",
".",
"manifestMaps",
")",
"{",
"int",
"colonIndex",
"=",
"mapString",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"checkState",
"(",
"colonIndex",
">",
"0",
")",
";",
"String",
"execPath",
"=",
"mapString",
".",
"substring",
"(",
"0",
",",
"colonIndex",
")",
";",
"String",
"rootRelativePath",
"=",
"mapString",
".",
"substring",
"(",
"colonIndex",
"+",
"1",
")",
";",
"checkState",
"(",
"rootRelativePath",
".",
"indexOf",
"(",
"'",
"'",
")",
"==",
"-",
"1",
")",
";",
"rootRelativePathsMap",
".",
"put",
"(",
"execPath",
",",
"rootRelativePath",
")",
";",
"}",
"return",
"rootRelativePathsMap",
";",
"}"
] | Construct and return the input root path map. The key is the exec path of each input file, and
the value is the corresponding root relative path. | [
"Construct",
"and",
"return",
"the",
"input",
"root",
"path",
"map",
".",
"The",
"key",
"is",
"the",
"exec",
"path",
"of",
"each",
"input",
"file",
"and",
"the",
"value",
"is",
"the",
"corresponding",
"root",
"relative",
"path",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java#L2154-L2166 |
23,931 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectValidTypeofName | void expectValidTypeofName(Node n, String found) {
report(JSError.make(n, UNKNOWN_TYPEOF_VALUE, found));
} | java | void expectValidTypeofName(Node n, String found) {
report(JSError.make(n, UNKNOWN_TYPEOF_VALUE, found));
} | [
"void",
"expectValidTypeofName",
"(",
"Node",
"n",
",",
"String",
"found",
")",
"{",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"UNKNOWN_TYPEOF_VALUE",
",",
"found",
")",
")",
";",
"}"
] | a warning and attempt to correct the mismatch, when possible. | [
"a",
"warning",
"and",
"attempt",
"to",
"correct",
"the",
"mismatch",
"when",
"possible",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L239-L241 |
23,932 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectObject | boolean expectObject(Node n, JSType type, String msg) {
if (!type.matchesObjectContext()) {
mismatch(n, msg, type, OBJECT_TYPE);
return false;
}
return true;
} | java | boolean expectObject(Node n, JSType type, String msg) {
if (!type.matchesObjectContext()) {
mismatch(n, msg, type, OBJECT_TYPE);
return false;
}
return true;
} | [
"boolean",
"expectObject",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"type",
".",
"matchesObjectContext",
"(",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"OBJECT_TYPE",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Expect the type to be an object, or a type convertible to object. If the expectation is not
met, issue a warning at the provided node's source code position.
@return True if there was no warning, false if there was a mismatch. | [
"Expect",
"the",
"type",
"to",
"be",
"an",
"object",
"or",
"a",
"type",
"convertible",
"to",
"object",
".",
"If",
"the",
"expectation",
"is",
"not",
"met",
"issue",
"a",
"warning",
"at",
"the",
"provided",
"node",
"s",
"source",
"code",
"position",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L249-L255 |
23,933 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectActualObject | void expectActualObject(Node n, JSType type, String msg) {
if (!type.isObject()) {
mismatch(n, msg, type, OBJECT_TYPE);
}
} | java | void expectActualObject(Node n, JSType type, String msg) {
if (!type.isObject()) {
mismatch(n, msg, type, OBJECT_TYPE);
}
} | [
"void",
"expectActualObject",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"type",
".",
"isObject",
"(",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"OBJECT_TYPE",
")",
";",
"}",
"}"
] | Expect the type to be an object. Unlike expectObject, a type convertible to object is not
acceptable. | [
"Expect",
"the",
"type",
"to",
"be",
"an",
"object",
".",
"Unlike",
"expectObject",
"a",
"type",
"convertible",
"to",
"object",
"is",
"not",
"acceptable",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L261-L265 |
23,934 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectAnyObject | void expectAnyObject(Node n, JSType type, String msg) {
JSType anyObjectType = getNativeType(NO_OBJECT_TYPE);
if (!anyObjectType.isSubtypeOf(type) && !type.isEmptyType()) {
mismatch(n, msg, type, anyObjectType);
}
} | java | void expectAnyObject(Node n, JSType type, String msg) {
JSType anyObjectType = getNativeType(NO_OBJECT_TYPE);
if (!anyObjectType.isSubtypeOf(type) && !type.isEmptyType()) {
mismatch(n, msg, type, anyObjectType);
}
} | [
"void",
"expectAnyObject",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"JSType",
"anyObjectType",
"=",
"getNativeType",
"(",
"NO_OBJECT_TYPE",
")",
";",
"if",
"(",
"!",
"anyObjectType",
".",
"isSubtypeOf",
"(",
"type",
")",
"&&",
"!",
"type",
".",
"isEmptyType",
"(",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"anyObjectType",
")",
";",
"}",
"}"
] | Expect the type to contain an object sometimes. If the expectation is not met, issue a warning
at the provided node's source code position. | [
"Expect",
"the",
"type",
"to",
"contain",
"an",
"object",
"sometimes",
".",
"If",
"the",
"expectation",
"is",
"not",
"met",
"issue",
"a",
"warning",
"at",
"the",
"provided",
"node",
"s",
"source",
"code",
"position",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L271-L276 |
23,935 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectAutoboxesToIterable | boolean expectAutoboxesToIterable(Node n, JSType type, String msg) {
// Note: we don't just use JSType.autobox() here because that removes null and undefined.
// We want to keep null and undefined around.
if (type.isUnionType()) {
for (JSType alt : type.toMaybeUnionType().getAlternates()) {
alt = alt.isBoxableScalar() ? alt.autoboxesTo() : alt;
if (!alt.isSubtypeOf(getNativeType(ITERABLE_TYPE))) {
mismatch(n, msg, type, ITERABLE_TYPE);
return false;
}
}
} else {
JSType autoboxedType = type.isBoxableScalar() ? type.autoboxesTo() : type;
if (!autoboxedType.isSubtypeOf(getNativeType(ITERABLE_TYPE))) {
mismatch(n, msg, type, ITERABLE_TYPE);
return false;
}
}
return true;
} | java | boolean expectAutoboxesToIterable(Node n, JSType type, String msg) {
// Note: we don't just use JSType.autobox() here because that removes null and undefined.
// We want to keep null and undefined around.
if (type.isUnionType()) {
for (JSType alt : type.toMaybeUnionType().getAlternates()) {
alt = alt.isBoxableScalar() ? alt.autoboxesTo() : alt;
if (!alt.isSubtypeOf(getNativeType(ITERABLE_TYPE))) {
mismatch(n, msg, type, ITERABLE_TYPE);
return false;
}
}
} else {
JSType autoboxedType = type.isBoxableScalar() ? type.autoboxesTo() : type;
if (!autoboxedType.isSubtypeOf(getNativeType(ITERABLE_TYPE))) {
mismatch(n, msg, type, ITERABLE_TYPE);
return false;
}
}
return true;
} | [
"boolean",
"expectAutoboxesToIterable",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"// Note: we don't just use JSType.autobox() here because that removes null and undefined.",
"// We want to keep null and undefined around.",
"if",
"(",
"type",
".",
"isUnionType",
"(",
")",
")",
"{",
"for",
"(",
"JSType",
"alt",
":",
"type",
".",
"toMaybeUnionType",
"(",
")",
".",
"getAlternates",
"(",
")",
")",
"{",
"alt",
"=",
"alt",
".",
"isBoxableScalar",
"(",
")",
"?",
"alt",
".",
"autoboxesTo",
"(",
")",
":",
"alt",
";",
"if",
"(",
"!",
"alt",
".",
"isSubtypeOf",
"(",
"getNativeType",
"(",
"ITERABLE_TYPE",
")",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"ITERABLE_TYPE",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"JSType",
"autoboxedType",
"=",
"type",
".",
"isBoxableScalar",
"(",
")",
"?",
"type",
".",
"autoboxesTo",
"(",
")",
":",
"type",
";",
"if",
"(",
"!",
"autoboxedType",
".",
"isSubtypeOf",
"(",
"getNativeType",
"(",
"ITERABLE_TYPE",
")",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"ITERABLE_TYPE",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Expect the type to autobox to be an Iterable.
@return True if there was no warning, false if there was a mismatch. | [
"Expect",
"the",
"type",
"to",
"autobox",
"to",
"be",
"an",
"Iterable",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L282-L302 |
23,936 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectAutoboxesToIterableOrAsyncIterable | Optional<JSType> expectAutoboxesToIterableOrAsyncIterable(Node n, JSType type, String msg) {
MaybeBoxedIterableOrAsyncIterable maybeBoxed =
JsIterables.maybeBoxIterableOrAsyncIterable(type, typeRegistry);
if (maybeBoxed.isMatch()) {
return Optional.of(maybeBoxed.getTemplatedType());
}
mismatch(n, msg, type, iterableOrAsyncIterable);
return Optional.empty();
} | java | Optional<JSType> expectAutoboxesToIterableOrAsyncIterable(Node n, JSType type, String msg) {
MaybeBoxedIterableOrAsyncIterable maybeBoxed =
JsIterables.maybeBoxIterableOrAsyncIterable(type, typeRegistry);
if (maybeBoxed.isMatch()) {
return Optional.of(maybeBoxed.getTemplatedType());
}
mismatch(n, msg, type, iterableOrAsyncIterable);
return Optional.empty();
} | [
"Optional",
"<",
"JSType",
">",
"expectAutoboxesToIterableOrAsyncIterable",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"MaybeBoxedIterableOrAsyncIterable",
"maybeBoxed",
"=",
"JsIterables",
".",
"maybeBoxIterableOrAsyncIterable",
"(",
"type",
",",
"typeRegistry",
")",
";",
"if",
"(",
"maybeBoxed",
".",
"isMatch",
"(",
")",
")",
"{",
"return",
"Optional",
".",
"of",
"(",
"maybeBoxed",
".",
"getTemplatedType",
"(",
")",
")",
";",
"}",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"iterableOrAsyncIterable",
")",
";",
"return",
"Optional",
".",
"empty",
"(",
")",
";",
"}"
] | Expect the type to autobox to be an Iterable or AsyncIterable.
@return The unwrapped variants of the iterable(s), or empty if not iterable. | [
"Expect",
"the",
"type",
"to",
"autobox",
"to",
"be",
"an",
"Iterable",
"or",
"AsyncIterable",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L309-L320 |
23,937 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectGeneratorSupertype | void expectGeneratorSupertype(Node n, JSType type, String msg) {
if (!getNativeType(GENERATOR_TYPE).isSubtypeOf(type)) {
mismatch(n, msg, type, GENERATOR_TYPE);
}
} | java | void expectGeneratorSupertype(Node n, JSType type, String msg) {
if (!getNativeType(GENERATOR_TYPE).isSubtypeOf(type)) {
mismatch(n, msg, type, GENERATOR_TYPE);
}
} | [
"void",
"expectGeneratorSupertype",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"getNativeType",
"(",
"GENERATOR_TYPE",
")",
".",
"isSubtypeOf",
"(",
"type",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"GENERATOR_TYPE",
")",
";",
"}",
"}"
] | Expect the type to be a Generator or supertype of Generator. | [
"Expect",
"the",
"type",
"to",
"be",
"a",
"Generator",
"or",
"supertype",
"of",
"Generator",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L323-L327 |
23,938 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectAsyncGeneratorSupertype | void expectAsyncGeneratorSupertype(Node n, JSType type, String msg) {
if (!getNativeType(ASYNC_GENERATOR_TYPE).isSubtypeOf(type)) {
mismatch(n, msg, type, ASYNC_GENERATOR_TYPE);
}
} | java | void expectAsyncGeneratorSupertype(Node n, JSType type, String msg) {
if (!getNativeType(ASYNC_GENERATOR_TYPE).isSubtypeOf(type)) {
mismatch(n, msg, type, ASYNC_GENERATOR_TYPE);
}
} | [
"void",
"expectAsyncGeneratorSupertype",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"getNativeType",
"(",
"ASYNC_GENERATOR_TYPE",
")",
".",
"isSubtypeOf",
"(",
"type",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"ASYNC_GENERATOR_TYPE",
")",
";",
"}",
"}"
] | Expect the type to be a AsyncGenerator or supertype of AsyncGenerator. | [
"Expect",
"the",
"type",
"to",
"be",
"a",
"AsyncGenerator",
"or",
"supertype",
"of",
"AsyncGenerator",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L330-L334 |
23,939 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectValidAsyncReturnType | void expectValidAsyncReturnType(Node n, JSType type) {
if (promiseOfUnknownType.isSubtypeOf(type)) {
return;
}
JSError err = JSError.make(n, INVALID_ASYNC_RETURN_TYPE, type.toString());
registerMismatch(type, promiseOfUnknownType, err);
report(err);
} | java | void expectValidAsyncReturnType(Node n, JSType type) {
if (promiseOfUnknownType.isSubtypeOf(type)) {
return;
}
JSError err = JSError.make(n, INVALID_ASYNC_RETURN_TYPE, type.toString());
registerMismatch(type, promiseOfUnknownType, err);
report(err);
} | [
"void",
"expectValidAsyncReturnType",
"(",
"Node",
"n",
",",
"JSType",
"type",
")",
"{",
"if",
"(",
"promiseOfUnknownType",
".",
"isSubtypeOf",
"(",
"type",
")",
")",
"{",
"return",
";",
"}",
"JSError",
"err",
"=",
"JSError",
".",
"make",
"(",
"n",
",",
"INVALID_ASYNC_RETURN_TYPE",
",",
"type",
".",
"toString",
"(",
")",
")",
";",
"registerMismatch",
"(",
"type",
",",
"promiseOfUnknownType",
",",
"err",
")",
";",
"report",
"(",
"err",
")",
";",
"}"
] | Expect the type to be a supertype of `Promise`.
<p>`Promise` is the <em>lower</em> bound of the declared return type, since that's what async
functions always return; the user can't return an instance of a more specific type. | [
"Expect",
"the",
"type",
"to",
"be",
"a",
"supertype",
"of",
"Promise",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L342-L350 |
23,940 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectITemplateArraySupertype | void expectITemplateArraySupertype(Node n, JSType type, String msg) {
if (!getNativeType(I_TEMPLATE_ARRAY_TYPE).isSubtypeOf(type)) {
mismatch(n, msg, type, I_TEMPLATE_ARRAY_TYPE);
}
} | java | void expectITemplateArraySupertype(Node n, JSType type, String msg) {
if (!getNativeType(I_TEMPLATE_ARRAY_TYPE).isSubtypeOf(type)) {
mismatch(n, msg, type, I_TEMPLATE_ARRAY_TYPE);
}
} | [
"void",
"expectITemplateArraySupertype",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"getNativeType",
"(",
"I_TEMPLATE_ARRAY_TYPE",
")",
".",
"isSubtypeOf",
"(",
"type",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"I_TEMPLATE_ARRAY_TYPE",
")",
";",
"}",
"}"
] | Expect the type to be an ITemplateArray or supertype of ITemplateArray. | [
"Expect",
"the",
"type",
"to",
"be",
"an",
"ITemplateArray",
"or",
"supertype",
"of",
"ITemplateArray",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L353-L357 |
23,941 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectString | void expectString(Node n, JSType type, String msg) {
if (!type.matchesStringContext()) {
mismatch(n, msg, type, STRING_TYPE);
}
} | java | void expectString(Node n, JSType type, String msg) {
if (!type.matchesStringContext()) {
mismatch(n, msg, type, STRING_TYPE);
}
} | [
"void",
"expectString",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"type",
".",
"matchesStringContext",
"(",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"STRING_TYPE",
")",
";",
"}",
"}"
] | Expect the type to be a string, or a type convertible to string. If the expectation is not met,
issue a warning at the provided node's source code position. | [
"Expect",
"the",
"type",
"to",
"be",
"a",
"string",
"or",
"a",
"type",
"convertible",
"to",
"string",
".",
"If",
"the",
"expectation",
"is",
"not",
"met",
"issue",
"a",
"warning",
"at",
"the",
"provided",
"node",
"s",
"source",
"code",
"position",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L363-L367 |
23,942 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectNumber | void expectNumber(Node n, JSType type, String msg) {
if (!type.matchesNumberContext()) {
mismatch(n, msg, type, NUMBER_TYPE);
} else {
expectNumberStrict(n, type, msg);
}
} | java | void expectNumber(Node n, JSType type, String msg) {
if (!type.matchesNumberContext()) {
mismatch(n, msg, type, NUMBER_TYPE);
} else {
expectNumberStrict(n, type, msg);
}
} | [
"void",
"expectNumber",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"type",
".",
"matchesNumberContext",
"(",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"NUMBER_TYPE",
")",
";",
"}",
"else",
"{",
"expectNumberStrict",
"(",
"n",
",",
"type",
",",
"msg",
")",
";",
"}",
"}"
] | Expect the type to be a number, or a type convertible to number. If the expectation is not met,
issue a warning at the provided node's source code position. | [
"Expect",
"the",
"type",
"to",
"be",
"a",
"number",
"or",
"a",
"type",
"convertible",
"to",
"number",
".",
"If",
"the",
"expectation",
"is",
"not",
"met",
"issue",
"a",
"warning",
"at",
"the",
"provided",
"node",
"s",
"source",
"code",
"position",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L373-L379 |
23,943 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectNumberStrict | void expectNumberStrict(Node n, JSType type, String msg) {
if (!type.isSubtypeOf(getNativeType(NUMBER_TYPE))) {
registerMismatchAndReport(
n, INVALID_OPERAND_TYPE, msg, type, getNativeType(NUMBER_TYPE), null, null);
}
} | java | void expectNumberStrict(Node n, JSType type, String msg) {
if (!type.isSubtypeOf(getNativeType(NUMBER_TYPE))) {
registerMismatchAndReport(
n, INVALID_OPERAND_TYPE, msg, type, getNativeType(NUMBER_TYPE), null, null);
}
} | [
"void",
"expectNumberStrict",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"type",
".",
"isSubtypeOf",
"(",
"getNativeType",
"(",
"NUMBER_TYPE",
")",
")",
")",
"{",
"registerMismatchAndReport",
"(",
"n",
",",
"INVALID_OPERAND_TYPE",
",",
"msg",
",",
"type",
",",
"getNativeType",
"(",
"NUMBER_TYPE",
")",
",",
"null",
",",
"null",
")",
";",
"}",
"}"
] | Expect the type to be a number or a subtype. | [
"Expect",
"the",
"type",
"to",
"be",
"a",
"number",
"or",
"a",
"subtype",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L384-L389 |
23,944 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectNumberOrSymbol | void expectNumberOrSymbol(Node n, JSType type, String msg) {
if (!type.matchesNumberContext() && !type.matchesSymbolContext()) {
mismatch(n, msg, type, NUMBER_SYMBOL);
}
} | java | void expectNumberOrSymbol(Node n, JSType type, String msg) {
if (!type.matchesNumberContext() && !type.matchesSymbolContext()) {
mismatch(n, msg, type, NUMBER_SYMBOL);
}
} | [
"void",
"expectNumberOrSymbol",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"type",
".",
"matchesNumberContext",
"(",
")",
"&&",
"!",
"type",
".",
"matchesSymbolContext",
"(",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"NUMBER_SYMBOL",
")",
";",
"}",
"}"
] | Expect the type to be a number or string, or a type convertible to a number or symbol. If the
expectation is not met, issue a warning at the provided node's source code position. | [
"Expect",
"the",
"type",
"to",
"be",
"a",
"number",
"or",
"string",
"or",
"a",
"type",
"convertible",
"to",
"a",
"number",
"or",
"symbol",
".",
"If",
"the",
"expectation",
"is",
"not",
"met",
"issue",
"a",
"warning",
"at",
"the",
"provided",
"node",
"s",
"source",
"code",
"position",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L413-L417 |
23,945 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectStringOrSymbol | void expectStringOrSymbol(Node n, JSType type, String msg) {
if (!type.matchesStringContext() && !type.matchesSymbolContext()) {
mismatch(n, msg, type, STRING_SYMBOL);
}
} | java | void expectStringOrSymbol(Node n, JSType type, String msg) {
if (!type.matchesStringContext() && !type.matchesSymbolContext()) {
mismatch(n, msg, type, STRING_SYMBOL);
}
} | [
"void",
"expectStringOrSymbol",
"(",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
")",
"{",
"if",
"(",
"!",
"type",
".",
"matchesStringContext",
"(",
")",
"&&",
"!",
"type",
".",
"matchesSymbolContext",
"(",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"STRING_SYMBOL",
")",
";",
"}",
"}"
] | Expect the type to be a string or symbol, or a type convertible to a string. If the expectation
is not met, issue a warning at the provided node's source code position. | [
"Expect",
"the",
"type",
"to",
"be",
"a",
"string",
"or",
"symbol",
"or",
"a",
"type",
"convertible",
"to",
"a",
"string",
".",
"If",
"the",
"expectation",
"is",
"not",
"met",
"issue",
"a",
"warning",
"at",
"the",
"provided",
"node",
"s",
"source",
"code",
"position",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L423-L427 |
23,946 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectNotNullOrUndefined | boolean expectNotNullOrUndefined(
NodeTraversal t, Node n, JSType type, String msg, JSType expectedType) {
if (!type.isNoType() && !type.isUnknownType()
&& type.isSubtypeOf(nullOrUndefined)
&& !containsForwardDeclaredUnresolvedName(type)) {
// There's one edge case right now that we don't handle well, and
// that we don't want to warn about.
// if (this.x == null) {
// this.initializeX();
// this.x.foo();
// }
// In this case, we incorrectly type x because of how we
// infer properties locally. See issue 109.
// http://blickly.github.io/closure-compiler-issues/#109
//
// We do not do this inference globally.
if (n.isGetProp() && !t.inGlobalScope() && type.isNullType()) {
return true;
}
mismatch(n, msg, type, expectedType);
return false;
}
return true;
} | java | boolean expectNotNullOrUndefined(
NodeTraversal t, Node n, JSType type, String msg, JSType expectedType) {
if (!type.isNoType() && !type.isUnknownType()
&& type.isSubtypeOf(nullOrUndefined)
&& !containsForwardDeclaredUnresolvedName(type)) {
// There's one edge case right now that we don't handle well, and
// that we don't want to warn about.
// if (this.x == null) {
// this.initializeX();
// this.x.foo();
// }
// In this case, we incorrectly type x because of how we
// infer properties locally. See issue 109.
// http://blickly.github.io/closure-compiler-issues/#109
//
// We do not do this inference globally.
if (n.isGetProp() && !t.inGlobalScope() && type.isNullType()) {
return true;
}
mismatch(n, msg, type, expectedType);
return false;
}
return true;
} | [
"boolean",
"expectNotNullOrUndefined",
"(",
"NodeTraversal",
"t",
",",
"Node",
"n",
",",
"JSType",
"type",
",",
"String",
"msg",
",",
"JSType",
"expectedType",
")",
"{",
"if",
"(",
"!",
"type",
".",
"isNoType",
"(",
")",
"&&",
"!",
"type",
".",
"isUnknownType",
"(",
")",
"&&",
"type",
".",
"isSubtypeOf",
"(",
"nullOrUndefined",
")",
"&&",
"!",
"containsForwardDeclaredUnresolvedName",
"(",
"type",
")",
")",
"{",
"// There's one edge case right now that we don't handle well, and",
"// that we don't want to warn about.",
"// if (this.x == null) {",
"// this.initializeX();",
"// this.x.foo();",
"// }",
"// In this case, we incorrectly type x because of how we",
"// infer properties locally. See issue 109.",
"// http://blickly.github.io/closure-compiler-issues/#109",
"//",
"// We do not do this inference globally.",
"if",
"(",
"n",
".",
"isGetProp",
"(",
")",
"&&",
"!",
"t",
".",
"inGlobalScope",
"(",
")",
"&&",
"type",
".",
"isNullType",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"mismatch",
"(",
"n",
",",
"msg",
",",
"type",
",",
"expectedType",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Expect the type to be anything but the null or void type. If the expectation is not met, issue
a warning at the provided node's source code position. Note that a union type that includes the
void type and at least one other type meets the expectation.
@return Whether the expectation was met. | [
"Expect",
"the",
"type",
"to",
"be",
"anything",
"but",
"the",
"null",
"or",
"void",
"type",
".",
"If",
"the",
"expectation",
"is",
"not",
"met",
"issue",
"a",
"warning",
"at",
"the",
"provided",
"node",
"s",
"source",
"code",
"position",
".",
"Note",
"that",
"a",
"union",
"type",
"that",
"includes",
"the",
"void",
"type",
"and",
"at",
"least",
"one",
"other",
"type",
"meets",
"the",
"expectation",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L480-L505 |
23,947 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectSwitchMatchesCase | void expectSwitchMatchesCase(Node n, JSType switchType, JSType caseType) {
// ECMA-262, page 68, step 3 of evaluation of CaseBlock,
// but allowing extra autoboxing.
// TODO(user): remove extra conditions when type annotations
// in the code base have adapted to the change in the compiler.
if (!switchType.canTestForShallowEqualityWith(caseType)
&& (caseType.autoboxesTo() == null || !caseType.autoboxesTo().isSubtypeOf(switchType))) {
mismatch(n.getFirstChild(), "case expression doesn't match switch", caseType, switchType);
} else if (!switchType.canTestForShallowEqualityWith(caseType)
&& (caseType.autoboxesTo() == null
|| !caseType.autoboxesTo().isSubtypeWithoutStructuralTyping(switchType))) {
TypeMismatch.recordImplicitInterfaceUses(this.implicitInterfaceUses, n, caseType, switchType);
TypeMismatch.recordImplicitUseOfNativeObject(this.mismatches, n, caseType, switchType);
}
} | java | void expectSwitchMatchesCase(Node n, JSType switchType, JSType caseType) {
// ECMA-262, page 68, step 3 of evaluation of CaseBlock,
// but allowing extra autoboxing.
// TODO(user): remove extra conditions when type annotations
// in the code base have adapted to the change in the compiler.
if (!switchType.canTestForShallowEqualityWith(caseType)
&& (caseType.autoboxesTo() == null || !caseType.autoboxesTo().isSubtypeOf(switchType))) {
mismatch(n.getFirstChild(), "case expression doesn't match switch", caseType, switchType);
} else if (!switchType.canTestForShallowEqualityWith(caseType)
&& (caseType.autoboxesTo() == null
|| !caseType.autoboxesTo().isSubtypeWithoutStructuralTyping(switchType))) {
TypeMismatch.recordImplicitInterfaceUses(this.implicitInterfaceUses, n, caseType, switchType);
TypeMismatch.recordImplicitUseOfNativeObject(this.mismatches, n, caseType, switchType);
}
} | [
"void",
"expectSwitchMatchesCase",
"(",
"Node",
"n",
",",
"JSType",
"switchType",
",",
"JSType",
"caseType",
")",
"{",
"// ECMA-262, page 68, step 3 of evaluation of CaseBlock,",
"// but allowing extra autoboxing.",
"// TODO(user): remove extra conditions when type annotations",
"// in the code base have adapted to the change in the compiler.",
"if",
"(",
"!",
"switchType",
".",
"canTestForShallowEqualityWith",
"(",
"caseType",
")",
"&&",
"(",
"caseType",
".",
"autoboxesTo",
"(",
")",
"==",
"null",
"||",
"!",
"caseType",
".",
"autoboxesTo",
"(",
")",
".",
"isSubtypeOf",
"(",
"switchType",
")",
")",
")",
"{",
"mismatch",
"(",
"n",
".",
"getFirstChild",
"(",
")",
",",
"\"case expression doesn't match switch\"",
",",
"caseType",
",",
"switchType",
")",
";",
"}",
"else",
"if",
"(",
"!",
"switchType",
".",
"canTestForShallowEqualityWith",
"(",
"caseType",
")",
"&&",
"(",
"caseType",
".",
"autoboxesTo",
"(",
")",
"==",
"null",
"||",
"!",
"caseType",
".",
"autoboxesTo",
"(",
")",
".",
"isSubtypeWithoutStructuralTyping",
"(",
"switchType",
")",
")",
")",
"{",
"TypeMismatch",
".",
"recordImplicitInterfaceUses",
"(",
"this",
".",
"implicitInterfaceUses",
",",
"n",
",",
"caseType",
",",
"switchType",
")",
";",
"TypeMismatch",
".",
"recordImplicitUseOfNativeObject",
"(",
"this",
".",
"mismatches",
",",
"n",
",",
"caseType",
",",
"switchType",
")",
";",
"}",
"}"
] | Expect that the type of a switch condition matches the type of its case condition. | [
"Expect",
"that",
"the",
"type",
"of",
"a",
"switch",
"condition",
"matches",
"the",
"type",
"of",
"its",
"case",
"condition",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L519-L533 |
23,948 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectIndexMatch | void expectIndexMatch(Node n, JSType objType, JSType indexType) {
checkState(n.isGetElem() || n.isComputedProp(), n);
Node indexNode = n.isGetElem() ? n.getLastChild() : n.getFirstChild();
if (indexType.isSymbolValueType()) {
// For now, allow symbols definitions/access on any type. In the future only allow them
// on the subtypes for which they are defined.
return;
}
if (objType.isStruct()) {
report(JSError.make(indexNode,
ILLEGAL_PROPERTY_ACCESS, "'[]'", "struct"));
}
if (objType.isUnknownType()) {
expectStringOrNumberOrSymbol(indexNode, indexType, "property access");
} else {
ObjectType dereferenced = objType.dereference();
if (dereferenced != null && dereferenced
.getTemplateTypeMap()
.hasTemplateKey(typeRegistry.getObjectIndexKey())) {
expectCanAssignTo(
indexNode,
indexType,
dereferenced
.getTemplateTypeMap()
.getResolvedTemplateType(typeRegistry.getObjectIndexKey()),
"restricted index type");
} else if (dereferenced != null && dereferenced.isArrayType()) {
expectNumberOrSymbol(indexNode, indexType, "array access");
} else if (objType.matchesObjectContext()) {
expectStringOrSymbol(indexNode, indexType, "property access");
} else {
mismatch(
n,
"only arrays or objects can be accessed",
objType,
typeRegistry.createUnionType(ARRAY_TYPE, OBJECT_TYPE));
}
}
} | java | void expectIndexMatch(Node n, JSType objType, JSType indexType) {
checkState(n.isGetElem() || n.isComputedProp(), n);
Node indexNode = n.isGetElem() ? n.getLastChild() : n.getFirstChild();
if (indexType.isSymbolValueType()) {
// For now, allow symbols definitions/access on any type. In the future only allow them
// on the subtypes for which they are defined.
return;
}
if (objType.isStruct()) {
report(JSError.make(indexNode,
ILLEGAL_PROPERTY_ACCESS, "'[]'", "struct"));
}
if (objType.isUnknownType()) {
expectStringOrNumberOrSymbol(indexNode, indexType, "property access");
} else {
ObjectType dereferenced = objType.dereference();
if (dereferenced != null && dereferenced
.getTemplateTypeMap()
.hasTemplateKey(typeRegistry.getObjectIndexKey())) {
expectCanAssignTo(
indexNode,
indexType,
dereferenced
.getTemplateTypeMap()
.getResolvedTemplateType(typeRegistry.getObjectIndexKey()),
"restricted index type");
} else if (dereferenced != null && dereferenced.isArrayType()) {
expectNumberOrSymbol(indexNode, indexType, "array access");
} else if (objType.matchesObjectContext()) {
expectStringOrSymbol(indexNode, indexType, "property access");
} else {
mismatch(
n,
"only arrays or objects can be accessed",
objType,
typeRegistry.createUnionType(ARRAY_TYPE, OBJECT_TYPE));
}
}
} | [
"void",
"expectIndexMatch",
"(",
"Node",
"n",
",",
"JSType",
"objType",
",",
"JSType",
"indexType",
")",
"{",
"checkState",
"(",
"n",
".",
"isGetElem",
"(",
")",
"||",
"n",
".",
"isComputedProp",
"(",
")",
",",
"n",
")",
";",
"Node",
"indexNode",
"=",
"n",
".",
"isGetElem",
"(",
")",
"?",
"n",
".",
"getLastChild",
"(",
")",
":",
"n",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"indexType",
".",
"isSymbolValueType",
"(",
")",
")",
"{",
"// For now, allow symbols definitions/access on any type. In the future only allow them",
"// on the subtypes for which they are defined.",
"return",
";",
"}",
"if",
"(",
"objType",
".",
"isStruct",
"(",
")",
")",
"{",
"report",
"(",
"JSError",
".",
"make",
"(",
"indexNode",
",",
"ILLEGAL_PROPERTY_ACCESS",
",",
"\"'[]'\"",
",",
"\"struct\"",
")",
")",
";",
"}",
"if",
"(",
"objType",
".",
"isUnknownType",
"(",
")",
")",
"{",
"expectStringOrNumberOrSymbol",
"(",
"indexNode",
",",
"indexType",
",",
"\"property access\"",
")",
";",
"}",
"else",
"{",
"ObjectType",
"dereferenced",
"=",
"objType",
".",
"dereference",
"(",
")",
";",
"if",
"(",
"dereferenced",
"!=",
"null",
"&&",
"dereferenced",
".",
"getTemplateTypeMap",
"(",
")",
".",
"hasTemplateKey",
"(",
"typeRegistry",
".",
"getObjectIndexKey",
"(",
")",
")",
")",
"{",
"expectCanAssignTo",
"(",
"indexNode",
",",
"indexType",
",",
"dereferenced",
".",
"getTemplateTypeMap",
"(",
")",
".",
"getResolvedTemplateType",
"(",
"typeRegistry",
".",
"getObjectIndexKey",
"(",
")",
")",
",",
"\"restricted index type\"",
")",
";",
"}",
"else",
"if",
"(",
"dereferenced",
"!=",
"null",
"&&",
"dereferenced",
".",
"isArrayType",
"(",
")",
")",
"{",
"expectNumberOrSymbol",
"(",
"indexNode",
",",
"indexType",
",",
"\"array access\"",
")",
";",
"}",
"else",
"if",
"(",
"objType",
".",
"matchesObjectContext",
"(",
")",
")",
"{",
"expectStringOrSymbol",
"(",
"indexNode",
",",
"indexType",
",",
"\"property access\"",
")",
";",
"}",
"else",
"{",
"mismatch",
"(",
"n",
",",
"\"only arrays or objects can be accessed\"",
",",
"objType",
",",
"typeRegistry",
".",
"createUnionType",
"(",
"ARRAY_TYPE",
",",
"OBJECT_TYPE",
")",
")",
";",
"}",
"}",
"}"
] | Expect that the first type can be addressed with GETELEM syntax and that the second type is the
right type for an index into the first type.
@param t The node traversal.
@param n The GETELEM or COMPUTED_PROP node to issue warnings on.
@param objType The type we're indexing into (the left side of the GETELEM).
@param indexType The type inside the brackets of the GETELEM/COMPUTED_PROP. | [
"Expect",
"that",
"the",
"first",
"type",
"can",
"be",
"addressed",
"with",
"GETELEM",
"syntax",
"and",
"that",
"the",
"second",
"type",
"is",
"the",
"right",
"type",
"for",
"an",
"index",
"into",
"the",
"first",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L544-L582 |
23,949 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectArgumentMatchesParameter | void expectArgumentMatchesParameter(
Node n, JSType argType, JSType paramType, Node callNode, int ordinal) {
if (!argType.isSubtypeOf(paramType)) {
mismatch(
n,
SimpleFormat.format(
"actual parameter %d of %s does not match formal parameter",
ordinal, typeRegistry.getReadableTypeNameNoDeref(callNode.getFirstChild())),
argType,
paramType);
} else if (!argType.isSubtypeWithoutStructuralTyping(paramType)){
TypeMismatch.recordImplicitInterfaceUses(this.implicitInterfaceUses, n, argType, paramType);
TypeMismatch.recordImplicitUseOfNativeObject(this.mismatches, n, argType, paramType);
}
} | java | void expectArgumentMatchesParameter(
Node n, JSType argType, JSType paramType, Node callNode, int ordinal) {
if (!argType.isSubtypeOf(paramType)) {
mismatch(
n,
SimpleFormat.format(
"actual parameter %d of %s does not match formal parameter",
ordinal, typeRegistry.getReadableTypeNameNoDeref(callNode.getFirstChild())),
argType,
paramType);
} else if (!argType.isSubtypeWithoutStructuralTyping(paramType)){
TypeMismatch.recordImplicitInterfaceUses(this.implicitInterfaceUses, n, argType, paramType);
TypeMismatch.recordImplicitUseOfNativeObject(this.mismatches, n, argType, paramType);
}
} | [
"void",
"expectArgumentMatchesParameter",
"(",
"Node",
"n",
",",
"JSType",
"argType",
",",
"JSType",
"paramType",
",",
"Node",
"callNode",
",",
"int",
"ordinal",
")",
"{",
"if",
"(",
"!",
"argType",
".",
"isSubtypeOf",
"(",
"paramType",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"SimpleFormat",
".",
"format",
"(",
"\"actual parameter %d of %s does not match formal parameter\"",
",",
"ordinal",
",",
"typeRegistry",
".",
"getReadableTypeNameNoDeref",
"(",
"callNode",
".",
"getFirstChild",
"(",
")",
")",
")",
",",
"argType",
",",
"paramType",
")",
";",
"}",
"else",
"if",
"(",
"!",
"argType",
".",
"isSubtypeWithoutStructuralTyping",
"(",
"paramType",
")",
")",
"{",
"TypeMismatch",
".",
"recordImplicitInterfaceUses",
"(",
"this",
".",
"implicitInterfaceUses",
",",
"n",
",",
"argType",
",",
"paramType",
")",
";",
"TypeMismatch",
".",
"recordImplicitUseOfNativeObject",
"(",
"this",
".",
"mismatches",
",",
"n",
",",
"argType",
",",
"paramType",
")",
";",
"}",
"}"
] | Expect that the type of an argument matches the type of the parameter that it's fulfilling.
@param t The node traversal.
@param n The node to issue warnings on.
@param argType The type of the argument.
@param paramType The type of the parameter.
@param callNode The call node, to help with the warning message.
@param ordinal The argument ordinal, to help with the warning message. | [
"Expect",
"that",
"the",
"type",
"of",
"an",
"argument",
"matches",
"the",
"type",
"of",
"the",
"parameter",
"that",
"it",
"s",
"fulfilling",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L655-L669 |
23,950 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectSuperType | void expectSuperType(Node n, ObjectType superObject, ObjectType subObject) {
FunctionType subCtor = subObject.getConstructor();
ObjectType implicitProto = subObject.getImplicitPrototype();
ObjectType declaredSuper =
implicitProto == null ? null : implicitProto.getImplicitPrototype();
if (declaredSuper != null && declaredSuper.isTemplatizedType()) {
declaredSuper =
declaredSuper.toMaybeTemplatizedType().getReferencedType();
}
if (declaredSuper != null
&& !(superObject instanceof UnknownType)
&& !declaredSuper.isEquivalentTo(superObject)) {
if (declaredSuper.isEquivalentTo(getNativeType(OBJECT_TYPE))) {
registerMismatch(
superObject,
declaredSuper,
report(JSError.make(n, MISSING_EXTENDS_TAG_WARNING, subObject.toString())));
} else {
mismatch(n, "mismatch in declaration of superclass type", superObject, declaredSuper);
}
// Correct the super type.
if (!subCtor.hasCachedValues()) {
subCtor.setPrototypeBasedOn(superObject);
}
}
} | java | void expectSuperType(Node n, ObjectType superObject, ObjectType subObject) {
FunctionType subCtor = subObject.getConstructor();
ObjectType implicitProto = subObject.getImplicitPrototype();
ObjectType declaredSuper =
implicitProto == null ? null : implicitProto.getImplicitPrototype();
if (declaredSuper != null && declaredSuper.isTemplatizedType()) {
declaredSuper =
declaredSuper.toMaybeTemplatizedType().getReferencedType();
}
if (declaredSuper != null
&& !(superObject instanceof UnknownType)
&& !declaredSuper.isEquivalentTo(superObject)) {
if (declaredSuper.isEquivalentTo(getNativeType(OBJECT_TYPE))) {
registerMismatch(
superObject,
declaredSuper,
report(JSError.make(n, MISSING_EXTENDS_TAG_WARNING, subObject.toString())));
} else {
mismatch(n, "mismatch in declaration of superclass type", superObject, declaredSuper);
}
// Correct the super type.
if (!subCtor.hasCachedValues()) {
subCtor.setPrototypeBasedOn(superObject);
}
}
} | [
"void",
"expectSuperType",
"(",
"Node",
"n",
",",
"ObjectType",
"superObject",
",",
"ObjectType",
"subObject",
")",
"{",
"FunctionType",
"subCtor",
"=",
"subObject",
".",
"getConstructor",
"(",
")",
";",
"ObjectType",
"implicitProto",
"=",
"subObject",
".",
"getImplicitPrototype",
"(",
")",
";",
"ObjectType",
"declaredSuper",
"=",
"implicitProto",
"==",
"null",
"?",
"null",
":",
"implicitProto",
".",
"getImplicitPrototype",
"(",
")",
";",
"if",
"(",
"declaredSuper",
"!=",
"null",
"&&",
"declaredSuper",
".",
"isTemplatizedType",
"(",
")",
")",
"{",
"declaredSuper",
"=",
"declaredSuper",
".",
"toMaybeTemplatizedType",
"(",
")",
".",
"getReferencedType",
"(",
")",
";",
"}",
"if",
"(",
"declaredSuper",
"!=",
"null",
"&&",
"!",
"(",
"superObject",
"instanceof",
"UnknownType",
")",
"&&",
"!",
"declaredSuper",
".",
"isEquivalentTo",
"(",
"superObject",
")",
")",
"{",
"if",
"(",
"declaredSuper",
".",
"isEquivalentTo",
"(",
"getNativeType",
"(",
"OBJECT_TYPE",
")",
")",
")",
"{",
"registerMismatch",
"(",
"superObject",
",",
"declaredSuper",
",",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"MISSING_EXTENDS_TAG_WARNING",
",",
"subObject",
".",
"toString",
"(",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"mismatch",
"(",
"n",
",",
"\"mismatch in declaration of superclass type\"",
",",
"superObject",
",",
"declaredSuper",
")",
";",
"}",
"// Correct the super type.",
"if",
"(",
"!",
"subCtor",
".",
"hasCachedValues",
"(",
")",
")",
"{",
"subCtor",
".",
"setPrototypeBasedOn",
"(",
"superObject",
")",
";",
"}",
"}",
"}"
] | Expect that the first type is the direct superclass of the second type.
@param t The node traversal.
@param n The node where warnings should point to.
@param superObject The expected super instance type.
@param subObject The sub instance type. | [
"Expect",
"that",
"the",
"first",
"type",
"is",
"the",
"direct",
"superclass",
"of",
"the",
"second",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L679-L705 |
23,951 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectExtends | void expectExtends(Node n, FunctionType subCtor, FunctionType astSuperCtor) {
if (astSuperCtor == null || (!astSuperCtor.isConstructor() && !astSuperCtor.isInterface())) {
// toMaybeFunctionType failed, or we've got a loose type. Let it go for now.
return;
}
if (astSuperCtor.isConstructor() != subCtor.isConstructor()) {
// Don't bother looking if one is a constructor and the other is an interface.
// We'll report an error elsewhere.
return;
}
ObjectType astSuperInstance = astSuperCtor.getInstanceType();
if (subCtor.isConstructor()) {
// There should be exactly one superclass, and it needs to have this constructor.
// Note: if the registered supertype (from the @extends jsdoc) was unresolved,
// then getSuperClassConstructor will be null - make sure not to crash.
FunctionType registeredSuperCtor = subCtor.getSuperClassConstructor();
if (registeredSuperCtor != null) {
ObjectType registeredSuperInstance = registeredSuperCtor.getInstanceType();
if (!astSuperInstance.isEquivalentTo(registeredSuperInstance)) {
mismatch(
n,
"mismatch in declaration of superclass type",
astSuperInstance,
registeredSuperInstance);
}
}
} else if (subCtor.isInterface()) {
// We intentionally skip this check for interfaces because they can extend multiple other
// interfaces.
}
} | java | void expectExtends(Node n, FunctionType subCtor, FunctionType astSuperCtor) {
if (astSuperCtor == null || (!astSuperCtor.isConstructor() && !astSuperCtor.isInterface())) {
// toMaybeFunctionType failed, or we've got a loose type. Let it go for now.
return;
}
if (astSuperCtor.isConstructor() != subCtor.isConstructor()) {
// Don't bother looking if one is a constructor and the other is an interface.
// We'll report an error elsewhere.
return;
}
ObjectType astSuperInstance = astSuperCtor.getInstanceType();
if (subCtor.isConstructor()) {
// There should be exactly one superclass, and it needs to have this constructor.
// Note: if the registered supertype (from the @extends jsdoc) was unresolved,
// then getSuperClassConstructor will be null - make sure not to crash.
FunctionType registeredSuperCtor = subCtor.getSuperClassConstructor();
if (registeredSuperCtor != null) {
ObjectType registeredSuperInstance = registeredSuperCtor.getInstanceType();
if (!astSuperInstance.isEquivalentTo(registeredSuperInstance)) {
mismatch(
n,
"mismatch in declaration of superclass type",
astSuperInstance,
registeredSuperInstance);
}
}
} else if (subCtor.isInterface()) {
// We intentionally skip this check for interfaces because they can extend multiple other
// interfaces.
}
} | [
"void",
"expectExtends",
"(",
"Node",
"n",
",",
"FunctionType",
"subCtor",
",",
"FunctionType",
"astSuperCtor",
")",
"{",
"if",
"(",
"astSuperCtor",
"==",
"null",
"||",
"(",
"!",
"astSuperCtor",
".",
"isConstructor",
"(",
")",
"&&",
"!",
"astSuperCtor",
".",
"isInterface",
"(",
")",
")",
")",
"{",
"// toMaybeFunctionType failed, or we've got a loose type. Let it go for now.",
"return",
";",
"}",
"if",
"(",
"astSuperCtor",
".",
"isConstructor",
"(",
")",
"!=",
"subCtor",
".",
"isConstructor",
"(",
")",
")",
"{",
"// Don't bother looking if one is a constructor and the other is an interface.",
"// We'll report an error elsewhere.",
"return",
";",
"}",
"ObjectType",
"astSuperInstance",
"=",
"astSuperCtor",
".",
"getInstanceType",
"(",
")",
";",
"if",
"(",
"subCtor",
".",
"isConstructor",
"(",
")",
")",
"{",
"// There should be exactly one superclass, and it needs to have this constructor.",
"// Note: if the registered supertype (from the @extends jsdoc) was unresolved,",
"// then getSuperClassConstructor will be null - make sure not to crash.",
"FunctionType",
"registeredSuperCtor",
"=",
"subCtor",
".",
"getSuperClassConstructor",
"(",
")",
";",
"if",
"(",
"registeredSuperCtor",
"!=",
"null",
")",
"{",
"ObjectType",
"registeredSuperInstance",
"=",
"registeredSuperCtor",
".",
"getInstanceType",
"(",
")",
";",
"if",
"(",
"!",
"astSuperInstance",
".",
"isEquivalentTo",
"(",
"registeredSuperInstance",
")",
")",
"{",
"mismatch",
"(",
"n",
",",
"\"mismatch in declaration of superclass type\"",
",",
"astSuperInstance",
",",
"registeredSuperInstance",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"subCtor",
".",
"isInterface",
"(",
")",
")",
"{",
"// We intentionally skip this check for interfaces because they can extend multiple other",
"// interfaces.",
"}",
"}"
] | Expect that an ES6 class's extends clause is actually a supertype of the given class.
Compares the registered supertype, which is taken from the JSDoc if present, otherwise
from the AST, with the type in the extends node of the AST.
@param n The node where warnings should point to.
@param subCtor The sub constructor type.
@param astSuperCtor The expected super constructor from the extends node in the AST. | [
"Expect",
"that",
"an",
"ES6",
"class",
"s",
"extends",
"clause",
"is",
"actually",
"a",
"supertype",
"of",
"the",
"given",
"class",
".",
"Compares",
"the",
"registered",
"supertype",
"which",
"is",
"taken",
"from",
"the",
"JSDoc",
"if",
"present",
"otherwise",
"from",
"the",
"AST",
"with",
"the",
"type",
"in",
"the",
"extends",
"node",
"of",
"the",
"AST",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L716-L746 |
23,952 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectCanAssignToPrototype | void expectCanAssignToPrototype(JSType ownerType, Node node, JSType rightType) {
if (ownerType.isFunctionType()) {
FunctionType functionType = ownerType.toMaybeFunctionType();
if (functionType.isConstructor()) {
expectObject(node, rightType, "cannot override prototype with non-object");
}
}
} | java | void expectCanAssignToPrototype(JSType ownerType, Node node, JSType rightType) {
if (ownerType.isFunctionType()) {
FunctionType functionType = ownerType.toMaybeFunctionType();
if (functionType.isConstructor()) {
expectObject(node, rightType, "cannot override prototype with non-object");
}
}
} | [
"void",
"expectCanAssignToPrototype",
"(",
"JSType",
"ownerType",
",",
"Node",
"node",
",",
"JSType",
"rightType",
")",
"{",
"if",
"(",
"ownerType",
".",
"isFunctionType",
"(",
")",
")",
"{",
"FunctionType",
"functionType",
"=",
"ownerType",
".",
"toMaybeFunctionType",
"(",
")",
";",
"if",
"(",
"functionType",
".",
"isConstructor",
"(",
")",
")",
"{",
"expectObject",
"(",
"node",
",",
"rightType",
",",
"\"cannot override prototype with non-object\"",
")",
";",
"}",
"}",
"}"
] | Expect that it's valid to assign something to a given type's prototype.
<p>Most of these checks occur during TypedScopeCreator, so we just handle very basic cases here
<p>For example, assuming `Foo` is a constructor, `Foo.prototype = 3;` will warn because `3` is
not an object.
@param ownerType The type of the object whose prototype is being changed. (e.g. `Foo` above)
@param node Node to issue warnings on (e.g. `3` above)
@param rightType the rvalue type being assigned to the prototype (e.g. `number` above) | [
"Expect",
"that",
"it",
"s",
"valid",
"to",
"assign",
"something",
"to",
"a",
"given",
"type",
"s",
"prototype",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L760-L767 |
23,953 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectCanCast | void expectCanCast(Node n, JSType targetType, JSType sourceType) {
if (!sourceType.canCastTo(targetType)) {
registerMismatch(
sourceType,
targetType,
report(JSError.make(n, INVALID_CAST, sourceType.toString(), targetType.toString())));
} else if (!sourceType.isSubtypeWithoutStructuralTyping(targetType)){
TypeMismatch.recordImplicitInterfaceUses(
this.implicitInterfaceUses, n, sourceType, targetType);
}
} | java | void expectCanCast(Node n, JSType targetType, JSType sourceType) {
if (!sourceType.canCastTo(targetType)) {
registerMismatch(
sourceType,
targetType,
report(JSError.make(n, INVALID_CAST, sourceType.toString(), targetType.toString())));
} else if (!sourceType.isSubtypeWithoutStructuralTyping(targetType)){
TypeMismatch.recordImplicitInterfaceUses(
this.implicitInterfaceUses, n, sourceType, targetType);
}
} | [
"void",
"expectCanCast",
"(",
"Node",
"n",
",",
"JSType",
"targetType",
",",
"JSType",
"sourceType",
")",
"{",
"if",
"(",
"!",
"sourceType",
".",
"canCastTo",
"(",
"targetType",
")",
")",
"{",
"registerMismatch",
"(",
"sourceType",
",",
"targetType",
",",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"INVALID_CAST",
",",
"sourceType",
".",
"toString",
"(",
")",
",",
"targetType",
".",
"toString",
"(",
")",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"sourceType",
".",
"isSubtypeWithoutStructuralTyping",
"(",
"targetType",
")",
")",
"{",
"TypeMismatch",
".",
"recordImplicitInterfaceUses",
"(",
"this",
".",
"implicitInterfaceUses",
",",
"n",
",",
"sourceType",
",",
"targetType",
")",
";",
"}",
"}"
] | Expect that the first type can be cast to the second type. The first type must have some
relationship with the second.
@param t The node traversal.
@param n The node where warnings should point.
@param targetType The type being cast to.
@param sourceType The type being cast from. | [
"Expect",
"that",
"the",
"first",
"type",
"can",
"be",
"cast",
"to",
"the",
"second",
"type",
".",
"The",
"first",
"type",
"must",
"have",
"some",
"relationship",
"with",
"the",
"second",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L778-L788 |
23,954 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectUndeclaredVariable | TypedVar expectUndeclaredVariable(String sourceName, CompilerInput input,
Node n, Node parent, TypedVar var, String variableName, JSType newType) {
TypedVar newVar = var;
JSType varType = var.getType();
// Only report duplicate declarations that have types. Other duplicates
// will be reported by the syntactic scope creator later in the
// compilation process.
if (varType != null
&& varType != typeRegistry.getNativeType(UNKNOWN_TYPE)
&& newType != null
&& newType != typeRegistry.getNativeType(UNKNOWN_TYPE)) {
// If there are two typed declarations of the same variable, that
// is an error and the second declaration is ignored, except in the
// case of native types. A null input type means that the declaration
// was made in TypedScopeCreator#createInitialScope and is a
// native type. We should redeclare it at the new input site.
if (var.input == null) {
TypedScope s = var.getScope();
s.undeclare(var);
newVar = s.declare(variableName, n, varType, input, false);
n.setJSType(varType);
if (parent.isVar()) {
if (n.hasChildren()) {
n.getFirstChild().setJSType(varType);
}
} else {
checkState(parent.isFunction() || parent.isClass());
parent.setJSType(varType);
}
} else {
// Check for @suppress duplicate or similar warnings guard on the previous variable
// declaration location.
boolean allowDupe = hasDuplicateDeclarationSuppression(compiler, var.getNameNode());
// If the previous definition doesn't suppress the warning, emit it here (i.e. always emit
// on the second of the duplicate definitions). The warning might still be suppressed by an
// @suppress tag on this declaration.
if (!allowDupe) {
// Report specifically if it is not just a duplicate, but types also don't mismatch.
// NOTE: structural matches are explicitly allowed here.
if (!newType.isEquivalentTo(varType, true)) {
report(
JSError.make(
n,
DUP_VAR_DECLARATION_TYPE_MISMATCH,
variableName,
newType.toString(),
var.getInputName(),
String.valueOf(var.nameNode.getLineno()),
varType.toString()));
} else if (!var.getParentNode().isExprResult()) {
// If the type matches and the previous declaration was a stub declaration
// (isExprResult), then ignore the duplicate, otherwise emit an error.
report(
JSError.make(
n,
DUP_VAR_DECLARATION,
variableName,
var.getInputName(),
String.valueOf(var.nameNode.getLineno())));
}
}
}
}
return newVar;
} | java | TypedVar expectUndeclaredVariable(String sourceName, CompilerInput input,
Node n, Node parent, TypedVar var, String variableName, JSType newType) {
TypedVar newVar = var;
JSType varType = var.getType();
// Only report duplicate declarations that have types. Other duplicates
// will be reported by the syntactic scope creator later in the
// compilation process.
if (varType != null
&& varType != typeRegistry.getNativeType(UNKNOWN_TYPE)
&& newType != null
&& newType != typeRegistry.getNativeType(UNKNOWN_TYPE)) {
// If there are two typed declarations of the same variable, that
// is an error and the second declaration is ignored, except in the
// case of native types. A null input type means that the declaration
// was made in TypedScopeCreator#createInitialScope and is a
// native type. We should redeclare it at the new input site.
if (var.input == null) {
TypedScope s = var.getScope();
s.undeclare(var);
newVar = s.declare(variableName, n, varType, input, false);
n.setJSType(varType);
if (parent.isVar()) {
if (n.hasChildren()) {
n.getFirstChild().setJSType(varType);
}
} else {
checkState(parent.isFunction() || parent.isClass());
parent.setJSType(varType);
}
} else {
// Check for @suppress duplicate or similar warnings guard on the previous variable
// declaration location.
boolean allowDupe = hasDuplicateDeclarationSuppression(compiler, var.getNameNode());
// If the previous definition doesn't suppress the warning, emit it here (i.e. always emit
// on the second of the duplicate definitions). The warning might still be suppressed by an
// @suppress tag on this declaration.
if (!allowDupe) {
// Report specifically if it is not just a duplicate, but types also don't mismatch.
// NOTE: structural matches are explicitly allowed here.
if (!newType.isEquivalentTo(varType, true)) {
report(
JSError.make(
n,
DUP_VAR_DECLARATION_TYPE_MISMATCH,
variableName,
newType.toString(),
var.getInputName(),
String.valueOf(var.nameNode.getLineno()),
varType.toString()));
} else if (!var.getParentNode().isExprResult()) {
// If the type matches and the previous declaration was a stub declaration
// (isExprResult), then ignore the duplicate, otherwise emit an error.
report(
JSError.make(
n,
DUP_VAR_DECLARATION,
variableName,
var.getInputName(),
String.valueOf(var.nameNode.getLineno())));
}
}
}
}
return newVar;
} | [
"TypedVar",
"expectUndeclaredVariable",
"(",
"String",
"sourceName",
",",
"CompilerInput",
"input",
",",
"Node",
"n",
",",
"Node",
"parent",
",",
"TypedVar",
"var",
",",
"String",
"variableName",
",",
"JSType",
"newType",
")",
"{",
"TypedVar",
"newVar",
"=",
"var",
";",
"JSType",
"varType",
"=",
"var",
".",
"getType",
"(",
")",
";",
"// Only report duplicate declarations that have types. Other duplicates",
"// will be reported by the syntactic scope creator later in the",
"// compilation process.",
"if",
"(",
"varType",
"!=",
"null",
"&&",
"varType",
"!=",
"typeRegistry",
".",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
"&&",
"newType",
"!=",
"null",
"&&",
"newType",
"!=",
"typeRegistry",
".",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
")",
"{",
"// If there are two typed declarations of the same variable, that",
"// is an error and the second declaration is ignored, except in the",
"// case of native types. A null input type means that the declaration",
"// was made in TypedScopeCreator#createInitialScope and is a",
"// native type. We should redeclare it at the new input site.",
"if",
"(",
"var",
".",
"input",
"==",
"null",
")",
"{",
"TypedScope",
"s",
"=",
"var",
".",
"getScope",
"(",
")",
";",
"s",
".",
"undeclare",
"(",
"var",
")",
";",
"newVar",
"=",
"s",
".",
"declare",
"(",
"variableName",
",",
"n",
",",
"varType",
",",
"input",
",",
"false",
")",
";",
"n",
".",
"setJSType",
"(",
"varType",
")",
";",
"if",
"(",
"parent",
".",
"isVar",
"(",
")",
")",
"{",
"if",
"(",
"n",
".",
"hasChildren",
"(",
")",
")",
"{",
"n",
".",
"getFirstChild",
"(",
")",
".",
"setJSType",
"(",
"varType",
")",
";",
"}",
"}",
"else",
"{",
"checkState",
"(",
"parent",
".",
"isFunction",
"(",
")",
"||",
"parent",
".",
"isClass",
"(",
")",
")",
";",
"parent",
".",
"setJSType",
"(",
"varType",
")",
";",
"}",
"}",
"else",
"{",
"// Check for @suppress duplicate or similar warnings guard on the previous variable",
"// declaration location.",
"boolean",
"allowDupe",
"=",
"hasDuplicateDeclarationSuppression",
"(",
"compiler",
",",
"var",
".",
"getNameNode",
"(",
")",
")",
";",
"// If the previous definition doesn't suppress the warning, emit it here (i.e. always emit",
"// on the second of the duplicate definitions). The warning might still be suppressed by an",
"// @suppress tag on this declaration.",
"if",
"(",
"!",
"allowDupe",
")",
"{",
"// Report specifically if it is not just a duplicate, but types also don't mismatch.",
"// NOTE: structural matches are explicitly allowed here.",
"if",
"(",
"!",
"newType",
".",
"isEquivalentTo",
"(",
"varType",
",",
"true",
")",
")",
"{",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"DUP_VAR_DECLARATION_TYPE_MISMATCH",
",",
"variableName",
",",
"newType",
".",
"toString",
"(",
")",
",",
"var",
".",
"getInputName",
"(",
")",
",",
"String",
".",
"valueOf",
"(",
"var",
".",
"nameNode",
".",
"getLineno",
"(",
")",
")",
",",
"varType",
".",
"toString",
"(",
")",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"var",
".",
"getParentNode",
"(",
")",
".",
"isExprResult",
"(",
")",
")",
"{",
"// If the type matches and the previous declaration was a stub declaration",
"// (isExprResult), then ignore the duplicate, otherwise emit an error.",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"DUP_VAR_DECLARATION",
",",
"variableName",
",",
"var",
".",
"getInputName",
"(",
")",
",",
"String",
".",
"valueOf",
"(",
"var",
".",
"nameNode",
".",
"getLineno",
"(",
")",
")",
")",
")",
";",
"}",
"}",
"}",
"}",
"return",
"newVar",
";",
"}"
] | Expect that the given variable has not been declared with a type.
@param sourceName The name of the source file we're in.
@param n The node where warnings should point to.
@param parent The parent of {@code n}.
@param var The variable that we're checking.
@param variableName The name of the variable.
@param newType The type being applied to the variable. Mostly just here
for the benefit of the warning.
@return The variable we end up with. Most of the time, this will just
be {@code var}, but in some rare cases we will need to declare
a new var with new source info. | [
"Expect",
"that",
"the",
"given",
"variable",
"has",
"not",
"been",
"declared",
"with",
"a",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L804-L871 |
23,955 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectAllInterfaceProperties | void expectAllInterfaceProperties(Node n, FunctionType type) {
ObjectType instance = type.getInstanceType();
for (ObjectType implemented : type.getAllImplementedInterfaces()) {
if (implemented.getImplicitPrototype() != null) {
for (String prop :
implemented.getImplicitPrototype().getOwnPropertyNames()) {
expectInterfaceProperty(n, instance, implemented, prop);
}
}
}
} | java | void expectAllInterfaceProperties(Node n, FunctionType type) {
ObjectType instance = type.getInstanceType();
for (ObjectType implemented : type.getAllImplementedInterfaces()) {
if (implemented.getImplicitPrototype() != null) {
for (String prop :
implemented.getImplicitPrototype().getOwnPropertyNames()) {
expectInterfaceProperty(n, instance, implemented, prop);
}
}
}
} | [
"void",
"expectAllInterfaceProperties",
"(",
"Node",
"n",
",",
"FunctionType",
"type",
")",
"{",
"ObjectType",
"instance",
"=",
"type",
".",
"getInstanceType",
"(",
")",
";",
"for",
"(",
"ObjectType",
"implemented",
":",
"type",
".",
"getAllImplementedInterfaces",
"(",
")",
")",
"{",
"if",
"(",
"implemented",
".",
"getImplicitPrototype",
"(",
")",
"!=",
"null",
")",
"{",
"for",
"(",
"String",
"prop",
":",
"implemented",
".",
"getImplicitPrototype",
"(",
")",
".",
"getOwnPropertyNames",
"(",
")",
")",
"{",
"expectInterfaceProperty",
"(",
"n",
",",
"instance",
",",
"implemented",
",",
"prop",
")",
";",
"}",
"}",
"}",
"}"
] | Expect that all properties on interfaces that this type implements are implemented and
correctly typed. | [
"Expect",
"that",
"all",
"properties",
"on",
"interfaces",
"that",
"this",
"type",
"implements",
"are",
"implemented",
"and",
"correctly",
"typed",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L877-L887 |
23,956 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectInterfaceProperty | private void expectInterfaceProperty(
Node n, ObjectType instance, ObjectType implementedInterface, String prop) {
StaticTypedSlot propSlot = instance.getSlot(prop);
if (propSlot == null) {
// Not implemented
String sourceName = n.getSourceFileName();
sourceName = nullToEmpty(sourceName);
registerMismatch(
instance,
implementedInterface,
report(
JSError.make(
n,
INTERFACE_METHOD_NOT_IMPLEMENTED,
prop,
implementedInterface.toString(),
instance.toString())));
} else {
Node propNode =
propSlot.getDeclaration() == null ? null : propSlot.getDeclaration().getNode();
// Fall back on the constructor node if we can't find a node for the
// property.
propNode = propNode == null ? n : propNode;
JSType found = propSlot.getType();
found = found.restrictByNotNullOrUndefined();
JSType required
= implementedInterface.getImplicitPrototype().getPropertyType(prop);
TemplateTypeMap typeMap = implementedInterface.getTemplateTypeMap();
if (!typeMap.isEmpty()) {
TemplateTypeMapReplacer replacer = new TemplateTypeMapReplacer(
typeRegistry, typeMap);
required = required.visit(replacer);
}
required = required.restrictByNotNullOrUndefined();
if (!found.isSubtype(required, this.subtypingMode)) {
// Implemented, but not correctly typed
FunctionType constructor =
implementedInterface.toObjectType().getConstructor();
JSError err =
JSError.make(
propNode,
HIDDEN_INTERFACE_PROPERTY_MISMATCH,
prop,
instance.toString(),
constructor.getTopMostDefiningType(prop).toString(),
required.toString(),
found.toString());
registerMismatch(found, required, err);
report(err);
}
}
} | java | private void expectInterfaceProperty(
Node n, ObjectType instance, ObjectType implementedInterface, String prop) {
StaticTypedSlot propSlot = instance.getSlot(prop);
if (propSlot == null) {
// Not implemented
String sourceName = n.getSourceFileName();
sourceName = nullToEmpty(sourceName);
registerMismatch(
instance,
implementedInterface,
report(
JSError.make(
n,
INTERFACE_METHOD_NOT_IMPLEMENTED,
prop,
implementedInterface.toString(),
instance.toString())));
} else {
Node propNode =
propSlot.getDeclaration() == null ? null : propSlot.getDeclaration().getNode();
// Fall back on the constructor node if we can't find a node for the
// property.
propNode = propNode == null ? n : propNode;
JSType found = propSlot.getType();
found = found.restrictByNotNullOrUndefined();
JSType required
= implementedInterface.getImplicitPrototype().getPropertyType(prop);
TemplateTypeMap typeMap = implementedInterface.getTemplateTypeMap();
if (!typeMap.isEmpty()) {
TemplateTypeMapReplacer replacer = new TemplateTypeMapReplacer(
typeRegistry, typeMap);
required = required.visit(replacer);
}
required = required.restrictByNotNullOrUndefined();
if (!found.isSubtype(required, this.subtypingMode)) {
// Implemented, but not correctly typed
FunctionType constructor =
implementedInterface.toObjectType().getConstructor();
JSError err =
JSError.make(
propNode,
HIDDEN_INTERFACE_PROPERTY_MISMATCH,
prop,
instance.toString(),
constructor.getTopMostDefiningType(prop).toString(),
required.toString(),
found.toString());
registerMismatch(found, required, err);
report(err);
}
}
} | [
"private",
"void",
"expectInterfaceProperty",
"(",
"Node",
"n",
",",
"ObjectType",
"instance",
",",
"ObjectType",
"implementedInterface",
",",
"String",
"prop",
")",
"{",
"StaticTypedSlot",
"propSlot",
"=",
"instance",
".",
"getSlot",
"(",
"prop",
")",
";",
"if",
"(",
"propSlot",
"==",
"null",
")",
"{",
"// Not implemented",
"String",
"sourceName",
"=",
"n",
".",
"getSourceFileName",
"(",
")",
";",
"sourceName",
"=",
"nullToEmpty",
"(",
"sourceName",
")",
";",
"registerMismatch",
"(",
"instance",
",",
"implementedInterface",
",",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"INTERFACE_METHOD_NOT_IMPLEMENTED",
",",
"prop",
",",
"implementedInterface",
".",
"toString",
"(",
")",
",",
"instance",
".",
"toString",
"(",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"Node",
"propNode",
"=",
"propSlot",
".",
"getDeclaration",
"(",
")",
"==",
"null",
"?",
"null",
":",
"propSlot",
".",
"getDeclaration",
"(",
")",
".",
"getNode",
"(",
")",
";",
"// Fall back on the constructor node if we can't find a node for the",
"// property.",
"propNode",
"=",
"propNode",
"==",
"null",
"?",
"n",
":",
"propNode",
";",
"JSType",
"found",
"=",
"propSlot",
".",
"getType",
"(",
")",
";",
"found",
"=",
"found",
".",
"restrictByNotNullOrUndefined",
"(",
")",
";",
"JSType",
"required",
"=",
"implementedInterface",
".",
"getImplicitPrototype",
"(",
")",
".",
"getPropertyType",
"(",
"prop",
")",
";",
"TemplateTypeMap",
"typeMap",
"=",
"implementedInterface",
".",
"getTemplateTypeMap",
"(",
")",
";",
"if",
"(",
"!",
"typeMap",
".",
"isEmpty",
"(",
")",
")",
"{",
"TemplateTypeMapReplacer",
"replacer",
"=",
"new",
"TemplateTypeMapReplacer",
"(",
"typeRegistry",
",",
"typeMap",
")",
";",
"required",
"=",
"required",
".",
"visit",
"(",
"replacer",
")",
";",
"}",
"required",
"=",
"required",
".",
"restrictByNotNullOrUndefined",
"(",
")",
";",
"if",
"(",
"!",
"found",
".",
"isSubtype",
"(",
"required",
",",
"this",
".",
"subtypingMode",
")",
")",
"{",
"// Implemented, but not correctly typed",
"FunctionType",
"constructor",
"=",
"implementedInterface",
".",
"toObjectType",
"(",
")",
".",
"getConstructor",
"(",
")",
";",
"JSError",
"err",
"=",
"JSError",
".",
"make",
"(",
"propNode",
",",
"HIDDEN_INTERFACE_PROPERTY_MISMATCH",
",",
"prop",
",",
"instance",
".",
"toString",
"(",
")",
",",
"constructor",
".",
"getTopMostDefiningType",
"(",
"prop",
")",
".",
"toString",
"(",
")",
",",
"required",
".",
"toString",
"(",
")",
",",
"found",
".",
"toString",
"(",
")",
")",
";",
"registerMismatch",
"(",
"found",
",",
"required",
",",
"err",
")",
";",
"report",
"(",
"err",
")",
";",
"}",
"}",
"}"
] | Expect that the property in an interface that this type implements is implemented and correctly
typed. | [
"Expect",
"that",
"the",
"property",
"in",
"an",
"interface",
"that",
"this",
"type",
"implements",
"is",
"implemented",
"and",
"correctly",
"typed",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L893-L948 |
23,957 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.expectAbstractMethodsImplemented | void expectAbstractMethodsImplemented(Node n, FunctionType ctorType) {
checkArgument(ctorType.isConstructor());
Map<String, ObjectType> abstractMethodSuperTypeMap = new LinkedHashMap<>();
FunctionType currSuperCtor = ctorType.getSuperClassConstructor();
if (currSuperCtor == null || !currSuperCtor.isAbstract()) {
return;
}
while (currSuperCtor != null && currSuperCtor.isAbstract()) {
ObjectType superType = currSuperCtor.getInstanceType();
for (String prop :
currSuperCtor.getInstanceType().getImplicitPrototype().getOwnPropertyNames()) {
FunctionType maybeAbstractMethod = superType.findPropertyType(prop).toMaybeFunctionType();
if (maybeAbstractMethod != null
&& maybeAbstractMethod.isAbstract()
&& !abstractMethodSuperTypeMap.containsKey(prop)) {
abstractMethodSuperTypeMap.put(prop, superType);
}
}
currSuperCtor = currSuperCtor.getSuperClassConstructor();
}
ObjectType instance = ctorType.getInstanceType();
for (Map.Entry<String, ObjectType> entry : abstractMethodSuperTypeMap.entrySet()) {
String method = entry.getKey();
ObjectType superType = entry.getValue();
FunctionType abstractMethod = instance.findPropertyType(method).toMaybeFunctionType();
if (abstractMethod == null || abstractMethod.isAbstract()) {
String sourceName = n.getSourceFileName();
sourceName = nullToEmpty(sourceName);
registerMismatch(
instance,
superType,
report(
JSError.make(
n,
ABSTRACT_METHOD_NOT_IMPLEMENTED,
method,
superType.toString(),
instance.toString())));
}
}
} | java | void expectAbstractMethodsImplemented(Node n, FunctionType ctorType) {
checkArgument(ctorType.isConstructor());
Map<String, ObjectType> abstractMethodSuperTypeMap = new LinkedHashMap<>();
FunctionType currSuperCtor = ctorType.getSuperClassConstructor();
if (currSuperCtor == null || !currSuperCtor.isAbstract()) {
return;
}
while (currSuperCtor != null && currSuperCtor.isAbstract()) {
ObjectType superType = currSuperCtor.getInstanceType();
for (String prop :
currSuperCtor.getInstanceType().getImplicitPrototype().getOwnPropertyNames()) {
FunctionType maybeAbstractMethod = superType.findPropertyType(prop).toMaybeFunctionType();
if (maybeAbstractMethod != null
&& maybeAbstractMethod.isAbstract()
&& !abstractMethodSuperTypeMap.containsKey(prop)) {
abstractMethodSuperTypeMap.put(prop, superType);
}
}
currSuperCtor = currSuperCtor.getSuperClassConstructor();
}
ObjectType instance = ctorType.getInstanceType();
for (Map.Entry<String, ObjectType> entry : abstractMethodSuperTypeMap.entrySet()) {
String method = entry.getKey();
ObjectType superType = entry.getValue();
FunctionType abstractMethod = instance.findPropertyType(method).toMaybeFunctionType();
if (abstractMethod == null || abstractMethod.isAbstract()) {
String sourceName = n.getSourceFileName();
sourceName = nullToEmpty(sourceName);
registerMismatch(
instance,
superType,
report(
JSError.make(
n,
ABSTRACT_METHOD_NOT_IMPLEMENTED,
method,
superType.toString(),
instance.toString())));
}
}
} | [
"void",
"expectAbstractMethodsImplemented",
"(",
"Node",
"n",
",",
"FunctionType",
"ctorType",
")",
"{",
"checkArgument",
"(",
"ctorType",
".",
"isConstructor",
"(",
")",
")",
";",
"Map",
"<",
"String",
",",
"ObjectType",
">",
"abstractMethodSuperTypeMap",
"=",
"new",
"LinkedHashMap",
"<>",
"(",
")",
";",
"FunctionType",
"currSuperCtor",
"=",
"ctorType",
".",
"getSuperClassConstructor",
"(",
")",
";",
"if",
"(",
"currSuperCtor",
"==",
"null",
"||",
"!",
"currSuperCtor",
".",
"isAbstract",
"(",
")",
")",
"{",
"return",
";",
"}",
"while",
"(",
"currSuperCtor",
"!=",
"null",
"&&",
"currSuperCtor",
".",
"isAbstract",
"(",
")",
")",
"{",
"ObjectType",
"superType",
"=",
"currSuperCtor",
".",
"getInstanceType",
"(",
")",
";",
"for",
"(",
"String",
"prop",
":",
"currSuperCtor",
".",
"getInstanceType",
"(",
")",
".",
"getImplicitPrototype",
"(",
")",
".",
"getOwnPropertyNames",
"(",
")",
")",
"{",
"FunctionType",
"maybeAbstractMethod",
"=",
"superType",
".",
"findPropertyType",
"(",
"prop",
")",
".",
"toMaybeFunctionType",
"(",
")",
";",
"if",
"(",
"maybeAbstractMethod",
"!=",
"null",
"&&",
"maybeAbstractMethod",
".",
"isAbstract",
"(",
")",
"&&",
"!",
"abstractMethodSuperTypeMap",
".",
"containsKey",
"(",
"prop",
")",
")",
"{",
"abstractMethodSuperTypeMap",
".",
"put",
"(",
"prop",
",",
"superType",
")",
";",
"}",
"}",
"currSuperCtor",
"=",
"currSuperCtor",
".",
"getSuperClassConstructor",
"(",
")",
";",
"}",
"ObjectType",
"instance",
"=",
"ctorType",
".",
"getInstanceType",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"String",
",",
"ObjectType",
">",
"entry",
":",
"abstractMethodSuperTypeMap",
".",
"entrySet",
"(",
")",
")",
"{",
"String",
"method",
"=",
"entry",
".",
"getKey",
"(",
")",
";",
"ObjectType",
"superType",
"=",
"entry",
".",
"getValue",
"(",
")",
";",
"FunctionType",
"abstractMethod",
"=",
"instance",
".",
"findPropertyType",
"(",
"method",
")",
".",
"toMaybeFunctionType",
"(",
")",
";",
"if",
"(",
"abstractMethod",
"==",
"null",
"||",
"abstractMethod",
".",
"isAbstract",
"(",
")",
")",
"{",
"String",
"sourceName",
"=",
"n",
".",
"getSourceFileName",
"(",
")",
";",
"sourceName",
"=",
"nullToEmpty",
"(",
"sourceName",
")",
";",
"registerMismatch",
"(",
"instance",
",",
"superType",
",",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"ABSTRACT_METHOD_NOT_IMPLEMENTED",
",",
"method",
",",
"superType",
".",
"toString",
"(",
")",
",",
"instance",
".",
"toString",
"(",
")",
")",
")",
")",
";",
"}",
"}",
"}"
] | For a concrete class, expect that all abstract methods that haven't been implemented by any of
the super classes on the inheritance chain are implemented. | [
"For",
"a",
"concrete",
"class",
"expect",
"that",
"all",
"abstract",
"methods",
"that",
"haven",
"t",
"been",
"implemented",
"by",
"any",
"of",
"the",
"super",
"classes",
"on",
"the",
"inheritance",
"chain",
"are",
"implemented",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L954-L997 |
23,958 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.registerMismatchAndReport | private void registerMismatchAndReport(
Node n,
DiagnosticType diagnostic,
String msg,
JSType found,
JSType required,
Set<String> missing,
Set<String> mismatch) {
String foundRequiredFormatted = formatFoundRequired(msg, found, required, missing, mismatch);
JSError err = JSError.make(n, diagnostic, foundRequiredFormatted);
registerMismatch(found, required, err);
report(err);
} | java | private void registerMismatchAndReport(
Node n,
DiagnosticType diagnostic,
String msg,
JSType found,
JSType required,
Set<String> missing,
Set<String> mismatch) {
String foundRequiredFormatted = formatFoundRequired(msg, found, required, missing, mismatch);
JSError err = JSError.make(n, diagnostic, foundRequiredFormatted);
registerMismatch(found, required, err);
report(err);
} | [
"private",
"void",
"registerMismatchAndReport",
"(",
"Node",
"n",
",",
"DiagnosticType",
"diagnostic",
",",
"String",
"msg",
",",
"JSType",
"found",
",",
"JSType",
"required",
",",
"Set",
"<",
"String",
">",
"missing",
",",
"Set",
"<",
"String",
">",
"mismatch",
")",
"{",
"String",
"foundRequiredFormatted",
"=",
"formatFoundRequired",
"(",
"msg",
",",
"found",
",",
"required",
",",
"missing",
",",
"mismatch",
")",
";",
"JSError",
"err",
"=",
"JSError",
".",
"make",
"(",
"n",
",",
"diagnostic",
",",
"foundRequiredFormatted",
")",
";",
"registerMismatch",
"(",
"found",
",",
"required",
",",
"err",
")",
";",
"report",
"(",
"err",
")",
";",
"}"
] | Used both for TYPE_MISMATCH_WARNING and INVALID_OPERAND_TYPE. | [
"Used",
"both",
"for",
"TYPE_MISMATCH_WARNING",
"and",
"INVALID_OPERAND_TYPE",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L1037-L1049 |
23,959 | google/closure-compiler | src/com/google/javascript/jscomp/TypeValidator.java | TypeValidator.registerMismatch | private void registerMismatch(JSType found, JSType required, JSError error) {
TypeMismatch.registerMismatch(
this.mismatches, this.implicitInterfaceUses, found, required, error);
} | java | private void registerMismatch(JSType found, JSType required, JSError error) {
TypeMismatch.registerMismatch(
this.mismatches, this.implicitInterfaceUses, found, required, error);
} | [
"private",
"void",
"registerMismatch",
"(",
"JSType",
"found",
",",
"JSType",
"required",
",",
"JSError",
"error",
")",
"{",
"TypeMismatch",
".",
"registerMismatch",
"(",
"this",
".",
"mismatches",
",",
"this",
".",
"implicitInterfaceUses",
",",
"found",
",",
"required",
",",
"error",
")",
";",
"}"
] | Registers a type mismatch into the universe of mismatches owned by this pass. | [
"Registers",
"a",
"type",
"mismatch",
"into",
"the",
"universe",
"of",
"mismatches",
"owned",
"by",
"this",
"pass",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/TypeValidator.java#L1052-L1055 |
23,960 | google/closure-compiler | src/com/google/javascript/jscomp/OptimizeParameters.java | OptimizeParameters.tryEliminateOptionalArgs | private void tryEliminateOptionalArgs(ArrayList<Node> refs) {
// Count the maximum number of arguments passed into this function all
// all points of the program.
int maxArgs = -1;
for (Node n : refs) {
if (ReferenceMap.isCallOrNewTarget(n)) {
int numArgs = 0;
Node firstArg = ReferenceMap.getFirstArgumentForCallOrNewOrDotCall(n);
for (Node c = firstArg; c != null; c = c.getNext()) {
numArgs++;
if (c.isSpread()) {
// Bail: with spread we must assume all parameters are used, don't waste
// any more time.
return;
}
}
if (numArgs > maxArgs) {
maxArgs = numArgs;
}
}
}
for (Node fn : ReferenceMap.getFunctionNodes(refs).values()) {
eliminateParamsAfter(fn, maxArgs);
}
} | java | private void tryEliminateOptionalArgs(ArrayList<Node> refs) {
// Count the maximum number of arguments passed into this function all
// all points of the program.
int maxArgs = -1;
for (Node n : refs) {
if (ReferenceMap.isCallOrNewTarget(n)) {
int numArgs = 0;
Node firstArg = ReferenceMap.getFirstArgumentForCallOrNewOrDotCall(n);
for (Node c = firstArg; c != null; c = c.getNext()) {
numArgs++;
if (c.isSpread()) {
// Bail: with spread we must assume all parameters are used, don't waste
// any more time.
return;
}
}
if (numArgs > maxArgs) {
maxArgs = numArgs;
}
}
}
for (Node fn : ReferenceMap.getFunctionNodes(refs).values()) {
eliminateParamsAfter(fn, maxArgs);
}
} | [
"private",
"void",
"tryEliminateOptionalArgs",
"(",
"ArrayList",
"<",
"Node",
">",
"refs",
")",
"{",
"// Count the maximum number of arguments passed into this function all",
"// all points of the program.",
"int",
"maxArgs",
"=",
"-",
"1",
";",
"for",
"(",
"Node",
"n",
":",
"refs",
")",
"{",
"if",
"(",
"ReferenceMap",
".",
"isCallOrNewTarget",
"(",
"n",
")",
")",
"{",
"int",
"numArgs",
"=",
"0",
";",
"Node",
"firstArg",
"=",
"ReferenceMap",
".",
"getFirstArgumentForCallOrNewOrDotCall",
"(",
"n",
")",
";",
"for",
"(",
"Node",
"c",
"=",
"firstArg",
";",
"c",
"!=",
"null",
";",
"c",
"=",
"c",
".",
"getNext",
"(",
")",
")",
"{",
"numArgs",
"++",
";",
"if",
"(",
"c",
".",
"isSpread",
"(",
")",
")",
"{",
"// Bail: with spread we must assume all parameters are used, don't waste",
"// any more time.",
"return",
";",
"}",
"}",
"if",
"(",
"numArgs",
">",
"maxArgs",
")",
"{",
"maxArgs",
"=",
"numArgs",
";",
"}",
"}",
"}",
"for",
"(",
"Node",
"fn",
":",
"ReferenceMap",
".",
"getFunctionNodes",
"(",
"refs",
")",
".",
"values",
"(",
")",
")",
"{",
"eliminateParamsAfter",
"(",
"fn",
",",
"maxArgs",
")",
";",
"}",
"}"
] | Removes any optional parameters if no callers specifies it as an argument. | [
"Removes",
"any",
"optional",
"parameters",
"if",
"no",
"callers",
"specifies",
"it",
"as",
"an",
"argument",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/OptimizeParameters.java#L461-L488 |
23,961 | google/closure-compiler | src/com/google/javascript/jscomp/OptimizeParameters.java | OptimizeParameters.tryEliminateConstantArgs | private void tryEliminateConstantArgs(ArrayList<Node> refs) {
List<Parameter> parameters = findFixedArguments(refs);
if (parameters == null) {
return;
}
ImmutableListMultimap<Node, Node> fns = ReferenceMap.getFunctionNodes(refs);
if (fns.size() > 1) {
// TODO(johnlenz): support moving simple constants.
// This requires cloning the tree and avoiding adding additional calls/definitions that will
// invalidate the reference map
return;
}
// Only one definition is currently supported.
Node fn = Iterables.getOnlyElement(fns.values());
boolean continueLooking = adjustForConstraints(fn, parameters);
if (!continueLooking) {
return;
}
// Found something to do, move the values from the call sites to the function definitions.
for (Node n : refs) {
if (ReferenceMap.isCallOrNewTarget(n) && !alreadyRemoved(n)) {
optimizeCallSite(parameters, n);
}
}
optimizeFunctionDefinition(parameters, fn);
} | java | private void tryEliminateConstantArgs(ArrayList<Node> refs) {
List<Parameter> parameters = findFixedArguments(refs);
if (parameters == null) {
return;
}
ImmutableListMultimap<Node, Node> fns = ReferenceMap.getFunctionNodes(refs);
if (fns.size() > 1) {
// TODO(johnlenz): support moving simple constants.
// This requires cloning the tree and avoiding adding additional calls/definitions that will
// invalidate the reference map
return;
}
// Only one definition is currently supported.
Node fn = Iterables.getOnlyElement(fns.values());
boolean continueLooking = adjustForConstraints(fn, parameters);
if (!continueLooking) {
return;
}
// Found something to do, move the values from the call sites to the function definitions.
for (Node n : refs) {
if (ReferenceMap.isCallOrNewTarget(n) && !alreadyRemoved(n)) {
optimizeCallSite(parameters, n);
}
}
optimizeFunctionDefinition(parameters, fn);
} | [
"private",
"void",
"tryEliminateConstantArgs",
"(",
"ArrayList",
"<",
"Node",
">",
"refs",
")",
"{",
"List",
"<",
"Parameter",
">",
"parameters",
"=",
"findFixedArguments",
"(",
"refs",
")",
";",
"if",
"(",
"parameters",
"==",
"null",
")",
"{",
"return",
";",
"}",
"ImmutableListMultimap",
"<",
"Node",
",",
"Node",
">",
"fns",
"=",
"ReferenceMap",
".",
"getFunctionNodes",
"(",
"refs",
")",
";",
"if",
"(",
"fns",
".",
"size",
"(",
")",
">",
"1",
")",
"{",
"// TODO(johnlenz): support moving simple constants.",
"// This requires cloning the tree and avoiding adding additional calls/definitions that will",
"// invalidate the reference map",
"return",
";",
"}",
"// Only one definition is currently supported.",
"Node",
"fn",
"=",
"Iterables",
".",
"getOnlyElement",
"(",
"fns",
".",
"values",
"(",
")",
")",
";",
"boolean",
"continueLooking",
"=",
"adjustForConstraints",
"(",
"fn",
",",
"parameters",
")",
";",
"if",
"(",
"!",
"continueLooking",
")",
"{",
"return",
";",
"}",
"// Found something to do, move the values from the call sites to the function definitions.",
"for",
"(",
"Node",
"n",
":",
"refs",
")",
"{",
"if",
"(",
"ReferenceMap",
".",
"isCallOrNewTarget",
"(",
"n",
")",
"&&",
"!",
"alreadyRemoved",
"(",
"n",
")",
")",
"{",
"optimizeCallSite",
"(",
"parameters",
",",
"n",
")",
";",
"}",
"}",
"optimizeFunctionDefinition",
"(",
"parameters",
",",
"fn",
")",
";",
"}"
] | Eliminate parameters if they are always constant.
function foo(a, b) {...}
foo(1,2);
foo(1,3)
becomes
function foo(b) { var a = 1 ... }
foo(2);
foo(3);
@param refs A list of references to the symbol (name or property) as vetted by
#isCandidate. | [
"Eliminate",
"parameters",
"if",
"they",
"are",
"always",
"constant",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/OptimizeParameters.java#L504-L534 |
23,962 | google/closure-compiler | src/com/google/javascript/jscomp/OptimizeParameters.java | OptimizeParameters.findFixedParameters | private boolean findFixedParameters(List<Parameter> parameters, Node cur) {
boolean anyMovable = false;
int index = 0;
while (cur != null) {
Parameter p;
if (index >= parameters.size()) {
p = new Parameter(cur, false);
parameters.add(p);
setParameterSideEffectInfo(p, cur);
} else {
p = parameters.get(index);
if (p.shouldRemove()) {
Node value = p.getArg();
if (!cur.isEquivalentTo(value)) {
p.setShouldRemove(false);
} else {
anyMovable = true;
}
}
}
cur = cur.getNext();
index++;
}
for (; index < parameters.size(); index++) {
parameters.get(index).setShouldRemove(false);
}
return anyMovable;
} | java | private boolean findFixedParameters(List<Parameter> parameters, Node cur) {
boolean anyMovable = false;
int index = 0;
while (cur != null) {
Parameter p;
if (index >= parameters.size()) {
p = new Parameter(cur, false);
parameters.add(p);
setParameterSideEffectInfo(p, cur);
} else {
p = parameters.get(index);
if (p.shouldRemove()) {
Node value = p.getArg();
if (!cur.isEquivalentTo(value)) {
p.setShouldRemove(false);
} else {
anyMovable = true;
}
}
}
cur = cur.getNext();
index++;
}
for (; index < parameters.size(); index++) {
parameters.get(index).setShouldRemove(false);
}
return anyMovable;
} | [
"private",
"boolean",
"findFixedParameters",
"(",
"List",
"<",
"Parameter",
">",
"parameters",
",",
"Node",
"cur",
")",
"{",
"boolean",
"anyMovable",
"=",
"false",
";",
"int",
"index",
"=",
"0",
";",
"while",
"(",
"cur",
"!=",
"null",
")",
"{",
"Parameter",
"p",
";",
"if",
"(",
"index",
">=",
"parameters",
".",
"size",
"(",
")",
")",
"{",
"p",
"=",
"new",
"Parameter",
"(",
"cur",
",",
"false",
")",
";",
"parameters",
".",
"add",
"(",
"p",
")",
";",
"setParameterSideEffectInfo",
"(",
"p",
",",
"cur",
")",
";",
"}",
"else",
"{",
"p",
"=",
"parameters",
".",
"get",
"(",
"index",
")",
";",
"if",
"(",
"p",
".",
"shouldRemove",
"(",
")",
")",
"{",
"Node",
"value",
"=",
"p",
".",
"getArg",
"(",
")",
";",
"if",
"(",
"!",
"cur",
".",
"isEquivalentTo",
"(",
"value",
")",
")",
"{",
"p",
".",
"setShouldRemove",
"(",
"false",
")",
";",
"}",
"else",
"{",
"anyMovable",
"=",
"true",
";",
"}",
"}",
"}",
"cur",
"=",
"cur",
".",
"getNext",
"(",
")",
";",
"index",
"++",
";",
"}",
"for",
"(",
";",
"index",
"<",
"parameters",
".",
"size",
"(",
")",
";",
"index",
"++",
")",
"{",
"parameters",
".",
"get",
"(",
"index",
")",
".",
"setShouldRemove",
"(",
"false",
")",
";",
"}",
"return",
"anyMovable",
";",
"}"
] | Determine which parameters use the same expression.
@return Whether any parameter was found that can be updated. | [
"Determine",
"which",
"parameters",
"use",
"the",
"same",
"expression",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/OptimizeParameters.java#L680-L710 |
23,963 | google/closure-compiler | src/com/google/javascript/jscomp/OptimizeParameters.java | OptimizeParameters.eliminateParamsAfter | private void eliminateParamsAfter(Node fnNode, int argIndex) {
Node formalArgPtr = NodeUtil.getFunctionParameters(fnNode).getFirstChild();
while (argIndex != 0 && formalArgPtr != null) {
formalArgPtr = formalArgPtr.getNext();
argIndex--;
}
eliminateParamsAfter(fnNode, formalArgPtr);
} | java | private void eliminateParamsAfter(Node fnNode, int argIndex) {
Node formalArgPtr = NodeUtil.getFunctionParameters(fnNode).getFirstChild();
while (argIndex != 0 && formalArgPtr != null) {
formalArgPtr = formalArgPtr.getNext();
argIndex--;
}
eliminateParamsAfter(fnNode, formalArgPtr);
} | [
"private",
"void",
"eliminateParamsAfter",
"(",
"Node",
"fnNode",
",",
"int",
"argIndex",
")",
"{",
"Node",
"formalArgPtr",
"=",
"NodeUtil",
".",
"getFunctionParameters",
"(",
"fnNode",
")",
".",
"getFirstChild",
"(",
")",
";",
"while",
"(",
"argIndex",
"!=",
"0",
"&&",
"formalArgPtr",
"!=",
"null",
")",
"{",
"formalArgPtr",
"=",
"formalArgPtr",
".",
"getNext",
"(",
")",
";",
"argIndex",
"--",
";",
"}",
"eliminateParamsAfter",
"(",
"fnNode",
",",
"formalArgPtr",
")",
";",
"}"
] | Removes all formal parameters starting at argIndex. | [
"Removes",
"all",
"formal",
"parameters",
"starting",
"at",
"argIndex",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/OptimizeParameters.java#L936-L943 |
23,964 | google/closure-compiler | src/com/google/javascript/jscomp/OptimizeParameters.java | OptimizeParameters.eliminateCallTargetArgAt | private void eliminateCallTargetArgAt(Node ref, int argIndex) {
Node callArgNode = ReferenceMap.getArgumentForCallOrNewOrDotCall(ref, argIndex);
if (callArgNode != null) {
NodeUtil.deleteNode(callArgNode, compiler);
}
} | java | private void eliminateCallTargetArgAt(Node ref, int argIndex) {
Node callArgNode = ReferenceMap.getArgumentForCallOrNewOrDotCall(ref, argIndex);
if (callArgNode != null) {
NodeUtil.deleteNode(callArgNode, compiler);
}
} | [
"private",
"void",
"eliminateCallTargetArgAt",
"(",
"Node",
"ref",
",",
"int",
"argIndex",
")",
"{",
"Node",
"callArgNode",
"=",
"ReferenceMap",
".",
"getArgumentForCallOrNewOrDotCall",
"(",
"ref",
",",
"argIndex",
")",
";",
"if",
"(",
"callArgNode",
"!=",
"null",
")",
"{",
"NodeUtil",
".",
"deleteNode",
"(",
"callArgNode",
",",
"compiler",
")",
";",
"}",
"}"
] | Eliminates the parameter from a function call.
@param definitionFinder The definition and use sites index.
@param p
@param call The function call node
@param argIndex The index of the argument to remove. | [
"Eliminates",
"the",
"parameter",
"from",
"a",
"function",
"call",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/OptimizeParameters.java#L975-L980 |
23,965 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.maybeUseNativeClassTemplateNames | private boolean maybeUseNativeClassTemplateNames(JSDocInfo info) {
// TODO(b/74253232): maybeGetNativeTypesOfBuiltin should also handle cases where a local type
// declaration shadows a templatized native type.
ImmutableList<TemplateType> nativeKeys = typeRegistry.maybeGetTemplateTypesOfBuiltin(fnName);
// TODO(b/73386087): Make infoTemplateTypeNames.size() == nativeKeys.size() a
// Preconditions check. It currently fails for "var symbol" in the externs.
if (nativeKeys != null && info.getTemplateTypeNames().size() == nativeKeys.size()) {
this.templateTypeNames = nativeKeys;
return true;
}
return false;
} | java | private boolean maybeUseNativeClassTemplateNames(JSDocInfo info) {
// TODO(b/74253232): maybeGetNativeTypesOfBuiltin should also handle cases where a local type
// declaration shadows a templatized native type.
ImmutableList<TemplateType> nativeKeys = typeRegistry.maybeGetTemplateTypesOfBuiltin(fnName);
// TODO(b/73386087): Make infoTemplateTypeNames.size() == nativeKeys.size() a
// Preconditions check. It currently fails for "var symbol" in the externs.
if (nativeKeys != null && info.getTemplateTypeNames().size() == nativeKeys.size()) {
this.templateTypeNames = nativeKeys;
return true;
}
return false;
} | [
"private",
"boolean",
"maybeUseNativeClassTemplateNames",
"(",
"JSDocInfo",
"info",
")",
"{",
"// TODO(b/74253232): maybeGetNativeTypesOfBuiltin should also handle cases where a local type",
"// declaration shadows a templatized native type.",
"ImmutableList",
"<",
"TemplateType",
">",
"nativeKeys",
"=",
"typeRegistry",
".",
"maybeGetTemplateTypesOfBuiltin",
"(",
"fnName",
")",
";",
"// TODO(b/73386087): Make infoTemplateTypeNames.size() == nativeKeys.size() a",
"// Preconditions check. It currently fails for \"var symbol\" in the externs.",
"if",
"(",
"nativeKeys",
"!=",
"null",
"&&",
"info",
".",
"getTemplateTypeNames",
"(",
")",
".",
"size",
"(",
")",
"==",
"nativeKeys",
".",
"size",
"(",
")",
")",
"{",
"this",
".",
"templateTypeNames",
"=",
"nativeKeys",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Clobber the templateTypeNames from the JSDoc with builtin ones for native types. | [
"Clobber",
"the",
"templateTypeNames",
"from",
"the",
"JSDoc",
"with",
"builtin",
"ones",
"for",
"native",
"types",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L402-L413 |
23,966 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.inferParameterTypes | FunctionTypeBuilder inferParameterTypes(JSDocInfo info) {
// Create a fake args parent.
Node lp = IR.paramList();
for (String name : info.getParameterNames()) {
lp.addChildToBack(IR.name(name));
}
return inferParameterTypes(lp, info);
} | java | FunctionTypeBuilder inferParameterTypes(JSDocInfo info) {
// Create a fake args parent.
Node lp = IR.paramList();
for (String name : info.getParameterNames()) {
lp.addChildToBack(IR.name(name));
}
return inferParameterTypes(lp, info);
} | [
"FunctionTypeBuilder",
"inferParameterTypes",
"(",
"JSDocInfo",
"info",
")",
"{",
"// Create a fake args parent.",
"Node",
"lp",
"=",
"IR",
".",
"paramList",
"(",
")",
";",
"for",
"(",
"String",
"name",
":",
"info",
".",
"getParameterNames",
"(",
")",
")",
"{",
"lp",
".",
"addChildToBack",
"(",
"IR",
".",
"name",
"(",
"name",
")",
")",
";",
"}",
"return",
"inferParameterTypes",
"(",
"lp",
",",
"info",
")",
";",
"}"
] | Infer the parameter types from the doc info alone. | [
"Infer",
"the",
"parameter",
"types",
"from",
"the",
"doc",
"info",
"alone",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L560-L568 |
23,967 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.inferConstructorParameters | FunctionTypeBuilder inferConstructorParameters(FunctionType superCtor) {
inferImplicitConstructorParameters(superCtor.getParametersNode().cloneTree());
// Look for template parameters in superCtor that are missing from its instance type.
setConstructorTemplateTypeNames(superCtor.getConstructorOnlyTemplateParameters(), null);
return this;
} | java | FunctionTypeBuilder inferConstructorParameters(FunctionType superCtor) {
inferImplicitConstructorParameters(superCtor.getParametersNode().cloneTree());
// Look for template parameters in superCtor that are missing from its instance type.
setConstructorTemplateTypeNames(superCtor.getConstructorOnlyTemplateParameters(), null);
return this;
} | [
"FunctionTypeBuilder",
"inferConstructorParameters",
"(",
"FunctionType",
"superCtor",
")",
"{",
"inferImplicitConstructorParameters",
"(",
"superCtor",
".",
"getParametersNode",
"(",
")",
".",
"cloneTree",
"(",
")",
")",
";",
"// Look for template parameters in superCtor that are missing from its instance type.",
"setConstructorTemplateTypeNames",
"(",
"superCtor",
".",
"getConstructorOnlyTemplateParameters",
"(",
")",
",",
"null",
")",
";",
"return",
"this",
";",
"}"
] | Infer constructor parameters from the superclass constructor. | [
"Infer",
"constructor",
"parameters",
"from",
"the",
"superclass",
"constructor",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L694-L701 |
23,968 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.addParameter | private boolean addParameter(FunctionParamBuilder builder,
JSType paramType, boolean warnedAboutArgList,
boolean isOptional, boolean isVarArgs) {
boolean emittedWarning = false;
if (isOptional) {
// Remembering that an optional parameter has been encountered
// so that if a non optional param is encountered later, an
// error can be reported.
if (!builder.addOptionalParams(paramType) && !warnedAboutArgList) {
reportWarning(VAR_ARGS_MUST_BE_LAST);
emittedWarning = true;
}
} else if (isVarArgs) {
if (!builder.addVarArgs(paramType) && !warnedAboutArgList) {
reportWarning(VAR_ARGS_MUST_BE_LAST);
emittedWarning = true;
}
} else {
if (!builder.addRequiredParams(paramType) && !warnedAboutArgList) {
// An optional parameter was seen and this argument is not an optional
// or var arg so it is an error.
if (builder.hasVarArgs()) {
reportWarning(VAR_ARGS_MUST_BE_LAST);
} else {
reportWarning(OPTIONAL_ARG_AT_END);
}
emittedWarning = true;
}
}
return emittedWarning;
} | java | private boolean addParameter(FunctionParamBuilder builder,
JSType paramType, boolean warnedAboutArgList,
boolean isOptional, boolean isVarArgs) {
boolean emittedWarning = false;
if (isOptional) {
// Remembering that an optional parameter has been encountered
// so that if a non optional param is encountered later, an
// error can be reported.
if (!builder.addOptionalParams(paramType) && !warnedAboutArgList) {
reportWarning(VAR_ARGS_MUST_BE_LAST);
emittedWarning = true;
}
} else if (isVarArgs) {
if (!builder.addVarArgs(paramType) && !warnedAboutArgList) {
reportWarning(VAR_ARGS_MUST_BE_LAST);
emittedWarning = true;
}
} else {
if (!builder.addRequiredParams(paramType) && !warnedAboutArgList) {
// An optional parameter was seen and this argument is not an optional
// or var arg so it is an error.
if (builder.hasVarArgs()) {
reportWarning(VAR_ARGS_MUST_BE_LAST);
} else {
reportWarning(OPTIONAL_ARG_AT_END);
}
emittedWarning = true;
}
}
return emittedWarning;
} | [
"private",
"boolean",
"addParameter",
"(",
"FunctionParamBuilder",
"builder",
",",
"JSType",
"paramType",
",",
"boolean",
"warnedAboutArgList",
",",
"boolean",
"isOptional",
",",
"boolean",
"isVarArgs",
")",
"{",
"boolean",
"emittedWarning",
"=",
"false",
";",
"if",
"(",
"isOptional",
")",
"{",
"// Remembering that an optional parameter has been encountered",
"// so that if a non optional param is encountered later, an",
"// error can be reported.",
"if",
"(",
"!",
"builder",
".",
"addOptionalParams",
"(",
"paramType",
")",
"&&",
"!",
"warnedAboutArgList",
")",
"{",
"reportWarning",
"(",
"VAR_ARGS_MUST_BE_LAST",
")",
";",
"emittedWarning",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"isVarArgs",
")",
"{",
"if",
"(",
"!",
"builder",
".",
"addVarArgs",
"(",
"paramType",
")",
"&&",
"!",
"warnedAboutArgList",
")",
"{",
"reportWarning",
"(",
"VAR_ARGS_MUST_BE_LAST",
")",
";",
"emittedWarning",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"builder",
".",
"addRequiredParams",
"(",
"paramType",
")",
"&&",
"!",
"warnedAboutArgList",
")",
"{",
"// An optional parameter was seen and this argument is not an optional",
"// or var arg so it is an error.",
"if",
"(",
"builder",
".",
"hasVarArgs",
"(",
")",
")",
"{",
"reportWarning",
"(",
"VAR_ARGS_MUST_BE_LAST",
")",
";",
"}",
"else",
"{",
"reportWarning",
"(",
"OPTIONAL_ARG_AT_END",
")",
";",
"}",
"emittedWarning",
"=",
"true",
";",
"}",
"}",
"return",
"emittedWarning",
";",
"}"
] | Add a parameter to the param list.
@param builder A builder.
@param paramType The parameter type.
@param warnedAboutArgList Whether we've already warned about arg ordering
issues (like if optional args appeared before required ones).
@param isOptional Is this an optional parameter?
@param isVarArgs Is this a var args parameter?
@return Whether a warning was emitted. | [
"Add",
"a",
"parameter",
"to",
"the",
"param",
"list",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L810-L840 |
23,969 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.provideDefaultReturnType | private void provideDefaultReturnType() {
if (contents.getSourceNode() != null && contents.getSourceNode().isAsyncGeneratorFunction()) {
// Set the return type of a generator function to:
// @return {!AsyncGenerator<?>}
ObjectType generatorType = typeRegistry.getNativeObjectType(ASYNC_GENERATOR_TYPE);
returnType =
typeRegistry.createTemplatizedType(
generatorType, typeRegistry.getNativeType(UNKNOWN_TYPE));
return;
} else if (contents.getSourceNode() != null && contents.getSourceNode().isGeneratorFunction()) {
// Set the return type of a generator function to:
// @return {!Generator<?>}
ObjectType generatorType = typeRegistry.getNativeObjectType(GENERATOR_TYPE);
returnType =
typeRegistry.createTemplatizedType(
generatorType, typeRegistry.getNativeType(UNKNOWN_TYPE));
return;
}
JSType inferredReturnType = typeRegistry.getNativeType(UNKNOWN_TYPE);
if (!contents.mayHaveNonEmptyReturns()
&& !contents.mayHaveSingleThrow()
&& !contents.mayBeFromExterns()) {
// Infer return types for non-generator functions.
// We need to be extremely conservative about this, because of two
// competing needs.
// 1) If we infer the return type of f too widely, then we won't be able
// to assign f to other functions.
// 2) If we infer the return type of f too narrowly, then we won't be
// able to override f in subclasses.
// So we only infer in cases where the user doesn't expect to write
// @return annotations--when it's very obvious that the function returns
// nothing.
inferredReturnType = typeRegistry.getNativeType(VOID_TYPE);
returnTypeInferred = true;
}
if (contents.getSourceNode() != null && contents.getSourceNode().isAsyncFunction()) {
// Set the return type of an async function:
// @return {!Promise<?>} or @return {!Promise<undefined>}
ObjectType promiseType = typeRegistry.getNativeObjectType(PROMISE_TYPE);
returnType = typeRegistry.createTemplatizedType(promiseType, inferredReturnType);
} else {
returnType = inferredReturnType;
}
} | java | private void provideDefaultReturnType() {
if (contents.getSourceNode() != null && contents.getSourceNode().isAsyncGeneratorFunction()) {
// Set the return type of a generator function to:
// @return {!AsyncGenerator<?>}
ObjectType generatorType = typeRegistry.getNativeObjectType(ASYNC_GENERATOR_TYPE);
returnType =
typeRegistry.createTemplatizedType(
generatorType, typeRegistry.getNativeType(UNKNOWN_TYPE));
return;
} else if (contents.getSourceNode() != null && contents.getSourceNode().isGeneratorFunction()) {
// Set the return type of a generator function to:
// @return {!Generator<?>}
ObjectType generatorType = typeRegistry.getNativeObjectType(GENERATOR_TYPE);
returnType =
typeRegistry.createTemplatizedType(
generatorType, typeRegistry.getNativeType(UNKNOWN_TYPE));
return;
}
JSType inferredReturnType = typeRegistry.getNativeType(UNKNOWN_TYPE);
if (!contents.mayHaveNonEmptyReturns()
&& !contents.mayHaveSingleThrow()
&& !contents.mayBeFromExterns()) {
// Infer return types for non-generator functions.
// We need to be extremely conservative about this, because of two
// competing needs.
// 1) If we infer the return type of f too widely, then we won't be able
// to assign f to other functions.
// 2) If we infer the return type of f too narrowly, then we won't be
// able to override f in subclasses.
// So we only infer in cases where the user doesn't expect to write
// @return annotations--when it's very obvious that the function returns
// nothing.
inferredReturnType = typeRegistry.getNativeType(VOID_TYPE);
returnTypeInferred = true;
}
if (contents.getSourceNode() != null && contents.getSourceNode().isAsyncFunction()) {
// Set the return type of an async function:
// @return {!Promise<?>} or @return {!Promise<undefined>}
ObjectType promiseType = typeRegistry.getNativeObjectType(PROMISE_TYPE);
returnType = typeRegistry.createTemplatizedType(promiseType, inferredReturnType);
} else {
returnType = inferredReturnType;
}
} | [
"private",
"void",
"provideDefaultReturnType",
"(",
")",
"{",
"if",
"(",
"contents",
".",
"getSourceNode",
"(",
")",
"!=",
"null",
"&&",
"contents",
".",
"getSourceNode",
"(",
")",
".",
"isAsyncGeneratorFunction",
"(",
")",
")",
"{",
"// Set the return type of a generator function to:",
"// @return {!AsyncGenerator<?>}",
"ObjectType",
"generatorType",
"=",
"typeRegistry",
".",
"getNativeObjectType",
"(",
"ASYNC_GENERATOR_TYPE",
")",
";",
"returnType",
"=",
"typeRegistry",
".",
"createTemplatizedType",
"(",
"generatorType",
",",
"typeRegistry",
".",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
")",
";",
"return",
";",
"}",
"else",
"if",
"(",
"contents",
".",
"getSourceNode",
"(",
")",
"!=",
"null",
"&&",
"contents",
".",
"getSourceNode",
"(",
")",
".",
"isGeneratorFunction",
"(",
")",
")",
"{",
"// Set the return type of a generator function to:",
"// @return {!Generator<?>}",
"ObjectType",
"generatorType",
"=",
"typeRegistry",
".",
"getNativeObjectType",
"(",
"GENERATOR_TYPE",
")",
";",
"returnType",
"=",
"typeRegistry",
".",
"createTemplatizedType",
"(",
"generatorType",
",",
"typeRegistry",
".",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
")",
";",
"return",
";",
"}",
"JSType",
"inferredReturnType",
"=",
"typeRegistry",
".",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
";",
"if",
"(",
"!",
"contents",
".",
"mayHaveNonEmptyReturns",
"(",
")",
"&&",
"!",
"contents",
".",
"mayHaveSingleThrow",
"(",
")",
"&&",
"!",
"contents",
".",
"mayBeFromExterns",
"(",
")",
")",
"{",
"// Infer return types for non-generator functions.",
"// We need to be extremely conservative about this, because of two",
"// competing needs.",
"// 1) If we infer the return type of f too widely, then we won't be able",
"// to assign f to other functions.",
"// 2) If we infer the return type of f too narrowly, then we won't be",
"// able to override f in subclasses.",
"// So we only infer in cases where the user doesn't expect to write",
"// @return annotations--when it's very obvious that the function returns",
"// nothing.",
"inferredReturnType",
"=",
"typeRegistry",
".",
"getNativeType",
"(",
"VOID_TYPE",
")",
";",
"returnTypeInferred",
"=",
"true",
";",
"}",
"if",
"(",
"contents",
".",
"getSourceNode",
"(",
")",
"!=",
"null",
"&&",
"contents",
".",
"getSourceNode",
"(",
")",
".",
"isAsyncFunction",
"(",
")",
")",
"{",
"// Set the return type of an async function:",
"// @return {!Promise<?>} or @return {!Promise<undefined>}",
"ObjectType",
"promiseType",
"=",
"typeRegistry",
".",
"getNativeObjectType",
"(",
"PROMISE_TYPE",
")",
";",
"returnType",
"=",
"typeRegistry",
".",
"createTemplatizedType",
"(",
"promiseType",
",",
"inferredReturnType",
")",
";",
"}",
"else",
"{",
"returnType",
"=",
"inferredReturnType",
";",
"}",
"}"
] | Sets the returnType for this function using very basic type inference. | [
"Sets",
"the",
"returnType",
"for",
"this",
"function",
"using",
"very",
"basic",
"type",
"inference",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L843-L888 |
23,970 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.buildAndRegister | FunctionType buildAndRegister() {
if (returnType == null) {
provideDefaultReturnType();
checkNotNull(returnType);
}
if (parametersNode == null) {
throw new IllegalStateException(
"All Function types must have params and a return type");
}
FunctionType fnType;
if (isConstructor) {
fnType = getOrCreateConstructor();
} else if (isInterface) {
fnType = getOrCreateInterface();
} else {
fnType =
FunctionType.builder(typeRegistry)
.withName(fnName)
.withSourceNode(contents.getSourceNode())
.withParamsNode(parametersNode)
.withReturnType(returnType, returnTypeInferred)
.withTypeOfThis(thisType)
.withTemplateKeys(templateTypeNames)
.withIsAbstract(isAbstract)
.withClosurePrimitiveId(closurePrimitiveId)
.build();
maybeSetBaseType(fnType);
}
if (implementedInterfaces != null && fnType.isConstructor()) {
fnType.setImplementedInterfaces(implementedInterfaces);
}
if (extendedInterfaces != null) {
fnType.setExtendedInterfaces(extendedInterfaces);
}
if (isRecord) {
fnType.setImplicitMatch(true);
}
return fnType;
} | java | FunctionType buildAndRegister() {
if (returnType == null) {
provideDefaultReturnType();
checkNotNull(returnType);
}
if (parametersNode == null) {
throw new IllegalStateException(
"All Function types must have params and a return type");
}
FunctionType fnType;
if (isConstructor) {
fnType = getOrCreateConstructor();
} else if (isInterface) {
fnType = getOrCreateInterface();
} else {
fnType =
FunctionType.builder(typeRegistry)
.withName(fnName)
.withSourceNode(contents.getSourceNode())
.withParamsNode(parametersNode)
.withReturnType(returnType, returnTypeInferred)
.withTypeOfThis(thisType)
.withTemplateKeys(templateTypeNames)
.withIsAbstract(isAbstract)
.withClosurePrimitiveId(closurePrimitiveId)
.build();
maybeSetBaseType(fnType);
}
if (implementedInterfaces != null && fnType.isConstructor()) {
fnType.setImplementedInterfaces(implementedInterfaces);
}
if (extendedInterfaces != null) {
fnType.setExtendedInterfaces(extendedInterfaces);
}
if (isRecord) {
fnType.setImplicitMatch(true);
}
return fnType;
} | [
"FunctionType",
"buildAndRegister",
"(",
")",
"{",
"if",
"(",
"returnType",
"==",
"null",
")",
"{",
"provideDefaultReturnType",
"(",
")",
";",
"checkNotNull",
"(",
"returnType",
")",
";",
"}",
"if",
"(",
"parametersNode",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"All Function types must have params and a return type\"",
")",
";",
"}",
"FunctionType",
"fnType",
";",
"if",
"(",
"isConstructor",
")",
"{",
"fnType",
"=",
"getOrCreateConstructor",
"(",
")",
";",
"}",
"else",
"if",
"(",
"isInterface",
")",
"{",
"fnType",
"=",
"getOrCreateInterface",
"(",
")",
";",
"}",
"else",
"{",
"fnType",
"=",
"FunctionType",
".",
"builder",
"(",
"typeRegistry",
")",
".",
"withName",
"(",
"fnName",
")",
".",
"withSourceNode",
"(",
"contents",
".",
"getSourceNode",
"(",
")",
")",
".",
"withParamsNode",
"(",
"parametersNode",
")",
".",
"withReturnType",
"(",
"returnType",
",",
"returnTypeInferred",
")",
".",
"withTypeOfThis",
"(",
"thisType",
")",
".",
"withTemplateKeys",
"(",
"templateTypeNames",
")",
".",
"withIsAbstract",
"(",
"isAbstract",
")",
".",
"withClosurePrimitiveId",
"(",
"closurePrimitiveId",
")",
".",
"build",
"(",
")",
";",
"maybeSetBaseType",
"(",
"fnType",
")",
";",
"}",
"if",
"(",
"implementedInterfaces",
"!=",
"null",
"&&",
"fnType",
".",
"isConstructor",
"(",
")",
")",
"{",
"fnType",
".",
"setImplementedInterfaces",
"(",
"implementedInterfaces",
")",
";",
"}",
"if",
"(",
"extendedInterfaces",
"!=",
"null",
")",
"{",
"fnType",
".",
"setExtendedInterfaces",
"(",
"extendedInterfaces",
")",
";",
"}",
"if",
"(",
"isRecord",
")",
"{",
"fnType",
".",
"setImplicitMatch",
"(",
"true",
")",
";",
"}",
"return",
"fnType",
";",
"}"
] | Builds the function type, and puts it in the registry. | [
"Builds",
"the",
"function",
"type",
"and",
"puts",
"it",
"in",
"the",
"registry",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L893-L937 |
23,971 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.isFunctionTypeDeclaration | static boolean isFunctionTypeDeclaration(JSDocInfo info) {
return info.getParameterCount() > 0
|| info.hasReturnType()
|| info.hasThisType()
|| info.isConstructor()
|| info.isInterface()
|| info.isAbstract();
} | java | static boolean isFunctionTypeDeclaration(JSDocInfo info) {
return info.getParameterCount() > 0
|| info.hasReturnType()
|| info.hasThisType()
|| info.isConstructor()
|| info.isInterface()
|| info.isAbstract();
} | [
"static",
"boolean",
"isFunctionTypeDeclaration",
"(",
"JSDocInfo",
"info",
")",
"{",
"return",
"info",
".",
"getParameterCount",
"(",
")",
">",
"0",
"||",
"info",
".",
"hasReturnType",
"(",
")",
"||",
"info",
".",
"hasThisType",
"(",
")",
"||",
"info",
".",
"isConstructor",
"(",
")",
"||",
"info",
".",
"isInterface",
"(",
")",
"||",
"info",
".",
"isAbstract",
"(",
")",
";",
"}"
] | Determines whether the given JsDoc info declares a function type. | [
"Determines",
"whether",
"the",
"given",
"JsDoc",
"info",
"declares",
"a",
"function",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L1065-L1072 |
23,972 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.getScopeDeclaredIn | private TypedScope getScopeDeclaredIn() {
if (declarationScope != null) {
return declarationScope;
}
int dotIndex = fnName.indexOf('.');
if (dotIndex != -1) {
String rootVarName = fnName.substring(0, dotIndex);
TypedVar rootVar = enclosingScope.getVar(rootVarName);
if (rootVar != null) {
return rootVar.getScope();
}
}
return enclosingScope;
} | java | private TypedScope getScopeDeclaredIn() {
if (declarationScope != null) {
return declarationScope;
}
int dotIndex = fnName.indexOf('.');
if (dotIndex != -1) {
String rootVarName = fnName.substring(0, dotIndex);
TypedVar rootVar = enclosingScope.getVar(rootVarName);
if (rootVar != null) {
return rootVar.getScope();
}
}
return enclosingScope;
} | [
"private",
"TypedScope",
"getScopeDeclaredIn",
"(",
")",
"{",
"if",
"(",
"declarationScope",
"!=",
"null",
")",
"{",
"return",
"declarationScope",
";",
"}",
"int",
"dotIndex",
"=",
"fnName",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"dotIndex",
"!=",
"-",
"1",
")",
"{",
"String",
"rootVarName",
"=",
"fnName",
".",
"substring",
"(",
"0",
",",
"dotIndex",
")",
";",
"TypedVar",
"rootVar",
"=",
"enclosingScope",
".",
"getVar",
"(",
"rootVarName",
")",
";",
"if",
"(",
"rootVar",
"!=",
"null",
")",
"{",
"return",
"rootVar",
".",
"getScope",
"(",
")",
";",
"}",
"}",
"return",
"enclosingScope",
";",
"}"
] | The scope that we should declare this function in, if it needs
to be declared in a scope. Notice that TypedScopeCreator takes
care of most scope-declaring. | [
"The",
"scope",
"that",
"we",
"should",
"declare",
"this",
"function",
"in",
"if",
"it",
"needs",
"to",
"be",
"declared",
"in",
"a",
"scope",
".",
"Notice",
"that",
"TypedScopeCreator",
"takes",
"care",
"of",
"most",
"scope",
"-",
"declaring",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L1079-L1093 |
23,973 | google/closure-compiler | src/com/google/javascript/jscomp/FunctionTypeBuilder.java | FunctionTypeBuilder.hasMoreTagsToResolve | private static boolean hasMoreTagsToResolve(ObjectType objectType) {
checkArgument(objectType.isUnknownType());
FunctionType ctor = objectType.getConstructor();
if (ctor != null) {
// interface extends interfaces
for (ObjectType interfaceType : ctor.getExtendedInterfaces()) {
if (!interfaceType.isResolved()) {
return true;
}
}
}
if (objectType.getImplicitPrototype() != null) {
// constructor extends class
return !objectType.getImplicitPrototype().isResolved();
}
return false;
} | java | private static boolean hasMoreTagsToResolve(ObjectType objectType) {
checkArgument(objectType.isUnknownType());
FunctionType ctor = objectType.getConstructor();
if (ctor != null) {
// interface extends interfaces
for (ObjectType interfaceType : ctor.getExtendedInterfaces()) {
if (!interfaceType.isResolved()) {
return true;
}
}
}
if (objectType.getImplicitPrototype() != null) {
// constructor extends class
return !objectType.getImplicitPrototype().isResolved();
}
return false;
} | [
"private",
"static",
"boolean",
"hasMoreTagsToResolve",
"(",
"ObjectType",
"objectType",
")",
"{",
"checkArgument",
"(",
"objectType",
".",
"isUnknownType",
"(",
")",
")",
";",
"FunctionType",
"ctor",
"=",
"objectType",
".",
"getConstructor",
"(",
")",
";",
"if",
"(",
"ctor",
"!=",
"null",
")",
"{",
"// interface extends interfaces",
"for",
"(",
"ObjectType",
"interfaceType",
":",
"ctor",
".",
"getExtendedInterfaces",
"(",
")",
")",
"{",
"if",
"(",
"!",
"interfaceType",
".",
"isResolved",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"objectType",
".",
"getImplicitPrototype",
"(",
")",
"!=",
"null",
")",
"{",
"// constructor extends class",
"return",
"!",
"objectType",
".",
"getImplicitPrototype",
"(",
")",
".",
"isResolved",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Check whether a type is resolvable in the future
If this has a supertype that hasn't been resolved yet, then we can assume
this type will be OK once the super type resolves.
@param objectType
@return true if objectType is resolvable in the future | [
"Check",
"whether",
"a",
"type",
"is",
"resolvable",
"in",
"the",
"future",
"If",
"this",
"has",
"a",
"supertype",
"that",
"hasn",
"t",
"been",
"resolved",
"yet",
"then",
"we",
"can",
"assume",
"this",
"type",
"will",
"be",
"OK",
"once",
"the",
"super",
"type",
"resolves",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/FunctionTypeBuilder.java#L1102-L1118 |
23,974 | google/closure-compiler | src/com/google/javascript/jscomp/VariableReferenceCheck.java | VariableReferenceCheck.checkForUnusedLocalVar | private void checkForUnusedLocalVar(Var v, Reference unusedAssignment) {
if (!v.isLocal()) {
return;
}
JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(unusedAssignment.getNode());
if (jsDoc != null && jsDoc.hasTypedefType()) {
return;
}
boolean inGoogScope = false;
Scope s = v.getScope();
if (s.isFunctionBlockScope()) {
Node function = s.getRootNode().getParent();
Node callee = function.getPrevious();
inGoogScope = callee != null && callee.matchesQualifiedName("goog.scope");
}
if (inGoogScope) {
// No warning.
return;
}
if (s.isModuleScope()) {
Node statement = NodeUtil.getEnclosingStatement(v.getNode());
if (NodeUtil.isNameDeclaration(statement)) {
Node lhs = statement.getFirstChild();
Node rhs = lhs.getFirstChild();
if (rhs != null
&& (NodeUtil.isCallTo(rhs, "goog.forwardDeclare")
|| NodeUtil.isCallTo(rhs, "goog.requireType")
|| NodeUtil.isCallTo(rhs, "goog.require")
|| rhs.isQualifiedName())) {
// No warning. module imports will be caught by the unused-require check, and if the
// right side is a qualified name then this is likely an alias used in type annotations.
return;
}
}
}
compiler.report(JSError.make(unusedAssignment.getNode(), UNUSED_LOCAL_ASSIGNMENT, v.name));
} | java | private void checkForUnusedLocalVar(Var v, Reference unusedAssignment) {
if (!v.isLocal()) {
return;
}
JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(unusedAssignment.getNode());
if (jsDoc != null && jsDoc.hasTypedefType()) {
return;
}
boolean inGoogScope = false;
Scope s = v.getScope();
if (s.isFunctionBlockScope()) {
Node function = s.getRootNode().getParent();
Node callee = function.getPrevious();
inGoogScope = callee != null && callee.matchesQualifiedName("goog.scope");
}
if (inGoogScope) {
// No warning.
return;
}
if (s.isModuleScope()) {
Node statement = NodeUtil.getEnclosingStatement(v.getNode());
if (NodeUtil.isNameDeclaration(statement)) {
Node lhs = statement.getFirstChild();
Node rhs = lhs.getFirstChild();
if (rhs != null
&& (NodeUtil.isCallTo(rhs, "goog.forwardDeclare")
|| NodeUtil.isCallTo(rhs, "goog.requireType")
|| NodeUtil.isCallTo(rhs, "goog.require")
|| rhs.isQualifiedName())) {
// No warning. module imports will be caught by the unused-require check, and if the
// right side is a qualified name then this is likely an alias used in type annotations.
return;
}
}
}
compiler.report(JSError.make(unusedAssignment.getNode(), UNUSED_LOCAL_ASSIGNMENT, v.name));
} | [
"private",
"void",
"checkForUnusedLocalVar",
"(",
"Var",
"v",
",",
"Reference",
"unusedAssignment",
")",
"{",
"if",
"(",
"!",
"v",
".",
"isLocal",
"(",
")",
")",
"{",
"return",
";",
"}",
"JSDocInfo",
"jsDoc",
"=",
"NodeUtil",
".",
"getBestJSDocInfo",
"(",
"unusedAssignment",
".",
"getNode",
"(",
")",
")",
";",
"if",
"(",
"jsDoc",
"!=",
"null",
"&&",
"jsDoc",
".",
"hasTypedefType",
"(",
")",
")",
"{",
"return",
";",
"}",
"boolean",
"inGoogScope",
"=",
"false",
";",
"Scope",
"s",
"=",
"v",
".",
"getScope",
"(",
")",
";",
"if",
"(",
"s",
".",
"isFunctionBlockScope",
"(",
")",
")",
"{",
"Node",
"function",
"=",
"s",
".",
"getRootNode",
"(",
")",
".",
"getParent",
"(",
")",
";",
"Node",
"callee",
"=",
"function",
".",
"getPrevious",
"(",
")",
";",
"inGoogScope",
"=",
"callee",
"!=",
"null",
"&&",
"callee",
".",
"matchesQualifiedName",
"(",
"\"goog.scope\"",
")",
";",
"}",
"if",
"(",
"inGoogScope",
")",
"{",
"// No warning.",
"return",
";",
"}",
"if",
"(",
"s",
".",
"isModuleScope",
"(",
")",
")",
"{",
"Node",
"statement",
"=",
"NodeUtil",
".",
"getEnclosingStatement",
"(",
"v",
".",
"getNode",
"(",
")",
")",
";",
"if",
"(",
"NodeUtil",
".",
"isNameDeclaration",
"(",
"statement",
")",
")",
"{",
"Node",
"lhs",
"=",
"statement",
".",
"getFirstChild",
"(",
")",
";",
"Node",
"rhs",
"=",
"lhs",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"rhs",
"!=",
"null",
"&&",
"(",
"NodeUtil",
".",
"isCallTo",
"(",
"rhs",
",",
"\"goog.forwardDeclare\"",
")",
"||",
"NodeUtil",
".",
"isCallTo",
"(",
"rhs",
",",
"\"goog.requireType\"",
")",
"||",
"NodeUtil",
".",
"isCallTo",
"(",
"rhs",
",",
"\"goog.require\"",
")",
"||",
"rhs",
".",
"isQualifiedName",
"(",
")",
")",
")",
"{",
"// No warning. module imports will be caught by the unused-require check, and if the",
"// right side is a qualified name then this is likely an alias used in type annotations.",
"return",
";",
"}",
"}",
"}",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"unusedAssignment",
".",
"getNode",
"(",
")",
",",
"UNUSED_LOCAL_ASSIGNMENT",
",",
"v",
".",
"name",
")",
")",
";",
"}"
] | that we can run it after goog.scope processing, and get rid of the inGoogScope check. | [
"that",
"we",
"can",
"run",
"it",
"after",
"goog",
".",
"scope",
"processing",
"and",
"get",
"rid",
"of",
"the",
"inGoogScope",
"check",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/VariableReferenceCheck.java#L438-L478 |
23,975 | google/closure-compiler | src/com/google/javascript/jscomp/BranchCoverageInstrumentationCallback.java | BranchCoverageInstrumentationCallback.instrumentBranchCoverage | private void instrumentBranchCoverage(NodeTraversal traversal, FileInstrumentationData data) {
int maxLine = data.maxBranchPresentLine();
int branchCoverageOffset = 0;
for (int lineIdx = 1; lineIdx <= maxLine; ++lineIdx) {
Integer numBranches = data.getNumBranches(lineIdx);
if (numBranches != null) {
for (int branchIdx = 1; branchIdx <= numBranches; ++branchIdx) {
Node block = data.getBranchNode(lineIdx, branchIdx);
block.addChildToFront(
newBranchInstrumentationNode(traversal, block, branchCoverageOffset + branchIdx - 1));
compiler.reportChangeToEnclosingScope(block);
}
branchCoverageOffset += numBranches;
}
}
} | java | private void instrumentBranchCoverage(NodeTraversal traversal, FileInstrumentationData data) {
int maxLine = data.maxBranchPresentLine();
int branchCoverageOffset = 0;
for (int lineIdx = 1; lineIdx <= maxLine; ++lineIdx) {
Integer numBranches = data.getNumBranches(lineIdx);
if (numBranches != null) {
for (int branchIdx = 1; branchIdx <= numBranches; ++branchIdx) {
Node block = data.getBranchNode(lineIdx, branchIdx);
block.addChildToFront(
newBranchInstrumentationNode(traversal, block, branchCoverageOffset + branchIdx - 1));
compiler.reportChangeToEnclosingScope(block);
}
branchCoverageOffset += numBranches;
}
}
} | [
"private",
"void",
"instrumentBranchCoverage",
"(",
"NodeTraversal",
"traversal",
",",
"FileInstrumentationData",
"data",
")",
"{",
"int",
"maxLine",
"=",
"data",
".",
"maxBranchPresentLine",
"(",
")",
";",
"int",
"branchCoverageOffset",
"=",
"0",
";",
"for",
"(",
"int",
"lineIdx",
"=",
"1",
";",
"lineIdx",
"<=",
"maxLine",
";",
"++",
"lineIdx",
")",
"{",
"Integer",
"numBranches",
"=",
"data",
".",
"getNumBranches",
"(",
"lineIdx",
")",
";",
"if",
"(",
"numBranches",
"!=",
"null",
")",
"{",
"for",
"(",
"int",
"branchIdx",
"=",
"1",
";",
"branchIdx",
"<=",
"numBranches",
";",
"++",
"branchIdx",
")",
"{",
"Node",
"block",
"=",
"data",
".",
"getBranchNode",
"(",
"lineIdx",
",",
"branchIdx",
")",
";",
"block",
".",
"addChildToFront",
"(",
"newBranchInstrumentationNode",
"(",
"traversal",
",",
"block",
",",
"branchCoverageOffset",
"+",
"branchIdx",
"-",
"1",
")",
")",
";",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"block",
")",
";",
"}",
"branchCoverageOffset",
"+=",
"numBranches",
";",
"}",
"}",
"}"
] | Add instrumentation code for branch coverage. For each block that correspond to a branch,
insert an assignment of the branch coverage data to the front of the block. | [
"Add",
"instrumentation",
"code",
"for",
"branch",
"coverage",
".",
"For",
"each",
"block",
"that",
"correspond",
"to",
"a",
"branch",
"insert",
"an",
"assignment",
"of",
"the",
"branch",
"coverage",
"data",
"to",
"the",
"front",
"of",
"the",
"block",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/BranchCoverageInstrumentationCallback.java#L123-L138 |
23,976 | google/closure-compiler | src/com/google/javascript/jscomp/BranchCoverageInstrumentationCallback.java | BranchCoverageInstrumentationCallback.newBranchInstrumentationNode | private Node newBranchInstrumentationNode(NodeTraversal traversal, Node node, int idx) {
String arrayName = createArrayName(traversal);
// Create instrumentation Node
Node getElemNode = IR.getelem(IR.name(arrayName), IR.number(idx)); // Make line number 0-based
Node exprNode = IR.exprResult(IR.assign(getElemNode, IR.trueNode()));
// Note line as instrumented
String fileName = traversal.getSourceName();
if (!instrumentationData.containsKey(fileName)) {
instrumentationData.put(fileName, new FileInstrumentationData(fileName, arrayName));
}
return exprNode.useSourceInfoIfMissingFromForTree(node);
} | java | private Node newBranchInstrumentationNode(NodeTraversal traversal, Node node, int idx) {
String arrayName = createArrayName(traversal);
// Create instrumentation Node
Node getElemNode = IR.getelem(IR.name(arrayName), IR.number(idx)); // Make line number 0-based
Node exprNode = IR.exprResult(IR.assign(getElemNode, IR.trueNode()));
// Note line as instrumented
String fileName = traversal.getSourceName();
if (!instrumentationData.containsKey(fileName)) {
instrumentationData.put(fileName, new FileInstrumentationData(fileName, arrayName));
}
return exprNode.useSourceInfoIfMissingFromForTree(node);
} | [
"private",
"Node",
"newBranchInstrumentationNode",
"(",
"NodeTraversal",
"traversal",
",",
"Node",
"node",
",",
"int",
"idx",
")",
"{",
"String",
"arrayName",
"=",
"createArrayName",
"(",
"traversal",
")",
";",
"// Create instrumentation Node",
"Node",
"getElemNode",
"=",
"IR",
".",
"getelem",
"(",
"IR",
".",
"name",
"(",
"arrayName",
")",
",",
"IR",
".",
"number",
"(",
"idx",
")",
")",
";",
"// Make line number 0-based",
"Node",
"exprNode",
"=",
"IR",
".",
"exprResult",
"(",
"IR",
".",
"assign",
"(",
"getElemNode",
",",
"IR",
".",
"trueNode",
"(",
")",
")",
")",
";",
"// Note line as instrumented",
"String",
"fileName",
"=",
"traversal",
".",
"getSourceName",
"(",
")",
";",
"if",
"(",
"!",
"instrumentationData",
".",
"containsKey",
"(",
"fileName",
")",
")",
"{",
"instrumentationData",
".",
"put",
"(",
"fileName",
",",
"new",
"FileInstrumentationData",
"(",
"fileName",
",",
"arrayName",
")",
")",
";",
"}",
"return",
"exprNode",
".",
"useSourceInfoIfMissingFromForTree",
"(",
"node",
")",
";",
"}"
] | Create an assignment to the branch coverage data for the given index into the array.
@return the newly constructed assignment node. | [
"Create",
"an",
"assignment",
"to",
"the",
"branch",
"coverage",
"data",
"for",
"the",
"given",
"index",
"into",
"the",
"array",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/BranchCoverageInstrumentationCallback.java#L145-L158 |
23,977 | google/closure-compiler | src/com/google/javascript/jscomp/BranchCoverageInstrumentationCallback.java | BranchCoverageInstrumentationCallback.processBranchInfo | private void processBranchInfo(Node branchNode, FileInstrumentationData data, List<Node> blocks) {
int lineNumber = branchNode.getLineno();
data.setBranchPresent(lineNumber);
// Instrument for each block
int numBranches = 0;
for (Node child : blocks) {
data.putBranchNode(lineNumber, numBranches + 1, child);
numBranches++;
}
data.addBranches(lineNumber, numBranches);
} | java | private void processBranchInfo(Node branchNode, FileInstrumentationData data, List<Node> blocks) {
int lineNumber = branchNode.getLineno();
data.setBranchPresent(lineNumber);
// Instrument for each block
int numBranches = 0;
for (Node child : blocks) {
data.putBranchNode(lineNumber, numBranches + 1, child);
numBranches++;
}
data.addBranches(lineNumber, numBranches);
} | [
"private",
"void",
"processBranchInfo",
"(",
"Node",
"branchNode",
",",
"FileInstrumentationData",
"data",
",",
"List",
"<",
"Node",
">",
"blocks",
")",
"{",
"int",
"lineNumber",
"=",
"branchNode",
".",
"getLineno",
"(",
")",
";",
"data",
".",
"setBranchPresent",
"(",
"lineNumber",
")",
";",
"// Instrument for each block",
"int",
"numBranches",
"=",
"0",
";",
"for",
"(",
"Node",
"child",
":",
"blocks",
")",
"{",
"data",
".",
"putBranchNode",
"(",
"lineNumber",
",",
"numBranches",
"+",
"1",
",",
"child",
")",
";",
"numBranches",
"++",
";",
"}",
"data",
".",
"addBranches",
"(",
"lineNumber",
",",
"numBranches",
")",
";",
"}"
] | Add branch instrumentation information for each block. | [
"Add",
"branch",
"instrumentation",
"information",
"for",
"each",
"block",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/BranchCoverageInstrumentationCallback.java#L161-L172 |
23,978 | google/closure-compiler | src/com/google/javascript/jscomp/modules/ClosureRequireProcessor.java | ClosureRequireProcessor.getAllRequires | static ImmutableList<Require> getAllRequires(Node nameDeclaration) {
Node rhs =
nameDeclaration.getFirstChild().isDestructuringLhs()
? nameDeclaration.getFirstChild().getSecondChild()
: nameDeclaration.getFirstFirstChild();
// This may be a require, requireType, or forwardDeclare.
Binding.CreatedBy requireKind = getModuleDependencyTypeFromRhs(rhs);
if (requireKind == null) {
return ImmutableList.of();
}
return new ClosureRequireProcessor(nameDeclaration, requireKind).getAllRequiresInDeclaration();
} | java | static ImmutableList<Require> getAllRequires(Node nameDeclaration) {
Node rhs =
nameDeclaration.getFirstChild().isDestructuringLhs()
? nameDeclaration.getFirstChild().getSecondChild()
: nameDeclaration.getFirstFirstChild();
// This may be a require, requireType, or forwardDeclare.
Binding.CreatedBy requireKind = getModuleDependencyTypeFromRhs(rhs);
if (requireKind == null) {
return ImmutableList.of();
}
return new ClosureRequireProcessor(nameDeclaration, requireKind).getAllRequiresInDeclaration();
} | [
"static",
"ImmutableList",
"<",
"Require",
">",
"getAllRequires",
"(",
"Node",
"nameDeclaration",
")",
"{",
"Node",
"rhs",
"=",
"nameDeclaration",
".",
"getFirstChild",
"(",
")",
".",
"isDestructuringLhs",
"(",
")",
"?",
"nameDeclaration",
".",
"getFirstChild",
"(",
")",
".",
"getSecondChild",
"(",
")",
":",
"nameDeclaration",
".",
"getFirstFirstChild",
"(",
")",
";",
"// This may be a require, requireType, or forwardDeclare.",
"Binding",
".",
"CreatedBy",
"requireKind",
"=",
"getModuleDependencyTypeFromRhs",
"(",
"rhs",
")",
";",
"if",
"(",
"requireKind",
"==",
"null",
")",
"{",
"return",
"ImmutableList",
".",
"of",
"(",
")",
";",
"}",
"return",
"new",
"ClosureRequireProcessor",
"(",
"nameDeclaration",
",",
"requireKind",
")",
".",
"getAllRequiresInDeclaration",
"(",
")",
";",
"}"
] | Returns all Require built from the given statement, or null if it is not a require
@param nameDeclaration a VAR, LET, or CONST
@return all Requires contained in this declaration | [
"Returns",
"all",
"Require",
"built",
"from",
"the",
"given",
"statement",
"or",
"null",
"if",
"it",
"is",
"not",
"a",
"require"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/modules/ClosureRequireProcessor.java#L66-L78 |
23,979 | google/closure-compiler | src/com/google/javascript/jscomp/DiagnosticGroups.java | DiagnosticGroups.setWarningLevel | public void setWarningLevel(CompilerOptions options, String name, CheckLevel level) {
DiagnosticGroup group = forName(name);
Preconditions.checkNotNull(group, "No warning class for name: %s", name);
options.setWarningLevel(group, level);
} | java | public void setWarningLevel(CompilerOptions options, String name, CheckLevel level) {
DiagnosticGroup group = forName(name);
Preconditions.checkNotNull(group, "No warning class for name: %s", name);
options.setWarningLevel(group, level);
} | [
"public",
"void",
"setWarningLevel",
"(",
"CompilerOptions",
"options",
",",
"String",
"name",
",",
"CheckLevel",
"level",
")",
"{",
"DiagnosticGroup",
"group",
"=",
"forName",
"(",
"name",
")",
";",
"Preconditions",
".",
"checkNotNull",
"(",
"group",
",",
"\"No warning class for name: %s\"",
",",
"name",
")",
";",
"options",
".",
"setWarningLevel",
"(",
"group",
",",
"level",
")",
";",
"}"
] | Adds warning levels by name. | [
"Adds",
"warning",
"levels",
"by",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DiagnosticGroups.java#L737-L741 |
23,980 | google/closure-compiler | src/com/google/javascript/jscomp/CrossChunkReferenceCollector.java | CrossChunkReferenceCollector.process | @Override
public void process(Node externs, Node root) {
checkState(topLevelStatements.isEmpty(), "process() called more than once");
NodeTraversal t = new NodeTraversal(compiler, this, scopeCreator);
t.traverseRoots(externs, root);
} | java | @Override
public void process(Node externs, Node root) {
checkState(topLevelStatements.isEmpty(), "process() called more than once");
NodeTraversal t = new NodeTraversal(compiler, this, scopeCreator);
t.traverseRoots(externs, root);
} | [
"@",
"Override",
"public",
"void",
"process",
"(",
"Node",
"externs",
",",
"Node",
"root",
")",
"{",
"checkState",
"(",
"topLevelStatements",
".",
"isEmpty",
"(",
")",
",",
"\"process() called more than once\"",
")",
";",
"NodeTraversal",
"t",
"=",
"new",
"NodeTraversal",
"(",
"compiler",
",",
"this",
",",
"scopeCreator",
")",
";",
"t",
".",
"traverseRoots",
"(",
"externs",
",",
"root",
")",
";",
"}"
] | Convenience method for running this pass over a tree with this
class as a callback. | [
"Convenience",
"method",
"for",
"running",
"this",
"pass",
"over",
"a",
"tree",
"with",
"this",
"class",
"as",
"a",
"callback",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CrossChunkReferenceCollector.java#L75-L80 |
23,981 | google/closure-compiler | src/com/google/javascript/rhino/TokenUtil.java | TokenUtil.isStrWhiteSpaceChar | public static TernaryValue isStrWhiteSpaceChar(int c) {
switch (c) {
case '\u000B': // <VT>
return TernaryValue.UNKNOWN; // IE says "no", ECMAScript says "yes"
case ' ': // <SP>
case '\n': // <LF>
case '\r': // <CR>
case '\t': // <TAB>
case '\u00A0': // <NBSP>
case '\u000C': // <FF>
case '\u2028': // <LS>
case '\u2029': // <PS>
case '\uFEFF': // <BOM>
return TernaryValue.TRUE;
default:
return (Character.getType(c) == Character.SPACE_SEPARATOR)
? TernaryValue.TRUE : TernaryValue.FALSE;
}
} | java | public static TernaryValue isStrWhiteSpaceChar(int c) {
switch (c) {
case '\u000B': // <VT>
return TernaryValue.UNKNOWN; // IE says "no", ECMAScript says "yes"
case ' ': // <SP>
case '\n': // <LF>
case '\r': // <CR>
case '\t': // <TAB>
case '\u00A0': // <NBSP>
case '\u000C': // <FF>
case '\u2028': // <LS>
case '\u2029': // <PS>
case '\uFEFF': // <BOM>
return TernaryValue.TRUE;
default:
return (Character.getType(c) == Character.SPACE_SEPARATOR)
? TernaryValue.TRUE : TernaryValue.FALSE;
}
} | [
"public",
"static",
"TernaryValue",
"isStrWhiteSpaceChar",
"(",
"int",
"c",
")",
"{",
"switch",
"(",
"c",
")",
"{",
"case",
"'",
"'",
":",
"// <VT>",
"return",
"TernaryValue",
".",
"UNKNOWN",
";",
"// IE says \"no\", ECMAScript says \"yes\"",
"case",
"'",
"'",
":",
"// <SP>",
"case",
"'",
"'",
":",
"// <LF>",
"case",
"'",
"'",
":",
"// <CR>",
"case",
"'",
"'",
":",
"// <TAB>",
"case",
"'",
"'",
":",
"// <NBSP>",
"case",
"'",
"'",
":",
"// <FF>",
"case",
"'",
"'",
":",
"// <LS>",
"case",
"'",
"'",
":",
"// <PS>",
"case",
"'",
"'",
":",
"// <BOM>",
"return",
"TernaryValue",
".",
"TRUE",
";",
"default",
":",
"return",
"(",
"Character",
".",
"getType",
"(",
"c",
")",
"==",
"Character",
".",
"SPACE_SEPARATOR",
")",
"?",
"TernaryValue",
".",
"TRUE",
":",
"TernaryValue",
".",
"FALSE",
";",
"}",
"}"
] | Copied from Rhino's ScriptRuntime | [
"Copied",
"from",
"Rhino",
"s",
"ScriptRuntime"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/TokenUtil.java#L83-L101 |
23,982 | google/closure-compiler | src/com/google/javascript/jscomp/DeadAssignmentsElimination.java | DeadAssignmentsElimination.isRemovableAssign | boolean isRemovableAssign(Node n) {
return (NodeUtil.isAssignmentOp(n) && n.getFirstChild().isName()) || n.isInc() || n.isDec();
} | java | boolean isRemovableAssign(Node n) {
return (NodeUtil.isAssignmentOp(n) && n.getFirstChild().isName()) || n.isInc() || n.isDec();
} | [
"boolean",
"isRemovableAssign",
"(",
"Node",
"n",
")",
"{",
"return",
"(",
"NodeUtil",
".",
"isAssignmentOp",
"(",
"n",
")",
"&&",
"n",
".",
"getFirstChild",
"(",
")",
".",
"isName",
"(",
")",
")",
"||",
"n",
".",
"isInc",
"(",
")",
"||",
"n",
".",
"isDec",
"(",
")",
";",
"}"
] | will already remove variables that are initialized but unused. | [
"will",
"already",
"remove",
"variables",
"that",
"are",
"initialized",
"but",
"unused",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DeadAssignmentsElimination.java#L137-L139 |
23,983 | google/closure-compiler | src/com/google/javascript/jscomp/DeadAssignmentsElimination.java | DeadAssignmentsElimination.tryRemoveDeadAssignments | private void tryRemoveDeadAssignments(NodeTraversal t,
ControlFlowGraph<Node> cfg,
Map<String, Var> allVarsInFn) {
Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes();
for (DiGraphNode<Node, Branch> cfgNode : nodes) {
FlowState<LiveVariableLattice> state =
cfgNode.getAnnotation();
Node n = cfgNode.getValue();
if (n == null) {
continue;
}
switch (n.getToken()) {
case IF:
case WHILE:
case DO:
tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state, allVarsInFn);
continue;
case FOR:
case FOR_IN:
case FOR_OF:
case FOR_AWAIT_OF:
if (n.isVanillaFor()) {
tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state, allVarsInFn);
}
continue;
case SWITCH:
case CASE:
case RETURN:
if (n.hasChildren()) {
tryRemoveAssignment(t, n.getFirstChild(), state, allVarsInFn);
}
continue;
// TODO(user): case VAR: Remove var a=1;a=2;.....
default:
break;
}
tryRemoveAssignment(t, n, state, allVarsInFn);
}
} | java | private void tryRemoveDeadAssignments(NodeTraversal t,
ControlFlowGraph<Node> cfg,
Map<String, Var> allVarsInFn) {
Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes();
for (DiGraphNode<Node, Branch> cfgNode : nodes) {
FlowState<LiveVariableLattice> state =
cfgNode.getAnnotation();
Node n = cfgNode.getValue();
if (n == null) {
continue;
}
switch (n.getToken()) {
case IF:
case WHILE:
case DO:
tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state, allVarsInFn);
continue;
case FOR:
case FOR_IN:
case FOR_OF:
case FOR_AWAIT_OF:
if (n.isVanillaFor()) {
tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state, allVarsInFn);
}
continue;
case SWITCH:
case CASE:
case RETURN:
if (n.hasChildren()) {
tryRemoveAssignment(t, n.getFirstChild(), state, allVarsInFn);
}
continue;
// TODO(user): case VAR: Remove var a=1;a=2;.....
default:
break;
}
tryRemoveAssignment(t, n, state, allVarsInFn);
}
} | [
"private",
"void",
"tryRemoveDeadAssignments",
"(",
"NodeTraversal",
"t",
",",
"ControlFlowGraph",
"<",
"Node",
">",
"cfg",
",",
"Map",
"<",
"String",
",",
"Var",
">",
"allVarsInFn",
")",
"{",
"Iterable",
"<",
"DiGraphNode",
"<",
"Node",
",",
"Branch",
">",
">",
"nodes",
"=",
"cfg",
".",
"getDirectedGraphNodes",
"(",
")",
";",
"for",
"(",
"DiGraphNode",
"<",
"Node",
",",
"Branch",
">",
"cfgNode",
":",
"nodes",
")",
"{",
"FlowState",
"<",
"LiveVariableLattice",
">",
"state",
"=",
"cfgNode",
".",
"getAnnotation",
"(",
")",
";",
"Node",
"n",
"=",
"cfgNode",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"n",
"==",
"null",
")",
"{",
"continue",
";",
"}",
"switch",
"(",
"n",
".",
"getToken",
"(",
")",
")",
"{",
"case",
"IF",
":",
"case",
"WHILE",
":",
"case",
"DO",
":",
"tryRemoveAssignment",
"(",
"t",
",",
"NodeUtil",
".",
"getConditionExpression",
"(",
"n",
")",
",",
"state",
",",
"allVarsInFn",
")",
";",
"continue",
";",
"case",
"FOR",
":",
"case",
"FOR_IN",
":",
"case",
"FOR_OF",
":",
"case",
"FOR_AWAIT_OF",
":",
"if",
"(",
"n",
".",
"isVanillaFor",
"(",
")",
")",
"{",
"tryRemoveAssignment",
"(",
"t",
",",
"NodeUtil",
".",
"getConditionExpression",
"(",
"n",
")",
",",
"state",
",",
"allVarsInFn",
")",
";",
"}",
"continue",
";",
"case",
"SWITCH",
":",
"case",
"CASE",
":",
"case",
"RETURN",
":",
"if",
"(",
"n",
".",
"hasChildren",
"(",
")",
")",
"{",
"tryRemoveAssignment",
"(",
"t",
",",
"n",
".",
"getFirstChild",
"(",
")",
",",
"state",
",",
"allVarsInFn",
")",
";",
"}",
"continue",
";",
"// TODO(user): case VAR: Remove var a=1;a=2;.....",
"default",
":",
"break",
";",
"}",
"tryRemoveAssignment",
"(",
"t",
",",
"n",
",",
"state",
",",
"allVarsInFn",
")",
";",
"}",
"}"
] | Try to remove useless assignments from a control flow graph that has been
annotated with liveness information.
@param t The node traversal.
@param cfg The control flow graph of the program annotated with liveness
information. | [
"Try",
"to",
"remove",
"useless",
"assignments",
"from",
"a",
"control",
"flow",
"graph",
"that",
"has",
"been",
"annotated",
"with",
"liveness",
"information",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DeadAssignmentsElimination.java#L149-L189 |
23,984 | google/closure-compiler | src/com/google/javascript/jscomp/DeadAssignmentsElimination.java | DeadAssignmentsElimination.isVariableStillLiveWithinExpression | private boolean isVariableStillLiveWithinExpression(
Node n, Node exprRoot, String variable) {
while (n != exprRoot) {
VariableLiveness state = VariableLiveness.MAYBE_LIVE;
switch (n.getParent().getToken()) {
case OR:
case AND:
// If the currently node is the first child of
// AND/OR, be conservative only consider the READs
// of the second operand.
if (n.getNext() != null) {
state = isVariableReadBeforeKill(
n.getNext(), variable);
if (state == VariableLiveness.KILL) {
state = VariableLiveness.MAYBE_LIVE;
}
}
break;
case HOOK:
// If current node is the condition, check each following
// branch, otherwise it is a conditional branch and the
// other branch can be ignored.
if (n.getNext() != null && n.getNext().getNext() != null) {
state = checkHookBranchReadBeforeKill(
n.getNext(), n.getNext().getNext(), variable);
}
break;
default:
for (Node sibling = n.getNext(); sibling != null;
sibling = sibling.getNext()) {
state = isVariableReadBeforeKill(sibling, variable);
if (state != VariableLiveness.MAYBE_LIVE) {
break;
}
}
}
// If we see a READ or KILL there is no need to continue.
if (state == VariableLiveness.READ) {
return true;
} else if (state == VariableLiveness.KILL) {
return false;
}
n = n.getParent();
}
return false;
} | java | private boolean isVariableStillLiveWithinExpression(
Node n, Node exprRoot, String variable) {
while (n != exprRoot) {
VariableLiveness state = VariableLiveness.MAYBE_LIVE;
switch (n.getParent().getToken()) {
case OR:
case AND:
// If the currently node is the first child of
// AND/OR, be conservative only consider the READs
// of the second operand.
if (n.getNext() != null) {
state = isVariableReadBeforeKill(
n.getNext(), variable);
if (state == VariableLiveness.KILL) {
state = VariableLiveness.MAYBE_LIVE;
}
}
break;
case HOOK:
// If current node is the condition, check each following
// branch, otherwise it is a conditional branch and the
// other branch can be ignored.
if (n.getNext() != null && n.getNext().getNext() != null) {
state = checkHookBranchReadBeforeKill(
n.getNext(), n.getNext().getNext(), variable);
}
break;
default:
for (Node sibling = n.getNext(); sibling != null;
sibling = sibling.getNext()) {
state = isVariableReadBeforeKill(sibling, variable);
if (state != VariableLiveness.MAYBE_LIVE) {
break;
}
}
}
// If we see a READ or KILL there is no need to continue.
if (state == VariableLiveness.READ) {
return true;
} else if (state == VariableLiveness.KILL) {
return false;
}
n = n.getParent();
}
return false;
} | [
"private",
"boolean",
"isVariableStillLiveWithinExpression",
"(",
"Node",
"n",
",",
"Node",
"exprRoot",
",",
"String",
"variable",
")",
"{",
"while",
"(",
"n",
"!=",
"exprRoot",
")",
"{",
"VariableLiveness",
"state",
"=",
"VariableLiveness",
".",
"MAYBE_LIVE",
";",
"switch",
"(",
"n",
".",
"getParent",
"(",
")",
".",
"getToken",
"(",
")",
")",
"{",
"case",
"OR",
":",
"case",
"AND",
":",
"// If the currently node is the first child of",
"// AND/OR, be conservative only consider the READs",
"// of the second operand.",
"if",
"(",
"n",
".",
"getNext",
"(",
")",
"!=",
"null",
")",
"{",
"state",
"=",
"isVariableReadBeforeKill",
"(",
"n",
".",
"getNext",
"(",
")",
",",
"variable",
")",
";",
"if",
"(",
"state",
"==",
"VariableLiveness",
".",
"KILL",
")",
"{",
"state",
"=",
"VariableLiveness",
".",
"MAYBE_LIVE",
";",
"}",
"}",
"break",
";",
"case",
"HOOK",
":",
"// If current node is the condition, check each following",
"// branch, otherwise it is a conditional branch and the",
"// other branch can be ignored.",
"if",
"(",
"n",
".",
"getNext",
"(",
")",
"!=",
"null",
"&&",
"n",
".",
"getNext",
"(",
")",
".",
"getNext",
"(",
")",
"!=",
"null",
")",
"{",
"state",
"=",
"checkHookBranchReadBeforeKill",
"(",
"n",
".",
"getNext",
"(",
")",
",",
"n",
".",
"getNext",
"(",
")",
".",
"getNext",
"(",
")",
",",
"variable",
")",
";",
"}",
"break",
";",
"default",
":",
"for",
"(",
"Node",
"sibling",
"=",
"n",
".",
"getNext",
"(",
")",
";",
"sibling",
"!=",
"null",
";",
"sibling",
"=",
"sibling",
".",
"getNext",
"(",
")",
")",
"{",
"state",
"=",
"isVariableReadBeforeKill",
"(",
"sibling",
",",
"variable",
")",
";",
"if",
"(",
"state",
"!=",
"VariableLiveness",
".",
"MAYBE_LIVE",
")",
"{",
"break",
";",
"}",
"}",
"}",
"// If we see a READ or KILL there is no need to continue.",
"if",
"(",
"state",
"==",
"VariableLiveness",
".",
"READ",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"state",
"==",
"VariableLiveness",
".",
"KILL",
")",
"{",
"return",
"false",
";",
"}",
"n",
"=",
"n",
".",
"getParent",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Given a variable, node n in the tree and a sub-tree denoted by exprRoot as
the root, this function returns true if there exists a read of that
variable before a write to that variable that is on the right side of n.
For example, suppose the node is x = 1:
y = 1, x = 1; // false, there is no reads at all.
y = 1, x = 1, print(x) // true, there is a read right of n.
y = 1, x = 1, x = 2, print(x) // false, there is a read right of n but
// it is after a write.
@param n The current node we should look at.
@param exprRoot The node | [
"Given",
"a",
"variable",
"node",
"n",
"in",
"the",
"tree",
"and",
"a",
"sub",
"-",
"tree",
"denoted",
"by",
"exprRoot",
"as",
"the",
"root",
"this",
"function",
"returns",
"true",
"if",
"there",
"exists",
"a",
"read",
"of",
"that",
"variable",
"before",
"a",
"write",
"to",
"that",
"variable",
"that",
"is",
"on",
"the",
"right",
"side",
"of",
"n",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DeadAssignmentsElimination.java#L349-L397 |
23,985 | google/closure-compiler | src/com/google/javascript/jscomp/DeadAssignmentsElimination.java | DeadAssignmentsElimination.isVariableReadBeforeKill | private VariableLiveness isVariableReadBeforeKill(
Node n, String variable) {
if (ControlFlowGraph.isEnteringNewCfgNode(n)) { // Not a FUNCTION
return VariableLiveness.MAYBE_LIVE;
}
if (n.isName() && variable.equals(n.getString())) {
if (NodeUtil.isNameDeclOrSimpleAssignLhs(n, n.getParent())) {
checkState(n.getParent().isAssign(), n.getParent());
// The expression to which the assignment is made is evaluated before
// the RHS is evaluated (normal left to right evaluation) but the KILL
// occurs after the RHS is evaluated.
Node rhs = n.getNext();
VariableLiveness state = isVariableReadBeforeKill(rhs, variable);
if (state == VariableLiveness.READ) {
return state;
}
return VariableLiveness.KILL;
} else {
return VariableLiveness.READ;
}
}
switch (n.getToken()) {
// Conditionals
case OR:
case AND:
VariableLiveness v1 = isVariableReadBeforeKill(
n.getFirstChild(), variable);
VariableLiveness v2 = isVariableReadBeforeKill(
n.getLastChild(), variable);
// With a AND/OR the first branch always runs, but the second is
// may not.
if (v1 != VariableLiveness.MAYBE_LIVE) {
return v1;
} else if (v2 == VariableLiveness.READ) {
return VariableLiveness.READ;
} else {
return VariableLiveness.MAYBE_LIVE;
}
case HOOK:
VariableLiveness first = isVariableReadBeforeKill(
n.getFirstChild(), variable);
if (first != VariableLiveness.MAYBE_LIVE) {
return first;
}
return checkHookBranchReadBeforeKill(
n.getSecondChild(), n.getLastChild(), variable);
default:
// Expressions are evaluated left-right, depth first.
for (Node child = n.getFirstChild();
child != null; child = child.getNext()) {
VariableLiveness state = isVariableReadBeforeKill(child, variable);
if (state != VariableLiveness.MAYBE_LIVE) {
return state;
}
}
}
return VariableLiveness.MAYBE_LIVE;
} | java | private VariableLiveness isVariableReadBeforeKill(
Node n, String variable) {
if (ControlFlowGraph.isEnteringNewCfgNode(n)) { // Not a FUNCTION
return VariableLiveness.MAYBE_LIVE;
}
if (n.isName() && variable.equals(n.getString())) {
if (NodeUtil.isNameDeclOrSimpleAssignLhs(n, n.getParent())) {
checkState(n.getParent().isAssign(), n.getParent());
// The expression to which the assignment is made is evaluated before
// the RHS is evaluated (normal left to right evaluation) but the KILL
// occurs after the RHS is evaluated.
Node rhs = n.getNext();
VariableLiveness state = isVariableReadBeforeKill(rhs, variable);
if (state == VariableLiveness.READ) {
return state;
}
return VariableLiveness.KILL;
} else {
return VariableLiveness.READ;
}
}
switch (n.getToken()) {
// Conditionals
case OR:
case AND:
VariableLiveness v1 = isVariableReadBeforeKill(
n.getFirstChild(), variable);
VariableLiveness v2 = isVariableReadBeforeKill(
n.getLastChild(), variable);
// With a AND/OR the first branch always runs, but the second is
// may not.
if (v1 != VariableLiveness.MAYBE_LIVE) {
return v1;
} else if (v2 == VariableLiveness.READ) {
return VariableLiveness.READ;
} else {
return VariableLiveness.MAYBE_LIVE;
}
case HOOK:
VariableLiveness first = isVariableReadBeforeKill(
n.getFirstChild(), variable);
if (first != VariableLiveness.MAYBE_LIVE) {
return first;
}
return checkHookBranchReadBeforeKill(
n.getSecondChild(), n.getLastChild(), variable);
default:
// Expressions are evaluated left-right, depth first.
for (Node child = n.getFirstChild();
child != null; child = child.getNext()) {
VariableLiveness state = isVariableReadBeforeKill(child, variable);
if (state != VariableLiveness.MAYBE_LIVE) {
return state;
}
}
}
return VariableLiveness.MAYBE_LIVE;
} | [
"private",
"VariableLiveness",
"isVariableReadBeforeKill",
"(",
"Node",
"n",
",",
"String",
"variable",
")",
"{",
"if",
"(",
"ControlFlowGraph",
".",
"isEnteringNewCfgNode",
"(",
"n",
")",
")",
"{",
"// Not a FUNCTION",
"return",
"VariableLiveness",
".",
"MAYBE_LIVE",
";",
"}",
"if",
"(",
"n",
".",
"isName",
"(",
")",
"&&",
"variable",
".",
"equals",
"(",
"n",
".",
"getString",
"(",
")",
")",
")",
"{",
"if",
"(",
"NodeUtil",
".",
"isNameDeclOrSimpleAssignLhs",
"(",
"n",
",",
"n",
".",
"getParent",
"(",
")",
")",
")",
"{",
"checkState",
"(",
"n",
".",
"getParent",
"(",
")",
".",
"isAssign",
"(",
")",
",",
"n",
".",
"getParent",
"(",
")",
")",
";",
"// The expression to which the assignment is made is evaluated before",
"// the RHS is evaluated (normal left to right evaluation) but the KILL",
"// occurs after the RHS is evaluated.",
"Node",
"rhs",
"=",
"n",
".",
"getNext",
"(",
")",
";",
"VariableLiveness",
"state",
"=",
"isVariableReadBeforeKill",
"(",
"rhs",
",",
"variable",
")",
";",
"if",
"(",
"state",
"==",
"VariableLiveness",
".",
"READ",
")",
"{",
"return",
"state",
";",
"}",
"return",
"VariableLiveness",
".",
"KILL",
";",
"}",
"else",
"{",
"return",
"VariableLiveness",
".",
"READ",
";",
"}",
"}",
"switch",
"(",
"n",
".",
"getToken",
"(",
")",
")",
"{",
"// Conditionals",
"case",
"OR",
":",
"case",
"AND",
":",
"VariableLiveness",
"v1",
"=",
"isVariableReadBeforeKill",
"(",
"n",
".",
"getFirstChild",
"(",
")",
",",
"variable",
")",
";",
"VariableLiveness",
"v2",
"=",
"isVariableReadBeforeKill",
"(",
"n",
".",
"getLastChild",
"(",
")",
",",
"variable",
")",
";",
"// With a AND/OR the first branch always runs, but the second is",
"// may not.",
"if",
"(",
"v1",
"!=",
"VariableLiveness",
".",
"MAYBE_LIVE",
")",
"{",
"return",
"v1",
";",
"}",
"else",
"if",
"(",
"v2",
"==",
"VariableLiveness",
".",
"READ",
")",
"{",
"return",
"VariableLiveness",
".",
"READ",
";",
"}",
"else",
"{",
"return",
"VariableLiveness",
".",
"MAYBE_LIVE",
";",
"}",
"case",
"HOOK",
":",
"VariableLiveness",
"first",
"=",
"isVariableReadBeforeKill",
"(",
"n",
".",
"getFirstChild",
"(",
")",
",",
"variable",
")",
";",
"if",
"(",
"first",
"!=",
"VariableLiveness",
".",
"MAYBE_LIVE",
")",
"{",
"return",
"first",
";",
"}",
"return",
"checkHookBranchReadBeforeKill",
"(",
"n",
".",
"getSecondChild",
"(",
")",
",",
"n",
".",
"getLastChild",
"(",
")",
",",
"variable",
")",
";",
"default",
":",
"// Expressions are evaluated left-right, depth first.",
"for",
"(",
"Node",
"child",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"child",
"!=",
"null",
";",
"child",
"=",
"child",
".",
"getNext",
"(",
")",
")",
"{",
"VariableLiveness",
"state",
"=",
"isVariableReadBeforeKill",
"(",
"child",
",",
"variable",
")",
";",
"if",
"(",
"state",
"!=",
"VariableLiveness",
".",
"MAYBE_LIVE",
")",
"{",
"return",
"state",
";",
"}",
"}",
"}",
"return",
"VariableLiveness",
".",
"MAYBE_LIVE",
";",
"}"
] | Give an expression and a variable. It returns READ, if the first
reference of that variable is a read. It returns KILL, if the first
reference of that variable is an assignment. It returns MAY_LIVE otherwise. | [
"Give",
"an",
"expression",
"and",
"a",
"variable",
".",
"It",
"returns",
"READ",
"if",
"the",
"first",
"reference",
"of",
"that",
"variable",
"is",
"a",
"read",
".",
"It",
"returns",
"KILL",
"if",
"the",
"first",
"reference",
"of",
"that",
"variable",
"is",
"an",
"assignment",
".",
"It",
"returns",
"MAY_LIVE",
"otherwise",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DeadAssignmentsElimination.java#L411-L472 |
23,986 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.getNormalizedReferenceName | @Nullable
public final String getNormalizedReferenceName() {
String name = getReferenceName();
if (name != null) {
int start = name.indexOf('(');
if (start != -1) {
int end = name.lastIndexOf(')');
String prefix = name.substring(0, start);
return end + 1 % name.length() == 0 ? prefix : prefix + name.substring(end + 1);
}
}
return name;
} | java | @Nullable
public final String getNormalizedReferenceName() {
String name = getReferenceName();
if (name != null) {
int start = name.indexOf('(');
if (start != -1) {
int end = name.lastIndexOf(')');
String prefix = name.substring(0, start);
return end + 1 % name.length() == 0 ? prefix : prefix + name.substring(end + 1);
}
}
return name;
} | [
"@",
"Nullable",
"public",
"final",
"String",
"getNormalizedReferenceName",
"(",
")",
"{",
"String",
"name",
"=",
"getReferenceName",
"(",
")",
";",
"if",
"(",
"name",
"!=",
"null",
")",
"{",
"int",
"start",
"=",
"name",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"start",
"!=",
"-",
"1",
")",
"{",
"int",
"end",
"=",
"name",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"String",
"prefix",
"=",
"name",
".",
"substring",
"(",
"0",
",",
"start",
")",
";",
"return",
"end",
"+",
"1",
"%",
"name",
".",
"length",
"(",
")",
"==",
"0",
"?",
"prefix",
":",
"prefix",
"+",
"name",
".",
"substring",
"(",
"end",
"+",
"1",
")",
";",
"}",
"}",
"return",
"name",
";",
"}"
] | Due to the complexity of some of our internal type systems, sometimes
we have different types constructed by the same constructor.
In other parts of the type system, these are called delegates.
We construct these types by appending suffixes to the constructor name.
The normalized reference name does not have these suffixes, and as such,
recollapses these implicit types back to their real type. Note that
suffixes such as ".prototype" can be added <i>after</i> the delegate
suffix, so anything after the parentheses must still be retained. | [
"Due",
"to",
"the",
"complexity",
"of",
"some",
"of",
"our",
"internal",
"type",
"systems",
"sometimes",
"we",
"have",
"different",
"types",
"constructed",
"by",
"the",
"same",
"constructor",
".",
"In",
"other",
"parts",
"of",
"the",
"type",
"system",
"these",
"are",
"called",
"delegates",
".",
"We",
"construct",
"these",
"types",
"by",
"appending",
"suffixes",
"to",
"the",
"constructor",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L231-L243 |
23,987 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.defineDeclaredProperty | public final boolean defineDeclaredProperty(String propertyName,
JSType type, Node propertyNode) {
boolean result = defineProperty(propertyName, type, false, propertyNode);
// All property definitions go through this method
// or defineInferredProperty. Because the properties defined an an
// object can affect subtyping, it's slightly more efficient
// to register this after defining the property.
registry.registerPropertyOnType(propertyName, this);
return result;
} | java | public final boolean defineDeclaredProperty(String propertyName,
JSType type, Node propertyNode) {
boolean result = defineProperty(propertyName, type, false, propertyNode);
// All property definitions go through this method
// or defineInferredProperty. Because the properties defined an an
// object can affect subtyping, it's slightly more efficient
// to register this after defining the property.
registry.registerPropertyOnType(propertyName, this);
return result;
} | [
"public",
"final",
"boolean",
"defineDeclaredProperty",
"(",
"String",
"propertyName",
",",
"JSType",
"type",
",",
"Node",
"propertyNode",
")",
"{",
"boolean",
"result",
"=",
"defineProperty",
"(",
"propertyName",
",",
"type",
",",
"false",
",",
"propertyNode",
")",
";",
"// All property definitions go through this method",
"// or defineInferredProperty. Because the properties defined an an",
"// object can affect subtyping, it's slightly more efficient",
"// to register this after defining the property.",
"registry",
".",
"registerPropertyOnType",
"(",
"propertyName",
",",
"this",
")",
";",
"return",
"result",
";",
"}"
] | Defines a property whose type is explicitly declared by the programmer.
@param propertyName the property's name
@param type the type
@param propertyNode the node corresponding to the declaration of property
which might later be accessed using {@code getPropertyNode}. | [
"Defines",
"a",
"property",
"whose",
"type",
"is",
"explicitly",
"declared",
"by",
"the",
"programmer",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L369-L378 |
23,988 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.defineSynthesizedProperty | public final boolean defineSynthesizedProperty(String propertyName,
JSType type, Node propertyNode) {
return defineProperty(propertyName, type, false, propertyNode);
} | java | public final boolean defineSynthesizedProperty(String propertyName,
JSType type, Node propertyNode) {
return defineProperty(propertyName, type, false, propertyNode);
} | [
"public",
"final",
"boolean",
"defineSynthesizedProperty",
"(",
"String",
"propertyName",
",",
"JSType",
"type",
",",
"Node",
"propertyNode",
")",
"{",
"return",
"defineProperty",
"(",
"propertyName",
",",
"type",
",",
"false",
",",
"propertyNode",
")",
";",
"}"
] | Defines a property whose type is on a synthesized object. These objects
don't actually exist in the user's program. They're just used for
bookkeeping in the type system. | [
"Defines",
"a",
"property",
"whose",
"type",
"is",
"on",
"a",
"synthesized",
"object",
".",
"These",
"objects",
"don",
"t",
"actually",
"exist",
"in",
"the",
"user",
"s",
"program",
".",
"They",
"re",
"just",
"used",
"for",
"bookkeeping",
"in",
"the",
"type",
"system",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L385-L388 |
23,989 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.defineInferredProperty | public final boolean defineInferredProperty(String propertyName,
JSType type, Node propertyNode) {
if (hasProperty(propertyName)) {
if (isPropertyTypeDeclared(propertyName)) {
// We never want to hide a declared property with an inferred property.
return true;
}
JSType originalType = getPropertyType(propertyName);
type = originalType == null ? type : originalType.getLeastSupertype(type);
}
boolean result = defineProperty(propertyName, type, true,
propertyNode);
// All property definitions go through this method
// or defineDeclaredProperty. Because the properties defined an an
// object can affect subtyping, it's slightly more efficient
// to register this after defining the property.
registry.registerPropertyOnType(propertyName, this);
return result;
} | java | public final boolean defineInferredProperty(String propertyName,
JSType type, Node propertyNode) {
if (hasProperty(propertyName)) {
if (isPropertyTypeDeclared(propertyName)) {
// We never want to hide a declared property with an inferred property.
return true;
}
JSType originalType = getPropertyType(propertyName);
type = originalType == null ? type : originalType.getLeastSupertype(type);
}
boolean result = defineProperty(propertyName, type, true,
propertyNode);
// All property definitions go through this method
// or defineDeclaredProperty. Because the properties defined an an
// object can affect subtyping, it's slightly more efficient
// to register this after defining the property.
registry.registerPropertyOnType(propertyName, this);
return result;
} | [
"public",
"final",
"boolean",
"defineInferredProperty",
"(",
"String",
"propertyName",
",",
"JSType",
"type",
",",
"Node",
"propertyNode",
")",
"{",
"if",
"(",
"hasProperty",
"(",
"propertyName",
")",
")",
"{",
"if",
"(",
"isPropertyTypeDeclared",
"(",
"propertyName",
")",
")",
"{",
"// We never want to hide a declared property with an inferred property.",
"return",
"true",
";",
"}",
"JSType",
"originalType",
"=",
"getPropertyType",
"(",
"propertyName",
")",
";",
"type",
"=",
"originalType",
"==",
"null",
"?",
"type",
":",
"originalType",
".",
"getLeastSupertype",
"(",
"type",
")",
";",
"}",
"boolean",
"result",
"=",
"defineProperty",
"(",
"propertyName",
",",
"type",
",",
"true",
",",
"propertyNode",
")",
";",
"// All property definitions go through this method",
"// or defineDeclaredProperty. Because the properties defined an an",
"// object can affect subtyping, it's slightly more efficient",
"// to register this after defining the property.",
"registry",
".",
"registerPropertyOnType",
"(",
"propertyName",
",",
"this",
")",
";",
"return",
"result",
";",
"}"
] | Defines a property whose type is inferred.
@param propertyName the property's name
@param type the type
@param propertyNode the node corresponding to the inferred definition of
property that might later be accessed using {@code getPropertyNode}. | [
"Defines",
"a",
"property",
"whose",
"type",
"is",
"inferred",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L397-L418 |
23,990 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.getOwnPropertyJSDocInfo | public final JSDocInfo getOwnPropertyJSDocInfo(String propertyName) {
Property p = getOwnSlot(propertyName);
return p == null ? null : p.getJSDocInfo();
} | java | public final JSDocInfo getOwnPropertyJSDocInfo(String propertyName) {
Property p = getOwnSlot(propertyName);
return p == null ? null : p.getJSDocInfo();
} | [
"public",
"final",
"JSDocInfo",
"getOwnPropertyJSDocInfo",
"(",
"String",
"propertyName",
")",
"{",
"Property",
"p",
"=",
"getOwnSlot",
"(",
"propertyName",
")",
";",
"return",
"p",
"==",
"null",
"?",
"null",
":",
"p",
".",
"getJSDocInfo",
"(",
")",
";",
"}"
] | Gets the docInfo on the specified property on this type. This should not
be implemented recursively, as you generally need to know exactly on
which type in the prototype chain the JSDocInfo exists. | [
"Gets",
"the",
"docInfo",
"on",
"the",
"specified",
"property",
"on",
"this",
"type",
".",
"This",
"should",
"not",
"be",
"implemented",
"recursively",
"as",
"you",
"generally",
"need",
"to",
"know",
"exactly",
"on",
"which",
"type",
"in",
"the",
"prototype",
"chain",
"the",
"JSDocInfo",
"exists",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L481-L484 |
23,991 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.getPropertyType | public JSType getPropertyType(String propertyName) {
StaticTypedSlot slot = getSlot(propertyName);
if (slot == null) {
if (isNoResolvedType() || isCheckedUnknownType()) {
return getNativeType(JSTypeNative.CHECKED_UNKNOWN_TYPE);
} else if (isEmptyType()) {
return getNativeType(JSTypeNative.NO_TYPE);
}
return getNativeType(JSTypeNative.UNKNOWN_TYPE);
}
return slot.getType();
} | java | public JSType getPropertyType(String propertyName) {
StaticTypedSlot slot = getSlot(propertyName);
if (slot == null) {
if (isNoResolvedType() || isCheckedUnknownType()) {
return getNativeType(JSTypeNative.CHECKED_UNKNOWN_TYPE);
} else if (isEmptyType()) {
return getNativeType(JSTypeNative.NO_TYPE);
}
return getNativeType(JSTypeNative.UNKNOWN_TYPE);
}
return slot.getType();
} | [
"public",
"JSType",
"getPropertyType",
"(",
"String",
"propertyName",
")",
"{",
"StaticTypedSlot",
"slot",
"=",
"getSlot",
"(",
"propertyName",
")",
";",
"if",
"(",
"slot",
"==",
"null",
")",
"{",
"if",
"(",
"isNoResolvedType",
"(",
")",
"||",
"isCheckedUnknownType",
"(",
")",
")",
"{",
"return",
"getNativeType",
"(",
"JSTypeNative",
".",
"CHECKED_UNKNOWN_TYPE",
")",
";",
"}",
"else",
"if",
"(",
"isEmptyType",
"(",
")",
")",
"{",
"return",
"getNativeType",
"(",
"JSTypeNative",
".",
"NO_TYPE",
")",
";",
"}",
"return",
"getNativeType",
"(",
"JSTypeNative",
".",
"UNKNOWN_TYPE",
")",
";",
"}",
"return",
"slot",
".",
"getType",
"(",
")",
";",
"}"
] | Gets the property type of the property whose name is given. If the
underlying object does not have this property, the Unknown type is
returned to indicate that no information is available on this property.
This gets overridden by FunctionType for lazily-resolved call() and
bind() functions.
@return the property's type or {@link UnknownType}. This method never
returns {@code null}. | [
"Gets",
"the",
"property",
"type",
"of",
"the",
"property",
"whose",
"name",
"is",
"given",
".",
"If",
"the",
"underlying",
"object",
"does",
"not",
"have",
"this",
"property",
"the",
"Unknown",
"type",
"is",
"returned",
"to",
"indicate",
"that",
"no",
"information",
"is",
"available",
"on",
"this",
"property",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L522-L533 |
23,992 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.getOwnPropertyKind | public final HasPropertyKind getOwnPropertyKind(String propertyName) {
return getOwnSlot(propertyName) != null
? HasPropertyKind.KNOWN_PRESENT
: HasPropertyKind.ABSENT;
} | java | public final HasPropertyKind getOwnPropertyKind(String propertyName) {
return getOwnSlot(propertyName) != null
? HasPropertyKind.KNOWN_PRESENT
: HasPropertyKind.ABSENT;
} | [
"public",
"final",
"HasPropertyKind",
"getOwnPropertyKind",
"(",
"String",
"propertyName",
")",
"{",
"return",
"getOwnSlot",
"(",
"propertyName",
")",
"!=",
"null",
"?",
"HasPropertyKind",
".",
"KNOWN_PRESENT",
":",
"HasPropertyKind",
".",
"ABSENT",
";",
"}"
] | Checks whether the property whose name is given is present directly on
the object. Returns false even if it is declared on a supertype. | [
"Checks",
"whether",
"the",
"property",
"whose",
"name",
"is",
"given",
"is",
"present",
"directly",
"on",
"the",
"object",
".",
"Returns",
"false",
"even",
"if",
"it",
"is",
"declared",
"on",
"a",
"supertype",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L545-L549 |
23,993 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.isPropertyTypeDeclared | public final boolean isPropertyTypeDeclared(String propertyName) {
StaticTypedSlot slot = getSlot(propertyName);
return slot == null ? false : !slot.isTypeInferred();
} | java | public final boolean isPropertyTypeDeclared(String propertyName) {
StaticTypedSlot slot = getSlot(propertyName);
return slot == null ? false : !slot.isTypeInferred();
} | [
"public",
"final",
"boolean",
"isPropertyTypeDeclared",
"(",
"String",
"propertyName",
")",
"{",
"StaticTypedSlot",
"slot",
"=",
"getSlot",
"(",
"propertyName",
")",
";",
"return",
"slot",
"==",
"null",
"?",
"false",
":",
"!",
"slot",
".",
"isTypeInferred",
"(",
")",
";",
"}"
] | Checks whether the property's type is declared. | [
"Checks",
"whether",
"the",
"property",
"s",
"type",
"is",
"declared",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L582-L585 |
23,994 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.isPropertyInExterns | public final boolean isPropertyInExterns(String propertyName) {
Property p = getSlot(propertyName);
return p == null ? false : p.isFromExterns();
} | java | public final boolean isPropertyInExterns(String propertyName) {
Property p = getSlot(propertyName);
return p == null ? false : p.isFromExterns();
} | [
"public",
"final",
"boolean",
"isPropertyInExterns",
"(",
"String",
"propertyName",
")",
"{",
"Property",
"p",
"=",
"getSlot",
"(",
"propertyName",
")",
";",
"return",
"p",
"==",
"null",
"?",
"false",
":",
"p",
".",
"isFromExterns",
"(",
")",
";",
"}"
] | Checks whether the property was defined in the externs. | [
"Checks",
"whether",
"the",
"property",
"was",
"defined",
"in",
"the",
"externs",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L601-L604 |
23,995 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.getPropertyNames | public final Set<String> getPropertyNames() {
Set<String> props = new TreeSet<>();
collectPropertyNames(props);
return props;
} | java | public final Set<String> getPropertyNames() {
Set<String> props = new TreeSet<>();
collectPropertyNames(props);
return props;
} | [
"public",
"final",
"Set",
"<",
"String",
">",
"getPropertyNames",
"(",
")",
"{",
"Set",
"<",
"String",
">",
"props",
"=",
"new",
"TreeSet",
"<>",
"(",
")",
";",
"collectPropertyNames",
"(",
"props",
")",
";",
"return",
"props",
";",
"}"
] | Returns a list of properties defined or inferred on this type and any of
its supertypes. | [
"Returns",
"a",
"list",
"of",
"properties",
"defined",
"or",
"inferred",
"on",
"this",
"type",
"and",
"any",
"of",
"its",
"supertypes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L717-L721 |
23,996 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.isImplicitPrototype | @SuppressWarnings("ReferenceEquality")
final boolean isImplicitPrototype(ObjectType prototype) {
for (ObjectType current = this; current != null; current = current.getImplicitPrototype()) {
if (current.isTemplatizedType()) {
current = current.toMaybeTemplatizedType().getReferencedType();
}
current = deeplyUnwrap(current);
// The prototype should match exactly.
// NOTE: the use of "==" here rather than isEquivalentTo is deliberate. This method
// is very hot in the type checker and relying on identity improves performance of both
// type checking/type inferrence and property disambiguation.
if (current != null && current == prototype) {
return true;
}
}
return false;
} | java | @SuppressWarnings("ReferenceEquality")
final boolean isImplicitPrototype(ObjectType prototype) {
for (ObjectType current = this; current != null; current = current.getImplicitPrototype()) {
if (current.isTemplatizedType()) {
current = current.toMaybeTemplatizedType().getReferencedType();
}
current = deeplyUnwrap(current);
// The prototype should match exactly.
// NOTE: the use of "==" here rather than isEquivalentTo is deliberate. This method
// is very hot in the type checker and relying on identity improves performance of both
// type checking/type inferrence and property disambiguation.
if (current != null && current == prototype) {
return true;
}
}
return false;
} | [
"@",
"SuppressWarnings",
"(",
"\"ReferenceEquality\"",
")",
"final",
"boolean",
"isImplicitPrototype",
"(",
"ObjectType",
"prototype",
")",
"{",
"for",
"(",
"ObjectType",
"current",
"=",
"this",
";",
"current",
"!=",
"null",
";",
"current",
"=",
"current",
".",
"getImplicitPrototype",
"(",
")",
")",
"{",
"if",
"(",
"current",
".",
"isTemplatizedType",
"(",
")",
")",
"{",
"current",
"=",
"current",
".",
"toMaybeTemplatizedType",
"(",
")",
".",
"getReferencedType",
"(",
")",
";",
"}",
"current",
"=",
"deeplyUnwrap",
"(",
"current",
")",
";",
"// The prototype should match exactly.",
"// NOTE: the use of \"==\" here rather than isEquivalentTo is deliberate. This method",
"// is very hot in the type checker and relying on identity improves performance of both",
"// type checking/type inferrence and property disambiguation.",
"if",
"(",
"current",
"!=",
"null",
"&&",
"current",
"==",
"prototype",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks that the prototype is an implicit prototype of this object. Since each object has an
implicit prototype, an implicit prototype's implicit prototype is also this implicit
prototype's.
@param prototype any prototype based object
@return {@code true} if {@code prototype} is {@code equal} to any object in this object's
implicit prototype chain. | [
"Checks",
"that",
"the",
"prototype",
"is",
"an",
"implicit",
"prototype",
"of",
"this",
"object",
".",
"Since",
"each",
"object",
"has",
"an",
"implicit",
"prototype",
"an",
"implicit",
"prototype",
"s",
"implicit",
"prototype",
"is",
"also",
"this",
"implicit",
"prototype",
"s",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L748-L766 |
23,997 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.isUnknownType | @Override
public boolean isUnknownType() {
// If the object is unknown now, check the supertype again,
// because it might have been resolved since the last check.
if (unknown) {
ObjectType implicitProto = getImplicitPrototype();
if (implicitProto == null || implicitProto.isNativeObjectType()) {
unknown = false;
for (ObjectType interfaceType : getCtorExtendedInterfaces()) {
if (interfaceType.isUnknownType()) {
unknown = true;
break;
}
}
} else {
unknown = implicitProto.isUnknownType();
}
}
return unknown;
} | java | @Override
public boolean isUnknownType() {
// If the object is unknown now, check the supertype again,
// because it might have been resolved since the last check.
if (unknown) {
ObjectType implicitProto = getImplicitPrototype();
if (implicitProto == null || implicitProto.isNativeObjectType()) {
unknown = false;
for (ObjectType interfaceType : getCtorExtendedInterfaces()) {
if (interfaceType.isUnknownType()) {
unknown = true;
break;
}
}
} else {
unknown = implicitProto.isUnknownType();
}
}
return unknown;
} | [
"@",
"Override",
"public",
"boolean",
"isUnknownType",
"(",
")",
"{",
"// If the object is unknown now, check the supertype again,",
"// because it might have been resolved since the last check.",
"if",
"(",
"unknown",
")",
"{",
"ObjectType",
"implicitProto",
"=",
"getImplicitPrototype",
"(",
")",
";",
"if",
"(",
"implicitProto",
"==",
"null",
"||",
"implicitProto",
".",
"isNativeObjectType",
"(",
")",
")",
"{",
"unknown",
"=",
"false",
";",
"for",
"(",
"ObjectType",
"interfaceType",
":",
"getCtorExtendedInterfaces",
"(",
")",
")",
"{",
"if",
"(",
"interfaceType",
".",
"isUnknownType",
"(",
")",
")",
"{",
"unknown",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"unknown",
"=",
"implicitProto",
".",
"isUnknownType",
"(",
")",
";",
"}",
"}",
"return",
"unknown",
";",
"}"
] | We treat this as the unknown type if any of its implicit prototype
properties is unknown. | [
"We",
"treat",
"this",
"as",
"the",
"unknown",
"type",
"if",
"any",
"of",
"its",
"implicit",
"prototype",
"properties",
"is",
"unknown",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L792-L811 |
23,998 | google/closure-compiler | src/com/google/javascript/rhino/jstype/ObjectType.java | ObjectType.getPropertyTypeMap | public Map<String, JSType> getPropertyTypeMap() {
ImmutableMap.Builder<String, JSType> propTypeMap = ImmutableMap.builder();
for (String name : this.getPropertyNames()) {
propTypeMap.put(name, this.getPropertyType(name));
}
return propTypeMap.build();
} | java | public Map<String, JSType> getPropertyTypeMap() {
ImmutableMap.Builder<String, JSType> propTypeMap = ImmutableMap.builder();
for (String name : this.getPropertyNames()) {
propTypeMap.put(name, this.getPropertyType(name));
}
return propTypeMap.build();
} | [
"public",
"Map",
"<",
"String",
",",
"JSType",
">",
"getPropertyTypeMap",
"(",
")",
"{",
"ImmutableMap",
".",
"Builder",
"<",
"String",
",",
"JSType",
">",
"propTypeMap",
"=",
"ImmutableMap",
".",
"builder",
"(",
")",
";",
"for",
"(",
"String",
"name",
":",
"this",
".",
"getPropertyNames",
"(",
")",
")",
"{",
"propTypeMap",
".",
"put",
"(",
"name",
",",
"this",
".",
"getPropertyType",
"(",
"name",
")",
")",
";",
"}",
"return",
"propTypeMap",
".",
"build",
"(",
")",
";",
"}"
] | get the map of properties to types covered in an object type
@return a Map that maps the property's name to the property's type | [
"get",
"the",
"map",
"of",
"properties",
"to",
"types",
"covered",
"in",
"an",
"object",
"type"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/ObjectType.java#L878-L884 |
23,999 | google/closure-compiler | src/com/google/javascript/jscomp/CheckConstPrivateProperties.java | CheckConstPrivateProperties.reportMissingConst | private void reportMissingConst(NodeTraversal t) {
for (Node n : candidates) {
String propName = n.getLastChild().getString();
if (!modified.contains(propName)) {
t.report(n, MISSING_CONST_PROPERTY, propName);
}
}
candidates.clear();
modified.clear();
} | java | private void reportMissingConst(NodeTraversal t) {
for (Node n : candidates) {
String propName = n.getLastChild().getString();
if (!modified.contains(propName)) {
t.report(n, MISSING_CONST_PROPERTY, propName);
}
}
candidates.clear();
modified.clear();
} | [
"private",
"void",
"reportMissingConst",
"(",
"NodeTraversal",
"t",
")",
"{",
"for",
"(",
"Node",
"n",
":",
"candidates",
")",
"{",
"String",
"propName",
"=",
"n",
".",
"getLastChild",
"(",
")",
".",
"getString",
"(",
")",
";",
"if",
"(",
"!",
"modified",
".",
"contains",
"(",
"propName",
")",
")",
"{",
"t",
".",
"report",
"(",
"n",
",",
"MISSING_CONST_PROPERTY",
",",
"propName",
")",
";",
"}",
"}",
"candidates",
".",
"clear",
"(",
")",
";",
"modified",
".",
"clear",
"(",
")",
";",
"}"
] | Reports the property definitions that should use the @const annotation. | [
"Reports",
"the",
"property",
"definitions",
"that",
"should",
"use",
"the"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CheckConstPrivateProperties.java#L59-L68 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.