Skip to content

Commit

Permalink
Change CodingConvention#checkForCallingConventionDefinition to operat…
Browse files Browse the repository at this point in the history
…e on getprop instead of call nodes.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=169993573
  • Loading branch information
shicks authored and brad4d committed Sep 27, 2017
1 parent 4ad9f50 commit d6ff1a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
7 changes: 3 additions & 4 deletions src/com/google/javascript/jscomp/CodingConvention.java
Expand Up @@ -277,11 +277,10 @@ public void applyDelegateRelationship(
public String getDelegateSuperclassName(); public String getDelegateSuperclassName();


/** /**
* Checks for function calls that set the calling conventions on delegate * Checks for getprops that set the calling conventions on delegate methods.
* methods.
*/ */
public void checkForCallingConventionDefiningCalls( public void checkForCallingConventionDefinitions(
Node n, Map<String, String> delegateCallingConventions); Node getPropNode, Map<String, String> delegateCallingConventions);


/** /**
* Defines the delegate proxy prototype properties. Their types depend on * Defines the delegate proxy prototype properties. Their types depend on
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/CodingConventions.java
Expand Up @@ -250,9 +250,9 @@ public String getDelegateSuperclassName() {
} }


@Override @Override
public void checkForCallingConventionDefiningCalls( public void checkForCallingConventionDefinitions(
Node n, Map<String, String> delegateCallingConventions) { Node n, Map<String, String> delegateCallingConventions) {
nextConvention.checkForCallingConventionDefiningCalls( nextConvention.checkForCallingConventionDefinitions(
n, delegateCallingConventions); n, delegateCallingConventions);
} }


Expand Down Expand Up @@ -510,7 +510,7 @@ public String getDelegateSuperclassName() {
} }


@Override @Override
public void checkForCallingConventionDefiningCalls(Node n, public void checkForCallingConventionDefinitions(Node n,
Map<String, String> delegateCallingConventions) { Map<String, String> delegateCallingConventions) {
// do nothing. // do nothing.
} }
Expand Down
36 changes: 10 additions & 26 deletions src/com/google/javascript/jscomp/TypedScopeCreator.java
Expand Up @@ -533,7 +533,6 @@ public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getToken()) { switch (n.getToken()) {
case CALL: case CALL:
checkForClassDefiningCalls(n); checkForClassDefiningCalls(n);
checkForCallingConventionDefiningCalls(n, delegateCallingConventions);
break; break;


case FUNCTION: case FUNCTION:
Expand Down Expand Up @@ -566,6 +565,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
break; break;


case GETPROP: case GETPROP:
checkForCallingConventionDefinitions(n);
// Handle stubbed properties. // Handle stubbed properties.
if (parent.isExprResult() && if (parent.isExprResult() &&
n.isQualifiedName()) { n.isQualifiedName()) {
Expand Down Expand Up @@ -1473,12 +1473,10 @@ private JSType lookupQualifiedName(Node n) {
} }


/** /**
* Look for calls that set a delegate method's calling convention. * Look for expressions that set a delegate method's calling convention.
*/ */
private void checkForCallingConventionDefiningCalls( private void checkForCallingConventionDefinitions(Node n) {
Node n, Map<String, String> delegateCallingConventions) { codingConvention.checkForCallingConventionDefinitions(n, delegateCallingConventions);
codingConvention.checkForCallingConventionDefiningCalls(n,
delegateCallingConventions);
} }


/** /**
Expand Down Expand Up @@ -1578,12 +1576,12 @@ private void applyDelegateRelationship(


FunctionType delegateProxy = FunctionType delegateProxy =
typeRegistry.createConstructorType( typeRegistry.createConstructorType(
delegateBaseObject.getReferenceName() + DELEGATE_PROXY_SUFFIX, delegateBaseObject.getReferenceName() + DELEGATE_PROXY_SUFFIX /* name */,
null, null /* source */,
null, null /* parameters */,
null, null /* returnType */,
null, null /* templateKeys */,
false); false /* isAbstract */);
delegateProxy.setPrototypeBasedOn(delegateBaseObject); delegateProxy.setPrototypeBasedOn(delegateBaseObject);


codingConvention.applyDelegateRelationship( codingConvention.applyDelegateRelationship(
Expand Down Expand Up @@ -1695,20 +1693,6 @@ void maybeDeclareQualifiedName(NodeTraversal t, JSDocInfo info,
// If the property is already declared, the error will be // If the property is already declared, the error will be
// caught when we try to declare it in the current scope. // caught when we try to declare it in the current scope.
defineSlot(n, parent, valueType, inferred); defineSlot(n, parent, valueType, inferred);
} else if (rhsValue != null && rhsValue.isTrue()) {
// We declare these for delegate proxy method properties.
ObjectType ownerType = getObjectSlot(ownerName);
FunctionType ownerFnType = JSType.toMaybeFunctionType(ownerType);
if (ownerFnType != null) {
JSType ownerTypeOfThis = ownerFnType.getTypeOfThis();
String delegateName = codingConvention.getDelegateSuperclassName();
JSType delegateType = delegateName == null ?
null : typeRegistry.getType(delegateName);
if (delegateType != null &&
ownerTypeOfThis.isSubtype(delegateType)) {
defineSlot(n, parent, getNativeType(BOOLEAN_TYPE), true);
}
}
} }
} }


Expand Down

0 comments on commit d6ff1a2

Please sign in to comment.