bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#22358: 24.5; Analysis and indentation of Java default interface meth


From: Alan Mackenzie
Subject: bug#22358: 24.5; Analysis and indentation of Java default interface methods incorrect
Date: 13 Jan 2016 22:46:39 -0000
User-agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.2-RELEASE-p7 (amd64))

Hello, Lanning.

In article <mailman.2245.1452630247.843.bug-gnu-emacs@gnu.org> you wrote:
> [-- text/plain, encoding 7bit, charset: UTF-8, 141 lines --]

> Consider the Java interface

>     public interface IndentDefaultInterfaceMethod {
>         String doSomething(Foo foo);
>         // The"default" in the next line is *not* a case tag...
>         default String doSomething() {
>             return doSomething(Foo.getDefaultFoo());
>         }
>     } // IndentDefaultInterfaceMethod

> Syntactic analysis of the "default" line declares it a case-label.
> As a result it gets indented to align with the "public" modifier.

Yes.  First of all, thanks for taking the trouble to report this problem,
and thanks even more for distilling it into a nice short test case which
is easy to work with.

Please see the patch below.  After applying it, it is utterly
essential to recompile several files in CC Mode, to ensure that a change
to one of the macros in cc-langs.el is propagated through the rest of the
code.  So after applying the patch (in directory
.../emacs-24.5/lisp/progmodes), compile as follows

$ emacs -Q -batch -f batch-byte-compile cc-*.el

.

> Instead it should (probably) be treated the same as an access modifier.
> But boy howdy is that code in c-guess-basic-syntax complicated!

:-)  Actually, c-guess-basic-syntax is relatively simple, it's just long,
long, long; it's little more than a big `cond' form.  The place where the
current bug was happening was at "CASE 14: A case or default label",
where a match happened with no more checking than seeing the keyword
"default".  I've added more rigorous checking to that.

Would you please let me know whether the patch solves the problem
completely, or whether there are still issues with it remaining to be
fixed.

Thanks!

> In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.16.6)
>  of 2015-09-17 on lgw01-52, modified by Debian
> Windowing system distributor `The X.Org Foundation', version 11.0.11702000
> System Description: Ubuntu 15.10

OK, here's the patch:



diff -r 03dea479cb53 cc-engine.el
--- a/cc-engine.el      Tue Jan 12 17:50:29 2016 +0000
+++ b/cc-engine.el      Wed Jan 13 22:26:10 2016 +0000
@@ -9782,7 +9782,20 @@
                                       paren-state)))
 
        ;; CASE 14: A case or default label
-       ((looking-at c-label-kwds-regexp)
+       ((save-excursion
+         (and (looking-at c-label-kwds-regexp)
+              (or (c-major-mode-is 'idl-mode)
+                  (and
+                   containing-sexp
+                   (goto-char containing-sexp)
+                   (eq (char-after) ?{)
+                   (progn (c-backward-syntactic-ws) t)
+                   (eq (char-before) ?\))
+                   (c-go-list-backward)
+                   (progn (c-backward-syntactic-ws) t)
+                   (c-simple-skip-symbol-backward)
+                   (looking-at c-block-stmt-2-key)))
+            ))
        (if containing-sexp
            (progn
              (goto-char containing-sexp)
@@ -9798,6 +9811,7 @@
        ((save-excursion
          (back-to-indentation)
          (and (not (looking-at c-syntactic-ws-start))
+              (not (looking-at c-label-kwds-regexp))
               (c-forward-label)))
        (cond (containing-decl-open
               (setq placeholder (c-add-class-syntax 'inclass
diff -r 03dea479cb53 cc-langs.el
--- a/cc-langs.el       Tue Jan 12 17:50:29 2016 +0000
+++ b/cc-langs.el       Wed Jan 13 22:26:10 2016 +0000
@@ -1884,7 +1884,7 @@
         "bindsTo" "delegatesTo" "implements" "proxy" "storedOn")
   ;; Note: "const" is not used in Java, but it's still a reserved keyword.
   java '("abstract" "const" "final" "native" "private" "protected" "public"
-        "static" "strictfp" "synchronized" "transient" "volatile")
+        "default" "static" "strictfp" "synchronized" "transient" "volatile")
   pike '("final" "inline" "local" "nomask" "optional" "private" "protected"
         "public" "static" "variant"))
 


[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).






reply via email to

[Prev in Thread] Current Thread [Next in Thread]