本文整理汇总了Java中com.google.javascript.jscomp.CodingConvention.SubclassRelationship类的典型用法代码示例。如果您正苦于以下问题:Java SubclassRelationship类的具体用法?Java SubclassRelationship怎么用?Java SubclassRelationship使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SubclassRelationship类属于com.google.javascript.jscomp.CodingConvention包,在下文中一共展示了SubclassRelationship类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actsOnStripType
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* Determines whether the given node helps to define a
* strip type. For example, goog.inherits(stripType, Object)
* would be such a call.
*
* Also reports an error if a non-strip type inherits from a strip type.
*
* @param t The current traversal
* @param callNode The CALL node
*/
private boolean actsOnStripType(NodeTraversal t, Node callNode) {
SubclassRelationship classes =
compiler.getCodingConvention().getClassesDefinedByCall(callNode);
if (classes != null) {
// It's okay to strip a type that inherits from a non-stripped type
// e.g. goog.inherits(goog.debug.Logger, Object)
if (qualifiedNameBeginsWithStripType(classes.subclassName)) {
return true;
}
// report an error if a non-strip type inherits from a
// strip type.
if (qualifiedNameBeginsWithStripType(classes.superclassName)) {
t.report(callNode, STRIP_TYPE_INHERIT_ERROR,
classes.subclassName, classes.superclassName);
}
}
return false;
}
示例2: checkCallConventions
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* Validate class-defining calls.
* Because JS has no 'native' syntax for defining classes, we need
* to do this manually.
*/
private void checkCallConventions(NodeTraversal t, Node n) {
SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(n);
TypedScope scope = t.getTypedScope();
if (relationship != null) {
ObjectType superClass = TypeValidator.getInstanceOfCtor(
scope.getVar(relationship.superclassName));
ObjectType subClass = TypeValidator.getInstanceOfCtor(
scope.getVar(relationship.subclassName));
if (relationship.type == SubclassType.INHERITS &&
superClass != null && !superClass.isEmptyType() &&
subClass != null && !subClass.isEmptyType()) {
validator.expectSuperType(t, n, superClass, subClass);
}
}
}
示例3: isClassDefiningCall
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
private boolean isClassDefiningCall(Node callNode) {
CodingConvention convention = compiler.getCodingConvention();
// Look for goog.inherits, goog.mixin
SubclassRelationship classes =
convention.getClassesDefinedByCall(callNode);
if (classes != null) {
return true;
}
// Look for calls to goog.addSingletonGetter calls.
String className = convention.getSingletonGetterClassName(callNode);
if (className != null) {
return true;
}
return false;
}
示例4: checkCallConventions
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* Validate class-defining calls.
* Because JS has no 'native' syntax for defining classes, we need
* to do this manually.
*/
private void checkCallConventions(NodeTraversal t, Node n) {
SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(n);
Scope scope = t.getScope();
if (relationship != null) {
ObjectType superClass = TypeValidator.getInstanceOfCtor(
scope.getVar(relationship.superclassName));
ObjectType subClass = TypeValidator.getInstanceOfCtor(
scope.getVar(relationship.subclassName));
if (relationship.type == SubclassType.INHERITS &&
superClass != null && !superClass.isEmptyType() &&
subClass != null && !subClass.isEmptyType()) {
validator.expectSuperType(t, n, superClass, subClass);
}
}
}
示例5: assertDefinesClasses
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
private void assertDefinesClasses(String code, String subclassName,
String superclassName) {
Node n = parseTestCode(code);
SubclassRelationship classes =
conv.getClassesDefinedByCall(n.getFirstChild());
assertNotNull(classes);
assertEquals(subclassName, classes.subclassName);
assertEquals(superclassName, classes.superclassName);
}
示例6: isClassDefiningCall
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
private boolean isClassDefiningCall(Node callNode) {
CodingConvention convention = compiler.getCodingConvention();
// Look for goog.inherits, goog.mixin
SubclassRelationship classes =
convention.getClassesDefinedByCall(callNode);
if (classes != null) {
return true;
}
// Look for calls to goog.addSingletonGetter calls.
String className = convention.getSingletonGetterClassName(callNode);
return className != null;
}
示例7: visitCall
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
private void visitCall(Node call) {
// Check various coding conventions to see if any additional handling is needed.
SubclassRelationship relationship = convention.getClassesDefinedByCall(call);
if (relationship != null) {
applySubclassRelationship(relationship);
}
String className = convention.getSingletonGetterClassName(call);
if (className != null) {
applySingletonGetter(className);
}
DelegateRelationship delegateRelationship = convention.getDelegateRelationship(call);
if (delegateRelationship != null) {
applyDelegateRelationship(delegateRelationship);
}
}
示例8: applySubclassRelationship
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
private void applySubclassRelationship(SubclassRelationship rel) {
if (rel.superclassName.equals(rel.subclassName)) {
// Note: this is a messed up situation, but it's dealt with elsewhere, so let it go here.
return;
}
RawNominalType superClass = findInScope(rel.superclassName);
RawNominalType subClass = findInScope(rel.subclassName);
if (superClass != null && superClass.getConstructorFunction() != null
&& subClass != null && subClass.getConstructorFunction() != null) {
convention.applySubclassRelationship(
new NominalTypeBuilderNti(superClass.getAsNominalType()),
new NominalTypeBuilderNti(subClass.getAsNominalType()),
rel.type);
}
}
示例9: assertDefinesClasses
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
private void assertDefinesClasses(String code, String subclassName,
String superclassName) {
Node n = parseTestCode(code);
SubclassRelationship classes =
conv.getClassesDefinedByCall(n.getFirstChild());
assertThat(classes).isNotNull();
assertThat(classes.subclassName).isEqualTo(subclassName);
assertThat(classes.superclassName).isEqualTo(superclassName);
}
示例10: canInline
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* @return true if the provided reference and declaration can be safely
* inlined according to our criteria
*/
private boolean canInline(
Reference declaration,
Reference initialization,
Reference reference) {
if (!isValidDeclaration(declaration)
|| !isValidInitialization(initialization)
|| !isValidReference(reference)) {
return false;
}
// If the value is read more than once, skip it.
// VAR declarations and EXPR_RESULT don't need the value, but other
// ASSIGN expressions parents do.
if (declaration != initialization &&
initialization.getGrandparent().getType() != Token.EXPR_RESULT) {
return false;
}
// Be very conservative and do no cross control structures or
// scope boundaries
if (declaration.getBasicBlock() != initialization.getBasicBlock()
|| declaration.getBasicBlock() != reference.getBasicBlock()) {
return false;
}
// Do not inline into a call node. This would change
// the context in which it was being called. For example,
// var a = b.c;
// a();
// should not be inlined, because it calls a in the context of b
// rather than the context of the window.
// var a = b.c;
// f(a)
// is ok.
Node value = initialization.getAssignedValue();
Preconditions.checkState(value != null);
if (value.getType() == Token.GETPROP
&& reference.getParent().getType() == Token.CALL
&& reference.getParent().getFirstChild() == reference.getNameNode()) {
return false;
}
// Bug 2388531: Don't inline subclass definitions into class defining
// calls as this confused class removing logic.
if (value.getType() == Token.FUNCTION) {
Node callNode = reference.getParent();
if (reference.getParent().getType() == Token.CALL) {
SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(callNode);
if (relationship != null) {
return false;
}
}
}
return canMoveAggressively(value) ||
canMoveModerately(initialization, reference);
}
示例11: maybeProcessDeclaration
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* Determines whether the given NAME node belongs to a delcaration that
* can be moved across modules. If it is, registers it properly.
*
* There are four types of movable declarations:
* 1) var NAME = [movable object];
* 2) function NAME() {}
* 3) NAME = [movable object];
* NAME.prop = [movable object];
* NAME.prop.prop2 = [movable object];
* etc.
* 4) Class-defining function calls, like "inherits" and "mixin".
* NAME.inherits([some other name]);
* where "movable object" is a literal or a function.
*/
private boolean maybeProcessDeclaration(NodeTraversal t, Node name,
Node parent, NamedInfo info) {
Node gramps = parent.getParent();
switch (parent.getType()) {
case Token.VAR:
if (canMoveValue(name.getFirstChild())) {
return info.addDeclaration(
new Declaration(t.getModule(), name, parent, gramps));
}
return false;
case Token.FUNCTION:
if (NodeUtil.isFunctionDeclaration(parent)) {
return info.addDeclaration(
new Declaration(t.getModule(), name, parent, gramps));
}
return false;
case Token.ASSIGN:
case Token.GETPROP:
Node child = name;
// Look for assignment expressions where the name is the root
// of a qualified name on the left hand side of the assignment.
for (Node current : name.getAncestors()) {
if (current.getType() == Token.GETPROP) {
// fallthrough
} else if (current.getType() == Token.ASSIGN &&
current.getFirstChild() == child) {
Node currentParent = current.getParent();
if (NodeUtil.isExpressionNode(currentParent) &&
canMoveValue(current.getLastChild())) {
return info.addDeclaration(
new Declaration(t.getModule(), current, currentParent,
currentParent.getParent()));
}
} else {
return false;
}
child = current;
}
return false;
case Token.CALL:
if (NodeUtil.isExprCall(gramps)) {
SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(parent);
if (relationship != null &&
name.getString().equals(relationship.subclassName)) {
return info.addDeclaration(
new Declaration(t.getModule(), parent, gramps,
gramps.getParent()));
}
}
return false;
default:
return false;
}
}
示例12: isClassDefiningCall
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* Determines if a call defines a class inheritance or mixing
* relation, according to the current coding convention.
*/
private boolean isClassDefiningCall(Node callNode) {
SubclassRelationship classes =
compiler.getCodingConvention().getClassesDefinedByCall(callNode);
return classes != null;
}
示例13: canInline
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* @return true if the provided reference and declaration can be safely
* inlined according to our criteria
*/
private boolean canInline(
Reference declaration,
Reference initialization,
Reference reference) {
if (!isValidDeclaration(declaration)
|| !isValidInitialization(initialization)
|| !isValidReference(reference)) {
return false;
}
// If the value is read more than once, skip it.
// VAR declarations and EXPR_RESULT don't need the value, but other
// ASSIGN expressions parents do.
if (declaration != initialization &&
!initialization.getGrandparent().isExprResult()) {
return false;
}
// Be very conservative and do no cross control structures or
// scope boundaries
if (declaration.getBasicBlock() != initialization.getBasicBlock()
|| declaration.getBasicBlock() != reference.getBasicBlock()) {
return false;
}
// Do not inline into a call node. This would change
// the context in which it was being called. For example,
// var a = b.c;
// a();
// should not be inlined, because it calls a in the context of b
// rather than the context of the window.
// var a = b.c;
// f(a)
// is OK.
Node value = initialization.getAssignedValue();
Preconditions.checkState(value != null);
if (value.isGetProp()
&& reference.getParent().isCall()
&& reference.getParent().getFirstChild() == reference.getNode()) {
return false;
}
if (value.isFunction()) {
Node callNode = reference.getParent();
if (reference.getParent().isCall()) {
CodingConvention convention = compiler.getCodingConvention();
// Bug 2388531: Don't inline subclass definitions into class defining
// calls as this confused class removing logic.
SubclassRelationship relationship =
convention.getClassesDefinedByCall(callNode);
if (relationship != null) {
return false;
}
// issue 668: Don't inline singleton getter methods
// calls as this confused class removing logic.
if (convention.getSingletonGetterClassName(callNode) != null) {
return false;
}
}
}
return canMoveAggressively(value) ||
canMoveModerately(initialization, reference);
}
示例14: maybeProcessDeclaration
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* Determines whether the given NAME node belongs to a declaration that
* can be moved across modules. If it is, registers it properly.
*
* There are four types of movable declarations:
* 1) var NAME = [movable object];
* 2) function NAME() {}
* 3) NAME = [movable object];
* NAME.prop = [movable object];
* NAME.prop.prop2 = [movable object];
* etc.
* 4) Class-defining function calls, like "inherits" and "mixin".
* NAME.inherits([some other name]);
* where "movable object" is a literal or a function.
*/
private boolean maybeProcessDeclaration(NodeTraversal t, Node name,
Node parent, NamedInfo info) {
Node gramps = parent.getParent();
switch (parent.getType()) {
case Token.VAR:
if (canMoveValue(name.getFirstChild())) {
return info.addDeclaration(
new Declaration(t.getModule(), name, parent, gramps));
}
return false;
case Token.FUNCTION:
if (NodeUtil.isFunctionDeclaration(parent)) {
return info.addDeclaration(
new Declaration(t.getModule(), name, parent, gramps));
}
return false;
case Token.ASSIGN:
case Token.GETPROP:
Node child = name;
// Look for assignment expressions where the name is the root
// of a qualified name on the left hand side of the assignment.
for (Node current : name.getAncestors()) {
if (current.isGetProp()) {
// fallthrough
} else if (current.isAssign() &&
current.getFirstChild() == child) {
Node currentParent = current.getParent();
if (currentParent.isExprResult() &&
canMoveValue(current.getLastChild())) {
return info.addDeclaration(
new Declaration(t.getModule(), current, currentParent,
currentParent.getParent()));
}
} else {
return false;
}
child = current;
}
return false;
case Token.CALL:
if (NodeUtil.isExprCall(gramps)) {
SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(parent);
if (relationship != null &&
name.getString().equals(relationship.subclassName)) {
return info.addDeclaration(
new Declaration(t.getModule(), parent, gramps,
gramps.getParent()));
}
}
return false;
default:
return false;
}
}
示例15: canInline
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
/**
* @return true if the provided reference and declaration can be safely
* inlined according to our criteria
*/
private boolean canInline(
Reference declaration,
Reference initialization,
Reference reference) {
if (!isValidDeclaration(declaration)
|| !isValidInitialization(initialization)
|| !isValidReference(reference)) {
return false;
}
// If the value is read more than once, skip it.
// VAR declarations and EXPR_RESULT don't need the value, but other
// ASSIGN expressions parents do.
if (declaration != initialization &&
!initialization.getGrandparent().isExprResult()) {
return false;
}
// Be very conservative and do not cross control structures or scope boundaries
if (declaration.getBasicBlock() != initialization.getBasicBlock()
|| declaration.getBasicBlock() != reference.getBasicBlock()) {
return false;
}
// Do not inline into a call node. This would change
// the context in which it was being called. For example,
// var a = b.c;
// a();
// should not be inlined, because it calls a in the context of b
// rather than the context of the window.
// var a = b.c;
// f(a)
// is OK.
Node value = initialization.getAssignedValue();
checkState(value != null);
if (value.isGetProp()
&& reference.getParent().isCall()
&& reference.getParent().getFirstChild() == reference.getNode()) {
return false;
}
if (value.isFunction()) {
Node callNode = reference.getParent();
if (reference.getParent().isCall()) {
CodingConvention convention = compiler.getCodingConvention();
// Bug 2388531: Don't inline subclass definitions into class defining
// calls as this confused class removing logic.
SubclassRelationship relationship =
convention.getClassesDefinedByCall(callNode);
if (relationship != null) {
return false;
}
// issue 668: Don't inline singleton getter methods
// calls as this confused class removing logic.
if (convention.getSingletonGetterClassName(callNode) != null) {
return false;
}
}
}
if (initialization.getScope() != declaration.getScope()
|| !initialization.getScope().contains(reference.getScope())) {
return false;
}
return canMoveAggressively(value) || canMoveModerately(initialization, reference);
}