Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to add superinterface to IType
How to add superinterface to IType [message #259556] Wed, 15 April 2009 03:20 Go to next message
Eclipse UserFriend
Hi all,

Could anyone tell me if it is possible and how to add a superinterface to
an IType ? I've been searching for a while now but couldn't find anything
really.

Thanks in advance.

Julien
Re: How to add superinterface to IType [message #259580 is a reply to message #259556] Thu, 16 April 2009 09:29 Go to previous messageGo to next message
Eclipse UserFriend
In case someone googles it :

Document doc = new Document(sourceCode);
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(doc.get().toCharArray());
CompilationUnit cu = (CompilationUnit)parser.createAST(null);
AST ast = cu.getAST();
cu.recordModifications();
TypeDeclaration type = (TypeDeclaration)cu.types().get(0);
ASTRewrite rewriter = ASTRewrite.create(ast);
ListRewrite listRewriter;
listRewriter = rewriter.getListRewrite(type,
TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY);
listRewriter.insertLast(ast.newSimpleName("GeneratedInterface "), null);
TextEdit edits = rewriter.rewriteAST(doc, null);
try {
edits.apply(doc);
} catch (MalformedTreeException e) {
e.printStackTrace();
} catch (BadLocationException e) {
e.printStackTrace();
}
try {
t.getCompilationUnit().getBuffer().setContents(doc.get());
} catch (JavaModelException e) {
e.printStackTrace();
}
Re: How to add superinterface to IType [message #259584 is a reply to message #259580] Thu, 16 April 2009 11:07 Go to previous messageGo to next message
Eclipse UserFriend
Actually the previous post is not correct, a superinterface is added to
the class but the final source code only contains the definition of the
class : package declarations and imports are erased !

Any help would be great

Julien
Re: How to add superinterface to IType [message #259591 is a reply to message #259584] Fri, 17 April 2009 04:01 Go to previous message
Eclipse UserFriend
Found what was wrong : just a bad initialization of the document :
IType.getSource() only returns the source code of the class people should
use ICompilationUnit.getSource() instead

Julien
Previous Topic:Get Tab Size from Preferences
Next Topic:Generics lost on IField when coming from .class files
Goto Forum:
  


Current Time: Sat Apr 19 12:00:39 EDT 2025

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

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

Back to the top