< prev index next >

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

Print this page

   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.tree;
  27 
  28 
  29 
  30 import com.sun.source.tree.Tree;
  31 import com.sun.source.util.TreePath;
  32 import com.sun.tools.javac.code.*;
  33 import com.sun.tools.javac.code.Symbol.RecordComponent;
  34 import com.sun.tools.javac.comp.AttrContext;
  35 import com.sun.tools.javac.comp.Env;
  36 import com.sun.tools.javac.tree.JCTree.*;
  37 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*;
  38 import com.sun.tools.javac.util.*;
  39 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  40 
  41 import static com.sun.tools.javac.code.Flags.*;
  42 import static com.sun.tools.javac.code.Kinds.Kind.*;
  43 import com.sun.tools.javac.code.Symbol.VarSymbol;
  44 import static com.sun.tools.javac.code.TypeTag.BOOLEAN;
  45 import static com.sun.tools.javac.code.TypeTag.BOT;
  46 import static com.sun.tools.javac.tree.JCTree.Tag.*;
  47 import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
  48 import static com.sun.tools.javac.tree.JCTree.Tag.SYNCHRONIZED;
  49 
  50 import javax.lang.model.element.ElementKind;
  51 import javax.tools.JavaFileObject;
  52 
  53 import java.util.function.Function;
  54 import java.util.function.Predicate;

 173         switch (tree.getTag()) {
 174             case PARENS:
 175                 return isIdentOrThisDotIdent(skipParens(tree));
 176             case IDENT:
 177                 return true;
 178             case SELECT:
 179                 return isThisQualifier(((JCFieldAccess)tree).selected);
 180             default:
 181                 return false;
 182         }
 183     }
 184 
 185     /** Check if the given tree is an explicit reference to the 'this' instance of the
 186      *  class currently being compiled. This is true if tree is:
 187      *  - An unqualified 'this' identifier
 188      *  - A 'super' identifier qualified by a class name whose type is 'currentClass' or a supertype
 189      *  - A 'this' identifier qualified by a class name whose type is 'currentClass' or a supertype
 190      *    but also NOT an enclosing outer class of 'currentClass'.
 191      */
 192     public static boolean isExplicitThisReference(Types types, Type.ClassType currentClass, JCTree tree) {

 193         switch (tree.getTag()) {
 194             case PARENS:
 195                 return isExplicitThisReference(types, currentClass, skipParens(tree));
 196             case IDENT: {
 197                 JCIdent ident = (JCIdent)tree;
 198                 Names names = ident.name.table.names;
 199                 return ident.name == names._this || ident.name == names._super;



 200             }
 201             case SELECT: {
 202                 JCFieldAccess select = (JCFieldAccess)tree;
 203                 Type selectedType = types.erasure(select.selected.type);
 204                 if (!selectedType.hasTag(TypeTag.CLASS))
 205                     return false;
 206                 Symbol.ClassSymbol currentClassSym = (Symbol.ClassSymbol)((Type.ClassType)types.erasure(currentClass)).tsym;
 207                 Symbol.ClassSymbol selectedClassSym = (Symbol.ClassSymbol)((Type.ClassType)selectedType).tsym;
 208                 Names names = select.name.table.names;
 209                 return currentClassSym.isSubClass(selectedClassSym, types) &&
 210                         (select.name == names._super ||
 211                         (select.name == names._this &&
 212                             (currentClassSym == selectedClassSym ||
 213                             !currentClassSym.isEnclosedBy(selectedClassSym))));
 214             }
 215             default:
 216                 return false;
 217         }
 218     }
 219 
 220     /** Is this a call to super?
 221      */
 222     public static boolean isSuperCall(JCTree tree) {
 223         Name name = calledMethodName(tree);
 224         if (name != null) {
 225             Names names = name.table.names;
 226             return name==names._super;
 227         } else {

   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.tree;
  27 


  28 import com.sun.source.tree.Tree;
  29 import com.sun.source.util.TreePath;
  30 import com.sun.tools.javac.code.*;
  31 import com.sun.tools.javac.code.Symbol.RecordComponent;

  32 import com.sun.tools.javac.comp.Env;
  33 import com.sun.tools.javac.tree.JCTree.*;
  34 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*;
  35 import com.sun.tools.javac.util.*;
  36 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  37 
  38 import static com.sun.tools.javac.code.Flags.*;
  39 import static com.sun.tools.javac.code.Kinds.Kind.*;
  40 import com.sun.tools.javac.code.Symbol.VarSymbol;
  41 import static com.sun.tools.javac.code.TypeTag.BOOLEAN;
  42 import static com.sun.tools.javac.code.TypeTag.BOT;
  43 import static com.sun.tools.javac.tree.JCTree.Tag.*;
  44 import static com.sun.tools.javac.tree.JCTree.Tag.BLOCK;
  45 import static com.sun.tools.javac.tree.JCTree.Tag.SYNCHRONIZED;
  46 
  47 import javax.lang.model.element.ElementKind;
  48 import javax.tools.JavaFileObject;
  49 
  50 import java.util.function.Function;
  51 import java.util.function.Predicate;

 170         switch (tree.getTag()) {
 171             case PARENS:
 172                 return isIdentOrThisDotIdent(skipParens(tree));
 173             case IDENT:
 174                 return true;
 175             case SELECT:
 176                 return isThisQualifier(((JCFieldAccess)tree).selected);
 177             default:
 178                 return false;
 179         }
 180     }
 181 
 182     /** Check if the given tree is an explicit reference to the 'this' instance of the
 183      *  class currently being compiled. This is true if tree is:
 184      *  - An unqualified 'this' identifier
 185      *  - A 'super' identifier qualified by a class name whose type is 'currentClass' or a supertype
 186      *  - A 'this' identifier qualified by a class name whose type is 'currentClass' or a supertype
 187      *    but also NOT an enclosing outer class of 'currentClass'.
 188      */
 189     public static boolean isExplicitThisReference(Types types, Type.ClassType currentClass, JCTree tree) {
 190         Symbol.ClassSymbol currentClassSym = (Symbol.ClassSymbol) types.erasure(currentClass).tsym;
 191         switch (tree.getTag()) {
 192             case PARENS:
 193                 return isExplicitThisReference(types, currentClass, skipParens(tree));
 194             case IDENT: {
 195                 JCIdent ident = (JCIdent)tree;
 196                 Names names = ident.name.table.names;
 197                 return ident.name == names._this && tree.type.tsym == currentClass.tsym ||
 198                        ident.name == names._super &&
 199                                (tree.type.tsym == currentClass.tsym ||
 200                                 currentClassSym.isSubClass(tree.type.tsym, types));
 201             }
 202             case SELECT: {
 203                 JCFieldAccess select = (JCFieldAccess)tree;
 204                 Type selectedType = types.erasure(select.selected.type);
 205                 if (!selectedType.hasTag(TypeTag.CLASS))
 206                     return false;
 207                 Symbol.ClassSymbol selectedClassSym = (Symbol.ClassSymbol)(selectedType).tsym;

 208                 Names names = select.name.table.names;
 209                 return currentClassSym.isSubClass(selectedClassSym, types) &&
 210                         (select.name == names._super ||
 211                         (select.name == names._this &&
 212                             (currentClassSym == selectedClassSym ||
 213                             !currentClassSym.isEnclosedBy(selectedClassSym))));
 214             }
 215             default:
 216                 return false;
 217         }
 218     }
 219 
 220     /** Is this a call to super?
 221      */
 222     public static boolean isSuperCall(JCTree tree) {
 223         Name name = calledMethodName(tree);
 224         if (name != null) {
 225             Names names = name.table.names;
 226             return name==names._super;
 227         } else {
< prev index next >