Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » [howto] get the fully qualified class name of a *.class file
[howto] get the fully qualified class name of a *.class file [message #74323] Fri, 13 June 2003 21:17 Go to next message
Eclipse UserFriend
I have the folloing method and I'm trying to pass the absolute path to a
..class file and get back the fully qualified name of the .class file.
However eclipse keeps reporting that the packageName variable equals "".
What tidbit of info am I missing?

public String getFullClassName( String path )
{
IPath filePath = new Path( path );
IFile file =
ResourcesPlugin.getWorkspace().getRoot().getFile( filePath );
IClassFile element = (IClassFile) JavaCore.create(file);
IJavaElement parent = element.getParent();

// should return "com.abc", but instead returns ""
String packageName = parent.getElementName();

String className = element.getElementName();
className = className.substring( 0, className.length() - 6 );
className = packageName + "." + className;
return className;
}

String fqcn =
getFullClassName("d:\\runtime-workspace\bar\bin\com\abc\Foo.class ");

Binyan
Re: [howto] get the fully qualified class name of a *.class file [message #74360 is a reply to message #74323] Sat, 14 June 2003 03:20 Go to previous messageGo to next message
Eclipse UserFriend
Eclipse has problems with recognizing the package of a .class file
You can use IClassFileReader (I don't know whether it helps, I cannot
find the appropriate methods). What I do in my plugin is to iterate over
the output paths and check whether one of them is a prefix of the path
of my class file.

Genady

Binyan wrote:
> I have the folloing method and I'm trying to pass the absolute path to a
> .class file and get back the fully qualified name of the .class file.
> However eclipse keeps reporting that the packageName variable equals "".
> What tidbit of info am I missing?
>
> public String getFullClassName( String path )
> {
> IPath filePath = new Path( path );
> IFile file =
> ResourcesPlugin.getWorkspace().getRoot().getFile( filePath );
> IClassFile element = (IClassFile) JavaCore.create(file);
> IJavaElement parent = element.getParent();
>
> // should return "com.abc", but instead returns ""
> String packageName = parent.getElementName();
>
> String className = element.getElementName();
> className = className.substring( 0, className.length() - 6 );
> className = packageName + "." + className;
> return className;
> }
>
> String fqcn =
> getFullClassName("d:\\runtime-workspace\bar\bin\com\abc\Foo.class ");
>
> Binyan
>
Re: [howto] get the fully qualified class name of a *.class file [message #75448 is a reply to message #74323] Mon, 16 June 2003 09:45 Go to previous message
Eclipse UserFriend
Binyan,

You're trying the create a Java element handle on a resource that is not
part of the Java model.
..class files in the output directory are created by the Java builder as a
result of a build action.

As Genady said, your should use IClassFileReader.getClassName() and remove
the part after
the last slash ('/').

Jerome

"Binyan" <binyan357@yahoo.com> wrote in message
news:bcdt1v$a53$1@rogue.oti.com...
> I have the folloing method and I'm trying to pass the absolute path to a
> .class file and get back the fully qualified name of the .class file.
> However eclipse keeps reporting that the packageName variable equals "".
> What tidbit of info am I missing?
>
> public String getFullClassName( String path )
> {
> IPath filePath = new Path( path );
> IFile file =
> ResourcesPlugin.getWorkspace().getRoot().getFile( filePath );
> IClassFile element = (IClassFile) JavaCore.create(file);
> IJavaElement parent = element.getParent();
>
> // should return "com.abc", but instead returns ""
> String packageName = parent.getElementName();
>
> String className = element.getElementName();
> className = className.substring( 0, className.length() - 6 );
> className = packageName + "." + className;
> return className;
> }
>
> String fqcn =
> getFullClassName("d:\\runtime-workspace\bar\bin\com\abc\Foo.class ");
>
> Binyan
>
Previous Topic:CTRL+ARROW_UP and CTRL+ARROW_DOWN not heard in TextEditor
Next Topic:Getting the classpath for a plugin
Goto Forum:
  


Current Time: Mon Jul 07 23:07:52 EDT 2025

Powered by FUDForum. Page generated in 0.07665 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top