Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to get the fully qualified name of the type of a variable
How to get the fully qualified name of the type of a variable [message #30621] Tue, 20 May 2003 00:03 Go to next message
Eclipse UserFriend
Hi,

I have a piece of code which is similar to this

class A {
public String one;
}

when i try to use JDOM and get the contents of this java file what i get
the type of the variable one is "String", but what I expect is that it
should give me the fully qualified name of String (i.e.,)
"java.lang.String", coz i do some validation based on the fully qualified
name. Plz provide me the details how can i get the corresponding qualified
name.

This is the same case with the SuperClasses, for eg.,
package org;
public class A {
public String one;
}

package org;
public class B
extends A {
public String two;
}

when i try to get the SuperClass Name it gives me A and not org.A
Re: How to get the fully qualified name of the type of a variable [message #30798 is a reply to message #30621] Tue, 20 May 2003 05:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adam_kiezun.ch.ibm.spam.protection.com

try IType.resolveType(String)

a.
--
eclipse.org
Re: How to get the fully qualified name of the type of a variable [message #31008 is a reply to message #30798] Tue, 20 May 2003 08:51 Go to previous messageGo to next message
Eclipse UserFriend
When i try to get an IType it states that the IType object is not open.
When i try to perform any action on that it states that the corresponding
element does not exist.

I get the IType through ICompilationUnit.getType(TypeName)

The compilation unit is obtained from

JavaCore.createCompilationUnitFrom(IFile) method.

When i try the open method on ICompilationUnit it states that the element
does not exist.
Re: How to get the fully qualified name of the type of a variable [message #31043 is a reply to message #31008] Tue, 20 May 2003 08:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adam_kiezun.ch.ibm.spam.protection.com

does the IFile exist? call exists() on it
is it on the classpath of a Java project?
a.
--
eclipse.org
Re: How to get the fully qualified name of the type of a variable [message #31184 is a reply to message #31043] Tue, 20 May 2003 10:01 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I have the file in my project but it gives me false when i check for the
exists()
Re: How to get the fully qualified name of the type of a variable [message #31250 is a reply to message #31184] Tue, 20 May 2003 10:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adam_kiezun.ch.ibm.spam.protection.com

> I have the file in my project but it gives me false when i check for the
> exists()

how did you get the handle to the file?
a.
--
eclipse.org
Re: How to get the fully qualified name of the type of a variable [message #31280 is a reply to message #31250] Tue, 20 May 2003 10:54 Go to previous messageGo to next message
Eclipse UserFriend
String fileName = \"c:\\A.java\";
Path path = new Path(fileName);
IFile file = FrontierSuitePlugin.getWorkspace().getRoot().getFile(path);
System.out.println(\"The existence of file is \" + file.exists());
ICompilationUnit compUnit = JavaCore.createCompilationUnitFrom(file);

This is how i got the handle to the file and the ICompilationUnit.
Re: How to get the fully qualified name of the type of a variable [message #31309 is a reply to message #31280] Tue, 20 May 2003 11:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adam_kiezun.ch.ibm.spam.protection.com

> String fileName = \"c:\\A.java\";
> Path path = new Path(fileName);
> IFile file = FrontierSuitePlugin.getWorkspace().getRoot().getFile(path);

i think this cannot work (by looking at IContainer javadoc)
path should be relative to the container

a.
--
eclipse.org
Re: How to get the fully qualified name of the type of a variable [message #31533 is a reply to message #31309] Tue, 20 May 2003 11:13 Go to previous messageGo to next message
Eclipse UserFriend
Sorry

I had given a wrong code snippet, i made the path as relative using
path.makeRelative() method and passed on the same to the IFile even then i
get false for the existence
Re: How to get the fully qualified name of the type of a variable [message #31567 is a reply to message #31533] Tue, 20 May 2003 11:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: adam_kiezun.ch.ibm.spam.protection.com

> I had given a wrong code snippet, i made the path as relative using
> path.makeRelative() method and passed on the same to the IFile even then i
> get false for the existence

i don't know a lot about Paths
but i looked at the javadoc and i think
it still cannot work

put the file under a java project in the workspace
it must be one the classpath anyway fo you to be able to resolve anything in it

a.
--
eclipse.org
Re: How to get the fully qualified name of the type of a variable [message #34639 is a reply to message #31567] Thu, 22 May 2003 00:04 Go to previous messageGo to next message
Eclipse UserFriend
My file is under a javaProject and when i try to get the IFile instance of
that file it gives me it does not exists.
Re: How to get the fully qualified name of the type of a variable [message #34672 is a reply to message #31567] Thu, 22 May 2003 01:41 Go to previous message
Eclipse UserFriend
Hi Adam,

Thanx a lot for ur suggesstions. It worked out fine for me when i got the
IFile through the
ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( path). When i
checked this IFile instance's existence it gave me true and proceded with
other operations. Then tried to resolve the type using IType's
resolveType() method and got the corresponding qualified name of the
respective types.

Once again I thank for ur valuable suggestions.
Previous Topic:simple help please
Next Topic:how 2 do the following programatically
Goto Forum:
  


Current Time: Sat May 10 04:36:50 EDT 2025

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

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

Back to the top