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=169730047
  • Loading branch information
shicks authored and blickly committed Sep 22, 2017
1 parent 2957eae commit de651d6
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();

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

/**
* 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
public void checkForCallingConventionDefiningCalls(
public void checkForCallingConventionDefinitions(
Node n, Map<String, String> delegateCallingConventions) {
nextConvention.checkForCallingConventionDefiningCalls(
nextConvention.checkForCallingConventionDefinitions(
n, delegateCallingConventions);
}

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

@Override
public void checkForCallingConventionDefiningCalls(Node n,
public void checkForCallingConventionDefinitions(Node n,
Map<String, String> delegateCallingConventions) {
// 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()) {
case CALL:
checkForClassDefiningCalls(n);
checkForCallingConventionDefiningCalls(n, delegateCallingConventions);
break;

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

case GETPROP:
checkForCallingConventionDefinitions(n);
// Handle stubbed properties.
if (parent.isExprResult() &&
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(
Node n, Map<String, String> delegateCallingConventions) {
codingConvention.checkForCallingConventionDefiningCalls(n,
delegateCallingConventions);
private void checkForCallingConventionDefinitions(Node n) {
codingConvention.checkForCallingConventionDefinitions(n, delegateCallingConventions);
}

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

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

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
// caught when we try to declare it in the current scope.
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 de651d6

Please sign in to comment.