< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java

Print this page
@@ -23,17 +23,14 @@
   * questions.
   */
  
  package com.sun.tools.javac.tree;
  
- 
- 
  import com.sun.source.tree.Tree;
  import com.sun.source.util.TreePath;
  import com.sun.tools.javac.code.*;
  import com.sun.tools.javac.code.Symbol.RecordComponent;
- import com.sun.tools.javac.comp.AttrContext;
  import com.sun.tools.javac.comp.Env;
  import com.sun.tools.javac.tree.JCTree.*;
  import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*;
  import com.sun.tools.javac.util.*;
  import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;

@@ -188,25 +185,28 @@
       *  - A 'super' identifier qualified by a class name whose type is 'currentClass' or a supertype
       *  - A 'this' identifier qualified by a class name whose type is 'currentClass' or a supertype
       *    but also NOT an enclosing outer class of 'currentClass'.
       */
      public static boolean isExplicitThisReference(Types types, Type.ClassType currentClass, JCTree tree) {
+         Symbol.ClassSymbol currentClassSym = (Symbol.ClassSymbol) types.erasure(currentClass).tsym;
          switch (tree.getTag()) {
              case PARENS:
                  return isExplicitThisReference(types, currentClass, skipParens(tree));
              case IDENT: {
                  JCIdent ident = (JCIdent)tree;
                  Names names = ident.name.table.names;
-                 return ident.name == names._this || ident.name == names._super;
+                 return ident.name == names._this && tree.type.tsym == currentClass.tsym ||
+                        ident.name == names._super &&
+                                (tree.type.tsym == currentClass.tsym ||
+                                 currentClassSym.isSubClass(tree.type.tsym, types));
              }
              case SELECT: {
                  JCFieldAccess select = (JCFieldAccess)tree;
                  Type selectedType = types.erasure(select.selected.type);
                  if (!selectedType.hasTag(TypeTag.CLASS))
                      return false;
-                 Symbol.ClassSymbol currentClassSym = (Symbol.ClassSymbol)((Type.ClassType)types.erasure(currentClass)).tsym;
-                 Symbol.ClassSymbol selectedClassSym = (Symbol.ClassSymbol)((Type.ClassType)selectedType).tsym;
+                 Symbol.ClassSymbol selectedClassSym = (Symbol.ClassSymbol)(selectedType).tsym;
                  Names names = select.name.table.names;
                  return currentClassSym.isSubClass(selectedClassSym, types) &&
                          (select.name == names._super ||
                          (select.name == names._this &&
                              (currentClassSym == selectedClassSym ||
< prev index next >