本文整理汇总了Java中com.google.javascript.rhino.InputId类的典型用法代码示例。如果您正苦于以下问题:Java InputId类的具体用法?Java InputId怎么用?Java InputId使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InputId类属于com.google.javascript.rhino包,在下文中一共展示了InputId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateGlobalVarReferences
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
/**
* Updates the internal reference map based on the provided parameters. If
* {@code scriptRoot} is not SCRIPT, it basically replaces the internal map
* with the new one, otherwise it replaces all the information associated to
* the given script.
*
* @param refMapPatch The reference map result of a
* {@link ReferenceCollectingCallback} pass which might be collected from
* the whole AST or just a sub-tree associated to a SCRIPT node.
* @param root AST sub-tree root on which reference collection was done.
*/
void updateGlobalVarReferences(Map<Var, ReferenceCollection>
refMapPatch, Node root) {
if (refMap == null || !root.isScript()) {
resetGlobalVarReferences(refMapPatch);
return;
}
InputId inputId = root.getInputId();
Preconditions.checkNotNull(inputId);
// Note there are two assumptions here (i) the order of compiler inputs
// has not changed and (ii) all references are in the order they appear
// in AST (this is enforced in ReferenceCollectionCallback).
removeScriptReferences(inputId);
for (Entry<Var, ReferenceCollection> entry : refMapPatch.entrySet()) {
Var var = entry.getKey();
if (var.isGlobal()) {
replaceReferences(var.getName(), inputId, entry.getValue());
}
}
}
示例2: removeScriptReferences
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
private void removeScriptReferences(InputId inputId) {
Preconditions.checkNotNull(inputId);
if (!inputOrder.containsKey(inputId)) {
return; // Input did not exist when last computed, so skip
}
// TODO(bashir): If this is too slow it is not too difficult to make it
// faster with keeping an index for variables accessed in sourceName.
for (ReferenceCollection collection : refMap.values()) {
if (collection == null) {
continue;
}
List<Reference> oldRefs = collection.references;
SourceRefRange range = findSourceRefRange(oldRefs, inputId);
List<Reference> newRefs = Lists.newArrayList(range.refsBefore());
newRefs.addAll(range.refsAfter());
collection.references = newRefs;
}
}
示例3: replaceReferences
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
private void replaceReferences(String varName, InputId inputId,
ReferenceCollection newSourceCollection) {
ReferenceCollection combined = new ReferenceCollection();
List<Reference> combinedRefs = combined.references;
ReferenceCollection oldCollection = refMap.get(varName);
refMap.put(varName, combined);
if (oldCollection == null) {
combinedRefs.addAll(newSourceCollection.references);
return;
}
// otherwise replace previous references that are from sourceName
SourceRefRange range = findSourceRefRange(oldCollection.references,
inputId);
combinedRefs.addAll(range.refsBefore());
combinedRefs.addAll(newSourceCollection.references);
combinedRefs.addAll(range.refsAfter());
}
示例4: findSourceRefRange
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
/**
* Finds the range of references associated to {@code sourceName}. Note that
* even if there is no sourceName references the returned information can be
* used to decide where to insert new sourceName refs.
*/
private SourceRefRange findSourceRefRange(List<Reference> refList,
InputId inputId) {
Preconditions.checkNotNull(inputId);
// TODO(bashir): We can do binary search here, but since this is fast enough
// right now, we just do a linear search for simplicity.
int lastBefore = -1;
int firstAfter = refList.size();
int index = 0;
Preconditions.checkState(inputOrder.containsKey(inputId), inputId.getIdName());
int sourceInputOrder = inputOrder.get(inputId);
for (Reference ref : refList) {
Preconditions.checkNotNull(ref.getInputId());
int order = inputOrder.get(ref.getInputId());
if (order < sourceInputOrder) {
lastBefore = index;
} else if (order > sourceInputOrder) {
firstAfter = index;
break;
}
index++;
}
return new SourceRefRange(refList, lastBefore, firstAfter);
}
示例5: computeLiveness
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
private static LiveVariablesAnalysis computeLiveness(String src) {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setCodingConvention(new GoogleCodingConvention());
compiler.initOptions(options);
src = "function _FUNCTION(param1, param2){" + src + "}";
Node n = compiler.parseTestCode(src).removeFirstChild();
Node script = new Node(Token.SCRIPT, n);
script.setInputId(new InputId("test"));
assertEquals(0, compiler.getErrorCount());
Scope scope = new SyntacticScopeCreator(compiler).createScope(
n, Scope.createGlobalScope(script));
ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false, true);
cfa.process(null, n);
ControlFlowGraph<Node> cfg = cfa.getCfg();
LiveVariablesAnalysis analysis =
new LiveVariablesAnalysis(cfg, scope, compiler);
analysis.analyze();
return analysis;
}
示例6: parseAndTypeCheckWithScope
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
private TypeCheckResult parseAndTypeCheckWithScope(
String externs, String js) {
compiler.init(
Lists.newArrayList(SourceFile.fromCode("[externs]", externs)),
Lists.newArrayList(SourceFile.fromCode("[testcode]", js)),
compiler.getOptions());
Node n = compiler.getInput(new InputId("[testcode]")).getAstRoot(compiler);
Node externsNode = compiler.getInput(new InputId("[externs]"))
.getAstRoot(compiler);
Node externAndJsRoot = new Node(Token.BLOCK, externsNode, n);
externAndJsRoot.setIsSyntheticBlock(true);
assertEquals("parsing error: " +
Joiner.on(", ").join(compiler.getErrors()),
0, compiler.getErrorCount());
Scope s = makeTypeCheck().processForTesting(externsNode, n);
return new TypeCheckResult(n, s);
}
示例7: parse
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
Node parse(String js, boolean checkTypes) {
Compiler compiler = new Compiler();
CompilerOptions options = new CompilerOptions();
options.setTrustedStrings(trustedStrings);
// Allow getters and setters.
options.setLanguageIn(LanguageMode.ECMASCRIPT5);
compiler.initOptions(options);
Node n = compiler.parseTestCode(js);
if (checkTypes) {
DefaultPassConfig passConfig = new DefaultPassConfig(null);
CompilerPass typeResolver = passConfig.resolveTypes.create(compiler);
Node externs = new Node(Token.SCRIPT);
externs.setInputId(new InputId("externs"));
Node externAndJsRoot = new Node(Token.BLOCK, externs, n);
externAndJsRoot.setIsSyntheticBlock(true);
typeResolver.process(externs, n);
CompilerPass inferTypes = passConfig.inferTypes.create(compiler);
inferTypes.process(externs, n);
}
checkUnexpectedErrorsOrWarnings(compiler, 0);
return n;
}
示例8: getSourceFileByName
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
@Override
SourceFile getSourceFileByName(String sourceName) {
// Here we assume that the source name is the input name, this
// is true of JavaScript parsed from source.
if (sourceName != null) {
CompilerInput input = inputsById.get(new InputId(sourceName));
if (input != null) {
return input.getSourceFile();
}
// Alternatively, the sourceName might have been reverse-mapped by
// an input source-map, so let's look in our sourcemap original sources.
return sourceMapOriginalSources.get(sourceName);
}
return null;
}
示例9: updateGlobalVarReferences
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
/**
* Updates the internal reference map based on the provided parameters. If
* {@code scriptRoot} is not SCRIPT, it basically replaces the internal map
* with the new one, otherwise it replaces all the information associated to
* the given script.
*
* @param refMapPatch The reference map result of a
* {@link ReferenceCollectingCallback} pass which might be collected from
* the whole AST or just a sub-tree associated to a SCRIPT node.
* @param root AST sub-tree root on which reference collection was done.
*/
void updateGlobalVarReferences(Map<Var, ReferenceCollection>
refMapPatch, Node root) {
if (refMap == null || !root.isScript()) {
resetGlobalVarReferences(refMapPatch);
return;
}
InputId inputId = root.getInputId();
checkNotNull(inputId);
// Note there are two assumptions here (i) the order of compiler inputs
// has not changed and (ii) all references are in the order they appear
// in AST (this is enforced in ReferenceCollectionCallback).
removeScriptReferences(inputId);
for (Entry<Var, ReferenceCollection> entry : refMapPatch.entrySet()) {
Var var = entry.getKey();
if (var.isGlobal()) {
replaceReferences(var.getName(), inputId, entry.getValue());
}
}
}
示例10: removeScriptReferences
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
private void removeScriptReferences(InputId inputId) {
checkNotNull(inputId);
if (!inputOrder.containsKey(inputId)) {
return; // Input did not exist when last computed, so skip
}
// TODO(bashir): If this is too slow it is not too difficult to make it
// faster with keeping an index for variables accessed in sourceName.
for (ReferenceCollection collection : refMap.values()) {
if (collection == null) {
continue;
}
List<Reference> oldRefs = collection.references;
SourceRefRange range = findSourceRefRange(oldRefs, inputId);
List<Reference> newRefs = new ArrayList<>(range.refsBefore());
newRefs.addAll(range.refsAfter());
collection.references = newRefs;
}
}
示例11: findSourceRefRange
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
/**
* Finds the range of references associated to {@code sourceName}. Note that
* even if there is no sourceName references the returned information can be
* used to decide where to insert new sourceName refs.
*/
private SourceRefRange findSourceRefRange(List<Reference> refList,
InputId inputId) {
checkNotNull(inputId);
// TODO(bashir): We can do binary search here, but since this is fast enough
// right now, we just do a linear search for simplicity.
int lastBefore = -1;
int firstAfter = refList.size();
int index = 0;
checkState(inputOrder.containsKey(inputId), inputId.getIdName());
int sourceInputOrder = inputOrder.get(inputId);
for (Reference ref : refList) {
checkNotNull(ref.getInputId());
int order = inputOrder.get(ref.getInputId());
if (order < sourceInputOrder) {
lastBefore = index;
} else if (order > sourceInputOrder) {
firstAfter = index;
break;
}
index++;
}
return new SourceRefRange(refList, lastBefore, firstAfter);
}
示例12: testInferWithModules
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
public void testInferWithModules() {
CompilerOptions options = getOptions();
Compiler compiler = new Compiler();
List<SourceFile> inputs = ImmutableList.of(
SourceFile.fromCode("in", ""));
Result result = compiler.compile(EXTVAR_EXTERNS, inputs, options);
assertTrue(result.success);
CompilerInput oldInput = compiler.getInput(new InputId("in"));
JSModule myModule = oldInput.getModule();
assertThat(myModule.getInputs()).hasSize(1);
SourceFile newSource = SourceFile.fromCode("in", "var x;");
JsAst ast = new JsAst(newSource);
compiler.replaceScript(ast);
assertThat(myModule.getInputs()).hasSize(1);
assertThat(myModule.getInputs()).doesNotContain(oldInput);
assertThat(myModule.getInputs()).containsExactly(compiler.getInput(new InputId("in")));
}
示例13: generate
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
@Override
public Node generate(int budget, Set<Type> types) {
int numElements = generateLength(budget - 1);
Node script;
if (numElements > 0) {
SourceElementFuzzer[] fuzzers = new SourceElementFuzzer[numElements];
Arrays.fill(
fuzzers,
new SourceElementFuzzer(context));
Node[] elements = distribute(budget - 1, fuzzers);
script = new Node(Token.SCRIPT, elements);
} else {
script = new Node(Token.SCRIPT);
}
InputId inputId = new InputId("fuzzedInput");
script.setInputId(inputId);
script.setSourceFileForTesting(inputId.getIdName());
return script;
}
示例14: parseAndTypeCheck
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
private NewTypeInference parseAndTypeCheck(String externs, String js) {
setUp();
compiler.init(
Lists.newArrayList(SourceFile.fromCode("[externs]", externs)),
Lists.newArrayList(SourceFile.fromCode("[testcode]", js)),
compiler.getOptions());
Node externsRoot =
compiler.getInput(new InputId("[externs]")).getAstRoot(compiler);
Node astRoot =
compiler.getInput(new InputId("[testcode]")).getAstRoot(compiler);
assertEquals("parsing error: " +
Joiner.on(", ").join(compiler.getErrors()),
0, compiler.getErrorCount());
assertEquals("parsing warning: " +
Joiner.on(", ").join(compiler.getWarnings()),
0, compiler.getWarningCount());
GlobalTypeInfo symbolTable = new GlobalTypeInfo(compiler);
symbolTable.process(externsRoot, astRoot);
compiler.setSymbolTable(symbolTable);
NewTypeInference typeInf = new NewTypeInference(compiler);
typeInf.process(externsRoot, astRoot);
return typeInf;
}
示例15: parse
import com.google.javascript.rhino.InputId; //导入依赖的package包/类
Node parse(String js, boolean checkTypes) {
Compiler compiler = new Compiler();
lastCompiler = compiler;
CompilerOptions options = new CompilerOptions();
options.setTrustedStrings(trustedStrings);
// Allow getters and setters.
options.setLanguageIn(languageMode);
compiler.initOptions(options);
Node n = compiler.parseTestCode(js);
if (checkTypes) {
DefaultPassConfig passConfig = new DefaultPassConfig(null);
CompilerPass typeResolver = passConfig.resolveTypes.create(compiler);
Node externs = new Node(Token.SCRIPT);
externs.setInputId(new InputId("externs"));
Node externAndJsRoot = new Node(Token.BLOCK, externs, n);
externAndJsRoot.setIsSyntheticBlock(true);
typeResolver.process(externs, n);
CompilerPass inferTypes = passConfig.inferTypes.create(compiler);
inferTypes.process(externs, n);
}
checkUnexpectedErrorsOrWarnings(compiler, 0);
return n;
}