unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Lanning <lanning@gmail.com>
Cc: 22358@debbugs.gnu.org
Subject: bug#22358: 24.5; Analysis and indentation of Java default interface methods incorrect
Date: 13 Jan 2016 22:46:39 -0000	[thread overview]
Message-ID: <20160113224639.96018.qmail@mail.muc.de> (raw)
In-Reply-To: <mailman.2245.1452630247.843.bug-gnu-emacs@gnu.org>

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).






  parent reply	other threads:[~2016-01-13 22:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 20:23 bug#22358: 24.5; Analysis and indentation of Java default interface methods incorrect Lanning
     [not found] ` <mailman.2245.1452630247.843.bug-gnu-emacs@gnu.org>
2016-01-13 22:46   ` Alan Mackenzie [this message]
     [not found]     ` <CAH0R2Fvn7=n==jZOc06ssb4T-cgZdeZmgYLte4Rm1E4=waA=8A@mail.gmail.com>
2016-01-23 19:52       ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160113224639.96018.qmail@mail.muc.de \
    --to=acm@muc.de \
    --cc=22358@debbugs.gnu.org \
    --cc=lanning@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).