Community
Participate
Working Groups
Hello, I wrote the following code, which is part of a Java project, *not* a plug-in. It compiles fine with the appropriate class-path: public class ASTTest { public static void main(final String[] args) { CompilationUnit compilationUnit = AST.parseCompilationUnit( "class A { private int i; }".toCharArray()); compilationUnit.accept(new ASTVisitor() { public boolean visit(final TypeDeclaration node) { System.out.println(node.getName()); return true; } }); } } When I run it, I get an exception: java.lang.NullPointerException at org.eclipse.jdt.core.JavaCore.getOptions(JavaCore.java:1224) at org.eclipse.jdt.core.dom.CompilationUnitResolver.parse(CompilationUnitResolv er.java:180) at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:359) at yann.test.ast.ASTTest.main(ASTTest.java:39) Exception in thread "main" It seems to me that the AST class is tightly coupled with the plug-in management mechanism. Indeed, the exception arises in class JavaCore at the following line: public static Hashtable getOptions() { Hashtable options = new Hashtable(10); // see #initializeDefaultPluginPreferences() for changing default settings Preferences preferences = getPlugin().getPluginPreferences(); ///////////////////////////////////////////////////////////// Here HashSet optionNames = JavaModelManager.getJavaModelManager().OptionNames; // get preferences set to their default String[] defaultPropertyNames = preferences.defaultPropertyNames(); for (int i = 0; i < defaultPropertyNames.length; i++){ String propertyName = defaultPropertyNames[i]; if (optionNames.contains(propertyName)){ options.put(propertyName, preferences.getString(propertyName)); } } // get preferences not set to their default String[] propertyNames = preferences.propertyNames(); for (int i = 0; i < propertyNames.length; i++){ String propertyName = propertyNames[i]; if (optionNames.contains(propertyName)){ options.put(propertyName, preferences.getString(propertyName)); } } // get encoding through resource plugin options.put(CORE_ENCODING, ResourcesPlugin.getEncoding()); return options; } Because the JavaCode class is never initialized, the private static field (!) JAVA_CORE_PLUGIN is set to null and thus the getPlugin() method returns null. Yann-Gaël Guéhéneuc
If JavaCore plug-in is never started properly, various things won't work, like the background indexing which won't get started. No action planned, the plug-in is to be started.
No action planned.
Sure. However, I do not understand why parsing through the AST class should be plug- in dependent. The parser (I believe) does not (should not) care whether indexing and other goodies are enabled... I think it must be left to the developper to start or not the JavaCore plug-in as long as she knows what she will get. (Also, the JAVA_CORE_PLUGIN private static variable seemed to me as a quick fix?)