Hello,
I have the following classes:
public class Model {
protected String name;
protected ArrayList<Model> children;
public Model(){
children = new ArrayList<Model>();
}
public void addChild(Model node) {
children.add(node);
}
//other code here
}
public class cPackage extends Model{
public cPackage() {
super();
}
//other code here
}
public class cClass extends Model{
public cClass() {
super();
}
//other code here
}
public class cMethod extends Model{
public cMethod() {
super();
}
//other code here
}
public void tryme(Object[] objs){
String values = (String)objs[0];
Model root = null;
astNode = ax.getDeclaringNodeInProject(handles, bindings);
if(astNode instanceof TypeDeclaration){
TypeDeclaration cl = (TypeDeclaration)astNode;
root = new cClass();
root.setName(cl.getName().getFullyQualifiedName());
}else if(astNode instanceof MethodDeclaration){
MethodDeclaration me = (MethodDeclaration)astNode;
root = new cMethod();
List mod = me.parameters();
String vars ="";
...
root.setName(me.getName().getFullyQualifiedName() + "(" + vars + ")");
}
Model currentNode = null;
Model prevNode = root;
for(int i = 1 ; i < objs.length; i++){
if(astNode instanceof PackageDeclaration){
PackageDeclaration pka = (PackageDeclaration)astNode;
p8.setName(pka.getFullyQualifiedName());
if(currentNode == null) {
currentNode = p8;
prevNode.addChild(currentNode);
}
prevNode = currentNode;
}else if(astNode instanceof MethodDeclaration){
MethodDeclaration me = (MethodDeclaration)astNode;
...
m8.setName(me.getName().getFullyQualifiedName() + "(" + vars + ")");
if(currentNode == null) {
currentNode = m8;
prevNode.addChild(currentNode);
}
prevNode = currentNode;
}else if(astNode instanceof TypeDeclaration){
TypeDeclaration cl = (TypeDeclaration)astNode;
c8.setName(cl.getName().getFullyQualifiedName());
if(currentNode == null) {
currentNode = c8;
prevNode.addChild(currentNode);
}
prevNode = currentNode;
}
}
}
Sorry if there are missing "{" or "}". What i am trying to do here is i have a data from the server like these:
[School Chair Table Chalk]
...
[Apple Peer Mango Melon]
all in arrays. I want to build something like a tree-like structure whereby reading from the left :
Each element will be de parent of the element that follows it. I am looping through the data to do it. For example i want to get something like:
+School
Chair
Table
Chalk
+Apple
Peer
Mango
Melon
But when i run the above code i get only the first two elements like:
+School
Chair
+Apple
Peer
and the following elements don't show up.
Can someone help me where am doing wrong.
Thanks.