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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
24,900 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.parseConfiguration | private void parseConfiguration(List<String> functionsToInspect) {
for (String function : functionsToInspect) {
Config config = parseConfiguration(function);
functions.put(config.name, config);
String method = getMethodFromDeclarationName(config.name);
if (method != null) {
methods.put(method, config.name);
}
}
} | java | private void parseConfiguration(List<String> functionsToInspect) {
for (String function : functionsToInspect) {
Config config = parseConfiguration(function);
functions.put(config.name, config);
String method = getMethodFromDeclarationName(config.name);
if (method != null) {
methods.put(method, config.name);
}
}
} | [
"private",
"void",
"parseConfiguration",
"(",
"List",
"<",
"String",
">",
"functionsToInspect",
")",
"{",
"for",
"(",
"String",
"function",
":",
"functionsToInspect",
")",
"{",
"Config",
"config",
"=",
"parseConfiguration",
"(",
"function",
")",
";",
"functions",
".",
"put",
"(",
"config",
".",
"name",
",",
"config",
")",
";",
"String",
"method",
"=",
"getMethodFromDeclarationName",
"(",
"config",
".",
"name",
")",
";",
"if",
"(",
"method",
"!=",
"null",
")",
"{",
"methods",
".",
"put",
"(",
"method",
",",
"config",
".",
"name",
")",
";",
"}",
"}",
"}"
] | Build the data structures need by this pass from the provided list of functions and methods. | [
"Build",
"the",
"data",
"structures",
"need",
"by",
"this",
"pass",
"from",
"the",
"provided",
"list",
"of",
"functions",
"and",
"methods",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L461-L471 |
24,901 | google/closure-compiler | src/com/google/javascript/jscomp/ReplaceStrings.java | ReplaceStrings.createNameGenerator | private static DefaultNameGenerator createNameGenerator(Iterable<String> reserved) {
final String namePrefix = "";
final char[] reservedChars = new char[0];
return new DefaultNameGenerator(ImmutableSet.copyOf(reserved), namePrefix, reservedChars);
} | java | private static DefaultNameGenerator createNameGenerator(Iterable<String> reserved) {
final String namePrefix = "";
final char[] reservedChars = new char[0];
return new DefaultNameGenerator(ImmutableSet.copyOf(reserved), namePrefix, reservedChars);
} | [
"private",
"static",
"DefaultNameGenerator",
"createNameGenerator",
"(",
"Iterable",
"<",
"String",
">",
"reserved",
")",
"{",
"final",
"String",
"namePrefix",
"=",
"\"\"",
";",
"final",
"char",
"[",
"]",
"reservedChars",
"=",
"new",
"char",
"[",
"0",
"]",
";",
"return",
"new",
"DefaultNameGenerator",
"(",
"ImmutableSet",
".",
"copyOf",
"(",
"reserved",
")",
",",
"namePrefix",
",",
"reservedChars",
")",
";",
"}"
] | Use a name generate to create names so the names overlap with the names used for variable and
properties. | [
"Use",
"a",
"name",
"generate",
"to",
"create",
"names",
"so",
"the",
"names",
"overlap",
"with",
"the",
"names",
"used",
"for",
"variable",
"and",
"properties",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ReplaceStrings.java#L523-L527 |
24,902 | google/closure-compiler | src/com/google/javascript/jscomp/ClosureCodingConvention.java | ClosureCodingConvention.typeofClassDefiningName | private static SubclassType typeofClassDefiningName(Node callName) {
// Check if the method name matches one of the class-defining methods.
String methodName = null;
if (callName.isGetProp()) {
methodName = callName.getLastChild().getString();
} else if (callName.isName()) {
String name = callName.getString();
int dollarIndex = name.lastIndexOf('$');
if (dollarIndex != -1) {
methodName = name.substring(dollarIndex + 1);
}
}
if (methodName != null) {
if (methodName.equals("inherits")) {
return SubclassType.INHERITS;
} else if (methodName.equals("mixin")) {
return SubclassType.MIXIN;
}
}
return null;
} | java | private static SubclassType typeofClassDefiningName(Node callName) {
// Check if the method name matches one of the class-defining methods.
String methodName = null;
if (callName.isGetProp()) {
methodName = callName.getLastChild().getString();
} else if (callName.isName()) {
String name = callName.getString();
int dollarIndex = name.lastIndexOf('$');
if (dollarIndex != -1) {
methodName = name.substring(dollarIndex + 1);
}
}
if (methodName != null) {
if (methodName.equals("inherits")) {
return SubclassType.INHERITS;
} else if (methodName.equals("mixin")) {
return SubclassType.MIXIN;
}
}
return null;
} | [
"private",
"static",
"SubclassType",
"typeofClassDefiningName",
"(",
"Node",
"callName",
")",
"{",
"// Check if the method name matches one of the class-defining methods.",
"String",
"methodName",
"=",
"null",
";",
"if",
"(",
"callName",
".",
"isGetProp",
"(",
")",
")",
"{",
"methodName",
"=",
"callName",
".",
"getLastChild",
"(",
")",
".",
"getString",
"(",
")",
";",
"}",
"else",
"if",
"(",
"callName",
".",
"isName",
"(",
")",
")",
"{",
"String",
"name",
"=",
"callName",
".",
"getString",
"(",
")",
";",
"int",
"dollarIndex",
"=",
"name",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"dollarIndex",
"!=",
"-",
"1",
")",
"{",
"methodName",
"=",
"name",
".",
"substring",
"(",
"dollarIndex",
"+",
"1",
")",
";",
"}",
"}",
"if",
"(",
"methodName",
"!=",
"null",
")",
"{",
"if",
"(",
"methodName",
".",
"equals",
"(",
"\"inherits\"",
")",
")",
"{",
"return",
"SubclassType",
".",
"INHERITS",
";",
"}",
"else",
"if",
"(",
"methodName",
".",
"equals",
"(",
"\"mixin\"",
")",
")",
"{",
"return",
"SubclassType",
".",
"MIXIN",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Determines whether the given node is a class-defining name, like
"inherits" or "mixin."
@return The type of class-defining name, or null. | [
"Determines",
"whether",
"the",
"given",
"node",
"is",
"a",
"class",
"-",
"defining",
"name",
"like",
"inherits",
"or",
"mixin",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ClosureCodingConvention.java#L156-L177 |
24,903 | google/closure-compiler | src/com/google/javascript/rhino/jstype/UnionTypeBuilder.java | UnionTypeBuilder.addAlternates | public UnionTypeBuilder addAlternates(ImmutableList<JSType> list) {
for (int i = 0; i < list.size(); i++) {
addAlternate(list.get(i));
}
return this;
} | java | public UnionTypeBuilder addAlternates(ImmutableList<JSType> list) {
for (int i = 0; i < list.size(); i++) {
addAlternate(list.get(i));
}
return this;
} | [
"public",
"UnionTypeBuilder",
"addAlternates",
"(",
"ImmutableList",
"<",
"JSType",
">",
"list",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"list",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"addAlternate",
"(",
"list",
".",
"get",
"(",
"i",
")",
")",
";",
"}",
"return",
"this",
";",
"}"
] | adding a union as an alternate. | [
"adding",
"a",
"union",
"as",
"an",
"alternate",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/UnionTypeBuilder.java#L162-L167 |
24,904 | google/closure-compiler | src/com/google/javascript/rhino/jstype/UnionTypeBuilder.java | UnionTypeBuilder.reduceAlternatesWithoutUnion | private JSType reduceAlternatesWithoutUnion() {
JSType wildcard = getNativeWildcardType();
if (wildcard != null) {
return containsVoidType ? null : wildcard;
}
int size = alternates.size();
if (size > maxUnionSize) {
return registry.getNativeType(UNKNOWN_TYPE);
} else if (size > 1) {
return null;
} else if (size == 1) {
return alternates.get(0);
} else {
return registry.getNativeType(NO_TYPE);
}
} | java | private JSType reduceAlternatesWithoutUnion() {
JSType wildcard = getNativeWildcardType();
if (wildcard != null) {
return containsVoidType ? null : wildcard;
}
int size = alternates.size();
if (size > maxUnionSize) {
return registry.getNativeType(UNKNOWN_TYPE);
} else if (size > 1) {
return null;
} else if (size == 1) {
return alternates.get(0);
} else {
return registry.getNativeType(NO_TYPE);
}
} | [
"private",
"JSType",
"reduceAlternatesWithoutUnion",
"(",
")",
"{",
"JSType",
"wildcard",
"=",
"getNativeWildcardType",
"(",
")",
";",
"if",
"(",
"wildcard",
"!=",
"null",
")",
"{",
"return",
"containsVoidType",
"?",
"null",
":",
"wildcard",
";",
"}",
"int",
"size",
"=",
"alternates",
".",
"size",
"(",
")",
";",
"if",
"(",
"size",
">",
"maxUnionSize",
")",
"{",
"return",
"registry",
".",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
";",
"}",
"else",
"if",
"(",
"size",
">",
"1",
")",
"{",
"return",
"null",
";",
"}",
"else",
"if",
"(",
"size",
"==",
"1",
")",
"{",
"return",
"alternates",
".",
"get",
"(",
"0",
")",
";",
"}",
"else",
"{",
"return",
"registry",
".",
"getNativeType",
"(",
"NO_TYPE",
")",
";",
"}",
"}"
] | Reduce the alternates into a non-union type.
If the alternates can't be accurately represented with a non-union
type, return null. | [
"Reduce",
"the",
"alternates",
"into",
"a",
"non",
"-",
"union",
"type",
".",
"If",
"the",
"alternates",
"can",
"t",
"be",
"accurately",
"represented",
"with",
"a",
"non",
"-",
"union",
"type",
"return",
"null",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/UnionTypeBuilder.java#L351-L366 |
24,905 | google/closure-compiler | src/com/google/javascript/rhino/jstype/UnionTypeBuilder.java | UnionTypeBuilder.getNativeWildcardType | private JSType getNativeWildcardType() {
if (isAllType) {
return registry.getNativeType(ALL_TYPE);
} else if (isNativeUnknownType) {
if (areAllUnknownsChecked) {
return registry.getNativeType(CHECKED_UNKNOWN_TYPE);
} else {
return registry.getNativeType(UNKNOWN_TYPE);
}
}
return null;
} | java | private JSType getNativeWildcardType() {
if (isAllType) {
return registry.getNativeType(ALL_TYPE);
} else if (isNativeUnknownType) {
if (areAllUnknownsChecked) {
return registry.getNativeType(CHECKED_UNKNOWN_TYPE);
} else {
return registry.getNativeType(UNKNOWN_TYPE);
}
}
return null;
} | [
"private",
"JSType",
"getNativeWildcardType",
"(",
")",
"{",
"if",
"(",
"isAllType",
")",
"{",
"return",
"registry",
".",
"getNativeType",
"(",
"ALL_TYPE",
")",
";",
"}",
"else",
"if",
"(",
"isNativeUnknownType",
")",
"{",
"if",
"(",
"areAllUnknownsChecked",
")",
"{",
"return",
"registry",
".",
"getNativeType",
"(",
"CHECKED_UNKNOWN_TYPE",
")",
";",
"}",
"else",
"{",
"return",
"registry",
".",
"getNativeType",
"(",
"UNKNOWN_TYPE",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns ALL_TYPE, UNKNOWN_TYPE, or CHECKED_UNKNOWN_TYPE, as specified by the flags, or null | [
"Returns",
"ALL_TYPE",
"UNKNOWN_TYPE",
"or",
"CHECKED_UNKNOWN_TYPE",
"as",
"specified",
"by",
"the",
"flags",
"or",
"null"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/UnionTypeBuilder.java#L369-L380 |
24,906 | google/closure-compiler | src/com/google/javascript/rhino/jstype/UnionTypeBuilder.java | UnionTypeBuilder.build | public JSType build() {
if (result == null) {
result = reduceAlternatesWithoutUnion();
if (result == null) {
result = new UnionType(registry, ImmutableList.copyOf(getAlternates()));
}
}
return result;
} | java | public JSType build() {
if (result == null) {
result = reduceAlternatesWithoutUnion();
if (result == null) {
result = new UnionType(registry, ImmutableList.copyOf(getAlternates()));
}
}
return result;
} | [
"public",
"JSType",
"build",
"(",
")",
"{",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"result",
"=",
"reduceAlternatesWithoutUnion",
"(",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"result",
"=",
"new",
"UnionType",
"(",
"registry",
",",
"ImmutableList",
".",
"copyOf",
"(",
"getAlternates",
"(",
")",
")",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Creates a union.
@return A UnionType if it has two or more alternates, the
only alternate if it has one and otherwise {@code NO_TYPE}. | [
"Creates",
"a",
"union",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/UnionTypeBuilder.java#L387-L395 |
24,907 | google/closure-compiler | src/com/google/javascript/jscomp/ClosureOptimizePrimitives.java | ClosureOptimizePrimitives.canOptimizeObjectCreate | private boolean canOptimizeObjectCreate(Node firstParam) {
Node curParam = firstParam;
while (curParam != null) {
if (!isOptimizableKey(curParam)) {
return false;
}
curParam = curParam.getNext();
// Check for an odd number of parameters.
if (curParam == null) {
return false;
}
curParam = curParam.getNext();
}
return true;
} | java | private boolean canOptimizeObjectCreate(Node firstParam) {
Node curParam = firstParam;
while (curParam != null) {
if (!isOptimizableKey(curParam)) {
return false;
}
curParam = curParam.getNext();
// Check for an odd number of parameters.
if (curParam == null) {
return false;
}
curParam = curParam.getNext();
}
return true;
} | [
"private",
"boolean",
"canOptimizeObjectCreate",
"(",
"Node",
"firstParam",
")",
"{",
"Node",
"curParam",
"=",
"firstParam",
";",
"while",
"(",
"curParam",
"!=",
"null",
")",
"{",
"if",
"(",
"!",
"isOptimizableKey",
"(",
"curParam",
")",
")",
"{",
"return",
"false",
";",
"}",
"curParam",
"=",
"curParam",
".",
"getNext",
"(",
")",
";",
"// Check for an odd number of parameters.",
"if",
"(",
"curParam",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"curParam",
"=",
"curParam",
".",
"getNext",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Returns whether the given call to goog.object.create can be converted to an
object literal. | [
"Returns",
"whether",
"the",
"given",
"call",
"to",
"goog",
".",
"object",
".",
"create",
"can",
"be",
"converted",
"to",
"an",
"object",
"literal",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ClosureOptimizePrimitives.java#L150-L165 |
24,908 | google/closure-compiler | src/com/google/javascript/jscomp/ClosureOptimizePrimitives.java | ClosureOptimizePrimitives.canOptimizeObjectCreateSet | private boolean canOptimizeObjectCreateSet(Node firstParam) {
if (firstParam != null
&& firstParam.getNext() == null
&& !(firstParam.isNumber() || firstParam.isString())) {
// if there is only one argument, and it's an array, then the method uses the array elements
// as keys. Don't optimize it to {[arr]: true}. We only special-case number and string
// arguments in order to not regress ES5-out behavior
return false;
}
Node curParam = firstParam;
Set<String> keys = new HashSet<>();
while (curParam != null) {
// All keys must be strings or numbers, otherwise we can't optimize the call.
if (!isOptimizableKey(curParam)) {
return false;
}
if (curParam.isString() || curParam.isNumber()) {
String key =
curParam.isString() ? curParam.getString() : numberToString(curParam.getDouble());
if (!keys.add(key)) {
compiler.report(JSError.make(firstParam.getPrevious(), DUPLICATE_SET_MEMBER, key));
return false;
}
}
curParam = curParam.getNext();
}
return true;
} | java | private boolean canOptimizeObjectCreateSet(Node firstParam) {
if (firstParam != null
&& firstParam.getNext() == null
&& !(firstParam.isNumber() || firstParam.isString())) {
// if there is only one argument, and it's an array, then the method uses the array elements
// as keys. Don't optimize it to {[arr]: true}. We only special-case number and string
// arguments in order to not regress ES5-out behavior
return false;
}
Node curParam = firstParam;
Set<String> keys = new HashSet<>();
while (curParam != null) {
// All keys must be strings or numbers, otherwise we can't optimize the call.
if (!isOptimizableKey(curParam)) {
return false;
}
if (curParam.isString() || curParam.isNumber()) {
String key =
curParam.isString() ? curParam.getString() : numberToString(curParam.getDouble());
if (!keys.add(key)) {
compiler.report(JSError.make(firstParam.getPrevious(), DUPLICATE_SET_MEMBER, key));
return false;
}
}
curParam = curParam.getNext();
}
return true;
} | [
"private",
"boolean",
"canOptimizeObjectCreateSet",
"(",
"Node",
"firstParam",
")",
"{",
"if",
"(",
"firstParam",
"!=",
"null",
"&&",
"firstParam",
".",
"getNext",
"(",
")",
"==",
"null",
"&&",
"!",
"(",
"firstParam",
".",
"isNumber",
"(",
")",
"||",
"firstParam",
".",
"isString",
"(",
")",
")",
")",
"{",
"// if there is only one argument, and it's an array, then the method uses the array elements",
"// as keys. Don't optimize it to {[arr]: true}. We only special-case number and string",
"// arguments in order to not regress ES5-out behavior",
"return",
"false",
";",
"}",
"Node",
"curParam",
"=",
"firstParam",
";",
"Set",
"<",
"String",
">",
"keys",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"while",
"(",
"curParam",
"!=",
"null",
")",
"{",
"// All keys must be strings or numbers, otherwise we can't optimize the call.",
"if",
"(",
"!",
"isOptimizableKey",
"(",
"curParam",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"curParam",
".",
"isString",
"(",
")",
"||",
"curParam",
".",
"isNumber",
"(",
")",
")",
"{",
"String",
"key",
"=",
"curParam",
".",
"isString",
"(",
")",
"?",
"curParam",
".",
"getString",
"(",
")",
":",
"numberToString",
"(",
"curParam",
".",
"getDouble",
"(",
")",
")",
";",
"if",
"(",
"!",
"keys",
".",
"add",
"(",
"key",
")",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"firstParam",
".",
"getPrevious",
"(",
")",
",",
"DUPLICATE_SET_MEMBER",
",",
"key",
")",
")",
";",
"return",
"false",
";",
"}",
"}",
"curParam",
"=",
"curParam",
".",
"getNext",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Returns whether the given call to goog.object.createSet can be converted to an object literal. | [
"Returns",
"whether",
"the",
"given",
"call",
"to",
"goog",
".",
"object",
".",
"createSet",
"can",
"be",
"converted",
"to",
"an",
"object",
"literal",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ClosureOptimizePrimitives.java#L192-L220 |
24,909 | google/closure-compiler | src/com/google/javascript/jscomp/ClosureOptimizePrimitives.java | ClosureOptimizePrimitives.maybeProcessDomTagName | private void maybeProcessDomTagName(Node n) {
if (NodeUtil.isLValue(n)) {
return;
}
String prefix = "goog$dom$TagName$";
String tagName;
if (n.isName() && n.getString().startsWith(prefix)) {
tagName = n.getString().substring(prefix.length());
} else if (n.isGetProp() && !n.getParent().isGetProp()
&& n.getFirstChild().matchesQualifiedName("goog.dom.TagName")) {
tagName = n.getSecondChild().getString()
.replaceFirst(".*\\$", ""); // Added by DisambiguateProperties.
} else {
return;
}
Node stringNode = IR.string(tagName).srcref(n);
n.replaceWith(stringNode);
compiler.reportChangeToEnclosingScope(stringNode);
} | java | private void maybeProcessDomTagName(Node n) {
if (NodeUtil.isLValue(n)) {
return;
}
String prefix = "goog$dom$TagName$";
String tagName;
if (n.isName() && n.getString().startsWith(prefix)) {
tagName = n.getString().substring(prefix.length());
} else if (n.isGetProp() && !n.getParent().isGetProp()
&& n.getFirstChild().matchesQualifiedName("goog.dom.TagName")) {
tagName = n.getSecondChild().getString()
.replaceFirst(".*\\$", ""); // Added by DisambiguateProperties.
} else {
return;
}
Node stringNode = IR.string(tagName).srcref(n);
n.replaceWith(stringNode);
compiler.reportChangeToEnclosingScope(stringNode);
} | [
"private",
"void",
"maybeProcessDomTagName",
"(",
"Node",
"n",
")",
"{",
"if",
"(",
"NodeUtil",
".",
"isLValue",
"(",
"n",
")",
")",
"{",
"return",
";",
"}",
"String",
"prefix",
"=",
"\"goog$dom$TagName$\"",
";",
"String",
"tagName",
";",
"if",
"(",
"n",
".",
"isName",
"(",
")",
"&&",
"n",
".",
"getString",
"(",
")",
".",
"startsWith",
"(",
"prefix",
")",
")",
"{",
"tagName",
"=",
"n",
".",
"getString",
"(",
")",
".",
"substring",
"(",
"prefix",
".",
"length",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"n",
".",
"isGetProp",
"(",
")",
"&&",
"!",
"n",
".",
"getParent",
"(",
")",
".",
"isGetProp",
"(",
")",
"&&",
"n",
".",
"getFirstChild",
"(",
")",
".",
"matchesQualifiedName",
"(",
"\"goog.dom.TagName\"",
")",
")",
"{",
"tagName",
"=",
"n",
".",
"getSecondChild",
"(",
")",
".",
"getString",
"(",
")",
".",
"replaceFirst",
"(",
"\".*\\\\$\"",
",",
"\"\"",
")",
";",
"// Added by DisambiguateProperties.",
"}",
"else",
"{",
"return",
";",
"}",
"Node",
"stringNode",
"=",
"IR",
".",
"string",
"(",
"tagName",
")",
".",
"srcref",
"(",
"n",
")",
";",
"n",
".",
"replaceWith",
"(",
"stringNode",
")",
";",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"stringNode",
")",
";",
"}"
] | Converts the given node to string if it is safe to do so. | [
"Converts",
"the",
"given",
"node",
"to",
"string",
"if",
"it",
"is",
"safe",
"to",
"do",
"so",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ClosureOptimizePrimitives.java#L248-L266 |
24,910 | google/closure-compiler | src/com/google/javascript/jscomp/ModuleRenaming.java | ModuleRenaming.getGlobalNameOfEsModuleLocalVariable | static String getGlobalNameOfEsModuleLocalVariable(
ModuleMetadata moduleMetadata, String variableName) {
return variableName + "$$" + getGlobalName(moduleMetadata, /* googNamespace= */ null);
} | java | static String getGlobalNameOfEsModuleLocalVariable(
ModuleMetadata moduleMetadata, String variableName) {
return variableName + "$$" + getGlobalName(moduleMetadata, /* googNamespace= */ null);
} | [
"static",
"String",
"getGlobalNameOfEsModuleLocalVariable",
"(",
"ModuleMetadata",
"moduleMetadata",
",",
"String",
"variableName",
")",
"{",
"return",
"variableName",
"+",
"\"$$\"",
"+",
"getGlobalName",
"(",
"moduleMetadata",
",",
"/* googNamespace= */",
"null",
")",
";",
"}"
] | Returns the global name of a variable declared in an ES module. | [
"Returns",
"the",
"global",
"name",
"of",
"a",
"variable",
"declared",
"in",
"an",
"ES",
"module",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ModuleRenaming.java#L42-L45 |
24,911 | google/closure-compiler | src/com/google/javascript/jscomp/ModuleRenaming.java | ModuleRenaming.getGlobalName | static String getGlobalName(Export export) {
if (export.moduleMetadata().isEs6Module()) {
if (export.localName().equals(Export.DEFAULT_EXPORT_NAME)) {
return getGlobalNameOfAnonymousDefaultExport(export.moduleMetadata());
}
return getGlobalNameOfEsModuleLocalVariable(export.moduleMetadata(), export.localName());
}
return getGlobalName(export.moduleMetadata(), export.closureNamespace())
+ "."
+ export.exportName();
} | java | static String getGlobalName(Export export) {
if (export.moduleMetadata().isEs6Module()) {
if (export.localName().equals(Export.DEFAULT_EXPORT_NAME)) {
return getGlobalNameOfAnonymousDefaultExport(export.moduleMetadata());
}
return getGlobalNameOfEsModuleLocalVariable(export.moduleMetadata(), export.localName());
}
return getGlobalName(export.moduleMetadata(), export.closureNamespace())
+ "."
+ export.exportName();
} | [
"static",
"String",
"getGlobalName",
"(",
"Export",
"export",
")",
"{",
"if",
"(",
"export",
".",
"moduleMetadata",
"(",
")",
".",
"isEs6Module",
"(",
")",
")",
"{",
"if",
"(",
"export",
".",
"localName",
"(",
")",
".",
"equals",
"(",
"Export",
".",
"DEFAULT_EXPORT_NAME",
")",
")",
"{",
"return",
"getGlobalNameOfAnonymousDefaultExport",
"(",
"export",
".",
"moduleMetadata",
"(",
")",
")",
";",
"}",
"return",
"getGlobalNameOfEsModuleLocalVariable",
"(",
"export",
".",
"moduleMetadata",
"(",
")",
",",
"export",
".",
"localName",
"(",
")",
")",
";",
"}",
"return",
"getGlobalName",
"(",
"export",
".",
"moduleMetadata",
"(",
")",
",",
"export",
".",
"closureNamespace",
"(",
")",
")",
"+",
"\".\"",
"+",
"export",
".",
"exportName",
"(",
")",
";",
"}"
] | Returns the post-transpilation, globalized name of the export. | [
"Returns",
"the",
"post",
"-",
"transpilation",
"globalized",
"name",
"of",
"the",
"export",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ModuleRenaming.java#L76-L86 |
24,912 | google/closure-compiler | src/com/google/javascript/jscomp/ModuleRenaming.java | ModuleRenaming.getGlobalName | static String getGlobalName(Binding binding) {
if (binding.isModuleNamespace()) {
return getGlobalName(binding.metadata(), binding.closureNamespace());
}
return getGlobalName(binding.originatingExport());
} | java | static String getGlobalName(Binding binding) {
if (binding.isModuleNamespace()) {
return getGlobalName(binding.metadata(), binding.closureNamespace());
}
return getGlobalName(binding.originatingExport());
} | [
"static",
"String",
"getGlobalName",
"(",
"Binding",
"binding",
")",
"{",
"if",
"(",
"binding",
".",
"isModuleNamespace",
"(",
")",
")",
"{",
"return",
"getGlobalName",
"(",
"binding",
".",
"metadata",
"(",
")",
",",
"binding",
".",
"closureNamespace",
"(",
")",
")",
";",
"}",
"return",
"getGlobalName",
"(",
"binding",
".",
"originatingExport",
"(",
")",
")",
";",
"}"
] | Returns the post-transpilation, globalized name of the binding. | [
"Returns",
"the",
"post",
"-",
"transpilation",
"globalized",
"name",
"of",
"the",
"binding",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ModuleRenaming.java#L89-L94 |
24,913 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.anything | public static Matcher anything() {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return true;
}
};
} | java | public static Matcher anything() {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return true;
}
};
} | [
"public",
"static",
"Matcher",
"anything",
"(",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"return",
"true",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches every node. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"every",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L37-L43 |
24,914 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.allOf | public static Matcher allOf(final Matcher... matchers) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
for (Matcher m : matchers) {
if (!m.matches(node, metadata)) {
return false;
}
}
return true;
}
};
} | java | public static Matcher allOf(final Matcher... matchers) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
for (Matcher m : matchers) {
if (!m.matches(node, metadata)) {
return false;
}
}
return true;
}
};
} | [
"public",
"static",
"Matcher",
"allOf",
"(",
"final",
"Matcher",
"...",
"matchers",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"for",
"(",
"Matcher",
"m",
":",
"matchers",
")",
"{",
"if",
"(",
"!",
"m",
".",
"matches",
"(",
"node",
",",
"metadata",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that returns true only if all of the provided
matchers match. | [
"Returns",
"a",
"Matcher",
"that",
"returns",
"true",
"only",
"if",
"all",
"of",
"the",
"provided",
"matchers",
"match",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L49-L60 |
24,915 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.not | public static Matcher not(final Matcher matcher) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return !matcher.matches(node, metadata);
}
};
} | java | public static Matcher not(final Matcher matcher) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return !matcher.matches(node, metadata);
}
};
} | [
"public",
"static",
"Matcher",
"not",
"(",
"final",
"Matcher",
"matcher",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"return",
"!",
"matcher",
".",
"matches",
"(",
"node",
",",
"metadata",
")",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches the opposite of the provided matcher. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"the",
"opposite",
"of",
"the",
"provided",
"matcher",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L81-L87 |
24,916 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.constructor | public static Matcher constructor(final String name) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
JSDocInfo info = node.getJSDocInfo();
if (info != null && info.isConstructor()) {
Node firstChild = node.getFirstChild();
// TODO(mknichel): Make sure this works with the following cases:
// ns = {
// /** @constructor */
// name: function() {}
// }
if (name == null) {
return true;
}
if ((firstChild.isGetProp() || firstChild.isName())
&& firstChild.matchesQualifiedName(name)) {
return true;
}
}
return false;
}
};
} | java | public static Matcher constructor(final String name) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
JSDocInfo info = node.getJSDocInfo();
if (info != null && info.isConstructor()) {
Node firstChild = node.getFirstChild();
// TODO(mknichel): Make sure this works with the following cases:
// ns = {
// /** @constructor */
// name: function() {}
// }
if (name == null) {
return true;
}
if ((firstChild.isGetProp() || firstChild.isName())
&& firstChild.matchesQualifiedName(name)) {
return true;
}
}
return false;
}
};
} | [
"public",
"static",
"Matcher",
"constructor",
"(",
"final",
"String",
"name",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"JSDocInfo",
"info",
"=",
"node",
".",
"getJSDocInfo",
"(",
")",
";",
"if",
"(",
"info",
"!=",
"null",
"&&",
"info",
".",
"isConstructor",
"(",
")",
")",
"{",
"Node",
"firstChild",
"=",
"node",
".",
"getFirstChild",
"(",
")",
";",
"// TODO(mknichel): Make sure this works with the following cases:",
"// ns = {",
"// /** @constructor */",
"// name: function() {}",
"// }",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"(",
"firstChild",
".",
"isGetProp",
"(",
")",
"||",
"firstChild",
".",
"isName",
"(",
")",
")",
"&&",
"firstChild",
".",
"matchesQualifiedName",
"(",
"name",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"}",
";",
"}"
] | Returns a matcher that matches constructor definitions of the specified
name.
@param name The name of the class constructor to match. | [
"Returns",
"a",
"matcher",
"that",
"matches",
"constructor",
"definitions",
"of",
"the",
"specified",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L101-L123 |
24,917 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.newClass | public static Matcher newClass() {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return node.isNew();
}
};
} | java | public static Matcher newClass() {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return node.isNew();
}
};
} | [
"public",
"static",
"Matcher",
"newClass",
"(",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"return",
"node",
".",
"isNew",
"(",
")",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches constructing new objects. This will match
the NEW node of the JS Compiler AST. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"constructing",
"new",
"objects",
".",
"This",
"will",
"match",
"the",
"NEW",
"node",
"of",
"the",
"JS",
"Compiler",
"AST",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L129-L135 |
24,918 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.newClass | public static Matcher newClass(final String className) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
if (!node.isNew()) {
return false;
}
JSType providedJsType = getJsType(metadata, className);
if (providedJsType == null) {
return false;
}
JSType jsType = node.getJSType();
if (jsType == null) {
return false;
}
jsType = jsType.restrictByNotNullOrUndefined();
return areTypesEquivalentIgnoringGenerics(jsType, providedJsType);
}
};
} | java | public static Matcher newClass(final String className) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
if (!node.isNew()) {
return false;
}
JSType providedJsType = getJsType(metadata, className);
if (providedJsType == null) {
return false;
}
JSType jsType = node.getJSType();
if (jsType == null) {
return false;
}
jsType = jsType.restrictByNotNullOrUndefined();
return areTypesEquivalentIgnoringGenerics(jsType, providedJsType);
}
};
} | [
"public",
"static",
"Matcher",
"newClass",
"(",
"final",
"String",
"className",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"if",
"(",
"!",
"node",
".",
"isNew",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"JSType",
"providedJsType",
"=",
"getJsType",
"(",
"metadata",
",",
"className",
")",
";",
"if",
"(",
"providedJsType",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"JSType",
"jsType",
"=",
"node",
".",
"getJSType",
"(",
")",
";",
"if",
"(",
"jsType",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"jsType",
"=",
"jsType",
".",
"restrictByNotNullOrUndefined",
"(",
")",
";",
"return",
"areTypesEquivalentIgnoringGenerics",
"(",
"jsType",
",",
"providedJsType",
")",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches constructing objects of the provided class
name. This will match the NEW node of the JS Compiler AST.
@param className The name of the class to return matching NEW nodes. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"constructing",
"objects",
"of",
"the",
"provided",
"class",
"name",
".",
"This",
"will",
"match",
"the",
"NEW",
"node",
"of",
"the",
"JS",
"Compiler",
"AST",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L142-L161 |
24,919 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.functionCall | public static Matcher functionCall(final String name) {
return new Matcher() {
@Override
public boolean matches(Node node, NodeMetadata metadata) {
// TODO(mknichel): Handle the case when functions are applied through .call or .apply.
return node.isCall() && propertyAccess(name).matches(node.getFirstChild(), metadata);
}
};
} | java | public static Matcher functionCall(final String name) {
return new Matcher() {
@Override
public boolean matches(Node node, NodeMetadata metadata) {
// TODO(mknichel): Handle the case when functions are applied through .call or .apply.
return node.isCall() && propertyAccess(name).matches(node.getFirstChild(), metadata);
}
};
} | [
"public",
"static",
"Matcher",
"functionCall",
"(",
"final",
"String",
"name",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"// TODO(mknichel): Handle the case when functions are applied through .call or .apply.",
"return",
"node",
".",
"isCall",
"(",
")",
"&&",
"propertyAccess",
"(",
"name",
")",
".",
"matches",
"(",
"node",
".",
"getFirstChild",
"(",
")",
",",
"metadata",
")",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches all nodes that are function calls that match the provided name.
@param name The name of the function to match. For non-static functions, this must be the fully
qualified name that includes the type of the object. For instance: {@code
ns.AppContext.prototype.get} will match {@code appContext.get} and {@code this.get} when
called from the AppContext class. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"all",
"nodes",
"that",
"are",
"function",
"calls",
"that",
"match",
"the",
"provided",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L178-L186 |
24,920 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.functionCallWithNumArgs | public static Matcher functionCallWithNumArgs(final int numArgs) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return node.isCall() && (node.getChildCount() - 1) == numArgs;
}
};
} | java | public static Matcher functionCallWithNumArgs(final int numArgs) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return node.isCall() && (node.getChildCount() - 1) == numArgs;
}
};
} | [
"public",
"static",
"Matcher",
"functionCallWithNumArgs",
"(",
"final",
"int",
"numArgs",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"return",
"node",
".",
"isCall",
"(",
")",
"&&",
"(",
"node",
".",
"getChildCount",
"(",
")",
"-",
"1",
")",
"==",
"numArgs",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches any function call that has the given
number of arguments. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"any",
"function",
"call",
"that",
"has",
"the",
"given",
"number",
"of",
"arguments",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L192-L198 |
24,921 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.functionCallWithNumArgs | public static Matcher functionCallWithNumArgs(final String name, final int numArgs) {
return allOf(functionCallWithNumArgs(numArgs), functionCall(name));
} | java | public static Matcher functionCallWithNumArgs(final String name, final int numArgs) {
return allOf(functionCallWithNumArgs(numArgs), functionCall(name));
} | [
"public",
"static",
"Matcher",
"functionCallWithNumArgs",
"(",
"final",
"String",
"name",
",",
"final",
"int",
"numArgs",
")",
"{",
"return",
"allOf",
"(",
"functionCallWithNumArgs",
"(",
"numArgs",
")",
",",
"functionCall",
"(",
"name",
")",
")",
";",
"}"
] | Returns a Matcher that matches any function call that has the given
number of arguments and the given name.
@param name The name of the function to match. For non-static functions,
this must be the fully qualified name that includes the type of the
object. For instance: {@code ns.AppContext.prototype.get} will match
{@code appContext.get} and {@code this.get} when called from the
AppContext class. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"any",
"function",
"call",
"that",
"has",
"the",
"given",
"number",
"of",
"arguments",
"and",
"the",
"given",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L209-L211 |
24,922 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.propertyAccess | public static Matcher propertyAccess(final String name) {
return new Matcher() {
@Override
public boolean matches(Node node, NodeMetadata metadata) {
if (node.isGetProp()) {
if (name == null) {
return true;
}
if (node.matchesQualifiedName(name)) {
return true;
} else if (name.contains(".prototype.")) {
return matchesPrototypeInstanceVar(node, metadata, name);
}
}
return false;
}
};
} | java | public static Matcher propertyAccess(final String name) {
return new Matcher() {
@Override
public boolean matches(Node node, NodeMetadata metadata) {
if (node.isGetProp()) {
if (name == null) {
return true;
}
if (node.matchesQualifiedName(name)) {
return true;
} else if (name.contains(".prototype.")) {
return matchesPrototypeInstanceVar(node, metadata, name);
}
}
return false;
}
};
} | [
"public",
"static",
"Matcher",
"propertyAccess",
"(",
"final",
"String",
"name",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"if",
"(",
"node",
".",
"isGetProp",
"(",
")",
")",
"{",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"node",
".",
"matchesQualifiedName",
"(",
"name",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"name",
".",
"contains",
"(",
"\".prototype.\"",
")",
")",
"{",
"return",
"matchesPrototypeInstanceVar",
"(",
"node",
",",
"metadata",
",",
"name",
")",
";",
"}",
"}",
"return",
"false",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches nodes representing a GETPROP access of
an object property.
@param name The name of the property to match. For non-static properties,
this must be the fully qualified name that includes the type of the
object. For instance: {@code ns.AppContext.prototype.root}
will match {@code appContext.root} and {@code this.root} when accessed
from the AppContext. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"nodes",
"representing",
"a",
"GETPROP",
"access",
"of",
"an",
"object",
"property",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L252-L269 |
24,923 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.enumDefinition | public static Matcher enumDefinition() {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
JSType jsType = node.getJSType();
return jsType != null && jsType.isEnumType();
}
};
} | java | public static Matcher enumDefinition() {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
JSType jsType = node.getJSType();
return jsType != null && jsType.isEnumType();
}
};
} | [
"public",
"static",
"Matcher",
"enumDefinition",
"(",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"JSType",
"jsType",
"=",
"node",
".",
"getJSType",
"(",
")",
";",
"return",
"jsType",
"!=",
"null",
"&&",
"jsType",
".",
"isEnumType",
"(",
")",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches definitions of any enum. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"definitions",
"of",
"any",
"enum",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L274-L281 |
24,924 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.enumDefinitionOfType | public static Matcher enumDefinitionOfType(final String type) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
JSType providedJsType = getJsType(metadata, type);
if (providedJsType == null) {
return false;
}
providedJsType = providedJsType.restrictByNotNullOrUndefined();
JSType jsType = node.getJSType();
return jsType != null && jsType.isEnumType() && providedJsType.isEquivalentTo(
jsType.toMaybeEnumType().getElementsType().getPrimitiveType());
}
};
} | java | public static Matcher enumDefinitionOfType(final String type) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
JSType providedJsType = getJsType(metadata, type);
if (providedJsType == null) {
return false;
}
providedJsType = providedJsType.restrictByNotNullOrUndefined();
JSType jsType = node.getJSType();
return jsType != null && jsType.isEnumType() && providedJsType.isEquivalentTo(
jsType.toMaybeEnumType().getElementsType().getPrimitiveType());
}
};
} | [
"public",
"static",
"Matcher",
"enumDefinitionOfType",
"(",
"final",
"String",
"type",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"JSType",
"providedJsType",
"=",
"getJsType",
"(",
"metadata",
",",
"type",
")",
";",
"if",
"(",
"providedJsType",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"providedJsType",
"=",
"providedJsType",
".",
"restrictByNotNullOrUndefined",
"(",
")",
";",
"JSType",
"jsType",
"=",
"node",
".",
"getJSType",
"(",
")",
";",
"return",
"jsType",
"!=",
"null",
"&&",
"jsType",
".",
"isEnumType",
"(",
")",
"&&",
"providedJsType",
".",
"isEquivalentTo",
"(",
"jsType",
".",
"toMaybeEnumType",
"(",
")",
".",
"getElementsType",
"(",
")",
".",
"getPrimitiveType",
"(",
")",
")",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches definitions of an enum of the given type. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"definitions",
"of",
"an",
"enum",
"of",
"the",
"given",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L286-L300 |
24,925 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.assignmentWithRhs | public static Matcher assignmentWithRhs(final Matcher rhsMatcher) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return node.isAssign() && rhsMatcher.matches(node.getLastChild(), metadata);
}
};
} | java | public static Matcher assignmentWithRhs(final Matcher rhsMatcher) {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
return node.isAssign() && rhsMatcher.matches(node.getLastChild(), metadata);
}
};
} | [
"public",
"static",
"Matcher",
"assignmentWithRhs",
"(",
"final",
"Matcher",
"rhsMatcher",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"return",
"node",
".",
"isAssign",
"(",
")",
"&&",
"rhsMatcher",
".",
"matches",
"(",
"node",
".",
"getLastChild",
"(",
")",
",",
"metadata",
")",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches an ASSIGN node where the RHS of the assignment matches the given
rhsMatcher. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"an",
"ASSIGN",
"node",
"where",
"the",
"RHS",
"of",
"the",
"assignment",
"matches",
"the",
"given",
"rhsMatcher",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L306-L312 |
24,926 | google/closure-compiler | src/com/google/javascript/refactoring/Matchers.java | Matchers.constructorPropertyDeclaration | public static Matcher constructorPropertyDeclaration() {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
// This will match against code that looks like:
// /** @constructor */
// function constructor() {
// this.variable = 3;
// }
if (!node.isAssign()
|| !node.getFirstChild().isGetProp()
|| !node.getFirstFirstChild().isThis()) {
return false;
}
while (node != null && !node.isFunction()) {
node = node.getParent();
}
if (node != null && node.isFunction()) {
JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(node);
if (jsDoc != null) {
return jsDoc.isConstructor();
}
}
return false;
}
};
} | java | public static Matcher constructorPropertyDeclaration() {
return new Matcher() {
@Override public boolean matches(Node node, NodeMetadata metadata) {
// This will match against code that looks like:
// /** @constructor */
// function constructor() {
// this.variable = 3;
// }
if (!node.isAssign()
|| !node.getFirstChild().isGetProp()
|| !node.getFirstFirstChild().isThis()) {
return false;
}
while (node != null && !node.isFunction()) {
node = node.getParent();
}
if (node != null && node.isFunction()) {
JSDocInfo jsDoc = NodeUtil.getBestJSDocInfo(node);
if (jsDoc != null) {
return jsDoc.isConstructor();
}
}
return false;
}
};
} | [
"public",
"static",
"Matcher",
"constructorPropertyDeclaration",
"(",
")",
"{",
"return",
"new",
"Matcher",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"matches",
"(",
"Node",
"node",
",",
"NodeMetadata",
"metadata",
")",
"{",
"// This will match against code that looks like:",
"// /** @constructor */",
"// function constructor() {",
"// this.variable = 3;",
"// }",
"if",
"(",
"!",
"node",
".",
"isAssign",
"(",
")",
"||",
"!",
"node",
".",
"getFirstChild",
"(",
")",
".",
"isGetProp",
"(",
")",
"||",
"!",
"node",
".",
"getFirstFirstChild",
"(",
")",
".",
"isThis",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"while",
"(",
"node",
"!=",
"null",
"&&",
"!",
"node",
".",
"isFunction",
"(",
")",
")",
"{",
"node",
"=",
"node",
".",
"getParent",
"(",
")",
";",
"}",
"if",
"(",
"node",
"!=",
"null",
"&&",
"node",
".",
"isFunction",
"(",
")",
")",
"{",
"JSDocInfo",
"jsDoc",
"=",
"NodeUtil",
".",
"getBestJSDocInfo",
"(",
"node",
")",
";",
"if",
"(",
"jsDoc",
"!=",
"null",
")",
"{",
"return",
"jsDoc",
".",
"isConstructor",
"(",
")",
";",
"}",
"}",
"return",
"false",
";",
"}",
"}",
";",
"}"
] | Returns a Matcher that matches against properties that are declared in the constructor. | [
"Returns",
"a",
"Matcher",
"that",
"matches",
"against",
"properties",
"that",
"are",
"declared",
"in",
"the",
"constructor",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/Matchers.java#L362-L387 |
24,927 | google/closure-compiler | src/com/google/javascript/jscomp/deps/ModuleLoader.java | ModuleLoader.createRootPaths | private static ImmutableList<String> createRootPaths(
Iterable<String> roots, PathResolver resolver, PathEscaper escaper) {
// Sort longest length to shortest so that paths are applied most specific to least.
Set<String> builder =
new TreeSet<>(
Comparator.comparingInt(String::length).thenComparing(String::compareTo).reversed());
for (String root : roots) {
String rootModuleName = escaper.escape(resolver.apply(root));
if (isAmbiguousIdentifier(rootModuleName)) {
rootModuleName = MODULE_SLASH + rootModuleName;
}
builder.add(rootModuleName);
}
return ImmutableList.copyOf(builder);
} | java | private static ImmutableList<String> createRootPaths(
Iterable<String> roots, PathResolver resolver, PathEscaper escaper) {
// Sort longest length to shortest so that paths are applied most specific to least.
Set<String> builder =
new TreeSet<>(
Comparator.comparingInt(String::length).thenComparing(String::compareTo).reversed());
for (String root : roots) {
String rootModuleName = escaper.escape(resolver.apply(root));
if (isAmbiguousIdentifier(rootModuleName)) {
rootModuleName = MODULE_SLASH + rootModuleName;
}
builder.add(rootModuleName);
}
return ImmutableList.copyOf(builder);
} | [
"private",
"static",
"ImmutableList",
"<",
"String",
">",
"createRootPaths",
"(",
"Iterable",
"<",
"String",
">",
"roots",
",",
"PathResolver",
"resolver",
",",
"PathEscaper",
"escaper",
")",
"{",
"// Sort longest length to shortest so that paths are applied most specific to least.",
"Set",
"<",
"String",
">",
"builder",
"=",
"new",
"TreeSet",
"<>",
"(",
"Comparator",
".",
"comparingInt",
"(",
"String",
"::",
"length",
")",
".",
"thenComparing",
"(",
"String",
"::",
"compareTo",
")",
".",
"reversed",
"(",
")",
")",
";",
"for",
"(",
"String",
"root",
":",
"roots",
")",
"{",
"String",
"rootModuleName",
"=",
"escaper",
".",
"escape",
"(",
"resolver",
".",
"apply",
"(",
"root",
")",
")",
";",
"if",
"(",
"isAmbiguousIdentifier",
"(",
"rootModuleName",
")",
")",
"{",
"rootModuleName",
"=",
"MODULE_SLASH",
"+",
"rootModuleName",
";",
"}",
"builder",
".",
"add",
"(",
"rootModuleName",
")",
";",
"}",
"return",
"ImmutableList",
".",
"copyOf",
"(",
"builder",
")",
";",
"}"
] | Normalizes the given root paths, which are path prefixes to be removed from a module path when
resolved. | [
"Normalizes",
"the",
"given",
"root",
"paths",
"which",
"are",
"path",
"prefixes",
"to",
"be",
"removed",
"from",
"a",
"module",
"path",
"when",
"resolved",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/ModuleLoader.java#L240-L254 |
24,928 | google/closure-compiler | src/com/google/javascript/jscomp/deps/ModuleLoader.java | ModuleLoader.normalize | static String normalize(String path, Iterable<String> moduleRootPaths) {
String normalizedPath = path;
if (isAmbiguousIdentifier(normalizedPath)) {
normalizedPath = MODULE_SLASH + normalizedPath;
}
// Find a moduleRoot that this URI is under. If none, use as is.
for (String moduleRoot : moduleRootPaths) {
if (normalizedPath.startsWith(moduleRoot)) {
// Make sure that e.g. path "foobar/test.js" is not matched by module "foo", by checking for
// a leading slash.
String trailing = normalizedPath.substring(moduleRoot.length());
if (trailing.startsWith(MODULE_SLASH)) {
return trailing.substring(MODULE_SLASH.length());
}
}
}
// Not underneath any of the roots.
return path;
} | java | static String normalize(String path, Iterable<String> moduleRootPaths) {
String normalizedPath = path;
if (isAmbiguousIdentifier(normalizedPath)) {
normalizedPath = MODULE_SLASH + normalizedPath;
}
// Find a moduleRoot that this URI is under. If none, use as is.
for (String moduleRoot : moduleRootPaths) {
if (normalizedPath.startsWith(moduleRoot)) {
// Make sure that e.g. path "foobar/test.js" is not matched by module "foo", by checking for
// a leading slash.
String trailing = normalizedPath.substring(moduleRoot.length());
if (trailing.startsWith(MODULE_SLASH)) {
return trailing.substring(MODULE_SLASH.length());
}
}
}
// Not underneath any of the roots.
return path;
} | [
"static",
"String",
"normalize",
"(",
"String",
"path",
",",
"Iterable",
"<",
"String",
">",
"moduleRootPaths",
")",
"{",
"String",
"normalizedPath",
"=",
"path",
";",
"if",
"(",
"isAmbiguousIdentifier",
"(",
"normalizedPath",
")",
")",
"{",
"normalizedPath",
"=",
"MODULE_SLASH",
"+",
"normalizedPath",
";",
"}",
"// Find a moduleRoot that this URI is under. If none, use as is.",
"for",
"(",
"String",
"moduleRoot",
":",
"moduleRootPaths",
")",
"{",
"if",
"(",
"normalizedPath",
".",
"startsWith",
"(",
"moduleRoot",
")",
")",
"{",
"// Make sure that e.g. path \"foobar/test.js\" is not matched by module \"foo\", by checking for",
"// a leading slash.",
"String",
"trailing",
"=",
"normalizedPath",
".",
"substring",
"(",
"moduleRoot",
".",
"length",
"(",
")",
")",
";",
"if",
"(",
"trailing",
".",
"startsWith",
"(",
"MODULE_SLASH",
")",
")",
"{",
"return",
"trailing",
".",
"substring",
"(",
"MODULE_SLASH",
".",
"length",
"(",
")",
")",
";",
"}",
"}",
"}",
"// Not underneath any of the roots.",
"return",
"path",
";",
"}"
] | Normalizes the name and resolves it against the module roots. | [
"Normalizes",
"the",
"name",
"and",
"resolves",
"it",
"against",
"the",
"module",
"roots",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/ModuleLoader.java#L282-L301 |
24,929 | google/closure-compiler | src/com/google/javascript/jscomp/graph/FixedPointGraphTraversal.java | FixedPointGraphTraversal.newTraversal | public static <NODE, EDGE> FixedPointGraphTraversal<NODE, EDGE> newTraversal(
EdgeCallback<NODE, EDGE> callback) {
return new FixedPointGraphTraversal<>(callback);
} | java | public static <NODE, EDGE> FixedPointGraphTraversal<NODE, EDGE> newTraversal(
EdgeCallback<NODE, EDGE> callback) {
return new FixedPointGraphTraversal<>(callback);
} | [
"public",
"static",
"<",
"NODE",
",",
"EDGE",
">",
"FixedPointGraphTraversal",
"<",
"NODE",
",",
"EDGE",
">",
"newTraversal",
"(",
"EdgeCallback",
"<",
"NODE",
",",
"EDGE",
">",
"callback",
")",
"{",
"return",
"new",
"FixedPointGraphTraversal",
"<>",
"(",
"callback",
")",
";",
"}"
] | Helper method for creating new traversals. | [
"Helper",
"method",
"for",
"creating",
"new",
"traversals",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/graph/FixedPointGraphTraversal.java#L58-L61 |
24,930 | google/closure-compiler | src/com/google/javascript/jscomp/graph/FixedPointGraphTraversal.java | FixedPointGraphTraversal.computeFixedPoint | public void computeFixedPoint(DiGraph<N, E> graph) {
Set<N> nodes = new LinkedHashSet<>();
for (DiGraphNode<N, E> node : graph.getDirectedGraphNodes()) {
nodes.add(node.getValue());
}
computeFixedPoint(graph, nodes);
} | java | public void computeFixedPoint(DiGraph<N, E> graph) {
Set<N> nodes = new LinkedHashSet<>();
for (DiGraphNode<N, E> node : graph.getDirectedGraphNodes()) {
nodes.add(node.getValue());
}
computeFixedPoint(graph, nodes);
} | [
"public",
"void",
"computeFixedPoint",
"(",
"DiGraph",
"<",
"N",
",",
"E",
">",
"graph",
")",
"{",
"Set",
"<",
"N",
">",
"nodes",
"=",
"new",
"LinkedHashSet",
"<>",
"(",
")",
";",
"for",
"(",
"DiGraphNode",
"<",
"N",
",",
"E",
">",
"node",
":",
"graph",
".",
"getDirectedGraphNodes",
"(",
")",
")",
"{",
"nodes",
".",
"add",
"(",
"node",
".",
"getValue",
"(",
")",
")",
";",
"}",
"computeFixedPoint",
"(",
"graph",
",",
"nodes",
")",
";",
"}"
] | Compute a fixed point for the given graph.
@param graph The graph to traverse. | [
"Compute",
"a",
"fixed",
"point",
"for",
"the",
"given",
"graph",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/graph/FixedPointGraphTraversal.java#L67-L73 |
24,931 | google/closure-compiler | src/com/google/javascript/jscomp/graph/FixedPointGraphTraversal.java | FixedPointGraphTraversal.computeFixedPoint | public void computeFixedPoint(DiGraph<N, E> graph, N entry) {
Set<N> entrySet = new LinkedHashSet<>();
entrySet.add(entry);
computeFixedPoint(graph, entrySet);
} | java | public void computeFixedPoint(DiGraph<N, E> graph, N entry) {
Set<N> entrySet = new LinkedHashSet<>();
entrySet.add(entry);
computeFixedPoint(graph, entrySet);
} | [
"public",
"void",
"computeFixedPoint",
"(",
"DiGraph",
"<",
"N",
",",
"E",
">",
"graph",
",",
"N",
"entry",
")",
"{",
"Set",
"<",
"N",
">",
"entrySet",
"=",
"new",
"LinkedHashSet",
"<>",
"(",
")",
";",
"entrySet",
".",
"add",
"(",
"entry",
")",
";",
"computeFixedPoint",
"(",
"graph",
",",
"entrySet",
")",
";",
"}"
] | Compute a fixed point for the given graph, entering from the given node.
@param graph The graph to traverse.
@param entry The node to begin traversing from. | [
"Compute",
"a",
"fixed",
"point",
"for",
"the",
"given",
"graph",
"entering",
"from",
"the",
"given",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/graph/FixedPointGraphTraversal.java#L80-L84 |
24,932 | google/closure-compiler | src/com/google/javascript/jscomp/graph/FixedPointGraphTraversal.java | FixedPointGraphTraversal.computeFixedPoint | public void computeFixedPoint(DiGraph<N, E> graph, Set<N> entrySet) {
int cycleCount = 0;
long nodeCount = graph.getNodeCount();
// Choose a bail-out heuristically in case the computation
// doesn't converge.
long maxIterations = Math.max(nodeCount * nodeCount * nodeCount, 100);
// Use a LinkedHashSet, so that the traversal is deterministic.
LinkedHashSet<DiGraphNode<N, E>> workSet = new LinkedHashSet<>();
for (N n : entrySet) {
workSet.add(graph.getDirectedGraphNode(n));
}
for (; !workSet.isEmpty() && cycleCount < maxIterations; cycleCount++) {
// For every out edge in the workSet, traverse that edge. If that
// edge updates the state of the graph, then add the destination
// node to the resultSet, so that we can update all of its out edges
// on the next iteration.
DiGraphNode<N, E> source = workSet.iterator().next();
N sourceValue = source.getValue();
workSet.remove(source);
List<DiGraphEdge<N, E>> outEdges = source.getOutEdges();
for (DiGraphEdge<N, E> edge : outEdges) {
N destNode = edge.getDestination().getValue();
if (callback.traverseEdge(sourceValue, edge.getValue(), destNode)) {
workSet.add(edge.getDestination());
}
}
}
checkState(cycleCount != maxIterations, NON_HALTING_ERROR_MSG);
} | java | public void computeFixedPoint(DiGraph<N, E> graph, Set<N> entrySet) {
int cycleCount = 0;
long nodeCount = graph.getNodeCount();
// Choose a bail-out heuristically in case the computation
// doesn't converge.
long maxIterations = Math.max(nodeCount * nodeCount * nodeCount, 100);
// Use a LinkedHashSet, so that the traversal is deterministic.
LinkedHashSet<DiGraphNode<N, E>> workSet = new LinkedHashSet<>();
for (N n : entrySet) {
workSet.add(graph.getDirectedGraphNode(n));
}
for (; !workSet.isEmpty() && cycleCount < maxIterations; cycleCount++) {
// For every out edge in the workSet, traverse that edge. If that
// edge updates the state of the graph, then add the destination
// node to the resultSet, so that we can update all of its out edges
// on the next iteration.
DiGraphNode<N, E> source = workSet.iterator().next();
N sourceValue = source.getValue();
workSet.remove(source);
List<DiGraphEdge<N, E>> outEdges = source.getOutEdges();
for (DiGraphEdge<N, E> edge : outEdges) {
N destNode = edge.getDestination().getValue();
if (callback.traverseEdge(sourceValue, edge.getValue(), destNode)) {
workSet.add(edge.getDestination());
}
}
}
checkState(cycleCount != maxIterations, NON_HALTING_ERROR_MSG);
} | [
"public",
"void",
"computeFixedPoint",
"(",
"DiGraph",
"<",
"N",
",",
"E",
">",
"graph",
",",
"Set",
"<",
"N",
">",
"entrySet",
")",
"{",
"int",
"cycleCount",
"=",
"0",
";",
"long",
"nodeCount",
"=",
"graph",
".",
"getNodeCount",
"(",
")",
";",
"// Choose a bail-out heuristically in case the computation",
"// doesn't converge.",
"long",
"maxIterations",
"=",
"Math",
".",
"max",
"(",
"nodeCount",
"*",
"nodeCount",
"*",
"nodeCount",
",",
"100",
")",
";",
"// Use a LinkedHashSet, so that the traversal is deterministic.",
"LinkedHashSet",
"<",
"DiGraphNode",
"<",
"N",
",",
"E",
">",
">",
"workSet",
"=",
"new",
"LinkedHashSet",
"<>",
"(",
")",
";",
"for",
"(",
"N",
"n",
":",
"entrySet",
")",
"{",
"workSet",
".",
"add",
"(",
"graph",
".",
"getDirectedGraphNode",
"(",
"n",
")",
")",
";",
"}",
"for",
"(",
";",
"!",
"workSet",
".",
"isEmpty",
"(",
")",
"&&",
"cycleCount",
"<",
"maxIterations",
";",
"cycleCount",
"++",
")",
"{",
"// For every out edge in the workSet, traverse that edge. If that",
"// edge updates the state of the graph, then add the destination",
"// node to the resultSet, so that we can update all of its out edges",
"// on the next iteration.",
"DiGraphNode",
"<",
"N",
",",
"E",
">",
"source",
"=",
"workSet",
".",
"iterator",
"(",
")",
".",
"next",
"(",
")",
";",
"N",
"sourceValue",
"=",
"source",
".",
"getValue",
"(",
")",
";",
"workSet",
".",
"remove",
"(",
"source",
")",
";",
"List",
"<",
"DiGraphEdge",
"<",
"N",
",",
"E",
">",
">",
"outEdges",
"=",
"source",
".",
"getOutEdges",
"(",
")",
";",
"for",
"(",
"DiGraphEdge",
"<",
"N",
",",
"E",
">",
"edge",
":",
"outEdges",
")",
"{",
"N",
"destNode",
"=",
"edge",
".",
"getDestination",
"(",
")",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"callback",
".",
"traverseEdge",
"(",
"sourceValue",
",",
"edge",
".",
"getValue",
"(",
")",
",",
"destNode",
")",
")",
"{",
"workSet",
".",
"add",
"(",
"edge",
".",
"getDestination",
"(",
")",
")",
";",
"}",
"}",
"}",
"checkState",
"(",
"cycleCount",
"!=",
"maxIterations",
",",
"NON_HALTING_ERROR_MSG",
")",
";",
"}"
] | Compute a fixed point for the given graph, entering from the given nodes.
@param graph The graph to traverse.
@param entrySet The nodes to begin traversing from. | [
"Compute",
"a",
"fixed",
"point",
"for",
"the",
"given",
"graph",
"entering",
"from",
"the",
"given",
"nodes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/graph/FixedPointGraphTraversal.java#L91-L124 |
24,933 | google/closure-compiler | src/com/google/javascript/jscomp/MinimizeExitPoints.java | MinimizeExitPoints.moveAllFollowing | private static void moveAllFollowing(
Node start, Node srcParent, Node destParent) {
for (Node n = start.getNext(); n != null; n = start.getNext()) {
boolean isFunctionDeclaration = NodeUtil.isFunctionDeclaration(n);
srcParent.removeChild(n);
if (isFunctionDeclaration) {
destParent.addChildToFront(n);
} else {
destParent.addChildToBack(n);
}
}
} | java | private static void moveAllFollowing(
Node start, Node srcParent, Node destParent) {
for (Node n = start.getNext(); n != null; n = start.getNext()) {
boolean isFunctionDeclaration = NodeUtil.isFunctionDeclaration(n);
srcParent.removeChild(n);
if (isFunctionDeclaration) {
destParent.addChildToFront(n);
} else {
destParent.addChildToBack(n);
}
}
} | [
"private",
"static",
"void",
"moveAllFollowing",
"(",
"Node",
"start",
",",
"Node",
"srcParent",
",",
"Node",
"destParent",
")",
"{",
"for",
"(",
"Node",
"n",
"=",
"start",
".",
"getNext",
"(",
")",
";",
"n",
"!=",
"null",
";",
"n",
"=",
"start",
".",
"getNext",
"(",
")",
")",
"{",
"boolean",
"isFunctionDeclaration",
"=",
"NodeUtil",
".",
"isFunctionDeclaration",
"(",
"n",
")",
";",
"srcParent",
".",
"removeChild",
"(",
"n",
")",
";",
"if",
"(",
"isFunctionDeclaration",
")",
"{",
"destParent",
".",
"addChildToFront",
"(",
"n",
")",
";",
"}",
"else",
"{",
"destParent",
".",
"addChildToBack",
"(",
"n",
")",
";",
"}",
"}",
"}"
] | Move all the child nodes following start in srcParent to the end of
destParent's child list.
@param start The start point in the srcParent child list.
@param srcParent The parent node of start.
@param destParent The destination node. | [
"Move",
"all",
"the",
"child",
"nodes",
"following",
"start",
"in",
"srcParent",
"to",
"the",
"end",
"of",
"destParent",
"s",
"child",
"list",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/MinimizeExitPoints.java#L345-L356 |
24,934 | google/closure-compiler | src/com/google/javascript/jscomp/MinimizeExitPoints.java | MinimizeExitPoints.hasBlockScopedVarsFollowing | private static boolean hasBlockScopedVarsFollowing(Node start) {
for (Node n = start.getNext(); n != null; n = n.getNext()) {
if (n.isLet() || n.isConst()) {
return true;
}
}
return false;
} | java | private static boolean hasBlockScopedVarsFollowing(Node start) {
for (Node n = start.getNext(); n != null; n = n.getNext()) {
if (n.isLet() || n.isConst()) {
return true;
}
}
return false;
} | [
"private",
"static",
"boolean",
"hasBlockScopedVarsFollowing",
"(",
"Node",
"start",
")",
"{",
"for",
"(",
"Node",
"n",
"=",
"start",
".",
"getNext",
"(",
")",
";",
"n",
"!=",
"null",
";",
"n",
"=",
"n",
".",
"getNext",
"(",
")",
")",
"{",
"if",
"(",
"n",
".",
"isLet",
"(",
")",
"||",
"n",
".",
"isConst",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Detect any block-scoped declarations that are younger siblings of the given starting point.
@param start The start point | [
"Detect",
"any",
"block",
"-",
"scoped",
"declarations",
"that",
"are",
"younger",
"siblings",
"of",
"the",
"given",
"starting",
"point",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/MinimizeExitPoints.java#L385-L392 |
24,935 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.traverse | public void traverse(Node root) {
try {
initTraversal(root);
curNode = root;
pushScope(root);
// null parent ensures that the shallow callbacks will traverse root
traverseBranch(root, null);
popScope();
} catch (Error | Exception unexpectedException) {
throwUnexpectedException(unexpectedException);
}
} | java | public void traverse(Node root) {
try {
initTraversal(root);
curNode = root;
pushScope(root);
// null parent ensures that the shallow callbacks will traverse root
traverseBranch(root, null);
popScope();
} catch (Error | Exception unexpectedException) {
throwUnexpectedException(unexpectedException);
}
} | [
"public",
"void",
"traverse",
"(",
"Node",
"root",
")",
"{",
"try",
"{",
"initTraversal",
"(",
"root",
")",
";",
"curNode",
"=",
"root",
";",
"pushScope",
"(",
"root",
")",
";",
"// null parent ensures that the shallow callbacks will traverse root",
"traverseBranch",
"(",
"root",
",",
"null",
")",
";",
"popScope",
"(",
")",
";",
"}",
"catch",
"(",
"Error",
"|",
"Exception",
"unexpectedException",
")",
"{",
"throwUnexpectedException",
"(",
"unexpectedException",
")",
";",
"}",
"}"
] | Traverses a parse tree recursively. | [
"Traverses",
"a",
"parse",
"tree",
"recursively",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L365-L376 |
24,936 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.traverse | public static void traverse(AbstractCompiler compiler, Node root, Callback cb) {
NodeTraversal t = new NodeTraversal(compiler, cb, new Es6SyntacticScopeCreator(compiler));
t.traverse(root);
} | java | public static void traverse(AbstractCompiler compiler, Node root, Callback cb) {
NodeTraversal t = new NodeTraversal(compiler, cb, new Es6SyntacticScopeCreator(compiler));
t.traverse(root);
} | [
"public",
"static",
"void",
"traverse",
"(",
"AbstractCompiler",
"compiler",
",",
"Node",
"root",
",",
"Callback",
"cb",
")",
"{",
"NodeTraversal",
"t",
"=",
"new",
"NodeTraversal",
"(",
"compiler",
",",
"cb",
",",
"new",
"Es6SyntacticScopeCreator",
"(",
"compiler",
")",
")",
";",
"t",
".",
"traverse",
"(",
"root",
")",
";",
"}"
] | Traverses using the ES6SyntacticScopeCreator | [
"Traverses",
"using",
"the",
"ES6SyntacticScopeCreator"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L379-L382 |
24,937 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.traversePostOrder | public static void traversePostOrder(
AbstractCompiler compiler, Node root, AbstractPostOrderCallbackInterface cb) {
traverse(compiler, root, makePostOrderCallback(cb));
} | java | public static void traversePostOrder(
AbstractCompiler compiler, Node root, AbstractPostOrderCallbackInterface cb) {
traverse(compiler, root, makePostOrderCallback(cb));
} | [
"public",
"static",
"void",
"traversePostOrder",
"(",
"AbstractCompiler",
"compiler",
",",
"Node",
"root",
",",
"AbstractPostOrderCallbackInterface",
"cb",
")",
"{",
"traverse",
"(",
"compiler",
",",
"root",
",",
"makePostOrderCallback",
"(",
"cb",
")",
")",
";",
"}"
] | Traverses in post order. | [
"Traverses",
"in",
"post",
"order",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L385-L388 |
24,938 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.traverseFunctionOutOfBand | public void traverseFunctionOutOfBand(Node node, AbstractScope<?, ?> scope) {
checkNotNull(scope);
checkState(node.isFunction(), node);
checkNotNull(scope.getRootNode());
initTraversal(node);
curNode = node.getParent();
pushScope(scope, true /* quietly */);
traverseBranch(node, curNode);
popScope(true /* quietly */);
} | java | public void traverseFunctionOutOfBand(Node node, AbstractScope<?, ?> scope) {
checkNotNull(scope);
checkState(node.isFunction(), node);
checkNotNull(scope.getRootNode());
initTraversal(node);
curNode = node.getParent();
pushScope(scope, true /* quietly */);
traverseBranch(node, curNode);
popScope(true /* quietly */);
} | [
"public",
"void",
"traverseFunctionOutOfBand",
"(",
"Node",
"node",
",",
"AbstractScope",
"<",
"?",
",",
"?",
">",
"scope",
")",
"{",
"checkNotNull",
"(",
"scope",
")",
";",
"checkState",
"(",
"node",
".",
"isFunction",
"(",
")",
",",
"node",
")",
";",
"checkNotNull",
"(",
"scope",
".",
"getRootNode",
"(",
")",
")",
";",
"initTraversal",
"(",
"node",
")",
";",
"curNode",
"=",
"node",
".",
"getParent",
"(",
")",
";",
"pushScope",
"(",
"scope",
",",
"true",
"/* quietly */",
")",
";",
"traverseBranch",
"(",
"node",
",",
"curNode",
")",
";",
"popScope",
"(",
"true",
"/* quietly */",
")",
";",
"}"
] | Traverse a function out-of-band of normal traversal.
@param node The function node.
@param scope The scope the function is contained in. Does not fire enter/exit
callback events for this scope. | [
"Traverse",
"a",
"function",
"out",
"-",
"of",
"-",
"band",
"of",
"normal",
"traversal",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L661-L670 |
24,939 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.getLineNumber | public int getLineNumber() {
Node cur = curNode;
while (cur != null) {
int line = cur.getLineno();
if (line >= 0) {
return line;
}
cur = cur.getParent();
}
return 0;
} | java | public int getLineNumber() {
Node cur = curNode;
while (cur != null) {
int line = cur.getLineno();
if (line >= 0) {
return line;
}
cur = cur.getParent();
}
return 0;
} | [
"public",
"int",
"getLineNumber",
"(",
")",
"{",
"Node",
"cur",
"=",
"curNode",
";",
"while",
"(",
"cur",
"!=",
"null",
")",
"{",
"int",
"line",
"=",
"cur",
".",
"getLineno",
"(",
")",
";",
"if",
"(",
"line",
">=",
"0",
")",
"{",
"return",
"line",
";",
"}",
"cur",
"=",
"cur",
".",
"getParent",
"(",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Gets the current line number, or zero if it cannot be determined. The line
number is retrieved lazily as a running time optimization. | [
"Gets",
"the",
"current",
"line",
"number",
"or",
"zero",
"if",
"it",
"cannot",
"be",
"determined",
".",
"The",
"line",
"number",
"is",
"retrieved",
"lazily",
"as",
"a",
"running",
"time",
"optimization",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L703-L713 |
24,940 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.getCharno | public int getCharno() {
Node cur = curNode;
while (cur != null) {
int line = cur.getCharno();
if (line >= 0) {
return line;
}
cur = cur.getParent();
}
return 0;
} | java | public int getCharno() {
Node cur = curNode;
while (cur != null) {
int line = cur.getCharno();
if (line >= 0) {
return line;
}
cur = cur.getParent();
}
return 0;
} | [
"public",
"int",
"getCharno",
"(",
")",
"{",
"Node",
"cur",
"=",
"curNode",
";",
"while",
"(",
"cur",
"!=",
"null",
")",
"{",
"int",
"line",
"=",
"cur",
".",
"getCharno",
"(",
")",
";",
"if",
"(",
"line",
">=",
"0",
")",
"{",
"return",
"line",
";",
"}",
"cur",
"=",
"cur",
".",
"getParent",
"(",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Gets the current char number, or zero if it cannot be determined. The line
number is retrieved lazily as a running time optimization. | [
"Gets",
"the",
"current",
"char",
"number",
"or",
"zero",
"if",
"it",
"cannot",
"be",
"determined",
".",
"The",
"line",
"number",
"is",
"retrieved",
"lazily",
"as",
"a",
"running",
"time",
"optimization",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L719-L729 |
24,941 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.getInput | public CompilerInput getInput() {
if (compilerInput == null && inputId != null) {
compilerInput = compiler.getInput(inputId);
}
return compilerInput;
} | java | public CompilerInput getInput() {
if (compilerInput == null && inputId != null) {
compilerInput = compiler.getInput(inputId);
}
return compilerInput;
} | [
"public",
"CompilerInput",
"getInput",
"(",
")",
"{",
"if",
"(",
"compilerInput",
"==",
"null",
"&&",
"inputId",
"!=",
"null",
")",
"{",
"compilerInput",
"=",
"compiler",
".",
"getInput",
"(",
"inputId",
")",
";",
"}",
"return",
"compilerInput",
";",
"}"
] | Gets the current input source. | [
"Gets",
"the",
"current",
"input",
"source",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L743-L748 |
24,942 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.getModule | public JSModule getModule() {
CompilerInput input = getInput();
return input == null ? null : input.getModule();
} | java | public JSModule getModule() {
CompilerInput input = getInput();
return input == null ? null : input.getModule();
} | [
"public",
"JSModule",
"getModule",
"(",
")",
"{",
"CompilerInput",
"input",
"=",
"getInput",
"(",
")",
";",
"return",
"input",
"==",
"null",
"?",
"null",
":",
"input",
".",
"getModule",
"(",
")",
";",
"}"
] | Gets the current input module. | [
"Gets",
"the",
"current",
"input",
"module",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L753-L756 |
24,943 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.handleModule | private void handleModule(Node n, Node parent) {
pushScope(n);
curNode = n;
if (callback.shouldTraverse(this, n, parent)) {
curNode = n;
traverseChildren(n);
callback.visit(this, n, parent);
}
popScope();
} | java | private void handleModule(Node n, Node parent) {
pushScope(n);
curNode = n;
if (callback.shouldTraverse(this, n, parent)) {
curNode = n;
traverseChildren(n);
callback.visit(this, n, parent);
}
popScope();
} | [
"private",
"void",
"handleModule",
"(",
"Node",
"n",
",",
"Node",
"parent",
")",
"{",
"pushScope",
"(",
"n",
")",
";",
"curNode",
"=",
"n",
";",
"if",
"(",
"callback",
".",
"shouldTraverse",
"(",
"this",
",",
"n",
",",
"parent",
")",
")",
"{",
"curNode",
"=",
"n",
";",
"traverseChildren",
"(",
"n",
")",
";",
"callback",
".",
"visit",
"(",
"this",
",",
"n",
",",
"parent",
")",
";",
"}",
"popScope",
"(",
")",
";",
"}"
] | Traverses a module. | [
"Traverses",
"a",
"module",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L824-L833 |
24,944 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.traverseBranch | private void traverseBranch(Node n, Node parent) {
switch (n.getToken()) {
case SCRIPT:
handleScript(n, parent);
return;
case FUNCTION:
handleFunction(n, parent);
return;
case MODULE_BODY:
handleModule(n, parent);
return;
default:
break;
}
curNode = n;
if (!callback.shouldTraverse(this, n, parent)) {
return;
}
Token type = n.getToken();
if (type == Token.CLASS) {
traverseClass(n);
} else if (type == Token.CLASS_MEMBERS) {
traverseClassMembers(n);
} else if (useBlockScope && NodeUtil.createsBlockScope(n)) {
traverseBlockScope(n);
} else {
traverseChildren(n);
}
curNode = n;
callback.visit(this, n, parent);
} | java | private void traverseBranch(Node n, Node parent) {
switch (n.getToken()) {
case SCRIPT:
handleScript(n, parent);
return;
case FUNCTION:
handleFunction(n, parent);
return;
case MODULE_BODY:
handleModule(n, parent);
return;
default:
break;
}
curNode = n;
if (!callback.shouldTraverse(this, n, parent)) {
return;
}
Token type = n.getToken();
if (type == Token.CLASS) {
traverseClass(n);
} else if (type == Token.CLASS_MEMBERS) {
traverseClassMembers(n);
} else if (useBlockScope && NodeUtil.createsBlockScope(n)) {
traverseBlockScope(n);
} else {
traverseChildren(n);
}
curNode = n;
callback.visit(this, n, parent);
} | [
"private",
"void",
"traverseBranch",
"(",
"Node",
"n",
",",
"Node",
"parent",
")",
"{",
"switch",
"(",
"n",
".",
"getToken",
"(",
")",
")",
"{",
"case",
"SCRIPT",
":",
"handleScript",
"(",
"n",
",",
"parent",
")",
";",
"return",
";",
"case",
"FUNCTION",
":",
"handleFunction",
"(",
"n",
",",
"parent",
")",
";",
"return",
";",
"case",
"MODULE_BODY",
":",
"handleModule",
"(",
"n",
",",
"parent",
")",
";",
"return",
";",
"default",
":",
"break",
";",
"}",
"curNode",
"=",
"n",
";",
"if",
"(",
"!",
"callback",
".",
"shouldTraverse",
"(",
"this",
",",
"n",
",",
"parent",
")",
")",
"{",
"return",
";",
"}",
"Token",
"type",
"=",
"n",
".",
"getToken",
"(",
")",
";",
"if",
"(",
"type",
"==",
"Token",
".",
"CLASS",
")",
"{",
"traverseClass",
"(",
"n",
")",
";",
"}",
"else",
"if",
"(",
"type",
"==",
"Token",
".",
"CLASS_MEMBERS",
")",
"{",
"traverseClassMembers",
"(",
"n",
")",
";",
"}",
"else",
"if",
"(",
"useBlockScope",
"&&",
"NodeUtil",
".",
"createsBlockScope",
"(",
"n",
")",
")",
"{",
"traverseBlockScope",
"(",
"n",
")",
";",
"}",
"else",
"{",
"traverseChildren",
"(",
"n",
")",
";",
"}",
"curNode",
"=",
"n",
";",
"callback",
".",
"visit",
"(",
"this",
",",
"n",
",",
"parent",
")",
";",
"}"
] | Traverses a branch. | [
"Traverses",
"a",
"branch",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L836-L868 |
24,945 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.traverseFunction | private void traverseFunction(Node n, Node parent) {
final Node fnName = n.getFirstChild();
// NOTE: If a function declaration is the root of a traversal, then we will treat it as a
// function expression (since 'parent' is null, even though 'n' actually has a parent node) and
// traverse the function name before entering the scope, rather than afterwards. Removing the
// null check for 'parent' seems safe, but causes a rare crash when traverseScopeRoots is called
// by PeepholeOptimizationsPass on a function that somehow doesn't actually have a parent at all
// (presumably because it's already been removed from the AST?) so that doesn't actually work.
// This does not actually change anything, though, since rooting a traversal at a function node
// causes the function scope to be entered twice (unless using #traverseAtScope, which doesn't
// call this method), so that the name node is just always traversed inside the scope anyway.
boolean isFunctionDeclaration = parent != null && NodeUtil.isFunctionDeclaration(n);
if (isFunctionDeclaration) {
// Function declarations are in the scope containing the declaration.
traverseBranch(fnName, n);
}
curNode = n;
pushScope(n);
if (!isFunctionDeclaration) {
// Function expression names are only accessible within the function
// scope.
traverseBranch(fnName, n);
}
final Node args = fnName.getNext();
final Node body = args.getNext();
// Args
traverseBranch(args, n);
// Body
// ES6 "arrow" function may not have a block as a body.
traverseBranch(body, n);
popScope();
} | java | private void traverseFunction(Node n, Node parent) {
final Node fnName = n.getFirstChild();
// NOTE: If a function declaration is the root of a traversal, then we will treat it as a
// function expression (since 'parent' is null, even though 'n' actually has a parent node) and
// traverse the function name before entering the scope, rather than afterwards. Removing the
// null check for 'parent' seems safe, but causes a rare crash when traverseScopeRoots is called
// by PeepholeOptimizationsPass on a function that somehow doesn't actually have a parent at all
// (presumably because it's already been removed from the AST?) so that doesn't actually work.
// This does not actually change anything, though, since rooting a traversal at a function node
// causes the function scope to be entered twice (unless using #traverseAtScope, which doesn't
// call this method), so that the name node is just always traversed inside the scope anyway.
boolean isFunctionDeclaration = parent != null && NodeUtil.isFunctionDeclaration(n);
if (isFunctionDeclaration) {
// Function declarations are in the scope containing the declaration.
traverseBranch(fnName, n);
}
curNode = n;
pushScope(n);
if (!isFunctionDeclaration) {
// Function expression names are only accessible within the function
// scope.
traverseBranch(fnName, n);
}
final Node args = fnName.getNext();
final Node body = args.getNext();
// Args
traverseBranch(args, n);
// Body
// ES6 "arrow" function may not have a block as a body.
traverseBranch(body, n);
popScope();
} | [
"private",
"void",
"traverseFunction",
"(",
"Node",
"n",
",",
"Node",
"parent",
")",
"{",
"final",
"Node",
"fnName",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"// NOTE: If a function declaration is the root of a traversal, then we will treat it as a",
"// function expression (since 'parent' is null, even though 'n' actually has a parent node) and",
"// traverse the function name before entering the scope, rather than afterwards. Removing the",
"// null check for 'parent' seems safe, but causes a rare crash when traverseScopeRoots is called",
"// by PeepholeOptimizationsPass on a function that somehow doesn't actually have a parent at all",
"// (presumably because it's already been removed from the AST?) so that doesn't actually work.",
"// This does not actually change anything, though, since rooting a traversal at a function node",
"// causes the function scope to be entered twice (unless using #traverseAtScope, which doesn't",
"// call this method), so that the name node is just always traversed inside the scope anyway.",
"boolean",
"isFunctionDeclaration",
"=",
"parent",
"!=",
"null",
"&&",
"NodeUtil",
".",
"isFunctionDeclaration",
"(",
"n",
")",
";",
"if",
"(",
"isFunctionDeclaration",
")",
"{",
"// Function declarations are in the scope containing the declaration.",
"traverseBranch",
"(",
"fnName",
",",
"n",
")",
";",
"}",
"curNode",
"=",
"n",
";",
"pushScope",
"(",
"n",
")",
";",
"if",
"(",
"!",
"isFunctionDeclaration",
")",
"{",
"// Function expression names are only accessible within the function",
"// scope.",
"traverseBranch",
"(",
"fnName",
",",
"n",
")",
";",
"}",
"final",
"Node",
"args",
"=",
"fnName",
".",
"getNext",
"(",
")",
";",
"final",
"Node",
"body",
"=",
"args",
".",
"getNext",
"(",
")",
";",
"// Args",
"traverseBranch",
"(",
"args",
",",
"n",
")",
";",
"// Body",
"// ES6 \"arrow\" function may not have a block as a body.",
"traverseBranch",
"(",
"body",
",",
"n",
")",
";",
"popScope",
"(",
")",
";",
"}"
] | Traverses a function. | [
"Traverses",
"a",
"function",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L871-L909 |
24,946 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.traverseClassMembers | private void traverseClassMembers(Node n) {
for (Node child = n.getFirstChild(); child != null;) {
Node next = child.getNext(); // see traverseChildren
if (child.isComputedProp()) {
curNode = n;
if (callback.shouldTraverse(this, child, n)) {
traverseBranch(child.getLastChild(), child);
curNode = n;
callback.visit(this, child, n);
}
} else {
traverseBranch(child, n);
}
child = next;
}
} | java | private void traverseClassMembers(Node n) {
for (Node child = n.getFirstChild(); child != null;) {
Node next = child.getNext(); // see traverseChildren
if (child.isComputedProp()) {
curNode = n;
if (callback.shouldTraverse(this, child, n)) {
traverseBranch(child.getLastChild(), child);
curNode = n;
callback.visit(this, child, n);
}
} else {
traverseBranch(child, n);
}
child = next;
}
} | [
"private",
"void",
"traverseClassMembers",
"(",
"Node",
"n",
")",
"{",
"for",
"(",
"Node",
"child",
"=",
"n",
".",
"getFirstChild",
"(",
")",
";",
"child",
"!=",
"null",
";",
")",
"{",
"Node",
"next",
"=",
"child",
".",
"getNext",
"(",
")",
";",
"// see traverseChildren",
"if",
"(",
"child",
".",
"isComputedProp",
"(",
")",
")",
"{",
"curNode",
"=",
"n",
";",
"if",
"(",
"callback",
".",
"shouldTraverse",
"(",
"this",
",",
"child",
",",
"n",
")",
")",
"{",
"traverseBranch",
"(",
"child",
".",
"getLastChild",
"(",
")",
",",
"child",
")",
";",
"curNode",
"=",
"n",
";",
"callback",
".",
"visit",
"(",
"this",
",",
"child",
",",
"n",
")",
";",
"}",
"}",
"else",
"{",
"traverseBranch",
"(",
"child",
",",
"n",
")",
";",
"}",
"child",
"=",
"next",
";",
"}",
"}"
] | Traverse class members, excluding keys of computed props. | [
"Traverse",
"class",
"members",
"excluding",
"keys",
"of",
"computed",
"props",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L957-L972 |
24,947 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.getAbstractScope | public AbstractScope<?, ?> getAbstractScope() {
AbstractScope<?, ?> scope = scopes.peek();
// NOTE(dylandavidson): Use for-each loop to avoid slow ArrayList#get performance.
for (Node scopeRoot : scopeRoots) {
scope = scopeCreator.createScope(scopeRoot, scope);
scopes.push(scope);
}
scopeRoots.clear();
return scope;
} | java | public AbstractScope<?, ?> getAbstractScope() {
AbstractScope<?, ?> scope = scopes.peek();
// NOTE(dylandavidson): Use for-each loop to avoid slow ArrayList#get performance.
for (Node scopeRoot : scopeRoots) {
scope = scopeCreator.createScope(scopeRoot, scope);
scopes.push(scope);
}
scopeRoots.clear();
return scope;
} | [
"public",
"AbstractScope",
"<",
"?",
",",
"?",
">",
"getAbstractScope",
"(",
")",
"{",
"AbstractScope",
"<",
"?",
",",
"?",
">",
"scope",
"=",
"scopes",
".",
"peek",
"(",
")",
";",
"// NOTE(dylandavidson): Use for-each loop to avoid slow ArrayList#get performance.",
"for",
"(",
"Node",
"scopeRoot",
":",
"scopeRoots",
")",
"{",
"scope",
"=",
"scopeCreator",
".",
"createScope",
"(",
"scopeRoot",
",",
"scope",
")",
";",
"scopes",
".",
"push",
"(",
"scope",
")",
";",
"}",
"scopeRoots",
".",
"clear",
"(",
")",
";",
"return",
"scope",
";",
"}"
] | Gets the current scope. | [
"Gets",
"the",
"current",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L1060-L1070 |
24,948 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.instantiateScopes | private AbstractScope<?, ?> instantiateScopes(int count) {
checkArgument(count <= scopeRoots.size());
AbstractScope<?, ?> scope = scopes.peek();
for (int i = 0; i < count; i++) {
scope = scopeCreator.createScope(scopeRoots.get(i), scope);
scopes.push(scope);
}
scopeRoots.subList(0, count).clear();
return scope;
} | java | private AbstractScope<?, ?> instantiateScopes(int count) {
checkArgument(count <= scopeRoots.size());
AbstractScope<?, ?> scope = scopes.peek();
for (int i = 0; i < count; i++) {
scope = scopeCreator.createScope(scopeRoots.get(i), scope);
scopes.push(scope);
}
scopeRoots.subList(0, count).clear();
return scope;
} | [
"private",
"AbstractScope",
"<",
"?",
",",
"?",
">",
"instantiateScopes",
"(",
"int",
"count",
")",
"{",
"checkArgument",
"(",
"count",
"<=",
"scopeRoots",
".",
"size",
"(",
")",
")",
";",
"AbstractScope",
"<",
"?",
",",
"?",
">",
"scope",
"=",
"scopes",
".",
"peek",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"scope",
"=",
"scopeCreator",
".",
"createScope",
"(",
"scopeRoots",
".",
"get",
"(",
"i",
")",
",",
"scope",
")",
";",
"scopes",
".",
"push",
"(",
"scope",
")",
";",
"}",
"scopeRoots",
".",
"subList",
"(",
"0",
",",
"count",
")",
".",
"clear",
"(",
")",
";",
"return",
"scope",
";",
"}"
] | Instantiate some, but not necessarily all, scopes from stored roots.
<p>NodeTraversal instantiates scopes lazily when getScope() or similar is called, by iterating
over a stored list of not-yet-instantiated scopeRoots. When a not-yet-instantiated parent
scope is requested, it doesn't make sense to instantiate <i>all</i> pending scopes. Instead,
we count the number that are needed to ensure the requested parent is instantiated and call
this function to instantiate only as many scopes as are needed, shifting their roots off the
queue, and returning the deepest scope actually created. | [
"Instantiate",
"some",
"but",
"not",
"necessarily",
"all",
"scopes",
"from",
"stored",
"roots",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L1082-L1092 |
24,949 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.getControlFlowGraph | @SuppressWarnings("unchecked") // The type is always ControlFlowGraph<Node>
public ControlFlowGraph<Node> getControlFlowGraph() {
ControlFlowGraph<Node> result;
Object o = cfgs.peek();
if (o instanceof Node) {
Node cfgRoot = (Node) o;
ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false, true);
cfa.process(null, cfgRoot);
result = cfa.getCfg();
cfgs.pop();
cfgs.push(result);
} else {
result = (ControlFlowGraph<Node>) o;
}
return result;
} | java | @SuppressWarnings("unchecked") // The type is always ControlFlowGraph<Node>
public ControlFlowGraph<Node> getControlFlowGraph() {
ControlFlowGraph<Node> result;
Object o = cfgs.peek();
if (o instanceof Node) {
Node cfgRoot = (Node) o;
ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false, true);
cfa.process(null, cfgRoot);
result = cfa.getCfg();
cfgs.pop();
cfgs.push(result);
} else {
result = (ControlFlowGraph<Node>) o;
}
return result;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"// The type is always ControlFlowGraph<Node>",
"public",
"ControlFlowGraph",
"<",
"Node",
">",
"getControlFlowGraph",
"(",
")",
"{",
"ControlFlowGraph",
"<",
"Node",
">",
"result",
";",
"Object",
"o",
"=",
"cfgs",
".",
"peek",
"(",
")",
";",
"if",
"(",
"o",
"instanceof",
"Node",
")",
"{",
"Node",
"cfgRoot",
"=",
"(",
"Node",
")",
"o",
";",
"ControlFlowAnalysis",
"cfa",
"=",
"new",
"ControlFlowAnalysis",
"(",
"compiler",
",",
"false",
",",
"true",
")",
";",
"cfa",
".",
"process",
"(",
"null",
",",
"cfgRoot",
")",
";",
"result",
"=",
"cfa",
".",
"getCfg",
"(",
")",
";",
"cfgs",
".",
"pop",
"(",
")",
";",
"cfgs",
".",
"push",
"(",
"result",
")",
";",
"}",
"else",
"{",
"result",
"=",
"(",
"ControlFlowGraph",
"<",
"Node",
">",
")",
"o",
";",
"}",
"return",
"result",
";",
"}"
] | Gets the control flow graph for the current JS scope. | [
"Gets",
"the",
"control",
"flow",
"graph",
"for",
"the",
"current",
"JS",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L1149-L1164 |
24,950 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.getScopeRoot | public Node getScopeRoot() {
int roots = scopeRoots.size();
if (roots > 0) {
return scopeRoots.get(roots - 1);
} else {
AbstractScope<?, ?> s = scopes.peek();
return s != null ? s.getRootNode() : null;
}
} | java | public Node getScopeRoot() {
int roots = scopeRoots.size();
if (roots > 0) {
return scopeRoots.get(roots - 1);
} else {
AbstractScope<?, ?> s = scopes.peek();
return s != null ? s.getRootNode() : null;
}
} | [
"public",
"Node",
"getScopeRoot",
"(",
")",
"{",
"int",
"roots",
"=",
"scopeRoots",
".",
"size",
"(",
")",
";",
"if",
"(",
"roots",
">",
"0",
")",
"{",
"return",
"scopeRoots",
".",
"get",
"(",
"roots",
"-",
"1",
")",
";",
"}",
"else",
"{",
"AbstractScope",
"<",
"?",
",",
"?",
">",
"s",
"=",
"scopes",
".",
"peek",
"(",
")",
";",
"return",
"s",
"!=",
"null",
"?",
"s",
".",
"getRootNode",
"(",
")",
":",
"null",
";",
"}",
"}"
] | Returns the current scope's root. | [
"Returns",
"the",
"current",
"scope",
"s",
"root",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L1167-L1175 |
24,951 | google/closure-compiler | src/com/google/javascript/jscomp/NodeTraversal.java | NodeTraversal.initScopeRoots | private void initScopeRoots(Node n) {
Deque<Node> queuedScopeRoots = new ArrayDeque<>();
while (n != null) {
if (isScopeRoot(n)) {
queuedScopeRoots.addFirst(n);
}
n = n.getParent();
}
for (Node queuedScopeRoot : queuedScopeRoots) {
pushScope(queuedScopeRoot);
}
} | java | private void initScopeRoots(Node n) {
Deque<Node> queuedScopeRoots = new ArrayDeque<>();
while (n != null) {
if (isScopeRoot(n)) {
queuedScopeRoots.addFirst(n);
}
n = n.getParent();
}
for (Node queuedScopeRoot : queuedScopeRoots) {
pushScope(queuedScopeRoot);
}
} | [
"private",
"void",
"initScopeRoots",
"(",
"Node",
"n",
")",
"{",
"Deque",
"<",
"Node",
">",
"queuedScopeRoots",
"=",
"new",
"ArrayDeque",
"<>",
"(",
")",
";",
"while",
"(",
"n",
"!=",
"null",
")",
"{",
"if",
"(",
"isScopeRoot",
"(",
"n",
")",
")",
"{",
"queuedScopeRoots",
".",
"addFirst",
"(",
"n",
")",
";",
"}",
"n",
"=",
"n",
".",
"getParent",
"(",
")",
";",
"}",
"for",
"(",
"Node",
"queuedScopeRoot",
":",
"queuedScopeRoots",
")",
"{",
"pushScope",
"(",
"queuedScopeRoot",
")",
";",
"}",
"}"
] | Prefills the scopeRoots stack up to a given spot in the AST. Allows for starting traversal at
any spot while still having correct scope state. | [
"Prefills",
"the",
"scopeRoots",
"stack",
"up",
"to",
"a",
"given",
"spot",
"in",
"the",
"AST",
".",
"Allows",
"for",
"starting",
"traversal",
"at",
"any",
"spot",
"while",
"still",
"having",
"correct",
"scope",
"state",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/NodeTraversal.java#L1313-L1324 |
24,952 | google/closure-compiler | src/com/google/javascript/rhino/jstype/EnumElementType.java | EnumElementType.meet | JSType meet(JSType that) {
JSType meetPrimitive = primitiveType.getGreatestSubtype(that);
if (meetPrimitive.isEmptyType()) {
return null;
} else {
return new EnumElementType(registry, meetPrimitive, name, getEnumType());
}
} | java | JSType meet(JSType that) {
JSType meetPrimitive = primitiveType.getGreatestSubtype(that);
if (meetPrimitive.isEmptyType()) {
return null;
} else {
return new EnumElementType(registry, meetPrimitive, name, getEnumType());
}
} | [
"JSType",
"meet",
"(",
"JSType",
"that",
")",
"{",
"JSType",
"meetPrimitive",
"=",
"primitiveType",
".",
"getGreatestSubtype",
"(",
"that",
")",
";",
"if",
"(",
"meetPrimitive",
".",
"isEmptyType",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"new",
"EnumElementType",
"(",
"registry",
",",
"meetPrimitive",
",",
"name",
",",
"getEnumType",
"(",
")",
")",
";",
"}",
"}"
] | Returns the infimum of a enum element type and another type, or null
if the infimum is empty.
This can be a little bit weird. For example, suppose you have an enum
of {(string|number)}, and you want the greatest subtype of the enum
and a {number}.
The infimum is non-empty. But at the same time, we don't really have
a name for this infimum. It's equivalent to "elements of this enum that
are numbers".
The best we can do is make up a new type. This is similar to what
we do in UnionType#meet, which kind-of-sort-of makes sense, because
an EnumElementType is a union of instances of a type. | [
"Returns",
"the",
"infimum",
"of",
"a",
"enum",
"element",
"type",
"and",
"another",
"type",
"or",
"null",
"if",
"the",
"infimum",
"is",
"empty",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/rhino/jstype/EnumElementType.java#L238-L245 |
24,953 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.getGlobalScope | public final S getGlobalScope() {
S result = thisScope();
while (result.getParent() != null) {
result = result.getParent();
}
return result;
} | java | public final S getGlobalScope() {
S result = thisScope();
while (result.getParent() != null) {
result = result.getParent();
}
return result;
} | [
"public",
"final",
"S",
"getGlobalScope",
"(",
")",
"{",
"S",
"result",
"=",
"thisScope",
"(",
")",
";",
"while",
"(",
"result",
".",
"getParent",
"(",
")",
"!=",
"null",
")",
"{",
"result",
"=",
"result",
".",
"getParent",
"(",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Walks up the tree to find the global scope. | [
"Walks",
"up",
"the",
"tree",
"to",
"find",
"the",
"global",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L115-L121 |
24,954 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.undeclare | final void undeclare(V var) {
checkState(var.scope == this);
checkState(vars.get(var.name).equals(var));
undeclareInteral(var);
} | java | final void undeclare(V var) {
checkState(var.scope == this);
checkState(vars.get(var.name).equals(var));
undeclareInteral(var);
} | [
"final",
"void",
"undeclare",
"(",
"V",
"var",
")",
"{",
"checkState",
"(",
"var",
".",
"scope",
"==",
"this",
")",
";",
"checkState",
"(",
"vars",
".",
"get",
"(",
"var",
".",
"name",
")",
".",
"equals",
"(",
"var",
")",
")",
";",
"undeclareInteral",
"(",
"var",
")",
";",
"}"
] | Undeclares a variable, to be used when the compiler optimizes out
a variable and removes it from the scope. | [
"Undeclares",
"a",
"variable",
"to",
"be",
"used",
"when",
"the",
"compiler",
"optimizes",
"out",
"a",
"variable",
"and",
"removes",
"it",
"from",
"the",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L134-L138 |
24,955 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.getVar | public V getVar(String name) {
ImplicitVar implicit = name != null ? ImplicitVar.of(name) : null;
if (implicit != null) {
return getImplicitVar(implicit, true);
}
S scope = thisScope();
while (scope != null) {
V var = scope.getOwnSlot(name);
if (var != null) {
return var;
}
// Recurse up the parent Scope
scope = scope.getParent();
}
return null;
} | java | public V getVar(String name) {
ImplicitVar implicit = name != null ? ImplicitVar.of(name) : null;
if (implicit != null) {
return getImplicitVar(implicit, true);
}
S scope = thisScope();
while (scope != null) {
V var = scope.getOwnSlot(name);
if (var != null) {
return var;
}
// Recurse up the parent Scope
scope = scope.getParent();
}
return null;
} | [
"public",
"V",
"getVar",
"(",
"String",
"name",
")",
"{",
"ImplicitVar",
"implicit",
"=",
"name",
"!=",
"null",
"?",
"ImplicitVar",
".",
"of",
"(",
"name",
")",
":",
"null",
";",
"if",
"(",
"implicit",
"!=",
"null",
")",
"{",
"return",
"getImplicitVar",
"(",
"implicit",
",",
"true",
")",
";",
"}",
"S",
"scope",
"=",
"thisScope",
"(",
")",
";",
"while",
"(",
"scope",
"!=",
"null",
")",
"{",
"V",
"var",
"=",
"scope",
".",
"getOwnSlot",
"(",
"name",
")",
";",
"if",
"(",
"var",
"!=",
"null",
")",
"{",
"return",
"var",
";",
"}",
"// Recurse up the parent Scope",
"scope",
"=",
"scope",
".",
"getParent",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Non-final for jsdev tests | [
"Non",
"-",
"final",
"for",
"jsdev",
"tests"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L171-L186 |
24,956 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.getImplicitVar | private final V getImplicitVar(ImplicitVar var, boolean allowDeclaredVars) {
S scope = thisScope();
while (scope != null) {
if (var.isMadeByScope(scope)) {
V result = ((AbstractScope<S, V>) scope).implicitVars.get(var);
if (result == null) {
((AbstractScope<S, V>) scope).implicitVars.put(var, result = scope.makeImplicitVar(var));
}
return result;
}
V result = allowDeclaredVars ? scope.getOwnSlot(var.name) : null;
if (result != null) {
return result;
}
// Recurse up the parent Scope
scope = scope.getParent();
}
return null;
} | java | private final V getImplicitVar(ImplicitVar var, boolean allowDeclaredVars) {
S scope = thisScope();
while (scope != null) {
if (var.isMadeByScope(scope)) {
V result = ((AbstractScope<S, V>) scope).implicitVars.get(var);
if (result == null) {
((AbstractScope<S, V>) scope).implicitVars.put(var, result = scope.makeImplicitVar(var));
}
return result;
}
V result = allowDeclaredVars ? scope.getOwnSlot(var.name) : null;
if (result != null) {
return result;
}
// Recurse up the parent Scope
scope = scope.getParent();
}
return null;
} | [
"private",
"final",
"V",
"getImplicitVar",
"(",
"ImplicitVar",
"var",
",",
"boolean",
"allowDeclaredVars",
")",
"{",
"S",
"scope",
"=",
"thisScope",
"(",
")",
";",
"while",
"(",
"scope",
"!=",
"null",
")",
"{",
"if",
"(",
"var",
".",
"isMadeByScope",
"(",
"scope",
")",
")",
"{",
"V",
"result",
"=",
"(",
"(",
"AbstractScope",
"<",
"S",
",",
"V",
">",
")",
"scope",
")",
".",
"implicitVars",
".",
"get",
"(",
"var",
")",
";",
"if",
"(",
"result",
"==",
"null",
")",
"{",
"(",
"(",
"AbstractScope",
"<",
"S",
",",
"V",
">",
")",
"scope",
")",
".",
"implicitVars",
".",
"put",
"(",
"var",
",",
"result",
"=",
"scope",
".",
"makeImplicitVar",
"(",
"var",
")",
")",
";",
"}",
"return",
"result",
";",
"}",
"V",
"result",
"=",
"allowDeclaredVars",
"?",
"scope",
".",
"getOwnSlot",
"(",
"var",
".",
"name",
")",
":",
"null",
";",
"if",
"(",
"result",
"!=",
"null",
")",
"{",
"return",
"result",
";",
"}",
"// Recurse up the parent Scope",
"scope",
"=",
"scope",
".",
"getParent",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get a unique Var object of the given implicit var type. | [
"Get",
"a",
"unique",
"Var",
"object",
"of",
"the",
"given",
"implicit",
"var",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L196-L214 |
24,957 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.hasSlot | public final boolean hasSlot(String name) {
S scope = thisScope();
while (scope != null) {
if (scope.hasOwnSlot(name)) {
return true;
}
scope = scope.getParent();
}
return false;
} | java | public final boolean hasSlot(String name) {
S scope = thisScope();
while (scope != null) {
if (scope.hasOwnSlot(name)) {
return true;
}
scope = scope.getParent();
}
return false;
} | [
"public",
"final",
"boolean",
"hasSlot",
"(",
"String",
"name",
")",
"{",
"S",
"scope",
"=",
"thisScope",
"(",
")",
";",
"while",
"(",
"scope",
"!=",
"null",
")",
"{",
"if",
"(",
"scope",
".",
"hasOwnSlot",
"(",
"name",
")",
")",
"{",
"return",
"true",
";",
"}",
"scope",
"=",
"scope",
".",
"getParent",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if a variable is declared in this or any parent scope. | [
"Returns",
"true",
"if",
"a",
"variable",
"is",
"declared",
"in",
"this",
"or",
"any",
"parent",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L222-L231 |
24,958 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.canDeclare | final boolean canDeclare(String name) {
return !hasOwnSlot(name)
&& (!isFunctionBlockScope()
|| !getParent().hasOwnSlot(name)
|| isBleedingFunctionName(name));
} | java | final boolean canDeclare(String name) {
return !hasOwnSlot(name)
&& (!isFunctionBlockScope()
|| !getParent().hasOwnSlot(name)
|| isBleedingFunctionName(name));
} | [
"final",
"boolean",
"canDeclare",
"(",
"String",
"name",
")",
"{",
"return",
"!",
"hasOwnSlot",
"(",
"name",
")",
"&&",
"(",
"!",
"isFunctionBlockScope",
"(",
")",
"||",
"!",
"getParent",
"(",
")",
".",
"hasOwnSlot",
"(",
"name",
")",
"||",
"isBleedingFunctionName",
"(",
"name",
")",
")",
";",
"}"
] | Returns true if the name can be declared on this scope without causing illegal shadowing.
Specifically, this is aware of the connection between function container scopes and function
block scopes and returns false for redeclaring parameters on the block scope. | [
"Returns",
"true",
"if",
"the",
"name",
"can",
"be",
"declared",
"on",
"this",
"scope",
"without",
"causing",
"illegal",
"shadowing",
".",
"Specifically",
"this",
"is",
"aware",
"of",
"the",
"connection",
"between",
"function",
"container",
"scopes",
"and",
"function",
"block",
"scopes",
"and",
"returns",
"false",
"for",
"redeclaring",
"parameters",
"on",
"the",
"block",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L238-L243 |
24,959 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.isBleedingFunctionName | private boolean isBleedingFunctionName(String name) {
V var = getVar(name);
return var != null && var.getNode().getParent().isFunction();
} | java | private boolean isBleedingFunctionName(String name) {
V var = getVar(name);
return var != null && var.getNode().getParent().isFunction();
} | [
"private",
"boolean",
"isBleedingFunctionName",
"(",
"String",
"name",
")",
"{",
"V",
"var",
"=",
"getVar",
"(",
"name",
")",
";",
"return",
"var",
"!=",
"null",
"&&",
"var",
".",
"getNode",
"(",
")",
".",
"getParent",
"(",
")",
".",
"isFunction",
"(",
")",
";",
"}"
] | Returns true if the given name is a bleeding function name in this scope. Local variables in
the function block are not allowed to shadow parameters, but they are allowed to shadow a
bleeding function name. | [
"Returns",
"true",
"if",
"the",
"given",
"name",
"is",
"a",
"bleeding",
"function",
"name",
"in",
"this",
"scope",
".",
"Local",
"variables",
"in",
"the",
"function",
"block",
"are",
"not",
"allowed",
"to",
"shadow",
"parameters",
"but",
"they",
"are",
"allowed",
"to",
"shadow",
"a",
"bleeding",
"function",
"name",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L250-L253 |
24,960 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.getClosestHoistScope | public final S getClosestHoistScope() {
S current = thisScope();
while (current != null) {
if (current.isHoistScope()) {
return current;
}
current = current.getParent();
}
return null;
} | java | public final S getClosestHoistScope() {
S current = thisScope();
while (current != null) {
if (current.isHoistScope()) {
return current;
}
current = current.getParent();
}
return null;
} | [
"public",
"final",
"S",
"getClosestHoistScope",
"(",
")",
"{",
"S",
"current",
"=",
"thisScope",
"(",
")",
";",
"while",
"(",
"current",
"!=",
"null",
")",
"{",
"if",
"(",
"current",
".",
"isHoistScope",
"(",
")",
")",
"{",
"return",
"current",
";",
"}",
"current",
"=",
"current",
".",
"getParent",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | If a var were declared in this scope, return the scope it would be hoisted to.
<p>For function scopes, we return back the scope itself, since even though there is no way to
declare a var inside function parameters, it would make even less sense to say that such
declarations would be "hoisted" somewhere else. | [
"If",
"a",
"var",
"were",
"declared",
"in",
"this",
"scope",
"return",
"the",
"scope",
"it",
"would",
"be",
"hoisted",
"to",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L359-L368 |
24,961 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.getClosestContainerScope | public final S getClosestContainerScope() {
S scope = getClosestHoistScope();
if (scope.isBlockScope()) {
scope = scope.getParent();
checkState(!scope.isBlockScope());
}
return scope;
} | java | public final S getClosestContainerScope() {
S scope = getClosestHoistScope();
if (scope.isBlockScope()) {
scope = scope.getParent();
checkState(!scope.isBlockScope());
}
return scope;
} | [
"public",
"final",
"S",
"getClosestContainerScope",
"(",
")",
"{",
"S",
"scope",
"=",
"getClosestHoistScope",
"(",
")",
";",
"if",
"(",
"scope",
".",
"isBlockScope",
"(",
")",
")",
"{",
"scope",
"=",
"scope",
".",
"getParent",
"(",
")",
";",
"checkState",
"(",
"!",
"scope",
".",
"isBlockScope",
"(",
")",
")",
";",
"}",
"return",
"scope",
";",
"}"
] | Returns the closest container scope. This is equivalent to what the current scope would have
been for non-ES6 scope creators, and is thus useful for migrating code to use block scopes. | [
"Returns",
"the",
"closest",
"container",
"scope",
".",
"This",
"is",
"equivalent",
"to",
"what",
"the",
"current",
"scope",
"would",
"have",
"been",
"for",
"non",
"-",
"ES6",
"scope",
"creators",
"and",
"is",
"thus",
"useful",
"for",
"migrating",
"code",
"to",
"use",
"block",
"scopes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L374-L381 |
24,962 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.checkChildScope | final void checkChildScope(S parent) {
checkNotNull(parent);
checkArgument(NodeUtil.createsScope(rootNode), rootNode);
checkArgument(
rootNode != parent.getRootNode(),
"rootNode should not be the parent's root node: %s", rootNode);
} | java | final void checkChildScope(S parent) {
checkNotNull(parent);
checkArgument(NodeUtil.createsScope(rootNode), rootNode);
checkArgument(
rootNode != parent.getRootNode(),
"rootNode should not be the parent's root node: %s", rootNode);
} | [
"final",
"void",
"checkChildScope",
"(",
"S",
"parent",
")",
"{",
"checkNotNull",
"(",
"parent",
")",
";",
"checkArgument",
"(",
"NodeUtil",
".",
"createsScope",
"(",
"rootNode",
")",
",",
"rootNode",
")",
";",
"checkArgument",
"(",
"rootNode",
"!=",
"parent",
".",
"getRootNode",
"(",
")",
",",
"\"rootNode should not be the parent's root node: %s\"",
",",
"rootNode",
")",
";",
"}"
] | Performs simple validity checks on when constructing a child scope. | [
"Performs",
"simple",
"validity",
"checks",
"on",
"when",
"constructing",
"a",
"child",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L392-L398 |
24,963 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.checkRootScope | final void checkRootScope() {
// TODO(tbreisacher): Can we tighten this to just NodeUtil.createsScope?
checkArgument(
NodeUtil.createsScope(rootNode) || rootNode.isScript() || rootNode.isRoot(), rootNode);
} | java | final void checkRootScope() {
// TODO(tbreisacher): Can we tighten this to just NodeUtil.createsScope?
checkArgument(
NodeUtil.createsScope(rootNode) || rootNode.isScript() || rootNode.isRoot(), rootNode);
} | [
"final",
"void",
"checkRootScope",
"(",
")",
"{",
"// TODO(tbreisacher): Can we tighten this to just NodeUtil.createsScope?",
"checkArgument",
"(",
"NodeUtil",
".",
"createsScope",
"(",
"rootNode",
")",
"||",
"rootNode",
".",
"isScript",
"(",
")",
"||",
"rootNode",
".",
"isRoot",
"(",
")",
",",
"rootNode",
")",
";",
"}"
] | Performs simple validity checks on when constructing a root scope. | [
"Performs",
"simple",
"validity",
"checks",
"on",
"when",
"constructing",
"a",
"root",
"scope",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L401-L405 |
24,964 | google/closure-compiler | src/com/google/javascript/jscomp/AbstractScope.java | AbstractScope.getCommonParent | S getCommonParent(S other) {
S left = thisScope();
S right = other;
while (left != null && right != null && left != right) {
int leftDepth = left.getDepth();
int rightDepth = right.getDepth();
if (leftDepth >= rightDepth) {
left = left.getParent();
}
if (leftDepth <= rightDepth) {
right = right.getParent();
}
}
checkState(left != null && left == right);
return left;
} | java | S getCommonParent(S other) {
S left = thisScope();
S right = other;
while (left != null && right != null && left != right) {
int leftDepth = left.getDepth();
int rightDepth = right.getDepth();
if (leftDepth >= rightDepth) {
left = left.getParent();
}
if (leftDepth <= rightDepth) {
right = right.getParent();
}
}
checkState(left != null && left == right);
return left;
} | [
"S",
"getCommonParent",
"(",
"S",
"other",
")",
"{",
"S",
"left",
"=",
"thisScope",
"(",
")",
";",
"S",
"right",
"=",
"other",
";",
"while",
"(",
"left",
"!=",
"null",
"&&",
"right",
"!=",
"null",
"&&",
"left",
"!=",
"right",
")",
"{",
"int",
"leftDepth",
"=",
"left",
".",
"getDepth",
"(",
")",
";",
"int",
"rightDepth",
"=",
"right",
".",
"getDepth",
"(",
")",
";",
"if",
"(",
"leftDepth",
">=",
"rightDepth",
")",
"{",
"left",
"=",
"left",
".",
"getParent",
"(",
")",
";",
"}",
"if",
"(",
"leftDepth",
"<=",
"rightDepth",
")",
"{",
"right",
"=",
"right",
".",
"getParent",
"(",
")",
";",
"}",
"}",
"checkState",
"(",
"left",
"!=",
"null",
"&&",
"left",
"==",
"right",
")",
";",
"return",
"left",
";",
"}"
] | Returns the nearest common parent between two scopes. | [
"Returns",
"the",
"nearest",
"common",
"parent",
"between",
"two",
"scopes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/AbstractScope.java#L408-L424 |
24,965 | google/closure-compiler | src/com/google/javascript/jscomp/ExploitAssigns.java | ExploitAssigns.collapseAssign | private void collapseAssign(Node assign, Node expr, Node exprParent) {
Node leftValue = assign.getFirstChild();
Node rightValue = leftValue.getNext();
if (leftValue.isDestructuringPattern()) {
// We don't collapse expressions containing these because they can have side effects:
// - Reassigning RHS names. (e.g. `() => { ({c: a} = a); return a; }`).
// - Calling a getter defined on the RHS.
// - Evaluating a default value.
// TODO(b/123102446): Check for these issues and optimize when they aren't present.
return;
} else if (isCollapsibleValue(leftValue, true)
&& collapseAssignEqualTo(expr, exprParent, leftValue)) {
// Condition has side-effects.
} else if (isCollapsibleValue(rightValue, false)
&& collapseAssignEqualTo(expr, exprParent, rightValue)) {
// Condition has side-effects.
} else if (rightValue.isAssign()) {
// Recursively deal with nested assigns.
collapseAssign(rightValue, expr, exprParent);
}
} | java | private void collapseAssign(Node assign, Node expr, Node exprParent) {
Node leftValue = assign.getFirstChild();
Node rightValue = leftValue.getNext();
if (leftValue.isDestructuringPattern()) {
// We don't collapse expressions containing these because they can have side effects:
// - Reassigning RHS names. (e.g. `() => { ({c: a} = a); return a; }`).
// - Calling a getter defined on the RHS.
// - Evaluating a default value.
// TODO(b/123102446): Check for these issues and optimize when they aren't present.
return;
} else if (isCollapsibleValue(leftValue, true)
&& collapseAssignEqualTo(expr, exprParent, leftValue)) {
// Condition has side-effects.
} else if (isCollapsibleValue(rightValue, false)
&& collapseAssignEqualTo(expr, exprParent, rightValue)) {
// Condition has side-effects.
} else if (rightValue.isAssign()) {
// Recursively deal with nested assigns.
collapseAssign(rightValue, expr, exprParent);
}
} | [
"private",
"void",
"collapseAssign",
"(",
"Node",
"assign",
",",
"Node",
"expr",
",",
"Node",
"exprParent",
")",
"{",
"Node",
"leftValue",
"=",
"assign",
".",
"getFirstChild",
"(",
")",
";",
"Node",
"rightValue",
"=",
"leftValue",
".",
"getNext",
"(",
")",
";",
"if",
"(",
"leftValue",
".",
"isDestructuringPattern",
"(",
")",
")",
"{",
"// We don't collapse expressions containing these because they can have side effects:",
"// - Reassigning RHS names. (e.g. `() => { ({c: a} = a); return a; }`).",
"// - Calling a getter defined on the RHS.",
"// - Evaluating a default value.",
"// TODO(b/123102446): Check for these issues and optimize when they aren't present.",
"return",
";",
"}",
"else",
"if",
"(",
"isCollapsibleValue",
"(",
"leftValue",
",",
"true",
")",
"&&",
"collapseAssignEqualTo",
"(",
"expr",
",",
"exprParent",
",",
"leftValue",
")",
")",
"{",
"// Condition has side-effects.",
"}",
"else",
"if",
"(",
"isCollapsibleValue",
"(",
"rightValue",
",",
"false",
")",
"&&",
"collapseAssignEqualTo",
"(",
"expr",
",",
"exprParent",
",",
"rightValue",
")",
")",
"{",
"// Condition has side-effects.",
"}",
"else",
"if",
"(",
"rightValue",
".",
"isAssign",
"(",
")",
")",
"{",
"// Recursively deal with nested assigns.",
"collapseAssign",
"(",
"rightValue",
",",
"expr",
",",
"exprParent",
")",
";",
"}",
"}"
] | Try to collapse the given assign into subsequent expressions. | [
"Try",
"to",
"collapse",
"the",
"given",
"assign",
"into",
"subsequent",
"expressions",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ExploitAssigns.java#L43-L64 |
24,966 | google/closure-compiler | src/com/google/javascript/jscomp/ExploitAssigns.java | ExploitAssigns.isCollapsibleValue | private static boolean isCollapsibleValue(Node value, boolean isLValue) {
switch (value.getToken()) {
case GETPROP:
// Do not collapse GETPROPs on arbitrary objects, because
// they may be implemented setter functions, and oftentimes
// setter functions fail on native objects. This is OK for "THIS"
// objects, because we assume that they are non-native.
return !isLValue || value.getFirstChild().isThis();
case NAME:
return true;
default:
return NodeUtil.isImmutableValue(value);
}
} | java | private static boolean isCollapsibleValue(Node value, boolean isLValue) {
switch (value.getToken()) {
case GETPROP:
// Do not collapse GETPROPs on arbitrary objects, because
// they may be implemented setter functions, and oftentimes
// setter functions fail on native objects. This is OK for "THIS"
// objects, because we assume that they are non-native.
return !isLValue || value.getFirstChild().isThis();
case NAME:
return true;
default:
return NodeUtil.isImmutableValue(value);
}
} | [
"private",
"static",
"boolean",
"isCollapsibleValue",
"(",
"Node",
"value",
",",
"boolean",
"isLValue",
")",
"{",
"switch",
"(",
"value",
".",
"getToken",
"(",
")",
")",
"{",
"case",
"GETPROP",
":",
"// Do not collapse GETPROPs on arbitrary objects, because",
"// they may be implemented setter functions, and oftentimes",
"// setter functions fail on native objects. This is OK for \"THIS\"",
"// objects, because we assume that they are non-native.",
"return",
"!",
"isLValue",
"||",
"value",
".",
"getFirstChild",
"(",
")",
".",
"isThis",
"(",
")",
";",
"case",
"NAME",
":",
"return",
"true",
";",
"default",
":",
"return",
"NodeUtil",
".",
"isImmutableValue",
"(",
"value",
")",
";",
"}",
"}"
] | Determines whether we know enough about the given value to be able
to collapse it into subsequent expressions.
For example, we can collapse booleans and variable names:
<code>
x = 3; y = x; // y = x = 3;
a = true; b = true; // b = a = true;
<code>
But we won't try to collapse complex expressions.
@param value The value node.
@param isLValue Whether it's on the left-hand side of an expr. | [
"Determines",
"whether",
"we",
"know",
"enough",
"about",
"the",
"given",
"value",
"to",
"be",
"able",
"to",
"collapse",
"it",
"into",
"subsequent",
"expressions",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ExploitAssigns.java#L80-L95 |
24,967 | google/closure-compiler | src/com/google/javascript/jscomp/ExploitAssigns.java | ExploitAssigns.collapseAssignEqualTo | private boolean collapseAssignEqualTo(Node expr, Node exprParent, Node value) {
Node assign = expr.getFirstChild();
Node parent = exprParent;
Node next = expr.getNext();
while (next != null) {
switch (next.getToken()) {
case AND:
case OR:
case HOOK:
case IF:
case RETURN:
case EXPR_RESULT:
// Dive down the left side
parent = next;
next = next.getFirstChild();
break;
case CONST:
case LET:
case VAR:
if (next.getFirstChild().hasChildren()) {
parent = next.getFirstChild();
next = parent.getFirstChild();
break;
}
return false;
case GETPROP:
case NAME:
if (next.isQualifiedName()) {
if (value.isQualifiedName() &&
next.matchesQualifiedName(value)) {
// If the previous expression evaluates to value of a
// qualified name, and that qualified name is used again
// shortly, then we can exploit the assign here.
// Verify the assignment doesn't change its own value.
if (!isSafeReplacement(next, assign)) {
return false;
}
exprParent.removeChild(expr);
expr.removeChild(assign);
parent.replaceChild(next, assign);
reportChangeToEnclosingScope(parent);
return true;
}
}
return false;
case ASSIGN:
// Assigns are really tricky. In lots of cases, we want to inline
// into the right side of the assign. But the left side of the
// assign is evaluated first, and it may have convoluted logic:
// a = null;
// (a = b).c = null;
// We don't want to exploit the first assign. Similarly:
// a.b = null;
// a.b.c = null;
// We don't want to exploit the first assign either.
//
// To protect against this, we simply only inline when the left side
// is guaranteed to evaluate to the same L-value no matter what.
Node leftSide = next.getFirstChild();
if (leftSide.isName() || (leftSide.isGetProp() && leftSide.getFirstChild().isThis())) {
// Dive down the right side of the assign.
parent = next;
next = leftSide.getNext();
break;
} else {
return false;
}
default:
if (NodeUtil.isImmutableValue(next)
&& next.isEquivalentTo(value)) {
// If the r-value of the expr assign is an immutable value,
// and the value is used again shortly, then we can exploit
// the assign here.
exprParent.removeChild(expr);
expr.removeChild(assign);
parent.replaceChild(next, assign);
reportChangeToEnclosingScope(parent);
return true;
}
// Return without inlining a thing
return false;
}
}
return false;
} | java | private boolean collapseAssignEqualTo(Node expr, Node exprParent, Node value) {
Node assign = expr.getFirstChild();
Node parent = exprParent;
Node next = expr.getNext();
while (next != null) {
switch (next.getToken()) {
case AND:
case OR:
case HOOK:
case IF:
case RETURN:
case EXPR_RESULT:
// Dive down the left side
parent = next;
next = next.getFirstChild();
break;
case CONST:
case LET:
case VAR:
if (next.getFirstChild().hasChildren()) {
parent = next.getFirstChild();
next = parent.getFirstChild();
break;
}
return false;
case GETPROP:
case NAME:
if (next.isQualifiedName()) {
if (value.isQualifiedName() &&
next.matchesQualifiedName(value)) {
// If the previous expression evaluates to value of a
// qualified name, and that qualified name is used again
// shortly, then we can exploit the assign here.
// Verify the assignment doesn't change its own value.
if (!isSafeReplacement(next, assign)) {
return false;
}
exprParent.removeChild(expr);
expr.removeChild(assign);
parent.replaceChild(next, assign);
reportChangeToEnclosingScope(parent);
return true;
}
}
return false;
case ASSIGN:
// Assigns are really tricky. In lots of cases, we want to inline
// into the right side of the assign. But the left side of the
// assign is evaluated first, and it may have convoluted logic:
// a = null;
// (a = b).c = null;
// We don't want to exploit the first assign. Similarly:
// a.b = null;
// a.b.c = null;
// We don't want to exploit the first assign either.
//
// To protect against this, we simply only inline when the left side
// is guaranteed to evaluate to the same L-value no matter what.
Node leftSide = next.getFirstChild();
if (leftSide.isName() || (leftSide.isGetProp() && leftSide.getFirstChild().isThis())) {
// Dive down the right side of the assign.
parent = next;
next = leftSide.getNext();
break;
} else {
return false;
}
default:
if (NodeUtil.isImmutableValue(next)
&& next.isEquivalentTo(value)) {
// If the r-value of the expr assign is an immutable value,
// and the value is used again shortly, then we can exploit
// the assign here.
exprParent.removeChild(expr);
expr.removeChild(assign);
parent.replaceChild(next, assign);
reportChangeToEnclosingScope(parent);
return true;
}
// Return without inlining a thing
return false;
}
}
return false;
} | [
"private",
"boolean",
"collapseAssignEqualTo",
"(",
"Node",
"expr",
",",
"Node",
"exprParent",
",",
"Node",
"value",
")",
"{",
"Node",
"assign",
"=",
"expr",
".",
"getFirstChild",
"(",
")",
";",
"Node",
"parent",
"=",
"exprParent",
";",
"Node",
"next",
"=",
"expr",
".",
"getNext",
"(",
")",
";",
"while",
"(",
"next",
"!=",
"null",
")",
"{",
"switch",
"(",
"next",
".",
"getToken",
"(",
")",
")",
"{",
"case",
"AND",
":",
"case",
"OR",
":",
"case",
"HOOK",
":",
"case",
"IF",
":",
"case",
"RETURN",
":",
"case",
"EXPR_RESULT",
":",
"// Dive down the left side",
"parent",
"=",
"next",
";",
"next",
"=",
"next",
".",
"getFirstChild",
"(",
")",
";",
"break",
";",
"case",
"CONST",
":",
"case",
"LET",
":",
"case",
"VAR",
":",
"if",
"(",
"next",
".",
"getFirstChild",
"(",
")",
".",
"hasChildren",
"(",
")",
")",
"{",
"parent",
"=",
"next",
".",
"getFirstChild",
"(",
")",
";",
"next",
"=",
"parent",
".",
"getFirstChild",
"(",
")",
";",
"break",
";",
"}",
"return",
"false",
";",
"case",
"GETPROP",
":",
"case",
"NAME",
":",
"if",
"(",
"next",
".",
"isQualifiedName",
"(",
")",
")",
"{",
"if",
"(",
"value",
".",
"isQualifiedName",
"(",
")",
"&&",
"next",
".",
"matchesQualifiedName",
"(",
"value",
")",
")",
"{",
"// If the previous expression evaluates to value of a",
"// qualified name, and that qualified name is used again",
"// shortly, then we can exploit the assign here.",
"// Verify the assignment doesn't change its own value.",
"if",
"(",
"!",
"isSafeReplacement",
"(",
"next",
",",
"assign",
")",
")",
"{",
"return",
"false",
";",
"}",
"exprParent",
".",
"removeChild",
"(",
"expr",
")",
";",
"expr",
".",
"removeChild",
"(",
"assign",
")",
";",
"parent",
".",
"replaceChild",
"(",
"next",
",",
"assign",
")",
";",
"reportChangeToEnclosingScope",
"(",
"parent",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"case",
"ASSIGN",
":",
"// Assigns are really tricky. In lots of cases, we want to inline",
"// into the right side of the assign. But the left side of the",
"// assign is evaluated first, and it may have convoluted logic:",
"// a = null;",
"// (a = b).c = null;",
"// We don't want to exploit the first assign. Similarly:",
"// a.b = null;",
"// a.b.c = null;",
"// We don't want to exploit the first assign either.",
"//",
"// To protect against this, we simply only inline when the left side",
"// is guaranteed to evaluate to the same L-value no matter what.",
"Node",
"leftSide",
"=",
"next",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"leftSide",
".",
"isName",
"(",
")",
"||",
"(",
"leftSide",
".",
"isGetProp",
"(",
")",
"&&",
"leftSide",
".",
"getFirstChild",
"(",
")",
".",
"isThis",
"(",
")",
")",
")",
"{",
"// Dive down the right side of the assign.",
"parent",
"=",
"next",
";",
"next",
"=",
"leftSide",
".",
"getNext",
"(",
")",
";",
"break",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"default",
":",
"if",
"(",
"NodeUtil",
".",
"isImmutableValue",
"(",
"next",
")",
"&&",
"next",
".",
"isEquivalentTo",
"(",
"value",
")",
")",
"{",
"// If the r-value of the expr assign is an immutable value,",
"// and the value is used again shortly, then we can exploit",
"// the assign here.",
"exprParent",
".",
"removeChild",
"(",
"expr",
")",
";",
"expr",
".",
"removeChild",
"(",
"assign",
")",
";",
"parent",
".",
"replaceChild",
"(",
"next",
",",
"assign",
")",
";",
"reportChangeToEnclosingScope",
"(",
"parent",
")",
";",
"return",
"true",
";",
"}",
"// Return without inlining a thing",
"return",
"false",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Collapse the given assign expression into the expression directly following it, if possible.
@param expr The expression that may be moved.
@param exprParent The parent of {@code expr}.
@param value The value of this expression, expressed as a node. Each expression may have
multiple values, so this function may be called multiple times for the same expression. For
example, <code>
a = true;
</code> is equal to the name "a" and the boolean "true".
@return Whether the expression was collapsed successfully. | [
"Collapse",
"the",
"given",
"assign",
"expression",
"into",
"the",
"expression",
"directly",
"following",
"it",
"if",
"possible",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ExploitAssigns.java#L109-L200 |
24,968 | google/closure-compiler | src/com/google/javascript/jscomp/ExploitAssigns.java | ExploitAssigns.isSafeReplacement | private boolean isSafeReplacement(Node node, Node replacement) {
// No checks are needed for simple names.
if (node.isName()) {
return true;
}
checkArgument(node.isGetProp());
while (node.isGetProp()) {
node = node.getFirstChild();
}
return !(node.isName() && isNameAssignedTo(node.getString(), replacement));
} | java | private boolean isSafeReplacement(Node node, Node replacement) {
// No checks are needed for simple names.
if (node.isName()) {
return true;
}
checkArgument(node.isGetProp());
while (node.isGetProp()) {
node = node.getFirstChild();
}
return !(node.isName() && isNameAssignedTo(node.getString(), replacement));
} | [
"private",
"boolean",
"isSafeReplacement",
"(",
"Node",
"node",
",",
"Node",
"replacement",
")",
"{",
"// No checks are needed for simple names.",
"if",
"(",
"node",
".",
"isName",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"checkArgument",
"(",
"node",
".",
"isGetProp",
"(",
")",
")",
";",
"while",
"(",
"node",
".",
"isGetProp",
"(",
")",
")",
"{",
"node",
"=",
"node",
".",
"getFirstChild",
"(",
")",
";",
"}",
"return",
"!",
"(",
"node",
".",
"isName",
"(",
")",
"&&",
"isNameAssignedTo",
"(",
"node",
".",
"getString",
"(",
")",
",",
"replacement",
")",
")",
";",
"}"
] | Checks name referenced in node to determine if it might have
changed.
@return Whether the replacement can be made. | [
"Checks",
"name",
"referenced",
"in",
"node",
"to",
"determine",
"if",
"it",
"might",
"have",
"changed",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ExploitAssigns.java#L207-L219 |
24,969 | google/closure-compiler | src/com/google/javascript/jscomp/regex/RegExpTree.java | RegExpTree.matchesWholeInput | public static boolean matchesWholeInput(RegExpTree t, String flags) {
if (flags.indexOf('m') >= 0) { return false; }
if (!(t instanceof Concatenation)) {
return false;
}
Concatenation c = (Concatenation) t;
if (c.elements.isEmpty()) { return false; }
RegExpTree first = c.elements.get(0), last = Iterables.getLast(c.elements);
if (!(first instanceof Anchor && last instanceof Anchor)) { return false; }
return ((Anchor) first).type == '^' && ((Anchor) last).type == '$';
} | java | public static boolean matchesWholeInput(RegExpTree t, String flags) {
if (flags.indexOf('m') >= 0) { return false; }
if (!(t instanceof Concatenation)) {
return false;
}
Concatenation c = (Concatenation) t;
if (c.elements.isEmpty()) { return false; }
RegExpTree first = c.elements.get(0), last = Iterables.getLast(c.elements);
if (!(first instanceof Anchor && last instanceof Anchor)) { return false; }
return ((Anchor) first).type == '^' && ((Anchor) last).type == '$';
} | [
"public",
"static",
"boolean",
"matchesWholeInput",
"(",
"RegExpTree",
"t",
",",
"String",
"flags",
")",
"{",
"if",
"(",
"flags",
".",
"indexOf",
"(",
"'",
"'",
")",
">=",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"(",
"t",
"instanceof",
"Concatenation",
")",
")",
"{",
"return",
"false",
";",
"}",
"Concatenation",
"c",
"=",
"(",
"Concatenation",
")",
"t",
";",
"if",
"(",
"c",
".",
"elements",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"RegExpTree",
"first",
"=",
"c",
".",
"elements",
".",
"get",
"(",
"0",
")",
",",
"last",
"=",
"Iterables",
".",
"getLast",
"(",
"c",
".",
"elements",
")",
";",
"if",
"(",
"!",
"(",
"first",
"instanceof",
"Anchor",
"&&",
"last",
"instanceof",
"Anchor",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"(",
"Anchor",
")",
"first",
")",
".",
"type",
"==",
"'",
"'",
"&&",
"(",
"(",
"Anchor",
")",
"last",
")",
".",
"type",
"==",
"'",
"'",
";",
"}"
] | True if, but not necessarily always when the, given regular expression
must match the whole input or none of it. | [
"True",
"if",
"but",
"not",
"necessarily",
"always",
"when",
"the",
"given",
"regular",
"expression",
"must",
"match",
"the",
"whole",
"input",
"or",
"none",
"of",
"it",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/regex/RegExpTree.java#L759-L771 |
24,970 | google/closure-compiler | src/com/google/javascript/jscomp/DefaultPassConfig.java | DefaultPassConfig.getMainOptimizationLoop | private List<PassFactory> getMainOptimizationLoop() {
List<PassFactory> passes = new ArrayList<>();
if (options.inlineGetters) {
passes.add(inlineSimpleMethods);
}
passes.addAll(getCodeRemovingPasses());
if (options.getInlineFunctionsLevel() != Reach.NONE) {
passes.add(inlineFunctions);
}
if (options.shouldInlineProperties() && options.isTypecheckingEnabled()) {
passes.add(inlineProperties);
}
if (options.removeUnusedVars || options.removeUnusedLocalVars) {
if (options.deadAssignmentElimination) {
passes.add(deadAssignmentsElimination);
// The Polymer source is usually not included in the compilation, but it creates
// getters/setters for many properties in compiled code. Dead property assignment
// elimination is only safe when it knows about getters/setters. Therefore, we skip
// it if the polymer pass is enabled.
if (options.polymerVersion == null) {
passes.add(deadPropertyAssignmentElimination);
}
}
}
if (options.optimizeCalls) {
passes.add(optimizeCalls);
}
if (options.j2clPassMode.shouldAddJ2clPasses()) {
passes.add(j2clConstantHoisterPass);
passes.add(j2clClinitPass);
}
assertAllLoopablePasses(passes);
return passes;
} | java | private List<PassFactory> getMainOptimizationLoop() {
List<PassFactory> passes = new ArrayList<>();
if (options.inlineGetters) {
passes.add(inlineSimpleMethods);
}
passes.addAll(getCodeRemovingPasses());
if (options.getInlineFunctionsLevel() != Reach.NONE) {
passes.add(inlineFunctions);
}
if (options.shouldInlineProperties() && options.isTypecheckingEnabled()) {
passes.add(inlineProperties);
}
if (options.removeUnusedVars || options.removeUnusedLocalVars) {
if (options.deadAssignmentElimination) {
passes.add(deadAssignmentsElimination);
// The Polymer source is usually not included in the compilation, but it creates
// getters/setters for many properties in compiled code. Dead property assignment
// elimination is only safe when it knows about getters/setters. Therefore, we skip
// it if the polymer pass is enabled.
if (options.polymerVersion == null) {
passes.add(deadPropertyAssignmentElimination);
}
}
}
if (options.optimizeCalls) {
passes.add(optimizeCalls);
}
if (options.j2clPassMode.shouldAddJ2clPasses()) {
passes.add(j2clConstantHoisterPass);
passes.add(j2clClinitPass);
}
assertAllLoopablePasses(passes);
return passes;
} | [
"private",
"List",
"<",
"PassFactory",
">",
"getMainOptimizationLoop",
"(",
")",
"{",
"List",
"<",
"PassFactory",
">",
"passes",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"options",
".",
"inlineGetters",
")",
"{",
"passes",
".",
"add",
"(",
"inlineSimpleMethods",
")",
";",
"}",
"passes",
".",
"addAll",
"(",
"getCodeRemovingPasses",
"(",
")",
")",
";",
"if",
"(",
"options",
".",
"getInlineFunctionsLevel",
"(",
")",
"!=",
"Reach",
".",
"NONE",
")",
"{",
"passes",
".",
"add",
"(",
"inlineFunctions",
")",
";",
"}",
"if",
"(",
"options",
".",
"shouldInlineProperties",
"(",
")",
"&&",
"options",
".",
"isTypecheckingEnabled",
"(",
")",
")",
"{",
"passes",
".",
"add",
"(",
"inlineProperties",
")",
";",
"}",
"if",
"(",
"options",
".",
"removeUnusedVars",
"||",
"options",
".",
"removeUnusedLocalVars",
")",
"{",
"if",
"(",
"options",
".",
"deadAssignmentElimination",
")",
"{",
"passes",
".",
"add",
"(",
"deadAssignmentsElimination",
")",
";",
"// The Polymer source is usually not included in the compilation, but it creates",
"// getters/setters for many properties in compiled code. Dead property assignment",
"// elimination is only safe when it knows about getters/setters. Therefore, we skip",
"// it if the polymer pass is enabled.",
"if",
"(",
"options",
".",
"polymerVersion",
"==",
"null",
")",
"{",
"passes",
".",
"add",
"(",
"deadPropertyAssignmentElimination",
")",
";",
"}",
"}",
"}",
"if",
"(",
"options",
".",
"optimizeCalls",
")",
"{",
"passes",
".",
"add",
"(",
"optimizeCalls",
")",
";",
"}",
"if",
"(",
"options",
".",
"j2clPassMode",
".",
"shouldAddJ2clPasses",
"(",
")",
")",
"{",
"passes",
".",
"add",
"(",
"j2clConstantHoisterPass",
")",
";",
"passes",
".",
"add",
"(",
"j2clClinitPass",
")",
";",
"}",
"assertAllLoopablePasses",
"(",
"passes",
")",
";",
"return",
"passes",
";",
"}"
] | Creates the passes for the main optimization loop. | [
"Creates",
"the",
"passes",
"for",
"the",
"main",
"optimization",
"loop",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DefaultPassConfig.java#L865-L906 |
24,971 | google/closure-compiler | src/com/google/javascript/jscomp/DefaultPassConfig.java | DefaultPassConfig.getCodeRemovingPasses | private List<PassFactory> getCodeRemovingPasses() {
List<PassFactory> passes = new ArrayList<>();
if (options.collapseObjectLiterals) {
passes.add(collapseObjectLiterals);
}
if (options.inlineVariables || options.inlineLocalVariables) {
passes.add(inlineVariables);
} else if (options.inlineConstantVars) {
passes.add(inlineConstants);
}
if (options.foldConstants) {
passes.add(peepholeOptimizations);
}
if (options.removeDeadCode) {
passes.add(removeUnreachableCode);
}
if (shouldRunRemoveUnusedCode()) {
passes.add(removeUnusedCode);
}
assertAllLoopablePasses(passes);
return passes;
} | java | private List<PassFactory> getCodeRemovingPasses() {
List<PassFactory> passes = new ArrayList<>();
if (options.collapseObjectLiterals) {
passes.add(collapseObjectLiterals);
}
if (options.inlineVariables || options.inlineLocalVariables) {
passes.add(inlineVariables);
} else if (options.inlineConstantVars) {
passes.add(inlineConstants);
}
if (options.foldConstants) {
passes.add(peepholeOptimizations);
}
if (options.removeDeadCode) {
passes.add(removeUnreachableCode);
}
if (shouldRunRemoveUnusedCode()) {
passes.add(removeUnusedCode);
}
assertAllLoopablePasses(passes);
return passes;
} | [
"private",
"List",
"<",
"PassFactory",
">",
"getCodeRemovingPasses",
"(",
")",
"{",
"List",
"<",
"PassFactory",
">",
"passes",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"options",
".",
"collapseObjectLiterals",
")",
"{",
"passes",
".",
"add",
"(",
"collapseObjectLiterals",
")",
";",
"}",
"if",
"(",
"options",
".",
"inlineVariables",
"||",
"options",
".",
"inlineLocalVariables",
")",
"{",
"passes",
".",
"add",
"(",
"inlineVariables",
")",
";",
"}",
"else",
"if",
"(",
"options",
".",
"inlineConstantVars",
")",
"{",
"passes",
".",
"add",
"(",
"inlineConstants",
")",
";",
"}",
"if",
"(",
"options",
".",
"foldConstants",
")",
"{",
"passes",
".",
"add",
"(",
"peepholeOptimizations",
")",
";",
"}",
"if",
"(",
"options",
".",
"removeDeadCode",
")",
"{",
"passes",
".",
"add",
"(",
"removeUnreachableCode",
")",
";",
"}",
"if",
"(",
"shouldRunRemoveUnusedCode",
"(",
")",
")",
"{",
"passes",
".",
"add",
"(",
"removeUnusedCode",
")",
";",
"}",
"assertAllLoopablePasses",
"(",
"passes",
")",
";",
"return",
"passes",
";",
"}"
] | Creates several passes aimed at removing code. | [
"Creates",
"several",
"passes",
"aimed",
"at",
"removing",
"code",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DefaultPassConfig.java#L909-L935 |
24,972 | google/closure-compiler | src/com/google/javascript/jscomp/DefaultPassConfig.java | DefaultPassConfig.assertAllOneTimePasses | private static void assertAllOneTimePasses(List<PassFactory> passes) {
for (PassFactory pass : passes) {
checkState(pass.isOneTimePass());
}
} | java | private static void assertAllOneTimePasses(List<PassFactory> passes) {
for (PassFactory pass : passes) {
checkState(pass.isOneTimePass());
}
} | [
"private",
"static",
"void",
"assertAllOneTimePasses",
"(",
"List",
"<",
"PassFactory",
">",
"passes",
")",
"{",
"for",
"(",
"PassFactory",
"pass",
":",
"passes",
")",
"{",
"checkState",
"(",
"pass",
".",
"isOneTimePass",
"(",
")",
")",
";",
"}",
"}"
] | Verify that all the passes are one-time passes. | [
"Verify",
"that",
"all",
"the",
"passes",
"are",
"one",
"-",
"time",
"passes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DefaultPassConfig.java#L1003-L1007 |
24,973 | google/closure-compiler | src/com/google/javascript/jscomp/DefaultPassConfig.java | DefaultPassConfig.assertAllLoopablePasses | private static void assertAllLoopablePasses(List<PassFactory> passes) {
for (PassFactory pass : passes) {
checkState(!pass.isOneTimePass());
}
} | java | private static void assertAllLoopablePasses(List<PassFactory> passes) {
for (PassFactory pass : passes) {
checkState(!pass.isOneTimePass());
}
} | [
"private",
"static",
"void",
"assertAllLoopablePasses",
"(",
"List",
"<",
"PassFactory",
">",
"passes",
")",
"{",
"for",
"(",
"PassFactory",
"pass",
":",
"passes",
")",
"{",
"checkState",
"(",
"!",
"pass",
".",
"isOneTimePass",
"(",
")",
")",
";",
"}",
"}"
] | Verify that all the passes are multi-run passes. | [
"Verify",
"that",
"all",
"the",
"passes",
"are",
"multi",
"-",
"run",
"passes",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DefaultPassConfig.java#L1010-L1014 |
24,974 | google/closure-compiler | src/com/google/javascript/jscomp/DefaultPassConfig.java | DefaultPassConfig.createPeepholeOptimizationsPass | private static CompilerPass createPeepholeOptimizationsPass(
AbstractCompiler compiler, String passName) {
final boolean late = false;
final boolean useTypesForOptimization = compiler.getOptions().useTypesForLocalOptimization;
List<AbstractPeepholeOptimization> optimizations = new ArrayList<>();
optimizations.add(new MinimizeExitPoints());
optimizations.add(new PeepholeMinimizeConditions(late));
optimizations.add(new PeepholeSubstituteAlternateSyntax(late));
optimizations.add(new PeepholeReplaceKnownMethods(late, useTypesForOptimization));
optimizations.add(new PeepholeRemoveDeadCode());
if (compiler.getOptions().j2clPassMode.shouldAddJ2clPasses()) {
optimizations.add(new J2clEqualitySameRewriterPass(useTypesForOptimization));
optimizations.add(new J2clStringValueOfRewriterPass());
}
optimizations.add(new PeepholeFoldConstants(late, useTypesForOptimization));
optimizations.add(new PeepholeCollectPropertyAssignments());
return new PeepholeOptimizationsPass(compiler, passName, optimizations);
} | java | private static CompilerPass createPeepholeOptimizationsPass(
AbstractCompiler compiler, String passName) {
final boolean late = false;
final boolean useTypesForOptimization = compiler.getOptions().useTypesForLocalOptimization;
List<AbstractPeepholeOptimization> optimizations = new ArrayList<>();
optimizations.add(new MinimizeExitPoints());
optimizations.add(new PeepholeMinimizeConditions(late));
optimizations.add(new PeepholeSubstituteAlternateSyntax(late));
optimizations.add(new PeepholeReplaceKnownMethods(late, useTypesForOptimization));
optimizations.add(new PeepholeRemoveDeadCode());
if (compiler.getOptions().j2clPassMode.shouldAddJ2clPasses()) {
optimizations.add(new J2clEqualitySameRewriterPass(useTypesForOptimization));
optimizations.add(new J2clStringValueOfRewriterPass());
}
optimizations.add(new PeepholeFoldConstants(late, useTypesForOptimization));
optimizations.add(new PeepholeCollectPropertyAssignments());
return new PeepholeOptimizationsPass(compiler, passName, optimizations);
} | [
"private",
"static",
"CompilerPass",
"createPeepholeOptimizationsPass",
"(",
"AbstractCompiler",
"compiler",
",",
"String",
"passName",
")",
"{",
"final",
"boolean",
"late",
"=",
"false",
";",
"final",
"boolean",
"useTypesForOptimization",
"=",
"compiler",
".",
"getOptions",
"(",
")",
".",
"useTypesForLocalOptimization",
";",
"List",
"<",
"AbstractPeepholeOptimization",
">",
"optimizations",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"optimizations",
".",
"add",
"(",
"new",
"MinimizeExitPoints",
"(",
")",
")",
";",
"optimizations",
".",
"add",
"(",
"new",
"PeepholeMinimizeConditions",
"(",
"late",
")",
")",
";",
"optimizations",
".",
"add",
"(",
"new",
"PeepholeSubstituteAlternateSyntax",
"(",
"late",
")",
")",
";",
"optimizations",
".",
"add",
"(",
"new",
"PeepholeReplaceKnownMethods",
"(",
"late",
",",
"useTypesForOptimization",
")",
")",
";",
"optimizations",
".",
"add",
"(",
"new",
"PeepholeRemoveDeadCode",
"(",
")",
")",
";",
"if",
"(",
"compiler",
".",
"getOptions",
"(",
")",
".",
"j2clPassMode",
".",
"shouldAddJ2clPasses",
"(",
")",
")",
"{",
"optimizations",
".",
"add",
"(",
"new",
"J2clEqualitySameRewriterPass",
"(",
"useTypesForOptimization",
")",
")",
";",
"optimizations",
".",
"add",
"(",
"new",
"J2clStringValueOfRewriterPass",
"(",
")",
")",
";",
"}",
"optimizations",
".",
"add",
"(",
"new",
"PeepholeFoldConstants",
"(",
"late",
",",
"useTypesForOptimization",
")",
")",
";",
"optimizations",
".",
"add",
"(",
"new",
"PeepholeCollectPropertyAssignments",
"(",
")",
")",
";",
"return",
"new",
"PeepholeOptimizationsPass",
"(",
"compiler",
",",
"passName",
",",
"optimizations",
")",
";",
"}"
] | Various peephole optimizations. | [
"Various",
"peephole",
"optimizations",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DefaultPassConfig.java#L1702-L1719 |
24,975 | google/closure-compiler | src/com/google/javascript/jscomp/DefaultPassConfig.java | DefaultPassConfig.runInSerial | private static CompilerPass runInSerial(
final Collection<CompilerPass> passes) {
return new CompilerPass() {
@Override public void process(Node externs, Node root) {
for (CompilerPass pass : passes) {
pass.process(externs, root);
}
}
};
} | java | private static CompilerPass runInSerial(
final Collection<CompilerPass> passes) {
return new CompilerPass() {
@Override public void process(Node externs, Node root) {
for (CompilerPass pass : passes) {
pass.process(externs, root);
}
}
};
} | [
"private",
"static",
"CompilerPass",
"runInSerial",
"(",
"final",
"Collection",
"<",
"CompilerPass",
">",
"passes",
")",
"{",
"return",
"new",
"CompilerPass",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(",
"Node",
"externs",
",",
"Node",
"root",
")",
"{",
"for",
"(",
"CompilerPass",
"pass",
":",
"passes",
")",
"{",
"pass",
".",
"process",
"(",
"externs",
",",
"root",
")",
";",
"}",
"}",
"}",
";",
"}"
] | Create a compiler pass that runs the given passes in serial. | [
"Create",
"a",
"compiler",
"pass",
"that",
"runs",
"the",
"given",
"passes",
"in",
"serial",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/DefaultPassConfig.java#L3190-L3199 |
24,976 | google/closure-compiler | src/com/google/javascript/jscomp/deps/DepsFileParser.java | DepsFileParser.parseFile | public List<DependencyInfo> parseFile(String filePath) throws IOException {
return parseFileReader(filePath, Files.newReader(new File(filePath), StandardCharsets.UTF_8));
} | java | public List<DependencyInfo> parseFile(String filePath) throws IOException {
return parseFileReader(filePath, Files.newReader(new File(filePath), StandardCharsets.UTF_8));
} | [
"public",
"List",
"<",
"DependencyInfo",
">",
"parseFile",
"(",
"String",
"filePath",
")",
"throws",
"IOException",
"{",
"return",
"parseFileReader",
"(",
"filePath",
",",
"Files",
".",
"newReader",
"(",
"new",
"File",
"(",
"filePath",
")",
",",
"StandardCharsets",
".",
"UTF_8",
")",
")",
";",
"}"
] | Parses the given file and returns a list of dependency information that it
contained.
@param filePath Path to the file to parse.
@return A list of DependencyInfo objects.
@throws IOException Thrown if the file could not be read. | [
"Parses",
"the",
"given",
"file",
"and",
"returns",
"a",
"list",
"of",
"dependency",
"information",
"that",
"it",
"contained",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/DepsFileParser.java#L105-L107 |
24,977 | google/closure-compiler | src/com/google/javascript/jscomp/deps/DepsFileParser.java | DepsFileParser.parseFile | public List<DependencyInfo> parseFile(String filePath, String fileContents) {
return parseFileReader(filePath, new StringReader(fileContents));
} | java | public List<DependencyInfo> parseFile(String filePath, String fileContents) {
return parseFileReader(filePath, new StringReader(fileContents));
} | [
"public",
"List",
"<",
"DependencyInfo",
">",
"parseFile",
"(",
"String",
"filePath",
",",
"String",
"fileContents",
")",
"{",
"return",
"parseFileReader",
"(",
"filePath",
",",
"new",
"StringReader",
"(",
"fileContents",
")",
")",
";",
"}"
] | Parses the given file and returns a list of dependency information that it
contained.
It uses the passed in fileContents instead of reading the file.
@param filePath Path to the file to parse.
@param fileContents The contents to parse.
@return A list of DependencyInfo objects. | [
"Parses",
"the",
"given",
"file",
"and",
"returns",
"a",
"list",
"of",
"dependency",
"information",
"that",
"it",
"contained",
".",
"It",
"uses",
"the",
"passed",
"in",
"fileContents",
"instead",
"of",
"reading",
"the",
"file",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/DepsFileParser.java#L118-L120 |
24,978 | google/closure-compiler | src/com/google/javascript/jscomp/deps/DepsFileParser.java | DepsFileParser.parseFileReader | public List<DependencyInfo> parseFileReader(String filePath, Reader reader) {
depInfos = new ArrayList<>();
if (logger.isLoggable(Level.FINE)) {
logger.fine("Parsing Dep: " + filePath);
}
doParse(filePath, reader);
return depInfos;
} | java | public List<DependencyInfo> parseFileReader(String filePath, Reader reader) {
depInfos = new ArrayList<>();
if (logger.isLoggable(Level.FINE)) {
logger.fine("Parsing Dep: " + filePath);
}
doParse(filePath, reader);
return depInfos;
} | [
"public",
"List",
"<",
"DependencyInfo",
">",
"parseFileReader",
"(",
"String",
"filePath",
",",
"Reader",
"reader",
")",
"{",
"depInfos",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"if",
"(",
"logger",
".",
"isLoggable",
"(",
"Level",
".",
"FINE",
")",
")",
"{",
"logger",
".",
"fine",
"(",
"\"Parsing Dep: \"",
"+",
"filePath",
")",
";",
"}",
"doParse",
"(",
"filePath",
",",
"reader",
")",
";",
"return",
"depInfos",
";",
"}"
] | Parses the file from the given reader and returns a list of
dependency information that it contained.
@param filePath Path to the file to parse.
@param reader A reader for the file.
@return A list of DependencyInfo objects. | [
"Parses",
"the",
"file",
"from",
"the",
"given",
"reader",
"and",
"returns",
"a",
"list",
"of",
"dependency",
"information",
"that",
"it",
"contained",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/deps/DepsFileParser.java#L131-L138 |
24,979 | google/closure-compiler | src/com/google/javascript/jscomp/J2clChecksPass.java | J2clChecksPass.checkReferenceEquality | private void checkReferenceEquality(Node n, String typeName, String fileName) {
if (n.getToken() == Token.SHEQ
|| n.getToken() == Token.EQ
|| n.getToken() == Token.SHNE
|| n.getToken() == Token.NE) {
JSType firstJsType = n.getFirstChild().getJSType();
JSType lastJsType = n.getLastChild().getJSType();
boolean hasType = isType(firstJsType, fileName) || isType(lastJsType, fileName);
boolean hasNullType = isNullType(firstJsType) || isNullType(lastJsType);
if (hasType && !hasNullType) {
compiler.report(JSError.make(n, J2CL_REFERENCE_EQUALITY, typeName));
}
}
} | java | private void checkReferenceEquality(Node n, String typeName, String fileName) {
if (n.getToken() == Token.SHEQ
|| n.getToken() == Token.EQ
|| n.getToken() == Token.SHNE
|| n.getToken() == Token.NE) {
JSType firstJsType = n.getFirstChild().getJSType();
JSType lastJsType = n.getLastChild().getJSType();
boolean hasType = isType(firstJsType, fileName) || isType(lastJsType, fileName);
boolean hasNullType = isNullType(firstJsType) || isNullType(lastJsType);
if (hasType && !hasNullType) {
compiler.report(JSError.make(n, J2CL_REFERENCE_EQUALITY, typeName));
}
}
} | [
"private",
"void",
"checkReferenceEquality",
"(",
"Node",
"n",
",",
"String",
"typeName",
",",
"String",
"fileName",
")",
"{",
"if",
"(",
"n",
".",
"getToken",
"(",
")",
"==",
"Token",
".",
"SHEQ",
"||",
"n",
".",
"getToken",
"(",
")",
"==",
"Token",
".",
"EQ",
"||",
"n",
".",
"getToken",
"(",
")",
"==",
"Token",
".",
"SHNE",
"||",
"n",
".",
"getToken",
"(",
")",
"==",
"Token",
".",
"NE",
")",
"{",
"JSType",
"firstJsType",
"=",
"n",
".",
"getFirstChild",
"(",
")",
".",
"getJSType",
"(",
")",
";",
"JSType",
"lastJsType",
"=",
"n",
".",
"getLastChild",
"(",
")",
".",
"getJSType",
"(",
")",
";",
"boolean",
"hasType",
"=",
"isType",
"(",
"firstJsType",
",",
"fileName",
")",
"||",
"isType",
"(",
"lastJsType",
",",
"fileName",
")",
";",
"boolean",
"hasNullType",
"=",
"isNullType",
"(",
"firstJsType",
")",
"||",
"isNullType",
"(",
"lastJsType",
")",
";",
"if",
"(",
"hasType",
"&&",
"!",
"hasNullType",
")",
"{",
"compiler",
".",
"report",
"(",
"JSError",
".",
"make",
"(",
"n",
",",
"J2CL_REFERENCE_EQUALITY",
",",
"typeName",
")",
")",
";",
"}",
"}",
"}"
] | Reports an error if the node is a reference equality check of the specified type. | [
"Reports",
"an",
"error",
"if",
"the",
"node",
"is",
"a",
"reference",
"equality",
"check",
"of",
"the",
"specified",
"type",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/J2clChecksPass.java#L56-L69 |
24,980 | google/closure-compiler | src/com/google/javascript/jscomp/Result.java | Result.createResultForStage1 | public static Result createResultForStage1(Result result) {
VariableMap emptyVariableMap = new VariableMap(ImmutableMap.of());
return new Result(
result.errors,
result.warnings,
emptyVariableMap,
emptyVariableMap,
emptyVariableMap,
null,
null,
"",
null,
null,
null);
} | java | public static Result createResultForStage1(Result result) {
VariableMap emptyVariableMap = new VariableMap(ImmutableMap.of());
return new Result(
result.errors,
result.warnings,
emptyVariableMap,
emptyVariableMap,
emptyVariableMap,
null,
null,
"",
null,
null,
null);
} | [
"public",
"static",
"Result",
"createResultForStage1",
"(",
"Result",
"result",
")",
"{",
"VariableMap",
"emptyVariableMap",
"=",
"new",
"VariableMap",
"(",
"ImmutableMap",
".",
"of",
"(",
")",
")",
";",
"return",
"new",
"Result",
"(",
"result",
".",
"errors",
",",
"result",
".",
"warnings",
",",
"emptyVariableMap",
",",
"emptyVariableMap",
",",
"emptyVariableMap",
",",
"null",
",",
"null",
",",
"\"\"",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"}"
] | Returns an almost empty result that is used for multistage compilation.
<p>For multistage compilations, Result for stage1 only cares about errors and warnings. It is
unnecessary to write all of other results in the disk. | [
"Returns",
"an",
"almost",
"empty",
"result",
"that",
"is",
"used",
"for",
"multistage",
"compilation",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Result.java#L99-L113 |
24,981 | google/closure-compiler | src/com/google/javascript/refactoring/RefactoringDriver.java | RefactoringDriver.drive | public List<SuggestedFix> drive(Scanner scanner, Pattern includeFilePattern) {
JsFlumeCallback callback = new JsFlumeCallback(scanner, includeFilePattern);
NodeTraversal.traverse(compiler, rootNode, callback);
List<SuggestedFix> fixes = callback.getFixes();
fixes.addAll(scanner.processAllMatches(callback.getMatches()));
return fixes;
} | java | public List<SuggestedFix> drive(Scanner scanner, Pattern includeFilePattern) {
JsFlumeCallback callback = new JsFlumeCallback(scanner, includeFilePattern);
NodeTraversal.traverse(compiler, rootNode, callback);
List<SuggestedFix> fixes = callback.getFixes();
fixes.addAll(scanner.processAllMatches(callback.getMatches()));
return fixes;
} | [
"public",
"List",
"<",
"SuggestedFix",
">",
"drive",
"(",
"Scanner",
"scanner",
",",
"Pattern",
"includeFilePattern",
")",
"{",
"JsFlumeCallback",
"callback",
"=",
"new",
"JsFlumeCallback",
"(",
"scanner",
",",
"includeFilePattern",
")",
";",
"NodeTraversal",
".",
"traverse",
"(",
"compiler",
",",
"rootNode",
",",
"callback",
")",
";",
"List",
"<",
"SuggestedFix",
">",
"fixes",
"=",
"callback",
".",
"getFixes",
"(",
")",
";",
"fixes",
".",
"addAll",
"(",
"scanner",
".",
"processAllMatches",
"(",
"callback",
".",
"getMatches",
"(",
")",
")",
")",
";",
"return",
"fixes",
";",
"}"
] | Run a refactoring and return any suggested fixes as a result. | [
"Run",
"a",
"refactoring",
"and",
"return",
"any",
"suggested",
"fixes",
"as",
"a",
"result",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/RefactoringDriver.java#L59-L65 |
24,982 | google/closure-compiler | src/com/google/javascript/refactoring/RefactoringDriver.java | RefactoringDriver.getCompilerOptions | @VisibleForTesting
public static CompilerOptions getCompilerOptions() {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setSummaryDetailLevel(0);
options.setDependencyOptions(DependencyOptions.sortOnly());
options.setChecksOnly(true);
options.setContinueAfterErrors(true);
options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
options.setCheckSuspiciousCode(true);
options.setCheckSymbols(true);
options.setCheckTypes(true);
options.setBrokenClosureRequiresLevel(CheckLevel.OFF);
// TODO(bangert): Remove this -- we want to rewrite code before closure syntax is removed.
// Unfortunately, setClosurePass is required, or code doesn't type check.
options.setClosurePass(true);
options.setGenerateExports(true);
options.setPreserveClosurePrimitives(true);
options.setWarningLevel(DiagnosticGroups.STRICT_MISSING_REQUIRE, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.EXTRA_REQUIRE, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING);
return options;
} | java | @VisibleForTesting
public static CompilerOptions getCompilerOptions() {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setSummaryDetailLevel(0);
options.setDependencyOptions(DependencyOptions.sortOnly());
options.setChecksOnly(true);
options.setContinueAfterErrors(true);
options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
options.setCheckSuspiciousCode(true);
options.setCheckSymbols(true);
options.setCheckTypes(true);
options.setBrokenClosureRequiresLevel(CheckLevel.OFF);
// TODO(bangert): Remove this -- we want to rewrite code before closure syntax is removed.
// Unfortunately, setClosurePass is required, or code doesn't type check.
options.setClosurePass(true);
options.setGenerateExports(true);
options.setPreserveClosurePrimitives(true);
options.setWarningLevel(DiagnosticGroups.STRICT_MISSING_REQUIRE, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.EXTRA_REQUIRE, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING);
return options;
} | [
"@",
"VisibleForTesting",
"public",
"static",
"CompilerOptions",
"getCompilerOptions",
"(",
")",
"{",
"CompilerOptions",
"options",
"=",
"new",
"CompilerOptions",
"(",
")",
";",
"options",
".",
"setLanguageIn",
"(",
"LanguageMode",
".",
"ECMASCRIPT_NEXT",
")",
";",
"options",
".",
"setLanguageOut",
"(",
"LanguageMode",
".",
"ECMASCRIPT5",
")",
";",
"options",
".",
"setSummaryDetailLevel",
"(",
"0",
")",
";",
"options",
".",
"setDependencyOptions",
"(",
"DependencyOptions",
".",
"sortOnly",
"(",
")",
")",
";",
"options",
".",
"setChecksOnly",
"(",
"true",
")",
";",
"options",
".",
"setContinueAfterErrors",
"(",
"true",
")",
";",
"options",
".",
"setParseJsDocDocumentation",
"(",
"Config",
".",
"JsDocParsing",
".",
"INCLUDE_DESCRIPTIONS_NO_WHITESPACE",
")",
";",
"options",
".",
"setCheckSuspiciousCode",
"(",
"true",
")",
";",
"options",
".",
"setCheckSymbols",
"(",
"true",
")",
";",
"options",
".",
"setCheckTypes",
"(",
"true",
")",
";",
"options",
".",
"setBrokenClosureRequiresLevel",
"(",
"CheckLevel",
".",
"OFF",
")",
";",
"// TODO(bangert): Remove this -- we want to rewrite code before closure syntax is removed.",
"// Unfortunately, setClosurePass is required, or code doesn't type check.",
"options",
".",
"setClosurePass",
"(",
"true",
")",
";",
"options",
".",
"setGenerateExports",
"(",
"true",
")",
";",
"options",
".",
"setPreserveClosurePrimitives",
"(",
"true",
")",
";",
"options",
".",
"setWarningLevel",
"(",
"DiagnosticGroups",
".",
"STRICT_MISSING_REQUIRE",
",",
"CheckLevel",
".",
"WARNING",
")",
";",
"options",
".",
"setWarningLevel",
"(",
"DiagnosticGroups",
".",
"EXTRA_REQUIRE",
",",
"CheckLevel",
".",
"WARNING",
")",
";",
"options",
".",
"setWarningLevel",
"(",
"DiagnosticGroups",
".",
"LINT_CHECKS",
",",
"CheckLevel",
".",
"WARNING",
")",
";",
"return",
"options",
";",
"}"
] | don't need to call it directly. | [
"don",
"t",
"need",
"to",
"call",
"it",
"directly",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/RefactoringDriver.java#L86-L113 |
24,983 | google/closure-compiler | src/com/google/javascript/jscomp/InlineSimpleMethods.java | InlineSimpleMethods.isPropertyTree | private static boolean isPropertyTree(Node expectedGetprop) {
if (!expectedGetprop.isGetProp()) {
return false;
}
Node leftChild = expectedGetprop.getFirstChild();
if (!leftChild.isThis() && !isPropertyTree(leftChild)) {
return false;
}
Node retVal = leftChild.getNext();
return NodeUtil.getStringValue(retVal) != null;
} | java | private static boolean isPropertyTree(Node expectedGetprop) {
if (!expectedGetprop.isGetProp()) {
return false;
}
Node leftChild = expectedGetprop.getFirstChild();
if (!leftChild.isThis() && !isPropertyTree(leftChild)) {
return false;
}
Node retVal = leftChild.getNext();
return NodeUtil.getStringValue(retVal) != null;
} | [
"private",
"static",
"boolean",
"isPropertyTree",
"(",
"Node",
"expectedGetprop",
")",
"{",
"if",
"(",
"!",
"expectedGetprop",
".",
"isGetProp",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"Node",
"leftChild",
"=",
"expectedGetprop",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"!",
"leftChild",
".",
"isThis",
"(",
")",
"&&",
"!",
"isPropertyTree",
"(",
"leftChild",
")",
")",
"{",
"return",
"false",
";",
"}",
"Node",
"retVal",
"=",
"leftChild",
".",
"getNext",
"(",
")",
";",
"return",
"NodeUtil",
".",
"getStringValue",
"(",
"retVal",
")",
"!=",
"null",
";",
"}"
] | Returns true if the provided node is a getprop for
which the left child is this or a valid property tree
and for which the right side is a string. | [
"Returns",
"true",
"if",
"the",
"provided",
"node",
"is",
"a",
"getprop",
"for",
"which",
"the",
"left",
"child",
"is",
"this",
"or",
"a",
"valid",
"property",
"tree",
"and",
"for",
"which",
"the",
"right",
"side",
"is",
"a",
"string",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/InlineSimpleMethods.java#L138-L150 |
24,984 | google/closure-compiler | src/com/google/javascript/jscomp/InlineSimpleMethods.java | InlineSimpleMethods.replaceThis | private static void replaceThis(Node expectedGetprop, Node replacement) {
Node leftChild = expectedGetprop.getFirstChild();
if (leftChild.isThis()) {
expectedGetprop.replaceChild(leftChild, replacement);
} else {
replaceThis(leftChild, replacement);
}
} | java | private static void replaceThis(Node expectedGetprop, Node replacement) {
Node leftChild = expectedGetprop.getFirstChild();
if (leftChild.isThis()) {
expectedGetprop.replaceChild(leftChild, replacement);
} else {
replaceThis(leftChild, replacement);
}
} | [
"private",
"static",
"void",
"replaceThis",
"(",
"Node",
"expectedGetprop",
",",
"Node",
"replacement",
")",
"{",
"Node",
"leftChild",
"=",
"expectedGetprop",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"leftChild",
".",
"isThis",
"(",
")",
")",
"{",
"expectedGetprop",
".",
"replaceChild",
"(",
"leftChild",
",",
"replacement",
")",
";",
"}",
"else",
"{",
"replaceThis",
"(",
"leftChild",
",",
"replacement",
")",
";",
"}",
"}"
] | Finds the occurrence of "this" in the provided property tree and replaces
it with replacement | [
"Finds",
"the",
"occurrence",
"of",
"this",
"in",
"the",
"provided",
"property",
"tree",
"and",
"replaces",
"it",
"with",
"replacement"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/InlineSimpleMethods.java#L156-L163 |
24,985 | google/closure-compiler | src/com/google/javascript/jscomp/InlineSimpleMethods.java | InlineSimpleMethods.returnedExpression | private static Node returnedExpression(Node fn) {
Node expectedBlock = NodeUtil.getFunctionBody(fn);
if (!expectedBlock.hasOneChild()) {
return null;
}
Node expectedReturn = expectedBlock.getFirstChild();
if (!expectedReturn.isReturn()) {
return null;
}
if (!expectedReturn.hasOneChild()) {
return null;
}
return expectedReturn.getOnlyChild();
} | java | private static Node returnedExpression(Node fn) {
Node expectedBlock = NodeUtil.getFunctionBody(fn);
if (!expectedBlock.hasOneChild()) {
return null;
}
Node expectedReturn = expectedBlock.getFirstChild();
if (!expectedReturn.isReturn()) {
return null;
}
if (!expectedReturn.hasOneChild()) {
return null;
}
return expectedReturn.getOnlyChild();
} | [
"private",
"static",
"Node",
"returnedExpression",
"(",
"Node",
"fn",
")",
"{",
"Node",
"expectedBlock",
"=",
"NodeUtil",
".",
"getFunctionBody",
"(",
"fn",
")",
";",
"if",
"(",
"!",
"expectedBlock",
".",
"hasOneChild",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"Node",
"expectedReturn",
"=",
"expectedBlock",
".",
"getFirstChild",
"(",
")",
";",
"if",
"(",
"!",
"expectedReturn",
".",
"isReturn",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"expectedReturn",
".",
"hasOneChild",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"expectedReturn",
".",
"getOnlyChild",
"(",
")",
";",
"}"
] | Return the node that represents the expression returned
by the method, given a FUNCTION node. | [
"Return",
"the",
"node",
"that",
"represents",
"the",
"expression",
"returned",
"by",
"the",
"method",
"given",
"a",
"FUNCTION",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/InlineSimpleMethods.java#L169-L185 |
24,986 | google/closure-compiler | src/com/google/javascript/jscomp/InlineSimpleMethods.java | InlineSimpleMethods.inlinePropertyReturn | private void inlinePropertyReturn(Node parent, Node call, Node returnedValue) {
Node getProp = returnedValue.cloneTree();
replaceThis(getProp, call.getFirstChild().removeFirstChild());
parent.replaceChild(call, getProp);
compiler.reportChangeToEnclosingScope(getProp);
} | java | private void inlinePropertyReturn(Node parent, Node call, Node returnedValue) {
Node getProp = returnedValue.cloneTree();
replaceThis(getProp, call.getFirstChild().removeFirstChild());
parent.replaceChild(call, getProp);
compiler.reportChangeToEnclosingScope(getProp);
} | [
"private",
"void",
"inlinePropertyReturn",
"(",
"Node",
"parent",
",",
"Node",
"call",
",",
"Node",
"returnedValue",
")",
"{",
"Node",
"getProp",
"=",
"returnedValue",
".",
"cloneTree",
"(",
")",
";",
"replaceThis",
"(",
"getProp",
",",
"call",
".",
"getFirstChild",
"(",
")",
".",
"removeFirstChild",
"(",
")",
")",
";",
"parent",
".",
"replaceChild",
"(",
"call",
",",
"getProp",
")",
";",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"getProp",
")",
";",
"}"
] | Replace the provided method call with the tree specified in returnedValue
Parse tree of a call is
name
call
getprop
obj
string | [
"Replace",
"the",
"provided",
"method",
"call",
"with",
"the",
"tree",
"specified",
"in",
"returnedValue"
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/InlineSimpleMethods.java#L220-L225 |
24,987 | google/closure-compiler | src/com/google/javascript/jscomp/InlineSimpleMethods.java | InlineSimpleMethods.inlineConstReturn | private void inlineConstReturn(Node parent, Node call, Node returnedValue) {
Node retValue = returnedValue.cloneTree();
parent.replaceChild(call, retValue);
compiler.reportChangeToEnclosingScope(retValue);
} | java | private void inlineConstReturn(Node parent, Node call, Node returnedValue) {
Node retValue = returnedValue.cloneTree();
parent.replaceChild(call, retValue);
compiler.reportChangeToEnclosingScope(retValue);
} | [
"private",
"void",
"inlineConstReturn",
"(",
"Node",
"parent",
",",
"Node",
"call",
",",
"Node",
"returnedValue",
")",
"{",
"Node",
"retValue",
"=",
"returnedValue",
".",
"cloneTree",
"(",
")",
";",
"parent",
".",
"replaceChild",
"(",
"call",
",",
"retValue",
")",
";",
"compiler",
".",
"reportChangeToEnclosingScope",
"(",
"retValue",
")",
";",
"}"
] | Replace the provided object and its method call with the tree specified
in returnedValue. Should be called only if the object reference has
no side effects. | [
"Replace",
"the",
"provided",
"object",
"and",
"its",
"method",
"call",
"with",
"the",
"tree",
"specified",
"in",
"returnedValue",
".",
"Should",
"be",
"called",
"only",
"if",
"the",
"object",
"reference",
"has",
"no",
"side",
"effects",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/InlineSimpleMethods.java#L232-L236 |
24,988 | google/closure-compiler | src/com/google/javascript/jscomp/InlineSimpleMethods.java | InlineSimpleMethods.inlineEmptyMethod | private void inlineEmptyMethod(NodeTraversal t, Node parent, Node call) {
// If the return value of the method call is read,
// replace it with "void 0". Otherwise, remove the call entirely.
if (NodeUtil.isExprCall(parent)) {
parent.replaceWith(IR.empty());
NodeUtil.markFunctionsDeleted(parent, compiler);
} else {
Node srcLocation = call;
parent.replaceChild(call, NodeUtil.newUndefinedNode(srcLocation));
NodeUtil.markFunctionsDeleted(call, compiler);
}
t.reportCodeChange();
} | java | private void inlineEmptyMethod(NodeTraversal t, Node parent, Node call) {
// If the return value of the method call is read,
// replace it with "void 0". Otherwise, remove the call entirely.
if (NodeUtil.isExprCall(parent)) {
parent.replaceWith(IR.empty());
NodeUtil.markFunctionsDeleted(parent, compiler);
} else {
Node srcLocation = call;
parent.replaceChild(call, NodeUtil.newUndefinedNode(srcLocation));
NodeUtil.markFunctionsDeleted(call, compiler);
}
t.reportCodeChange();
} | [
"private",
"void",
"inlineEmptyMethod",
"(",
"NodeTraversal",
"t",
",",
"Node",
"parent",
",",
"Node",
"call",
")",
"{",
"// If the return value of the method call is read,",
"// replace it with \"void 0\". Otherwise, remove the call entirely.",
"if",
"(",
"NodeUtil",
".",
"isExprCall",
"(",
"parent",
")",
")",
"{",
"parent",
".",
"replaceWith",
"(",
"IR",
".",
"empty",
"(",
")",
")",
";",
"NodeUtil",
".",
"markFunctionsDeleted",
"(",
"parent",
",",
"compiler",
")",
";",
"}",
"else",
"{",
"Node",
"srcLocation",
"=",
"call",
";",
"parent",
".",
"replaceChild",
"(",
"call",
",",
"NodeUtil",
".",
"newUndefinedNode",
"(",
"srcLocation",
")",
")",
";",
"NodeUtil",
".",
"markFunctionsDeleted",
"(",
"call",
",",
"compiler",
")",
";",
"}",
"t",
".",
"reportCodeChange",
"(",
")",
";",
"}"
] | Remove the provided object and its method call. | [
"Remove",
"the",
"provided",
"object",
"and",
"its",
"method",
"call",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/InlineSimpleMethods.java#L241-L254 |
24,989 | google/closure-compiler | src/com/google/javascript/jscomp/InlineSimpleMethods.java | InlineSimpleMethods.argsMayHaveSideEffects | private boolean argsMayHaveSideEffects(Node call) {
for (Node currentChild = call.getSecondChild();
currentChild != null;
currentChild = currentChild.getNext()) {
if (NodeUtil.mayHaveSideEffects(currentChild, compiler)) {
return true;
}
}
return false;
} | java | private boolean argsMayHaveSideEffects(Node call) {
for (Node currentChild = call.getSecondChild();
currentChild != null;
currentChild = currentChild.getNext()) {
if (NodeUtil.mayHaveSideEffects(currentChild, compiler)) {
return true;
}
}
return false;
} | [
"private",
"boolean",
"argsMayHaveSideEffects",
"(",
"Node",
"call",
")",
"{",
"for",
"(",
"Node",
"currentChild",
"=",
"call",
".",
"getSecondChild",
"(",
")",
";",
"currentChild",
"!=",
"null",
";",
"currentChild",
"=",
"currentChild",
".",
"getNext",
"(",
")",
")",
"{",
"if",
"(",
"NodeUtil",
".",
"mayHaveSideEffects",
"(",
"currentChild",
",",
"compiler",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check whether the given method call's arguments have side effects.
@param call The call node of a method invocation. | [
"Check",
"whether",
"the",
"given",
"method",
"call",
"s",
"arguments",
"have",
"side",
"effects",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/InlineSimpleMethods.java#L260-L270 |
24,990 | google/closure-compiler | src/com/google/javascript/jscomp/ant/CompileTask.java | CompileTask.setWarning | public void setWarning(String value) {
if ("default".equalsIgnoreCase(value)) {
this.warningLevel = WarningLevel.DEFAULT;
} else if ("quiet".equalsIgnoreCase(value)) {
this.warningLevel = WarningLevel.QUIET;
} else if ("verbose".equalsIgnoreCase(value)) {
this.warningLevel = WarningLevel.VERBOSE;
} else {
throw new BuildException(
"Unrecognized 'warning' option value (" + value + ")");
}
} | java | public void setWarning(String value) {
if ("default".equalsIgnoreCase(value)) {
this.warningLevel = WarningLevel.DEFAULT;
} else if ("quiet".equalsIgnoreCase(value)) {
this.warningLevel = WarningLevel.QUIET;
} else if ("verbose".equalsIgnoreCase(value)) {
this.warningLevel = WarningLevel.VERBOSE;
} else {
throw new BuildException(
"Unrecognized 'warning' option value (" + value + ")");
}
} | [
"public",
"void",
"setWarning",
"(",
"String",
"value",
")",
"{",
"if",
"(",
"\"default\"",
".",
"equalsIgnoreCase",
"(",
"value",
")",
")",
"{",
"this",
".",
"warningLevel",
"=",
"WarningLevel",
".",
"DEFAULT",
";",
"}",
"else",
"if",
"(",
"\"quiet\"",
".",
"equalsIgnoreCase",
"(",
"value",
")",
")",
"{",
"this",
".",
"warningLevel",
"=",
"WarningLevel",
".",
"QUIET",
";",
"}",
"else",
"if",
"(",
"\"verbose\"",
".",
"equalsIgnoreCase",
"(",
"value",
")",
")",
"{",
"this",
".",
"warningLevel",
"=",
"WarningLevel",
".",
"VERBOSE",
";",
"}",
"else",
"{",
"throw",
"new",
"BuildException",
"(",
"\"Unrecognized 'warning' option value (\"",
"+",
"value",
"+",
"\")\"",
")",
";",
"}",
"}"
] | Set the warning level.
@param value The warning level by string name. (default, quiet, verbose). | [
"Set",
"the",
"warning",
"level",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ant/CompileTask.java#L173-L184 |
24,991 | google/closure-compiler | src/com/google/javascript/jscomp/ant/CompileTask.java | CompileTask.setEnvironment | public void setEnvironment(String value) {
switch (value) {
case "BROWSER":
this.environment = CompilerOptions.Environment.BROWSER;
break;
case "CUSTOM":
this.environment = CompilerOptions.Environment.CUSTOM;
break;
default:
throw new BuildException(
"Unrecognized 'environment' option value (" + value + ")");
}
} | java | public void setEnvironment(String value) {
switch (value) {
case "BROWSER":
this.environment = CompilerOptions.Environment.BROWSER;
break;
case "CUSTOM":
this.environment = CompilerOptions.Environment.CUSTOM;
break;
default:
throw new BuildException(
"Unrecognized 'environment' option value (" + value + ")");
}
} | [
"public",
"void",
"setEnvironment",
"(",
"String",
"value",
")",
"{",
"switch",
"(",
"value",
")",
"{",
"case",
"\"BROWSER\"",
":",
"this",
".",
"environment",
"=",
"CompilerOptions",
".",
"Environment",
".",
"BROWSER",
";",
"break",
";",
"case",
"\"CUSTOM\"",
":",
"this",
".",
"environment",
"=",
"CompilerOptions",
".",
"Environment",
".",
"CUSTOM",
";",
"break",
";",
"default",
":",
"throw",
"new",
"BuildException",
"(",
"\"Unrecognized 'environment' option value (\"",
"+",
"value",
"+",
"\")\"",
")",
";",
"}",
"}"
] | Set the environment which determines the builtin extern set.
@param value The name of the environment.
(BROWSER, CUSTOM). | [
"Set",
"the",
"environment",
"which",
"determines",
"the",
"builtin",
"extern",
"set",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ant/CompileTask.java#L191-L203 |
24,992 | google/closure-compiler | src/com/google/javascript/jscomp/ant/CompileTask.java | CompileTask.setCompilationLevel | public void setCompilationLevel(String value) {
if ("simple".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
} else if ("advanced".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.ADVANCED_OPTIMIZATIONS;
} else if ("whitespace".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.WHITESPACE_ONLY;
} else {
throw new BuildException(
"Unrecognized 'compilation' option value (" + value + ")");
}
} | java | public void setCompilationLevel(String value) {
if ("simple".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
} else if ("advanced".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.ADVANCED_OPTIMIZATIONS;
} else if ("whitespace".equalsIgnoreCase(value)) {
this.compilationLevel = CompilationLevel.WHITESPACE_ONLY;
} else {
throw new BuildException(
"Unrecognized 'compilation' option value (" + value + ")");
}
} | [
"public",
"void",
"setCompilationLevel",
"(",
"String",
"value",
")",
"{",
"if",
"(",
"\"simple\"",
".",
"equalsIgnoreCase",
"(",
"value",
")",
")",
"{",
"this",
".",
"compilationLevel",
"=",
"CompilationLevel",
".",
"SIMPLE_OPTIMIZATIONS",
";",
"}",
"else",
"if",
"(",
"\"advanced\"",
".",
"equalsIgnoreCase",
"(",
"value",
")",
")",
"{",
"this",
".",
"compilationLevel",
"=",
"CompilationLevel",
".",
"ADVANCED_OPTIMIZATIONS",
";",
"}",
"else",
"if",
"(",
"\"whitespace\"",
".",
"equalsIgnoreCase",
"(",
"value",
")",
")",
"{",
"this",
".",
"compilationLevel",
"=",
"CompilationLevel",
".",
"WHITESPACE_ONLY",
";",
"}",
"else",
"{",
"throw",
"new",
"BuildException",
"(",
"\"Unrecognized 'compilation' option value (\"",
"+",
"value",
"+",
"\")\"",
")",
";",
"}",
"}"
] | Set the compilation level.
@param value The optimization level by string name.
(whitespace, simple, advanced). | [
"Set",
"the",
"compilation",
"level",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ant/CompileTask.java#L218-L229 |
24,993 | google/closure-compiler | src/com/google/javascript/jscomp/ant/CompileTask.java | CompileTask.findJavaScriptFiles | private List<SourceFile> findJavaScriptFiles(ResourceCollection rc) {
List<SourceFile> files = new ArrayList<>();
Iterator<Resource> iter = rc.iterator();
while (iter.hasNext()) {
FileResource fr = (FileResource) iter.next();
// Construct path to file, relative to current working directory.
java.nio.file.Path path = Paths.get("").toAbsolutePath().relativize(fr.getFile().toPath());
files.add(SourceFile.fromPath(path, Charset.forName(encoding)));
}
return files;
} | java | private List<SourceFile> findJavaScriptFiles(ResourceCollection rc) {
List<SourceFile> files = new ArrayList<>();
Iterator<Resource> iter = rc.iterator();
while (iter.hasNext()) {
FileResource fr = (FileResource) iter.next();
// Construct path to file, relative to current working directory.
java.nio.file.Path path = Paths.get("").toAbsolutePath().relativize(fr.getFile().toPath());
files.add(SourceFile.fromPath(path, Charset.forName(encoding)));
}
return files;
} | [
"private",
"List",
"<",
"SourceFile",
">",
"findJavaScriptFiles",
"(",
"ResourceCollection",
"rc",
")",
"{",
"List",
"<",
"SourceFile",
">",
"files",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"Iterator",
"<",
"Resource",
">",
"iter",
"=",
"rc",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"FileResource",
"fr",
"=",
"(",
"FileResource",
")",
"iter",
".",
"next",
"(",
")",
";",
"// Construct path to file, relative to current working directory.",
"java",
".",
"nio",
".",
"file",
".",
"Path",
"path",
"=",
"Paths",
".",
"get",
"(",
"\"\"",
")",
".",
"toAbsolutePath",
"(",
")",
".",
"relativize",
"(",
"fr",
".",
"getFile",
"(",
")",
".",
"toPath",
"(",
")",
")",
";",
"files",
".",
"add",
"(",
"SourceFile",
".",
"fromPath",
"(",
"path",
",",
"Charset",
".",
"forName",
"(",
"encoding",
")",
")",
")",
";",
"}",
"return",
"files",
";",
"}"
] | Translates an Ant resource collection into the file list format that
the compiler expects. | [
"Translates",
"an",
"Ant",
"resource",
"collection",
"into",
"the",
"file",
"list",
"format",
"that",
"the",
"compiler",
"expects",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ant/CompileTask.java#L655-L665 |
24,994 | google/closure-compiler | src/com/google/javascript/jscomp/ant/CompileTask.java | CompileTask.getBuiltinExterns | private List<SourceFile> getBuiltinExterns(CompilerOptions options) {
try {
return CommandLineRunner.getBuiltinExterns(options.getEnvironment());
} catch (IOException e) {
throw new BuildException(e);
}
} | java | private List<SourceFile> getBuiltinExterns(CompilerOptions options) {
try {
return CommandLineRunner.getBuiltinExterns(options.getEnvironment());
} catch (IOException e) {
throw new BuildException(e);
}
} | [
"private",
"List",
"<",
"SourceFile",
">",
"getBuiltinExterns",
"(",
"CompilerOptions",
"options",
")",
"{",
"try",
"{",
"return",
"CommandLineRunner",
".",
"getBuiltinExterns",
"(",
"options",
".",
"getEnvironment",
"(",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"e",
")",
";",
"}",
"}"
] | Gets the default externs set.
Adapted from {@link CommandLineRunner}. | [
"Gets",
"the",
"default",
"externs",
"set",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ant/CompileTask.java#L672-L678 |
24,995 | google/closure-compiler | src/com/google/javascript/jscomp/ant/CompileTask.java | CompileTask.getLastModifiedTime | private long getLastModifiedTime(List<?> fileLists) {
long lastModified = 0;
for (Object entry : fileLists) {
if (entry instanceof FileList) {
FileList list = (FileList) entry;
for (String fileName : list.getFiles(this.getProject())) {
File path = list.getDir(this.getProject());
File file = new File(path, fileName);
lastModified = Math.max(getLastModifiedTime(file), lastModified);
}
} else if (entry instanceof Path) {
Path path = (Path) entry;
for (String src : path.list()) {
File file = new File(src);
lastModified = Math.max(getLastModifiedTime(file), lastModified);
}
}
}
return lastModified;
} | java | private long getLastModifiedTime(List<?> fileLists) {
long lastModified = 0;
for (Object entry : fileLists) {
if (entry instanceof FileList) {
FileList list = (FileList) entry;
for (String fileName : list.getFiles(this.getProject())) {
File path = list.getDir(this.getProject());
File file = new File(path, fileName);
lastModified = Math.max(getLastModifiedTime(file), lastModified);
}
} else if (entry instanceof Path) {
Path path = (Path) entry;
for (String src : path.list()) {
File file = new File(src);
lastModified = Math.max(getLastModifiedTime(file), lastModified);
}
}
}
return lastModified;
} | [
"private",
"long",
"getLastModifiedTime",
"(",
"List",
"<",
"?",
">",
"fileLists",
")",
"{",
"long",
"lastModified",
"=",
"0",
";",
"for",
"(",
"Object",
"entry",
":",
"fileLists",
")",
"{",
"if",
"(",
"entry",
"instanceof",
"FileList",
")",
"{",
"FileList",
"list",
"=",
"(",
"FileList",
")",
"entry",
";",
"for",
"(",
"String",
"fileName",
":",
"list",
".",
"getFiles",
"(",
"this",
".",
"getProject",
"(",
")",
")",
")",
"{",
"File",
"path",
"=",
"list",
".",
"getDir",
"(",
"this",
".",
"getProject",
"(",
")",
")",
";",
"File",
"file",
"=",
"new",
"File",
"(",
"path",
",",
"fileName",
")",
";",
"lastModified",
"=",
"Math",
".",
"max",
"(",
"getLastModifiedTime",
"(",
"file",
")",
",",
"lastModified",
")",
";",
"}",
"}",
"else",
"if",
"(",
"entry",
"instanceof",
"Path",
")",
"{",
"Path",
"path",
"=",
"(",
"Path",
")",
"entry",
";",
"for",
"(",
"String",
"src",
":",
"path",
".",
"list",
"(",
")",
")",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"src",
")",
";",
"lastModified",
"=",
"Math",
".",
"max",
"(",
"getLastModifiedTime",
"(",
"file",
")",
",",
"lastModified",
")",
";",
"}",
"}",
"}",
"return",
"lastModified",
";",
"}"
] | Returns the most recent modified timestamp of the file collection.
Note: this must be combined into one method to account for both
Path and FileList erasure types.
@param fileLists Collection of FileList or Path
@return Most recent modified timestamp | [
"Returns",
"the",
"most",
"recent",
"modified",
"timestamp",
"of",
"the",
"file",
"collection",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ant/CompileTask.java#L722-L744 |
24,996 | google/closure-compiler | src/com/google/javascript/jscomp/ant/CompileTask.java | CompileTask.getLastModifiedTime | private static long getLastModifiedTime(File file) {
long fileLastModified = file.lastModified();
// If the file is absent, we don't know if it changed (maybe was deleted),
// so assume it has just changed.
if (fileLastModified == 0) {
fileLastModified = new Date().getTime();
}
return fileLastModified;
} | java | private static long getLastModifiedTime(File file) {
long fileLastModified = file.lastModified();
// If the file is absent, we don't know if it changed (maybe was deleted),
// so assume it has just changed.
if (fileLastModified == 0) {
fileLastModified = new Date().getTime();
}
return fileLastModified;
} | [
"private",
"static",
"long",
"getLastModifiedTime",
"(",
"File",
"file",
")",
"{",
"long",
"fileLastModified",
"=",
"file",
".",
"lastModified",
"(",
")",
";",
"// If the file is absent, we don't know if it changed (maybe was deleted),",
"// so assume it has just changed.",
"if",
"(",
"fileLastModified",
"==",
"0",
")",
"{",
"fileLastModified",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"}",
"return",
"fileLastModified",
";",
"}"
] | Returns the last modified timestamp of the given File. | [
"Returns",
"the",
"last",
"modified",
"timestamp",
"of",
"the",
"given",
"File",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/ant/CompileTask.java#L749-L757 |
24,997 | google/closure-compiler | src/com/google/javascript/jscomp/RenameProperties.java | RenameProperties.reusePropertyNames | private void reusePropertyNames(Set<String> reservedNames,
Collection<Property> allProps) {
for (Property prop : allProps) {
// Check if this node can reuse a name from a previous compilation - if
// it can set the newName for the property too.
String prevName = prevUsedPropertyMap.lookupNewName(prop.oldName);
if (!generatePseudoNames && prevName != null) {
// We can reuse prevName if it's not reserved.
if (reservedNames.contains(prevName)) {
continue;
}
prop.newName = prevName;
reservedNames.add(prevName);
}
}
} | java | private void reusePropertyNames(Set<String> reservedNames,
Collection<Property> allProps) {
for (Property prop : allProps) {
// Check if this node can reuse a name from a previous compilation - if
// it can set the newName for the property too.
String prevName = prevUsedPropertyMap.lookupNewName(prop.oldName);
if (!generatePseudoNames && prevName != null) {
// We can reuse prevName if it's not reserved.
if (reservedNames.contains(prevName)) {
continue;
}
prop.newName = prevName;
reservedNames.add(prevName);
}
}
} | [
"private",
"void",
"reusePropertyNames",
"(",
"Set",
"<",
"String",
">",
"reservedNames",
",",
"Collection",
"<",
"Property",
">",
"allProps",
")",
"{",
"for",
"(",
"Property",
"prop",
":",
"allProps",
")",
"{",
"// Check if this node can reuse a name from a previous compilation - if",
"// it can set the newName for the property too.",
"String",
"prevName",
"=",
"prevUsedPropertyMap",
".",
"lookupNewName",
"(",
"prop",
".",
"oldName",
")",
";",
"if",
"(",
"!",
"generatePseudoNames",
"&&",
"prevName",
"!=",
"null",
")",
"{",
"// We can reuse prevName if it's not reserved.",
"if",
"(",
"reservedNames",
".",
"contains",
"(",
"prevName",
")",
")",
"{",
"continue",
";",
"}",
"prop",
".",
"newName",
"=",
"prevName",
";",
"reservedNames",
".",
"add",
"(",
"prevName",
")",
";",
"}",
"}",
"}"
] | Runs through the list of properties and renames as many as possible with
names from the previous compilation. Also, updates reservedNames with the
set of reused names.
@param reservedNames Reserved names to use during renaming.
@param allProps Properties to rename. | [
"Runs",
"through",
"the",
"list",
"of",
"properties",
"and",
"renames",
"as",
"many",
"as",
"possible",
"with",
"names",
"from",
"the",
"previous",
"compilation",
".",
"Also",
"updates",
"reservedNames",
"with",
"the",
"set",
"of",
"reused",
"names",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/RenameProperties.java#L268-L284 |
24,998 | google/closure-compiler | src/com/google/javascript/jscomp/RenameProperties.java | RenameProperties.generateNames | private void generateNames(Set<Property> props, Set<String> reservedNames) {
nameGenerator.reset(reservedNames, "", reservedFirstCharacters, reservedNonFirstCharacters);
for (Property p : props) {
if (generatePseudoNames) {
p.newName = "$" + p.oldName + "$";
} else {
// If we haven't already given this property a reusable name.
if (p.newName == null) {
p.newName = nameGenerator.generateNextName();
}
}
reservedNames.add(p.newName);
}
} | java | private void generateNames(Set<Property> props, Set<String> reservedNames) {
nameGenerator.reset(reservedNames, "", reservedFirstCharacters, reservedNonFirstCharacters);
for (Property p : props) {
if (generatePseudoNames) {
p.newName = "$" + p.oldName + "$";
} else {
// If we haven't already given this property a reusable name.
if (p.newName == null) {
p.newName = nameGenerator.generateNextName();
}
}
reservedNames.add(p.newName);
}
} | [
"private",
"void",
"generateNames",
"(",
"Set",
"<",
"Property",
">",
"props",
",",
"Set",
"<",
"String",
">",
"reservedNames",
")",
"{",
"nameGenerator",
".",
"reset",
"(",
"reservedNames",
",",
"\"\"",
",",
"reservedFirstCharacters",
",",
"reservedNonFirstCharacters",
")",
";",
"for",
"(",
"Property",
"p",
":",
"props",
")",
"{",
"if",
"(",
"generatePseudoNames",
")",
"{",
"p",
".",
"newName",
"=",
"\"$\"",
"+",
"p",
".",
"oldName",
"+",
"\"$\"",
";",
"}",
"else",
"{",
"// If we haven't already given this property a reusable name.",
"if",
"(",
"p",
".",
"newName",
"==",
"null",
")",
"{",
"p",
".",
"newName",
"=",
"nameGenerator",
".",
"generateNextName",
"(",
")",
";",
"}",
"}",
"reservedNames",
".",
"add",
"(",
"p",
".",
"newName",
")",
";",
"}",
"}"
] | Generates new names for properties.
@param props Properties to generate new names for
@param reservedNames A set of names to which properties should not be
renamed | [
"Generates",
"new",
"names",
"for",
"properties",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/RenameProperties.java#L293-L306 |
24,999 | google/closure-compiler | src/com/google/javascript/jscomp/Es6ExtractClasses.java | Es6ExtractClasses.addAtConstructor | private void addAtConstructor(Node node) {
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(node.getJSDocInfo());
builder.recordConstructor();
node.setJSDocInfo(builder.build());
} | java | private void addAtConstructor(Node node) {
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(node.getJSDocInfo());
builder.recordConstructor();
node.setJSDocInfo(builder.build());
} | [
"private",
"void",
"addAtConstructor",
"(",
"Node",
"node",
")",
"{",
"JSDocInfoBuilder",
"builder",
"=",
"JSDocInfoBuilder",
".",
"maybeCopyFrom",
"(",
"node",
".",
"getJSDocInfo",
"(",
")",
")",
";",
"builder",
".",
"recordConstructor",
"(",
")",
";",
"node",
".",
"setJSDocInfo",
"(",
"builder",
".",
"build",
"(",
")",
")",
";",
"}"
] | Add at-constructor to the JSDoc of the given node.
@param node | [
"Add",
"at",
"-",
"constructor",
"to",
"the",
"JSDoc",
"of",
"the",
"given",
"node",
"."
] | d81e36740f6a9e8ac31a825ee8758182e1dc5aae | https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Es6ExtractClasses.java#L249-L253 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.