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
25,000
google/closure-compiler
src/com/google/javascript/jscomp/PolymerPassStaticUtils.java
PolymerPassStaticUtils.quoteListenerAndHostAttributeKeys
static void quoteListenerAndHostAttributeKeys(Node objLit, AbstractCompiler compiler) { checkState(objLit.isObjectLit()); for (Node keyNode : objLit.children()) { if (keyNode.isComputedProp()) { continue; } if (!keyNode.getString().equals("listeners") && !keyNode.getString().equals("hostAttributes")) { continue; } for (Node keyToQuote : keyNode.getFirstChild().children()) { if (!keyToQuote.isQuotedString()) { keyToQuote.setQuotedString(); compiler.reportChangeToEnclosingScope(keyToQuote); } } } }
java
static void quoteListenerAndHostAttributeKeys(Node objLit, AbstractCompiler compiler) { checkState(objLit.isObjectLit()); for (Node keyNode : objLit.children()) { if (keyNode.isComputedProp()) { continue; } if (!keyNode.getString().equals("listeners") && !keyNode.getString().equals("hostAttributes")) { continue; } for (Node keyToQuote : keyNode.getFirstChild().children()) { if (!keyToQuote.isQuotedString()) { keyToQuote.setQuotedString(); compiler.reportChangeToEnclosingScope(keyToQuote); } } } }
[ "static", "void", "quoteListenerAndHostAttributeKeys", "(", "Node", "objLit", ",", "AbstractCompiler", "compiler", ")", "{", "checkState", "(", "objLit", ".", "isObjectLit", "(", ")", ")", ";", "for", "(", "Node", "keyNode", ":", "objLit", ".", "children", "(", ")", ")", "{", "if", "(", "keyNode", ".", "isComputedProp", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "keyNode", ".", "getString", "(", ")", ".", "equals", "(", "\"listeners\"", ")", "&&", "!", "keyNode", ".", "getString", "(", ")", ".", "equals", "(", "\"hostAttributes\"", ")", ")", "{", "continue", ";", "}", "for", "(", "Node", "keyToQuote", ":", "keyNode", ".", "getFirstChild", "(", ")", ".", "children", "(", ")", ")", "{", "if", "(", "!", "keyToQuote", ".", "isQuotedString", "(", ")", ")", "{", "keyToQuote", ".", "setQuotedString", "(", ")", ";", "compiler", ".", "reportChangeToEnclosingScope", "(", "keyToQuote", ")", ";", "}", "}", "}", "}" ]
Makes sure that the keys for listeners and hostAttributes blocks are quoted to avoid renaming.
[ "Makes", "sure", "that", "the", "keys", "for", "listeners", "and", "hostAttributes", "blocks", "are", "quoted", "to", "avoid", "renaming", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PolymerPassStaticUtils.java#L109-L126
25,001
google/closure-compiler
src/com/google/javascript/jscomp/PolymerPassStaticUtils.java
PolymerPassStaticUtils.collectConstructorPropertyJsDoc
private static void collectConstructorPropertyJsDoc(Node node, Map<String, JSDocInfo> map) { checkNotNull(node); for (Node child : node.children()) { if (child.isGetProp() && child.getFirstChild().isThis() && child.getSecondChild().isString()) { // We found a "this.foo" expression. Map "foo" to its JSDoc. map.put(child.getSecondChild().getString(), NodeUtil.getBestJSDocInfo(child)); } else { // Recurse through every other kind of node, because properties are not necessarily declared // at the top level of the constructor body; e.g. they could be declared as part of an // assignment, or within an if statement. We're being overly loose here, e.g. we shouldn't // traverse into a nested function where "this" doesn't refer to our prototype, but // hopefully this is good enough for our purposes. collectConstructorPropertyJsDoc(child, map); } } }
java
private static void collectConstructorPropertyJsDoc(Node node, Map<String, JSDocInfo> map) { checkNotNull(node); for (Node child : node.children()) { if (child.isGetProp() && child.getFirstChild().isThis() && child.getSecondChild().isString()) { // We found a "this.foo" expression. Map "foo" to its JSDoc. map.put(child.getSecondChild().getString(), NodeUtil.getBestJSDocInfo(child)); } else { // Recurse through every other kind of node, because properties are not necessarily declared // at the top level of the constructor body; e.g. they could be declared as part of an // assignment, or within an if statement. We're being overly loose here, e.g. we shouldn't // traverse into a nested function where "this" doesn't refer to our prototype, but // hopefully this is good enough for our purposes. collectConstructorPropertyJsDoc(child, map); } } }
[ "private", "static", "void", "collectConstructorPropertyJsDoc", "(", "Node", "node", ",", "Map", "<", "String", ",", "JSDocInfo", ">", "map", ")", "{", "checkNotNull", "(", "node", ")", ";", "for", "(", "Node", "child", ":", "node", ".", "children", "(", ")", ")", "{", "if", "(", "child", ".", "isGetProp", "(", ")", "&&", "child", ".", "getFirstChild", "(", ")", ".", "isThis", "(", ")", "&&", "child", ".", "getSecondChild", "(", ")", ".", "isString", "(", ")", ")", "{", "// We found a \"this.foo\" expression. Map \"foo\" to its JSDoc.", "map", ".", "put", "(", "child", ".", "getSecondChild", "(", ")", ".", "getString", "(", ")", ",", "NodeUtil", ".", "getBestJSDocInfo", "(", "child", ")", ")", ";", "}", "else", "{", "// Recurse through every other kind of node, because properties are not necessarily declared", "// at the top level of the constructor body; e.g. they could be declared as part of an", "// assignment, or within an if statement. We're being overly loose here, e.g. we shouldn't", "// traverse into a nested function where \"this\" doesn't refer to our prototype, but", "// hopefully this is good enough for our purposes.", "collectConstructorPropertyJsDoc", "(", "child", ",", "map", ")", ";", "}", "}", "}" ]
Find the properties that are initialized in the given constructor, and return a map from each property name to its JSDoc. @param node The constructor function node to traverse. @param map The map from property name to JSDoc.
[ "Find", "the", "properties", "that", "are", "initialized", "in", "the", "given", "constructor", "and", "return", "a", "map", "from", "each", "property", "name", "to", "its", "JSDoc", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PolymerPassStaticUtils.java#L184-L201
25,002
google/closure-compiler
src/com/google/javascript/jscomp/PolymerPassStaticUtils.java
PolymerPassStaticUtils.getTypeFromProperty
static JSTypeExpression getTypeFromProperty( MemberDefinition property, AbstractCompiler compiler) { if (property.info != null && property.info.hasType()) { return property.info.getType(); } String typeString; if (property.value.isObjectLit()) { Node typeValue = NodeUtil.getFirstPropMatchingKey(property.value, "type"); if (typeValue == null || !typeValue.isName()) { compiler.report(JSError.make(property.name, PolymerPassErrors.POLYMER_INVALID_PROPERTY)); return null; } typeString = typeValue.getString(); } else if (property.value.isName()) { typeString = property.value.getString(); } else { typeString = ""; } Node typeNode; switch (typeString) { case "Boolean": case "String": case "Number": typeNode = IR.string(typeString.toLowerCase()); break; case "Array": case "Function": case "Object": case "Date": typeNode = new Node(Token.BANG, IR.string(typeString)); break; default: compiler.report(JSError.make(property.name, PolymerPassErrors.POLYMER_INVALID_PROPERTY)); return null; } return new JSTypeExpression(typeNode, VIRTUAL_FILE); }
java
static JSTypeExpression getTypeFromProperty( MemberDefinition property, AbstractCompiler compiler) { if (property.info != null && property.info.hasType()) { return property.info.getType(); } String typeString; if (property.value.isObjectLit()) { Node typeValue = NodeUtil.getFirstPropMatchingKey(property.value, "type"); if (typeValue == null || !typeValue.isName()) { compiler.report(JSError.make(property.name, PolymerPassErrors.POLYMER_INVALID_PROPERTY)); return null; } typeString = typeValue.getString(); } else if (property.value.isName()) { typeString = property.value.getString(); } else { typeString = ""; } Node typeNode; switch (typeString) { case "Boolean": case "String": case "Number": typeNode = IR.string(typeString.toLowerCase()); break; case "Array": case "Function": case "Object": case "Date": typeNode = new Node(Token.BANG, IR.string(typeString)); break; default: compiler.report(JSError.make(property.name, PolymerPassErrors.POLYMER_INVALID_PROPERTY)); return null; } return new JSTypeExpression(typeNode, VIRTUAL_FILE); }
[ "static", "JSTypeExpression", "getTypeFromProperty", "(", "MemberDefinition", "property", ",", "AbstractCompiler", "compiler", ")", "{", "if", "(", "property", ".", "info", "!=", "null", "&&", "property", ".", "info", ".", "hasType", "(", ")", ")", "{", "return", "property", ".", "info", ".", "getType", "(", ")", ";", "}", "String", "typeString", ";", "if", "(", "property", ".", "value", ".", "isObjectLit", "(", ")", ")", "{", "Node", "typeValue", "=", "NodeUtil", ".", "getFirstPropMatchingKey", "(", "property", ".", "value", ",", "\"type\"", ")", ";", "if", "(", "typeValue", "==", "null", "||", "!", "typeValue", ".", "isName", "(", ")", ")", "{", "compiler", ".", "report", "(", "JSError", ".", "make", "(", "property", ".", "name", ",", "PolymerPassErrors", ".", "POLYMER_INVALID_PROPERTY", ")", ")", ";", "return", "null", ";", "}", "typeString", "=", "typeValue", ".", "getString", "(", ")", ";", "}", "else", "if", "(", "property", ".", "value", ".", "isName", "(", ")", ")", "{", "typeString", "=", "property", ".", "value", ".", "getString", "(", ")", ";", "}", "else", "{", "typeString", "=", "\"\"", ";", "}", "Node", "typeNode", ";", "switch", "(", "typeString", ")", "{", "case", "\"Boolean\"", ":", "case", "\"String\"", ":", "case", "\"Number\"", ":", "typeNode", "=", "IR", ".", "string", "(", "typeString", ".", "toLowerCase", "(", ")", ")", ";", "break", ";", "case", "\"Array\"", ":", "case", "\"Function\"", ":", "case", "\"Object\"", ":", "case", "\"Date\"", ":", "typeNode", "=", "new", "Node", "(", "Token", ".", "BANG", ",", "IR", ".", "string", "(", "typeString", ")", ")", ";", "break", ";", "default", ":", "compiler", ".", "report", "(", "JSError", ".", "make", "(", "property", ".", "name", ",", "PolymerPassErrors", ".", "POLYMER_INVALID_PROPERTY", ")", ")", ";", "return", "null", ";", "}", "return", "new", "JSTypeExpression", "(", "typeNode", ",", "VIRTUAL_FILE", ")", ";", "}" ]
Gets the JSTypeExpression for a given property using its "type" key. @see https://github.com/Polymer/polymer/blob/0.8-preview/PRIMER.md#configuring-properties
[ "Gets", "the", "JSTypeExpression", "for", "a", "given", "property", "using", "its", "type", "key", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/PolymerPassStaticUtils.java#L207-L246
25,003
google/closure-compiler
src/com/google/javascript/jscomp/Scope.java
Scope.declare
Var declare(String name, Node nameNode, CompilerInput input) { checkArgument(!name.isEmpty()); // Make sure that it's declared only once checkState(getOwnSlot(name) == null); Var var = new Var(name, nameNode, this, getVarCount(), input); declareInternal(name, var); return var; }
java
Var declare(String name, Node nameNode, CompilerInput input) { checkArgument(!name.isEmpty()); // Make sure that it's declared only once checkState(getOwnSlot(name) == null); Var var = new Var(name, nameNode, this, getVarCount(), input); declareInternal(name, var); return var; }
[ "Var", "declare", "(", "String", "name", ",", "Node", "nameNode", ",", "CompilerInput", "input", ")", "{", "checkArgument", "(", "!", "name", ".", "isEmpty", "(", ")", ")", ";", "// Make sure that it's declared only once", "checkState", "(", "getOwnSlot", "(", "name", ")", "==", "null", ")", ";", "Var", "var", "=", "new", "Var", "(", "name", ",", "nameNode", ",", "this", ",", "getVarCount", "(", ")", ",", "input", ")", ";", "declareInternal", "(", "name", ",", "var", ")", ";", "return", "var", ";", "}" ]
Non-final for PersisteneScope.
[ "Non", "-", "final", "for", "PersisteneScope", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Scope.java#L59-L66
25,004
google/closure-compiler
src/com/google/javascript/refactoring/ErrorToFixMapper.java
ErrorToFixMapper.getFixForJsError
public static SuggestedFix getFixForJsError(JSError error, AbstractCompiler compiler) { switch (error.getType().key) { case "JSC_REDECLARED_VARIABLE": return getFixForRedeclaration(error, compiler); case "JSC_REFERENCE_BEFORE_DECLARE": return getFixForEarlyReference(error, compiler); case "JSC_MISSING_SEMICOLON": return getFixForMissingSemicolon(error, compiler); case "JSC_REQUIRES_NOT_SORTED": return getFixForUnsortedRequires(error, compiler); case "JSC_PROVIDES_NOT_SORTED": return getFixForUnsortedProvides(error, compiler); case "JSC_DEBUGGER_STATEMENT_PRESENT": return removeNode(error, compiler); case "JSC_USELESS_EMPTY_STATEMENT": return removeEmptyStatement(error, compiler); case "JSC_INEXISTENT_PROPERTY": return getFixForInexistentProperty(error, compiler); case "JSC_MISSING_CALL_TO_SUPER": return getFixForMissingSuper(error, compiler); case "JSC_INVALID_SUPER_CALL_WITH_SUGGESTION": return getFixForInvalidSuper(error, compiler); case "JSC_MISSING_REQUIRE_WARNING": case "JSC_MISSING_REQUIRE_STRICT_WARNING": return getFixForMissingRequire(error, compiler); case "JSC_EXTRA_REQUIRE_WARNING": return getFixForExtraRequire(error, compiler); case "JSC_REFERENCE_TO_SHORT_IMPORT_BY_LONG_NAME_INCLUDING_SHORT_NAME": case "JSC_JSDOC_REFERENCE_TO_SHORT_IMPORT_BY_LONG_NAME_INCLUDING_SHORT_NAME": case "JSC_REFERENCE_TO_FULLY_QUALIFIED_IMPORT_NAME": // TODO(tbreisacher): Apply this fix for JSC_JSDOC_REFERENCE_TO_FULLY_QUALIFIED_IMPORT_NAME. return getFixForReferenceToShortImportByLongName(error, compiler); case "JSC_REDUNDANT_NULLABILITY_MODIFIER_JSDOC": return getFixForRedundantNullabilityModifierJsDoc(error, compiler); default: return null; } }
java
public static SuggestedFix getFixForJsError(JSError error, AbstractCompiler compiler) { switch (error.getType().key) { case "JSC_REDECLARED_VARIABLE": return getFixForRedeclaration(error, compiler); case "JSC_REFERENCE_BEFORE_DECLARE": return getFixForEarlyReference(error, compiler); case "JSC_MISSING_SEMICOLON": return getFixForMissingSemicolon(error, compiler); case "JSC_REQUIRES_NOT_SORTED": return getFixForUnsortedRequires(error, compiler); case "JSC_PROVIDES_NOT_SORTED": return getFixForUnsortedProvides(error, compiler); case "JSC_DEBUGGER_STATEMENT_PRESENT": return removeNode(error, compiler); case "JSC_USELESS_EMPTY_STATEMENT": return removeEmptyStatement(error, compiler); case "JSC_INEXISTENT_PROPERTY": return getFixForInexistentProperty(error, compiler); case "JSC_MISSING_CALL_TO_SUPER": return getFixForMissingSuper(error, compiler); case "JSC_INVALID_SUPER_CALL_WITH_SUGGESTION": return getFixForInvalidSuper(error, compiler); case "JSC_MISSING_REQUIRE_WARNING": case "JSC_MISSING_REQUIRE_STRICT_WARNING": return getFixForMissingRequire(error, compiler); case "JSC_EXTRA_REQUIRE_WARNING": return getFixForExtraRequire(error, compiler); case "JSC_REFERENCE_TO_SHORT_IMPORT_BY_LONG_NAME_INCLUDING_SHORT_NAME": case "JSC_JSDOC_REFERENCE_TO_SHORT_IMPORT_BY_LONG_NAME_INCLUDING_SHORT_NAME": case "JSC_REFERENCE_TO_FULLY_QUALIFIED_IMPORT_NAME": // TODO(tbreisacher): Apply this fix for JSC_JSDOC_REFERENCE_TO_FULLY_QUALIFIED_IMPORT_NAME. return getFixForReferenceToShortImportByLongName(error, compiler); case "JSC_REDUNDANT_NULLABILITY_MODIFIER_JSDOC": return getFixForRedundantNullabilityModifierJsDoc(error, compiler); default: return null; } }
[ "public", "static", "SuggestedFix", "getFixForJsError", "(", "JSError", "error", ",", "AbstractCompiler", "compiler", ")", "{", "switch", "(", "error", ".", "getType", "(", ")", ".", "key", ")", "{", "case", "\"JSC_REDECLARED_VARIABLE\"", ":", "return", "getFixForRedeclaration", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_REFERENCE_BEFORE_DECLARE\"", ":", "return", "getFixForEarlyReference", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_MISSING_SEMICOLON\"", ":", "return", "getFixForMissingSemicolon", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_REQUIRES_NOT_SORTED\"", ":", "return", "getFixForUnsortedRequires", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_PROVIDES_NOT_SORTED\"", ":", "return", "getFixForUnsortedProvides", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_DEBUGGER_STATEMENT_PRESENT\"", ":", "return", "removeNode", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_USELESS_EMPTY_STATEMENT\"", ":", "return", "removeEmptyStatement", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_INEXISTENT_PROPERTY\"", ":", "return", "getFixForInexistentProperty", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_MISSING_CALL_TO_SUPER\"", ":", "return", "getFixForMissingSuper", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_INVALID_SUPER_CALL_WITH_SUGGESTION\"", ":", "return", "getFixForInvalidSuper", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_MISSING_REQUIRE_WARNING\"", ":", "case", "\"JSC_MISSING_REQUIRE_STRICT_WARNING\"", ":", "return", "getFixForMissingRequire", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_EXTRA_REQUIRE_WARNING\"", ":", "return", "getFixForExtraRequire", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_REFERENCE_TO_SHORT_IMPORT_BY_LONG_NAME_INCLUDING_SHORT_NAME\"", ":", "case", "\"JSC_JSDOC_REFERENCE_TO_SHORT_IMPORT_BY_LONG_NAME_INCLUDING_SHORT_NAME\"", ":", "case", "\"JSC_REFERENCE_TO_FULLY_QUALIFIED_IMPORT_NAME\"", ":", "// TODO(tbreisacher): Apply this fix for JSC_JSDOC_REFERENCE_TO_FULLY_QUALIFIED_IMPORT_NAME.", "return", "getFixForReferenceToShortImportByLongName", "(", "error", ",", "compiler", ")", ";", "case", "\"JSC_REDUNDANT_NULLABILITY_MODIFIER_JSDOC\"", ":", "return", "getFixForRedundantNullabilityModifierJsDoc", "(", "error", ",", "compiler", ")", ";", "default", ":", "return", "null", ";", "}", "}" ]
Creates a SuggestedFix for the given error. Note that some errors have multiple fixes so getFixesForJsError should often be used instead of this.
[ "Creates", "a", "SuggestedFix", "for", "the", "given", "error", ".", "Note", "that", "some", "errors", "have", "multiple", "fixes", "so", "getFixesForJsError", "should", "often", "be", "used", "instead", "of", "this", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/refactoring/ErrorToFixMapper.java#L74-L111
25,005
google/closure-compiler
src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java
ChainableReverseAbstractInterpreter.firstPreciserScopeKnowingConditionOutcome
protected FlowScope firstPreciserScopeKnowingConditionOutcome(Node condition, FlowScope blindScope, boolean outcome) { return firstLink.getPreciserScopeKnowingConditionOutcome( condition, blindScope, outcome); }
java
protected FlowScope firstPreciserScopeKnowingConditionOutcome(Node condition, FlowScope blindScope, boolean outcome) { return firstLink.getPreciserScopeKnowingConditionOutcome( condition, blindScope, outcome); }
[ "protected", "FlowScope", "firstPreciserScopeKnowingConditionOutcome", "(", "Node", "condition", ",", "FlowScope", "blindScope", ",", "boolean", "outcome", ")", "{", "return", "firstLink", ".", "getPreciserScopeKnowingConditionOutcome", "(", "condition", ",", "blindScope", ",", "outcome", ")", ";", "}" ]
Calculates the preciser scope starting with the first link.
[ "Calculates", "the", "preciser", "scope", "starting", "with", "the", "first", "link", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java#L98-L102
25,006
google/closure-compiler
src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java
ChainableReverseAbstractInterpreter.nextPreciserScopeKnowingConditionOutcome
protected FlowScope nextPreciserScopeKnowingConditionOutcome(Node condition, FlowScope blindScope, boolean outcome) { return nextLink != null ? nextLink.getPreciserScopeKnowingConditionOutcome( condition, blindScope, outcome) : blindScope; }
java
protected FlowScope nextPreciserScopeKnowingConditionOutcome(Node condition, FlowScope blindScope, boolean outcome) { return nextLink != null ? nextLink.getPreciserScopeKnowingConditionOutcome( condition, blindScope, outcome) : blindScope; }
[ "protected", "FlowScope", "nextPreciserScopeKnowingConditionOutcome", "(", "Node", "condition", ",", "FlowScope", "blindScope", ",", "boolean", "outcome", ")", "{", "return", "nextLink", "!=", "null", "?", "nextLink", ".", "getPreciserScopeKnowingConditionOutcome", "(", "condition", ",", "blindScope", ",", "outcome", ")", ":", "blindScope", ";", "}" ]
Delegates the calculation of the preciser scope to the next link. If there is no next link, returns the blind scope.
[ "Delegates", "the", "calculation", "of", "the", "preciser", "scope", "to", "the", "next", "link", ".", "If", "there", "is", "no", "next", "link", "returns", "the", "blind", "scope", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java#L108-L112
25,007
google/closure-compiler
src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java
ChainableReverseAbstractInterpreter.getTypeIfRefinable
protected JSType getTypeIfRefinable(Node node, FlowScope scope) { switch (node.getToken()) { case NAME: StaticTypedSlot nameVar = scope.getSlot(node.getString()); if (nameVar != null) { JSType nameVarType = nameVar.getType(); if (nameVarType == null) { nameVarType = node.getJSType(); } return nameVarType; } return null; case GETPROP: String qualifiedName = node.getQualifiedName(); if (qualifiedName == null) { return null; } StaticTypedSlot propVar = scope.getSlot(qualifiedName); JSType propVarType = null; if (propVar != null) { propVarType = propVar.getType(); } if (propVarType == null) { propVarType = node.getJSType(); } if (propVarType == null) { propVarType = getNativeType(UNKNOWN_TYPE); } return propVarType; default: break; } return null; }
java
protected JSType getTypeIfRefinable(Node node, FlowScope scope) { switch (node.getToken()) { case NAME: StaticTypedSlot nameVar = scope.getSlot(node.getString()); if (nameVar != null) { JSType nameVarType = nameVar.getType(); if (nameVarType == null) { nameVarType = node.getJSType(); } return nameVarType; } return null; case GETPROP: String qualifiedName = node.getQualifiedName(); if (qualifiedName == null) { return null; } StaticTypedSlot propVar = scope.getSlot(qualifiedName); JSType propVarType = null; if (propVar != null) { propVarType = propVar.getType(); } if (propVarType == null) { propVarType = node.getJSType(); } if (propVarType == null) { propVarType = getNativeType(UNKNOWN_TYPE); } return propVarType; default: break; } return null; }
[ "protected", "JSType", "getTypeIfRefinable", "(", "Node", "node", ",", "FlowScope", "scope", ")", "{", "switch", "(", "node", ".", "getToken", "(", ")", ")", "{", "case", "NAME", ":", "StaticTypedSlot", "nameVar", "=", "scope", ".", "getSlot", "(", "node", ".", "getString", "(", ")", ")", ";", "if", "(", "nameVar", "!=", "null", ")", "{", "JSType", "nameVarType", "=", "nameVar", ".", "getType", "(", ")", ";", "if", "(", "nameVarType", "==", "null", ")", "{", "nameVarType", "=", "node", ".", "getJSType", "(", ")", ";", "}", "return", "nameVarType", ";", "}", "return", "null", ";", "case", "GETPROP", ":", "String", "qualifiedName", "=", "node", ".", "getQualifiedName", "(", ")", ";", "if", "(", "qualifiedName", "==", "null", ")", "{", "return", "null", ";", "}", "StaticTypedSlot", "propVar", "=", "scope", ".", "getSlot", "(", "qualifiedName", ")", ";", "JSType", "propVarType", "=", "null", ";", "if", "(", "propVar", "!=", "null", ")", "{", "propVarType", "=", "propVar", ".", "getType", "(", ")", ";", "}", "if", "(", "propVarType", "==", "null", ")", "{", "propVarType", "=", "node", ".", "getJSType", "(", ")", ";", "}", "if", "(", "propVarType", "==", "null", ")", "{", "propVarType", "=", "getNativeType", "(", "UNKNOWN_TYPE", ")", ";", "}", "return", "propVarType", ";", "default", ":", "break", ";", "}", "return", "null", ";", "}" ]
Returns the type of a node in the given scope if the node corresponds to a name whose type is capable of being refined. @return The current type of the node if it can be refined, null otherwise.
[ "Returns", "the", "type", "of", "a", "node", "in", "the", "given", "scope", "if", "the", "node", "corresponds", "to", "a", "name", "whose", "type", "is", "capable", "of", "being", "refined", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java#L119-L153
25,008
google/closure-compiler
src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java
ChainableReverseAbstractInterpreter.getRestrictedWithoutUndefined
protected final JSType getRestrictedWithoutUndefined(JSType type) { return type == null ? null : type.visit(restrictUndefinedVisitor); }
java
protected final JSType getRestrictedWithoutUndefined(JSType type) { return type == null ? null : type.visit(restrictUndefinedVisitor); }
[ "protected", "final", "JSType", "getRestrictedWithoutUndefined", "(", "JSType", "type", ")", "{", "return", "type", "==", "null", "?", "null", ":", "type", ".", "visit", "(", "restrictUndefinedVisitor", ")", ";", "}" ]
Returns a version of type where undefined is not present.
[ "Returns", "a", "version", "of", "type", "where", "undefined", "is", "not", "present", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java#L691-L693
25,009
google/closure-compiler
src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java
ChainableReverseAbstractInterpreter.getRestrictedWithoutNull
protected final JSType getRestrictedWithoutNull(JSType type) { return type == null ? null : type.visit(restrictNullVisitor); }
java
protected final JSType getRestrictedWithoutNull(JSType type) { return type == null ? null : type.visit(restrictNullVisitor); }
[ "protected", "final", "JSType", "getRestrictedWithoutNull", "(", "JSType", "type", ")", "{", "return", "type", "==", "null", "?", "null", ":", "type", ".", "visit", "(", "restrictNullVisitor", ")", ";", "}" ]
Returns a version of type where null is not present.
[ "Returns", "a", "version", "of", "type", "where", "null", "is", "not", "present", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java#L698-L700
25,010
google/closure-compiler
src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java
ChainableReverseAbstractInterpreter.getNativeTypeForTypeOf
private JSType getNativeTypeForTypeOf(String value) { switch (value) { case "number": return getNativeType(NUMBER_TYPE); case "boolean": return getNativeType(BOOLEAN_TYPE); case "string": return getNativeType(STRING_TYPE); case "symbol": return getNativeType(SYMBOL_TYPE); case "undefined": return getNativeType(VOID_TYPE); case "function": return getNativeType(U2U_CONSTRUCTOR_TYPE); default: return null; } }
java
private JSType getNativeTypeForTypeOf(String value) { switch (value) { case "number": return getNativeType(NUMBER_TYPE); case "boolean": return getNativeType(BOOLEAN_TYPE); case "string": return getNativeType(STRING_TYPE); case "symbol": return getNativeType(SYMBOL_TYPE); case "undefined": return getNativeType(VOID_TYPE); case "function": return getNativeType(U2U_CONSTRUCTOR_TYPE); default: return null; } }
[ "private", "JSType", "getNativeTypeForTypeOf", "(", "String", "value", ")", "{", "switch", "(", "value", ")", "{", "case", "\"number\"", ":", "return", "getNativeType", "(", "NUMBER_TYPE", ")", ";", "case", "\"boolean\"", ":", "return", "getNativeType", "(", "BOOLEAN_TYPE", ")", ";", "case", "\"string\"", ":", "return", "getNativeType", "(", "STRING_TYPE", ")", ";", "case", "\"symbol\"", ":", "return", "getNativeType", "(", "SYMBOL_TYPE", ")", ";", "case", "\"undefined\"", ":", "return", "getNativeType", "(", "VOID_TYPE", ")", ";", "case", "\"function\"", ":", "return", "getNativeType", "(", "U2U_CONSTRUCTOR_TYPE", ")", ";", "default", ":", "return", "null", ";", "}", "}" ]
If we definitely know what a type is based on the typeof result, return it. Otherwise, return null. The typeof operation in JS is poorly defined, and this function works for both the native typeof and goog.typeOf. It should not be made public, because its semantics are informally defined, and would be wrong in the general case.
[ "If", "we", "definitely", "know", "what", "a", "type", "is", "based", "on", "the", "typeof", "result", "return", "it", ".", "Otherwise", "return", "null", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/type/ChainableReverseAbstractInterpreter.java#L756-L773
25,011
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.reconcileOptionsWithGuards
protected void reconcileOptionsWithGuards() { // DiagnosticGroups override the plain checkTypes option. if (options.enables(DiagnosticGroups.CHECK_TYPES)) { options.checkTypes = true; } else if (options.disables(DiagnosticGroups.CHECK_TYPES)) { options.checkTypes = false; } else if (!options.checkTypes) { // If DiagnosticGroups did not override the plain checkTypes // option, and checkTypes is disabled, then turn off the // parser type warnings. options.setWarningLevel( DiagnosticGroup.forType( RhinoErrorReporter.TYPE_PARSE_ERROR), CheckLevel.OFF); } if (options.checkGlobalThisLevel.isOn() && !options.disables(DiagnosticGroups.GLOBAL_THIS)) { options.setWarningLevel( DiagnosticGroups.GLOBAL_THIS, options.checkGlobalThisLevel); } if (options.expectStrictModeInput()) { options.setWarningLevel( DiagnosticGroups.ES5_STRICT, CheckLevel.ERROR); } // All passes must run the variable check. This synthesizes // variables later so that the compiler doesn't crash. It also // checks the externs file for validity. If you don't want to warn // about missing variable declarations, we shut that specific // error off. if (!options.checkSymbols && !options.enables(DiagnosticGroups.CHECK_VARIABLES)) { options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.OFF); } // If we're in transpile-only mode, we don't need to do checks for suspicious var usages. // Since we still have to run VariableReferenceCheck before transpilation to check block-scoped // variables, though, we disable the unnecessary warnings it produces relating to vars here. if (options.skipNonTranspilationPasses && !options.enables(DiagnosticGroups.CHECK_VARIABLES)) { options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.OFF); } // If we're in transpile-only mode, we don't need to check for missing requires unless the user // explicitly enables missing-provide checks. if (options.skipNonTranspilationPasses && !options.enables(DiagnosticGroups.MISSING_PROVIDE)) { options.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.OFF); } if (options.brokenClosureRequiresLevel == CheckLevel.OFF) { options.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.OFF); } }
java
protected void reconcileOptionsWithGuards() { // DiagnosticGroups override the plain checkTypes option. if (options.enables(DiagnosticGroups.CHECK_TYPES)) { options.checkTypes = true; } else if (options.disables(DiagnosticGroups.CHECK_TYPES)) { options.checkTypes = false; } else if (!options.checkTypes) { // If DiagnosticGroups did not override the plain checkTypes // option, and checkTypes is disabled, then turn off the // parser type warnings. options.setWarningLevel( DiagnosticGroup.forType( RhinoErrorReporter.TYPE_PARSE_ERROR), CheckLevel.OFF); } if (options.checkGlobalThisLevel.isOn() && !options.disables(DiagnosticGroups.GLOBAL_THIS)) { options.setWarningLevel( DiagnosticGroups.GLOBAL_THIS, options.checkGlobalThisLevel); } if (options.expectStrictModeInput()) { options.setWarningLevel( DiagnosticGroups.ES5_STRICT, CheckLevel.ERROR); } // All passes must run the variable check. This synthesizes // variables later so that the compiler doesn't crash. It also // checks the externs file for validity. If you don't want to warn // about missing variable declarations, we shut that specific // error off. if (!options.checkSymbols && !options.enables(DiagnosticGroups.CHECK_VARIABLES)) { options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.OFF); } // If we're in transpile-only mode, we don't need to do checks for suspicious var usages. // Since we still have to run VariableReferenceCheck before transpilation to check block-scoped // variables, though, we disable the unnecessary warnings it produces relating to vars here. if (options.skipNonTranspilationPasses && !options.enables(DiagnosticGroups.CHECK_VARIABLES)) { options.setWarningLevel(DiagnosticGroups.CHECK_VARIABLES, CheckLevel.OFF); } // If we're in transpile-only mode, we don't need to check for missing requires unless the user // explicitly enables missing-provide checks. if (options.skipNonTranspilationPasses && !options.enables(DiagnosticGroups.MISSING_PROVIDE)) { options.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.OFF); } if (options.brokenClosureRequiresLevel == CheckLevel.OFF) { options.setWarningLevel(DiagnosticGroups.MISSING_PROVIDE, CheckLevel.OFF); } }
[ "protected", "void", "reconcileOptionsWithGuards", "(", ")", "{", "// DiagnosticGroups override the plain checkTypes option.", "if", "(", "options", ".", "enables", "(", "DiagnosticGroups", ".", "CHECK_TYPES", ")", ")", "{", "options", ".", "checkTypes", "=", "true", ";", "}", "else", "if", "(", "options", ".", "disables", "(", "DiagnosticGroups", ".", "CHECK_TYPES", ")", ")", "{", "options", ".", "checkTypes", "=", "false", ";", "}", "else", "if", "(", "!", "options", ".", "checkTypes", ")", "{", "// If DiagnosticGroups did not override the plain checkTypes", "// option, and checkTypes is disabled, then turn off the", "// parser type warnings.", "options", ".", "setWarningLevel", "(", "DiagnosticGroup", ".", "forType", "(", "RhinoErrorReporter", ".", "TYPE_PARSE_ERROR", ")", ",", "CheckLevel", ".", "OFF", ")", ";", "}", "if", "(", "options", ".", "checkGlobalThisLevel", ".", "isOn", "(", ")", "&&", "!", "options", ".", "disables", "(", "DiagnosticGroups", ".", "GLOBAL_THIS", ")", ")", "{", "options", ".", "setWarningLevel", "(", "DiagnosticGroups", ".", "GLOBAL_THIS", ",", "options", ".", "checkGlobalThisLevel", ")", ";", "}", "if", "(", "options", ".", "expectStrictModeInput", "(", ")", ")", "{", "options", ".", "setWarningLevel", "(", "DiagnosticGroups", ".", "ES5_STRICT", ",", "CheckLevel", ".", "ERROR", ")", ";", "}", "// All passes must run the variable check. This synthesizes", "// variables later so that the compiler doesn't crash. It also", "// checks the externs file for validity. If you don't want to warn", "// about missing variable declarations, we shut that specific", "// error off.", "if", "(", "!", "options", ".", "checkSymbols", "&&", "!", "options", ".", "enables", "(", "DiagnosticGroups", ".", "CHECK_VARIABLES", ")", ")", "{", "options", ".", "setWarningLevel", "(", "DiagnosticGroups", ".", "CHECK_VARIABLES", ",", "CheckLevel", ".", "OFF", ")", ";", "}", "// If we're in transpile-only mode, we don't need to do checks for suspicious var usages.", "// Since we still have to run VariableReferenceCheck before transpilation to check block-scoped", "// variables, though, we disable the unnecessary warnings it produces relating to vars here.", "if", "(", "options", ".", "skipNonTranspilationPasses", "&&", "!", "options", ".", "enables", "(", "DiagnosticGroups", ".", "CHECK_VARIABLES", ")", ")", "{", "options", ".", "setWarningLevel", "(", "DiagnosticGroups", ".", "CHECK_VARIABLES", ",", "CheckLevel", ".", "OFF", ")", ";", "}", "// If we're in transpile-only mode, we don't need to check for missing requires unless the user", "// explicitly enables missing-provide checks.", "if", "(", "options", ".", "skipNonTranspilationPasses", "&&", "!", "options", ".", "enables", "(", "DiagnosticGroups", ".", "MISSING_PROVIDE", ")", ")", "{", "options", ".", "setWarningLevel", "(", "DiagnosticGroups", ".", "MISSING_PROVIDE", ",", "CheckLevel", ".", "OFF", ")", ";", "}", "if", "(", "options", ".", "brokenClosureRequiresLevel", "==", "CheckLevel", ".", "OFF", ")", "{", "options", ".", "setWarningLevel", "(", "DiagnosticGroups", ".", "MISSING_PROVIDE", ",", "CheckLevel", ".", "OFF", ")", ";", "}", "}" ]
When the CompilerOptions and its WarningsGuard overlap, reconcile any discrepancies.
[ "When", "the", "CompilerOptions", "and", "its", "WarningsGuard", "overlap", "reconcile", "any", "discrepancies", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L415-L468
25,012
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.init
public final <T1 extends SourceFile, T2 extends SourceFile> void init( List<T1> externs, List<T2> sources, CompilerOptions options) { JSModule module = new JSModule(JSModule.STRONG_MODULE_NAME); for (SourceFile source : sources) { module.add(new CompilerInput(source)); } List<JSModule> modules = new ArrayList<>(1); modules.add(module); initModules(externs, modules, options); addFilesToSourceMap(sources); }
java
public final <T1 extends SourceFile, T2 extends SourceFile> void init( List<T1> externs, List<T2> sources, CompilerOptions options) { JSModule module = new JSModule(JSModule.STRONG_MODULE_NAME); for (SourceFile source : sources) { module.add(new CompilerInput(source)); } List<JSModule> modules = new ArrayList<>(1); modules.add(module); initModules(externs, modules, options); addFilesToSourceMap(sources); }
[ "public", "final", "<", "T1", "extends", "SourceFile", ",", "T2", "extends", "SourceFile", ">", "void", "init", "(", "List", "<", "T1", ">", "externs", ",", "List", "<", "T2", ">", "sources", ",", "CompilerOptions", "options", ")", "{", "JSModule", "module", "=", "new", "JSModule", "(", "JSModule", ".", "STRONG_MODULE_NAME", ")", ";", "for", "(", "SourceFile", "source", ":", "sources", ")", "{", "module", ".", "add", "(", "new", "CompilerInput", "(", "source", ")", ")", ";", "}", "List", "<", "JSModule", ">", "modules", "=", "new", "ArrayList", "<>", "(", "1", ")", ";", "modules", ".", "add", "(", "module", ")", ";", "initModules", "(", "externs", ",", "modules", ",", "options", ")", ";", "addFilesToSourceMap", "(", "sources", ")", ";", "}" ]
Initializes the instance state needed for a compile job.
[ "Initializes", "the", "instance", "state", "needed", "for", "a", "compile", "job", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L471-L482
25,013
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.initModules
public <T extends SourceFile> void initModules( List<T> externs, List<JSModule> modules, CompilerOptions options) { initOptions(options); checkFirstModule(modules); this.externs = makeExternInputs(externs); // Generate the module graph, and report any errors in the module specification as errors. try { this.moduleGraph = new JSModuleGraph(modules); } catch (JSModuleGraph.ModuleDependenceException e) { // problems with the module format. Report as an error. The // message gives all details. report(JSError.make(MODULE_DEPENDENCY_ERROR, e.getModule().getName(), e.getDependentModule().getName())); return; } // Creating the module graph can move weak source around, and end up with empty modules. fillEmptyModules(getModules()); this.commentsPerFile = new ConcurrentHashMap<>(moduleGraph.getInputCount()); initBasedOnOptions(); initInputsByIdMap(); initAST(); }
java
public <T extends SourceFile> void initModules( List<T> externs, List<JSModule> modules, CompilerOptions options) { initOptions(options); checkFirstModule(modules); this.externs = makeExternInputs(externs); // Generate the module graph, and report any errors in the module specification as errors. try { this.moduleGraph = new JSModuleGraph(modules); } catch (JSModuleGraph.ModuleDependenceException e) { // problems with the module format. Report as an error. The // message gives all details. report(JSError.make(MODULE_DEPENDENCY_ERROR, e.getModule().getName(), e.getDependentModule().getName())); return; } // Creating the module graph can move weak source around, and end up with empty modules. fillEmptyModules(getModules()); this.commentsPerFile = new ConcurrentHashMap<>(moduleGraph.getInputCount()); initBasedOnOptions(); initInputsByIdMap(); initAST(); }
[ "public", "<", "T", "extends", "SourceFile", ">", "void", "initModules", "(", "List", "<", "T", ">", "externs", ",", "List", "<", "JSModule", ">", "modules", ",", "CompilerOptions", "options", ")", "{", "initOptions", "(", "options", ")", ";", "checkFirstModule", "(", "modules", ")", ";", "this", ".", "externs", "=", "makeExternInputs", "(", "externs", ")", ";", "// Generate the module graph, and report any errors in the module specification as errors.", "try", "{", "this", ".", "moduleGraph", "=", "new", "JSModuleGraph", "(", "modules", ")", ";", "}", "catch", "(", "JSModuleGraph", ".", "ModuleDependenceException", "e", ")", "{", "// problems with the module format. Report as an error. The", "// message gives all details.", "report", "(", "JSError", ".", "make", "(", "MODULE_DEPENDENCY_ERROR", ",", "e", ".", "getModule", "(", ")", ".", "getName", "(", ")", ",", "e", ".", "getDependentModule", "(", ")", ".", "getName", "(", ")", ")", ")", ";", "return", ";", "}", "// Creating the module graph can move weak source around, and end up with empty modules.", "fillEmptyModules", "(", "getModules", "(", ")", ")", ";", "this", ".", "commentsPerFile", "=", "new", "ConcurrentHashMap", "<>", "(", "moduleGraph", ".", "getInputCount", "(", ")", ")", ";", "initBasedOnOptions", "(", ")", ";", "initInputsByIdMap", "(", ")", ";", "initAST", "(", ")", ";", "}" ]
Initializes the instance state needed for a compile job if the sources are in modules.
[ "Initializes", "the", "instance", "state", "needed", "for", "a", "compile", "job", "if", "the", "sources", "are", "in", "modules", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L488-L516
25,014
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.initBasedOnOptions
public void initBasedOnOptions() { inputSourceMaps.putAll(options.inputSourceMaps); // Create the source map if necessary. if (options.sourceMapOutputPath != null) { sourceMap = options.sourceMapFormat.getInstance(); sourceMap.setPrefixMappings(options.sourceMapLocationMappings); if (options.applyInputSourceMaps) { sourceMap.setSourceFileMapping(this); if (options.sourceMapIncludeSourcesContent) { for (SourceMapInput inputSourceMap : inputSourceMaps.values()) { addSourceMapSourceFiles(inputSourceMap); } } } } }
java
public void initBasedOnOptions() { inputSourceMaps.putAll(options.inputSourceMaps); // Create the source map if necessary. if (options.sourceMapOutputPath != null) { sourceMap = options.sourceMapFormat.getInstance(); sourceMap.setPrefixMappings(options.sourceMapLocationMappings); if (options.applyInputSourceMaps) { sourceMap.setSourceFileMapping(this); if (options.sourceMapIncludeSourcesContent) { for (SourceMapInput inputSourceMap : inputSourceMaps.values()) { addSourceMapSourceFiles(inputSourceMap); } } } } }
[ "public", "void", "initBasedOnOptions", "(", ")", "{", "inputSourceMaps", ".", "putAll", "(", "options", ".", "inputSourceMaps", ")", ";", "// Create the source map if necessary.", "if", "(", "options", ".", "sourceMapOutputPath", "!=", "null", ")", "{", "sourceMap", "=", "options", ".", "sourceMapFormat", ".", "getInstance", "(", ")", ";", "sourceMap", ".", "setPrefixMappings", "(", "options", ".", "sourceMapLocationMappings", ")", ";", "if", "(", "options", ".", "applyInputSourceMaps", ")", "{", "sourceMap", ".", "setSourceFileMapping", "(", "this", ")", ";", "if", "(", "options", ".", "sourceMapIncludeSourcesContent", ")", "{", "for", "(", "SourceMapInput", "inputSourceMap", ":", "inputSourceMaps", ".", "values", "(", ")", ")", "{", "addSourceMapSourceFiles", "(", "inputSourceMap", ")", ";", "}", "}", "}", "}", "}" ]
Do any initialization that is dependent on the compiler options.
[ "Do", "any", "initialization", "that", "is", "dependent", "on", "the", "compiler", "options", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L521-L536
25,015
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.checkFirstModule
private void checkFirstModule(List<JSModule> modules) { if (modules.isEmpty()) { report(JSError.make(EMPTY_MODULE_LIST_ERROR)); } else if (modules.get(0).getInputs().isEmpty() && modules.size() > 1) { // The root module may only be empty if there is exactly 1 module. report(JSError.make(EMPTY_ROOT_MODULE_ERROR, modules.get(0).getName())); } }
java
private void checkFirstModule(List<JSModule> modules) { if (modules.isEmpty()) { report(JSError.make(EMPTY_MODULE_LIST_ERROR)); } else if (modules.get(0).getInputs().isEmpty() && modules.size() > 1) { // The root module may only be empty if there is exactly 1 module. report(JSError.make(EMPTY_ROOT_MODULE_ERROR, modules.get(0).getName())); } }
[ "private", "void", "checkFirstModule", "(", "List", "<", "JSModule", ">", "modules", ")", "{", "if", "(", "modules", ".", "isEmpty", "(", ")", ")", "{", "report", "(", "JSError", ".", "make", "(", "EMPTY_MODULE_LIST_ERROR", ")", ")", ";", "}", "else", "if", "(", "modules", ".", "get", "(", "0", ")", ".", "getInputs", "(", ")", ".", "isEmpty", "(", ")", "&&", "modules", ".", "size", "(", ")", ">", "1", ")", "{", "// The root module may only be empty if there is exactly 1 module.", "report", "(", "JSError", ".", "make", "(", "EMPTY_ROOT_MODULE_ERROR", ",", "modules", ".", "get", "(", "0", ")", ".", "getName", "(", ")", ")", ")", ";", "}", "}" ]
Verifies that at least one module has been provided and that the first one has at least one source code input.
[ "Verifies", "that", "at", "least", "one", "module", "has", "been", "provided", "and", "that", "the", "first", "one", "has", "at", "least", "one", "source", "code", "input", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L558-L566
25,016
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.fillEmptyModules
private void fillEmptyModules(Iterable<JSModule> modules) { for (JSModule module : modules) { if (!module.getName().equals(JSModule.WEAK_MODULE_NAME) && module.getInputs().isEmpty()) { CompilerInput input = new CompilerInput(SourceFile.fromCode(createFillFileName(module.getName()), "")); input.setCompiler(this); module.add(input); } } }
java
private void fillEmptyModules(Iterable<JSModule> modules) { for (JSModule module : modules) { if (!module.getName().equals(JSModule.WEAK_MODULE_NAME) && module.getInputs().isEmpty()) { CompilerInput input = new CompilerInput(SourceFile.fromCode(createFillFileName(module.getName()), "")); input.setCompiler(this); module.add(input); } } }
[ "private", "void", "fillEmptyModules", "(", "Iterable", "<", "JSModule", ">", "modules", ")", "{", "for", "(", "JSModule", "module", ":", "modules", ")", "{", "if", "(", "!", "module", ".", "getName", "(", ")", ".", "equals", "(", "JSModule", ".", "WEAK_MODULE_NAME", ")", "&&", "module", ".", "getInputs", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "CompilerInput", "input", "=", "new", "CompilerInput", "(", "SourceFile", ".", "fromCode", "(", "createFillFileName", "(", "module", ".", "getName", "(", ")", ")", ",", "\"\"", ")", ")", ";", "input", ".", "setCompiler", "(", "this", ")", ";", "module", ".", "add", "(", "input", ")", ";", "}", "}", "}" ]
Fill any empty modules with a place holder file. It makes any cross module motion easier.
[ "Fill", "any", "empty", "modules", "with", "a", "place", "holder", "file", ".", "It", "makes", "any", "cross", "module", "motion", "easier", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L576-L585
25,017
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.initInputsByIdMap
void initInputsByIdMap() { inputsById.clear(); for (CompilerInput input : externs) { InputId id = input.getInputId(); CompilerInput previous = putCompilerInput(id, input); if (previous != null) { report(JSError.make(DUPLICATE_EXTERN_INPUT, input.getName())); } } for (CompilerInput input : moduleGraph.getAllInputs()) { InputId id = input.getInputId(); CompilerInput previous = putCompilerInput(id, input); if (previous != null) { report(JSError.make(DUPLICATE_INPUT, input.getName())); } } }
java
void initInputsByIdMap() { inputsById.clear(); for (CompilerInput input : externs) { InputId id = input.getInputId(); CompilerInput previous = putCompilerInput(id, input); if (previous != null) { report(JSError.make(DUPLICATE_EXTERN_INPUT, input.getName())); } } for (CompilerInput input : moduleGraph.getAllInputs()) { InputId id = input.getInputId(); CompilerInput previous = putCompilerInput(id, input); if (previous != null) { report(JSError.make(DUPLICATE_INPUT, input.getName())); } } }
[ "void", "initInputsByIdMap", "(", ")", "{", "inputsById", ".", "clear", "(", ")", ";", "for", "(", "CompilerInput", "input", ":", "externs", ")", "{", "InputId", "id", "=", "input", ".", "getInputId", "(", ")", ";", "CompilerInput", "previous", "=", "putCompilerInput", "(", "id", ",", "input", ")", ";", "if", "(", "previous", "!=", "null", ")", "{", "report", "(", "JSError", ".", "make", "(", "DUPLICATE_EXTERN_INPUT", ",", "input", ".", "getName", "(", ")", ")", ")", ";", "}", "}", "for", "(", "CompilerInput", "input", ":", "moduleGraph", ".", "getAllInputs", "(", ")", ")", "{", "InputId", "id", "=", "input", ".", "getInputId", "(", ")", ";", "CompilerInput", "previous", "=", "putCompilerInput", "(", "id", ",", "input", ")", ";", "if", "(", "previous", "!=", "null", ")", "{", "report", "(", "JSError", ".", "make", "(", "DUPLICATE_INPUT", ",", "input", ".", "getName", "(", ")", ")", ")", ";", "}", "}", "}" ]
Creates a map to make looking up an input by name fast. Also checks for duplicate inputs.
[ "Creates", "a", "map", "to", "make", "looking", "up", "an", "input", "by", "name", "fast", ".", "Also", "checks", "for", "duplicate", "inputs", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L605-L621
25,018
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.compile
public Result compile(SourceFile extern, SourceFile input, CompilerOptions options) { return compile(ImmutableList.of(extern), ImmutableList.of(input), options); }
java
public Result compile(SourceFile extern, SourceFile input, CompilerOptions options) { return compile(ImmutableList.of(extern), ImmutableList.of(input), options); }
[ "public", "Result", "compile", "(", "SourceFile", "extern", ",", "SourceFile", "input", ",", "CompilerOptions", "options", ")", "{", "return", "compile", "(", "ImmutableList", ".", "of", "(", "extern", ")", ",", "ImmutableList", ".", "of", "(", "input", ")", ",", "options", ")", ";", "}" ]
Compiles a single source file and a single externs file.
[ "Compiles", "a", "single", "source", "file", "and", "a", "single", "externs", "file", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L633-L635
25,019
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.compile
public <T1 extends SourceFile, T2 extends SourceFile> Result compile( List<T1> externs, List<T2> inputs, CompilerOptions options) { // The compile method should only be called once. checkState(jsRoot == null); try { init(externs, inputs, options); if (options.printConfig) { printConfig(System.err); } if (!hasErrors()) { parseForCompilation(); } if (!hasErrors()) { if (options.getInstrumentForCoverageOnly()) { // TODO(bradfordcsmith): The option to instrument for coverage only should belong to the // runner, not the compiler. instrumentForCoverage(); } else { stage1Passes(); if (!hasErrors()) { stage2Passes(); } } performPostCompilationTasks(); } } finally { generateReport(); } return getResult(); }
java
public <T1 extends SourceFile, T2 extends SourceFile> Result compile( List<T1> externs, List<T2> inputs, CompilerOptions options) { // The compile method should only be called once. checkState(jsRoot == null); try { init(externs, inputs, options); if (options.printConfig) { printConfig(System.err); } if (!hasErrors()) { parseForCompilation(); } if (!hasErrors()) { if (options.getInstrumentForCoverageOnly()) { // TODO(bradfordcsmith): The option to instrument for coverage only should belong to the // runner, not the compiler. instrumentForCoverage(); } else { stage1Passes(); if (!hasErrors()) { stage2Passes(); } } performPostCompilationTasks(); } } finally { generateReport(); } return getResult(); }
[ "public", "<", "T1", "extends", "SourceFile", ",", "T2", "extends", "SourceFile", ">", "Result", "compile", "(", "List", "<", "T1", ">", "externs", ",", "List", "<", "T2", ">", "inputs", ",", "CompilerOptions", "options", ")", "{", "// The compile method should only be called once.", "checkState", "(", "jsRoot", "==", "null", ")", ";", "try", "{", "init", "(", "externs", ",", "inputs", ",", "options", ")", ";", "if", "(", "options", ".", "printConfig", ")", "{", "printConfig", "(", "System", ".", "err", ")", ";", "}", "if", "(", "!", "hasErrors", "(", ")", ")", "{", "parseForCompilation", "(", ")", ";", "}", "if", "(", "!", "hasErrors", "(", ")", ")", "{", "if", "(", "options", ".", "getInstrumentForCoverageOnly", "(", ")", ")", "{", "// TODO(bradfordcsmith): The option to instrument for coverage only should belong to the", "// runner, not the compiler.", "instrumentForCoverage", "(", ")", ";", "}", "else", "{", "stage1Passes", "(", ")", ";", "if", "(", "!", "hasErrors", "(", ")", ")", "{", "stage2Passes", "(", ")", ";", "}", "}", "performPostCompilationTasks", "(", ")", ";", "}", "}", "finally", "{", "generateReport", "(", ")", ";", "}", "return", "getResult", "(", ")", ";", "}" ]
Compiles a list of inputs. <p>This is a convenience method to wrap up all the work of compilation, including generating the error and warning report. <p>NOTE: All methods called here must be public, because client code must be able to replicate and customize this.
[ "Compiles", "a", "list", "of", "inputs", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L646-L676
25,020
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.compileModules
public <T extends SourceFile> Result compileModules( List<T> externs, List<JSModule> modules, CompilerOptions options) { // The compile method should only be called once. checkState(jsRoot == null); try { initModules(externs, modules, options); if (options.printConfig) { printConfig(System.err); } if (!hasErrors()) { parseForCompilation(); } if (!hasErrors()) { // TODO(bradfordcsmith): The option to instrument for coverage only should belong to the // runner, not the compiler. if (options.getInstrumentForCoverageOnly()) { instrumentForCoverage(); } else { stage1Passes(); if (!hasErrors()) { stage2Passes(); } } performPostCompilationTasks(); } } finally { generateReport(); } return getResult(); }
java
public <T extends SourceFile> Result compileModules( List<T> externs, List<JSModule> modules, CompilerOptions options) { // The compile method should only be called once. checkState(jsRoot == null); try { initModules(externs, modules, options); if (options.printConfig) { printConfig(System.err); } if (!hasErrors()) { parseForCompilation(); } if (!hasErrors()) { // TODO(bradfordcsmith): The option to instrument for coverage only should belong to the // runner, not the compiler. if (options.getInstrumentForCoverageOnly()) { instrumentForCoverage(); } else { stage1Passes(); if (!hasErrors()) { stage2Passes(); } } performPostCompilationTasks(); } } finally { generateReport(); } return getResult(); }
[ "public", "<", "T", "extends", "SourceFile", ">", "Result", "compileModules", "(", "List", "<", "T", ">", "externs", ",", "List", "<", "JSModule", ">", "modules", ",", "CompilerOptions", "options", ")", "{", "// The compile method should only be called once.", "checkState", "(", "jsRoot", "==", "null", ")", ";", "try", "{", "initModules", "(", "externs", ",", "modules", ",", "options", ")", ";", "if", "(", "options", ".", "printConfig", ")", "{", "printConfig", "(", "System", ".", "err", ")", ";", "}", "if", "(", "!", "hasErrors", "(", ")", ")", "{", "parseForCompilation", "(", ")", ";", "}", "if", "(", "!", "hasErrors", "(", ")", ")", "{", "// TODO(bradfordcsmith): The option to instrument for coverage only should belong to the", "// runner, not the compiler.", "if", "(", "options", ".", "getInstrumentForCoverageOnly", "(", ")", ")", "{", "instrumentForCoverage", "(", ")", ";", "}", "else", "{", "stage1Passes", "(", ")", ";", "if", "(", "!", "hasErrors", "(", ")", ")", "{", "stage2Passes", "(", ")", ";", "}", "}", "performPostCompilationTasks", "(", ")", ";", "}", "}", "finally", "{", "generateReport", "(", ")", ";", "}", "return", "getResult", "(", ")", ";", "}" ]
Compiles a list of modules. <p>This is a convenience method to wrap up all the work of compilation, including generating the error and warning report. <p>NOTE: All methods called here must be public, because client code must be able to replicate and customize this.
[ "Compiles", "a", "list", "of", "modules", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L701-L731
25,021
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.stage1Passes
public void stage1Passes() { checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?"); checkState(!hasErrors()); checkState(!options.getInstrumentForCoverageOnly()); runInCompilerThread( () -> { performChecksAndTranspilation(); return null; }); }
java
public void stage1Passes() { checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?"); checkState(!hasErrors()); checkState(!options.getInstrumentForCoverageOnly()); runInCompilerThread( () -> { performChecksAndTranspilation(); return null; }); }
[ "public", "void", "stage1Passes", "(", ")", "{", "checkState", "(", "moduleGraph", "!=", "null", ",", "\"No inputs. Did you call init() or initModules()?\"", ")", ";", "checkState", "(", "!", "hasErrors", "(", ")", ")", ";", "checkState", "(", "!", "options", ".", "getInstrumentForCoverageOnly", "(", ")", ")", ";", "runInCompilerThread", "(", "(", ")", "->", "{", "performChecksAndTranspilation", "(", ")", ";", "return", "null", ";", "}", ")", ";", "}" ]
Perform compiler passes for stage 1 of compilation. <p>Stage 1 consists primarily of error and type checking passes. <p>{@code parseForCompilation()} must be called before this method is called. <p>The caller is responsible for also calling {@code generateReport()} to generate a report of warnings and errors to stderr. See the invocation in {@link #compile} for a good example.
[ "Perform", "compiler", "passes", "for", "stage", "1", "of", "compilation", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L743-L752
25,022
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.stage2Passes
public void stage2Passes() { checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?"); checkState(!hasErrors()); checkState(!options.getInstrumentForCoverageOnly()); JSModule weakModule = moduleGraph.getModuleByName(JSModule.WEAK_MODULE_NAME); if (weakModule != null) { for (CompilerInput i : moduleGraph.getAllInputs()) { if (i.getSourceFile().isWeak()) { checkState( i.getModule() == weakModule, "Expected all weak files to be in the weak module."); } } } runInCompilerThread( () -> { if (options.shouldOptimize()) { performOptimizations(); } return null; }); }
java
public void stage2Passes() { checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?"); checkState(!hasErrors()); checkState(!options.getInstrumentForCoverageOnly()); JSModule weakModule = moduleGraph.getModuleByName(JSModule.WEAK_MODULE_NAME); if (weakModule != null) { for (CompilerInput i : moduleGraph.getAllInputs()) { if (i.getSourceFile().isWeak()) { checkState( i.getModule() == weakModule, "Expected all weak files to be in the weak module."); } } } runInCompilerThread( () -> { if (options.shouldOptimize()) { performOptimizations(); } return null; }); }
[ "public", "void", "stage2Passes", "(", ")", "{", "checkState", "(", "moduleGraph", "!=", "null", ",", "\"No inputs. Did you call init() or initModules()?\"", ")", ";", "checkState", "(", "!", "hasErrors", "(", ")", ")", ";", "checkState", "(", "!", "options", ".", "getInstrumentForCoverageOnly", "(", ")", ")", ";", "JSModule", "weakModule", "=", "moduleGraph", ".", "getModuleByName", "(", "JSModule", ".", "WEAK_MODULE_NAME", ")", ";", "if", "(", "weakModule", "!=", "null", ")", "{", "for", "(", "CompilerInput", "i", ":", "moduleGraph", ".", "getAllInputs", "(", ")", ")", "{", "if", "(", "i", ".", "getSourceFile", "(", ")", ".", "isWeak", "(", ")", ")", "{", "checkState", "(", "i", ".", "getModule", "(", ")", "==", "weakModule", ",", "\"Expected all weak files to be in the weak module.\"", ")", ";", "}", "}", "}", "runInCompilerThread", "(", "(", ")", "->", "{", "if", "(", "options", ".", "shouldOptimize", "(", ")", ")", "{", "performOptimizations", "(", ")", ";", "}", "return", "null", ";", "}", ")", ";", "}" ]
Perform compiler passes for stage 2 of compilation. <p>Stage 2 consists primarily of optimization passes. <p>{@code stage1Passes()} must be called before this method is called. <p>The caller is responsible for also calling {@code generateReport()} to generate a report of warnings and errors to stderr. See the invocation in {@link #compile} for a good example.
[ "Perform", "compiler", "passes", "for", "stage", "2", "of", "compilation", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L764-L784
25,023
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.runInCompilerThread
<T> T runInCompilerThread(Callable<T> callable) { return compilerExecutor.runInCompilerThread( callable, options != null && options.getTracerMode().isOn()); }
java
<T> T runInCompilerThread(Callable<T> callable) { return compilerExecutor.runInCompilerThread( callable, options != null && options.getTracerMode().isOn()); }
[ "<", "T", ">", "T", "runInCompilerThread", "(", "Callable", "<", "T", ">", "callable", ")", "{", "return", "compilerExecutor", ".", "runInCompilerThread", "(", "callable", ",", "options", "!=", "null", "&&", "options", ".", "getTracerMode", "(", ")", ".", "isOn", "(", ")", ")", ";", "}" ]
The primary purpose of this method is to run the provided code with a larger than standard stack.
[ "The", "primary", "purpose", "of", "this", "method", "is", "to", "run", "the", "provided", "code", "with", "a", "larger", "than", "standard", "stack", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L806-L809
25,024
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.performPostCompilationTasksInternal
private void performPostCompilationTasksInternal() { if (options.devMode == DevMode.START_AND_END) { runValidityCheck(); } setProgress(1.0, "recordFunctionInformation"); if (tracker != null) { tracker.outputTracerReport(); } }
java
private void performPostCompilationTasksInternal() { if (options.devMode == DevMode.START_AND_END) { runValidityCheck(); } setProgress(1.0, "recordFunctionInformation"); if (tracker != null) { tracker.outputTracerReport(); } }
[ "private", "void", "performPostCompilationTasksInternal", "(", ")", "{", "if", "(", "options", ".", "devMode", "==", "DevMode", ".", "START_AND_END", ")", "{", "runValidityCheck", "(", ")", ";", "}", "setProgress", "(", "1.0", ",", "\"recordFunctionInformation\"", ")", ";", "if", "(", "tracker", "!=", "null", ")", "{", "tracker", ".", "outputTracerReport", "(", ")", ";", "}", "}" ]
Performs all the bookkeeping required at the end of a compilation.
[ "Performs", "all", "the", "bookkeeping", "required", "at", "the", "end", "of", "a", "compilation", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L841-L850
25,025
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.instrumentForCoverage
public void instrumentForCoverage() { checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?"); checkState(!hasErrors()); runInCompilerThread( () -> { checkState(options.getInstrumentForCoverageOnly()); checkState(!hasErrors()); instrumentForCoverageInternal(options.instrumentBranchCoverage); return null; }); }
java
public void instrumentForCoverage() { checkState(moduleGraph != null, "No inputs. Did you call init() or initModules()?"); checkState(!hasErrors()); runInCompilerThread( () -> { checkState(options.getInstrumentForCoverageOnly()); checkState(!hasErrors()); instrumentForCoverageInternal(options.instrumentBranchCoverage); return null; }); }
[ "public", "void", "instrumentForCoverage", "(", ")", "{", "checkState", "(", "moduleGraph", "!=", "null", ",", "\"No inputs. Did you call init() or initModules()?\"", ")", ";", "checkState", "(", "!", "hasErrors", "(", ")", ")", ";", "runInCompilerThread", "(", "(", ")", "->", "{", "checkState", "(", "options", ".", "getInstrumentForCoverageOnly", "(", ")", ")", ";", "checkState", "(", "!", "hasErrors", "(", ")", ")", ";", "instrumentForCoverageInternal", "(", "options", ".", "instrumentBranchCoverage", ")", ";", "return", "null", ";", "}", ")", ";", "}" ]
Instrument code for coverage. <p>{@code parseForCompilation()} must be called before this method is called. <p>The caller is responsible for also calling {@code generateReport()} to generate a report of warnings and errors to stderr. See the invocation in {@link #compile} for a good example. <p>This method is mutually exclusive with stage1Passes() and stage2Passes(). Either call those two methods or this one, but not both.
[ "Instrument", "code", "for", "coverage", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L863-L873
25,026
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.startPass
void startPass(String passName) { checkState(currentTracer == null); currentPassName = passName; currentTracer = newTracer(passName); beforePass(passName); }
java
void startPass(String passName) { checkState(currentTracer == null); currentPassName = passName; currentTracer = newTracer(passName); beforePass(passName); }
[ "void", "startPass", "(", "String", "passName", ")", "{", "checkState", "(", "currentTracer", "==", "null", ")", ";", "currentPassName", "=", "passName", ";", "currentTracer", "=", "newTracer", "(", "passName", ")", ";", "beforePass", "(", "passName", ")", ";", "}" ]
Marks the beginning of a pass.
[ "Marks", "the", "beginning", "of", "a", "pass", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1074-L1079
25,027
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.endPass
void endPass(String passName) { checkState(currentTracer != null, "Tracer should not be null at the end of a pass."); stopTracer(currentTracer, currentPassName); afterPass(passName); currentPassName = null; currentTracer = null; maybeRunValidityCheck(); }
java
void endPass(String passName) { checkState(currentTracer != null, "Tracer should not be null at the end of a pass."); stopTracer(currentTracer, currentPassName); afterPass(passName); currentPassName = null; currentTracer = null; maybeRunValidityCheck(); }
[ "void", "endPass", "(", "String", "passName", ")", "{", "checkState", "(", "currentTracer", "!=", "null", ",", "\"Tracer should not be null at the end of a pass.\"", ")", ";", "stopTracer", "(", "currentTracer", ",", "currentPassName", ")", ";", "afterPass", "(", "passName", ")", ";", "currentPassName", "=", "null", ";", "currentTracer", "=", "null", ";", "maybeRunValidityCheck", "(", ")", ";", "}" ]
Marks the end of a pass.
[ "Marks", "the", "end", "of", "a", "pass", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1084-L1092
25,028
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.newTracer
Tracer newTracer(String passName) { String comment = passName + (recentChange.hasCodeChanged() ? " on recently changed AST" : ""); if (options.getTracerMode().isOn() && tracker != null) { tracker.recordPassStart(passName, true); } return new Tracer("Compiler", comment); }
java
Tracer newTracer(String passName) { String comment = passName + (recentChange.hasCodeChanged() ? " on recently changed AST" : ""); if (options.getTracerMode().isOn() && tracker != null) { tracker.recordPassStart(passName, true); } return new Tracer("Compiler", comment); }
[ "Tracer", "newTracer", "(", "String", "passName", ")", "{", "String", "comment", "=", "passName", "+", "(", "recentChange", ".", "hasCodeChanged", "(", ")", "?", "\" on recently changed AST\"", ":", "\"\"", ")", ";", "if", "(", "options", ".", "getTracerMode", "(", ")", ".", "isOn", "(", ")", "&&", "tracker", "!=", "null", ")", "{", "tracker", ".", "recordPassStart", "(", "passName", ",", "true", ")", ";", "}", "return", "new", "Tracer", "(", "\"Compiler\"", ",", "comment", ")", ";", "}" ]
Returns a new tracer for the given pass name.
[ "Returns", "a", "new", "tracer", "for", "the", "given", "pass", "name", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1177-L1184
25,029
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.getResult
public Result getResult() { Set<SourceFile> transpiledFiles = new HashSet<>(); if (jsRoot != null) { for (Node scriptNode : jsRoot.children()) { if (scriptNode.getBooleanProp(Node.TRANSPILED)) { transpiledFiles.add(getSourceFileByName(scriptNode.getSourceFileName())); } } } return new Result( getErrors(), getWarnings(), this.variableMap, this.propertyMap, this.anonymousFunctionNameMap, this.stringMap, this.sourceMap, this.externExports, this.cssNames, this.idGeneratorMap, transpiledFiles); }
java
public Result getResult() { Set<SourceFile> transpiledFiles = new HashSet<>(); if (jsRoot != null) { for (Node scriptNode : jsRoot.children()) { if (scriptNode.getBooleanProp(Node.TRANSPILED)) { transpiledFiles.add(getSourceFileByName(scriptNode.getSourceFileName())); } } } return new Result( getErrors(), getWarnings(), this.variableMap, this.propertyMap, this.anonymousFunctionNameMap, this.stringMap, this.sourceMap, this.externExports, this.cssNames, this.idGeneratorMap, transpiledFiles); }
[ "public", "Result", "getResult", "(", ")", "{", "Set", "<", "SourceFile", ">", "transpiledFiles", "=", "new", "HashSet", "<>", "(", ")", ";", "if", "(", "jsRoot", "!=", "null", ")", "{", "for", "(", "Node", "scriptNode", ":", "jsRoot", ".", "children", "(", ")", ")", "{", "if", "(", "scriptNode", ".", "getBooleanProp", "(", "Node", ".", "TRANSPILED", ")", ")", "{", "transpiledFiles", ".", "add", "(", "getSourceFileByName", "(", "scriptNode", ".", "getSourceFileName", "(", ")", ")", ")", ";", "}", "}", "}", "return", "new", "Result", "(", "getErrors", "(", ")", ",", "getWarnings", "(", ")", ",", "this", ".", "variableMap", ",", "this", ".", "propertyMap", ",", "this", ".", "anonymousFunctionNameMap", ",", "this", ".", "stringMap", ",", "this", ".", "sourceMap", ",", "this", ".", "externExports", ",", "this", ".", "cssNames", ",", "this", ".", "idGeneratorMap", ",", "transpiledFiles", ")", ";", "}" ]
Returns the result of the compilation.
[ "Returns", "the", "result", "of", "the", "compilation", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1196-L1217
25,030
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.getInput
@Override public CompilerInput getInput(InputId id) { // TODO(bradfordcsmith): Allowing null id is less ideal. Add checkNotNull(id) here and fix // call sites that break. if (id == null) { return null; } return inputsById.get(id); }
java
@Override public CompilerInput getInput(InputId id) { // TODO(bradfordcsmith): Allowing null id is less ideal. Add checkNotNull(id) here and fix // call sites that break. if (id == null) { return null; } return inputsById.get(id); }
[ "@", "Override", "public", "CompilerInput", "getInput", "(", "InputId", "id", ")", "{", "// TODO(bradfordcsmith): Allowing null id is less ideal. Add checkNotNull(id) here and fix", "// call sites that break.", "if", "(", "id", "==", "null", ")", "{", "return", "null", ";", "}", "return", "inputsById", ".", "get", "(", "id", ")", ";", "}" ]
interface, and which ones should always be injected.
[ "interface", "and", "which", "ones", "should", "always", "be", "injected", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1282-L1290
25,031
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.removeExternInput
protected void removeExternInput(InputId id) { CompilerInput input = getInput(id); if (input == null) { return; } checkState(input.isExtern(), "Not an extern input: %s", input.getName()); inputsById.remove(id); externs.remove(input); Node root = checkNotNull(input.getAstRoot(this)); if (root != null) { root.detach(); } }
java
protected void removeExternInput(InputId id) { CompilerInput input = getInput(id); if (input == null) { return; } checkState(input.isExtern(), "Not an extern input: %s", input.getName()); inputsById.remove(id); externs.remove(input); Node root = checkNotNull(input.getAstRoot(this)); if (root != null) { root.detach(); } }
[ "protected", "void", "removeExternInput", "(", "InputId", "id", ")", "{", "CompilerInput", "input", "=", "getInput", "(", "id", ")", ";", "if", "(", "input", "==", "null", ")", "{", "return", ";", "}", "checkState", "(", "input", ".", "isExtern", "(", ")", ",", "\"Not an extern input: %s\"", ",", "input", ".", "getName", "(", ")", ")", ";", "inputsById", ".", "remove", "(", "id", ")", ";", "externs", ".", "remove", "(", "input", ")", ";", "Node", "root", "=", "checkNotNull", "(", "input", ".", "getAstRoot", "(", "this", ")", ")", ";", "if", "(", "root", "!=", "null", ")", "{", "root", ".", "detach", "(", ")", ";", "}", "}" ]
Removes an input file from AST. @param id The id of the input to be removed.
[ "Removes", "an", "input", "file", "from", "AST", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1296-L1308
25,032
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.replaceIncrementalSourceAst
boolean replaceIncrementalSourceAst(JsAst ast) { CompilerInput oldInput = getInput(ast.getInputId()); checkNotNull(oldInput, "No input to replace: %s", ast.getInputId().getIdName()); Node newRoot = checkNotNull(ast.getAstRoot(this)); Node oldRoot = oldInput.getAstRoot(this); oldRoot.replaceWith(newRoot); CompilerInput newInput = new CompilerInput(ast); putCompilerInput(ast.getInputId(), newInput); JSModule module = oldInput.getModule(); if (module != null) { module.addAfter(newInput, oldInput); module.remove(oldInput); } // Verify the input id is set properly. checkState(newInput.getInputId().equals(oldInput.getInputId())); InputId inputIdOnAst = newInput.getAstRoot(this).getInputId(); checkState(newInput.getInputId().equals(inputIdOnAst)); return true; }
java
boolean replaceIncrementalSourceAst(JsAst ast) { CompilerInput oldInput = getInput(ast.getInputId()); checkNotNull(oldInput, "No input to replace: %s", ast.getInputId().getIdName()); Node newRoot = checkNotNull(ast.getAstRoot(this)); Node oldRoot = oldInput.getAstRoot(this); oldRoot.replaceWith(newRoot); CompilerInput newInput = new CompilerInput(ast); putCompilerInput(ast.getInputId(), newInput); JSModule module = oldInput.getModule(); if (module != null) { module.addAfter(newInput, oldInput); module.remove(oldInput); } // Verify the input id is set properly. checkState(newInput.getInputId().equals(oldInput.getInputId())); InputId inputIdOnAst = newInput.getAstRoot(this).getInputId(); checkState(newInput.getInputId().equals(inputIdOnAst)); return true; }
[ "boolean", "replaceIncrementalSourceAst", "(", "JsAst", "ast", ")", "{", "CompilerInput", "oldInput", "=", "getInput", "(", "ast", ".", "getInputId", "(", ")", ")", ";", "checkNotNull", "(", "oldInput", ",", "\"No input to replace: %s\"", ",", "ast", ".", "getInputId", "(", ")", ".", "getIdName", "(", ")", ")", ";", "Node", "newRoot", "=", "checkNotNull", "(", "ast", ".", "getAstRoot", "(", "this", ")", ")", ";", "Node", "oldRoot", "=", "oldInput", ".", "getAstRoot", "(", "this", ")", ";", "oldRoot", ".", "replaceWith", "(", "newRoot", ")", ";", "CompilerInput", "newInput", "=", "new", "CompilerInput", "(", "ast", ")", ";", "putCompilerInput", "(", "ast", ".", "getInputId", "(", ")", ",", "newInput", ")", ";", "JSModule", "module", "=", "oldInput", ".", "getModule", "(", ")", ";", "if", "(", "module", "!=", "null", ")", "{", "module", ".", "addAfter", "(", "newInput", ",", "oldInput", ")", ";", "module", ".", "remove", "(", "oldInput", ")", ";", "}", "// Verify the input id is set properly.", "checkState", "(", "newInput", ".", "getInputId", "(", ")", ".", "equals", "(", "oldInput", ".", "getInputId", "(", ")", ")", ")", ";", "InputId", "inputIdOnAst", "=", "newInput", ".", "getAstRoot", "(", "this", ")", ".", "getInputId", "(", ")", ";", "checkState", "(", "newInput", ".", "getInputId", "(", ")", ".", "equals", "(", "inputIdOnAst", ")", ")", ";", "return", "true", ";", "}" ]
Replace a source input dynamically. Intended for incremental re-compilation. If the new source input doesn't parse, then keep the old input in the AST and return false. @return Whether the new AST was attached successfully.
[ "Replace", "a", "source", "input", "dynamically", ".", "Intended", "for", "incremental", "re", "-", "compilation", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1347-L1369
25,033
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.findModulesFromEntryPoints
private void findModulesFromEntryPoints( boolean supportEs6Modules, boolean supportCommonJSModules) { maybeDoThreadedParsing(); List<CompilerInput> entryPoints = new ArrayList<>(); Map<String, CompilerInput> inputsByProvide = new HashMap<>(); Map<String, CompilerInput> inputsByIdentifier = new HashMap<>(); for (CompilerInput input : moduleGraph.getAllInputs()) { if (!options.getDependencyOptions().shouldDropMoochers() && input.getProvides().isEmpty()) { entryPoints.add(input); } inputsByIdentifier.put( ModuleIdentifier.forFile(input.getPath().toString()).toString(), input); for (String provide : input.getProvides()) { if (!provide.startsWith("module$")) { inputsByProvide.put(provide, input); } } } for (ModuleIdentifier moduleIdentifier : options.getDependencyOptions().getEntryPoints()) { CompilerInput input = inputsByProvide.get(moduleIdentifier.toString()); if (input == null) { input = inputsByIdentifier.get(moduleIdentifier.toString()); } if (input != null) { entryPoints.add(input); } } Set<CompilerInput> workingInputSet = Sets.newHashSet(moduleGraph.getAllInputs()); for (CompilerInput entryPoint : entryPoints) { findModulesFromInput( entryPoint, /* wasImportedByModule = */ false, workingInputSet, inputsByIdentifier, inputsByProvide, supportEs6Modules, supportCommonJSModules); } }
java
private void findModulesFromEntryPoints( boolean supportEs6Modules, boolean supportCommonJSModules) { maybeDoThreadedParsing(); List<CompilerInput> entryPoints = new ArrayList<>(); Map<String, CompilerInput> inputsByProvide = new HashMap<>(); Map<String, CompilerInput> inputsByIdentifier = new HashMap<>(); for (CompilerInput input : moduleGraph.getAllInputs()) { if (!options.getDependencyOptions().shouldDropMoochers() && input.getProvides().isEmpty()) { entryPoints.add(input); } inputsByIdentifier.put( ModuleIdentifier.forFile(input.getPath().toString()).toString(), input); for (String provide : input.getProvides()) { if (!provide.startsWith("module$")) { inputsByProvide.put(provide, input); } } } for (ModuleIdentifier moduleIdentifier : options.getDependencyOptions().getEntryPoints()) { CompilerInput input = inputsByProvide.get(moduleIdentifier.toString()); if (input == null) { input = inputsByIdentifier.get(moduleIdentifier.toString()); } if (input != null) { entryPoints.add(input); } } Set<CompilerInput> workingInputSet = Sets.newHashSet(moduleGraph.getAllInputs()); for (CompilerInput entryPoint : entryPoints) { findModulesFromInput( entryPoint, /* wasImportedByModule = */ false, workingInputSet, inputsByIdentifier, inputsByProvide, supportEs6Modules, supportCommonJSModules); } }
[ "private", "void", "findModulesFromEntryPoints", "(", "boolean", "supportEs6Modules", ",", "boolean", "supportCommonJSModules", ")", "{", "maybeDoThreadedParsing", "(", ")", ";", "List", "<", "CompilerInput", ">", "entryPoints", "=", "new", "ArrayList", "<>", "(", ")", ";", "Map", "<", "String", ",", "CompilerInput", ">", "inputsByProvide", "=", "new", "HashMap", "<>", "(", ")", ";", "Map", "<", "String", ",", "CompilerInput", ">", "inputsByIdentifier", "=", "new", "HashMap", "<>", "(", ")", ";", "for", "(", "CompilerInput", "input", ":", "moduleGraph", ".", "getAllInputs", "(", ")", ")", "{", "if", "(", "!", "options", ".", "getDependencyOptions", "(", ")", ".", "shouldDropMoochers", "(", ")", "&&", "input", ".", "getProvides", "(", ")", ".", "isEmpty", "(", ")", ")", "{", "entryPoints", ".", "add", "(", "input", ")", ";", "}", "inputsByIdentifier", ".", "put", "(", "ModuleIdentifier", ".", "forFile", "(", "input", ".", "getPath", "(", ")", ".", "toString", "(", ")", ")", ".", "toString", "(", ")", ",", "input", ")", ";", "for", "(", "String", "provide", ":", "input", ".", "getProvides", "(", ")", ")", "{", "if", "(", "!", "provide", ".", "startsWith", "(", "\"module$\"", ")", ")", "{", "inputsByProvide", ".", "put", "(", "provide", ",", "input", ")", ";", "}", "}", "}", "for", "(", "ModuleIdentifier", "moduleIdentifier", ":", "options", ".", "getDependencyOptions", "(", ")", ".", "getEntryPoints", "(", ")", ")", "{", "CompilerInput", "input", "=", "inputsByProvide", ".", "get", "(", "moduleIdentifier", ".", "toString", "(", ")", ")", ";", "if", "(", "input", "==", "null", ")", "{", "input", "=", "inputsByIdentifier", ".", "get", "(", "moduleIdentifier", ".", "toString", "(", ")", ")", ";", "}", "if", "(", "input", "!=", "null", ")", "{", "entryPoints", ".", "add", "(", "input", ")", ";", "}", "}", "Set", "<", "CompilerInput", ">", "workingInputSet", "=", "Sets", ".", "newHashSet", "(", "moduleGraph", ".", "getAllInputs", "(", ")", ")", ";", "for", "(", "CompilerInput", "entryPoint", ":", "entryPoints", ")", "{", "findModulesFromInput", "(", "entryPoint", ",", "/* wasImportedByModule = */", "false", ",", "workingInputSet", ",", "inputsByIdentifier", ",", "inputsByProvide", ",", "supportEs6Modules", ",", "supportCommonJSModules", ")", ";", "}", "}" ]
Find modules by recursively traversing dependencies starting with the entry points. <p>Causes a regex parse of every file, and a full parse of every file reachable from the entry points (which would be required by later compilation passes regardless). <p>If the dependency mode is set to LOOSE, inputs which the regex parse does not identify as ES modules and which do not contain any provide statements are considered to be additional entry points.
[ "Find", "modules", "by", "recursively", "traversing", "dependencies", "starting", "with", "the", "entry", "points", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1812-L1851
25,034
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.findModulesFromInput
private void findModulesFromInput( CompilerInput input, boolean wasImportedByModule, Set<CompilerInput> inputs, Map<String, CompilerInput> inputsByIdentifier, Map<String, CompilerInput> inputsByProvide, boolean supportEs6Modules, boolean supportCommonJSModules) { if (!inputs.remove(input)) { // It's possible for a module to be included as both a script // and a module in the same compilation. In these cases, it should // be forced to be a module. if (wasImportedByModule && input.getJsModuleType() == CompilerInput.ModuleType.NONE) { input.setJsModuleType(CompilerInput.ModuleType.IMPORTED_SCRIPT); } return; } FindModuleDependencies findDeps = new FindModuleDependencies( this, supportEs6Modules, supportCommonJSModules, inputPathByWebpackId); findDeps.process(checkNotNull(input.getAstRoot(this))); // If this input was imported by another module, it is itself a module // so we force it to be detected as such. if (wasImportedByModule && input.getJsModuleType() == CompilerInput.ModuleType.NONE) { input.setJsModuleType(CompilerInput.ModuleType.IMPORTED_SCRIPT); } this.moduleTypesByName.put(input.getPath().toModuleName(), input.getJsModuleType()); Iterable<String> allDeps = Iterables.concat( input.getRequiredSymbols(), input.getDynamicRequires(), input.getTypeRequires()); for (String requiredNamespace : allDeps) { CompilerInput requiredInput = null; boolean requiredByModuleImport = false; if (inputsByProvide.containsKey(requiredNamespace)) { requiredInput = inputsByProvide.get(requiredNamespace); } else if (inputsByIdentifier.containsKey(requiredNamespace)) { requiredByModuleImport = true; requiredInput = inputsByIdentifier.get(requiredNamespace); } if (requiredInput != null) { findModulesFromInput( requiredInput, requiredByModuleImport, inputs, inputsByIdentifier, inputsByProvide, supportEs6Modules, supportCommonJSModules); } } }
java
private void findModulesFromInput( CompilerInput input, boolean wasImportedByModule, Set<CompilerInput> inputs, Map<String, CompilerInput> inputsByIdentifier, Map<String, CompilerInput> inputsByProvide, boolean supportEs6Modules, boolean supportCommonJSModules) { if (!inputs.remove(input)) { // It's possible for a module to be included as both a script // and a module in the same compilation. In these cases, it should // be forced to be a module. if (wasImportedByModule && input.getJsModuleType() == CompilerInput.ModuleType.NONE) { input.setJsModuleType(CompilerInput.ModuleType.IMPORTED_SCRIPT); } return; } FindModuleDependencies findDeps = new FindModuleDependencies( this, supportEs6Modules, supportCommonJSModules, inputPathByWebpackId); findDeps.process(checkNotNull(input.getAstRoot(this))); // If this input was imported by another module, it is itself a module // so we force it to be detected as such. if (wasImportedByModule && input.getJsModuleType() == CompilerInput.ModuleType.NONE) { input.setJsModuleType(CompilerInput.ModuleType.IMPORTED_SCRIPT); } this.moduleTypesByName.put(input.getPath().toModuleName(), input.getJsModuleType()); Iterable<String> allDeps = Iterables.concat( input.getRequiredSymbols(), input.getDynamicRequires(), input.getTypeRequires()); for (String requiredNamespace : allDeps) { CompilerInput requiredInput = null; boolean requiredByModuleImport = false; if (inputsByProvide.containsKey(requiredNamespace)) { requiredInput = inputsByProvide.get(requiredNamespace); } else if (inputsByIdentifier.containsKey(requiredNamespace)) { requiredByModuleImport = true; requiredInput = inputsByIdentifier.get(requiredNamespace); } if (requiredInput != null) { findModulesFromInput( requiredInput, requiredByModuleImport, inputs, inputsByIdentifier, inputsByProvide, supportEs6Modules, supportCommonJSModules); } } }
[ "private", "void", "findModulesFromInput", "(", "CompilerInput", "input", ",", "boolean", "wasImportedByModule", ",", "Set", "<", "CompilerInput", ">", "inputs", ",", "Map", "<", "String", ",", "CompilerInput", ">", "inputsByIdentifier", ",", "Map", "<", "String", ",", "CompilerInput", ">", "inputsByProvide", ",", "boolean", "supportEs6Modules", ",", "boolean", "supportCommonJSModules", ")", "{", "if", "(", "!", "inputs", ".", "remove", "(", "input", ")", ")", "{", "// It's possible for a module to be included as both a script", "// and a module in the same compilation. In these cases, it should", "// be forced to be a module.", "if", "(", "wasImportedByModule", "&&", "input", ".", "getJsModuleType", "(", ")", "==", "CompilerInput", ".", "ModuleType", ".", "NONE", ")", "{", "input", ".", "setJsModuleType", "(", "CompilerInput", ".", "ModuleType", ".", "IMPORTED_SCRIPT", ")", ";", "}", "return", ";", "}", "FindModuleDependencies", "findDeps", "=", "new", "FindModuleDependencies", "(", "this", ",", "supportEs6Modules", ",", "supportCommonJSModules", ",", "inputPathByWebpackId", ")", ";", "findDeps", ".", "process", "(", "checkNotNull", "(", "input", ".", "getAstRoot", "(", "this", ")", ")", ")", ";", "// If this input was imported by another module, it is itself a module", "// so we force it to be detected as such.", "if", "(", "wasImportedByModule", "&&", "input", ".", "getJsModuleType", "(", ")", "==", "CompilerInput", ".", "ModuleType", ".", "NONE", ")", "{", "input", ".", "setJsModuleType", "(", "CompilerInput", ".", "ModuleType", ".", "IMPORTED_SCRIPT", ")", ";", "}", "this", ".", "moduleTypesByName", ".", "put", "(", "input", ".", "getPath", "(", ")", ".", "toModuleName", "(", ")", ",", "input", ".", "getJsModuleType", "(", ")", ")", ";", "Iterable", "<", "String", ">", "allDeps", "=", "Iterables", ".", "concat", "(", "input", ".", "getRequiredSymbols", "(", ")", ",", "input", ".", "getDynamicRequires", "(", ")", ",", "input", ".", "getTypeRequires", "(", ")", ")", ";", "for", "(", "String", "requiredNamespace", ":", "allDeps", ")", "{", "CompilerInput", "requiredInput", "=", "null", ";", "boolean", "requiredByModuleImport", "=", "false", ";", "if", "(", "inputsByProvide", ".", "containsKey", "(", "requiredNamespace", ")", ")", "{", "requiredInput", "=", "inputsByProvide", ".", "get", "(", "requiredNamespace", ")", ";", "}", "else", "if", "(", "inputsByIdentifier", ".", "containsKey", "(", "requiredNamespace", ")", ")", "{", "requiredByModuleImport", "=", "true", ";", "requiredInput", "=", "inputsByIdentifier", ".", "get", "(", "requiredNamespace", ")", ";", "}", "if", "(", "requiredInput", "!=", "null", ")", "{", "findModulesFromInput", "(", "requiredInput", ",", "requiredByModuleImport", ",", "inputs", ",", "inputsByIdentifier", ",", "inputsByProvide", ",", "supportEs6Modules", ",", "supportCommonJSModules", ")", ";", "}", "}", "}" ]
Traverse an input's dependencies to find additional modules.
[ "Traverse", "an", "input", "s", "dependencies", "to", "find", "additional", "modules", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1854-L1908
25,035
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.hoistIfExtern
private boolean hoistIfExtern(CompilerInput input) { if (input.getHasExternsAnnotation()) { // If the input file is explicitly marked as an externs file, then move it out of the main // JS root and put it with the other externs. externsRoot.addChildToBack(input.getAstRoot(this)); JSModule module = input.getModule(); if (module != null) { module.remove(input); } externs.add(input); return true; } return false; }
java
private boolean hoistIfExtern(CompilerInput input) { if (input.getHasExternsAnnotation()) { // If the input file is explicitly marked as an externs file, then move it out of the main // JS root and put it with the other externs. externsRoot.addChildToBack(input.getAstRoot(this)); JSModule module = input.getModule(); if (module != null) { module.remove(input); } externs.add(input); return true; } return false; }
[ "private", "boolean", "hoistIfExtern", "(", "CompilerInput", "input", ")", "{", "if", "(", "input", ".", "getHasExternsAnnotation", "(", ")", ")", "{", "// If the input file is explicitly marked as an externs file, then move it out of the main", "// JS root and put it with the other externs.", "externsRoot", ".", "addChildToBack", "(", "input", ".", "getAstRoot", "(", "this", ")", ")", ";", "JSModule", "module", "=", "input", ".", "getModule", "(", ")", ";", "if", "(", "module", "!=", "null", ")", "{", "module", ".", "remove", "(", "input", ")", ";", "}", "externs", ".", "add", "(", "input", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Hoists a compiler input to externs if it contains the @externs annotation. Return whether or not the given input was hoisted.
[ "Hoists", "a", "compiler", "input", "to", "externs", "if", "it", "contains", "the" ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1928-L1943
25,036
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.markExterns
private void markExterns(ImmutableList<CompilerInput> originalInputs) { for (CompilerInput input : originalInputs) { if (input.getHasExternsAnnotation()) { input.setIsExtern(); } } }
java
private void markExterns(ImmutableList<CompilerInput> originalInputs) { for (CompilerInput input : originalInputs) { if (input.getHasExternsAnnotation()) { input.setIsExtern(); } } }
[ "private", "void", "markExterns", "(", "ImmutableList", "<", "CompilerInput", ">", "originalInputs", ")", "{", "for", "(", "CompilerInput", "input", ":", "originalInputs", ")", "{", "if", "(", "input", ".", "getHasExternsAnnotation", "(", ")", ")", "{", "input", ".", "setIsExtern", "(", ")", ";", "}", "}", "}" ]
Marks inputs with the @externs annotation as an Extern source file type. This is so that externs marking can be done before dependency management, and externs hoisting done after dependency management.
[ "Marks", "inputs", "with", "the" ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1950-L1956
25,037
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.processJsonInputs
Map<String, String> processJsonInputs(Iterable<CompilerInput> inputsToProcess) { RewriteJsonToModule rewriteJson = new RewriteJsonToModule(this); for (CompilerInput input : inputsToProcess) { if (!input.getSourceFile().getOriginalPath().endsWith(".json")) { continue; } input.setCompiler(this); try { // JSON objects need wrapped in parens to parse properly input.getSourceFile().setCode("(" + input.getSourceFile().getCode() + ")"); } catch (IOException e) { continue; } Node root = checkNotNull(input.getAstRoot(this)); input.setJsModuleType(CompilerInput.ModuleType.JSON); rewriteJson.process(null, root); } return rewriteJson.getPackageJsonMainEntries(); }
java
Map<String, String> processJsonInputs(Iterable<CompilerInput> inputsToProcess) { RewriteJsonToModule rewriteJson = new RewriteJsonToModule(this); for (CompilerInput input : inputsToProcess) { if (!input.getSourceFile().getOriginalPath().endsWith(".json")) { continue; } input.setCompiler(this); try { // JSON objects need wrapped in parens to parse properly input.getSourceFile().setCode("(" + input.getSourceFile().getCode() + ")"); } catch (IOException e) { continue; } Node root = checkNotNull(input.getAstRoot(this)); input.setJsModuleType(CompilerInput.ModuleType.JSON); rewriteJson.process(null, root); } return rewriteJson.getPackageJsonMainEntries(); }
[ "Map", "<", "String", ",", "String", ">", "processJsonInputs", "(", "Iterable", "<", "CompilerInput", ">", "inputsToProcess", ")", "{", "RewriteJsonToModule", "rewriteJson", "=", "new", "RewriteJsonToModule", "(", "this", ")", ";", "for", "(", "CompilerInput", "input", ":", "inputsToProcess", ")", "{", "if", "(", "!", "input", ".", "getSourceFile", "(", ")", ".", "getOriginalPath", "(", ")", ".", "endsWith", "(", "\".json\"", ")", ")", "{", "continue", ";", "}", "input", ".", "setCompiler", "(", "this", ")", ";", "try", "{", "// JSON objects need wrapped in parens to parse properly", "input", ".", "getSourceFile", "(", ")", ".", "setCode", "(", "\"(\"", "+", "input", ".", "getSourceFile", "(", ")", ".", "getCode", "(", ")", "+", "\")\"", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "continue", ";", "}", "Node", "root", "=", "checkNotNull", "(", "input", ".", "getAstRoot", "(", "this", ")", ")", ";", "input", ".", "setJsModuleType", "(", "CompilerInput", ".", "ModuleType", ".", "JSON", ")", ";", "rewriteJson", ".", "process", "(", "null", ",", "root", ")", ";", "}", "return", "rewriteJson", ".", "getPackageJsonMainEntries", "(", ")", ";", "}" ]
Transforms JSON files to a module export that closure compiler can process and keeps track of any "main" entries in package.json files.
[ "Transforms", "JSON", "files", "to", "a", "module", "export", "that", "closure", "compiler", "can", "process", "and", "keeps", "track", "of", "any", "main", "entries", "in", "package", ".", "json", "files", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L1992-L2012
25,038
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.processAMDModules
void processAMDModules(Iterable<CompilerInput> inputs) { for (CompilerInput input : inputs) { input.setCompiler(this); Node root = checkNotNull(input.getAstRoot(this)); new TransformAMDToCJSModule(this).process(null, root); } }
java
void processAMDModules(Iterable<CompilerInput> inputs) { for (CompilerInput input : inputs) { input.setCompiler(this); Node root = checkNotNull(input.getAstRoot(this)); new TransformAMDToCJSModule(this).process(null, root); } }
[ "void", "processAMDModules", "(", "Iterable", "<", "CompilerInput", ">", "inputs", ")", "{", "for", "(", "CompilerInput", "input", ":", "inputs", ")", "{", "input", ".", "setCompiler", "(", "this", ")", ";", "Node", "root", "=", "checkNotNull", "(", "input", ".", "getAstRoot", "(", "this", ")", ")", ";", "new", "TransformAMDToCJSModule", "(", "this", ")", ".", "process", "(", "null", ",", "root", ")", ";", "}", "}" ]
Transforms AMD to CJS modules
[ "Transforms", "AMD", "to", "CJS", "modules" ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2037-L2043
25,039
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.toSource
@Override public String toSource() { return runInCompilerThread( () -> { Tracer tracer = newTracer("toSource"); try { CodeBuilder cb = new CodeBuilder(); if (jsRoot != null) { int i = 0; if (options.shouldPrintExterns()) { for (Node scriptNode = externsRoot.getFirstChild(); scriptNode != null; scriptNode = scriptNode.getNext()) { toSource(cb, i++, scriptNode); } } for (Node scriptNode = jsRoot.getFirstChild(); scriptNode != null; scriptNode = scriptNode.getNext()) { toSource(cb, i++, scriptNode); } } return cb.toString(); } finally { stopTracer(tracer, "toSource"); } }); }
java
@Override public String toSource() { return runInCompilerThread( () -> { Tracer tracer = newTracer("toSource"); try { CodeBuilder cb = new CodeBuilder(); if (jsRoot != null) { int i = 0; if (options.shouldPrintExterns()) { for (Node scriptNode = externsRoot.getFirstChild(); scriptNode != null; scriptNode = scriptNode.getNext()) { toSource(cb, i++, scriptNode); } } for (Node scriptNode = jsRoot.getFirstChild(); scriptNode != null; scriptNode = scriptNode.getNext()) { toSource(cb, i++, scriptNode); } } return cb.toString(); } finally { stopTracer(tracer, "toSource"); } }); }
[ "@", "Override", "public", "String", "toSource", "(", ")", "{", "return", "runInCompilerThread", "(", "(", ")", "->", "{", "Tracer", "tracer", "=", "newTracer", "(", "\"toSource\"", ")", ";", "try", "{", "CodeBuilder", "cb", "=", "new", "CodeBuilder", "(", ")", ";", "if", "(", "jsRoot", "!=", "null", ")", "{", "int", "i", "=", "0", ";", "if", "(", "options", ".", "shouldPrintExterns", "(", ")", ")", "{", "for", "(", "Node", "scriptNode", "=", "externsRoot", ".", "getFirstChild", "(", ")", ";", "scriptNode", "!=", "null", ";", "scriptNode", "=", "scriptNode", ".", "getNext", "(", ")", ")", "{", "toSource", "(", "cb", ",", "i", "++", ",", "scriptNode", ")", ";", "}", "}", "for", "(", "Node", "scriptNode", "=", "jsRoot", ".", "getFirstChild", "(", ")", ";", "scriptNode", "!=", "null", ";", "scriptNode", "=", "scriptNode", ".", "getNext", "(", ")", ")", "{", "toSource", "(", "cb", ",", "i", "++", ",", "scriptNode", ")", ";", "}", "}", "return", "cb", ".", "toString", "(", ")", ";", "}", "finally", "{", "stopTracer", "(", "tracer", ",", "\"toSource\"", ")", ";", "}", "}", ")", ";", "}" ]
Converts the main parse tree back to JS code.
[ "Converts", "the", "main", "parse", "tree", "back", "to", "JS", "code", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2101-L2128
25,040
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.toSource
public String toSource(final JSModule module) { return runInCompilerThread( () -> { List<CompilerInput> inputs = module.getInputs(); int numInputs = inputs.size(); if (numInputs == 0) { return ""; } CodeBuilder cb = new CodeBuilder(); for (int i = 0; i < numInputs; i++) { Node scriptNode = inputs.get(i).getAstRoot(Compiler.this); if (scriptNode == null) { throw new IllegalArgumentException("Bad module: " + module.getName()); } toSource(cb, i, scriptNode); } return cb.toString(); }); }
java
public String toSource(final JSModule module) { return runInCompilerThread( () -> { List<CompilerInput> inputs = module.getInputs(); int numInputs = inputs.size(); if (numInputs == 0) { return ""; } CodeBuilder cb = new CodeBuilder(); for (int i = 0; i < numInputs; i++) { Node scriptNode = inputs.get(i).getAstRoot(Compiler.this); if (scriptNode == null) { throw new IllegalArgumentException("Bad module: " + module.getName()); } toSource(cb, i, scriptNode); } return cb.toString(); }); }
[ "public", "String", "toSource", "(", "final", "JSModule", "module", ")", "{", "return", "runInCompilerThread", "(", "(", ")", "->", "{", "List", "<", "CompilerInput", ">", "inputs", "=", "module", ".", "getInputs", "(", ")", ";", "int", "numInputs", "=", "inputs", ".", "size", "(", ")", ";", "if", "(", "numInputs", "==", "0", ")", "{", "return", "\"\"", ";", "}", "CodeBuilder", "cb", "=", "new", "CodeBuilder", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numInputs", ";", "i", "++", ")", "{", "Node", "scriptNode", "=", "inputs", ".", "get", "(", "i", ")", ".", "getAstRoot", "(", "Compiler", ".", "this", ")", ";", "if", "(", "scriptNode", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Bad module: \"", "+", "module", ".", "getName", "(", ")", ")", ";", "}", "toSource", "(", "cb", ",", "i", ",", "scriptNode", ")", ";", "}", "return", "cb", ".", "toString", "(", ")", ";", "}", ")", ";", "}" ]
Converts the parse tree for a module back to JS code.
[ "Converts", "the", "parse", "tree", "for", "a", "module", "back", "to", "JS", "code", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2133-L2151
25,041
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.toSource
public void toSource(final CodeBuilder cb, final int inputSeqNum, final Node root) { runInCompilerThread( () -> { if (options.printInputDelimiter) { if ((cb.getLength() > 0) && !cb.endsWith("\n")) { cb.append("\n"); // Make sure that the label starts on a new line } checkState(root.isScript()); String delimiter = options.inputDelimiter; String inputName = root.getInputId().getIdName(); String sourceName = root.getSourceFileName(); checkState(sourceName != null); checkState(!sourceName.isEmpty()); delimiter = delimiter .replace("%name%", Matcher.quoteReplacement(inputName)) .replace("%num%", String.valueOf(inputSeqNum)) .replace("%n%", "\n"); cb.append(delimiter).append("\n"); } if (root.getJSDocInfo() != null) { String license = root.getJSDocInfo().getLicense(); if (license != null && cb.addLicense(license)) { cb.append("/*\n").append(license).append("*/\n"); } } // If there is a valid source map, then indicate to it that the current // root node's mappings are offset by the given string builder buffer. if (options.sourceMapOutputPath != null) { sourceMap.setStartingPosition(cb.getLineIndex(), cb.getColumnIndex()); } // if LanguageMode is strict, only print 'use strict' // for the first input file String code = toSource(root, sourceMap, inputSeqNum == 0); if (!code.isEmpty()) { cb.append(code); // In order to avoid parse ambiguity when files are concatenated // together, all files should end in a semi-colon. Do a quick // heuristic check if there's an obvious semi-colon already there. int length = code.length(); char lastChar = code.charAt(length - 1); char secondLastChar = length >= 2 ? code.charAt(length - 2) : '\0'; boolean hasSemiColon = lastChar == ';' || (lastChar == '\n' && secondLastChar == ';'); if (!hasSemiColon) { cb.append(";"); } } return null; }); }
java
public void toSource(final CodeBuilder cb, final int inputSeqNum, final Node root) { runInCompilerThread( () -> { if (options.printInputDelimiter) { if ((cb.getLength() > 0) && !cb.endsWith("\n")) { cb.append("\n"); // Make sure that the label starts on a new line } checkState(root.isScript()); String delimiter = options.inputDelimiter; String inputName = root.getInputId().getIdName(); String sourceName = root.getSourceFileName(); checkState(sourceName != null); checkState(!sourceName.isEmpty()); delimiter = delimiter .replace("%name%", Matcher.quoteReplacement(inputName)) .replace("%num%", String.valueOf(inputSeqNum)) .replace("%n%", "\n"); cb.append(delimiter).append("\n"); } if (root.getJSDocInfo() != null) { String license = root.getJSDocInfo().getLicense(); if (license != null && cb.addLicense(license)) { cb.append("/*\n").append(license).append("*/\n"); } } // If there is a valid source map, then indicate to it that the current // root node's mappings are offset by the given string builder buffer. if (options.sourceMapOutputPath != null) { sourceMap.setStartingPosition(cb.getLineIndex(), cb.getColumnIndex()); } // if LanguageMode is strict, only print 'use strict' // for the first input file String code = toSource(root, sourceMap, inputSeqNum == 0); if (!code.isEmpty()) { cb.append(code); // In order to avoid parse ambiguity when files are concatenated // together, all files should end in a semi-colon. Do a quick // heuristic check if there's an obvious semi-colon already there. int length = code.length(); char lastChar = code.charAt(length - 1); char secondLastChar = length >= 2 ? code.charAt(length - 2) : '\0'; boolean hasSemiColon = lastChar == ';' || (lastChar == '\n' && secondLastChar == ';'); if (!hasSemiColon) { cb.append(";"); } } return null; }); }
[ "public", "void", "toSource", "(", "final", "CodeBuilder", "cb", ",", "final", "int", "inputSeqNum", ",", "final", "Node", "root", ")", "{", "runInCompilerThread", "(", "(", ")", "->", "{", "if", "(", "options", ".", "printInputDelimiter", ")", "{", "if", "(", "(", "cb", ".", "getLength", "(", ")", ">", "0", ")", "&&", "!", "cb", ".", "endsWith", "(", "\"\\n\"", ")", ")", "{", "cb", ".", "append", "(", "\"\\n\"", ")", ";", "// Make sure that the label starts on a new line", "}", "checkState", "(", "root", ".", "isScript", "(", ")", ")", ";", "String", "delimiter", "=", "options", ".", "inputDelimiter", ";", "String", "inputName", "=", "root", ".", "getInputId", "(", ")", ".", "getIdName", "(", ")", ";", "String", "sourceName", "=", "root", ".", "getSourceFileName", "(", ")", ";", "checkState", "(", "sourceName", "!=", "null", ")", ";", "checkState", "(", "!", "sourceName", ".", "isEmpty", "(", ")", ")", ";", "delimiter", "=", "delimiter", ".", "replace", "(", "\"%name%\"", ",", "Matcher", ".", "quoteReplacement", "(", "inputName", ")", ")", ".", "replace", "(", "\"%num%\"", ",", "String", ".", "valueOf", "(", "inputSeqNum", ")", ")", ".", "replace", "(", "\"%n%\"", ",", "\"\\n\"", ")", ";", "cb", ".", "append", "(", "delimiter", ")", ".", "append", "(", "\"\\n\"", ")", ";", "}", "if", "(", "root", ".", "getJSDocInfo", "(", ")", "!=", "null", ")", "{", "String", "license", "=", "root", ".", "getJSDocInfo", "(", ")", ".", "getLicense", "(", ")", ";", "if", "(", "license", "!=", "null", "&&", "cb", ".", "addLicense", "(", "license", ")", ")", "{", "cb", ".", "append", "(", "\"/*\\n\"", ")", ".", "append", "(", "license", ")", ".", "append", "(", "\"*/\\n\"", ")", ";", "}", "}", "// If there is a valid source map, then indicate to it that the current", "// root node's mappings are offset by the given string builder buffer.", "if", "(", "options", ".", "sourceMapOutputPath", "!=", "null", ")", "{", "sourceMap", ".", "setStartingPosition", "(", "cb", ".", "getLineIndex", "(", ")", ",", "cb", ".", "getColumnIndex", "(", ")", ")", ";", "}", "// if LanguageMode is strict, only print 'use strict'", "// for the first input file", "String", "code", "=", "toSource", "(", "root", ",", "sourceMap", ",", "inputSeqNum", "==", "0", ")", ";", "if", "(", "!", "code", ".", "isEmpty", "(", ")", ")", "{", "cb", ".", "append", "(", "code", ")", ";", "// In order to avoid parse ambiguity when files are concatenated", "// together, all files should end in a semi-colon. Do a quick", "// heuristic check if there's an obvious semi-colon already there.", "int", "length", "=", "code", ".", "length", "(", ")", ";", "char", "lastChar", "=", "code", ".", "charAt", "(", "length", "-", "1", ")", ";", "char", "secondLastChar", "=", "length", ">=", "2", "?", "code", ".", "charAt", "(", "length", "-", "2", ")", ":", "'", "'", ";", "boolean", "hasSemiColon", "=", "lastChar", "==", "'", "'", "||", "(", "lastChar", "==", "'", "'", "&&", "secondLastChar", "==", "'", "'", ")", ";", "if", "(", "!", "hasSemiColon", ")", "{", "cb", ".", "append", "(", "\";\"", ")", ";", "}", "}", "return", "null", ";", "}", ")", ";", "}" ]
Writes out JS code from a root node. If printing input delimiters, this method will attach a comment to the start of the text indicating which input the output derived from. If there were any preserve annotations within the root's source, they will also be printed in a block comment at the beginning of the output.
[ "Writes", "out", "JS", "code", "from", "a", "root", "node", ".", "If", "printing", "input", "delimiters", "this", "method", "will", "attach", "a", "comment", "to", "the", "start", "of", "the", "text", "indicating", "which", "input", "the", "output", "derived", "from", ".", "If", "there", "were", "any", "preserve", "annotations", "within", "the", "root", "s", "source", "they", "will", "also", "be", "printed", "in", "a", "block", "comment", "at", "the", "beginning", "of", "the", "output", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2160-L2218
25,042
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.toSource
@Override public String toSource(Node n) { initCompilerOptionsIfTesting(); return toSource(n, null, true); }
java
@Override public String toSource(Node n) { initCompilerOptionsIfTesting(); return toSource(n, null, true); }
[ "@", "Override", "public", "String", "toSource", "(", "Node", "n", ")", "{", "initCompilerOptionsIfTesting", "(", ")", ";", "return", "toSource", "(", "n", ",", "null", ",", "true", ")", ";", "}" ]
Generates JavaScript source code for an AST, doesn't generate source map info.
[ "Generates", "JavaScript", "source", "code", "for", "an", "AST", "doesn", "t", "generate", "source", "map", "info", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2224-L2228
25,043
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.toSource
private String toSource(Node n, SourceMap sourceMap, boolean firstOutput) { CodePrinter.Builder builder = new CodePrinter.Builder(n); builder.setTypeRegistry(getTypeRegistry()); builder.setCompilerOptions(options); builder.setSourceMap(sourceMap); builder.setTagAsTypeSummary(!n.isFromExterns() && options.shouldGenerateTypedExterns()); builder.setTagAsStrict(firstOutput && options.shouldEmitUseStrict()); return builder.build(); }
java
private String toSource(Node n, SourceMap sourceMap, boolean firstOutput) { CodePrinter.Builder builder = new CodePrinter.Builder(n); builder.setTypeRegistry(getTypeRegistry()); builder.setCompilerOptions(options); builder.setSourceMap(sourceMap); builder.setTagAsTypeSummary(!n.isFromExterns() && options.shouldGenerateTypedExterns()); builder.setTagAsStrict(firstOutput && options.shouldEmitUseStrict()); return builder.build(); }
[ "private", "String", "toSource", "(", "Node", "n", ",", "SourceMap", "sourceMap", ",", "boolean", "firstOutput", ")", "{", "CodePrinter", ".", "Builder", "builder", "=", "new", "CodePrinter", ".", "Builder", "(", "n", ")", ";", "builder", ".", "setTypeRegistry", "(", "getTypeRegistry", "(", ")", ")", ";", "builder", ".", "setCompilerOptions", "(", "options", ")", ";", "builder", ".", "setSourceMap", "(", "sourceMap", ")", ";", "builder", ".", "setTagAsTypeSummary", "(", "!", "n", ".", "isFromExterns", "(", ")", "&&", "options", ".", "shouldGenerateTypedExterns", "(", ")", ")", ";", "builder", ".", "setTagAsStrict", "(", "firstOutput", "&&", "options", ".", "shouldEmitUseStrict", "(", ")", ")", ";", "return", "builder", ".", "build", "(", ")", ";", "}" ]
Generates JavaScript source code for an AST.
[ "Generates", "JavaScript", "source", "code", "for", "an", "AST", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2233-L2241
25,044
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.toSourceArray
public String[] toSourceArray() { return runInCompilerThread( () -> { Tracer tracer = newTracer("toSourceArray"); try { int numInputs = moduleGraph.getInputCount(); String[] sources = new String[numInputs]; CodeBuilder cb = new CodeBuilder(); int i = 0; for (CompilerInput input : moduleGraph.getAllInputs()) { Node scriptNode = input.getAstRoot(Compiler.this); cb.reset(); toSource(cb, i, scriptNode); sources[i] = cb.toString(); i++; } return sources; } finally { stopTracer(tracer, "toSourceArray"); } }); }
java
public String[] toSourceArray() { return runInCompilerThread( () -> { Tracer tracer = newTracer("toSourceArray"); try { int numInputs = moduleGraph.getInputCount(); String[] sources = new String[numInputs]; CodeBuilder cb = new CodeBuilder(); int i = 0; for (CompilerInput input : moduleGraph.getAllInputs()) { Node scriptNode = input.getAstRoot(Compiler.this); cb.reset(); toSource(cb, i, scriptNode); sources[i] = cb.toString(); i++; } return sources; } finally { stopTracer(tracer, "toSourceArray"); } }); }
[ "public", "String", "[", "]", "toSourceArray", "(", ")", "{", "return", "runInCompilerThread", "(", "(", ")", "->", "{", "Tracer", "tracer", "=", "newTracer", "(", "\"toSourceArray\"", ")", ";", "try", "{", "int", "numInputs", "=", "moduleGraph", ".", "getInputCount", "(", ")", ";", "String", "[", "]", "sources", "=", "new", "String", "[", "numInputs", "]", ";", "CodeBuilder", "cb", "=", "new", "CodeBuilder", "(", ")", ";", "int", "i", "=", "0", ";", "for", "(", "CompilerInput", "input", ":", "moduleGraph", ".", "getAllInputs", "(", ")", ")", "{", "Node", "scriptNode", "=", "input", ".", "getAstRoot", "(", "Compiler", ".", "this", ")", ";", "cb", ".", "reset", "(", ")", ";", "toSource", "(", "cb", ",", "i", ",", "scriptNode", ")", ";", "sources", "[", "i", "]", "=", "cb", ".", "toString", "(", ")", ";", "i", "++", ";", "}", "return", "sources", ";", "}", "finally", "{", "stopTracer", "(", "tracer", ",", "\"toSourceArray\"", ")", ";", "}", "}", ")", ";", "}" ]
Converts the parse tree for each input back to JS code.
[ "Converts", "the", "parse", "tree", "for", "each", "input", "back", "to", "JS", "code", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2246-L2267
25,045
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.toSourceArray
public String[] toSourceArray(final JSModule module) { return runInCompilerThread( () -> { List<CompilerInput> inputs = module.getInputs(); int numInputs = inputs.size(); if (numInputs == 0) { return new String[0]; } String[] sources = new String[numInputs]; CodeBuilder cb = new CodeBuilder(); for (int i = 0; i < numInputs; i++) { Node scriptNode = inputs.get(i).getAstRoot(Compiler.this); if (scriptNode == null) { throw new IllegalArgumentException("Bad module input: " + inputs.get(i).getName()); } cb.reset(); toSource(cb, i, scriptNode); sources[i] = cb.toString(); } return sources; }); }
java
public String[] toSourceArray(final JSModule module) { return runInCompilerThread( () -> { List<CompilerInput> inputs = module.getInputs(); int numInputs = inputs.size(); if (numInputs == 0) { return new String[0]; } String[] sources = new String[numInputs]; CodeBuilder cb = new CodeBuilder(); for (int i = 0; i < numInputs; i++) { Node scriptNode = inputs.get(i).getAstRoot(Compiler.this); if (scriptNode == null) { throw new IllegalArgumentException("Bad module input: " + inputs.get(i).getName()); } cb.reset(); toSource(cb, i, scriptNode); sources[i] = cb.toString(); } return sources; }); }
[ "public", "String", "[", "]", "toSourceArray", "(", "final", "JSModule", "module", ")", "{", "return", "runInCompilerThread", "(", "(", ")", "->", "{", "List", "<", "CompilerInput", ">", "inputs", "=", "module", ".", "getInputs", "(", ")", ";", "int", "numInputs", "=", "inputs", ".", "size", "(", ")", ";", "if", "(", "numInputs", "==", "0", ")", "{", "return", "new", "String", "[", "0", "]", ";", "}", "String", "[", "]", "sources", "=", "new", "String", "[", "numInputs", "]", ";", "CodeBuilder", "cb", "=", "new", "CodeBuilder", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numInputs", ";", "i", "++", ")", "{", "Node", "scriptNode", "=", "inputs", ".", "get", "(", "i", ")", ".", "getAstRoot", "(", "Compiler", ".", "this", ")", ";", "if", "(", "scriptNode", "==", "null", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"Bad module input: \"", "+", "inputs", ".", "get", "(", "i", ")", ".", "getName", "(", ")", ")", ";", "}", "cb", ".", "reset", "(", ")", ";", "toSource", "(", "cb", ",", "i", ",", "scriptNode", ")", ";", "sources", "[", "i", "]", "=", "cb", ".", "toString", "(", ")", ";", "}", "return", "sources", ";", "}", ")", ";", "}" ]
Converts the parse tree for each input in a module back to JS code.
[ "Converts", "the", "parse", "tree", "for", "each", "input", "in", "a", "module", "back", "to", "JS", "code", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2272-L2295
25,046
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.computeCFG
ControlFlowGraph<Node> computeCFG() { logger.fine("Computing Control Flow Graph"); Tracer tracer = newTracer("computeCFG"); ControlFlowAnalysis cfa = new ControlFlowAnalysis(this, true, false); process(cfa); stopTracer(tracer, "computeCFG"); return cfa.getCfg(); }
java
ControlFlowGraph<Node> computeCFG() { logger.fine("Computing Control Flow Graph"); Tracer tracer = newTracer("computeCFG"); ControlFlowAnalysis cfa = new ControlFlowAnalysis(this, true, false); process(cfa); stopTracer(tracer, "computeCFG"); return cfa.getCfg(); }
[ "ControlFlowGraph", "<", "Node", ">", "computeCFG", "(", ")", "{", "logger", ".", "fine", "(", "\"Computing Control Flow Graph\"", ")", ";", "Tracer", "tracer", "=", "newTracer", "(", "\"computeCFG\"", ")", ";", "ControlFlowAnalysis", "cfa", "=", "new", "ControlFlowAnalysis", "(", "this", ",", "true", ",", "false", ")", ";", "process", "(", "cfa", ")", ";", "stopTracer", "(", "tracer", ",", "\"computeCFG\"", ")", ";", "return", "cfa", ".", "getCfg", "(", ")", ";", "}" ]
Control Flow Analysis.
[ "Control", "Flow", "Analysis", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2395-L2402
25,047
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.addSourceMapSourceFiles
private synchronized void addSourceMapSourceFiles(SourceMapInput inputSourceMap) { // synchronized annotation guards concurrent access to sourceMap during parsing. SourceMapConsumerV3 consumer = inputSourceMap.getSourceMap(errorManager); if (consumer == null) { return; } Collection<String> sourcesContent = consumer.getOriginalSourcesContent(); if (sourcesContent == null) { return; } Iterator<String> content = sourcesContent.iterator(); Iterator<String> sources = consumer.getOriginalSources().iterator(); while (sources.hasNext() && content.hasNext()) { String code = content.next(); SourceFile source = SourceMapResolver.getRelativePath( inputSourceMap.getOriginalPath(), sources.next()); if (source != null) { sourceMap.addSourceFile(source.getOriginalPath(), code); } } if (sources.hasNext() || content.hasNext()) { throw new RuntimeException( "Source map's \"sources\" and \"sourcesContent\" lengths do not match."); } }
java
private synchronized void addSourceMapSourceFiles(SourceMapInput inputSourceMap) { // synchronized annotation guards concurrent access to sourceMap during parsing. SourceMapConsumerV3 consumer = inputSourceMap.getSourceMap(errorManager); if (consumer == null) { return; } Collection<String> sourcesContent = consumer.getOriginalSourcesContent(); if (sourcesContent == null) { return; } Iterator<String> content = sourcesContent.iterator(); Iterator<String> sources = consumer.getOriginalSources().iterator(); while (sources.hasNext() && content.hasNext()) { String code = content.next(); SourceFile source = SourceMapResolver.getRelativePath( inputSourceMap.getOriginalPath(), sources.next()); if (source != null) { sourceMap.addSourceFile(source.getOriginalPath(), code); } } if (sources.hasNext() || content.hasNext()) { throw new RuntimeException( "Source map's \"sources\" and \"sourcesContent\" lengths do not match."); } }
[ "private", "synchronized", "void", "addSourceMapSourceFiles", "(", "SourceMapInput", "inputSourceMap", ")", "{", "// synchronized annotation guards concurrent access to sourceMap during parsing.", "SourceMapConsumerV3", "consumer", "=", "inputSourceMap", ".", "getSourceMap", "(", "errorManager", ")", ";", "if", "(", "consumer", "==", "null", ")", "{", "return", ";", "}", "Collection", "<", "String", ">", "sourcesContent", "=", "consumer", ".", "getOriginalSourcesContent", "(", ")", ";", "if", "(", "sourcesContent", "==", "null", ")", "{", "return", ";", "}", "Iterator", "<", "String", ">", "content", "=", "sourcesContent", ".", "iterator", "(", ")", ";", "Iterator", "<", "String", ">", "sources", "=", "consumer", ".", "getOriginalSources", "(", ")", ".", "iterator", "(", ")", ";", "while", "(", "sources", ".", "hasNext", "(", ")", "&&", "content", ".", "hasNext", "(", ")", ")", "{", "String", "code", "=", "content", ".", "next", "(", ")", ";", "SourceFile", "source", "=", "SourceMapResolver", ".", "getRelativePath", "(", "inputSourceMap", ".", "getOriginalPath", "(", ")", ",", "sources", ".", "next", "(", ")", ")", ";", "if", "(", "source", "!=", "null", ")", "{", "sourceMap", ".", "addSourceFile", "(", "source", ".", "getOriginalPath", "(", ")", ",", "code", ")", ";", "}", "}", "if", "(", "sources", ".", "hasNext", "(", ")", "||", "content", ".", "hasNext", "(", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Source map's \\\"sources\\\" and \\\"sourcesContent\\\" lengths do not match.\"", ")", ";", "}", "}" ]
Adds file name to content mappings for all sources found in a source map. This is used to populate sourcesContent array in the output source map even for sources embedded in the input source map.
[ "Adds", "file", "name", "to", "content", "mappings", "for", "all", "sources", "found", "in", "a", "source", "map", ".", "This", "is", "used", "to", "populate", "sourcesContent", "array", "in", "the", "output", "source", "map", "even", "for", "sources", "embedded", "in", "the", "input", "source", "map", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L2781-L2805
25,048
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.getAstDotGraph
public String getAstDotGraph() throws IOException { if (jsRoot != null) { ControlFlowAnalysis cfa = new ControlFlowAnalysis(this, true, false); cfa.process(null, jsRoot); return DotFormatter.toDot(jsRoot, cfa.getCfg()); } else { return ""; } }
java
public String getAstDotGraph() throws IOException { if (jsRoot != null) { ControlFlowAnalysis cfa = new ControlFlowAnalysis(this, true, false); cfa.process(null, jsRoot); return DotFormatter.toDot(jsRoot, cfa.getCfg()); } else { return ""; } }
[ "public", "String", "getAstDotGraph", "(", ")", "throws", "IOException", "{", "if", "(", "jsRoot", "!=", "null", ")", "{", "ControlFlowAnalysis", "cfa", "=", "new", "ControlFlowAnalysis", "(", "this", ",", "true", ",", "false", ")", ";", "cfa", ".", "process", "(", "null", ",", "jsRoot", ")", ";", "return", "DotFormatter", ".", "toDot", "(", "jsRoot", ",", "cfa", ".", "getCfg", "(", ")", ")", ";", "}", "else", "{", "return", "\"\"", ";", "}", "}" ]
Gets the DOT graph of the AST generated at the end of compilation.
[ "Gets", "the", "DOT", "graph", "of", "the", "AST", "generated", "at", "the", "end", "of", "compilation", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L3005-L3013
25,049
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.replaceScript
public void replaceScript(JsAst ast) { CompilerInput input = this.getInput(ast.getInputId()); if (!replaceIncrementalSourceAst(ast)) { return; } Node originalRoot = checkNotNull(input.getAstRoot(this)); processNewScript(ast, originalRoot); }
java
public void replaceScript(JsAst ast) { CompilerInput input = this.getInput(ast.getInputId()); if (!replaceIncrementalSourceAst(ast)) { return; } Node originalRoot = checkNotNull(input.getAstRoot(this)); processNewScript(ast, originalRoot); }
[ "public", "void", "replaceScript", "(", "JsAst", "ast", ")", "{", "CompilerInput", "input", "=", "this", ".", "getInput", "(", "ast", ".", "getInputId", "(", ")", ")", ";", "if", "(", "!", "replaceIncrementalSourceAst", "(", "ast", ")", ")", "{", "return", ";", "}", "Node", "originalRoot", "=", "checkNotNull", "(", "input", ".", "getAstRoot", "(", "this", ")", ")", ";", "processNewScript", "(", "ast", ",", "originalRoot", ")", ";", "}" ]
Replaces one file in a hot-swap mode. The given JsAst should be made from a new version of a file that already was present in the last compile call. If the file is new, this will silently ignored. @param ast the ast of the file that is being replaced
[ "Replaces", "one", "file", "in", "a", "hot", "-", "swap", "mode", ".", "The", "given", "JsAst", "should", "be", "made", "from", "a", "new", "version", "of", "a", "file", "that", "already", "was", "present", "in", "the", "last", "compile", "call", ".", "If", "the", "file", "is", "new", "this", "will", "silently", "ignored", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L3163-L3171
25,050
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.runHotSwap
private void runHotSwap( Node originalRoot, Node js, PassConfig passConfig) { for (PassFactory passFactory : passConfig.getChecks()) { runHotSwapPass(originalRoot, js, passFactory); } }
java
private void runHotSwap( Node originalRoot, Node js, PassConfig passConfig) { for (PassFactory passFactory : passConfig.getChecks()) { runHotSwapPass(originalRoot, js, passFactory); } }
[ "private", "void", "runHotSwap", "(", "Node", "originalRoot", ",", "Node", "js", ",", "PassConfig", "passConfig", ")", "{", "for", "(", "PassFactory", "passFactory", ":", "passConfig", ".", "getChecks", "(", ")", ")", "{", "runHotSwapPass", "(", "originalRoot", ",", "js", ",", "passFactory", ")", ";", "}", "}" ]
Execute the passes from a PassConfig instance over a single replaced file.
[ "Execute", "the", "passes", "from", "a", "PassConfig", "instance", "over", "a", "single", "replaced", "file", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L3214-L3219
25,051
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.getReleaseVersion
@GwtIncompatible("java.util.ResourceBundle") public static String getReleaseVersion() { ResourceBundle config = ResourceBundle.getBundle(CONFIG_RESOURCE); return config.getString("compiler.version"); }
java
@GwtIncompatible("java.util.ResourceBundle") public static String getReleaseVersion() { ResourceBundle config = ResourceBundle.getBundle(CONFIG_RESOURCE); return config.getString("compiler.version"); }
[ "@", "GwtIncompatible", "(", "\"java.util.ResourceBundle\"", ")", "public", "static", "String", "getReleaseVersion", "(", ")", "{", "ResourceBundle", "config", "=", "ResourceBundle", ".", "getBundle", "(", "CONFIG_RESOURCE", ")", ";", "return", "config", ".", "getString", "(", "\"compiler.version\"", ")", ";", "}" ]
Returns the compiler version baked into the jar.
[ "Returns", "the", "compiler", "version", "baked", "into", "the", "jar", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L3308-L3312
25,052
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.getReleaseDate
@GwtIncompatible("java.util.ResourceBundle") public static String getReleaseDate() { ResourceBundle config = ResourceBundle.getBundle(CONFIG_RESOURCE); return config.getString("compiler.date"); }
java
@GwtIncompatible("java.util.ResourceBundle") public static String getReleaseDate() { ResourceBundle config = ResourceBundle.getBundle(CONFIG_RESOURCE); return config.getString("compiler.date"); }
[ "@", "GwtIncompatible", "(", "\"java.util.ResourceBundle\"", ")", "public", "static", "String", "getReleaseDate", "(", ")", "{", "ResourceBundle", "config", "=", "ResourceBundle", ".", "getBundle", "(", "CONFIG_RESOURCE", ")", ";", "return", "config", ".", "getString", "(", "\"compiler.date\"", ")", ";", "}" ]
Returns the compiler date baked into the jar.
[ "Returns", "the", "compiler", "date", "baked", "into", "the", "jar", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L3315-L3319
25,053
google/closure-compiler
src/com/google/javascript/jscomp/Compiler.java
Compiler.resolveSibling
private static String resolveSibling(String fromPath, String toPath) { // If the destination is an absolute path, nothing to do. if (toPath.startsWith("/")) { return toPath; } List<String> fromPathParts = new ArrayList<>(Arrays.asList(fromPath.split("/"))); List<String> toPathParts = new ArrayList<>(Arrays.asList(toPath.split("/"))); if (!fromPathParts.isEmpty()) { fromPathParts.remove(fromPathParts.size() - 1); } while (!fromPathParts.isEmpty() && !toPathParts.isEmpty()) { if (toPathParts.get(0).equals(".")) { toPathParts.remove(0); } else if (toPathParts.get(0).equals("..")) { toPathParts.remove(0); fromPathParts.remove(fromPathParts.size() - 1); } else { break; } } fromPathParts.addAll(toPathParts); return String.join("/", fromPathParts); }
java
private static String resolveSibling(String fromPath, String toPath) { // If the destination is an absolute path, nothing to do. if (toPath.startsWith("/")) { return toPath; } List<String> fromPathParts = new ArrayList<>(Arrays.asList(fromPath.split("/"))); List<String> toPathParts = new ArrayList<>(Arrays.asList(toPath.split("/"))); if (!fromPathParts.isEmpty()) { fromPathParts.remove(fromPathParts.size() - 1); } while (!fromPathParts.isEmpty() && !toPathParts.isEmpty()) { if (toPathParts.get(0).equals(".")) { toPathParts.remove(0); } else if (toPathParts.get(0).equals("..")) { toPathParts.remove(0); fromPathParts.remove(fromPathParts.size() - 1); } else { break; } } fromPathParts.addAll(toPathParts); return String.join("/", fromPathParts); }
[ "private", "static", "String", "resolveSibling", "(", "String", "fromPath", ",", "String", "toPath", ")", "{", "// If the destination is an absolute path, nothing to do.", "if", "(", "toPath", ".", "startsWith", "(", "\"/\"", ")", ")", "{", "return", "toPath", ";", "}", "List", "<", "String", ">", "fromPathParts", "=", "new", "ArrayList", "<>", "(", "Arrays", ".", "asList", "(", "fromPath", ".", "split", "(", "\"/\"", ")", ")", ")", ";", "List", "<", "String", ">", "toPathParts", "=", "new", "ArrayList", "<>", "(", "Arrays", ".", "asList", "(", "toPath", ".", "split", "(", "\"/\"", ")", ")", ")", ";", "if", "(", "!", "fromPathParts", ".", "isEmpty", "(", ")", ")", "{", "fromPathParts", ".", "remove", "(", "fromPathParts", ".", "size", "(", ")", "-", "1", ")", ";", "}", "while", "(", "!", "fromPathParts", ".", "isEmpty", "(", ")", "&&", "!", "toPathParts", ".", "isEmpty", "(", ")", ")", "{", "if", "(", "toPathParts", ".", "get", "(", "0", ")", ".", "equals", "(", "\".\"", ")", ")", "{", "toPathParts", ".", "remove", "(", "0", ")", ";", "}", "else", "if", "(", "toPathParts", ".", "get", "(", "0", ")", ".", "equals", "(", "\"..\"", ")", ")", "{", "toPathParts", ".", "remove", "(", "0", ")", ";", "fromPathParts", ".", "remove", "(", "fromPathParts", ".", "size", "(", ")", "-", "1", ")", ";", "}", "else", "{", "break", ";", "}", "}", "fromPathParts", ".", "addAll", "(", "toPathParts", ")", ";", "return", "String", ".", "join", "(", "\"/\"", ",", "fromPathParts", ")", ";", "}" ]
Simplistic implementation of the java.nio.file.Path resolveSibling method that works with GWT. @param fromPath - must be a file (not directory) @param toPath - must be a file (not directory)
[ "Simplistic", "implementation", "of", "the", "java", ".", "nio", ".", "file", ".", "Path", "resolveSibling", "method", "that", "works", "with", "GWT", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/Compiler.java#L3618-L3643
25,054
google/closure-compiler
src/com/google/javascript/jscomp/CoverageInstrumentationPass.java
CoverageInstrumentationPass.addHeaderCode
private void addHeaderCode(Node script) { script.addChildToFront(createConditionalObjectDecl(JS_INSTRUMENTATION_OBJECT_NAME, script)); // Make subsequent usages of "window" and "window.top" work in a Web Worker context. script.addChildToFront( compiler.parseSyntheticCode( "if (!self.window) { self.window = self; self.window.top = self; }") .removeFirstChild() .useSourceInfoIfMissingFromForTree(script)); }
java
private void addHeaderCode(Node script) { script.addChildToFront(createConditionalObjectDecl(JS_INSTRUMENTATION_OBJECT_NAME, script)); // Make subsequent usages of "window" and "window.top" work in a Web Worker context. script.addChildToFront( compiler.parseSyntheticCode( "if (!self.window) { self.window = self; self.window.top = self; }") .removeFirstChild() .useSourceInfoIfMissingFromForTree(script)); }
[ "private", "void", "addHeaderCode", "(", "Node", "script", ")", "{", "script", ".", "addChildToFront", "(", "createConditionalObjectDecl", "(", "JS_INSTRUMENTATION_OBJECT_NAME", ",", "script", ")", ")", ";", "// Make subsequent usages of \"window\" and \"window.top\" work in a Web Worker context.", "script", ".", "addChildToFront", "(", "compiler", ".", "parseSyntheticCode", "(", "\"if (!self.window) { self.window = self; self.window.top = self; }\"", ")", ".", "removeFirstChild", "(", ")", ".", "useSourceInfoIfMissingFromForTree", "(", "script", ")", ")", ";", "}" ]
Creates the js code to be added to source. This code declares and initializes the variables required for collection of coverage data.
[ "Creates", "the", "js", "code", "to", "be", "added", "to", "source", ".", "This", "code", "declares", "and", "initializes", "the", "variables", "required", "for", "collection", "of", "coverage", "data", "." ]
d81e36740f6a9e8ac31a825ee8758182e1dc5aae
https://github.com/google/closure-compiler/blob/d81e36740f6a9e8ac31a825ee8758182e1dc5aae/src/com/google/javascript/jscomp/CoverageInstrumentationPass.java#L73-L82
25,055
appium/java-client
src/main/java/io/appium/java_client/touch/WaitOptions.java
WaitOptions.withDuration
public WaitOptions withDuration(Duration duration) { checkNotNull(duration); checkArgument(duration.toMillis() >= 0, "Duration value should be greater or equal to zero"); this.duration = duration; return this; }
java
public WaitOptions withDuration(Duration duration) { checkNotNull(duration); checkArgument(duration.toMillis() >= 0, "Duration value should be greater or equal to zero"); this.duration = duration; return this; }
[ "public", "WaitOptions", "withDuration", "(", "Duration", "duration", ")", "{", "checkNotNull", "(", "duration", ")", ";", "checkArgument", "(", "duration", ".", "toMillis", "(", ")", ">=", "0", ",", "\"Duration value should be greater or equal to zero\"", ")", ";", "this", ".", "duration", "=", "duration", ";", "return", "this", ";", "}" ]
Set the wait duration. @param duration the value to set. Time resolution unit is 1 ms. @return this instance for chaining.
[ "Set", "the", "wait", "duration", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/touch/WaitOptions.java#L46-L52
25,056
appium/java-client
src/main/java/io/appium/java_client/touch/LongPressOptions.java
LongPressOptions.withDuration
public LongPressOptions withDuration(Duration duration) { checkNotNull(duration); checkArgument(duration.toMillis() >= 0, "Duration value should be greater or equal to zero"); this.duration = duration; return this; }
java
public LongPressOptions withDuration(Duration duration) { checkNotNull(duration); checkArgument(duration.toMillis() >= 0, "Duration value should be greater or equal to zero"); this.duration = duration; return this; }
[ "public", "LongPressOptions", "withDuration", "(", "Duration", "duration", ")", "{", "checkNotNull", "(", "duration", ")", ";", "checkArgument", "(", "duration", ".", "toMillis", "(", ")", ">=", "0", ",", "\"Duration value should be greater or equal to zero\"", ")", ";", "this", ".", "duration", "=", "duration", ";", "return", "this", ";", "}" ]
Set the long press duration. @param duration the value to set. Time resolution unit is 1 ms. @return this instance for chaining.
[ "Set", "the", "long", "press", "duration", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/touch/LongPressOptions.java#L47-L53
25,057
appium/java-client
src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java
AndroidMobileCommandHelper.getPerformanceDataCommand
public static Map.Entry<String, Map<String, ?>> getPerformanceDataCommand( String packageName, String dataType, int dataReadTimeout) { String[] parameters = new String[] {"packageName", "dataType", "dataReadTimeout"}; Object[] values = new Object[] {packageName, dataType, dataReadTimeout}; return new AbstractMap.SimpleEntry<>( GET_PERFORMANCE_DATA, prepareArguments(parameters, values)); }
java
public static Map.Entry<String, Map<String, ?>> getPerformanceDataCommand( String packageName, String dataType, int dataReadTimeout) { String[] parameters = new String[] {"packageName", "dataType", "dataReadTimeout"}; Object[] values = new Object[] {packageName, dataType, dataReadTimeout}; return new AbstractMap.SimpleEntry<>( GET_PERFORMANCE_DATA, prepareArguments(parameters, values)); }
[ "public", "static", "Map", ".", "Entry", "<", "String", ",", "Map", "<", "String", ",", "?", ">", ">", "getPerformanceDataCommand", "(", "String", "packageName", ",", "String", "dataType", ",", "int", "dataReadTimeout", ")", "{", "String", "[", "]", "parameters", "=", "new", "String", "[", "]", "{", "\"packageName\"", ",", "\"dataType\"", ",", "\"dataReadTimeout\"", "}", ";", "Object", "[", "]", "values", "=", "new", "Object", "[", "]", "{", "packageName", ",", "dataType", ",", "dataReadTimeout", "}", ";", "return", "new", "AbstractMap", ".", "SimpleEntry", "<>", "(", "GET_PERFORMANCE_DATA", ",", "prepareArguments", "(", "parameters", ",", "values", ")", ")", ";", "}" ]
returns the resource usage information of the application. the resource is one of the system state which means cpu, memory, network traffic, and battery. @param packageName the package name of the application @param dataType the type of system state which wants to read. It should be one of the supported performance data types, the return value of the function "getSupportedPerformanceDataTypes" @param dataReadTimeout the number of attempts to read @return table of the performance data, The first line of the table represents the type of data. The remaining lines represent the values of the data. in case of battery info : [[power], [23]] in case of memory info : [[totalPrivateDirty, nativePrivateDirty, dalvikPrivateDirty, eglPrivateDirty, glPrivateDirty, totalPss, nativePss, dalvikPss, eglPss, glPss, nativeHeapAllocatedSize, nativeHeapSize], [18360, 8296, 6132, null, null, 42588, 8406, 7024, null, null, 26519, 10344]] in case of network info : [[bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations, bucketDuration,], [1478091600000, null, 1099075, 610947, 928, 114362, 769, 0, 3600000], [1478095200000, null, 1306300, 405997, 509, 46359, 370, 0, 3600000]] in case of network info : [[st, activeTime, rb, rp, tb, tp, op, bucketDuration], [1478088000, null, null, 32115296, 34291, 2956805, 25705, 0, 3600], [1478091600, null, null, 2714683, 11821, 1420564, 12650, 0, 3600], [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600], [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]] in case of cpu info : [[user, kernel], [0.9, 1.3]]
[ "returns", "the", "resource", "usage", "information", "of", "the", "application", ".", "the", "resource", "is", "one", "of", "the", "system", "state", "which", "means", "cpu", "memory", "network", "traffic", "and", "battery", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java#L109-L115
25,058
appium/java-client
src/main/java/io/appium/java_client/ws/StringWebSocketClient.java
StringWebSocketClient.connect
public void connect(URI endpoint) { if (endpoint.equals(this.getEndpoint()) && isListening) { return; } OkHttpClient client = new OkHttpClient.Builder() .readTimeout(0, TimeUnit.MILLISECONDS) .build(); Request request = new Request.Builder() .url(endpoint.toString()) .build(); client.newWebSocket(request, this); client.dispatcher().executorService().shutdown(); setEndpoint(endpoint); }
java
public void connect(URI endpoint) { if (endpoint.equals(this.getEndpoint()) && isListening) { return; } OkHttpClient client = new OkHttpClient.Builder() .readTimeout(0, TimeUnit.MILLISECONDS) .build(); Request request = new Request.Builder() .url(endpoint.toString()) .build(); client.newWebSocket(request, this); client.dispatcher().executorService().shutdown(); setEndpoint(endpoint); }
[ "public", "void", "connect", "(", "URI", "endpoint", ")", "{", "if", "(", "endpoint", ".", "equals", "(", "this", ".", "getEndpoint", "(", ")", ")", "&&", "isListening", ")", "{", "return", ";", "}", "OkHttpClient", "client", "=", "new", "OkHttpClient", ".", "Builder", "(", ")", ".", "readTimeout", "(", "0", ",", "TimeUnit", ".", "MILLISECONDS", ")", ".", "build", "(", ")", ";", "Request", "request", "=", "new", "Request", ".", "Builder", "(", ")", ".", "url", "(", "endpoint", ".", "toString", "(", ")", ")", ".", "build", "(", ")", ";", "client", ".", "newWebSocket", "(", "request", ",", "this", ")", ";", "client", ".", "dispatcher", "(", ")", ".", "executorService", "(", ")", ".", "shutdown", "(", ")", ";", "setEndpoint", "(", "endpoint", ")", ";", "}" ]
Connects web socket client. @param endpoint The full address of an endpoint to connect to. Usually starts with 'ws://'.
[ "Connects", "web", "socket", "client", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/ws/StringWebSocketClient.java#L63-L78
25,059
appium/java-client
src/main/java/io/appium/java_client/ScreenshotState.java
ScreenshotState.verifyChanged
public ScreenshotState verifyChanged(Duration timeout, double minScore) { return checkState((x) -> x < minScore, timeout); }
java
public ScreenshotState verifyChanged(Duration timeout, double minScore) { return checkState((x) -> x < minScore, timeout); }
[ "public", "ScreenshotState", "verifyChanged", "(", "Duration", "timeout", ",", "double", "minScore", ")", "{", "return", "checkState", "(", "(", "x", ")", "-", ">", "x", "<", "minScore", ",", "timeout", ")", ";", "}" ]
Verifies whether the state of the screenshot provided by stateProvider lambda function is changed within the given timeout. @param timeout timeout value @param minScore the value in range (0.0, 1.0) @return self instance for chaining @throws ScreenshotComparisonTimeout if the calculated score is still greater or equal to the given score after timeout happens @throws ScreenshotComparisonError if {@link #remember()} method has not been invoked yet
[ "Verifies", "whether", "the", "state", "of", "the", "screenshot", "provided", "by", "stateProvider", "lambda", "function", "is", "changed", "within", "the", "given", "timeout", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/ScreenshotState.java#L186-L188
25,060
appium/java-client
src/main/java/io/appium/java_client/ScreenshotState.java
ScreenshotState.verifyNotChanged
public ScreenshotState verifyNotChanged(Duration timeout, double minScore) { return checkState((x) -> x >= minScore, timeout); }
java
public ScreenshotState verifyNotChanged(Duration timeout, double minScore) { return checkState((x) -> x >= minScore, timeout); }
[ "public", "ScreenshotState", "verifyNotChanged", "(", "Duration", "timeout", ",", "double", "minScore", ")", "{", "return", "checkState", "(", "(", "x", ")", "-", ">", "x", ">=", "minScore", ",", "timeout", ")", ";", "}" ]
Verifies whether the state of the screenshot provided by stateProvider lambda function is not changed within the given timeout. @param timeout timeout value @param minScore the value in range (0.0, 1.0) @return self instance for chaining @throws ScreenshotComparisonTimeout if the calculated score is still less than the given score after timeout happens @throws ScreenshotComparisonError if {@link #remember()} method has not been invoked yet
[ "Verifies", "whether", "the", "state", "of", "the", "screenshot", "provided", "by", "stateProvider", "lambda", "function", "is", "not", "changed", "within", "the", "given", "timeout", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/ScreenshotState.java#L201-L203
25,061
appium/java-client
src/main/java/io/appium/java_client/ios/IOSTouchAction.java
IOSTouchAction.doubleTap
public IOSTouchAction doubleTap(PointOption doubleTapOption) { ActionParameter action = new ActionParameter("doubleTap", doubleTapOption); parameterBuilder.add(action); return this; }
java
public IOSTouchAction doubleTap(PointOption doubleTapOption) { ActionParameter action = new ActionParameter("doubleTap", doubleTapOption); parameterBuilder.add(action); return this; }
[ "public", "IOSTouchAction", "doubleTap", "(", "PointOption", "doubleTapOption", ")", "{", "ActionParameter", "action", "=", "new", "ActionParameter", "(", "\"doubleTap\"", ",", "doubleTapOption", ")", ";", "parameterBuilder", ".", "add", "(", "action", ")", ";", "return", "this", ";", "}" ]
Double taps using coordinates. @param doubleTapOption see {@link PointOption} and {@link ElementOption}.. @return self-reference
[ "Double", "taps", "using", "coordinates", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/ios/IOSTouchAction.java#L37-L42
25,062
appium/java-client
src/main/java/io/appium/java_client/pagefactory/utils/ProxyFactory.java
ProxyFactory.getEnhancedProxy
@SuppressWarnings("unchecked") public static <T> T getEnhancedProxy(Class<T> requiredClazz, Class<?>[] params, Object[] values, MethodInterceptor interceptor) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(requiredClazz); enhancer.setCallback(interceptor); return (T) enhancer.create(params, values); }
java
@SuppressWarnings("unchecked") public static <T> T getEnhancedProxy(Class<T> requiredClazz, Class<?>[] params, Object[] values, MethodInterceptor interceptor) { Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(requiredClazz); enhancer.setCallback(interceptor); return (T) enhancer.create(params, values); }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", ">", "T", "getEnhancedProxy", "(", "Class", "<", "T", ">", "requiredClazz", ",", "Class", "<", "?", ">", "[", "]", "params", ",", "Object", "[", "]", "values", ",", "MethodInterceptor", "interceptor", ")", "{", "Enhancer", "enhancer", "=", "new", "Enhancer", "(", ")", ";", "enhancer", ".", "setSuperclass", "(", "requiredClazz", ")", ";", "enhancer", ".", "setCallback", "(", "interceptor", ")", ";", "return", "(", "T", ")", "enhancer", ".", "create", "(", "params", ",", "values", ")", ";", "}" ]
It returns some proxies created by CGLIB. @param requiredClazz is a {@link java.lang.Class} whose instance should be created @param params is an array of @link java.lang.Class}. It should be convenient to parameter types of some declared constructor which belongs to desired class. @param values is an array of @link java.lang.Object}. It should be convenient to parameter types of some declared constructor which belongs to desired class. @param interceptor is the instance of {@link net.sf.cglib.proxy.MethodInterceptor} @return a proxied instance of the desired class
[ "It", "returns", "some", "proxies", "created", "by", "CGLIB", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/pagefactory/utils/ProxyFactory.java#L49-L56
25,063
appium/java-client
src/main/java/io/appium/java_client/AppiumDriver.java
AppiumDriver.substituteMobilePlatform
protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities, String newPlatform) { DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities); dc.setCapability(PLATFORM_NAME, newPlatform); return dc; }
java
protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities, String newPlatform) { DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities); dc.setCapability(PLATFORM_NAME, newPlatform); return dc; }
[ "protected", "static", "Capabilities", "substituteMobilePlatform", "(", "Capabilities", "originalCapabilities", ",", "String", "newPlatform", ")", "{", "DesiredCapabilities", "dc", "=", "new", "DesiredCapabilities", "(", "originalCapabilities", ")", ";", "dc", ".", "setCapability", "(", "PLATFORM_NAME", ",", "newPlatform", ")", ";", "return", "dc", ";", "}" ]
Changes platform name and returns new capabilities. @param originalCapabilities the given {@link Capabilities}. @param newPlatform a {@link MobileCapabilityType#PLATFORM_NAME} value which has to be set up @return {@link Capabilities} with changed mobile platform value
[ "Changes", "platform", "name", "and", "returns", "new", "capabilities", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/AppiumDriver.java#L140-L145
25,064
appium/java-client
src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java
AppiumElementLocator.findElements
public List<WebElement> findElements() { if (cachedElementList != null && shouldCache) { return cachedElementList; } List<WebElement> result; try { result = waitFor(() -> { List<WebElement> list = searchContext .findElements(getBy(by, searchContext)); return list.size() > 0 ? list : null; }); } catch (TimeoutException | StaleElementReferenceException e) { result = new ArrayList<>(); } if (shouldCache) { cachedElementList = result; } return result; }
java
public List<WebElement> findElements() { if (cachedElementList != null && shouldCache) { return cachedElementList; } List<WebElement> result; try { result = waitFor(() -> { List<WebElement> list = searchContext .findElements(getBy(by, searchContext)); return list.size() > 0 ? list : null; }); } catch (TimeoutException | StaleElementReferenceException e) { result = new ArrayList<>(); } if (shouldCache) { cachedElementList = result; } return result; }
[ "public", "List", "<", "WebElement", ">", "findElements", "(", ")", "{", "if", "(", "cachedElementList", "!=", "null", "&&", "shouldCache", ")", "{", "return", "cachedElementList", ";", "}", "List", "<", "WebElement", ">", "result", ";", "try", "{", "result", "=", "waitFor", "(", "(", ")", "->", "{", "List", "<", "WebElement", ">", "list", "=", "searchContext", ".", "findElements", "(", "getBy", "(", "by", ",", "searchContext", ")", ")", ";", "return", "list", ".", "size", "(", ")", ">", "0", "?", "list", ":", "null", ";", "}", ")", ";", "}", "catch", "(", "TimeoutException", "|", "StaleElementReferenceException", "e", ")", "{", "result", "=", "new", "ArrayList", "<>", "(", ")", ";", "}", "if", "(", "shouldCache", ")", "{", "cachedElementList", "=", "result", ";", "}", "return", "result", ";", "}" ]
Find the element list.
[ "Find", "the", "element", "list", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java#L133-L153
25,065
appium/java-client
src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java
NewAppiumSessionPayload.writeTo
public void writeTo(Appendable appendable) throws IOException { try (JsonOutput json = new Json().newOutput(appendable)) { json.beginObject(); Map<String, Object> first = getOss(); if (first == null) { //noinspection unchecked first = (Map<String, Object>) stream().findFirst() .orElse(new ImmutableCapabilities()) .asMap(); } // Write the first capability we get as the desired capability. json.name(DESIRED_CAPABILITIES); json.write(first); if (!forceMobileJSONWP) { // And write the first capability for gecko13 json.name(CAPABILITIES); json.beginObject(); // Then write everything into the w3c payload. Because of the way we do this, it's easiest // to just populate the "firstMatch" section. The spec says it's fine to omit the // "alwaysMatch" field, so we do this. json.name(FIRST_MATCH); json.beginArray(); getW3C().forEach(json::write); json.endArray(); json.endObject(); // Close "capabilities" object } writeMetaData(json); json.endObject(); } }
java
public void writeTo(Appendable appendable) throws IOException { try (JsonOutput json = new Json().newOutput(appendable)) { json.beginObject(); Map<String, Object> first = getOss(); if (first == null) { //noinspection unchecked first = (Map<String, Object>) stream().findFirst() .orElse(new ImmutableCapabilities()) .asMap(); } // Write the first capability we get as the desired capability. json.name(DESIRED_CAPABILITIES); json.write(first); if (!forceMobileJSONWP) { // And write the first capability for gecko13 json.name(CAPABILITIES); json.beginObject(); // Then write everything into the w3c payload. Because of the way we do this, it's easiest // to just populate the "firstMatch" section. The spec says it's fine to omit the // "alwaysMatch" field, so we do this. json.name(FIRST_MATCH); json.beginArray(); getW3C().forEach(json::write); json.endArray(); json.endObject(); // Close "capabilities" object } writeMetaData(json); json.endObject(); } }
[ "public", "void", "writeTo", "(", "Appendable", "appendable", ")", "throws", "IOException", "{", "try", "(", "JsonOutput", "json", "=", "new", "Json", "(", ")", ".", "newOutput", "(", "appendable", ")", ")", "{", "json", ".", "beginObject", "(", ")", ";", "Map", "<", "String", ",", "Object", ">", "first", "=", "getOss", "(", ")", ";", "if", "(", "first", "==", "null", ")", "{", "//noinspection unchecked", "first", "=", "(", "Map", "<", "String", ",", "Object", ">", ")", "stream", "(", ")", ".", "findFirst", "(", ")", ".", "orElse", "(", "new", "ImmutableCapabilities", "(", ")", ")", ".", "asMap", "(", ")", ";", "}", "// Write the first capability we get as the desired capability.", "json", ".", "name", "(", "DESIRED_CAPABILITIES", ")", ";", "json", ".", "write", "(", "first", ")", ";", "if", "(", "!", "forceMobileJSONWP", ")", "{", "// And write the first capability for gecko13", "json", ".", "name", "(", "CAPABILITIES", ")", ";", "json", ".", "beginObject", "(", ")", ";", "// Then write everything into the w3c payload. Because of the way we do this, it's easiest", "// to just populate the \"firstMatch\" section. The spec says it's fine to omit the", "// \"alwaysMatch\" field, so we do this.", "json", ".", "name", "(", "FIRST_MATCH", ")", ";", "json", ".", "beginArray", "(", ")", ";", "getW3C", "(", ")", ".", "forEach", "(", "json", "::", "write", ")", ";", "json", ".", "endArray", "(", ")", ";", "json", ".", "endObject", "(", ")", ";", "// Close \"capabilities\" object", "}", "writeMetaData", "(", "json", ")", ";", "json", ".", "endObject", "(", ")", ";", "}", "}" ]
Writes json capabilities to some appendable object. @param appendable to write a json
[ "Writes", "json", "capabilities", "to", "some", "appendable", "object", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/remote/NewAppiumSessionPayload.java#L239-L275
25,066
appium/java-client
src/main/java/io/appium/java_client/MultiTouchAction.java
MultiTouchAction.perform
public MultiTouchAction perform() { List<TouchAction> touchActions = actions.build(); checkArgument(touchActions.size() > 0, "MultiTouch action must have at least one TouchAction added before it can be performed"); if (touchActions.size() > 1) { performsTouchActions.performMultiTouchAction(this); return this; } //android doesn't like having multi-touch actions with only a single TouchAction... performsTouchActions.performTouchAction(touchActions.get(0)); return this; }
java
public MultiTouchAction perform() { List<TouchAction> touchActions = actions.build(); checkArgument(touchActions.size() > 0, "MultiTouch action must have at least one TouchAction added before it can be performed"); if (touchActions.size() > 1) { performsTouchActions.performMultiTouchAction(this); return this; } //android doesn't like having multi-touch actions with only a single TouchAction... performsTouchActions.performTouchAction(touchActions.get(0)); return this; }
[ "public", "MultiTouchAction", "perform", "(", ")", "{", "List", "<", "TouchAction", ">", "touchActions", "=", "actions", ".", "build", "(", ")", ";", "checkArgument", "(", "touchActions", ".", "size", "(", ")", ">", "0", ",", "\"MultiTouch action must have at least one TouchAction added before it can be performed\"", ")", ";", "if", "(", "touchActions", ".", "size", "(", ")", ">", "1", ")", "{", "performsTouchActions", ".", "performMultiTouchAction", "(", "this", ")", ";", "return", "this", ";", "}", "//android doesn't like having multi-touch actions with only a single TouchAction...", "performsTouchActions", ".", "performTouchAction", "(", "touchActions", ".", "get", "(", "0", ")", ")", ";", "return", "this", ";", "}" ]
Perform the multi-touch action on the mobile performsTouchActions.
[ "Perform", "the", "multi", "-", "touch", "action", "on", "the", "mobile", "performsTouchActions", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/MultiTouchAction.java#L69-L79
25,067
appium/java-client
src/main/java/io/appium/java_client/ios/IOSDriver.java
IOSDriver.runAppInBackground
@Override public void runAppInBackground(Duration duration) { // timeout parameter is expected to be in milliseconds // float values are allowed execute(RUN_APP_IN_BACKGROUND, prepareArguments("seconds", prepareArguments("timeout", duration.toMillis()))); }
java
@Override public void runAppInBackground(Duration duration) { // timeout parameter is expected to be in milliseconds // float values are allowed execute(RUN_APP_IN_BACKGROUND, prepareArguments("seconds", prepareArguments("timeout", duration.toMillis()))); }
[ "@", "Override", "public", "void", "runAppInBackground", "(", "Duration", "duration", ")", "{", "// timeout parameter is expected to be in milliseconds", "// float values are allowed", "execute", "(", "RUN_APP_IN_BACKGROUND", ",", "prepareArguments", "(", "\"seconds\"", ",", "prepareArguments", "(", "\"timeout\"", ",", "duration", ".", "toMillis", "(", ")", ")", ")", ")", ";", "}" ]
Runs the current app as a background app for the number of seconds or minimizes the app. @param duration The time to run App in background.
[ "Runs", "the", "current", "app", "as", "a", "background", "app", "for", "the", "number", "of", "seconds", "or", "minimizes", "the", "app", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/ios/IOSDriver.java#L182-L187
25,068
appium/java-client
src/main/java/io/appium/java_client/ios/IOSDriver.java
IOSDriver.getCapabilities
@Nullable public Capabilities getCapabilities() { MutableCapabilities capabilities = (MutableCapabilities) super.getCapabilities(); if (capabilities != null) { capabilities.setCapability(PLATFORM_NAME, IOS_PLATFORM); } return capabilities; }
java
@Nullable public Capabilities getCapabilities() { MutableCapabilities capabilities = (MutableCapabilities) super.getCapabilities(); if (capabilities != null) { capabilities.setCapability(PLATFORM_NAME, IOS_PLATFORM); } return capabilities; }
[ "@", "Nullable", "public", "Capabilities", "getCapabilities", "(", ")", "{", "MutableCapabilities", "capabilities", "=", "(", "MutableCapabilities", ")", "super", ".", "getCapabilities", "(", ")", ";", "if", "(", "capabilities", "!=", "null", ")", "{", "capabilities", ".", "setCapability", "(", "PLATFORM_NAME", ",", "IOS_PLATFORM", ")", ";", "}", "return", "capabilities", ";", "}" ]
Returns capabilities that were provided on instantiation. @return given {@link Capabilities}
[ "Returns", "capabilities", "that", "were", "provided", "on", "instantiation", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/ios/IOSDriver.java#L211-L218
25,069
appium/java-client
src/main/java/io/appium/java_client/MobileElement.java
MobileElement.getCenter
public Point getCenter() { Point upperLeft = this.getLocation(); Dimension dimensions = this.getSize(); return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); }
java
public Point getCenter() { Point upperLeft = this.getLocation(); Dimension dimensions = this.getSize(); return new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2); }
[ "public", "Point", "getCenter", "(", ")", "{", "Point", "upperLeft", "=", "this", ".", "getLocation", "(", ")", ";", "Dimension", "dimensions", "=", "this", ".", "getSize", "(", ")", ";", "return", "new", "Point", "(", "upperLeft", ".", "getX", "(", ")", "+", "dimensions", ".", "getWidth", "(", ")", "/", "2", ",", "upperLeft", ".", "getY", "(", ")", "+", "dimensions", ".", "getHeight", "(", ")", "/", "2", ")", ";", "}" ]
Method returns central coordinates of an element. @return The instance of the {@link org.openqa.selenium.Point}
[ "Method", "returns", "central", "coordinates", "of", "an", "element", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/MobileElement.java#L38-L43
25,070
appium/java-client
src/main/java/io/appium/java_client/MobileElement.java
MobileElement.setValue
public void setValue(String value) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); builder.put("id", id).put("value", value); execute(MobileCommand.SET_VALUE, builder.build()); }
java
public void setValue(String value) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); builder.put("id", id).put("value", value); execute(MobileCommand.SET_VALUE, builder.build()); }
[ "public", "void", "setValue", "(", "String", "value", ")", "{", "ImmutableMap", ".", "Builder", "<", "String", ",", "Object", ">", "builder", "=", "ImmutableMap", ".", "builder", "(", ")", ";", "builder", ".", "put", "(", "\"id\"", ",", "id", ")", ".", "put", "(", "\"value\"", ",", "value", ")", ";", "execute", "(", "MobileCommand", ".", "SET_VALUE", ",", "builder", ".", "build", "(", ")", ")", ";", "}" ]
This method sets the new value of the attribute "value". @param value is the new value which should be set
[ "This", "method", "sets", "the", "new", "value", "of", "the", "attribute", "value", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/MobileElement.java#L94-L98
25,071
appium/java-client
src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java
AppiumDriverLocalService.start
public void start() throws AppiumServerHasNotBeenStartedLocallyException { lock.lock(); try { if (isRunning()) { return; } try { process = new CommandLine(this.nodeJSExec.getCanonicalPath(), nodeJSArgs.toArray(new String[] {})); process.setEnvironmentVariables(nodeJSEnvironment); process.copyOutputTo(stream); process.executeAsync(); ping(startupTimeout, timeUnit); } catch (Throwable e) { destroyProcess(); String msgTxt = "The local appium server has not been started. " + "The given Node.js executable: " + this.nodeJSExec.getAbsolutePath() + " Arguments: " + nodeJSArgs.toString() + " " + "\n"; if (process != null) { String processStream = process.getStdOut(); if (!StringUtils.isBlank(processStream)) { msgTxt = msgTxt + "Process output: " + processStream + "\n"; } } throw new AppiumServerHasNotBeenStartedLocallyException(msgTxt, e); } } finally { lock.unlock(); } }
java
public void start() throws AppiumServerHasNotBeenStartedLocallyException { lock.lock(); try { if (isRunning()) { return; } try { process = new CommandLine(this.nodeJSExec.getCanonicalPath(), nodeJSArgs.toArray(new String[] {})); process.setEnvironmentVariables(nodeJSEnvironment); process.copyOutputTo(stream); process.executeAsync(); ping(startupTimeout, timeUnit); } catch (Throwable e) { destroyProcess(); String msgTxt = "The local appium server has not been started. " + "The given Node.js executable: " + this.nodeJSExec.getAbsolutePath() + " Arguments: " + nodeJSArgs.toString() + " " + "\n"; if (process != null) { String processStream = process.getStdOut(); if (!StringUtils.isBlank(processStream)) { msgTxt = msgTxt + "Process output: " + processStream + "\n"; } } throw new AppiumServerHasNotBeenStartedLocallyException(msgTxt, e); } } finally { lock.unlock(); } }
[ "public", "void", "start", "(", ")", "throws", "AppiumServerHasNotBeenStartedLocallyException", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "if", "(", "isRunning", "(", ")", ")", "{", "return", ";", "}", "try", "{", "process", "=", "new", "CommandLine", "(", "this", ".", "nodeJSExec", ".", "getCanonicalPath", "(", ")", ",", "nodeJSArgs", ".", "toArray", "(", "new", "String", "[", "]", "{", "}", ")", ")", ";", "process", ".", "setEnvironmentVariables", "(", "nodeJSEnvironment", ")", ";", "process", ".", "copyOutputTo", "(", "stream", ")", ";", "process", ".", "executeAsync", "(", ")", ";", "ping", "(", "startupTimeout", ",", "timeUnit", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "destroyProcess", "(", ")", ";", "String", "msgTxt", "=", "\"The local appium server has not been started. \"", "+", "\"The given Node.js executable: \"", "+", "this", ".", "nodeJSExec", ".", "getAbsolutePath", "(", ")", "+", "\" Arguments: \"", "+", "nodeJSArgs", ".", "toString", "(", ")", "+", "\" \"", "+", "\"\\n\"", ";", "if", "(", "process", "!=", "null", ")", "{", "String", "processStream", "=", "process", ".", "getStdOut", "(", ")", ";", "if", "(", "!", "StringUtils", ".", "isBlank", "(", "processStream", ")", ")", "{", "msgTxt", "=", "msgTxt", "+", "\"Process output: \"", "+", "processStream", "+", "\"\\n\"", ";", "}", "}", "throw", "new", "AppiumServerHasNotBeenStartedLocallyException", "(", "msgTxt", ",", "e", ")", ";", "}", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}" ]
Starts the defined appium server. @throws AppiumServerHasNotBeenStartedLocallyException If an error occurs while spawning the child process. @see #stop()
[ "Starts", "the", "defined", "appium", "server", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java#L135-L166
25,072
appium/java-client
src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java
AppiumDriverLocalService.stop
@Override public void stop() { lock.lock(); try { if (process != null) { destroyProcess(); } process = null; } finally { lock.unlock(); } }
java
@Override public void stop() { lock.lock(); try { if (process != null) { destroyProcess(); } process = null; } finally { lock.unlock(); } }
[ "@", "Override", "public", "void", "stop", "(", ")", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "if", "(", "process", "!=", "null", ")", "{", "destroyProcess", "(", ")", ";", "}", "process", "=", "null", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}" ]
Stops this service is it is currently running. This method will attempt to block until the server has been fully shutdown. @see #start()
[ "Stops", "this", "service", "is", "it", "is", "currently", "running", ".", "This", "method", "will", "attempt", "to", "block", "until", "the", "server", "has", "been", "fully", "shutdown", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java#L174-L184
25,073
appium/java-client
src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java
AppiumDriverLocalService.addOutPutStreams
public void addOutPutStreams(List<OutputStream> outputStreams) { checkNotNull(outputStreams, "outputStreams parameter is NULL!"); for (OutputStream stream : outputStreams) { addOutPutStream(stream); } }
java
public void addOutPutStreams(List<OutputStream> outputStreams) { checkNotNull(outputStreams, "outputStreams parameter is NULL!"); for (OutputStream stream : outputStreams) { addOutPutStream(stream); } }
[ "public", "void", "addOutPutStreams", "(", "List", "<", "OutputStream", ">", "outputStreams", ")", "{", "checkNotNull", "(", "outputStreams", ",", "\"outputStreams parameter is NULL!\"", ")", ";", "for", "(", "OutputStream", "stream", ":", "outputStreams", ")", "{", "addOutPutStream", "(", "stream", ")", ";", "}", "}" ]
Adds other output streams which should accept server output data. @param outputStreams is a list of additional {@link OutputStream} that are ready to accept server output
[ "Adds", "other", "output", "streams", "which", "should", "accept", "server", "output", "data", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java#L222-L227
25,074
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/OccurrenceMatchingResult.java
OccurrenceMatchingResult.getRect
public Rectangle getRect() { verifyPropertyPresence(RECT); //noinspection unchecked return mapToRect((Map<String, Object>) getCommandResult().get(RECT)); }
java
public Rectangle getRect() { verifyPropertyPresence(RECT); //noinspection unchecked return mapToRect((Map<String, Object>) getCommandResult().get(RECT)); }
[ "public", "Rectangle", "getRect", "(", ")", "{", "verifyPropertyPresence", "(", "RECT", ")", ";", "//noinspection unchecked", "return", "mapToRect", "(", "(", "Map", "<", "String", ",", "Object", ">", ")", "getCommandResult", "(", ")", ".", "get", "(", "RECT", ")", ")", ";", "}" ]
Returns rectangle of partial image occurrence. @return The region of the partial image occurrence on the full image.
[ "Returns", "rectangle", "of", "partial", "image", "occurrence", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/OccurrenceMatchingResult.java#L35-L39
25,075
appium/java-client
src/main/java/io/appium/java_client/android/nativekey/KeyEvent.java
KeyEvent.withMetaModifier
public KeyEvent withMetaModifier(KeyEventMetaModifier keyEventMetaModifier) { if (this.metaState == null) { this.metaState = 0; } this.metaState |= keyEventMetaModifier.getValue(); return this; }
java
public KeyEvent withMetaModifier(KeyEventMetaModifier keyEventMetaModifier) { if (this.metaState == null) { this.metaState = 0; } this.metaState |= keyEventMetaModifier.getValue(); return this; }
[ "public", "KeyEvent", "withMetaModifier", "(", "KeyEventMetaModifier", "keyEventMetaModifier", ")", "{", "if", "(", "this", ".", "metaState", "==", "null", ")", "{", "this", ".", "metaState", "=", "0", ";", "}", "this", ".", "metaState", "|=", "keyEventMetaModifier", ".", "getValue", "(", ")", ";", "return", "this", ";", "}" ]
Adds the meta modifier. @param keyEventMetaModifier Native Android modifier value. Multiple modifiers can be combined into a single key event. @return self instance for chaining
[ "Adds", "the", "meta", "modifier", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/android/nativekey/KeyEvent.java#L55-L61
25,076
appium/java-client
src/main/java/io/appium/java_client/android/nativekey/KeyEvent.java
KeyEvent.withFlag
public KeyEvent withFlag(KeyEventFlag keyEventFlag) { if (this.flags == null) { this.flags = 0; } this.flags |= keyEventFlag.getValue(); return this; }
java
public KeyEvent withFlag(KeyEventFlag keyEventFlag) { if (this.flags == null) { this.flags = 0; } this.flags |= keyEventFlag.getValue(); return this; }
[ "public", "KeyEvent", "withFlag", "(", "KeyEventFlag", "keyEventFlag", ")", "{", "if", "(", "this", ".", "flags", "==", "null", ")", "{", "this", ".", "flags", "=", "0", ";", "}", "this", ".", "flags", "|=", "keyEventFlag", ".", "getValue", "(", ")", ";", "return", "this", ";", "}" ]
Adds the flag. @param keyEventFlag Native Android flag value. Several flags can be combined into a single key event. @return self instance for chaining
[ "Adds", "the", "flag", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/android/nativekey/KeyEvent.java#L70-L76
25,077
appium/java-client
src/main/java/io/appium/java_client/android/nativekey/KeyEvent.java
KeyEvent.build
public Map<String, Object> build() { final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); final int keyCode = ofNullable(this.keyCode) .orElseThrow(() -> new IllegalStateException("The key code must be set")); builder.put("keycode", keyCode); ofNullable(this.metaState).ifPresent(x -> builder.put("metastate", x)); ofNullable(this.flags).ifPresent(x -> builder.put("flags", x)); return builder.build(); }
java
public Map<String, Object> build() { final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); final int keyCode = ofNullable(this.keyCode) .orElseThrow(() -> new IllegalStateException("The key code must be set")); builder.put("keycode", keyCode); ofNullable(this.metaState).ifPresent(x -> builder.put("metastate", x)); ofNullable(this.flags).ifPresent(x -> builder.put("flags", x)); return builder.build(); }
[ "public", "Map", "<", "String", ",", "Object", ">", "build", "(", ")", "{", "final", "ImmutableMap", ".", "Builder", "<", "String", ",", "Object", ">", "builder", "=", "ImmutableMap", ".", "builder", "(", ")", ";", "final", "int", "keyCode", "=", "ofNullable", "(", "this", ".", "keyCode", ")", ".", "orElseThrow", "(", "(", ")", "->", "new", "IllegalStateException", "(", "\"The key code must be set\"", ")", ")", ";", "builder", ".", "put", "(", "\"keycode\"", ",", "keyCode", ")", ";", "ofNullable", "(", "this", ".", "metaState", ")", ".", "ifPresent", "(", "x", "->", "builder", ".", "put", "(", "\"metastate\"", ",", "x", ")", ")", ";", "ofNullable", "(", "this", ".", "flags", ")", ".", "ifPresent", "(", "x", "->", "builder", ".", "put", "(", "\"flags\"", ",", "x", ")", ")", ";", "return", "builder", ".", "build", "(", ")", ";", "}" ]
Builds a map, which is ready to be used by the downstream API. @return API parameters mapping @throws IllegalStateException if key code is not set
[ "Builds", "a", "map", "which", "is", "ready", "to", "be", "used", "by", "the", "downstream", "API", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/android/nativekey/KeyEvent.java#L84-L92
25,078
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java
FeaturesMatchingResult.getPoints1
public List<Point> getPoints1() { verifyPropertyPresence(POINTS1); //noinspection unchecked return ((List<Map<String, Object>>) getCommandResult().get(POINTS1)).stream() .map(ComparisonResult::mapToPoint) .collect(Collectors.toList()); }
java
public List<Point> getPoints1() { verifyPropertyPresence(POINTS1); //noinspection unchecked return ((List<Map<String, Object>>) getCommandResult().get(POINTS1)).stream() .map(ComparisonResult::mapToPoint) .collect(Collectors.toList()); }
[ "public", "List", "<", "Point", ">", "getPoints1", "(", ")", "{", "verifyPropertyPresence", "(", "POINTS1", ")", ";", "//noinspection unchecked", "return", "(", "(", "List", "<", "Map", "<", "String", ",", "Object", ">", ">", ")", "getCommandResult", "(", ")", ".", "get", "(", "POINTS1", ")", ")", ".", "stream", "(", ")", ".", "map", "(", "ComparisonResult", "::", "mapToPoint", ")", ".", "collect", "(", "Collectors", ".", "toList", "(", ")", ")", ";", "}" ]
Returns a list of matching points on the first image. @return The list of matching points on the first image.
[ "Returns", "a", "list", "of", "matching", "points", "on", "the", "first", "image", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java#L67-L73
25,079
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java
FeaturesMatchingResult.getRect1
public Rectangle getRect1() { verifyPropertyPresence(RECT1); //noinspection unchecked return mapToRect((Map<String, Object>) getCommandResult().get(RECT1)); }
java
public Rectangle getRect1() { verifyPropertyPresence(RECT1); //noinspection unchecked return mapToRect((Map<String, Object>) getCommandResult().get(RECT1)); }
[ "public", "Rectangle", "getRect1", "(", ")", "{", "verifyPropertyPresence", "(", "RECT1", ")", ";", "//noinspection unchecked", "return", "mapToRect", "(", "(", "Map", "<", "String", ",", "Object", ">", ")", "getCommandResult", "(", ")", ".", "get", "(", "RECT1", ")", ")", ";", "}" ]
Returns a rect for the `points1` list. @return The bounding rect for the `points1` list or a zero rect if not enough matching points were found.
[ "Returns", "a", "rect", "for", "the", "points1", "list", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java#L80-L84
25,080
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java
FeaturesMatchingResult.getPoints2
public List<Point> getPoints2() { verifyPropertyPresence(POINTS2); //noinspection unchecked return ((List<Map<String, Object>>) getCommandResult().get(POINTS2)).stream() .map(ComparisonResult::mapToPoint) .collect(Collectors.toList()); }
java
public List<Point> getPoints2() { verifyPropertyPresence(POINTS2); //noinspection unchecked return ((List<Map<String, Object>>) getCommandResult().get(POINTS2)).stream() .map(ComparisonResult::mapToPoint) .collect(Collectors.toList()); }
[ "public", "List", "<", "Point", ">", "getPoints2", "(", ")", "{", "verifyPropertyPresence", "(", "POINTS2", ")", ";", "//noinspection unchecked", "return", "(", "(", "List", "<", "Map", "<", "String", ",", "Object", ">", ">", ")", "getCommandResult", "(", ")", ".", "get", "(", "POINTS2", ")", ")", ".", "stream", "(", ")", ".", "map", "(", "ComparisonResult", "::", "mapToPoint", ")", ".", "collect", "(", "Collectors", ".", "toList", "(", ")", ")", ";", "}" ]
Returns a list of matching points on the second image. @return The list of matching points on the second image.
[ "Returns", "a", "list", "of", "matching", "points", "on", "the", "second", "image", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java#L91-L97
25,081
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java
FeaturesMatchingResult.getRect2
public Rectangle getRect2() { verifyPropertyPresence(RECT2); //noinspection unchecked return mapToRect((Map<String, Object>) getCommandResult().get(RECT2)); }
java
public Rectangle getRect2() { verifyPropertyPresence(RECT2); //noinspection unchecked return mapToRect((Map<String, Object>) getCommandResult().get(RECT2)); }
[ "public", "Rectangle", "getRect2", "(", ")", "{", "verifyPropertyPresence", "(", "RECT2", ")", ";", "//noinspection unchecked", "return", "mapToRect", "(", "(", "Map", "<", "String", ",", "Object", ">", ")", "getCommandResult", "(", ")", ".", "get", "(", "RECT2", ")", ")", ";", "}" ]
Returns a rect for the `points2` list. @return The bounding rect for the `points2` list or a zero rect if not enough matching points were found.
[ "Returns", "a", "rect", "for", "the", "points2", "list", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/FeaturesMatchingResult.java#L104-L108
25,082
appium/java-client
src/main/java/io/appium/java_client/battery/BatteryInfo.java
BatteryInfo.getLevel
public double getLevel() { final Object value = getInput().get("level"); if (value instanceof Long) { return ((Long) value).doubleValue(); } return (double) value; }
java
public double getLevel() { final Object value = getInput().get("level"); if (value instanceof Long) { return ((Long) value).doubleValue(); } return (double) value; }
[ "public", "double", "getLevel", "(", ")", "{", "final", "Object", "value", "=", "getInput", "(", ")", ".", "get", "(", "\"level\"", ")", ";", "if", "(", "value", "instanceof", "Long", ")", "{", "return", "(", "(", "Long", ")", "value", ")", ".", "doubleValue", "(", ")", ";", "}", "return", "(", "double", ")", "value", ";", "}" ]
Returns battery level. @return Battery level in range [0.0, 1.0], where 1.0 means 100% charge.
[ "Returns", "battery", "level", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/battery/BatteryInfo.java#L17-L23
25,083
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java
ComparisonResult.verifyPropertyPresence
protected void verifyPropertyPresence(String propertyName) { if (!commandResult.containsKey(propertyName)) { throw new IllegalStateException( String.format("There is no '%s' attribute in the resulting command output %s. " + "Did you set the options properly?", propertyName, commandResult)); } }
java
protected void verifyPropertyPresence(String propertyName) { if (!commandResult.containsKey(propertyName)) { throw new IllegalStateException( String.format("There is no '%s' attribute in the resulting command output %s. " + "Did you set the options properly?", propertyName, commandResult)); } }
[ "protected", "void", "verifyPropertyPresence", "(", "String", "propertyName", ")", "{", "if", "(", "!", "commandResult", ".", "containsKey", "(", "propertyName", ")", ")", "{", "throw", "new", "IllegalStateException", "(", "String", ".", "format", "(", "\"There is no '%s' attribute in the resulting command output %s. \"", "+", "\"Did you set the options properly?\"", ",", "propertyName", ",", "commandResult", ")", ")", ";", "}", "}" ]
Verifies if the corresponding property is present in the commend result and throws an exception if not. @param propertyName the actual property name to be verified for presence
[ "Verifies", "if", "the", "corresponding", "property", "is", "present", "in", "the", "commend", "result", "and", "throws", "an", "exception", "if", "not", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java#L50-L56
25,084
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java
ComparisonResult.getVisualization
public byte[] getVisualization() { verifyPropertyPresence(VISUALIZATION); return ((String) getCommandResult().get(VISUALIZATION)).getBytes(StandardCharsets.UTF_8); }
java
public byte[] getVisualization() { verifyPropertyPresence(VISUALIZATION); return ((String) getCommandResult().get(VISUALIZATION)).getBytes(StandardCharsets.UTF_8); }
[ "public", "byte", "[", "]", "getVisualization", "(", ")", "{", "verifyPropertyPresence", "(", "VISUALIZATION", ")", ";", "return", "(", "(", "String", ")", "getCommandResult", "(", ")", ".", "get", "(", "VISUALIZATION", ")", ")", ".", "getBytes", "(", "StandardCharsets", ".", "UTF_8", ")", ";", "}" ]
Returns the visualization of the matching result. @return The visualization of the matching result represented as base64-encoded PNG image.
[ "Returns", "the", "visualization", "of", "the", "matching", "result", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java#L63-L66
25,085
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java
ComparisonResult.storeVisualization
public void storeVisualization(File destination) throws IOException { final byte[] data = Base64.decodeBase64(getVisualization()); try (OutputStream stream = new FileOutputStream(destination)) { stream.write(data); } }
java
public void storeVisualization(File destination) throws IOException { final byte[] data = Base64.decodeBase64(getVisualization()); try (OutputStream stream = new FileOutputStream(destination)) { stream.write(data); } }
[ "public", "void", "storeVisualization", "(", "File", "destination", ")", "throws", "IOException", "{", "final", "byte", "[", "]", "data", "=", "Base64", ".", "decodeBase64", "(", "getVisualization", "(", ")", ")", ";", "try", "(", "OutputStream", "stream", "=", "new", "FileOutputStream", "(", "destination", ")", ")", "{", "stream", ".", "write", "(", "data", ")", ";", "}", "}" ]
Stores visualization image into the given file. @param destination file to save image.
[ "Stores", "visualization", "image", "into", "the", "given", "file", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java#L73-L78
25,086
appium/java-client
src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java
ComparisonResult.toSeleniumCoordinate
private static int toSeleniumCoordinate(Object openCVCoordinate) { if (openCVCoordinate instanceof Long) { return ((Long) openCVCoordinate).intValue(); } if (openCVCoordinate instanceof Double) { return ((Double) openCVCoordinate).intValue(); } return (int) openCVCoordinate; }
java
private static int toSeleniumCoordinate(Object openCVCoordinate) { if (openCVCoordinate instanceof Long) { return ((Long) openCVCoordinate).intValue(); } if (openCVCoordinate instanceof Double) { return ((Double) openCVCoordinate).intValue(); } return (int) openCVCoordinate; }
[ "private", "static", "int", "toSeleniumCoordinate", "(", "Object", "openCVCoordinate", ")", "{", "if", "(", "openCVCoordinate", "instanceof", "Long", ")", "{", "return", "(", "(", "Long", ")", "openCVCoordinate", ")", ".", "intValue", "(", ")", ";", "}", "if", "(", "openCVCoordinate", "instanceof", "Double", ")", "{", "return", "(", "(", "Double", ")", "openCVCoordinate", ")", ".", "intValue", "(", ")", ";", "}", "return", "(", "int", ")", "openCVCoordinate", ";", "}" ]
Converts float OpenCV coordinates to Selenium-compatible format. @param openCVCoordinate the original coordinate value @return The converted value
[ "Converts", "float", "OpenCV", "coordinates", "to", "Selenium", "-", "compatible", "format", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/imagecomparison/ComparisonResult.java#L86-L94
25,087
appium/java-client
src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java
AppiumServiceBuilder.withArgument
public AppiumServiceBuilder withArgument(ServerArgument argument, String value) { String argName = argument.getArgument().trim().toLowerCase(); if ("--port".equals(argName) || "-p".equals(argName)) { usingPort(Integer.valueOf(value)); } else if ("--address".equals(argName) || "-a".equals(argName)) { withIPAddress(value); } else if ("--log".equals(argName) || "-g".equals(argName)) { withLogFile(new File(value)); } else { serverArguments.put(argName, value); } return this; }
java
public AppiumServiceBuilder withArgument(ServerArgument argument, String value) { String argName = argument.getArgument().trim().toLowerCase(); if ("--port".equals(argName) || "-p".equals(argName)) { usingPort(Integer.valueOf(value)); } else if ("--address".equals(argName) || "-a".equals(argName)) { withIPAddress(value); } else if ("--log".equals(argName) || "-g".equals(argName)) { withLogFile(new File(value)); } else { serverArguments.put(argName, value); } return this; }
[ "public", "AppiumServiceBuilder", "withArgument", "(", "ServerArgument", "argument", ",", "String", "value", ")", "{", "String", "argName", "=", "argument", ".", "getArgument", "(", ")", ".", "trim", "(", ")", ".", "toLowerCase", "(", ")", ";", "if", "(", "\"--port\"", ".", "equals", "(", "argName", ")", "||", "\"-p\"", ".", "equals", "(", "argName", ")", ")", "{", "usingPort", "(", "Integer", ".", "valueOf", "(", "value", ")", ")", ";", "}", "else", "if", "(", "\"--address\"", ".", "equals", "(", "argName", ")", "||", "\"-a\"", ".", "equals", "(", "argName", ")", ")", "{", "withIPAddress", "(", "value", ")", ";", "}", "else", "if", "(", "\"--log\"", ".", "equals", "(", "argName", ")", "||", "\"-g\"", ".", "equals", "(", "argName", ")", ")", "{", "withLogFile", "(", "new", "File", "(", "value", ")", ")", ";", "}", "else", "{", "serverArguments", ".", "put", "(", "argName", ",", "value", ")", ";", "}", "return", "this", ";", "}" ]
Adds a server argument. @param argument is an instance which contains the argument name. @param value A non null string value. (Warn!!!) Boolean arguments have a special moment: the presence of an arguments means "true". At this case an empty string should be defined. @return the self-reference.
[ "Adds", "a", "server", "argument", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java#L265-L277
25,088
appium/java-client
src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java
AppiumServiceBuilder.withCapabilities
public AppiumServiceBuilder withCapabilities(DesiredCapabilities capabilities) { if (this.capabilities == null) { this.capabilities = capabilities; } else { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.merge(this.capabilities).merge(capabilities); this.capabilities = desiredCapabilities; } return this; }
java
public AppiumServiceBuilder withCapabilities(DesiredCapabilities capabilities) { if (this.capabilities == null) { this.capabilities = capabilities; } else { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.merge(this.capabilities).merge(capabilities); this.capabilities = desiredCapabilities; } return this; }
[ "public", "AppiumServiceBuilder", "withCapabilities", "(", "DesiredCapabilities", "capabilities", ")", "{", "if", "(", "this", ".", "capabilities", "==", "null", ")", "{", "this", ".", "capabilities", "=", "capabilities", ";", "}", "else", "{", "DesiredCapabilities", "desiredCapabilities", "=", "new", "DesiredCapabilities", "(", ")", ";", "desiredCapabilities", ".", "merge", "(", "this", ".", "capabilities", ")", ".", "merge", "(", "capabilities", ")", ";", "this", ".", "capabilities", "=", "desiredCapabilities", ";", "}", "return", "this", ";", "}" ]
Adds a desired capabilities. @param capabilities is an instance of {@link DesiredCapabilities}. @return the self-reference.
[ "Adds", "a", "desired", "capabilities", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java#L285-L294
25,089
appium/java-client
src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java
AppiumServiceBuilder.withStartUpTimeOut
public AppiumServiceBuilder withStartUpTimeOut(long time, TimeUnit timeUnit) { checkNotNull(timeUnit); checkArgument(time > 0, "Time value should be greater than zero", time); this.startupTimeout = time; this.timeUnit = timeUnit; return this; }
java
public AppiumServiceBuilder withStartUpTimeOut(long time, TimeUnit timeUnit) { checkNotNull(timeUnit); checkArgument(time > 0, "Time value should be greater than zero", time); this.startupTimeout = time; this.timeUnit = timeUnit; return this; }
[ "public", "AppiumServiceBuilder", "withStartUpTimeOut", "(", "long", "time", ",", "TimeUnit", "timeUnit", ")", "{", "checkNotNull", "(", "timeUnit", ")", ";", "checkArgument", "(", "time", ">", "0", ",", "\"Time value should be greater than zero\"", ",", "time", ")", ";", "this", ".", "startupTimeout", "=", "time", ";", "this", ".", "timeUnit", "=", "timeUnit", ";", "return", "this", ";", "}" ]
Sets start up timeout. @param time a time value for the service starting up. @param timeUnit a time unit for the service starting up. @return self-reference.
[ "Sets", "start", "up", "timeout", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/service/local/AppiumServiceBuilder.java#L320-L326
25,090
appium/java-client
src/main/java/io/appium/java_client/MobileCommand.java
MobileCommand.prepareArguments
public static ImmutableMap<String, Object> prepareArguments(String param, Object value) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); builder.put(param, value); return builder.build(); }
java
public static ImmutableMap<String, Object> prepareArguments(String param, Object value) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); builder.put(param, value); return builder.build(); }
[ "public", "static", "ImmutableMap", "<", "String", ",", "Object", ">", "prepareArguments", "(", "String", "param", ",", "Object", "value", ")", "{", "ImmutableMap", ".", "Builder", "<", "String", ",", "Object", ">", "builder", "=", "ImmutableMap", ".", "builder", "(", ")", ";", "builder", ".", "put", "(", "param", ",", "value", ")", ";", "return", "builder", ".", "build", "(", ")", ";", "}" ]
Prepares single argument. @param param is a parameter name. @param value is the parameter value. @return built {@link ImmutableMap}.
[ "Prepares", "single", "argument", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/MobileCommand.java#L342-L347
25,091
appium/java-client
src/main/java/io/appium/java_client/MobileCommand.java
MobileCommand.prepareArguments
public static ImmutableMap<String, Object> prepareArguments(String[] params, Object[] values) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (int i = 0; i < params.length; i++) { if (!StringUtils.isBlank(params[i]) && (values[i] != null)) { builder.put(params[i], values[i]); } } return builder.build(); }
java
public static ImmutableMap<String, Object> prepareArguments(String[] params, Object[] values) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (int i = 0; i < params.length; i++) { if (!StringUtils.isBlank(params[i]) && (values[i] != null)) { builder.put(params[i], values[i]); } } return builder.build(); }
[ "public", "static", "ImmutableMap", "<", "String", ",", "Object", ">", "prepareArguments", "(", "String", "[", "]", "params", ",", "Object", "[", "]", "values", ")", "{", "ImmutableMap", ".", "Builder", "<", "String", ",", "Object", ">", "builder", "=", "ImmutableMap", ".", "builder", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "params", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "StringUtils", ".", "isBlank", "(", "params", "[", "i", "]", ")", "&&", "(", "values", "[", "i", "]", "!=", "null", ")", ")", "{", "builder", ".", "put", "(", "params", "[", "i", "]", ",", "values", "[", "i", "]", ")", ";", "}", "}", "return", "builder", ".", "build", "(", ")", ";", "}" ]
Prepares collection of arguments. @param params is the array with parameter names. @param values is the array with parameter values. @return built {@link ImmutableMap}.
[ "Prepares", "collection", "of", "arguments", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/MobileCommand.java#L356-L365
25,092
appium/java-client
src/main/java/io/appium/java_client/TouchAction.java
TouchAction.moveTo
public T moveTo(PointOption moveToOptions) { ActionParameter action = new ActionParameter("moveTo", moveToOptions); parameterBuilder.add(action); return (T) this; }
java
public T moveTo(PointOption moveToOptions) { ActionParameter action = new ActionParameter("moveTo", moveToOptions); parameterBuilder.add(action); return (T) this; }
[ "public", "T", "moveTo", "(", "PointOption", "moveToOptions", ")", "{", "ActionParameter", "action", "=", "new", "ActionParameter", "(", "\"moveTo\"", ",", "moveToOptions", ")", ";", "parameterBuilder", ".", "add", "(", "action", ")", ";", "return", "(", "T", ")", "this", ";", "}" ]
Moves current touch to a new position. @param moveToOptions see {@link PointOption} and {@link ElementOption} Important: some older Appium drivers releases have a bug when moveTo coordinates are calculated as relative to the recent pointer position in the chain instead of being absolute. @see <a href="https://github.com/appium/appium/issues/7486">Appium Issue #7486 for more details.</a> @return this TouchAction, for chaining.
[ "Moves", "current", "touch", "to", "a", "new", "position", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/TouchAction.java#L91-L95
25,093
appium/java-client
src/main/java/io/appium/java_client/TouchAction.java
TouchAction.tap
public T tap(TapOptions tapOptions) { ActionParameter action = new ActionParameter("tap", tapOptions); parameterBuilder.add(action); return (T) this; }
java
public T tap(TapOptions tapOptions) { ActionParameter action = new ActionParameter("tap", tapOptions); parameterBuilder.add(action); return (T) this; }
[ "public", "T", "tap", "(", "TapOptions", "tapOptions", ")", "{", "ActionParameter", "action", "=", "new", "ActionParameter", "(", "\"tap\"", ",", "tapOptions", ")", ";", "parameterBuilder", ".", "add", "(", "action", ")", ";", "return", "(", "T", ")", "this", ";", "}" ]
Tap on an element. @param tapOptions see {@link TapOptions}. @return this TouchAction, for chaining.
[ "Tap", "on", "an", "element", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/TouchAction.java#L103-L107
25,094
appium/java-client
src/main/java/io/appium/java_client/TouchAction.java
TouchAction.tap
public T tap(PointOption tapOptions) { ActionParameter action = new ActionParameter("tap", tapOptions); parameterBuilder.add(action); return (T) this; }
java
public T tap(PointOption tapOptions) { ActionParameter action = new ActionParameter("tap", tapOptions); parameterBuilder.add(action); return (T) this; }
[ "public", "T", "tap", "(", "PointOption", "tapOptions", ")", "{", "ActionParameter", "action", "=", "new", "ActionParameter", "(", "\"tap\"", ",", "tapOptions", ")", ";", "parameterBuilder", ".", "add", "(", "action", ")", ";", "return", "(", "T", ")", "this", ";", "}" ]
Tap on a position. @param tapOptions see {@link PointOption} and {@link ElementOption} @return this TouchAction, for chaining.
[ "Tap", "on", "a", "position", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/TouchAction.java#L115-L119
25,095
appium/java-client
src/main/java/io/appium/java_client/TouchAction.java
TouchAction.waitAction
public T waitAction(WaitOptions waitOptions) { ActionParameter action = new ActionParameter("wait", waitOptions); parameterBuilder.add(action); //noinspection unchecked return (T) this; }
java
public T waitAction(WaitOptions waitOptions) { ActionParameter action = new ActionParameter("wait", waitOptions); parameterBuilder.add(action); //noinspection unchecked return (T) this; }
[ "public", "T", "waitAction", "(", "WaitOptions", "waitOptions", ")", "{", "ActionParameter", "action", "=", "new", "ActionParameter", "(", "\"wait\"", ",", "waitOptions", ")", ";", "parameterBuilder", ".", "add", "(", "action", ")", ";", "//noinspection unchecked", "return", "(", "T", ")", "this", ";", "}" ]
Waits for specified amount of time to pass before continue to next touch action. @param waitOptions see {@link WaitOptions}. @return this TouchAction, for chaining.
[ "Waits", "for", "specified", "amount", "of", "time", "to", "pass", "before", "continue", "to", "next", "touch", "action", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/TouchAction.java#L139-L144
25,096
appium/java-client
src/main/java/io/appium/java_client/TouchAction.java
TouchAction.getParameters
protected Map<String, List<Object>> getParameters() { List<ActionParameter> actionList = parameterBuilder.build(); return ImmutableMap.of("actions", actionList.stream() .map(ActionParameter::getParameterMap).collect(toList())); }
java
protected Map<String, List<Object>> getParameters() { List<ActionParameter> actionList = parameterBuilder.build(); return ImmutableMap.of("actions", actionList.stream() .map(ActionParameter::getParameterMap).collect(toList())); }
[ "protected", "Map", "<", "String", ",", "List", "<", "Object", ">", ">", "getParameters", "(", ")", "{", "List", "<", "ActionParameter", ">", "actionList", "=", "parameterBuilder", ".", "build", "(", ")", ";", "return", "ImmutableMap", ".", "of", "(", "\"actions\"", ",", "actionList", ".", "stream", "(", ")", ".", "map", "(", "ActionParameter", "::", "getParameterMap", ")", ".", "collect", "(", "toList", "(", ")", ")", ")", ";", "}" ]
Get the mjsonwp parameters for this Action. @return A map of parameters for this touch action to pass as part of mjsonwp.
[ "Get", "the", "mjsonwp", "parameters", "for", "this", "Action", "." ]
5a17759b05d6fda8ef425b3ab6e766c73ed2e8df
https://github.com/appium/java-client/blob/5a17759b05d6fda8ef425b3ab6e766c73ed2e8df/src/main/java/io/appium/java_client/TouchAction.java#L197-L201
25,097
gatling/gatling
gatling-http-client/src/main/java/io/gatling/http/client/util/HttpUtils.java
HttpUtils.computeMultipartBoundary
public static byte[] computeMultipartBoundary() { ThreadLocalRandom random = ThreadLocalRandom.current(); byte[] bytes = new byte[35]; for (int i = 0; i < bytes.length; i++) { bytes[i] = MULTIPART_CHARS[random.nextInt(MULTIPART_CHARS.length)]; } return bytes; }
java
public static byte[] computeMultipartBoundary() { ThreadLocalRandom random = ThreadLocalRandom.current(); byte[] bytes = new byte[35]; for (int i = 0; i < bytes.length; i++) { bytes[i] = MULTIPART_CHARS[random.nextInt(MULTIPART_CHARS.length)]; } return bytes; }
[ "public", "static", "byte", "[", "]", "computeMultipartBoundary", "(", ")", "{", "ThreadLocalRandom", "random", "=", "ThreadLocalRandom", ".", "current", "(", ")", ";", "byte", "[", "]", "bytes", "=", "new", "byte", "[", "35", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "bytes", ".", "length", ";", "i", "++", ")", "{", "bytes", "[", "i", "]", "=", "MULTIPART_CHARS", "[", "random", ".", "nextInt", "(", "MULTIPART_CHARS", ".", "length", ")", "]", ";", "}", "return", "bytes", ";", "}" ]
a fixed size of 35
[ "a", "fixed", "size", "of", "35" ]
7652b6ad8e661e8aef102f405b32c11a58d88b2c
https://github.com/gatling/gatling/blob/7652b6ad8e661e8aef102f405b32c11a58d88b2c/gatling-http-client/src/main/java/io/gatling/http/client/util/HttpUtils.java#L122-L129
25,098
AltBeacon/android-beacon-library
lib/src/main/java/org/altbeacon/beacon/service/ScanJobScheduler.java
ScanJobScheduler.scheduleAfterBackgroundWakeup
public void scheduleAfterBackgroundWakeup(Context context, List<ScanResult> scanResults) { if (scanResults != null) { mBackgroundScanResultQueue.addAll(scanResults); } synchronized (this) { // We typically get a bunch of calls in a row here, separated by a few millis. Only do this once. if (System.currentTimeMillis() - mScanJobScheduleTime > MIN_MILLIS_BETWEEN_SCAN_JOB_SCHEDULING) { LogManager.d(TAG, "scheduling an immediate scan job because last did "+(System.currentTimeMillis() - mScanJobScheduleTime)+"seconds ago."); mScanJobScheduleTime = System.currentTimeMillis(); } else { LogManager.d(TAG, "Not scheduling an immediate scan job because we just did recently."); return; } } ScanState scanState = ScanState.restore(context); schedule(context, scanState, true); }
java
public void scheduleAfterBackgroundWakeup(Context context, List<ScanResult> scanResults) { if (scanResults != null) { mBackgroundScanResultQueue.addAll(scanResults); } synchronized (this) { // We typically get a bunch of calls in a row here, separated by a few millis. Only do this once. if (System.currentTimeMillis() - mScanJobScheduleTime > MIN_MILLIS_BETWEEN_SCAN_JOB_SCHEDULING) { LogManager.d(TAG, "scheduling an immediate scan job because last did "+(System.currentTimeMillis() - mScanJobScheduleTime)+"seconds ago."); mScanJobScheduleTime = System.currentTimeMillis(); } else { LogManager.d(TAG, "Not scheduling an immediate scan job because we just did recently."); return; } } ScanState scanState = ScanState.restore(context); schedule(context, scanState, true); }
[ "public", "void", "scheduleAfterBackgroundWakeup", "(", "Context", "context", ",", "List", "<", "ScanResult", ">", "scanResults", ")", "{", "if", "(", "scanResults", "!=", "null", ")", "{", "mBackgroundScanResultQueue", ".", "addAll", "(", "scanResults", ")", ";", "}", "synchronized", "(", "this", ")", "{", "// We typically get a bunch of calls in a row here, separated by a few millis. Only do this once.", "if", "(", "System", ".", "currentTimeMillis", "(", ")", "-", "mScanJobScheduleTime", ">", "MIN_MILLIS_BETWEEN_SCAN_JOB_SCHEDULING", ")", "{", "LogManager", ".", "d", "(", "TAG", ",", "\"scheduling an immediate scan job because last did \"", "+", "(", "System", ".", "currentTimeMillis", "(", ")", "-", "mScanJobScheduleTime", ")", "+", "\"seconds ago.\"", ")", ";", "mScanJobScheduleTime", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "}", "else", "{", "LogManager", ".", "d", "(", "TAG", ",", "\"Not scheduling an immediate scan job because we just did recently.\"", ")", ";", "return", ";", "}", "}", "ScanState", "scanState", "=", "ScanState", ".", "restore", "(", "context", ")", ";", "schedule", "(", "context", ",", "scanState", ",", "true", ")", ";", "}" ]
must exist on another branch until the SDKs are released.
[ "must", "exist", "on", "another", "branch", "until", "the", "SDKs", "are", "released", "." ]
f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3
https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/ScanJobScheduler.java#L107-L124
25,099
AltBeacon/android-beacon-library
lib/src/main/java/org/altbeacon/bluetooth/BluetoothMedic.java
BluetoothMedic.enablePowerCycleOnFailures
@SuppressWarnings("unused") @RequiresApi(21) public void enablePowerCycleOnFailures(Context context) { initializeWithContext(context); if (this.mLocalBroadcastManager != null) { this.mLocalBroadcastManager.registerReceiver(this.mBluetoothEventReceiver, new IntentFilter("onScanFailed")); this.mLocalBroadcastManager.registerReceiver(this.mBluetoothEventReceiver, new IntentFilter("onStartFailure")); LogManager.d(TAG, "Medic monitoring for transmission and scan failure notifications with receiver: " + this.mBluetoothEventReceiver); } }
java
@SuppressWarnings("unused") @RequiresApi(21) public void enablePowerCycleOnFailures(Context context) { initializeWithContext(context); if (this.mLocalBroadcastManager != null) { this.mLocalBroadcastManager.registerReceiver(this.mBluetoothEventReceiver, new IntentFilter("onScanFailed")); this.mLocalBroadcastManager.registerReceiver(this.mBluetoothEventReceiver, new IntentFilter("onStartFailure")); LogManager.d(TAG, "Medic monitoring for transmission and scan failure notifications with receiver: " + this.mBluetoothEventReceiver); } }
[ "@", "SuppressWarnings", "(", "\"unused\"", ")", "@", "RequiresApi", "(", "21", ")", "public", "void", "enablePowerCycleOnFailures", "(", "Context", "context", ")", "{", "initializeWithContext", "(", "context", ")", ";", "if", "(", "this", ".", "mLocalBroadcastManager", "!=", "null", ")", "{", "this", ".", "mLocalBroadcastManager", ".", "registerReceiver", "(", "this", ".", "mBluetoothEventReceiver", ",", "new", "IntentFilter", "(", "\"onScanFailed\"", ")", ")", ";", "this", ".", "mLocalBroadcastManager", ".", "registerReceiver", "(", "this", ".", "mBluetoothEventReceiver", ",", "new", "IntentFilter", "(", "\"onStartFailure\"", ")", ")", ";", "LogManager", ".", "d", "(", "TAG", ",", "\"Medic monitoring for transmission and scan failure notifications with receiver: \"", "+", "this", ".", "mBluetoothEventReceiver", ")", ";", "}", "}" ]
If set to true, bluetooth will be power cycled on any tests run that determine bluetooth is in a bad state. @param context
[ "If", "set", "to", "true", "bluetooth", "will", "be", "power", "cycled", "on", "any", "tests", "run", "that", "determine", "bluetooth", "is", "in", "a", "bad", "state", "." ]
f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3
https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/bluetooth/BluetoothMedic.java#L170-L183