Hello,
I am using org.eclipse.php.internal.core to parse PHP files. I need to get the expression statements as they are in the source code, but the node.getExpression() returns
an Expression and with a toString() it return an xml-like string. please see the code:
public class MyVisitor implement Visitor{
...
@Override
public boolean visit(ExpressionStatement node) {
// TODO Auto-generated method stub
System.out.println("ExpressionStatement: "+node.getExpression().toString);
return true;
}
...
}
So for the following php file, the output for line "$aa= new AA();" here:
ExpressionStatement: <ExpressionStatement start='187' length='14'>
<Assignment start='187' length='13' operator='='>
<Variable start='187' length='3' isDollared='true'>
<Identifier start='188' length='2' name='aa'/>
</Variable>
<Value>
<ClassInstanceCreation start='192' length='8'>
<ClassName start='196' length='2'>
<Identifier start='196' length='2' name='AA'/>
</ClassName>
<ConstructorParameters>
</ConstructorParameters>
</ClassInstanceCreation>
</Value>
</Assignment>
</ExpressionStatement>
<?php
include 'varInclude.php';
print ("name: ".$name."\t\t\t");
function printName(){
include_once 'varInclude.php';
include 'varInclude2.php';
print ("name: ".$name."\t\t\t");
$aa= new AA();
$aa->m1("hello");
$aa->f1=5;
}
printName();
?>
So do i need to write another parser to parse this xml like output to get to the actual statement "$aa= new AA();" ? If yes, then how a bout the parenthesis and quotations???
Is there other way to get this statement as is ,from AST?