2699 prepend(makeLit(syms.intType, ordinal)).
2700 prepend(makeLit(syms.stringType, var.name.toString()));
2701 }
2702
2703 public void visitMethodDef(JCMethodDecl tree) {
2704 if (tree.name == names.init && (currentClass.flags_field&ENUM) != 0) {
2705 // Add "String $enum$name, int $enum$ordinal" to the beginning of the
2706 // argument list for each constructor of an enum.
2707 JCVariableDecl nameParam = make_at(tree.pos()).
2708 Param(names.fromString(target.syntheticNameChar() +
2709 "enum" + target.syntheticNameChar() + "name"),
2710 syms.stringType, tree.sym);
2711 nameParam.mods.flags |= SYNTHETIC; nameParam.sym.flags_field |= SYNTHETIC;
2712 JCVariableDecl ordParam = make.
2713 Param(names.fromString(target.syntheticNameChar() +
2714 "enum" + target.syntheticNameChar() +
2715 "ordinal"),
2716 syms.intType, tree.sym);
2717 ordParam.mods.flags |= SYNTHETIC; ordParam.sym.flags_field |= SYNTHETIC;
2718
2719 tree.params = tree.params.prepend(ordParam).prepend(nameParam);
2720
2721 MethodSymbol m = tree.sym;
2722 m.extraParams = m.extraParams.prepend(ordParam.sym);
2723 m.extraParams = m.extraParams.prepend(nameParam.sym);
2724 Type olderasure = m.erasure(types);
2725 m.erasure_field = new MethodType(
2726 olderasure.getParameterTypes().prepend(syms.intType).prepend(syms.stringType),
2727 olderasure.getReturnType(),
2728 olderasure.getThrownTypes(),
2729 syms.methodClass);
2730 }
2731
2732 JCMethodDecl prevMethodDef = currentMethodDef;
2733 MethodSymbol prevMethodSym = currentMethodSym;
2734 try {
2735 currentMethodDef = tree;
2736 currentMethodSym = tree.sym;
2737 visitMethodDefInternal(tree);
2738 } finally {
2739 currentMethodDef = prevMethodDef;
2740 currentMethodSym = prevMethodSym;
2741 }
2742 }
2743 //where
2744 private void visitMethodDefInternal(JCMethodDecl tree) {
2745 if (tree.name == names.init &&
2746 (currentClass.isInner() || currentClass.isLocal())) {
2747 // We are seeing a constructor of an inner class.
2748 MethodSymbol m = tree.sym;
2749
2750 // Push a new proxy scope for constructor parameters.
2751 // and create definitions for any this$n and proxy parameters.
2752 proxies = proxies.dup(m);
2753 List<VarSymbol> prevOuterThisStack = outerThisStack;
2754 List<VarSymbol> fvs = freevars(currentClass);
2755 JCVariableDecl otdef = null;
2756 if (currentClass.hasOuterInstance())
2757 otdef = outerThisDef(tree.pos, m);
2758 List<JCVariableDecl> fvdefs = freevarDefs(tree.pos, fvs, m, PARAMETER);
2759
2760 // Recursively translate result type, parameters and thrown list.
2761 tree.restype = translate(tree.restype);
2762 tree.params = translateVarDefs(tree.params);
2763 tree.thrown = translate(tree.thrown);
2764
2765 // when compiling stubs, don't process body
2766 if (tree.body == null) {
2767 result = tree;
2768 return;
2769 }
2770
2771 // Add this$n (if needed) in front of and free variables behind
2772 // constructor parameter list.
2773 tree.params = tree.params.appendList(fvdefs);
2774 if (currentClass.hasOuterInstance())
2775 tree.params = tree.params.prepend(otdef);
2776
2777 // If this is an initial constructor, i.e., it does not start with
2778 // this(...), insert initializers for this$n and proxies
2779 // before (pre-1.4, after) the call to superclass constructor.
2780 JCStatement selfCall = translate(tree.body.stats.head);
2781
2782 List<JCStatement> added = List.nil();
2783 if (fvs.nonEmpty()) {
2784 List<Type> addedargtypes = List.nil();
2785 for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail) {
2786 if (TreeInfo.isInitialConstructor(tree)) {
2787 final Name pName = proxyName(l.head.name);
2788 m.capturedLocals =
2789 m.capturedLocals.append((VarSymbol)
2790 (proxies.lookup(pName).sym));
2791 added = added.prepend(
2792 initField(tree.body.pos, pName));
2793 }
2794 addedargtypes = addedargtypes.prepend(l.head.erasure(types));
2795 }
|
2699 prepend(makeLit(syms.intType, ordinal)).
2700 prepend(makeLit(syms.stringType, var.name.toString()));
2701 }
2702
2703 public void visitMethodDef(JCMethodDecl tree) {
2704 if (tree.name == names.init && (currentClass.flags_field&ENUM) != 0) {
2705 // Add "String $enum$name, int $enum$ordinal" to the beginning of the
2706 // argument list for each constructor of an enum.
2707 JCVariableDecl nameParam = make_at(tree.pos()).
2708 Param(names.fromString(target.syntheticNameChar() +
2709 "enum" + target.syntheticNameChar() + "name"),
2710 syms.stringType, tree.sym);
2711 nameParam.mods.flags |= SYNTHETIC; nameParam.sym.flags_field |= SYNTHETIC;
2712 JCVariableDecl ordParam = make.
2713 Param(names.fromString(target.syntheticNameChar() +
2714 "enum" + target.syntheticNameChar() +
2715 "ordinal"),
2716 syms.intType, tree.sym);
2717 ordParam.mods.flags |= SYNTHETIC; ordParam.sym.flags_field |= SYNTHETIC;
2718
2719 MethodSymbol m = tree.sym;
2720 tree.params = tree.params.prepend(ordParam).prepend(nameParam);
2721 incrementParamTypeAnnoIndexes(m, 2);
2722
2723 m.extraParams = m.extraParams.prepend(ordParam.sym);
2724 m.extraParams = m.extraParams.prepend(nameParam.sym);
2725 Type olderasure = m.erasure(types);
2726 m.erasure_field = new MethodType(
2727 olderasure.getParameterTypes().prepend(syms.intType).prepend(syms.stringType),
2728 olderasure.getReturnType(),
2729 olderasure.getThrownTypes(),
2730 syms.methodClass);
2731 }
2732
2733 JCMethodDecl prevMethodDef = currentMethodDef;
2734 MethodSymbol prevMethodSym = currentMethodSym;
2735 try {
2736 currentMethodDef = tree;
2737 currentMethodSym = tree.sym;
2738 visitMethodDefInternal(tree);
2739 } finally {
2740 currentMethodDef = prevMethodDef;
2741 currentMethodSym = prevMethodSym;
2742 }
2743 }
2744 //where
2745 private void incrementParamTypeAnnoIndexes(MethodSymbol m,
2746 int amount) {
2747 for (final Attribute.TypeCompound anno : m.getRawTypeAttributes()) {
2748 // Increment the parameter_index of any existing formal
2749 // parameter annotations.
2750 if (anno.position.type == TargetType.METHOD_FORMAL_PARAMETER) {
2751 anno.position.parameter_index += amount;
2752 }
2753 }
2754 }
2755
2756 private void visitMethodDefInternal(JCMethodDecl tree) {
2757 if (tree.name == names.init &&
2758 (currentClass.isInner() || currentClass.isLocal())) {
2759 // We are seeing a constructor of an inner class.
2760 MethodSymbol m = tree.sym;
2761
2762 // Push a new proxy scope for constructor parameters.
2763 // and create definitions for any this$n and proxy parameters.
2764 proxies = proxies.dup(m);
2765 List<VarSymbol> prevOuterThisStack = outerThisStack;
2766 List<VarSymbol> fvs = freevars(currentClass);
2767 JCVariableDecl otdef = null;
2768 if (currentClass.hasOuterInstance())
2769 otdef = outerThisDef(tree.pos, m);
2770 List<JCVariableDecl> fvdefs = freevarDefs(tree.pos, fvs, m, PARAMETER);
2771
2772 // Recursively translate result type, parameters and thrown list.
2773 tree.restype = translate(tree.restype);
2774 tree.params = translateVarDefs(tree.params);
2775 tree.thrown = translate(tree.thrown);
2776
2777 // when compiling stubs, don't process body
2778 if (tree.body == null) {
2779 result = tree;
2780 return;
2781 }
2782
2783 // Add this$n (if needed) in front of and free variables behind
2784 // constructor parameter list.
2785 tree.params = tree.params.appendList(fvdefs);
2786 if (currentClass.hasOuterInstance()) {
2787 tree.params = tree.params.prepend(otdef);
2788 incrementParamTypeAnnoIndexes(m, 1);
2789 }
2790
2791 // If this is an initial constructor, i.e., it does not start with
2792 // this(...), insert initializers for this$n and proxies
2793 // before (pre-1.4, after) the call to superclass constructor.
2794 JCStatement selfCall = translate(tree.body.stats.head);
2795
2796 List<JCStatement> added = List.nil();
2797 if (fvs.nonEmpty()) {
2798 List<Type> addedargtypes = List.nil();
2799 for (List<VarSymbol> l = fvs; l.nonEmpty(); l = l.tail) {
2800 if (TreeInfo.isInitialConstructor(tree)) {
2801 final Name pName = proxyName(l.head.name);
2802 m.capturedLocals =
2803 m.capturedLocals.append((VarSymbol)
2804 (proxies.lookup(pName).sym));
2805 added = added.prepend(
2806 initField(tree.body.pos, pName));
2807 }
2808 addedargtypes = addedargtypes.prepend(l.head.erasure(types));
2809 }
|