Skip to content
Snippets Groups Projects
Commit a9de78d5 authored by René Schöne's avatar René Schöne
Browse files

Added DrAst for scope4j.

parent dce7c3b1
No related branches found
No related tags found
No related merge requests found
DrAST.cfg
plugins {
id 'java'
id 'application'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation project(':scope4j')
implementation files('../tools/DrAST-1.2.2.jar')
implementation fileTree(dir: "${System.properties['java.home']}", include: '**/jfxrt.jar')
}
run {
mainClassName = 'de.tudresden.inf.st.scope4j.DrAstRunner'
doFirst { environment 'JAVA_TOOL_OPTIONS', '-Dlog4j2.disableJmx=true' }
}
run.dependsOn ':scope4j:jar'
package de.tudresden.inf.st.scope4j;
import drast.Log;
import drast.model.DrAST;
import drast.model.DrASTSettings;
import drast.model.TreeFilter;
import drast.views.gui.DrASTGUI;
import drast.views.gui.GUIData;
import drast.views.gui.controllers.Controller;
import drast.views.gui.graph.GraphView;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
/**
* Extended runner for DrAST
*
* @author jmey - Initial contribution
*/
public class DrAstRunner extends DrASTGUI {
public static void main(String[] args) {
openView();
System.exit(0);
}
private static final GUIData mon = new GUIData();
private static Controller con;
private static boolean guiHasBeenCreated = false;
private static void openView() {
guiHasBeenCreated = true;
DrASTSettings.put(DrASTSettings.PREV_JAR, "../scope4j/scope4j.jar");
DrASTSettings.put(DrASTSettings.PREV_TAIL_ARGS, "--drast");
launch();
con.onApplicationClose();
}
public void setRoot(Object root) {
long timeStart = System.currentTimeMillis();
DrAST newAst = new DrAST(root, TreeFilter.readFilter(con.getFilter()));
Log.info("Filter update: done after %d ms", System.currentTimeMillis() - timeStart);
Platform.runLater(() -> {
mon.reset(newAst);
if (guiHasBeenCreated) {
con.onSetRoot();
} else {
openView();
}
});
}
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader();
Parent rootView = loader.load(this.getClass().getResource("/main.fxml").openStream());
con = loader.getController();
mon.setParentStage(stage);
mon.setController(con);
mon.setDrASTUI(this);
mon.setStage(stage);
GraphView graphview = new GraphView(mon);
graphview.setOnMouseClicked((event) -> graphview.getParent().requestFocus());
mon.setGraphView(graphview);
con.init(mon);
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
stage.setTitle("Scope4J DrAST 1.2.2");
stage.setScene(new Scene(rootView, primaryScreenBounds.getWidth(), primaryScreenBounds.getHeight() - 100.0D));
stage.show();
ScrollPane center = (ScrollPane)rootView.lookup("#graphViewScrollPane");
center.setContent(graphview);
Platform.runLater(() -> graphview.setPreferredSize((int)center.getWidth(), (int)center.getHeight()));
con.loadPreviousFilter();
}
}
...@@ -219,7 +219,7 @@ generateAst.dependsOn preprocess ...@@ -219,7 +219,7 @@ generateAst.dependsOn preprocess
mainClassName = 'org.extendj.ScopeAnalysis' mainClassName = 'org.extendj.ScopeAnalysis'
jar.manifest.attributes 'Main-Class': mainClassName jar.manifest.attributes 'Main-Class': mainClassName
jar.destinationDir = projectDir jar.destinationDirectory = projectDir
sourceCompatibility = '1.8' sourceCompatibility = '1.8'
targetCompatibility = '1.8' targetCompatibility = '1.8'
...@@ -17,6 +17,8 @@ public class ScopeAnalysis extends Frontend { ...@@ -17,6 +17,8 @@ public class ScopeAnalysis extends Frontend {
super("Java Scope Anaysis", ExtendJVersion.getVersion()); super("Java Scope Anaysis", ExtendJVersion.getVersion());
} }
@SuppressWarnings("WeakerAccess")
public static Object DrAST_root_node;
public Program getProgram() { public Program getProgram() {
return program; return program;
...@@ -24,6 +26,8 @@ public class ScopeAnalysis extends Frontend { ...@@ -24,6 +26,8 @@ public class ScopeAnalysis extends Frontend {
private Program program; private Program program;
private static boolean isDrAst = false;
/** /**
* Entry point for the Java checker. * Entry point for the Java checker.
* *
...@@ -36,9 +40,11 @@ public class ScopeAnalysis extends Frontend { ...@@ -36,9 +40,11 @@ public class ScopeAnalysis extends Frontend {
boolean debug = arguments.isEmpty() || arguments.remove("--debug"); boolean debug = arguments.isEmpty() || arguments.remove("--debug");
boolean tree = arguments.remove("--tree"); boolean tree = arguments.remove("--tree");
boolean warnings = arguments.remove("--warnings"); boolean warnings = arguments.remove("--warnings");
isDrAst = arguments.remove("--drast");
if (arguments.size() > 1) { if (arguments.size() > 1) {
System.out.println("usage: ScopeAnalysis [--debug] [--tree] [--warnings] <directory with java files>"); System.out.println("usage: ScopeAnalysis [--debug] [--tree] [--warnings] <directory with java files>");
System.out.println(arguments);
System.exit(-1); System.exit(-1);
} }
String path = arguments.isEmpty() ? "../testprograms/simpleScope" : arguments.get(arguments.size() - 1); String path = arguments.isEmpty() ? "../testprograms/simpleScope" : arguments.get(arguments.size() - 1);
...@@ -52,6 +58,11 @@ public class ScopeAnalysis extends Frontend { ...@@ -52,6 +58,11 @@ public class ScopeAnalysis extends Frontend {
} }
public void analyzeTimed(String path) { public void analyzeTimed(String path) {
if (isDrAst) {
// quick-fix for DrAst, use directory of given file
path = Paths.get(path).getParent().toFile().getPath();
}
try { try {
List<String> files = Files.walk(Paths.get(path)) List<String> files = Files.walk(Paths.get(path))
.filter(Files::isRegularFile) .filter(Files::isRegularFile)
...@@ -66,6 +77,7 @@ public class ScopeAnalysis extends Frontend { ...@@ -66,6 +77,7 @@ public class ScopeAnalysis extends Frontend {
long startGenerationTime = System.nanoTime(); long startGenerationTime = System.nanoTime();
ScopeTree scopeTree = program.scopeTree(); ScopeTree scopeTree = program.scopeTree();
DrAST_root_node = scopeTree;
long startAnalysisTime = System.nanoTime(); long startAnalysisTime = System.nanoTime();
......
...@@ -21,3 +21,5 @@ include 'extendj:java5' ...@@ -21,3 +21,5 @@ include 'extendj:java5'
include 'extendj:java6' include 'extendj:java6'
include 'extendj:java7' include 'extendj:java7'
include 'extendj:java8' include 'extendj:java8'
include 'drast'
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment