Permalink
Browse files

iniciação

  • Loading branch information...
1 parent 3ebe6f4 commit 25a0481a3979a1c7ae14ce244dc9334ca1f21201 Fernando committed Feb 2, 2012
@@ -2,9 +2,7 @@
import java.util.ArrayList;
import java.util.List;
-
import Info.*;
-
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -19,6 +17,7 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.MethodDeclaration;
@@ -27,11 +26,13 @@
public class GetInfo extends AbstractHandler {
- private List<ClasseInfo> no = new ArrayList<ClasseInfo>();
+ private static Grafo grafo = new Grafo();
private TypeDeclaration classeDeclaration;
private List<MethodDeclaration> metodoDeclaration;
- private List<FieldDeclaration> fieldDeclaration;
+ //private List<FieldDeclaration> fieldDeclaration;
private List<MethodInvocation> metodoInvocation;
+ private List<ClassInstanceCreation> instanceCreation;
+ private List<Aresta> arestas;
public Object execute(ExecutionEvent event) throws ExecutionException {
@@ -57,35 +58,73 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
DeclarationVisitor declarationVisitor = new DeclarationVisitor();
MethodVisitor methodVisitor = new MethodVisitor();
MethodInvocationVisitor methodInvocationVisitor = new MethodInvocationVisitor();
+ InstanceVisitor instanceVisitor = new InstanceVisitor();
parse.accept(classVisitor);
parse.accept(declarationVisitor);
parse.accept(methodVisitor);
parse.accept(methodInvocationVisitor);
+ parse.accept(instanceVisitor);
metodoDeclaration = new ArrayList<MethodDeclaration>();
- fieldDeclaration = new ArrayList<FieldDeclaration>();
+ //fieldDeclaration = new ArrayList<FieldDeclaration>();
metodoInvocation = new ArrayList<MethodInvocation>();
+ instanceCreation = new ArrayList<ClassInstanceCreation>();
+ arestas = new ArrayList<Aresta>();
for (TypeDeclaration classe : classVisitor.getClasses()){
- System.out.println("\n\nNome da classe: " + classe.getName() + " Super classe: " + classe.getSuperclassType() + " Interface implemets: "+ classe.superInterfaceTypes() + " teste 2: " + classe.isInterface());
+ System.out.println("\n\nNome da classe: " + classe.getName());// + " Super classe: " + classe.getSuperclassType() + " Interface implemets: "+ classe.superInterfaceTypes() + " teste 2: " + classe.isInterface());
+
+ if(classe.getSuperclassType() != null){
+ arestas.add(new ArestaHeranca(classe.getSuperclassType().toString()));
+ }//aresta de herança -->>> extends
+
+ int i = 0;
+ while(i < classe.superInterfaceTypes().size()){
+ arestas.add(new ArestaDeInterface(classe.superInterfaceTypes().get(i).toString()));
+ ++i;
+ }//aresta de inteface --->>> implements
+
if(classe.modifiers().size() >= 2){
//System.out.println("teste" + classe.modifiers().get(1));
}
classeDeclaration = classe;
for(FieldDeclaration declaration : declarationVisitor.getDeclarations()){
//System.out.println("Tipo variavel : " + declaration.getType());
- fieldDeclaration.add(declaration);
- }
- for(MethodInvocation methodInvocation : methodInvocationVisitor.getMethodsInvocations()){
- //System.out.println("Metodo invocado : " + methodInvocation.getName() + " tetste: ");
- metodoInvocation.add(methodInvocation);
- }
+ if(!declaration.getType().isPrimitiveType()){
+ if(!(declaration.getType().toString()).equals("String")){
+ //fieldDeclaration.add(declaration);
+ arestas.add(new ArestaAssociacao(declaration.getType().toString(), declaration));
+ }
+ }
+ }// aresta de associação
+
for (MethodDeclaration method : methodVisitor.getMethods()){
//System.out.println("\n\nNome do metodo: " + method.getName());// + " \nTipo de retorno do metodo: " + method.getReturnType2() + "\nParametro do metodo: " + method.parameters() + " Test: " + method.isConstructor());
- metodoDeclaration.add(method);
+ if(!method.isConstructor()){
+ metodoDeclaration.add(method);
+ }
}
- no.add(new ClasseInfo(classeDeclaration, metodoDeclaration, fieldDeclaration, metodoInvocation));
+
+ for(ClassInstanceCreation instanceCreation : instanceVisitor.getInstances()){
+ //System.out.println("\n\nInstanciação: " + instanceCreation.getType() + "Tipo (nome Classe): " + instanceCreation.resolveConstructorBinding().getName());
+ arestas.add(new ArestaDeInstancia(instanceCreation.getType().toString(), instanceCreation));
+ }
+
+ for(MethodInvocation methodInvocation : methodInvocationVisitor.getMethodsInvocations()){
+ //System.out.println("Metodo invocado : " + methodInvocation.getName() + " Pertence à classe: " + methodInvocation.resolveMethodBinding().getDeclaringClass().getName());
+
+ if(!methodInvocation.resolveMethodBinding().isVarargs()){
+ metodoInvocation.add(methodInvocation);
+ }
+ /*for(int j = 0; j < metodoDeclaration.size(); ++j){
+ if(metodoDeclaration.get(j).getName().equals(methodInvocation.getName())){
+ System.out.println("Metodo invocado : " + methodInvocation.getName() + " tetste: ");
+ arestas.add(new ArestaChamadaDeMetodo(metodoDeclaration.get(j).getName().toString(), methodInvocation));
+ }
+ }*/
+ }
+ grafo.setGrafo(new ClasseInfo(classeDeclaration, metodoDeclaration, metodoInvocation, arestas));
}
}
}
@@ -96,7 +135,24 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
e.printStackTrace();
}
}
-
+ //testes
+ /*for(int i = 0; i < grafo.getGrafo().size(); ++i){
+ for(int j = 0; j < grafo.getGrafo(i).getFieldDeclaration().size(); ++j){
+ for(int t = 0; t < grafo.getGrafo(i).getMethodDeclaration().size(); ++t){
+ if((grafo.getGrafo(i).getFieldDeclaration(j).getType().toString()).equals(grafo.getGrafo(i).getMethodDeclaration(t).getName().toString())){
+ arestas.add(null);
+ }
+ }
+ }
+ }
+
+ for(int i = 0; i < grafo.getGrafo().size(); ++i){
+ if(grafo.getGrafo(i).getAresta().size() != 0){
+ for(int j = 0; j < grafo.getGrafo(i).getAresta().size(); ++j){
+ System.out.println("No: " + grafo.getGrafo(i).getClassDeclaration().getName() + " Aresta: " + grafo.getGrafo(i).getAresta().get(j).getNome());
+ }
+ }
+ }*/
return null;
}
@@ -109,18 +165,20 @@ private static CompilationUnit parse(ICompilationUnit unit) {
return (CompilationUnit) parser.createAST(null); // parse
}
- private void arestas(){
+ /*private void arestas(){
int i = 0;
Aresta aresta;
while(i < no.size()){
- if(this.no.get(i).getClassDeclaration().getSuperclassType() != null){
+ if(this.no.get(i).getClassDeclaration().getSuperclassType() != null && !this.no.get(i).getClassDeclaration().isInterface()){
for(int j = 0; j < no.size(); ++j){
- if(this.no.get(i).getClassDeclaration().getSuperclassType().equals(this.no.get(j).getClassDeclaration().getName()) && !this.no.get(i).getClassDeclaration().isInterface()){
- aresta = new ArestaHeranca(this.no.get(i).getClassDeclaration().getSuperclassType().toString());
+ if(this.no.get(i).getClassDeclaration().getSuperclassType().toString().equals(this.no.get(j).getClassDeclaration().getName().toString())){
+ aresta = new ArestaHeranca();
+ no.get(i).setAresta(aresta);
+ break;
}
}
}
++i;
}
- }
+ }*/
}
@@ -0,0 +1,21 @@
+package ASTSimple.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
+
+public class InstanceVisitor extends ASTVisitor{
+
+ List<ClassInstanceCreation> instances = new ArrayList<ClassInstanceCreation>();
+
+ public boolean visit(ClassInstanceCreation node){
+ this.instances.add(node);
+ return super.visit(node);
+ }
+
+ public List<ClassInstanceCreation> getInstances(){
+ return this.instances;
+ }
+}
View
@@ -1,6 +1,6 @@
package Info;
-public class Aresta {
+public abstract class Aresta {
private String nome;
@@ -1,20 +1,21 @@
package Info;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+
public class ArestaAssociacao extends Aresta{
- private String nomeMetodo;
+ private FieldDeclaration variavel;
- public ArestaAssociacao(String tipoClasse, String nomeMetodo){
+ public ArestaAssociacao(String tipoClasse, FieldDeclaration variavel){
super(tipoClasse);
- this.nomeMetodo = nomeMetodo;
+ this.variavel = variavel;
}
- public String getNomeMetodo() {
- return nomeMetodo;
+ public FieldDeclaration getNomeVariavel() {
+ return variavel;
}
- public void setNomeMetodo(String nomeMetodo) {
- this.nomeMetodo = nomeMetodo;
+ public void setNomeVariavel(FieldDeclaration nomeVariavel) {
+ this.variavel = nomeVariavel;
}
-
}
@@ -1,30 +1,33 @@
package Info;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+
public class ArestaChamadaDeMetodo extends Aresta{
- private String nomeMetodoChamado;
- private String metodoLocalChamado; //em qual metodo houve a chamada
+ private MethodInvocation metodoChamado;
+ //private String metodoLocalChamado; //em qual metodo houve a chamada
- public ArestaChamadaDeMetodo(String nomeClasse, String nomeMetodoChamado, String metodoLocalChamado){
+ public ArestaChamadaDeMetodo(String nomeClasse, MethodInvocation metodoChamado){//, String metodoLocalChamado){
super(nomeClasse);
- this.nomeMetodoChamado = nomeMetodoChamado;
- this.metodoLocalChamado = metodoLocalChamado;
+ this.metodoChamado = metodoChamado;
+ //this.metodoLocalChamado = metodoLocalChamado;
}
- public String getNomeMetodoChamado() {
- return nomeMetodoChamado;
+ public MethodInvocation getMetodoChamado() {
+ return this.metodoChamado;
}
- public void setNomeMetodoChamado(String nomeMetodoChamado) {
- this.nomeMetodoChamado = nomeMetodoChamado;
+ public void setMetodoChamado(MethodInvocation metodoChamado) {
+ this.metodoChamado = metodoChamado;
}
+ /*
public String getMetodoLocalChamado() {
return metodoLocalChamado;
}
public void setMetodoLocalChamado(String metodoLocalChamado) {
this.metodoLocalChamado = metodoLocalChamado;
- }
+ }*/
}
@@ -0,0 +1,22 @@
+package Info;
+
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
+
+public class ArestaDeInstancia extends Aresta{
+
+ ClassInstanceCreation instancia;
+
+ public ArestaDeInstancia(String tipo, ClassInstanceCreation instancia) {
+ super(tipo);
+ this.instancia = instancia;
+ }
+
+ public ClassInstanceCreation getInstancia() {
+ return instancia;
+ }
+
+ public void setInstancia(ClassInstanceCreation instancia) {
+ this.instancia = instancia;
+ }
+
+}
@@ -13,56 +13,69 @@
private TypeDeclaration classDeclaration;
private List<MethodDeclaration> methodDeclaration;
- private List<FieldDeclaration> fieldDeclaration;
+ //private List<FieldDeclaration> fieldDeclaration;
private List<MethodInvocation> methodInvocation;
- private List<Aresta> aresta = new ArrayList<Aresta>();
+ private List<Aresta> arestas = new ArrayList<Aresta>();
public ClasseInfo(){} //Construtor default
- public ClasseInfo(TypeDeclaration c, List<MethodDeclaration> m, List<FieldDeclaration> d, List<MethodInvocation> mi){
+ public ClasseInfo(TypeDeclaration c, List<MethodDeclaration> m, List<MethodInvocation> mi, List<Aresta> a){
setClassDeclaration(c);
setMethodDeclaration(m);
- setFieldDeclaration(d);
+ // setFieldDeclaration(d);
setMethodInvocation(mi);
+ setAresta(a);
}
public TypeDeclaration getClassDeclaration() {
- return classDeclaration;
+ return this.classDeclaration;
}
public void setClassDeclaration(TypeDeclaration classDeclaration) {
this.classDeclaration = classDeclaration;
}
public List<MethodDeclaration> getMethodDeclaration() {
- return methodDeclaration;
+ return this.methodDeclaration;
+ }
+
+ public MethodDeclaration getMethodDeclaration(int i) {
+ return this.methodDeclaration.get(i);
}
public void setMethodDeclaration(List<MethodDeclaration> methodDeclaration) {
this.methodDeclaration = methodDeclaration;
}
-
+/*
public List<FieldDeclaration> getFieldDeclaration() {
- return fieldDeclaration;
+ return this.fieldDeclaration;
}
public void setFieldDeclaration(List<FieldDeclaration> fieldDeclaration) {
this.fieldDeclaration = fieldDeclaration;
}
-
+*/
public List<MethodInvocation> getMethodInvocation() {
- return methodInvocation;
+ return this.methodInvocation;
+ }
+
+ public MethodInvocation getMethodInvocation(int i) {
+ return this.methodInvocation.get(i);
}
public void setMethodInvocation(List<MethodInvocation> methodInvocation) {
this.methodInvocation = methodInvocation;
}
public List<Aresta> getAresta() {
- return aresta;
+ return this.arestas;
}
public void setAresta(List<Aresta> aresta) {
- this.aresta = aresta;
+ this.arestas = aresta;
+ }
+
+ public void setAresta(Aresta aresta) {
+ this.arestas.add(aresta);
}
}
Oops, something went wrong.

0 comments on commit 25a0481

Please sign in to comment.