本文整理汇总了Java中com.google.javascript.jscomp.ReferenceCollectingCallback.Behavior类的典型用法代码示例。如果您正苦于以下问题:Java Behavior类的具体用法?Java Behavior怎么用?Java Behavior使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Behavior类属于com.google.javascript.jscomp.ReferenceCollectingCallback包,在下文中一共展示了Behavior类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
});
}
示例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();
}
}
});
}
示例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();
}
}
});
}
示例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();
}
}
});
}
示例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);
}
}
});
}
示例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();
}
}
});
}
示例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();
}
}
});
}
示例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);
}
示例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);
}
示例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();
}
}
});
}
示例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();
}
}
});
}
示例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);
}
示例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();
}
}
});
}
示例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);
}
示例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);
}