Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Adding super interface : nothing happens
Adding super interface : nothing happens [message #260351] Tue, 02 June 2009 09:24 Go to next message
Eclipse UserFriend
Hi all,

I'm developing a plug-in that's supposed to generate code depending on
user's interactions. The user can modify existing java files or create new
ones and then modify them.

For some reason, after the creation of a class, I can add fields and
methods but I can't add a super interface (when the class was not created
programmatically adding a super interface works perfectly).

Any help is more than welcome !

Julien
Re: Adding super interface : nothing happens [message #260392 is a reply to message #260351] Wed, 03 June 2009 02:02 Go to previous messageGo to next message
Eclipse UserFriend
"Julien M." <jmananki@enib.fr> wrote in message
news:68b45ad138ddd0bfa1dcf3fa75f565bc$1@www.eclipse.org...
> Hi all,
>
> I'm developing a plug-in that's supposed to generate code depending on
> user's interactions. The user can modify existing java files or create new
> ones and then modify them.
>
> For some reason, after the creation of a class, I can add fields and
> methods but I can't add a super interface (when the class was not created
> programmatically adding a super interface works perfectly).

Please be more specific about the problem you are encountering.
Re: Adding super interface : nothing happens [message #260394 is a reply to message #260392] Wed, 03 June 2009 03:50 Go to previous messageGo to next message
Eclipse UserFriend
Here are more specifications, I think I'm encountering this problem for
two reasons :
- first the newly programmatically created files are out of sync with the
file system ;
- second to add super interfaces I use the DOM/AST API whereas I use
org.eclipse.jdt.core to add everything else.

So either I add a super interface using org.eclipse.jdt.core or I
synchronize the new classes with the file system.

As I couldn't find a way to add super interface with org.eclipse.jdt.core
I tried synchronize the classes with ICompilationUnit.reconcile(),
IcompilationUnit.makeConsistent(), IPackageFragment.makeConsistent() ...
didn't get any results so far though.

So can anyone tell me either how to add super interface with
org.eclipse.jdt.core or how to synchronize the files (method called when
pressing F5 on any resource).

Thanks in advance,

Julien
Re: Adding super interface : nothing happens [message #260401 is a reply to message #260394] Wed, 03 June 2009 07:39 Go to previous messageGo to next message
Eclipse UserFriend
Actually refreshing the resources didn't change anything...
Re: Adding super interface : nothing happens [message #260419 is a reply to message #260394] Wed, 03 June 2009 14:06 Go to previous messageGo to next message
Eclipse UserFriend
"Julien M." <jmananki@enib.fr> wrote in message
news:c569585fac0222d854c6976ea384bc4a$1@www.eclipse.org...
> Here are more specifications, I think I'm encountering this problem for
> two reasons :
> - first the newly programmatically created files are out of sync with the
> file system ;
> - second to add super interfaces I use the DOM/AST API whereas I use
> org.eclipse.jdt.core to add everything else.
>
> So either I add a super interface using org.eclipse.jdt.core or I
> synchronize the new classes with the file system.
>
> As I couldn't find a way to add super interface with org.eclipse.jdt.core
> I tried synchronize the classes with ICompilationUnit.reconcile(),
> IcompilationUnit.makeConsistent(), IPackageFragment.makeConsistent() ...
> didn't get any results so far though.
>
> So can anyone tell me either how to add super interface with
> org.eclipse.jdt.core or how to synchronize the files (method called when
> pressing F5 on any resource).


You still haven't said what the problem *is* - do you get an exception?
Does it fail to change a file? Fail to recompile a changed file?

And you haven't been at all clear about what APIs you are using. (E.g., you
said that you're using DOM AST for some stuff, jdt.core for other, but DOM
AST is part of jdt.core so I have no clue what you mean.)

And you've not been clear about when your code runs: you said "depending on
user's interactions" but I don't know whether that means it's happening on
the UI thread, during a build, or what.

Nor is it clear what you mean by "add super interface". Are you talking
about adding the "implements ..." or "extends..." clauses to an existing
type? Or are you talking about creating a new interface type and adding it
to the project?

I would suggest reading this:
http://www.eclipse.org/articles/article.php?file=Article-Jav aCodeManipulation_AST/index.html
and closely working through its example.
Re: Adding super interface : nothing happens [message #260423 is a reply to message #260419] Thu, 04 June 2009 04:02 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your answer Walter and sorry about the lack of clarity I'll try
to tell all you need to know to help me.

As I said I'm developing a plug-in that allows a user to create and change
java files using an hmi. So basically the user can create and/or modify
classes and interfaces in his java project by clicking a bunch of buttons.

Say there's the following existing java file :

public class MyClass {

}

The user can modify MyClass to get the following

public class MyClass implements SomeInterface{

protected String someField;

public void someMethod(){
}

}

The user can add imports, fields, methods and implemented interfaces to
MyCass. To add imports, fields and methods I'm using
ICompilationUnit.createImport IType.createField IType.createMethod
(org.eclipse.jdt.core). This works fine for existing files and for
programmatically generated ones.

The problem occurs when attempting to add implemented interfaces if
MyClass doesn't already exist. The generation of MyClass works fine but if
the user resquests to add implemented interfaces nothing happens. As the
method called is the same either if the file exist or if it doesn't. I
assume the problem comes from the generation of MyClass.

The adding of implemented interfaces is done using ListRewrite.insertLast
(org.eclipse.jdt.core.dom).

MyClass could also be an interface in which case an extended interface is
supposed to be added. I think ListRewrite.insertLast manages whether
MyClass is a class or an interface.

Concerning when my code runs I'm not sure what you mean by "it's happening
on the UI thread" but I hope the previously given informations told you
what you need to know.

There is one more thing, I've noticed that after refreshing the project
the adding of implemented interfaces works fine so I tried the
programmatically refresh the project. But unfortunately it didn't work.

Hope I was clear enough this time.

Thanks in advance for your answers.

Julien
Re: Adding super interface : nothing happens [message #260582 is a reply to message #260423] Fri, 12 June 2009 05:51 Go to previous message
Eclipse UserFriend
Found it ! I was having this problem just because the ICompilationUnit was
not a working copy.
Previous Topic:PackageFragmentRoot not returning the correct JavaProject
Next Topic:Tie environment variables to classpath variables
Goto Forum:
  


Current Time: Tue Jul 22 16:17:27 EDT 2025

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

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

Back to the top