Since: Version 1.0.2
Description: A naming strategy used when creating new classpath variables. This extension enables developers to control the naming of classpath variables created by the plugin and impose thir own naming conventions or any other rational behind the generated names.
Configuration Markup:
<!ELEMENT extension (classpathVarNamingStrategy)>
<!ATTLIST extension
point CDATA #REQUIRED
id CDATA #IMPLIED
name CDATA #IMPLIED
>
<!ELEMENT classpathVarNamingStrategy EMPTY>
A naming strategy used when creating new classpath variables.
<!ATTLIST classpathVarNamingStrategy<extension id="myID" name="myPoint" point="com.danikenan.eclipse.classlocator.classpathVarNamingStrategy"> <classpathVarNamingStrategy class="myPackage.MyStrategy"/> </extension>
API Information: The strategy must implement com.danikenan.eclipse.classlocator.ClasspathVarNamingStrategy
which defines a single method:
/** * Suggest a name for classpath variable corresponding to the path given. * Keep in mind that if a name is rejected, you need to change it, otherwise there is * a possibility for an endless loop. * * @param path the path for the classpath var. * @param rejectedName a previously rejected name, if such exists or null, if first * time for path. * @return String the suggested name. */ public String suggestName(IPath path, String rejectedName);For each path, a new strategy instance is created. It is called with the path and a null rejectedName. If the name returned by a call is rejected (the var name exists, for example) then the strategy is called again, with the rejected name provided to it, in addition to the path. A sample implementation could look like:
public class MyStrategy implements ClasspathVarNamingStrategy { int varVersion = 0; String baseVarName = null; public String suggestName(IPath path, String rejectedName){ String varName; if(rejectedName == null){ baseVarName = "MYCOMPANY_" + path.lastSegment().replace('.', '_').toUpperCase(); varName = baseVarName; } else{ varName = baseVarName + (++varVersion); } return varName; } }
Supplied Implementation: The default naming generation strategy is an inner class that reads:
public static class DefaultClasspathVarNamingStrategy implements ClasspathVarNamingStrategy{ int varVersion = 0; String baseVarName = null; public String suggestName(IPath path, String rejectedName){ String varName; if(rejectedName == null){ baseVarName = path.lastSegment().replace('.', '_').toUpperCase(); varName = baseVarName; } else{ varName = baseVarName + (++varVersion); } return varName; } }
Copyright (C) 2002 Dani Kenan.