2012/6/16 Eric M. Ludlam <ericludlam@gmail.com>
On 06/08/2012 03:22 AM, Fredrik Malmros wrote:

There seems to be an issue with visibility when completing members with
default visibility i.e. members or classes without access modifier in Java.
When calling semantic-analyze-possible-completion with point at ^ in the
class below, I get:
void baz(), but I expect to get both void baz() and void bar() since bar
is visible in Foo (and all other classes in the same package as Foo).

public class Foo {
     void bar () {}

     private void baz () {


Sorry for the late reply.

The java utilities return the protection of 'bar' as being 'nil', and 'baz' as being 'private'.  I think all that is needed is for java to override semantic-tag-protection to return private if nothing was specified.  (If private is the right thing.  I'm not that familiar with java.

This patch should solve the problem if 'private is the right answer. Please let me know if unspecified protection means private.



=== modified file 'lisp/cedet/semantic/java.el'
*** lisp/cedet/semantic/java.el 2011-11-07 20:57:12 +0000
--- lisp/cedet/semantic/java.el 2012-06-16 02:14:07 +0000
*** 173,178 ****
--- 173,187 ----
            'type (semantic-find-tag-by-overlay point))))

+ ;; Tag Protection
+ ;;
+ (define-mode-local-override semantic-tag-protection
+   java-mode (tag &optional parent)
+   "Return the protection of TAG in PARENT.
+ Override function for `semantic-tag-protection'."
+   (let ((prot (semantic-tag-protection-default tag parent)))
+     (or prot 'private)))
 ;; Prototype handler
 (defun semantic-java-prototype-function (tag &optional parent color)


no modifier i.e "package private" makes a field or method visible everywhere in its own package.  So unspecified and private does not mean the same thing; however, when completing members defined in the class we are in, the the modifier doesn't really matter since everything is visible in its own class.

I think the following sums the rules up:

public - accessible everywhere.
protected - accessible to the package classes and subclasses (that might be defined in other packages).
no modifier "package private" - accessible to classes in the same package.
private - accessible within the class.