diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 1a3dcb74..f58e82c4 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -10,6 +10,7 @@ on:
branches:
- master
- staging
+ - multi-weaver
push:
branches:
@@ -157,7 +158,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- node-version: ["22.x"]
+ node-version: ['25.x', '24.x']
os: [ubuntu-latest, windows-2022, macos-latest]
runs-on: ${{ matrix.os }}
diff --git a/.gitignore b/.gitignore
index 254a04cd..2c1c77f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -59,4 +59,6 @@ ivy/
build/
-**/node_modules/*
\ No newline at end of file
+**/node_modules/*
+# Test artifacts from the legacy weaver tests
+/src/
diff --git a/JavaWeaver/.gitignore b/JavaWeaver/.gitignore
index 0c20678d..c29f1a68 100644
--- a/JavaWeaver/.gitignore
+++ b/JavaWeaver/.gitignore
@@ -3,10 +3,8 @@ src-weaved/*
package.json
src/weaver/kadabra/abstracts/
-!src/weaver/kadabra/abstracts/AJavaWeaverJoinPoint.java
-src/weaver/kadabra/exceptions/
src/weaver/kadabra/enums/
*.dotty
-JavaWeaver.json
-JavaWeaver.png
-JavaWeaver.svg
+JWeaver.json
+JWeaver.png
+JWeaver.svg
diff --git a/JavaWeaver/build.gradle b/JavaWeaver/build.gradle
index 319ed9a0..e378e23d 100644
--- a/JavaWeaver/build.gradle
+++ b/JavaWeaver/build.gradle
@@ -23,6 +23,30 @@ configurations {
weaverGeneratorRuntime
}
+// Project sources
+sourceSets {
+ // Spec source set: compiled independently to avoid circular dependency
+ spec {
+ java {
+ srcDir 'src-spec'
+ }
+ }
+ main {
+ java {
+ srcDir 'src'
+ }
+ resources {
+ srcDir 'resources'
+ }
+ }
+
+ test {
+ java {
+ srcDir 'test'
+ }
+ }
+}
+
dependencies {
testImplementation "junit:junit:4.13.1"
@@ -34,7 +58,7 @@ dependencies {
implementation ':KadabraAPI'
- implementation ':LanguageSpecification'
+ implementation ':LangSpec2'
implementation ':LaraUtils'
implementation ':LARAI'
implementation ':WeaverInterface'
@@ -44,26 +68,11 @@ dependencies {
implementation 'org.ow2.asm:asm:9.8'
implementation 'org.json:json:20251224'
- weaverGeneratorRuntime ":WeaverGenerator"
-}
-
-// Project sources
-sourceSets {
- main {
- java {
- srcDir 'src'
- srcDir 'api'
- }
- resources {
- srcDir 'resources'
- }
- }
+ weaverGeneratorRuntime ":WeaverGen2"
- test {
- java {
- srcDir 'test'
- }
- }
+ // Spec source set: only needs LangSpec2 and WeaverInterface (for BaseJoinPointSpec)
+ specImplementation ":LangSpec2"
+ specImplementation ":WeaverInterface"
}
application {
@@ -79,22 +88,51 @@ tasks.register('kadabra', JavaExec) {
args = []
}
-// Weaver Generator
+// Generate weaver abstracts using WeaverGen2 (Java DSL-based)
tasks.register('generateWeaver', JavaExec) {
group = "Execution"
- description = "Generates the join point classes from the Language Specification"
- classpath = configurations.weaverGeneratorRuntime
- mainClass = 'org.lara.interpreter.weaver.generator.commandline.WeaverGenerator'
-
+ description = "Generates the Weaver Abstracts using WeaverGen2"
+ classpath = configurations.weaverGeneratorRuntime + sourceSets.spec.runtimeClasspath
+ mainClass = 'org.lara.weavergen2.cli.WeaverGen2Cli'
args = [
- '-w', 'JavaWeaver',
- '-x', './resources/specs/kadabra',
- '-o', './src',
- '-p', 'weaver.kadabra',
- '-n', 'spoon.reflect.declaration.CtElement',
- "-e",
- '-j'
+ "weaver.kadabra.KadabraSpec",
+ "${projectDir}/src",
+ "--base", "org.lara.interpreter.weaver.interf.BaseJoinPointSpec",
+ "--node", "spoon.reflect.declaration.CtElement"
]
}
compileJava.dependsOn generateWeaver
+
+def javaWeaverInstallDir = layout.buildDirectory.dir('install/JavaWeaver')
+def kadabraJsJavaBinaries = layout.projectDirectory.dir('../Kadabra-JS/java-binaries')
+
+def syncKadabraJsJavaBinaries = tasks.register('syncKadabraJsJavaBinaries', Sync) {
+ group = 'distribution'
+ description = 'Synchronizes the JavaWeaver installDist output used by Kadabra-JS.'
+ dependsOn tasks.named('installDist')
+ from javaWeaverInstallDir
+ into kadabraJsJavaBinaries
+
+ // The destination is also used by npm packaging and must not retain files
+ // that are no longer part of installDist.
+ outputs.upToDateWhen { false }
+
+ doFirst {
+ def installLib = javaWeaverInstallDir.get().dir('lib').asFile
+ if (!installLib.isDirectory()) {
+ throw new GradleException("JavaWeaver installDist output is missing: ${installLib}")
+ }
+
+ def destination = kadabraJsJavaBinaries.asFile.toPath()
+ if (java.nio.file.Files.isSymbolicLink(destination)) {
+ java.nio.file.Files.delete(destination)
+ } else if (java.nio.file.Files.exists(destination) && !java.nio.file.Files.isDirectory(destination)) {
+ throw new GradleException("Kadabra-JS java-binaries is not a directory: ${destination}")
+ }
+ }
+}
+
+tasks.named('installDist') {
+ finalizedBy syncKadabraJsJavaBinaries
+}
diff --git a/JavaWeaver/resources/specs/kadabra/actionModel.xml b/JavaWeaver/resources/specs/kadabra/actionModel.xml
deleted file mode 100644
index 4b806aed..00000000
--- a/JavaWeaver/resources/specs/kadabra/actionModel.xml
+++ /dev/null
@@ -1,367 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/JavaWeaver/resources/specs/kadabra/artifacts.xml b/JavaWeaver/resources/specs/kadabra/artifacts.xml
deleted file mode 100644
index e68c4f8a..00000000
--- a/JavaWeaver/resources/specs/kadabra/artifacts.xml
+++ /dev/null
@@ -1,471 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/JavaWeaver/resources/specs/kadabra/joinPointModel.xml b/JavaWeaver/resources/specs/kadabra/joinPointModel.xml
deleted file mode 100644
index a98c52da..00000000
--- a/JavaWeaver/resources/specs/kadabra/joinPointModel.xml
+++ /dev/null
@@ -1,151 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/JavaWeaver/settings.gradle b/JavaWeaver/settings.gradle
index 697d21ec..9c20d91f 100644
--- a/JavaWeaver/settings.gradle
+++ b/JavaWeaver/settings.gradle
@@ -9,9 +9,10 @@ includeBuild("${specsJavaLibsRoot}/jOptions")
includeBuild("${specsJavaLibsRoot}/SpecsUtils")
includeBuild("${specsJavaLibsRoot}/tdrcLibrary")
+includeBuild("${laraFrameworkRoot}/LangSpec2")
includeBuild("${laraFrameworkRoot}/LaraUtils")
includeBuild("${laraFrameworkRoot}/LARAI")
+includeBuild("${laraFrameworkRoot}/WeaverGen2")
includeBuild("${laraFrameworkRoot}/WeaverInterface")
-includeBuild("${laraFrameworkRoot}/WeaverGenerator")
includeBuild("../KadabraAPI")
diff --git a/JavaWeaver/src-spec/weaver/kadabra/KadabraSpec.java b/JavaWeaver/src-spec/weaver/kadabra/KadabraSpec.java
new file mode 100644
index 00000000..781a1ea5
--- /dev/null
+++ b/JavaWeaver/src-spec/weaver/kadabra/KadabraSpec.java
@@ -0,0 +1,694 @@
+package weaver.kadabra;
+
+import org.lara.langspec2.dsl.WeaverSpec;
+
+/**
+ * Weaver specification for the Kadabra (Java) weaver, translated from the XML
+ * specification files (joinPointModel.xml, artifacts.xml and actionModel.xml)
+ * into the Java DSL.
+ *
+ * The weaver prefix is 'J', so the concrete join point classes keep their
+ * original names (JMethod, JVar, JLoop, ...), and the LARA-visible join point
+ * names are exactly the ones of the old XML model.
+ *
+ * Excludes base contract (from BaseJoinPointSpec): dump, joinPointType, node,
+ * self, children, descendants, scopeNodes, parent, root, code, line, column,
+ * toString, equals, compareNodes, same, instanceOf, insert.
+ *
+ * The 'enum' join point of the old XML model is not declared: it had no
+ * attributes, actions or concrete class (enum nodes were represented by 'class'),
+ * so it was never reachable.
+ */
+public class KadabraSpec extends WeaverSpec {
+
+ @Override
+ public void define() {
+ weaverPrefix("J");
+ packageName("weaver.kadabra");
+ rootJoinPoint("app");
+
+ // =====================================================================
+ // Enum definitions
+ // =====================================================================
+
+ enumDef("LoopType")
+ .value("for")
+ .value("foreach")
+ .value("while")
+ .value("doWhile")
+ .end();
+
+ enumDef("CommentType")
+ .value("file")
+ .value("inline")
+ .value("block")
+ .value("javadoc")
+ .value("pragma")
+ .end();
+
+ enumDef("RefType")
+ .value("read")
+ .value("write")
+ .value("readwrite")
+ .value("decl")
+ .end();
+
+ // =====================================================================
+ // Global attributes and actions (weaver-specific, not in BaseJoinPointSpec)
+ // =====================================================================
+
+ global()
+ .attribute("srcCode", STRING, "Alias for attribute 'code'")
+ .attribute("ast", STRING, "A string representation of the AST corresponding to this node")
+ .attribute("numChildren", INT, "Returns the number of children of the node")
+ .attribute("child")
+ .tooltip("Returns the child of the node at the given index")
+ .param("index", INT)
+ .returns(jpRef("joinpoint"))
+ .attribute("astParent", jpRef("joinpoint"), "Alias of attribute 'parent'")
+ .attribute("getAncestor")
+ .param("type", STRING)
+ .returns(jpRef("joinpoint"))
+ .attribute("left", array(jpRef("joinpoint")), "Sibling nodes to the left of this node")
+ .attribute("right", array(jpRef("joinpoint")), "Sibling nodes to the right of this node")
+ .attribute("isStatement", BOOLEAN, "true if this node is considered a statement")
+ .attribute("isBlock", BOOLEAN, "true if this node is considered a block of statements")
+ .attribute("modifiers", array(STRING),
+ "an array of modifiers (e.g., final, static) applied to this node. If no modifiers are applied, or if the node does not support modifiers, returns an empty array")
+ .attribute("hasModifier")
+ .tooltip("true if this node has the given modifier")
+ .param("modifier", STRING)
+ .returns(BOOLEAN)
+ .attribute("isFinal", BOOLEAN, "true if this node has the modifier 'final'")
+ .attribute("isStatic", BOOLEAN, "true if this node has the modifier 'static'")
+ .attribute("annotations", array(jpRef("annotation")), "an array of the annotations of this node")
+ .attribute("id", STRING, "unique identifier for node")
+ .attribute("isInsideLoopHeader", BOOLEAN, "true if the node is inside a loop header, false otherwise")
+ .action("insertBefore")
+ .tooltip("Inserts node before the given node")
+ .param("node", jpRef("joinpoint"))
+ .returns(jpRef("joinpoint"))
+ .action("insertBefore")
+ .tooltip("Overload which accepts String")
+ .param("code", STRING)
+ .returns(jpRef("joinpoint"))
+ .action("insertAfter")
+ .tooltip("Inserts node after the given node")
+ .param("node", jpRef("joinpoint"))
+ .returns(jpRef("joinpoint"))
+ .action("insertAfter")
+ .tooltip("Overload which accepts String")
+ .param("code", STRING)
+ .returns(jpRef("joinpoint"))
+ .action("insertReplace")
+ .tooltip("Replaces join point with the given node")
+ .param("jp", jpRef("joinpoint"))
+ .returns(jpRef("joinpoint"))
+ .action("insertReplace")
+ .tooltip("Overload which accepts String")
+ .param("code", STRING)
+ .returns(jpRef("joinpoint"))
+ .action("replaceWith")
+ .tooltip("Replaces join point with the given node")
+ .param("jp", jpRef("joinpoint"))
+ .returns(jpRef("joinpoint"))
+ .action("replaceWith")
+ .tooltip("Overload which accepts String")
+ .param("code", STRING)
+ .returns(jpRef("joinpoint"))
+ .action("copy")
+ .tooltip("Copies the node and returns the copy")
+ .returns(jpRef("joinpoint"))
+ .action("remove")
+ .tooltip("Deletes the node")
+ .returns(VOID)
+ .action("removeAnnotation")
+ .tooltip("Removes an annotation")
+ .param("annotation", jpRef("annotation"))
+ .returns(VOID)
+ .action("removeModifier")
+ .param("modifier", STRING)
+ .returns(VOID)
+ .action("setModifiers")
+ .param("modifiers", array(STRING))
+ .returns(VOID)
+ .action("setLine")
+ .param("value", INT)
+ .returns(VOID)
+ .action("setLine")
+ .param("value", STRING)
+ .returns(VOID);
+
+ // =====================================================================
+ // Join point definitions
+ // =====================================================================
+
+ joinPoint("app")
+ .tooltip("Root node that represents the application")
+ .attribute("folder", STRING)
+ .attribute("showAST")
+ .param("Title", STRING)
+ .returns(STRING)
+ .attribute("manifest", jpRef("androidManifest"))
+ .attribute("files", array(jpRef("file")))
+ .action("newClass")
+ .param("name", STRING)
+ .param("extend", STRING, "\"\"")
+ .param("implement", array(STRING))
+ .returns(jpRef("class"))
+ .action("newClass")
+ .param("name", STRING)
+ .returns(jpRef("class"))
+ .action("newInterface")
+ .param("name", STRING)
+ .param("extend", array(STRING))
+ .returns(jpRef("interfaceType"))
+ .action("newInterface")
+ .param("name", STRING)
+ .returns(jpRef("interfaceType"))
+ .action("mapVersions")
+ .param("name", STRING)
+ .param("keyType", STRING)
+ .param("interfaceType", jpRef("interfaceType"))
+ .param("methodName", STRING)
+ .returns(jpRef("class"));
+
+ joinPoint("libClass").extending("NamedType")
+ .tooltip("class that is part of a library, included in the classpath");
+
+ joinPoint("libMethod")
+ .tooltip("method of a class that is part of a library included in the classpath")
+ .defaultAttribute("name")
+ .attribute("name", STRING, "the simple name of the type")
+ .attribute("declarator", jpRef("NamedType"))
+ .attribute("returnType", STRING);
+
+ joinPoint("xmlNode")
+ .attribute("elements", array(jpRef("xmlElement")))
+ .attribute("elementsByName")
+ .param("name", STRING)
+ .returns(array(jpRef("xmlElement")))
+ .attribute("text", STRING)
+ .action("setText")
+ .param("text", STRING)
+ .returns(STRING);
+
+ joinPoint("androidManifest").extending("xmlNode")
+ .attribute("asJson", STRING);
+
+ joinPoint("xmlElement").extending("xmlNode")
+ .defaultAttribute("name")
+ .attribute("name", STRING, "the name (i.e., tag) of this element")
+ .attribute("attribute")
+ .tooltip("the value associated with the given attribute")
+ .param("name", STRING)
+ .returns(STRING)
+ .attribute("attributeNames", array(STRING), "a list of available attributes in this element")
+ .action("setAttribute")
+ .param("name", STRING)
+ .param("value", STRING)
+ .returns(STRING);
+
+ joinPoint("file")
+ .tooltip("Represents a source-code file")
+ .defaultAttribute("name")
+ .attribute("name", STRING)
+ .attribute("path", STRING)
+ .attribute("dir", STRING)
+ .attribute("packageName", STRING)
+ .attribute("numClasses", INT)
+ .attribute("numInterfaces", INT)
+ .attribute("mainClass", jpRef("type"),
+ "Main class of the file. Java files must have a top level class with the same name as the file.")
+ .action("newClass")
+ .param("name", STRING)
+ .param("extend", STRING, "\"\"")
+ .param("implement", array(STRING))
+ .returns(jpRef("class"))
+ .action("newClass")
+ .param("name", STRING)
+ .returns(jpRef("class"))
+ .action("newInterface")
+ .param("name", STRING)
+ .param("extend", array(STRING))
+ .returns(jpRef("interfaceType"))
+ .action("newInterface")
+ .param("name", STRING)
+ .returns(jpRef("interfaceType"))
+ .action("addImport")
+ .param("qualifiedName", STRING)
+ .returns(VOID)
+ .action("addClass")
+ .tooltip("insert a given class inside the target")
+ .param("newClass", jpRef("class"))
+ .returns(VOID)
+ .action("addInterface")
+ .param("newInterface", jpRef("interfaceType"))
+ .returns(VOID)
+ .action("removeInterface")
+ .param("interfaceName", STRING)
+ .returns(jpRef("interfaceType"))
+ .action("mapVersions")
+ .param("name", STRING)
+ .param("keyType", STRING)
+ .param("interfaceType", jpRef("interfaceType"))
+ .param("methodName", STRING)
+ .returns(jpRef("class"));
+
+ joinPoint("NamedType")
+ .defaultAttribute("name")
+ .attribute("name", STRING, "the simple name of the type")
+ .attribute("qualifiedName", STRING, "the qualified name of this type, includes packages")
+ .attribute("superClass", STRING, "name of the superclass this type extends")
+ .attribute("packageName", STRING, "package name of this type")
+ .attribute("interfaces", array(STRING), "list of names of interfaces that this type implements")
+ .attribute("javadoc", STRING)
+ .attribute("isSubtypeOf")
+ .tooltip("verify if the type is extends OR implements the given type")
+ .param("type", STRING)
+ .returns(BOOLEAN_BOXED);
+
+ joinPoint("type")
+ .tooltip("base join point that class, interface and enum extend")
+ .defaultAttribute("name")
+ .attribute("name", STRING, "the simple name of the class")
+ .attribute("qualifiedName", STRING, "the qualified name of this class, includes packages")
+ .attribute("superClass", STRING, "name of the superclass this class extends")
+ .attribute("superClassJp", jpRef("typeReference"),
+ "the superclass this class extends, or undefined if the class extends java.lang.Object")
+ .attribute("packageName", STRING, "package name of this class")
+ .attribute("interfaces", array(STRING), "list of names of interfaces that this class implements")
+ .attribute("interfacesTypes", array(jpRef("interfaceType")),
+ "returns the interface join points that this class implements")
+ .attribute("javadoc", STRING)
+ .attribute("isSubtypeOf")
+ .tooltip("verify if the type is extends OR implements the given type")
+ .param("type", STRING)
+ .returns(BOOLEAN_BOXED)
+ .action("addClass")
+ .tooltip("insert a given class inside the target")
+ .param("newClass", jpRef("class"))
+ .returns(VOID)
+ .action("addInterface")
+ .param("newInterface", jpRef("interfaceType"))
+ .returns(VOID)
+ .action("removeInterface")
+ .param("interfaceName", STRING)
+ .returns(jpRef("interfaceType"))
+ .action("newMethod")
+ .tooltip("add a new method inside the class")
+ .param("modifiers", array(STRING))
+ .param("returnType", STRING)
+ .param("name", STRING)
+ .param("paramLeft", array(STRING))
+ .param("paramRight", array(STRING))
+ .param("code", STRING, "\"\"")
+ .returns(jpRef("method"))
+ .action("newMethod")
+ .tooltip("overload which accepts 4 parameters (code is empty string)")
+ .param("modifiers", array(STRING))
+ .param("returnType", STRING)
+ .param("name", STRING)
+ .param("paramLeft", array(STRING))
+ .param("paramRight", array(STRING))
+ .returns(jpRef("method"))
+ .action("insertMethod")
+ .param("code", STRING)
+ .returns(VOID)
+ .action("insertCode")
+ .param("code", STRING)
+ .returns(VOID)
+ .action("newField")
+ .param("modifiers", array(STRING))
+ .param("type", STRING)
+ .param("name", STRING)
+ .param("defaultValue", STRING, "null")
+ .returns(jpRef("field"))
+ .action("newField")
+ .param("modifiers", array(STRING))
+ .param("type", STRING)
+ .param("name", STRING)
+ .returns(jpRef("field"))
+ .action("addImplement")
+ .param("interfaceType", jpRef("interfaceType"))
+ .returns(VOID);
+
+ joinPoint("class").extending("type")
+ .tooltip("join point representation of a class")
+ .defaultAttribute("name")
+ .attribute("isTopLevel", BOOLEAN)
+ .action("newConstructor")
+ .param("modifiers", array(STRING), "['public']")
+ .param("paramLeft", array(STRING), "[]")
+ .param("paramRight", array(STRING), "[]")
+ .returns(jpRef("constructor"))
+ .action("newFunctionalClass")
+ .param("interfaceMethod", jpRef("method"))
+ .param("generatorMethod", jpRef("method"))
+ .returns(jpRef("method"))
+ .action("insertStatic")
+ .param("code", STRING)
+ .returns(VOID)
+ .action("extractInterface")
+ .param("name", STRING)
+ .param("packageName", STRING, "\"\"")
+ .param("method", jpRef("method"))
+ .param("associate", BOOLEAN, "false")
+ .param("newFile", BOOLEAN)
+ .returns(jpRef("interfaceType"))
+ .action("mapVersions")
+ .param("name", STRING)
+ .param("keyType", STRING)
+ .param("interfaceType", jpRef("interfaceType"))
+ .param("methodName", STRING)
+ .returns(jpRef("class"));
+
+ joinPoint("interfaceType").extending("type")
+ .defaultAttribute("name");
+
+ joinPoint("field").extending("declaration")
+ .defaultAttribute("name")
+ .attribute("declarator", STRING)
+ .attribute("staticAccess", STRING);
+
+ joinPoint("enumValue").extending("field");
+
+ joinPoint("executable")
+ .defaultAttribute("name")
+ .attribute("name", STRING)
+ .attribute("returnType", STRING)
+ .attribute("body", jpRef("body"))
+ .attribute("params", array(jpRef("declaration")))
+ .attribute("returnRef", jpRef("typeReference"))
+ .action("setName")
+ .tooltip("Sets the name of this executable, returns the previous name")
+ .param("name", STRING)
+ .returns(STRING);
+
+ joinPoint("method").extending("executable")
+ .defaultAttribute("name")
+ .attribute("declarator", STRING)
+ .attribute("privacy", STRING)
+ .attribute("toReference", STRING)
+ .attribute("toQualifiedReference", STRING)
+ .attribute("isOverriding")
+ .param("method", jpRef("method"))
+ .returns(BOOLEAN)
+ .action("addComment")
+ .param("comment", STRING)
+ .returns(VOID)
+ .action("addParameter")
+ .param("type", STRING)
+ .param("name", STRING)
+ .returns(VOID)
+ .action("createAdapter")
+ .param("adaptMethod", jpRef("method"))
+ .param("name", STRING)
+ .returns(jpRef("class"))
+ .action("clone")
+ .param("newName", STRING)
+ .returns(jpRef("method"))
+ .action("setPrivacy")
+ .param("privacy", STRING)
+ .returns(VOID);
+
+ joinPoint("constructor").extending("executable")
+ .defaultAttribute("name")
+ .attribute("declarator", STRING);
+
+ joinPoint("anonymousExec").extending("executable");
+
+ joinPoint("body").extending("statement")
+ .attribute("lastStmt", jpRef("statement"),
+ "The last statement of the body, or undefined if it has no statements")
+ .action("insertBegin")
+ .param("code", STRING)
+ .returns(VOID)
+ .action("insertBegin")
+ .param("statement", jpRef("statement"))
+ .returns(VOID);
+
+ joinPoint("localVariable").extending("statement")
+ .defaultAttribute("name")
+ .attribute("name", STRING)
+ .attribute("type", STRING)
+ .attribute("typeReference", jpRef("typeReference"))
+ .attribute("isArray", BOOLEAN)
+ .attribute("isPrimitive", BOOLEAN)
+ .attribute("completeType", STRING)
+ .attribute("init", jpRef("expression"),
+ "Initialization of this variable, if present, or undefined of unintialized")
+ .action("setInit")
+ .param("init", jpRef("expression"))
+ .returns(VOID);
+
+ joinPoint("declaration")
+ .defaultAttribute("name")
+ .attribute("name", STRING)
+ .attribute("type", STRING)
+ .attribute("typeReference", jpRef("typeReference"))
+ .attribute("isArray", BOOLEAN)
+ .attribute("isPrimitive", BOOLEAN)
+ .attribute("completeType", STRING)
+ .attribute("init", jpRef("expression"))
+ .action("setInit")
+ .param("value", jpRef("expression"))
+ .returns(VOID);
+
+ joinPoint("loop").extending("statement")
+ .defaultAttribute("type")
+ .attribute("type", enumRef("LoopType"))
+ .attribute("rank", STRING)
+ .attribute("nestedLevel", INT)
+ .attribute("isInnermost", BOOLEAN)
+ .attribute("isOutermost", BOOLEAN)
+ .attribute("controlVar", STRING)
+ .attribute("cond", jpRef("expression"))
+ .action("tile")
+ .param("tileName", STRING, "\"\"")
+ .param("block", STRING)
+ .param("unique", BOOLEAN)
+ .param("around", jpRef("joinpoint"), "null")
+ .returns(jpRef("field"))
+ .action("tile")
+ .param("block", INT)
+ .returns(VOID)
+ .action("interchange")
+ .param("loop2", jpRef("loop"))
+ .returns(VOID);
+
+ joinPoint("if").extending("statement")
+ .attribute("rank", STRING)
+ .attribute("cond", jpRef("expression"))
+ .attribute("then", jpRef("body"))
+ .attribute("else", jpRef("body"));
+
+ joinPoint("try").extending("statement")
+ .attribute("body", jpRef("body"))
+ .attribute("catches", array(jpRef("catch")));
+
+ joinPoint("catch")
+ .attribute("body", jpRef("body"));
+
+ joinPoint("statement")
+ .defaultAttribute("kind")
+ .attribute("kind", STRING)
+ .attribute("endLine", INT);
+
+ joinPoint("callStatement").extending("statement")
+ .attribute("call", jpRef("call"));
+
+ joinPoint("assignment").extending("statement")
+ .defaultAttribute("operator")
+ .attribute("operator", STRING)
+ .attribute("lhs", jpRef("expression"))
+ .attribute("rhs", jpRef("expression"))
+ .action("setLhs")
+ .param("lhs", jpRef("expression"))
+ .returns(VOID)
+ .action("setRhs")
+ .param("rhs", jpRef("expression"))
+ .returns(VOID);
+
+ joinPoint("opAssignment").extending("assignment")
+ .defaultAttribute("operator")
+ .action("setOperator")
+ .param("operator", STRING)
+ .returns(VOID);
+
+ joinPoint("expression")
+ .attribute("kind", STRING)
+ .attribute("type", STRING)
+ .attribute("qualifiedType", STRING)
+ .attribute("typeReference", jpRef("typeReference"))
+ .attribute("test", INT)
+ .action("extract")
+ .param("varName", STRING)
+ .param("location", jpRef("statement"))
+ .param("position", STRING)
+ .returns(VOID)
+ .action("setTest")
+ .param("test", jpRef("expression"))
+ .returns(VOID)
+ .action("setTest")
+ .param("test", INT)
+ .returns(VOID);
+
+ joinPoint("annotation").extending("expression");
+
+ joinPoint("var").extending("expression")
+ .defaultAttribute("name")
+ .attribute("name", STRING)
+ .attribute("reference", enumRef("RefType"))
+ .attribute("isArray", BOOLEAN)
+ .attribute("isPrimitive", BOOLEAN)
+ .attribute("isField", BOOLEAN)
+ .attribute("inLoopHeader", BOOLEAN, "Equivalent to the global attribute 'isInsideLoopHeader'")
+ .attribute("referenceChain", array(jpRef("joinpoint")),
+ "the chain of references of this variable (e.g., this.field)")
+ .attribute("declaration", jpRef("joinpoint"));
+
+ joinPoint("fieldAccess").extending("var")
+ .defaultAttribute("name")
+ .attribute("base", jpRef("expression"),
+ "The base expression of this fieldAccess. E.g., for the field access a.b.c, returns the expression representing a.b");
+
+ joinPoint("literal").extending("expression")
+ .defaultAttribute("value")
+ .attribute("value", STRING)
+ .action("setValue")
+ .param("value", STRING)
+ .returns(VOID);
+
+ joinPoint("call").extending("expression")
+ .defaultAttribute("name")
+ .attribute("name", STRING)
+ .attribute("decl", jpRef("method"))
+ .attribute("simpleDecl", STRING)
+ .attribute("qualifiedDecl", STRING)
+ .attribute("declarator", STRING)
+ .attribute("executable", STRING)
+ .attribute("target", STRING)
+ .attribute("targetType", jpRef("type"))
+ .attribute("returnType", STRING)
+ .attribute("returnTypeJp", jpRef("typeReference"))
+ .attribute("arguments", array(jpRef("expression")))
+ .action("clone")
+ .param("location", jpRef("statement"))
+ .param("position", STRING)
+ .returns(jpRef("call"))
+ .action("setArguments")
+ .param("newArguments", array(jpRef("expression")))
+ .returns(VOID)
+ .action("setTarget")
+ .param("target", jpRef("expression"), "null")
+ .returns(jpRef("call"))
+ .action("setTarget")
+ .param("target", STRING, "null")
+ .returns(jpRef("call"))
+ .action("setExecutable")
+ .param("executable", jpRef("method"))
+ .returns(jpRef("call"))
+ .action("setArgument")
+ .param("newArgument", jpRef("expression"))
+ .param("index", INT)
+ .returns(VOID);
+
+ joinPoint("new").extending("expression")
+ .defaultAttribute("name")
+ .attribute("name", STRING)
+ .attribute("arguments", array(jpRef("expression")))
+ .action("setArguments")
+ .param("newArguments", array(jpRef("expression")))
+ .returns(VOID);
+
+ joinPoint("binaryExpression").extending("expression")
+ .defaultAttribute("operator")
+ .attribute("operator", STRING)
+ .attribute("operands", array(jpRef("expression")))
+ .attribute("lhs", jpRef("expression"))
+ .attribute("rhs", jpRef("expression"))
+ .action("setOperator")
+ .param("operator", STRING)
+ .returns(VOID);
+
+ joinPoint("unaryExpression").extending("expression")
+ .defaultAttribute("operator")
+ .attribute("operand", jpRef("expression"))
+ .attribute("operator", STRING)
+ .action("setOperator")
+ .tooltip("Sets the operator of the unary expression. To distinguish between postfix and prefix operator, add an underscore signalling the place of the variable (e.g., _++ for postfix incremment). If no underscore is specified, postfix is assumed.")
+ .param("operator", STRING)
+ .returns(VOID);
+
+ joinPoint("ternary").extending("expression")
+ .attribute("condition", jpRef("expression"), "the condition of the ternary expression")
+ .attribute("cond", jpRef("expression"), "alias for attribute 'condition'")
+ .attribute("then", jpRef("expression"))
+ .attribute("else", jpRef("expression"));
+
+ joinPoint("arrayAccess").extending("expression")
+ .attribute("reference", enumRef("RefType"));
+
+ joinPoint("this").extending("expression");
+
+ joinPoint("snippetExpr").extending("expression")
+ .action("setLine")
+ .param("line", INTEGER)
+ .returns(VOID);
+
+ joinPoint("return").extending("statement");
+
+ joinPoint("comment").extending("statement")
+ .defaultAttribute("type")
+ .attribute("type", enumRef("CommentType"))
+ .attribute("content", STRING);
+
+ joinPoint("pragma").extending("comment")
+ .defaultAttribute("name")
+ .attribute("name", STRING);
+
+ joinPoint("assert").extending("statement");
+
+ joinPoint("throw").extending("statement");
+
+ joinPoint("switch").extending("statement")
+ .attribute("cases", array(jpRef("case")));
+
+ joinPoint("case").extending("statement")
+ .attribute("expr", jpRef("expression"),
+ "the expression associated with this case, of undefined if it is the default case")
+ .attribute("isDefault", BOOLEAN, "true if this is the default case, false otherwise")
+ .attribute("stmts", array(jpRef("statement")), "the statements of this case");
+
+ joinPoint("continue").extending("statement");
+
+ joinPoint("break").extending("statement");
+
+ joinPoint("snippetStmt").extending("statement")
+ .action("setLine")
+ .param("line", INTEGER)
+ .returns(VOID);
+
+ joinPoint("reference")
+ .tooltip("Points to a named program element reference")
+ .defaultAttribute("name")
+ .attribute("name", STRING, "Name of the element of the reference")
+ .attribute("declaration", jpRef("joinpoint"), "The element that is being referenced")
+ .attribute("type", STRING, "Type of the element of the reference");
+
+ joinPoint("typeReference").extending("reference")
+ .tooltip("Reference to a type")
+ .defaultAttribute("name")
+ .attribute("isPrimitive", BOOLEAN, "true if this is a reference to a primitive type, false otherwise")
+ .attribute("isArray", BOOLEAN, "true if this is a reference to an array type, false otherwise")
+ .attribute("isNumeric", BOOLEAN_BOXED,
+ "true if this is a reference to a numeric type, primitive or class (i.e., byte, Byte, char, Character, short, Short, int, Integer, long, Long, float, Float, double and Double)")
+ .attribute("isBoolean", BOOLEAN,
+ "true if this is a reference to a boolean type, primitive or class (i.e., boolean, Boolean)")
+ .attribute("packageName", STRING, "package name of this type")
+ .attribute("packageNames", array(STRING),
+ "the package name of this type as an array, where each element is a part of the package")
+ .attribute("qualifiedName", STRING, "fully qualified name of the type");
+ }
+}
diff --git a/JavaWeaver/src/weaver/kadabra/JavaWeaver.java b/JavaWeaver/src/weaver/kadabra/JWeaver.java
similarity index 86%
rename from JavaWeaver/src/weaver/kadabra/JavaWeaver.java
rename to JavaWeaver/src/weaver/kadabra/JWeaver.java
index 419eb572..77973e71 100644
--- a/JavaWeaver/src/weaver/kadabra/JavaWeaver.java
+++ b/JavaWeaver/src/weaver/kadabra/JWeaver.java
@@ -1,498 +1,491 @@
-package weaver.kadabra;
-
-import org.apache.commons.io.FileUtils;
-import org.lara.interpreter.joptions.config.interpreter.LaraiKeys;
-import org.lara.interpreter.weaver.ast.AstMethods;
-import org.lara.interpreter.weaver.interf.AGear;
-import org.lara.interpreter.weaver.interf.JoinPoint;
-import org.lara.interpreter.weaver.options.WeaverOption;
-import org.lara.interpreter.weaver.options.WeaverOptionBuilder;
-import org.lara.language.specification.dsl.LanguageSpecification;
-import org.suikasoft.jOptions.Interfaces.DataStore;
-import pt.up.fe.specs.jadx.DecompilationFailedException;
-import pt.up.fe.specs.jadx.SpecsJadx;
-import pt.up.fe.specs.spoon.SpoonFactory;
-import pt.up.fe.specs.util.SpecsCollections;
-import pt.up.fe.specs.util.SpecsIo;
-import pt.up.fe.specs.util.SpecsLogs;
-import pt.up.fe.specs.util.utilities.LineStream;
-import spoon.Launcher;
-import spoon.OutputType;
-import spoon.compiler.Environment;
-import spoon.reflect.factory.Factory;
-import spoon.support.JavaOutputProcessor;
-import spoon.support.SerializationModelStreamer;
-import weaver.kadabra.abstracts.weaver.AJavaWeaver;
-import weaver.kadabra.exceptions.JavaWeaverException;
-import weaver.kadabra.gears.Report;
-import weaver.kadabra.joinpoints.JApp;
-import weaver.kadabra.spoon.extensions.launcher.JWSpoonLauncher;
-import weaver.kadabra.spoon.extensions.nodes.CtApp;
-import weaver.kadabra.spoon.extensions.printer.KadabraPrettyPrinter;
-import weaver.kadabra.util.KadabraLog;
-import weaver.options.JavaWeaverKeys;
-import weaver.options.JavaWeaverOption;
-import weaver.utils.KadabraAstMethods;
-import weaver.utils.SpoonUtils;
-import weaver.utils.processors.IfProcessor;
-import weaver.utils.weaving.AnnotationsTable;
-
-import java.io.*;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import static weaver.specification.JavaWeaverResource.*;
-
-/**
- * LARA Weaving Engine that uses Spoon as the Java compiler/processor
- * Weaver Implementation for JavaWeaver
- * Since the generated abstract classes are always overwritten, their
- * implementation should be done by extending those abstract classes with
- * user-defined classes.
- * The abstract class {@link weaver.abstracts.AJoinPoint} can be used to add
- * user-defined methods and fields which the user intends to add for all join
- * points and are not intended to be used in LARA aspects.
- *
- * @author Lara C.
- */
-public class JavaWeaver extends AJavaWeaver {
- static {
- KadabraLog.setDebug(true);
- }
-
- private static final Set LANGUAGES = SpecsCollections.asSet("java");
-
- // Fields
- private DataStore args;
- private File outputDir;
- private JWSpoonLauncher spoon;
- private JApp jApp;
- private AnnotationsTable table;
- private List classPath;
- private boolean clearOutputFolder;
- private boolean prettyPrint;
- private File currentOutputDir;
- private KadabraPrettyPrinter sourceCodePrinter;
-
- private boolean noClassPath = false; // Continues even if an error of missing lib occurs
- private OutputType outType = OutputType.COMPILATION_UNITS;
- private final Report reportGear;
-
- private File temp;
-
- public JavaWeaver() {
- reportGear = new Report();
- reportGear.setActive(false);
- table = AnnotationsTable.getStaticTable();
- }
-
- /**
- * Set a file/folder in the weaver if it is valid file/folder type for the
- * weaver.
- *
- * @param sources the file with the source code
- * @param outputDir output directory for the generated file(s)
- * @param args arguments to start the weaver
- * @return true if the file type is valid
- */
- @Override
- protected boolean begin(List sources, File outputDir, DataStore args) {
- // Add 'woven_code' to the end of the outputDir
- if (args.get(JavaWeaverKeys.WOVEN_FOLDER)) {
- outputDir = new File(outputDir, "woven_code");
- }
-
- this.args = args;
- classPath = new ArrayList<>();
- this.outputDir = outputDir;
- clearOutputFolder = false;
- reset();
- parseOptions(args);
-
- if (prettyPrint) {
-
- this.outputDir.mkdirs();
- temp = getTemporaryWeaverFolder();
- outputDir = temp;
- }
-
- // Pass only Java files to spoon
- // Method can do some processing, such as filtering duplicate classes
- var javaSources = getJavaSources(sources);
- spoon = newSpoon(javaSources, outputDir);
-
- this.currentOutputDir = outputDir;
- buildAndProcess();
-
- jApp = JApp.newInstance(spoon, sources, this);
-
- return true;
- }
-
- private List getJavaSources(List sources) {
- List javaSources = new ArrayList<>();
- Map seenTypes = new HashMap<>();
- for (var source : sources) {
-
- if (SpecsIo.getExtension(source).toLowerCase().equals("apk")) {
- try {
- var filterList = args.get(JavaWeaverKeys.APK_PACKAGE_FILTER).getStringList();
- source = new SpecsJadx().decompileAPK(source, filterList);
- } catch (DecompilationFailedException e) {
- SpecsLogs.warn(String.format("Jadx: DECOMPILE FAILED | %s", e.getMessage()));
- }
- }
-
- var javaFiles = SpecsIo.getFilesRecursive(source, Arrays.asList("java"));
-
- for (var javaFile : javaFiles) {
- // Extract Java package
- String packageDecl = getPackage(javaFile).orElse("");
-
- var separator = packageDecl.isEmpty() ? "" : ".";
-
- var javaKey = packageDecl + separator + javaFile.getName();
-
- if (seenTypes.containsKey(javaKey)) {
-
- SpecsLogs.info("Found duplicate class '" + javaFile.getAbsolutePath() + "', already added '"
- + seenTypes.get(javaKey) + "'");
- continue;
- }
-
- javaSources.add(javaFile);
- seenTypes.put(javaKey, javaFile);
- }
- }
-
- return javaSources;
- }
-
- private Optional getPackage(File javaFile) {
- // Read each line until 'package' is found
- try (var lines = LineStream.newInstance(javaFile)) {
- while (lines.hasNextLine()) {
- var line = lines.nextLine().strip().toLowerCase();
-
- // Found package
- if (line.startsWith("package ")) {
- var packageName = line.substring("package ".length()).strip();
- int colonIndex = packageName.indexOf(';');
- if (colonIndex == -1) {
- SpecsLogs.info("Found package, but could not find ';': " + line);
- return Optional.empty();
- }
-
- return Optional.of(packageName.substring(0, colonIndex).strip());
- }
-
- // Stop when import, class, interface or modifier is found
- if (line.startsWith("import ") || line.startsWith("public ") || line.startsWith("class ")
- || line.startsWith("interface ") || line.startsWith("enum ")) {
- break;
- }
-
- // Ignore other lines
- }
- }
-
- return Optional.empty();
- }
-
- /**
- * Closes the weaver to the specified output directory location, if the weaver
- * generates new file(s)
- *
- * @return if close was successful
- */
- @Override
- protected boolean close() {
-
- if (clearOutputFolder) {
- if (!args.hasValue(LaraiKeys.OUTPUT_FOLDER)) {
- KadabraLog.warning("No output folder defined, skipping cleaning");
- } else {
- try {
- FileUtils.cleanDirectory(outputDir);
- } catch (final IOException e) {
- KadabraLog.warning("Output folder could not be cleaned before code generation: " + e.getMessage());
- }
- }
-
- }
-
- if (args.get(JavaWeaverKeys.WRITE_CODE)) {
- if (prettyPrint) {
- spoon.prettyprint();
- spoon = newSpoon(Arrays.asList(temp), outputDir);
- buildAndProcess();
- spoon.prettyprint();
- } else {
- spoon.prettyprint();
- }
- }
-
- // Write XML files
- jApp.getAndroidResources().write(outputDir);
-
- // writeCode(temp, outputDir, true);
-
- if (reportGear.isActive()) {
-
- KadabraLog.info("REPORT: ");
- KadabraLog.info("Advised Join Points: " + reportGear.getAdvisedJoinPoints().size());
- }
- return true;
- }
-
- @Override
- public void writeCode(File outputFolder) {
- // Set output folder
- spoon.setSourceOutputDirectory(outputFolder);
- // Generate code to output folder
- spoon.prettyprint();
-
- // Write XML files
- jApp.getAndroidResources().write(outputFolder);
- }
-
- public void rebuild(File inputFolder, File outputFolder) {
- if (clearOutputFolder) {
- try {
- FileUtils.cleanDirectory(outputFolder);
- } catch (final IOException e) {
- KadabraLog.warning("Output folder could not be cleaned before code generation: " + e.getMessage());
- }
- }
-
- // Generate code to current output dir
- spoon.prettyprint();
-
- var newSpoon = newSpoon(Arrays.asList(inputFolder), outputFolder);
- buildAndProcess(newSpoon);
- newSpoon.prettyprint();
-
- // Write XML files
- jApp.getAndroidResources().write(outputFolder);
- }
-
- /**
- * Returns a list of Gears associated to this weaver engine
- *
- * @return a list of implementations of {@link AGear} or null if no gears are
- * available
- */
- @Override
- public List getGears() {
- List gears = new ArrayList<>();
- gears.add(reportGear);
- return gears;
- }
-
- private void reset() {
- SpoonUtils.resetCounter();
- table.reset();
- /* RESET GEARS */
- reportGear.reset();
- }
-
- /**
- * Instantiates a new {@link JWSpoonLauncher} based on the given input sources
- * and the properties of this {@link JavaWeaver} instance.
- *
- * @param sources the input sources to parse
- * @return
- */
- private JWSpoonLauncher newSpoon(List sources, File outputDir) {
- JWSpoonLauncher spoon = new JWSpoonLauncher(sources);
-
- Environment environment = spoon.getFactory().getEnvironment();
-
- spoon.setArgs(new String[] { "--output-type", outType.toString() }); // required to define the type of output...
-
- if (!classPath.isEmpty()) {
-
- try {
- // Process classpath
- // If there are JARs present in folders, add them as individual classpaths
- List processedClasspath = new ArrayList<>();
- processedClasspath.addAll(classPath);
- var additionalJars = classPath.stream()
- .filter(classPath -> classPath.isDirectory())
- .flatMap(folder -> SpecsIo.getFilesRecursive(folder, "jar").stream())
- .collect(Collectors.toList());
- SpecsLogs.debug("Adding JARs to classpath: " + additionalJars);
- processedClasspath.addAll(additionalJars);
-
- List filesStr = processedClasspath.stream().map(SpecsIo::getCanonicalPath)
- .collect(Collectors.toList());
- String[] classPathArray = filesStr.toArray(new String[0]);
- environment.setSourceClasspath(classPathArray);
- } catch (Exception e) {
- throw new JavaWeaverException("setting the classpath", e);
- }
- }
-
- environment.setCommentEnabled(true);
- setOutputProcessor(outputDir, spoon, environment);
- environment.setNoClasspath(noClassPath);
- setInputSources(sources, spoon);
- spoon.addProcessor(new IfProcessor());
-
- // Set fully qualified names
- if (args.get(JavaWeaverKeys.FULLY_QUALIFIED_NAMES)) {
- environment.setAutoImports(false);
- } else {
- environment.setAutoImports(true);
- }
-
- environment.setCopyResources(args.get(JavaWeaverKeys.COPY_RESOURCES));
-
- environment.setComplianceLevel(args.get(JavaWeaverKeys.JAVA_COMPLIANCE_LEVEL));
-
- // Set pretty printer
- this.sourceCodePrinter = SpoonUtils.createSourcePrinter(environment);
-
- return spoon;
- }
-
- public KadabraPrettyPrinter getSourceCodePrinter() {
- return sourceCodePrinter;
- }
-
- private static void setInputSources(List sources, Launcher spoon) {
- for (File source : sources) {
- spoon.addInputResource(SpecsIo.getCanonicalPath(source));
- }
- }
-
- private static void setOutputProcessor(File outputDir, Launcher spoon, Environment environment) {
-
- JavaOutputProcessor outProcessor = spoon.createOutputWriter();
- // Define output folder (needed for the output type: classes)
- environment.setDefaultFileGenerator(outProcessor);
-
- spoon.setSourceOutputDirectory(SpecsIo.getCanonicalPath(outputDir));// Define output folder AGAIN
- spoon.setBinaryOutputDirectory(SpecsIo.getCanonicalPath(outputDir)); // Define output folder AGAIN (needed for
- }
-
- /**
- * Parse the options given to the weaver
- *
- * @param args
- */
- private void parseOptions(DataStore args) {
-
- if (args.hasValue(JavaWeaverKeys.CLEAR_OUTPUT_FOLDER)) {
- clearOutputFolder = args.get(JavaWeaverKeys.CLEAR_OUTPUT_FOLDER);
- }
- if (args.hasValue(JavaWeaverKeys.NO_CLASSPATH)) {
- noClassPath = args.get(JavaWeaverKeys.NO_CLASSPATH);
- }
- if (args.hasValue(JavaWeaverKeys.INCLUDE_DIRS)) {
- classPath = args.get(JavaWeaverKeys.INCLUDE_DIRS).getFiles();
- }
- if (args.hasValue(JavaWeaverKeys.OUTPUT_TYPE)) {
- outType = args.get(JavaWeaverKeys.OUTPUT_TYPE);
- }
- if (args.hasValue(JavaWeaverKeys.FORMAT)) {
- prettyPrint = args.get(JavaWeaverKeys.FORMAT);
- }
-
- if (args.hasValue(JavaWeaverKeys.REPORT)) {
-
- reportGear.setActive(args.get(JavaWeaverKeys.REPORT));
- }
-
- }
-
- private void buildAndProcess() {
- spoon.buildModel();
- spoon.process();
- }
-
- public void saveSpoonLauncher(Launcher spoonLauncher, File outputModelFile) throws IOException {
- try (ByteArrayOutputStream outstr = new ByteArrayOutputStream()) {
- new SerializationModelStreamer().save(spoonLauncher.getFactory(), outstr);
-
- try (FileOutputStream outputStream = new FileOutputStream(outputModelFile)) {
- outstr.writeTo(outputStream);
- }
- }
- }
-
- public Launcher loadSpoonLauncher(File inputModelFile) throws IOException {
- try (FileInputStream instr = new FileInputStream(inputModelFile)) {
- Factory loadedFactory = new SerializationModelStreamer()
- .load(new ByteArrayInputStream(instr.readAllBytes()));
-
- return new Launcher(loadedFactory);
- }
- }
-
- private void buildAndProcess(Launcher spoonLauncher) {
- spoonLauncher.buildModel();
- spoonLauncher.process();
- }
-
- /**
- * @return the clearOutputFolder
- */
- public boolean isClearOutputFolder() {
- return clearOutputFolder;
- }
-
- /**
- * @param clearOutputFolder the clearOutputFolder to set
- */
- public void setClearOutputFolder(boolean clearOutputFolder) {
- this.clearOutputFolder = clearOutputFolder;
- }
-
- public boolean isNoClassPath() {
- return noClassPath;
- }
-
- public void setNoClassPath(boolean noClassPath) {
- this.noClassPath = noClassPath;
- }
-
- @Override
- public List getOptions() {
- return WeaverOptionBuilder.enum2List(JavaWeaverOption.class, JavaWeaverOption::getOption);
- }
-
- @Override
- protected LanguageSpecification buildLangSpecs() {
- return LanguageSpecification.newInstance(JOINPOINTS, ARTIFACTS, ACTIONS);
- }
-
- @Override
- public String getName() {
- return "KADABRA";
- }
-
- public SpoonFactory getFactory() {
- return new SpoonFactory(spoon.getFactory());
- }
-
- @Override
- public Set getLanguages() {
- return LANGUAGES;
- }
-
- @Override
- public AstMethods getAstMethods() {
- return new KadabraAstMethods(this);
- }
-
- @Override
- public Object getRootNode() {
- return new CtApp(spoon);
- }
-
- @Override
- public JoinPoint getRootJp() {
- return jApp;
- }
-}
+package weaver.kadabra;
+
+import org.apache.commons.io.FileUtils;
+import org.lara.interpreter.joptions.config.interpreter.LaraiKeys;
+import org.lara.interpreter.weaver.ast.AstMethods;
+import org.lara.interpreter.weaver.interf.AGear;
+import org.lara.interpreter.weaver.options.WeaverOption;
+import org.lara.interpreter.weaver.options.WeaverOptionBuilder;
+import org.suikasoft.jOptions.Interfaces.DataStore;
+import pt.up.fe.specs.jadx.DecompilationFailedException;
+import pt.up.fe.specs.jadx.SpecsJadx;
+import pt.up.fe.specs.spoon.SpoonFactory;
+import pt.up.fe.specs.util.SpecsCollections;
+import pt.up.fe.specs.util.SpecsIo;
+import pt.up.fe.specs.util.SpecsLogs;
+import pt.up.fe.specs.util.utilities.LineStream;
+import spoon.Launcher;
+import spoon.OutputType;
+import spoon.compiler.Environment;
+import spoon.reflect.factory.Factory;
+import spoon.support.JavaOutputProcessor;
+import spoon.support.SerializationModelStreamer;
+import weaver.kadabra.abstracts.weaver.AJWeaver;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
+import weaver.kadabra.exceptions.JavaWeaverException;
+import weaver.kadabra.gears.Report;
+import weaver.kadabra.joinpoints.JApp;
+import weaver.kadabra.spoon.extensions.launcher.JWSpoonLauncher;
+import weaver.kadabra.spoon.extensions.nodes.CtApp;
+import weaver.kadabra.spoon.extensions.printer.KadabraPrettyPrinter;
+import weaver.kadabra.util.KadabraLog;
+import weaver.options.JavaWeaverKeys;
+import weaver.options.JavaWeaverOption;
+import weaver.utils.KadabraAstMethods;
+import weaver.utils.SpoonUtils;
+import weaver.utils.processors.IfProcessor;
+import weaver.utils.weaving.AnnotationsTable;
+
+import java.io.*;
+import java.util.*;
+import java.util.stream.Collectors;
+
+
+/**
+ * LARA Weaving Engine that uses Spoon as the Java compiler/processor
+ * Weaver Implementation for JWeaver
+ * Since the generated abstract classes are always overwritten, their
+ * implementation should be done by extending those abstract classes with
+ * user-defined classes.
+ * The abstract class {@link weaver.abstracts.AJoinPoint} can be used to add
+ * user-defined methods and fields which the user intends to add for all join
+ * points and are not intended to be used in LARA aspects.
+ *
+ * @author Lara C.
+ */
+public class JWeaver extends AJWeaver {
+ static {
+ KadabraLog.setDebug(true);
+ }
+
+ private static final Set LANGUAGES = SpecsCollections.asSet("java");
+
+ // Fields
+ private File outputDir;
+ private JWSpoonLauncher spoon;
+ private JApp jApp;
+ private AnnotationsTable table;
+ private List classPath;
+ private boolean clearOutputFolder;
+ private boolean prettyPrint;
+ private File currentOutputDir;
+ private KadabraPrettyPrinter sourceCodePrinter;
+
+ private boolean noClassPath = false; // Continues even if an error of missing lib occurs
+ private OutputType outType = OutputType.COMPILATION_UNITS;
+ private final Report reportGear;
+
+ private File temp;
+
+ public JWeaver() {
+ reportGear = new Report();
+ reportGear.setActive(false);
+ table = AnnotationsTable.getStaticTable();
+ }
+
+ /**
+ * Set a file/folder in the weaver if it is valid file/folder type for the
+ * weaver.
+ *
+ * @param sources the file with the source code
+ * @param outputDir output directory for the generated file(s)
+ * @param args arguments to start the weaver
+ * @return true if the file type is valid
+ */
+ @Override
+ protected boolean begin(List sources, File outputDir, DataStore args) {
+ setData(args);
+
+ // Add 'woven_code' to the end of the outputDir
+ if (dataStore.get(JavaWeaverKeys.WOVEN_FOLDER)) {
+ outputDir = new File(outputDir, "woven_code");
+ }
+
+ classPath = new ArrayList<>();
+ this.outputDir = outputDir;
+ clearOutputFolder = false;
+ reset();
+ parseOptions(args);
+
+ if (prettyPrint) {
+
+ this.outputDir.mkdirs();
+ temp = getTemporaryWeaverFolder();
+ outputDir = temp;
+ }
+
+ // Pass only Java files to spoon
+ // Method can do some processing, such as filtering duplicate classes
+ var javaSources = getJavaSources(sources);
+ spoon = newSpoon(javaSources, outputDir);
+
+ this.currentOutputDir = outputDir;
+ buildAndProcess();
+
+ jApp = JApp.newInstance(spoon, sources, this);
+
+ return true;
+ }
+
+ private List getJavaSources(List sources) {
+ List javaSources = new ArrayList<>();
+ Map seenTypes = new HashMap<>();
+ for (var source : sources) {
+
+ if (SpecsIo.getExtension(source).toLowerCase().equals("apk")) {
+ try {
+ var filterList = dataStore.get(JavaWeaverKeys.APK_PACKAGE_FILTER).getStringList();
+ source = new SpecsJadx().decompileAPK(source, filterList);
+ } catch (DecompilationFailedException e) {
+ SpecsLogs.warn(String.format("Jadx: DECOMPILE FAILED | %s", e.getMessage()));
+ }
+ }
+
+ var javaFiles = SpecsIo.getFilesRecursive(source, Arrays.asList("java"));
+
+ for (var javaFile : javaFiles) {
+ // Extract Java package
+ String packageDecl = getPackage(javaFile).orElse("");
+
+ var separator = packageDecl.isEmpty() ? "" : ".";
+
+ var javaKey = packageDecl + separator + javaFile.getName();
+
+ if (seenTypes.containsKey(javaKey)) {
+
+ SpecsLogs.info("Found duplicate class '" + javaFile.getAbsolutePath() + "', already added '"
+ + seenTypes.get(javaKey) + "'");
+ continue;
+ }
+
+ javaSources.add(javaFile);
+ seenTypes.put(javaKey, javaFile);
+ }
+ }
+
+ return javaSources;
+ }
+
+ private Optional getPackage(File javaFile) {
+ // Read each line until 'package' is found
+ try (var lines = LineStream.newInstance(javaFile)) {
+ while (lines.hasNextLine()) {
+ var line = lines.nextLine().strip().toLowerCase();
+
+ // Found package
+ if (line.startsWith("package ")) {
+ var packageName = line.substring("package ".length()).strip();
+ int colonIndex = packageName.indexOf(';');
+ if (colonIndex == -1) {
+ SpecsLogs.info("Found package, but could not find ';': " + line);
+ return Optional.empty();
+ }
+
+ return Optional.of(packageName.substring(0, colonIndex).strip());
+ }
+
+ // Stop when import, class, interface or modifier is found
+ if (line.startsWith("import ") || line.startsWith("public ") || line.startsWith("class ")
+ || line.startsWith("interface ") || line.startsWith("enum ")) {
+ break;
+ }
+
+ // Ignore other lines
+ }
+ }
+
+ return Optional.empty();
+ }
+
+ /**
+ * Closes the weaver to the specified output directory location, if the weaver
+ * generates new file(s)
+ *
+ * @return if close was successful
+ */
+ @Override
+ protected boolean close() {
+
+ if (clearOutputFolder) {
+ if (!dataStore.hasValue(LaraiKeys.OUTPUT_FOLDER)) {
+ KadabraLog.warning("No output folder defined, skipping cleaning");
+ } else {
+ try {
+ FileUtils.cleanDirectory(outputDir);
+ } catch (final IOException e) {
+ KadabraLog.warning("Output folder could not be cleaned before code generation: " + e.getMessage());
+ }
+ }
+
+ }
+
+ if (dataStore.get(JavaWeaverKeys.WRITE_CODE)) {
+ if (prettyPrint) {
+ spoon.prettyprint();
+ spoon = newSpoon(Arrays.asList(temp), outputDir);
+ buildAndProcess();
+ spoon.prettyprint();
+ } else {
+ spoon.prettyprint();
+ }
+ }
+
+ // Write XML files
+ jApp.getAndroidResources().write(outputDir);
+
+ // writeCode(temp, outputDir, true);
+
+ if (reportGear.isActive()) {
+
+ KadabraLog.info("REPORT: ");
+ KadabraLog.info("Advised Join Points: " + reportGear.getAdvisedJoinPoints().size());
+ }
+ return true;
+ }
+
+ @Override
+ public void writeCode(File outputFolder) {
+ // Set output folder
+ spoon.setSourceOutputDirectory(outputFolder);
+ // Generate code to output folder
+ spoon.prettyprint();
+
+ // Write XML files
+ jApp.getAndroidResources().write(outputFolder);
+ }
+
+ public void rebuild(File inputFolder, File outputFolder) {
+ if (clearOutputFolder) {
+ try {
+ FileUtils.cleanDirectory(outputFolder);
+ } catch (final IOException e) {
+ KadabraLog.warning("Output folder could not be cleaned before code generation: " + e.getMessage());
+ }
+ }
+
+ // Generate code to current output dir
+ spoon.prettyprint();
+
+ var newSpoon = newSpoon(Arrays.asList(inputFolder), outputFolder);
+ buildAndProcess(newSpoon);
+ newSpoon.prettyprint();
+
+ // Write XML files
+ jApp.getAndroidResources().write(outputFolder);
+ }
+
+ /**
+ * Returns a list of Gears associated to this weaver engine
+ *
+ * @return a list of implementations of {@link AGear} or null if no gears are
+ * available
+ */
+ @Override
+ public List getGears() {
+ List gears = new ArrayList<>();
+ gears.add(reportGear);
+ return gears;
+ }
+
+ private void reset() {
+ SpoonUtils.resetCounter();
+ table.reset();
+ /* RESET GEARS */
+ reportGear.reset();
+ }
+
+ /**
+ * Instantiates a new {@link JWSpoonLauncher} based on the given input sources
+ * and the properties of this {@link JWeaver} instance.
+ *
+ * @param sources the input sources to parse
+ * @return
+ */
+ private JWSpoonLauncher newSpoon(List sources, File outputDir) {
+ JWSpoonLauncher spoon = new JWSpoonLauncher(sources);
+
+ Environment environment = spoon.getFactory().getEnvironment();
+
+ spoon.setArgs(new String[] { "--output-type", outType.toString() }); // required to define the type of output...
+
+ if (!classPath.isEmpty()) {
+
+ try {
+ // Process classpath
+ // If there are JARs present in folders, add them as individual classpaths
+ List processedClasspath = new ArrayList<>();
+ processedClasspath.addAll(classPath);
+ var additionalJars = classPath.stream()
+ .filter(classPath -> classPath.isDirectory())
+ .flatMap(folder -> SpecsIo.getFilesRecursive(folder, "jar").stream())
+ .collect(Collectors.toList());
+ SpecsLogs.debug("Adding JARs to classpath: " + additionalJars);
+ processedClasspath.addAll(additionalJars);
+
+ List filesStr = processedClasspath.stream().map(SpecsIo::getCanonicalPath)
+ .collect(Collectors.toList());
+ String[] classPathArray = filesStr.toArray(new String[0]);
+ environment.setSourceClasspath(classPathArray);
+ } catch (Exception e) {
+ throw new JavaWeaverException("setting the classpath", e);
+ }
+ }
+
+ environment.setCommentEnabled(true);
+ setOutputProcessor(outputDir, spoon, environment);
+ environment.setNoClasspath(noClassPath);
+ setInputSources(sources, spoon);
+ spoon.addProcessor(new IfProcessor());
+
+ // Set fully qualified names
+ if (dataStore.get(JavaWeaverKeys.FULLY_QUALIFIED_NAMES)) {
+ environment.setAutoImports(false);
+ } else {
+ environment.setAutoImports(true);
+ }
+
+ environment.setCopyResources(dataStore.get(JavaWeaverKeys.COPY_RESOURCES));
+
+ environment.setComplianceLevel(dataStore.get(JavaWeaverKeys.JAVA_COMPLIANCE_LEVEL));
+
+ // Set pretty printer
+ this.sourceCodePrinter = SpoonUtils.createSourcePrinter(environment);
+
+ return spoon;
+ }
+
+ public KadabraPrettyPrinter getSourceCodePrinter() {
+ return sourceCodePrinter;
+ }
+
+ private static void setInputSources(List sources, Launcher spoon) {
+ for (File source : sources) {
+ spoon.addInputResource(SpecsIo.getCanonicalPath(source));
+ }
+ }
+
+ private static void setOutputProcessor(File outputDir, Launcher spoon, Environment environment) {
+
+ JavaOutputProcessor outProcessor = spoon.createOutputWriter();
+ // Define output folder (needed for the output type: classes)
+ environment.setDefaultFileGenerator(outProcessor);
+
+ spoon.setSourceOutputDirectory(SpecsIo.getCanonicalPath(outputDir));// Define output folder AGAIN
+ spoon.setBinaryOutputDirectory(SpecsIo.getCanonicalPath(outputDir)); // Define output folder AGAIN (needed for
+ }
+
+ /**
+ * Parse the options given to the weaver
+ *
+ * @param args
+ */
+ private void parseOptions(DataStore args) {
+
+ if (dataStore.hasValue(JavaWeaverKeys.CLEAR_OUTPUT_FOLDER)) {
+ clearOutputFolder = dataStore.get(JavaWeaverKeys.CLEAR_OUTPUT_FOLDER);
+ }
+ if (dataStore.hasValue(JavaWeaverKeys.NO_CLASSPATH)) {
+ noClassPath = dataStore.get(JavaWeaverKeys.NO_CLASSPATH);
+ }
+ if (dataStore.hasValue(JavaWeaverKeys.INCLUDE_DIRS)) {
+ classPath = dataStore.get(JavaWeaverKeys.INCLUDE_DIRS).getFiles();
+ }
+ if (dataStore.hasValue(JavaWeaverKeys.OUTPUT_TYPE)) {
+ outType = dataStore.get(JavaWeaverKeys.OUTPUT_TYPE);
+ }
+ if (dataStore.hasValue(JavaWeaverKeys.FORMAT)) {
+ prettyPrint = dataStore.get(JavaWeaverKeys.FORMAT);
+ }
+
+ if (dataStore.hasValue(JavaWeaverKeys.REPORT)) {
+
+ reportGear.setActive(dataStore.get(JavaWeaverKeys.REPORT));
+ }
+
+ }
+
+ private void buildAndProcess() {
+ spoon.buildModel();
+ spoon.process();
+ }
+
+ public void saveSpoonLauncher(Launcher spoonLauncher, File outputModelFile) throws IOException {
+ try (ByteArrayOutputStream outstr = new ByteArrayOutputStream()) {
+ new SerializationModelStreamer().save(spoonLauncher.getFactory(), outstr);
+
+ try (FileOutputStream outputStream = new FileOutputStream(outputModelFile)) {
+ outstr.writeTo(outputStream);
+ }
+ }
+ }
+
+ public Launcher loadSpoonLauncher(File inputModelFile) throws IOException {
+ try (FileInputStream instr = new FileInputStream(inputModelFile)) {
+ Factory loadedFactory = new SerializationModelStreamer()
+ .load(new ByteArrayInputStream(instr.readAllBytes()));
+
+ return new Launcher(loadedFactory);
+ }
+ }
+
+ private void buildAndProcess(Launcher spoonLauncher) {
+ spoonLauncher.buildModel();
+ spoonLauncher.process();
+ }
+
+ /**
+ * @return the clearOutputFolder
+ */
+ public boolean isClearOutputFolder() {
+ return clearOutputFolder;
+ }
+
+ /**
+ * @param clearOutputFolder the clearOutputFolder to set
+ */
+ public void setClearOutputFolder(boolean clearOutputFolder) {
+ this.clearOutputFolder = clearOutputFolder;
+ }
+
+ public boolean isNoClassPath() {
+ return noClassPath;
+ }
+
+ public void setNoClassPath(boolean noClassPath) {
+ this.noClassPath = noClassPath;
+ }
+
+ @Override
+ public List getOptions() {
+ return WeaverOptionBuilder.enum2List(JavaWeaverOption.class, JavaWeaverOption::getOption);
+ }
+
+ @Override
+ public String getName() {
+ return "KADABRA";
+ }
+
+ public SpoonFactory getFactory() {
+ return new SpoonFactory(spoon.getFactory());
+ }
+
+ @Override
+ public Set getLanguages() {
+ return LANGUAGES;
+ }
+
+ @Override
+ public AstMethods getAstMethods() {
+ return new KadabraAstMethods(this);
+ }
+
+ @Override
+ public Object getRootNode() {
+ return new CtApp(spoon);
+ }
+
+ @Override
+ public AJoinpoint> getRootJp() {
+ return jApp;
+ }
+}
diff --git a/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/ACommentTypeEnum.java b/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/ACommentTypeEnum.java
deleted file mode 100644
index 2e544ce5..00000000
--- a/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/ACommentTypeEnum.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package weaver.kadabra.abstracts.joinpoints.enums;
-
-import org.lara.interpreter.weaver.interf.NamedEnum;
-
-/**
- *
- */
-public enum ACommentTypeEnum implements NamedEnum{
- FILE("file"),
- INLINE("inline"),
- BLOCK("block"),
- JAVADOC("javadoc"),
- PRAGMA("pragma");
- private String name;
-
- /**
- *
- */
- private ACommentTypeEnum(String name){
- this.name = name;
- }
- /**
- *
- */
- public String getName() {
- return name;
- }
-}
diff --git a/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/ALoopTypeEnum.java b/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/ALoopTypeEnum.java
deleted file mode 100644
index 1f0b3e96..00000000
--- a/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/ALoopTypeEnum.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package weaver.kadabra.abstracts.joinpoints.enums;
-
-import org.lara.interpreter.weaver.interf.NamedEnum;
-
-/**
- *
- */
-public enum ALoopTypeEnum implements NamedEnum{
- FOR("for"),
- WHILE("while"),
- DO_WHILE("do-while"),
- FOREACH("foreach");
- private String name;
-
- /**
- *
- */
- private ALoopTypeEnum(String name){
- this.name = name;
- }
- /**
- *
- */
- public String getName() {
- return name;
- }
-}
diff --git a/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/AVarReferenceEnum.java b/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/AVarReferenceEnum.java
deleted file mode 100644
index fcb5c5f3..00000000
--- a/JavaWeaver/src/weaver/kadabra/abstracts/joinpoints/enums/AVarReferenceEnum.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package weaver.kadabra.abstracts.joinpoints.enums;
-
-import org.lara.interpreter.weaver.interf.NamedEnum;
-
-/**
- *
- */
-public enum AVarReferenceEnum implements NamedEnum{
- READ("read"),
- WRITE("write"),
- DECL("decl");
- private String name;
-
- /**
- *
- */
- private AVarReferenceEnum(String name){
- this.name = name;
- }
- /**
- *
- */
- public String getName() {
- return name;
- }
-}
diff --git a/JavaWeaver/src/weaver/kadabra/exceptions/JavaWeaverException.java b/JavaWeaver/src/weaver/kadabra/exceptions/JavaWeaverException.java
new file mode 100644
index 00000000..6e5ce7f2
--- /dev/null
+++ b/JavaWeaver/src/weaver/kadabra/exceptions/JavaWeaverException.java
@@ -0,0 +1,46 @@
+package weaver.kadabra.exceptions;
+
+import pt.up.fe.specs.tools.lara.exception.BaseException;
+
+/**
+ * This class can be used as the exception of this weaver in order to follow the message pretty print used by the interpreter
+ */
+public class JavaWeaverException extends BaseException {
+
+ private static final long serialVersionUID = 1L;
+ private final String event;
+
+ /**
+ * Create a new exception with a message
+ * @param event the exception message
+ */
+ public JavaWeaverException(String event){
+ this(event,null);
+ }
+ /**
+ * Create a new exception with the cause and the triggering event
+ * @param event the event that caused the exception
+ * @param cause the cause of this exception
+ */
+ public JavaWeaverException(String event, Throwable cause){
+ super(cause);
+ this.event = event;
+ }
+ /**
+ *
+ * @see pt.up.fe.specs.tools.lara.exception.BaseException#generateSimpleMessage()
+ */
+ @Override
+ protected String generateSimpleMessage() {
+ return " [JWeaver] " +this.event;
+ }
+
+ /**
+ *
+ * @see pt.up.fe.specs.tools.lara.exception.BaseException#generateMessage()
+ */
+ @Override
+ protected String generateMessage() {
+ return "Exception in "+this.generateSimpleMessage();
+ }
+}
diff --git a/JavaWeaver/src/weaver/kadabra/gears/KadabraUniqueNodeCounter.java b/JavaWeaver/src/weaver/kadabra/gears/KadabraUniqueNodeCounter.java
index 18d1aacb..5db127f0 100644
--- a/JavaWeaver/src/weaver/kadabra/gears/KadabraUniqueNodeCounter.java
+++ b/JavaWeaver/src/weaver/kadabra/gears/KadabraUniqueNodeCounter.java
@@ -20,7 +20,7 @@
import java.util.Optional;
import java.util.Set;
-import org.lara.interpreter.weaver.interf.JoinPoint;
+import org.lara.interpreter.weaver.interf.JoinPoint2;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtNamedElement;
@@ -40,7 +40,7 @@ public long getTotalNodes() {
return reduce.orElse(0);
}
- public void addNode(String key, JoinPoint joinPoint) {
+ public void addNode(String key, JoinPoint2, ?> joinPoint) {
if (!map.containsKey(key)) {
map.put(key, new HashSet<>());
}
@@ -50,12 +50,12 @@ public void addNode(String key, JoinPoint joinPoint) {
// } else if (joinPoint instanceof JFile) {
// source.add(((JFile) joinPoint).getPathImpl());
} else {
- source.add(joinPoint.getNode());
+ source.add(joinPoint.getNodeImpl());
}
}
- public void addIteration(String key, List joinpoints) {
- for (JoinPoint joinPoint : joinpoints) {
+ public void addIteration(String key, List> joinpoints) {
+ for (JoinPoint2, ?> joinPoint : joinpoints) {
addNode(key, joinPoint);
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/gears/Report.java b/JavaWeaver/src/weaver/kadabra/gears/Report.java
index 691e51e2..b6d06752 100644
--- a/JavaWeaver/src/weaver/kadabra/gears/Report.java
+++ b/JavaWeaver/src/weaver/kadabra/gears/Report.java
@@ -17,10 +17,10 @@
import java.util.Set;
import org.lara.interpreter.weaver.interf.AGear;
-import org.lara.interpreter.weaver.interf.JoinPoint;
+import org.lara.interpreter.weaver.interf.JoinPoint2;
import org.lara.interpreter.weaver.interf.events.data.ActionEvent;
-import weaver.kadabra.abstracts.joinpoints.AJoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
import weaver.kadabra.util.KadabraLog;
public class Report extends AGear {
@@ -29,13 +29,13 @@ public class Report extends AGear {
@Override
public void onAction(ActionEvent data) {
- JoinPoint joinPoint = data.getJoinPoint();
- if (!(joinPoint instanceof AJoinPoint)) {
+ var joinPoint = data.getJoinPoint();
+ if (!(joinPoint instanceof AJoinpoint>)) {
KadabraLog.warning("Report: unrecognized type of join point: " + joinPoint.getClass());
return;
}
- AJoinPoint aJP = (AJoinPoint) joinPoint;
- advisedJoinPoints.add(aJP.getNode());
+ AJoinpoint> aJP = (AJoinpoint>) joinPoint;
+ advisedJoinPoints.add(aJP.getNodeImpl());
}
public Set getAdvisedJoinPoints() {
diff --git a/JavaWeaver/src/weaver/kadabra/importable/KadabraJoinPoints.java b/JavaWeaver/src/weaver/kadabra/importable/KadabraJoinPoints.java
index 42299e79..ee3014eb 100644
--- a/JavaWeaver/src/weaver/kadabra/importable/KadabraJoinPoints.java
+++ b/JavaWeaver/src/weaver/kadabra/importable/KadabraJoinPoints.java
@@ -16,7 +16,7 @@
import java.util.Arrays;
import java.util.Objects;
-import org.lara.interpreter.weaver.interf.JoinPoint;
+import org.lara.interpreter.weaver.interf.JoinPoint2;
import pt.up.fe.specs.util.SpecsCheck;
import spoon.reflect.code.BinaryOperatorKind;
@@ -24,8 +24,8 @@
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.UnaryOperatorKind;
import spoon.reflect.declaration.CtElement;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.AJavaWeaverJoinPoint;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
import weaver.kadabra.joinpoints.JComment;
import weaver.kadabra.joinpoints.JLocalVariable;
import weaver.utils.SpoonLiterals;
@@ -44,7 +44,7 @@ public class KadabraJoinPoints {
* the type of comment, according to CtComment.CommentType
* @return
*/
- public static JComment comment(JavaWeaver weaver, String comment, String type) {
+ public static JComment comment(JWeaver weaver, String comment, String type) {
// Convert the type
CommentType typeEnum = null;
@@ -68,7 +68,7 @@ public static JComment comment(JavaWeaver weaver, String comment, String type) {
* signed, returns a unaryExpression instead of a literal
* @return
*/
- public static Object literal(JavaWeaver weaver, String literal, String type) {
+ public static Object literal(JWeaver weaver, String literal, String type) {
boolean isNegative = false;
// Check if negative
@@ -89,9 +89,9 @@ public static Object literal(JavaWeaver weaver, String literal, String type) {
return CtElement2JoinPoint.convert(expressionNode, weaver);
}
- public static Object nullLiteral(JavaWeaver weaver, Object referenceJp) {
+ public static Object nullLiteral(JWeaver weaver, Object referenceJp) {
if (referenceJp != null) {
- SpecsCheck.checkArgument(referenceJp instanceof JoinPoint,
+ SpecsCheck.checkArgument(referenceJp instanceof AJoinpoint>,
() -> "Reference join point must be a join point, it is a "
+ referenceJp.getClass().getSimpleName());
}
@@ -112,17 +112,17 @@ public static Object nullLiteral(JavaWeaver weaver, Object referenceJp) {
* an expression join point
* @return
*/
- public static Object unaryOperator(JavaWeaver weaver, String operator, Object operand) {
+ public static Object unaryOperator(JWeaver weaver, String operator, Object operand) {
- SpecsCheck.checkArgument(operand instanceof JoinPoint,
+ SpecsCheck.checkArgument(operand instanceof AJoinpoint>,
() -> "Operand must be a join point, it " + operator.getClass().getSimpleName());
- AJavaWeaverJoinPoint jpOperand = (AJavaWeaverJoinPoint) operand;
+ AJoinpoint> jpOperand = (AJoinpoint>) operand;
SpecsCheck.checkArgument(jpOperand.instanceOf("expression"),
- () -> "Operand must be a join point of type 'expression', is " + jpOperand.getJoinPointType());
+ () -> "Operand must be a join point of type 'expression', is " + jpOperand.get_class());
- CtExpression> nodeExpr = (CtExpression>) jpOperand.getNode();
+ CtExpression> nodeExpr = (CtExpression>) jpOperand.getNodeImpl();
// Convert string to kind
UnaryOperatorKind opKind = OperatorUtils.parseUnary(operator);
@@ -143,23 +143,23 @@ public static Object unaryOperator(JavaWeaver weaver, String operator, Object op
* expression
* @return
*/
- public static Object binaryOperator(JavaWeaver weaver, String operator, Object lhs, Object rhs) {
+ public static Object binaryOperator(JWeaver weaver, String operator, Object lhs, Object rhs) {
- SpecsCheck.checkArgument(lhs instanceof JoinPoint,
+ SpecsCheck.checkArgument(lhs instanceof AJoinpoint>,
() -> "Lhs must be a join point, it " + operator.getClass().getSimpleName());
- SpecsCheck.checkArgument(rhs instanceof JoinPoint,
+ SpecsCheck.checkArgument(rhs instanceof AJoinpoint>,
() -> "Rhs must be a join point, it " + operator.getClass().getSimpleName());
- AJavaWeaverJoinPoint jpLhs = (AJavaWeaverJoinPoint) lhs;
- AJavaWeaverJoinPoint jpRhs = (AJavaWeaverJoinPoint) rhs;
+ AJoinpoint> jpLhs = (AJoinpoint>) lhs;
+ AJoinpoint> jpRhs = (AJoinpoint>) rhs;
SpecsCheck.checkArgument(jpLhs.instanceOf("expression"),
- () -> "Lhs must be a join point of type 'expression', is " + jpLhs.getJoinPointType());
+ () -> "Lhs must be a join point of type 'expression', is " + jpLhs.get_class());
SpecsCheck.checkArgument(jpRhs.instanceOf("expression"),
- () -> "Rhs must be a join point of type 'expression', is " + jpRhs.getJoinPointType());
+ () -> "Rhs must be a join point of type 'expression', is " + jpRhs.get_class());
- CtExpression> nodeLhs = (CtExpression>) jpLhs.getNode();
- CtExpression> nodeRhs = (CtExpression>) jpRhs.getNode();
+ CtExpression> nodeLhs = (CtExpression>) jpLhs.getNodeImpl();
+ CtExpression> nodeRhs = (CtExpression>) jpRhs.getNodeImpl();
// Convert string to kind
BinaryOperatorKind opKind = OperatorUtils.parseBinary(operator);
@@ -167,31 +167,31 @@ public static Object binaryOperator(JavaWeaver weaver, String operator, Object l
return CtElement2JoinPoint.convert(weaver.getFactory().binaryOperator(opKind, nodeLhs, nodeRhs), weaver);
}
- public static Object assignment(JavaWeaver weaver, Object lhs, Object rhs) {
+ public static Object assignment(JWeaver weaver, Object lhs, Object rhs) {
Objects.requireNonNull(lhs, () -> "lhs cannot be null");
Objects.requireNonNull(rhs, () -> "rhs cannot be null");
- SpecsCheck.checkArgument(lhs instanceof JoinPoint,
+ SpecsCheck.checkArgument(lhs instanceof AJoinpoint>,
() -> "Lhs must be a join point, it is a " + lhs.getClass().getSimpleName());
- SpecsCheck.checkArgument(rhs instanceof JoinPoint,
+ SpecsCheck.checkArgument(rhs instanceof AJoinpoint>,
() -> "Rhs must be a join point, it is a " + rhs.getClass().getSimpleName());
- AJavaWeaverJoinPoint jpLhs = (AJavaWeaverJoinPoint) lhs;
- AJavaWeaverJoinPoint jpRhs = (AJavaWeaverJoinPoint) rhs;
+ AJoinpoint> jpLhs = (AJoinpoint>) lhs;
+ AJoinpoint> jpRhs = (AJoinpoint>) rhs;
SpecsCheck.checkArgument(jpLhs.instanceOf("expression"),
- () -> "Lhs must be a join point of type 'expression', is " + jpLhs.getJoinPointType());
+ () -> "Lhs must be a join point of type 'expression', is " + jpLhs.get_class());
SpecsCheck.checkArgument(jpRhs.instanceOf("expression"),
- () -> "Rhs must be a join point of type 'expression', is " + jpRhs.getJoinPointType());
+ () -> "Rhs must be a join point of type 'expression', is " + jpRhs.get_class());
- CtExpression> nodeLhs = (CtExpression>) jpLhs.getNode();
- CtExpression> nodeRhs = (CtExpression>) jpRhs.getNode();
+ CtExpression> nodeLhs = (CtExpression>) jpLhs.getNodeImpl();
+ CtExpression> nodeRhs = (CtExpression>) jpRhs.getNodeImpl();
return CtElement2JoinPoint.convert(weaver.getFactory().assignment(nodeLhs, nodeRhs), weaver);
}
- public static Object var(JavaWeaver weaver, JLocalVariable localVariable, boolean isWrite) {
- var localVarSpoon = localVariable.getNode();
+ public static Object var(JWeaver weaver, JLocalVariable localVariable, boolean isWrite) {
+ var localVarSpoon = localVariable.getNodeImpl();
return CtElement2JoinPoint.convert(weaver.getFactory().var(localVarSpoon, isWrite), weaver);
}
@@ -201,7 +201,7 @@ public static Object var(JavaWeaver weaver, JLocalVariable localVariable, boolea
* @param code
* @return
*/
- public static Object snippetExpression(JavaWeaver weaver, String code) {
+ public static Object snippetExpression(JWeaver weaver, String code) {
return CtElement2JoinPoint
.convert(SnippetFactory.createSnippetExpression(weaver.getFactory().getSpoonFactory(), code), weaver);
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JAndroidManifest.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JAndroidManifest.java
index 9dc72821..1438bc80 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JAndroidManifest.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JAndroidManifest.java
@@ -14,40 +14,35 @@
package weaver.kadabra.joinpoints;
import org.json.XML;
+
import pt.up.fe.specs.util.xml.XmlDocument;
-import spoon.reflect.declaration.CtElement;
-import weaver.kadabra.JavaWeaver;
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.AAndroidManifest;
-import weaver.kadabra.abstracts.joinpoints.AJoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
-public class JAndroidManifest extends AAndroidManifest {
+public class JAndroidManifest> extends AAndroidManifest {
private final XmlDocument manifest;
- public JAndroidManifest(XmlDocument manifest, JavaWeaver weaver) {
- super(new JXmlNode(manifest, weaver), weaver);
+ public JAndroidManifest(XmlDocument manifest, JWeaver weaver) {
+ super(manifest, weaver);
this.manifest = manifest;
}
- @Override
- public CtElement getNode() {
- return null;
- }
-
@Override
public String getAsJsonImpl() {
return XML.toJSONObject(manifest.toString()).toString(4);
}
@Override
- public String toString() {
+ public String getToStringImpl() {
return "AndroidManifest";
}
@Override
- public AJoinPoint getParentImpl() {
+ public AJoinpoint> getParentImpl() {
// Parent is App
- return (JApp) getWeaverEngine().getRootJp();
+ return (JApp>) getWeaverEngine().getRootJp();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JAnnotation.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JAnnotation.java
index 4a9e70a9..36cc5716 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JAnnotation.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JAnnotation.java
@@ -1,11 +1,11 @@
/**
* Copyright 2020 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -14,23 +14,19 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.declaration.CtAnnotation;
-import spoon.reflect.declaration.CtElement;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.AAnnotation;
-
-public class JAnnotation extends AAnnotation {
- private final CtAnnotation> annotation;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AAnnotation;
- public JAnnotation(CtAnnotation> annotation, JavaWeaver weaver) {
- super(new JExpression<>(annotation, weaver), weaver);
+public class JAnnotation> extends AAnnotation {
- this.annotation = annotation;
+ public JAnnotation(CtAnnotation annotation, JWeaver weaver) {
+ super(annotation, weaver);
}
@Override
- public CtElement getNode() {
- return annotation;
+ public CtAnnotation> getNodeImpl() {
+ return (CtAnnotation>) super.getNodeImpl();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JAnonymousExec.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JAnonymousExec.java
index 24c8fc02..e0d97165 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JAnonymousExec.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JAnonymousExec.java
@@ -1,11 +1,11 @@
/**
* Copyright 2017 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -14,26 +14,19 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.declaration.CtAnonymousExecutable;
-import spoon.reflect.declaration.CtElement;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.AAnonymousExec;
-
-public class JAnonymousExec extends AAnonymousExec {
- private CtAnonymousExecutable node;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AAnonymousExec;
- public JAnonymousExec(CtAnonymousExecutable executable, JavaWeaver weaver) {
- super(JExecutable.newInstance(executable, weaver), weaver);
- this.node = executable;
- }
+public class JAnonymousExec> extends AAnonymousExec {
- public static JAnonymousExec newInstance(CtAnonymousExecutable executable, JavaWeaver weaver) {
- return new JAnonymousExec(executable, weaver);
+ public JAnonymousExec(CtAnonymousExecutable node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtElement getNode() {
- return node;
+ public CtAnonymousExecutable getNodeImpl() {
+ return (CtAnonymousExecutable) super.getNodeImpl();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JApp.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JApp.java
index 6d8158ec..b373a0fd 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JApp.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JApp.java
@@ -13,14 +13,14 @@
package weaver.kadabra.joinpoints;
-import org.lara.interpreter.weaver.interf.JoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AApp;
import spoon.Launcher;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtInterface;
import spoon.reflect.factory.Factory;
import spoon.support.gui.SpoonModelTree;
-import weaver.kadabra.JavaWeaver;
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.*;
import weaver.kadabra.spoon.extensions.nodes.CtApp;
import weaver.utils.android.AndroidResources;
@@ -34,37 +34,41 @@
import java.util.Set;
import java.util.stream.Collectors;
-public class JApp extends AApp {
+public class JApp> extends AApp {
public final Launcher spoon;
private final Set sources;
private final AndroidResources androidResources;
- private JApp(Launcher spoon, List sources, JavaWeaver weaver) {
- super(weaver);
- this.spoon = spoon;
+ public JApp(CtApp node, JWeaver weaver) {
+ this(node, Collections.emptyList(), weaver);
+ }
+
+ public JApp(CtApp node, List sources, JWeaver weaver) {
+ super(node, weaver);
+ this.spoon = node.spoon;
this.sources = new HashSet<>(sources);
this.androidResources = AndroidResources.newInstance(sources);
}
- public static JApp newInstance(Launcher spoon, List sources, JavaWeaver weaver) {
- var app = new JApp(spoon, sources, weaver);
+ public static JApp> newInstance(Launcher spoon, List sources, JWeaver weaver) {
+ var app = new JApp<>(new CtApp(spoon), sources, weaver);
return app;
}
- public static JApp newInstance(CtApp app, JavaWeaver weaver) {
- return new JApp(app.spoon, Collections.emptyList(), weaver);
+ public static JApp> newInstance(CtApp app, JWeaver weaver) {
+ return new JApp<>(app, weaver);
}
public AndroidResources getAndroidResources() {
return androidResources;
}
- private List extends AFile> retrieveFiles() {
+ private List> retrieveFiles() {
- final List files = spoon.getFactory().CompilationUnit().getMap().values().stream()
- .map(cu -> new JFile(cu, getWeaverEngine()))
+ final List> files = spoon.getFactory().CompilationUnit().getMap().values().stream()
+ .map(cu -> new JFile<>(cu, getWeaverEngine()))
.collect(Collectors.toList());
return files;
@@ -78,58 +82,59 @@ public String getFolderImpl() {
}
@Override
- public AClass newClassImpl(String name) {
+ public AClass> newClassImpl(String name) {
return newClassImpl(name, null, null);
}
@Override
- public AClass newClassImpl(String name, String extend, String[] implement) {
+ public AClass> newClassImpl(String name, String extend, String[] implement) {
if (name == null || name.isEmpty()) {
throw new NullPointerException("the name of the new class cannot be null or empty");
}
var cu = ActionUtils.compilationUnitWithClass(name, extend, implement,
spoon.getModelBuilder().getBinaryOutputDirectory(), spoon.getFactory());
CtClass> mainClass = (CtClass>) cu.getMainType();
- AClass newInstance = JClass.newInstance(mainClass, cu, getWeaverEngine());
+ AClass> newInstance = new JClass<>(mainClass, cu, getWeaverEngine());
return newInstance;
}
@Override
- public AInterfaceType newInterfaceImpl(String name) {
+ public AInterfaceType> newInterfaceImpl(String name) {
return newInterfaceImpl(name, null);
}
@Override
- public AInterfaceType newInterfaceImpl(String name, String[] extend) {
- final CtInterface newInterface = ActionUtils.compilationUnitWithInterface(name, extend,
+ public AInterfaceType> newInterfaceImpl(String name, String[] extend) {
+ final CtInterface> newInterface = ActionUtils.compilationUnitWithInterface(name, extend,
spoon.getModelBuilder().getBinaryOutputDirectory(),
spoon.getFactory());
- JInterfaceType newInstance = JInterfaceType.newInstance(newInterface, getWeaverEngine());
+ JInterfaceType> newInstance = new JInterfaceType<>(newInterface, getWeaverEngine());
return newInstance;
}
@Override
- public AClass mapVersionsImpl(String name, String keyType, AInterfaceType _interface, String methodName) {
+ public AClass> mapVersionsImpl(String name, String keyType, AInterfaceType> _interface, String methodName) {
File outDir = spoon.getModelBuilder().getBinaryOutputDirectory();
Factory factory = spoon.getFactory();
var cu = MapGenerator.generate(factory, name, keyType, _interface, methodName, outDir);
- JClass> newInstance = JClass.newInstance((CtClass>) cu.getMainType(), cu, getWeaverEngine());
+ JClass> newInstance = new JClass<>((CtClass>) cu.getMainType(), cu, getWeaverEngine());
return newInstance;
}
@Override
- public String showASTImpl(String title) {
+ public String getShowASTImpl(String Title) {
// SpoonModelTree window starts in the constructor
SpoonModelTree tree = new SpoonModelTree(spoon.getFactory());
- tree.setTitle(title);
+ tree.setTitle(Title);
tree.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
return "";
}
@Override
- public CtElement getNode() {
+ public CtElement getNodeImpl() {
+ // App has no AST node of its own
return null;
}
@@ -137,13 +142,13 @@ public CtElement getNode() {
* App is the root node, so it has not parent.
*/
@Override
- public AJoinPoint getParentImpl() {
+ public AJoinpoint> getParentImpl() {
return null;
}
@Override
- public boolean compareNodes(AJoinPoint aJoinPoint) {
- return equals(aJoinPoint);
+ public boolean getCompareNodesImpl(AJoinpoint> aJoinPoint) {
+ return this == aJoinPoint;
}
public Launcher getSpoon() {
@@ -152,19 +157,10 @@ public Launcher getSpoon() {
}
@Override
- public String toString() {
+ public String getToStringImpl() {
return "Java application"; // from " + getFolderImpl();
}
- @Override
- public boolean same(JoinPoint iJoinPoint) {
- if (this.get_class().equals(iJoinPoint.get_class())) {
-
- return this.compareNodes((AJoinPoint) iJoinPoint);
- }
- return false;
- }
-
@Override
public String getCodeImpl() {
String separator = "/************/";
@@ -174,18 +170,18 @@ public String getCodeImpl() {
}
@Override
- public AJoinPoint[] getChildrenArrayImpl() {
- return retrieveFiles().toArray(size -> new AJoinPoint[size]);
+ public AJoinpoint>[] getChildrenImpl() {
+ return retrieveFiles().toArray(size -> new AJoinpoint[size]);
}
@Override
- public AAndroidManifest getManifestImpl() {
+ public AAndroidManifest> getManifestImpl() {
var manifest = androidResources.getAndroidManifest();
- return manifest != null ? new JAndroidManifest(manifest, getWeaverEngine()) : null;
+ return manifest != null ? new JAndroidManifest<>(manifest, getWeaverEngine()) : null;
}
@Override
- public AFile[] getFilesArrayImpl() {
+ public AFile>[] getFilesImpl() {
return retrieveFiles().toArray(size -> new AFile[size]);
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JArrayAccess.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JArrayAccess.java
index 8297bb3f..034f4140 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JArrayAccess.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JArrayAccess.java
@@ -1,11 +1,11 @@
/**
* Copyright 2015 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -13,36 +13,28 @@
package weaver.kadabra.joinpoints;
+import weaver.kadabra.abstracts.joinpoints.AArrayAccess;
import spoon.reflect.code.CtArrayAccess;
import spoon.reflect.code.CtArrayWrite;
-import spoon.reflect.code.CtExpression;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.AArrayAccess;
+
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ATypeReference;
import weaver.kadabra.enums.RefType;
-public class JArrayAccess> extends AArrayAccess {
-
- private final CtArrayAccess node;
-
- protected JArrayAccess(CtArrayAccess access, JavaWeaver weaver) {
- super(new JExpression<>(access, weaver), weaver);
- this.node = access;
- }
+public class JArrayAccess> extends AArrayAccess {
- public static > JArrayAccess newInstance(CtArrayAccess access,
- JavaWeaver weaver) {
- return new JArrayAccess<>(access, weaver);
+ public JArrayAccess(CtArrayAccess node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public String getReferenceImpl() {
- return node instanceof CtArrayWrite ? RefType.WRITE.getName() : RefType.READ.getName();
+ public RefType getReferenceImpl() {
+ return getNodeImpl() instanceof CtArrayWrite ? RefType.WRITE : RefType.READ;
}
@Override
- public ATypeReference getTypeReferenceImpl() {
- return new JTypeReference<>(node.getType(), getWeaverEngine());
+ public ATypeReference> getTypeReferenceImpl() {
+ return new JTypeReference<>(getNodeImpl().getType(), getWeaverEngine());
}
@Override
@@ -51,7 +43,7 @@ public String getTypeImpl() {
}
@Override
- public CtArrayAccess getNode() {
- return node;
+ public CtArrayAccess, ?> getNodeImpl() {
+ return (CtArrayAccess, ?>) super.getNodeImpl();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JAssert.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JAssert.java
index dd9bec17..0228388f 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JAssert.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JAssert.java
@@ -1,11 +1,11 @@
/**
* Copyright 2016 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -14,24 +14,18 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.code.CtAssert;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.AAssert;
-
-public class JAssert extends AAssert {
- private final CtAssert node;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AAssert;
- private JAssert(CtAssert node, JavaWeaver weaver) {
- super(new JStatement(node, weaver), weaver);
- this.node = node;
- }
+public class JAssert> extends AAssert {
- public static JAssert newInstance(CtAssert node, JavaWeaver weaver) {
- return new JAssert<>(node, weaver);
+ public JAssert(CtAssert node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtAssert getNode() {
- return node;
+ public CtAssert> getNodeImpl() {
+ return (CtAssert>) super.getNodeImpl();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JAssignment.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JAssignment.java
index f1f4bd33..88cbe97d 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JAssignment.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JAssignment.java
@@ -1,11 +1,11 @@
/**
* Copyright 2016 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -15,26 +15,15 @@
import spoon.reflect.code.CtAssignment;
import spoon.reflect.code.CtExpression;
-import spoon.reflect.code.CtOperatorAssignment;
-import weaver.kadabra.JavaWeaver;
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.AAssignment;
import weaver.kadabra.abstracts.joinpoints.AExpression;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-public class JAssignment extends AAssignment {
+public class JAssignment> extends AAssignment {
- private final CtAssignment node;
-
- protected JAssignment(CtAssignment node, JavaWeaver weaver) {
- super(new JStatement(node, weaver), weaver);
- this.node = node;
- }
-
- public static JAssignment newInstance(CtAssignment node, JavaWeaver weaver) {
- if (node instanceof CtOperatorAssignment) {
- return JOpAssignmentAux.newInstance((CtOperatorAssignment) node, weaver);
- }
- return new JAssignment<>(node, weaver);
+ public JAssignment(CtAssignment node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
@@ -43,29 +32,29 @@ public String getOperatorImpl() {
}
@Override
- public CtAssignment getNode() {
- return node;
+ public CtAssignment, ?> getNodeImpl() {
+ return (CtAssignment, ?>) super.getNodeImpl();
}
@Override
- public AExpression getLhsImpl() {
- return (AExpression) CtElement2JoinPoint.convert(node.getAssigned(), getWeaverEngine());
+ public AExpression> getLhsImpl() {
+ return (AExpression>) CtElement2JoinPoint.convert(getNodeImpl().getAssigned(), getWeaverEngine());
}
@Override
- public AExpression getRhsImpl() {
- return (AExpression) CtElement2JoinPoint.convert(node.getAssignment(), getWeaverEngine());
+ public AExpression> getRhsImpl() {
+ return (AExpression>) CtElement2JoinPoint.convert(getNodeImpl().getAssignment(), getWeaverEngine());
}
@Override
- @SuppressWarnings("unchecked")
- public void setLhsImpl(AExpression lhs) {
- node.setAssigned((CtExpression) lhs.getNode());
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void setLhsImpl(AExpression> lhs) {
+ ((CtAssignment) getNodeImpl()).setAssigned((CtExpression) lhs.getNodeImpl());
}
@Override
- @SuppressWarnings("unchecked")
- public void setRhsImpl(AExpression rhs) {
- node.setAssignment((CtExpression) rhs.getNode());
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void setRhsImpl(AExpression> rhs) {
+ ((CtAssignment) getNodeImpl()).setAssignment((CtExpression) rhs.getNodeImpl());
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JBinaryExpression.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JBinaryExpression.java
index d8e4cf07..ae03d88d 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JBinaryExpression.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JBinaryExpression.java
@@ -1,11 +1,11 @@
/**
* Copyright 2015 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -14,64 +14,58 @@
package weaver.kadabra.joinpoints;
import pt.up.fe.specs.util.SpecsLogs;
+
import spoon.reflect.code.BinaryOperatorKind;
import spoon.reflect.code.CtBinaryOperator;
-import weaver.kadabra.JavaWeaver;
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ABinaryExpression;
import weaver.kadabra.abstracts.joinpoints.AExpression;
import weaver.utils.element.OperatorUtils;
import weaver.utils.weaving.SelectUtils;
-public class JBinaryExpression extends ABinaryExpression {
-
- public CtBinaryOperator node;
-
- public JBinaryExpression(CtBinaryOperator expr, JavaWeaver weaver) {
- super(new JExpression<>(expr, weaver), weaver);
- node = expr;
- }
+public class JBinaryExpression> extends ABinaryExpression {
- public static JBinaryExpression newInstance(CtBinaryOperator expr, JavaWeaver weaver) {
- return new JBinaryExpression<>(expr, weaver);
+ public JBinaryExpression(CtBinaryOperator node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
public String getOperatorImpl() {
- return OperatorUtils.convert(node.getKind());
+ return OperatorUtils.convert(getNodeImpl().getKind());
}
@Override
- public CtBinaryOperator> getNode() {
- return node;
+ public CtBinaryOperator> getNodeImpl() {
+ return (CtBinaryOperator>) super.getNodeImpl();
}
@Override
- public void setOperatorImpl(String value) {
+ public void setOperatorImpl(String operator) {
// Convert string to kind
- BinaryOperatorKind kind = OperatorUtils.parseBinaryTry(value).orElse(null);
+ BinaryOperatorKind kind = OperatorUtils.parseBinaryTry(operator).orElse(null);
if (kind == null) {
- SpecsLogs.msgInfo("Could not parse binary operator '" + value + "'");
+ SpecsLogs.msgInfo("Could not parse binary operator '" + operator + "'");
return;
}
- node.setKind(kind);
+ getNodeImpl().setKind(kind);
}
@Override
- public AExpression[] getOperandsArrayImpl() {
- AExpression[] operands = { getLhsImpl(), getRhsImpl() };
+ public AExpression>[] getOperandsImpl() {
+ AExpression>[] operands = { getLhsImpl(), getRhsImpl() };
return operands;
}
@Override
- public AExpression getLhsImpl() {
- return SelectUtils.expression2JoinPoint(node.getLeftHandOperand(), getWeaverEngine());
+ public AExpression> getLhsImpl() {
+ return SelectUtils.expression2JoinPoint(getNodeImpl().getLeftHandOperand(), getWeaverEngine());
}
@Override
- public AExpression getRhsImpl() {
- return SelectUtils.expression2JoinPoint(node.getRightHandOperand(), getWeaverEngine());
+ public AExpression> getRhsImpl() {
+ return SelectUtils.expression2JoinPoint(getNodeImpl().getRightHandOperand(), getWeaverEngine());
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JBody.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JBody.java
index 1c5d7029..10423d72 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JBody.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JBody.java
@@ -1,11 +1,11 @@
/**
* Copyright 2015 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -13,102 +13,97 @@
package weaver.kadabra.joinpoints;
+import org.lara.interpreter.weaver.interf.enums.InsertPosition;
+
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtCodeSnippetStatement;
-import spoon.reflect.code.CtStatement;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.AJavaWeaverJoinPoint;
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ABody;
-import weaver.kadabra.abstracts.joinpoints.AJoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
import weaver.kadabra.abstracts.joinpoints.AStatement;
import weaver.utils.weaving.ActionUtils.Location;
import weaver.utils.weaving.SnippetFactory;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-public class JBody extends ABody {
-
- private final CtBlock node;
-
- private JBody(CtBlock block, JavaWeaver weaver) {
- super(new JStatement(block, weaver), weaver);
- node = block;
- }
+public class JBody> extends ABody {
- public static JBody newInstance(CtBlock block, JavaWeaver weaver) {
- return new JBody<>(block, weaver);
+ public JBody(CtBlock node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public AJoinPoint[] insertImpl(String position, String code) {
- return new AJoinPoint[] { insertImplJBody(position, code) };
+ public AJoinpoint>[] insertImpl(InsertPosition position, String code) {
+ return new AJoinpoint>[] { insertImplJBody(position, code) };
}
- public AJavaWeaverJoinPoint insertImplJBody(String position, String code) {
- final CtCodeSnippetStatement snippet = SnippetFactory.createSnippetStatement(code, node.getFactory());
+ public AJoinpoint> insertImplJBody(InsertPosition position, String code) {
+ final CtCodeSnippetStatement snippet = SnippetFactory.createSnippetStatement(code,
+ getNodeImpl().getFactory());
- switch (Location.valueOf(position.toUpperCase())) {
- case AROUND:
+ switch (position) {
case REPLACE:
- node.getStatements().clear();
- node.addStatement(snippet);
- snippet.setParent(node);
+ getNodeImpl().getStatements().clear();
+ getNodeImpl().addStatement(snippet);
+ snippet.setParent(getNodeImpl());
break;
default:
throw new RuntimeException(
"Code insertion on a block can only be done around (i.e., complete code replacement)");
}
- snippet.setParent(node);
+ snippet.setParent(getNodeImpl());
return CtElement2JoinPoint.convert(snippet, getWeaverEngine());
}
@Override
public void insertBeginImpl(String code) {
- final CtCodeSnippetStatement snippet = SnippetFactory.createSnippetStatement(code, node.getFactory());
- node.insertBegin(snippet);
+ final CtCodeSnippetStatement snippet = SnippetFactory.createSnippetStatement(code,
+ getNodeImpl().getFactory());
+ getNodeImpl().insertBegin(snippet);
}
@Override
- public void insertBeginImpl(AStatement statement) {
- node.insertBegin((CtStatement) statement.getNode());
+ public void insertBeginImpl(AStatement> statement) {
+ getNodeImpl().insertBegin((spoon.reflect.code.CtStatement) statement.getNodeImpl());
}
@Override
- public AJoinPoint insertBeforeImpl(String code) {
- return insertImplJBody("before", code);
+ public AJoinpoint> insertBeforeImpl(String code) {
+ return insertImplJBody(InsertPosition.BEFORE, code);
}
@Override
- public AJoinPoint insertAfterImpl(String code) {
- return insertImplJBody("after", code);
+ public AJoinpoint> insertAfterImpl(String code) {
+ return insertImplJBody(InsertPosition.AFTER, code);
}
@Override
- public AJoinPoint insertReplaceImpl(String code) {
- return insertImplJBody("replace", code);
+ public AJoinpoint> insertReplaceImpl(String code) {
+ return insertImplJBody(InsertPosition.REPLACE, code);
}
@Override
- public AStatement getLastStmtImpl() {
+ public AStatement> getLastStmtImpl() {
if (!hasStatements()) {
return null;
}
- return CtElement2JoinPoint.convert(node.getStatement(node.getStatements().size() - 1), getWeaverEngine(),
+ return CtElement2JoinPoint.convert(getNodeImpl().getStatement(getNodeImpl().getStatements().size() - 1),
+ getWeaverEngine(),
AStatement.class);
}
private boolean hasStatements() {
- return !(node == null) && !node.getStatements().isEmpty();
+ return !(getNodeImpl() == null) && !getNodeImpl().getStatements().isEmpty();
}
@Override
- public CtBlock getNode() {
- return node;
+ public CtBlock> getNodeImpl() {
+ return (CtBlock>) super.getNodeImpl();
}
@Override
- public String toString() {
+ public String getToStringImpl() {
return "";
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JBreak.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JBreak.java
index 80e79699..16a1c0ad 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JBreak.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JBreak.java
@@ -1,11 +1,11 @@
/**
* Copyright 2018 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -14,26 +14,19 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.code.CtBreak;
-import spoon.reflect.declaration.CtElement;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.ABreak;
-
-public class JBreak extends ABreak {
- private CtBreak node;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.ABreak;
- private JBreak(CtBreak node, JavaWeaver weaver) {
- super(new JStatement(node, weaver), weaver);
- this.node = node;
- }
+public class JBreak> extends ABreak {
- public static JBreak newInstance(CtBreak node, JavaWeaver weaver) {
- return new JBreak(node, weaver);
+ public JBreak(CtBreak node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtElement getNode() {
- return node;
+ public CtBreak getNodeImpl() {
+ return (CtBreak) super.getNodeImpl();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JCall.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JCall.java
index ec994cb1..77c9d13b 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JCall.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JCall.java
@@ -18,16 +18,17 @@
import java.util.Objects;
import pt.up.fe.specs.util.SpecsLogs;
+
import spoon.reflect.code.CtCodeSnippetExpression;
import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtInvocation;
import spoon.reflect.declaration.CtType;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtTypeReference;
-import weaver.kadabra.JavaWeaver;
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ACall;
import weaver.kadabra.abstracts.joinpoints.AExpression;
-import weaver.kadabra.abstracts.joinpoints.AJoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
import weaver.kadabra.abstracts.joinpoints.AMethod;
import weaver.kadabra.abstracts.joinpoints.AStatement;
import weaver.kadabra.abstracts.joinpoints.AType;
@@ -40,26 +41,19 @@
import weaver.utils.weaving.converters.CtElement2JoinPoint;
import weaver.utils.weaving.converters.CtType2AType;
-public class JCall extends ACall {
-
- private final CtInvocation node;
-
- private JCall(CtInvocation call, JavaWeaver weaver) {
- super(new JExpression<>(call, weaver), weaver);
- node = call;
- }
+public class JCall> extends ACall {
- public static JCall newInstance(CtInvocation call, JavaWeaver weaver) {
- return new JCall<>(call, weaver);
+ public JCall(CtInvocation node, JWeaver weaver) {
+ super(node, weaver);
}
/**
* If this Call is the call of a CallStatement, return CallStatement.
*/
@Override
- public AJoinPoint getParentImpl() {
- if (SpoonUtils.isStatementInBlock(node)) {
- return new JCallStatement<>(node, getWeaverEngine());
+ public AJoinpoint> getParentImpl() {
+ if (SpoonUtils.isStatementInBlock(getNodeImpl())) {
+ return new JCallStatement<>(getNodeImpl(), getWeaverEngine());
}
return super.getParentImpl();
@@ -67,18 +61,18 @@ public AJoinPoint getParentImpl() {
@Override
public String getNameImpl() {
- return node.getExecutable().getSimpleName();
+ return getNodeImpl().getExecutable().getSimpleName();
}
@Override
public String getDeclaratorImpl() {
- CtExecutableReference executable = node.getExecutable();
+ CtExecutableReference> executable = getNodeImpl().getExecutable();
return executable.getDeclaringType().getSimpleName();
}
@Override
public String getQualifiedDeclImpl() {
- String qualifiedName = node.getExecutable().getDeclaringType().getQualifiedName();
+ String qualifiedName = getNodeImpl().getExecutable().getDeclaringType().getQualifiedName();
return qualifiedName;
}
@@ -91,18 +85,18 @@ public String getSimpleDeclImpl() {
@Override
public String getExecutableImpl() {
- return node.getExecutable().getSimpleName();
+ return getNodeImpl().getExecutable().getSimpleName();
}
@Override
public String getTargetImpl() {
- var target = node.getTarget();
+ var target = getNodeImpl().getTarget();
return target != null ? String.valueOf(target) : null;
}
@Override
- public AType getTargetTypeImpl() {
- CtTypeReference> type = node.getTarget().getType();
+ public AType> getTargetTypeImpl() {
+ CtTypeReference> type = getNodeImpl().getTarget().getType();
CtType> typeDeclaration = type.getTypeDeclaration();
return CtType2AType.convert(typeDeclaration, getWeaverEngine());
}
@@ -114,8 +108,8 @@ public String getReturnTypeImpl() {
}
@Override
- public ATypeReference getReturnTypeJpImpl() {
- var executable = node.getExecutable();
+ public ATypeReference> getReturnTypeJpImpl() {
+ var executable = getNodeImpl().getExecutable();
Objects.requireNonNull(executable, () -> "Call should have an executable");
var declaringType = executable.getDeclaringType();
@@ -124,22 +118,22 @@ public ATypeReference getReturnTypeJpImpl() {
return null;
}
- return (ATypeReference) CtElement2JoinPoint.convert(declaringType, getWeaverEngine());
+ return (ATypeReference>) CtElement2JoinPoint.convert(declaringType, getWeaverEngine());
}
@Override
- public void setArgumentsImpl(AExpression[] newArguments) {
+ public void setArgumentsImpl(AExpression>[] newArguments) {
var newArgs = new ArrayList>();
for (var arg : newArguments) {
- newArgs.add((CtExpression>) arg.getNode());
+ newArgs.add((CtExpression>) arg.getNodeImpl());
}
- node.setArguments(newArgs);
+ getNodeImpl().setArguments(newArgs);
}
@Override
- public void setArgumentImpl(AExpression newArgument, Integer index) {
- var previousArgs = new ArrayList<>(getNode().getArguments());
+ public void setArgumentImpl(AExpression> newArgument, int index) {
+ var previousArgs = new ArrayList<>(getNodeImpl().getArguments());
if (index < 0 || index >= previousArgs.size()) {
SpecsLogs.info("Trying to set argument with index '" + index + "', but call only has " + previousArgs.size()
@@ -148,62 +142,61 @@ public void setArgumentImpl(AExpression newArgument, Integer index) {
}
var newArgs = new ArrayList>(previousArgs);
- newArgs.set(index, (CtExpression) newArgument.getNode());
- node.setArguments(newArgs);
+ newArgs.set(index, (CtExpression) newArgument.getNodeImpl());
+ getNodeImpl().setArguments(newArgs);
}
@Override
- public CtInvocation getNode() {
- return node;
+ public CtInvocation> getNodeImpl() {
+ return (CtInvocation>) super.getNodeImpl();
}
@Override
- public ACall setTargetImpl(String value) {
- CtCodeSnippetExpression newTarget = SnippetFactory.snippetExpression(value.toString(),
- node.getFactory());
- node.setTarget(newTarget);
+ public ACall> setTargetImpl(String value) {
+ CtCodeSnippetExpression> newTarget = SnippetFactory.snippetExpression(value.toString(),
+ getNodeImpl().getFactory());
+ getNodeImpl().setTarget(newTarget);
return this;
}
@Override
- public ACall setTargetImpl(AExpression value) {
+ public ACall> setTargetImpl(AExpression> value) {
return setTargetImpl(value.getSrcCodeImpl());
}
@Override
- public ACall setExecutableImpl(AMethod executable) {
- @SuppressWarnings("unchecked")
- JMethod method = JMethod.class.cast(executable);
- CtExecutableReference reference = method.getNode().getReference();
- node.setExecutable(reference);
+ public ACall> setExecutableImpl(AMethod> executable) {
+ var method = (JMethod>) executable;
+ CtExecutableReference> reference = method.getNodeImpl().getReference();
+ getNodeImpl().setExecutable((CtExecutableReference) reference);
return this;
}
@Override
- public ACall cloneImpl(AStatement location, String position) {
- if (!(location instanceof JStatement)) {
+ public ACall> cloneImpl(AStatement> location, String position) {
+ if (!(location instanceof JStatement>)) {
throw new JavaWeaverException("During method call cloning",
new RuntimeException("Class " + location.getClass() + " is not acceptable here"));
}
- JStatement stat = (JStatement) location;
+ JStatement> stat = (JStatement>) location;
- CtInvocation cloned = ActionUtils.cloneElement(node);
- ActionUtils.insert(position, cloned, stat.getNode(), getWeaverEngine());
- return JCall.newInstance(cloned, getWeaverEngine());
+ CtInvocation> cloned = ActionUtils.cloneElement(getNodeImpl());
+ ActionUtils.insert(position, cloned, stat.getNodeImpl(), getWeaverEngine());
+ return new JCall<>(cloned, getWeaverEngine());
}
@Override
- public AExpression[] getArgumentsArrayImpl() {
- final List exprs = SelectUtils.nodeList2JoinPointList(node.getArguments(),
+ public AExpression>[] getArgumentsImpl() {
+ final List> exprs = SelectUtils.nodeList2JoinPointList(getNodeImpl().getArguments(),
arg -> JExpression.newInstance(arg, getWeaverEngine()));
return exprs.toArray(size -> new AExpression[size]);
}
@Override
- public AMethod getDeclImpl() {
- var decl = node.getExecutable().getExecutableDeclaration();
- if (decl == null || node.getExecutable().isConstructor()) {
+ public AMethod> getDeclImpl() {
+ var decl = getNodeImpl().getExecutable().getExecutableDeclaration();
+ if (decl == null || getNodeImpl().getExecutable().isConstructor()) {
return null;
}
return CtElement2JoinPoint.convert(decl, getWeaverEngine(), AMethod.class);
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JCallStatement.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JCallStatement.java
index 78f577f7..b4d5ab72 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JCallStatement.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JCallStatement.java
@@ -14,41 +14,37 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.code.CtInvocation;
-import spoon.reflect.declaration.CtElement;
-import weaver.kadabra.JavaWeaver;
+
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ACall;
import weaver.kadabra.abstracts.joinpoints.ACallStatement;
-import weaver.kadabra.abstracts.joinpoints.AJoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
/**
* This is a "synthetic" join point, to emulate statements around single
* statement calls.
*
- * @param
* @author JoaoBispo
*/
-public class JCallStatement extends ACallStatement {
-
- private final CtInvocation call;
+public class JCallStatement> extends ACallStatement {
- public JCallStatement(CtInvocation call, JavaWeaver weaver) {
- super(new JStatement(call, weaver), weaver);
- this.call = call;
+ public JCallStatement(CtInvocation call, JWeaver weaver) {
+ super(call, weaver);
}
@Override
- public CtElement getNode() {
- return call;
+ public CtInvocation> getNodeImpl() {
+ return (CtInvocation>) super.getNodeImpl();
}
@Override
- public ACall getCallImpl() {
- return JCall.newInstance(call, getWeaverEngine());
+ public ACall> getCallImpl() {
+ return new JCall<>(getNodeImpl(), getWeaverEngine());
}
@Override
- public AJoinPoint[] getChildrenArrayImpl() {
- var children = new AJoinPoint[1];
+ public AJoinpoint>[] getChildrenImpl() {
+ var children = new AJoinpoint[1];
children[0] = getCallImpl();
return children;
}
@@ -61,7 +57,7 @@ public String getCodeImpl() {
}
/**
- * TODO: This is an example where the getSrcCodeImpl() in AJavaWeaverJoinPoint
+ * TODO: This is an example where the getSrcCodeImpl() in JJoinpoint
* does not call the overridden getCodeImpl()
*/
@Override
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JCase.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JCase.java
index 78ad956c..cb379791 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JCase.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JCase.java
@@ -1,11 +1,11 @@
/**
* Copyright 2018 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -14,43 +14,37 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.code.CtCase;
-import weaver.kadabra.JavaWeaver;
+
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ACase;
import weaver.kadabra.abstracts.joinpoints.AExpression;
import weaver.kadabra.abstracts.joinpoints.AStatement;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-public class JCase extends ACase {
-
- private final CtCase node;
-
- private JCase(CtCase node, JavaWeaver weaver) {
- super(new JStatement(node, weaver), weaver);
- this.node = node;
- }
+public class JCase> extends ACase {
- public static JCase newInstance(CtCase node, JavaWeaver weaver) {
- return new JCase<>(node, weaver);
+ public JCase(CtCase node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtCase getNode() {
- return node;
+ public CtCase> getNodeImpl() {
+ return (CtCase>) super.getNodeImpl();
}
@Override
- public Boolean getIsDefaultImpl() {
- return node.getCaseExpression() == null;
+ public boolean getIsDefaultImpl() {
+ return getNodeImpl().getCaseExpression() == null;
}
@Override
- public AStatement[] getStmtsArrayImpl() {
- return CtElement2JoinPoint.convertList(node.getStatements(), getWeaverEngine(), AStatement.class);
+ public AStatement>[] getStmtsImpl() {
+ return CtElement2JoinPoint.convertList(getNodeImpl().getStatements(), getWeaverEngine(), AStatement.class);
}
@Override
- public AExpression getExprImpl() {
- return CtElement2JoinPoint.convert(node.getCaseExpression(), getWeaverEngine(), AExpression.class);
+ public AExpression> getExprImpl() {
+ return CtElement2JoinPoint.convert(getNodeImpl().getCaseExpression(), getWeaverEngine(), AExpression.class);
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JCatch.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JCatch.java
index 2fefac6c..8f9e494f 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JCatch.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JCatch.java
@@ -1,29 +1,26 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.code.CtCatch;
-import spoon.reflect.declaration.CtElement;
-import weaver.kadabra.JavaWeaver;
+
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ABody;
import weaver.kadabra.abstracts.joinpoints.ACatch;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-public class JCatch extends ACatch {
-
- private final CtCatch node;
+public class JCatch> extends ACatch {
- public JCatch(CtCatch node, JavaWeaver weaver) {
- super(weaver);
- this.node = node;
+ public JCatch(CtCatch node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtElement getNode() {
- return node;
+ public CtCatch getNodeImpl() {
+ return (CtCatch) super.getNodeImpl();
}
@Override
- public ABody getBodyImpl() {
- return CtElement2JoinPoint.convert(node.getBody(), getWeaverEngine(), ABody.class);
+ public ABody> getBodyImpl() {
+ return CtElement2JoinPoint.convert(getNodeImpl().getBody(), getWeaverEngine(), ABody.class);
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JClass.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JClass.java
index cc23b2df..065a4c2e 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JClass.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JClass.java
@@ -13,14 +13,34 @@
package weaver.kadabra.joinpoints;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import spoon.reflect.code.CtBlock;
import spoon.reflect.code.CtCodeSnippetStatement;
import spoon.reflect.cu.CompilationUnit;
-import spoon.reflect.declaration.*;
+import spoon.reflect.declaration.CtAnonymousExecutable;
+import spoon.reflect.declaration.CtClass;
+import spoon.reflect.declaration.CtConstructor;
+import spoon.reflect.declaration.CtCompilationUnit;
+import spoon.reflect.declaration.CtElement;
+import spoon.reflect.declaration.CtInterface;
+import spoon.reflect.declaration.CtMethod;
+import spoon.reflect.declaration.CtPackage;
+import spoon.reflect.declaration.CtParameter;
+import spoon.reflect.declaration.CtType;
+import spoon.reflect.declaration.ModifierKind;
import spoon.reflect.factory.Factory;
import spoon.reflect.reference.CtTypeReference;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.*;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AClass;
+import weaver.kadabra.abstracts.joinpoints.AConstructor;
+import weaver.kadabra.abstracts.joinpoints.AInterfaceType;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
+import weaver.kadabra.abstracts.joinpoints.AMethod;
import weaver.utils.generators.FunctionalClassGenerator;
import weaver.utils.generators.MapGenerator;
import weaver.utils.weaving.ActionUtils;
@@ -28,62 +48,54 @@
import weaver.utils.weaving.SnippetFactory;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-import java.util.*;
-
-public class JClass extends AClass {
+public class JClass> extends AClass {
- private final CtClass originClass;
private final CtCompilationUnit parent;
- private JClass(CtClass node, CtCompilationUnit parent, JavaWeaver weaver) {
- super(JType.newInstance(node, parent, weaver), weaver);
- this.originClass = node;
- this.parent = parent;
- }
-
- @Override
- public String toString() {
- return originClass.getQualifiedName();
+ public JClass(CtClass node, JWeaver weaver) {
+ this(node, node.getPosition().getCompilationUnit(), weaver);
}
- public static JClass newInstance(CtClass node, CtCompilationUnit parent, JavaWeaver weaver) {
- return new JClass<>(node, parent, weaver);
+ public JClass(CtClass node, CtCompilationUnit parent, JWeaver weaver) {
+ super(node, weaver);
+ this.parent = parent;
}
- public static JClass newInstance(CtClass node, JavaWeaver weaver) {
- return new JClass<>(node, node.getPosition().getCompilationUnit(), weaver);
+ @Override
+ public String getToStringImpl() {
+ return getNodeImpl().getQualifiedName();
}
@Override
- public CtClass getNode() {
- return originClass;
+ public CtClass> getNodeImpl() {
+ return (CtClass>) super.getNodeImpl();
}
@Override
public void insertStaticImpl(String code) {
- Factory factory = originClass.getFactory();
+ Factory factory = getNodeImpl().getFactory();
CtCodeSnippetStatement snippetStmt = SnippetFactory.createSnippetStatement(code, factory);
CtBlock newBlock = factory.Core().createBlock();
newBlock.addStatement(snippetStmt);
- CtAnonymousExecutable createAnonymous = factory.Method().createAnonymous(originClass, newBlock);
+ CtAnonymousExecutable createAnonymous = factory.Method().createAnonymous(getNodeImpl(), newBlock);
createAnonymous.addModifier(ModifierKind.STATIC);
}
@Override
- public AClass mapVersionsImpl(String name, String keyType, AInterfaceType _interface, String methodName) {
+ public AClass> mapVersionsImpl(String name, String keyType, AInterfaceType> _interface, String methodName) {
- CtClass> generate = MapGenerator.generate(originClass.getFactory(), name, keyType, _interface, methodName);
- originClass.addNestedType(generate);
+ CtClass> generate = MapGenerator.generate(getNodeImpl().getFactory(), name, keyType, _interface, methodName);
+ getNodeImpl().addNestedType(generate);
JClass> jClass = new JClass<>(generate, parent, getWeaverEngine());
return jClass;
}
@Override
- public AInterfaceType extractInterfaceImpl(String name, String _package, AMethod method, boolean associate,
+ public AInterfaceType> extractInterfaceImpl(String name, String _package, AMethod> method, boolean associate,
boolean newFile) {
- Factory factory = originClass.getFactory();
+ Factory factory = getNodeImpl().getFactory();
// First create the interface
Collection compilationUnits = factory.CompilationUnit().getMap().values();
@@ -102,33 +114,31 @@ public AInterfaceType extractInterfaceImpl(String name, String _package, AMethod
}
String qualifiedName = _package.isEmpty() ? name : _package + "." + name;
- final CtInterface newInterface;
+ final CtInterface> newInterface;
if (newFile) {
newInterface = ActionUtils.compilationUnitWithInterface(qualifiedName, null,
parent.getFile().getParentFile(), factory);
} else {
- newInterface = ActionUtils.newInterface(name, null, originClass.getFactory());
+ newInterface = ActionUtils.newInterface(name, null, getNodeImpl().getFactory());
}
if (associate) {
- originClass.addSuperInterface(newInterface.getReference());
+ getNodeImpl().addSuperInterface(newInterface.getReference());
}
// Then add the method signature
final JMethod> jMethod = (JMethod>) method;
- final CtMethod> ctMethod = jMethod.getNode();
- // To be replaced in Spoon 5.0 with: create(newInterface, ctMethod, true);
- // newMethod.setBody(null);
+ final CtMethod> ctMethod = jMethod.getNodeImpl();
final CtMethod> newMethod = copyMethod(newInterface, ctMethod, factory);
newMethod.removeModifier(ModifierKind.STATIC); // methods in interfaces are non-static!
newMethod.removeModifier(ModifierKind.PRIVATE); // we want this method to be public
newMethod.addModifier(ModifierKind.PUBLIC);
newMethod.setParent(newInterface);
- JInterfaceType> newInstance = JInterfaceType.newInstance(newInterface, getWeaverEngine());
+ JInterfaceType> newInstance = new JInterfaceType<>(newInterface, getWeaverEngine());
return newInstance;
}
- private static CtMethod> copyMethod(CtInterface newInterface, CtMethod> ctMethod, Factory factory) {
+ private static CtMethod> copyMethod(CtInterface> newInterface, CtMethod> ctMethod, Factory factory) {
Set modifiers = new HashSet<>(ctMethod.getModifiers());
Set> thrownTypes = new HashSet<>(ctMethod.getThrownTypes());
List> parameters = new ArrayList<>(ctMethod.getParameters());
@@ -138,37 +148,37 @@ private static CtMethod> copyMethod(CtInterface newInterface, CtMethod
}
@Override
- public AMethod newFunctionalClassImpl(AMethod interfaceMethod, AMethod generatorMethod) {
+ public AMethod> newFunctionalClassImpl(AMethod> interfaceMethod, AMethod> generatorMethod) {
JMethod> iMethod = (JMethod>) interfaceMethod;
- CtMethod> iMethodNode = iMethod.getNode();
+ CtMethod> iMethodNode = iMethod.getNodeImpl();
JMethod> gMethod = (JMethod>) generatorMethod;
- CtMethod> gMethodNode = gMethod.getNode();
+ CtMethod> gMethodNode = gMethod.getNodeImpl();
JMethod> jMethod = FunctionalClassGenerator.generate(getWeaverEngine(), iMethodNode, gMethodNode,
- this.originClass);
+ getNodeImpl());
return jMethod;
}
@Override
- public AConstructor newConstructorImpl(String[] modifiers, String[] paramLeft, String[] paramRight) {
- CtConstructor> newConstructor = ActionUtils.newConstructor(originClass, paramLeft, paramRight, modifiers);
+ public AConstructor> newConstructorImpl(String[] modifiers, String[] paramLeft, String[] paramRight) {
+ CtConstructor> newConstructor = ActionUtils.newConstructor(getNodeImpl(), paramLeft, paramRight, modifiers);
JConstructor> newInstance = SelectUtils.node2JoinPoint(newConstructor,
- (node -> JConstructor.newInstance(node, getWeaverEngine())));
+ (node -> new JConstructor<>(node, getWeaverEngine())));
return newInstance;
}
@Override
- public AJoinPoint getParentImpl() {
- var spoonParent = getNode().getParent();
+ public AJoinpoint> getParentImpl() {
+ var spoonParent = getNodeImpl().getParent();
if (spoonParent != null && !(spoonParent instanceof CtPackage)) {
return CtElement2JoinPoint.convert(spoonParent, getWeaverEngine());
}
- return new JFile(parent, getWeaverEngine());
+ return new JFile<>(parent, getWeaverEngine());
}
@Override
- public Boolean getIsTopLevelImpl() {
- return originClass.isTopLevel();
+ public boolean getIsTopLevelImpl() {
+ return getNodeImpl().isTopLevel();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JComment.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JComment.java
index 332eb7f3..a7259ef3 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JComment.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JComment.java
@@ -1,11 +1,11 @@
/**
* Copyright 2017 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -13,63 +13,57 @@
package weaver.kadabra.joinpoints;
+import org.lara.interpreter.weaver.interf.enums.InsertPosition;
+
import spoon.reflect.code.CtComment;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.AJavaWeaverJoinPoint;
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.AComment;
-import weaver.kadabra.abstracts.joinpoints.AJoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
import weaver.kadabra.enums.CommentType;
import weaver.utils.weaving.ActionUtils;
-public class JComment extends AComment {
-
- private final CtComment comment;
-
- private JComment(CtComment comment, JavaWeaver weaver) {
- super(new JStatement(comment, weaver), weaver);
- this.comment = comment;
- }
+public class JComment> extends AComment {
- public static JComment newInstance(CtComment comment, JavaWeaver weaver) {
- return new JComment(comment, weaver);
+ public JComment(CtComment comment, JWeaver weaver) {
+ super(comment, weaver);
}
@Override
- public String getTypeImpl() {
- return CommentType.valueOf(comment.getCommentType().name()).getName();
+ public CommentType getTypeImpl() {
+ return CommentType.valueOf(getNodeImpl().getCommentType().name());
}
@Override
public String getContentImpl() {
- return comment.getContent();
+ return getNodeImpl().getContent();
}
@Override
- public CtComment getNode() {
- return comment;
+ public CtComment getNodeImpl() {
+ return (CtComment) super.getNodeImpl();
}
@Override
- public AJoinPoint[] insertImpl(String position, String code) {
- return new AJoinPoint[] { insertImplJComment(position, code) };
+ public AJoinpoint>[] insertImpl(InsertPosition position, String code) {
+ return new AJoinpoint>[] { insertImplJComment(position, code) };
}
- public AJavaWeaverJoinPoint insertImplJComment(String position, String code) {
- return ActionUtils.insertInTable(comment, code, position, getWeaverEngine());
+ public AJoinpoint> insertImplJComment(InsertPosition position, String code) {
+ return ActionUtils.insertInTable(getNodeImpl(), code, position.name().toLowerCase(), getWeaverEngine());
}
@Override
- public AJoinPoint insertBeforeImpl(String code) {
- return insertImplJComment("before", code);
+ public AJoinpoint> insertBeforeImpl(String code) {
+ return insertImplJComment(InsertPosition.BEFORE, code);
}
@Override
- public AJoinPoint insertAfterImpl(String code) {
- return insertImplJComment("after", code);
+ public AJoinpoint> insertAfterImpl(String code) {
+ return insertImplJComment(InsertPosition.AFTER, code);
}
@Override
- public AJoinPoint insertReplaceImpl(String code) {
- return insertImplJComment("replace", code);
+ public AJoinpoint> insertReplaceImpl(String code) {
+ return insertImplJComment(InsertPosition.REPLACE, code);
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JConstructor.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JConstructor.java
index 5a43c85c..a74517e7 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JConstructor.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JConstructor.java
@@ -1,11 +1,11 @@
/**
* Copyright 2016 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -14,35 +14,29 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.declaration.CtConstructor;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.AConstructor;
-
-public class JConstructor extends AConstructor {
- private final CtConstructor node;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AConstructor;
- private JConstructor(CtConstructor node, JavaWeaver weaver) {
- super(JExecutable.newInstance(node, weaver), weaver);
- this.node = node;
- }
+public class JConstructor> extends AConstructor {
- public static JConstructor newInstance(CtConstructor node, JavaWeaver weaver) {
- return new JConstructor<>(node, weaver);
+ public JConstructor(CtConstructor node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtConstructor> getNode() {
- return node;
+ public CtConstructor> getNodeImpl() {
+ return (CtConstructor>) super.getNodeImpl();
}
@Override
public String getDeclaratorImpl() {
- return node.getDeclaringType().getQualifiedName();
+ return getNodeImpl().getDeclaringType().getQualifiedName();
}
@Override
- public String toString() {
- return node.getSignature();
+ public String getToStringImpl() {
+ return getNodeImpl().getSignature();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JContinue.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JContinue.java
index 4ab87bc6..bccbf56c 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JContinue.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JContinue.java
@@ -1,11 +1,11 @@
/**
* Copyright 2018 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -14,26 +14,19 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.code.CtContinue;
-import spoon.reflect.declaration.CtElement;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.AContinue;
-
-public class JContinue extends AContinue {
- private CtContinue node;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AContinue;
- private JContinue(CtContinue node, JavaWeaver weaver) {
- super(new JStatement(node, weaver), weaver);
- this.node = node;
- }
+public class JContinue> extends AContinue {
- public static JContinue newInstance(CtContinue node, JavaWeaver weaver) {
- return new JContinue(node, weaver);
+ public JContinue(CtContinue node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtElement getNode() {
- return node;
+ public CtContinue getNodeImpl() {
+ return (CtContinue) super.getNodeImpl();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JDeclaration.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JDeclaration.java
index 32da974b..f4d37052 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JDeclaration.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JDeclaration.java
@@ -1,11 +1,11 @@
/**
* Copyright 2015 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -13,10 +13,10 @@
package weaver.kadabra.joinpoints;
-import spoon.reflect.code.CtExpression;
import spoon.reflect.declaration.CtVariable;
import spoon.reflect.reference.CtTypeReference;
-import weaver.kadabra.JavaWeaver;
+
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ADeclaration;
import weaver.kadabra.abstracts.joinpoints.AExpression;
import weaver.kadabra.abstracts.joinpoints.ATypeReference;
@@ -24,27 +24,20 @@
import weaver.utils.weaving.TypeUtils;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-public class JDeclaration extends ADeclaration {
-
- protected CtVariable node;
-
- private JDeclaration(CtVariable node, JavaWeaver weaver) {
- super(weaver);
- this.node = node;
- }
+public class JDeclaration> extends ADeclaration {
- public static JDeclaration newInstance(CtVariable node, JavaWeaver weaver) {
- return new JDeclaration<>(node, weaver);
+ public JDeclaration(CtVariable node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
public String getNameImpl() {
- return node.getSimpleName();
+ return getNodeImpl().getSimpleName();
}
@Override
- public ATypeReference getTypeReferenceImpl() {
- CtTypeReference> type2 = node.getType();
+ public ATypeReference> getTypeReferenceImpl() {
+ CtTypeReference> type2 = getNodeImpl().getType();
return type2 != null ? new JTypeReference<>(type2, getWeaverEngine()) : null;
}
@@ -55,33 +48,33 @@ public String getTypeImpl() {
}
@Override
- public Boolean getIsArrayImpl() {
- return CtTypeReferenceUtils.getIsArray(node.getType());
+ public boolean getIsArrayImpl() {
+ return CtTypeReferenceUtils.getIsArray(getNodeImpl().getType());
}
@Override
- public Boolean getIsPrimitiveImpl() {
- return CtTypeReferenceUtils.getIsPrimitive(node.getType());
+ public boolean getIsPrimitiveImpl() {
+ return CtTypeReferenceUtils.getIsPrimitive(getNodeImpl().getType());
}
@Override
- public CtVariable getNode() {
- return node;
+ public CtVariable> getNodeImpl() {
+ return (CtVariable>) super.getNodeImpl();
}
@Override
public String getCompleteTypeImpl() {
- return TypeUtils.getTypeString(node.getType());
+ return TypeUtils.getTypeString(getNodeImpl().getType());
}
@Override
- public String toString() {
+ public String getToStringImpl() {
return getNameImpl();
}
@Override
- public AExpression getInitImpl() {
- var init = node.getDefaultExpression();
+ public AExpression> getInitImpl() {
+ var init = getNodeImpl().getDefaultExpression();
if (init == null) {
return null;
}
@@ -90,13 +83,13 @@ public AExpression getInitImpl() {
}
@Override
- @SuppressWarnings("unchecked")
- public void setInitImpl(AExpression value) {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void setInitImpl(AExpression> value) {
if (value == null) {
- node.setDefaultExpression(null);
+ getNodeImpl().setDefaultExpression(null);
return;
}
- node.setDefaultExpression((CtExpression) value.getNode());
+ ((CtVariable) getNodeImpl()).setDefaultExpression((spoon.reflect.code.CtExpression) value.getNodeImpl());
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JEnumValue.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JEnumValue.java
index 36af6a7d..650d0b33 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JEnumValue.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JEnumValue.java
@@ -1,27 +1,32 @@
+/**
+ * Copyright 2015 SPeCS.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
package weaver.kadabra.joinpoints;
-import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtEnumValue;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.joinpoints.AEnumValue;
-
-public class JEnumValue extends AEnumValue {
- private final CtEnumValue node;
-
- public JEnumValue(CtEnumValue node, JavaWeaver weaver) {
- super(new JField<>(node, weaver), weaver);
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AEnumValue;
- this.node = node;
- }
+public class JEnumValue> extends AEnumValue {
- public static JEnumValue newInstance(CtEnumValue field, JavaWeaver weaver) {
- return new JEnumValue<>(field, weaver);
+ public JEnumValue(CtEnumValue node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtElement getNode() {
- return node;
+ public CtEnumValue> getNodeImpl() {
+ return (CtEnumValue>) super.getNodeImpl();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JExecutable.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JExecutable.java
index 63ed9187..04ec5fec 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JExecutable.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JExecutable.java
@@ -1,11 +1,11 @@
/**
* Copyright 2017 SPeCS.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -13,17 +13,16 @@
package weaver.kadabra.joinpoints;
-import org.lara.interpreter.weaver.interf.JoinPoint;
+import org.lara.interpreter.weaver.interf.enums.InsertPosition;
import spoon.reflect.code.CtBlock;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.factory.Factory;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.AJavaWeaverJoinPoint;
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.ABody;
import weaver.kadabra.abstracts.joinpoints.ADeclaration;
import weaver.kadabra.abstracts.joinpoints.AExecutable;
-import weaver.kadabra.abstracts.joinpoints.AJoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
import weaver.kadabra.abstracts.joinpoints.ATypeReference;
import weaver.kadabra.spoon.extensions.nodes.CtKadabraSnippetElement;
import weaver.utils.weaving.ActionUtils;
@@ -31,39 +30,32 @@
import weaver.utils.weaving.SnippetFactory;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-public class JExecutable extends AExecutable {
+public class JExecutable> extends AExecutable {
- private CtExecutable node;
-
- private JExecutable(CtExecutable node, JavaWeaver weaver) {
- super(weaver);
- this.node = node;
- }
-
- public static JExecutable newInstance(CtExecutable node, JavaWeaver weaver) {
- return new JExecutable<>(node, weaver);
+ public JExecutable(CtExecutable node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
public String getNameImpl() {
- return node.getSimpleName().toString();
+ return getNodeImpl().getSimpleName().toString();
}
@Override
public String setNameImpl(String name) {
- var currentName = node.getSimpleName();
- node.setSimpleName(name);
+ var currentName = getNodeImpl().getSimpleName();
+ getNodeImpl().setSimpleName(name);
return currentName;
}
@Override
public String getReturnTypeImpl() {
- return node.getType().getSimpleName();
+ return getNodeImpl().getType().getSimpleName();
}
@Override
- public ABody getBodyImpl() {
- final CtBlock> body = node.getBody();
+ public ABody> getBodyImpl() {
+ final CtBlock> body = getNodeImpl().getBody();
if (body == null) {
return null;
}
@@ -72,48 +64,49 @@ public ABody getBodyImpl() {
}
@Override
- public CtExecutable getNode() {
- return node;
+ public CtExecutable> getNodeImpl() {
+ return (CtExecutable>) super.getNodeImpl();
}
@Override
- public String toString() {
- return node.getSignature();
+ public String getToStringImpl() {
+ return getNodeImpl().getSignature();
}
@Override
- public ADeclaration[] getParamsArrayImpl() {
+ public ADeclaration>[] getParamsImpl() {
return SelectUtils
- .nodeList2JoinPointList(node.getParameters(),
- (node -> JDeclaration.newInstance(node, getWeaverEngine())))
+ .nodeList2JoinPointList(getNodeImpl().getParameters(),
+ (node -> new JDeclaration<>(node, getWeaverEngine())))
.toArray(length -> new ADeclaration[0]);
}
@Override
- public ATypeReference getReturnRefImpl() {
- return (ATypeReference) CtElement2JoinPoint.convert(node.getType(), getWeaverEngine());
+ public ATypeReference> getReturnRefImpl() {
+ return (ATypeReference>) CtElement2JoinPoint.convert(getNodeImpl().getType(), getWeaverEngine());
}
@Override
- public AJoinPoint[] insertImpl(String position, String code) {
- return new AJoinPoint[] { insertImplExecutable(position, code) };
+ public AJoinpoint>[] insertImpl(InsertPosition position, String code) {
+ return new AJoinpoint>[] { insertImplExecutable(position, code) };
}
@Override
- public AJoinPoint[] insertImpl(String position, JoinPoint code) {
- return new AJoinPoint[] { insertImplExecutable(position, (AJoinPoint) code) };
+ public AJoinpoint>[] insertImpl(InsertPosition position, AJoinpoint> code) {
+ return new AJoinpoint>[] { insertImplExecutable(position, code) };
}
- public AJavaWeaverJoinPoint insertImplExecutable(String position, String code) {
- Factory factory = getNode().getFactory();
+ public AJoinpoint> insertImplExecutable(InsertPosition position, String code) {
+ Factory factory = getNodeImpl().getFactory();
CtKadabraSnippetElement snippet = SnippetFactory.createSnippetElement(factory, code);
- return ActionUtils.insertMember(node, snippet, position, getWeaverEngine());
+ return ActionUtils.insertMember(getNodeImpl(), snippet, position.name().toLowerCase(), getWeaverEngine());
}
- public AJavaWeaverJoinPoint insertImplExecutable(String position, AJoinPoint code) {
- return ActionUtils.insertMember(node, code.getNode(), position, getWeaverEngine());
+ public AJoinpoint> insertImplExecutable(InsertPosition position, AJoinpoint> code) {
+ return ActionUtils.insertMember(getNodeImpl(), code.getNodeImpl(), position.name().toLowerCase(),
+ getWeaverEngine());
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JExpression.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JExpression.java
index a93bf504..cf6bcaf6 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JExpression.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JExpression.java
@@ -13,49 +13,48 @@
package weaver.kadabra.joinpoints;
-import org.lara.interpreter.weaver.interf.JoinPoint;
-import spoon.reflect.code.*;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.AJavaWeaverJoinPoint;
-import weaver.kadabra.abstracts.joinpoints.*;
+import java.util.Optional;
+
+import org.lara.interpreter.weaver.interf.enums.InsertPosition;
+
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AExpression;
+import weaver.kadabra.abstracts.joinpoints.AStatement;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
+import weaver.kadabra.abstracts.joinpoints.ATypeReference;
import weaver.kadabra.exceptions.JavaWeaverException;
import weaver.kadabra.util.KadabraLog;
import weaver.utils.SpoonUtils;
import weaver.utils.weaving.ActionUtils;
import weaver.utils.weaving.converters.CtExpression2AExpression;
-import java.util.Optional;
-
-public class JExpression extends AExpression {
+public class JExpression> extends AExpression {
- CtExpression node;
- Integer test = 10;
+ int test = 10;
- public JExpression(CtExpression expr, JavaWeaver weaver) {
- super(weaver);
- node = expr;
+ public JExpression(spoon.reflect.code.CtExpression expr, JWeaver weaver) {
+ super(expr, weaver);
}
@Override
- public Integer getTestImpl() {
- return test;
+ public String getToStringImpl() {
+ if (getClass() == JExpression.class) {
+ return getNodeImpl().toString() + " - " + getNodeImpl().getClass().getSimpleName();
+ }
+ return super.getToStringImpl();
}
@Override
- public String toString() {
- return super.toString() + " - " + node.getClass().getSimpleName();
- }
-
- public static AExpression newInstanceDefault(CtExpression expr, JavaWeaver weaver) {
- return new JExpression<>(expr, weaver);
+ public int getTestImpl() {
+ return test;
}
- public static AExpression newInstance(CtExpression expr, JavaWeaver weaver) {
+ public static AExpression> newInstance(spoon.reflect.code.CtExpression> expr, JWeaver weaver) {
return CtExpression2AExpression.convertToExpression(expr, weaver);
}
@Override
- public void setTestImpl(AExpression value) {
+ public void setTestImpl(AExpression> value) {
setTestImpl(value.getLineImpl());
}
@@ -70,22 +69,22 @@ public String getKindImpl() {
}
@Override
- public ATypeReference getTypeReferenceImpl() {
- var children = getChildrenArrayImpl();
+ public ATypeReference> getTypeReferenceImpl() {
+ var children = getChildrenImpl();
if (children.length > 0) {
var firstChild = children[0];
// First child should be a TypeReference
- if (firstChild instanceof ATypeReference) {
- return (ATypeReference) firstChild;
+ if (firstChild instanceof ATypeReference> typeReference) {
+ return typeReference;
}
}
// Fallback
- var type = node.getType();
+ var type = getNodeImpl().getType();
if (type == null) {
- KadabraLog.info("Currrent expression, of join point type '" + getJoinPointType()
+ KadabraLog.info("Currrent expression, of join point type '" + get_class()
+ "', does not have a type defined: '" + getCodeImpl() + "'");
return null;
}
@@ -113,83 +112,85 @@ public String getQualifiedTypeImpl() {
}
@Override
- public void extractImpl(String varName, AStatement location, String position) {
+ public void extractImpl(String varName, AStatement> location, String position) {
- Optional targetO = getTarget(location);
+ Optional targetO = getTarget(location);
if (!targetO.isPresent()) {
throw new JavaWeaverException("Could not get the target location");
}
- targetO.ifPresent(t -> SpoonUtils.extract(node, varName, t, position, getWeaverEngine()));
+ targetO.ifPresent(t -> SpoonUtils.extract(getNodeImpl(), varName, t, position, getWeaverEngine()));
}
- private Optional getTarget(AStatement location) {
+ private Optional getTarget(AStatement> location) {
if (location == null) {
- return SpoonUtils.getAncestorIncludeSelf(node, CtStatement.class);
+ return SpoonUtils.getAncestorIncludeSelf(getNodeImpl(), spoon.reflect.code.CtStatement.class);
}
- Object stmt = location.getNode();
- if (stmt instanceof CtStatement) {
- return Optional.of((CtStatement) stmt);
+ Object stmt = location.getNodeImpl();
+ if (stmt instanceof spoon.reflect.code.CtStatement) {
+ return Optional.of((spoon.reflect.code.CtStatement) stmt);
}
return Optional.empty();
}
@Override
- public CtExpression getNode() {
- return node;
+ public spoon.reflect.code.CtExpression> getNodeImpl() {
+ return (spoon.reflect.code.CtExpression>) super.getNodeImpl();
}
@Override
- public AJoinPoint[] insertImpl(String position, String code) {
- return new AJoinPoint[] { insertImplJExpression(position, code) };
+ public AJoinpoint>[] insertImpl(InsertPosition position, String code) {
+ return new AJoinpoint>[] { insertImplJExpression(position, code) };
}
- public AJavaWeaverJoinPoint insertImplJExpression(String position, String code) {
- if (position.equals("replace") || position.equals("around")) {
- return ActionUtils.replaceExpression(position, code, node, getWeaverEngine());
+ public AJoinpoint> insertImplJExpression(InsertPosition position, String code) {
+ if (position == InsertPosition.REPLACE) {
+ return ActionUtils.replaceExpression(position.name().toLowerCase(), code, getNodeImpl(),
+ getWeaverEngine());
} else {
- return ActionUtils.insert(position, code, node, getWeaverEngine());
+ return ActionUtils.insert(position.name().toLowerCase(), code, getNodeImpl(), getWeaverEngine());
}
}
@Override
- public AJoinPoint[] insertImpl(String position, JoinPoint JoinPoint) {
- return new AJoinPoint[] { insertImplJExpression(position, (AJavaWeaverJoinPoint) JoinPoint) };
+ public AJoinpoint>[] insertImpl(InsertPosition position, AJoinpoint> joinPoint) {
+ return new AJoinpoint>[] { insertImplJExpression(position, joinPoint) };
}
- public AJavaWeaverJoinPoint insertImplJExpression(String position, AJavaWeaverJoinPoint joinPoint) {
- var ctElement = joinPoint.getNode();
+ public AJoinpoint> insertImplJExpression(InsertPosition position, AJoinpoint> joinPoint) {
+ var ctElement = joinPoint.getNodeImpl();
- if (position.equals("replace") || position.equals("around")) {
- if (!(ctElement instanceof CtExpression>)) {
- KadabraLog.info("Cannot replace a join point of type " + joinPoint.getJoinPointType()
+ if (position == InsertPosition.REPLACE) {
+ if (!(ctElement instanceof spoon.reflect.code.CtExpression>)) {
+ KadabraLog.info("Cannot replace a join point of type " + joinPoint.get_class()
+ " inside an expression, it has to be another expression");
return null;
}
- CtExpression> expression = (CtExpression>) ctElement;
+ spoon.reflect.code.CtExpression> expression = (spoon.reflect.code.CtExpression>) ctElement;
- return ActionUtils.replaceExpression(position, expression, node, getWeaverEngine());
+ return ActionUtils.replaceExpression(position.name().toLowerCase(), expression, getNodeImpl(),
+ getWeaverEngine());
} else {
- return ActionUtils.insert(position, ctElement, node, getWeaverEngine());
+ return ActionUtils.insert(position.name().toLowerCase(), ctElement, getNodeImpl(), getWeaverEngine());
}
}
@Override
- public AJoinPoint insertBeforeImpl(String code) {
- return insertImplJExpression("before", code);
+ public AJoinpoint> insertBeforeImpl(String code) {
+ return insertImplJExpression(InsertPosition.BEFORE, code);
}
@Override
- public AJoinPoint insertAfterImpl(String code) {
- return insertImplJExpression("after", code);
+ public AJoinpoint> insertAfterImpl(String code) {
+ return insertImplJExpression(InsertPosition.AFTER, code);
}
@Override
- public AJoinPoint insertReplaceImpl(String code) {
- return insertImplJExpression("replace", code);
+ public AJoinpoint> insertReplaceImpl(String code) {
+ return insertImplJExpression(InsertPosition.REPLACE, code);
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JField.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JField.java
index 051b919e..9c2d5093 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JField.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JField.java
@@ -1,11 +1,11 @@
/**
* Copyright 2015 SPeCS Research Group.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
@@ -13,70 +13,62 @@
package weaver.kadabra.joinpoints;
-import org.lara.interpreter.weaver.interf.JoinPoint;
+import org.lara.interpreter.weaver.interf.enums.InsertPosition;
-import spoon.reflect.declaration.CtElement;
import spoon.reflect.declaration.CtField;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.AJavaWeaverJoinPoint;
+
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.AField;
-import weaver.kadabra.abstracts.joinpoints.AJoinPoint;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
import weaver.utils.weaving.ActionUtils;
-public class JField extends AField {
-
- private final CtField node;
-
- JField(CtField field, JavaWeaver weaver) {
- super(JDeclaration.newInstance(field, weaver), weaver);
- node = field;
- }
+public class JField> extends AField {
- public static JField newInstance(CtField field, JavaWeaver weaver) {
- return new JField<>(field, weaver);
+ public JField(CtField node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtField> getNode() {
- return node;
+ public CtField> getNodeImpl() {
+ return (CtField>) super.getNodeImpl();
}
@Override
public String getDeclaratorImpl() {
- return node.getDeclaringType().getQualifiedName();
+ return getNodeImpl().getDeclaringType().getQualifiedName();
}
@Override
- public AJoinPoint[] insertImpl(String position, JoinPoint code) {
- return new AJoinPoint[] { insertImplJField(position, (CtElement) code.getNode()) };
+ public AJoinpoint>[] insertImpl(InsertPosition position, AJoinpoint> code) {
+ return new AJoinpoint>[] { insertImplJField(position, code.getNodeImpl()) };
}
@Override
- public AJoinPoint[] insertImpl(String position, String code) {
- return new AJoinPoint[] { insertImplJField(position, code) };
+ public AJoinpoint>[] insertImpl(InsertPosition position, String code) {
+ return new AJoinpoint>[] { insertImplJField(position, code) };
}
- public AJavaWeaverJoinPoint insertImplJField(String position, CtElement code) {
- return ActionUtils.insertMember(node, code, position, getWeaverEngine());
+ public AJoinpoint> insertImplJField(InsertPosition position, spoon.reflect.declaration.CtElement code) {
+ return ActionUtils.insertMember(getNodeImpl(), code, position.name().toLowerCase(), getWeaverEngine());
}
- public AJavaWeaverJoinPoint insertImplJField(String position, String code) {
- return ActionUtils.insertMember(node, code, position, getWeaverEngine());
+ public AJoinpoint> insertImplJField(InsertPosition position, String code) {
+ return ActionUtils.insertMember(getNodeImpl(), code, position.name().toLowerCase(), getWeaverEngine());
}
@Override
- public AJoinPoint insertBeforeImpl(String code) {
- return insertImplJField("before", code);
+ public AJoinpoint> insertBeforeImpl(String code) {
+ return insertImplJField(InsertPosition.BEFORE, code);
}
@Override
- public AJoinPoint insertAfterImpl(String code) {
- return insertImplJField("after", code);
+ public AJoinpoint> insertAfterImpl(String code) {
+ return insertImplJField(InsertPosition.AFTER, code);
}
@Override
- public AJoinPoint insertReplaceImpl(String code) {
- return insertImplJField("replace", code);
+ public AJoinpoint> insertReplaceImpl(String code) {
+ return insertImplJField(InsertPosition.REPLACE, code);
}
@Override
@@ -85,7 +77,7 @@ public String getStaticAccessImpl() {
}
@Override
- public String toString() {
+ public String getToStringImpl() {
return getNameImpl();
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JFieldAccess.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JFieldAccess.java
index 897462a3..f4fdc844 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JFieldAccess.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JFieldAccess.java
@@ -14,32 +14,25 @@
package weaver.kadabra.joinpoints;
import spoon.reflect.code.CtFieldAccess;
-import spoon.reflect.declaration.CtElement;
+
+import weaver.kadabra.JWeaver;
import weaver.kadabra.abstracts.joinpoints.AExpression;
-import weaver.kadabra.JavaWeaver;
import weaver.kadabra.abstracts.joinpoints.AFieldAccess;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-public class JFieldAccess extends AFieldAccess {
-
- private final CtFieldAccess node;
-
- protected JFieldAccess(CtFieldAccess var, JavaWeaver weaver) {
- super(new JVar<>(var, weaver), weaver);
- node = var;
- }
+public class JFieldAccess> extends AFieldAccess {
- public static JFieldAccess newInstance(CtFieldAccess var, JavaWeaver weaver) {
- return new JFieldAccess<>(var, weaver);
+ public JFieldAccess(CtFieldAccess node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
- public CtElement getNode() {
- return node;
+ public CtFieldAccess> getNodeImpl() {
+ return (CtFieldAccess>) super.getNodeImpl();
}
@Override
- public AExpression getBaseImpl() {
- return CtElement2JoinPoint.convert(node.getTarget(), getWeaverEngine(), AExpression.class);
+ public AExpression> getBaseImpl() {
+ return CtElement2JoinPoint.convert(getNodeImpl().getTarget(), getWeaverEngine(), AExpression.class);
}
}
diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JFile.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JFile.java
index b0f13333..fbf38562 100644
--- a/JavaWeaver/src/weaver/kadabra/joinpoints/JFile.java
+++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JFile.java
@@ -13,60 +13,63 @@
package weaver.kadabra.joinpoints;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Stream;
+
import org.apache.commons.lang3.NotImplementedException;
-import org.lara.interpreter.weaver.interf.JoinPoint;
+
import pt.up.fe.specs.util.SpecsIo;
import pt.up.fe.specs.util.SpecsLogs;
-import spoon.reflect.declaration.*;
-import spoon.support.reflect.declaration.CtImportImpl;
-import spoon.support.reflect.reference.CtTypeReferenceImpl;
+import spoon.reflect.declaration.CtClass;
+import spoon.reflect.declaration.CtCompilationUnit;
+import spoon.reflect.declaration.CtElement;
+import spoon.reflect.declaration.CtInterface;
+import spoon.reflect.declaration.CtType;
import spoon.support.visitor.equals.EqualsVisitor;
-import weaver.kadabra.JavaWeaver;
-import weaver.kadabra.abstracts.AJavaWeaverJoinPoint;
-import weaver.kadabra.abstracts.joinpoints.*;
+import weaver.kadabra.JWeaver;
+import weaver.kadabra.abstracts.joinpoints.AClass;
+import weaver.kadabra.abstracts.joinpoints.AInterfaceType;
+import weaver.kadabra.abstracts.joinpoints.AJoinpoint;
+import weaver.kadabra.abstracts.joinpoints.AType;
+import weaver.kadabra.abstracts.joinpoints.AFile;
import weaver.utils.generators.MapGenerator;
import weaver.utils.weaving.ActionUtils;
import weaver.utils.weaving.converters.CtElement2JoinPoint;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.stream.Stream;
-
-public class JFile extends AFile {
- private final CtCompilationUnit node;
+public class JFile> extends AFile {
- public JFile(CtCompilationUnit node, JavaWeaver weaver) {
- super(weaver);
- this.node = node;
+ public JFile(CtCompilationUnit node, JWeaver weaver) {
+ super(node, weaver);
}
@Override
public void addImportImpl(String qualifiedName) {
- var imports = node.getImports();
- var packageReferece = new CtTypeReferenceImpl();
+ var imports = getNodeImpl().getImports();
+ var packageReferece = new spoon.support.reflect.reference.CtTypeReferenceImpl();
packageReferece.setSimpleName(qualifiedName);
- var newImport = new CtImportImpl().setReference(packageReferece);
+ var newImport = new spoon.support.reflect.declaration.CtImportImpl().setReference(packageReferece);
imports.add(newImport);
- node.setImports(new ArrayList<>(imports));
+ getNodeImpl().setImports(new ArrayList<>(imports));
}
@Override
- public boolean compareNodes(AJoinPoint aJoinPoint) {
+ public boolean getCompareNodesImpl(AJoinpoint> aJoinPoint) {
- if (!(aJoinPoint instanceof JFile)) {
+ if (!(aJoinPoint instanceof JFile>)) {
return false;
}
// Verify source file equality
- CtCompilationUnit other = ((JFile) aJoinPoint).node;
- if (!node.getFile().equals(other.getFile())) {
+ CtCompilationUnit other = ((JFile>) aJoinPoint).getNodeImpl();
+ if (!getNodeImpl().getFile().equals(other.getFile())) {
return false;
}
// Use a biscan visitor to verify if both contains the same types
- List> elements = node.getDeclaredTypes();
+ List> elements = getNodeImpl().getDeclaredTypes();
List> others = other.getDeclaredTypes();
for (Iterator extends CtElement> firstIt = elements.iterator(), secondIt = others.iterator(); (firstIt
@@ -82,50 +85,40 @@ public boolean compareNodes(AJoinPoint aJoinPoint) {
@Override
public String getPackageNameImpl() {
- CtType> type = node.getMainType();
+ CtType> type = getNodeImpl().getMainType();
return type.getPackage().getQualifiedName();
}
@Override
public String getNameImpl() {
- return node.getFile().getName();
+ return getNodeImpl().getFile().getName();
}
@Override
public String getPathImpl() {
- return node.getFile().getAbsolutePath();
+ return getNodeImpl().getFile().getAbsolutePath();
}
@Override
public String getDirImpl() {
- return node.getFile().getParent();
+ return getNodeImpl().getFile().getParent();
}
@Override
- public Integer getNumClassesImpl() {
+ public int getNumClassesImpl() {
final int classes = (int) streamOfClasses().count();
return classes;
}
@Override
- public Integer getNumInterfacesImpl() {
+ public int getNumInterfacesImpl() {
final int interfs = (int) streamOfInterfaces().count();
return interfs;
}
@Override
- public CtCompilationUnit getNode() {
- return node;
- }
-
- @Override
- public boolean same(JoinPoint iJoinPoint) {
-
- if (!(iJoinPoint instanceof JFile)) {
- return false;
- }
- JFile other = (JFile) iJoinPoint;
- return node.equals(other.node);
+ public CtCompilationUnit getNodeImpl() {
+ return (CtCompilationUnit) super.getNodeImpl();
}
private Stream> streamOfInterfaces() {
@@ -140,74 +133,74 @@ private Stream> streamOfClasses() {
}
private Stream> streamOfTypes() {
- return node.getDeclaredTypes().stream();
+ return getNodeImpl().getDeclaredTypes().stream();
}
@Override
- public AClass newClassImpl(String name, String extend, String[] implement) {
- final CtClass newClass = ActionUtils.newClass(name, extend, implement, node.getFactory());
- node.getDeclaredTypes().add(newClass);
- JClass newInstance = JClass.newInstance(newClass, node, getWeaverEngine());
+ public AClass> newClassImpl(String name, String extend, String[] implement) {
+ final CtClass> newClass = ActionUtils.newClass(name, extend, implement, getNodeImpl().getFactory());
+ getNodeImpl().getDeclaredTypes().add(newClass);
+ JClass> newInstance = new JClass<>(newClass, getNodeImpl(), getWeaverEngine());
return newInstance;
}
@Override
- public AClass newClassImpl(String name) {
+ public AClass> newClassImpl(String name) {
return newClassImpl(name, null, null);
}
@Override
- public AInterfaceType newInterfaceImpl(String name, String[] extend) {
- final CtInterface newInterface = ActionUtils.newInterface(name, extend, node.getFactory());
- node.getDeclaredTypes().add(newInterface);
- JInterfaceType