Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Add javadoc comments programmatically
Add javadoc comments programmatically [message #210635] Fri, 22 July 2005 05:57 Go to next message
Eclipse UserFriend
Originally posted by: david.nitenberg.gmail.com

Hi,

I would like to add javadoc comments programmatically to some methods or
fields in a .java file. Is it possible and if so, what Interface or Class
should I use. I tried to find a solution in org.eclipse.jdt.core but
without success.

Thanks
David
Re: Add javadoc comments programmatically [message #210703 is a reply to message #210635] Sat, 23 July 2005 09:24 Go to previous message
Eclipse UserFriend
Originally posted by: david.nitenberg.gmail.com

I found some source Code to add a javadoc comment in an ICompilationUnit
but I always get an exception. Here is below the code I use :

################## SOURCE CODE #####################

// I already have an ICompilationUnit icu.
parser.setSource(icu);
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.recordModifications();
List cuTypes = cu.types();
TypeDeclaration type = (TypeDeclaration)cuTypes.get(0);

// Creating the new JavaDoc node
AST ast = cu.getAST();
Javadoc jc = ast.newJavadoc();
TagElement tag = ast.newTagElement();
TextElement te = ast.newTextElement();
tag.fragments().add(te);
te.setText("BLA BLA BLA");
jc.tags().add(tag);
tag = ast.newTagElement();
tag.setTagName(TagElement.TAG_AUTHOR);
jc.tags().add(tag);
type.setJavadoc(jc);

// Applying changes
TextEdit text = cu.rewrite(document, javaProject.getOptions(true));
try {
text.apply(document);
} catch (MalformedTreeException e1) { e1.printStackTrace(); }
catch (BadLocationException e1) { e1.printStackTrace(); }

String newSource = document.get();
try {
icu.getBuffer().setContents(newSource);
} catch (JavaModelException e1) { e1.printStackTrace(); }


########################### Exception received ######################
Exception in thread "AWT-EventQueue-0" java.lang.LinkageError: loader
constraints violated when linking org/eclipse/jface/text/IDocument class

This exception occurs with the following statement :
TextEdit text = cu.rewrite(document, javaProject.getOptions(true));

I don't understand what it means and why I get this exception. If anyone
could help me please ?
Thanx
David
Previous Topic:writing code in java source
Next Topic:Problem with GetterSetterUtil.getGetterStub
Goto Forum:
  


Current Time: Fri Mar 14 06:20:50 EDT 2025

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

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

Back to the top