本文整理汇总了Java中com.google.javascript.jscomp.CodingConvention.SubclassRelationship类的典型用法代码示例。如果您正苦于以下问题:Java SubclassRelationship类的具体用法?Java SubclassRelationship怎么用?Java SubclassRelationship使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SubclassRelationship类属于com.google.javascript.jscomp.CodingConvention包,在下文中一共展示了SubclassRelationship类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:andyjko,项目名称:feedlack,代码行数:31,代码来源:StripCode.java
示例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);
}
}
}
开发者ID:google,项目名称:closure-compiler,代码行数:22,代码来源:TypeCheck.java
示例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;
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:17,代码来源:GlobalNamespace.java
示例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);
}
}
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:22,代码来源:TypeCheck.java
示例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);
}
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:ClosureCodingConventionTest.java
示例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;
}
开发者ID:google,项目名称:closure-compiler,代码行数:14,代码来源:GlobalNamespace.java
示例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);
}
}
开发者ID:google,项目名称:closure-compiler,代码行数:16,代码来源:GlobalTypeInfoCollector.java
示例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);
}
}
开发者ID:google,项目名称:closure-compiler,代码行数:16,代码来源:GlobalTypeInfoCollector.java
示例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);
}
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:DefaultCodingConventionTest.java
示例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);
}
开发者ID:andyjko,项目名称:feedlack,代码行数:63,代码来源:InlineVariables.java
示例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;
}
}
开发者ID:andyjko,项目名称:feedlack,代码行数:77,代码来源:CrossModuleCodeMotion.java
示例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;
}
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:GatherSideEffectSubexpressionsCallback.java
示例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);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:70,代码来源:InlineVariables.java
示例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;
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:77,代码来源:CrossModuleCodeMotion.java
示例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);
}
开发者ID:google,项目名称:closure-compiler,代码行数:73,代码来源:InlineVariables.java
示例16: traverseCall
import com.google.javascript.jscomp.CodingConvention.SubclassRelationship; //导入依赖的package包/类
private void traverseCall(Node callNode, Scope scope) {
Node callee = callNode.getFirstChild();
if (callee.isQualifiedName()
&& codingConvention.isPropertyRenameFunction(callee.getOriginalQualifiedName())) {
Node propertyNameNode = checkNotNull(callee.getNext());
if (propertyNameNode.isString()) {
markPropertyNameReferenced(propertyNameNode.getString());
}
traverseChildren(callNode, scope);
} else if (NodeUtil.isObjectDefinePropertiesDefinition(callNode)) {
// TODO(bradfordcsmith): Should also handle Object.create() and Object.defineProperty().
traverseObjectDefinePropertiesCall(callNode, scope);
} else {
Node parent = callNode.getParent();
String classVarName = null;
// A call that is a statement unto itself or the left side of a comma expression might be
// a call to a known method for doing class setup
// e.g. $jscomp.inherits(Class, BaseClass) or goog.addSingletonGetter(Class)
// Such methods never have meaningful return values, so we won't look for them in other
// contexts
if (parent.isExprResult() || (parent.isComma() && parent.getFirstChild() == callNode)) {
SubclassRelationship subclassRelationship =
codingConvention.getClassesDefinedByCall(callNode);
if (subclassRelationship != null) {
// e.g. goog.inherits(DerivedClass, BaseClass);
// NOTE: DerivedClass and BaseClass must be QNames. Otherwise getClassesDefinedByCall()
// will return null.
classVarName = subclassRelationship.subclassName;
} else {
// Look for calls to addSingletonGetter calls.
classVarName = codingConvention.getSingletonGetterClassName(callNode);
}
}
Var classVar = null;
if (classVarName != null && NodeUtil.isValidSimpleName(classVarName)) {
classVar = checkNotNull(scope.getVar(classVarName), classVarName);
}
if (classVar == null || !classVar.isGlobal()) {
// The call we are traversing does not modify a class definition,
// or the class is not specified with a simple variable name,
// or the variable name is not global.
// TODO(bradfordcsmith): It would be more correct to check whether the class name
// references a known constructor and expand to allow QNames.
traverseChildren(callNode, scope);
} else {
RemovableBuilder builder = new RemovableBuilder();
for (Node child = callNode.getFirstChild(); child != null; child = child.getNext()) {
builder.addContinuation(new Continuation(child, scope));
}
traverseVar(classVar).addRemovable(builder.buildClassSetupCall(callNode));
}
}
}
开发者ID:google,项目名称:closure-compiler,代码行数:58,代码来源:RemoveUnusedCode.java
示例17: 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(
ReferenceCollectingCallback collector, Reference ref, NamedInfo info) {
Node name = ref.getNode();
Node parent = name.getParent();
Node gramps = parent.getParent();
switch (parent.getType()) {
case Token.VAR:
if (canMoveValue(collector, ref.getScope(), name.getFirstChild())) {
return info.addDeclaration(
new Declaration(getModule(ref), name));
}
return false;
case Token.FUNCTION:
if (NodeUtil.isFunctionDeclaration(parent)) {
return info.addDeclaration(
new Declaration(getModule(ref), name));
}
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(
collector, ref.getScope(), current.getLastChild())) {
return info.addDeclaration(
new Declaration(getModule(ref), current));
}
} 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(getModule(ref), parent));
}
}
return false;
default:
return false;
}
}
开发者ID:nicks,项目名称:closure-compiler-old,代码行数:78,代码来源:CrossModuleCodeMotion.java
注:本文中的com.google.javascript.jscomp.CodingConvention.SubclassRelationship类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论