本文整理汇总了Java中com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior类的典型用法代码示例。如果您正苦于以下问题:Java Behavior类的具体用法?Java Behavior怎么用?Java Behavior使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Behavior类属于com.google.javascript.jscomp.ReferenceCollectingCallback包,在下文中一共展示了Behavior类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testVarInBlock_oldScopeCreator
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testVarInBlock_oldScopeCreator() {
es6ScopeCreator = false;
testBehavior(
lines(
"function f(x) {",
" if (true) {",
" var y = x;",
" y;",
" y;",
" }",
"}"),
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isFunctionScope()) {
ReferenceCollection y = rm.getReferences(t.getScope().getVar("y"));
assertThat(y.isAssignedOnceInLifetime()).isTrue();
assertThat(y.isWellDefined()).isTrue();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:ReferenceCollectingCallbackTest.java
示例2: testVarInBlock
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testVarInBlock() {
testBehavior(
lines(
"function f(x) {",
" if (true) {",
" var y = x;",
" y;",
" y;",
" }",
"}"),
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isBlockScope() && t.getScope().getParent().isFunctionBlockScope()) {
ReferenceCollection y = rm.getReferences(t.getScope().getVar("y"));
assertThat(y.isAssignedOnceInLifetime()).isTrue();
assertThat(y.isWellDefined()).isTrue();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:ReferenceCollectingCallbackTest.java
示例3: testLetAssignedOnceInLifetime1
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testLetAssignedOnceInLifetime1() {
testBehavior(
lines(
"try {",
"} catch (e) {",
" let y = e;",
" g();",
" y;y;",
"}"),
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isCatchScope()) {
ReferenceCollection e = rm.getReferences(t.getScope().getVar("e"));
assertThat(e.isAssignedOnceInLifetime()).isTrue();
ReferenceCollection y = rm.getReferences(t.getScope().getVar("y"));
assertThat(y.isAssignedOnceInLifetime()).isTrue();
assertThat(y.isWellDefined()).isTrue();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:ReferenceCollectingCallbackTest.java
示例4: testLetAssignedOnceInLifetime2
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testLetAssignedOnceInLifetime2() {
testBehavior(
lines(
"try {",
"} catch (e) {",
" let y; y = e;",
" g();",
" y;y;",
"}"),
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isCatchScope()) {
ReferenceCollection e = rm.getReferences(t.getScope().getVar("e"));
assertThat(e.isAssignedOnceInLifetime()).isTrue();
ReferenceCollection y = rm.getReferences(t.getScope().getVar("y"));
assertThat(y.isAssignedOnceInLifetime()).isTrue();
assertThat(y.isWellDefined()).isTrue();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:ReferenceCollectingCallbackTest.java
示例5: testBasicBlocks
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
private void testBasicBlocks(boolean scopeCreator) {
es6ScopeCreator = scopeCreator;
testBehavior(
lines(
"var x = 0;",
"switch (x) {",
" case 0:",
" x;",
"}"),
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isGlobal()) {
ReferenceCollection x = rm.getReferences(t.getScope().getVar("x"));
assertThat(x.references).hasSize(3);
assertNode(x.references.get(0).getBasicBlock().getRoot()).hasType(Token.ROOT);
assertNode(x.references.get(1).getBasicBlock().getRoot()).hasType(Token.ROOT);
assertNode(x.references.get(2).getBasicBlock().getRoot()).hasType(Token.CASE);
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:ReferenceCollectingCallbackTest.java
示例6: testThis
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testThis() {
testBehavior(
lines(
"/** @constructor */",
"function C() {}",
"",
"C.prototype.m = function m() {",
" var self = this;",
" if (true) {",
" alert(self);",
" }",
"};"),
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isFunctionBlockScope()
&& t.getScopeRoot().getParent().getFirstChild().matchesQualifiedName("m")) {
ReferenceCollection self = rm.getReferences(t.getScope().getVar("self"));
assertThat(self.isEscaped()).isFalse();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:24,代码来源:ReferenceCollectingCallbackTest.java
示例7: testThis_oldScopeCreator
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testThis_oldScopeCreator() {
es6ScopeCreator = false;
testBehavior(
lines(
"/** @constructor */",
"function C() {}",
"",
"C.prototype.m = function m() {",
" var self = this;",
" if (true) {",
" alert(self);",
" }",
"};"),
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isFunctionBlockScope()
&& t.getScopeRoot().getParent().getFirstChild().matchesQualifiedName("m")) {
ReferenceCollection self = rm.getReferences(t.getScope().getVar("self"));
assertThat(self.isEscaped()).isFalse();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:25,代码来源:ReferenceCollectingCallbackTest.java
示例8: testVarInLoopNotAssignedOnlyOnceInLifetime
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testVarInLoopNotAssignedOnlyOnceInLifetime() {
Behavior behavior =
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isBlockScope()) {
ReferenceCollection x = rm.getReferences(t.getScope().getVar("x"));
assertThat(x.isAssignedOnceInLifetime()).isFalse();
}
}
};
testBehavior("while (true) { var x = 0; }", behavior);
testBehavior("while (true) { let x = 0; }", behavior);
}
开发者ID:google,项目名称:closure-compiler,代码行数:15,代码来源:ReferenceCollectingCallbackTest.java
示例9: testVarInFunctionNotAssignedOnlyOnceInLifetime
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
/**
* Although there is only one assignment to x in the code, it's in a function which could be
* called multiple times, so {@code isAssignedOnceInLifetime()} returns false.
*/
public void testVarInFunctionNotAssignedOnlyOnceInLifetime() {
Behavior behavior =
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isGlobal()) {
ReferenceCollection x = rm.getReferences(t.getScope().getVar("x"));
assertThat(x.isAssignedOnceInLifetime()).isFalse();
}
}
};
testBehavior("var x; function f() { x = 0; }", behavior);
testBehavior("let x; function f() { x = 0; }", behavior);
}
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:ReferenceCollectingCallbackTest.java
示例10: testParameterAssignedOnlyOnceInLifetime
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testParameterAssignedOnlyOnceInLifetime() {
testBehavior(
"function f(x) { x; }",
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isFunctionScope()) {
ReferenceCollection x = rm.getReferences(t.getScope().getVar("x"));
assertThat(x.isAssignedOnceInLifetime()).isTrue();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:14,代码来源:ReferenceCollectingCallbackTest.java
示例11: testModifiedParameterNotAssignedOnlyOnceInLifetime
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testModifiedParameterNotAssignedOnlyOnceInLifetime() {
testBehavior(
"function f(x) { x = 3; }",
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isFunctionScope()) {
ReferenceCollection x = rm.getReferences(t.getScope().getVar("x"));
assertThat(x.isAssignedOnceInLifetime()).isFalse();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:14,代码来源:ReferenceCollectingCallbackTest.java
示例12: testVarAssignedOnceInLifetime1
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testVarAssignedOnceInLifetime1() {
Behavior behavior =
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isFunctionBlockScope()) {
ReferenceCollection x = rm.getReferences(t.getScope().getVar("x"));
assertThat(x.isAssignedOnceInLifetime()).isTrue();
}
}
};
testBehavior("function f() { var x = 0; }", behavior);
testBehavior("function f() { let x = 0; }", behavior);
}
开发者ID:google,项目名称:closure-compiler,代码行数:15,代码来源:ReferenceCollectingCallbackTest.java
示例13: testVarAssignedOnceInLifetime2
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testVarAssignedOnceInLifetime2() {
testBehavior(
"function f() { { let x = 0; } }",
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isBlockScope() && !t.getScope().isFunctionBlockScope()) {
ReferenceCollection x = rm.getReferences(t.getScope().getVar("x"));
assertThat(x.isAssignedOnceInLifetime()).isTrue();
}
}
});
}
开发者ID:google,项目名称:closure-compiler,代码行数:14,代码来源:ReferenceCollectingCallbackTest.java
示例14: testVarAssignedOnceInLifetime3
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testVarAssignedOnceInLifetime3() {
Behavior behavior =
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
if (t.getScope().isCatchScope()) {
ReferenceCollection e = rm.getReferences(t.getScope().getVar("e"));
assertThat(e.isAssignedOnceInLifetime()).isTrue();
ReferenceCollection y = rm.getReferences(t.getScope().getVar("y"));
assertThat(y.isAssignedOnceInLifetime()).isTrue();
assertThat(y.isWellDefined()).isTrue();
}
}
};
testBehavior(
lines(
"try {",
"} catch (e) {",
" var y = e;",
" g();",
" y;y;",
"}"),
behavior);
testBehavior(
lines(
"try {",
"} catch (e) {",
" var y; y = e;",
" g();",
" y;y;",
"}"),
behavior);
}
开发者ID:google,项目名称:closure-compiler,代码行数:34,代码来源:ReferenceCollectingCallbackTest.java
示例15: testProcessScopeThatsNotABasicBlock
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
public void testProcessScopeThatsNotABasicBlock() {
// Tests the case where the scope we pass in is not really a basic block, but we create a new
// basic block anyway because ReferenceCollectingCallback expects all nodes to be in a block.
Compiler compiler = createCompiler();
Es6SyntacticScopeCreator es6SyntacticScopeCreator = new Es6SyntacticScopeCreator(compiler);
ReferenceCollectingCallback referenceCollectingCallback =
new ReferenceCollectingCallback(
compiler,
new Behavior() {
@Override
public void afterExitScope(NodeTraversal t, ReferenceMap rm) {
ReferenceCollection y = rm.getReferences(t.getScope().getVar("y"));
assertThat(y.isWellDefined()).isTrue();
BasicBlock firstBasicBlock = y.references.get(0).getBasicBlock();
assertNode(firstBasicBlock.getRoot()).hasType(Token.BLOCK);
assertNode(firstBasicBlock.getRoot().getParent()).hasType(Token.SCRIPT);
// We do not create a new BasicBlock for the second { use(y); }
BasicBlock secondBasicBlock = y.references.get(1).getBasicBlock();
assertNode(secondBasicBlock.getRoot()).hasType(Token.BLOCK);
assertNode(secondBasicBlock.getRoot().getParent()).hasType(Token.IF);
}
},
es6SyntacticScopeCreator);
String js = "let x = 5; { let y = x + 1; if (true) { { use(y); } } }";
Node root = compiler.parseTestCode(js);
Node block = root.getSecondChild();
Scope globalScope = es6SyntacticScopeCreator.createScope(root, null);
Scope blockScope = es6SyntacticScopeCreator.createScope(block, globalScope);
referenceCollectingCallback.processScope(blockScope);
}
开发者ID:google,项目名称:closure-compiler,代码行数:34,代码来源:ReferenceCollectingCallbackTest.java
示例16: testBehavior
import com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior; //导入依赖的package包/类
private void testBehavior(String js, Behavior behavior) {
this.behavior = behavior;
testSame(js);
}
开发者ID:google,项目名称:closure-compiler,代码行数:5,代码来源:ReferenceCollectingCallbackTest.java
注:本文中的com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论