From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#22358: 24.5; Analysis and indentation of Java default interface methods incorrect Date: 13 Jan 2016 22:46:39 -0000 Organization: muc.de e.V. Message-ID: <20160113224639.96018.qmail@mail.muc.de> References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1452725240 18415 80.91.229.3 (13 Jan 2016 22:47:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Jan 2016 22:47:20 +0000 (UTC) Cc: 22358@debbugs.gnu.org To: Lanning Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jan 13 23:47:10 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aJUC5-0007UN-9O for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Jan 2016 23:47:09 +0100 Original-Received: from localhost ([::1]:39447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJUC4-00030f-JR for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Jan 2016 17:47:08 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJUC1-00030X-9E for bug-gnu-emacs@gnu.org; Wed, 13 Jan 2016 17:47:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJUBy-000803-1O for bug-gnu-emacs@gnu.org; Wed, 13 Jan 2016 17:47:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJUBx-0007zi-UE; Wed, 13 Jan 2016 17:47:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aJUBx-0001cs-H6; Wed, 13 Jan 2016 17:47:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Wed, 13 Jan 2016 22:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22358 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 22358-submit@debbugs.gnu.org id=B22358.14527252036225 (code B ref 22358); Wed, 13 Jan 2016 22:47:01 +0000 Original-Received: (at 22358) by debbugs.gnu.org; 13 Jan 2016 22:46:43 +0000 Original-Received: from localhost ([127.0.0.1]:48628 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aJUBf-0001cL-5Y for submit@debbugs.gnu.org; Wed, 13 Jan 2016 17:46:43 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:20980) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aJUBd-0001cD-9n for 22358@debbugs.gnu.org; Wed, 13 Jan 2016 17:46:41 -0500 Original-Received: (qmail 96019 invoked by uid 3782); 13 Jan 2016 22:46:39 -0000 In-Reply-To: X-Newsgroups: gnu.emacs.bug User-Agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.2-RELEASE-p7 (amd64)) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:111599 Archived-At: Hello, Lanning. In article 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).