From 647f43c39b458ddf044d837335ca6a4400d5e29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Bispo?= Date: Sun, 5 Jan 2025 15:50:44 +0000 Subject: [PATCH] [WeaverGenerator] Removes option L, deletes unused class --- .../commandline/OldWeaverGenerator.java | 184 ------------------ .../commandline/WeaverGenerator.java | 8 - .../commandline/WeaverGeneratorOptions.java | 65 +++---- 3 files changed, 25 insertions(+), 232 deletions(-) delete mode 100644 WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/OldWeaverGenerator.java diff --git a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/OldWeaverGenerator.java b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/OldWeaverGenerator.java deleted file mode 100644 index 08a5c86db..000000000 --- a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/OldWeaverGenerator.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2013 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. under the License. - */ -package org.lara.interpreter.weaver.generator.commandline; - -public class OldWeaverGenerator { - /* - * /** Generate a new weaver, according to the input language specification. - * The language specification folder should contain the three required - * files: joinPointModel.xml, artifacts.xml and actionModel.xml - * - * @param weaverName The name for the new Weaver - * - * @param languageSpecificationDir The location of the language - * specification - * - * @param outputDir The output directory - * - * @param outputPackage The package for the generated classes - * - * @param showGraph - * - * @return true if generated successfully, false otherwise. - * - * public static boolean generate(String weaverName, File - * languageSpecificationDir, File outputDir, String outputPackage, boolean - * abstractGetters, boolean showGraph) { - * - * // String xmlLocation = languageSpecificationDir.getAbsolutePath(); try { - * LanguageSpecification languageSpecification; languageSpecification = - * LanguageSpecification.newInstance(languageSpecificationDir, true); - * - * generate(weaverName, languageSpecification, outputDir, outputPackage, - * abstractGetters); if (showGraph) { // - * languageSpecification.createGraph(outputDir, outputPackage); } return - * true; } catch (Exception e) { System.err.println( - * "Could not generate weaver!"); e.printStackTrace(); } return false; } - * - * /** Generate a new weaver, according to the {@link JPModel}, {@link - * Artifacts} and {@link ActionModel}. - * - * @param weaverName The name for the new Weaver - * - * @param languageSpecificationDir The location of the language - * specification - * - * @param outputDir The output directory - * - * @param outputPackage The package for the generated classes - * - * @param abstractGetters If true, getters are defined as abstract and the - * fields are not generated - * - * @return true if generated successfully, false otherwise. - * - * public static void generate(String weaverName, LanguageSpecification - * langSpec, File outputDir, String outputPackage, boolean abstractGetters) - * { - * - * // Assign required package names to be constructed String jpClassPackage - * = outputPackage.isEmpty() ? "" : outputPackage + "."; String - * weaverPackage = outputPackage; String aWeaverPackage = jpClassPackage + - * "abstracts.weaver"; String aJPPackage = weaverPackage + ".abstracts"; - * jpClassPackage += "abstracts.joinpoints"; List enums = new - * ArrayList<>(); - * - * // Generate the user defined objects, which are seen in LARA List - * definedObjects = - * generateUserDefinedObjects(langSpec.getArtifacts().getObjects(), - * outputPackage, outputDir); - * - * // Abstract class containing all the global elements JavaClass - * abstrJPClass = generateAbstractJoinPointClass(langSpec, jpClassPackage, - * GenConstants.i, enums, abstractGetters); - * - * String superClass = abstrJPClass.getName(); - * - * // Create a class which can be defined by the user JavaClass userClass = - * generateUserClass(superClass, aJPPackage, GenConstants.interfaceName(), - * weaverName); userClass.addImport(jpClassPackage + "." + - * abstrJPClass.getName()); superClass = userClass.getName(); - * - * List classes = generateClasses(langSpec, jpClassPackage, - * superClass, enums, abstractGetters); - * - * // Generate the Weaver abstraction class JavaClass weaverAbstractClass = - * WeaverAbstractGenerator.generate(weaverName, aWeaverPackage, aJPPackage, - * langSpec); Utils.generateToFile(outputDir, weaverAbstractClass, true); - * - * // Generate the Weaver implementation JavaClass weaverImplClass = - * createWeaverImplementation(weaverName, weaverPackage, - * weaverAbstractClass, interfaceName, "A" + - * Utils.firstCharToUpper(langSpec.getJpModel().getRoot().getClazz())); - * boolean generatedWeaverImpl = Utils.generateToFile(outputDir, - * weaverImplClass, false); if (!generatedWeaverImpl) System.out.println( - * "Note: java class for the weaver '" + weaverName + - * "' was not created because the file already exist on the path!"); - * - * Utils.generateToFile(outputDir, abstrJPClass, true); - * Utils.generateToFile(outputDir, userClass, false); for (JavaClass javaC : - * classes) { if (javaC.getSuperClass().equals(userClass.getName())) - * javaC.addImport(aJPPackage + "." + userClass.getName()); for (Field f : - * javaC.getFields()) if (definedObjects.contains(f.getType())) { - * - * javaC.addImport(outputPackage + "." + ENTITY + "." + f.getType()); } - * - * Utils.generateToFile(outputDir, javaC, true); } for (JavaEnum javaE : - * enums) { Utils.generateToFile(outputDir, javaE, true); } } - * - * /** Generate a new weaver, according to the input language specification. - *
Usage: java -jar WeaverGenerator.jar [options]
- * - * @param args List of available arguments: - * - * - * - * - * - *
Option Long Option Description
-h --help Print a help message
-o --output <dir> Change output - * directory (default: .)
-p --package <packageName> Define the - * package for the java files
-w --weaver - * <className> Name for the class (default: MyWeaver)
-x --XMLspec <dir> Location of the - * target language specification (default: .)
- * - * public static void main(String[] args) { - * - * WeaverGeneratorOptions opts = new WeaverGeneratorOptions(); - * - * CommandLine cmdLine = opts.parse(args); if - * (cmdLine.hasOption(GeneratorOption.H.getOption())) { opts.help(); return; - * } - * - * if (cmdLine.hasOption(GeneratorOption.W.getOption())) { weaverName = - * cmdLine.getOptionValue(GeneratorOption.W.getOption()); } else weaverName - * = GenConstants.getDefaultWeaverName(); if - * (cmdLine.hasOption(GeneratorOption.P.getOption())) { outPackage = - * cmdLine.getOptionValue(GeneratorOption.P.getOption()); } else outPackage - * = GenConstants.getDefaultPackage(); - * - * if (cmdLine.hasOption(GeneratorOption.X.getOption())) { XMLSpecDir = new - * File(cmdLine.getOptionValue(GeneratorOption.X.getOption())); } else - * XMLSpecDir = GenConstants.getDefaultxmldir(); - * - * if (cmdLine.hasOption(GeneratorOption.O.getOption())) { outDir = new - * File(cmdLine.getOptionValue(GeneratorOption.O.getOption())); } else - * outDir = GenConstants.getDefaultOutputDir(); - * - * if (cmdLine.hasOption(GeneratorOption.A.getOption())) { abstractGetters = - * true; } else abstractGetters = GenConstants.getDefaultAbstractGetters(); - * - * if (cmdLine.hasOption(GeneratorOption.N.getOption())) { String nodeOpt = - * cmdLine.getOptionValue(GeneratorOption.N.getOption()); if (nodeOpt != - * null) nodeGenerics = nodeOpt; else nodeGenerics = - * GenConstants.getDefaultNode(); } else nodeGenerics = - * GenConstants.getDefaultNode(); - * - * if (cmdLine.hasOption(GeneratorOption.G.getOption())) { showGraph = true; - * } else showGraph = GenConstants.getDefaultShowGraph(); - * - * printReport(weaverName, outPackage, XMLSpecDir, outDir, showGraph); - * - * boolean generated = generate(weaverName, XMLSpecDir, outDir, outPackage, - * abstractGetters, showGraph); if (!generated) System.err.println( - * "The Weaver was not created!"); else System.out.println( - * "Weaver successfully created!"); } - * - * private static void printReport(String weaverName, String outPackage, - * File xMLSpecDir, File outDir, boolean showGraph) { StringBuilder report = - * new StringBuilder(); report.append("Weaver name: " + weaverName + "\n"); - * report.append("Package: " + outPackage + "\n"); report.append( - * "Lang. Spec: " + xMLSpecDir + "\n"); report.append("Output Dir.: " + - * outDir + "\n"); report.append("Show Graph: " + showGraph + "\n"); - * System.out.println(report); } - */ -} diff --git a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/WeaverGenerator.java b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/WeaverGenerator.java index 6acf8f22d..db12788d9 100644 --- a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/WeaverGenerator.java +++ b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/WeaverGenerator.java @@ -191,14 +191,6 @@ public static void main(String[] args) { if (cmdLine.hasOption(GeneratorOption.C.getOption())) { System.out.println("Warning: option 'C' is deprecated and was not tested after a Weaver Generator refactoring, proceed at your own risk"); generator = new TemplatedGenerator(XMLSpecDir); - } else if (cmdLine.hasOption(GeneratorOption.L.getOption())) { - optionValue = cmdLine.getOptionValue(GeneratorOption.L.getOption()); - if (optionValue.equals("java2cpp")) { - throw new RuntimeException("Option java2cpp no longer supported"); - } - - generator = new JavaAbstractsGenerator(XMLSpecDir); - } else { // Create the JavaAbstractGenerator generator = new JavaAbstractsGenerator(XMLSpecDir); diff --git a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/WeaverGeneratorOptions.java b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/WeaverGeneratorOptions.java index 2307dabe8..4f324ef24 100644 --- a/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/WeaverGeneratorOptions.java +++ b/WeaverGenerator/src/org/lara/interpreter/weaver/generator/commandline/WeaverGeneratorOptions.java @@ -1,40 +1,33 @@ /* * Copyright 2013 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. under the License. */ package org.lara.interpreter.weaver.generator.commandline; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; +import org.apache.commons.cli.*; import org.apache.commons.cli.Option.Builder; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; import org.lara.interpreter.weaver.generator.generator.utils.GenConstants; class WeaverGeneratorOptions extends Options { private static HelpFormatter formatter = new HelpFormatter(); /** - * + * */ private static final long serialVersionUID = -7738963410049098076L; /** * Arguments for options - * + * * @author Tiago Carvalho - * */ private enum ArgOption { NO_ARGS, @@ -49,7 +42,6 @@ protected enum GeneratorOption { W("w", "weaver"), X("x", "XMLspec"), - L("l", "language"), O("o", "output"), P("p", "package"), // A("a", "abstractGetters"), //replaced with -f @@ -91,18 +83,12 @@ protected WeaverGeneratorOptions() { final Option xmlDir = newOption("dir", GeneratorOption.X, ArgOption.ONE_ARG, "location of the target language specification (default: " + GenConstants.getDefaultXMLDir() + ")"); - final Option language = newOption("language", GeneratorOption.L, ArgOption.ONE_ARG, - "define in which language the code will be generated (default: Java)"); - final Option outDir = newOption("dir", GeneratorOption.O, ArgOption.ONE_ARG, "change output directory (default: " + GenConstants.getDefaultOutputDir() + ")"); final Option packDir = newOption("packageName", GeneratorOption.P, ArgOption.ONE_ARG, "define the package for the java files"); - - // final Option abstractGetters = newOption(null, GeneratorOption.A, ArgOption.NO_ARGS, - // "don't use fields for attributes and and define getter methods as abstract"); //Replaced with - // GeneratorOption.F + final Option fields = newOption(null, GeneratorOption.F, ArgOption.NO_ARGS, "use fields for attributes"); @@ -127,7 +113,6 @@ protected WeaverGeneratorOptions() { addOption(help); addOption(weaver); addOption(xmlDir); - addOption(language); addOption(outDir); addOption(packDir); // addOption(abstractGetters); @@ -163,7 +148,7 @@ protected void help() { /** * Create a new Option with all the description - * + * * @param argName * @param shortOpt * @param longOpt @@ -172,7 +157,7 @@ protected void help() { * @return */ protected static Option newOption(String argName, GeneratorOption shortOpt, ArgOption argOption, - String description) { + String description) { Builder builder = Option.builder(shortOpt.getOption()); @@ -181,22 +166,22 @@ protected static Option newOption(String argName, GeneratorOption shortOpt, ArgO builder.desc(description); switch (argOption) { - case ONE_ARG: - builder.hasArg(); - break; - case SEVERAL_ARGS: - builder.hasArgs(); - break; - case OPTIONAL_ARG: - builder.hasArg(); - builder.optionalArg(true); - break; - case OPTIONAL_ARGS: - builder.hasArgs(); - builder.optionalArg(true); - break; - default: - break; + case ONE_ARG: + builder.hasArg(); + break; + case SEVERAL_ARGS: + builder.hasArgs(); + break; + case OPTIONAL_ARG: + builder.hasArg(); + builder.optionalArg(true); + break; + case OPTIONAL_ARGS: + builder.hasArgs(); + builder.optionalArg(true); + break; + default: + break; } return builder.build(); }