5

I've been trying to get my Emacs config for Java development working. It's pretty good - I've gotten malabar-mode working and have GNU Global working for tag browsing. The one thing I can't get working is getting semanticdb to use gnu global properly. None of my imports are found.

First, this is a Maven multi-module project with all sources checked out from the top-level root project folder. All other projects are below this one in the directory tree. There is a single GTAGS database in this root folder covering everything.

Things that work:

  • M-x gtags-find-tag RET symbol RET works fine, so the database is good and global can find it.
  • M-x cedet-gnu-global-version-check works and reports that my version is good.
  • M-x cedet-gnu-global-expand-filename works
  • M-x semanticdb-find-test-translate-path shows a "GNU Global Search Table" when in a Java buffer
  • I have the JDK source folder set as a system include folder, so core Java imports are parsed properly.

My java config is as follows (cedet initialization is earlier in the file):

(add-local-load-path "malabar/lisp")

(require 'malabar-mode)
(setq malabar-groovy-lib-dir (concat emacs-local-site-lisp "malabar/lib"))
(add-to-list 'auto-mode-alist '("\\.java\\'" . malabar-mode))

;; enable semanticdb support for gnu global
(when (cedet-gnu-global-version-check t)
  (semanticdb-enable-gnu-global-databases 'java-mode))

(add-hook 'java-mode-hook
    (lambda ()
    (gtags-mode 1)))

(add-hook 'java-mode-hook 'flymake-mode-on)

(defun my-java-flymake-init ()
  (list "javac" (list (flymake-init-create-temp-buffer-copy
                   'flymake-create-temp-with-folder-structure))))

(add-to-list 'flymake-allowed-file-name-masks
         '("\\.java$" my-java-flymake-init flymake-simple-cleanup))

(add-hook 'java-mode-hook
      '(lambda ()
         (semantic-add-system-include (getenv "JAVA_HOME") 'java-mode)))
DuckPuppy
  • 1,336
  • 1
  • 12
  • 21
  • Please, look onto my [answer to similar question][1] - it describes how to use javap + Semantic [1]: http://stackoverflow.com/questions/4173737/how-to-include-standard-jdk-library-in-emacs-semantic/10510736#10510736 – Alex Ott May 17 '12 at 09:09
  • 1
    Thanks, but I've already seen that and set that up. The problem is that Semantic doesn't know where the other source files are. Since this is in a nested Maven submodule the source files will be in some other project's folder. If I haven't built that project there won't even be any class files for javap to process. In some cases, the class files are in a jar somewhere in my local maven repository. Using the GNU Global database will at least allow SemanticDB to find and parse the unknown files from the other submodule projects using the tag database. – DuckPuppy May 21 '12 at 15:05
  • Please, try latest version of CEDET (from bzr) - it was extended to work with Maven, plus some Java-related fixes were made, so you'll get names completion also for 3rd party libraries – Alex Ott Nov 02 '12 at 09:53

1 Answers1

3

The answer is related to how your projects are set up, and if you are using EDE. EDE is Emacs Development Envornment (play on IDE) and is how CEDET tracks which files belong to your project. That limiter is related to both performance (searching less stuff) and preventing configurations from one project bleeding into another.

Unfortunately, Maven is not yet supported in CEDET/EDE. You can, however, just tag the root of your project, and I'd guess ede-cpp-root (usually used for C++ projects) might be sufficient. We should probably make a java version of that.

Anyway, EDE can be configured to use GNU Global to find files quickly (see the manual for GNU Global support with both EDE and Semantic) but your GTAGS file needs to be at the project root.

If you are in project-1, and expect to jump to files in project-2, and GTAGS is as the root of project-1, then it won't work. You'd have to move your GTAGS file and EDE project up to a common parent directory.

In your current setup, if everything is already under a common directory with GTAGS, then it is more likely you just need to setup an EDE project to hang the GTAGS file finding feature.

There are threads in the cedet-devel mailing list archive of a couple folks who have had some success in this.

Eric
  • 3,959
  • 17
  • 15
  • So, an EDE project would be required for SemanticDB to use the GNU Global database? I thought enabling GNU Global support for SemanticDB would simply use the default GNU Global search strategy for finding tag files and using them. – DuckPuppy Jun 05 '12 at 17:55
  • If your source file is in the same directory as a GTAGS file, it can be used to find other tags. If you want GTAGS to be used to find the location of files (like include files) that is part of EDE, not SemanticDB. SemanticDB relies on EDE to find files so they can be indexed and searched for symbols. – Eric Jun 08 '12 at 01:13
  • I have to ask, then - what is the purpose of semanticdb-enable-gnu-global-databases? – DuckPuppy Jun 09 '12 at 03:35
  • The gtags minor mode lets me find other tags as long as the tags files are somewhere higher up the directory tree. I was hoping that setting would let SemanticDB take advantage of them too. I can already jump between projects with my current tag setup. I want Semantic support for autocompletion. – DuckPuppy Jun 09 '12 at 03:44
  • Semantic supports different kinds of databases, so you need to enable the GNU Global databases. The global databases are broad and lack the kinds of data needed for smart completion, so whenever a tag is looked up via Global, the results need to be pulled in and parsed by the Semantic parsers to get usable tags. That's what gets enabled by the enable command. In EDE, you need to configure that to also use the file location tables in GNU Global to help it find files in your project. Semantic will only find files identified via relative path names. Anything on some 'path' is done via EDE. – Eric Jun 14 '12 at 01:21