Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » I cannot insert statement into the "block" code.
I cannot insert statement into the "block" code. [message #251115] Wed, 30 January 2008 03:22 Go to next message
Eclipse UserFriend
Originally posted by: cikinohana.hotmail.com

Hello everyone,
I created a new "block" node and then want to insert an ASTNode of
statement type into the block node, but it seemed the statement node could
not be inserted into the block. The code is as follows:

/**Insert the given node to the given block node;
*
* @param node:the node to be inserted to the block;
* @param block: the block to have node inserted;
*/

public void insertIntoBlock(ASTNode node, Block block){
ASTRewrite rewriter = ASTRewrite.Create(node.getAST());
ListRewrite statementsListRewrite = rewriter.getListRewrite(block,
Block.STATEMENTS_PROPERTY);

statementsListRewrite.insertFirst(ASTNode.copySubtree(node.g etAST(),
node), null);
TextEdit edits = rewriter.rewriteAST(Documentation.getDoc(), null);
//Documentation.getDoc() returns a Document object which stores current
(modified) source codein this project;

edits.apply(Documentation.getDoc());
}

I think this code should work, but it doesn't. Can you help me out of this
problem? Thank you very much.

cikinohana
Re: I cannot insert statement into the "block" code. [message #251120 is a reply to message #251115] Wed, 30 January 2008 05:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: 4cs6fcg02.sneakemail.com

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigEEBB2F0818B12331671EB8BF
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

cikinohana schreef:
> Hello everyone,
> I created a new "block" node and then want to insert an ASTNode of=20
> statement type into the block node, but it seemed the statement node=20
> could not be inserted into the block. The code is as follows:
>=20
> /**Insert the given node to the given block node;
> * * @param node:the node to be inserted to the block;
> * @param block: the block to have node inserted;
> */
>=20
> public void insertIntoBlock(ASTNode node, Block block){
> ASTRewrite rewriter =3D ASTRewrite.Create(node.getAST()); =
=20
> ListRewrite statementsListRewrite =3D rewriter.getListRewrite(block,
> Block.STATEMENTS_PROPERTY);
> =20
> statementsListRewrite.insertFirst(ASTNode.copySubtree(node.g etAST(),=20
> node), null);
> TextEdit edits =3D rewriter.rewriteAST(Documentation.getDoc(), n=
ull);
> //Documentation.getDoc() returns a Document object which stores=
=20
> current (modified) source codein this project;
> =20
> edits.apply(Documentation.getDoc());
> }
>=20
> I think this code should work, but it doesn't. Can you help me out of=20
> this problem? Thank you very much.

I do not know what Block is, nor what Documentation, ASTNode,=20
ASTRewrite, TextEdit and ListRewrite are. You don=E2=80=99t indicate whe=
re the=20
problem is. How can we help you if you do not give enough information?

Read the link below and ask again.

H.
--=20
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


--------------enigEEBB2F0818B12331671EB8BF
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFHoFJ+e+7xMGD3itQRAvoMAJ9sbYeYOw0MwbX0J2fKgonRS/QGVwCf YNbr
7m/8wyAuDC1zbTqTj/FpEyo=
=48At
-----END PGP SIGNATURE-----

--------------enigEEBB2F0818B12331671EB8BF--
Re: I cannot insert statement into the "block" code. [message #251123 is a reply to message #251115] Wed, 30 January 2008 11:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jacek.pospychala.pl.ibm.com

cikinohana,
If you want to modify block, not node, maybe it would be more reasonable
to create rewriter for block.getAST() and then in copySubtree also use
block.getAST() as target.
Also does it work if you insert something simple, eg
"block.getAST().newBlock()", instead of "ASTNode.copySubtree(...)"?
I'm asking, because I've tried your code and it works - so maybe the
problem is somewhere else.

cikinohana wrote:
> Hello everyone,
> I created a new "block" node and then want to insert an ASTNode of
> statement type into the block node, but it seemed the statement node
> could not be inserted into the block. The code is as follows:
>
> /**Insert the given node to the given block node;
> * * @param node:the node to be inserted to the block;
> * @param block: the block to have node inserted;
> */
>
> public void insertIntoBlock(ASTNode node, Block block){
> ASTRewrite rewriter = ASTRewrite.Create(node.getAST());
> ListRewrite statementsListRewrite = rewriter.getListRewrite(block,
> Block.STATEMENTS_PROPERTY);
>
> statementsListRewrite.insertFirst(ASTNode.copySubtree(node.g etAST(),
> node), null);
> TextEdit edits = rewriter.rewriteAST(Documentation.getDoc(),
> null);
> //Documentation.getDoc() returns a Document object which
> stores current (modified) source codein this project;
>
> edits.apply(Documentation.getDoc());
> }
>
> I think this code should work, but it doesn't. Can you help me out of
> this problem? Thank you very much.
>
> cikinohana
>
Re: I cannot insert statement into the "block" code. [message #251127 is a reply to message #251120] Wed, 30 January 2008 11:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wharley.bea.com

"Hendrik Maryns" <4cs6fcg02@sneakemail.com> wrote in message
news:fnpjpu$nl9$1@build.eclipse.org...
> I do not know what Block is, nor what Documentation, ASTNode,
> ASTRewrite, TextEdit and ListRewrite are. You don't indicate where the
> problem is. How can we help you if you do not give enough information?

Hi, Hendrik. Maybe you are overreacting a little? :-)

Tthe types that the poster is referring to are commonly used elements of the
public JDT DOM AST (org.eclipse.jdt.core.dom and ....dom.rewrite), as
discussed here:
http://www.eclipse.org/articles/article.php?file=Article-Jav aCodeManipulation_AST/index.html .
These are types that someone familiar with the JDT API should be aware of,
and this post is in eclipse.tools.jdt so it seems reasonable to assume that
level of knowledge. The only exception is the type Documentation, which the
comment in his code explains.

You are right that it would be helpful if he were more articulate about what
he means by "I think this code should work, but it doesn't."
Re: I cannot insert statement into the "block" code. [message #251141 is a reply to message #251123] Wed, 30 January 2008 15:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cikinohana.hotmail.com

I'm sorry if my poster confused you. I will improve my description next
time. Thank you Jacek. I know where the problem is.
Re: I cannot insert statement into the "block" code. [message #251185 is a reply to message #251127] Fri, 01 February 2008 09:45 Go to previous message
Eclipse UserFriend
Originally posted by: 4cs6fcg02.sneakemail.com

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig6C0730CEE7B0B4D10C1A8706
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Walter Harley schreef:
> "Hendrik Maryns" <4cs6fcg02@sneakemail.com> wrote in message=20
> news:fnpjpu$nl9$1@build.eclipse.org...
>> I do not know what Block is, nor what Documentation, ASTNode,
>> ASTRewrite, TextEdit and ListRewrite are. You don't indicate where th=
e
>> problem is. How can we help you if you do not give enough information=
?
>=20
> Hi, Hendrik. Maybe you are overreacting a little? :-)
>=20
> Tthe types that the poster is referring to are commonly used elements o=
f the=20
> public JDT DOM AST (org.eclipse.jdt.core.dom and ....dom.rewrite), as=20
> discussed here:=20
> http://www.eclipse.org/articles/article.php?file=3DArticle-J avaCodeMani=
pulation_AST/index.html .=20
> These are types that someone familiar with the JDT API should be aware =
of,=20
> and this post is in eclipse.tools.jdt so it seems reasonable to assume =
that=20
> level of knowledge. The only exception is the type Documentation, whic=
h the=20
> comment in his code explains.

Ah, yes, I am reading this newsgroup from the viewpoint of an Eclipse=20
user, not an Eclipse developer. Sorry.

H.
--=20
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


--------------enig6C0730CEE7B0B4D10C1A8706
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFHozCUe+7xMGD3itQRAh5pAJ9Z4tVr2PVKsuf4haxLmcLLMXKnlgCc D4q0
m0s0NLKqHu7RVjNo/3jUQ/k=
=XRkm
-----END PGP SIGNATURE-----

--------------enig6C0730CEE7B0B4D10C1A8706--
Previous Topic:eclipse 3.2.1 running OutOfMemory while building workspace
Next Topic:problem creating lib directory
Goto Forum:
  


Current Time: Mon Apr 28 12:19:09 EDT 2025

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

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

Back to the top