How to include standard jdk library in emacs semantic?
Asked Answered
W

3

6

I'm using Emacs 23.2. Here's how I'm loading semantic:

(setq semantic-default-submodes '(global-semantic-idle-scheduler-mode
                  global-semanticdb-minor-mode
                  global-semantic-idle-summary-mode
                  global-semantic-mru-bookmark-mode))
(semantic-mode 1)

So, if I create a simple java file and visit it, I get code completion for locally defined methods and classes. But I can't figure out how to make semantic aware of jdk libraries. For example, if I try semantic-ia-complete-symbol on a String variable, I get Cannot find types for 'String blah'.

Does anyone know how to load the jdk libraries into semanticdb so code completion of standard object types like String are available?

Wahkuna answered 13/11, 2010 at 17:19 Comment(0)
G
3

Starting with CEDET 1.1, Semantic has support for retrieving class information through javap. You need to setup cedet-java-jdk-root variable to JAVA_HOME, and populate semanticdb-javap-classpath variable with list of paths to Java's system jars, like rt.jar, etc.

There is an article (in Russian, but you can get translation) about setting Semantic up for Java completion - please look there for more details.

Guenevere answered 9/5, 2012 at 6:18 Comment(0)
S
1

If you unzip src.zip that is found in $JAVA_HOME you can add a hook for you java mode like this:

(add-hook 'java-mode-hook
  '(lambda ()
     (semantic-add-system-include (getenv "JAVA_HOME") 'java-mode)))

It solves the problem for me with Emacs 23.3 and CEDET 1.1.

Stopgap answered 8/5, 2012 at 15:24 Comment(0)
I
0

Haven't tried CEDET in a while, so I'll blindly ask a few questions that might give insight into your problem.

  1. I assume JDK is on your path, and Emacs can find it?
  2. Since JDK is basically a bunch of jar files without source code, can Semantic parse that? Example: if you make your own Class1.java, compile it to Class1.class and then delete Class1.java, when you write Class2.java and reference some methods from Class1, can Semantic find them?
  3. Have you tried JDEE?
Ichthyornis answered 16/11, 2010 at 8:40 Comment(1)
Yes, jdk is on my path. I found src.jar inside the os x jdk and even tried extracting and visiting String.java. It seems semantic parses String.java into semanticdb, but when I'm back inside my custom java project, it can't seem to find methods for Strings. I've looked at JDEE, but my goal here is to understand semantic first before adding more complexity. I think it's mostly my ignorance of how semantic works, so I'll keep digging, but thanks for your response!Wahkuna

© 2022 - 2024 — McMap. All rights reserved.