diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..537aa29
Binary files /dev/null and b/.DS_Store differ
diff --git a/.classpath b/.classpath
index eca7bdb..b862a29 100644
--- a/.classpath
+++ b/.classpath
@@ -1,7 +1,7 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..e208459
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..cc08f7d
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..ecda4c4
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,477 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ DEFINITION_ORDER
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1508991795086
+
+
+ 1508991795086
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ JAVA
+ org.tec.datos1.flow
+
+ org.tec.datos1.flow.graphics.ASTStorageParser
+ org.tec.datos1.flow.graphics.Process
+ org.tec.datos1.flow.graphics.Widget
+ org.tec.datos1.flow.handlers.StepOverHandler
+ org.tec.datos1.flow.debug.DebugListener
+ org.tec.datos1.flow.graphics.While
+ org.tec.datos1.flow.debug.DebugStepper
+ org.tec.datos1.flow.graphics.Method
+ org.tec.datos1.flow.handlers.MethodVisitor
+ org.tec.datos1.flow.graphics.Line
+ org.tec.datos1.flow.storage.ASTStorage
+ org.tec.datos1.flow.CodeParser
+ org.tec.datos1.flow.Activator
+ org.tec.datos1.flow.parts.DiagramView
+ org.tec.datos1.flow.handlers.StepInHandler
+ org.tec.datos1.flow.graphics.If
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Fields
+ Inner Classes
+ Constructors
+ Properties
+ Methods
+
+ All
+ private
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Class Diagram.pdf b/Class Diagram.pdf
new file mode 100644
index 0000000..07598cf
Binary files /dev/null and b/Class Diagram.pdf differ
diff --git "a/Documentaci\303\263n Flow.pdf" "b/Documentaci\303\263n Flow.pdf"
new file mode 100644
index 0000000..59510e8
Binary files /dev/null and "b/Documentaci\303\263n Flow.pdf" differ
diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF
index 6970551..4946c6a 100644
--- a/META-INF/MANIFEST.MF
+++ b/META-INF/MANIFEST.MF
@@ -17,7 +17,9 @@ Require-Bundle: javax.inject,
org.eclipse.jdt.ui;bundle-version="3.13.1",
org.eclipse.jface.text;bundle-version="3.12.0",
org.eclipse.core.resources;bundle-version="3.12.0",
- org.eclipse.ui;bundle-version="3.109.0"
+ org.eclipse.ui;bundle-version="3.109.0",
+ org.eclipse.debug.core;bundle-version="3.11.0",
+ org.eclipse.jdt.debug;bundle-version="3.11.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.annotation;version="1.2.0"
Bundle-ActivationPolicy: lazy
diff --git a/Manual Flow.pdf b/Manual Flow.pdf
new file mode 100644
index 0000000..2963e80
Binary files /dev/null and b/Manual Flow.pdf differ
diff --git a/fragment.e4xmi b/fragment.e4xmi
old mode 100644
new mode 100755
index d9cb52a..7aad39a
--- a/fragment.e4xmi
+++ b/fragment.e4xmi
@@ -1,25 +1,28 @@
-
-
-
-
- View
- categoryTag:Sample Category
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ View
+ categoryTag:Sample Category
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/icons/.DS_Store b/icons/.DS_Store
new file mode 100644
index 0000000..5008ddf
Binary files /dev/null and b/icons/.DS_Store differ
diff --git a/icons/001-diagrams.png b/icons/001-diagrams.png
deleted file mode 100644
index 49f9782..0000000
Binary files a/icons/001-diagrams.png and /dev/null differ
diff --git a/icons/002-flow-1.png b/icons/002-flow-1.png
deleted file mode 100644
index 44f467e..0000000
Binary files a/icons/002-flow-1.png and /dev/null differ
diff --git a/icons/003-flow-1.png b/icons/003-flow-1.png
new file mode 100644
index 0000000..9f83c0d
Binary files /dev/null and b/icons/003-flow-1.png differ
diff --git a/icons/003-flow-1@2x.png b/icons/003-flow-1@2x.png
new file mode 100644
index 0000000..189628f
Binary files /dev/null and b/icons/003-flow-1@2x.png differ
diff --git a/icons/003-flow.png b/icons/003-flow.png
deleted file mode 100644
index 96c387a..0000000
Binary files a/icons/003-flow.png and /dev/null differ
diff --git a/icons/004-debug.png b/icons/004-debug.png
deleted file mode 100644
index 509b951..0000000
Binary files a/icons/004-debug.png and /dev/null differ
diff --git a/icons/005-browser.png b/icons/005-browser.png
index 1288038..89175d0 100644
Binary files a/icons/005-browser.png and b/icons/005-browser.png differ
diff --git a/icons/005-browser@2x.png b/icons/005-browser@2x.png
new file mode 100644
index 0000000..c47ceca
Binary files /dev/null and b/icons/005-browser@2x.png differ
diff --git a/icons/006-arrow-into-drive-symbol.png b/icons/006-arrow-into-drive-symbol.png
deleted file mode 100644
index aa14542..0000000
Binary files a/icons/006-arrow-into-drive-symbol.png and /dev/null differ
diff --git a/icons/007-downloaded-into-inbox.png b/icons/007-downloaded-into-inbox.png
deleted file mode 100644
index 8c54269..0000000
Binary files a/icons/007-downloaded-into-inbox.png and /dev/null differ
diff --git a/icons/008-login-square-arrow-button-outline.png b/icons/008-login-square-arrow-button-outline.png
deleted file mode 100644
index 1ea76e9..0000000
Binary files a/icons/008-login-square-arrow-button-outline.png and /dev/null differ
diff --git a/icons/icons8-step_into.png b/icons/icons8-step_into.png
new file mode 100644
index 0000000..2f38021
Binary files /dev/null and b/icons/icons8-step_into.png differ
diff --git a/icons/icons8-step_into@2x.png b/icons/icons8-step_into@2x.png
new file mode 100644
index 0000000..fc31ca7
Binary files /dev/null and b/icons/icons8-step_into@2x.png differ
diff --git a/icons/icons8-step_out@2x.png b/icons/icons8-step_out@2x.png
new file mode 100644
index 0000000..13897b4
Binary files /dev/null and b/icons/icons8-step_out@2x.png differ
diff --git a/icons/icons8-step_over.png b/icons/icons8-step_over.png
new file mode 100644
index 0000000..79e9025
Binary files /dev/null and b/icons/icons8-step_over.png differ
diff --git a/icons/icons8-step_over@2x.png b/icons/icons8-step_over@2x.png
new file mode 100644
index 0000000..be5192a
Binary files /dev/null and b/icons/icons8-step_over@2x.png differ
diff --git a/org.tec.datos1.flow.iml b/org.tec.datos1.flow.iml
new file mode 100644
index 0000000..8c46d08
--- /dev/null
+++ b/org.tec.datos1.flow.iml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/plugin.xml b/plugin.xml
index ce89d11..87bd5ce 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -12,60 +12,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ point="org.eclipse.jdt.debug.breakpointListeners">
+
+
+
diff --git a/src/.DS_Store b/src/.DS_Store
new file mode 100644
index 0000000..f5a328d
Binary files /dev/null and b/src/.DS_Store differ
diff --git a/src/org/.DS_Store b/src/org/.DS_Store
new file mode 100644
index 0000000..b68777e
Binary files /dev/null and b/src/org/.DS_Store differ
diff --git a/src/org/tec/.DS_Store b/src/org/tec/.DS_Store
new file mode 100644
index 0000000..54c04aa
Binary files /dev/null and b/src/org/tec/.DS_Store differ
diff --git a/src/org/tec/datos1/.DS_Store b/src/org/tec/datos1/.DS_Store
new file mode 100644
index 0000000..377bbe1
Binary files /dev/null and b/src/org/tec/datos1/.DS_Store differ
diff --git a/src/org/tec/datos1/flow/.DS_Store b/src/org/tec/datos1/flow/.DS_Store
new file mode 100644
index 0000000..b6de639
Binary files /dev/null and b/src/org/tec/datos1/flow/.DS_Store differ
diff --git a/src/org/tec/datos1/flow/Activator.java b/src/org/tec/datos1/flow/Activator.java
index 8c452bc..5e016d4 100644
--- a/src/org/tec/datos1/flow/Activator.java
+++ b/src/org/tec/datos1/flow/Activator.java
@@ -1,7 +1,9 @@
package org.tec.datos1.flow;
+import org.eclipse.jdt.debug.core.JDIDebugModel;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.tec.datos1.flow.debug.DebugListener;
public class Activator implements BundleActivator {
@@ -16,7 +18,10 @@ static BundleContext getContext() {
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext bundleContext) throws Exception {
+ JDIDebugModel.addJavaBreakpointListener(new DebugListener());
Activator.context = bundleContext;
+
+
}
/*
diff --git a/src/org/tec/datos1/flow/handlers/Handler.java b/src/org/tec/datos1/flow/CodeParser.java
similarity index 53%
rename from src/org/tec/datos1/flow/handlers/Handler.java
rename to src/org/tec/datos1/flow/CodeParser.java
index cbeae01..3757550 100644
--- a/src/org/tec/datos1/flow/handlers/Handler.java
+++ b/src/org/tec/datos1/flow/CodeParser.java
@@ -1,67 +1,96 @@
-package org.tec.datos1.flow.handlers;
-
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.ASTParser;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-
-public class Handler extends AbstractHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
-
- IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
- ICompilationUnit IcUnit = null;
- try{
- IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
- IcUnit = (ICompilationUnit) JavaCore.create(file);
- }catch(Exception e) {
- System.err.println("Debe tener una clase abierta");
- return null;
- }
- try {
- createAST(IcUnit);
- }catch(JavaModelException exeption){}
-
- return null;
- }
-
- private void createAST(ICompilationUnit IcUnit)
- throws JavaModelException {
-
- CompilationUnit parse = parse(IcUnit);
-
- MethodVisitor visitor = new MethodVisitor();
- parse.accept(visitor);
-
- }
-
- /**
- * Reads a ICompilationUnit and creates the AST DOM for manipulating the
- * Java source file
- *
- * @param unit
- * @return
- */
-
- public static CompilationUnit parse(ICompilationUnit unit) {
- ASTParser parser = ASTParser.newParser(AST.JLS2);
- parser.setKind(ASTParser.K_COMPILATION_UNIT);
- parser.setSource(unit);
- parser.setResolveBindings(true);
-
- return (CompilationUnit) parser.createAST(null); // parse
- }
-
-
-
-}
+package org.tec.datos1.flow;
+
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.tec.datos1.flow.handlers.MethodVisitor;
+import org.tec.datos1.flow.storage.ASTStorage;
+
+
+public class CodeParser {
+
+ /**
+ * Este método se encarga de parsear el código de la
+ * clase abierta en el instante que se llama el método
+ * @throws ExecutionException
+ */
+ public static void execute() throws ExecutionException {
+ if (ASTStorage.getRoot() != null){
+ ASTStorage.getRoot().deleteChildren();
+ }
+ IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
+ ICompilationUnit IcUnit = null;
+
+ try{
+ IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
+ IcUnit = (ICompilationUnit) JavaCore.create(file);
+ }catch(Exception e) {
+ System.err.println("Debe tener una clase abierta");
+ }
+ try {
+
+ createAST(IcUnit);
+
+ }catch(JavaModelException exeption){}
+
+ }
+
+ /**
+ * Este método se encarga de parsear el código de la
+ * clase abierta en el instante que se llama el método
+ * @throws ExecutionException
+ */
+ public static void executeSpecific(ICompilationUnit unit ) throws ExecutionException {
+ if (ASTStorage.getRoot() != null){
+ ASTStorage.getRoot().deleteChildren();
+ }
+ try {
+ createAST(unit);
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Crea el arbol AST
+ * @param IcUnit Clase que se va a analizar
+ * @throws JavaModelException
+ */
+ private static void createAST(ICompilationUnit IcUnit) throws JavaModelException {
+
+ CompilationUnit parse = parse(IcUnit);
+ ASTStorage.setCompUnit(parse);
+ MethodVisitor visitor = new MethodVisitor();
+ parse.accept(visitor);
+
+ }
+
+
+ /**
+ * Reads a ICompilationUnit and creates the AST DOM for manipulating the
+ * Java source file
+ *
+ * @param unit
+ * @return
+ */
+
+ public static CompilationUnit parse(ICompilationUnit unit) {
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setSource(unit);
+ parser.setResolveBindings(true);
+
+ return (CompilationUnit) parser.createAST(null); // parse
+ }
+
+
+
+}
diff --git a/src/org/tec/datos1/flow/debug/DebugListener.java b/src/org/tec/datos1/flow/debug/DebugListener.java
new file mode 100644
index 0000000..9582ed4
--- /dev/null
+++ b/src/org/tec/datos1/flow/debug/DebugListener.java
@@ -0,0 +1,59 @@
+package org.tec.datos1.flow.debug;
+
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.ILineBreakpoint;
+import org.eclipse.jdt.core.dom.Message;
+import org.eclipse.jdt.debug.core.IJavaBreakpoint;
+import org.eclipse.jdt.debug.core.IJavaBreakpointListener;
+import org.eclipse.jdt.debug.core.IJavaDebugTarget;
+import org.eclipse.jdt.debug.core.IJavaLineBreakpoint;
+import org.eclipse.jdt.debug.core.IJavaThread;
+import org.eclipse.jdt.debug.core.IJavaType;
+import org.tec.datos1.flow.parts.DiagramView;
+
+public class DebugListener implements IJavaBreakpointListener{
+
+ @Override
+ public void addingBreakpoint(IJavaDebugTarget arg0, IJavaBreakpoint arg1) {}
+
+ @Override
+ public void breakpointHasCompilationErrors(IJavaLineBreakpoint arg0, Message[] arg1) {}
+
+ @Override
+ public void breakpointHasRuntimeException(IJavaLineBreakpoint arg0, DebugException arg1) {}
+
+ /**
+ * Este método se ejecuta cuando al depurar un programa,
+ * choca con un breakPoint y se encarga de mantener una referencia al hilo
+ * @param thread Hilo que se encarga de mantener el proceso de depurado
+ * @param breakpoint BreakPoint contra el cual choca el depurador
+ * @see org.eclipse.jdt.debug.core.IJavaBreakpointListener#breakpointHit(org.eclipse.jdt.debug.core.IJavaThread, org.eclipse.jdt.debug.core.IJavaBreakpoint)
+ */
+ @Override
+ public int breakpointHit(IJavaThread thread, IJavaBreakpoint breakpoint) {
+
+ DebugStepper.setDebugThread(thread);
+
+ ILineBreakpoint lineBreak = (ILineBreakpoint)breakpoint;
+ int lineNumber = 0;
+ try {
+ lineNumber = lineBreak.getLineNumber();
+ }catch(CoreException e) {}
+ try {
+ DiagramView.setLineNumber(lineNumber);
+ }catch(org.eclipse.swt.SWTException e) {}
+ return lineNumber;
+ }
+
+ @Override
+ public void breakpointInstalled(IJavaDebugTarget arg0, IJavaBreakpoint arg1) {}
+
+ @Override
+ public void breakpointRemoved(IJavaDebugTarget arg0, IJavaBreakpoint arg1) {}
+
+ @Override
+ public int installingBreakpoint(IJavaDebugTarget arg0, IJavaBreakpoint arg1, IJavaType arg2) {return 0;}
+
+}
diff --git a/src/org/tec/datos1/flow/debug/DebugStepper.java b/src/org/tec/datos1/flow/debug/DebugStepper.java
new file mode 100644
index 0000000..b5b99be
--- /dev/null
+++ b/src/org/tec/datos1/flow/debug/DebugStepper.java
@@ -0,0 +1,138 @@
+package org.tec.datos1.flow.debug;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.debug.core.model.IStackFrame;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.debug.core.IJavaThread;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.tec.datos1.flow.CodeParser;
+import org.tec.datos1.flow.handlers.Methods;
+import org.tec.datos1.flow.parts.DiagramView;
+import org.tec.datos1.flow.storage.ASTStorage;
+
+public class DebugStepper {
+
+ private static IJavaThread debugThread;
+
+ public static IJavaThread getDebugThread() {
+ return debugThread;
+ }
+
+ public static void setDebugThread(IJavaThread DebugThread) {
+ debugThread = DebugThread;
+ }
+ /**
+ * Este método se encarga de ejecutar la acción de
+ * StepInto del debugger de eclipse
+ */
+ public static void stepInto() {
+ try {
+ ASTStorage step = ASTStorage.getRoot().findLine(update());
+ if (step.getElement() instanceof MethodInvocation) {
+ debugThread.stepInto();
+ int currentLine = update();
+ DiagramView.setLineNumber(currentLine);
+ try {
+
+ MethodInvocation methodInvoc = (MethodInvocation) step.getElement();
+ ICompilationUnit newUnit = Methods.findClass(methodInvoc.resolveMethodBinding().getDeclaringClass().getQualifiedName());
+
+
+ if (!ASTStorage.getCompUnit().getJavaElement().getElementName()
+ .equals(newUnit.getElementName())){
+ CodeParser.executeSpecific(newUnit);
+ }
+
+ List methods = ASTStorage.getMethods();
+ String[] array = new String[methods.size()];
+ int cont = 0;
+ for(String method : methods) {
+ array[cont] = method;
+ cont++;
+ }
+
+ DiagramView.setMethods(array);
+ DiagramView.selectMethod(methodInvoc.getName().toString());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ else {
+ stepOver();
+ }
+
+ } catch (Exception e) {
+ stepOver();
+ }
+
+ }
+ /**
+ * Este método se encarga de ejecutar la acción de
+ * StepOver del debugger de eclipse
+ */
+ public static void stepOver() {
+ try {
+
+ debugThread.stepOver();
+ IJavaThread thread = getDebugThread();
+ int currentLine = update();
+ if (currentLine == -5) {
+ DiagramView.setLineNumber(-1);
+ return;}
+ DiagramView.setLineNumber(currentLine);
+ if ( !DiagramView.getMethodSelector().getText().equalsIgnoreCase(
+ ((MethodDeclaration)ASTStorage.getMethodByLine(currentLine).getElement()) //Null pointer exception al hacer step into o over a println
+ .getName().toString())) {
+
+ List methods = ASTStorage.getMethods();
+ String[] array = new String[methods.size()];
+ int cont = 0;
+ for(String method : methods) {
+ array[cont] = method;
+ cont++;
+ }
+
+ DiagramView.setMethods(array);
+ DiagramView.Select();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Este método se encarga de obtener la lÃnea en la que
+ * se encuentra el debugger en dicho instante.
+ */
+ public static int update(){
+ try {
+
+ IStackFrame Frame = null;
+ Integer time = 0;
+ while (Frame == null) {
+ if(time == 1000000) {
+ return -5;
+ }
+ time++;
+ Frame = debugThread.getTopStackFrame();
+ }
+ IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
+ IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
+ ICompilationUnit IcUnit = (ICompilationUnit) JavaCore.create(file);
+
+ if(!IcUnit.getElementName().equalsIgnoreCase(ASTStorage.getCompUnit().getJavaElement().getElementName())) {
+ CodeParser.executeSpecific(IcUnit);
+ }
+ return Frame.getLineNumber();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return 0;
+ }
+}
diff --git a/src/org/tec/datos1/flow/graphics/ASTStorageParser.java b/src/org/tec/datos1/flow/graphics/ASTStorageParser.java
new file mode 100644
index 0000000..142eed9
--- /dev/null
+++ b/src/org/tec/datos1/flow/graphics/ASTStorageParser.java
@@ -0,0 +1,289 @@
+package org.tec.datos1.flow.graphics;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.DoStatement;
+import org.eclipse.jdt.core.dom.EnhancedForStatement;
+import org.eclipse.jdt.core.dom.ExpressionStatement;
+import org.eclipse.jdt.core.dom.ForStatement;
+import org.eclipse.jdt.core.dom.IfStatement;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.TryStatement;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.WhileStatement;
+import org.eclipse.swt.graphics.Point;
+import org.tec.datos1.flow.graphics.Widget;
+import org.tec.datos1.flow.storage.ASTStorage;
+import org.tec.datos1.flow.storage.DiagramSize;
+
+public class ASTStorageParser {
+ LinkedList scene;
+ int spacing = 30;
+ DiagramSize size;
+
+ public void setSpacing(int spacing) {
+ this.spacing = spacing;
+ }
+
+ /**
+ * Convierte un arbol ASTStorage a LinkedList
+ * @param storage Arbol AST que se va a convertir
+ * @return LinkedLIst con los widgets a dibujar
+ */
+ public LinkedList parse(List storage){
+ scene = new LinkedList();
+
+ DiagramSize size = new DiagramSize();
+ size.lastOutput = new Point(100, 20);
+ size.maxWidth = 0;
+
+ Start start = new Start(size.lastOutput);
+ scene.add(start);
+ size.lastOutput = start.getOutput();
+ size.maxWidth = start.getWidth();
+
+ size = draw(storage, size, this.scene);
+
+ this.size = size;
+
+ return this.scene;
+ }
+
+ /**
+ * Anade los elementos en orden a la lista de acuerdo al arbol ASTStorage
+ * @param storage Arbol a analizar
+ * @param x Posicion en X
+ * @param y Posicion en Y
+ */
+ public DiagramSize draw(List storage, DiagramSize size, LinkedList scene) {
+ for(ASTStorage storageElement : storage) {
+ ASTNode element = storageElement.getElement();
+ Point input = new Point(size.lastOutput.x, size.lastOutput.y + spacing);
+ Line union = new Line(size.lastOutput, input);
+ scene.add(union);
+ if (element == null) {
+ if (storageElement.getName().equals("Root") && storageElement.then) {
+ storageElement.getChildren();
+ System.out.println("Cuerpo if");
+ }else {
+ System.out.println("Else: ");
+ }
+
+ } else {
+ String[] clazz_aux = element.getClass().toString().split("\\.");
+ String clazz = clazz_aux[clazz_aux.length - 1];
+
+ if (clazz.equalsIgnoreCase("WhileStatement")) {
+
+ WhileStatement While = (WhileStatement) element;
+ While whileDiagram = new While(While.getExpression().toString(), input, storageElement.getLineNumber());
+ size.lastOutput = whileDiagram.getOutputTrue();
+ scene.add(whileDiagram);
+
+ DiagramSize bodySize = new DiagramSize();
+ bodySize.lastOutput = size.lastOutput;
+ bodySize.maxWidth = whileDiagram.getWidth();
+ bodySize = draw(storageElement.getChildren(), bodySize, scene);
+ size.lastOutput = bodySize.lastOutput;
+
+ Line returnLine = new Line(size.lastOutput, whileDiagram.getInputReturn(), bodySize.maxWidth, LineType.RETURN);
+ scene.add(returnLine);
+
+ bodySize.maxWidth += 40;
+
+ if(bodySize.maxWidth > size.maxWidth) {
+ size.maxWidth = bodySize.maxWidth;
+ }
+ size.lastOutput = new Point(size.lastOutput.x, size.lastOutput.y + 40);
+
+ Line falseLine = new Line(whileDiagram.getOutputFalse(), size.lastOutput, LineType.JUMP, "false", bodySize.maxWidth - whileDiagram.getWidth());
+ scene.add(falseLine);
+
+ } else if (clazz.equalsIgnoreCase("DoStatement")) {
+ DoStatement Do = (DoStatement) element;
+ size = draw(storageElement.getChildren(), size, scene);
+
+ Point newInput = new Point(size.lastOutput.x, size.lastOutput.y + spacing);
+ Line line = new Line(size.lastOutput, newInput, LineType.NONE);
+ scene.add(line);
+ While doDrawing = new While(Do.getExpression().toString(), newInput, storageElement.getLineNumber());
+ scene.add(doDrawing);
+
+ size.lastOutput = doDrawing.getInputReturn();
+ input.y -= 10;
+ Line returnLine = new Line(size.lastOutput, input, LineType.DORETURN);
+ scene.add(returnLine);
+
+ size.lastOutput = doDrawing.outputTrue;
+
+
+
+
+ } else if (clazz.equalsIgnoreCase("EnhancedForStatement")) {
+ EnhancedForStatement EnhancedFor = (EnhancedForStatement) element;
+
+ While whileDiagram = new While(EnhancedFor.getParameter().toString() + ":" + EnhancedFor.getExpression(), input, storageElement.getLineNumber());
+ size.lastOutput = whileDiagram.getOutputTrue();
+ if(whileDiagram.getWidth() > size.maxWidth) {
+ size.maxWidth = whileDiagram.getWidth();
+ }
+ scene.add(whileDiagram);
+
+ DiagramSize bodySize = new DiagramSize();
+ bodySize.lastOutput = size.lastOutput;
+ bodySize.maxWidth = 0;
+ bodySize = draw(storageElement.getChildren(), bodySize, scene);
+ size.lastOutput = bodySize.lastOutput;
+
+ Line returnLine = new Line(size.lastOutput, whileDiagram.getInputReturn(), bodySize.maxWidth, LineType.RETURN);
+ scene.add(returnLine);
+ bodySize.maxWidth += 40;
+
+ if(bodySize.maxWidth > size.maxWidth) {
+ size.maxWidth = bodySize.maxWidth;
+ }
+ size.lastOutput = new Point(size.lastOutput.x, size.lastOutput.y + 40);
+
+ Line falseLine = new Line(whileDiagram.getOutputFalse(), size.lastOutput, LineType.JUMP, "", bodySize.maxWidth - whileDiagram.getWidth());
+ scene.add(falseLine);
+
+ } else if (clazz.equalsIgnoreCase("ForStatement")) {
+ ForStatement For = (ForStatement) element;
+
+ While whileDiagram = new While(For.getExpression().toString(), input, storageElement.getLineNumber());
+ size.lastOutput = whileDiagram.getOutputTrue();
+ if(whileDiagram.getWidth() > size.maxWidth) {
+ size.maxWidth = whileDiagram.getWidth();
+ }
+ scene.add(whileDiagram);
+
+ DiagramSize bodySize = new DiagramSize();
+ bodySize.lastOutput = size.lastOutput;
+ bodySize.maxWidth = 0;
+ bodySize = draw(storageElement.getChildren(), bodySize, scene);
+ size.lastOutput = bodySize.lastOutput;
+
+ Line returnLine = new Line(size.lastOutput, whileDiagram.getInputReturn(), bodySize.maxWidth, LineType.RETURN);
+ scene.add(returnLine);
+ bodySize.maxWidth += 40;
+
+ if(bodySize.maxWidth > size.maxWidth) {
+ size.maxWidth = bodySize.maxWidth;
+ }
+ size.lastOutput = new Point(size.lastOutput.x, size.lastOutput.y + 40);
+
+ Line falseLine = new Line(whileDiagram.getOutputFalse(), size.lastOutput, LineType.JUMP, "false", bodySize.maxWidth - whileDiagram.getWidth());
+ scene.add(falseLine);
+
+ } else if (clazz.equalsIgnoreCase("IfStatement")) {
+ IfStatement If = (IfStatement) element;
+ If ifDrawing = new If(If.getExpression().toString(), input, storageElement.getLineNumber());
+ if(ifDrawing.getWidth() > size.maxWidth) {
+ size.maxWidth = ifDrawing.getWidth();
+ }
+ scene.add(ifDrawing);
+
+ LinkedList falseScene = new LinkedList();
+ DiagramSize falseSize = new DiagramSize();
+ falseSize.lastOutput = new Point(ifDrawing.getOutputFalse().x + 20, ifDrawing.getOutputFalse().y);
+ falseSize.maxWidth = 0;
+ falseSize = draw(storageElement.getChildren().get(1).getChildren(), falseSize, falseScene); //False
+ if (falseSize.lastOutput.x - falseSize.maxWidth / 2 <= input.x) {
+ for(Widget widget : falseScene) {
+ widget.fix(input.x - (falseSize.lastOutput.x - falseSize.maxWidth / 2) + 20);
+ }
+ falseSize.lastOutput.x += input.x - (falseSize.lastOutput.x - falseSize.maxWidth / 2) + 20;
+ }
+ Line elseLine = new Line(ifDrawing.getOutputFalse(), new Point(falseSize.lastOutput.x, ifDrawing.getOutputFalse().y), "false");
+ scene.add(elseLine);
+ scene.addAll(falseScene);
+
+
+
+ LinkedList trueScene = new LinkedList();
+ DiagramSize trueSize = new DiagramSize();
+ trueSize.lastOutput = new Point(ifDrawing.getOutputTrue().x - 20, ifDrawing.getOutputTrue().y);
+ trueSize.maxWidth = 0;
+ trueSize = draw(storageElement.getChildren().get(0).getChildren(), trueSize, trueScene); //True
+
+ if (trueSize.lastOutput.x + trueSize.maxWidth / 2 >= input.x) {
+ for(Widget widget : trueScene) {
+ widget.fix(input.x - (trueSize.lastOutput.x + trueSize.maxWidth / 2) - 20);
+ }
+ trueSize.lastOutput.x += input.x - (trueSize.lastOutput.x + trueSize.maxWidth / 2) - 20;
+ }
+ Line ifLine = new Line(ifDrawing.getOutputTrue(), new Point(trueSize.lastOutput.x, ifDrawing.getOutputTrue().y), "true");
+ scene.add(ifLine);
+ scene.addAll(trueScene);
+
+ if(trueSize.maxWidth > falseSize.maxWidth) {
+ if(size.maxWidth < 2 * (trueSize.maxWidth + this.spacing)) {
+ size.maxWidth = 2 * (trueSize.maxWidth + this.spacing);
+ }
+ } else {
+ if(size.maxWidth < 2 * (falseSize.maxWidth + this.spacing)) {
+ size.maxWidth = 2 * (falseSize.maxWidth + this.spacing);
+ }
+ }
+
+ int outputY;
+ if (trueSize.lastOutput.y >= falseSize.lastOutput.y) {
+ outputY = trueSize.lastOutput.y;
+ } else {
+ outputY = falseSize.lastOutput.y;
+ }
+ size.lastOutput = new Point(input.x, outputY + 10);
+ Line trueLine = new Line(trueSize.lastOutput, size.lastOutput, LineType.JOIN);
+ Line falseLine = new Line(falseSize.lastOutput, size.lastOutput, LineType.JOIN);
+ scene.add(trueLine);
+ scene.add(falseLine);
+
+ } else if (clazz.equalsIgnoreCase("TryStatement")) {
+ TryStatement Try = (TryStatement) element;
+
+ System.out.println("Try:");
+
+ } else if (clazz.equalsIgnoreCase("ExpressionStatement")) {
+
+ ExpressionStatement expression = (ExpressionStatement) element;
+
+ Process statement = new Process(expression.toString().replaceAll("\n", ""), input, storageElement.getLineNumber());
+ size.lastOutput = statement.getOutput();
+ if(statement.getWidth() > size.maxWidth) {
+ size.maxWidth = statement.getWidth();
+ }
+ scene.add(statement);
+
+ } else if (clazz.equalsIgnoreCase("VariableDeclarationStatement")) {
+ VariableDeclarationStatement variable = (VariableDeclarationStatement) element;
+ Process statement = new Process(variable.toString().replaceAll("\n", ""), input, storageElement.getLineNumber());
+ size.lastOutput = statement.getOutput();
+ if(statement.getWidth() > size.maxWidth) {
+ size.maxWidth = statement.getWidth();
+ }
+ scene.add(statement);
+
+ } else if (clazz.equalsIgnoreCase("MethodInvocation")) {
+ MethodInvocation method = (MethodInvocation) element;
+ String argumentos = method.arguments().toString().replace('[', '(').replace(']', ')');
+ Method methodDiagram = new Method(method.getName().toString() + argumentos, input, storageElement.getLineNumber());
+ size.lastOutput = methodDiagram.getOutput();
+ if(methodDiagram.getWidth() > size.maxWidth) {
+ size.maxWidth = methodDiagram.getWidth();
+ }
+ scene.add(methodDiagram);
+ } else {
+ System.out.println("OTRO: " + clazz);
+ }
+
+ }
+ }
+ return size;
+ }
+
+ public DiagramSize getSize() {
+ return this.size;
+ }
+}
diff --git a/src/org/tec/datos1/flow/graphics/If.java b/src/org/tec/datos1/flow/graphics/If.java
index 939c845..7779a5b 100644
--- a/src/org/tec/datos1/flow/graphics/If.java
+++ b/src/org/tec/datos1/flow/graphics/If.java
@@ -6,42 +6,40 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
-public class If {
+public class If implements Widget{
String text;
Point input;
Point outputTrue;
Point outputFalse;
- GC gc;
Rectangle focus;
+ int[] shape;
+ int line;
/**
- * Constructor para el gráfico de un condicional
- * @param gc Graphical Context en el cual se dibuja
+ * Constructor para el gr�fico de un condicional\
* @param text Texto que va a contener el condicional
* @param input Punto de entrada del condicional
*/
- public If(GC gc, String text, Point input) {
+ public If(String text, Point input, int line) {
+ Shell shell = new Shell();
+ GC gc = new GC(shell);
+
this.input = input;
this.outputTrue = new Point(input.x - 30 - gc.stringExtent(text).x / 2, input.y + gc.stringExtent(text).y / 2 + 20);
this.outputFalse = new Point(input.x + 30 + gc.stringExtent(text).x / 2, input.y + gc.stringExtent(text).y / 2 + 20);
this.text = text;
- this.gc = gc;
-
- int[] diamond = new int[] {input.x, input.y, outputFalse.x, outputFalse.y, input.x, input.y + gc.stringExtent(text).y + 40, outputTrue.x, outputTrue.y};
-
- gc.drawPolygon(diamond);
- gc.drawText(text, input.x - gc.stringExtent(text).x / 2, input.y + 20);
+ this.line = line;
}
/**
- * Constructor para el gráfico de un proceso
- * @param gc Graphical Context en el cual se dibuja
+ * Constructor para el grafico de un proceso
* @param text Texto que va a contener el proceso
* @param x Coordenada en x del punto de entrada del condicional
* @param y Coordenada en y del punto de entrada del condicional
*/
- public If(GC gc, String text, int x, int y) {
- this(gc, text, new Point(x, y));
+ public If(String text, int x, int y, int line) {
+ this(text, new Point(x, y), line);
}
/**
@@ -52,33 +50,63 @@ public Point getInput() {
}
/**
- * @return Punto de salida en caso de que se cumpla la condición
+ * @return Punto de salida en caso de que se cumpla la condicion
*/
public Point getOutputTrue() {
return outputTrue;
}
/**
- * @return Punto de salida en caso de que no se cumpla la condición
+ * @return Punto de salida en caso de que no se cumpla la condicion
*/
public Point getOutputFalse() {
return outputFalse;
}
//Todavia no funcionan bien
- public void execute() {
+// public void execute() {
+
+// this.focus = new Rectangle(input.x - 20 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 40, 40);
+// gc.drawRectangle(focus);
+// Color black = display.getSystemColor(SWT.COLOR_BLACK);
+// gc.setForeground(black);
+// gc.setLineWidth(1);
+// }
+//
+// public void end() {
+// this.focus = null;
+// }
+
+ /**
+ * Dibuja el grafico en el contexto grafico
+ * @param gc Contexto grafico en el que se va a dibujar
+ */
+ @Override
+ public void draw(GC gc, int line) {
+ shape = new int[] {input.x, input.y, outputFalse.x, outputFalse.y, input.x, input.y + gc.stringExtent(text).y + 40, outputTrue.x, outputTrue.y};
Display display = Display.getCurrent();
- Color red = display.getSystemColor(SWT.COLOR_RED);
- gc.setForeground(red);
- gc.setLineWidth(3);
- this.focus = new Rectangle(input.x - 20 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 40, 40);
- gc.drawRectangle(focus);
- Color black = display.getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(black);
- gc.setLineWidth(1);
+ Color color;
+ int border;
+ if (line == this.line) {
+ color = display.getSystemColor(SWT.COLOR_RED);
+ border = 3;
+ } else {
+ color = display.getSystemColor(SWT.COLOR_BLACK);
+ border = 1;
+ }
+ gc.setForeground(color);
+ gc.setLineWidth(border);
+ gc.drawPolygon(shape);
+ gc.drawText(text, input.x - gc.stringExtent(text).x / 2, input.y + 20);
}
- public void end() {
- this.focus = null;
+ @Override
+ public void fix(int x) {
+ input = new Point(input.x + x, input.y);
+ outputTrue = new Point(outputTrue.x + x, outputTrue.y);
+ outputFalse = new Point(outputFalse.x + x, outputFalse.y);
+ }
+ public int getWidth() {
+ return outputFalse.x - outputTrue.x;
}
}
diff --git a/src/org/tec/datos1/flow/graphics/Line.java b/src/org/tec/datos1/flow/graphics/Line.java
index 76b6139..20432d3 100644
--- a/src/org/tec/datos1/flow/graphics/Line.java
+++ b/src/org/tec/datos1/flow/graphics/Line.java
@@ -1,27 +1,112 @@
package org.tec.datos1.flow.graphics;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Display;
-public class Line {
+public class Line implements Widget{
Point start;
Point finish;
+ LineType type;
+ String text= "";
+ int width;
- public Line(GC gc, Point start, Point finish) {
+ /**
+ * Constructor para el grafico de una linea
+ * @param start Punto de inicio de la linea
+ * @param finish Punto final de la linea
+ */
+ public Line(Point start, Point finish) {
this.start = start;
this.finish = finish;
-
- //Falta implementar la flecha de salida de un while
- if(finish.y < start.y) {
- gc.drawLine(start.x, start.y, start.x, start.y + 10);
- gc.drawLine(start.x, start.y + 10, 20, start.y + 10);
- gc.drawLine(20, start.y + 10, 20, finish.y);
- gc.drawLine(20, finish.y, finish.x, finish.y);
- } else if (start.x != finish.x) {
- gc.drawLine(start.x, start.y, finish.x, start.y);
- gc.drawLine(finish.x, start.y, finish.x, finish.y);
- } else {
- gc.drawLine(start.x, start.y, finish.x, finish.y);
+ this.type = LineType.NONE;
+ }
+
+ public Line(Point start, Point finish, int width) {
+ this(start, finish);
+ this.width = width;
+ }
+
+ public Line(Point start, Point finish, int width, LineType type) {
+ this(start, finish);
+ this.width = width;
+ this.type = type;
+ }
+
+ public Line(Point start, Point finish, LineType type) {
+ this(start, finish);
+ this.type = type;
+ }
+
+ public Line(Point start, Point finish, LineType type, String text) {
+ this(start, finish, type);
+ this.text = text;
+ }
+
+ public Line(Point start, Point finish, LineType type, String text, int width) {
+ this(start, finish, width);
+ this.type = type;
+ this.text = text;
+ }
+
+ public Line(Point start, Point finish, String text) {
+ this(start, finish);
+ this.text = text;
+ }
+
+ /**
+ * Dibuja el elemento en el contexto grafico
+ * @param gc Contexto grafico en el cual se va a dibujar
+ */
+ public void draw(GC gc, int line) {
+ Display display = Display.getCurrent();
+ Color color = display.getSystemColor(SWT.COLOR_BLACK);
+ gc.setForeground(color);
+ gc.setLineWidth(1);
+ switch (this.type) {
+ case DORETURN:
+ gc.drawLine(this.start.x, this.start.y, this.start.x - this.width / 2 - 20, this.start.y);
+ gc.drawLine(this.start.x - this.width / 2 - 20, this.start.y, this.start.x - this.width / 2 - 20, this.finish.y);
+ gc.drawLine(this.start.x - this.width / 2 - 20, this.finish.y, this.finish.x, this.finish.y);
+ break;
+ case RETURN:
+ gc.drawLine(this.start.x, this.start.y, this.start.x, this.start.y + 10);
+ gc.drawLine(this.start.x, this.start.y + 10, this.start.x - this.width / 2 - 20, this.start.y + 10);
+ gc.drawLine(this.start.x - this.width / 2 - 20, this.start.y + 10, this.start.x - this.width / 2 - 20, this.finish.y);
+ gc.drawLine(this.start.x - this.width / 2 - 20, this.finish.y, this.finish.x, this.finish.y);
+ break;
+ case JOIN:
+ gc.drawLine(this.start.x, this.start.y, this.start.x, this.finish.y);
+ gc.drawLine(this.start.x, this.finish.y, this.finish.x, this.finish.y);
+ break;
+ case JUMP:
+ gc.drawText(text, this.start.x + 10, this.start.y - 15);
+ gc.drawLine(this.start.x, this.start.y, this.start.x + this.width / 2 + 20, this.start.y);
+ gc.drawLine(this.start.x + this.width / 2 + 20, this.start.y, this.start.x + this.width / 2 + 20, this.finish.y);
+ gc.drawLine(this.start.x + this.width / 2 + 20, this.finish.y, this.finish.x, this.finish.y);
+ break;
+ case NONE:
+ if (this.start.x != this.finish.x) {
+ if (this.finish.x < this.start.x) {
+ gc.drawText(text, start.x - 30, start.y - 15);
+ } else {
+ gc.drawText(text, this.start.x + 10, this.start.y - 15);
+ }
+ gc.drawLine(this.start.x, this.start.y, this.finish.x, this.start.y);
+ gc.drawLine(this.finish.x, this.start.y, this.finish.x, this.finish.y);
+ } else {
+ gc.drawText(text, this.start.x + 5, this.start.y + 5);
+ gc.drawLine(this.start.x, this.start.y, this.finish.x, this.finish.y);
+ }
+ break;
+ }
}
+
+ @Override
+ public void fix(int x) {
+ start = new Point(start.x + x, start.y);
+ finish = new Point(finish.x + x, finish.y);
}
}
diff --git a/src/org/tec/datos1/flow/graphics/LineType.java b/src/org/tec/datos1/flow/graphics/LineType.java
new file mode 100644
index 0000000..37dffb3
--- /dev/null
+++ b/src/org/tec/datos1/flow/graphics/LineType.java
@@ -0,0 +1,5 @@
+package org.tec.datos1.flow.graphics;
+
+public enum LineType {
+ RETURN, JUMP, JOIN, NONE, DORETURN
+}
diff --git a/src/org/tec/datos1/flow/graphics/Method.java b/src/org/tec/datos1/flow/graphics/Method.java
index 36ba1c6..460399d 100644
--- a/src/org/tec/datos1/flow/graphics/Method.java
+++ b/src/org/tec/datos1/flow/graphics/Method.java
@@ -6,41 +6,35 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
-public class Method {
+public class Method implements Widget{
String text;
Point input;
Point output;
- GC gc;
Rectangle focus;
+ int line;
/**
- * Constructor para el gráfico de un método
- * @param gc Graphical Context en el cual se dibuja
- * @param text Texto que va a contener el método
- * @param input Punto de entrada del método
+ * Constructor para el grafico de un metodo
+ * @param text Texto que va a contener el metodo
+ * @param input Punto de entrada del metodo
*/
- public Method(GC gc, String text, Point input) {
+ public Method(String text, Point input, int line) {
this.input = input;
this.output = new Point(input.x, input.y + 40);
this.text = text;
- this.gc = gc;
-
- Rectangle rectangle = new Rectangle(input.x - 10 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 20, 40);
- gc.drawRectangle(rectangle);
- Rectangle externalRectangle = new Rectangle(input.x - 20 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 40, 40);
- gc.drawRectangle(externalRectangle);
- gc.drawText(text, input.x - gc.stringExtent(text).x / 2, input.y + (40 - gc.stringExtent(text).y) / 2);
+ this.line = line;
}
/**
- * Constructor para el gráfico de un método
+ * Constructor para el grafico de un metodo
* @param gc Graphical Context en el cual se dibuja
- * @param text Texto que va a contener el método
- * @param x Coordenada en x del punto de entrada del método
- * @param y Coordenada en y del punto de entrada del método
+ * @param text Texto que va a contener el metodo
+ * @param x Coordenada en x del punto de entrada del metodo
+ * @param y Coordenada en y del punto de entrada del metodo
*/
- public Method(GC gc, String text, int x, int y) {
- this(gc, text, new Point(x, y));
+ public Method(String text, int x, int y, int line) {
+ this(text, new Point(x, y), line);
}
/**
@@ -58,19 +52,58 @@ public Point getInput() {
}
//Todavia no funcionan bien
- public void execute() {
+// public void execute() {
+// Display display = Display.getCurrent();
+// Color red = display.getSystemColor(SWT.COLOR_RED);
+// gc.setForeground(red);
+// gc.setLineWidth(3);
+// this.focus = new Rectangle(input.x - 20 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 40, 40);
+// gc.drawRectangle(focus);
+// Color black = display.getSystemColor(SWT.COLOR_BLACK);
+// gc.setForeground(black);
+// gc.setLineWidth(1);
+// }
+//
+// public void end() {
+// this.focus = null;
+// }
+
+ /**
+ * Dibuja el metodo en el contexto grafico
+ * @param gc Contexto grafico en el que se va a dibujar
+ */
+ @Override
+ public void draw(GC gc, int line) {
Display display = Display.getCurrent();
- Color red = display.getSystemColor(SWT.COLOR_RED);
- gc.setForeground(red);
- gc.setLineWidth(3);
- this.focus = new Rectangle(input.x - 20 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 40, 40);
- gc.drawRectangle(focus);
- Color black = display.getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(black);
- gc.setLineWidth(1);
+ Color color;
+ int border;
+ if (line == this.line) {
+ color = display.getSystemColor(SWT.COLOR_RED);
+ border = 3;
+ } else {
+ color = display.getSystemColor(SWT.COLOR_BLACK);
+ border = 1;
+ }
+ gc.setForeground(color);
+ gc.setLineWidth(border);
+ Rectangle rectangle = new Rectangle(input.x - 10 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 20, 40);
+ gc.drawRectangle(rectangle);
+ Rectangle externalRectangle = new Rectangle(input.x - 20 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 40, 40);
+ gc.drawRectangle(externalRectangle);
+ gc.drawText(text, input.x - gc.stringExtent(text).x / 2, input.y + (40 - gc.stringExtent(text).y) / 2);
+ }
+ @Override
+ public void fix(int x) {
+ input = new Point(input.x + x, input.y);
+ output = new Point(output.x + x, output.y);
+ }
+ public int getWidth() {
+ Shell shell = new Shell();
+ GC gc = new GC(shell);
+ return gc.stringExtent(text).x + 40;
}
- public void end() {
- this.focus = null;
+ public int getLine() {
+ return this.line;
}
}
diff --git a/src/org/tec/datos1/flow/graphics/Process.java b/src/org/tec/datos1/flow/graphics/Process.java
index 1b732b6..57aa3c4 100644
--- a/src/org/tec/datos1/flow/graphics/Process.java
+++ b/src/org/tec/datos1/flow/graphics/Process.java
@@ -6,39 +6,36 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
-public class Process {
+public class Process implements Widget{
String text;
Point input;
Point output;
- GC gc;
+ int line;
/**
- * Constructor para el gráfico de un proceso
- * @param gc Graphical Context en el cual se dibuja
+ * Constructor para el grafico de un proceso
* @param text Texto que va a contener el proceso
* @param input Punto de entrada del proceso
*/
- public Process(GC gc, String text, Point input) {
+ public Process(String text, Point input, int line) {
this.input = input;
this.output = new Point(input.x, input.y + 40);
this.text = text;
- this.gc = gc;
+ this.line = line;
- Rectangle rectangle = new Rectangle(input.x - 10 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 20, 40);
- gc.drawRectangle(rectangle);
- gc.drawText(text, input.x - gc.stringExtent(text).x / 2, input.y + (40 - gc.stringExtent(text).y) / 2);
}
/**
- * Constructor para el gráfico de un proceso
+ * Constructor para el grafico de un proceso
* @param gc Graphical Context en el cual se dibuja
* @param text Texto que va a contener el proceso
* @param x Coordenada en x del punto de entrada del proceso
* @param y Coordenada en y del punto de entrada del proceso
*/
- public Process(GC gc, String text, int x, int y) {
- this(gc, text, new Point(x, y));
+ public Process(String text, int x, int y, int line) {
+ this(text, new Point(x, y), line);
}
/**
@@ -55,16 +52,39 @@ public Point getInput() {
return input;
}
- //Todavia no funcionan bien
- public void execute() {
+ /**
+ * Dibuja el grafico en el contexto grafico
+ * @param gc Contexto grafico en el cual se va a dibujar
+ */
+ @Override
+ public void draw(GC gc, int line) {
Display display = Display.getCurrent();
- Color red = display.getSystemColor(SWT.COLOR_RED);
- gc.setForeground(red);
+ Color color;
+ int border;
+ if (line == this.line) {
+ color = display.getSystemColor(SWT.COLOR_RED);
+ border = 3;
+ } else {
+ color = display.getSystemColor(SWT.COLOR_BLACK);
+ border = 1;
+ }
+ gc.setForeground(color);
+ gc.setLineWidth(border);
+ Rectangle rectangle = new Rectangle(input.x - 10 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 20, 40);
+ gc.drawRectangle(rectangle);
+ gc.drawText(text, input.x - gc.stringExtent(text).x / 2, input.y + (40 - gc.stringExtent(text).y) / 2);
}
-
- public void end() {
- Display display = Display.getCurrent();
- Color black = display.getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(black);
+ @Override
+ public void fix(int x) {
+ input = new Point(input.x + x, input.y);
+ output = new Point(output.x + x, output.y);
+ }
+ public int getWidth() {
+ Shell shell = new Shell();
+ GC gc = new GC(shell);
+ return gc.stringExtent(text).x + 20;
+ }
+ public int getLine() {
+ return this.line;
}
}
diff --git a/src/org/tec/datos1/flow/graphics/Start.java b/src/org/tec/datos1/flow/graphics/Start.java
new file mode 100644
index 0000000..f1fe30d
--- /dev/null
+++ b/src/org/tec/datos1/flow/graphics/Start.java
@@ -0,0 +1,67 @@
+package org.tec.datos1.flow.graphics;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Display;
+
+public class Start implements Widget{
+ Point input;
+ Point output;
+ int width = 80;
+
+ /**
+ * Constructor para el grafico de un proceso
+ * @param text Texto que va a contener el proceso
+ * @param input Punto de entrada del proceso
+ */
+ public Start(Point input) {
+ this.input = input;
+ this.output = new Point(input.x, input.y + 40);
+ }
+ /**
+ * Constructor para el grafico de un proceso
+ * @param gc Graphical Context en el cual se dibuja
+ * @param text Texto que va a contener el proceso
+ * @param x Coordenada en x del punto de entrada del proceso
+ * @param y Coordenada en y del punto de entrada del proceso
+ */
+ public Start(int x, int y) {
+ this(new Point(x, y));
+ }
+
+ /**
+ * @return Punto de salida del proceso
+ */
+ public Point getOutput() {
+ return output;
+ }
+
+ /**
+ * @return Punto de entrada del proceso
+ */
+ public Point getInput() {
+ return input;
+ }
+
+ /**
+ * Dibuja el grafico en el contexto grafico
+ * @param gc Contexto grafico en el cual se va a dibujar
+ */
+ @Override
+ public void draw(GC gc, int line) {
+ gc.drawOval(input.x - this.width / 2, input.y, this.width, 40);
+ gc.drawText("Start", input.x - gc.stringExtent("Start").x / 2, input.y + (40 - gc.stringExtent("Start").y) / 2);
+ }
+ @Override
+ public void fix(int x) {
+ input = new Point(input.x + x, input.y);
+ output = new Point(output.x + x, output.y);
+ }
+
+ public int getWidth() {
+ return this.width;
+ }
+}
diff --git a/src/org/tec/datos1/flow/graphics/While.java b/src/org/tec/datos1/flow/graphics/While.java
index b73fc07..533d1d3 100644
--- a/src/org/tec/datos1/flow/graphics/While.java
+++ b/src/org/tec/datos1/flow/graphics/While.java
@@ -6,45 +6,44 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
-public class While {
+public class While implements Widget{
String text;
Point input;
Point outputTrue;
Point outputFalse;
Point inputReturn;
- GC gc;
Rectangle focus;
+ int line;
/**
- * Constructor para el gráfico de un condicional
- * @param gc Graphical Context en el cual se dibuja
+ * Constructor para el grafico de un condicional
* @param text Texto que va a contener el condicional
* @param input Punto de entrada del condicional
*/
- public While(GC gc, String text, Point input) {
+ public While(String text, Point input, int line) {
+ Shell shell = new Shell();
+ GC gc = new GC(shell);
+
+
this.input = input;
- this.outputTrue = new Point(input.x, input.y + gc.stringExtent(text).y + 40);
+ this.outputTrue = new Point(input.x, input.y + 60);
this.outputFalse = new Point(input.x + 30 + gc.stringExtent(text).x / 2, input.y + gc.stringExtent(text).y / 2 + 20);
this.inputReturn = new Point(input.x - 30 - gc.stringExtent(text).x / 2, input.y + gc.stringExtent(text).y / 2 + 20);
this.text = text;
- this.gc = gc;
-
- int[] diamond = new int[] {input.x, input.y, outputFalse.x, outputFalse.y, outputTrue.x, outputTrue.y, inputReturn.x, inputReturn.y};
-
- gc.drawPolygon(diamond);
- gc.drawText(text, input.x - gc.stringExtent(text).x / 2, input.y + 20);
+ this.line = line;
}
/**
- * Constructor para el gráfico de un proceso
+ * Constructor para el grafico de un proceso
* @param gc Graphical Context en el cual se dibuja
* @param text Texto que va a contener el proceso
* @param x Coordenada en x del punto de entrada del condicional
* @param y Coordenada en y del punto de entrada del condicional
*/
- public While(GC gc, String text, int x, int y) {
- this(gc, text, new Point(x, y));
+ public While(String text, int x, int y, int line) {
+ this(text, new Point(x, y), line);
}
/**
@@ -62,33 +61,51 @@ public Point getInputReturn() {
}
/**
- * @return Punto de salida en caso de que se cumpla la condición
+ * @return Punto de salida en caso de que se cumpla la condici�n
*/
public Point getOutputTrue() {
return outputTrue;
}
/**
- * @return Punto de salida en caso de que no se cumpla la condición
+ * @return Punto de salida en caso de que no se cumpla la condici�n
*/
public Point getOutputFalse() {
return outputFalse;
}
- //Todavia no funcionan bien
- public void execute() {
+ /**
+ * Dibuja el grafico en el contexto grafico
+ * param gc Contexto grafico en el que se va a dibujar
+ */
+ @Override
+ public void draw(GC gc, int line) {
Display display = Display.getCurrent();
- Color red = display.getSystemColor(SWT.COLOR_RED);
- gc.setForeground(red);
- gc.setLineWidth(3);
- this.focus = new Rectangle(input.x - 20 - gc.stringExtent(text).x / 2, input.y, gc.stringExtent(text).x + 40, 40);
- gc.drawRectangle(focus);
- Color black = display.getSystemColor(SWT.COLOR_BLACK);
- gc.setForeground(black);
- gc.setLineWidth(1);
+ Color color;
+ int border;
+ if (line == this.line) {
+ color = display.getSystemColor(SWT.COLOR_RED);
+ border = 3;
+ } else {
+ color = display.getSystemColor(SWT.COLOR_BLACK);
+ border = 1;
+ }
+ gc.setForeground(color);
+ gc.setLineWidth(border);
+
+ int [] shape = new int[] {input.x, input.y, outputFalse.x, outputFalse.y, outputTrue.x, outputTrue.y, inputReturn.x, inputReturn.y};
+
+ gc.drawPolygon(shape);
+ gc.drawText(text, input.x - gc.stringExtent(text).x / 2, input.y + 20);
}
-
- public void end() {
- this.focus = null;
+ @Override
+ public void fix(int x) {
+ input = new Point(input.x + x, input.y);
+ outputTrue = new Point(outputTrue.x + x, outputTrue.y);
+ outputFalse = new Point(outputFalse.x + x, outputFalse.y);
+ inputReturn = new Point(inputReturn.x + x, inputReturn.y);
+ }
+ public int getWidth() {
+ return outputFalse.x - inputReturn.x;
}
}
diff --git a/src/org/tec/datos1/flow/graphics/Widget.java b/src/org/tec/datos1/flow/graphics/Widget.java
new file mode 100644
index 0000000..ab1d624
--- /dev/null
+++ b/src/org/tec/datos1/flow/graphics/Widget.java
@@ -0,0 +1,12 @@
+package org.tec.datos1.flow.graphics;
+
+import org.eclipse.swt.graphics.GC;
+
+public interface Widget {
+ /**
+ * Dibuja el widget en el contexto grafico
+ * @param gc Contexto grafico en el que se va a dibujar
+ */
+ public void draw(GC gc, int line);
+ public void fix(int x);
+}
diff --git a/src/org/tec/datos1/flow/handlers/Load.java b/src/org/tec/datos1/flow/handlers/Load.java
new file mode 100644
index 0000000..cef9aab
--- /dev/null
+++ b/src/org/tec/datos1/flow/handlers/Load.java
@@ -0,0 +1,34 @@
+package org.tec.datos1.flow.handlers;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.swt.widgets.Shell;
+import org.tec.datos1.flow.CodeParser;
+import org.tec.datos1.flow.parts.DiagramView;
+import org.tec.datos1.flow.storage.ASTStorage;
+
+public class Load {
+
+ @Execute
+ public void execute(Shell shell) {
+ try {
+ CodeParser.execute();
+ Methods.load();
+ List methods = ASTStorage.getMethods();
+ String[] array = new String[methods.size()];
+ int cont = 0;
+ for(String method : methods) {
+ array[cont] = method;
+ cont++;
+ }
+ DiagramView.setMethods(array);
+ DiagramView.setLineNumber(-1);
+
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+
+ }
+}
diff --git a/src/org/tec/datos1/flow/handlers/MethodVisitor.java b/src/org/tec/datos1/flow/handlers/MethodVisitor.java
index 2c51038..78eb59e 100644
--- a/src/org/tec/datos1/flow/handlers/MethodVisitor.java
+++ b/src/org/tec/datos1/flow/handlers/MethodVisitor.java
@@ -1,174 +1,39 @@
package org.tec.datos1.flow.handlers;
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Block;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.DoStatement;
-import org.eclipse.jdt.core.dom.EnhancedForStatement;
-import org.eclipse.jdt.core.dom.ExpressionStatement;
-import org.eclipse.jdt.core.dom.ForStatement;
-import org.eclipse.jdt.core.dom.IMethodBinding;
-import org.eclipse.jdt.core.dom.IfStatement;
import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jdt.core.dom.MethodInvocation;
-import org.eclipse.jdt.core.dom.TryStatement;
-import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
-import org.eclipse.jdt.core.dom.WhileStatement;
-
import org.tec.datos1.flow.storage.ASTStorage;
+
public class MethodVisitor extends ASTVisitor {
ASTStorage Root = new ASTStorage(null, "Root");
- List methods = new ArrayList<>();
-
- @Override
+
+ /**
+ * Este método se ejecuta cuando se encuentra una declaración de
+ * método durante el parseo del código
+ */
+ @SuppressWarnings("unchecked")
+ @Override
public boolean visit(MethodDeclaration methodNode) {
- //methods.add(node);
+
+
+ if (ASTStorage.getRoot() == null) {
+ ASTStorage.setRoot(Root);
+ }
try {
-
- ASTStorage storageMethod = new ASTStorage(methodNode,Root,methodNode.getName().toString());
+ ASTStorage storageMethod = new ASTStorage(methodNode,methodNode.getName().toString());
Root.addChild(storageMethod);
Block b1 = (Block)methodNode.getBody();
- addChildren(storageMethod, b1.statements());
- storageMethod.print(0);
- System.out.println(getRoot());
+ storageMethod.addChildren(b1.statements());
- }catch(Exception ex) { ex.printStackTrace();}
+ }catch(Exception ex) {ex.printStackTrace();}
- methods.add(methodNode);
return super.visit(methodNode);
}
- public List getMethods() {
- return methods;
- }
- public List getRoot() {
- return Root.getChildren();
- }
-
- public static String addChildren(ASTStorage parent, List Statements) {
-
- for (Object statement : Statements) {
- ASTNode child = (ASTNode) statement;
- addChildrenAux(parent,child);
- //ASTNode.nodeClassForType(node2.getNodeType());
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- public static void addChildrenAux(ASTStorage parent, ASTNode child) {
- String[] clazz_aux = child.getClass().toString().split("\\.");
- String clazz = clazz_aux[clazz_aux.length - 1];
-
- if (clazz.equalsIgnoreCase("WhileStatement")) {
- WhileStatement While = (WhileStatement) child;
- ASTStorage WhileStorage = new ASTStorage(While,parent,While.getExpression().toString());
- parent.addChild(WhileStorage);
- //System.out.println("While: \n" + While.getExpression());
-
- Block block = (Block) While.getBody();
-
- addChildren(WhileStorage, block.statements());
- } else if (clazz.equalsIgnoreCase("DoStatement")) {
- DoStatement Do = (DoStatement) child;
- ASTStorage DoStorage = new ASTStorage(Do,parent, Do.getExpression().toString());
- parent.addChild(DoStorage);
- //System.out.println("Do: \n" + Do.getExpression());
- Block block = (Block) Do.getBody();
-
- addChildren(DoStorage, block.statements());
-
- } else if (clazz.equalsIgnoreCase("EnhancedForStatement")) {
- EnhancedForStatement EnhancedFor = (EnhancedForStatement) child;
- ASTStorage EnhancedForStorage = new ASTStorage(EnhancedFor,parent,EnhancedFor.getExpression().toString());
- parent.addChild(EnhancedForStorage);
- //System.out.println("EnhancedFor: \n" + EnhancedFor.getExpression());
- Block block = (Block) EnhancedFor.getBody();
-
- addChildren(EnhancedForStorage, block.statements());
-
- } else if (clazz.equalsIgnoreCase("ForStatement")) {
- ForStatement For = (ForStatement) child;
- ASTStorage ForStorage = new ASTStorage(For,parent,For.getExpression().toString());
- parent.addChild(ForStorage);
- //System.out.println("For: \n" + For.getExpression());
- Block block = (Block) For.getBody();
-
- addChildren(ForStorage, block.statements());
-
- } else if (clazz.equalsIgnoreCase("IfStatement")) {
- IfStatement If = (IfStatement) child;
- ASTStorage IfStorage = new ASTStorage(If,parent,If.getExpression().toString());
- parent.addChild(IfStorage);
- ASTStorage thenStorage = new ASTStorage(null,parent,true,If.getExpression().toString());
- IfStorage.addChild(thenStorage);
- Block b1 = (Block) If.getThenStatement();
- addChildren(thenStorage, b1.statements());
-
- if (If.getElseStatement() instanceof Block) {
- //System.out.println("If: \n" + If.getThenStatement() + "Else: \n" + If.getElseStatement());
- ASTStorage elseStorage = new ASTStorage(null,parent,false,If.getExpression().toString());
- IfStorage.addChild(elseStorage);
- Block b2 = (Block) If.getElseStatement();
- addChildren(elseStorage, b2.statements());
- } else {
- //System.out.println("If: \n" + If.getThenStatement() + "Else ");
- ASTStorage elseStorage = new ASTStorage(null,parent,false, If.getExpression().toString());
- IfStorage.addChild(elseStorage);
- IfStatement If2 = (IfStatement) If.getElseStatement();
- addChildrenAux(elseStorage, If2);
- }
-
- } else if(clazz.equalsIgnoreCase("TryStatement")){
- TryStatement Try = (TryStatement) child;
- ASTStorage TryStorage = new ASTStorage(Try,parent,"Try");
- parent.addChild(TryStorage);
-
- //System.out.println("For: \n");
- Block block = (Block) Try.getBody();
-
- addChildren(TryStorage, block.statements());
-
- } else if (clazz.equalsIgnoreCase("ExpressionStatement")) {
-
- ExpressionStatement Expression = (ExpressionStatement) child;
-
- try{
- MethodInvocation methodInvocation = (MethodInvocation) Expression.getExpression();
- ASTStorage MethoInvocationStorage = new ASTStorage(methodInvocation, parent, methodInvocation.toString());
- parent.addChild(MethoInvocationStorage);
-
-// IMethodBinding binding = methodInvocation.resolveMethodBinding().getMethodDeclaration();
-// ICompilationUnit unit = (ICompilationUnit) binding.getJavaElement().getAncestor( IJavaElement.COMPILATION_UNIT );
-// CompilationUnit parse = Handler.parse(unit);
-// MethodDeclaration decl = (MethodDeclaration)parse.findDeclaringNode( binding.getKey() );
-
- //System.out.println(decl.getBody());
-
- }catch(Exception ex) {
- ASTStorage ExpressionStorage = new ASTStorage(Expression,parent,Expression.toString());
- parent.addChild(ExpressionStorage);
- }
-
- //System.out.println("Expression:" + Expression.getExpression());
-
- }else if (clazz.equalsIgnoreCase("VariableDeclarationFragment")) {
- VariableDeclarationFragment Variable = (VariableDeclarationFragment) child;
- ASTStorage VariableStorage = new ASTStorage(Variable,parent,Variable.toString());
- parent.addChild(VariableStorage);
- }else {
- System.out.println("OTRO: " + clazz);
- }
-
- }
}
\ No newline at end of file
diff --git a/src/org/tec/datos1/flow/handlers/Methods.java b/src/org/tec/datos1/flow/handlers/Methods.java
new file mode 100644
index 0000000..c79c56d
--- /dev/null
+++ b/src/org/tec/datos1/flow/handlers/Methods.java
@@ -0,0 +1,73 @@
+package org.tec.datos1.flow.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+
+public class Methods extends ASTVisitor{
+ static List classes = new ArrayList();
+ private static final String JDT_NATURE = "org.eclipse.jdt.core.javanature";
+
+
+
+ public static ICompilationUnit findClass(String clazz) {
+ clazz = "src." + clazz + ".java";
+ for(ICompilationUnit current : classes) {
+
+ String name = current.getResource().getProjectRelativePath().toString().replace("/", ".");
+ if (clazz.equals(name)) {
+ return current;
+ }
+ }
+ return null;
+ }
+
+
+ public static void load() {
+ if (classes.size() != 0) return;
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceRoot root = workspace.getRoot();
+ // Get all projects in the workspace
+ IProject[] projects = root.getProjects();
+ // Loop over all projects
+ for (IProject project : projects) {
+ try {
+ if (project.isNatureEnabled(JDT_NATURE)) {
+ analyseMethods(project);
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static void analyseMethods(IProject project) throws JavaModelException {
+ IPackageFragment[] packages = JavaCore.create(project)
+ .getPackageFragments();
+ // parse(JavaCore.create(project));
+ for (IPackageFragment mypackage : packages) {
+ if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) {
+ createAST(mypackage);
+ }
+
+ }
+ }
+
+ private static void createAST(IPackageFragment mypackage)
+ throws JavaModelException {
+ for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
+ classes.add(unit);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/org/tec/datos1/flow/handlers/StepInHandler.java b/src/org/tec/datos1/flow/handlers/StepInHandler.java
index 447d148..7b1e33c 100644
--- a/src/org/tec/datos1/flow/handlers/StepInHandler.java
+++ b/src/org/tec/datos1/flow/handlers/StepInHandler.java
@@ -1,11 +1,17 @@
package org.tec.datos1.flow.handlers;
import org.eclipse.swt.widgets.Shell;
+import org.tec.datos1.flow.debug.DebugStepper;
import org.eclipse.e4.core.di.annotations.Execute;
public class StepInHandler {
+ /**
+ * Se ejecuta al presionar el boton
+ * @param shell Ventana donde se va a ejecutar la accion
+ */
@Execute
public void execute(Shell shell) {
- System.out.println("Stepped in");
+ if (DebugStepper.getDebugThread() != null)
+ DebugStepper.stepInto();
}
}
diff --git a/src/org/tec/datos1/flow/handlers/StepOverHandler.java b/src/org/tec/datos1/flow/handlers/StepOverHandler.java
index ba0946a..f929cde 100644
--- a/src/org/tec/datos1/flow/handlers/StepOverHandler.java
+++ b/src/org/tec/datos1/flow/handlers/StepOverHandler.java
@@ -1,12 +1,18 @@
package org.tec.datos1.flow.handlers;
import org.eclipse.swt.widgets.Shell;
+import org.tec.datos1.flow.debug.DebugStepper;
import org.eclipse.e4.core.di.annotations.Execute;
public class StepOverHandler {
+ /**
+ * Se ejecuta al presionar el boton
+ * @param shell Ventana donde se va a ejecutar la accion
+ */
@Execute
public void execute(Shell shell) {
- System.out.println("Stepped over");
+ if (DebugStepper.getDebugThread() != null)
+ DebugStepper.stepOver();
}
}
diff --git a/src/org/tec/datos1/flow/parts/DiagramView.java b/src/org/tec/datos1/flow/parts/DiagramView.java
index 8eda551..97945b3 100644
--- a/src/org/tec/datos1/flow/parts/DiagramView.java
+++ b/src/org/tec/datos1/flow/parts/DiagramView.java
@@ -2,51 +2,147 @@
+import java.util.LinkedList;
import javax.inject.Inject;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.ScrollBar;
-import org.tec.datos1.flow.graphics.If;
-import org.tec.datos1.flow.graphics.Line;
-import org.tec.datos1.flow.graphics.Method;
-import org.tec.datos1.flow.graphics.Process;
-import org.tec.datos1.flow.graphics.While;
+import org.tec.datos1.flow.graphics.ASTStorageParser;
+import org.tec.datos1.flow.graphics.Widget;
+import org.tec.datos1.flow.storage.ASTStorage;
+import org.tec.datos1.flow.storage.DiagramSize;
public class DiagramView {
+ private static Canvas canvas;
+ static LinkedList diagram;
+ static DiagramSize diagramSize;
+ static Combo methodSelector;
+ private static Integer lineNumber = -1;
+
+ /**
+ * Crea la vista para el plugin
+ * @param parent Componente de la interfaz en el cual se va a generar los graficos
+ */
@Inject
public DiagramView(Composite parent) {
- ScrolledComposite container = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
+ GridLayout layout = new GridLayout();
+ GridData diagramLayout = new GridData();
+ diagramLayout.grabExcessVerticalSpace = true;
+ diagramLayout.grabExcessHorizontalSpace = true;
+
+ GridData comboLayout = new GridData();
+ comboLayout.widthHint = 200;
+
+ parent.setLayout(layout);
- Canvas canvas = new Canvas(container, SWT.NONE);
+ methodSelector = new Combo(parent, SWT.NONE);
+ methodSelector.setLayoutData(comboLayout);
+
+ ScrolledComposite container = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
+ container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ container.setLayoutData(diagramLayout);
+ canvas = new Canvas(container, SWT.NONE);
canvas.setSize(1000, 1000);
container.setContent(canvas);
+
+
+
+ diagram = new LinkedList();
+
+ //Anade todo al selector
+ methodSelector.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Select();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ System.out.println("Default selected");
+ }
+ });
+
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
- Rectangle clientArea = parent.getClientArea();
- Method metodo = new Method(e.gc, "System.out.println(\"Hola mundo\")", clientArea.width / 2, 20);
- Process process = new Process(e.gc, "x = 1", clientArea.width / 2, 100);
- Line line1 = new Line(e.gc, metodo.getOutput(), process.getInput());
- If condicional = new If(e.gc, "a <= 1", clientArea.width / 2, 400);
- Line line2 = new Line(e.gc, process.getOutput(), condicional.getInput());
- While ciclo = new While(e.gc, "cont <= 100", clientArea.width * 2 / 3, 800);
- Line line3 = new Line(e.gc, condicional.getOutputFalse(), ciclo.getInput());
- Line line4 = new Line(e.gc, ciclo.getOutputTrue(), ciclo.getInputReturn());
-// canvas.setSize(size); Despues de dibujar el diagrama debe actualizar el tamano del canvas
+ for(Widget widget : diagram) {
+ widget.draw(e.gc, lineNumber);
+ }
}
-
});
+ }
+
+ public static void Select() {
+ try {
+ ASTStorageParser astParser = new ASTStorageParser();
+ if (lineNumber == -1) {
+ diagram = astParser.parse(ASTStorage.getMethod(methodSelector.getText()).getChildren());
+ }else {
+ ASTStorage storage = ASTStorage.getMethodByLine(lineNumber);
+ diagram = astParser.parse(storage.getChildren());
+ methodSelector.setText(((MethodDeclaration)storage.getElement()).getName().toString());
+ }
+ diagramSize = astParser.getSize();
+ canvas.setSize(diagramSize.maxWidth + 60, diagramSize.lastOutput.y + 40);
+ if (diagramSize.maxWidth / 2 > 100) {
+ for(Widget widget : diagram) {
+ widget.fix(diagramSize.maxWidth / 2 - 80);
+ }
+ }
+ canvas.redraw();
+
+ } catch (Exception e1) {
+ System.err.println("No se pudo parsear el arbol");
+ e1.printStackTrace();
+ canvas.redraw();
+ }
+ }
+
+ public static void setMethods(String[] methods) {
+ methodSelector.setItems(methods);
+ }
+
+ public static void selectMethod(String method) {
+ System.out.println("Buscando metodo");
+ System.out.println(method);
+ String[] methods = methodSelector.getItems();
+ for(int index = 0; index < methods.length ; index++) {
+ System.out.println("Comparando con " + methods[index]);
+ if (methods[index].equals(method)) {
+ System.out.println("Metodo seleccionado");
+ methodSelector.select(index);
+ Select();
+ }
+ }
+ }
+
+ public static Integer getLineNumber() {
+ return lineNumber;
+ }
+
+
+ public static void setLineNumber(Integer LineNumber) {
+ lineNumber = LineNumber;
+ canvas.redraw();
+
+ }
+ public static Combo getMethodSelector() {
+ return methodSelector;
}
}
diff --git a/src/org/tec/datos1/flow/storage/ASTStorage.java b/src/org/tec/datos1/flow/storage/ASTStorage.java
index e98a844..e715c10 100644
--- a/src/org/tec/datos1/flow/storage/ASTStorage.java
+++ b/src/org/tec/datos1/flow/storage/ASTStorage.java
@@ -5,23 +5,38 @@
import java.util.ArrayList;
import java.util.List;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.DoStatement;
+import org.eclipse.jdt.core.dom.EnhancedForStatement;
+import org.eclipse.jdt.core.dom.ExpressionStatement;
+import org.eclipse.jdt.core.dom.ForStatement;
+import org.eclipse.jdt.core.dom.IfStatement;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.TryStatement;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.WhileStatement;
public class ASTStorage {
+ static ASTStorage root;
String Name;
ASTNode Element;
List Children;
- Boolean then;
- ASTStorage Parent;
-
+ public Boolean then;
+ static CompilationUnit compilationUnit;
public ASTStorage(ASTNode Element,ASTStorage Parent,String Name) {
this.Element = Element;
this.Children = new ArrayList();
- this.Parent = Parent;
this.Name = Name;
- }
+ }
public ASTStorage(ASTNode Element,String Name) {
this.Element = Element;
@@ -29,56 +44,224 @@ public ASTStorage(ASTNode Element,String Name) {
this.Name = Name;
}
- public ASTStorage(ASTNode Element,ASTStorage Parent,Boolean then,String Name) {
- this(Element,Parent,Name);
+ public ASTStorage(ASTNode Element,Boolean then,String Name) {
+ this(Element,Name);
this.then = then;
}
-
- public void addChild(ASTStorage Child) {
- Children.add(Child);
+ public static ASTStorage getRoot(){
+ return root;
}
- public void setParent(ASTStorage parent) {
- this.Parent = parent;
+ public static void setRoot(ASTStorage Root) {
+ root = Root;
}
- public ASTStorage getParent() {
- return this.Parent;
- }
-
public ASTNode getElement() {
return this.Element;
}
+
public List getChildren(){
return Children;
}
+
public void setThen() {
this.then = true;
}
+
public String getName() {
return this.Name;
}
- public void print(int Level) {
-
- if (Element == null){
- if (this.then) {
- System.out.println("ThenStatement");
- }
- else {
- System.out.println("ElseStatement");
+
+ public static void setCompUnit(CompilationUnit compUnit) {
+ compilationUnit = compUnit;
+ }
+
+ public static CompilationUnit getCompUnit() {
+ return compilationUnit;
+ }
+
+ public static List getMethods() {
+ List result = new ArrayList<>();
+ if (root == null) {
+ return null;
+ }
+ for (ASTStorage method :root.getChildren()) {
+ result.add(method.getName());
+ }
+ return result;
+ }
+
+ public static ASTStorage getMethod(String Method) {
+ for (ASTStorage method :root.getChildren()) {
+ if (method.getName().equals(Method)) return method;
+ }
+ return null;
+ }
+
+ public static ASTStorage getMethodByLine(Integer Line) {
+ ASTStorage result = null;
+ for (ASTStorage method :root.getChildren()) {
+ if (method.getLineNumber() > Line) {
+ return result;
}
-
- }else {
- System.out.println("NIVEL: " + Level);
- System.out.println(Element.getClass());
- Level++;
+ result = method;
}
+ return result;
+ }
+
+
+
+
+ public Integer getLineNumber() {
+ return compilationUnit.getLineNumber(Element.getStartPosition());
+ }
+
+ public void addChild(ASTStorage Child) {
+ Children.add(Child);
+ }
+ /**parseado
+ * Este método busca el ASTStorage correspondiente a una linea
+ * especÃfica dentro del código
+ * @param lineNumber
+ * @return
+ */
+ public ASTStorage findLine(Integer lineNumber) {
- for (ASTStorage child : Children) {
- child.print(Level);
-
+ if (Element != null && (compilationUnit.getLineNumber(Element.getStartPosition()) == lineNumber)) {
+ return this;
+ }else if (Children.size() != 0) {
+ for (ASTStorage child : Children) {
+ ASTStorage tempNode = child.findLine(lineNumber);
+ if ( tempNode != null)
+ return tempNode;
+ }
}
+ return null;
}
+
+ /**
+ * Este metodo se encarga de descomponer el AST de eclipse en una estructura
+ * más simple
+ * @param parent Nodo padre al que se le agregaran los componentes hijos
+ * @param Statements Lista de nodos hijos por agregar
+ */
+ public void addChildren(List Statements) {
+
+ for (Object statement : Statements) {
+ ASTNode child = (ASTNode) statement;
+ this.addChildrenAux(child);
+ }
+ }
+
+ public void deleteChildren() {
+ this.Children.clear();
+ ASTStorage.root = null;
+ }
+
+ /**
+ * Este metodo auxiliar asiste al metodo addChildren para complir su función
+ * @param parent Nodo padre al que se le agregaran los componentes hijos
+ * @param Statements Nodo hijo por agregar
+ */
+ @SuppressWarnings("unchecked")
+ public void addChildrenAux(ASTNode child) {
+ if (child == null) {return;}
+ String[] clazz_aux = child.getClass().toString().split("\\.");
+ String clazz = clazz_aux[clazz_aux.length - 1];
+
+ if (clazz.equalsIgnoreCase("WhileStatement")) {
+
+ WhileStatement While = (WhileStatement) child;
+ ASTStorage WhileStorage = new ASTStorage(While,While.getExpression().toString());
+ this.addChild(WhileStorage);
+
+ Block block = (Block) While.getBody();
+
+ WhileStorage.addChildren(block.statements());
+
+ } else if (clazz.equalsIgnoreCase("DoStatement")) {
+ DoStatement Do = (DoStatement) child;
+ ASTStorage DoStorage = new ASTStorage(Do, Do.getExpression().toString());
+ this.addChild(DoStorage);
+ //System.out.println("Do: \n" + Do.getExpression());
+ Block block = (Block) Do.getBody();
+
+ DoStorage.addChildren(block.statements());
+
+ } else if (clazz.equalsIgnoreCase("EnhancedForStatement")) {
+ EnhancedForStatement EnhancedFor = (EnhancedForStatement) child;
+ ASTStorage EnhancedForStorage = new ASTStorage(EnhancedFor,EnhancedFor.getExpression().toString());
+ this.addChild(EnhancedForStorage);
+ Block block = (Block) EnhancedFor.getBody();
+
+ EnhancedForStorage.addChildren(block.statements());
+
+ } else if (clazz.equalsIgnoreCase("ForStatement")) {
+ ForStatement For = (ForStatement) child;
+ ASTStorage ForStorage = new ASTStorage(For,For.getExpression().toString());
+ this.addChild(ForStorage);
+ Block block = (Block) For.getBody();
+
+ ForStorage.addChildren(block.statements());
+
+ } else if (clazz.equalsIgnoreCase("IfStatement")) {
+ IfStatement If = (IfStatement) child;
+ ASTStorage IfStorage = new ASTStorage(If,If.getExpression().toString());
+ this.addChild(IfStorage);
+ ASTStorage thenStorage = new ASTStorage(null,true,If.getExpression().toString());
+ IfStorage.addChild(thenStorage);
+ Block b1 = (Block) If.getThenStatement();
+ thenStorage.addChildren(b1.statements());
+
+ if (If.getElseStatement() instanceof Block) {
+ ASTStorage elseStorage = new ASTStorage(null,false,If.getExpression().toString());
+ IfStorage.addChild(elseStorage);
+ Block b2 = (Block) If.getElseStatement();
+ elseStorage.addChildren(b2.statements());
+ } else {
+ ASTStorage elseStorage = new ASTStorage(null,false, If.getExpression().toString());
+ IfStorage.addChild(elseStorage);
+ IfStatement If2 = (IfStatement) If.getElseStatement();
+ elseStorage.addChildrenAux(If2);
+ }
+
+ } else if(clazz.equalsIgnoreCase("TryStatement")){
+ TryStatement Try = (TryStatement) child;
+ ASTStorage TryStorage = new ASTStorage(Try,"Try");
+ this.addChild(TryStorage);
+
+ Block block = (Block) Try.getBody();
+
+ TryStorage.addChildren(block.statements());
+
+ } else if (clazz.equalsIgnoreCase("ExpressionStatement")) {
+
+ ExpressionStatement Expression = (ExpressionStatement) child;
+ try{
+
+ MethodInvocation methodInvocation = (MethodInvocation) Expression.getExpression();
+ String methodClass = methodInvocation.resolveMethodBinding().getDeclaringClass().getQualifiedName();
+ if (methodClass.split("\\.")[0].equals("java")) {
+ ASTStorage ExpressionStorage = new ASTStorage(Expression,Expression.toString());
+ this.addChild(ExpressionStorage);
+ return;
+ }
+ ASTStorage MethoInvocationStorage = new ASTStorage(methodInvocation, methodInvocation.toString());
+ this.addChild(MethoInvocationStorage);
+
+ }catch(Exception ex) {
+ ASTStorage ExpressionStorage = new ASTStorage(Expression,Expression.toString());
+ this.addChild(ExpressionStorage);
+ }
+
+ }else if (clazz.equalsIgnoreCase("VariableDeclarationStatement")) {
+ VariableDeclarationStatement Variable = (VariableDeclarationStatement) child;
+ ASTStorage VariableStorage = new ASTStorage(Variable,Variable.toString());
+ this.addChild(VariableStorage);
+ }else {}
+
+ }
+
}
diff --git a/src/org/tec/datos1/flow/storage/DiagramSize.java b/src/org/tec/datos1/flow/storage/DiagramSize.java
new file mode 100644
index 0000000..c6a6a58
--- /dev/null
+++ b/src/org/tec/datos1/flow/storage/DiagramSize.java
@@ -0,0 +1,8 @@
+package org.tec.datos1.flow.storage;
+
+import org.eclipse.swt.graphics.Point;
+
+public class DiagramSize {
+ public Point lastOutput;
+ public int maxWidth;
+}