langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java
changeset 3557 a803afefa115
parent 3300 02ba23f205f3
child 4142 bd950c8f4fb3
equal deleted inserted replaced
3556:08a404c6ff0f 3557:a803afefa115
   594 
   594 
   595 /**************************************************************************
   595 /**************************************************************************
   596  * Symbol manipulation utilities
   596  * Symbol manipulation utilities
   597  *************************************************************************/
   597  *************************************************************************/
   598 
   598 
   599     /** Report a conflict between a user symbol and a synthetic symbol.
       
   600      */
       
   601     private void duplicateError(DiagnosticPosition pos, Symbol sym) {
       
   602         if (!sym.type.isErroneous()) {
       
   603             log.error(pos, "synthetic.name.conflict", sym, sym.location());
       
   604         }
       
   605     }
       
   606 
       
   607     /** Enter a synthetic symbol in a given scope, but complain if there was already one there.
   599     /** Enter a synthetic symbol in a given scope, but complain if there was already one there.
   608      *  @param pos           Position for error reporting.
   600      *  @param pos           Position for error reporting.
   609      *  @param sym           The symbol.
   601      *  @param sym           The symbol.
   610      *  @param s             The scope.
   602      *  @param s             The scope.
   611      */
   603      */
   612     private void enterSynthetic(DiagnosticPosition pos, Symbol sym, Scope s) {
   604     private void enterSynthetic(DiagnosticPosition pos, Symbol sym, Scope s) {
   613         if (sym.name != names.error && sym.name != names.empty) {
       
   614             for (Scope.Entry e = s.lookup(sym.name); e.scope == s; e = e.next()) {
       
   615                 if (sym != e.sym && sym.kind == e.sym.kind) {
       
   616                     // VM allows methods and variables with differing types
       
   617                     if ((sym.kind & (MTH|VAR)) != 0 &&
       
   618                         !types.erasure(sym.type).equals(types.erasure(e.sym.type)))
       
   619                         continue;
       
   620                     duplicateError(pos, e.sym);
       
   621                     break;
       
   622                 }
       
   623             }
       
   624         }
       
   625         s.enter(sym);
   605         s.enter(sym);
   626     }
   606     }
       
   607 
       
   608     /** Check whether synthetic symbols generated during lowering conflict
       
   609      *  with user-defined symbols.
       
   610      *
       
   611      *  @param translatedTrees lowered class trees
       
   612      */
       
   613     void checkConflicts(List<JCTree> translatedTrees) {
       
   614         for (JCTree t : translatedTrees) {
       
   615             t.accept(conflictsChecker);
       
   616         }
       
   617     }
       
   618 
       
   619     JCTree.Visitor conflictsChecker = new TreeScanner() {
       
   620 
       
   621         TypeSymbol currentClass;
       
   622 
       
   623         @Override
       
   624         public void visitMethodDef(JCMethodDecl that) {
       
   625             chk.checkConflicts(that.pos(), that.sym, currentClass);
       
   626             super.visitMethodDef(that);
       
   627         }
       
   628 
       
   629         @Override
       
   630         public void visitVarDef(JCVariableDecl that) {
       
   631             if (that.sym.owner.kind == TYP) {
       
   632                 chk.checkConflicts(that.pos(), that.sym, currentClass);
       
   633             }
       
   634             super.visitVarDef(that);
       
   635         }
       
   636 
       
   637         @Override
       
   638         public void visitClassDef(JCClassDecl that) {
       
   639             TypeSymbol prevCurrentClass = currentClass;
       
   640             currentClass = that.sym;
       
   641             try {
       
   642                 super.visitClassDef(that);
       
   643             }
       
   644             finally {
       
   645                 currentClass = prevCurrentClass;
       
   646             }
       
   647         }
       
   648     };
   627 
   649 
   628     /** Look up a synthetic name in a given scope.
   650     /** Look up a synthetic name in a given scope.
   629      *  @param scope        The scope.
   651      *  @param scope        The scope.
   630      *  @param name         The name.
   652      *  @param name         The name.
   631      */
   653      */
  3190             translate(cdef, (JCExpression)null);
  3212             translate(cdef, (JCExpression)null);
  3191             for (List<Symbol> l = accessed.toList(); l.nonEmpty(); l = l.tail)
  3213             for (List<Symbol> l = accessed.toList(); l.nonEmpty(); l = l.tail)
  3192                 makeAccessible(l.head);
  3214                 makeAccessible(l.head);
  3193             for (EnumMapping map : enumSwitchMap.values())
  3215             for (EnumMapping map : enumSwitchMap.values())
  3194                 map.translate();
  3216                 map.translate();
       
  3217             checkConflicts(this.translated.toList());
  3195             translated = this.translated;
  3218             translated = this.translated;
  3196         } finally {
  3219         } finally {
  3197             // note that recursive invocations of this method fail hard
  3220             // note that recursive invocations of this method fail hard
  3198             attrEnv = null;
  3221             attrEnv = null;
  3199             this.make = null;
  3222             this.make = null;