Skip to content

Commit

Permalink
Rollback of "Change CodingConvention#checkForCallingConventionDefinit…
Browse files Browse the repository at this point in the history
…ion"

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

/**
* Checks for getprops that set the calling conventions on delegate methods.
* Checks for function calls that set the calling conventions on delegate
* methods.
*/
public void checkForCallingConventionDefinitions(
Node getPropNode, Map<String, String> delegateCallingConventions);
public void checkForCallingConventionDefiningCalls(
Node n, 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 checkForCallingConventionDefinitions(
public void checkForCallingConventionDefiningCalls(
Node n, Map<String, String> delegateCallingConventions) {
nextConvention.checkForCallingConventionDefinitions(
nextConvention.checkForCallingConventionDefiningCalls(
n, delegateCallingConventions);
}

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

@Override
public void checkForCallingConventionDefinitions(Node n,
public void checkForCallingConventionDefiningCalls(Node n,
Map<String, String> delegateCallingConventions) {
// do nothing.
}
Expand Down
36 changes: 26 additions & 10 deletions src/com/google/javascript/jscomp/TypedScopeCreator.java
Expand Up @@ -533,6 +533,7 @@ 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 @@ -565,7 +566,6 @@ 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,10 +1473,12 @@ private JSType lookupQualifiedName(Node n) {
}

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

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

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

codingConvention.applyDelegateRelationship(
Expand Down Expand Up @@ -1693,6 +1695,20 @@ 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 659fbc6

Please sign in to comment.