changeset 52624:cac8618a27ec concise-method-declarations

tuning the finder for concise methods
author vromero
date Tue, 25 Sep 2018 12:11:37 -0700
parents abb5364fcb36
children 839a4787b5be
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java
diffstat 2 files changed, 22 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java	Tue Sep 25 09:40:01 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Analyzer.java	Tue Sep 25 12:11:37 2018 -0700
@@ -84,6 +84,7 @@
 import com.sun.tools.javac.util.Options;
 import com.sun.tools.javac.util.Position;
 
+import static com.sun.tools.javac.code.Flags.ANONCONSTR;
 import static com.sun.tools.javac.code.Flags.GENERATEDCONSTR;
 import static com.sun.tools.javac.code.TypeTag.CLASS;
 import static com.sun.tools.javac.tree.JCTree.Tag.APPLY;
@@ -354,23 +355,27 @@
             if (methodDec != null &&
                     ((methodDec.mods.flags & Flags.SYNTHETIC) == 0) &&
                     ((methodDec.mods.flags & Flags.ABSTRACT) == 0) &&
+//                    ((methodDec.mods.flags & Flags.GENERATEDCONSTR) == 0) &&
+//                    ((methodDec.mods.flags & Flags.ANONCONSTR) == 0) &&
                     methodDec.body.stats.size() == 1 &&
                     methodDec.name != names.init) {
                 JCStatement stat = methodDec.body.stats.head;
                 JCMethodInvocation apply = findInvocation(stat);
                 if (apply != null) {
                     Symbol qualifier = null;
+                    List<Symbol> paramsSyms = TreeInfo.symbols(methodDec.params);
+                    List<Symbol> argsSyms = TreeInfo.symbols(apply.args);
                     if (apply.meth.hasTag(SELECT)) {
                         JCFieldAccess fieldAcc = (JCFieldAccess)apply.meth;
-                        if (fieldAcc.selected.hasTag(Tag.IDENT)) {
+                        if (TreeInfo.isIdentOrIdentDotIdent(fieldAcc)) {
                             qualifier = TreeInfo.symbol(((JCFieldAccess) apply.meth).selected);
+                            qualifier = methodDec.params.isEmpty() || qualifier != methodDec.params.head.sym ? null : qualifier;
                         } else {
+                            // no chain().of().invocations() etc
                             return false;
                         }
                     }
                     if (methodDec.params.size() == apply.args.size() + (qualifier != null ? 1 : 0)) {
-                        List<Symbol> paramsSyms = TreeInfo.symbols(methodDec.params);
-                        List<Symbol> argsSyms = TreeInfo.symbols(apply.args);
                         argsSyms = qualifier != null ? argsSyms.prepend(qualifier) : argsSyms;
                         result = paramsSyms.equals(argsSyms);
                         if (result) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Tue Sep 25 09:40:01 2018 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java	Tue Sep 25 12:11:37 2018 -0700
@@ -163,8 +163,21 @@
         }
     }
 
-    /** Is this tree an identifier, possibly qualified by 'this'?
+    /** Is this tree an identifier, possibly qualified by a chain of identifiers?
      */
+    public static boolean isIdentOrIdentDotIdent(JCTree tree) {
+        switch (tree.getTag()) {
+            case PARENS:
+                return isIdentOrThisDotIdent(skipParens(tree));
+            case IDENT:
+                return true;
+            case SELECT:
+                return isIdentOrIdentDotIdent(((JCFieldAccess)tree).selected);
+            default:
+                return false;
+        }
+    }
+
     public static boolean isIdentOrThisDotIdent(JCTree tree) {
         switch (tree.getTag()) {
             case PARENS: