6 Replies Last post: Feb 3, 2010 10:22 PM by Andre Kullmann  
Andre Kullmann Newbie 6 posts since
Feb 3, 2010
Currently Being Moderated

Feb 3, 2010 2:27 PM

Class object from sources of an project

Hi,

I try to develop my first intellij idea plugin.

Now I need the compiled class of an source in the project.

Something like :

 

Project

 

com/company/MyClass.java

 

Plugin {


  ClassLoader cl = project.getClassLoader();

  for( Class c =cl.loadClass( "com.company.MyClass" ); c != null; c = c.getSuperClass() )

       System.out.println( c );

}

 

Is this possible ?

 

Thanx,

André

Dmitry Jemerov JetBrains 11,356 posts since
Aug 19, 2002
Currently Being Moderated
Feb 3, 2010 2:50 PM in response to: Andre Kullmann
Re: Class object from sources of an project

Hello Andre,

 

What are you trying to accomplish? Usually it's not a good approach to load

the compiled classes of your application into IDEA's classloader.

 

Hi,

I try to develop my first intellij idea plugin.

Now I need the compiled class of an source in the project.

Something like :

Project

 

com/company/MyClass.java

 

Plugin {

+

+

+  ClassLoader cl = project.getClassLoader();+

+  for( Class c =cl.loadClass( "com.company.MyClass" ); c != null; c =

c.getSuperClass() )+

+       System.out.println( c );+

}

Is this possible ?

 

Thanx,

André

---

Original message URL:

http://www.jetbrains.net/devnet/message/5255841#5255841

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

Dmitry Jemerov JetBrains 11,356 posts since
Aug 19, 2002
Currently Being Moderated
Feb 3, 2010 4:50 PM in response to: Andre Kullmann
Re: Class object from sources of an project

Hello Andre,

 

You don't need access to compiled classes in order to find out the class

hierarchy. See PsiClass.getSuperClass() in the OpenAPI.

 

Hi Dmitry,

 

thanks for reply.

 

I try to find out the class hierarchy.

 

The plugin I develop shows an preview of gui layout defined in xml.

Every xml belongs to an class. The translations are stored In

properties files. So it is possible to override information in

properties and xml in and child class.

 

The parser needs the class and the xml as input to render the layout

preview.

 

Currently my code looks like

 

URL buildRoot =

new File( project.getBaseDir().getPath() +

"/out/production/" + project.getName() ).toURI().toURL();

URL srcRoot =

new File( project.getBaseDir().getPath() +

"/src" ).toURI().toURL();

URLClassLoader cl = new URLClassLoader( new URL[]{

srcRoot, buildRoot }, null );

 

Class<?> c = cl.loadClass( tmp );

 

The problems are

 

1 ) there can be more than on src path, how will i know the src paths

?

 

2 ) same with the out path.

 

3 ) i need the classpath of the project, to include in the

URLClassLoader, how will i know the classpath ?

 

---

Original message URL:

http://www.jetbrains.net/devnet/message/5255845#5255845

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

Dmitry Jemerov JetBrains 11,356 posts since
Aug 19, 2002
Currently Being Moderated
Feb 3, 2010 9:23 PM in response to: Andre Kullmann
Re: Class object from sources of an project

Hello Andre,

 

JavaPsiFacade.getInstance(project).findClass(String qualifiedName)

 

He,

 

ok psi looks interesting.

To get an PsiClass instance I using

PsiJavaFile j = (PsiJavaFile)

PsiManager.getInstance( project ).findFile( file );

for( PsiClass c : j.getClasses() ) {

find the right

}

Is there an way more simple to get an PsiClass, like

 

PsiManager.getInstance( project ).findClass(

"com.company." );

 

Thanks,

André

---

Original message URL:

http://www.jetbrains.net/devnet/message/5255884#5255884

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

 

 

 

More Like This

  • Retrieving data ...