Bug 115067 - Util#getJavaLikeExtensions should become API
Summary: Util#getJavaLikeExtensions should become API
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M4   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 89977
  Show dependency tree
 
Reported: 2005-11-04 09:14 EST by Dirk Baeumer CLA
Modified: 2005-12-12 13:05 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2005-11-04 09:14:30 EST
To easy the process of makeing JDT/UI *.java agnostic, the above method should
become API.
Comment 1 Dirk Baeumer CLA 2005-11-04 10:54:39 EST
Another one is: indexOfJavaLikeExtension.

Aditionally it would be good to have something like:

boolean isJavaLikeExtension(String extension).
Comment 2 Dirk Baeumer CLA 2005-11-04 11:03:45 EST
May be we don't have to provide getJavaLikeExtensions if we have
indexOfJavaLikeExtension and isJavaLikeExtension
Comment 3 Matt Chapman CLA 2005-11-04 11:54:22 EST
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.
Comment 4 Jerome Lanneluc CLA 2005-11-15 13:22:01 EST
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 ...
Comment 5 Matt Chapman CLA 2005-11-15 15:02:12 EST
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.
Comment 6 Martin Aeschlimann CLA 2005-11-16 04:01:01 EST
I would also favour 2 APIs isJavaLikeFileName, removeJavaLikeExtension. That's
clearer than the 'all in one' 'indexOfJavaLikeExtension'.
Comment 7 Jerome Lanneluc CLA 2005-11-16 04:18:11 EST
So you don't need indexOfJavaLikeExtension ?
Comment 8 Matt Chapman CLA 2005-11-16 04:43:35 EST
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.
Comment 9 Jerome Lanneluc CLA 2005-11-16 06:52:40 EST
Matt, are you saying that you need getJavaLikeExtensions() ? Or are
isJavaLikeFileName(String) and removeJavaLikeExtension(String) sufficient ?
Comment 10 Matt Chapman CLA 2005-11-16 08:44:46 EST
Jerome, sorry if I wasn't clear. Yes, getJavaLikeExtensions() is required.
isJavaLikeFileName(String) and removeJavaLikeExtension(String) would be nice
extras.
Comment 11 Darin Wright CLA 2005-11-16 09:36:55 EST
I believe this API will meet JDT debug's needs. +1
Comment 12 Jerome Lanneluc CLA 2005-11-17 03:53:48 EST
Added JavaCore#getJavaLikeExtensions(), isJavaLikeFileName(String) and
removeJavaLikeExtension(String).
Added tests JavaLikeExtensionsTests.
Comment 13 David Audel CLA 2005-12-12 13:05:24 EST
Verified for 3.2 M4 using build I20051212-0010