Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
Add comment
  • Loading branch information
mcimadamore committed Jun 14, 2024
1 parent 3ea65cc commit e4d0e1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public Type erasure(Types types) {
public Type externalType(Types types) {
Type t = erasure(types);
if (name == name.table.names.init && owner.hasOuterInstance()) {
Type outerThisType = types.erasure(owner.innermostAccessibleEnclosingType());
Type outerThisType = owner.innermostAccessibleEnclosingClass().erasure(types);
return new MethodType(t.getParameterTypes().prepend(outerThisType),
t.getReturnType(),
t.getThrownTypes(),
Expand Down Expand Up @@ -510,13 +510,19 @@ public boolean hasOuterInstance() {
((flags() & NOOUTERTHIS) == 0 || type.getEnclosingType().tsym.hasOuterInstance());
}

public Type innermostAccessibleEnclosingType() {
/** If the class containing this symbol is a local or an anonymous class, then it might be
* defined inside one or more pre-construction contexts, for which the corresponding enclosing
* instance is considered inaccessible. This method return the class symbol corresponding to the
* innermost enclosing type that is accessible from this symbol's class. Note: this method should
* only be called after checking that {@link #hasOuterInstance()} returns {@code true}.
*/
public ClassSymbol innermostAccessibleEnclosingClass() {
Assert.check(enclClass().hasOuterInstance());
Type current = enclClass().type;
while ((current.tsym.flags() & NOOUTERTHIS) != 0) {
current = current.getEnclosingType();
}
return current.getEnclosingType();
return (ClassSymbol) current.getEnclosingType().tsym;
}

/** The closest enclosing class of this symbol's declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ Name outerThisName(Type type, Symbol owner) {
}

private VarSymbol makeOuterThisVarSymbol(Symbol owner, long flags) {
Type target = types.erasure(owner.innermostAccessibleEnclosingType());
Type target = owner.innermostAccessibleEnclosingClass().erasure(types);
// Set NOOUTERTHIS for all synthetic outer instance variables, and unset
// it when the variable is accessed. If the variable is never accessed,
// we skip creating an outer instance field and saving the constructor
Expand Down Expand Up @@ -3057,7 +3057,7 @@ public void visitNewClass(JCNewClass tree) {
thisArg.type = tree.encl.type;
} else if (c.isDirectlyOrIndirectlyLocal()) {
// local class
thisArg = makeThis(tree.pos(), c.innermostAccessibleEnclosingType().tsym);
thisArg = makeThis(tree.pos(), c.innermostAccessibleEnclosingClass());
} else {
// nested class
thisArg = makeOwnerThis(tree.pos(), c, false);
Expand Down Expand Up @@ -3263,7 +3263,7 @@ public void visitApply(JCMethodInvocation tree) {
((JCIdent) tree.meth).name = methName;
} else if (c.isDirectlyOrIndirectlyLocal() || methName == names._this){
// local class or this() call
thisArg = makeThis(tree.meth.pos(), c.innermostAccessibleEnclosingType().tsym);
thisArg = makeThis(tree.meth.pos(), c.innermostAccessibleEnclosingClass());
} else if (currentClass.isStatic()) {
// super() call from static nested class - invalid
log.error(tree.pos(),
Expand Down

0 comments on commit e4d0e1f

Please sign in to comment.