Community
Participate
Working Groups
To easy the process of makeing JDT/UI *.java agnostic, the above method should become API.
Another one is: indexOfJavaLikeExtension. Aditionally it would be good to have something like: boolean isJavaLikeExtension(String extension).
May be we don't have to provide getJavaLikeExtensions if we have indexOfJavaLikeExtension and isJavaLikeExtension
I like isJavaLikeExtension(), that'd be cleaner than having to keep doing indexOfJavaLikeExtension()!=-1, as I've needed when looking at one of the issues in bug 89977, although of course indexOfJavaLikeExtension() will most likely be needed as well. I don't yet know whether getJavaLikeExtensions itself will be required.
Propose to add the following API on JavaCore: /** * Returns the index of the Java like extension of the given file name * or -1 if it doesn't end with a known Java like extension. * Java like extension are defined in the {@link org.eclipse.core.runtime.Platform#getContentTypeManager() * content type manager} for the org.eclipse.jdt.core.javaSource content type. * Note that the ".java" extension is always defined as a Java like extension. * * @param fileName the given file name * @return the index of the Java like extension of the given file name * or -1 if it doesn't end with a known Java like extension * @since 3.2 */ public static int indexOfJavaLikeExtension(String fileName) I'm not sure what the value of isJavaLikeExtension(String) would be ...
I believe getJavaLikeExtensions() is going to be needed, for example when mapping from a type name back to a path, each of extensions will need to be considered in turn. indexOfJavaLikeExtension() is okay as everything can be derived from that (plus getJavaLikeExtensions()). Although in my investigations for 89977 I've found the following useful: isJavaLikeFileName(String name) - as currently implemented in Util. This is nicer than isJavaLikeExtension() removeJavaLikeExtension(String name) - to strip off the extension, implemented like this: /** * Removes the file extension from the given file name, if it has a file * extension defined as Java source code. Otherwise the file name itself is * returned. * * @param fileName the name of a file * @return the fileName without the extension * @since 3.2 */ public static String removeJavaLikeExtension(String fileName) { if (fileName != null) { int i = Util.indexOfJavaLikeExtension(fileName); if (i != -1) { return fileName.substring(0, i); } } return fileName; } So far isJavaLikeFileName, removeJavaLikeExtension, and getJavaLikeExtensions have been sufficient, without having to call indexOfJavaLikeExtension directly, although of course if more appropriate the first two could be internal utilities in JDT/UI instead of API.
I would also favour 2 APIs isJavaLikeFileName, removeJavaLikeExtension. That's clearer than the 'all in one' 'indexOfJavaLikeExtension'.
So you don't need indexOfJavaLikeExtension ?
getJavaLikeExtensions() is the minimum required as public API, and the others could be implemented from that as internal methods. But usually it is it enough to just know whether a name is valid, or to remove the extension, so boolean isJavaLikeFileName(String) and String removeJavaLikeExtension(String) would make good clean API, and would save callers having to deal with char[][] and char indexes. So I'd say indexOfJavaLikeExtension() could remain as internal.
Matt, are you saying that you need getJavaLikeExtensions() ? Or are isJavaLikeFileName(String) and removeJavaLikeExtension(String) sufficient ?
Jerome, sorry if I wasn't clear. Yes, getJavaLikeExtensions() is required. isJavaLikeFileName(String) and removeJavaLikeExtension(String) would be nice extras.
I believe this API will meet JDT debug's needs. +1
Added JavaCore#getJavaLikeExtensions(), isJavaLikeFileName(String) and removeJavaLikeExtension(String). Added tests JavaLikeExtensionsTests.
Verified for 3.2 M4 using build I20051212-0010