Eclipse JDT
Release 3.2

org.eclipse.jdt.apt.core.util
Class AptConfig

java.lang.Object
  extended by org.eclipse.jdt.apt.core.util.AptConfig

public class AptConfig
extends Object

Accesses configuration data for APT. Note that some of the code in org.eclipse.jdt.ui reads and writes settings data directly, rather than calling into the methods of this class. This class is static. Instances should not be constructed. Helpful information about the Eclipse preferences mechanism can be found at: http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-core-home/documents/user_settings/faq.html


Method Summary
static void addProcessorOption(IJavaProject jproj, String key, String val)
          Add the equivalent of -Akey=val to the list of processor options.
static void dispose()
          Flush unsaved preferences and perform any other config-related shutdown.
static IFactoryPath getDefaultFactoryPath(IJavaProject jproj)
          Get a factory path corresponding to the default values: if jproj is non-null, return the current workspace factory path (workspace prefs are the default for a project); if jproj is null, return the default list of plugin factories (which is the "factory default").
static IFactoryPath getFactoryPath(IJavaProject jproj)
          Get the factory path for a given project or for the workspace.
static String getGenSrcDir(IJavaProject jproject)
           
static Map<String,String> getProcessorOptions(IJavaProject jproj)
          Get the options that are presented to annotation processors by the AnnotationProcessorEnvironment.
static Map<String,String> getRawProcessorOptions(IJavaProject jproj)
          Get the options that are presented to annotation processors by the AnnotationProcessorEnvironment.
static String getString(IJavaProject jproj, String optionName)
          Helper method to get a single preference setting, e.g., APT_GENSRCDIR.
static boolean hasProjectSpecificFactoryPath(IJavaProject jproj)
          Has an explicit factory path been set for the specified project, or is it just defaulting to the workspace settings?
static void initialize()
          Initialize preferences lookups, and register change listeners.
static boolean isAutomaticProcessorOption(String key)
          Is the named option automatically generated in getProcessorOptions(), or did it come from somewhere else, such as a -A processor option?
static boolean isEnabled(IJavaProject jproject)
          Is annotation processing turned on for this project?
static void removeProcessorOption(IJavaProject jproj, String key)
          Remove an option from the list of processor options.
static void setEnabled(IJavaProject jproject, boolean enabled)
          Turn annotation processing on or off for this project.
static void setFactoryPath(IJavaProject jproj, IFactoryPath path)
          Set the factory path for a given project or for the workspace.
static void setGenSrcDir(IJavaProject jproject, String dirString)
           
static void setProcessorOptions(Map<String,String> options, IJavaProject jproj)
          Set all the processor options in one call.
static boolean validateGenSrcDir(IJavaProject jproject, String dirName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addProcessorOption

public static void addProcessorOption(IJavaProject jproj,
                                      String key,
                                      String val)
Add the equivalent of -Akey=val to the list of processor options.

Parameters:
key - must be a nonempty string. It should only include the key; that is, it should not start with "-A".
jproj - a project, or null to set the option workspace-wide.
val - can be null (equivalent to -Akey). This does not mean remove the key; for that functionality, @see #removeProcessorOption(IJavaProject, String).

removeProcessorOption

public static void removeProcessorOption(IJavaProject jproj,
                                         String key)
Remove an option from the list of processor options.

Parameters:
jproj - a project, or null to remove the option workspace-wide.
key - must be a nonempty string. It should only include the key; that is, it should not start with "-A".

getProcessorOptions

public static Map<String,String> getProcessorOptions(IJavaProject jproj)
Get the options that are presented to annotation processors by the AnnotationProcessorEnvironment. The -A and = are stripped out, so (key, value) is the equivalent of -Akey=value. This method returns some options which are set programmatically but are not directly editable, are not displayed in the configuration GUI, and are not persisted to the preference store. This is meant to emulate the behavior of Sun's apt command-line tool, which passes most of its command line options to the processor environment. The programmatically set options are: -classpath [set to Java build path] -sourcepath [set to Java source path] -s [set to generated src dir] -d [set to binary output dir] -target [set to compiler target version] -source [set to compiler source version]

Parameters:
jproj - a project, or null to query the workspace-wide setting.
Returns:
a mutable, possibly empty, map of (key, value) pairs. The value part of a pair may be null (equivalent to "-Akey"). The value part can contain spaces, if it is quoted: -Afoo="bar baz".

setProcessorOptions

public static void setProcessorOptions(Map<String,String> options,
                                       IJavaProject jproj)
Set all the processor options in one call. This will delete any options that are not passed in, so callers who do not wish to destroy pre-existing options should use addProcessorOption() instead.

Parameters:
options - a map of keys to values. The keys should not include any automatic options (@see #isAutomaticProcessorOption(String)), and the "-A" should not be included. That is, to perform the equivalent of the apt command line "-Afoo=bar", use the key "foo" and the value "bar". Keys cannot contain spaces; values can contain anything at all. Keys cannot be null, but values can be.

isAutomaticProcessorOption

public static boolean isAutomaticProcessorOption(String key)
Is the named option automatically generated in getProcessorOptions(), or did it come from somewhere else, such as a -A processor option?

Parameters:
key - the name of an AnnotationProcessorEnvironment option
Returns:
true if the option is automatically set.

getRawProcessorOptions

public static Map<String,String> getRawProcessorOptions(IJavaProject jproj)
Get the options that are presented to annotation processors by the AnnotationProcessorEnvironment. The -A and = are stripped out, so (key, value) is the equivalent of -Akey=value. This method differs from getProcessorOptions in that the options returned by this method do NOT include any programmatically set options. This method returns only the options that are persisted to the preference store and that are displayed in the configuration GUI.

Parameters:
jproj - a project, or null to query the workspace-wide setting. If jproj is not null, but the project has no per-project settings, this method will fall back to the workspace-wide settings.
Returns:
a mutable, possibly empty, map of (key, value) pairs. The value part of a pair may be null (equivalent to "-Akey"). The value part can contain spaces, if it is quoted: -Afoo="bar baz".

dispose

public static void dispose()
Flush unsaved preferences and perform any other config-related shutdown. This is called once, from AptPlugin.shutdown().


initialize

public static void initialize()
Initialize preferences lookups, and register change listeners. This is called once, from AptPlugin.startup().


isEnabled

public static boolean isEnabled(IJavaProject jproject)
Is annotation processing turned on for this project?

Parameters:
jproject - an IJavaProject, or null to request workspace preferences.
Returns:
true if annotation processing is turned on.

setEnabled

public static void setEnabled(IJavaProject jproject,
                              boolean enabled)
Turn annotation processing on or off for this project.

Parameters:
jproject - an IJavaProject, or null to set workspace preferences.
enabled -

getDefaultFactoryPath

public static IFactoryPath getDefaultFactoryPath(IJavaProject jproj)
Get a factory path corresponding to the default values: if jproj is non-null, return the current workspace factory path (workspace prefs are the default for a project); if jproj is null, return the default list of plugin factories (which is the "factory default").


getFactoryPath

public static IFactoryPath getFactoryPath(IJavaProject jproj)
Get the factory path for a given project or for the workspace.

Parameters:
jproj - the project, or null to get the factory path for the workspace.
Returns:
a FactoryPath representing the current state of the specified project. Note that changes made to the project after this call will not affect the returned object - that is, it behaves like a value, not like a live link to the project state.

setFactoryPath

public static void setFactoryPath(IJavaProject jproj,
                                  IFactoryPath path)
                           throws CoreException
Set the factory path for a given project or for the workspace. Does not perform any validation on the path.

Parameters:
jproj - the project, or null to set the factory path for the workspace.
path - a factory path, or null to reset the factory path to the default.
Throws:
CoreException

hasProjectSpecificFactoryPath

public static boolean hasProjectSpecificFactoryPath(IJavaProject jproj)
Has an explicit factory path been set for the specified project, or is it just defaulting to the workspace settings?

Returns:
true if there is a project-specific factory path.

getString

public static String getString(IJavaProject jproj,
                               String optionName)
Helper method to get a single preference setting, e.g., APT_GENSRCDIR. This is a different level of abstraction than the processor -A settings! The -A settings are all contained under one single preference node, APT_PROCESSOROPTIONS. Use @see #getProcessorOptions(IJavaProject) to get the -A settings; use @see #getOptions(IJavaProject) to get all the preference settings as a map; and use this helper method to get a single preference setting.

Parameters:
jproj - the project, or null for workspace.
optionName - a preference constant from @see AptPreferenceConstants.
Returns:
the string value of the setting.

getGenSrcDir

public static String getGenSrcDir(IJavaProject jproject)

setGenSrcDir

public static void setGenSrcDir(IJavaProject jproject,
                                String dirString)

validateGenSrcDir

public static boolean validateGenSrcDir(IJavaProject jproject,
                                        String dirName)

Eclipse JDT
Release 3.2

Copyright (c) IBM Corp. and others 2000, 2006. All Rights Reserved.