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 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 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 newInstance = JInterfaceType.newInstance(newInterface, getWeaverEngine()); + public AInterfaceType newInterfaceImpl(String name, String[] extend) { + final CtInterface newInterface = ActionUtils.newInterface(name, extend, getNodeImpl().getFactory()); + getNodeImpl().getDeclaredTypes().add(newInterface); + JInterfaceType newInstance = new JInterfaceType<>(newInterface, getWeaverEngine()); return newInstance; } @Override - public AInterfaceType newInterfaceImpl(String name) { + public AInterfaceType newInterfaceImpl(String name) { return newInterfaceImpl(name, null); } @Override - public void addClassImpl(AClass newClass) { - add((CtType) newClass.getNode()); + public void addClassImpl(AClass newClass) { + add((CtType) newClass.getNodeImpl()); } @Override - public void addInterfaceImpl(AInterfaceType newInterface) { - add((CtType) newInterface.getNode()); + public void addInterfaceImpl(AInterfaceType newInterface) { + add((CtType) newInterface.getNodeImpl()); } @Override - public AInterfaceType removeInterfaceImpl(String interfaceName) { + public AInterfaceType removeInterfaceImpl(String interfaceName) { throw new NotImplementedException("Not implemented yet"); } private void add(CtType type) { - node.getDeclaredTypes().add(type); + getNodeImpl().getDeclaredTypes().add(type); } @Override - public AClass mapVersionsImpl(String name, String keyType, AInterfaceType _interface, String methodName) { + public AClass mapVersionsImpl(String name, String keyType, AInterfaceType _interface, String methodName) { - CtClass newClass = MapGenerator.generate(node.getFactory(), name, keyType, _interface, methodName); - node.getDeclaredTypes().add(newClass); - AClass newInstance = JClass.newInstance(newClass, node, getWeaverEngine()); + CtClass newClass = MapGenerator.generate(getNodeImpl().getFactory(), name, keyType, _interface, methodName); + getNodeImpl().getDeclaredTypes().add(newClass); + AClass newInstance = new JClass<>(newClass, getNodeImpl(), getWeaverEngine()); return newInstance; } @Override - public AJoinPoint getParentImpl() { - return (AJoinPoint) getWeaverEngine().getRootJp(); + public AJoinpoint getParentImpl() { + return getWeaverEngine().getRootJp(); } @Override - public AJoinPoint[] getChildrenArrayImpl() { - List children = new ArrayList<>(); + public AJoinpoint[] getChildrenImpl() { + List> children = new ArrayList<>(); - for (var file : getNode().getDeclaredTypes()) { - AJavaWeaverJoinPoint type = CtElement2JoinPoint.convertTry(file, getWeaverEngine()).orElse(null); + for (var file : getNodeImpl().getDeclaredTypes()) { + var type = CtElement2JoinPoint.convertTry(file, getWeaverEngine()).orElse(null); if (type == null) { continue; } @@ -215,20 +208,20 @@ public AJoinPoint[] getChildrenArrayImpl() { children.add(type); } - return children.toArray(new AJoinPoint[0]); + return children.toArray(new AJoinpoint[0]); } @Override - public String toString() { + public String getToStringImpl() { return getNameImpl(); } @Override - public AType getMainClassImpl() { + public AType getMainClassImpl() { var fileName = SpecsIo.removeExtension(getNameImpl()); - var declaredTypes = node.getDeclaredTypes(); + var declaredTypes = getNodeImpl().getDeclaredTypes(); if (declaredTypes.isEmpty()) { SpecsLogs diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JGenericJoinPoint.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JGenericJoinPoint.java deleted file mode 100644 index 22ad1766..00000000 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JGenericJoinPoint.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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. - */ - -package weaver.kadabra.joinpoints; - -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; - -public class JGenericJoinPoint extends AJavaWeaverJoinPoint { - - private CtElement node; - - public static JGenericJoinPoint newDummy(JavaWeaver weaver) { - return new JGenericJoinPoint(null, weaver); - } - - public static JGenericJoinPoint newInstance(CtElement node, JavaWeaver weaver) { - return new JGenericJoinPoint(node, weaver); - } - - public JGenericJoinPoint(CtElement node, JavaWeaver weaver) { - super(weaver); - this.node = node; - } - - @Override - public CtElement getNode() { - return node; - } - - @Override - public String toString() { - return "Spoon class: " + node.getClass().getSimpleName() + ", content: " + node; - } - -} diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JIf.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JIf.java index bd46660a..f430c0b9 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JIf.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JIf.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,12 +15,10 @@ import java.util.List; -import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtIf; -import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtElement; import tdrc.utils.StringUtils; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ABody; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.abstracts.joinpoints.AIf; @@ -29,18 +27,12 @@ import weaver.utils.element.RankCalculator; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JIf extends AIf { +public class JIf> extends AIf { - private final CtIf node; private String rank; - private JIf(CtIf node, JavaWeaver weaver) { - super(new JStatement(node, weaver), weaver); - this.node = node; - } - - public static JIf newInstance(CtIf node, JavaWeaver weaver) { - return new JIf(node, weaver); + public JIf(CtIf node, JWeaver weaver) { + super(node, weaver); } @Override @@ -48,49 +40,49 @@ public String getRankImpl() { if (rank != null) { return rank; } - CtElement executableAncestor = SpoonUtils.getExecutableAncestor(node); - List ranks = RankCalculator.calculate(node, CtIf.class, executableAncestor); + CtElement executableAncestor = SpoonUtils.getExecutableAncestor(getNodeImpl()); + List ranks = RankCalculator.calculate(getNodeImpl(), CtIf.class, executableAncestor); rank = StringUtils.join(ranks, "."); return rank; } @Override - public CtIf getNode() { - return node; + public CtIf getNodeImpl() { + return (CtIf) super.getNodeImpl(); } @Override - public AExpression getCondImpl() { - return (AExpression) CtElement2JoinPoint.convert(node.getCondition(), getWeaverEngine()); + public AExpression getCondImpl() { + return (AExpression) CtElement2JoinPoint.convert(getNodeImpl().getCondition(), getWeaverEngine()); } @Override - public ABody getThenImpl() { - CtStatement thenStatement = node.getThenStatement(); + public ABody getThenImpl() { + spoon.reflect.code.CtStatement thenStatement = getNodeImpl().getThenStatement(); if (thenStatement == null) { return null; } - if (!(thenStatement instanceof CtBlock)) { + if (!(thenStatement instanceof spoon.reflect.code.CtBlock)) { throw new JavaWeaverException("The then statement must always be a block"); } - return (ABody) CtElement2JoinPoint.convert(thenStatement, getWeaverEngine()); + return (ABody) CtElement2JoinPoint.convert(thenStatement, getWeaverEngine()); } @Override - public ABody getElseImpl() { - CtStatement elseStatement = node.getElseStatement(); + public ABody getElseImpl() { + spoon.reflect.code.CtStatement elseStatement = getNodeImpl().getElseStatement(); if (elseStatement == null) { return null; } - if (!(elseStatement instanceof CtBlock)) { + if (!(elseStatement instanceof spoon.reflect.code.CtBlock)) { throw new JavaWeaverException("The else statement must always be a block"); } - return (ABody) CtElement2JoinPoint.convert(elseStatement, getWeaverEngine()); + return (ABody) CtElement2JoinPoint.convert(elseStatement, getWeaverEngine()); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JInterfaceType.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JInterfaceType.java index 76d2661e..3cf9867b 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JInterfaceType.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JInterfaceType.java @@ -13,26 +13,15 @@ package weaver.kadabra.joinpoints; -import spoon.reflect.cu.CompilationUnit; import spoon.reflect.declaration.CtInterface; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.AInterfaceType; - -public class JInterfaceType extends AInterfaceType { - CtInterface node; - - private JInterfaceType(CtInterface node, CompilationUnit parent, JavaWeaver weaver) { - super(JType.newInstance(node, parent, weaver), weaver); - this.node = node; - } +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AInterfaceType; - public static JInterfaceType newInstance(CtInterface node, CompilationUnit parent, JavaWeaver weaver) { - return new JInterfaceType<>(node, parent, weaver); - } +public class JInterfaceType> extends AInterfaceType { - public static JInterfaceType newInstance(CtInterface node, JavaWeaver weaver) { - return new JInterfaceType<>(node, node.getPosition().getCompilationUnit(), weaver); + public JInterfaceType(CtInterface node, JWeaver weaver) { + super(node, weaver); } @Override @@ -41,13 +30,12 @@ public String getSuperClassImpl() { } @Override - public CtInterface getNode() { - - return node; + public CtInterface getNodeImpl() { + return (CtInterface) super.getNodeImpl(); } @Override - public String toString() { - return node.getQualifiedName(); + public String getToStringImpl() { + return getNodeImpl().getQualifiedName(); } } diff --git a/JavaWeaver/src/weaver/kadabra/abstracts/AJavaWeaverJoinPoint.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JJoinpoint.java similarity index 51% rename from JavaWeaver/src/weaver/kadabra/abstracts/AJavaWeaverJoinPoint.java rename to JavaWeaver/src/weaver/kadabra/joinpoints/JJoinpoint.java index 42075cc9..36de4f21 100644 --- a/JavaWeaver/src/weaver/kadabra/abstracts/AJavaWeaverJoinPoint.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JJoinpoint.java @@ -1,7 +1,30 @@ -package weaver.kadabra.abstracts; +/** + * 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. + */ + +package weaver.kadabra.joinpoints; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import com.google.common.base.Preconditions; -import org.lara.interpreter.weaver.interf.JoinPoint; + +import org.lara.interpreter.weaver.interf.enums.InsertPosition; + import pt.up.fe.specs.util.SpecsEnums; import pt.up.fe.specs.util.SpecsLogs; import pt.up.fe.specs.util.exceptions.NotImplementedException; @@ -10,58 +33,71 @@ import spoon.reflect.code.CtLoop; import spoon.reflect.code.CtStatement; import spoon.reflect.cu.SourcePosition; -import spoon.reflect.declaration.*; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.*; +import spoon.reflect.declaration.CtAnnotation; +import spoon.reflect.declaration.CtElement; +import spoon.reflect.declaration.CtExecutable; +import spoon.reflect.declaration.CtType; +import spoon.reflect.declaration.ModifierKind; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AAnnotation; +import weaver.kadabra.abstracts.joinpoints.ACallStatement; +import weaver.kadabra.abstracts.joinpoints.AExecutable; +import weaver.kadabra.abstracts.joinpoints.AExpression; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; +import weaver.kadabra.abstracts.joinpoints.AStatement; +import weaver.kadabra.abstracts.joinpoints.AType; import weaver.kadabra.spoon.extensions.launcher.JWEnvironment; import weaver.kadabra.util.KadabraLog; import weaver.utils.JoinPoints; import weaver.utils.SpoonUtils; import weaver.utils.weaving.ActionUtils; import weaver.utils.weaving.SelectUtils; -import weaver.utils.weaving.converters.*; - -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; +import weaver.utils.weaving.converters.CtElement2JoinPoint; +import weaver.utils.weaving.converters.CtExpression2AExpression; +import weaver.utils.weaving.converters.CtExecutable2AExecutable; +import weaver.utils.weaving.converters.CtStatement2AStatement; +import weaver.utils.weaving.converters.CtType2AType; /** - * Abstract class which can be edited by the developer. This class will not be - * overwritten. - * - * @author Lara Weaver Generator + * Editable class which contains the implementation shared by all join points. + * This class will NOT be overwritten by the generator. + *

+ * It is also the default join point, used to represent Spoon nodes that do not + * have a more specific join point. */ -public abstract class AJavaWeaverJoinPoint extends AJoinPoint { +public class JJoinpoint> extends AJoinpoint { - public AJavaWeaverJoinPoint(JavaWeaver weaver) { - super(weaver); + public JJoinpoint(CtElement node, JWeaver weaver) { + super(node, weaver); } @Override - public JavaWeaver getWeaverEngine() { - return (JavaWeaver) super.getWeaverEngine(); + public JWeaver getWeaverEngine() { + return (JWeaver) super.getWeaverEngine(); } @Override - public boolean equals(Object obj) { - if (obj instanceof JoinPoint jp) { - return same(jp); + public boolean getSameImpl(AJoinpoint other) { + return this.get_class().equals(other.get_class()) && this.getCompareNodesImpl(other); + } + + @Override + public boolean getCompareNodesImpl(AJoinpoint aJoinPoint) { + return getNodeImpl().equals(aJoinPoint.getNodeImpl()); + } + + @Override + public boolean getEqualsImpl(Self jp) { + if (!(jp instanceof AJoinpoint)) { + return false; } - return false; + return this.getSameImpl(jp); } - /** - * Compares the two join points based on their node reference of the used - * compiler/parsing tool.
- * This is the default implementation for comparing two join points.
- * Note for developers: A weaver may override this implementation in the - * editable abstract join point, so the changes are made for all join points, or - * override this method in specific join points. - */ @Override - public boolean compareNodes(AJoinPoint aJoinPoint) { - return getNode().equals(aJoinPoint.getNode()); + public AJoinpoint getRootImpl() { + return getWeaverEngine().getRootJp(); } @Override @@ -71,21 +107,18 @@ public String getSrcCodeImpl() { @Override public String getCodeImpl() { - return getWeaverEngine().getSourceCodePrinter().getSourceCode(getNode()); + return getWeaverEngine().getSourceCodePrinter().getSourceCode(getNodeImpl()); } - @Override - public abstract CtElement getNode(); - @Override public void setLineImpl(int value) { - CtElement node = getNode(); + CtElement node = getNodeImpl(); if (node == null) { - KadabraLog.warning("Cannot change line in this join point: " + getJoinPointType()); + KadabraLog.warning("Cannot change line in this join point: " + get_class()); } SourcePosition position = node.getPosition(); if (position == null) { - KadabraLog.warning("Cannot change line in this join point: " + getJoinPointType()); + KadabraLog.warning("Cannot change line in this join point: " + get_class()); } int line = position.getLine(); KadabraLog.info("Changing line number from " + line + " to " + value); @@ -97,17 +130,17 @@ public void setLineImpl(String value) { } @Override - public AJoinPoint getParentImpl() { + public AJoinpoint getParentImpl() { // If no node, no parent // This condition is a bit suspicious, // because if a join point returns a null node // (e.g., JApp or JFile), they should have their // own implementations of getParentImpl() - if (getNode() == null) { + if (getNodeImpl() == null) { return null; } - CtElement parent = getNode().getParent(); + CtElement parent = getNodeImpl().getParent(); if (parent == null) { return null; } @@ -115,15 +148,15 @@ public AJoinPoint getParentImpl() { var parentJp = CtElement2JoinPoint.convert(parent, getWeaverEngine()); // Special case: if parent is a CallStatement, return the Call instead - if (parentJp instanceof ACallStatement) { - return ((ACallStatement) parentJp).getCallImpl(); + if (parentJp instanceof ACallStatement callStatement) { + return callStatement.getCallImpl(); } return parentJp; } @Override - public AJoinPoint getAstParentImpl() { + public AJoinpoint getAstParentImpl() { return getParentImpl(); } @@ -132,20 +165,20 @@ public AJoinPoint getAstParentImpl() { * @return */ public T getAncestor(Class ancestorType) { - return SpoonUtils.getAncestor(getNode(), ancestorType); + return SpoonUtils.getAncestor(getNodeImpl(), ancestorType); } public Optional getAncestorTry(Class ancestorType) { - return SpoonUtils.getAncestorTry(getNode(), ancestorType); + return SpoonUtils.getAncestorTry(getNodeImpl(), ancestorType); } @Override - public AJoinPoint getAncestorImpl(String type) { + public AJoinpoint getGetAncestorImpl(String type) { Preconditions.checkNotNull(type, "Missing type of ancestor in attribute 'ancestor'"); - AJoinPoint currentNode = getParentImpl(); + AJoinpoint currentNode = getParentImpl(); while (currentNode != null) { - if (currentNode.instanceOf(type)) { + if (currentNode.getInstanceOfImpl(type)) { return currentNode; } currentNode = currentNode.getParentImpl(); @@ -154,28 +187,28 @@ public AJoinPoint getAncestorImpl(String type) { return currentNode; } - protected AExpression toAExpression(CtExpression expression) { + protected AExpression toAExpression(CtExpression expression) { return CtExpression2AExpression.convertToExpression(expression, getWeaverEngine()); } - protected AJavaWeaverJoinPoint toAStatement(CtStatement statement) { - return CtStatement2AStatement.convert(statement, getWeaverEngine()); + protected AStatement toAStatement(CtStatement statement) { + return (AStatement) CtStatement2AStatement.convert(statement, getWeaverEngine()); } - protected AType toAType(CtType type) { + protected AType toAType(CtType type) { return CtType2AType.convert(type, getWeaverEngine()); } - protected AExecutable toAExecutable(CtExecutable exec) { + protected AExecutable toAExecutable(CtExecutable exec) { return CtExecutable2AExecutable.convert(exec, getWeaverEngine()); } @Override public Integer getLineImpl() { - if (getNode() == null) { + if (getNodeImpl() == null) { return null; } - SourcePosition position = getNode().getPosition(); + SourcePosition position = getNodeImpl().getPosition(); if (position == null || !position.isValidPosition()) { return null; } @@ -183,122 +216,139 @@ public Integer getLineImpl() { return position.getLine(); } + @Override + public Integer getColumnImpl() { + if (getNodeImpl() == null) { + return null; + } + SourcePosition position = getNodeImpl().getPosition(); + if (position == null || !position.isValidPosition()) { + return null; + } + + return position.getColumn(); + } + /** * Required, because original insertImpl returns JoinPoint, but abstract join - * points return AJoinPoint. + * points return AJoinpoint. */ @Override - public AJoinPoint[] insertImpl(String position, String code) { - throw new RuntimeException("Not implemented yet for join point type '" + getJoinPointType() + "'"); + public AJoinpoint[] insertImpl(InsertPosition position, String code) { + throw new RuntimeException("Not implemented yet for join point type '" + get_class() + "'"); } @Override - public AJoinPoint insertBeforeImpl(AJoinPoint node) { - insertImpl("after", node); + public AJoinpoint insertBeforeImpl(AJoinpoint node) { + insertImpl(InsertPosition.AFTER, node); return node; } @Override - public AJoinPoint insertBeforeImpl(String code) { - return insertImpl("before", code)[0]; + public AJoinpoint insertBeforeImpl(String code) { + return insertImpl(InsertPosition.BEFORE, code)[0]; } @Override - public AJoinPoint insertAfterImpl(AJoinPoint node) { - insertImpl("after", node); + public AJoinpoint insertAfterImpl(AJoinpoint node) { + insertImpl(InsertPosition.AFTER, node); return node; } @Override - public AJoinPoint insertAfterImpl(String code) { - return insertImpl("after", code)[0]; + public AJoinpoint insertAfterImpl(String code) { + return insertImpl(InsertPosition.AFTER, code)[0]; } @Override - public AJoinPoint insertReplaceImpl(AJoinPoint jp) { + public AJoinpoint insertReplaceImpl(AJoinpoint jp) { return replaceWithImpl(jp); } @Override - public AJoinPoint insertReplaceImpl(String code) { + public AJoinpoint insertReplaceImpl(String code) { return replaceWithImpl(code); } @Override - public AJoinPoint replaceWithImpl(AJoinPoint jp) { - return insertImpl("replace", jp)[0]; + public AJoinpoint replaceWithImpl(AJoinpoint jp) { + return insertImpl(InsertPosition.REPLACE, jp)[0]; } @Override - public AJoinPoint replaceWithImpl(String code) { - return insertImpl("replace", code)[0]; + public AJoinpoint replaceWithImpl(String code) { + return insertImpl(InsertPosition.REPLACE, code)[0]; } @Override - public AJoinPoint[] insertImpl(String position, JoinPoint JoinPoint) { + public AJoinpoint[] insertImpl(InsertPosition position, AJoinpoint joinPoint) { throw new NotImplementedException(this); } @Override - public AJoinPoint[] getDescendantsArrayImpl() { - return getJpDescendantsStream().toArray(size -> new AJoinPoint[size]); + public AJoinpoint[] getDescendantsImpl() { + return getJpDescendantsStream().toArray(size -> new AJoinpoint[size]); } @Override - public Boolean getIsStatementImpl() { - return this instanceof AStatement; - // return getNode() instanceof CtStatement; + public boolean getIsStatementImpl() { + return this instanceof AStatement; } @Override - public Boolean getIsBlockImpl() { - return getNode() instanceof CtBlock; + public boolean getIsBlockImpl() { + return getNodeImpl() instanceof CtBlock; } @Override - public AJoinPoint copyImpl() { + public AJoinpoint copyImpl() { // Clone the node - var copy = getNode().clone(); + var copy = getNodeImpl().clone(); // Set the parent - copy.setParent(getNode().getParent()); + copy.setParent(getNodeImpl().getParent()); return CtElement2JoinPoint.convert(copy, getWeaverEngine()); } private List getChildrenNodes() { - return SpoonUtils.getChildren(getNode()); + return SpoonUtils.getChildren(getNodeImpl()); } @Override - public Stream getJpChildrenStream() { - return Arrays.stream(getChildrenArrayImpl()); + public java.util.stream.Stream> getJpChildrenStream() { + return Arrays.stream(getChildrenImpl()); } @Override - public JoinPoint getJpParent() { + public AJoinpoint getJpParent() { return getParentImpl(); } @Override - public AJoinPoint[] getChildrenArrayImpl() { + public AJoinpoint[] getScopeNodesImpl() { + return getChildrenImpl(); + } + + @Override + public AJoinpoint[] getChildrenImpl() { return getChildrenNodes().stream() .map(node -> CtElement2JoinPoint.convert(node, getWeaverEngine())) - .toArray(size -> new AJoinPoint[size]); + .toArray(size -> new AJoinpoint[size]); } @Override - public AJoinPoint childImpl(Integer index) { - return getChildrenArrayImpl()[index]; + public AJoinpoint getChildImpl(int index) { + return getChildrenImpl()[index]; } @Override - public Integer getNumChildrenImpl() { - return getChildrenArrayImpl().length; + public int getNumChildrenImpl() { + return getChildrenImpl().length; } @Override public String getAstImpl() { - var node = getNode(); + var node = getNodeImpl(); // If no node, start from join point if (node == null) { @@ -306,12 +356,15 @@ public String getAstImpl() { } // This method is more robust regarding the initial node - return SpoonUtils.toAst(getNode(), "", getWeaverEngine()); + return SpoonUtils.toAst(getNodeImpl(), "", getWeaverEngine()); } @Override - public String toString() { - return getNode().toString(); + public String getToStringImpl() { + if (getNodeImpl() == null) { + return "Joinpoint '" + get_class() + "'"; + } + return getNodeImpl().toString(); } @Override @@ -319,14 +372,14 @@ public void removeImpl() { // Delete from annotations JWEnvironment env = ActionUtils.getKadabraEnvironment(getWeaverEngine().getFactory().getSpoonFactory()); // TODO: This remove can be optimized - env.getTable().remove(getNode()); + env.getTable().remove(getNodeImpl()); - getNode().delete(); + getNodeImpl().delete(); } @Override - public String[] getModifiersArrayImpl() { - return modifiersToString(SpoonUtils.getModifiers(getNode())); + public String[] getModifiersImpl() { + return modifiersToString(SpoonUtils.getModifiers(getNodeImpl())); } public String[] modifiersToString(Collection modifiers) { @@ -336,7 +389,7 @@ public String[] modifiersToString(Collection modifiers) { } @Override - public Boolean hasModifierImpl(String modifier) { + public boolean getHasModifierImpl(String modifier) { ModifierKind modifierKind = null; try { modifierKind = ModifierKind.valueOf(modifier.toUpperCase()); @@ -345,55 +398,55 @@ public Boolean hasModifierImpl(String modifier) { + Arrays.toString(ModifierKind.values())); } - return SpoonUtils.getModifiers(getNode()).contains(modifierKind); + return SpoonUtils.getModifiers(getNodeImpl()).contains(modifierKind); } @Override - public Boolean getIsFinalImpl() { - return SpoonUtils.getModifiers(getNode()).contains(ModifierKind.FINAL); + public boolean getIsFinalImpl() { + return SpoonUtils.getModifiers(getNodeImpl()).contains(ModifierKind.FINAL); } @Override - public Boolean getIsStaticImpl() { - return SpoonUtils.getModifiers(getNode()).contains(ModifierKind.STATIC); + public boolean getIsStaticImpl() { + return SpoonUtils.getModifiers(getNodeImpl()).contains(ModifierKind.STATIC); } @Override - public AAnnotation[] getAnnotationsArrayImpl() { + public AAnnotation[] getAnnotationsImpl() { - return getNode().getAnnotations().stream() - .map(annotation -> (AAnnotation) SelectUtils.expression2JoinPoint(annotation, getWeaverEngine())) + return getNodeImpl().getAnnotations().stream() + .map(annotation -> (AAnnotation) SelectUtils.expression2JoinPoint(annotation, getWeaverEngine())) .collect(Collectors.toList()) .toArray(size -> new AAnnotation[size]); } @Override - public void removeAnnotationImpl(AAnnotation annotation) { - getNode().removeAnnotation((CtAnnotation) annotation.getNode()); + public void removeAnnotationImpl(AAnnotation annotation) { + getNodeImpl().removeAnnotation((CtAnnotation) annotation.getNodeImpl()); } @Override public String getIdImpl() { - var node = getNode(); + var node = getNodeImpl(); return node.getClass().getSimpleName() + "_" + node.hashCode(); } @Override - public AJoinPoint[] getLeftArrayImpl() { + public AJoinpoint[] getLeftImpl() { var parent = getParentImpl(); if (parent == null) { SpecsLogs.info("$jp.left: no parent, could not fetch siblings"); - return new AJoinPoint[0]; + return new AJoinpoint[0]; } - var siblings = parent.getChildrenArrayImpl(); + var siblings = parent.getChildrenImpl(); // Find self index int selfIndex = -1; for (int i = 0; i < siblings.length; i++) { // Using equality on purpose - if (siblings[i].getNode() == getNode()) { + if (siblings[i].getNodeImpl() == getNodeImpl()) { selfIndex = i; break; } @@ -401,28 +454,28 @@ public AJoinPoint[] getLeftArrayImpl() { if (selfIndex == -1) { SpecsLogs.info("$jp.left: could not find self in siblings"); - return new AJoinPoint[0]; + return new AJoinpoint[0]; } return Arrays.copyOfRange(siblings, 0, selfIndex); } @Override - public AJoinPoint[] getRightArrayImpl() { + public AJoinpoint[] getRightImpl() { var parent = getParentImpl(); if (parent == null) { SpecsLogs.info("$jp.right: no parent, could not fetch siblings"); - return new AJoinPoint[0]; + return new AJoinpoint[0]; } - var siblings = parent.getChildrenArrayImpl(); + var siblings = parent.getChildrenImpl(); // Find self index int selfIndex = -1; for (int i = 0; i < siblings.length; i++) { // Using equality on purpose - if (siblings[i].getNode() == getNode()) { + if (siblings[i].getNodeImpl() == getNodeImpl()) { selfIndex = i; break; } @@ -430,7 +483,7 @@ public AJoinPoint[] getRightArrayImpl() { if (selfIndex == -1) { SpecsLogs.info("$jp.right: could not find self in siblings"); - return new AJoinPoint[0]; + return new AJoinpoint[0]; } return Arrays.copyOfRange(siblings, selfIndex + 1, siblings.length); @@ -438,7 +491,7 @@ public AJoinPoint[] getRightArrayImpl() { @Override public void removeModifierImpl(String modifier) { - var modifiersSet = SpoonUtils.getModifiers(getNode()); + var modifiersSet = SpoonUtils.getModifiers(getNodeImpl()); if (modifiersSet.isEmpty()) { SpecsLogs.debug(() -> "No modifiers to remove"); @@ -458,7 +511,7 @@ public void removeModifierImpl(String modifier) { var hadModifier = newModifiers.remove(modifierEnum.get()); if (hadModifier) { - SpoonUtils.setModifiers(getNode(), newModifiers); + SpoonUtils.setModifiers(getNodeImpl(), newModifiers); } else { SpecsLogs.debug(() -> "Could not remove modifier '" + modifier + "', not present in node"); } @@ -484,12 +537,12 @@ public void setModifiersImpl(String[] modifiers) { modifiersSet.add(modifierEnum.get()); } - SpoonUtils.setModifiers(getNode(), modifiersSet); + SpoonUtils.setModifiers(getNodeImpl(), modifiersSet); } @Override - public Boolean getIsInsideLoopHeaderImpl() { - var node = getNode(); + public boolean getIsInsideLoopHeaderImpl() { + var node = getNodeImpl(); Optional ancestor = SpoonUtils.getAncestorTry(node, CtLoop.class); if (!ancestor.isPresent()) { diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JLibClass.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JLibClass.java index da8e8acf..95bcc399 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JLibClass.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JLibClass.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. @@ -15,23 +15,13 @@ import com.google.common.reflect.ClassPath.ClassInfo; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ALibClass; -public class JLibClass extends ALibClass { +public class JLibClass> extends ALibClass { - private JLibClass(ClassInfo info, JavaWeaver weaver) { - super(JNamedType.newInstance(info, weaver), weaver); - // this.info = info; + public JLibClass(ClassInfo info, JWeaver weaver) { + super(info, weaver); } - public static JLibClass newInstance(ClassInfo info, JavaWeaver weaver) { - return new JLibClass(info, weaver); - } - - @Override - public CtElement getNode() { - return null; - } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JLibMethod.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JLibMethod.java index bad79e25..b6234e17 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JLibMethod.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JLibMethod.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,27 +14,24 @@ package weaver.kadabra.joinpoints; import java.lang.reflect.Method; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ALibMethod; import weaver.kadabra.abstracts.joinpoints.ANamedType; import weaver.kadabra.exceptions.JavaWeaverException; -public class JLibMethod extends ALibMethod { - - private Method method; +public class JLibMethod> extends ALibMethod { - private JLibMethod(Method m, JavaWeaver weaver) { - super(weaver); - method = m; - } + private final Method method; - public static JLibMethod newInstance(Method m, JavaWeaver weaver) { - return new JLibMethod(m, weaver); + public JLibMethod(Method m, JWeaver weaver) { + super((spoon.reflect.declaration.CtElement) null, weaver); + this.method = m; } @Override - public CtElement getNode() { + public spoon.reflect.declaration.CtElement getNodeImpl() { + // Lib methods have no Spoon node return null; } @@ -44,7 +41,7 @@ public String getNameImpl() { } @Override - public ANamedType getDeclaratorImpl() { + public ANamedType getDeclaratorImpl() { throw new JavaWeaverException("Select declaration in LibMethod not implemented"); } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JLiteral.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JLiteral.java index c2dec45d..86eff6cf 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JLiteral.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JLiteral.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,42 +14,37 @@ package weaver.kadabra.joinpoints; import spoon.reflect.code.CtLiteral; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ALiteral; import weaver.utils.SpoonLiterals; -public class JLiteral extends ALiteral { - - private CtLiteral node; - - private JLiteral(CtLiteral node, JavaWeaver weaver) { - super(new JExpression<>(node, weaver), weaver); - this.node = node; - } +public class JLiteral> extends ALiteral { - public static JLiteral newInstance(CtLiteral node, JavaWeaver weaver) { - return new JLiteral<>(node, weaver); + public JLiteral(CtLiteral node, JWeaver weaver) { + super(node, weaver); } @Override public String getValueImpl() { - return String.valueOf(node.getValue()); + return String.valueOf(getNodeImpl().getValue()); } @Override - public CtLiteral getNode() { - return node; + public CtLiteral getNodeImpl() { + return (CtLiteral) super.getNodeImpl(); } @Override - public String toString() { + public String getToStringImpl() { return getValueImpl(); } @Override + @SuppressWarnings("unchecked") public void setValueImpl(String value) { - @SuppressWarnings("unchecked") // decode literal value transform the value into T - T decodedValue = (T) SpoonLiterals.decodeLiteralValue(getTypeImpl().toString(), value); - node.setValue(decodedValue); + // decode literal value transforms the value into the literal's type + Object decodedValue = SpoonLiterals.decodeLiteralValue(getTypeImpl().toString(), value); + ((CtLiteral) getNodeImpl()).setValue(decodedValue); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JLocalVariable.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JLocalVariable.java index 9864efc1..1b797f17 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JLocalVariable.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JLocalVariable.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,27 +13,19 @@ package weaver.kadabra.joinpoints; -import spoon.reflect.code.CtExpression; -import spoon.reflect.code.CtLocalVariable; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.abstracts.joinpoints.ALocalVariable; import weaver.kadabra.abstracts.joinpoints.ATypeReference; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JLocalVariable extends ALocalVariable { +public class JLocalVariable> extends ALocalVariable { - private CtLocalVariable node; - private JDeclaration declaration; + private final JDeclaration declaration; - private JLocalVariable(CtLocalVariable statement, JavaWeaver weaver) { - super(new JStatement(statement, weaver), weaver); - this.node = statement; - this.declaration = JDeclaration.newInstance(statement, weaver); - } - - public static JLocalVariable newInstance(CtLocalVariable statement, JavaWeaver weaver) { - return new JLocalVariable<>(statement, weaver); + public JLocalVariable(spoon.reflect.code.CtLocalVariable statement, JWeaver weaver) { + super(statement, weaver); + this.declaration = new JDeclaration<>(statement, weaver); } @Override @@ -42,7 +34,7 @@ public String getNameImpl() { } @Override - public ATypeReference getTypeReferenceImpl() { + public ATypeReference getTypeReferenceImpl() { return declaration.getTypeReferenceImpl(); } @@ -52,12 +44,12 @@ public String getTypeImpl() { } @Override - public Boolean getIsArrayImpl() { + public boolean getIsArrayImpl() { return declaration.getIsArrayImpl(); } @Override - public Boolean getIsPrimitiveImpl() { + public boolean getIsPrimitiveImpl() { return declaration.getIsPrimitiveImpl(); } @@ -67,28 +59,29 @@ public String getCompleteTypeImpl() { } @Override - public CtLocalVariable getNode() { - return node; + public spoon.reflect.code.CtLocalVariable getNodeImpl() { + return (spoon.reflect.code.CtLocalVariable) super.getNodeImpl(); } @Override - public AExpression getInitImpl() { - var defaultExpr = declaration.getNode().getDefaultExpression(); + public AExpression getInitImpl() { + var defaultExpr = getNodeImpl().getDefaultExpression(); if (defaultExpr == null) { return null; } - return (AExpression) CtElement2JoinPoint.convert(defaultExpr, getWeaverEngine()); + return (AExpression) CtElement2JoinPoint.convert(defaultExpr, getWeaverEngine()); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override - public void setInitImpl(AExpression value) { + public void setInitImpl(AExpression value) { if (value == null) { - declaration.getNode().setDefaultExpression(null); + getNodeImpl().setDefaultExpression(null); return; } - declaration.getNode().setDefaultExpression((CtExpression) value.getNode()); + ((spoon.reflect.code.CtLocalVariable) getNodeImpl()) + .setDefaultExpression((spoon.reflect.code.CtExpression) value.getNodeImpl()); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JLoop.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JLoop.java index 4db27889..1f685117 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JLoop.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JLoop.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. @@ -18,115 +18,118 @@ import java.util.Collections; import java.util.List; -import org.lara.interpreter.weaver.interf.JoinPoint; +import org.lara.interpreter.weaver.interf.enums.InsertPosition; -import spoon.reflect.code.CtDo; import spoon.reflect.code.CtFor; import spoon.reflect.code.CtForEach; +import spoon.reflect.code.CtDo; import spoon.reflect.code.CtLoop; import spoon.reflect.code.CtWhile; import spoon.reflect.declaration.CtAnonymousExecutable; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtExecutable; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; -import weaver.kadabra.abstracts.joinpoints.AJoinPoint; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AExpression; +import weaver.kadabra.abstracts.joinpoints.AField; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.abstracts.joinpoints.ALoop; import weaver.kadabra.enums.LoopType; -import weaver.kadabra.util.KadabraLog; +import weaver.kadabra.subtypes.JDoWhile; +import weaver.kadabra.subtypes.JFor; +import weaver.kadabra.subtypes.JForEach; +import weaver.kadabra.subtypes.JWhile; import weaver.utils.SpoonUtils; import weaver.utils.element.RankCalculator; import weaver.utils.scanners.NodeSearcher; import weaver.utils.weaving.ActionUtils; -public abstract class JLoop extends ALoop { +public class JLoop> extends ALoop { - private final CtLoop node; private final LoopType type; private Integer nestedLevel; protected String rank; - public static JLoop newInstance(CtLoop node, JavaWeaver weaver) { + public JLoop(CtLoop node, LoopType type, JWeaver weaver) { + super(node, weaver); + this.type = type; + nestedLevel = null; + rank = null; + } + + public static JLoop newInstance(CtLoop node, JWeaver weaver) { SpoonUtils.sanitizeBody(node); if (node instanceof CtFor) { - return JFor.newInstance((CtFor) node, weaver); + return new JFor<>((CtFor) node, weaver); } else if (node instanceof CtWhile) { - return JWhile.newInstance((CtWhile) node, weaver); + return new JWhile<>((CtWhile) node, weaver); } else if (node instanceof CtDo) { - return JDoWhile.newInstance((CtDo) node, weaver); + return new JDoWhile<>((CtDo) node, weaver); } else if (node instanceof CtForEach) { - return JForEach.newInstance((CtForEach) node, weaver); + return new JForEach<>((CtForEach) node, weaver); } throw new RuntimeException("Type of for loop not yet implemented: " + node.getClass()); } - protected JLoop(CtLoop node, LoopType type, JavaWeaver weaver) { - super(new JStatement(node, weaver), weaver); - this.node = node; - this.type = type; - nestedLevel = null; - rank = null; - } - @Override - public AJoinPoint[] insertImpl(String position, String code) { - return new AJoinPoint[] { insertImplJLoop(position, code) }; + public AJoinpoint[] insertImpl(InsertPosition position, String code) { + return new AJoinpoint[] { insertImplJLoop(position, code) }; } @Override - public AJoinPoint[] insertImpl(String position, JoinPoint code) { - return new AJoinPoint[] { - ActionUtils.insert(position, (CtElement) code.getNode(), node, getWeaverEngine()) }; + public AJoinpoint[] insertImpl(InsertPosition position, AJoinpoint code) { + return new AJoinpoint[] { + ActionUtils.insert(position.name().toLowerCase(), (CtElement) code.getNodeImpl(), getNodeImpl(), + getWeaverEngine()) }; } - public AJavaWeaverJoinPoint insertImplJLoop(String position, String code) { - return ActionUtils.insert(position, code, node, getWeaverEngine()); + public AJoinpoint insertImplJLoop(InsertPosition position, String code) { + return ActionUtils.insert(position.name().toLowerCase(), code, getNodeImpl(), getWeaverEngine()); } @Override - public AJoinPoint insertBeforeImpl(String code) { - return insertImplJLoop("before", code); + public AJoinpoint insertBeforeImpl(String code) { + return insertImplJLoop(InsertPosition.BEFORE, code); } @Override - public AJoinPoint insertAfterImpl(String code) { - return insertImplJLoop("after", code); + public AJoinpoint insertAfterImpl(String code) { + return insertImplJLoop(InsertPosition.AFTER, code); } @Override - public AJoinPoint insertReplaceImpl(String code) { - return insertImplJLoop("replace", code); + public AJoinpoint insertReplaceImpl(String code) { + return insertImplJLoop(InsertPosition.REPLACE, code); } @Override - public String getTypeImpl() { - return type.getName(); + public LoopType getTypeImpl() { + return type; } @Override - public CtLoop getNode() { - return node; + public CtLoop getNodeImpl() { + return (CtLoop) super.getNodeImpl(); } @Override - public Boolean getIsInnermostImpl() { + public boolean getIsInnermostImpl() { List innerLoops = new ArrayList<>(); Class searchClass = CtLoop.class; List> cuts = Arrays.asList(searchClass); new NodeSearcher(searchClass, innerLoops::add, Collections.emptyList(), cuts) - .scan(node.getElements(e -> e != node)); + .scan(getNodeImpl().getElements(e -> e != getNodeImpl())); return innerLoops.isEmpty(); } @Override - public Boolean getIsOutermostImpl() { + public boolean getIsOutermostImpl() { return getNestedLevelImpl() == 0; } @@ -135,31 +138,52 @@ public String getRankImpl() { if (rank != null) { return rank; } - rank = RankCalculator.calculateString(node, CtLoop.class); + rank = RankCalculator.calculateString(getNodeImpl(), CtLoop.class); return rank; } @Override - public Integer getNestedLevelImpl() { + public int getNestedLevelImpl() { if (nestedLevel != null) { return nestedLevel; } - CtElement parent = node.getParent(); - nestedLevel = 0; + CtElement parent = getNodeImpl().getParent(); + int level = 0; while (parent != null && !(parent instanceof CtAnonymousExecutable) && !(parent instanceof CtExecutable)) { - // System.out.println(parent); if (parent instanceof CtLoop) { - nestedLevel++; + level++; } parent = parent.getParent(); } - return nestedLevel; + nestedLevel = level; + return level; } @Override public String getControlVarImpl() { - KadabraLog.warning("Control variable can only be retrieved from 'for' loops"); + weaver.kadabra.util.KadabraLog.warning("Control variable can only be retrieved from 'for' loops"); return null; } + + @Override + public AExpression getCondImpl() { + // Only concrete loop subtypes (e.g., 'for', 'while') have a condition + return null; + } + + @Override + public AField tileImpl(String tileName, String block, boolean unique, AJoinpoint around) { + throw new RuntimeException("The tile action can only be applied to 'for' loops"); + } + + @Override + public void tileImpl(int block) { + throw new RuntimeException("The tile action can only be applied to 'for' loops"); + } + + @Override + public void interchangeImpl(ALoop loop2) { + throw new RuntimeException("The interchange action can only be applied to 'for' loops"); + } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JMethod.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JMethod.java index 4e46c57e..6ab35814 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JMethod.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JMethod.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. @@ -15,7 +15,7 @@ import java.util.Set; -import org.lara.interpreter.weaver.interf.JoinPoint; +import org.lara.interpreter.weaver.interf.enums.InsertPosition; import spoon.refactoring.Refactoring; import spoon.reflect.declaration.CtMethod; @@ -23,10 +23,9 @@ import spoon.reflect.declaration.CtType; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.factory.Factory; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AClass; -import weaver.kadabra.abstracts.joinpoints.AJoinPoint; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.abstracts.joinpoints.AMethod; import weaver.kadabra.spoon.extensions.nodes.CtKadabraSnippetElement; import weaver.utils.SpoonUtils; @@ -36,23 +35,16 @@ import weaver.utils.weaving.TypeUtils; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JMethod extends AMethod { +public class JMethod> extends AMethod { - private final CtMethod node; - - private JMethod(CtMethod node, JavaWeaver weaver) { - super(JExecutable.newInstance(node, weaver), weaver); - this.node = node; - } - - public static JMethod newInstance(CtMethod node, JavaWeaver weaver) { - return new JMethod<>(node, weaver); + public JMethod(CtMethod node, JWeaver weaver) { + super(node, weaver); } @Override - public AJoinPoint copyImpl() { + public AJoinpoint copyImpl() { var methodName = getNameImpl(); - var copy = Refactoring.copyMethod(node); + var copy = Refactoring.copyMethod((CtMethod) getNodeImpl()); // Refactor method changes the name of the method, appends copy at the end. // Restore original name copy.setSimpleName(methodName); @@ -60,81 +52,81 @@ public AJoinPoint copyImpl() { } @Override - public String toString() { + public String getToStringImpl() { return getNameImpl(); } @Override - public CtMethod getNode() { - return node; + public CtMethod getNodeImpl() { + return (CtMethod) super.getNodeImpl(); } @Override public String getToReferenceImpl() { - return node.getDeclaringType().getSimpleName() + "::" + node.getSimpleName(); + return getNodeImpl().getDeclaringType().getSimpleName() + "::" + getNodeImpl().getSimpleName(); } @Override public String getToQualifiedReferenceImpl() { - return node.getDeclaringType().getQualifiedName() + "::" + node.getSimpleName(); + return getNodeImpl().getDeclaringType().getQualifiedName() + "::" + getNodeImpl().getSimpleName(); } @Override - public JMethod cloneImpl(String newName) { + public AMethod cloneImpl(String newName) { - CtMethod clone = ActionUtils.cloneElement(node); - CtType ancestor = SpoonUtils.getAncestor(node, CtType.class); + CtMethod clone = ActionUtils.cloneElement(getNodeImpl()); + CtType ancestor = SpoonUtils.getAncestor(getNodeImpl(), CtType.class); int inc = 0; while (!ancestor.getMethodsByName(newName).isEmpty()) { newName = newName + (inc++); } clone.setSimpleName(newName); ancestor.addMethod(clone); - JMethod newInstance = JMethod.newInstance(clone, getWeaverEngine()); - return newInstance; + return new JMethod<>(clone, getWeaverEngine()); } @Override public void addCommentImpl(String comment) { - String docComment = node.getDocComment(); + String docComment = getNodeImpl().getDocComment(); if (docComment == null || docComment.isEmpty()) { docComment = comment; } else { docComment += "\n" + comment; } - node.setDocComment(docComment); + getNodeImpl().setDocComment(docComment); } @Override public void addParameterImpl(String type, String name) { - Factory factory = node.getFactory(); + Factory factory = getNodeImpl().getFactory(); CtParameter parameter = factory.Core().createParameter(); parameter.setType(TypeUtils.typeOf(type, factory)); parameter.setSimpleName(name); - node.addParameter(parameter); + getNodeImpl().addParameter(parameter); } @Override - public AClass createAdapterImpl(AMethod adaptMethod, String name) { + public AClass createAdapterImpl(AMethod adaptMethod, String name) { return createAdapterImpl(adaptMethod, name, false); } - public AClass createAdapterImpl(AMethod adaptMethod, String name, boolean reuseIfExists) { + public AClass createAdapterImpl(AMethod adaptMethod, String name, boolean reuseIfExists) { JMethod jMethod = (JMethod) adaptMethod; - CtMethod adaptMethodNode = jMethod.getNode(); - JClass jClass = AdapterGenerator.generate(getWeaverEngine(), name, adaptMethodNode, node, reuseIfExists); + CtMethod adaptMethodNode = jMethod.getNodeImpl(); + JClass jClass = AdapterGenerator.generate(getWeaverEngine(), name, adaptMethodNode, getNodeImpl(), + reuseIfExists); return jClass; } @Override public String getDeclaratorImpl() { - return node.getDeclaringType().getQualifiedName(); + return getNodeImpl().getDeclaringType().getQualifiedName(); } @Override public String getPrivacyImpl() { - Set modifiers = node.getModifiers(); + Set modifiers = getNodeImpl().getModifiers(); if (modifiers.contains(ModifierKind.PRIVATE)) { return "private"; } @@ -149,52 +141,53 @@ public String getPrivacyImpl() { @Override public void setPrivacyImpl(String value) { - node.addModifier(ModifierKind.valueOf(value.toString())); + getNodeImpl().addModifier(ModifierKind.valueOf(value.toString())); } @Override - public AJoinPoint[] insertImpl(String position, String code) { - return new AJoinPoint[] { insertImplJMethod(position, code) }; + public AJoinpoint[] insertImpl(InsertPosition position, String code) { + return new AJoinpoint[] { insertImplJMethod(position, code) }; } @Override - public AJoinPoint[] insertImpl(String position, JoinPoint code) { - return new AJoinPoint[] { insertImplJMethod(position, (AJoinPoint) code) }; + public AJoinpoint[] insertImpl(InsertPosition position, AJoinpoint code) { + return new AJoinpoint[] { insertImplJMethod(position, code) }; } - public AJavaWeaverJoinPoint insertImplJMethod(String position, String code) { - Factory factory = getNode().getFactory(); + public AJoinpoint insertImplJMethod(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 insertImplJMethod(String position, AJoinPoint code) { - return ActionUtils.insertMember(node, code.getNode(), position, getWeaverEngine()); + public AJoinpoint insertImplJMethod(InsertPosition position, AJoinpoint code) { + return ActionUtils.insertMember(getNodeImpl(), code.getNodeImpl(), position.name().toLowerCase(), + getWeaverEngine()); } @Override - public AJoinPoint insertAfterImpl(String code) { - return insertImplJMethod("after", code); + public AJoinpoint insertAfterImpl(String code) { + return insertImplJMethod(InsertPosition.AFTER, code); } @Override - public AJoinPoint insertBeforeImpl(String code) { - return insertImplJMethod("before", code); + public AJoinpoint insertBeforeImpl(String code) { + return insertImplJMethod(InsertPosition.BEFORE, code); } @Override - public AJoinPoint insertReplaceImpl(String code) { - return insertImplJMethod("replace", code); + public AJoinpoint insertReplaceImpl(String code) { + return insertImplJMethod(InsertPosition.REPLACE, code); } @Override - public AJoinPoint insertReplaceImpl(AJoinPoint jp) { - return insertImplJMethod("replace", jp); + public AJoinpoint insertReplaceImpl(AJoinpoint jp) { + return insertImplJMethod(InsertPosition.REPLACE, jp); } @Override - public Boolean isOverridingImpl(AMethod method) { - return node.isOverriding((CtMethod) method.getNode()); + public boolean getIsOverridingImpl(AMethod method) { + return getNodeImpl().isOverriding((CtMethod) method.getNodeImpl()); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JNamedType.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JNamedType.java index 0eacb096..8f9531b7 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JNamedType.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JNamedType.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. @@ -17,24 +17,19 @@ import com.google.common.reflect.ClassPath.ClassInfo; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ANamedType; -public class JNamedType extends ANamedType { +public class JNamedType> extends ANamedType { - private ClassInfo info; + private final ClassInfo info; private Class libClass; - private JNamedType(ClassInfo info, JavaWeaver weaver) { - super(weaver); + public JNamedType(ClassInfo info, JWeaver weaver) { + super((spoon.reflect.declaration.CtElement) null, weaver); this.info = info; } - public static JNamedType newInstance(ClassInfo info, JavaWeaver weaver) { - return new JNamedType(info, weaver); - } - @Override public String getNameImpl() { return info.getSimpleName(); @@ -56,7 +51,7 @@ public String getPackageNameImpl() { } @Override - public String[] getInterfacesArrayImpl() { + public String[] getInterfacesImpl() { Class[] interfaces = getLibClass().getInterfaces(); return Arrays.stream(interfaces).map(i -> i.getName()).toArray(String[]::new); } @@ -68,13 +63,13 @@ public String getJavadocImpl() { } @Override - public Boolean isSubtypeOfImpl(String type) { + public Boolean getIsSubtypeOfImpl(String type) { // TODO Auto-generated method stub return null; } @Override - public CtElement getNode() { + public spoon.reflect.declaration.CtElement getNodeImpl() { // TODO Auto-generated method stub return null; } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JNew.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JNew.java index c4570a39..10e96e72 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JNew.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JNew.java @@ -1,11 +1,11 @@ /** * Copyright 2019 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. @@ -17,51 +17,42 @@ import spoon.reflect.code.CtConstructorCall; import spoon.reflect.code.CtExpression; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.abstracts.joinpoints.ANew; import weaver.utils.weaving.SelectUtils; -public class JNew extends ANew { - - private final CtConstructorCall constructorCall; - - public JNew(CtConstructorCall constructorCall, JavaWeaver weaver) { - super(new JExpression<>(constructorCall, weaver), weaver); - - this.constructorCall = constructorCall; - } +public class JNew> extends ANew { - public static JNew newInstance(CtConstructorCall node, JavaWeaver weaver) { - return new JNew<>(node, weaver); + public JNew(CtConstructorCall node, JWeaver weaver) { + super(node, weaver); } @Override - public CtElement getNode() { - return constructorCall; + public CtConstructorCall getNodeImpl() { + return (CtConstructorCall) super.getNodeImpl(); } @Override public String getNameImpl() { - return constructorCall.getExecutable().getSimpleName(); + return getNodeImpl().getExecutable().getSimpleName(); } @Override - public AExpression[] getArgumentsArrayImpl() { - return SelectUtils.nodeList2JoinPointList(constructorCall.getArguments(), - arg -> JExpression.newInstance(arg, - getWeaverEngine())) + public AExpression[] getArgumentsImpl() { + return SelectUtils.nodeList2JoinPointList(getNodeImpl().getArguments(), + arg -> JExpression.newInstance(arg, getWeaverEngine())) .toArray(new AExpression[0]); } @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()); } - constructorCall.setArguments(newArgs); + getNodeImpl().setArguments(newArgs); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JOpAssignment.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JOpAssignment.java index 098f8d94..9502e0f6 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JOpAssignment.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JOpAssignment.java @@ -1,11 +1,11 @@ /** * Copyright 2023 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,29 +14,27 @@ package weaver.kadabra.joinpoints; import pt.up.fe.specs.util.SpecsLogs; + import spoon.reflect.code.CtOperatorAssignment; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AOpAssignment; import weaver.utils.element.OperatorUtils; -public class JOpAssignment extends AOpAssignment { - - private final CtOperatorAssignment node; +public class JOpAssignment> extends AOpAssignment { - public JOpAssignment(CtOperatorAssignment node, JavaWeaver weaver) { - super(new JAssignment<>(node, weaver), weaver); - this.node = node; + public JOpAssignment(CtOperatorAssignment node, JWeaver weaver) { + super(node, weaver); } @Override - public CtElement getNode() { - return node; + public CtOperatorAssignment getNodeImpl() { + return (CtOperatorAssignment) super.getNodeImpl(); } @Override public String getOperatorImpl() { - return OperatorUtils.convert(node.getKind()) + "="; + return OperatorUtils.convert(getNodeImpl().getKind()) + "="; } @Override @@ -57,7 +55,7 @@ public void setOperatorImpl(String operator) { return; } - node.setKind(kind); + getNodeImpl().setKind(kind); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JOpAssignmentAux.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JOpAssignmentAux.java deleted file mode 100644 index eb72aa24..00000000 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JOpAssignmentAux.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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. - */ - -package weaver.kadabra.joinpoints; - -import spoon.reflect.code.CtOperatorAssignment; -import weaver.kadabra.JavaWeaver; -import weaver.utils.element.OperatorUtils; - -public class JOpAssignmentAux extends JAssignment { - - private final CtOperatorAssignment node; - - private JOpAssignmentAux(CtOperatorAssignment node, JavaWeaver weaver) { - super(node, weaver); - this.node = node; - } - - public static JOpAssignmentAux newInstance(CtOperatorAssignment node, - JavaWeaver weaver) { - return new JOpAssignmentAux<>(node, weaver); - } - - @Override - public String getOperatorImpl() { - return OperatorUtils.convert(node.getKind()) + "="; - } - -} diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JPragma.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JPragma.java index c6fdbc6e..3984dbce 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JPragma.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JPragma.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. @@ -17,30 +17,23 @@ import java.util.regex.Pattern; import spoon.reflect.code.CtComment; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AComment; import weaver.kadabra.abstracts.joinpoints.APragma; import weaver.kadabra.enums.CommentType; -public class JPragma extends APragma { - - private final CtComment comment; +public class JPragma> extends APragma { - public JPragma(CtComment comment, JavaWeaver weaver) { - super(JComment.newInstance(comment, weaver), weaver); - this.comment = comment; - } + private static String PRAGMA_NAME_REGEX = "@(\\S+)"; + private static final Pattern PRAGMA_REGEX = Pattern.compile(PRAGMA_NAME_REGEX); - public JPragma(JComment comment, JavaWeaver weaver) { + public JPragma(CtComment comment, JWeaver weaver) { super(comment, weaver); - this.comment = comment.getNode(); - } - - public static JPragma newInstance(CtComment comment, JavaWeaver weaver) { - return new JPragma(comment, weaver); } - public static JPragma newInstance(JComment comment, JavaWeaver weaver) { - return new JPragma(comment, weaver); + public JPragma(JComment comment, JWeaver weaver) { + this(comment.getNodeImpl(), weaver); } @Override @@ -54,7 +47,7 @@ public String getContentImpl() { } private String extractName() { - String content = comment.getContent(); + String content = getNodeImpl().getContent(); Matcher matcher = PRAGMA_REGEX.matcher(content); if (matcher.find()) { return matcher.group(1); @@ -63,25 +56,21 @@ private String extractName() { } private String extractContent() { - String content = comment.getContent(); + String content = getNodeImpl().getContent(); return content.replaceFirst(PRAGMA_NAME_REGEX, "").trim(); } @Override - public CtComment getNode() { - return comment; + public CtComment getNodeImpl() { + return (CtComment) super.getNodeImpl(); } @Override - public String getTypeImpl() { + public CommentType getTypeImpl() { - return CommentType.PRAGMA.getName(); + return CommentType.PRAGMA; } - // private static String PRAGMA_NAME_REGEX = "\\/\\/\\s+\\@(\\S+)\\s+"; - private static String PRAGMA_NAME_REGEX = "@(\\S+)"; - private static final Pattern PRAGMA_REGEX = Pattern.compile(PRAGMA_NAME_REGEX); - public static boolean isPragma(CtComment comment) { if (!comment.getCommentType().equals(spoon.reflect.code.CtComment.CommentType.INLINE)) { return false; diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JReference.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JReference.java index 361c6423..43138dee 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JReference.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JReference.java @@ -1,11 +1,11 @@ /** * Copyright 2019 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,41 +15,35 @@ import spoon.reflect.declaration.CtElement; import spoon.reflect.reference.CtReference; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.AJoinPoint; + +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.abstracts.joinpoints.AReference; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JReference extends AReference { - - public static JReference newInstance(CtReference node, JavaWeaver weaver) { - return new JReference(node, weaver); - } - - private final CtReference node; +public class JReference> extends AReference { - public JReference(CtReference node, JavaWeaver weaver) { - super(weaver); - this.node = node; + public JReference(CtReference node, JWeaver weaver) { + super(node, weaver); } @Override - public CtElement getNode() { - return node; + public CtReference getNodeImpl() { + return (CtReference) super.getNodeImpl(); } @Override public String getNameImpl() { - if (node == null) { + if (getNodeImpl() == null) { return null; } - return node.getSimpleName(); + return getNodeImpl().getSimpleName(); } @Override - public AJoinPoint getDeclarationImpl() { - var decl = node.getDeclaration(); + public AJoinpoint getDeclarationImpl() { + var decl = getNodeImpl().getDeclaration(); if (decl == null) { return null; } @@ -59,7 +53,7 @@ public AJoinPoint getDeclarationImpl() { @Override public String getTypeImpl() { - String type = node.getClass().getSimpleName(); + String type = getNodeImpl().getClass().getSimpleName(); if (type.startsWith("Ct")) { type = type.substring(2); } @@ -71,7 +65,7 @@ public String getTypeImpl() { } @Override - public String toString() { + public String getToStringImpl() { return getNameImpl() + " - " + getTypeImpl(); } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JReturn.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JReturn.java index 6fd69abc..d85f84b1 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JReturn.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JReturn.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,25 +14,19 @@ package weaver.kadabra.joinpoints; import spoon.reflect.code.CtReturn; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.AReturn; - -public class JReturn extends AReturn { - private final CtReturn node; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AReturn; - public static JReturn newInstance(CtReturn node, JavaWeaver weaver) { - return new JReturn<>(node, weaver); - } +public class JReturn> extends AReturn { - private JReturn(CtReturn node, JavaWeaver weaver) { - super(new JStatement(node, weaver), weaver); - this.node = node; + public JReturn(CtReturn node, JWeaver weaver) { + super(node, weaver); } @Override - public CtReturn getNode() { - return node; + public CtReturn getNodeImpl() { + return (CtReturn) super.getNodeImpl(); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JSnippetExpr.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JSnippetExpr.java index 46bebd8e..9ee857f6 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JSnippetExpr.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JSnippetExpr.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,35 +14,32 @@ package weaver.kadabra.joinpoints; import spoon.reflect.code.CtCodeSnippetExpression; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ASnippetExpr; import weaver.kadabra.spoon.extensions.nodes.CtKadabraSnippetExpression; -public class JSnippetExpr extends ASnippetExpr { - - private CtKadabraSnippetExpression node; +public class JSnippetExpr> extends ASnippetExpr { - private JSnippetExpr(CtKadabraSnippetExpression expr, JavaWeaver weaver) { - super(new JExpression(expr.getOriginal(), weaver), weaver); - this.node = expr; - } + private final CtKadabraSnippetExpression snippetElement; - public static JSnippetExpr newInstance(CtKadabraSnippetExpression expr, JavaWeaver weaver) { - return new JSnippetExpr(expr, weaver); + public JSnippetExpr(CtKadabraSnippetExpression expr, JWeaver weaver) { + super(expr.getOriginal(), weaver); + this.snippetElement = expr; } @Override - public CtCodeSnippetExpression getNode() { - return node.getOriginal(); + public CtCodeSnippetExpression getNodeImpl() { + return snippetElement.getOriginal(); } @Override public void setLineImpl(Integer line) { - node.setLine(line); + snippetElement.setLine(line); } @Override public Integer getLineImpl() { - return node.getLine().orElse(null); + return snippetElement.getLine().orElse(null); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JSnippetStmt.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JSnippetStmt.java index f409df1d..60275fba 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JSnippetStmt.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JSnippetStmt.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,35 +13,31 @@ package weaver.kadabra.joinpoints; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ASnippetStmt; import weaver.kadabra.spoon.extensions.nodes.CtKadabraSnippetStatement; -public class JSnippetStmt extends ASnippetStmt { +public class JSnippetStmt> extends ASnippetStmt { - private CtKadabraSnippetStatement node; + private final CtKadabraSnippetStatement snippetStatement; - private JSnippetStmt(CtKadabraSnippetStatement stmt, JavaWeaver weaver) { - super(new JStatement(stmt, weaver), weaver); - this.node = stmt; - } - - public static JSnippetStmt newInstance(CtKadabraSnippetStatement stmt, JavaWeaver weaver) { - return new JSnippetStmt(stmt, weaver); + public JSnippetStmt(CtKadabraSnippetStatement stmt, JWeaver weaver) { + super(stmt, weaver); + this.snippetStatement = stmt; } @Override - public CtKadabraSnippetStatement getNode() { - return node; + public CtKadabraSnippetStatement getNodeImpl() { + return snippetStatement; } @Override public void setLineImpl(Integer line) { - node.setLine(line); + snippetStatement.setLine(line); } @Override public Integer getLineImpl() { - return node.getLine().orElse(null); + return snippetStatement.getLine().orElse(null); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JStatement.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JStatement.java index 036cd341..921fd93e 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JStatement.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JStatement.java @@ -13,76 +13,73 @@ package weaver.kadabra.joinpoints; -import org.lara.interpreter.weaver.interf.JoinPoint; +import org.lara.interpreter.weaver.interf.enums.InsertPosition; + import spoon.reflect.code.CtStatement; import spoon.reflect.declaration.CtElement; import tdrc.utils.StringUtils; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; -import weaver.kadabra.abstracts.joinpoints.AJoinPoint; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.abstracts.joinpoints.AStatement; import weaver.utils.weaving.ActionUtils; import weaver.utils.weaving.converters.CtStatement2AStatement; -public class JStatement extends AStatement { - - private final CtStatement node; +public class JStatement> extends AStatement { - public JStatement(CtStatement node, JavaWeaver weaver) { - super(weaver); - this.node = node; + public JStatement(CtStatement node, JWeaver weaver) { + super(node, weaver); } - public static AJavaWeaverJoinPoint newInstance(CtStatement node, JavaWeaver weaver) { + public static AJoinpoint newInstance(CtStatement node, JWeaver weaver) { return CtStatement2AStatement.convert(node, weaver); } @Override - public AJoinPoint[] insertImpl(String position, JoinPoint code) { - return new AJoinPoint[] { insertImplJStatement(position, (CtElement) code.getNode()) }; + public AJoinpoint[] insertImpl(InsertPosition position, AJoinpoint code) { + return new AJoinpoint[] { insertImplJStatement(position, (CtElement) code.getNodeImpl()) }; } @Override - public AJoinPoint[] insertImpl(String position, String code) { - return new AJoinPoint[] { insertImplJStatement(position, code) }; + public AJoinpoint[] insertImpl(InsertPosition position, String code) { + return new AJoinpoint[] { insertImplJStatement(position, code) }; } - public AJavaWeaverJoinPoint insertImplJStatement(String position, CtElement code) { - return ActionUtils.insert(position, code, node, getWeaverEngine()); + public AJoinpoint insertImplJStatement(InsertPosition position, CtElement code) { + return ActionUtils.insert(position.name().toLowerCase(), code, getNodeImpl(), getWeaverEngine()); } - public AJavaWeaverJoinPoint insertImplJStatement(String position, String code) { - return ActionUtils.insert(position, code, node, getWeaverEngine()); + public AJoinpoint insertImplJStatement(InsertPosition position, String code) { + return ActionUtils.insert(position.name().toLowerCase(), code, getNodeImpl(), getWeaverEngine()); } @Override - public AJoinPoint insertBeforeImpl(String code) { - return insertImplJStatement("before", code); + public AJoinpoint insertBeforeImpl(String code) { + return insertImplJStatement(InsertPosition.BEFORE, code); } @Override - public AJoinPoint insertAfterImpl(String code) { - return insertImplJStatement("after", code); + public AJoinpoint insertAfterImpl(String code) { + return insertImplJStatement(InsertPosition.AFTER, code); } @Override - public AJoinPoint insertReplaceImpl(String code) { - return insertImplJStatement("replace", code); + public AJoinpoint insertReplaceImpl(String code) { + return insertImplJStatement(InsertPosition.REPLACE, code); } @Override - public CtStatement getNode() { - return node; + public CtStatement getNodeImpl() { + return (CtStatement) super.getNodeImpl(); } @Override - public Integer getEndLineImpl() { - return node.getPosition().getEndLine(); + public int getEndLineImpl() { + return getNodeImpl().getPosition().getEndLine(); } @Override public String getKindImpl() { - String tempType = node.getClass().getSimpleName().replace("Ct", "").replace("Impl", ""); + String tempType = getNodeImpl().getClass().getSimpleName().replace("Ct", "").replace("Impl", ""); return StringUtils.firstCharToLower(tempType); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JSwitch.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JSwitch.java index 7a4e9c22..595b7ebb 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JSwitch.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JSwitch.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,32 +14,26 @@ package weaver.kadabra.joinpoints; import spoon.reflect.code.CtSwitch; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ACase; import weaver.kadabra.abstracts.joinpoints.ASwitch; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JSwitch extends ASwitch { - - private final CtSwitch node; - - private JSwitch(CtSwitch node, JavaWeaver weaver) { - super(new JStatement(node, weaver), weaver); - this.node = node; - } +public class JSwitch> extends ASwitch { - public static JSwitch newInstance(CtSwitch node, JavaWeaver weaver) { - return new JSwitch<>(node, weaver); + public JSwitch(CtSwitch node, JWeaver weaver) { + super(node, weaver); } @Override - public CtSwitch getNode() { - return node; + public CtSwitch getNodeImpl() { + return (CtSwitch) super.getNodeImpl(); } @Override - public ACase[] getCasesArrayImpl() { - return CtElement2JoinPoint.convertList(node.getCases(), getWeaverEngine(), ACase.class); + public ACase[] getCasesImpl() { + return CtElement2JoinPoint.convertList(getNodeImpl().getCases(), getWeaverEngine(), ACase.class); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JTernary.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JTernary.java index 4c9b66fb..0b520574 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JTernary.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JTernary.java @@ -1,11 +1,11 @@ /** * Copyright 2019 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,48 +14,40 @@ package weaver.kadabra.joinpoints; import spoon.reflect.code.CtConditional; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.abstracts.joinpoints.ATernary; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JTernary extends ATernary { - - private final CtConditional conditional; - - public JTernary(CtConditional conditional, JavaWeaver weaver) { - super(new JExpression<>(conditional, weaver), weaver); - - this.conditional = conditional; - } +public class JTernary> extends ATernary { - public static JTernary newInstance(CtConditional node, JavaWeaver weaver) { - return new JTernary<>(node, weaver); + public JTernary(CtConditional node, JWeaver weaver) { + super(node, weaver); } @Override - public CtElement getNode() { - return conditional; + public CtConditional getNodeImpl() { + return (CtConditional) super.getNodeImpl(); } @Override - public AExpression getConditionImpl() { - return (AExpression) CtElement2JoinPoint.convert(conditional.getCondition(), getWeaverEngine()); + public AExpression getConditionImpl() { + return (AExpression) CtElement2JoinPoint.convert(getNodeImpl().getCondition(), getWeaverEngine()); } @Override - public AExpression getCondImpl() { + public AExpression getCondImpl() { return getConditionImpl(); } @Override - public AExpression getThenImpl() { - return (AExpression) CtElement2JoinPoint.convert(conditional.getThenExpression(), getWeaverEngine()); + public AExpression getThenImpl() { + return (AExpression) CtElement2JoinPoint.convert(getNodeImpl().getThenExpression(), getWeaverEngine()); } @Override - public AExpression getElseImpl() { - return (AExpression) CtElement2JoinPoint.convert(conditional.getElseExpression(), getWeaverEngine()); + public AExpression getElseImpl() { + return (AExpression) CtElement2JoinPoint.convert(getNodeImpl().getElseExpression(), getWeaverEngine()); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JThis.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JThis.java index 6db5d18b..03bac2ba 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JThis.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JThis.java @@ -1,11 +1,11 @@ /** * Copyright 2022 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.code.CtThisAccess; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.AThis; - -public class JThis extends AThis { - private final CtThisAccess thisNode; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AThis; - public JThis(CtThisAccess thisNode, JavaWeaver weaver) { - super(new JExpression<>(thisNode, weaver), weaver); +public class JThis> extends AThis { - this.thisNode = thisNode; + public JThis(CtThisAccess node, JWeaver weaver) { + super(node, weaver); } @Override - public CtElement getNode() { - return thisNode; + public CtThisAccess getNodeImpl() { + return (CtThisAccess) super.getNodeImpl(); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JThrow.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JThrow.java index 6c19c745..6f4c12c6 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JThrow.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JThrow.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.CtThrow; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.AThrow; - -public class JThrow extends AThrow { - private final CtThrow node; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AThrow; - private JThrow(CtThrow node, JavaWeaver weaver) { - super(new JStatement(node, weaver), weaver); - this.node = node; - } +public class JThrow> extends AThrow { - public static JThrow newInstance(CtThrow node, JavaWeaver weaver) { - return new JThrow(node, weaver); + public JThrow(CtThrow node, JWeaver weaver) { + super(node, weaver); } @Override - public CtThrow getNode() { - return node; + public CtThrow getNodeImpl() { + return (CtThrow) super.getNodeImpl(); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JTry.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JTry.java index 51cd8a00..27ccf25f 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JTry.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JTry.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,45 +13,37 @@ package weaver.kadabra.joinpoints; -import java.util.stream.Collectors; - import spoon.reflect.code.CtTry; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.ABody; import weaver.kadabra.abstracts.joinpoints.ACatch; import weaver.kadabra.abstracts.joinpoints.ATry; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JTry extends ATry { - - private CtTry node; - - private JTry(CtTry node, JavaWeaver weaver) { - super(new JStatement(node, weaver), weaver); - this.node = node; - } +public class JTry> extends ATry { - public static JTry newInstance(CtTry node, JavaWeaver weaver) { - return new JTry(node, weaver); + public JTry(CtTry node, JWeaver weaver) { + super(node, weaver); } @Override - public CtTry getNode() { - return node; + public CtTry getNodeImpl() { + return (CtTry) 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); } @Override - public ACatch[] getCatchesArrayImpl() { + public ACatch[] getCatchesImpl() { - return node.getCatchers().stream() + return getNodeImpl().getCatchers().stream() .map(catchNode -> CtElement2JoinPoint.convert(catchNode, getWeaverEngine(), ACatch.class)) - .collect(Collectors.toList()) + .collect(java.util.stream.Collectors.toList()) .toArray(new ACatch[0]); } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JType.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JType.java index 7bc57a32..714cb096 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JType.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JType.java @@ -13,53 +13,55 @@ package weaver.kadabra.joinpoints; -import org.lara.interpreter.weaver.interf.JoinPoint; +import java.util.Collections; + +import org.lara.interpreter.weaver.interf.enums.InsertPosition; + import pt.up.fe.specs.util.SpecsLogs; import spoon.refactoring.Refactoring; -import spoon.reflect.declaration.*; -import spoon.reflect.reference.CtTypeReference; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; -import weaver.kadabra.abstracts.joinpoints.*; +import spoon.reflect.declaration.CtClass; +import spoon.reflect.declaration.CtCompilationUnit; +import spoon.reflect.declaration.CtElement; +import spoon.reflect.declaration.CtPackage; +import spoon.reflect.declaration.CtType; +import spoon.reflect.declaration.ModifierKind; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AClass; +import weaver.kadabra.abstracts.joinpoints.AField; +import weaver.kadabra.abstracts.joinpoints.AInterfaceType; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; +import weaver.kadabra.abstracts.joinpoints.AMethod; +import weaver.kadabra.abstracts.joinpoints.AType; +import weaver.kadabra.abstracts.joinpoints.ATypeReference; import weaver.kadabra.exceptions.JavaWeaverException; import weaver.kadabra.spoon.extensions.nodes.CtKadabraSnippetElement; import weaver.utils.SpoonUtils; import weaver.utils.weaving.ActionUtils; import weaver.utils.weaving.SnippetFactory; import weaver.utils.weaving.converters.CtElement2JoinPoint; -import java.util.*; -import java.util.stream.Collectors; -public class JType extends AType { +public class JType> extends AType { - private CtType node; private CtCompilationUnit parent; - private JType(CtType node, CtCompilationUnit parent, JavaWeaver weaver) { - super(weaver); - this.node = node; - this.parent = parent; + public JType(CtType node, JWeaver weaver) { + this(node, node.getPosition().getCompilationUnit(), weaver); } - /** - * @param - * @param node - * @param parent - * @return - */ - public static JType newInstance(CtType node, CtCompilationUnit parent, JavaWeaver weaver) { - return new JType<>(node, parent, weaver); + public JType(CtType node, CtCompilationUnit parent, JWeaver weaver) { + super(node, weaver); + this.parent = parent; } @Override - public AJoinPoint copyImpl() { - return CtElement2JoinPoint.convert(Refactoring.copyType(node), getWeaverEngine()); + public AJoinpoint copyImpl() { + return CtElement2JoinPoint.convert(Refactoring.copyType((CtType) getNodeImpl()), getWeaverEngine()); } @Override public String getSuperClassImpl() { - final CtTypeReference superclass = node.getSuperclass(); + final spoon.reflect.reference.CtTypeReference superclass = getNodeImpl().getSuperclass(); if (superclass == null) { return Object.class.getCanonicalName(); } @@ -69,49 +71,49 @@ public String getSuperClassImpl() { } @Override - public ATypeReference getSuperClassJpImpl() { - final CtTypeReference superclass = node.getSuperclass(); + public ATypeReference getSuperClassJpImpl() { + final spoon.reflect.reference.CtTypeReference superclass = getNodeImpl().getSuperclass(); if (superclass == null) { return null; } - return (ATypeReference) CtElement2JoinPoint.convert(superclass, getWeaverEngine()); + return (ATypeReference) CtElement2JoinPoint.convert(superclass, getWeaverEngine()); } @Override - public String[] getInterfacesArrayImpl() { + public String[] getInterfacesImpl() { - final List els = node.getSuperInterfaces().stream() + final var els = getNodeImpl().getSuperInterfaces().stream() .map(el -> el.getQualifiedName()) - .collect(Collectors.toList()); + .collect(java.util.stream.Collectors.toList()); return els.toArray(new String[0]); } @Override - public AInterfaceType[] getInterfacesTypesArrayImpl() { - var els = node.getSuperInterfaces().stream() + public AInterfaceType[] getInterfacesTypesImpl() { + var els = getNodeImpl().getSuperInterfaces().stream() .map(el -> CtElement2JoinPoint.convert(el, getWeaverEngine(), AInterfaceType.class)) - .collect(Collectors.toList()); + .collect(java.util.stream.Collectors.toList()); return els.toArray(new AInterfaceType[0]); } @Override public String getNameImpl() { - return node.getSimpleName(); + return getNodeImpl().getSimpleName(); } @Override public String getQualifiedNameImpl() { - return node.getQualifiedName(); + return getNodeImpl().getQualifiedName(); } @Override public String getPackageNameImpl() { - CtPackage package1 = node.getPackage(); + CtPackage package1 = getNodeImpl().getPackage(); if (package1 == null) { return ""; } @@ -119,14 +121,14 @@ public String getPackageNameImpl() { } @Override - public void addInterfaceImpl(AInterfaceType newInterface) { - node.addNestedType((CtType) newInterface.getNode()); + public void addInterfaceImpl(AInterfaceType newInterface) { + getNodeImpl().addNestedType((CtType) newInterface.getNodeImpl()); } @Override - public AInterfaceType removeInterfaceImpl(String interfaceName) { + public AInterfaceType removeInterfaceImpl(String interfaceName) { - var interfaceNode = node.getSuperInterfaces().stream() + var interfaceNode = getNodeImpl().getSuperInterfaces().stream() .filter(si -> si.getQualifiedName().equals(interfaceName)) .findFirst() .orElse(null); @@ -136,7 +138,7 @@ public AInterfaceType removeInterfaceImpl(String interfaceName) { return null; } - var success = node.removeSuperInterface(interfaceNode); + var success = getNodeImpl().removeSuperInterface(interfaceNode); if (!success) { SpecsLogs.info("removeInterface: could not remove interface " + interfaceName); @@ -155,27 +157,27 @@ public AInterfaceType removeInterfaceImpl(String interfaceName) { } @Override - public void addClassImpl(AClass newClass) { - node.addNestedType((CtType) newClass.getNode()); + public void addClassImpl(AClass newClass) { + getNodeImpl().addNestedType((CtType) newClass.getNodeImpl()); } @Override - public void addImplementImpl(AInterfaceType _interface) { + public void addImplementImpl(AInterfaceType _interface) { - CtType type = (CtType) _interface.getNode(); - node.addSuperInterface(type.getReference()); + CtType type = (CtType) _interface.getNodeImpl(); + getNodeImpl().addSuperInterface(type.getReference()); } @Override - public AMethod newMethodImpl(String[] modifiers, String returnType, String name, String[] paramLeft, + public AMethod newMethodImpl(String[] modifiers, String returnType, String name, String[] paramLeft, String[] paramRight, String code) { - CtMethod newMethod = ActionUtils.newMethod(node, name, returnType, paramLeft, paramRight, modifiers, code); - JMethod newInstance = JMethod.newInstance(newMethod, getWeaverEngine()); - return newInstance; + spoon.reflect.declaration.CtMethod newMethod = ActionUtils.newMethod(getNodeImpl(), name, returnType, + paramLeft, paramRight, modifiers, code); + return new JMethod<>(newMethod, getWeaverEngine()); } @Override - public AMethod newMethodImpl(String[] modifiers, String returnType, String name, String[] paramLeft, + public AMethod newMethodImpl(String[] modifiers, String returnType, String name, String[] paramLeft, String[] paramRight) { return newMethodImpl(modifiers, returnType, name, paramLeft, paramRight, ""); } @@ -187,25 +189,25 @@ public void insertMethodImpl(String code) { @Override public void insertCodeImpl(String code) { - CtKadabraSnippetElement method = SnippetFactory.createSnippetElement(node.getFactory(), code); - node.addNestedType(method); + CtKadabraSnippetElement method = SnippetFactory.createSnippetElement(getNodeImpl().getFactory(), code); + getNodeImpl().addNestedType(method); } @Override - public AField newFieldImpl(String[] modifiers, String fieldType, String baseName, String initialValue) { - CtField newField = ActionUtils.newField(node, baseName, fieldType, initialValue, modifiers); - JField newInstance = JField.newInstance(newField, getWeaverEngine()); - return newInstance; + public AField newFieldImpl(String[] modifiers, String fieldType, String baseName, String initialValue) { + spoon.reflect.declaration.CtField newField = ActionUtils.newField(getNodeImpl(), baseName, fieldType, + initialValue, modifiers); + return new JField<>(newField, getWeaverEngine()); } @Override - public AField newFieldImpl(String[] modifiers, String fieldType, String baseName) { + public AField newFieldImpl(String[] modifiers, String fieldType, String baseName) { return newFieldImpl(modifiers, fieldType, baseName, null); } @Override public String getJavadocImpl() { - String docComment = node.getDocComment(); + String docComment = getNodeImpl().getDocComment(); return docComment != null ? docComment : ""; } @@ -220,53 +222,54 @@ public static ModifierKind getModifier(String value) { } @Override - public AJoinPoint[] insertImpl(String position, JoinPoint code) { - return new AJoinPoint[] { insertImplJType(position, (CtElement) code.getNode()) }; + public AJoinpoint[] insertImpl(InsertPosition position, AJoinpoint code) { + return new AJoinpoint[] { insertImplJType(position, (CtElement) code.getNodeImpl()) }; } @Override - public AJoinPoint[] insertImpl(String position, String code) { - return new AJoinPoint[] { insertImplJType(position, code) }; + public AJoinpoint[] insertImpl(InsertPosition position, String code) { + return new AJoinpoint[] { insertImplJType(position, code) }; } - public AJavaWeaverJoinPoint insertImplJType(String position, CtElement code) { - return ActionUtils.insertMember(node, code, position, getWeaverEngine()); + public AJoinpoint insertImplJType(InsertPosition position, CtElement code) { + return ActionUtils.insertMember(getNodeImpl(), code, position.name().toLowerCase(), getWeaverEngine()); } - public AJavaWeaverJoinPoint insertImplJType(String position, String code) { - return ActionUtils.insertMember(node, code, position, getWeaverEngine()); + public AJoinpoint insertImplJType(InsertPosition position, String code) { + return ActionUtils.insertMember(getNodeImpl(), code, position.name().toLowerCase(), getWeaverEngine()); } @Override - public AJoinPoint insertBeforeImpl(String code) { - return insertImplJType("before", code); + public AJoinpoint insertBeforeImpl(String code) { + return insertImplJType(InsertPosition.BEFORE, code); } @Override - public AJoinPoint insertAfterImpl(String code) { - return insertImplJType("after", code); + public AJoinpoint insertAfterImpl(String code) { + return insertImplJType(InsertPosition.AFTER, code); } @Override - public AJoinPoint insertReplaceImpl(String code) { - return insertImplJType("replace", code); + public AJoinpoint insertReplaceImpl(String code) { + return insertImplJType(InsertPosition.REPLACE, code); } @Override - public CtType getNode() { - return node; + public CtType getNodeImpl() { + return (CtType) super.getNodeImpl(); } @Override - public Boolean isSubtypeOfImpl(String type) { + public Boolean getIsSubtypeOfImpl(String type) { - return node.isSubtypeOf(SpoonUtils.newCtTypeReference(type, node.getFactory(), Collections.emptyList())); + return getNodeImpl().isSubtypeOf(SpoonUtils.newCtTypeReference(type, getNodeImpl().getFactory(), + Collections.emptyList())); } @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()); diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JTypeReference.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JTypeReference.java index b3903022..c8e7baab 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JTypeReference.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JTypeReference.java @@ -13,45 +13,37 @@ package weaver.kadabra.joinpoints; -import spoon.reflect.declaration.CtElement; +import java.util.Set; + import spoon.reflect.reference.CtTypeReference; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.ATypeReference; -import java.util.Set; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.ATypeReference; -public class JTypeReference extends ATypeReference { +public class JTypeReference> extends ATypeReference { private static final Set NUMERIC_PRIMITIVES = Set.of("byte", "char", "short", "int", "long", "float", "double"); - private final CtTypeReference typeReference; - - public JTypeReference(CtTypeReference typeReference, JavaWeaver weaver) { - super(new JReference(typeReference, weaver), weaver); - - this.typeReference = typeReference; - } - - public static JTypeReference newInstance(CtTypeReference node, JavaWeaver weaver) { - return new JTypeReference<>(node, weaver); + public JTypeReference(CtTypeReference typeReference, JWeaver weaver) { + super(typeReference, weaver); } @Override - public CtElement getNode() { - return typeReference; + public CtTypeReference getNodeImpl() { + return (CtTypeReference) super.getNodeImpl(); } @Override - public Boolean getIsPrimitiveImpl() { - return typeReference.isPrimitive(); + public boolean getIsPrimitiveImpl() { + return getNodeImpl().isPrimitive(); } @Override - public Boolean getIsArrayImpl() { + public boolean getIsArrayImpl() { try { - return typeReference.getActualClass().isArray(); + return getNodeImpl().getActualClass().isArray(); } catch (Exception e) { // Do nothing, sometimes it can launch exception, such as when the type of the // class is not on the classpath @@ -60,21 +52,21 @@ public Boolean getIsArrayImpl() { } @Override - public String toString() { + public String getToStringImpl() { return getNameImpl(); } @Override public String getPackageNameImpl() { - var ctPackage = typeReference.getPackage(); + var ctPackage = getNodeImpl().getPackage(); return ctPackage != null ? ctPackage.getQualifiedName() : null; } @Override - public String[] getPackageNamesArrayImpl() { + public String[] getPackageNamesImpl() { var packageName = getPackageNameImpl(); - return packageName != null ? getPackageNameImpl().split(".") : new String[0]; + return packageName != null ? packageName.split("\\.") : new String[0]; } @Override @@ -94,7 +86,7 @@ public Boolean getIsNumericImpl() { } @Override - public Boolean getIsBooleanImpl() { + public boolean getIsBooleanImpl() { var qualifiedName = getQualifiedNameImpl(); if (getIsPrimitiveImpl()) { @@ -108,6 +100,6 @@ public Boolean getIsBooleanImpl() { public String getQualifiedNameImpl() { var packageName = getPackageNameImpl(); - return packageName != null ? packageName + "." + typeReference.getSimpleName() : typeReference.getSimpleName(); + return packageName != null ? packageName + "." + getNodeImpl().getSimpleName() : getNodeImpl().getSimpleName(); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JUnaryExpression.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JUnaryExpression.java index 6047aa7b..14a2925f 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JUnaryExpression.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JUnaryExpression.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,40 +14,35 @@ package weaver.kadabra.joinpoints; import pt.up.fe.specs.util.SpecsLogs; + import spoon.reflect.code.CtUnaryOperator; import spoon.reflect.code.UnaryOperatorKind; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.abstracts.joinpoints.AUnaryExpression; import weaver.utils.element.OperatorUtils; import weaver.utils.weaving.SelectUtils; -public class JUnaryExpression extends AUnaryExpression { - - public CtUnaryOperator node; - - public JUnaryExpression(CtUnaryOperator expr, JavaWeaver weaver) { - super(new JExpression<>(expr, weaver), weaver); - node = expr; - } +public class JUnaryExpression> extends AUnaryExpression { - public static JUnaryExpression newInstance(CtUnaryOperator expr, JavaWeaver weaver) { - return new JUnaryExpression<>(expr, weaver); + public JUnaryExpression(CtUnaryOperator node, JWeaver weaver) { + super(node, weaver); } @Override public String getOperatorImpl() { - return OperatorUtils.convert(node.getKind()); + return OperatorUtils.convert(getNodeImpl().getKind()); } @Override - public String toString() { - return "Unary Expression: " + node; + public String getToStringImpl() { + return "Unary Expression: " + getNodeImpl(); } @Override - public CtUnaryOperator getNode() { - return node; + public CtUnaryOperator getNodeImpl() { + return (CtUnaryOperator) super.getNodeImpl(); } @Override @@ -60,12 +55,12 @@ public void setOperatorImpl(String operator) { return; } - node.setKind(kind); + getNodeImpl().setKind(kind); } @Override - public AExpression getOperandImpl() { - return SelectUtils.expression2JoinPoint(node.getOperand(), getWeaverEngine()); + public AExpression getOperandImpl() { + return SelectUtils.expression2JoinPoint(getNodeImpl().getOperand(), getWeaverEngine()); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JVar.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JVar.java index 99677e39..a5c77928 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JVar.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JVar.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,82 +13,71 @@ package weaver.kadabra.joinpoints; +import weaver.kadabra.abstracts.joinpoints.AVar; import java.util.Optional; import spoon.reflect.code.CtArrayAccess; import spoon.reflect.code.CtAssignment; -import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtFieldAccess; import spoon.reflect.code.CtLoop; import spoon.reflect.code.CtOperatorAssignment; import spoon.reflect.code.CtUnaryOperator; import spoon.reflect.code.CtVariableAccess; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; -import weaver.kadabra.abstracts.joinpoints.AJoinPoint; + +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.abstracts.joinpoints.ATypeReference; -import weaver.kadabra.abstracts.joinpoints.AVar; import weaver.kadabra.enums.RefType; import weaver.utils.SpoonUtils; import weaver.utils.element.CtTypeReferenceUtils; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JVar extends AVar { - - private final CtVariableAccess node; - - protected JVar(CtVariableAccess var, JavaWeaver weaver) { - super(new JExpression<>(var, weaver), weaver); - node = var; - } +public class JVar> extends AVar { - public static JVar newInstance(CtVariableAccess var, JavaWeaver weaver) { - return new JVar<>(var, weaver); + public JVar(CtVariableAccess node, JWeaver weaver) { + super(node, weaver); } @Override - public String getReferenceImpl() { + public RefType getReferenceImpl() { // TODO - possibly move this to a visit approach - final CtElement parent = node.getParent(); + final spoon.reflect.declaration.CtElement parent = getNodeImpl().getParent(); if (parent instanceof CtOperatorAssignment) { - return RefType.READWRITE.getName(); + return RefType.READWRITE; } - if (parent instanceof CtAssignment) { - CtAssignment par = (CtAssignment) parent; - if (par.getAssigned().equals(node)) { - return RefType.WRITE.getName(); + if (parent instanceof CtAssignment par) { + if (par.getAssigned().equals(getNodeImpl())) { + return RefType.WRITE; } - return RefType.READ.getName(); + return RefType.READ; } if (parent instanceof CtArrayAccess) { if (parent.getParent() instanceof CtAssignment) { final CtArrayAccess arrAccParent = (CtArrayAccess) parent; - final CtExpression target = arrAccParent.getTarget(); - if (target == node) { - return RefType.WRITE.getName(); + final spoon.reflect.code.CtExpression target = arrAccParent.getTarget(); + if (target == getNodeImpl()) { + return RefType.WRITE; } } } - if (parent instanceof CtUnaryOperator) { - final CtUnaryOperator unOp = (CtUnaryOperator) parent; + if (parent instanceof CtUnaryOperator unOp) { switch (unOp.getKind()) { case POSTINC: case POSTDEC: case PREINC: case PREDEC: - return RefType.READWRITE.getName(); + return RefType.READWRITE; default: break; } } - return RefType.READ.getName(); + return RefType.READ; } @Override - public ATypeReference getTypeReferenceImpl() { - return new JTypeReference<>(node.getType(), getWeaverEngine()); + public ATypeReference getTypeReferenceImpl() { + return new JTypeReference<>(getNodeImpl().getType(), getWeaverEngine()); } @Override @@ -97,55 +86,55 @@ 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 String toString() { - return node.toString(); + public String getToStringImpl() { + return getNodeImpl().toString(); } @Override - public Boolean getIsFieldImpl() { - return node instanceof CtFieldAccess; + public boolean getIsFieldImpl() { + return getNodeImpl() instanceof CtFieldAccess; } @Override - public Boolean getInLoopHeaderImpl() { + public boolean getInLoopHeaderImpl() { - Optional ancestor = SpoonUtils.getAncestorTry(node, CtLoop.class); + Optional ancestor = SpoonUtils.getAncestorTry(getNodeImpl(), CtLoop.class); if (!ancestor.isPresent()) { return false; } CtLoop loop = ancestor.get(); - return SpoonUtils.insideHeader(loop, node); + return SpoonUtils.insideHeader(loop, getNodeImpl()); } @Override - public CtVariableAccess getNode() { - return node; + public CtVariableAccess getNodeImpl() { + return (CtVariableAccess) super.getNodeImpl(); } @Override public String getNameImpl() { - return node.getVariable().getSimpleName(); + return getNodeImpl().getVariable().getSimpleName(); } @Override - public AJoinPoint[] getReferenceChainArrayImpl() { - return getChildrenArrayImpl(); + public AJoinpoint[] getReferenceChainImpl() { + return getChildrenImpl(); } @Override - public AJavaWeaverJoinPoint getDeclarationImpl() { - var decl = node.getVariable().getDeclaration(); + public AJoinpoint getDeclarationImpl() { + var decl = getNodeImpl().getVariable().getDeclaration(); if (decl == null) { return null; } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JXmlElement.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JXmlElement.java index 213bde41..3cf61bb0 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JXmlElement.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JXmlElement.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,33 +14,26 @@ package weaver.kadabra.joinpoints; import pt.up.fe.specs.util.xml.XmlElement; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AXmlElement; -public class JXmlElement extends AXmlElement { +public class JXmlElement> extends AXmlElement { private final XmlElement element; - public JXmlElement(XmlElement element, JavaWeaver weaver) { - super(new JXmlNode(element, weaver), weaver); - + public JXmlElement(XmlElement element, JWeaver weaver) { + super(element, weaver); this.element = element; } - @Override - public CtElement getNode() { - // TODO Auto-generated method stub - return null; - } - @Override public String getNameImpl() { return element.getName(); } @Override - public String attributeImpl(String name) { + public String getAttributeImpl(String name) { return element.getAttribute(name); } @@ -50,7 +43,7 @@ public String setAttributeImpl(String name, String value) { } @Override - public String[] getAttributeNamesArrayImpl() { + public String[] getAttributeNamesImpl() { return element.getAttributes().toArray(length -> new String[length]); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JXmlNode.java b/JavaWeaver/src/weaver/kadabra/joinpoints/JXmlNode.java index 4b53110f..a869dc6c 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JXmlNode.java +++ b/JavaWeaver/src/weaver/kadabra/joinpoints/JXmlNode.java @@ -15,58 +15,59 @@ import pt.up.fe.specs.util.xml.XmlElement; import pt.up.fe.specs.util.xml.XmlNode; -import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.AJoinPoint; + +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.abstracts.joinpoints.AXmlElement; import weaver.kadabra.abstracts.joinpoints.AXmlNode; import weaver.utils.weaving.converters.XmlNode2JoinPoint; -public class JXmlNode extends AXmlNode { +public class JXmlNode> extends AXmlNode { private final XmlNode node; - public JXmlNode(XmlNode node, JavaWeaver weaver) { - super(weaver); + public JXmlNode(XmlNode node, JWeaver weaver) { + super((spoon.reflect.declaration.CtElement) null, weaver); this.node = node; } @Override - public CtElement getNode() { + public spoon.reflect.declaration.CtElement getNodeImpl() { + // XML nodes have no Spoon node return null; } @Override - public AJoinPoint getParentImpl() { + public AJoinpoint getParentImpl() { return XmlNode2JoinPoint.convert(node.getParent(), getWeaverEngine()); } @Override - public AJoinPoint[] getChildrenArrayImpl() { + public AJoinpoint[] getChildrenImpl() { return node.getChildren().stream() .map(child -> XmlNode2JoinPoint.convert(child, getWeaverEngine())) - .toArray(length -> new AJoinPoint[length]); + .toArray(length -> new AJoinpoint[length]); } @Override - public AJoinPoint[] getDescendantsArrayImpl() { + public AJoinpoint[] getDescendantsImpl() { return node.getDescendants().stream() .map(child -> XmlNode2JoinPoint.convert(child, getWeaverEngine())) - .toArray(length -> new AJoinPoint[length]); + .toArray(length -> new AJoinpoint[length]); } @Override - public AXmlElement[] getElementsArrayImpl() { + public AXmlElement[] getElementsImpl() { return node.getDescendants().stream() - .filter(node -> node instanceof XmlElement) - .map(element -> (AXmlElement) XmlNode2JoinPoint.convert(element, + .filter(descendant -> descendant instanceof XmlElement) + .map(element -> (AXmlElement) XmlNode2JoinPoint.convert(element, getWeaverEngine())) .toArray(length -> new AXmlElement[length]); } @Override - public AXmlElement[] elementsByNameArrayImpl(String name) { + public AXmlElement[] getElementsByNameImpl(String name) { return node.getElementsByName(name).toArray(length -> new AXmlElement[length]); } diff --git a/JavaWeaver/src/weaver/kadabra/spoon/extensions/nodes/CtKadabraCompilationUnit.java b/JavaWeaver/src/weaver/kadabra/spoon/extensions/nodes/CtKadabraCompilationUnit.java index 243bd017..14e5f099 100644 --- a/JavaWeaver/src/weaver/kadabra/spoon/extensions/nodes/CtKadabraCompilationUnit.java +++ b/JavaWeaver/src/weaver/kadabra/spoon/extensions/nodes/CtKadabraCompilationUnit.java @@ -94,7 +94,7 @@ public String toString() { List> toBePrinted = cu.getDeclaredTypes(); Environment environment = getFactory().getEnvironment(); PrettyPrinter printer = new KadabraPrettyPrinter(environment); - // PrettyPrinter printer = JavaWeaver.getJavaWeaver().getPrinter(); + // PrettyPrinter printer = JWeaver.getJavaWeaver().getPrinter(); printer.calculate(cu, toBePrinted); return printer.getResult(); } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JDoWhile.java b/JavaWeaver/src/weaver/kadabra/subtypes/JDoWhile.java similarity index 54% rename from JavaWeaver/src/weaver/kadabra/joinpoints/JDoWhile.java rename to JavaWeaver/src/weaver/kadabra/subtypes/JDoWhile.java index c06ae136..910a7ffb 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JDoWhile.java +++ b/JavaWeaver/src/weaver/kadabra/subtypes/JDoWhile.java @@ -1,45 +1,47 @@ /** * 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; +package weaver.kadabra.subtypes; import spoon.reflect.code.CtDo; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.enums.LoopType; +import weaver.kadabra.joinpoints.JLoop; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JDoWhile extends JLoop { - - CtDo node; +/** + * Join point of a 'do while' loop. + *

+ * This class lives outside the 'joinpoints' package because it is not a + * declared join point in the specification: the LARA-visible join point is + * 'loop' (represented by JLoop). + */ +public class JDoWhile> extends JLoop { - private JDoWhile(CtDo node, JavaWeaver weaver) { + public JDoWhile(CtDo node, JWeaver weaver) { super(node, LoopType.DOWHILE, weaver); - this.node = node; - } - - public static JDoWhile newInstance(CtDo node, JavaWeaver weaver) { - return new JDoWhile(node, weaver); } @Override - public AExpression getCondImpl() { - return CtElement2JoinPoint.convert(node.getLoopingExpression(), getWeaverEngine(), AExpression.class); + public AExpression getCondImpl() { + return CtElement2JoinPoint.convert(getNodeImpl().getLoopingExpression(), getWeaverEngine(), AExpression.class); } @Override - public CtDo getNode() { - return node; + public CtDo getNodeImpl() { + return (CtDo) super.getNodeImpl(); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JExpressionStatement.java b/JavaWeaver/src/weaver/kadabra/subtypes/JExpressionStatement.java similarity index 68% rename from JavaWeaver/src/weaver/kadabra/joinpoints/JExpressionStatement.java rename to JavaWeaver/src/weaver/kadabra/subtypes/JExpressionStatement.java index 64d9ba60..0bbcab7c 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JExpressionStatement.java +++ b/JavaWeaver/src/weaver/kadabra/subtypes/JExpressionStatement.java @@ -11,28 +11,26 @@ * specific language governing permissions and limitations under the License. */ -package weaver.kadabra.joinpoints; +package weaver.kadabra.subtypes; -import spoon.reflect.code.CtStatement; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; +import weaver.kadabra.joinpoints.JStatement; /** * This class encapsulates expressions that can also be a statement, such as * Invocations (JCall/CtInvocation) and Assignment (JAssignment/CtAssignment). - * - * @author tiago + *

+ * This class lives outside the 'joinpoints' package because it is not a + * declared join point in the specification. * + * @author tiago */ -public class JExpressionStatement extends JStatement { +public class JExpressionStatement> extends JStatement { - public JExpressionStatement(CtStatement node, JavaWeaver weaver) { + public JExpressionStatement(spoon.reflect.code.CtStatement node, JWeaver weaver) { super(node, weaver); } - public static JExpressionStatement newInstance(CtStatement node, JavaWeaver weaver) { - return new JExpressionStatement(node, weaver); - } - @Override public String getKindImpl() { return "expressionStatement"; diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JFor.java b/JavaWeaver/src/weaver/kadabra/subtypes/JFor.java similarity index 52% rename from JavaWeaver/src/weaver/kadabra/joinpoints/JFor.java rename to JavaWeaver/src/weaver/kadabra/subtypes/JFor.java index 4ecfb298..ea5682fa 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JFor.java +++ b/JavaWeaver/src/weaver/kadabra/subtypes/JFor.java @@ -1,17 +1,17 @@ /** * 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; +package weaver.kadabra.subtypes; import java.util.ArrayList; import java.util.List; @@ -19,38 +19,37 @@ import spoon.reflect.code.CtExpression; import spoon.reflect.code.CtFor; import spoon.reflect.code.CtLocalVariable; -import spoon.reflect.code.CtStatement; -import spoon.reflect.declaration.CtElement; -import spoon.reflect.declaration.CtField; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.abstracts.joinpoints.AField; -import weaver.kadabra.abstracts.joinpoints.AJoinPoint; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.abstracts.joinpoints.ALoop; import weaver.kadabra.enums.LoopType; import weaver.kadabra.exceptions.JavaWeaverException; +import weaver.kadabra.joinpoints.JField; +import weaver.kadabra.joinpoints.JLoop; import weaver.utils.SpoonUtils; import weaver.utils.transformations.LoopTiling; import weaver.utils.weaving.AttributeUtils; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JFor extends JLoop { - - CtFor node; +/** + * Join point of a 'for' loop. + *

+ * This class lives outside the 'joinpoints' package because it is not a + * declared join point in the specification: the LARA-visible join point is + * 'loop' (represented by JLoop). + */ +public class JFor> extends JLoop { - private JFor(CtFor node, JavaWeaver weaver) { + public JFor(CtFor node, JWeaver weaver) { super(node, LoopType.FOR, weaver); - this.node = node; - } - - public static JFor newInstance(CtFor node, JavaWeaver weaver) { - return new JFor(node, weaver); } @Override public String getControlVarImpl() { - CtLocalVariable controlVar = AttributeUtils.getControlVar(node); + CtLocalVariable controlVar = AttributeUtils.getControlVar(getNodeImpl()); if (controlVar == null) { return null; } @@ -59,69 +58,64 @@ public String getControlVarImpl() { /** * Implementation of loop tiling - * - * @param block - * @return */ @Override - public AField tileImpl(String tileName, String block, boolean unique, AJoinPoint around) { - CtStatement aroundStatement; + public AField tileImpl(String tileName, String block, boolean unique, AJoinpoint around) { + spoon.reflect.code.CtStatement aroundStatement; if (around == null) { - aroundStatement = node; + aroundStatement = getNodeImpl(); } else { - Object nodeRef = around.getNode(); - if (!(nodeRef instanceof CtElement)) { + Object nodeRef = around.getNodeImpl(); + if (!(nodeRef instanceof spoon.reflect.declaration.CtElement)) { String ref = nodeRef == null ? null : nodeRef.getClass().toString(); throw new JavaWeaverException("When applying tile action", new RuntimeException("unknown reference for insertion: " + ref)); } - aroundStatement = SpoonUtils.getInsertableParent((CtElement) nodeRef); + aroundStatement = SpoonUtils.getInsertableParent((spoon.reflect.declaration.CtElement) nodeRef); } - CtField tileField = LoopTiling.tile(this, tileName, block, unique, aroundStatement); + spoon.reflect.declaration.CtField tileField = LoopTiling.tile(this, tileName, block, unique, + aroundStatement); if (tileField == null) { return null; } // invalidate current rank rank = null; - JField newInstance = JField.newInstance(tileField, getWeaverEngine()); - return newInstance; + return new JField<>(tileField, getWeaverEngine()); } @Override public void tileImpl(int block) { - LoopTiling.tile(node, block); + LoopTiling.tile(getNodeImpl(), block); } @Override - public AExpression getCondImpl() { - return (AExpression) CtElement2JoinPoint.convert(node.getExpression(), getWeaverEngine()); + public AExpression getCondImpl() { + return (AExpression) CtElement2JoinPoint.convert(getNodeImpl().getExpression(), getWeaverEngine()); } /** * A simple implementation of loop interchange - * - * @param jFor */ @Override - public void interchangeImpl(ALoop jFor) { + public void interchangeImpl(ALoop jFor) { - if (!(jFor instanceof JFor)) { + if (!(jFor instanceof JFor)) { throw new JavaWeaverException("The second Loop for interchange has to be a 'for' loop"); } - JFor jFor2 = (JFor) jFor; - CtFor secondFor = jFor2.node; - List inits = new ArrayList<>(secondFor.getForInit()); + JFor jFor2 = (JFor) jFor; + CtFor secondFor = jFor2.getNodeImpl(); + List inits = new ArrayList<>(secondFor.getForInit()); CtExpression cond = secondFor.getExpression(); - List updates = new ArrayList<>(secondFor.getForUpdate()); + List updates = new ArrayList<>(secondFor.getForUpdate()); - secondFor.setForInit(node.getForInit()); - secondFor.setExpression(node.getExpression()); - secondFor.setForUpdate(node.getForUpdate()); + secondFor.setForInit(getNodeImpl().getForInit()); + secondFor.setExpression(getNodeImpl().getExpression()); + secondFor.setForUpdate(getNodeImpl().getForUpdate()); - node.setForInit(inits); - node.setExpression(cond); - node.setForUpdate(updates); + getNodeImpl().setForInit(inits); + getNodeImpl().setExpression(cond); + getNodeImpl().setForUpdate(updates); // invalidate ranks jFor2.rank = null; @@ -129,7 +123,7 @@ public void interchangeImpl(ALoop jFor) { } @Override - public CtFor getNode() { - return node; + public CtFor getNodeImpl() { + return (CtFor) super.getNodeImpl(); } } diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JForEach.java b/JavaWeaver/src/weaver/kadabra/subtypes/JForEach.java similarity index 65% rename from JavaWeaver/src/weaver/kadabra/joinpoints/JForEach.java rename to JavaWeaver/src/weaver/kadabra/subtypes/JForEach.java index 9a2656b6..5cd5f5d7 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JForEach.java +++ b/JavaWeaver/src/weaver/kadabra/subtypes/JForEach.java @@ -1,39 +1,42 @@ /** * 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; +package weaver.kadabra.subtypes; import pt.up.fe.specs.util.SpecsLogs; + import spoon.reflect.code.CtForEach; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.enums.LoopType; +import weaver.kadabra.joinpoints.JLoop; -public class JForEach extends JLoop { - - CtForEach node; +/** + * Join point of a 'foreach' loop. + *

+ * This class lives outside the 'joinpoints' package because it is not a + * declared join point in the specification: the LARA-visible join point is + * 'loop' (represented by JLoop). + */ +public class JForEach> extends JLoop { - private JForEach(CtForEach node, JavaWeaver weaver) { + public JForEach(CtForEach node, JWeaver weaver) { super(node, LoopType.FOREACH, weaver); - this.node = node; - } - - public static JForEach newInstance(CtForEach node, JavaWeaver weaver) { - return new JForEach(node, weaver); } @Override - public AExpression getCondImpl() { + public AExpression getCondImpl() { SpecsLogs.info( "The foreach loop does not contain a condition. The select 'cond' should only be used in 'for', 'while' and 'do while' loops"); diff --git a/JavaWeaver/src/weaver/kadabra/joinpoints/JWhile.java b/JavaWeaver/src/weaver/kadabra/subtypes/JWhile.java similarity index 54% rename from JavaWeaver/src/weaver/kadabra/joinpoints/JWhile.java rename to JavaWeaver/src/weaver/kadabra/subtypes/JWhile.java index 0e2832d8..588bfb2c 100644 --- a/JavaWeaver/src/weaver/kadabra/joinpoints/JWhile.java +++ b/JavaWeaver/src/weaver/kadabra/subtypes/JWhile.java @@ -1,44 +1,46 @@ /** * 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; +package weaver.kadabra.subtypes; import spoon.reflect.code.CtWhile; -import weaver.kadabra.JavaWeaver; + +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.enums.LoopType; +import weaver.kadabra.joinpoints.JLoop; import weaver.utils.weaving.converters.CtElement2JoinPoint; -public class JWhile extends JLoop { - - CtWhile node; +/** + * Join point of a 'while' loop. + *

+ * This class lives outside the 'joinpoints' package because it is not a + * declared join point in the specification: the LARA-visible join point is + * 'loop' (represented by JLoop). + */ +public class JWhile> extends JLoop { - private JWhile(CtWhile node, JavaWeaver weaver) { + public JWhile(CtWhile node, JWeaver weaver) { super(node, LoopType.WHILE, weaver); - this.node = node; - } - - public static JWhile newInstance(CtWhile node, JavaWeaver weaver) { - return new JWhile(node, weaver); } @Override - public AExpression getCondImpl() { - return (AExpression) CtElement2JoinPoint.convert(node.getLoopingExpression(), getWeaverEngine()); + public AExpression getCondImpl() { + return (AExpression) CtElement2JoinPoint.convert(getNodeImpl().getLoopingExpression(), getWeaverEngine()); } @Override - public CtWhile getNode() { - return node; + public CtWhile getNodeImpl() { + return (CtWhile) super.getNodeImpl(); } } diff --git a/JavaWeaver/src/weaver/specification/JavaWeaverResource.java b/JavaWeaver/src/weaver/specification/JavaWeaverResource.java deleted file mode 100644 index 1a1d7f69..00000000 --- a/JavaWeaver/src/weaver/specification/JavaWeaverResource.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2013 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. - */ - -package weaver.specification; - -import pt.up.fe.specs.util.providers.ResourceProvider; - -/** - * @author Joao Bispo - * - */ -public enum JavaWeaverResource implements ResourceProvider { - JOINPOINTS("joinPointModel.xml"), - ARTIFACTS("artifacts.xml"), - ACTIONS("actionModel.xml"); - - private final String resource; - - private static final String basePackage = "specs/kadabra/"; - - /** - * @param resource - */ - private JavaWeaverResource(String resource) { - this.resource = JavaWeaverResource.basePackage + resource; - } - - /* - * (non-Javadoc) - * - * @see - * pt.up.fe.specs.util.Interfaces.ResourceProvider#getResource() - */ - @Override - public String getResource() { - return resource; - } - -} diff --git a/JavaWeaver/src/weaver/utils/JoinPoints.java b/JavaWeaver/src/weaver/utils/JoinPoints.java index 80c575f0..b4c93836 100644 --- a/JavaWeaver/src/weaver/utils/JoinPoints.java +++ b/JavaWeaver/src/weaver/utils/JoinPoints.java @@ -14,7 +14,7 @@ package weaver.utils; import pt.up.fe.specs.util.utilities.StringLines; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; /** * Utility methods related to join points. @@ -24,18 +24,18 @@ */ public class JoinPoints { - public static String toAst(AJavaWeaverJoinPoint node, String prefix) { + public static String toAst(AJoinpoint node, String prefix) { var builder = new StringBuilder(); toAst(node, prefix, builder); return builder.toString(); } - private static void toAst(AJavaWeaverJoinPoint node, String prefix, + private static void toAst(AJoinpoint node, String prefix, StringBuilder builder) { builder.append(prefix); - builder.append(node.getJoinPointType()); + builder.append(node.get_class()); var nodeString = node.toString(); if (!nodeString.isBlank() && StringLines.getLines(nodeString).size() < 2) { @@ -45,8 +45,8 @@ private static void toAst(AJavaWeaverJoinPoint node, String prefix, } builder.append("\n"); - for (var child : node.getChildrenArrayImpl()) { - toAst((AJavaWeaverJoinPoint) child, prefix + " ", builder); + for (var child : node.getChildrenImpl()) { + toAst((AJoinpoint) child, prefix + " ", builder); } } diff --git a/JavaWeaver/src/weaver/utils/KadabraAstMethods.java b/JavaWeaver/src/weaver/utils/KadabraAstMethods.java index d0198a40..8a3d249b 100644 --- a/JavaWeaver/src/weaver/utils/KadabraAstMethods.java +++ b/JavaWeaver/src/weaver/utils/KadabraAstMethods.java @@ -14,13 +14,13 @@ package weaver.utils; import org.lara.interpreter.weaver.ast.AAstMethods; -import org.lara.interpreter.weaver.interf.JoinPoint; +import org.lara.interpreter.weaver.interf.JoinPoint2; import org.lara.interpreter.weaver.interf.WeaverEngine; import spoon.reflect.code.CtBodyHolder; import spoon.reflect.declaration.CtCompilationUnit; import spoon.reflect.declaration.CtElement; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.utils.weaving.converters.CtElement2JoinPoint; public class KadabraAstMethods extends AAstMethods { @@ -30,8 +30,8 @@ public KadabraAstMethods(WeaverEngine weaverEngine) { } @Override - protected JavaWeaver getWeaverEngine() { - return (JavaWeaver) super.getWeaverEngine(); + protected JWeaver getWeaverEngine() { + return (JWeaver) super.getWeaverEngine(); } @Override @@ -40,7 +40,7 @@ public Class getNodeClass() { } @Override - protected JoinPoint toJavaJoinPointImpl(CtElement node) { + protected JoinPoint2 toJavaJoinPointImpl(CtElement node) { return CtElement2JoinPoint.convert(node, this.getWeaverEngine()); } diff --git a/JavaWeaver/src/weaver/utils/SpoonUtils.java b/JavaWeaver/src/weaver/utils/SpoonUtils.java index 6801b064..e5042032 100644 --- a/JavaWeaver/src/weaver/utils/SpoonUtils.java +++ b/JavaWeaver/src/weaver/utils/SpoonUtils.java @@ -41,8 +41,8 @@ import spoon.reflect.reference.CtLocalVariableReference; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.DefaultJavaPrettyPrinter; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.joinpoints.AJoinPoint; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.exceptions.JavaWeaverException; import weaver.kadabra.spoon.extensions.nodes.CtCommentWrapper; import weaver.kadabra.spoon.extensions.printer.KadabraPrettyPrinter; @@ -247,7 +247,7 @@ public static boolean isExecutable(CtElement node) { } public static CtLocalVariable extract(CtExpression expression, String varName, CtStatement target, - String position, JavaWeaver weaver) { + String position, JWeaver weaver) { Factory factory = expression.getFactory(); CtTypeReference type = expression.getType(); @@ -469,7 +469,7 @@ public static List getChildren(CtElement node) { // System.out.println("IS PARENT: " + node.hasParent(node)); // System.out.println("IS PARENT INITIALIZED: " + node.isParentInitialized()); - // var originalNode = AJavaWeaverJoinPoint.CLONED_NODES.get(node); + // var originalNode = AJoinpoint.CLONED_NODES.get(node); // var nodeToCompare = originalNode == null ? node : originalNode; // return node.getElements(element -> element.getParent() == nodeToCompare); @@ -550,14 +550,14 @@ public static void setModifiers(CtElement node, Set modifiers) { * @param prefix * @return */ - public static String toAst(CtElement astNode, String prefix, JavaWeaver weaver) { + public static String toAst(CtElement astNode, String prefix, JWeaver weaver) { var builder = new StringBuilder(); toAst(CtElement2JoinPoint.convert(astNode, weaver), prefix, builder); return builder.toString(); } /** - * Input is a AJoinPoint node to preserve the child hierarchy returned by the join points. If we simply used + * Input is a AJoinpoint node to preserve the child hierarchy returned by the join points. If we simply used * CtElement and converted to JoinPoint, it would break custom code that uses the same CtElement node for multiple * join points (e.g., JCallStatement). * @@ -565,12 +565,12 @@ public static String toAst(CtElement astNode, String prefix, JavaWeaver weaver) * @param prefix * @param builder */ - private static void toAst(AJoinPoint node, String prefix, + private static void toAst(AJoinpoint node, String prefix, StringBuilder builder) { builder.append(prefix); - builder.append(node.getJoinPointType()); + builder.append(node.get_class()); var nodeString = node.toString(); if (!nodeString.isBlank() && StringLines.getLines(nodeString).size() < 2) { @@ -583,7 +583,7 @@ private static void toAst(AJoinPoint node, String prefix, // for (var child : node.getChildrenNodes()) { // toAst(child, prefix + " ", builder); // } - for (var child : node.getChildrenArrayImpl()) { + for (var child : node.getChildrenImpl()) { toAst(child, prefix + " ", builder); } diff --git a/JavaWeaver/src/weaver/utils/android/AndroidResources.java b/JavaWeaver/src/weaver/utils/android/AndroidResources.java index f4d08408..816ec426 100644 --- a/JavaWeaver/src/weaver/utils/android/AndroidResources.java +++ b/JavaWeaver/src/weaver/utils/android/AndroidResources.java @@ -19,7 +19,7 @@ import pt.up.fe.specs.util.SpecsIo; import pt.up.fe.specs.util.SpecsLogs; import pt.up.fe.specs.util.xml.XmlDocument; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.joinpoints.JXmlNode; /** @@ -83,7 +83,7 @@ public XmlDocument getAndroidManifest() { return this.androidManifest; } - public static JXmlNode parseXml(String xmlCode, JavaWeaver weaver) { + public static JXmlNode parseXml(String xmlCode, JWeaver weaver) { var xmlNode = XmlDocument.newInstance(xmlCode); return new JXmlNode(xmlNode, weaver); } diff --git a/JavaWeaver/src/weaver/utils/generators/AdapterGenerator.java b/JavaWeaver/src/weaver/utils/generators/AdapterGenerator.java index 2c52d2cb..e0b9d6ea 100644 --- a/JavaWeaver/src/weaver/utils/generators/AdapterGenerator.java +++ b/JavaWeaver/src/weaver/utils/generators/AdapterGenerator.java @@ -38,7 +38,7 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtFieldReference; import spoon.reflect.reference.CtTypeReference; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.agent.MethodAdapter; import weaver.kadabra.exceptions.JavaWeaverException; import weaver.kadabra.joinpoints.JClass; @@ -65,7 +65,7 @@ public class AdapterGenerator { * @param targetClass * @return */ - public static JClass generate(JavaWeaver weaver, String name, CtMethod adapterMethod, + public static JClass generate(JWeaver weaver, String name, CtMethod adapterMethod, CtMethod targetMethod, boolean reuseIfExists) { validateTransformerMethod(adapterMethod); @@ -95,7 +95,7 @@ public static JClass generate(JavaWeaver weaver, String name, CtMethod ada } addSuperAdaptInvocation(factory, adaptMethod); - JClass jClass = SelectUtils.node2JoinPoint(mainType, c -> JClass.newInstance(c, cu, weaver)); + JClass jClass = SelectUtils.node2JoinPoint(mainType, c -> new JClass<>(c, cu, weaver)); return jClass; } diff --git a/JavaWeaver/src/weaver/utils/generators/FunctionalClassGenerator.java b/JavaWeaver/src/weaver/utils/generators/FunctionalClassGenerator.java index 641b4932..3c5cf40d 100644 --- a/JavaWeaver/src/weaver/utils/generators/FunctionalClassGenerator.java +++ b/JavaWeaver/src/weaver/utils/generators/FunctionalClassGenerator.java @@ -39,7 +39,7 @@ import spoon.reflect.reference.CtParameterReference; import spoon.reflect.reference.CtTypeReference; import tdrc.utils.StringUtils; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.agent.asm.ASMUtils; import weaver.kadabra.agent.asm.MethodBuilder; import weaver.kadabra.exceptions.JavaWeaverException; @@ -57,7 +57,7 @@ public class FunctionalClassGenerator { * @param newMethodOwner * @return */ - public static JMethod generate(JavaWeaver weaver, CtMethod funcInterfaceMethod, CtMethod methodBuilder, + public static JMethod generate(JWeaver weaver, CtMethod funcInterfaceMethod, CtMethod methodBuilder, CtClass newMethodOwner) { validateTransformerMethod(methodBuilder); @@ -81,7 +81,7 @@ public static JMethod generate(JavaWeaver weaver, CtMethod funcInterfaceMe newMethod.getBody().addStatement(builderVar); newMethod.getBody().addStatement(returnStmt); - return JMethod.newInstance(newMethod, weaver); + return new JMethod<>(newMethod, weaver); } public static CtReturn generateReturnStmt(CtMethod methodBuilder, CtMethod funcInterfaceMethod, diff --git a/JavaWeaver/src/weaver/utils/scanners/NodeConverter.java b/JavaWeaver/src/weaver/utils/scanners/NodeConverter.java index 4d6a278d..30abd92b 100644 --- a/JavaWeaver/src/weaver/utils/scanners/NodeConverter.java +++ b/JavaWeaver/src/weaver/utils/scanners/NodeConverter.java @@ -1,7 +1,7 @@ package weaver.utils.scanners; import spoon.reflect.declaration.CtElement; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; /** * Copyright 2015 SPeCS Research Group. @@ -19,7 +19,7 @@ * the License. under the License. */ @FunctionalInterface -public interface NodeConverter { +public interface NodeConverter> { V toJoinPoint(T e); diff --git a/JavaWeaver/src/weaver/utils/scanners/NodeSearcher.java b/JavaWeaver/src/weaver/utils/scanners/NodeSearcher.java index ffac37cd..105f0bd3 100644 --- a/JavaWeaver/src/weaver/utils/scanners/NodeSearcher.java +++ b/JavaWeaver/src/weaver/utils/scanners/NodeSearcher.java @@ -8,7 +8,7 @@ import spoon.processing.Processor; import spoon.reflect.declaration.CtElement; import spoon.reflect.visitor.CtScanner; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.utils.weaving.SelectUtils; /** @@ -174,12 +174,12 @@ public static List list(Class searchClass, CtElement return elements; } - public static List searchAndConvert(Class searchClass, + public static > List searchAndConvert(Class searchClass, CtElement root, NodeConverter converter) { return searchAndConvert(searchClass, root, converter, Collections.emptyList(), Collections.emptyList()); } - public static List searchAndConvert(Class searchClass, + public static > List searchAndConvert(Class searchClass, CtElement root, NodeConverter converter, Collection> ignore, Collection> prune) { @@ -198,7 +198,7 @@ protected void enter(CtElement e) { super.enter(e); } - // public static List + // public static > List // nodes2JoinPointList(Class searchClass, // Class convertClass, // CtElement root, diff --git a/JavaWeaver/src/weaver/utils/transformations/LoopTiling.java b/JavaWeaver/src/weaver/utils/transformations/LoopTiling.java index 6da931c0..5259702d 100644 --- a/JavaWeaver/src/weaver/utils/transformations/LoopTiling.java +++ b/JavaWeaver/src/weaver/utils/transformations/LoopTiling.java @@ -34,7 +34,7 @@ import spoon.reflect.reference.CtExecutableReference; import spoon.reflect.reference.CtTypeReference; import weaver.kadabra.exceptions.JavaWeaverException; -import weaver.kadabra.joinpoints.JFor; +import weaver.kadabra.subtypes.JFor; import weaver.kadabra.util.KadabraLog; import weaver.utils.SpoonUtils; import weaver.utils.element.RankCalculator; @@ -84,7 +84,7 @@ public static void tile(CtFor ctFor, int block) { */ public static CtField tile(JFor jFor, String tileName, String block, boolean unique, CtStatement aroundStatement) { - CtFor ctFor = jFor.getNode(); + CtFor ctFor = jFor.getNodeImpl(); if (!isTileFriendly(ctFor)) { KadabraLog.warning("Cannot apply tile to loop " + RankCalculator.calculateString(ctFor, CtLoop.class) + ". It is not tile friendly"); @@ -114,7 +114,7 @@ public static CtField tile(JFor jFor, String tileName, String block, bo private static CtField createTileField(JFor jFor, String tileName, String block, boolean unique) { - return SpoonUtils.getAncestorTry(jFor.getNode(), CtType.class) + return SpoonUtils.getAncestorTry(jFor.getNodeImpl(), CtType.class) .map(ancestor -> buildField(jFor, tileName, block, unique, ancestor)) .orElseThrow(LoopTiling::noTypeFound); @@ -138,7 +138,7 @@ private static JavaWeaverException noTypeFound() { private static CtField buildField(JFor jFor, String tileName, String block, boolean unique, CtType ancestor) { String[] mods = { "public", "static" }; - CtFor ctFor = jFor.getNode(); + CtFor ctFor = jFor.getNodeImpl(); CtCodeSnippetExpression initExpr = SnippetFactory .createSnippetExpression(ctFor.getFactory(), block); CtTypeReference intType = ctFor.getFactory().Type().INTEGER_PRIMITIVE; diff --git a/JavaWeaver/src/weaver/utils/weaving/ActionUtils.java b/JavaWeaver/src/weaver/utils/weaving/ActionUtils.java index 8b64eede..1b0a0154 100644 --- a/JavaWeaver/src/weaver/utils/weaving/ActionUtils.java +++ b/JavaWeaver/src/weaver/utils/weaving/ActionUtils.java @@ -25,8 +25,8 @@ import spoon.reflect.factory.Factory; import spoon.reflect.factory.MethodFactory; import spoon.reflect.reference.CtTypeReference; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.exceptions.JavaWeaverException; import weaver.kadabra.spoon.extensions.launcher.JWEnvironment; import weaver.kadabra.spoon.extensions.nodes.CtKadabraSnippetElement; @@ -53,8 +53,8 @@ public static Location getLocation(String location) { } } - public static AJavaWeaverJoinPoint insert(String position, CtElement newElement, - final CtElement node, JavaWeaver weaver) { + public static AJoinpoint insert(String position, CtElement newElement, + final CtElement node, JWeaver weaver) { Location posIntert = Location.valueOf(position.toUpperCase()); if (posIntert.equals(Location.REPLACE) && newElement == null) { @@ -116,7 +116,7 @@ public static AJavaWeaverJoinPoint insert(String position, CtElement newElement, * @param snippetStr the code to inject * @param node the node used as reference for the insertion */ - public static AJavaWeaverJoinPoint insert(String position, String snippetStr, CtElement node, JavaWeaver weaver) { + public static AJoinpoint insert(String position, String snippetStr, CtElement node, JWeaver weaver) { var snippet = snippetStr.trim().isEmpty() ? null : SnippetFactory.createSnippetStatement(snippetStr, node.getFactory()); @@ -128,8 +128,8 @@ public static AJavaWeaverJoinPoint insert(String position, String snippetStr, Ct return insert(position, snippet, node, weaver); } - public static AJavaWeaverJoinPoint replaceExpression(String position, String snippetStr, CtExpression node, - JavaWeaver weaver) { + public static AJoinpoint replaceExpression(String position, String snippetStr, CtExpression node, + JWeaver weaver) { var snippet = snippetStr.trim().isEmpty() ? null : SnippetFactory.createSnippetExpression(node.getFactory(), snippetStr); @@ -142,8 +142,8 @@ public static AJavaWeaverJoinPoint replaceExpression(String position, String return replaceExpression(position, snippet, node, weaver); } - public static AJavaWeaverJoinPoint replaceExpression(String position, CtExpression expression, - CtExpression target, JavaWeaver weaver) { + public static AJoinpoint replaceExpression(String position, CtExpression expression, + CtExpression target, JWeaver weaver) { CtElement snippet = expression; CtElement node = target; @@ -177,8 +177,8 @@ public static AJavaWeaverJoinPoint replaceExpression(String position, CtExpr * @param location * @param weavingProfiler */ - public static AJavaWeaverJoinPoint insertMember(CtElement referenceNode, String codeSnippet, String location, - JavaWeaver weaver) { + public static AJoinpoint insertMember(CtElement referenceNode, String codeSnippet, String location, + JWeaver weaver) { Factory factory = referenceNode.getFactory(); CtKadabraSnippetElement snippet = SnippetFactory.createSnippetElement(factory, codeSnippet); @@ -186,8 +186,8 @@ public static AJavaWeaverJoinPoint insertMember(CtElement referenceNode, String return insertMember(referenceNode, snippet, location, weaver); } - public static AJavaWeaverJoinPoint insertMember(CtElement referenceNode, CtElement snippet, String location, - JavaWeaver weaver) { + public static AJoinpoint insertMember(CtElement referenceNode, CtElement snippet, String location, + JWeaver weaver) { location = location.toUpperCase(); Factory factory = referenceNode.getFactory(); @@ -212,8 +212,8 @@ public static AJavaWeaverJoinPoint insertMember(CtElement referenceNode, CtEleme return CtElement2JoinPoint.convert(snippet, weaver); } - public static AJavaWeaverJoinPoint insertInTable(CtElement referenceNode, String codeSnippet, String location, - JavaWeaver weaver) { + public static AJoinpoint insertInTable(CtElement referenceNode, String codeSnippet, String location, + JWeaver weaver) { location = location.toUpperCase(); Factory factory = referenceNode.getFactory(); @@ -415,7 +415,7 @@ public static N cloneElement(N node) { return node.getFactory().Core().clone(node); } - public static JP cloneJP(N node, + public static > JP cloneJP(N node, NodeConverter converter) { N newNode = node.getFactory().Core().clone(node); return converter.toJoinPoint(newNode); diff --git a/JavaWeaver/src/weaver/utils/weaving/SelectUtils.java b/JavaWeaver/src/weaver/utils/weaving/SelectUtils.java index 96915c70..1d4179de 100644 --- a/JavaWeaver/src/weaver/utils/weaving/SelectUtils.java +++ b/JavaWeaver/src/weaver/utils/weaving/SelectUtils.java @@ -22,8 +22,8 @@ import spoon.reflect.code.CtStatement; import spoon.reflect.code.CtVariableAccess; 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.abstracts.joinpoints.ACall; import weaver.kadabra.abstracts.joinpoints.AExpression; import weaver.kadabra.abstracts.joinpoints.AStatement; @@ -51,7 +51,7 @@ public class SelectUtils { * @param converter * @return */ - public static List select(CtElement startNode, + public static > List select(CtElement startNode, Class searchClass, NodeConverter converter) { return SelectUtils.select(startNode, searchClass, converter, Collections.emptyList(), Collections.emptyList()); @@ -67,7 +67,7 @@ public static List se * @param ignore sub-types that should not be selected * @return */ - public static List select(CtElement startNode, + public static > List select(CtElement startNode, Class searchClass, NodeConverter converter, Collection> ignore, Collection> prune) { return NodeSearcher.searchAndConvert(searchClass, startNode, converter, ignore, prune); @@ -80,7 +80,7 @@ public static List se * @param converter * @return */ - public static List nodeList2JoinPointList( + public static > List nodeList2JoinPointList( Collection elements, NodeConverter converter) { @@ -89,7 +89,7 @@ public static List node return joinPoints; } - public static List node2JoinPointList(T element, + public static > List node2JoinPointList(T element, NodeConverter converter) { final V joinPoint = SelectUtils.node2JoinPoint(element, converter); @@ -99,41 +99,41 @@ public static List node return joinPoints; } - public static List expression2JoinPointList( - CtExpression element, JavaWeaver weaver) { + public static List> expression2JoinPointList( + CtExpression element, JWeaver weaver) { - final AExpression joinPoint = SelectUtils.expression2JoinPoint(element, weaver); - final List joinPoints = SpecsCollections.newArrayList(); + final AExpression joinPoint = SelectUtils.expression2JoinPoint(element, weaver); + final List> joinPoints = SpecsCollections.newArrayList(); joinPoints.add(joinPoint); return joinPoints; } - public static AExpression expression2JoinPoint(CtExpression element, JavaWeaver weaver) { + public static AExpression expression2JoinPoint(CtExpression element, JWeaver weaver) { return JExpression.newInstance(element, weaver); } - public static AJavaWeaverJoinPoint statement2JoinPoint(CtStatement element, JavaWeaver weaver) { - return JStatement.newInstance(element, weaver); + public static AJoinpoint statement2JoinPoint(CtStatement element, JWeaver weaver) { + return new JStatement<>(element, weaver); } - public static V node2JoinPoint(T element, + public static > V node2JoinPoint(T element, NodeConverter converter) { return converter.toJoinPoint(element); } - public static List selectVar(CtStatement node, JavaWeaver weaver) { + public static List selectVar(CtStatement node, JWeaver weaver) { List> ignoreTypes = SpecsCollections.newArrayList(); List> prune = SpecsCollections.newArrayList(); - List select = select(node, CtVariableAccess.class, (var -> JVar.newInstance(var, weaver)), ignoreTypes, + List> select = select(node, CtVariableAccess.class, (var -> new JVar<>(var, weaver)), ignoreTypes, prune); return select; } - public static List selectCall(CtElement node, JavaWeaver weaver) { + public static List selectCall(CtElement node, JWeaver weaver) { final List> calls = SelectUtils.select(node, CtInvocation.class, - (call -> JCall.newInstance(call, weaver))); + (call -> new JCall<>(call, weaver))); // Filter constructors return calls.stream() @@ -141,10 +141,10 @@ public static List selectCall(CtElement node, JavaWeaver weaver .collect(Collectors.toList()); } - public static List selectLibClasses(JApp app) { + public static List> selectLibClasses(JApp app) { Set allClassesInfo = getAllClassesInfo(app); - List libClasses = allClassesInfo.stream() - .map(libClass -> JLibClass.newInstance(libClass, app.getWeaverEngine())) + List> libClasses = allClassesInfo.stream() + .map(libClass -> new JLibClass<>(libClass, app.getWeaverEngine())) .collect(Collectors.toList()); return libClasses; diff --git a/JavaWeaver/src/weaver/utils/weaving/converters/CtElement2JoinPoint.java b/JavaWeaver/src/weaver/utils/weaving/converters/CtElement2JoinPoint.java index bf674466..b43ef744 100644 --- a/JavaWeaver/src/weaver/utils/weaving/converters/CtElement2JoinPoint.java +++ b/JavaWeaver/src/weaver/utils/weaving/converters/CtElement2JoinPoint.java @@ -33,8 +33,8 @@ import spoon.reflect.declaration.CtVariable; import spoon.reflect.reference.CtReference; import spoon.reflect.reference.CtTypeReference; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.joinpoints.JApp; import weaver.kadabra.joinpoints.JBody; import weaver.kadabra.joinpoints.JCatch; @@ -43,7 +43,7 @@ import weaver.kadabra.joinpoints.JEnumValue; import weaver.kadabra.joinpoints.JField; import weaver.kadabra.joinpoints.JFile; -import weaver.kadabra.joinpoints.JGenericJoinPoint; +import weaver.kadabra.joinpoints.JJoinpoint; import weaver.kadabra.joinpoints.JReference; import weaver.kadabra.joinpoints.JTypeReference; import weaver.kadabra.spoon.extensions.nodes.CtApp; @@ -55,18 +55,18 @@ * */ public class CtElement2JoinPoint { - private static final BiFunctionClassMap CONVERTER = new BiFunctionClassMap<>(); + private static final BiFunctionClassMap> CONVERTER = new BiFunctionClassMap<>(); static { // Elements without specific converter CONVERTER.put(CtCatch.class, JCatch::new); - CONVERTER.put(CtBlock.class, JBody::newInstance); - CONVERTER.put(CtEnumValue.class, JEnumValue::newInstance); - CONVERTER.put(CtField.class, JField::newInstance); - CONVERTER.put(CtVariable.class, JDeclaration::newInstance); - CONVERTER.put(CtComment.class, JComment::newInstance); + CONVERTER.put(CtBlock.class, JBody::new); + CONVERTER.put(CtEnumValue.class, JEnumValue::new); + CONVERTER.put(CtField.class, JField::new); + CONVERTER.put(CtVariable.class, JDeclaration::new); + CONVERTER.put(CtComment.class, JComment::new); CONVERTER.put(CtCompilationUnit.class, JFile::new); - CONVERTER.put(CtApp.class, JApp::newInstance); + CONVERTER.put(CtApp.class, JApp::new); // Elements with own converter CONVERTER.put(CtExecutable.class, CtExecutable2AExecutable::convert); @@ -74,17 +74,17 @@ public class CtElement2JoinPoint { CONVERTER.put(CtInvocation.class, CtStatement2AStatement::convert); CONVERTER.put(CtStatement.class, CtStatement2AStatement::convert); CONVERTER.put(CtExpression.class, CtExpression2AExpression::convert); - CONVERTER.put(CtTypeReference.class, JTypeReference::newInstance); - CONVERTER.put(CtReference.class, JReference::newInstance); + CONVERTER.put(CtTypeReference.class, JTypeReference::new); + CONVERTER.put(CtReference.class, JReference::new); CONVERTER.put(CtElement.class, CtElement2JoinPoint::defaultFactory); } - public static AJavaWeaverJoinPoint defaultFactory(CtElement element, JavaWeaver weaver) { - return JGenericJoinPoint.newInstance(element, weaver); + public static AJoinpoint defaultFactory(CtElement element, JWeaver weaver) { + return new JJoinpoint<>(element, weaver); } - public static AJavaWeaverJoinPoint convert(CtElement element, JavaWeaver weaver) { + public static AJoinpoint convert(CtElement element, JWeaver weaver) { if (element == null) { return null; } @@ -92,12 +92,12 @@ public static AJavaWeaverJoinPoint convert(CtElement element, JavaWeaver weaver) return CONVERTER.apply(element, weaver); } - public static T convert(CtElement element, JavaWeaver weaver, Class jpClass) { + public static > T convert(CtElement element, JWeaver weaver, Class jpClass) { var jp = convert(element, weaver); return jpClass.cast(jp); } - public static Optional convertTry(CtElement element, JavaWeaver weaver) { + public static Optional> convertTry(CtElement element, JWeaver weaver) { try { return Optional.ofNullable(CONVERTER.apply(element, weaver)); } catch (Exception e) { @@ -105,8 +105,8 @@ public static Optional convertTry(CtElement element, JavaW } } - public static T[] convertList(List elements, - JavaWeaver weaver, Class jpClass) { + public static > T[] convertList(List elements, + JWeaver weaver, Class jpClass) { @SuppressWarnings("unchecked") T[] jps = (T[]) Array.newInstance(jpClass, elements.size()); diff --git a/JavaWeaver/src/weaver/utils/weaving/converters/CtExecutable2AExecutable.java b/JavaWeaver/src/weaver/utils/weaving/converters/CtExecutable2AExecutable.java index fba496be..c4a64e0d 100644 --- a/JavaWeaver/src/weaver/utils/weaving/converters/CtExecutable2AExecutable.java +++ b/JavaWeaver/src/weaver/utils/weaving/converters/CtExecutable2AExecutable.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. @@ -18,7 +18,7 @@ import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtExecutable; import spoon.reflect.declaration.CtMethod; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExecutable; import weaver.kadabra.joinpoints.JAnonymousExec; import weaver.kadabra.joinpoints.JConstructor; @@ -27,28 +27,28 @@ /** * Converts a given statement to the correct Join point type - * + * * @author tiago * */ public class CtExecutable2AExecutable { - private static final BiFunctionClassMap, JavaWeaver, AExecutable> CONVERTER = new BiFunctionClassMap<>(); + private static final BiFunctionClassMap, JWeaver, AExecutable> CONVERTER = new BiFunctionClassMap<>(); static { - CONVERTER.put(CtMethod.class, JMethod::newInstance); - CONVERTER.put(CtConstructor.class, JConstructor::newInstance); - CONVERTER.put(CtAnonymousExecutable.class, JAnonymousExec::newInstance); + CONVERTER.put(CtMethod.class, JMethod::new); + CONVERTER.put(CtConstructor.class, JConstructor::new); + CONVERTER.put(CtAnonymousExecutable.class, JAnonymousExec::new); CONVERTER.put(CtExecutable.class, CtExecutable2AExecutable::defaultFactory); } - public static AExecutable defaultFactory(CtExecutable element, JavaWeaver weaver) { - return JExecutable.newInstance(element, weaver); + public static AExecutable defaultFactory(CtExecutable element, JWeaver weaver) { + return new JExecutable<>(element, weaver); } // Package protected so only CtElement2JoinPoint can use this method - public static AExecutable convert(CtExecutable element, JavaWeaver weaver) { - AExecutable converted = CONVERTER.apply(element, weaver); + public static AExecutable convert(CtExecutable element, JWeaver weaver) { + AExecutable converted = CONVERTER.apply(element, weaver); return converted; } } diff --git a/JavaWeaver/src/weaver/utils/weaving/converters/CtExpression2AExpression.java b/JavaWeaver/src/weaver/utils/weaving/converters/CtExpression2AExpression.java index f5c37f1e..c9e22f13 100644 --- a/JavaWeaver/src/weaver/utils/weaving/converters/CtExpression2AExpression.java +++ b/JavaWeaver/src/weaver/utils/weaving/converters/CtExpression2AExpression.java @@ -27,9 +27,9 @@ import spoon.reflect.code.CtVariableAccess; import spoon.reflect.declaration.CtAnnotation; import spoon.support.reflect.code.CtCodeSnippetExpressionImpl; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AExpression; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.joinpoints.JAnnotation; import weaver.kadabra.joinpoints.JArrayAccess; import weaver.kadabra.joinpoints.JBinaryExpression; @@ -54,68 +54,66 @@ * */ public class CtExpression2AExpression { - private static final BiFunctionClassMap, JavaWeaver, AExpression> CONVERTER = new BiFunctionClassMap<>(); + private static final BiFunctionClassMap, JWeaver, AExpression> CONVERTER = new BiFunctionClassMap<>(); static { - CONVERTER.put(CtBinaryOperator.class, JBinaryExpression::newInstance); - CONVERTER.put(CtUnaryOperator.class, JUnaryExpression::newInstance); - CONVERTER.put(CtFieldAccess.class, JFieldAccess::newInstance); - CONVERTER.put(CtVariableAccess.class, JVar::newInstance); - CONVERTER.put(CtArrayAccess.class, JArrayAccess::newInstance); - CONVERTER.put(CtLiteral.class, JLiteral::newInstance); - CONVERTER.put(CtConstructorCall.class, JNew::newInstance); - CONVERTER.put(CtConditional.class, JTernary::newInstance); + CONVERTER.put(CtBinaryOperator.class, JBinaryExpression::new); + CONVERTER.put(CtUnaryOperator.class, JUnaryExpression::new); + CONVERTER.put(CtFieldAccess.class, JFieldAccess::new); + CONVERTER.put(CtVariableAccess.class, JVar::new); + CONVERTER.put(CtArrayAccess.class, JArrayAccess::new); + CONVERTER.put(CtLiteral.class, JLiteral::new); + CONVERTER.put(CtConstructorCall.class, JNew::new); + CONVERTER.put(CtConditional.class, JTernary::new); CONVERTER.put(CtAnnotation.class, JAnnotation::new); CONVERTER.put(CtThisAccess.class, JThis::new); CONVERTER.put(CtCodeSnippetExpressionImpl.class, - (ctElement, weaver) -> JSnippetExpr.newInstance(new CtKadabraSnippetExpression(ctElement), - weaver)); + (ctElement, weaver) -> new JSnippetExpr<>(new CtKadabraSnippetExpression<>(ctElement), weaver)); CONVERTER.put(CtExpression.class, CtExpression2AExpression::defaultFactory); } - public static AExpression defaultFactory(CtExpression element, JavaWeaver weaver) { - return JExpression.newInstanceDefault(element, weaver); + public static AExpression defaultFactory(CtExpression element, JWeaver weaver) { + return new JExpression<>(element, weaver); } - private static final BiFunctionClassMap, JavaWeaver, AExpression> CONVERTER_EXPR = new BiFunctionClassMap<>( + private static final BiFunctionClassMap, JWeaver, AExpression> CONVERTER_EXPR = new BiFunctionClassMap<>( CONVERTER); static { - CONVERTER_EXPR.put(CtInvocation.class, JCall::newInstance); + CONVERTER_EXPR.put(CtInvocation.class, JCall::new); } - private static final BiFunctionClassMap, JavaWeaver, AJavaWeaverJoinPoint> CONVERTER_GENERAL = new BiFunctionClassMap<>( + private static final BiFunctionClassMap, JWeaver, AJoinpoint> CONVERTER_GENERAL = new BiFunctionClassMap<>( CONVERTER); static { CONVERTER_GENERAL.put(CtInvocation.class, CtExpression2AExpression::ctInvokation); - // CONVERTER_GENERAL.put(CtInvocation.class, JCall::newInstance); } // Package protected so only CtElement2JoinPoint can use this method - public static AExpression convertToExpression(CtExpression element, JavaWeaver weaver) { + public static AExpression convertToExpression(CtExpression element, JWeaver weaver) { return CONVERTER_EXPR.apply(element, weaver); } /** * Converts the element CtExpression a join point, it does not always return an * AExpression (e.g., super(); is a AStatement) - * + * * @param element * @return */ - public static AJavaWeaverJoinPoint convert(CtExpression element, JavaWeaver weaver) { + public static AJoinpoint convert(CtExpression element, JWeaver weaver) { return CONVERTER_GENERAL.apply(element, weaver); } - public static AJavaWeaverJoinPoint ctInvokation(CtInvocation call, JavaWeaver weaver) { + public static AJoinpoint ctInvokation(CtInvocation call, JWeaver weaver) { // Special case: if call is also a statement, return JCallStatement if (SpoonUtils.isStatementInBlock(call)) { return new JCallStatement<>(call, weaver); } - return JCall.newInstance(call, weaver); + return new JCall<>(call, weaver); } } diff --git a/JavaWeaver/src/weaver/utils/weaving/converters/CtStatement2AStatement.java b/JavaWeaver/src/weaver/utils/weaving/converters/CtStatement2AStatement.java index 304b417b..2f679d92 100644 --- a/JavaWeaver/src/weaver/utils/weaving/converters/CtStatement2AStatement.java +++ b/JavaWeaver/src/weaver/utils/weaving/converters/CtStatement2AStatement.java @@ -31,8 +31,8 @@ import spoon.reflect.code.CtSwitch; import spoon.reflect.code.CtThrow; import spoon.reflect.code.CtTry; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.abstracts.joinpoints.AStatement; import weaver.kadabra.joinpoints.JAssert; import weaver.kadabra.joinpoints.JAssignment; @@ -41,7 +41,6 @@ import weaver.kadabra.joinpoints.JCase; import weaver.kadabra.joinpoints.JComment; import weaver.kadabra.joinpoints.JContinue; -import weaver.kadabra.joinpoints.JExpressionStatement; import weaver.kadabra.joinpoints.JIf; import weaver.kadabra.joinpoints.JLocalVariable; import weaver.kadabra.joinpoints.JLoop; @@ -61,36 +60,35 @@ * */ public class CtStatement2AStatement { - private static final BiFunctionClassMap CONVERTER = new BiFunctionClassMap<>(); + private static final BiFunctionClassMap> CONVERTER = new BiFunctionClassMap<>(); static { CONVERTER.put(CtInvocation.class, CtExpression2AExpression::ctInvokation); - CONVERTER.put(CtAssignment.class, JExpressionStatement::newInstance); - CONVERTER.put(CtIf.class, JIf::newInstance); + CONVERTER.put(CtIf.class, JIf::new); CONVERTER.put(CtLoop.class, JLoop::newInstance); - CONVERTER.put(CtAssignment.class, JAssignment::newInstance); + CONVERTER.put(CtAssignment.class, JAssignment::new); CONVERTER.put(CtOperatorAssignment.class, JOpAssignment::new); - CONVERTER.put(CtReturn.class, JReturn::newInstance); - CONVERTER.put(CtKadabraSnippetStatement.class, JSnippetStmt::newInstance); - CONVERTER.put(CtLocalVariable.class, JLocalVariable::newInstance); - CONVERTER.put(CtTry.class, JTry::newInstance); - CONVERTER.put(CtAssert.class, JAssert::newInstance); - CONVERTER.put(CtComment.class, JComment::newInstance); - CONVERTER.put(CtBlock.class, JBody::newInstance); - CONVERTER.put(CtThrow.class, JThrow::newInstance); - CONVERTER.put(CtSwitch.class, JSwitch::newInstance); - CONVERTER.put(CtCase.class, JCase::newInstance); - CONVERTER.put(CtBreak.class, JBreak::newInstance); - CONVERTER.put(CtContinue.class, JContinue::newInstance); + CONVERTER.put(CtReturn.class, JReturn::new); + CONVERTER.put(CtKadabraSnippetStatement.class, JSnippetStmt::new); + CONVERTER.put(CtLocalVariable.class, JLocalVariable::new); + CONVERTER.put(CtTry.class, JTry::new); + CONVERTER.put(CtAssert.class, JAssert::new); + CONVERTER.put(CtComment.class, JComment::new); + CONVERTER.put(CtBlock.class, JBody::new); + CONVERTER.put(CtThrow.class, JThrow::new); + CONVERTER.put(CtSwitch.class, JSwitch::new); + CONVERTER.put(CtCase.class, JCase::new); + CONVERTER.put(CtBreak.class, JBreak::new); + CONVERTER.put(CtContinue.class, JContinue::new); CONVERTER.put(CtStatement.class, CtStatement2AStatement::defaultFactory); } - public static AStatement defaultFactory(CtStatement element, JavaWeaver weaver) { - return new JStatement(element, weaver); + public static AStatement defaultFactory(CtStatement element, JWeaver weaver) { + return new JStatement<>(element, weaver); } // Package protected so only CtElement2JoinPoint can use this method - public static AJavaWeaverJoinPoint convert(CtStatement element, JavaWeaver weaver) { + public static AJoinpoint convert(CtStatement element, JWeaver weaver) { return CONVERTER.apply(element, weaver); } } diff --git a/JavaWeaver/src/weaver/utils/weaving/converters/CtType2AType.java b/JavaWeaver/src/weaver/utils/weaving/converters/CtType2AType.java index 42432c5e..fa083f96 100644 --- a/JavaWeaver/src/weaver/utils/weaving/converters/CtType2AType.java +++ b/JavaWeaver/src/weaver/utils/weaving/converters/CtType2AType.java @@ -17,7 +17,7 @@ import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtInterface; import spoon.reflect.declaration.CtType; -import weaver.kadabra.JavaWeaver; +import weaver.kadabra.JWeaver; import weaver.kadabra.abstracts.joinpoints.AType; import weaver.kadabra.joinpoints.JClass; import weaver.kadabra.joinpoints.JInterfaceType; @@ -30,20 +30,20 @@ * */ public class CtType2AType { - private static final BiFunctionClassMap, JavaWeaver, AType> CONVERTER = new BiFunctionClassMap<>(); + private static final BiFunctionClassMap, JWeaver, AType> CONVERTER = new BiFunctionClassMap<>(); static { - CONVERTER.put(CtClass.class, JClass::newInstance); - CONVERTER.put(CtInterface.class, JInterfaceType::newInstance); + CONVERTER.put(CtClass.class, JClass::new); + CONVERTER.put(CtInterface.class, JInterfaceType::new); CONVERTER.put(CtType.class, CtType2AType::defaultFactory); } - public static AType defaultFactory(CtType element, JavaWeaver weaver) { - return JType.newInstance(element, null, weaver); + public static AType defaultFactory(CtType element, JWeaver weaver) { + return new JType<>(element, weaver); } // Package protected so only CtElement2JoinPoint can use this method - public static AType convert(CtType element, JavaWeaver weaver) { + public static AType convert(CtType element, JWeaver weaver) { return CONVERTER.apply(element, weaver); } } diff --git a/JavaWeaver/src/weaver/utils/weaving/converters/XmlNode2JoinPoint.java b/JavaWeaver/src/weaver/utils/weaving/converters/XmlNode2JoinPoint.java index 9dd8a7f4..b8387cbf 100644 --- a/JavaWeaver/src/weaver/utils/weaving/converters/XmlNode2JoinPoint.java +++ b/JavaWeaver/src/weaver/utils/weaving/converters/XmlNode2JoinPoint.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. @@ -18,14 +18,14 @@ import pt.up.fe.specs.util.classmap.BiFunctionClassMap; import pt.up.fe.specs.util.xml.XmlElement; import pt.up.fe.specs.util.xml.XmlNode; -import weaver.kadabra.JavaWeaver; -import weaver.kadabra.abstracts.AJavaWeaverJoinPoint; +import weaver.kadabra.JWeaver; +import weaver.kadabra.abstracts.joinpoints.AJoinpoint; import weaver.kadabra.joinpoints.JXmlElement; import weaver.kadabra.joinpoints.JXmlNode; public class XmlNode2JoinPoint { - private static final BiFunctionClassMap CONVERTER; + private static final BiFunctionClassMap> CONVERTER; static { CONVERTER = new BiFunctionClassMap<>(); @@ -34,16 +34,16 @@ public class XmlNode2JoinPoint { CONVERTER.put(XmlNode.class, XmlNode2JoinPoint::defaultFactory); } - public static AJavaWeaverJoinPoint defaultFactory(XmlNode node, JavaWeaver weaver) { + public static AJoinpoint defaultFactory(XmlNode node, JWeaver weaver) { return new JXmlNode(node, weaver); } - public static AJavaWeaverJoinPoint convert(XmlNode node, JavaWeaver weaver) { + public static AJoinpoint convert(XmlNode node, JWeaver weaver) { return CONVERTER.apply(node, weaver); } - public static Optional convertTry(XmlNode node, JavaWeaver weaver) { + public static Optional> convertTry(XmlNode node, JWeaver weaver) { try { return Optional.ofNullable(CONVERTER.apply(node, weaver)); } catch (Exception e) { diff --git a/Kadabra-JS/.gitignore b/Kadabra-JS/.gitignore index 60a7a887..0c0f95d9 100644 --- a/Kadabra-JS/.gitignore +++ b/Kadabra-JS/.gitignore @@ -1,7 +1,6 @@ ##### User-added ##### woven_code/ -/api -/code +mutatedFilesTest/ package-lock.json java-binaries diff --git a/Kadabra-JS/src-api/Joinpoints.ts b/Kadabra-JS/api/Joinpoints.ts similarity index 82% rename from Kadabra-JS/src-api/Joinpoints.ts rename to Kadabra-JS/api/Joinpoints.ts index 4e3e1e3f..59d944a4 100644 --- a/Kadabra-JS/src-api/Joinpoints.ts +++ b/Kadabra-JS/api/Joinpoints.ts @@ -1,5 +1,5 @@ /////////////////////////////////////////////////// -// This file is generated by build-interfaces.js // +// This file is generated by build-interfaces.ts // /////////////////////////////////////////////////// import { @@ -7,118 +7,110 @@ import { registerJoinpointMapper, wrapJoinPoint, unwrapJoinPoint, -} from "@specs-feup/lara/api/LaraJoinPoint.js"; + InsertPosition, +} from "@specs-feup/lara/api/LaraJoinPoint.ts"; type PrivateMapper = { "Joinpoint": typeof Joinpoint, - "NamedType": typeof NamedType, "App": typeof App, - "Catch": typeof Catch, - "Declaration": typeof Declaration, + "LibMethod": typeof LibMethod, + "XmlNode": typeof XmlNode, + "AndroidManifest": typeof AndroidManifest, + "XmlElement": typeof XmlElement, + "FileJp": typeof FileJp, + "NamedType": typeof NamedType, + "Type": typeof Type, + "Class": typeof Class, + "InterfaceType": typeof InterfaceType, "Executable": typeof Executable, + "Method": typeof Method, + "Constructor": typeof Constructor, + "AnonymousExec": typeof AnonymousExec, + "Declaration": typeof Declaration, + "Catch": typeof Catch, + "Statement": typeof Statement, + "CallStatement": typeof CallStatement, + "Assignment": typeof Assignment, + "OpAssignment": typeof OpAssignment, "Expression": typeof Expression, - "Field": typeof Field, - "FileJp": typeof FileJp, - "LibClass": typeof LibClass, - "LibMethod": typeof LibMethod, + "Annotation": typeof Annotation, + "Var": typeof Var, + "FieldAccess": typeof FieldAccess, "Literal": typeof Literal, - "Method": typeof Method, + "Call": typeof Call, "New": typeof New, - "Reference": typeof Reference, - "SnippetExpr": typeof SnippetExpr, - "Statement": typeof Statement, - "Switch": typeof Switch, - "Ternary": typeof Ternary, - "This": typeof This, - "Throw": typeof Throw, - "Try": typeof Try, - "Type": typeof Type, - "TypeReference": typeof TypeReference, + "BinaryExpression": typeof BinaryExpression, "UnaryExpression": typeof UnaryExpression, - "Var": typeof Var, - "XmlNode": typeof XmlNode, - "AndroidManifest": typeof AndroidManifest, - "Annotation": typeof Annotation, - "AnonymousExec": typeof AnonymousExec, + "Ternary": typeof Ternary, "ArrayAccess": typeof ArrayAccess, + "This": typeof This, + "SnippetExpr": typeof SnippetExpr, + "Return": typeof Return, + "Comment": typeof Comment, + "Pragma": typeof Pragma, "Assert": typeof Assert, - "Assignment": typeof Assignment, - "BinaryExpression": typeof BinaryExpression, - "Body": typeof Body, - "Break": typeof Break, - "Call": typeof Call, - "CallStatement": typeof CallStatement, + "Throw": typeof Throw, + "Switch": typeof Switch, "Case": typeof Case, - "Class": typeof Class, - "Comment": typeof Comment, - "Constructor": typeof Constructor, "Continue": typeof Continue, - "Enum": typeof Enum, + "Break": typeof Break, + "SnippetStmt": typeof SnippetStmt, + "Reference": typeof Reference, + "TypeReference": typeof TypeReference, + "LibClass": typeof LibClass, + "Field": typeof Field, "EnumValue": typeof EnumValue, - "FieldAccess": typeof FieldAccess, - "If": typeof If, - "InterfaceType": typeof InterfaceType, + "Body": typeof Body, "LocalVariable": typeof LocalVariable, "Loop": typeof Loop, - "OpAssignment": typeof OpAssignment, - "Pragma": typeof Pragma, - "Return": typeof Return, - "SnippetStmt": typeof SnippetStmt, - "XmlElement": typeof XmlElement, + "If": typeof If, + "Try": typeof Try, }; type DefaultAttributeMap = { + LibMethod: "name", + XmlElement: "name", + FileJp: "name", NamedType: "name", - App: "name", - Declaration: "name", + Type: "name", + Class: "name", + InterfaceType: "name", Executable: "name", - Expression: "exprType", - Field: "name", - FileJp: "name", - LibClass: "name", - LibMethod: "name", - Literal: "value", Method: "name", - New: "name", - Reference: "name", - SnippetExpr: "exprType", - Statement: "kind", - Switch: "kind", - Ternary: "exprType", - This: "exprType", - Throw: "kind", - Try: "kind", - Type: "name", - TypeReference: "name", - UnaryExpression: "operator", - Var: "name", - Annotation: "exprType", + Constructor: "name", AnonymousExec: "name", - ArrayAccess: "name", - Assert: "kind", + Declaration: "name", + Statement: "kind", + CallStatement: "kind", Assignment: "operator", - BinaryExpression: "operator", - Body: "kind", - Break: "kind", + OpAssignment: "operator", + Var: "name", + FieldAccess: "name", + Literal: "value", Call: "name", - CallStatement: "kind", - Case: "kind", - Class: "name", + New: "name", + BinaryExpression: "operator", + UnaryExpression: "operator", + Return: "kind", Comment: "type", - Constructor: "name", + Pragma: "name", + Assert: "kind", + Throw: "kind", + Switch: "kind", + Case: "kind", Continue: "kind", - Enum: "name", + Break: "kind", + SnippetStmt: "kind", + Reference: "name", + TypeReference: "name", + LibClass: "name", + Field: "name", EnumValue: "name", - FieldAccess: "name", - If: "kind", - InterfaceType: "name", + Body: "kind", LocalVariable: "name", Loop: "type", - OpAssignment: "operator", - Pragma: "name", - Return: "kind", - SnippetStmt: "kind", - XmlElement: "name", + If: "kind", + Try: "kind", } export class Joinpoint extends LaraJoinPoint { @@ -131,58 +123,55 @@ export class Joinpoint extends LaraJoinPoint { /** * An array of the annotations of this node */ - get annotations(): Annotation[] { return wrapJoinPoint(this._javaObject.getAnnotations()) } + get annotations(): Annotation[] { return wrapJoinPoint(this._javaObject.annotations()) } /** * A string representation of the AST corresponding to this node */ - get ast(): string { return wrapJoinPoint(this._javaObject.getAst()) } + get ast(): string { return wrapJoinPoint(this._javaObject.ast()) } /** * Alias of attribute 'parent' */ - get astParent(): Joinpoint { return wrapJoinPoint(this._javaObject.getAstParent()) } + get astParent(): Joinpoint { return wrapJoinPoint(this._javaObject.astParent()) } /** - * Returns an array with the children of the node + * The children of this join point, ignoring null nodes */ - get children(): Joinpoint[] { return wrapJoinPoint(this._javaObject.getChildren()) } + get children(): Joinpoint[] { return wrapJoinPoint(this._javaObject.children()) } /** - * The source code corresponding to this join point + * All descendants of this join point */ - get code(): string { return wrapJoinPoint(this._javaObject.getCode()) } - get descendants(): Joinpoint[] { return wrapJoinPoint(this._javaObject.getDescendants()) } + get descendants(): Joinpoint[] { return wrapJoinPoint(this._javaObject.descendants()) } /** * Unique identifier for node */ - get id(): string { return wrapJoinPoint(this._javaObject.getId()) } + get id(): string { return wrapJoinPoint(this._javaObject.id()) } /** * True if this node is considered a block of statements */ - get isBlock(): boolean { return wrapJoinPoint(this._javaObject.getIsBlock()) } + get isBlock(): boolean { return wrapJoinPoint(this._javaObject.isBlock()) } /** * True if this node has the modifier 'final' */ - get isFinal(): boolean { return wrapJoinPoint(this._javaObject.getIsFinal()) } + get isFinal(): boolean { return wrapJoinPoint(this._javaObject.isFinal()) } /** * True if the node is inside a loop header, false otherwise */ - get isInsideLoopHeader(): boolean { return wrapJoinPoint(this._javaObject.getIsInsideLoopHeader()) } + get isInsideLoopHeader(): boolean { return wrapJoinPoint(this._javaObject.isInsideLoopHeader()) } /** * True if this node is considered a statement */ - get isStatement(): boolean { return wrapJoinPoint(this._javaObject.getIsStatement()) } + get isStatement(): boolean { return wrapJoinPoint(this._javaObject.isStatement()) } /** * True if this node has the modifier 'static' */ - get isStatic(): boolean { return wrapJoinPoint(this._javaObject.getIsStatic()) } + get isStatic(): boolean { return wrapJoinPoint(this._javaObject.isStatic()) } /** * Sibling nodes to the left of this node */ - get left(): Joinpoint[] { return wrapJoinPoint(this._javaObject.getLeft()) } - get line(): number { return wrapJoinPoint(this._javaObject.getLine()) } - set line(value: number | string) { this._javaObject.setLine(unwrapJoinPoint(value)); } + get left(): Joinpoint[] { return wrapJoinPoint(this._javaObject.left()) } /** * 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 */ - get modifiers(): string[] { return wrapJoinPoint(this._javaObject.getModifiers()) } + get modifiers(): string[] { return wrapJoinPoint(this._javaObject.modifiers()) } /** * 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 */ @@ -190,79 +179,112 @@ export class Joinpoint extends LaraJoinPoint { /** * Returns the number of children of the node */ - get numChildren(): number { return wrapJoinPoint(this._javaObject.getNumChildren()) } - get parent(): Joinpoint { return wrapJoinPoint(this._javaObject.getParent()) } + get numChildren(): number { return wrapJoinPoint(this._javaObject.numChildren()) } + /** + * Returns the parent node in the AST, or undefined if it is the root node + */ + get parent(): Joinpoint { return wrapJoinPoint(this._javaObject.parent()) } /** * Sibling nodes to the right of this node */ - get right(): Joinpoint[] { return wrapJoinPoint(this._javaObject.getRight()) } + get right(): Joinpoint[] { return wrapJoinPoint(this._javaObject.right()) } + /** + * The root of the tree + */ + get root(): Joinpoint { return wrapJoinPoint(this._javaObject.root()) } + /** + * The scope nodes of this join point + */ + get scopeNodes(): Joinpoint[] { return wrapJoinPoint(this._javaObject.scopeNodes()) } /** * Alias for attribute 'code' */ - get srcCode(): string { return wrapJoinPoint(this._javaObject.getSrcCode()) } + get srcCode(): string { return wrapJoinPoint(this._javaObject.srcCode()) } /** * Returns the child of the node at the given index */ child(index: number): Joinpoint { return wrapJoinPoint(this._javaObject.child(unwrapJoinPoint(index))); } + /** + * Compares this join point with another join point for identity (i.e., whether they represent the same AST node) + */ + compareNodes(aJoinPoint: Joinpoint): boolean { return wrapJoinPoint(this._javaObject.compareNodes(unwrapJoinPoint(aJoinPoint))); } + /** + * Copies the node and returns the copy + */ + copy(): Joinpoint { return wrapJoinPoint(this._javaObject.copy()); } getAncestor(type: string): Joinpoint { return wrapJoinPoint(this._javaObject.getAncestor(unwrapJoinPoint(type))); } /** * True if this node has the given modifier */ hasModifier(modifier: string): boolean { return wrapJoinPoint(this._javaObject.hasModifier(unwrapJoinPoint(modifier))); } - copy(): Joinpoint { return wrapJoinPoint(this._javaObject.copy()); } + insert(position: InsertPosition, code: string): Joinpoint[]; + insert(position: InsertPosition, joinpoint: Joinpoint): Joinpoint[]; + insert(p1: InsertPosition, p2: string | Joinpoint): Joinpoint[] { return wrapJoinPoint(this._javaObject.insert(unwrapJoinPoint(p1), unwrapJoinPoint(p2))); } + /** + * Inserts node after the given node + */ insertAfter(node: Joinpoint): Joinpoint; + /** + * Overload which accepts String + */ insertAfter(code: string): Joinpoint; + /** + * Inserts node after the given node + */ insertAfter(p1: Joinpoint | string): Joinpoint { return wrapJoinPoint(this._javaObject.insertAfter(unwrapJoinPoint(p1))); } + /** + * Inserts node before the given node + */ insertBefore(node: Joinpoint): Joinpoint; + /** + * Overload which accepts String + */ insertBefore(code: string): Joinpoint; + /** + * Inserts node before the given node + */ insertBefore(p1: Joinpoint | string): Joinpoint { return wrapJoinPoint(this._javaObject.insertBefore(unwrapJoinPoint(p1))); } + /** + * Replaces join point with the given node + */ insertReplace(jp: Joinpoint): Joinpoint; + /** + * Overload which accepts String + */ insertReplace(code: string): Joinpoint; - insertReplace(p1: Joinpoint | string): Joinpoint { return wrapJoinPoint(this._javaObject.insertReplace(unwrapJoinPoint(p1))); } - remove(): void { return wrapJoinPoint(this._javaObject.remove()); } - removeAnnotation(annotation: Annotation): void { return wrapJoinPoint(this._javaObject.removeAnnotation(unwrapJoinPoint(annotation))); } - removeModifier(modifier: string): void { return wrapJoinPoint(this._javaObject.removeModifier(unwrapJoinPoint(modifier))); } - replaceWith(jp: Joinpoint): Joinpoint; - replaceWith(code: string): Joinpoint; - replaceWith(p1: Joinpoint | string): Joinpoint { return wrapJoinPoint(this._javaObject.replaceWith(unwrapJoinPoint(p1))); } - setLine(value: number): void; - setLine(value: string): void; - setLine(p1: number | string): void { return wrapJoinPoint(this._javaObject.setLine(unwrapJoinPoint(p1))); } - setModifiers(modifiers: string[]): void { return wrapJoinPoint(this._javaObject.setModifiers(unwrapJoinPoint(modifiers))); } -} - -export class NamedType extends Joinpoint { /** - * @internal + * Replaces join point with the given node */ - static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", - }; + insertReplace(p1: Joinpoint | string): Joinpoint { return wrapJoinPoint(this._javaObject.insertReplace(unwrapJoinPoint(p1))); } /** - * List of names of interfaces that this type implements + * Deletes the node */ - get interfaces(): string[] { return wrapJoinPoint(this._javaObject.getInterfaces()) } - get javadoc(): string { return wrapJoinPoint(this._javaObject.getJavadoc()) } + remove(): void { return wrapJoinPoint(this._javaObject.remove()); } /** - * The simple name of the type + * Removes an annotation */ - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } + removeAnnotation(annotation: Annotation): void { return wrapJoinPoint(this._javaObject.removeAnnotation(unwrapJoinPoint(annotation))); } + removeModifier(modifier: string): void { return wrapJoinPoint(this._javaObject.removeModifier(unwrapJoinPoint(modifier))); } /** - * Package name of this type + * Replaces join point with the given node */ - get packageName(): string { return wrapJoinPoint(this._javaObject.getPackageName()) } + replaceWith(jp: Joinpoint): Joinpoint; /** - * The qualified name of this type, includes packages + * Overload which accepts String */ - get qualifiedName(): string { return wrapJoinPoint(this._javaObject.getQualifiedName()) } + replaceWith(code: string): Joinpoint; /** - * Name of the superclass this type extends + * Replaces join point with the given node */ - get superClass(): string { return wrapJoinPoint(this._javaObject.getSuperClass()) } + replaceWith(p1: Joinpoint | string): Joinpoint { return wrapJoinPoint(this._javaObject.replaceWith(unwrapJoinPoint(p1))); } /** - * Verify if the type is extends OR implements the given type + * Compares this join point with another join point for identity (i.e., whether they represent the same AST node) */ - isSubtypeOf(type: string): boolean { return wrapJoinPoint(this._javaObject.isSubtypeOf(unwrapJoinPoint(type))); } + same(other: Joinpoint): boolean { return wrapJoinPoint(this._javaObject.same(unwrapJoinPoint(other))); } + setLine(value: number): void; + setLine(value: string): void; + setLine(p1: number | string): void { return wrapJoinPoint(this._javaObject.setLine(unwrapJoinPoint(p1))); } + setModifiers(modifiers: string[]): void { return wrapJoinPoint(this._javaObject.setModifiers(unwrapJoinPoint(modifiers))); } } /** @@ -273,12 +295,11 @@ export class App extends Joinpoint { * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", + name: null, }; - get files(): FileJp[] { return wrapJoinPoint(this._javaObject.getFiles()) } - get folder(): string { return wrapJoinPoint(this._javaObject.getFolder()) } - get manifest(): AndroidManifest { return wrapJoinPoint(this._javaObject.getManifest()) } - showAST(Title: string): string { return wrapJoinPoint(this._javaObject.showAST(unwrapJoinPoint(Title))); } + get files(): FileJp[] { return wrapJoinPoint(this._javaObject.files()) } + get folder(): string { return wrapJoinPoint(this._javaObject.folder()) } + get manifest(): AndroidManifest { return wrapJoinPoint(this._javaObject.manifest()) } mapVersions(name: string, keyType: string, interfaceType: InterfaceType, methodName: string): Class { return wrapJoinPoint(this._javaObject.mapVersions(unwrapJoinPoint(name), unwrapJoinPoint(keyType), unwrapJoinPoint(interfaceType), unwrapJoinPoint(methodName))); } newClass(name: string, extend: string, implement: string[]): Class; newClass(name: string): Class; @@ -286,83 +307,71 @@ export class App extends Joinpoint { newInterface(name: string, extend: string[]): InterfaceType; newInterface(name: string): InterfaceType; newInterface(p1: string, p2?: string[]): InterfaceType { return wrapJoinPoint(this._javaObject.newInterface(unwrapJoinPoint(p1), unwrapJoinPoint(p2))); } + showAST(Title: string): string { return wrapJoinPoint(this._javaObject.showAST(unwrapJoinPoint(Title))); } } -export class Catch extends Joinpoint { /** - * @internal + * Method of a class that is part of a library included in the classpath */ - static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: null, - }; - get body(): Body { return wrapJoinPoint(this._javaObject.getBody()) } -} - -export class Declaration extends Joinpoint { +export class LibMethod extends Joinpoint { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - get completeType(): string { return wrapJoinPoint(this._javaObject.getCompleteType()) } - get init(): Expression { return wrapJoinPoint(this._javaObject.getInit()) } - set init(value: Expression) { this._javaObject.setInit(unwrapJoinPoint(value)); } - get isArray(): boolean { return wrapJoinPoint(this._javaObject.getIsArray()) } - get isPrimitive(): boolean { return wrapJoinPoint(this._javaObject.getIsPrimitive()) } - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - get type(): string { return wrapJoinPoint(this._javaObject.getType()) } - get typeReference(): TypeReference { return wrapJoinPoint(this._javaObject.getTypeReference()) } - setInit(value: Expression): void { return wrapJoinPoint(this._javaObject.setInit(unwrapJoinPoint(value))); } + get declarator(): NamedType { return wrapJoinPoint(this._javaObject.declarator()) } + /** + * The simple name of the type + */ + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + get returnType(): string { return wrapJoinPoint(this._javaObject.returnType()) } } -export class Executable extends Joinpoint { +export class XmlNode extends Joinpoint { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", + name: null, }; - get body(): Body { return wrapJoinPoint(this._javaObject.getBody()) } - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - set name(value: string) { this._javaObject.setName(unwrapJoinPoint(value)); } - get params(): Declaration[] { return wrapJoinPoint(this._javaObject.getParams()) } - get returnRef(): TypeReference { return wrapJoinPoint(this._javaObject.getReturnRef()) } - get returnType(): string { return wrapJoinPoint(this._javaObject.getReturnType()) } - /** - * Sets the name of this executable, returns the previous name - */ - setName(name: string): string { return wrapJoinPoint(this._javaObject.setName(unwrapJoinPoint(name))); } + get elements(): XmlElement[] { return wrapJoinPoint(this._javaObject.elements()) } + get text(): string { return wrapJoinPoint(this._javaObject.text()) } + set text(value: string) { this._javaObject.setText(unwrapJoinPoint(value)); } + elementsByName(name: string): XmlElement[] { return wrapJoinPoint(this._javaObject.elementsByName(unwrapJoinPoint(name))); } + setText(text: string): string { return wrapJoinPoint(this._javaObject.setText(unwrapJoinPoint(text))); } } -export class Expression extends Joinpoint { +export class AndroidManifest extends XmlNode { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "exprType", + name: null, }; - get kind(): string { return wrapJoinPoint(this._javaObject.getKind()) } - get qualifiedType(): string { return wrapJoinPoint(this._javaObject.getQualifiedType()) } - get test(): number { return wrapJoinPoint(this._javaObject.getTest()) } - set test(value: Expression | number) { this._javaObject.setTest(unwrapJoinPoint(value)); } - get type(): string { return wrapJoinPoint(this._javaObject.getType()) } - get typeReference(): TypeReference { return wrapJoinPoint(this._javaObject.getTypeReference()) } - extract(varName: string, location: Statement, position: string): void { return wrapJoinPoint(this._javaObject.extract(unwrapJoinPoint(varName), unwrapJoinPoint(location), unwrapJoinPoint(position))); } - setTest(test: Expression): void; - setTest(test: number): void; - setTest(p1: Expression | number): void { return wrapJoinPoint(this._javaObject.setTest(unwrapJoinPoint(p1))); } + get asJson(): string { return wrapJoinPoint(this._javaObject.asJson()) } } -export class Field extends Declaration { +export class XmlElement extends XmlNode { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - get declarator(): string { return wrapJoinPoint(this._javaObject.getDeclarator()) } - get staticAccess(): string { return wrapJoinPoint(this._javaObject.getStaticAccess()) } + /** + * A list of available attributes in this element + */ + get attributeNames(): string[] { return wrapJoinPoint(this._javaObject.attributeNames()) } + /** + * The name (i.e., tag) of this element + */ + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + /** + * The value associated with the given attribute + */ + attribute(name: string): string { return wrapJoinPoint(this._javaObject.attribute(unwrapJoinPoint(name))); } + setAttribute(name: string, value: string): string { return wrapJoinPoint(this._javaObject.setAttribute(unwrapJoinPoint(name), unwrapJoinPoint(value))); } } /** @@ -375,16 +384,16 @@ export class FileJp extends Joinpoint { static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - get dir(): string { return wrapJoinPoint(this._javaObject.getDir()) } + get dir(): string { return wrapJoinPoint(this._javaObject.dir()) } /** * Main class of the file. Java files must have a top level class with the same name as the file. */ - get mainClass(): Type { return wrapJoinPoint(this._javaObject.getMainClass()) } - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - get numClasses(): number { return wrapJoinPoint(this._javaObject.getNumClasses()) } - get numInterfaces(): number { return wrapJoinPoint(this._javaObject.getNumInterfaces()) } - get packageName(): string { return wrapJoinPoint(this._javaObject.getPackageName()) } - get path(): string { return wrapJoinPoint(this._javaObject.getPath()) } + get mainClass(): Type { return wrapJoinPoint(this._javaObject.mainClass()) } + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + get numClasses(): number { return wrapJoinPoint(this._javaObject.numClasses()) } + get numInterfaces(): number { return wrapJoinPoint(this._javaObject.numInterfaces()) } + get packageName(): string { return wrapJoinPoint(this._javaObject.packageName()) } + get path(): string { return wrapJoinPoint(this._javaObject.path()) } /** * Insert a given class inside the target */ @@ -401,46 +410,153 @@ export class FileJp extends Joinpoint { removeInterface(interfaceName: string): InterfaceType { return wrapJoinPoint(this._javaObject.removeInterface(unwrapJoinPoint(interfaceName))); } } +export class NamedType extends Joinpoint { + /** + * @internal + */ + static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { + name: "name", + }; + /** + * List of names of interfaces that this type implements + */ + get interfaces(): string[] { return wrapJoinPoint(this._javaObject.interfaces()) } + get javadoc(): string { return wrapJoinPoint(this._javaObject.javadoc()) } + /** + * The simple name of the type + */ + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + /** + * Package name of this type + */ + get packageName(): string { return wrapJoinPoint(this._javaObject.packageName()) } + /** + * The qualified name of this type, includes packages + */ + get qualifiedName(): string { return wrapJoinPoint(this._javaObject.qualifiedName()) } + /** + * Name of the superclass this type extends + */ + get superClass(): string { return wrapJoinPoint(this._javaObject.superClass()) } + /** + * Verify if the type is extends OR implements the given type + */ + isSubtypeOf(type: string): boolean { return wrapJoinPoint(this._javaObject.isSubtypeOf(unwrapJoinPoint(type))); } +} + + /** + * Base join point that class, interface and enum extend + */ +export class Type extends Joinpoint { + /** + * @internal + */ + static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { + name: "name", + }; + /** + * List of names of interfaces that this class implements + */ + get interfaces(): string[] { return wrapJoinPoint(this._javaObject.interfaces()) } + /** + * Returns the interface join points that this class implements + */ + get interfacesTypes(): InterfaceType[] { return wrapJoinPoint(this._javaObject.interfacesTypes()) } + get javadoc(): string { return wrapJoinPoint(this._javaObject.javadoc()) } + /** + * The simple name of the class + */ + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + /** + * Package name of this class + */ + get packageName(): string { return wrapJoinPoint(this._javaObject.packageName()) } + /** + * The qualified name of this class, includes packages + */ + get qualifiedName(): string { return wrapJoinPoint(this._javaObject.qualifiedName()) } + /** + * Name of the superclass this class extends + */ + get superClass(): string { return wrapJoinPoint(this._javaObject.superClass()) } + /** + * The superclass this class extends, or undefined if the class extends java.lang.Object + */ + get superClassJp(): TypeReference { return wrapJoinPoint(this._javaObject.superClassJp()) } + /** + * Insert a given class inside the target + */ + addClass(newClass: Class): void { return wrapJoinPoint(this._javaObject.addClass(unwrapJoinPoint(newClass))); } + addImplement(interfaceType: InterfaceType): void { return wrapJoinPoint(this._javaObject.addImplement(unwrapJoinPoint(interfaceType))); } + addInterface(newInterface: InterfaceType): void { return wrapJoinPoint(this._javaObject.addInterface(unwrapJoinPoint(newInterface))); } + insertCode(code: string): void { return wrapJoinPoint(this._javaObject.insertCode(unwrapJoinPoint(code))); } + insertMethod(code: string): void { return wrapJoinPoint(this._javaObject.insertMethod(unwrapJoinPoint(code))); } + /** + * Verify if the type is extends OR implements the given type + */ + isSubtypeOf(type: string): boolean { return wrapJoinPoint(this._javaObject.isSubtypeOf(unwrapJoinPoint(type))); } + newField(modifiers: string[], type: string, name: string, defaultValue?: string): Field; + newField(modifiers: string[], type: string, name: string): Field; + newField(p1: string[], p2: string, p3: string, p4?: string): Field { return wrapJoinPoint(this._javaObject.newField(unwrapJoinPoint(p1), unwrapJoinPoint(p2), unwrapJoinPoint(p3), unwrapJoinPoint(p4))); } + /** + * Add a new method inside the class + */ + newMethod(modifiers: string[], returnType: string, name: string, paramLeft: string[], paramRight: string[], code: string): Method; + /** + * Overload which accepts 4 parameters (code is empty string) + */ + newMethod(modifiers: string[], returnType: string, name: string, paramLeft: string[], paramRight: string[]): Method; + /** + * Add a new method inside the class + */ + newMethod(p1: string[], p2: string, p3: string, p4: string[], p5: string[], p6?: string): Method { return wrapJoinPoint(this._javaObject.newMethod(unwrapJoinPoint(p1), unwrapJoinPoint(p2), unwrapJoinPoint(p3), unwrapJoinPoint(p4), unwrapJoinPoint(p5), unwrapJoinPoint(p6))); } + removeInterface(interfaceName: string): InterfaceType { return wrapJoinPoint(this._javaObject.removeInterface(unwrapJoinPoint(interfaceName))); } +} + /** - * Class that is part of a library, included in the classpath + * Join point representation of a class */ -export class LibClass extends NamedType { +export class Class extends Type { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; + get isTopLevel(): boolean { return wrapJoinPoint(this._javaObject.isTopLevel()) } + extractInterface(name: string, packageName: string = "", method: Method, associate: boolean = false, newFile: boolean): InterfaceType { return wrapJoinPoint(this._javaObject.extractInterface(unwrapJoinPoint(name), unwrapJoinPoint(packageName), unwrapJoinPoint(method), unwrapJoinPoint(associate), unwrapJoinPoint(newFile))); } + insertStatic(code: string): void { return wrapJoinPoint(this._javaObject.insertStatic(unwrapJoinPoint(code))); } + mapVersions(name: string, keyType: string, interfaceType: InterfaceType, methodName: string): Class { return wrapJoinPoint(this._javaObject.mapVersions(unwrapJoinPoint(name), unwrapJoinPoint(keyType), unwrapJoinPoint(interfaceType), unwrapJoinPoint(methodName))); } + newConstructor(modifiers: string[] = ['public'], paramLeft: string[] = [], paramRight: string[] = []): Constructor { return wrapJoinPoint(this._javaObject.newConstructor(unwrapJoinPoint(modifiers), unwrapJoinPoint(paramLeft), unwrapJoinPoint(paramRight))); } + newFunctionalClass(interfaceMethod: Method, generatorMethod: Method): Method { return wrapJoinPoint(this._javaObject.newFunctionalClass(unwrapJoinPoint(interfaceMethod), unwrapJoinPoint(generatorMethod))); } } - /** - * Method of a class that is part of a library included in the classpath - */ -export class LibMethod extends Joinpoint { +export class InterfaceType extends Type { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - get declarator(): NamedType { return wrapJoinPoint(this._javaObject.getDeclarator()) } - /** - * The simple name of the type - */ - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - get returnType(): string { return wrapJoinPoint(this._javaObject.getReturnType()) } } -export class Literal extends Expression { +export class Executable extends Joinpoint { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "value", + name: "name", }; - get value(): string { return wrapJoinPoint(this._javaObject.getValue()) } - set value(value: string) { this._javaObject.setValue(unwrapJoinPoint(value)); } - setValue(value: string): void { return wrapJoinPoint(this._javaObject.setValue(unwrapJoinPoint(value))); } + get body(): Body { return wrapJoinPoint(this._javaObject.body()) } + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + set name(value: string) { this._javaObject.setName(unwrapJoinPoint(value)); } + get params(): Declaration[] { return wrapJoinPoint(this._javaObject.params()) } + get returnRef(): TypeReference { return wrapJoinPoint(this._javaObject.returnRef()) } + get returnType(): string { return wrapJoinPoint(this._javaObject.returnType()) } + /** + * Sets the name of this executable, returns the previous name + */ + setName(name: string): string { return wrapJoinPoint(this._javaObject.setName(unwrapJoinPoint(name))); } } export class Method extends Executable { @@ -450,67 +566,64 @@ export class Method extends Executable { static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - get declarator(): string { return wrapJoinPoint(this._javaObject.getDeclarator()) } - get privacy(): string { return wrapJoinPoint(this._javaObject.getPrivacy()) } + get declarator(): string { return wrapJoinPoint(this._javaObject.declarator()) } + get privacy(): string { return wrapJoinPoint(this._javaObject.privacy()) } set privacy(value: string) { this._javaObject.setPrivacy(unwrapJoinPoint(value)); } - get toQualifiedReference(): string { return wrapJoinPoint(this._javaObject.getToQualifiedReference()) } - get toReference(): string { return wrapJoinPoint(this._javaObject.getToReference()) } - isOverriding(method: Method): boolean { return wrapJoinPoint(this._javaObject.isOverriding(unwrapJoinPoint(method))); } + get toQualifiedReference(): string { return wrapJoinPoint(this._javaObject.toQualifiedReference()) } + get toReference(): string { return wrapJoinPoint(this._javaObject.toReference()) } addComment(comment: string): void { return wrapJoinPoint(this._javaObject.addComment(unwrapJoinPoint(comment))); } addParameter(type: string, name: string): void { return wrapJoinPoint(this._javaObject.addParameter(unwrapJoinPoint(type), unwrapJoinPoint(name))); } clone(newName: string): Method { return wrapJoinPoint(this._javaObject.clone(unwrapJoinPoint(newName))); } createAdapter(adaptMethod: Method, name: string): Class { return wrapJoinPoint(this._javaObject.createAdapter(unwrapJoinPoint(adaptMethod), unwrapJoinPoint(name))); } + isOverriding(method: Method): boolean { return wrapJoinPoint(this._javaObject.isOverriding(unwrapJoinPoint(method))); } setPrivacy(privacy: string): void { return wrapJoinPoint(this._javaObject.setPrivacy(unwrapJoinPoint(privacy))); } } -export class New extends Expression { +export class Constructor extends Executable { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - get arguments(): Expression[] { return wrapJoinPoint(this._javaObject.getArguments()) } - set arguments(value: Expression[]) { this._javaObject.setArguments(unwrapJoinPoint(value)); } - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - setArguments(newArguments: Expression[]): void { return wrapJoinPoint(this._javaObject.setArguments(unwrapJoinPoint(newArguments))); } + get declarator(): string { return wrapJoinPoint(this._javaObject.declarator()) } } - /** - * Points to a named program element reference - */ -export class Reference extends Joinpoint { +export class AnonymousExec extends Executable { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; +} + +export class Declaration extends Joinpoint { /** - * The element that is being referenced - */ - get declaration(): Joinpoint { return wrapJoinPoint(this._javaObject.getDeclaration()) } - /** - * Name of the element of the reference - */ - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - /** - * Type of the element of the reference + * @internal */ - get type(): string { return wrapJoinPoint(this._javaObject.getType()) } + static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { + name: "name", + }; + get completeType(): string { return wrapJoinPoint(this._javaObject.completeType()) } + get init(): Expression { return wrapJoinPoint(this._javaObject.init()) } + set init(value: Expression) { this._javaObject.setInit(unwrapJoinPoint(value)); } + get isArray(): boolean { return wrapJoinPoint(this._javaObject.isArray()) } + get isPrimitive(): boolean { return wrapJoinPoint(this._javaObject.isPrimitive()) } + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + get type(): string { return wrapJoinPoint(this._javaObject.type()) } + get typeReference(): TypeReference { return wrapJoinPoint(this._javaObject.typeReference()) } + setInit(value: Expression): void { return wrapJoinPoint(this._javaObject.setInit(unwrapJoinPoint(value))); } } -export class SnippetExpr extends Expression { +export class Catch extends Joinpoint { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "exprType", + name: null, }; - setLine(line: number): void; - setLine(value: number): void; - setLine(value: string): void; - setLine(p1: number | string): void { return wrapJoinPoint(this._javaObject.setLine(unwrapJoinPoint(p1))); } + get body(): Body { return wrapJoinPoint(this._javaObject.body()) } } export class Statement extends Joinpoint { @@ -520,141 +633,98 @@ export class Statement extends Joinpoint { static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "kind", }; - get endLine(): number { return wrapJoinPoint(this._javaObject.getEndLine()) } - get kind(): string { return wrapJoinPoint(this._javaObject.getKind()) } + get endLine(): number { return wrapJoinPoint(this._javaObject.endLine()) } + get kind(): string { return wrapJoinPoint(this._javaObject.kind()) } } -export class Switch extends Statement { +export class CallStatement extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "kind", }; - get cases(): Case[] { return wrapJoinPoint(this._javaObject.getCases()) } + get call(): Call { return wrapJoinPoint(this._javaObject.call()) } } -export class Ternary extends Expression { +export class Assignment extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "exprType", + name: "operator", }; - /** - * Alias for attribute 'condition' - */ - get cond(): Expression { return wrapJoinPoint(this._javaObject.getCond()) } - /** - * The condition of the ternary expression - */ - get condition(): Expression { return wrapJoinPoint(this._javaObject.getCondition()) } - get else(): Expression { return wrapJoinPoint(this._javaObject.getElse()) } - get then(): Expression { return wrapJoinPoint(this._javaObject.getThen()) } + get lhs(): Expression { return wrapJoinPoint(this._javaObject.lhs()) } + set lhs(value: Expression) { this._javaObject.setLhs(unwrapJoinPoint(value)); } + get operator(): string { return wrapJoinPoint(this._javaObject.operator()) } + get rhs(): Expression { return wrapJoinPoint(this._javaObject.rhs()) } + set rhs(value: Expression) { this._javaObject.setRhs(unwrapJoinPoint(value)); } + setLhs(lhs: Expression): void { return wrapJoinPoint(this._javaObject.setLhs(unwrapJoinPoint(lhs))); } + setRhs(rhs: Expression): void { return wrapJoinPoint(this._javaObject.setRhs(unwrapJoinPoint(rhs))); } } -export class This extends Expression { +export class OpAssignment extends Assignment { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "exprType", + name: "operator", }; + setOperator(operator: string): void { return wrapJoinPoint(this._javaObject.setOperator(unwrapJoinPoint(operator))); } } -export class Throw extends Statement { +export class Expression extends Joinpoint { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "kind", + name: null, }; + get kind(): string { return wrapJoinPoint(this._javaObject.kind()) } + get qualifiedType(): string { return wrapJoinPoint(this._javaObject.qualifiedType()) } + get test(): number { return wrapJoinPoint(this._javaObject.test()) } + set test(value: Expression | number) { this._javaObject.setTest(unwrapJoinPoint(value)); } + get type(): string { return wrapJoinPoint(this._javaObject.type()) } + get typeReference(): TypeReference { return wrapJoinPoint(this._javaObject.typeReference()) } + extract(varName: string, location: Statement, position: string): void { return wrapJoinPoint(this._javaObject.extract(unwrapJoinPoint(varName), unwrapJoinPoint(location), unwrapJoinPoint(position))); } + setTest(test: Expression): void; + setTest(test: number): void; + setTest(p1: Expression | number): void { return wrapJoinPoint(this._javaObject.setTest(unwrapJoinPoint(p1))); } } -export class Try extends Statement { +export class Annotation extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "kind", + name: null, }; - get body(): Body { return wrapJoinPoint(this._javaObject.getBody()) } - get catches(): Catch[] { return wrapJoinPoint(this._javaObject.getCatches()) } } - /** - * Base join point that class, interface and enum extend - */ -export class Type extends Joinpoint { +export class Var extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; + get declaration(): Joinpoint { return wrapJoinPoint(this._javaObject.declaration()) } /** - * List of names of interfaces that this class implements - */ - get interfaces(): string[] { return wrapJoinPoint(this._javaObject.getInterfaces()) } - /** - * Returns the interface join points that this class implements - */ - get interfacesTypes(): InterfaceType[] { return wrapJoinPoint(this._javaObject.getInterfacesTypes()) } - get javadoc(): string { return wrapJoinPoint(this._javaObject.getJavadoc()) } - /** - * The simple name of the class - */ - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - /** - * Package name of this class - */ - get packageName(): string { return wrapJoinPoint(this._javaObject.getPackageName()) } - /** - * The qualified name of this class, includes packages - */ - get qualifiedName(): string { return wrapJoinPoint(this._javaObject.getQualifiedName()) } - /** - * Name of the superclass this class extends - */ - get superClass(): string { return wrapJoinPoint(this._javaObject.getSuperClass()) } - /** - * The superclass this class extends, or undefined if the class extends java.lang.Object - */ - get superClassJp(): TypeReference { return wrapJoinPoint(this._javaObject.getSuperClassJp()) } - /** - * Verify if the type is extends OR implements the given type - */ - isSubtypeOf(type: string): boolean { return wrapJoinPoint(this._javaObject.isSubtypeOf(unwrapJoinPoint(type))); } - /** - * Insert a given class inside the target - */ - addClass(newClass: Class): void { return wrapJoinPoint(this._javaObject.addClass(unwrapJoinPoint(newClass))); } - addImplement(interfaceType: InterfaceType): void { return wrapJoinPoint(this._javaObject.addImplement(unwrapJoinPoint(interfaceType))); } - addInterface(newInterface: InterfaceType): void { return wrapJoinPoint(this._javaObject.addInterface(unwrapJoinPoint(newInterface))); } - insertCode(code: string): void { return wrapJoinPoint(this._javaObject.insertCode(unwrapJoinPoint(code))); } - insertMethod(code: string): void { return wrapJoinPoint(this._javaObject.insertMethod(unwrapJoinPoint(code))); } - newField(modifiers: string[], type: string, name: string, defaultValue?: string): Field; - newField(modifiers: string[], type: string, name: string): Field; - newField(p1: string[], p2: string, p3: string, p4?: string): Field { return wrapJoinPoint(this._javaObject.newField(unwrapJoinPoint(p1), unwrapJoinPoint(p2), unwrapJoinPoint(p3), unwrapJoinPoint(p4))); } - /** - * Add a new method inside the class - */ - newMethod(modifiers: string[], returnType: string, name: string, paramLeft: string[], paramRight: string[], code: string): Method; - /** - * Overload which accepts 4 parameters (code is empty string) + * Equivalent to the global attribute 'isInsideLoopHeader' */ - newMethod(modifiers: string[], returnType: string, name: string, paramLeft: string[], paramRight: string[]): Method; + get inLoopHeader(): boolean { return wrapJoinPoint(this._javaObject.inLoopHeader()) } + get isArray(): boolean { return wrapJoinPoint(this._javaObject.isArray()) } + get isField(): boolean { return wrapJoinPoint(this._javaObject.isField()) } + get isPrimitive(): boolean { return wrapJoinPoint(this._javaObject.isPrimitive()) } + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + get reference(): RefType { return wrapJoinPoint(this._javaObject.reference()) } /** - * Add a new method inside the class + * The chain of references of this variable (e.g., this.field) */ - newMethod(p1: string[], p2: string, p3: string, p4: string[], p5: string[], p6?: string): Method { return wrapJoinPoint(this._javaObject.newMethod(unwrapJoinPoint(p1), unwrapJoinPoint(p2), unwrapJoinPoint(p3), unwrapJoinPoint(p4), unwrapJoinPoint(p5), unwrapJoinPoint(p6))); } - removeInterface(interfaceName: string): InterfaceType { return wrapJoinPoint(this._javaObject.removeInterface(unwrapJoinPoint(interfaceName))); } + get referenceChain(): Joinpoint[] { return wrapJoinPoint(this._javaObject.referenceChain()) } } - /** - * Reference to a type - */ -export class TypeReference extends Reference { +export class FieldAccess extends Var { /** * @internal */ @@ -662,183 +732,178 @@ export class TypeReference extends Reference { name: "name", }; /** - * True if this is a reference to an array type, false otherwise - */ - get isArray(): boolean { return wrapJoinPoint(this._javaObject.getIsArray()) } - /** - * True if this is a reference to a boolean type, primitive or class (i.e., boolean, Boolean) - */ - get isBoolean(): boolean { return wrapJoinPoint(this._javaObject.getIsBoolean()) } - /** - * 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) - */ - get isNumeric(): boolean { return wrapJoinPoint(this._javaObject.getIsNumeric()) } - /** - * True if this is a reference to a primitive type, false otherwise - */ - get isPrimitive(): boolean { return wrapJoinPoint(this._javaObject.getIsPrimitive()) } - /** - * Package name of this type - */ - get packageName(): string { return wrapJoinPoint(this._javaObject.getPackageName()) } - /** - * The package name of this type as an array, where each element is a part of the package - */ - get packageNames(): string[] { return wrapJoinPoint(this._javaObject.getPackageNames()) } - /** - * Fully qualified name of the type + * The base expression of this fieldAccess. E.g., for the field access a.b.c, returns the expression representing a.b */ - get qualifiedName(): string { return wrapJoinPoint(this._javaObject.getQualifiedName()) } + get base(): Expression { return wrapJoinPoint(this._javaObject.base()) } } -export class UnaryExpression extends Expression { +export class Literal extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "operator", + name: "value", }; - get operand(): Expression { return wrapJoinPoint(this._javaObject.getOperand()) } - get operator(): string { return wrapJoinPoint(this._javaObject.getOperator()) } - set operator(value: string) { this._javaObject.setOperator(unwrapJoinPoint(value)); } - /** - * 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. - */ - setOperator(operator: string): void { return wrapJoinPoint(this._javaObject.setOperator(unwrapJoinPoint(operator))); } + get value(): string { return wrapJoinPoint(this._javaObject.value()) } + set value(value: string) { this._javaObject.setValue(unwrapJoinPoint(value)); } + setValue(value: string): void { return wrapJoinPoint(this._javaObject.setValue(unwrapJoinPoint(value))); } } -export class Var extends Expression { +export class Call extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - get declaration(): Joinpoint { return wrapJoinPoint(this._javaObject.getDeclaration()) } - /** - * Equivalent to the global attribute 'isInsideLoopHeader' - */ - get inLoopHeader(): boolean { return wrapJoinPoint(this._javaObject.getInLoopHeader()) } - get isArray(): boolean { return wrapJoinPoint(this._javaObject.getIsArray()) } - get isField(): boolean { return wrapJoinPoint(this._javaObject.getIsField()) } - get isPrimitive(): boolean { return wrapJoinPoint(this._javaObject.getIsPrimitive()) } - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - get reference(): RefType { return wrapJoinPoint(this._javaObject.getReference()) } + get arguments(): Expression[] { return wrapJoinPoint(this._javaObject.arguments()) } + set arguments(value: Expression[]) { this._javaObject.setArguments(unwrapJoinPoint(value)); } + get decl(): Method { return wrapJoinPoint(this._javaObject.decl()) } + get declarator(): string { return wrapJoinPoint(this._javaObject.declarator()) } + get executable(): string { return wrapJoinPoint(this._javaObject.executable()) } + set executable(value: Method) { this._javaObject.setExecutable(unwrapJoinPoint(value)); } + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + get qualifiedDecl(): string { return wrapJoinPoint(this._javaObject.qualifiedDecl()) } + get returnType(): string { return wrapJoinPoint(this._javaObject.returnType()) } + get returnTypeJp(): TypeReference { return wrapJoinPoint(this._javaObject.returnTypeJp()) } + get simpleDecl(): string { return wrapJoinPoint(this._javaObject.simpleDecl()) } + get target(): string { return wrapJoinPoint(this._javaObject.target()) } + set target(value: Expression | string) { this._javaObject.setTarget(unwrapJoinPoint(value)); } + get targetType(): Type { return wrapJoinPoint(this._javaObject.targetType()) } + clone(location: Statement, position: string): Call { return wrapJoinPoint(this._javaObject.clone(unwrapJoinPoint(location), unwrapJoinPoint(position))); } + setArgument(newArgument: Expression, index: number): void { return wrapJoinPoint(this._javaObject.setArgument(unwrapJoinPoint(newArgument), unwrapJoinPoint(index))); } + setArguments(newArguments: Expression[]): void { return wrapJoinPoint(this._javaObject.setArguments(unwrapJoinPoint(newArguments))); } + setExecutable(executable: Method): Call { return wrapJoinPoint(this._javaObject.setExecutable(unwrapJoinPoint(executable))); } + setTarget(target?: Expression): Call; + setTarget(target?: string): Call; + setTarget(p1?: Expression | string): Call { return wrapJoinPoint(this._javaObject.setTarget(unwrapJoinPoint(p1))); } +} + +export class New extends Expression { /** - * The chain of references of this variable (e.g., this.field) + * @internal */ - get referenceChain(): Joinpoint[] { return wrapJoinPoint(this._javaObject.getReferenceChain()) } + static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { + name: "name", + }; + get arguments(): Expression[] { return wrapJoinPoint(this._javaObject.arguments()) } + set arguments(value: Expression[]) { this._javaObject.setArguments(unwrapJoinPoint(value)); } + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + setArguments(newArguments: Expression[]): void { return wrapJoinPoint(this._javaObject.setArguments(unwrapJoinPoint(newArguments))); } } -export class XmlNode extends Joinpoint { +export class BinaryExpression extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: null, + name: "operator", }; - get elements(): XmlElement[] { return wrapJoinPoint(this._javaObject.getElements()) } - get text(): string { return wrapJoinPoint(this._javaObject.getText()) } - set text(value: string) { this._javaObject.setText(unwrapJoinPoint(value)); } - elementsByName(name: string): XmlElement[] { return wrapJoinPoint(this._javaObject.elementsByName(unwrapJoinPoint(name))); } - setText(text: string): string { return wrapJoinPoint(this._javaObject.setText(unwrapJoinPoint(text))); } + get lhs(): Expression { return wrapJoinPoint(this._javaObject.lhs()) } + get operands(): Expression[] { return wrapJoinPoint(this._javaObject.operands()) } + get operator(): string { return wrapJoinPoint(this._javaObject.operator()) } + set operator(value: string) { this._javaObject.setOperator(unwrapJoinPoint(value)); } + get rhs(): Expression { return wrapJoinPoint(this._javaObject.rhs()) } + setOperator(operator: string): void { return wrapJoinPoint(this._javaObject.setOperator(unwrapJoinPoint(operator))); } } -export class AndroidManifest extends XmlNode { +export class UnaryExpression extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: null, + name: "operator", }; - get asJson(): string { return wrapJoinPoint(this._javaObject.getAsJson()) } + get operand(): Expression { return wrapJoinPoint(this._javaObject.operand()) } + get operator(): string { return wrapJoinPoint(this._javaObject.operator()) } + set operator(value: string) { this._javaObject.setOperator(unwrapJoinPoint(value)); } + /** + * 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. + */ + setOperator(operator: string): void { return wrapJoinPoint(this._javaObject.setOperator(unwrapJoinPoint(operator))); } } -export class Annotation extends Expression { +export class Ternary extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "exprType", + name: null, }; + /** + * Alias for attribute 'condition' + */ + get cond(): Expression { return wrapJoinPoint(this._javaObject.cond()) } + /** + * The condition of the ternary expression + */ + get condition(): Expression { return wrapJoinPoint(this._javaObject.condition()) } + get else(): Expression { return wrapJoinPoint(this._javaObject._else()) } + get then(): Expression { return wrapJoinPoint(this._javaObject.then()) } } -export class AnonymousExec extends Executable { +export class ArrayAccess extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", + name: null, }; + get reference(): RefType { return wrapJoinPoint(this._javaObject.reference()) } } -export class ArrayAccess extends Expression { +export class This extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", + name: null, }; - get reference(): RefType { return wrapJoinPoint(this._javaObject.getReference()) } } -export class Assert extends Statement { +export class SnippetExpr extends Expression { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "kind", + name: null, }; + setLine(value: number | string): void; + setLine(line: number): void; + setLine(p1: number | string): void { return wrapJoinPoint(this._javaObject.setLine(unwrapJoinPoint(p1))); } } -export class Assignment extends Statement { +export class Return extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "operator", + name: "kind", }; - get lhs(): Expression { return wrapJoinPoint(this._javaObject.getLhs()) } - set lhs(value: Expression) { this._javaObject.setLhs(unwrapJoinPoint(value)); } - get operator(): string { return wrapJoinPoint(this._javaObject.getOperator()) } - get rhs(): Expression { return wrapJoinPoint(this._javaObject.getRhs()) } - set rhs(value: Expression) { this._javaObject.setRhs(unwrapJoinPoint(value)); } - setLhs(lhs: Expression): void { return wrapJoinPoint(this._javaObject.setLhs(unwrapJoinPoint(lhs))); } - setRhs(rhs: Expression): void { return wrapJoinPoint(this._javaObject.setRhs(unwrapJoinPoint(rhs))); } } -export class BinaryExpression extends Expression { +export class Comment extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "operator", + name: "type", }; - get lhs(): Expression { return wrapJoinPoint(this._javaObject.getLhs()) } - get operands(): Expression[] { return wrapJoinPoint(this._javaObject.getOperands()) } - get operator(): string { return wrapJoinPoint(this._javaObject.getOperator()) } - set operator(value: string) { this._javaObject.setOperator(unwrapJoinPoint(value)); } - get rhs(): Expression { return wrapJoinPoint(this._javaObject.getRhs()) } - setOperator(operator: string): void { return wrapJoinPoint(this._javaObject.setOperator(unwrapJoinPoint(operator))); } + get content(): string { return wrapJoinPoint(this._javaObject.content()) } + get type(): CommentType { return wrapJoinPoint(this._javaObject.type()) } } -export class Body extends Statement { +export class Pragma extends Comment { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "kind", + name: "name", }; - /** - * The last statement of the body, or undefined if it has no statements - */ - get lastStmt(): Statement { return wrapJoinPoint(this._javaObject.getLastStmt()) } - insertBegin(code: string): void; - insertBegin(statement: Statement): void; - insertBegin(p1: string | Statement): void { return wrapJoinPoint(this._javaObject.insertBegin(unwrapJoinPoint(p1))); } + get name(): string { return wrapJoinPoint(this._javaObject.name()) } } -export class Break extends Statement { +export class Assert extends Statement { /** * @internal */ @@ -847,44 +912,23 @@ export class Break extends Statement { }; } -export class Call extends Expression { +export class Throw extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", + name: "kind", }; - get arguments(): Expression[] { return wrapJoinPoint(this._javaObject.getArguments()) } - set arguments(value: Expression[]) { this._javaObject.setArguments(unwrapJoinPoint(value)); } - get decl(): Method { return wrapJoinPoint(this._javaObject.getDecl()) } - get declarator(): string { return wrapJoinPoint(this._javaObject.getDeclarator()) } - get executable(): string { return wrapJoinPoint(this._javaObject.getExecutable()) } - set executable(value: Method) { this._javaObject.setExecutable(unwrapJoinPoint(value)); } - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - get qualifiedDecl(): string { return wrapJoinPoint(this._javaObject.getQualifiedDecl()) } - get returnType(): string { return wrapJoinPoint(this._javaObject.getReturnType()) } - get returnTypeJp(): TypeReference { return wrapJoinPoint(this._javaObject.getReturnTypeJp()) } - get simpleDecl(): string { return wrapJoinPoint(this._javaObject.getSimpleDecl()) } - get target(): string { return wrapJoinPoint(this._javaObject.getTarget()) } - set target(value: Expression | string) { this._javaObject.setTarget(unwrapJoinPoint(value)); } - get targetType(): Type { return wrapJoinPoint(this._javaObject.getTargetType()) } - clone(location: Statement, position: string): Call { return wrapJoinPoint(this._javaObject.clone(unwrapJoinPoint(location), unwrapJoinPoint(position))); } - setArgument(newArgument: Expression, index: number): void { return wrapJoinPoint(this._javaObject.setArgument(unwrapJoinPoint(newArgument), unwrapJoinPoint(index))); } - setArguments(newArguments: Expression[]): void { return wrapJoinPoint(this._javaObject.setArguments(unwrapJoinPoint(newArguments))); } - setExecutable(executable: Method): Call { return wrapJoinPoint(this._javaObject.setExecutable(unwrapJoinPoint(executable))); } - setTarget(target?: Expression): Call; - setTarget(target?: string): Call; - setTarget(p1?: Expression | string): Call { return wrapJoinPoint(this._javaObject.setTarget(unwrapJoinPoint(p1))); } } -export class CallStatement extends Statement { +export class Switch extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "kind", }; - get call(): Call { return wrapJoinPoint(this._javaObject.getCall()) } + get cases(): Case[] { return wrapJoinPoint(this._javaObject.cases()) } } export class Case extends Statement { @@ -897,75 +941,115 @@ export class Case extends Statement { /** * The expression associated with this case, of undefined if it is the default case */ - get expr(): Expression { return wrapJoinPoint(this._javaObject.getExpr()) } + get expr(): Expression { return wrapJoinPoint(this._javaObject.expr()) } /** * True if this is the default case, false otherwise */ - get isDefault(): boolean { return wrapJoinPoint(this._javaObject.getIsDefault()) } + get isDefault(): boolean { return wrapJoinPoint(this._javaObject.isDefault()) } /** * The statements of this case */ - get stmts(): Statement[] { return wrapJoinPoint(this._javaObject.getStmts()) } + get stmts(): Statement[] { return wrapJoinPoint(this._javaObject.stmts()) } } - /** - * Join point representation of a class - */ -export class Class extends Type { +export class Continue extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", + name: "kind", }; - get isTopLevel(): boolean { return wrapJoinPoint(this._javaObject.getIsTopLevel()) } - extractInterface(name: string, packageName: string, method: Method, associate: boolean = false, newFile: boolean): InterfaceType { return wrapJoinPoint(this._javaObject.extractInterface(unwrapJoinPoint(name), unwrapJoinPoint(packageName), unwrapJoinPoint(method), unwrapJoinPoint(associate), unwrapJoinPoint(newFile))); } - insertStatic(code: string): void { return wrapJoinPoint(this._javaObject.insertStatic(unwrapJoinPoint(code))); } - mapVersions(name: string, keyType: string, interfaceType: InterfaceType, methodName: string): Class { return wrapJoinPoint(this._javaObject.mapVersions(unwrapJoinPoint(name), unwrapJoinPoint(keyType), unwrapJoinPoint(interfaceType), unwrapJoinPoint(methodName))); } - newConstructor(modifiers: string[] = ['public'], paramLeft: string[] = [], paramRight: string[] = []): Constructor { return wrapJoinPoint(this._javaObject.newConstructor(unwrapJoinPoint(modifiers), unwrapJoinPoint(paramLeft), unwrapJoinPoint(paramRight))); } - newFunctionalClass(interfaceMethod: Method, generatorMethod: Method): Method { return wrapJoinPoint(this._javaObject.newFunctionalClass(unwrapJoinPoint(interfaceMethod), unwrapJoinPoint(generatorMethod))); } } -export class Comment extends Statement { +export class Break extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "type", + name: "kind", }; - get content(): string { return wrapJoinPoint(this._javaObject.getContent()) } - get type(): CommentType { return wrapJoinPoint(this._javaObject.getType()) } } -export class Constructor extends Executable { +export class SnippetStmt extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", + name: "kind", }; - get declarator(): string { return wrapJoinPoint(this._javaObject.getDeclarator()) } + setLine(value: number | string): void; + setLine(line: number): void; + setLine(p1: number | string): void { return wrapJoinPoint(this._javaObject.setLine(unwrapJoinPoint(p1))); } } -export class Continue extends Statement { + /** + * Points to a named program element reference + */ +export class Reference extends Joinpoint { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "kind", + name: "name", }; + /** + * The element that is being referenced + */ + get declaration(): Joinpoint { return wrapJoinPoint(this._javaObject.declaration()) } + /** + * Name of the element of the reference + */ + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + /** + * Type of the element of the reference + */ + get type(): string { return wrapJoinPoint(this._javaObject.type()) } } -export class Enum extends Class { + /** + * Reference to a type + */ +export class TypeReference extends Reference { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; + /** + * True if this is a reference to an array type, false otherwise + */ + get isArray(): boolean { return wrapJoinPoint(this._javaObject.isArray()) } + /** + * True if this is a reference to a boolean type, primitive or class (i.e., boolean, Boolean) + */ + get isBoolean(): boolean { return wrapJoinPoint(this._javaObject.isBoolean()) } + /** + * 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) + */ + get isNumeric(): boolean { return wrapJoinPoint(this._javaObject.isNumeric()) } + /** + * True if this is a reference to a primitive type, false otherwise + */ + get isPrimitive(): boolean { return wrapJoinPoint(this._javaObject.isPrimitive()) } + /** + * Package name of this type + */ + get packageName(): string { return wrapJoinPoint(this._javaObject.packageName()) } + /** + * The package name of this type as an array, where each element is a part of the package + */ + get packageNames(): string[] { return wrapJoinPoint(this._javaObject.packageNames()) } + /** + * Fully qualified name of the type + */ + get qualifiedName(): string { return wrapJoinPoint(this._javaObject.qualifiedName()) } } -export class EnumValue extends Field { + /** + * Class that is part of a library, included in the classpath + */ +export class LibClass extends NamedType { /** * @internal */ @@ -974,39 +1058,40 @@ export class EnumValue extends Field { }; } -export class FieldAccess extends Var { +export class Field extends Declaration { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - /** - * The base expression of this fieldAccess. E.g., for the field access a.b.c, returns the expression representing a.b - */ - get base(): Expression { return wrapJoinPoint(this._javaObject.getBase()) } + get declarator(): string { return wrapJoinPoint(this._javaObject.declarator()) } + get staticAccess(): string { return wrapJoinPoint(this._javaObject.staticAccess()) } } -export class If extends Statement { +export class EnumValue extends Field { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "kind", + name: "name", }; - get cond(): Expression { return wrapJoinPoint(this._javaObject.getCond()) } - get else(): Body { return wrapJoinPoint(this._javaObject.getElse()) } - get rank(): string { return wrapJoinPoint(this._javaObject.getRank()) } - get then(): Body { return wrapJoinPoint(this._javaObject.getThen()) } } -export class InterfaceType extends Type { +export class Body extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", + name: "kind", }; + /** + * The last statement of the body, or undefined if it has no statements + */ + get lastStmt(): Statement { return wrapJoinPoint(this._javaObject.lastStmt()) } + insertBegin(code: string): void; + insertBegin(statement: Statement): void; + insertBegin(p1: string | Statement): void { return wrapJoinPoint(this._javaObject.insertBegin(unwrapJoinPoint(p1))); } } export class LocalVariable extends Statement { @@ -1016,20 +1101,20 @@ export class LocalVariable extends Statement { static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "name", }; - get completeType(): string { return wrapJoinPoint(this._javaObject.getCompleteType()) } + get completeType(): string { return wrapJoinPoint(this._javaObject.completeType()) } /** * Initialization of this variable, if present, or undefined of unintialized */ - get init(): Expression { return wrapJoinPoint(this._javaObject.getInit()) } + get init(): Expression { return wrapJoinPoint(this._javaObject.init()) } /** * Initialization of this variable, if present, or undefined of unintialized */ set init(value: Expression) { this._javaObject.setInit(unwrapJoinPoint(value)); } - get isArray(): boolean { return wrapJoinPoint(this._javaObject.getIsArray()) } - get isPrimitive(): boolean { return wrapJoinPoint(this._javaObject.getIsPrimitive()) } - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - get type(): string { return wrapJoinPoint(this._javaObject.getType()) } - get typeReference(): TypeReference { return wrapJoinPoint(this._javaObject.getTypeReference()) } + get isArray(): boolean { return wrapJoinPoint(this._javaObject.isArray()) } + get isPrimitive(): boolean { return wrapJoinPoint(this._javaObject.isPrimitive()) } + get name(): string { return wrapJoinPoint(this._javaObject.name()) } + get type(): string { return wrapJoinPoint(this._javaObject.type()) } + get typeReference(): TypeReference { return wrapJoinPoint(this._javaObject.typeReference()) } setInit(init: Expression): void { return wrapJoinPoint(this._javaObject.setInit(unwrapJoinPoint(init))); } } @@ -1040,161 +1125,138 @@ export class Loop extends Statement { static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "type", }; - get cond(): Expression { return wrapJoinPoint(this._javaObject.getCond()) } - get controlVar(): string { return wrapJoinPoint(this._javaObject.getControlVar()) } - get isInnermost(): boolean { return wrapJoinPoint(this._javaObject.getIsInnermost()) } - get isOutermost(): boolean { return wrapJoinPoint(this._javaObject.getIsOutermost()) } - get nestedLevel(): number { return wrapJoinPoint(this._javaObject.getNestedLevel()) } - get rank(): string { return wrapJoinPoint(this._javaObject.getRank()) } - get type(): LoopType { return wrapJoinPoint(this._javaObject.getType()) } + get cond(): Expression { return wrapJoinPoint(this._javaObject.cond()) } + get controlVar(): string { return wrapJoinPoint(this._javaObject.controlVar()) } + get isInnermost(): boolean { return wrapJoinPoint(this._javaObject.isInnermost()) } + get isOutermost(): boolean { return wrapJoinPoint(this._javaObject.isOutermost()) } + get nestedLevel(): number { return wrapJoinPoint(this._javaObject.nestedLevel()) } + get rank(): string { return wrapJoinPoint(this._javaObject.rank()) } + get type(): LoopType { return wrapJoinPoint(this._javaObject.type()) } interchange(loop2: Loop): void { return wrapJoinPoint(this._javaObject.interchange(unwrapJoinPoint(loop2))); } tile(tileName: string, block: string, unique: boolean, around?: Joinpoint): Field; tile(block: number): void; - tile(p1: string | number, p2?: string, p3?: boolean, p4?: Joinpoint): Field | void { return wrapJoinPoint(this._javaObject.tile(unwrapJoinPoint(p1), unwrapJoinPoint(p2), unwrapJoinPoint(p3), unwrapJoinPoint(p4))); } -} - -export class OpAssignment extends Assignment { - /** - * @internal - */ - static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "operator", - }; - setOperator(operator: string): void { return wrapJoinPoint(this._javaObject.setOperator(unwrapJoinPoint(operator))); } -} - -export class Pragma extends Comment { - /** - * @internal - */ - static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", - }; - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } + tile(p1?: string | number, p2?: string, p3?: boolean, p4?: Joinpoint): Field | void { return wrapJoinPoint(this._javaObject.tile(unwrapJoinPoint(p1), unwrapJoinPoint(p2), unwrapJoinPoint(p3), unwrapJoinPoint(p4))); } } -export class Return extends Statement { +export class If extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "kind", }; + get cond(): Expression { return wrapJoinPoint(this._javaObject.cond()) } + get else(): Body { return wrapJoinPoint(this._javaObject._else()) } + get rank(): string { return wrapJoinPoint(this._javaObject.rank()) } + get then(): Body { return wrapJoinPoint(this._javaObject.then()) } } -export class SnippetStmt extends Statement { +export class Try extends Statement { /** * @internal */ static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { name: "kind", }; - setLine(line: number): void; - setLine(value: number): void; - setLine(value: string): void; - setLine(p1: number | string): void { return wrapJoinPoint(this._javaObject.setLine(unwrapJoinPoint(p1))); } -} - -export class XmlElement extends XmlNode { - /** - * @internal - */ - static readonly _defaultAttributeInfo: {readonly map?: DefaultAttributeMap, readonly name: string | null, readonly type?: PrivateMapper, readonly jpMapper?: typeof JoinpointMapper} = { - name: "name", - }; - /** - * A list of available attributes in this element - */ - get attributeNames(): string[] { return wrapJoinPoint(this._javaObject.getAttributeNames()) } - /** - * The name (i.e., tag) of this element - */ - get name(): string { return wrapJoinPoint(this._javaObject.getName()) } - /** - * The value associated with the given attribute - */ - attribute(name: string): string { return wrapJoinPoint(this._javaObject.attribute(unwrapJoinPoint(name))); } - setAttribute(name: string, value: string): string { return wrapJoinPoint(this._javaObject.setAttribute(unwrapJoinPoint(name), unwrapJoinPoint(value))); } -} - -export enum LoopType { - DOWHILE = "dowhile", - FOR = "for", - FOREACH = "foreach", - WHILE = "while", -} - -export enum CommentType { - BLOCK = "block", - FILE = "file", - INLINE = "inline", - JAVADOC = "javadoc", - PRAGMA = "pragma", + get body(): Body { return wrapJoinPoint(this._javaObject.body()) } + get catches(): Catch[] { return wrapJoinPoint(this._javaObject.catches()) } } -export enum RefType { - DECL = "decl", - READ = "read", - READWRITE = "readwrite", - WRITE = "write", -} +/** + * This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax. + * Revert to an enum when Node.js supports it, or when we move to a different engine that supports it. + * This and the "type" declaration below. + */ +export const LoopType = { + for: "for", + foreach: "foreach", + while: "while", + doWhile: "doWhile", +} as const; +export type LoopType = typeof LoopType[keyof typeof LoopType]; + +/** + * This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax. + * Revert to an enum when Node.js supports it, or when we move to a different engine that supports it. + * This and the "type" declaration below. + */ +export const CommentType = { + file: "file", + inline: "inline", + block: "block", + javadoc: "javadoc", + pragma: "pragma", +} as const; +export type CommentType = typeof CommentType[keyof typeof CommentType]; + +/** + * This is supposed to be an enum, but Node.js v25 does bot support TS' enums, only erasable-syntax. + * Revert to an enum when Node.js supports it, or when we move to a different engine that supports it. + * This and the "type" declaration below. + */ +export const RefType = { + read: "read", + write: "write", + readwrite: "readwrite", + decl: "decl", +} as const; +export type RefType = typeof RefType[keyof typeof RefType]; const JoinpointMapper = { joinpoint: Joinpoint, - NamedType: NamedType, app: App, - catch: Catch, - declaration: Declaration, + libMethod: LibMethod, + xmlNode: XmlNode, + androidManifest: AndroidManifest, + xmlElement: XmlElement, + file: FileJp, + NamedType: NamedType, + type: Type, + class: Class, + interfaceType: InterfaceType, executable: Executable, + method: Method, + constructor: Constructor, + anonymousExec: AnonymousExec, + declaration: Declaration, + catch: Catch, + statement: Statement, + callStatement: CallStatement, + assignment: Assignment, + opAssignment: OpAssignment, expression: Expression, - field: Field, - file: FileJp, - libClass: LibClass, - libMethod: LibMethod, + annotation: Annotation, + var: Var, + fieldAccess: FieldAccess, literal: Literal, - method: Method, + call: Call, new: New, - reference: Reference, - snippetExpr: SnippetExpr, - statement: Statement, - switch: Switch, - ternary: Ternary, - this: This, - throw: Throw, - try: Try, - type: Type, - typeReference: TypeReference, + binaryExpression: BinaryExpression, unaryExpression: UnaryExpression, - var: Var, - xmlNode: XmlNode, - androidManifest: AndroidManifest, - annotation: Annotation, - anonymousExec: AnonymousExec, + ternary: Ternary, arrayAccess: ArrayAccess, + this: This, + snippetExpr: SnippetExpr, + return: Return, + comment: Comment, + pragma: Pragma, assert: Assert, - assignment: Assignment, - binaryExpression: BinaryExpression, - body: Body, - break: Break, - call: Call, - callStatement: CallStatement, + throw: Throw, + switch: Switch, case: Case, - class: Class, - comment: Comment, - constructor: Constructor, continue: Continue, - enum: Enum, + break: Break, + snippetStmt: SnippetStmt, + reference: Reference, + typeReference: TypeReference, + libClass: LibClass, + field: Field, enumValue: EnumValue, - fieldAccess: FieldAccess, - if: If, - interfaceType: InterfaceType, + body: Body, localVariable: LocalVariable, loop: Loop, - opAssignment: OpAssignment, - pragma: Pragma, - return: Return, - snippetStmt: SnippetStmt, - xmlElement: XmlElement, + if: If, + try: Try, }; let registered = false; diff --git a/Kadabra-JS/src-api/Kadabra.ts b/Kadabra-JS/api/Kadabra.ts similarity index 90% rename from Kadabra-JS/src-api/Kadabra.ts rename to Kadabra-JS/api/Kadabra.ts index 572c0854..190a19a9 100644 --- a/Kadabra-JS/src-api/Kadabra.ts +++ b/Kadabra-JS/api/Kadabra.ts @@ -1,4 +1,4 @@ -import KadabraJavaTypes from "./kadabra/KadabraJavaTypes.js"; +import KadabraJavaTypes from "./kadabra/KadabraJavaTypes.ts"; export default class Kadabra { /** diff --git a/Kadabra-JS/src-api/LegacyIntegrationTests - API.test.ts b/Kadabra-JS/api/LegacyIntegrationTests - API.test.ts similarity index 95% rename from Kadabra-JS/src-api/LegacyIntegrationTests - API.test.ts rename to Kadabra-JS/api/LegacyIntegrationTests - API.test.ts index 868b4c97..6a4900a1 100644 --- a/Kadabra-JS/src-api/LegacyIntegrationTests - API.test.ts +++ b/Kadabra-JS/api/LegacyIntegrationTests - API.test.ts @@ -1,7 +1,7 @@ -import { KadabraWeaverTester } from "../jest/KadabraLegacyTester.js"; +import { KadabraWeaverTester } from "../vitest/KadabraLegacyTester.ts"; import path from "path"; -/* eslint-disable jest/expect-expect */ +/* oxlint-disable vitest/expect-expect */ describe("ApiTest", () => { function newTester() { return new KadabraWeaverTester( diff --git a/Kadabra-JS/src-api/LegacyIntegrationTests - Issues.test.ts b/Kadabra-JS/api/LegacyIntegrationTests - Issues.test.ts similarity index 74% rename from Kadabra-JS/src-api/LegacyIntegrationTests - Issues.test.ts rename to Kadabra-JS/api/LegacyIntegrationTests - Issues.test.ts index a968dc9e..34a308fb 100644 --- a/Kadabra-JS/src-api/LegacyIntegrationTests - Issues.test.ts +++ b/Kadabra-JS/api/LegacyIntegrationTests - Issues.test.ts @@ -1,8 +1,8 @@ -import { KadabraWeaverTester } from "../jest/KadabraLegacyTester.js"; +import { KadabraWeaverTester } from "../vitest/KadabraLegacyTester.ts"; import path from "path"; -import KadabraJavaTypes from "./kadabra/KadabraJavaTypes.js"; +import KadabraJavaTypes from "./kadabra/KadabraJavaTypes.ts"; -/* eslint-disable jest/expect-expect */ +/* oxlint-disable vitest/expect-expect */ describe("IssuesTest", () => { function newTester() { return new KadabraWeaverTester( diff --git a/Kadabra-JS/src-api/LegacyIntegrationTests - Weaver.test.ts b/Kadabra-JS/api/LegacyIntegrationTests - Weaver.test.ts similarity index 94% rename from Kadabra-JS/src-api/LegacyIntegrationTests - Weaver.test.ts rename to Kadabra-JS/api/LegacyIntegrationTests - Weaver.test.ts index 5c817ef5..16ed83fa 100644 --- a/Kadabra-JS/src-api/LegacyIntegrationTests - Weaver.test.ts +++ b/Kadabra-JS/api/LegacyIntegrationTests - Weaver.test.ts @@ -1,8 +1,8 @@ -import { KadabraWeaverTester } from "../jest/KadabraLegacyTester.js"; +import { KadabraWeaverTester } from "../vitest/KadabraLegacyTester.ts"; import path from "path"; -import KadabraJavaTypes from "./kadabra/KadabraJavaTypes.js"; +import KadabraJavaTypes from "./kadabra/KadabraJavaTypes.ts"; -/* eslint-disable jest/expect-expect */ +/* oxlint-disable vitest/expect-expect */ describe("WeaverTest", () => { function newTester() { return new KadabraWeaverTester( diff --git a/Kadabra-JS/src-api/kadabra/Concurrent.ts b/Kadabra-JS/api/kadabra/Concurrent.ts similarity index 97% rename from Kadabra-JS/src-api/kadabra/Concurrent.ts rename to Kadabra-JS/api/kadabra/Concurrent.ts index 9c962dcf..84daf9ed 100644 --- a/Kadabra-JS/src-api/kadabra/Concurrent.ts +++ b/Kadabra-JS/api/kadabra/Concurrent.ts @@ -1,5 +1,5 @@ -import { getAPINames, convertPrimitive } from "./Utils.js"; -import { Class } from "../Joinpoints.js"; +import { getAPINames, convertPrimitive } from "./Utils.ts"; +import { Class } from "../Joinpoints.ts"; /** * Create an atomic field in the given class. This aspect provides outputs such as get and set of the field diff --git a/Kadabra-JS/src-api/kadabra/Factory.ts b/Kadabra-JS/api/kadabra/Factory.ts similarity index 98% rename from Kadabra-JS/src-api/kadabra/Factory.ts rename to Kadabra-JS/api/kadabra/Factory.ts index 8ccb7341..2841cc1b 100644 --- a/Kadabra-JS/src-api/kadabra/Factory.ts +++ b/Kadabra-JS/api/kadabra/Factory.ts @@ -1,5 +1,5 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import { Class, FileJp, Method, InterfaceType, App } from "../Joinpoints.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import { Class, FileJp, Method, InterfaceType, App } from "../Joinpoints.ts"; /** * Retrieves an existing class or creates a new one. diff --git a/Kadabra-JS/src-api/kadabra/KadabraAst.ts b/Kadabra-JS/api/kadabra/KadabraAst.ts similarity index 94% rename from Kadabra-JS/src-api/kadabra/KadabraAst.ts rename to Kadabra-JS/api/kadabra/KadabraAst.ts index a1f6014e..0cda1fbd 100644 --- a/Kadabra-JS/src-api/kadabra/KadabraAst.ts +++ b/Kadabra-JS/api/kadabra/KadabraAst.ts @@ -1,111 +1,111 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import KadabraJavaTypes from "./KadabraJavaTypes.js"; -import { Assignment, Class, Field, LocalVariable } from "../Joinpoints.js"; -import { LaraJoinPoint } from "@specs-feup/lara/api/LaraJoinPoint.js"; - -/** - * Utility methods related to searching join points and AST properties. - */ -export class KadabraAst { - private static _BINARY_OP_SET: Set | undefined = undefined; - private static _UNARY_OP_SET: Set | undefined = undefined; - - /** - * Searches constant values. Currently, three types of constants are returned: - * - Class fields which are final and initialized when declared; - * - Assignments to final fields; - * - Local variables which are final and initialized when declared. - * - * @param startingPoint - The join point where the search for constants will start (inclusive). - * @returns An array of join points, which can either be a field, an assignment, or a local variable. - */ - static getConstantInitializations( - startingPoint?: LaraJoinPoint - ): (Field | Assignment | LocalVariable)[] { - startingPoint ??= Query.root(); - - const constants: (Field | Assignment | LocalVariable)[] = []; - - // Search for final fields with initializations - for (const field of Query.searchFromInclusive(startingPoint, Field)) { - if (field.init !== undefined && field.isFinal) { - constants.push(field); - } - } - - // Search for assignments to final fields - for (const assign of Query.searchFromInclusive( - startingPoint, - Assignment - )) { - if (assign.lhs.isFinal) { - constants.push(assign); - } - } - - // Search for final local variables with initializations - for (const localVar of Query.searchFromInclusive( - startingPoint, - LocalVariable - )) { - if (localVar.init !== undefined && localVar.isFinal) { - constants.push(localVar); - } - } - return constants; - } - - /** - * Retrieves a set of valid binary operators. - * - * @returns A Set with valid binary operators. - */ - static getBinaryOperators(): Set { - if (this._BINARY_OP_SET === undefined) { - this._BINARY_OP_SET = new Set(); - for (const binaryOp of KadabraJavaTypes.OperatorUtils.getValidBinaryStrings()) { - this._BINARY_OP_SET.add(binaryOp); - } - } - return this._BINARY_OP_SET; - } - - /** - * Retrieves a set of valid unary operators. - * - * @returns A Set with valid unary operators. - */ - static getUnaryOperators(): Set { - if (this._UNARY_OP_SET === undefined) { - this._UNARY_OP_SET = new Set(); - for (const unaryOp of KadabraJavaTypes.OperatorUtils.getValidUnaryStrings()) { - this._UNARY_OP_SET.add(unaryOp); - } - } - return this._UNARY_OP_SET; - } - - /** - * Creates an object representing the class hierarchy of the current program. - * - * @returns A map where the keys are strings with the fully qualified name of the class, - * and the value is an array with class join points that are subclasses of the class represented by the key. - * If the map returns undefined, this means that the class has no subclasses. - */ - static getHierarchy(): Map { - const hierarchy: Map = new Map(); - - for (const cls of Query.search(Class)) { - const superClass = cls.superClass; - const subClasses = hierarchy.get(superClass); - - if (subClasses === undefined) { - hierarchy.set(superClass, [cls]); - } else { - subClasses.push(); - } - } - - return hierarchy; - } -} +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import KadabraJavaTypes from "./KadabraJavaTypes.ts"; +import { Assignment, Class, Field, LocalVariable } from "../Joinpoints.ts"; +import { LaraJoinPoint } from "@specs-feup/lara/api/LaraJoinPoint.ts"; + +/** + * Utility methods related to searching join points and AST properties. + */ +export class KadabraAst { + private static _BINARY_OP_SET: Set | undefined = undefined; + private static _UNARY_OP_SET: Set | undefined = undefined; + + /** + * Searches constant values. Currently, three types of constants are returned: + * - Class fields which are final and initialized when declared; + * - Assignments to final fields; + * - Local variables which are final and initialized when declared. + * + * @param startingPoint - The join point where the search for constants will start (inclusive). + * @returns An array of join points, which can either be a field, an assignment, or a local variable. + */ + static getConstantInitializations( + startingPoint?: LaraJoinPoint + ): (Field | Assignment | LocalVariable)[] { + startingPoint ??= Query.root(); + + const constants: (Field | Assignment | LocalVariable)[] = []; + + // Search for final fields with initializations + for (const field of Query.searchFromInclusive(startingPoint, Field)) { + if (field.init !== undefined && field.isFinal) { + constants.push(field); + } + } + + // Search for assignments to final fields + for (const assign of Query.searchFromInclusive( + startingPoint, + Assignment + )) { + if (assign.lhs.isFinal) { + constants.push(assign); + } + } + + // Search for final local variables with initializations + for (const localVar of Query.searchFromInclusive( + startingPoint, + LocalVariable + )) { + if (localVar.init !== undefined && localVar.isFinal) { + constants.push(localVar); + } + } + return constants; + } + + /** + * Retrieves a set of valid binary operators. + * + * @returns A Set with valid binary operators. + */ + static getBinaryOperators(): Set { + if (this._BINARY_OP_SET === undefined) { + this._BINARY_OP_SET = new Set(); + for (const binaryOp of KadabraJavaTypes.OperatorUtils.getValidBinaryStrings()) { + this._BINARY_OP_SET.add(binaryOp); + } + } + return this._BINARY_OP_SET; + } + + /** + * Retrieves a set of valid unary operators. + * + * @returns A Set with valid unary operators. + */ + static getUnaryOperators(): Set { + if (this._UNARY_OP_SET === undefined) { + this._UNARY_OP_SET = new Set(); + for (const unaryOp of KadabraJavaTypes.OperatorUtils.getValidUnaryStrings()) { + this._UNARY_OP_SET.add(unaryOp); + } + } + return this._UNARY_OP_SET; + } + + /** + * Creates an object representing the class hierarchy of the current program. + * + * @returns A map where the keys are strings with the fully qualified name of the class, + * and the value is an array with class join points that are subclasses of the class represented by the key. + * If the map returns undefined, this means that the class has no subclasses. + */ + static getHierarchy(): Map { + const hierarchy: Map = new Map(); + + for (const cls of Query.search(Class)) { + const superClass = cls.superClass; + const subClasses = hierarchy.get(superClass); + + if (subClasses === undefined) { + hierarchy.set(superClass, [cls]); + } else { + subClasses.push(); + } + } + + return hierarchy; + } +} diff --git a/Kadabra-JS/src-api/kadabra/KadabraJavaTypes.ts b/Kadabra-JS/api/kadabra/KadabraJavaTypes.ts similarity index 86% rename from Kadabra-JS/src-api/kadabra/KadabraJavaTypes.ts rename to Kadabra-JS/api/kadabra/KadabraJavaTypes.ts index 8614480e..a75f3d78 100644 --- a/Kadabra-JS/src-api/kadabra/KadabraJavaTypes.ts +++ b/Kadabra-JS/api/kadabra/KadabraJavaTypes.ts @@ -1,17 +1,17 @@ import JavaTypes, { - JavaClasses, -} from "@specs-feup/lara/api/lara/util/JavaTypes.js"; + type JavaClasses, +} from "@specs-feup/lara/api/lara/util/JavaTypes.ts"; -// eslint-disable-next-line @typescript-eslint/no-namespace +// oxlint-disable-next-line typescript/no-namespace export namespace KadabraJavaClasses { - /* eslint-disable @typescript-eslint/no-empty-object-type */ + /* oxlint-disable typescript/no-empty-object-type */ export interface ArgumentsParser extends JavaClasses.JavaClass {} export interface KadabraLauncher extends JavaClasses.JavaClass {} export interface JavaWeaverKeys extends JavaClasses.JavaClass {} export interface KadabraJoinPoints extends JavaClasses.JavaClass {} export interface OperatorUtils extends JavaClasses.JavaClass {} export interface AndroidResources extends JavaClasses.JavaClass {} - /* eslint-enable @typescript-eslint/no-empty-object-type */ + /* oxlint-enable typescript/no-empty-object-type */ } /** diff --git a/Kadabra-JS/src-api/kadabra/KadabraNodes.ts b/Kadabra-JS/api/kadabra/KadabraNodes.ts similarity index 96% rename from Kadabra-JS/src-api/kadabra/KadabraNodes.ts rename to Kadabra-JS/api/kadabra/KadabraNodes.ts index 3eefe03b..574cdeaf 100644 --- a/Kadabra-JS/src-api/kadabra/KadabraNodes.ts +++ b/Kadabra-JS/api/kadabra/KadabraNodes.ts @@ -1,10 +1,10 @@ import { wrapJoinPoint, unwrapJoinPoint, -} from "@specs-feup/lara/api/LaraJoinPoint.js"; -import { Joinpoint, LocalVariable } from "../Joinpoints.js"; -import KadabraJavaTypes from "./KadabraJavaTypes.js"; -import Weaver from "@specs-feup/lara/api/weaver/Weaver.js"; +} from "@specs-feup/lara/api/LaraJoinPoint.ts"; +import { Joinpoint, LocalVariable } from "../Joinpoints.ts"; +import KadabraJavaTypes from "./KadabraJavaTypes.ts"; +import Weaver from "@specs-feup/lara/api/weaver/Weaver.ts"; export class KadabraNodes { /** diff --git a/Kadabra-JS/src-api/kadabra/Metrics.ts b/Kadabra-JS/api/kadabra/Metrics.ts similarity index 98% rename from Kadabra-JS/src-api/kadabra/Metrics.ts rename to Kadabra-JS/api/kadabra/Metrics.ts index a05b64e6..03d1586a 100644 --- a/Kadabra-JS/src-api/kadabra/Metrics.ts +++ b/Kadabra-JS/api/kadabra/Metrics.ts @@ -1,5 +1,5 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import { object2string } from "@specs-feup/lara/api/core/output.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import { object2string } from "@specs-feup/lara/api/core/output.ts"; import { Body, Case, @@ -8,7 +8,7 @@ import { Method, Statement, Type, -} from "../Joinpoints.js"; +} from "../Joinpoints.ts"; /** * Main function to extract metrics and print the report. diff --git a/Kadabra-JS/src-api/kadabra/Transform.ts b/Kadabra-JS/api/kadabra/Transform.ts similarity index 97% rename from Kadabra-JS/src-api/kadabra/Transform.ts rename to Kadabra-JS/api/kadabra/Transform.ts index a40df1f6..25cee324 100644 --- a/Kadabra-JS/src-api/kadabra/Transform.ts +++ b/Kadabra-JS/api/kadabra/Transform.ts @@ -1,4 +1,4 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; import { Method, InterfaceType, @@ -7,8 +7,8 @@ import { Field, App, FileJp, -} from "../Joinpoints.js"; -import { generateFunctionalInterface } from "./Factory.js"; +} from "../Joinpoints.ts"; +import { generateFunctionalInterface } from "./Factory.ts"; /** * Prepares a given method call by: diff --git a/Kadabra-JS/src-api/kadabra/Types.ts b/Kadabra-JS/api/kadabra/Types.ts similarity index 92% rename from Kadabra-JS/src-api/kadabra/Types.ts rename to Kadabra-JS/api/kadabra/Types.ts index dcaeeb19..9acb07ea 100644 --- a/Kadabra-JS/src-api/kadabra/Types.ts +++ b/Kadabra-JS/api/kadabra/Types.ts @@ -111,14 +111,16 @@ export function isPrimitive(type: string): boolean { return PRIMITIVE_TYPES.includes(type); } -export enum Types { - "bool", - "int", - "char", - "void", - "byte", - "short", - "long", - "float", - "double", -} +// oxlint-disable-next-line eslint/no-redeclare +export const Types = { + bool: 0, + int: 1, + char: 2, + void: 3, + byte: 4, + short: 5, + long: 6, + float: 7, + double: 8, +} as const; +export type Types = (typeof Types)[keyof typeof Types]; diff --git a/Kadabra-JS/src-api/kadabra/Utils.ts b/Kadabra-JS/api/kadabra/Utils.ts similarity index 97% rename from Kadabra-JS/src-api/kadabra/Utils.ts rename to Kadabra-JS/api/kadabra/Utils.ts index ee3229e2..e46c4923 100644 --- a/Kadabra-JS/src-api/kadabra/Utils.ts +++ b/Kadabra-JS/api/kadabra/Utils.ts @@ -1,5 +1,5 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import { App, Class, Method, Return } from "../Joinpoints.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import { App, Class, Method, Return } from "../Joinpoints.ts"; /** * Opens a window with the AST of Spoon. diff --git a/Kadabra-JS/src-api/kadabra/adapt/Adapter.ts b/Kadabra-JS/api/kadabra/adapt/Adapter.ts similarity index 97% rename from Kadabra-JS/src-api/kadabra/adapt/Adapter.ts rename to Kadabra-JS/api/kadabra/adapt/Adapter.ts index 436c1717..0eb5c71a 100644 --- a/Kadabra-JS/src-api/kadabra/adapt/Adapter.ts +++ b/Kadabra-JS/api/kadabra/adapt/Adapter.ts @@ -1,6 +1,6 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import { Class, Field, FileJp, Method } from "../../Joinpoints.js"; -import { getOrNewClass } from "../Factory.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import { Class, Field, FileJp, Method } from "../../Joinpoints.ts"; +import { getOrNewClass } from "../Factory.ts"; export function CreateClassGenerator( adapterMethod: string, diff --git a/Kadabra-JS/src-api/kadabra/adapt/Algorithm.ts b/Kadabra-JS/api/kadabra/adapt/Algorithm.ts similarity index 96% rename from Kadabra-JS/src-api/kadabra/adapt/Algorithm.ts rename to Kadabra-JS/api/kadabra/adapt/Algorithm.ts index e6692dd2..cd563342 100644 --- a/Kadabra-JS/src-api/kadabra/adapt/Algorithm.ts +++ b/Kadabra-JS/api/kadabra/adapt/Algorithm.ts @@ -1,6 +1,6 @@ -import { InterfaceType, Method } from "../../Joinpoints.js"; -import { getMethod } from "../Utils.js"; -import { FunctionGenerator, TransformMethod } from "./Adapter.js"; +import { InterfaceType, Method } from "../../Joinpoints.ts"; +import { getMethod } from "../Utils.ts"; +import { FunctionGenerator, TransformMethod } from "./Adapter.ts"; export abstract class Algorithm { public static readonly PACKAGE = "autotuner.algorithm."; diff --git a/Kadabra-JS/src-api/kadabra/adapt/Autotuner.ts b/Kadabra-JS/api/kadabra/adapt/Autotuner.ts similarity index 98% rename from Kadabra-JS/src-api/kadabra/adapt/Autotuner.ts rename to Kadabra-JS/api/kadabra/adapt/Autotuner.ts index 2868af98..10077a7c 100644 --- a/Kadabra-JS/src-api/kadabra/adapt/Autotuner.ts +++ b/Kadabra-JS/api/kadabra/adapt/Autotuner.ts @@ -1,4 +1,4 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; import { App, Class, @@ -7,18 +7,18 @@ import { Joinpoint, Method, Statement, -} from "../../Joinpoints.js"; -import { newClass } from "../Factory.js"; +} from "../../Joinpoints.ts"; +import { newClass } from "../Factory.ts"; import { AdaptiveAlgorithm, Algorithm, AlgorithmWithKnob, GenerativeAlgorithm, SimpleAlgorithm, -} from "./Algorithm.js"; -import { Measurer } from "./Measurers.js"; -import { primitive2Class } from "../Utils.js"; -import { Configs, Configuration, PrimitiveRange } from "./Configs.js"; +} from "./Algorithm.ts"; +import { Measurer } from "./Measurers.ts"; +import { primitive2Class } from "../Utils.ts"; +import { Configs, Configuration, PrimitiveRange } from "./Configs.ts"; /****** * Algorithms Autotuner diff --git a/Kadabra-JS/src-api/kadabra/adapt/Configs.ts b/Kadabra-JS/api/kadabra/adapt/Configs.ts similarity index 98% rename from Kadabra-JS/src-api/kadabra/adapt/Configs.ts rename to Kadabra-JS/api/kadabra/adapt/Configs.ts index d7a742e7..01c2ec6a 100644 --- a/Kadabra-JS/src-api/kadabra/adapt/Configs.ts +++ b/Kadabra-JS/api/kadabra/adapt/Configs.ts @@ -1,5 +1,5 @@ -import { Field } from "../../Joinpoints.js"; -import { primitive2Class } from "../Utils.js"; +import { Field } from "../../Joinpoints.ts"; +import { primitive2Class } from "../Utils.ts"; /** * Class defining the structure of an autotuner diff --git a/Kadabra-JS/src-api/kadabra/adapt/DataFeature.ts b/Kadabra-JS/api/kadabra/adapt/DataFeature.ts similarity index 87% rename from Kadabra-JS/src-api/kadabra/adapt/DataFeature.ts rename to Kadabra-JS/api/kadabra/adapt/DataFeature.ts index caccee8a..72ed8b7f 100644 --- a/Kadabra-JS/src-api/kadabra/adapt/DataFeature.ts +++ b/Kadabra-JS/api/kadabra/adapt/DataFeature.ts @@ -1,5 +1,5 @@ -import { Class } from "../../Joinpoints.js"; -import { newClass } from "../Factory.js"; +import { Class } from "../../Joinpoints.ts"; +import { newClass } from "../Factory.ts"; export default class DataFeature { static readonly PACKAGE = "kadabra.adapt.features"; diff --git a/Kadabra-JS/src-api/kadabra/adapt/Measurers.ts b/Kadabra-JS/api/kadabra/adapt/Measurers.ts similarity index 97% rename from Kadabra-JS/src-api/kadabra/adapt/Measurers.ts rename to Kadabra-JS/api/kadabra/adapt/Measurers.ts index 04d3b2e2..b5c58564 100644 --- a/Kadabra-JS/src-api/kadabra/adapt/Measurers.ts +++ b/Kadabra-JS/api/kadabra/adapt/Measurers.ts @@ -1,4 +1,4 @@ -import Timer from "../monitor/Timer.js"; +import Timer from "../monitor/Timer.ts"; export class Measurer { type: string; diff --git a/Kadabra-JS/src-api/kadabra/adapt/Specializer.ts b/Kadabra-JS/api/kadabra/adapt/Specializer.ts similarity index 98% rename from Kadabra-JS/src-api/kadabra/adapt/Specializer.ts rename to Kadabra-JS/api/kadabra/adapt/Specializer.ts index de700796..d9c95db8 100644 --- a/Kadabra-JS/src-api/kadabra/adapt/Specializer.ts +++ b/Kadabra-JS/api/kadabra/adapt/Specializer.ts @@ -1,4 +1,4 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; import { App, Call, @@ -6,7 +6,7 @@ import { FileJp, InterfaceType, Method, -} from "../../Joinpoints.js"; +} from "../../Joinpoints.ts"; /** * Prepares a given method call by:
diff --git a/Kadabra-JS/src-api/kadabra/adapt/VersionTester.ts b/Kadabra-JS/api/kadabra/adapt/VersionTester.ts similarity index 98% rename from Kadabra-JS/src-api/kadabra/adapt/VersionTester.ts rename to Kadabra-JS/api/kadabra/adapt/VersionTester.ts index fcf7c42e..c1d172a1 100644 --- a/Kadabra-JS/src-api/kadabra/adapt/VersionTester.ts +++ b/Kadabra-JS/api/kadabra/adapt/VersionTester.ts @@ -1,6 +1,6 @@ -import { Class } from "../../Joinpoints.js"; -import Timer from "../monitor/Timer.js"; -import { convertPrimitive } from "../Utils.js"; +import { Class } from "../../Joinpoints.ts"; +import Timer from "../monitor/Timer.ts"; +import { convertPrimitive } from "../Utils.ts"; /** * Provides basic functionality to test versions by:
diff --git a/Kadabra-JS/src-api/kadabra/analysis/energy/EnergyAwareAndroidPatterns.ts b/Kadabra-JS/api/kadabra/analysis/energy/EnergyAwareAndroidPatterns.ts similarity index 89% rename from Kadabra-JS/src-api/kadabra/analysis/energy/EnergyAwareAndroidPatterns.ts rename to Kadabra-JS/api/kadabra/analysis/energy/EnergyAwareAndroidPatterns.ts index 4b49a2de..76213ab8 100644 --- a/Kadabra-JS/src-api/kadabra/analysis/energy/EnergyAwareAndroidPatterns.ts +++ b/Kadabra-JS/api/kadabra/analysis/energy/EnergyAwareAndroidPatterns.ts @@ -1,10 +1,10 @@ -import WeaverOptions from "@specs-feup/lara/api/weaver/WeaverOptions.js"; -import { JSONtoFile } from "@specs-feup/lara/api/core/output.js"; -import MemberIgnoringMethodDetector from "./detectors/MemberIgnoringMethodDetector.js"; -import InternalGetterDetector from "./detectors/InternalGetterDetector.js"; -import HashMapUsageDetector from "./detectors/HashMapUsageDetector.js"; -import ExcessiveMethodCallsDetector from "./detectors/ExcessiveMethodCallsDetector.js"; -import BaseDetector from "./detectors/BaseDetector.js"; +import WeaverOptions from "@specs-feup/lara/api/weaver/WeaverOptions.ts"; +import { JSONtoFile } from "@specs-feup/lara/api/core/output.ts"; +import MemberIgnoringMethodDetector from "./detectors/MemberIgnoringMethodDetector.ts"; +import InternalGetterDetector from "./detectors/InternalGetterDetector.ts"; +import HashMapUsageDetector from "./detectors/HashMapUsageDetector.ts"; +import ExcessiveMethodCallsDetector from "./detectors/ExcessiveMethodCallsDetector.ts"; +import BaseDetector from "./detectors/BaseDetector.ts"; export interface Report { sources: string[]; diff --git a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/BaseDetector.ts b/Kadabra-JS/api/kadabra/analysis/energy/detectors/BaseDetector.ts similarity index 90% rename from Kadabra-JS/src-api/kadabra/analysis/energy/detectors/BaseDetector.ts rename to Kadabra-JS/api/kadabra/analysis/energy/detectors/BaseDetector.ts index 8f8012b0..731feb90 100644 --- a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/BaseDetector.ts +++ b/Kadabra-JS/api/kadabra/analysis/energy/detectors/BaseDetector.ts @@ -1,5 +1,5 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import { Class, Joinpoint } from "../../../../Joinpoints.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import { Class, Joinpoint } from "../../../../Joinpoints.ts"; export default class BaseDetector { name: string; diff --git a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/ExcessiveMethodCallsDetector.ts b/Kadabra-JS/api/kadabra/analysis/energy/detectors/ExcessiveMethodCallsDetector.ts similarity index 95% rename from Kadabra-JS/src-api/kadabra/analysis/energy/detectors/ExcessiveMethodCallsDetector.ts rename to Kadabra-JS/api/kadabra/analysis/energy/detectors/ExcessiveMethodCallsDetector.ts index 7d28b2c2..ef6e3416 100644 --- a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/ExcessiveMethodCallsDetector.ts +++ b/Kadabra-JS/api/kadabra/analysis/energy/detectors/ExcessiveMethodCallsDetector.ts @@ -1,6 +1,6 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import Collections from "@specs-feup/lara/api/lara/Collections.js"; -import BaseDetector from "./BaseDetector.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import Collections from "@specs-feup/lara/api/lara/Collections.ts"; +import BaseDetector from "./BaseDetector.ts"; import { FileJp, Loop, @@ -15,7 +15,7 @@ import { ArrayAccess, Constructor, Declaration, -} from "../../../../Joinpoints.js"; +} from "../../../../Joinpoints.ts"; export interface MethodInfo { method: Method; @@ -155,7 +155,7 @@ export default class ExcessiveMethodCallsDetector extends BaseDetector { this.collectLoopInfo(child); } - if (jp instanceof Loop && jp.type !== LoopType.FOREACH) { + if (jp instanceof Loop && jp.type !== LoopType.foreach) { if (jp.cond !== undefined) { for (const v of Query.searchFrom(jp.cond, Var, { declaration: (d) => d !== undefined, @@ -178,14 +178,14 @@ export default class ExcessiveMethodCallsDetector extends BaseDetector { if (jpVar.declaration === undefined) return; const isField = jpVar.isField; const access = jpVar.reference; - if (isField && access === RefType.WRITE) { + if (isField && access === RefType.write) { addIfNew(this.loopGlobalWrites, jpVar.declaration); - } else if (isField && access === RefType.READ) { + } else if (isField && access === RefType.read) { addIfNew(this.loopGlobalReads, jpVar.declaration); - } else if (isField && access === RefType.READWRITE) { + } else if (isField && access === RefType.readwrite) { addIfNew(this.loopGlobalWrites, jpVar.declaration); addIfNew(this.loopGlobalReads, jpVar.declaration); - } else if (!isField && access === RefType.WRITE) { + } else if (!isField && access === RefType.write) { addIfNew(this.loopLocalWrites, jpVar.declaration); } } @@ -272,9 +272,9 @@ export default class ExcessiveMethodCallsDetector extends BaseDetector { const write = []; for (const v of declSplit[0]) { const accessType = v.reference; - if (accessType === RefType.WRITE) write.push(v); - else if (accessType === RefType.READ) read.push(v); - else if (accessType === RefType.READWRITE) { + if (accessType === RefType.write) write.push(v); + else if (accessType === RefType.read) read.push(v); + else if (accessType === RefType.readwrite) { read.push(v); write.push(v); } @@ -343,7 +343,7 @@ export default class ExcessiveMethodCallsDetector extends BaseDetector { this.variantCalls.push(jpCall.toString()); return false; } else if ( - this.loopLocalWrites.some((w) => w.equals(v.declaration)) + this.loopLocalWrites.some((w) => w.equals(v.declaration as Declaration)) ) { this.printDebugInfo( `Call: ${jpCall} @ L${jpCall.line} -> VARIANT (usesLoopVar)` diff --git a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/HashMapUsageDetector.ts b/Kadabra-JS/api/kadabra/analysis/energy/detectors/HashMapUsageDetector.ts similarity index 88% rename from Kadabra-JS/src-api/kadabra/analysis/energy/detectors/HashMapUsageDetector.ts rename to Kadabra-JS/api/kadabra/analysis/energy/detectors/HashMapUsageDetector.ts index 0691a15e..619a9bb7 100644 --- a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/HashMapUsageDetector.ts +++ b/Kadabra-JS/api/kadabra/analysis/energy/detectors/HashMapUsageDetector.ts @@ -1,7 +1,7 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import Collections from "@specs-feup/lara/api/lara/Collections.js"; -import BaseDetector from "./BaseDetector.js"; -import { Class, FileJp, Method, New } from "../../../../Joinpoints.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import Collections from "@specs-feup/lara/api/lara/Collections.ts"; +import BaseDetector from "./BaseDetector.ts"; +import { Class, FileJp, Method, New } from "../../../../Joinpoints.ts"; export default class HashMapUsageDetector extends BaseDetector { constructor() { diff --git a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/InternalGetterDetector.ts b/Kadabra-JS/api/kadabra/analysis/energy/detectors/InternalGetterDetector.ts similarity index 91% rename from Kadabra-JS/src-api/kadabra/analysis/energy/detectors/InternalGetterDetector.ts rename to Kadabra-JS/api/kadabra/analysis/energy/detectors/InternalGetterDetector.ts index 26c17ee8..a9a4250b 100644 --- a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/InternalGetterDetector.ts +++ b/Kadabra-JS/api/kadabra/analysis/energy/detectors/InternalGetterDetector.ts @@ -1,6 +1,6 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import Collections from "@specs-feup/lara/api/lara/Collections.js"; -import BaseDetector from "./BaseDetector.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import Collections from "@specs-feup/lara/api/lara/Collections.ts"; +import BaseDetector from "./BaseDetector.ts"; import { Body, Call, @@ -10,7 +10,7 @@ import { Method, Return, Var, -} from "../../../../Joinpoints.js"; +} from "../../../../Joinpoints.ts"; export default class InternalGetterDetector extends BaseDetector { results: Call[] = []; diff --git a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/MemberIgnoringMethodDetector.ts b/Kadabra-JS/api/kadabra/analysis/energy/detectors/MemberIgnoringMethodDetector.ts similarity index 94% rename from Kadabra-JS/src-api/kadabra/analysis/energy/detectors/MemberIgnoringMethodDetector.ts rename to Kadabra-JS/api/kadabra/analysis/energy/detectors/MemberIgnoringMethodDetector.ts index d9313185..93b9ed33 100644 --- a/Kadabra-JS/src-api/kadabra/analysis/energy/detectors/MemberIgnoringMethodDetector.ts +++ b/Kadabra-JS/api/kadabra/analysis/energy/detectors/MemberIgnoringMethodDetector.ts @@ -1,6 +1,6 @@ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import Collections from "@specs-feup/lara/api/lara/Collections.js"; -import BaseDetector from "./BaseDetector.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import Collections from "@specs-feup/lara/api/lara/Collections.ts"; +import BaseDetector from "./BaseDetector.ts"; import { Annotation, Call, @@ -10,7 +10,7 @@ import { Method, Reference, Var, -} from "../../../../Joinpoints.js"; +} from "../../../../Joinpoints.ts"; export default class MemberIgnoringMethodDetector extends BaseDetector { dups: Map; diff --git a/Kadabra-JS/src-api/kadabra/monitor/Counter.ts b/Kadabra-JS/api/kadabra/monitor/Counter.ts similarity index 97% rename from Kadabra-JS/src-api/kadabra/monitor/Counter.ts rename to Kadabra-JS/api/kadabra/monitor/Counter.ts index 39f9ed49..03414bd3 100644 --- a/Kadabra-JS/src-api/kadabra/monitor/Counter.ts +++ b/Kadabra-JS/api/kadabra/monitor/Counter.ts @@ -2,7 +2,7 @@ Monitor the occurences of a given join point; */ -import Query from "@specs-feup/lara/api/weaver/Query.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; import { App, Class, @@ -10,7 +10,7 @@ import { FileJp, Method, Statement, -} from "../../Joinpoints.js"; +} from "../../Joinpoints.ts"; export function NewCounter(jpClass: Class, name = "counter", fullPath = false) { const jpField = jpClass.newField( diff --git a/Kadabra-JS/src-api/kadabra/monitor/CounterList.ts b/Kadabra-JS/api/kadabra/monitor/CounterList.ts similarity index 97% rename from Kadabra-JS/src-api/kadabra/monitor/CounterList.ts rename to Kadabra-JS/api/kadabra/monitor/CounterList.ts index dbbc8b20..bdcd5be1 100644 --- a/Kadabra-JS/src-api/kadabra/monitor/CounterList.ts +++ b/Kadabra-JS/api/kadabra/monitor/CounterList.ts @@ -2,8 +2,8 @@ Monitor the occurences of a given join point; */ -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import { App, Class, Constructor, Field, FileJp } from "../../Joinpoints.js"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import { App, Class, Constructor, Field, FileJp } from "../../Joinpoints.ts"; export function CountingMonitorList( targetClass: Class, diff --git a/Kadabra-JS/src-api/kadabra/monitor/Timer.ts b/Kadabra-JS/api/kadabra/monitor/Timer.ts similarity index 96% rename from Kadabra-JS/src-api/kadabra/monitor/Timer.ts rename to Kadabra-JS/api/kadabra/monitor/Timer.ts index bf5d0376..0afbbbef 100644 --- a/Kadabra-JS/src-api/kadabra/monitor/Timer.ts +++ b/Kadabra-JS/api/kadabra/monitor/Timer.ts @@ -1,9 +1,9 @@ -import { primitive2Class } from "../Utils.js"; -import { newClass } from "../Factory.js"; -import TimerBase from "@specs-feup/lara/api/lara/code/TimerBase.js"; -import { Class, Field, Joinpoint } from "../../Joinpoints.js"; -import Query from "@specs-feup/lara/api/weaver/Query.js"; -import { TimerUnit } from "@specs-feup/lara/api/lara/util/TimeUnits.js"; +import { primitive2Class } from "../Utils.ts"; +import { newClass } from "../Factory.ts"; +import TimerBase from "@specs-feup/lara/api/lara/code/TimerBase.ts"; +import { Class, Field, Joinpoint } from "../../Joinpoints.ts"; +import Query from "@specs-feup/lara/api/weaver/Query.ts"; +import { TimerUnit } from "@specs-feup/lara/api/lara/util/TimeUnits.ts"; type insertOptions = "before" | "after" | "replace"; diff --git a/Kadabra-JS/src-api/kadabra/mutation/ArithmeticOperatorDeletionMutation.ts b/Kadabra-JS/api/kadabra/mutation/ArithmeticOperatorDeletionMutation.ts similarity index 85% rename from Kadabra-JS/src-api/kadabra/mutation/ArithmeticOperatorDeletionMutation.ts rename to Kadabra-JS/api/kadabra/mutation/ArithmeticOperatorDeletionMutation.ts index 197bb92c..67009807 100644 --- a/Kadabra-JS/src-api/kadabra/mutation/ArithmeticOperatorDeletionMutation.ts +++ b/Kadabra-JS/api/kadabra/mutation/ArithmeticOperatorDeletionMutation.ts @@ -1,7 +1,7 @@ -import IterativeMutation from "@specs-feup/lara/api/lara/mutation/IterativeMutation.js"; -import MutationResult from "@specs-feup/lara/api/lara/mutation/MutationResult.js"; -import { debug } from "@specs-feup/lara/api/lara/core/LaraCore.js"; -import { Joinpoint, BinaryExpression } from "../../Joinpoints.js"; +import IterativeMutation from "@specs-feup/lara/api/lara/mutation/IterativeMutation.ts"; +import MutationResult from "@specs-feup/lara/api/lara/mutation/MutationResult.ts"; +import { debug } from "@specs-feup/lara/api/lara/core/LaraCore.ts"; +import { Joinpoint, BinaryExpression } from "../../Joinpoints.ts"; export default class ArithmeticOperatorDeletionMutation extends IterativeMutation { constructor() { diff --git a/Kadabra-JS/src-api/kadabra/mutation/BinaryExpressionMutation.ts b/Kadabra-JS/api/kadabra/mutation/BinaryExpressionMutation.ts similarity index 90% rename from Kadabra-JS/src-api/kadabra/mutation/BinaryExpressionMutation.ts rename to Kadabra-JS/api/kadabra/mutation/BinaryExpressionMutation.ts index 674b65b9..bec1aad8 100644 --- a/Kadabra-JS/src-api/kadabra/mutation/BinaryExpressionMutation.ts +++ b/Kadabra-JS/api/kadabra/mutation/BinaryExpressionMutation.ts @@ -1,6 +1,6 @@ -import IterativeMutation from "@specs-feup/lara/api/lara/mutation/IterativeMutation.js"; -import MutationResult from "@specs-feup/lara/api/lara/mutation/MutationResult.js"; -import { Joinpoint, BinaryExpression } from "../../Joinpoints.js"; +import IterativeMutation from "@specs-feup/lara/api/lara/mutation/IterativeMutation.ts"; +import MutationResult from "@specs-feup/lara/api/lara/mutation/MutationResult.ts"; +import { Joinpoint, BinaryExpression } from "../../Joinpoints.ts"; /** * @param newOperators - Operators that will be used to mutate the binaryExpression. diff --git a/Kadabra-JS/src-api/kadabra/mutation/BinaryExpressionMutator.ts b/Kadabra-JS/api/kadabra/mutation/BinaryExpressionMutator.ts similarity index 96% rename from Kadabra-JS/src-api/kadabra/mutation/BinaryExpressionMutator.ts rename to Kadabra-JS/api/kadabra/mutation/BinaryExpressionMutator.ts index 83b1fab8..ac7c3220 100644 --- a/Kadabra-JS/src-api/kadabra/mutation/BinaryExpressionMutator.ts +++ b/Kadabra-JS/api/kadabra/mutation/BinaryExpressionMutator.ts @@ -1,5 +1,5 @@ -import Mutator from "@specs-feup/lara/api/lara/mutation/Mutator.js"; -import { BinaryExpression } from "../../Joinpoints.js"; +import Mutator from "@specs-feup/lara/api/lara/mutation/Mutator.ts"; +import { BinaryExpression } from "../../Joinpoints.ts"; /** * @param binaryExpression - A join point of type binaryExpression. diff --git a/Kadabra-JS/src-api/kadabra/mutation/ConditionalOperatorDeletionMutation.ts b/Kadabra-JS/api/kadabra/mutation/ConditionalOperatorDeletionMutation.ts similarity index 90% rename from Kadabra-JS/src-api/kadabra/mutation/ConditionalOperatorDeletionMutation.ts rename to Kadabra-JS/api/kadabra/mutation/ConditionalOperatorDeletionMutation.ts index aababe9f..56713dca 100644 --- a/Kadabra-JS/src-api/kadabra/mutation/ConditionalOperatorDeletionMutation.ts +++ b/Kadabra-JS/api/kadabra/mutation/ConditionalOperatorDeletionMutation.ts @@ -1,13 +1,13 @@ -import IterativeMutation from "@specs-feup/lara/api/lara/mutation/IterativeMutation.js"; -import MutationResult from "@specs-feup/lara/api/lara/mutation/MutationResult.js"; -import { debug } from "@specs-feup/lara/api/lara/core/LaraCore.js"; +import IterativeMutation from "@specs-feup/lara/api/lara/mutation/IterativeMutation.ts"; +import MutationResult from "@specs-feup/lara/api/lara/mutation/MutationResult.ts"; +import { debug } from "@specs-feup/lara/api/lara/core/LaraCore.ts"; import { Loop, Joinpoint, Ternary, If, UnaryExpression, -} from "../../Joinpoints.js"; +} from "../../Joinpoints.ts"; export default class ConditionalOperatorDeletionMutation extends IterativeMutation { constructor() { diff --git a/Kadabra-JS/src-api/kadabra/system/CpuInfo.ts b/Kadabra-JS/api/kadabra/system/CpuInfo.ts similarity index 100% rename from Kadabra-JS/src-api/kadabra/system/CpuInfo.ts rename to Kadabra-JS/api/kadabra/system/CpuInfo.ts diff --git a/Kadabra-JS/src-api/lara/code/Energy.ts b/Kadabra-JS/api/lara/code/Energy.ts similarity index 95% rename from Kadabra-JS/src-api/lara/code/Energy.ts rename to Kadabra-JS/api/lara/code/Energy.ts index 7b27ea62..0f248988 100644 --- a/Kadabra-JS/src-api/lara/code/Energy.ts +++ b/Kadabra-JS/api/lara/code/Energy.ts @@ -1,8 +1,8 @@ -import EnergyBase from "@specs-feup/lara/api/lara/code/EnergyBase.js"; -import Logger from "./Logger.js"; -import IdGenerator from "@specs-feup/lara/api/lara/util/IdGenerator.js"; -import PrintOnce from "@specs-feup/lara/api/lara/util/PrintOnce.js"; -import { Joinpoint } from "../../Joinpoints.js"; +import EnergyBase from "@specs-feup/lara/api/lara/code/EnergyBase.ts"; +import Logger from "./Logger.ts"; +import IdGenerator from "@specs-feup/lara/api/lara/util/IdGenerator.ts"; +import PrintOnce from "@specs-feup/lara/api/lara/util/PrintOnce.ts"; +import { Joinpoint } from "../../Joinpoints.ts"; // TODO: Detect if Odroid or Ubuntu? const EnergyCheckClass = "weaver.kadabra.monitor.pc.ubuntu.UbuntuEnergyCheck"; diff --git a/Kadabra-JS/src-api/lara/code/Logger.ts b/Kadabra-JS/api/lara/code/Logger.ts similarity index 97% rename from Kadabra-JS/src-api/lara/code/Logger.ts rename to Kadabra-JS/api/lara/code/Logger.ts index a10d0368..b4226460 100644 --- a/Kadabra-JS/src-api/lara/code/Logger.ts +++ b/Kadabra-JS/api/lara/code/Logger.ts @@ -1,6 +1,6 @@ -import PrintOnce from "@specs-feup/lara/api/lara/util/PrintOnce.js"; -import LoggerBase from "@specs-feup/lara/api/lara/code/LoggerBase.js"; -import { Joinpoint } from "../../Joinpoints.js"; +import PrintOnce from "@specs-feup/lara/api/lara/util/PrintOnce.ts"; +import LoggerBase from "@specs-feup/lara/api/lara/code/LoggerBase.ts"; +import { Joinpoint } from "../../Joinpoints.ts"; export default class Logger extends LoggerBase { constructor(isGlobal: boolean = false, filename?: string) { diff --git a/Kadabra-JS/src-api/lara/code/Timer.ts b/Kadabra-JS/api/lara/code/Timer.ts similarity index 95% rename from Kadabra-JS/src-api/lara/code/Timer.ts rename to Kadabra-JS/api/lara/code/Timer.ts index acd4592c..3c38a817 100644 --- a/Kadabra-JS/src-api/lara/code/Timer.ts +++ b/Kadabra-JS/api/lara/code/Timer.ts @@ -1,7 +1,7 @@ -import TimerBase from "@specs-feup/lara/api/lara/code/TimerBase.js"; -import IdGenerator from "@specs-feup/lara/api/lara/util/IdGenerator.js"; -import Logger from "./Logger.js"; -import { Joinpoint } from "../../Joinpoints.js"; +import TimerBase from "@specs-feup/lara/api/lara/code/TimerBase.ts"; +import IdGenerator from "@specs-feup/lara/api/lara/util/IdGenerator.ts"; +import Logger from "./Logger.ts"; +import { Joinpoint } from "../../Joinpoints.ts"; export default class Timer extends TimerBase { time($start: Joinpoint, prefix: string, $end: Joinpoint) { diff --git a/Kadabra-JS/code/WeaverConfiguration.ts b/Kadabra-JS/code/WeaverConfiguration.ts new file mode 100644 index 00000000..729a2b05 --- /dev/null +++ b/Kadabra-JS/code/WeaverConfiguration.ts @@ -0,0 +1,15 @@ +import type WeaverConfiguration from "@specs-feup/lara/code/WeaverConfiguration.ts"; +import path from "path"; +import { fileURLToPath } from "url"; + +export const weaverConfig: WeaverConfiguration = { + weaverName: "kadabra", + weaverPrettyName: "Kadabra", + weaverFileName: "@specs-feup/lara/code/Weaver.ts", + jarPath: path.join( + path.dirname(path.dirname(fileURLToPath(import.meta.url))), + "./java-binaries/", + ), + javaWeaverQualifiedName: "weaver.kadabra.JWeaver", + importForSideEffects: ["@specs-feup/kadabra/api/Joinpoints.ts"], +}; diff --git a/Kadabra-JS/src-code/index.ts b/Kadabra-JS/code/index.ts old mode 100644 new mode 100755 similarity index 73% rename from Kadabra-JS/src-code/index.ts rename to Kadabra-JS/code/index.ts index c9782c28..bdf002b8 --- a/Kadabra-JS/src-code/index.ts +++ b/Kadabra-JS/code/index.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import WeaverLauncher from "@specs-feup/lara/code/WeaverLauncher.js"; -import { weaverConfig } from "./WeaverConfiguration.js"; +import WeaverLauncher from "@specs-feup/lara/code/WeaverLauncher.ts"; +import { weaverConfig } from "./WeaverConfiguration.ts"; const weaverLauncher = new WeaverLauncher(weaverConfig); diff --git a/Kadabra-JS/eslint.config.js b/Kadabra-JS/eslint.config.js deleted file mode 100644 index 8ed0804f..00000000 --- a/Kadabra-JS/eslint.config.js +++ /dev/null @@ -1,58 +0,0 @@ -import { fileURLToPath } from "url"; -import { dirname } from "path"; -import typescriptEslint from "typescript-eslint"; -import tsdoc from "eslint-plugin-tsdoc"; -import jest from "eslint-plugin-jest"; -import js from "@eslint/js"; -import eslintConfigPrettier from "eslint-config-prettier"; - -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); - -export default [ - js.configs.recommended, - eslintConfigPrettier, - ...typescriptEslint.configs.recommended, - { - ignores: ["**/*.d.ts", "**/*.config.js", "api", "code"], - }, - { - plugins: { - "@typescript-eslint": typescriptEslint.plugin, - tsdoc, - }, - - languageOptions: { - parser: typescriptEslint.parser, - ecmaVersion: 5, - sourceType: "script", - - parserOptions: { - project: ["./*/tsconfig.json", "./tsconfig.*.json"], - tsconfigRootDir: __dirname, - }, - }, - - rules: { - "tsdoc/syntax": "warn", - }, - }, - { - ...typescriptEslint.configs.disableTypeChecked, - files: ["scripts/**/*.js"], - }, - { - ...jest.configs["flat/recommended"], - files: ["**/*.spec.ts", "**/*.test.ts"], - - plugins: { - jest, - }, - - languageOptions: { - globals: { - ...jest.environments.globals.globals, - }, - }, - }, -]; diff --git a/Kadabra-JS/jest.config.js b/Kadabra-JS/jest.config.js deleted file mode 100644 index ea4524bf..00000000 --- a/Kadabra-JS/jest.config.js +++ /dev/null @@ -1,18 +0,0 @@ -const config = { - preset: "ts-jest/presets/default-esm", - testEnvironment: "node", - notify: true, - notifyMode: "always", - //verbose: true, - collectCoverage: false, - coverageDirectory: "coverage", - coverageReporters: ["text", "lcov"], - collectCoverageFrom: ["**/*[^.d].(t|j)s"], - coverageProvider: "v8", - moduleNameMapper: { - "(.+)\\.js": "$1", - }, - projects: ["src-api", "src-code"], -}; - -export default config; diff --git a/Kadabra-JS/oxlint.config.ts b/Kadabra-JS/oxlint.config.ts new file mode 100644 index 00000000..b79245d6 --- /dev/null +++ b/Kadabra-JS/oxlint.config.ts @@ -0,0 +1,26 @@ +import config from "@specs-feup/lara/oxlint.config.ts"; +import { defineConfig } from "oxlint"; + +export default defineConfig({ + extends: [config], + overrides: [ + { + // Generated file: the enums use the const + type merged declaration + // pattern, and 'if'/'ternary' join points have a 'then' attribute. + files: ["api/Joinpoints.ts"], + rules: { + "eslint/no-redeclare": "off", + "unicorn/no-thenable": "off", + }, + }, + { + // Legacy API code that predates the lara-4 migration: uses template + // literals with non-string values and detached method references. + files: ["api/kadabra/**"], + rules: { + "typescript/restrict-template-expressions": "off", + "typescript/unbound-method": "off", + }, + }, + ], +}); diff --git a/Kadabra-JS/package.json b/Kadabra-JS/package.json index d511beb2..28bcb636 100644 --- a/Kadabra-JS/package.json +++ b/Kadabra-JS/package.json @@ -1,41 +1,50 @@ { "name": "@specs-feup/kadabra", - "version": "1.5.1", + "version": "4.0.0", "description": "A Java source-to-source compiler written in Typescript", "type": "module", + "bin": { + "kadabra": "./code/index.ts" + }, + "exports": { + "./api/*.test.ts": null, + "./api/*.config.ts": null, + "./api/*.js": "./api/*.ts", + "./api/*": "./api/*.ts", + "./api/*.ts": "./api/*.ts", + "./code/*.test.ts": null, + "./code/*.config.ts": null, + "./code/*.js": "./code/*.ts", + "./code/*": "./code/*.ts", + "./code/*.ts": "./code/*.ts" + }, "files": [ + ".gitignore", + "LICENSE", + "README.md", "api", "code", - "jest", - "src-api", - "src-code", "java-binaries", - ".gitignore", - "eslint.config.js", - "jest.config.js", - "LICENSE", + "oxlint.config.ts", "package.json", - "README.md", - "tsconfig.jest.json", "tsconfig.json", - "typedoc.config.js" + "typedoc.config.js", + "vitest.config.ts" ], - "bin": { - "kadabra": "code/index.js" - }, "scripts": { - "run": "node ./code/index.js", - "build": "tsc -b src-api src-code", - "build:api": "tsc -b src-api", - "build:code": "tsc -b src-code", + "run": "node ./code/index.ts", + "build": "tsc", "build:watch": "npm run build -- --watch", - "lint": "eslint .", - "test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --detectOpenHandles --forceExit", - "test:api": "npm run test -- src-api", - "test:code": "npm run test -- src-code", + "lint": "oxlint .", + "format": "oxfmt .", + "format:check": "oxfmt --check .", + "prepack": "node --input-type=module --eval \"import { validateJavaBinaries } from '@specs-feup/lara/scripts/validateJavaBinaries.js'; validateJavaBinaries();\"", + "test": "vitest run", + "test:api": "npm run test -- api", + "test:code": "npm run test -- code", "test:cov": "npm run test -- --coverage", "test:watch": "npm run test -- --watch", - "build-interfaces": "npx lara-build-interfaces --input ../JavaWeaver/src/weaver/kadabra/JavaWeaver.json --lara @specs-feup/lara/LaraJoinPointSpecification.json --output src-api/Joinpoints.ts" + "build-interfaces": "lara-build-interfaces --input ../JavaWeaver/src/weaver/kadabra/JWeaver.json --lara @specs-feup/lara/LaraJoinPointSpecification.json --output api/Joinpoints.ts" }, "repository": { "type": "git", @@ -55,24 +64,18 @@ }, "homepage": "https://github.com/specs-feup/kadabra#readme", "dependencies": { - "@specs-feup/lara": "~3.5.0" + "@specs-feup/lara": "^4.0.0" }, "devDependencies": { - "@jest/globals": "~30.3.0", "@types/debug": "^4.1.12", "@types/java": "^0.9.6", - "@types/jest": "^30.0.0", - "@types/node": "^20.14.10", + "@types/node": "^24.0.0", "@types/yargs": "^17.0.35", - "cross-env": "^10.1.0", - "eslint": "^9.39.2", - "eslint-config-prettier": "^10.1.8", - "eslint-plugin-jest": "^29.12.1", - "eslint-plugin-tsdoc": "^0.5.0", - "jest": "~30.3.0", - "node-notifier": "^10.0.1", - "ts-jest": "^29.4.6", - "typescript": "^5.9.3", - "typescript-eslint": "^8.52.0" + "@vitest/coverage-v8": "^4.1.10", + "oxfmt": "^0.59.0", + "oxlint": "^1.74.0", + "oxlint-tsgolint": "^7.0.2001", + "typescript": "^7.0.2", + "vitest": "^4.1.10" } } diff --git a/Kadabra-JS/src-api/jest.config.js b/Kadabra-JS/src-api/jest.config.js deleted file mode 100644 index 4a344f8e..00000000 --- a/Kadabra-JS/src-api/jest.config.js +++ /dev/null @@ -1,26 +0,0 @@ -import { weaverConfig } from "../code/WeaverConfiguration.js"; - -const config = { - preset: "ts-jest/presets/default-esm", - - testEnvironment: "@specs-feup/lara/jest/jestEnvironment.js", - - globalSetup: "@specs-feup/lara/jest/jestGlobalSetup.js", - globalTeardown: "@specs-feup/lara/jest/jestGlobalTeardown.js", - - setupFiles: ["@specs-feup/lara/jest/setupFiles/sharedJavaModule.js"], - setupFilesAfterEnv: ["@specs-feup/lara/jest/setupFiles/importSideEffects.js"], - - moduleNameMapper: { - "^@specs-feup/kadabra/api/(.+)\\.js$": "/$1", - "^@specs-feup/lara/jest/WeaverLegacyTester\\.js$": - "@specs-feup/lara/jest/WeaverLegacyTester.ts", - "^(\\.{1,2}/.*)\\.js$": "$1", - }, - - testEnvironmentOptions: { - weaverConfig, - }, -}; - -export default config; diff --git a/Kadabra-JS/src-api/tsconfig.json b/Kadabra-JS/src-api/tsconfig.json deleted file mode 100644 index b03a6a89..00000000 --- a/Kadabra-JS/src-api/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "outDir": "../api" - }, - "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"], - "references": [{ "path": "../src-code" }] -} diff --git a/Kadabra-JS/src-code/WeaverConfiguration.ts b/Kadabra-JS/src-code/WeaverConfiguration.ts deleted file mode 100644 index 3542de88..00000000 --- a/Kadabra-JS/src-code/WeaverConfiguration.ts +++ /dev/null @@ -1,16 +0,0 @@ -import WeaverConfiguration from "@specs-feup/lara/code/WeaverConfiguration.js"; -import path from "path"; -import { fileURLToPath } from "url"; - -export const weaverConfig: WeaverConfiguration = { - weaverName: "kadabra", - weaverPrettyName: "Kadabra", - weaverFileName: "@specs-feup/lara/code/Weaver.js", - jarPath: path.join( - path.dirname(path.dirname(fileURLToPath(import.meta.url))), - "./java-binaries/", - ), - javaWeaverQualifiedName: "weaver.kadabra.JavaWeaver", - //importForSideEffects: ["@specs-feup/kadabra/api/Joinpoints.js"], - importForSideEffects: [new URL("../api/Joinpoints.js", import.meta.url).href], -}; diff --git a/Kadabra-JS/src-code/jest.config.js b/Kadabra-JS/src-code/jest.config.js deleted file mode 100644 index f8502043..00000000 --- a/Kadabra-JS/src-code/jest.config.js +++ /dev/null @@ -1,9 +0,0 @@ -const config = { - preset: "ts-jest/presets/default-esm", - testEnvironment: "node", - moduleNameMapper: { - "(.+)\\.js": "$1", - }, -}; - -export default config; diff --git a/Kadabra-JS/src-code/tsconfig.json b/Kadabra-JS/src-code/tsconfig.json deleted file mode 100644 index 8061f3ca..00000000 --- a/Kadabra-JS/src-code/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "outDir": "../code", - "composite": true - }, - "exclude": ["node_modules", "**/*.spec.ts", "**/*.test.ts"] -} diff --git a/Kadabra-JS/tsconfig.jest.json b/Kadabra-JS/tsconfig.jest.json deleted file mode 100644 index dd7eedda..00000000 --- a/Kadabra-JS/tsconfig.jest.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": ["**/*.spec.ts", "**/*.test.ts"], - "exclude": ["node_modules"] -} diff --git a/Kadabra-JS/tsconfig.json b/Kadabra-JS/tsconfig.json index 855a6752..416c1093 100644 --- a/Kadabra-JS/tsconfig.json +++ b/Kadabra-JS/tsconfig.json @@ -1,16 +1,14 @@ { "compilerOptions": { - "target": "ES2022", + "noEmit": true, "module": "NodeNext", "declaration": true, "strict": true, - //"allowJs": true, - //"checkJs": true, - "moduleResolution": "NodeNext", "isolatedModules": true, - "sourceMap": true, - "declarationMap": true, - "allowSyntheticDefaultImports": true - //"esModuleInterop": true + "allowSyntheticDefaultImports": true, + "types": ["node", "vitest/globals"], + "rewriteRelativeImportExtensions": true, + "erasableSyntaxOnly": true, + "verbatimModuleSyntax": true } } diff --git a/Kadabra-JS/typedoc.config.js b/Kadabra-JS/typedoc.config.js index b000de54..357b6153 100644 --- a/Kadabra-JS/typedoc.config.js +++ b/Kadabra-JS/typedoc.config.js @@ -4,6 +4,6 @@ export default { extends: [ fileURLToPath(import.meta.resolve("@specs-feup/lara/typedoc.base.json")), ], - entryPoints: ["src-api/"], - tsconfig: "src-api/tsconfig.json", + entryPoints: ["api/"], + tsconfig: "tsconfig.json", }; diff --git a/Kadabra-JS/vitest.config.ts b/Kadabra-JS/vitest.config.ts new file mode 100644 index 00000000..8a6562ca --- /dev/null +++ b/Kadabra-JS/vitest.config.ts @@ -0,0 +1,4 @@ +import { createWeaverVitestConfig } from "@specs-feup/lara/vitest/weaverVitestConfig.ts"; +import { weaverConfig } from "./code/WeaverConfiguration.ts"; + +export default createWeaverVitestConfig(weaverConfig); diff --git a/Kadabra-JS/jest/KadabraLegacyTester.ts b/Kadabra-JS/vitest/KadabraLegacyTester.ts similarity index 77% rename from Kadabra-JS/jest/KadabraLegacyTester.ts rename to Kadabra-JS/vitest/KadabraLegacyTester.ts index 370a55ab..be8619d9 100644 --- a/Kadabra-JS/jest/KadabraLegacyTester.ts +++ b/Kadabra-JS/vitest/KadabraLegacyTester.ts @@ -1,5 +1,5 @@ -import { WeaverLegacyTester } from "@specs-feup/lara/jest/WeaverLegacyTester.js"; -import JavaTypes from "@specs-feup/lara/api/lara/util/JavaTypes.js"; +import { WeaverLegacyTester } from "@specs-feup/lara/vitest/WeaverLegacyTester.ts"; +import JavaTypes from "@specs-feup/lara/api/lara/util/JavaTypes.ts"; export class KadabraWeaverTester extends WeaverLegacyTester { public constructor(basePackage: string) {