From 56df026455bb77b130cabfe533042979d2b9265a Mon Sep 17 00:00:00 2001 From: Lutz Wrage Date: Thu, 17 Sep 2026 11:24:57 -0400 Subject: [PATCH] Modernize property code generation for Java 21 Convert the 27 tools Xtend sources to maintained Java 21 and replace collection helpers with JDK APIs. Remove obsolete Xtend source paths, builders, and runtime dependencies from the three tools bundles. Emit Java with var, pattern matching, expression lambdas, Optional.isEmpty, and Stream.toList, and keep generated blank lines empty. Generated list extraction now returns unmodifiable lists, including nested lists. Add an opt-in Maven tools profile and compile all 26 existing output-test fixtures with --release 21. Add six runtime tests using validated AADL models to exercise generated getters, constants, modes, lists, units, enums, ranges, and nested record round-tripping. Fixes #3237 --- pom.xml | 6 + tools/README.md | 36 + .../.classpath | 5 - .../.gitignore | 1 + .../.project | 6 - .../META-INF/MANIFEST.MF | 12 +- .../models/generatedjava/.gitignore | 2 + .../models/generatedjava/.project | 18 + .../models/generatedjava/ExternalTypes.aadl | 27 + .../models/generatedjava/RuntimeModel.aadl | 57 + .../generatedjava/RuntimeProperties.aadl | 51 + .../org.osate.propertiescodegen.tests/pom.xml | 18 + .../propertiescodegen/tests/BooleanTest.java | 369 ++ .../propertiescodegen/tests/BooleanTest.xtend | 368 -- .../tests/ClassifierTest.java | 437 +++ .../tests/ClassifierTest.xtend | 436 --- .../tests/CodegenPackageTest.java | 569 +++ .../tests/CodegenPackageTest.xtend | 570 --- .../tests/EnumerationTest.java | 679 ++++ .../tests/EnumerationTest.xtend | 683 ---- .../tests/GeneratedJavaCompiler.java | 156 + .../tests/GeneratedJavaRuntimeTest.java | 219 ++ .../tests/IntegerNoUnitsTest.java | 370 ++ .../tests/IntegerNoUnitsTest.xtend | 369 -- .../tests/IntegerWithUnitsTest.java | 1668 +++++++++ .../tests/IntegerWithUnitsTest.xtend | 1690 --------- .../tests/ListDefinitionTest.java | 2094 +++++++++++ .../tests/ListDefinitionTest.xtend | 2104 ----------- .../propertiescodegen/tests/ModalTest.java | 1334 +++++++ .../propertiescodegen/tests/ModalTest.xtend | 1347 ------- .../tests/PropertiesCodeGenTest.java | 475 +++ .../tests/PropertiesCodeGenTest.xtend | 479 --- .../tests/PropertyDefinitionTest.java | 931 +++++ .../tests/PropertyDefinitionTest.xtend | 933 ----- .../propertiescodegen/tests/RangeTest.java | 2539 +++++++++++++ .../propertiescodegen/tests/RangeTest.xtend | 2566 ------------- .../tests/RangeTypeTest.java | 307 ++ .../tests/RangeTypeTest.xtend | 309 -- .../tests/RealNoUnitsTest.java | 370 ++ .../tests/RealNoUnitsTest.xtend | 369 -- .../tests/RealWithUnitsTest.java | 1189 ++++++ .../tests/RealWithUnitsTest.xtend | 1202 ------ .../tests/RecordOfListTest.java | 2891 +++++++++++++++ .../tests/RecordOfListTest.xtend | 3069 --------------- .../tests/RecordTypeTest.java | 3271 ++++++++++++++++ .../tests/RecordTypeTest.xtend | 3299 ----------------- .../tests/ReferenceTest.java | 303 ++ .../tests/ReferenceTest.xtend | 302 -- .../tests/ResolveNamedValueTest.java | 943 +++++ .../tests/ResolveNamedValueTest.xtend | 955 ----- .../propertiescodegen/tests/StringTest.java | 369 ++ .../propertiescodegen/tests/StringTest.xtend | 368 -- .../xtend-gen/.gitignore | 4 - .../org.osate.propertiescodegen.ui/.classpath | 1 - .../org.osate.propertiescodegen.ui/.gitignore | 1 + tools/org.osate.propertiescodegen.ui/.project | 6 - .../META-INF/MANIFEST.MF | 4 - .../build.properties | 3 +- tools/org.osate.propertiescodegen.ui/pom.xml | 18 + .../ui/PropertiesCodeGenHandler.java | 124 + .../ui/PropertiesCodeGenHandler.xtend | 99 - .../xtend-gen/.gitignore | 4 - tools/org.osate.propertiescodegen/.classpath | 1 - tools/org.osate.propertiescodegen/.gitignore | 1 + tools/org.osate.propertiescodegen/.project | 6 - .../META-INF/MANIFEST.MF | 4 - .../build.properties | 3 +- tools/org.osate.propertiescodegen/pom.xml | 18 + .../AbstractPropertyGenerator.java | 222 ++ .../AbstractPropertyGenerator.xtend | 317 -- .../EnumerationGenerator.java | 85 + .../EnumerationGenerator.xtend | 85 - ...rtCollector.xtend => ImportCollector.java} | 57 +- .../propertiescodegen/PropertiesCodeGen.java | 128 + .../propertiescodegen/PropertiesCodeGen.xtend | 141 - .../PropertyGettersGenerator.java | 150 + .../PropertyGettersGenerator.xtend | 162 - .../propertiescodegen/RecordGenerator.java | 381 ++ .../propertiescodegen/RecordGenerator.xtend | 424 --- .../propertiescodegen/UnitsGenerator.java | 101 + .../propertiescodegen/UnitsGenerator.xtend | 99 - .../xtend-gen/.gitignore | 4 - tools/pom.xml | 29 + 83 files changed, 22989 insertions(+), 22833 deletions(-) create mode 100644 tools/README.md create mode 100644 tools/org.osate.propertiescodegen.tests/models/generatedjava/.gitignore create mode 100644 tools/org.osate.propertiescodegen.tests/models/generatedjava/.project create mode 100644 tools/org.osate.propertiescodegen.tests/models/generatedjava/ExternalTypes.aadl create mode 100644 tools/org.osate.propertiescodegen.tests/models/generatedjava/RuntimeModel.aadl create mode 100644 tools/org.osate.propertiescodegen.tests/models/generatedjava/RuntimeProperties.aadl create mode 100644 tools/org.osate.propertiescodegen.tests/pom.xml create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/BooleanTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/BooleanTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ClassifierTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ClassifierTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/CodegenPackageTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/CodegenPackageTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/EnumerationTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/EnumerationTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/GeneratedJavaCompiler.java create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/GeneratedJavaRuntimeTest.java create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerNoUnitsTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerNoUnitsTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerWithUnitsTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerWithUnitsTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ListDefinitionTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ListDefinitionTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ModalTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ModalTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/PropertiesCodeGenTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/PropertiesCodeGenTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/PropertyDefinitionTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/PropertyDefinitionTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RangeTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RangeTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RangeTypeTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RangeTypeTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RealNoUnitsTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RealNoUnitsTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RealWithUnitsTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RealWithUnitsTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RecordOfListTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RecordOfListTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RecordTypeTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/RecordTypeTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ReferenceTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ReferenceTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ResolveNamedValueTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ResolveNamedValueTest.xtend create mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/StringTest.java delete mode 100644 tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/StringTest.xtend delete mode 100644 tools/org.osate.propertiescodegen.tests/xtend-gen/.gitignore create mode 100644 tools/org.osate.propertiescodegen.ui/pom.xml create mode 100644 tools/org.osate.propertiescodegen.ui/src/org/osate/propertiescodegen/ui/PropertiesCodeGenHandler.java delete mode 100644 tools/org.osate.propertiescodegen.ui/src/org/osate/propertiescodegen/ui/PropertiesCodeGenHandler.xtend delete mode 100644 tools/org.osate.propertiescodegen.ui/xtend-gen/.gitignore create mode 100644 tools/org.osate.propertiescodegen/pom.xml create mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/AbstractPropertyGenerator.java delete mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/AbstractPropertyGenerator.xtend create mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/EnumerationGenerator.java delete mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/EnumerationGenerator.xtend rename tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/{ImportCollector.xtend => ImportCollector.java} (69%) create mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/PropertiesCodeGen.java delete mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/PropertiesCodeGen.xtend create mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/PropertyGettersGenerator.java delete mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/PropertyGettersGenerator.xtend create mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/RecordGenerator.java delete mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/RecordGenerator.xtend create mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/UnitsGenerator.java delete mode 100644 tools/org.osate.propertiescodegen/src/org/osate/propertiescodegen/UnitsGenerator.xtend delete mode 100644 tools/org.osate.propertiescodegen/xtend-gen/.gitignore create mode 100644 tools/pom.xml diff --git a/pom.xml b/pom.xml index e9f5c266008..3b71aa28f2a 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,12 @@ + + tools + + tools + + codecoverage diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 00000000000..38a31322525 --- /dev/null +++ b/tools/README.md @@ -0,0 +1,36 @@ +# Property code generator + +The optional Maven `tools` profile builds the property generator, its Eclipse +UI handler, and the generator's JUnit tests. All sources use Java 21. Normal root +builds do not include these bundles. + +To build and test only the tools reactor, run from the repository root after +installing the OSATE dependencies: + +```sh +mvn -o -T5 -s releng/osate.releng/settings.xml -f tools/pom.xml -Plocal,tools \ + -Dtycho.localArtifacts=default -Dpr.build=true -Dsign=false \ + -Dspotbugs=false -Dcodecoverage=false -Djavadoc=false \ + clean verify +``` + +Use `verify` to execute the Tycho tests. The 26 exact-output tests also compile +their generated Java, including imported property sets, using the JDK compiler +with `--release 21`. They continue to compare imports, indentation, and final +newlines. Generated Java uses `var` for obvious local types, pattern matching, +expression lambdas, and `Optional.isEmpty()`. Blank lines contain no spaces or +tabs. List extraction uses `Stream.toList()`, so returned lists are unmodifiable, +including nested lists and lists extracted from constants and record fields. + +Six additional tests load the freshly compiled classes and exercise scalar +getters, constant and property references, missing values, defaults, modes, +nested lists and rejection of list mutations, ranges, imported enums and units, and nested +record round-tripping. These tests use the validated AADL project in +`org.osate.propertiescodegen.tests/models/generatedjava/`. + +A JDK with the Java compiler is required. Compilation failures include compiler +diagnostics, and temporary source/class files and class loaders are cleaned up +after each test. + +Test reports are written to +`org.osate.propertiescodegen.tests/target/surefire-reports/`. diff --git a/tools/org.osate.propertiescodegen.tests/.classpath b/tools/org.osate.propertiescodegen.tests/.classpath index 97e95b27cae..1aa9eca95a0 100644 --- a/tools/org.osate.propertiescodegen.tests/.classpath +++ b/tools/org.osate.propertiescodegen.tests/.classpath @@ -7,10 +7,5 @@ - - - - - diff --git a/tools/org.osate.propertiescodegen.tests/.gitignore b/tools/org.osate.propertiescodegen.tests/.gitignore index ae3c1726048..65cc91aafaf 100644 --- a/tools/org.osate.propertiescodegen.tests/.gitignore +++ b/tools/org.osate.propertiescodegen.tests/.gitignore @@ -1 +1,2 @@ /bin/ +/.tycho-consumer-pom.xml diff --git a/tools/org.osate.propertiescodegen.tests/.project b/tools/org.osate.propertiescodegen.tests/.project index 796a062027e..545e163c0ee 100644 --- a/tools/org.osate.propertiescodegen.tests/.project +++ b/tools/org.osate.propertiescodegen.tests/.project @@ -5,11 +5,6 @@ - - org.eclipse.xtext.ui.shared.xtextBuilder - - - org.eclipse.jdt.core.javabuilder @@ -29,6 +24,5 @@ org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature - org.eclipse.xtext.ui.shared.xtextNature diff --git a/tools/org.osate.propertiescodegen.tests/META-INF/MANIFEST.MF b/tools/org.osate.propertiescodegen.tests/META-INF/MANIFEST.MF index dc2ae60bff0..835c4c1d5e3 100644 --- a/tools/org.osate.propertiescodegen.tests/META-INF/MANIFEST.MF +++ b/tools/org.osate.propertiescodegen.tests/META-INF/MANIFEST.MF @@ -5,12 +5,12 @@ Bundle-SymbolicName: org.osate.propertiescodegen.tests Bundle-Version: 1.0.0.qualifier Automatic-Module-Name: org.osate.propertiescodegen.tests Bundle-RequiredExecutionEnvironment: JavaSE-21 -Require-Bundle: com.google.guava, - org.eclipse.xtext.xbase.lib, - org.eclipse.xtend.lib, - org.eclipse.xtend.lib.macro, - org.osate.propertiescodegen;bundle-version="1.0.0", +Require-Bundle: org.osate.propertiescodegen;bundle-version="1.0.0", org.osate.testsupport;bundle-version="1.0.0", - org.osate.aadl2;bundle-version="1.0.0" + org.osate.aadl2;bundle-version="1.0.0", + org.osate.aadl2.modelsupport, + org.osate.pluginsupport, + org.eclipse.core.runtime +Import-Package: javax.tools Export-Package: org.osate.propertiescodegen.tests Bundle-Vendor: CMU/SEI diff --git a/tools/org.osate.propertiescodegen.tests/models/generatedjava/.gitignore b/tools/org.osate.propertiescodegen.tests/models/generatedjava/.gitignore new file mode 100644 index 00000000000..afce51184c6 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/models/generatedjava/.gitignore @@ -0,0 +1,2 @@ +/.aadlbin-gen/ +/instances/ diff --git a/tools/org.osate.propertiescodegen.tests/models/generatedjava/.project b/tools/org.osate.propertiescodegen.tests/models/generatedjava/.project new file mode 100644 index 00000000000..83b858fca50 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/models/generatedjava/.project @@ -0,0 +1,18 @@ + + + generatedjava + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + + org.osate.core.aadlnature + org.eclipse.xtext.ui.shared.xtextNature + + diff --git a/tools/org.osate.propertiescodegen.tests/models/generatedjava/ExternalTypes.aadl b/tools/org.osate.propertiescodegen.tests/models/generatedjava/ExternalTypes.aadl new file mode 100644 index 00000000000..b07c64b3137 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/models/generatedjava/ExternalTypes.aadl @@ -0,0 +1,27 @@ +-- Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). +-- All Rights Reserved. +-- +-- NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY +-- KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE +-- OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT +-- MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. +-- +-- This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 +-- which is available at https://www.eclipse.org/legal/epl-2.0/ +-- SPDX-License-Identifier: EPL-2.0 +-- +-- Created, in part, with funding and support from the United States Government. (see Acknowledgments file). +-- +-- This program includes and/or can make use of certain third party source code, object code, documentation and other +-- files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system +-- configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and +-- conditions contained in any such Third Party Software or separate license file distributed with such Third Party +-- Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries +-- to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses +-- only apply to the Third Party Software and not any other portion of this program or this program as a whole. + +-- @codegen-package generated.runtime.types +property set External_Types is + Time_Units: type units (ms, sec => ms * 1000); + Choice: type enumeration (red, green); +end External_Types; diff --git a/tools/org.osate.propertiescodegen.tests/models/generatedjava/RuntimeModel.aadl b/tools/org.osate.propertiescodegen.tests/models/generatedjava/RuntimeModel.aadl new file mode 100644 index 00000000000..4499b030b38 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/models/generatedjava/RuntimeModel.aadl @@ -0,0 +1,57 @@ +-- Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). +-- All Rights Reserved. +-- +-- NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY +-- KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE +-- OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT +-- MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. +-- +-- This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 +-- which is available at https://www.eclipse.org/legal/epl-2.0/ +-- SPDX-License-Identifier: EPL-2.0 +-- +-- Created, in part, with funding and support from the United States Government. (see Acknowledgments file). +-- +-- This program includes and/or can make use of certain third party source code, object code, documentation and other +-- files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system +-- configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and +-- conditions contained in any such Third Party Software or separate license file distributed with such Third Party +-- Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries +-- to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses +-- only apply to the Third Party Software and not any other portion of this program or this program as a whole. + +package Generated_Runtime +public + with Runtime_Properties; + + system Populated + properties + Runtime_Properties::Enabled => true; + Runtime_Properties::Count => Runtime_Properties::Alias_Constant; + Runtime_Properties::Count_Alias => Runtime_Properties::Count; + Runtime_Properties::Ratio => 1.5; + Runtime_Properties::Label => "hello"; + Runtime_Properties::Matrix => ((1, 2), (), (3, 4)); + Runtime_Properties::Duration => 2 sec; + Runtime_Properties::Selection => green; + Runtime_Properties::Bounds => 1 .. 9 delta 2; + Runtime_Properties::Settings => [ + enabled => true; + retries => 3; + labels => ("a", "b"); + kind => green; + nested => [amount => 8;]; + ]; + end Populated; + + system implementation Populated.i + modes + low: initial mode; + high: mode; + properties + Runtime_Properties::Mode_Count => 10 in modes (low), 20 in modes (high); + end Populated.i; + + system Empty + end Empty; +end Generated_Runtime; diff --git a/tools/org.osate.propertiescodegen.tests/models/generatedjava/RuntimeProperties.aadl b/tools/org.osate.propertiescodegen.tests/models/generatedjava/RuntimeProperties.aadl new file mode 100644 index 00000000000..b3bc8cc0eec --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/models/generatedjava/RuntimeProperties.aadl @@ -0,0 +1,51 @@ +-- Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). +-- All Rights Reserved. +-- +-- NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY +-- KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE +-- OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT +-- MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. +-- +-- This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 +-- which is available at https://www.eclipse.org/legal/epl-2.0/ +-- SPDX-License-Identifier: EPL-2.0 +-- +-- Created, in part, with funding and support from the United States Government. (see Acknowledgments file). +-- +-- This program includes and/or can make use of certain third party source code, object code, documentation and other +-- files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system +-- configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and +-- conditions contained in any such Third Party Software or separate license file distributed with such Third Party +-- Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries +-- to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses +-- only apply to the Third Party Software and not any other portion of this program or this program as a whole. + +-- @codegen-package generated.runtime +property set Runtime_Properties is + with External_Types; + + Base: constant aadlinteger => 41; + Alias_Constant: constant aadlinteger => Runtime_Properties::Base; + Matrix_Constant: constant list of list of aadlinteger => ((5, 6), ()); + Enabled: aadlboolean applies to (all); + Count: aadlinteger applies to (all); + Count_Alias: aadlinteger applies to (all); + Default_Count: aadlinteger => 7 applies to (all); + Thread_Only: aadlboolean applies to (thread); + Ratio: aadlreal applies to (all); + Label: aadlstring applies to (all); + Matrix: list of list of aadlinteger applies to (all); + Mode_Count: aadlinteger applies to (all); + Duration: aadlinteger units External_Types::Time_Units applies to (all); + Selection: External_Types::Choice applies to (all); + Bounds: range of aadlinteger applies to (all); + Settings_Type: type record ( + enabled: aadlboolean; + retries: aadlinteger; + labels: list of aadlstring; + kind: External_Types::Choice; + nested: record (amount: aadlinteger;); + ); + Settings: Runtime_Properties::Settings_Type applies to (all); + Settings_Constant: constant Runtime_Properties::Settings_Type => [enabled => false; retries => 2;]; +end Runtime_Properties; diff --git a/tools/org.osate.propertiescodegen.tests/pom.xml b/tools/org.osate.propertiescodegen.tests/pom.xml new file mode 100644 index 00000000000..c00d1068b5c --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + + org.osate + tools.parent + 2.20.0-SNAPSHOT + + + org.osate + org.osate.propertiescodegen.tests + 1.0.0-SNAPSHOT + eclipse-test-plugin + + diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/BooleanTest.java b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/BooleanTest.java new file mode 100644 index 00000000000..83f9c26bcdc --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/BooleanTest.java @@ -0,0 +1,369 @@ +/******************************************************************************* + * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). + * All Rights Reserved. + * + * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY + * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE + * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT + * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * SPDX-License-Identifier: EPL-2.0 + * + * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). + * + * This program includes and/or can make use of certain third party source code, object code, documentation and other + * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system + * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and + * conditions contained in any such Third Party Software or separate license file distributed with such Third Party + * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries + * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses + * only apply to the Third Party Software and not any other portion of this program or this program as a whole. + *******************************************************************************/ +package org.osate.propertiescodegen.tests; + +import static org.junit.Assert.assertEquals; +import static org.osate.propertiescodegen.tests.GeneratedJavaCompiler.generateAndCompile; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osate.aadl2.PropertySet; +import org.osate.testsupport.Aadl2InjectorProvider; +import org.osate.testsupport.TestHelper; + +import com.google.inject.Inject; + +/** Verifies exact generated Java for boolean. */ +@RunWith(XtextRunner.class) +@InjectWith(Aadl2InjectorProvider.class) +public class BooleanTest { + @Inject + private TestHelper testHelper; + + @Test + public void testBoolean() throws Exception { + var otherPs = """ + property set other_ps is + \tother_boolean_type: type aadlboolean; + end other_ps; + """; + var booleanTest = """ + property set boolean_test is + \twith other_ps; + \t + \tlocal_boolean_type: type aadlboolean; + \t + \towned_boolean: aadlboolean applies to (all); + \treferenced_boolean_local: boolean_test::local_boolean_type applies to (all); + \treferenced_boolean_other: other_ps::other_boolean_type applies to (all); + \t + \tlist_1_boolean: list of other_ps::other_boolean_type applies to (all); + \tlist_5_boolean: list of list of list of list of list of other_ps::other_boolean_type applies to (all); + \t + \tboolean_constant: constant aadlboolean => true; + \t + \tlist_1_boolean_constant: constant list of aadlboolean => (boolean_test::boolean_constant, false); + \tlist_5_boolean_constant: constant list of list of list of list of list of aadlboolean => (((( + \t\t(true, false, true), + \t\t() + \t)))); + end boolean_test; + """; + var booleanTestClass = """ + package booleantest; + + import java.util.List; + import java.util.Optional; + + import org.eclipse.emf.ecore.EObject; + import org.osate.aadl2.Aadl2Package; + import org.osate.aadl2.BooleanLiteral; + import org.osate.aadl2.ListValue; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.Property; + import org.osate.aadl2.PropertyConstant; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; + import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + + public final class BooleanTest { + \tpublic static final String BOOLEAN_TEST__NAME = "boolean_test"; + + \tprivate BooleanTest() {} + + \t// Lookup methods for boolean_test::owned_boolean + + \tpublic static final String OWNED_BOOLEAN__NAME = "owned_boolean"; + + \tpublic static boolean acceptsOwnedBoolean(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getOwnedBoolean_Property(lookupContext)); + \t} + + \tpublic static Optional getOwnedBoolean(NamedElement lookupContext) { + \t\treturn getOwnedBoolean(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getOwnedBoolean(NamedElement lookupContext, Mode mode) { + \t\treturn getOwnedBoolean(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getOwnedBoolean(NamedElement lookupContext, Optional mode) { + \t\tvar property = getOwnedBoolean_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((BooleanLiteral) resolved).getValue()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getOwnedBoolean_Property(EObject lookupContext) { + \t\tvar name = BOOLEAN_TEST__NAME + "::" + OWNED_BOOLEAN__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getOwnedBoolean_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getOwnedBoolean_Property(lookupContext)); + \t} + + \t// Lookup methods for boolean_test::referenced_boolean_local + + \tpublic static final String REFERENCED_BOOLEAN_LOCAL__NAME = "referenced_boolean_local"; + + \tpublic static boolean acceptsReferencedBooleanLocal(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getReferencedBooleanLocal_Property(lookupContext)); + \t} + + \tpublic static Optional getReferencedBooleanLocal(NamedElement lookupContext) { + \t\treturn getReferencedBooleanLocal(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getReferencedBooleanLocal(NamedElement lookupContext, Mode mode) { + \t\treturn getReferencedBooleanLocal(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getReferencedBooleanLocal(NamedElement lookupContext, Optional mode) { + \t\tvar property = getReferencedBooleanLocal_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((BooleanLiteral) resolved).getValue()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getReferencedBooleanLocal_Property(EObject lookupContext) { + \t\tvar name = BOOLEAN_TEST__NAME + "::" + REFERENCED_BOOLEAN_LOCAL__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getReferencedBooleanLocal_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getReferencedBooleanLocal_Property(lookupContext)); + \t} + + \t// Lookup methods for boolean_test::referenced_boolean_other + + \tpublic static final String REFERENCED_BOOLEAN_OTHER__NAME = "referenced_boolean_other"; + + \tpublic static boolean acceptsReferencedBooleanOther(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getReferencedBooleanOther_Property(lookupContext)); + \t} + + \tpublic static Optional getReferencedBooleanOther(NamedElement lookupContext) { + \t\treturn getReferencedBooleanOther(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getReferencedBooleanOther(NamedElement lookupContext, Mode mode) { + \t\treturn getReferencedBooleanOther(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getReferencedBooleanOther(NamedElement lookupContext, Optional mode) { + \t\tvar property = getReferencedBooleanOther_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((BooleanLiteral) resolved).getValue()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getReferencedBooleanOther_Property(EObject lookupContext) { + \t\tvar name = BOOLEAN_TEST__NAME + "::" + REFERENCED_BOOLEAN_OTHER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getReferencedBooleanOther_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getReferencedBooleanOther_Property(lookupContext)); + \t} + + \t// Lookup methods for boolean_test::list_1_boolean + + \tpublic static final String LIST_1_BOOLEAN__NAME = "list_1_boolean"; + + \tpublic static boolean acceptsList1Boolean(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList1Boolean_Property(lookupContext)); + \t} + + \tpublic static Optional> getList1Boolean(NamedElement lookupContext) { + \t\treturn getList1Boolean(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getList1Boolean(NamedElement lookupContext, Mode mode) { + \t\treturn getList1Boolean(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getList1Boolean(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList1Boolean_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn ((BooleanLiteral) resolved1).getValue(); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList1Boolean_Property(EObject lookupContext) { + \t\tvar name = BOOLEAN_TEST__NAME + "::" + LIST_1_BOOLEAN__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList1Boolean_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList1Boolean_Property(lookupContext)); + \t} + + \t// Lookup methods for boolean_test::list_5_boolean + + \tpublic static final String LIST_5_BOOLEAN__NAME = "list_5_boolean"; + + \tpublic static boolean acceptsList5Boolean(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList5Boolean_Property(lookupContext)); + \t} + + \tpublic static Optional>>>>> getList5Boolean(NamedElement lookupContext) { + \t\treturn getList5Boolean(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional>>>>> getList5Boolean(NamedElement lookupContext, Mode mode) { + \t\treturn getList5Boolean(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional>>>>> getList5Boolean(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList5Boolean_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); + \t\t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); + \t\t\t\t\t\treturn ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { + \t\t\t\t\t\t\tvar resolved4 = CodeGenUtil.resolveNamedValue(element4, lookupContext, mode); + \t\t\t\t\t\t\treturn ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { + \t\t\t\t\t\t\t\tvar resolved5 = CodeGenUtil.resolveNamedValue(element5, lookupContext, mode); + \t\t\t\t\t\t\t\treturn ((BooleanLiteral) resolved5).getValue(); + \t\t\t\t\t\t\t}).toList(); + \t\t\t\t\t\t}).toList(); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList5Boolean_Property(EObject lookupContext) { + \t\tvar name = BOOLEAN_TEST__NAME + "::" + LIST_5_BOOLEAN__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList5Boolean_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList5Boolean_Property(lookupContext)); + \t} + + \t// Lookup methods for boolean_test::boolean_constant + + \tpublic static final String BOOLEAN_CONSTANT__NAME = "boolean_constant"; + + \tpublic static boolean getBooleanConstant(EObject lookupContext) { + \t\tvar constant = getBooleanConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((BooleanLiteral) resolved).getValue(); + \t} + + \tpublic static PropertyConstant getBooleanConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = BOOLEAN_TEST__NAME + "::" + BOOLEAN_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for boolean_test::list_1_boolean_constant + + \tpublic static final String LIST_1_BOOLEAN_CONSTANT__NAME = "list_1_boolean_constant"; + + \tpublic static List getList1BooleanConstant(EObject lookupContext) { + \t\tvar constant = getList1BooleanConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn ((BooleanLiteral) resolved1).getValue(); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList1BooleanConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = BOOLEAN_TEST__NAME + "::" + LIST_1_BOOLEAN_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for boolean_test::list_5_boolean_constant + + \tpublic static final String LIST_5_BOOLEAN_CONSTANT__NAME = "list_5_boolean_constant"; + + \tpublic static List>>>> getList5BooleanConstant(EObject lookupContext) { + \t\tvar constant = getList5BooleanConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2); + \t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3); + \t\t\t\t\treturn ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { + \t\t\t\t\t\tvar resolved4 = CodeGenUtil.resolveNamedValue(element4); + \t\t\t\t\t\treturn ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { + \t\t\t\t\t\t\tvar resolved5 = CodeGenUtil.resolveNamedValue(element5); + \t\t\t\t\t\t\treturn ((BooleanLiteral) resolved5).getValue(); + \t\t\t\t\t\t}).toList(); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList(); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList5BooleanConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = BOOLEAN_TEST__NAME + "::" + LIST_5_BOOLEAN_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + } + """; + var results = generateAndCompile(testHelper.parseString(booleanTest, otherPs)); + assertEquals("src-gen/booleantest", results.getPackagePath()); + assertEquals(1, results.getClasses().size()); + + assertEquals("BooleanTest.java", results.getClasses().getFirst().getFileName()); + assertEquals(booleanTestClass, results.getClasses().getFirst().getContents()); + } +} diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/BooleanTest.xtend b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/BooleanTest.xtend deleted file mode 100644 index edfc64d3f95..00000000000 --- a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/BooleanTest.xtend +++ /dev/null @@ -1,368 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). - * All Rights Reserved. - * - * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY - * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE - * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT - * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. - * - * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * SPDX-License-Identifier: EPL-2.0 - * - * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). - * - * This program includes and/or can make use of certain third party source code, object code, documentation and other - * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system - * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and - * conditions contained in any such Third Party Software or separate license file distributed with such Third Party - * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries - * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses - * only apply to the Third Party Software and not any other portion of this program or this program as a whole. - *******************************************************************************/ -package org.osate.propertiescodegen.tests - -import com.google.inject.Inject -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner -import org.junit.Test -import org.junit.runner.RunWith -import org.osate.aadl2.PropertySet -import org.osate.propertiescodegen.PropertiesCodeGen -import org.osate.testsupport.Aadl2InjectorProvider -import org.osate.testsupport.TestHelper - -import static org.junit.Assert.assertEquals - -@RunWith(XtextRunner) -@InjectWith(Aadl2InjectorProvider) -class BooleanTest { - @Inject - TestHelper testHelper - - @Test - def void testBoolean() { - val otherPs = ''' - property set other_ps is - other_boolean_type: type aadlboolean; - end other_ps; - ''' - val booleanTest = ''' - property set boolean_test is - with other_ps; - - local_boolean_type: type aadlboolean; - - owned_boolean: aadlboolean applies to (all); - referenced_boolean_local: boolean_test::local_boolean_type applies to (all); - referenced_boolean_other: other_ps::other_boolean_type applies to (all); - - list_1_boolean: list of other_ps::other_boolean_type applies to (all); - list_5_boolean: list of list of list of list of list of other_ps::other_boolean_type applies to (all); - - boolean_constant: constant aadlboolean => true; - - list_1_boolean_constant: constant list of aadlboolean => (boolean_test::boolean_constant, false); - list_5_boolean_constant: constant list of list of list of list of list of aadlboolean => (((( - (true, false, true), - () - )))); - end boolean_test; - ''' - val booleanTestClass = ''' - package booleantest; - - import java.util.List; - import java.util.Optional; - import java.util.stream.Collectors; - - import org.eclipse.emf.ecore.EObject; - import org.osate.aadl2.Aadl2Package; - import org.osate.aadl2.BooleanLiteral; - import org.osate.aadl2.ListValue; - import org.osate.aadl2.Mode; - import org.osate.aadl2.NamedElement; - import org.osate.aadl2.Property; - import org.osate.aadl2.PropertyConstant; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; - import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; - import org.osate.aadl2.properties.PropertyNotPresentException; - import org.osate.pluginsupport.properties.CodeGenUtil; - - public final class BooleanTest { - public static final String BOOLEAN_TEST__NAME = "boolean_test"; - - private BooleanTest() {} - - // Lookup methods for boolean_test::owned_boolean - - public static final String OWNED_BOOLEAN__NAME = "owned_boolean"; - - public static boolean acceptsOwnedBoolean(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getOwnedBoolean_Property(lookupContext)); - } - - public static Optional getOwnedBoolean(NamedElement lookupContext) { - return getOwnedBoolean(lookupContext, Optional.empty()); - } - - public static Optional getOwnedBoolean(NamedElement lookupContext, Mode mode) { - return getOwnedBoolean(lookupContext, Optional.of(mode)); - } - - public static Optional getOwnedBoolean(NamedElement lookupContext, Optional mode) { - Property property = getOwnedBoolean_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((BooleanLiteral) resolved).getValue()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getOwnedBoolean_Property(EObject lookupContext) { - String name = BOOLEAN_TEST__NAME + "::" + OWNED_BOOLEAN__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getOwnedBoolean_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getOwnedBoolean_Property(lookupContext)); - } - - // Lookup methods for boolean_test::referenced_boolean_local - - public static final String REFERENCED_BOOLEAN_LOCAL__NAME = "referenced_boolean_local"; - - public static boolean acceptsReferencedBooleanLocal(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getReferencedBooleanLocal_Property(lookupContext)); - } - - public static Optional getReferencedBooleanLocal(NamedElement lookupContext) { - return getReferencedBooleanLocal(lookupContext, Optional.empty()); - } - - public static Optional getReferencedBooleanLocal(NamedElement lookupContext, Mode mode) { - return getReferencedBooleanLocal(lookupContext, Optional.of(mode)); - } - - public static Optional getReferencedBooleanLocal(NamedElement lookupContext, Optional mode) { - Property property = getReferencedBooleanLocal_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((BooleanLiteral) resolved).getValue()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getReferencedBooleanLocal_Property(EObject lookupContext) { - String name = BOOLEAN_TEST__NAME + "::" + REFERENCED_BOOLEAN_LOCAL__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getReferencedBooleanLocal_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getReferencedBooleanLocal_Property(lookupContext)); - } - - // Lookup methods for boolean_test::referenced_boolean_other - - public static final String REFERENCED_BOOLEAN_OTHER__NAME = "referenced_boolean_other"; - - public static boolean acceptsReferencedBooleanOther(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getReferencedBooleanOther_Property(lookupContext)); - } - - public static Optional getReferencedBooleanOther(NamedElement lookupContext) { - return getReferencedBooleanOther(lookupContext, Optional.empty()); - } - - public static Optional getReferencedBooleanOther(NamedElement lookupContext, Mode mode) { - return getReferencedBooleanOther(lookupContext, Optional.of(mode)); - } - - public static Optional getReferencedBooleanOther(NamedElement lookupContext, Optional mode) { - Property property = getReferencedBooleanOther_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((BooleanLiteral) resolved).getValue()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getReferencedBooleanOther_Property(EObject lookupContext) { - String name = BOOLEAN_TEST__NAME + "::" + REFERENCED_BOOLEAN_OTHER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getReferencedBooleanOther_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getReferencedBooleanOther_Property(lookupContext)); - } - - // Lookup methods for boolean_test::list_1_boolean - - public static final String LIST_1_BOOLEAN__NAME = "list_1_boolean"; - - public static boolean acceptsList1Boolean(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList1Boolean_Property(lookupContext)); - } - - public static Optional> getList1Boolean(NamedElement lookupContext) { - return getList1Boolean(lookupContext, Optional.empty()); - } - - public static Optional> getList1Boolean(NamedElement lookupContext, Mode mode) { - return getList1Boolean(lookupContext, Optional.of(mode)); - } - - public static Optional> getList1Boolean(NamedElement lookupContext, Optional mode) { - Property property = getList1Boolean_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return ((BooleanLiteral) resolved1).getValue(); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList1Boolean_Property(EObject lookupContext) { - String name = BOOLEAN_TEST__NAME + "::" + LIST_1_BOOLEAN__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList1Boolean_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList1Boolean_Property(lookupContext)); - } - - // Lookup methods for boolean_test::list_5_boolean - - public static final String LIST_5_BOOLEAN__NAME = "list_5_boolean"; - - public static boolean acceptsList5Boolean(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList5Boolean_Property(lookupContext)); - } - - public static Optional>>>>> getList5Boolean(NamedElement lookupContext) { - return getList5Boolean(lookupContext, Optional.empty()); - } - - public static Optional>>>>> getList5Boolean(NamedElement lookupContext, Mode mode) { - return getList5Boolean(lookupContext, Optional.of(mode)); - } - - public static Optional>>>>> getList5Boolean(NamedElement lookupContext, Optional mode) { - Property property = getList5Boolean_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); - return ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { - PropertyExpression resolved4 = CodeGenUtil.resolveNamedValue(element4, lookupContext, mode); - return ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { - PropertyExpression resolved5 = CodeGenUtil.resolveNamedValue(element5, lookupContext, mode); - return ((BooleanLiteral) resolved5).getValue(); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList5Boolean_Property(EObject lookupContext) { - String name = BOOLEAN_TEST__NAME + "::" + LIST_5_BOOLEAN__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList5Boolean_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList5Boolean_Property(lookupContext)); - } - - // Lookup methods for boolean_test::boolean_constant - - public static final String BOOLEAN_CONSTANT__NAME = "boolean_constant"; - - public static boolean getBooleanConstant(EObject lookupContext) { - PropertyConstant constant = getBooleanConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((BooleanLiteral) resolved).getValue(); - } - - public static PropertyConstant getBooleanConstant_PropertyConstant(EObject lookupContext) { - String name = BOOLEAN_TEST__NAME + "::" + BOOLEAN_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for boolean_test::list_1_boolean_constant - - public static final String LIST_1_BOOLEAN_CONSTANT__NAME = "list_1_boolean_constant"; - - public static List getList1BooleanConstant(EObject lookupContext) { - PropertyConstant constant = getList1BooleanConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return ((BooleanLiteral) resolved1).getValue(); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList1BooleanConstant_PropertyConstant(EObject lookupContext) { - String name = BOOLEAN_TEST__NAME + "::" + LIST_1_BOOLEAN_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for boolean_test::list_5_boolean_constant - - public static final String LIST_5_BOOLEAN_CONSTANT__NAME = "list_5_boolean_constant"; - - public static List>>>> getList5BooleanConstant(EObject lookupContext) { - PropertyConstant constant = getList5BooleanConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3); - return ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { - PropertyExpression resolved4 = CodeGenUtil.resolveNamedValue(element4); - return ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { - PropertyExpression resolved5 = CodeGenUtil.resolveNamedValue(element5); - return ((BooleanLiteral) resolved5).getValue(); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList5BooleanConstant_PropertyConstant(EObject lookupContext) { - String name = BOOLEAN_TEST__NAME + "::" + LIST_5_BOOLEAN_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - } - ''' - val results = PropertiesCodeGen.generateJava(testHelper.parseString(booleanTest, otherPs)) - assertEquals("src-gen/booleantest", results.packagePath) - assertEquals(1, results.classes.size) - - assertEquals("BooleanTest.java", results.classes.head.fileName) - assertEquals(booleanTestClass.toString, results.classes.head.contents) - } -} \ No newline at end of file diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ClassifierTest.java b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ClassifierTest.java new file mode 100644 index 00000000000..43d595994c4 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ClassifierTest.java @@ -0,0 +1,437 @@ +/******************************************************************************* + * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). + * All Rights Reserved. + * + * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY + * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE + * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT + * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * SPDX-License-Identifier: EPL-2.0 + * + * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). + * + * This program includes and/or can make use of certain third party source code, object code, documentation and other + * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system + * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and + * conditions contained in any such Third Party Software or separate license file distributed with such Third Party + * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries + * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses + * only apply to the Third Party Software and not any other portion of this program or this program as a whole. + *******************************************************************************/ +package org.osate.propertiescodegen.tests; + +import static org.junit.Assert.assertEquals; +import static org.osate.propertiescodegen.tests.GeneratedJavaCompiler.generateAndCompile; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osate.aadl2.PropertySet; +import org.osate.testsupport.Aadl2InjectorProvider; +import org.osate.testsupport.TestHelper; + +import com.google.inject.Inject; + +/** Verifies exact generated Java for classifier. */ +@RunWith(XtextRunner.class) +@InjectWith(Aadl2InjectorProvider.class) +public class ClassifierTest { + @Inject + private TestHelper testHelper; + + @Test + public void testClassifier() throws Exception { + var otherPs = """ + property set other_ps is + \tother_classifier_type: type classifier; + end other_ps; + """; + var pkg1 = """ + package pkg1 + public + \tsystem s1 + \tend s1; + + \tthread t1 + \tend t1; + + \tdata d1 + \tend d1; + end pkg1; + """; + var classifierTest = """ + property set classifier_test is + \twith other_ps; + \twith pkg1; + \t + \tlocal_classifier_type: type classifier; + \t + \towned_classifier: classifier applies to (all); + \treferenced_classifier_local: classifier_test::local_classifier_type applies to (all); + \treferenced_classifier_other: other_ps::other_classifier_type applies to (all); + \t + \tlist_1_classifier: list of other_ps::other_classifier_type applies to (all); + \tlist_5_classifier: list of list of list of list of list of other_ps::other_classifier_type applies to (all); + \t + \tclassifier_constant: constant classifier => classifier (pkg1::s1); + \t + \tconstant_chain_1: constant classifier_test::local_classifier_type => classifier_test::constant_chain_2; + \tconstant_chain_2: constant classifier_test::local_classifier_type => classifier_test::constant_chain_3; + \tconstant_chain_3: constant classifier_test::local_classifier_type => classifier (pkg1::t1); + \t + \tlist_1_classifier_constant: constant list of classifier_test::local_classifier_type => ( + \t\tclassifier_test::constant_chain_1, + \t\tclassifier (pkg1::d1) + \t); + \t + \tlist_5_classifier_constant: constant list of list of list of list of list of classifier => (((( + \t\t(classifier (pkg1::s1)), + \t\t() + \t)))); + end classifier_test; + """; + var classifierTestClass = """ + package classifiertest; + + import java.util.List; + import java.util.Optional; + + import org.eclipse.emf.ecore.EObject; + import org.osate.aadl2.Aadl2Package; + import org.osate.aadl2.Classifier; + import org.osate.aadl2.ClassifierValue; + import org.osate.aadl2.ListValue; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.Property; + import org.osate.aadl2.PropertyConstant; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; + import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + + public final class ClassifierTest { + \tpublic static final String CLASSIFIER_TEST__NAME = "classifier_test"; + + \tprivate ClassifierTest() {} + + \t// Lookup methods for classifier_test::owned_classifier + + \tpublic static final String OWNED_CLASSIFIER__NAME = "owned_classifier"; + + \tpublic static boolean acceptsOwnedClassifier(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getOwnedClassifier_Property(lookupContext)); + \t} + + \tpublic static Optional getOwnedClassifier(NamedElement lookupContext) { + \t\treturn getOwnedClassifier(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getOwnedClassifier(NamedElement lookupContext, Mode mode) { + \t\treturn getOwnedClassifier(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getOwnedClassifier(NamedElement lookupContext, Optional mode) { + \t\tvar property = getOwnedClassifier_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ClassifierValue) resolved).getClassifier()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getOwnedClassifier_Property(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + OWNED_CLASSIFIER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getOwnedClassifier_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getOwnedClassifier_Property(lookupContext)); + \t} + + \t// Lookup methods for classifier_test::referenced_classifier_local + + \tpublic static final String REFERENCED_CLASSIFIER_LOCAL__NAME = "referenced_classifier_local"; + + \tpublic static boolean acceptsReferencedClassifierLocal(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getReferencedClassifierLocal_Property(lookupContext)); + \t} + + \tpublic static Optional getReferencedClassifierLocal(NamedElement lookupContext) { + \t\treturn getReferencedClassifierLocal(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getReferencedClassifierLocal(NamedElement lookupContext, Mode mode) { + \t\treturn getReferencedClassifierLocal(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getReferencedClassifierLocal(NamedElement lookupContext, Optional mode) { + \t\tvar property = getReferencedClassifierLocal_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ClassifierValue) resolved).getClassifier()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getReferencedClassifierLocal_Property(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + REFERENCED_CLASSIFIER_LOCAL__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getReferencedClassifierLocal_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getReferencedClassifierLocal_Property(lookupContext)); + \t} + + \t// Lookup methods for classifier_test::referenced_classifier_other + + \tpublic static final String REFERENCED_CLASSIFIER_OTHER__NAME = "referenced_classifier_other"; + + \tpublic static boolean acceptsReferencedClassifierOther(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getReferencedClassifierOther_Property(lookupContext)); + \t} + + \tpublic static Optional getReferencedClassifierOther(NamedElement lookupContext) { + \t\treturn getReferencedClassifierOther(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getReferencedClassifierOther(NamedElement lookupContext, Mode mode) { + \t\treturn getReferencedClassifierOther(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getReferencedClassifierOther(NamedElement lookupContext, Optional mode) { + \t\tvar property = getReferencedClassifierOther_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ClassifierValue) resolved).getClassifier()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getReferencedClassifierOther_Property(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + REFERENCED_CLASSIFIER_OTHER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getReferencedClassifierOther_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getReferencedClassifierOther_Property(lookupContext)); + \t} + + \t// Lookup methods for classifier_test::list_1_classifier + + \tpublic static final String LIST_1_CLASSIFIER__NAME = "list_1_classifier"; + + \tpublic static boolean acceptsList1Classifier(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList1Classifier_Property(lookupContext)); + \t} + + \tpublic static Optional> getList1Classifier(NamedElement lookupContext) { + \t\treturn getList1Classifier(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getList1Classifier(NamedElement lookupContext, Mode mode) { + \t\treturn getList1Classifier(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getList1Classifier(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList1Classifier_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn ((ClassifierValue) resolved1).getClassifier(); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList1Classifier_Property(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + LIST_1_CLASSIFIER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList1Classifier_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList1Classifier_Property(lookupContext)); + \t} + + \t// Lookup methods for classifier_test::list_5_classifier + + \tpublic static final String LIST_5_CLASSIFIER__NAME = "list_5_classifier"; + + \tpublic static boolean acceptsList5Classifier(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList5Classifier_Property(lookupContext)); + \t} + + \tpublic static Optional>>>>> getList5Classifier(NamedElement lookupContext) { + \t\treturn getList5Classifier(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional>>>>> getList5Classifier(NamedElement lookupContext, Mode mode) { + \t\treturn getList5Classifier(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional>>>>> getList5Classifier(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList5Classifier_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); + \t\t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); + \t\t\t\t\t\treturn ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { + \t\t\t\t\t\t\tvar resolved4 = CodeGenUtil.resolveNamedValue(element4, lookupContext, mode); + \t\t\t\t\t\t\treturn ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { + \t\t\t\t\t\t\t\tvar resolved5 = CodeGenUtil.resolveNamedValue(element5, lookupContext, mode); + \t\t\t\t\t\t\t\treturn ((ClassifierValue) resolved5).getClassifier(); + \t\t\t\t\t\t\t}).toList(); + \t\t\t\t\t\t}).toList(); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList5Classifier_Property(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + LIST_5_CLASSIFIER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList5Classifier_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList5Classifier_Property(lookupContext)); + \t} + + \t// Lookup methods for classifier_test::classifier_constant + + \tpublic static final String CLASSIFIER_CONSTANT__NAME = "classifier_constant"; + + \tpublic static Classifier getClassifierConstant(EObject lookupContext) { + \t\tvar constant = getClassifierConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ClassifierValue) resolved).getClassifier(); + \t} + + \tpublic static PropertyConstant getClassifierConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + CLASSIFIER_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for classifier_test::constant_chain_1 + + \tpublic static final String CONSTANT_CHAIN_1__NAME = "constant_chain_1"; + + \tpublic static Classifier getConstantChain1(EObject lookupContext) { + \t\tvar constant = getConstantChain1_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ClassifierValue) resolved).getClassifier(); + \t} + + \tpublic static PropertyConstant getConstantChain1_PropertyConstant(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + CONSTANT_CHAIN_1__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for classifier_test::constant_chain_2 + + \tpublic static final String CONSTANT_CHAIN_2__NAME = "constant_chain_2"; + + \tpublic static Classifier getConstantChain2(EObject lookupContext) { + \t\tvar constant = getConstantChain2_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ClassifierValue) resolved).getClassifier(); + \t} + + \tpublic static PropertyConstant getConstantChain2_PropertyConstant(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + CONSTANT_CHAIN_2__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for classifier_test::constant_chain_3 + + \tpublic static final String CONSTANT_CHAIN_3__NAME = "constant_chain_3"; + + \tpublic static Classifier getConstantChain3(EObject lookupContext) { + \t\tvar constant = getConstantChain3_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ClassifierValue) resolved).getClassifier(); + \t} + + \tpublic static PropertyConstant getConstantChain3_PropertyConstant(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + CONSTANT_CHAIN_3__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for classifier_test::list_1_classifier_constant + + \tpublic static final String LIST_1_CLASSIFIER_CONSTANT__NAME = "list_1_classifier_constant"; + + \tpublic static List getList1ClassifierConstant(EObject lookupContext) { + \t\tvar constant = getList1ClassifierConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn ((ClassifierValue) resolved1).getClassifier(); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList1ClassifierConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + LIST_1_CLASSIFIER_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for classifier_test::list_5_classifier_constant + + \tpublic static final String LIST_5_CLASSIFIER_CONSTANT__NAME = "list_5_classifier_constant"; + + \tpublic static List>>>> getList5ClassifierConstant(EObject lookupContext) { + \t\tvar constant = getList5ClassifierConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2); + \t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3); + \t\t\t\t\treturn ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { + \t\t\t\t\t\tvar resolved4 = CodeGenUtil.resolveNamedValue(element4); + \t\t\t\t\t\treturn ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { + \t\t\t\t\t\t\tvar resolved5 = CodeGenUtil.resolveNamedValue(element5); + \t\t\t\t\t\t\treturn ((ClassifierValue) resolved5).getClassifier(); + \t\t\t\t\t\t}).toList(); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList(); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList5ClassifierConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = CLASSIFIER_TEST__NAME + "::" + LIST_5_CLASSIFIER_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + } + """; + var results = generateAndCompile(testHelper.parseString(classifierTest, otherPs, pkg1)); + assertEquals("src-gen/classifiertest", results.getPackagePath()); + assertEquals(1, results.getClasses().size()); + + assertEquals("ClassifierTest.java", results.getClasses().getFirst().getFileName()); + assertEquals(classifierTestClass, results.getClasses().getFirst().getContents()); + } +} diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ClassifierTest.xtend b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ClassifierTest.xtend deleted file mode 100644 index c7600eb1542..00000000000 --- a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/ClassifierTest.xtend +++ /dev/null @@ -1,436 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). - * All Rights Reserved. - * - * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY - * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE - * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT - * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. - * - * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * SPDX-License-Identifier: EPL-2.0 - * - * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). - * - * This program includes and/or can make use of certain third party source code, object code, documentation and other - * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system - * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and - * conditions contained in any such Third Party Software or separate license file distributed with such Third Party - * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries - * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses - * only apply to the Third Party Software and not any other portion of this program or this program as a whole. - *******************************************************************************/ -package org.osate.propertiescodegen.tests - -import com.google.inject.Inject -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner -import org.junit.Test -import org.junit.runner.RunWith -import org.osate.aadl2.PropertySet -import org.osate.propertiescodegen.PropertiesCodeGen -import org.osate.testsupport.Aadl2InjectorProvider -import org.osate.testsupport.TestHelper - -import static org.junit.Assert.assertEquals - -@RunWith(XtextRunner) -@InjectWith(Aadl2InjectorProvider) -class ClassifierTest { - @Inject - TestHelper testHelper - - @Test - def void testClassifier() { - val otherPs = ''' - property set other_ps is - other_classifier_type: type classifier; - end other_ps; - ''' - val pkg1 = ''' - package pkg1 - public - system s1 - end s1; - - thread t1 - end t1; - - data d1 - end d1; - end pkg1; - ''' - val classifierTest = ''' - property set classifier_test is - with other_ps; - with pkg1; - - local_classifier_type: type classifier; - - owned_classifier: classifier applies to (all); - referenced_classifier_local: classifier_test::local_classifier_type applies to (all); - referenced_classifier_other: other_ps::other_classifier_type applies to (all); - - list_1_classifier: list of other_ps::other_classifier_type applies to (all); - list_5_classifier: list of list of list of list of list of other_ps::other_classifier_type applies to (all); - - classifier_constant: constant classifier => classifier (pkg1::s1); - - constant_chain_1: constant classifier_test::local_classifier_type => classifier_test::constant_chain_2; - constant_chain_2: constant classifier_test::local_classifier_type => classifier_test::constant_chain_3; - constant_chain_3: constant classifier_test::local_classifier_type => classifier (pkg1::t1); - - list_1_classifier_constant: constant list of classifier_test::local_classifier_type => ( - classifier_test::constant_chain_1, - classifier (pkg1::d1) - ); - - list_5_classifier_constant: constant list of list of list of list of list of classifier => (((( - (classifier (pkg1::s1)), - () - )))); - end classifier_test; - ''' - val classifierTestClass = ''' - package classifiertest; - - import java.util.List; - import java.util.Optional; - import java.util.stream.Collectors; - - import org.eclipse.emf.ecore.EObject; - import org.osate.aadl2.Aadl2Package; - import org.osate.aadl2.Classifier; - import org.osate.aadl2.ClassifierValue; - import org.osate.aadl2.ListValue; - import org.osate.aadl2.Mode; - import org.osate.aadl2.NamedElement; - import org.osate.aadl2.Property; - import org.osate.aadl2.PropertyConstant; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; - import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; - import org.osate.aadl2.properties.PropertyNotPresentException; - import org.osate.pluginsupport.properties.CodeGenUtil; - - public final class ClassifierTest { - public static final String CLASSIFIER_TEST__NAME = "classifier_test"; - - private ClassifierTest() {} - - // Lookup methods for classifier_test::owned_classifier - - public static final String OWNED_CLASSIFIER__NAME = "owned_classifier"; - - public static boolean acceptsOwnedClassifier(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getOwnedClassifier_Property(lookupContext)); - } - - public static Optional getOwnedClassifier(NamedElement lookupContext) { - return getOwnedClassifier(lookupContext, Optional.empty()); - } - - public static Optional getOwnedClassifier(NamedElement lookupContext, Mode mode) { - return getOwnedClassifier(lookupContext, Optional.of(mode)); - } - - public static Optional getOwnedClassifier(NamedElement lookupContext, Optional mode) { - Property property = getOwnedClassifier_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ClassifierValue) resolved).getClassifier()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getOwnedClassifier_Property(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + OWNED_CLASSIFIER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getOwnedClassifier_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getOwnedClassifier_Property(lookupContext)); - } - - // Lookup methods for classifier_test::referenced_classifier_local - - public static final String REFERENCED_CLASSIFIER_LOCAL__NAME = "referenced_classifier_local"; - - public static boolean acceptsReferencedClassifierLocal(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getReferencedClassifierLocal_Property(lookupContext)); - } - - public static Optional getReferencedClassifierLocal(NamedElement lookupContext) { - return getReferencedClassifierLocal(lookupContext, Optional.empty()); - } - - public static Optional getReferencedClassifierLocal(NamedElement lookupContext, Mode mode) { - return getReferencedClassifierLocal(lookupContext, Optional.of(mode)); - } - - public static Optional getReferencedClassifierLocal(NamedElement lookupContext, Optional mode) { - Property property = getReferencedClassifierLocal_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ClassifierValue) resolved).getClassifier()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getReferencedClassifierLocal_Property(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + REFERENCED_CLASSIFIER_LOCAL__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getReferencedClassifierLocal_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getReferencedClassifierLocal_Property(lookupContext)); - } - - // Lookup methods for classifier_test::referenced_classifier_other - - public static final String REFERENCED_CLASSIFIER_OTHER__NAME = "referenced_classifier_other"; - - public static boolean acceptsReferencedClassifierOther(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getReferencedClassifierOther_Property(lookupContext)); - } - - public static Optional getReferencedClassifierOther(NamedElement lookupContext) { - return getReferencedClassifierOther(lookupContext, Optional.empty()); - } - - public static Optional getReferencedClassifierOther(NamedElement lookupContext, Mode mode) { - return getReferencedClassifierOther(lookupContext, Optional.of(mode)); - } - - public static Optional getReferencedClassifierOther(NamedElement lookupContext, Optional mode) { - Property property = getReferencedClassifierOther_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ClassifierValue) resolved).getClassifier()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getReferencedClassifierOther_Property(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + REFERENCED_CLASSIFIER_OTHER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getReferencedClassifierOther_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getReferencedClassifierOther_Property(lookupContext)); - } - - // Lookup methods for classifier_test::list_1_classifier - - public static final String LIST_1_CLASSIFIER__NAME = "list_1_classifier"; - - public static boolean acceptsList1Classifier(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList1Classifier_Property(lookupContext)); - } - - public static Optional> getList1Classifier(NamedElement lookupContext) { - return getList1Classifier(lookupContext, Optional.empty()); - } - - public static Optional> getList1Classifier(NamedElement lookupContext, Mode mode) { - return getList1Classifier(lookupContext, Optional.of(mode)); - } - - public static Optional> getList1Classifier(NamedElement lookupContext, Optional mode) { - Property property = getList1Classifier_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return ((ClassifierValue) resolved1).getClassifier(); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList1Classifier_Property(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + LIST_1_CLASSIFIER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList1Classifier_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList1Classifier_Property(lookupContext)); - } - - // Lookup methods for classifier_test::list_5_classifier - - public static final String LIST_5_CLASSIFIER__NAME = "list_5_classifier"; - - public static boolean acceptsList5Classifier(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList5Classifier_Property(lookupContext)); - } - - public static Optional>>>>> getList5Classifier(NamedElement lookupContext) { - return getList5Classifier(lookupContext, Optional.empty()); - } - - public static Optional>>>>> getList5Classifier(NamedElement lookupContext, Mode mode) { - return getList5Classifier(lookupContext, Optional.of(mode)); - } - - public static Optional>>>>> getList5Classifier(NamedElement lookupContext, Optional mode) { - Property property = getList5Classifier_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); - return ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { - PropertyExpression resolved4 = CodeGenUtil.resolveNamedValue(element4, lookupContext, mode); - return ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { - PropertyExpression resolved5 = CodeGenUtil.resolveNamedValue(element5, lookupContext, mode); - return ((ClassifierValue) resolved5).getClassifier(); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList5Classifier_Property(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + LIST_5_CLASSIFIER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList5Classifier_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList5Classifier_Property(lookupContext)); - } - - // Lookup methods for classifier_test::classifier_constant - - public static final String CLASSIFIER_CONSTANT__NAME = "classifier_constant"; - - public static Classifier getClassifierConstant(EObject lookupContext) { - PropertyConstant constant = getClassifierConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ClassifierValue) resolved).getClassifier(); - } - - public static PropertyConstant getClassifierConstant_PropertyConstant(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + CLASSIFIER_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for classifier_test::constant_chain_1 - - public static final String CONSTANT_CHAIN_1__NAME = "constant_chain_1"; - - public static Classifier getConstantChain1(EObject lookupContext) { - PropertyConstant constant = getConstantChain1_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ClassifierValue) resolved).getClassifier(); - } - - public static PropertyConstant getConstantChain1_PropertyConstant(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + CONSTANT_CHAIN_1__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for classifier_test::constant_chain_2 - - public static final String CONSTANT_CHAIN_2__NAME = "constant_chain_2"; - - public static Classifier getConstantChain2(EObject lookupContext) { - PropertyConstant constant = getConstantChain2_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ClassifierValue) resolved).getClassifier(); - } - - public static PropertyConstant getConstantChain2_PropertyConstant(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + CONSTANT_CHAIN_2__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for classifier_test::constant_chain_3 - - public static final String CONSTANT_CHAIN_3__NAME = "constant_chain_3"; - - public static Classifier getConstantChain3(EObject lookupContext) { - PropertyConstant constant = getConstantChain3_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ClassifierValue) resolved).getClassifier(); - } - - public static PropertyConstant getConstantChain3_PropertyConstant(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + CONSTANT_CHAIN_3__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for classifier_test::list_1_classifier_constant - - public static final String LIST_1_CLASSIFIER_CONSTANT__NAME = "list_1_classifier_constant"; - - public static List getList1ClassifierConstant(EObject lookupContext) { - PropertyConstant constant = getList1ClassifierConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return ((ClassifierValue) resolved1).getClassifier(); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList1ClassifierConstant_PropertyConstant(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + LIST_1_CLASSIFIER_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for classifier_test::list_5_classifier_constant - - public static final String LIST_5_CLASSIFIER_CONSTANT__NAME = "list_5_classifier_constant"; - - public static List>>>> getList5ClassifierConstant(EObject lookupContext) { - PropertyConstant constant = getList5ClassifierConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3); - return ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { - PropertyExpression resolved4 = CodeGenUtil.resolveNamedValue(element4); - return ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { - PropertyExpression resolved5 = CodeGenUtil.resolveNamedValue(element5); - return ((ClassifierValue) resolved5).getClassifier(); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList5ClassifierConstant_PropertyConstant(EObject lookupContext) { - String name = CLASSIFIER_TEST__NAME + "::" + LIST_5_CLASSIFIER_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - } - ''' - val results = PropertiesCodeGen.generateJava(testHelper.parseString(classifierTest, otherPs, pkg1)) - assertEquals("src-gen/classifiertest", results.packagePath) - assertEquals(1, results.classes.size) - - assertEquals("ClassifierTest.java", results.classes.head.fileName) - assertEquals(classifierTestClass.toString, results.classes.head.contents) - } -} \ No newline at end of file diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/CodegenPackageTest.java b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/CodegenPackageTest.java new file mode 100644 index 00000000000..2aac73ab372 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/CodegenPackageTest.java @@ -0,0 +1,569 @@ +/******************************************************************************* + * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). + * All Rights Reserved. + * + * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY + * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE + * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT + * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * SPDX-License-Identifier: EPL-2.0 + * + * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). + * + * This program includes and/or can make use of certain third party source code, object code, documentation and other + * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system + * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and + * conditions contained in any such Third Party Software or separate license file distributed with such Third Party + * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries + * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses + * only apply to the Third Party Software and not any other portion of this program or this program as a whole. + *******************************************************************************/ +package org.osate.propertiescodegen.tests; + +import static org.junit.Assert.assertEquals; +import static org.osate.propertiescodegen.tests.GeneratedJavaCompiler.generateAndCompile; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osate.aadl2.PropertySet; +import org.osate.testsupport.Aadl2InjectorProvider; +import org.osate.testsupport.TestHelper; + +import com.google.inject.Inject; + +/** Verifies exact generated Java for codegen package. */ +@RunWith(XtextRunner.class) +@InjectWith(Aadl2InjectorProvider.class) +public class CodegenPackageTest { + private static final String CODEGEN_PACKAGE_BASE = """ + -- other comments + -- @codegen-package org.osate.properties.codegenpackage + property set codegen_package_base is + \tspeed: type units (light, ridiculous => light * 1000, ludicrous => ridiculous * 1000); + \trecord_type: type record (bool: aadlboolean;); + \trecord_def: codegen_package_base::record_type applies to (all); + \trecord_const: constant codegen_package_base::record_type => [bool => true;]; + end codegen_package_base; + """; + + private static final String CODEGEN_PACKAGE_SAME = """ + -- @codegen-package org.osate.properties.codegenpackage + property set codegen_package_same is + \twith codegen_package_base; + \t + \trecord_def: codegen_package_base::record_type applies to (all); + \tint_def: aadlinteger units codegen_package_base::speed applies to (all); + \trecord_const: constant codegen_package_base::record_type => [bool => false;]; + end codegen_package_same; + """; + + private static final String CODEGEN_PACKAGE_OTHER = """ + -- @codegen-package org.osate.properties.codegenpackage.other + property set codegen_package_other is + \twith codegen_package_base; + \t + \trecord_def: codegen_package_base::record_type applies to (all); + \tint_def: aadlinteger units codegen_package_base::speed applies to (all); + \trecord_const: constant codegen_package_base::record_type => [bool => true;]; + end codegen_package_other; + """; + + @Inject + private TestHelper testHelper; + + @Test + public void testCustomPackage() throws Exception { + var codegenPackageBaseClass = """ + package org.osate.properties.codegenpackage; + + import java.util.Optional; + + import org.eclipse.emf.ecore.EObject; + import org.osate.aadl2.Aadl2Package; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.Property; + import org.osate.aadl2.PropertyConstant; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; + import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + + public final class CodegenPackageBase { + \tpublic static final String CODEGEN_PACKAGE_BASE__NAME = "codegen_package_base"; + + \tprivate CodegenPackageBase() {} + + \t// Lookup methods for codegen_package_base::record_def + + \tpublic static final String RECORD_DEF__NAME = "record_def"; + + \tpublic static boolean acceptsRecordDef(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getRecordDef_Property(lookupContext)); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext) { + \t\treturn getRecordDef(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext, Mode mode) { + \t\treturn getRecordDef(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext, Optional mode) { + \t\tvar property = getRecordDef_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new RecordType(resolved, lookupContext, mode)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getRecordDef_Property(EObject lookupContext) { + \t\tvar name = CODEGEN_PACKAGE_BASE__NAME + "::" + RECORD_DEF__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getRecordDef_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getRecordDef_Property(lookupContext)); + \t} + + \t// Lookup methods for codegen_package_base::record_const + + \tpublic static final String RECORD_CONST__NAME = "record_const"; + + \tpublic static RecordType getRecordConst(EObject lookupContext) { + \t\tvar constant = getRecordConst_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn new RecordType(resolved); + \t} + + \tpublic static PropertyConstant getRecordConst_PropertyConstant(EObject lookupContext) { + \t\tvar name = CODEGEN_PACKAGE_BASE__NAME + "::" + RECORD_CONST__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + } + """; + var speed = """ + package org.osate.properties.codegenpackage; + + import org.eclipse.emf.common.util.URI; + import org.osate.aadl2.NamedValue; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.UnitLiteral; + import org.osate.pluginsupport.properties.GeneratedUnits; + + public enum Speed implements GeneratedUnits { + \tLIGHT(1.0, "light", "__synthetic0.aadl#/0/@ownedPropertyType.0/@ownedLiteral.0"), + \tRIDICULOUS(1000.0, "ridiculous", "__synthetic0.aadl#/0/@ownedPropertyType.0/@ownedLiteral.1"), + \tLUDICROUS(1000000.0, "ludicrous", "__synthetic0.aadl#/0/@ownedPropertyType.0/@ownedLiteral.2"); + + \tprivate final double factorToBase; + \tprivate final String originalName; + \tprivate final URI uri; + + \tprivate Speed(double factorToBase, String originalName, String uri) { + \t\tthis.factorToBase = factorToBase; + \t\tthis.originalName = originalName; + \t\tthis.uri = URI.createURI(uri); + \t} + + \tpublic static Speed valueOf(PropertyExpression propertyExpression) { + \t\tvar abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); + \t\treturn valueOf(((UnitLiteral) abstractNamedValue).getName().toUpperCase()); + \t} + + \t@Override + \tpublic double getFactorToBase() { + \t\treturn factorToBase; + \t} + + \t@Override + \tpublic double getFactorTo(Speed target) { + \t\treturn factorToBase / target.factorToBase; + \t} + + \t@Override + \tpublic URI getURI() { + \t\treturn uri; + \t} + + \t@Override + \tpublic String toString() { + \t\treturn originalName; + \t} + } + """; + var recordType = """ + package org.osate.properties.codegenpackage; + + import java.util.Objects; + import java.util.Optional; + + import org.eclipse.emf.common.util.URI; + import org.eclipse.emf.ecore.resource.ResourceSet; + import org.osate.aadl2.Aadl2Factory; + import org.osate.aadl2.BooleanLiteral; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.RecordValue; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + import org.osate.pluginsupport.properties.GeneratedRecord; + + public class RecordType extends GeneratedRecord { + \tpublic static final String BOOL__NAME = "bool"; + \tpublic static final URI BOOL__URI = URI.createURI("__synthetic0.aadl#/0/@ownedPropertyType.1/@ownedField.0"); + + \tprivate final Optional bool; + + \tpublic RecordType(Optional bool) { + \t\tthis.bool = bool; + \t} + + \tpublic RecordType(PropertyExpression propertyExpression, NamedElement lookupContext, Optional mode) { + \t\tvar recordValue = (RecordValue) propertyExpression; + + \t\tOptional bool_local; + \t\ttry { + \t\t\tbool_local = findFieldValue(recordValue, BOOL__NAME).map(field -> { + \t\t\t\tvar resolved = CodeGenUtil.resolveNamedValue(field.getOwnedValue(), lookupContext, mode); + \t\t\t\treturn ((BooleanLiteral) resolved).getValue(); + \t\t\t}); + \t\t} catch (PropertyNotPresentException e) { + \t\t\tbool_local = Optional.empty(); + \t\t} + \t\tthis.bool = bool_local; + \t} + + \tpublic RecordType(PropertyExpression propertyExpression) { + \t\tvar recordValue = (RecordValue) propertyExpression; + + \t\tOptional bool_local; + \t\ttry { + \t\t\tbool_local = findFieldValue(recordValue, BOOL__NAME).map(field -> { + \t\t\t\tvar resolved = CodeGenUtil.resolveNamedValue(field.getOwnedValue()); + \t\t\t\treturn ((BooleanLiteral) resolved).getValue(); + \t\t\t}); + \t\t} catch (PropertyNotPresentException e) { + \t\t\tbool_local = Optional.empty(); + \t\t} + \t\tthis.bool = bool_local; + \t} + + \tpublic Optional getBool() { + \t\treturn bool; + \t} + + \t@Override + \tpublic RecordValue toPropertyExpression(ResourceSet resourceSet) { + \t\tif (bool.isEmpty()) { + \t\t\tthrow new IllegalStateException("Record must have at least one field set."); + \t\t} + \t\tvar recordValue = Aadl2Factory.eINSTANCE.createRecordValue(); + \t\tbool.ifPresent(field -> { + \t\t\tvar fieldAssociation = recordValue.createOwnedFieldValue(); + \t\t\tfieldAssociation.setProperty(loadField(resourceSet, BOOL__URI, BOOL__NAME)); + \t\t\tfieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field)); + \t\t}); + \t\treturn recordValue; + \t} + + \t@Override + \tpublic int hashCode() { + \t\treturn Objects.hash(bool); + \t} + + \t@Override + \tpublic boolean equals(Object obj) { + \t\tif (this == obj) { + \t\t\treturn true; + \t\t} + \t\tif (!(obj instanceof RecordType other)) { + \t\t\treturn false; + \t\t} + \t\treturn Objects.equals(this.bool, other.bool); + \t} + + \t@Override + \tpublic String toString() { + \t\tvar builder = new StringBuilder(); + \t\tbuilder.append('['); + \t\tthis.bool.ifPresent(field -> { + \t\t\tbuilder.append(BOOL__NAME); + \t\t\tbuilder.append(" => "); + \t\t\tbuilder.append(field); + \t\t\tbuilder.append(';'); + \t\t}); + \t\tbuilder.append(']'); + \t\treturn builder.toString(); + \t} + } + """; + var results = generateAndCompile(testHelper.parseString(CODEGEN_PACKAGE_BASE)); + assertEquals("src-gen/org/osate/properties/codegenpackage", results.getPackagePath()); + assertEquals(3, results.getClasses().size()); + + assertEquals("CodegenPackageBase.java", results.getClasses().get(0).getFileName()); + assertEquals(codegenPackageBaseClass, results.getClasses().get(0).getContents()); + + assertEquals("Speed.java", results.getClasses().get(1).getFileName()); + assertEquals(speed, results.getClasses().get(1).getContents()); + + assertEquals("RecordType.java", results.getClasses().get(2).getFileName()); + assertEquals(recordType, results.getClasses().get(2).getContents()); + } + + @Test + public void testReferenceToSameCustomPackage() throws Exception { + var codegenPackageSameClass = """ + package org.osate.properties.codegenpackage; + + import java.util.Optional; + + import org.eclipse.emf.ecore.EObject; + import org.osate.aadl2.Aadl2Package; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.Property; + import org.osate.aadl2.PropertyConstant; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; + import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + import org.osate.pluginsupport.properties.IntegerWithUnits; + + public final class CodegenPackageSame { + \tpublic static final String CODEGEN_PACKAGE_SAME__NAME = "codegen_package_same"; + + \tprivate CodegenPackageSame() {} + + \t// Lookup methods for codegen_package_same::record_def + + \tpublic static final String RECORD_DEF__NAME = "record_def"; + + \tpublic static boolean acceptsRecordDef(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getRecordDef_Property(lookupContext)); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext) { + \t\treturn getRecordDef(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext, Mode mode) { + \t\treturn getRecordDef(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext, Optional mode) { + \t\tvar property = getRecordDef_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new RecordType(resolved, lookupContext, mode)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getRecordDef_Property(EObject lookupContext) { + \t\tvar name = CODEGEN_PACKAGE_SAME__NAME + "::" + RECORD_DEF__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getRecordDef_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getRecordDef_Property(lookupContext)); + \t} + + \t// Lookup methods for codegen_package_same::int_def + + \tpublic static final String INT_DEF__NAME = "int_def"; + + \tpublic static boolean acceptsIntDef(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getIntDef_Property(lookupContext)); + \t} + + \tpublic static Optional> getIntDef(NamedElement lookupContext) { + \t\treturn getIntDef(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getIntDef(NamedElement lookupContext, Mode mode) { + \t\treturn getIntDef(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getIntDef(NamedElement lookupContext, Optional mode) { + \t\tvar property = getIntDef_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new IntegerWithUnits<>(resolved, Speed.class)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getIntDef_Property(EObject lookupContext) { + \t\tvar name = CODEGEN_PACKAGE_SAME__NAME + "::" + INT_DEF__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getIntDef_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getIntDef_Property(lookupContext)); + \t} + + \t// Lookup methods for codegen_package_same::record_const + + \tpublic static final String RECORD_CONST__NAME = "record_const"; + + \tpublic static RecordType getRecordConst(EObject lookupContext) { + \t\tvar constant = getRecordConst_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn new RecordType(resolved); + \t} + + \tpublic static PropertyConstant getRecordConst_PropertyConstant(EObject lookupContext) { + \t\tvar name = CODEGEN_PACKAGE_SAME__NAME + "::" + RECORD_CONST__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + } + """; + var results = generateAndCompile(testHelper.parseString(CODEGEN_PACKAGE_SAME, CODEGEN_PACKAGE_BASE)); + assertEquals("src-gen/org/osate/properties/codegenpackage", results.getPackagePath()); + assertEquals(1, results.getClasses().size()); + + assertEquals("CodegenPackageSame.java", results.getClasses().getFirst().getFileName()); + assertEquals(codegenPackageSameClass, results.getClasses().getFirst().getContents()); + } + + @Test + public void testReferenceToOtherCustomPackage() throws Exception { + var codegenPackageOtherClass = """ + package org.osate.properties.codegenpackage.other; + + import java.util.Optional; + + import org.eclipse.emf.ecore.EObject; + import org.osate.aadl2.Aadl2Package; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.Property; + import org.osate.aadl2.PropertyConstant; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; + import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + import org.osate.pluginsupport.properties.IntegerWithUnits; + import org.osate.properties.codegenpackage.RecordType; + import org.osate.properties.codegenpackage.Speed; + + public final class CodegenPackageOther { + \tpublic static final String CODEGEN_PACKAGE_OTHER__NAME = "codegen_package_other"; + + \tprivate CodegenPackageOther() {} + + \t// Lookup methods for codegen_package_other::record_def + + \tpublic static final String RECORD_DEF__NAME = "record_def"; + + \tpublic static boolean acceptsRecordDef(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getRecordDef_Property(lookupContext)); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext) { + \t\treturn getRecordDef(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext, Mode mode) { + \t\treturn getRecordDef(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getRecordDef(NamedElement lookupContext, Optional mode) { + \t\tvar property = getRecordDef_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new RecordType(resolved, lookupContext, mode)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getRecordDef_Property(EObject lookupContext) { + \t\tvar name = CODEGEN_PACKAGE_OTHER__NAME + "::" + RECORD_DEF__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getRecordDef_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getRecordDef_Property(lookupContext)); + \t} + + \t// Lookup methods for codegen_package_other::int_def + + \tpublic static final String INT_DEF__NAME = "int_def"; + + \tpublic static boolean acceptsIntDef(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getIntDef_Property(lookupContext)); + \t} + + \tpublic static Optional> getIntDef(NamedElement lookupContext) { + \t\treturn getIntDef(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getIntDef(NamedElement lookupContext, Mode mode) { + \t\treturn getIntDef(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getIntDef(NamedElement lookupContext, Optional mode) { + \t\tvar property = getIntDef_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new IntegerWithUnits<>(resolved, Speed.class)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getIntDef_Property(EObject lookupContext) { + \t\tvar name = CODEGEN_PACKAGE_OTHER__NAME + "::" + INT_DEF__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getIntDef_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getIntDef_Property(lookupContext)); + \t} + + \t// Lookup methods for codegen_package_other::record_const + + \tpublic static final String RECORD_CONST__NAME = "record_const"; + + \tpublic static RecordType getRecordConst(EObject lookupContext) { + \t\tvar constant = getRecordConst_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn new RecordType(resolved); + \t} + + \tpublic static PropertyConstant getRecordConst_PropertyConstant(EObject lookupContext) { + \t\tvar name = CODEGEN_PACKAGE_OTHER__NAME + "::" + RECORD_CONST__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + } + """; + var results = generateAndCompile(testHelper.parseString(CODEGEN_PACKAGE_OTHER, CODEGEN_PACKAGE_BASE)); + assertEquals("src-gen/org/osate/properties/codegenpackage/other", results.getPackagePath()); + assertEquals(1, results.getClasses().size()); + + assertEquals("CodegenPackageOther.java", results.getClasses().getFirst().getFileName()); + assertEquals(codegenPackageOtherClass, results.getClasses().getFirst().getContents()); + } +} diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/CodegenPackageTest.xtend b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/CodegenPackageTest.xtend deleted file mode 100644 index 1422153548f..00000000000 --- a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/CodegenPackageTest.xtend +++ /dev/null @@ -1,570 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). - * All Rights Reserved. - * - * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY - * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE - * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT - * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. - * - * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * SPDX-License-Identifier: EPL-2.0 - * - * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). - * - * This program includes and/or can make use of certain third party source code, object code, documentation and other - * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system - * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and - * conditions contained in any such Third Party Software or separate license file distributed with such Third Party - * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries - * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses - * only apply to the Third Party Software and not any other portion of this program or this program as a whole. - *******************************************************************************/ -package org.osate.propertiescodegen.tests - -import com.google.inject.Inject -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner -import org.junit.Test -import org.junit.runner.RunWith -import org.osate.aadl2.PropertySet -import org.osate.propertiescodegen.PropertiesCodeGen -import org.osate.testsupport.Aadl2InjectorProvider -import org.osate.testsupport.TestHelper - -import static org.junit.Assert.assertEquals - -@RunWith(XtextRunner) -@InjectWith(Aadl2InjectorProvider) -class CodegenPackageTest { - val static CODEGEN_PACKAGE_BASE = ''' - -- other comments - -- @codegen-package org.osate.properties.codegenpackage - property set codegen_package_base is - speed: type units (light, ridiculous => light * 1000, ludicrous => ridiculous * 1000); - record_type: type record (bool: aadlboolean;); - record_def: codegen_package_base::record_type applies to (all); - record_const: constant codegen_package_base::record_type => [bool => true;]; - end codegen_package_base; - ''' - - val static CODEGEN_PACKAGE_SAME = ''' - -- @codegen-package org.osate.properties.codegenpackage - property set codegen_package_same is - with codegen_package_base; - - record_def: codegen_package_base::record_type applies to (all); - int_def: aadlinteger units codegen_package_base::speed applies to (all); - record_const: constant codegen_package_base::record_type => [bool => false;]; - end codegen_package_same; - ''' - - val static CODEGEN_PACKAGE_OTHER = ''' - -- @codegen-package org.osate.properties.codegenpackage.other - property set codegen_package_other is - with codegen_package_base; - - record_def: codegen_package_base::record_type applies to (all); - int_def: aadlinteger units codegen_package_base::speed applies to (all); - record_const: constant codegen_package_base::record_type => [bool => true;]; - end codegen_package_other; - ''' - - @Inject - TestHelper testHelper - - @Test - def void testCustomPackage() { - val codegenPackageBaseClass = ''' - package org.osate.properties.codegenpackage; - - import java.util.Optional; - - import org.eclipse.emf.ecore.EObject; - import org.osate.aadl2.Aadl2Package; - import org.osate.aadl2.Mode; - import org.osate.aadl2.NamedElement; - import org.osate.aadl2.Property; - import org.osate.aadl2.PropertyConstant; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; - import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; - import org.osate.aadl2.properties.PropertyNotPresentException; - import org.osate.pluginsupport.properties.CodeGenUtil; - - public final class CodegenPackageBase { - public static final String CODEGEN_PACKAGE_BASE__NAME = "codegen_package_base"; - - private CodegenPackageBase() {} - - // Lookup methods for codegen_package_base::record_def - - public static final String RECORD_DEF__NAME = "record_def"; - - public static boolean acceptsRecordDef(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getRecordDef_Property(lookupContext)); - } - - public static Optional getRecordDef(NamedElement lookupContext) { - return getRecordDef(lookupContext, Optional.empty()); - } - - public static Optional getRecordDef(NamedElement lookupContext, Mode mode) { - return getRecordDef(lookupContext, Optional.of(mode)); - } - - public static Optional getRecordDef(NamedElement lookupContext, Optional mode) { - Property property = getRecordDef_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(new RecordType(resolved, lookupContext, mode)); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getRecordDef_Property(EObject lookupContext) { - String name = CODEGEN_PACKAGE_BASE__NAME + "::" + RECORD_DEF__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getRecordDef_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getRecordDef_Property(lookupContext)); - } - - // Lookup methods for codegen_package_base::record_const - - public static final String RECORD_CONST__NAME = "record_const"; - - public static RecordType getRecordConst(EObject lookupContext) { - PropertyConstant constant = getRecordConst_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return new RecordType(resolved); - } - - public static PropertyConstant getRecordConst_PropertyConstant(EObject lookupContext) { - String name = CODEGEN_PACKAGE_BASE__NAME + "::" + RECORD_CONST__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - } - ''' - val speed = ''' - package org.osate.properties.codegenpackage; - - import org.eclipse.emf.common.util.URI; - import org.osate.aadl2.AbstractNamedValue; - import org.osate.aadl2.NamedValue; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.UnitLiteral; - import org.osate.pluginsupport.properties.GeneratedUnits; - - public enum Speed implements GeneratedUnits { - LIGHT(1.0, "light", "__synthetic0.aadl#/0/@ownedPropertyType.0/@ownedLiteral.0"), - RIDICULOUS(1000.0, "ridiculous", "__synthetic0.aadl#/0/@ownedPropertyType.0/@ownedLiteral.1"), - LUDICROUS(1000000.0, "ludicrous", "__synthetic0.aadl#/0/@ownedPropertyType.0/@ownedLiteral.2"); - - private final double factorToBase; - private final String originalName; - private final URI uri; - - private Speed(double factorToBase, String originalName, String uri) { - this.factorToBase = factorToBase; - this.originalName = originalName; - this.uri = URI.createURI(uri); - } - - public static Speed valueOf(PropertyExpression propertyExpression) { - AbstractNamedValue abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); - return valueOf(((UnitLiteral) abstractNamedValue).getName().toUpperCase()); - } - - @Override - public double getFactorToBase() { - return factorToBase; - } - - @Override - public double getFactorTo(Speed target) { - return factorToBase / target.factorToBase; - } - - @Override - public URI getURI() { - return uri; - } - - @Override - public String toString() { - return originalName; - } - } - ''' - val recordType = ''' - package org.osate.properties.codegenpackage; - - import java.util.Objects; - import java.util.Optional; - - import org.eclipse.emf.common.util.URI; - import org.eclipse.emf.ecore.resource.ResourceSet; - import org.osate.aadl2.Aadl2Factory; - import org.osate.aadl2.BasicPropertyAssociation; - import org.osate.aadl2.BooleanLiteral; - import org.osate.aadl2.Mode; - import org.osate.aadl2.NamedElement; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.RecordValue; - import org.osate.aadl2.properties.PropertyNotPresentException; - import org.osate.pluginsupport.properties.CodeGenUtil; - import org.osate.pluginsupport.properties.GeneratedRecord; - - public class RecordType extends GeneratedRecord { - public static final String BOOL__NAME = "bool"; - public static final URI BOOL__URI = URI.createURI("__synthetic0.aadl#/0/@ownedPropertyType.1/@ownedField.0"); - - private final Optional bool; - - public RecordType(Optional bool) { - this.bool = bool; - } - - public RecordType(PropertyExpression propertyExpression, NamedElement lookupContext, Optional mode) { - RecordValue recordValue = (RecordValue) propertyExpression; - - Optional bool_local; - try { - bool_local = findFieldValue(recordValue, BOOL__NAME).map(field -> { - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(field.getOwnedValue(), lookupContext, mode); - return ((BooleanLiteral) resolved).getValue(); - }); - } catch (PropertyNotPresentException e) { - bool_local = Optional.empty(); - } - this.bool = bool_local; - } - - public RecordType(PropertyExpression propertyExpression) { - RecordValue recordValue = (RecordValue) propertyExpression; - - Optional bool_local; - try { - bool_local = findFieldValue(recordValue, BOOL__NAME).map(field -> { - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(field.getOwnedValue()); - return ((BooleanLiteral) resolved).getValue(); - }); - } catch (PropertyNotPresentException e) { - bool_local = Optional.empty(); - } - this.bool = bool_local; - } - - public Optional getBool() { - return bool; - } - - @Override - public RecordValue toPropertyExpression(ResourceSet resourceSet) { - if (!bool.isPresent()) { - throw new IllegalStateException("Record must have at least one field set."); - } - RecordValue recordValue = Aadl2Factory.eINSTANCE.createRecordValue(); - bool.ifPresent(field -> { - BasicPropertyAssociation fieldAssociation = recordValue.createOwnedFieldValue(); - fieldAssociation.setProperty(loadField(resourceSet, BOOL__URI, BOOL__NAME)); - fieldAssociation.setOwnedValue(CodeGenUtil.toPropertyExpression(field)); - }); - return recordValue; - } - - @Override - public int hashCode() { - return Objects.hash(bool); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof RecordType)) { - return false; - } - RecordType other = (RecordType) obj; - return Objects.equals(this.bool, other.bool); - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append('['); - this.bool.ifPresent(field -> { - builder.append(BOOL__NAME); - builder.append(" => "); - builder.append(field); - builder.append(';'); - }); - builder.append(']'); - return builder.toString(); - } - } - ''' - val results = PropertiesCodeGen.generateJava(testHelper.parseString(CODEGEN_PACKAGE_BASE)) - assertEquals("src-gen/org/osate/properties/codegenpackage", results.packagePath) - assertEquals(3, results.classes.size) - - assertEquals("CodegenPackageBase.java", results.classes.get(0).fileName) - assertEquals(codegenPackageBaseClass.toString, results.classes.get(0).contents) - - assertEquals("Speed.java", results.classes.get(1).fileName) - assertEquals(speed.toString, results.classes.get(1).contents) - - assertEquals("RecordType.java", results.classes.get(2).fileName) - assertEquals(recordType.toString, results.classes.get(2).contents) - } - - @Test - def void testReferenceToSameCustomPackage() { - val codegenPackageSameClass = ''' - package org.osate.properties.codegenpackage; - - import java.util.Optional; - - import org.eclipse.emf.ecore.EObject; - import org.osate.aadl2.Aadl2Package; - import org.osate.aadl2.Mode; - import org.osate.aadl2.NamedElement; - import org.osate.aadl2.Property; - import org.osate.aadl2.PropertyConstant; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; - import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; - import org.osate.aadl2.properties.PropertyNotPresentException; - import org.osate.pluginsupport.properties.CodeGenUtil; - import org.osate.pluginsupport.properties.IntegerWithUnits; - - public final class CodegenPackageSame { - public static final String CODEGEN_PACKAGE_SAME__NAME = "codegen_package_same"; - - private CodegenPackageSame() {} - - // Lookup methods for codegen_package_same::record_def - - public static final String RECORD_DEF__NAME = "record_def"; - - public static boolean acceptsRecordDef(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getRecordDef_Property(lookupContext)); - } - - public static Optional getRecordDef(NamedElement lookupContext) { - return getRecordDef(lookupContext, Optional.empty()); - } - - public static Optional getRecordDef(NamedElement lookupContext, Mode mode) { - return getRecordDef(lookupContext, Optional.of(mode)); - } - - public static Optional getRecordDef(NamedElement lookupContext, Optional mode) { - Property property = getRecordDef_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(new RecordType(resolved, lookupContext, mode)); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getRecordDef_Property(EObject lookupContext) { - String name = CODEGEN_PACKAGE_SAME__NAME + "::" + RECORD_DEF__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getRecordDef_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getRecordDef_Property(lookupContext)); - } - - // Lookup methods for codegen_package_same::int_def - - public static final String INT_DEF__NAME = "int_def"; - - public static boolean acceptsIntDef(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getIntDef_Property(lookupContext)); - } - - public static Optional> getIntDef(NamedElement lookupContext) { - return getIntDef(lookupContext, Optional.empty()); - } - - public static Optional> getIntDef(NamedElement lookupContext, Mode mode) { - return getIntDef(lookupContext, Optional.of(mode)); - } - - public static Optional> getIntDef(NamedElement lookupContext, Optional mode) { - Property property = getIntDef_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(new IntegerWithUnits<>(resolved, Speed.class)); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getIntDef_Property(EObject lookupContext) { - String name = CODEGEN_PACKAGE_SAME__NAME + "::" + INT_DEF__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getIntDef_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getIntDef_Property(lookupContext)); - } - - // Lookup methods for codegen_package_same::record_const - - public static final String RECORD_CONST__NAME = "record_const"; - - public static RecordType getRecordConst(EObject lookupContext) { - PropertyConstant constant = getRecordConst_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return new RecordType(resolved); - } - - public static PropertyConstant getRecordConst_PropertyConstant(EObject lookupContext) { - String name = CODEGEN_PACKAGE_SAME__NAME + "::" + RECORD_CONST__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - } - ''' - val results = PropertiesCodeGen.generateJava(testHelper.parseString(CODEGEN_PACKAGE_SAME, CODEGEN_PACKAGE_BASE)) - assertEquals("src-gen/org/osate/properties/codegenpackage", results.packagePath) - assertEquals(1, results.classes.size) - - assertEquals("CodegenPackageSame.java", results.classes.head.fileName) - assertEquals(codegenPackageSameClass.toString, results.classes.head.contents) - } - - @Test - def void testReferenceToOtherCustomPackage() { - val codegenPackageOtherClass = ''' - package org.osate.properties.codegenpackage.other; - - import java.util.Optional; - - import org.eclipse.emf.ecore.EObject; - import org.osate.aadl2.Aadl2Package; - import org.osate.aadl2.Mode; - import org.osate.aadl2.NamedElement; - import org.osate.aadl2.Property; - import org.osate.aadl2.PropertyConstant; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; - import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; - import org.osate.aadl2.properties.PropertyNotPresentException; - import org.osate.pluginsupport.properties.CodeGenUtil; - import org.osate.pluginsupport.properties.IntegerWithUnits; - import org.osate.properties.codegenpackage.RecordType; - import org.osate.properties.codegenpackage.Speed; - - public final class CodegenPackageOther { - public static final String CODEGEN_PACKAGE_OTHER__NAME = "codegen_package_other"; - - private CodegenPackageOther() {} - - // Lookup methods for codegen_package_other::record_def - - public static final String RECORD_DEF__NAME = "record_def"; - - public static boolean acceptsRecordDef(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getRecordDef_Property(lookupContext)); - } - - public static Optional getRecordDef(NamedElement lookupContext) { - return getRecordDef(lookupContext, Optional.empty()); - } - - public static Optional getRecordDef(NamedElement lookupContext, Mode mode) { - return getRecordDef(lookupContext, Optional.of(mode)); - } - - public static Optional getRecordDef(NamedElement lookupContext, Optional mode) { - Property property = getRecordDef_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(new RecordType(resolved, lookupContext, mode)); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getRecordDef_Property(EObject lookupContext) { - String name = CODEGEN_PACKAGE_OTHER__NAME + "::" + RECORD_DEF__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getRecordDef_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getRecordDef_Property(lookupContext)); - } - - // Lookup methods for codegen_package_other::int_def - - public static final String INT_DEF__NAME = "int_def"; - - public static boolean acceptsIntDef(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getIntDef_Property(lookupContext)); - } - - public static Optional> getIntDef(NamedElement lookupContext) { - return getIntDef(lookupContext, Optional.empty()); - } - - public static Optional> getIntDef(NamedElement lookupContext, Mode mode) { - return getIntDef(lookupContext, Optional.of(mode)); - } - - public static Optional> getIntDef(NamedElement lookupContext, Optional mode) { - Property property = getIntDef_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(new IntegerWithUnits<>(resolved, Speed.class)); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getIntDef_Property(EObject lookupContext) { - String name = CODEGEN_PACKAGE_OTHER__NAME + "::" + INT_DEF__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getIntDef_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getIntDef_Property(lookupContext)); - } - - // Lookup methods for codegen_package_other::record_const - - public static final String RECORD_CONST__NAME = "record_const"; - - public static RecordType getRecordConst(EObject lookupContext) { - PropertyConstant constant = getRecordConst_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return new RecordType(resolved); - } - - public static PropertyConstant getRecordConst_PropertyConstant(EObject lookupContext) { - String name = CODEGEN_PACKAGE_OTHER__NAME + "::" + RECORD_CONST__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - } - ''' - val results = PropertiesCodeGen.generateJava(testHelper.parseString(CODEGEN_PACKAGE_OTHER, CODEGEN_PACKAGE_BASE)) - assertEquals("src-gen/org/osate/properties/codegenpackage/other", results.packagePath) - assertEquals(1, results.classes.size) - - assertEquals("CodegenPackageOther.java", results.classes.head.fileName) - assertEquals(codegenPackageOtherClass.toString, results.classes.head.contents) - } -} \ No newline at end of file diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/EnumerationTest.java b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/EnumerationTest.java new file mode 100644 index 00000000000..68604e62688 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/EnumerationTest.java @@ -0,0 +1,679 @@ +/******************************************************************************* + * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). + * All Rights Reserved. + * + * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY + * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE + * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT + * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * SPDX-License-Identifier: EPL-2.0 + * + * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). + * + * This program includes and/or can make use of certain third party source code, object code, documentation and other + * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system + * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and + * conditions contained in any such Third Party Software or separate license file distributed with such Third Party + * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries + * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses + * only apply to the Third Party Software and not any other portion of this program or this program as a whole. + *******************************************************************************/ +package org.osate.propertiescodegen.tests; + +import static org.junit.Assert.assertEquals; +import static org.osate.propertiescodegen.tests.GeneratedJavaCompiler.generateAndCompile; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osate.aadl2.PropertySet; +import org.osate.testsupport.Aadl2InjectorProvider; +import org.osate.testsupport.TestHelper; + +import com.google.inject.Inject; + +/** Verifies exact generated Java for enumeration. */ +@RunWith(XtextRunner.class) +@InjectWith(Aadl2InjectorProvider.class) +public class EnumerationTest { + @Inject + private TestHelper testHelper; + + @Test + public void testEnumeration() throws Exception { + var otherPs = """ + property set other_ps is + \tother_enumeration_type: type enumeration (one, two, three); + end other_ps; + """; + var enumerationTest = """ + property set enumeration_test is + \twith other_ps; + \t + \tlocal_enumeration_type: type enumeration (a, b, c); + \t + \towned_enumeration: enumeration (x, y, z) applies to (all); + \treferenced_enumeration_local: enumeration_test::local_enumeration_type applies to (all); + \treferenced_enumeration_other: other_ps::other_enumeration_type applies to (all); + \t + \tlist_1_enumeration: list of enumeration (red, green, blue) applies to (all); + \tlist_3_enumeration: list of list of list of enumeration_test::local_enumeration_type applies to (all); + \tlist_5_enumeration: list of list of list of list of list of other_ps::other_enumeration_type applies to (all); + \t + \towned_constant: constant enumeration (canada, usa, mexico) => canada; + \treferenced_local_constant: constant enumeration_test::local_enumeration_type => a; + \treferenced_other_constant: constant other_ps::other_enumeration_type => one; + \t + \tlist_1_constant: constant list of enumeration (mac, linux, windows) => (mac, linux); + \tlist_3_constant: constant list of list of list of enumeration_test::local_enumeration_type => (((a, b), ())); + \tlist_5_constant: constant list of list of list of list of list of other_ps::other_enumeration_type => (((( + \t\t(one, two), + \t\t(three), + \t\t() + \t)))); + end enumeration_test; + """; + var enumerationTestClass = """ + package enumerationtest; + + import java.util.List; + import java.util.Optional; + + import org.eclipse.emf.ecore.EObject; + import org.osate.aadl2.Aadl2Package; + import org.osate.aadl2.ListValue; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.Property; + import org.osate.aadl2.PropertyConstant; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; + import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + + import otherps.OtherEnumerationType; + + public final class EnumerationTest { + \tpublic static final String ENUMERATION_TEST__NAME = "enumeration_test"; + + \tprivate EnumerationTest() {} + + \t// Lookup methods for enumeration_test::owned_enumeration + + \tpublic static final String OWNED_ENUMERATION__NAME = "owned_enumeration"; + + \tpublic static boolean acceptsOwnedEnumeration(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getOwnedEnumeration_Property(lookupContext)); + \t} + + \tpublic static Optional getOwnedEnumeration(NamedElement lookupContext) { + \t\treturn getOwnedEnumeration(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getOwnedEnumeration(NamedElement lookupContext, Mode mode) { + \t\treturn getOwnedEnumeration(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getOwnedEnumeration(NamedElement lookupContext, Optional mode) { + \t\tvar property = getOwnedEnumeration_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(OwnedEnumeration.valueOf(resolved)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getOwnedEnumeration_Property(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + OWNED_ENUMERATION__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getOwnedEnumeration_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getOwnedEnumeration_Property(lookupContext)); + \t} + + \t// Lookup methods for enumeration_test::referenced_enumeration_local + + \tpublic static final String REFERENCED_ENUMERATION_LOCAL__NAME = "referenced_enumeration_local"; + + \tpublic static boolean acceptsReferencedEnumerationLocal(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getReferencedEnumerationLocal_Property(lookupContext)); + \t} + + \tpublic static Optional getReferencedEnumerationLocal(NamedElement lookupContext) { + \t\treturn getReferencedEnumerationLocal(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getReferencedEnumerationLocal(NamedElement lookupContext, Mode mode) { + \t\treturn getReferencedEnumerationLocal(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getReferencedEnumerationLocal(NamedElement lookupContext, Optional mode) { + \t\tvar property = getReferencedEnumerationLocal_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(LocalEnumerationType.valueOf(resolved)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getReferencedEnumerationLocal_Property(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + REFERENCED_ENUMERATION_LOCAL__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getReferencedEnumerationLocal_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getReferencedEnumerationLocal_Property(lookupContext)); + \t} + + \t// Lookup methods for enumeration_test::referenced_enumeration_other + + \tpublic static final String REFERENCED_ENUMERATION_OTHER__NAME = "referenced_enumeration_other"; + + \tpublic static boolean acceptsReferencedEnumerationOther(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getReferencedEnumerationOther_Property(lookupContext)); + \t} + + \tpublic static Optional getReferencedEnumerationOther(NamedElement lookupContext) { + \t\treturn getReferencedEnumerationOther(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getReferencedEnumerationOther(NamedElement lookupContext, Mode mode) { + \t\treturn getReferencedEnumerationOther(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getReferencedEnumerationOther(NamedElement lookupContext, Optional mode) { + \t\tvar property = getReferencedEnumerationOther_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(OtherEnumerationType.valueOf(resolved)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getReferencedEnumerationOther_Property(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + REFERENCED_ENUMERATION_OTHER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getReferencedEnumerationOther_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getReferencedEnumerationOther_Property(lookupContext)); + \t} + + \t// Lookup methods for enumeration_test::list_1_enumeration + + \tpublic static final String LIST_1_ENUMERATION__NAME = "list_1_enumeration"; + + \tpublic static boolean acceptsList1Enumeration(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList1Enumeration_Property(lookupContext)); + \t} + + \tpublic static Optional> getList1Enumeration(NamedElement lookupContext) { + \t\treturn getList1Enumeration(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getList1Enumeration(NamedElement lookupContext, Mode mode) { + \t\treturn getList1Enumeration(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getList1Enumeration(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList1Enumeration_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn List1Enumeration.valueOf(resolved1); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList1Enumeration_Property(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + LIST_1_ENUMERATION__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList1Enumeration_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList1Enumeration_Property(lookupContext)); + \t} + + \t// Lookup methods for enumeration_test::list_3_enumeration + + \tpublic static final String LIST_3_ENUMERATION__NAME = "list_3_enumeration"; + + \tpublic static boolean acceptsList3Enumeration(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList3Enumeration_Property(lookupContext)); + \t} + + \tpublic static Optional>>> getList3Enumeration(NamedElement lookupContext) { + \t\treturn getList3Enumeration(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional>>> getList3Enumeration(NamedElement lookupContext, Mode mode) { + \t\treturn getList3Enumeration(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional>>> getList3Enumeration(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList3Enumeration_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); + \t\t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); + \t\t\t\t\t\treturn LocalEnumerationType.valueOf(resolved3); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList3Enumeration_Property(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + LIST_3_ENUMERATION__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList3Enumeration_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList3Enumeration_Property(lookupContext)); + \t} + + \t// Lookup methods for enumeration_test::list_5_enumeration + + \tpublic static final String LIST_5_ENUMERATION__NAME = "list_5_enumeration"; + + \tpublic static boolean acceptsList5Enumeration(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList5Enumeration_Property(lookupContext)); + \t} + + \tpublic static Optional>>>>> getList5Enumeration(NamedElement lookupContext) { + \t\treturn getList5Enumeration(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional>>>>> getList5Enumeration(NamedElement lookupContext, Mode mode) { + \t\treturn getList5Enumeration(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional>>>>> getList5Enumeration(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList5Enumeration_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); + \t\t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); + \t\t\t\t\t\treturn ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { + \t\t\t\t\t\t\tvar resolved4 = CodeGenUtil.resolveNamedValue(element4, lookupContext, mode); + \t\t\t\t\t\t\treturn ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { + \t\t\t\t\t\t\t\tvar resolved5 = CodeGenUtil.resolveNamedValue(element5, lookupContext, mode); + \t\t\t\t\t\t\t\treturn OtherEnumerationType.valueOf(resolved5); + \t\t\t\t\t\t\t}).toList(); + \t\t\t\t\t\t}).toList(); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList5Enumeration_Property(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + LIST_5_ENUMERATION__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList5Enumeration_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList5Enumeration_Property(lookupContext)); + \t} + + \t// Lookup methods for enumeration_test::owned_constant + + \tpublic static final String OWNED_CONSTANT__NAME = "owned_constant"; + + \tpublic static OwnedConstant getOwnedConstant(EObject lookupContext) { + \t\tvar constant = getOwnedConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn OwnedConstant.valueOf(resolved); + \t} + + \tpublic static PropertyConstant getOwnedConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + OWNED_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for enumeration_test::referenced_local_constant + + \tpublic static final String REFERENCED_LOCAL_CONSTANT__NAME = "referenced_local_constant"; + + \tpublic static LocalEnumerationType getReferencedLocalConstant(EObject lookupContext) { + \t\tvar constant = getReferencedLocalConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn LocalEnumerationType.valueOf(resolved); + \t} + + \tpublic static PropertyConstant getReferencedLocalConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + REFERENCED_LOCAL_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for enumeration_test::referenced_other_constant + + \tpublic static final String REFERENCED_OTHER_CONSTANT__NAME = "referenced_other_constant"; + + \tpublic static OtherEnumerationType getReferencedOtherConstant(EObject lookupContext) { + \t\tvar constant = getReferencedOtherConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn OtherEnumerationType.valueOf(resolved); + \t} + + \tpublic static PropertyConstant getReferencedOtherConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + REFERENCED_OTHER_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for enumeration_test::list_1_constant + + \tpublic static final String LIST_1_CONSTANT__NAME = "list_1_constant"; + + \tpublic static List getList1Constant(EObject lookupContext) { + \t\tvar constant = getList1Constant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn List1Constant.valueOf(resolved1); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList1Constant_PropertyConstant(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + LIST_1_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for enumeration_test::list_3_constant + + \tpublic static final String LIST_3_CONSTANT__NAME = "list_3_constant"; + + \tpublic static List>> getList3Constant(EObject lookupContext) { + \t\tvar constant = getList3Constant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2); + \t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3); + \t\t\t\t\treturn LocalEnumerationType.valueOf(resolved3); + \t\t\t\t}).toList(); + \t\t\t}).toList(); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList3Constant_PropertyConstant(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + LIST_3_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for enumeration_test::list_5_constant + + \tpublic static final String LIST_5_CONSTANT__NAME = "list_5_constant"; + + \tpublic static List>>>> getList5Constant(EObject lookupContext) { + \t\tvar constant = getList5Constant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2); + \t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3); + \t\t\t\t\treturn ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { + \t\t\t\t\t\tvar resolved4 = CodeGenUtil.resolveNamedValue(element4); + \t\t\t\t\t\treturn ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { + \t\t\t\t\t\t\tvar resolved5 = CodeGenUtil.resolveNamedValue(element5); + \t\t\t\t\t\t\treturn OtherEnumerationType.valueOf(resolved5); + \t\t\t\t\t\t}).toList(); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList(); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList5Constant_PropertyConstant(EObject lookupContext) { + \t\tvar name = ENUMERATION_TEST__NAME + "::" + LIST_5_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + } + """; + var localEnumerationType = """ + package enumerationtest; + + import org.eclipse.emf.common.util.URI; + import org.osate.aadl2.EnumerationLiteral; + import org.osate.aadl2.NamedValue; + import org.osate.aadl2.PropertyExpression; + import org.osate.pluginsupport.properties.GeneratedEnumeration; + + public enum LocalEnumerationType implements GeneratedEnumeration { + \tA("a", "__synthetic1.aadl#/0/@ownedPropertyType.0/@ownedLiteral.0"), + \tB("b", "__synthetic1.aadl#/0/@ownedPropertyType.0/@ownedLiteral.1"), + \tC("c", "__synthetic1.aadl#/0/@ownedPropertyType.0/@ownedLiteral.2"); + + \tprivate final String originalName; + \tprivate final URI uri; + + \tprivate LocalEnumerationType(String originalName, String uri) { + \t\tthis.originalName = originalName; + \t\tthis.uri = URI.createURI(uri); + \t} + + \tpublic static LocalEnumerationType valueOf(PropertyExpression propertyExpression) { + \t\tvar abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); + \t\treturn valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); + \t} + + \t@Override + \tpublic URI getURI() { + \t\treturn uri; + \t} + + \t@Override + \tpublic String toString() { + \t\treturn originalName; + \t} + } + """; + var ownedEnumeration = """ + package enumerationtest; + + import org.eclipse.emf.common.util.URI; + import org.osate.aadl2.EnumerationLiteral; + import org.osate.aadl2.NamedValue; + import org.osate.aadl2.PropertyExpression; + import org.osate.pluginsupport.properties.GeneratedEnumeration; + + public enum OwnedEnumeration implements GeneratedEnumeration { + \tX("x", "__synthetic1.aadl#/0/@ownedProperty.0/@ownedPropertyType/@ownedLiteral.0"), + \tY("y", "__synthetic1.aadl#/0/@ownedProperty.0/@ownedPropertyType/@ownedLiteral.1"), + \tZ("z", "__synthetic1.aadl#/0/@ownedProperty.0/@ownedPropertyType/@ownedLiteral.2"); + + \tprivate final String originalName; + \tprivate final URI uri; + + \tprivate OwnedEnumeration(String originalName, String uri) { + \t\tthis.originalName = originalName; + \t\tthis.uri = URI.createURI(uri); + \t} + + \tpublic static OwnedEnumeration valueOf(PropertyExpression propertyExpression) { + \t\tvar abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); + \t\treturn valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); + \t} + + \t@Override + \tpublic URI getURI() { + \t\treturn uri; + \t} + + \t@Override + \tpublic String toString() { + \t\treturn originalName; + \t} + } + """; + var list1Enumeration = """ + package enumerationtest; + + import org.eclipse.emf.common.util.URI; + import org.osate.aadl2.EnumerationLiteral; + import org.osate.aadl2.NamedValue; + import org.osate.aadl2.PropertyExpression; + import org.osate.pluginsupport.properties.GeneratedEnumeration; + + public enum List1Enumeration implements GeneratedEnumeration { + \tRED("red", "__synthetic1.aadl#/0/@ownedProperty.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.0"), + \tGREEN("green", "__synthetic1.aadl#/0/@ownedProperty.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.1"), + \tBLUE("blue", "__synthetic1.aadl#/0/@ownedProperty.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.2"); + + \tprivate final String originalName; + \tprivate final URI uri; + + \tprivate List1Enumeration(String originalName, String uri) { + \t\tthis.originalName = originalName; + \t\tthis.uri = URI.createURI(uri); + \t} + + \tpublic static List1Enumeration valueOf(PropertyExpression propertyExpression) { + \t\tvar abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); + \t\treturn valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); + \t} + + \t@Override + \tpublic URI getURI() { + \t\treturn uri; + \t} + + \t@Override + \tpublic String toString() { + \t\treturn originalName; + \t} + } + """; + var ownedConstant = """ + package enumerationtest; + + import org.eclipse.emf.common.util.URI; + import org.osate.aadl2.EnumerationLiteral; + import org.osate.aadl2.NamedValue; + import org.osate.aadl2.PropertyExpression; + import org.osate.pluginsupport.properties.GeneratedEnumeration; + + public enum OwnedConstant implements GeneratedEnumeration { + \tCANADA("canada", "__synthetic1.aadl#/0/@ownedPropertyConstant.0/@ownedPropertyType/@ownedLiteral.0"), + \tUSA("usa", "__synthetic1.aadl#/0/@ownedPropertyConstant.0/@ownedPropertyType/@ownedLiteral.1"), + \tMEXICO("mexico", "__synthetic1.aadl#/0/@ownedPropertyConstant.0/@ownedPropertyType/@ownedLiteral.2"); + + \tprivate final String originalName; + \tprivate final URI uri; + + \tprivate OwnedConstant(String originalName, String uri) { + \t\tthis.originalName = originalName; + \t\tthis.uri = URI.createURI(uri); + \t} + + \tpublic static OwnedConstant valueOf(PropertyExpression propertyExpression) { + \t\tvar abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); + \t\treturn valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); + \t} + + \t@Override + \tpublic URI getURI() { + \t\treturn uri; + \t} + + \t@Override + \tpublic String toString() { + \t\treturn originalName; + \t} + } + """; + var list1Constant = """ + package enumerationtest; + + import org.eclipse.emf.common.util.URI; + import org.osate.aadl2.EnumerationLiteral; + import org.osate.aadl2.NamedValue; + import org.osate.aadl2.PropertyExpression; + import org.osate.pluginsupport.properties.GeneratedEnumeration; + + public enum List1Constant implements GeneratedEnumeration { + \tMAC("mac", "__synthetic1.aadl#/0/@ownedPropertyConstant.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.0"), + \tLINUX("linux", "__synthetic1.aadl#/0/@ownedPropertyConstant.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.1"), + \tWINDOWS("windows", "__synthetic1.aadl#/0/@ownedPropertyConstant.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.2"); + + \tprivate final String originalName; + \tprivate final URI uri; + + \tprivate List1Constant(String originalName, String uri) { + \t\tthis.originalName = originalName; + \t\tthis.uri = URI.createURI(uri); + \t} + + \tpublic static List1Constant valueOf(PropertyExpression propertyExpression) { + \t\tvar abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); + \t\treturn valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); + \t} + + \t@Override + \tpublic URI getURI() { + \t\treturn uri; + \t} + + \t@Override + \tpublic String toString() { + \t\treturn originalName; + \t} + } + """; + var results = generateAndCompile(testHelper.parseString(enumerationTest, otherPs)); + assertEquals("src-gen/enumerationtest", results.getPackagePath()); + assertEquals(6, results.getClasses().size()); + + assertEquals("EnumerationTest.java", results.getClasses().get(0).getFileName()); + assertEquals(enumerationTestClass, results.getClasses().get(0).getContents()); + + assertEquals("LocalEnumerationType.java", results.getClasses().get(1).getFileName()); + assertEquals(localEnumerationType, results.getClasses().get(1).getContents()); + + assertEquals("OwnedEnumeration.java", results.getClasses().get(2).getFileName()); + assertEquals(ownedEnumeration, results.getClasses().get(2).getContents()); + + assertEquals("List1Enumeration.java", results.getClasses().get(3).getFileName()); + assertEquals(list1Enumeration, results.getClasses().get(3).getContents()); + + assertEquals("OwnedConstant.java", results.getClasses().get(4).getFileName()); + assertEquals(ownedConstant, results.getClasses().get(4).getContents()); + + assertEquals("List1Constant.java", results.getClasses().get(5).getFileName()); + assertEquals(list1Constant, results.getClasses().get(5).getContents()); + } +} diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/EnumerationTest.xtend b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/EnumerationTest.xtend deleted file mode 100644 index af39494f2bd..00000000000 --- a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/EnumerationTest.xtend +++ /dev/null @@ -1,683 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). - * All Rights Reserved. - * - * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY - * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE - * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT - * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. - * - * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * SPDX-License-Identifier: EPL-2.0 - * - * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). - * - * This program includes and/or can make use of certain third party source code, object code, documentation and other - * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system - * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and - * conditions contained in any such Third Party Software or separate license file distributed with such Third Party - * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries - * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses - * only apply to the Third Party Software and not any other portion of this program or this program as a whole. - *******************************************************************************/ -package org.osate.propertiescodegen.tests - -import com.google.inject.Inject -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner -import org.junit.Test -import org.junit.runner.RunWith -import org.osate.aadl2.PropertySet -import org.osate.propertiescodegen.PropertiesCodeGen -import org.osate.testsupport.Aadl2InjectorProvider -import org.osate.testsupport.TestHelper - -import static org.junit.Assert.assertEquals - -@RunWith(XtextRunner) -@InjectWith(Aadl2InjectorProvider) -class EnumerationTest { - @Inject - TestHelper testHelper - - @Test - def void testEnumeration() { - val otherPs = ''' - property set other_ps is - other_enumeration_type: type enumeration (one, two, three); - end other_ps; - ''' - val enumerationTest = ''' - property set enumeration_test is - with other_ps; - - local_enumeration_type: type enumeration (a, b, c); - - owned_enumeration: enumeration (x, y, z) applies to (all); - referenced_enumeration_local: enumeration_test::local_enumeration_type applies to (all); - referenced_enumeration_other: other_ps::other_enumeration_type applies to (all); - - list_1_enumeration: list of enumeration (red, green, blue) applies to (all); - list_3_enumeration: list of list of list of enumeration_test::local_enumeration_type applies to (all); - list_5_enumeration: list of list of list of list of list of other_ps::other_enumeration_type applies to (all); - - owned_constant: constant enumeration (canada, usa, mexico) => canada; - referenced_local_constant: constant enumeration_test::local_enumeration_type => a; - referenced_other_constant: constant other_ps::other_enumeration_type => one; - - list_1_constant: constant list of enumeration (mac, linux, windows) => (mac, linux); - list_3_constant: constant list of list of list of enumeration_test::local_enumeration_type => (((a, b), ())); - list_5_constant: constant list of list of list of list of list of other_ps::other_enumeration_type => (((( - (one, two), - (three), - () - )))); - end enumeration_test; - ''' - val enumerationTestClass = ''' - package enumerationtest; - - import java.util.List; - import java.util.Optional; - import java.util.stream.Collectors; - - import org.eclipse.emf.ecore.EObject; - import org.osate.aadl2.Aadl2Package; - import org.osate.aadl2.ListValue; - import org.osate.aadl2.Mode; - import org.osate.aadl2.NamedElement; - import org.osate.aadl2.Property; - import org.osate.aadl2.PropertyConstant; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; - import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; - import org.osate.aadl2.properties.PropertyNotPresentException; - import org.osate.pluginsupport.properties.CodeGenUtil; - - import otherps.OtherEnumerationType; - - public final class EnumerationTest { - public static final String ENUMERATION_TEST__NAME = "enumeration_test"; - - private EnumerationTest() {} - - // Lookup methods for enumeration_test::owned_enumeration - - public static final String OWNED_ENUMERATION__NAME = "owned_enumeration"; - - public static boolean acceptsOwnedEnumeration(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getOwnedEnumeration_Property(lookupContext)); - } - - public static Optional getOwnedEnumeration(NamedElement lookupContext) { - return getOwnedEnumeration(lookupContext, Optional.empty()); - } - - public static Optional getOwnedEnumeration(NamedElement lookupContext, Mode mode) { - return getOwnedEnumeration(lookupContext, Optional.of(mode)); - } - - public static Optional getOwnedEnumeration(NamedElement lookupContext, Optional mode) { - Property property = getOwnedEnumeration_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(OwnedEnumeration.valueOf(resolved)); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getOwnedEnumeration_Property(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + OWNED_ENUMERATION__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getOwnedEnumeration_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getOwnedEnumeration_Property(lookupContext)); - } - - // Lookup methods for enumeration_test::referenced_enumeration_local - - public static final String REFERENCED_ENUMERATION_LOCAL__NAME = "referenced_enumeration_local"; - - public static boolean acceptsReferencedEnumerationLocal(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getReferencedEnumerationLocal_Property(lookupContext)); - } - - public static Optional getReferencedEnumerationLocal(NamedElement lookupContext) { - return getReferencedEnumerationLocal(lookupContext, Optional.empty()); - } - - public static Optional getReferencedEnumerationLocal(NamedElement lookupContext, Mode mode) { - return getReferencedEnumerationLocal(lookupContext, Optional.of(mode)); - } - - public static Optional getReferencedEnumerationLocal(NamedElement lookupContext, Optional mode) { - Property property = getReferencedEnumerationLocal_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(LocalEnumerationType.valueOf(resolved)); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getReferencedEnumerationLocal_Property(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + REFERENCED_ENUMERATION_LOCAL__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getReferencedEnumerationLocal_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getReferencedEnumerationLocal_Property(lookupContext)); - } - - // Lookup methods for enumeration_test::referenced_enumeration_other - - public static final String REFERENCED_ENUMERATION_OTHER__NAME = "referenced_enumeration_other"; - - public static boolean acceptsReferencedEnumerationOther(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getReferencedEnumerationOther_Property(lookupContext)); - } - - public static Optional getReferencedEnumerationOther(NamedElement lookupContext) { - return getReferencedEnumerationOther(lookupContext, Optional.empty()); - } - - public static Optional getReferencedEnumerationOther(NamedElement lookupContext, Mode mode) { - return getReferencedEnumerationOther(lookupContext, Optional.of(mode)); - } - - public static Optional getReferencedEnumerationOther(NamedElement lookupContext, Optional mode) { - Property property = getReferencedEnumerationOther_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(OtherEnumerationType.valueOf(resolved)); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getReferencedEnumerationOther_Property(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + REFERENCED_ENUMERATION_OTHER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getReferencedEnumerationOther_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getReferencedEnumerationOther_Property(lookupContext)); - } - - // Lookup methods for enumeration_test::list_1_enumeration - - public static final String LIST_1_ENUMERATION__NAME = "list_1_enumeration"; - - public static boolean acceptsList1Enumeration(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList1Enumeration_Property(lookupContext)); - } - - public static Optional> getList1Enumeration(NamedElement lookupContext) { - return getList1Enumeration(lookupContext, Optional.empty()); - } - - public static Optional> getList1Enumeration(NamedElement lookupContext, Mode mode) { - return getList1Enumeration(lookupContext, Optional.of(mode)); - } - - public static Optional> getList1Enumeration(NamedElement lookupContext, Optional mode) { - Property property = getList1Enumeration_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return List1Enumeration.valueOf(resolved1); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList1Enumeration_Property(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + LIST_1_ENUMERATION__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList1Enumeration_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList1Enumeration_Property(lookupContext)); - } - - // Lookup methods for enumeration_test::list_3_enumeration - - public static final String LIST_3_ENUMERATION__NAME = "list_3_enumeration"; - - public static boolean acceptsList3Enumeration(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList3Enumeration_Property(lookupContext)); - } - - public static Optional>>> getList3Enumeration(NamedElement lookupContext) { - return getList3Enumeration(lookupContext, Optional.empty()); - } - - public static Optional>>> getList3Enumeration(NamedElement lookupContext, Mode mode) { - return getList3Enumeration(lookupContext, Optional.of(mode)); - } - - public static Optional>>> getList3Enumeration(NamedElement lookupContext, Optional mode) { - Property property = getList3Enumeration_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); - return LocalEnumerationType.valueOf(resolved3); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList3Enumeration_Property(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + LIST_3_ENUMERATION__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList3Enumeration_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList3Enumeration_Property(lookupContext)); - } - - // Lookup methods for enumeration_test::list_5_enumeration - - public static final String LIST_5_ENUMERATION__NAME = "list_5_enumeration"; - - public static boolean acceptsList5Enumeration(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList5Enumeration_Property(lookupContext)); - } - - public static Optional>>>>> getList5Enumeration(NamedElement lookupContext) { - return getList5Enumeration(lookupContext, Optional.empty()); - } - - public static Optional>>>>> getList5Enumeration(NamedElement lookupContext, Mode mode) { - return getList5Enumeration(lookupContext, Optional.of(mode)); - } - - public static Optional>>>>> getList5Enumeration(NamedElement lookupContext, Optional mode) { - Property property = getList5Enumeration_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); - return ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { - PropertyExpression resolved4 = CodeGenUtil.resolveNamedValue(element4, lookupContext, mode); - return ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { - PropertyExpression resolved5 = CodeGenUtil.resolveNamedValue(element5, lookupContext, mode); - return OtherEnumerationType.valueOf(resolved5); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList5Enumeration_Property(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + LIST_5_ENUMERATION__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList5Enumeration_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList5Enumeration_Property(lookupContext)); - } - - // Lookup methods for enumeration_test::owned_constant - - public static final String OWNED_CONSTANT__NAME = "owned_constant"; - - public static OwnedConstant getOwnedConstant(EObject lookupContext) { - PropertyConstant constant = getOwnedConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return OwnedConstant.valueOf(resolved); - } - - public static PropertyConstant getOwnedConstant_PropertyConstant(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + OWNED_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for enumeration_test::referenced_local_constant - - public static final String REFERENCED_LOCAL_CONSTANT__NAME = "referenced_local_constant"; - - public static LocalEnumerationType getReferencedLocalConstant(EObject lookupContext) { - PropertyConstant constant = getReferencedLocalConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return LocalEnumerationType.valueOf(resolved); - } - - public static PropertyConstant getReferencedLocalConstant_PropertyConstant(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + REFERENCED_LOCAL_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for enumeration_test::referenced_other_constant - - public static final String REFERENCED_OTHER_CONSTANT__NAME = "referenced_other_constant"; - - public static OtherEnumerationType getReferencedOtherConstant(EObject lookupContext) { - PropertyConstant constant = getReferencedOtherConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return OtherEnumerationType.valueOf(resolved); - } - - public static PropertyConstant getReferencedOtherConstant_PropertyConstant(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + REFERENCED_OTHER_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for enumeration_test::list_1_constant - - public static final String LIST_1_CONSTANT__NAME = "list_1_constant"; - - public static List getList1Constant(EObject lookupContext) { - PropertyConstant constant = getList1Constant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return List1Constant.valueOf(resolved1); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList1Constant_PropertyConstant(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + LIST_1_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for enumeration_test::list_3_constant - - public static final String LIST_3_CONSTANT__NAME = "list_3_constant"; - - public static List>> getList3Constant(EObject lookupContext) { - PropertyConstant constant = getList3Constant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3); - return LocalEnumerationType.valueOf(resolved3); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList3Constant_PropertyConstant(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + LIST_3_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for enumeration_test::list_5_constant - - public static final String LIST_5_CONSTANT__NAME = "list_5_constant"; - - public static List>>>> getList5Constant(EObject lookupContext) { - PropertyConstant constant = getList5Constant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3); - return ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { - PropertyExpression resolved4 = CodeGenUtil.resolveNamedValue(element4); - return ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { - PropertyExpression resolved5 = CodeGenUtil.resolveNamedValue(element5); - return OtherEnumerationType.valueOf(resolved5); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList5Constant_PropertyConstant(EObject lookupContext) { - String name = ENUMERATION_TEST__NAME + "::" + LIST_5_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - } - ''' - val localEnumerationType = ''' - package enumerationtest; - - import org.eclipse.emf.common.util.URI; - import org.osate.aadl2.AbstractNamedValue; - import org.osate.aadl2.EnumerationLiteral; - import org.osate.aadl2.NamedValue; - import org.osate.aadl2.PropertyExpression; - import org.osate.pluginsupport.properties.GeneratedEnumeration; - - public enum LocalEnumerationType implements GeneratedEnumeration { - A("a", "__synthetic1.aadl#/0/@ownedPropertyType.0/@ownedLiteral.0"), - B("b", "__synthetic1.aadl#/0/@ownedPropertyType.0/@ownedLiteral.1"), - C("c", "__synthetic1.aadl#/0/@ownedPropertyType.0/@ownedLiteral.2"); - - private final String originalName; - private final URI uri; - - private LocalEnumerationType(String originalName, String uri) { - this.originalName = originalName; - this.uri = URI.createURI(uri); - } - - public static LocalEnumerationType valueOf(PropertyExpression propertyExpression) { - AbstractNamedValue abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); - return valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); - } - - @Override - public URI getURI() { - return uri; - } - - @Override - public String toString() { - return originalName; - } - } - ''' - val ownedEnumeration = ''' - package enumerationtest; - - import org.eclipse.emf.common.util.URI; - import org.osate.aadl2.AbstractNamedValue; - import org.osate.aadl2.EnumerationLiteral; - import org.osate.aadl2.NamedValue; - import org.osate.aadl2.PropertyExpression; - import org.osate.pluginsupport.properties.GeneratedEnumeration; - - public enum OwnedEnumeration implements GeneratedEnumeration { - X("x", "__synthetic1.aadl#/0/@ownedProperty.0/@ownedPropertyType/@ownedLiteral.0"), - Y("y", "__synthetic1.aadl#/0/@ownedProperty.0/@ownedPropertyType/@ownedLiteral.1"), - Z("z", "__synthetic1.aadl#/0/@ownedProperty.0/@ownedPropertyType/@ownedLiteral.2"); - - private final String originalName; - private final URI uri; - - private OwnedEnumeration(String originalName, String uri) { - this.originalName = originalName; - this.uri = URI.createURI(uri); - } - - public static OwnedEnumeration valueOf(PropertyExpression propertyExpression) { - AbstractNamedValue abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); - return valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); - } - - @Override - public URI getURI() { - return uri; - } - - @Override - public String toString() { - return originalName; - } - } - ''' - val list1Enumeration = ''' - package enumerationtest; - - import org.eclipse.emf.common.util.URI; - import org.osate.aadl2.AbstractNamedValue; - import org.osate.aadl2.EnumerationLiteral; - import org.osate.aadl2.NamedValue; - import org.osate.aadl2.PropertyExpression; - import org.osate.pluginsupport.properties.GeneratedEnumeration; - - public enum List1Enumeration implements GeneratedEnumeration { - RED("red", "__synthetic1.aadl#/0/@ownedProperty.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.0"), - GREEN("green", "__synthetic1.aadl#/0/@ownedProperty.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.1"), - BLUE("blue", "__synthetic1.aadl#/0/@ownedProperty.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.2"); - - private final String originalName; - private final URI uri; - - private List1Enumeration(String originalName, String uri) { - this.originalName = originalName; - this.uri = URI.createURI(uri); - } - - public static List1Enumeration valueOf(PropertyExpression propertyExpression) { - AbstractNamedValue abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); - return valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); - } - - @Override - public URI getURI() { - return uri; - } - - @Override - public String toString() { - return originalName; - } - } - ''' - val ownedConstant = ''' - package enumerationtest; - - import org.eclipse.emf.common.util.URI; - import org.osate.aadl2.AbstractNamedValue; - import org.osate.aadl2.EnumerationLiteral; - import org.osate.aadl2.NamedValue; - import org.osate.aadl2.PropertyExpression; - import org.osate.pluginsupport.properties.GeneratedEnumeration; - - public enum OwnedConstant implements GeneratedEnumeration { - CANADA("canada", "__synthetic1.aadl#/0/@ownedPropertyConstant.0/@ownedPropertyType/@ownedLiteral.0"), - USA("usa", "__synthetic1.aadl#/0/@ownedPropertyConstant.0/@ownedPropertyType/@ownedLiteral.1"), - MEXICO("mexico", "__synthetic1.aadl#/0/@ownedPropertyConstant.0/@ownedPropertyType/@ownedLiteral.2"); - - private final String originalName; - private final URI uri; - - private OwnedConstant(String originalName, String uri) { - this.originalName = originalName; - this.uri = URI.createURI(uri); - } - - public static OwnedConstant valueOf(PropertyExpression propertyExpression) { - AbstractNamedValue abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); - return valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); - } - - @Override - public URI getURI() { - return uri; - } - - @Override - public String toString() { - return originalName; - } - } - ''' - val list1Constant = ''' - package enumerationtest; - - import org.eclipse.emf.common.util.URI; - import org.osate.aadl2.AbstractNamedValue; - import org.osate.aadl2.EnumerationLiteral; - import org.osate.aadl2.NamedValue; - import org.osate.aadl2.PropertyExpression; - import org.osate.pluginsupport.properties.GeneratedEnumeration; - - public enum List1Constant implements GeneratedEnumeration { - MAC("mac", "__synthetic1.aadl#/0/@ownedPropertyConstant.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.0"), - LINUX("linux", "__synthetic1.aadl#/0/@ownedPropertyConstant.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.1"), - WINDOWS("windows", "__synthetic1.aadl#/0/@ownedPropertyConstant.3/@ownedPropertyType/@ownedElementType/@ownedLiteral.2"); - - private final String originalName; - private final URI uri; - - private List1Constant(String originalName, String uri) { - this.originalName = originalName; - this.uri = URI.createURI(uri); - } - - public static List1Constant valueOf(PropertyExpression propertyExpression) { - AbstractNamedValue abstractNamedValue = ((NamedValue) propertyExpression).getNamedValue(); - return valueOf(((EnumerationLiteral) abstractNamedValue).getName().toUpperCase()); - } - - @Override - public URI getURI() { - return uri; - } - - @Override - public String toString() { - return originalName; - } - } - ''' - val results = PropertiesCodeGen.generateJava(testHelper.parseString(enumerationTest, otherPs)) - assertEquals("src-gen/enumerationtest", results.packagePath) - assertEquals(6, results.classes.size) - - assertEquals("EnumerationTest.java", results.classes.get(0).fileName) - assertEquals(enumerationTestClass.toString, results.classes.get(0).contents) - - assertEquals("LocalEnumerationType.java", results.classes.get(1).fileName) - assertEquals(localEnumerationType.toString, results.classes.get(1).contents) - - assertEquals("OwnedEnumeration.java", results.classes.get(2).fileName) - assertEquals(ownedEnumeration.toString, results.classes.get(2).contents) - - assertEquals("List1Enumeration.java", results.classes.get(3).fileName) - assertEquals(list1Enumeration.toString, results.classes.get(3).contents) - - assertEquals("OwnedConstant.java", results.classes.get(4).fileName) - assertEquals(ownedConstant.toString, results.classes.get(4).contents) - - assertEquals("List1Constant.java", results.classes.get(5).fileName) - assertEquals(list1Constant.toString, results.classes.get(5).contents) - } -} \ No newline at end of file diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/GeneratedJavaCompiler.java b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/GeneratedJavaCompiler.java new file mode 100644 index 00000000000..caad7179d35 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/GeneratedJavaCompiler.java @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). + * All Rights Reserved. + * + * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY + * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE + * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT + * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * SPDX-License-Identifier: EPL-2.0 + * + * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). + * + * This program includes and/or can make use of certain third party source code, object code, documentation and other + * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system + * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and + * conditions contained in any such Third Party Software or separate license file distributed with such Third Party + * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries + * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses + * only apply to the Third Party Software and not any other portion of this program or this program as a whole. + *******************************************************************************/ +package org.osate.propertiescodegen.tests; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.tools.DiagnosticCollector; +import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; +import javax.tools.ToolProvider; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.osate.aadl2.NamedElement; +import org.osate.aadl2.PropertySet; +import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; +import org.osate.pluginsupport.properties.CodeGenUtil; +import org.osate.propertiescodegen.GeneratedPackage; +import org.osate.propertiescodegen.PropertiesCodeGen; + +/** Compiles actual generator output against the same OSATE classes used by the OSGi test runtime. */ +final class GeneratedJavaCompiler { + private GeneratedJavaCompiler() { + } + + static GeneratedPackage generateAndCompile(PropertySet propertySet) throws Exception { + try (var compiled = compile(propertySet)) { + return compiled.generatedPackage(); + } + } + + static CompiledJava compile(PropertySet propertySet) throws Exception { + var compiler = ToolProvider.getSystemJavaCompiler(); + assertNotNull("Generated-code tests require a JDK with the Java compiler", compiler); + var directory = Files.createTempDirectory("osate-generated-java-"); + try { + var packages = new LinkedHashMap(); + generateDependencies(propertySet, packages); + var sources = new ArrayList(); + for (var generated : packages.values()) { + var packageDirectory = directory.resolve(generated.getPackagePath()); + Files.createDirectories(packageDirectory); + for (var source : generated.getClasses()) { + var path = packageDirectory.resolve(source.getFileName()); + Files.writeString(path, source.getContents(), StandardCharsets.UTF_8); + sources.add(path); + } + } + var classes = Files.createDirectory(directory.resolve("classes")); + var diagnostics = new DiagnosticCollector(); + try (var files = compiler.getStandardFileManager(diagnostics, null, StandardCharsets.UTF_8)) { + files.setLocationFromPaths(StandardLocation.CLASS_PATH, classPath()); + files.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, List.of(classes)); + var success = compiler + .getTask(null, files, diagnostics, List.of("--release", "21", "-proc:none"), null, + files.getJavaFileObjectsFromPaths(sources)) + .call(); + assertTrue("Generated Java failed to compile for " + propertySet.getName() + ":\n" + + diagnostics.getDiagnostics().stream().map(Object::toString).collect(Collectors.joining("\n")), + success); + } + return new CompiledJava(packages.get(propertySet), directory, new URLClassLoader( + new URL[] { classes.toUri().toURL() }, GeneratedJavaCompiler.class.getClassLoader())); + } catch (Exception | AssertionError e) { + try { + deleteDirectory(directory); + } catch (IOException cleanupFailure) { + e.addSuppressed(cleanupFailure); + } + throw e; + } + } + + private static void generateDependencies(PropertySet propertySet, Map packages) { + if (packages.containsKey(propertySet)) { + return; + } + packages.put(propertySet, PropertiesCodeGen.generateJava(propertySet)); + for (var imported : propertySet.getImportedUnits()) { + if (imported instanceof PropertySet dependency) { + generateDependencies(dependency, packages); + } + } + } + + private static List classPath() throws Exception { + // java.class.path contains the Equinox launcher, not the bundles supplying generated-code APIs. + var locations = new LinkedHashSet(); + for (var anchor : List.of(IAdaptable.class, URI.class, EObject.class, NamedElement.class, + Aadl2GlobalScopeUtil.class, CodeGenUtil.class)) { + locations.add(Path.of(anchor.getProtectionDomain().getCodeSource().getLocation().toURI())); + } + return List.copyOf(locations); + } + + private static void deleteDirectory(Path directory) throws IOException { + try (var paths = Files.walk(directory)) { + for (var path : paths.sorted(Comparator.reverseOrder()).toList()) { + Files.delete(path); + } + } + } + + record CompiledJava(GeneratedPackage generatedPackage, Path directory, URLClassLoader loader) + implements AutoCloseable { + Class loadClass(String name) throws ClassNotFoundException { + return loader.loadClass(name); + } + + @Override + public void close() throws IOException { + try { + loader.close(); + } finally { + deleteDirectory(directory); + } + } + } +} diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/GeneratedJavaRuntimeTest.java b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/GeneratedJavaRuntimeTest.java new file mode 100644 index 00000000000..260b21c0d9f --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/GeneratedJavaRuntimeTest.java @@ -0,0 +1,219 @@ +/******************************************************************************* + * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). + * All Rights Reserved. + * + * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY + * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE + * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT + * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * SPDX-License-Identifier: EPL-2.0 + * + * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). + * + * This program includes and/or can make use of certain third party source code, object code, documentation and other + * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system + * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and + * conditions contained in any such Third Party Software or separate license file distributed with such Third Party + * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries + * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses + * only apply to the Third Party Software and not any other portion of this program or this program as a whole. + *******************************************************************************/ +package org.osate.propertiescodegen.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.Optional; +import java.util.OptionalDouble; +import java.util.OptionalLong; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.eclipse.xtext.testing.validation.ValidationTestHelper; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osate.aadl2.AadlPackage; +import org.osate.aadl2.ComponentImplementation; +import org.osate.aadl2.Mode; +import org.osate.aadl2.NamedElement; +import org.osate.aadl2.PropertyExpression; +import org.osate.aadl2.PropertySet; +import org.osate.pluginsupport.properties.GeneratedEnumeration; +import org.osate.pluginsupport.properties.GeneratedRecord; +import org.osate.pluginsupport.properties.GeneratedUnits; +import org.osate.pluginsupport.properties.IntegerRange; +import org.osate.pluginsupport.properties.IntegerWithUnits; +import org.osate.propertiescodegen.tests.GeneratedJavaCompiler.CompiledJava; +import org.osate.testsupport.Aadl2InjectorProvider; +import org.osate.testsupport.TestHelper; + +import com.google.inject.Inject; + +/** Executes freshly compiled generated classes against validated AADL property values. */ +@RunWith(XtextRunner.class) +@InjectWith(Aadl2InjectorProvider.class) +public class GeneratedJavaRuntimeTest { + private static final String MODEL_PATH = "org.osate.propertiescodegen.tests/models/generatedjava/"; + + @Inject + private TestHelper testHelper; + + @Inject + private ValidationTestHelper validationHelper; + + private AadlPackage model; + private CompiledJava compiled; + private Class getters; + + @Before + public void compileModel() throws Exception { + model = testHelper.parseFile(MODEL_PATH + "RuntimeModel.aadl", MODEL_PATH + "ExternalTypes.aadl", + MODEL_PATH + "RuntimeProperties.aadl"); + validationHelper.assertNoIssues(model); + var properties = (PropertySet) model.getOwnedPublicSection().getImportedUnits().getFirst(); + validationHelper.assertNoIssues(properties); + validationHelper.assertNoIssues(properties.getImportedUnits().getFirst()); + compiled = GeneratedJavaCompiler.compile(properties); + getters = compiled.loadClass("generated.runtime.RuntimeProperties"); + } + + @After + public void closeCompiledClasses() throws Exception { + if (compiled != null) { + compiled.close(); + } + } + + @Test + public void scalarGettersResolveValuesConstantsAndPropertyReferences() throws Exception { + var context = classifier("Populated"); + assertEquals(Optional.of(true), get("Enabled", context)); + assertEquals(OptionalLong.of(41), get("Count", context)); + assertEquals(OptionalLong.of(41), get("CountAlias", context)); + assertEquals(OptionalDouble.of(1.5), get("Ratio", context)); + assertEquals(Optional.of("hello"), get("Label", context)); + assertEquals(41L, getters.getMethod("getAliasConstant", EObject.class).invoke(null, context)); + assertEquals(true, getters.getMethod("acceptsEnabled", NamedElement.class).invoke(null, context)); + } + + @Test + public void absentAndInapplicablePropertiesReturnEmptyAndDefaultsAreApplied() throws Exception { + var context = classifier("Empty"); + assertEquals(Optional.empty(), get("Enabled", context)); + assertEquals(OptionalLong.empty(), get("Count", context)); + assertEquals(OptionalDouble.empty(), get("Ratio", context)); + assertEquals(Optional.empty(), get("Settings", context)); + assertEquals(OptionalLong.of(7), get("DefaultCount", context)); + assertEquals(false, getters.getMethod("acceptsThreadOnly", NamedElement.class).invoke(null, context)); + assertEquals(Optional.empty(), get("ThreadOnly", context)); + } + + @Test + public void modalGetterOverloadsSelectTheRequestedMode() throws Exception { + var context = (ComponentImplementation) classifier("Populated.i"); + var low = context.getOwnedModes().getFirst(); + var high = context.getOwnedModes().getLast(); + var direct = getters.getMethod("getModeCount", NamedElement.class, Mode.class); + var optional = getters.getMethod("getModeCount", NamedElement.class, Optional.class); + assertEquals(OptionalLong.of(10), direct.invoke(null, context, low)); + assertEquals(OptionalLong.of(20), direct.invoke(null, context, high)); + assertEquals(OptionalLong.of(10), optional.invoke(null, context, Optional.of(low))); + assertEquals(OptionalLong.of(20), optional.invoke(null, context, Optional.of(high))); + } + + @Test + public void nestedListsAreUnmodifiableAndRangesPreserveTheirValues() throws Exception { + var context = classifier("Populated"); + var matrix = (List) ((Optional) get("Matrix", context)).orElseThrow(); + assertEquals(List.of(List.of(1L, 2L), List.of(), List.of(3L, 4L)), matrix); + assertThrows(UnsupportedOperationException.class, matrix::clear); + assertThrows(UnsupportedOperationException.class, ((List) matrix.getFirst())::clear); + assertThrows(UnsupportedOperationException.class, ((List) matrix.get(1))::clear); + var constant = (List) getters.getMethod("getMatrixConstant", EObject.class).invoke(null, context); + assertEquals(List.of(List.of(5L, 6L), List.of()), constant); + assertThrows(UnsupportedOperationException.class, constant::clear); + assertThrows(UnsupportedOperationException.class, ((List) constant.getFirst())::clear); + var range = (IntegerRange) ((Optional) get("Bounds", context)).orElseThrow(); + assertEquals(1L, range.getMinimum()); + assertEquals(9L, range.getMaximum()); + assertEquals(OptionalLong.of(2), range.getDelta()); + } + + @Test + public void importedEnumsAndUnitsResolveAndRoundTrip() throws Exception { + var context = classifier("Populated"); + var resourceSet = model.eResource().getResourceSet(); + var choice = (GeneratedEnumeration) ((Optional) get("Selection", context)).orElseThrow(); + assertEquals("green", choice.toString()); + assertEquals("GREEN", ((Enum) choice).name()); + var choiceClass = compiled.loadClass("generated.runtime.types.Choice"); + assertSame(choice, choiceClass.getMethod("valueOf", PropertyExpression.class) + .invoke(null, choice.toPropertyExpression(resourceSet))); + var duration = (IntegerWithUnits) ((Optional) get("Duration", context)).orElseThrow(); + assertEquals(2L, duration.getValue()); + var unitsClass = compiled.loadClass("generated.runtime.types.TimeUnits"); + var milliseconds = unitsClass.getField("MS").get(null); + var seconds = (GeneratedUnits) duration.getUnit(); + assertEquals(1000.0, seconds.getFactorToBase(), 0.0); + assertEquals(1000.0, (double) unitsClass.getMethod("getFactorTo", unitsClass).invoke(seconds, milliseconds), + 0.0); + assertSame(seconds, unitsClass.getMethod("valueOf", PropertyExpression.class) + .invoke(null, seconds.toPropertyExpression(resourceSet))); + var expression = duration.toPropertyExpression(resourceSet); + assertEquals(2L, expression.getValue()); + assertEquals("sec", expression.getUnit().getName()); + } + + @Test + public void recordsExtractFieldsAndRoundTripNestedValues() throws Exception { + var context = classifier("Populated"); + var record = (GeneratedRecord) ((Optional) get("Settings", context)).orElseThrow(); + var type = record.getClass(); + assertEquals(Optional.of(true), type.getMethod("getEnabled").invoke(record)); + assertEquals(OptionalLong.of(3), type.getMethod("getRetries").invoke(record)); + assertEquals(Optional.of(List.of("a", "b")), type.getMethod("getLabels").invoke(record)); + var labels = (List) ((Optional) type.getMethod("getLabels").invoke(record)).orElseThrow(); + assertThrows(UnsupportedOperationException.class, labels::clear); + var nested = ((Optional) type.getMethod("getNested").invoke(record)).orElseThrow(); + assertEquals(OptionalLong.of(8), nested.getClass().getMethod("getAmount").invoke(nested)); + var expression = record.toPropertyExpression(model.eResource().getResourceSet()); + assertEquals(5, expression.getOwnedFieldValues().size()); + var copy = type.getConstructor(PropertyExpression.class, NamedElement.class, Optional.class) + .newInstance(expression, context, Optional.empty()); + assertEquals(record, copy); + assertEquals(record.hashCode(), copy.hashCode()); + assertEquals(record.toString(), copy.toString()); + assertTrue(record.toString().contains("retries => 3;")); + assertFalse(record.equals(null)); + assertFalse(record.equals("not a record")); + var constant = getters.getMethod("getSettingsConstant", EObject.class).invoke(null, context); + assertEquals(Optional.of(false), type.getMethod("getEnabled").invoke(constant)); + assertEquals(OptionalLong.of(2), type.getMethod("getRetries").invoke(constant)); + assertEquals(Optional.empty(), type.getMethod("getNested").invoke(constant)); + assertNotEquals(record, constant); + } + + private Object get(String property, NamedElement context) throws Exception { + return getters.getMethod("get" + property, NamedElement.class).invoke(null, context); + } + + private NamedElement classifier(String name) { + return model.getOwnedPublicSection() + .getOwnedClassifiers() + .stream() + .filter(classifier -> classifier.getName().equalsIgnoreCase(name)) + .findFirst() + .orElseThrow(); + } +} diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerNoUnitsTest.java b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerNoUnitsTest.java new file mode 100644 index 00000000000..d37f7ada7f3 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerNoUnitsTest.java @@ -0,0 +1,370 @@ +/******************************************************************************* + * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). + * All Rights Reserved. + * + * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY + * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE + * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT + * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * SPDX-License-Identifier: EPL-2.0 + * + * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). + * + * This program includes and/or can make use of certain third party source code, object code, documentation and other + * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system + * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and + * conditions contained in any such Third Party Software or separate license file distributed with such Third Party + * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries + * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses + * only apply to the Third Party Software and not any other portion of this program or this program as a whole. + *******************************************************************************/ +package org.osate.propertiescodegen.tests; + +import static org.junit.Assert.assertEquals; +import static org.osate.propertiescodegen.tests.GeneratedJavaCompiler.generateAndCompile; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osate.aadl2.PropertySet; +import org.osate.testsupport.Aadl2InjectorProvider; +import org.osate.testsupport.TestHelper; + +import com.google.inject.Inject; + +/** Verifies exact generated Java for integer no units. */ +@RunWith(XtextRunner.class) +@InjectWith(Aadl2InjectorProvider.class) +public class IntegerNoUnitsTest { + @Inject + private TestHelper testHelper; + + @Test + public void testIntegerNoUnits() throws Exception { + var otherPs = """ + property set other_ps is + \tother_integer_no_units_type: type aadlinteger; + end other_ps; + """; + var integerNoUnitsTest = """ + property set integer_no_units_test is + \twith other_ps; + \t + \tlocal_integer_type: type aadlinteger; + \t + \towned_integer: aadlinteger applies to (all); + \treferenced_integer_local: integer_no_units_test::local_integer_type applies to (all); + \treferenced_integer_other: other_ps::other_integer_no_units_type applies to (all); + \t + \tlist_1_integer: list of other_ps::other_integer_no_units_type applies to (all); + \tlist_5_integer: list of list of list of list of list of other_ps::other_integer_no_units_type applies to (all); + \t + \tinteger_constant: constant aadlinteger => 1; + \t + \tlist_1_integer_constant: constant list of aadlinteger => (integer_no_units_test::integer_constant, 2); + \tlist_5_integer_constant: constant list of list of list of list of list of aadlinteger => (((( + \t\t(3, 4, 5), + \t\t() + \t)))); + end integer_no_units_test; + """; + var integerNoUnitsTestClass = """ + package integernounitstest; + + import java.util.List; + import java.util.Optional; + import java.util.OptionalLong; + + import org.eclipse.emf.ecore.EObject; + import org.osate.aadl2.Aadl2Package; + import org.osate.aadl2.IntegerLiteral; + import org.osate.aadl2.ListValue; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.Property; + import org.osate.aadl2.PropertyConstant; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; + import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + + public final class IntegerNoUnitsTest { + \tpublic static final String INTEGER_NO_UNITS_TEST__NAME = "integer_no_units_test"; + + \tprivate IntegerNoUnitsTest() {} + + \t// Lookup methods for integer_no_units_test::owned_integer + + \tpublic static final String OWNED_INTEGER__NAME = "owned_integer"; + + \tpublic static boolean acceptsOwnedInteger(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getOwnedInteger_Property(lookupContext)); + \t} + + \tpublic static OptionalLong getOwnedInteger(NamedElement lookupContext) { + \t\treturn getOwnedInteger(lookupContext, Optional.empty()); + \t} + + \tpublic static OptionalLong getOwnedInteger(NamedElement lookupContext, Mode mode) { + \t\treturn getOwnedInteger(lookupContext, Optional.of(mode)); + \t} + + \tpublic static OptionalLong getOwnedInteger(NamedElement lookupContext, Optional mode) { + \t\tvar property = getOwnedInteger_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn OptionalLong.of(((IntegerLiteral) resolved).getValue()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn OptionalLong.empty(); + \t\t} + \t} + + \tpublic static Property getOwnedInteger_Property(EObject lookupContext) { + \t\tvar name = INTEGER_NO_UNITS_TEST__NAME + "::" + OWNED_INTEGER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getOwnedInteger_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getOwnedInteger_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_no_units_test::referenced_integer_local + + \tpublic static final String REFERENCED_INTEGER_LOCAL__NAME = "referenced_integer_local"; + + \tpublic static boolean acceptsReferencedIntegerLocal(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getReferencedIntegerLocal_Property(lookupContext)); + \t} + + \tpublic static OptionalLong getReferencedIntegerLocal(NamedElement lookupContext) { + \t\treturn getReferencedIntegerLocal(lookupContext, Optional.empty()); + \t} + + \tpublic static OptionalLong getReferencedIntegerLocal(NamedElement lookupContext, Mode mode) { + \t\treturn getReferencedIntegerLocal(lookupContext, Optional.of(mode)); + \t} + + \tpublic static OptionalLong getReferencedIntegerLocal(NamedElement lookupContext, Optional mode) { + \t\tvar property = getReferencedIntegerLocal_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn OptionalLong.of(((IntegerLiteral) resolved).getValue()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn OptionalLong.empty(); + \t\t} + \t} + + \tpublic static Property getReferencedIntegerLocal_Property(EObject lookupContext) { + \t\tvar name = INTEGER_NO_UNITS_TEST__NAME + "::" + REFERENCED_INTEGER_LOCAL__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getReferencedIntegerLocal_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getReferencedIntegerLocal_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_no_units_test::referenced_integer_other + + \tpublic static final String REFERENCED_INTEGER_OTHER__NAME = "referenced_integer_other"; + + \tpublic static boolean acceptsReferencedIntegerOther(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getReferencedIntegerOther_Property(lookupContext)); + \t} + + \tpublic static OptionalLong getReferencedIntegerOther(NamedElement lookupContext) { + \t\treturn getReferencedIntegerOther(lookupContext, Optional.empty()); + \t} + + \tpublic static OptionalLong getReferencedIntegerOther(NamedElement lookupContext, Mode mode) { + \t\treturn getReferencedIntegerOther(lookupContext, Optional.of(mode)); + \t} + + \tpublic static OptionalLong getReferencedIntegerOther(NamedElement lookupContext, Optional mode) { + \t\tvar property = getReferencedIntegerOther_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn OptionalLong.of(((IntegerLiteral) resolved).getValue()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn OptionalLong.empty(); + \t\t} + \t} + + \tpublic static Property getReferencedIntegerOther_Property(EObject lookupContext) { + \t\tvar name = INTEGER_NO_UNITS_TEST__NAME + "::" + REFERENCED_INTEGER_OTHER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getReferencedIntegerOther_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getReferencedIntegerOther_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_no_units_test::list_1_integer + + \tpublic static final String LIST_1_INTEGER__NAME = "list_1_integer"; + + \tpublic static boolean acceptsList1Integer(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList1Integer_Property(lookupContext)); + \t} + + \tpublic static Optional> getList1Integer(NamedElement lookupContext) { + \t\treturn getList1Integer(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getList1Integer(NamedElement lookupContext, Mode mode) { + \t\treturn getList1Integer(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getList1Integer(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList1Integer_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn ((IntegerLiteral) resolved1).getValue(); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList1Integer_Property(EObject lookupContext) { + \t\tvar name = INTEGER_NO_UNITS_TEST__NAME + "::" + LIST_1_INTEGER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList1Integer_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList1Integer_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_no_units_test::list_5_integer + + \tpublic static final String LIST_5_INTEGER__NAME = "list_5_integer"; + + \tpublic static boolean acceptsList5Integer(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList5Integer_Property(lookupContext)); + \t} + + \tpublic static Optional>>>>> getList5Integer(NamedElement lookupContext) { + \t\treturn getList5Integer(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional>>>>> getList5Integer(NamedElement lookupContext, Mode mode) { + \t\treturn getList5Integer(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional>>>>> getList5Integer(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList5Integer_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); + \t\t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); + \t\t\t\t\t\treturn ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { + \t\t\t\t\t\t\tvar resolved4 = CodeGenUtil.resolveNamedValue(element4, lookupContext, mode); + \t\t\t\t\t\t\treturn ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { + \t\t\t\t\t\t\t\tvar resolved5 = CodeGenUtil.resolveNamedValue(element5, lookupContext, mode); + \t\t\t\t\t\t\t\treturn ((IntegerLiteral) resolved5).getValue(); + \t\t\t\t\t\t\t}).toList(); + \t\t\t\t\t\t}).toList(); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList5Integer_Property(EObject lookupContext) { + \t\tvar name = INTEGER_NO_UNITS_TEST__NAME + "::" + LIST_5_INTEGER__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList5Integer_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList5Integer_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_no_units_test::integer_constant + + \tpublic static final String INTEGER_CONSTANT__NAME = "integer_constant"; + + \tpublic static long getIntegerConstant(EObject lookupContext) { + \t\tvar constant = getIntegerConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((IntegerLiteral) resolved).getValue(); + \t} + + \tpublic static PropertyConstant getIntegerConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = INTEGER_NO_UNITS_TEST__NAME + "::" + INTEGER_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for integer_no_units_test::list_1_integer_constant + + \tpublic static final String LIST_1_INTEGER_CONSTANT__NAME = "list_1_integer_constant"; + + \tpublic static List getList1IntegerConstant(EObject lookupContext) { + \t\tvar constant = getList1IntegerConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn ((IntegerLiteral) resolved1).getValue(); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList1IntegerConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = INTEGER_NO_UNITS_TEST__NAME + "::" + LIST_1_INTEGER_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for integer_no_units_test::list_5_integer_constant + + \tpublic static final String LIST_5_INTEGER_CONSTANT__NAME = "list_5_integer_constant"; + + \tpublic static List>>>> getList5IntegerConstant(EObject lookupContext) { + \t\tvar constant = getList5IntegerConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1); + \t\t\treturn ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { + \t\t\t\tvar resolved2 = CodeGenUtil.resolveNamedValue(element2); + \t\t\t\treturn ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { + \t\t\t\t\tvar resolved3 = CodeGenUtil.resolveNamedValue(element3); + \t\t\t\t\treturn ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { + \t\t\t\t\t\tvar resolved4 = CodeGenUtil.resolveNamedValue(element4); + \t\t\t\t\t\treturn ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { + \t\t\t\t\t\t\tvar resolved5 = CodeGenUtil.resolveNamedValue(element5); + \t\t\t\t\t\t\treturn ((IntegerLiteral) resolved5).getValue(); + \t\t\t\t\t\t}).toList(); + \t\t\t\t\t}).toList(); + \t\t\t\t}).toList(); + \t\t\t}).toList(); + \t\t}).toList(); + \t} + + \tpublic static PropertyConstant getList5IntegerConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = INTEGER_NO_UNITS_TEST__NAME + "::" + LIST_5_INTEGER_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + } + """; + var results = generateAndCompile(testHelper.parseString(integerNoUnitsTest, otherPs)); + assertEquals("src-gen/integernounitstest", results.getPackagePath()); + assertEquals(1, results.getClasses().size()); + + assertEquals("IntegerNoUnitsTest.java", results.getClasses().getFirst().getFileName()); + assertEquals(integerNoUnitsTestClass, results.getClasses().getFirst().getContents()); + } +} diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerNoUnitsTest.xtend b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerNoUnitsTest.xtend deleted file mode 100644 index 71bc6a2ebd7..00000000000 --- a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerNoUnitsTest.xtend +++ /dev/null @@ -1,369 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). - * All Rights Reserved. - * - * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY - * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE - * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT - * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. - * - * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * SPDX-License-Identifier: EPL-2.0 - * - * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). - * - * This program includes and/or can make use of certain third party source code, object code, documentation and other - * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system - * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and - * conditions contained in any such Third Party Software or separate license file distributed with such Third Party - * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries - * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses - * only apply to the Third Party Software and not any other portion of this program or this program as a whole. - *******************************************************************************/ -package org.osate.propertiescodegen.tests - -import com.google.inject.Inject -import org.eclipse.xtext.testing.InjectWith -import org.eclipse.xtext.testing.XtextRunner -import org.junit.Test -import org.junit.runner.RunWith -import org.osate.aadl2.PropertySet -import org.osate.propertiescodegen.PropertiesCodeGen -import org.osate.testsupport.Aadl2InjectorProvider -import org.osate.testsupport.TestHelper - -import static org.junit.Assert.assertEquals - -@RunWith(XtextRunner) -@InjectWith(Aadl2InjectorProvider) -class IntegerNoUnitsTest { - @Inject - TestHelper testHelper - - @Test - def void testIntegerNoUnits() { - val otherPs = ''' - property set other_ps is - other_integer_no_units_type: type aadlinteger; - end other_ps; - ''' - val integerNoUnitsTest = ''' - property set integer_no_units_test is - with other_ps; - - local_integer_type: type aadlinteger; - - owned_integer: aadlinteger applies to (all); - referenced_integer_local: integer_no_units_test::local_integer_type applies to (all); - referenced_integer_other: other_ps::other_integer_no_units_type applies to (all); - - list_1_integer: list of other_ps::other_integer_no_units_type applies to (all); - list_5_integer: list of list of list of list of list of other_ps::other_integer_no_units_type applies to (all); - - integer_constant: constant aadlinteger => 1; - - list_1_integer_constant: constant list of aadlinteger => (integer_no_units_test::integer_constant, 2); - list_5_integer_constant: constant list of list of list of list of list of aadlinteger => (((( - (3, 4, 5), - () - )))); - end integer_no_units_test; - ''' - val integerNoUnitsTestClass = ''' - package integernounitstest; - - import java.util.List; - import java.util.Optional; - import java.util.OptionalLong; - import java.util.stream.Collectors; - - import org.eclipse.emf.ecore.EObject; - import org.osate.aadl2.Aadl2Package; - import org.osate.aadl2.IntegerLiteral; - import org.osate.aadl2.ListValue; - import org.osate.aadl2.Mode; - import org.osate.aadl2.NamedElement; - import org.osate.aadl2.Property; - import org.osate.aadl2.PropertyConstant; - import org.osate.aadl2.PropertyExpression; - import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; - import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; - import org.osate.aadl2.properties.PropertyNotPresentException; - import org.osate.pluginsupport.properties.CodeGenUtil; - - public final class IntegerNoUnitsTest { - public static final String INTEGER_NO_UNITS_TEST__NAME = "integer_no_units_test"; - - private IntegerNoUnitsTest() {} - - // Lookup methods for integer_no_units_test::owned_integer - - public static final String OWNED_INTEGER__NAME = "owned_integer"; - - public static boolean acceptsOwnedInteger(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getOwnedInteger_Property(lookupContext)); - } - - public static OptionalLong getOwnedInteger(NamedElement lookupContext) { - return getOwnedInteger(lookupContext, Optional.empty()); - } - - public static OptionalLong getOwnedInteger(NamedElement lookupContext, Mode mode) { - return getOwnedInteger(lookupContext, Optional.of(mode)); - } - - public static OptionalLong getOwnedInteger(NamedElement lookupContext, Optional mode) { - Property property = getOwnedInteger_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return OptionalLong.of(((IntegerLiteral) resolved).getValue()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return OptionalLong.empty(); - } - } - - public static Property getOwnedInteger_Property(EObject lookupContext) { - String name = INTEGER_NO_UNITS_TEST__NAME + "::" + OWNED_INTEGER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getOwnedInteger_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getOwnedInteger_Property(lookupContext)); - } - - // Lookup methods for integer_no_units_test::referenced_integer_local - - public static final String REFERENCED_INTEGER_LOCAL__NAME = "referenced_integer_local"; - - public static boolean acceptsReferencedIntegerLocal(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getReferencedIntegerLocal_Property(lookupContext)); - } - - public static OptionalLong getReferencedIntegerLocal(NamedElement lookupContext) { - return getReferencedIntegerLocal(lookupContext, Optional.empty()); - } - - public static OptionalLong getReferencedIntegerLocal(NamedElement lookupContext, Mode mode) { - return getReferencedIntegerLocal(lookupContext, Optional.of(mode)); - } - - public static OptionalLong getReferencedIntegerLocal(NamedElement lookupContext, Optional mode) { - Property property = getReferencedIntegerLocal_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return OptionalLong.of(((IntegerLiteral) resolved).getValue()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return OptionalLong.empty(); - } - } - - public static Property getReferencedIntegerLocal_Property(EObject lookupContext) { - String name = INTEGER_NO_UNITS_TEST__NAME + "::" + REFERENCED_INTEGER_LOCAL__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getReferencedIntegerLocal_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getReferencedIntegerLocal_Property(lookupContext)); - } - - // Lookup methods for integer_no_units_test::referenced_integer_other - - public static final String REFERENCED_INTEGER_OTHER__NAME = "referenced_integer_other"; - - public static boolean acceptsReferencedIntegerOther(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getReferencedIntegerOther_Property(lookupContext)); - } - - public static OptionalLong getReferencedIntegerOther(NamedElement lookupContext) { - return getReferencedIntegerOther(lookupContext, Optional.empty()); - } - - public static OptionalLong getReferencedIntegerOther(NamedElement lookupContext, Mode mode) { - return getReferencedIntegerOther(lookupContext, Optional.of(mode)); - } - - public static OptionalLong getReferencedIntegerOther(NamedElement lookupContext, Optional mode) { - Property property = getReferencedIntegerOther_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return OptionalLong.of(((IntegerLiteral) resolved).getValue()); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return OptionalLong.empty(); - } - } - - public static Property getReferencedIntegerOther_Property(EObject lookupContext) { - String name = INTEGER_NO_UNITS_TEST__NAME + "::" + REFERENCED_INTEGER_OTHER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getReferencedIntegerOther_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getReferencedIntegerOther_Property(lookupContext)); - } - - // Lookup methods for integer_no_units_test::list_1_integer - - public static final String LIST_1_INTEGER__NAME = "list_1_integer"; - - public static boolean acceptsList1Integer(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList1Integer_Property(lookupContext)); - } - - public static Optional> getList1Integer(NamedElement lookupContext) { - return getList1Integer(lookupContext, Optional.empty()); - } - - public static Optional> getList1Integer(NamedElement lookupContext, Mode mode) { - return getList1Integer(lookupContext, Optional.of(mode)); - } - - public static Optional> getList1Integer(NamedElement lookupContext, Optional mode) { - Property property = getList1Integer_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return ((IntegerLiteral) resolved1).getValue(); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList1Integer_Property(EObject lookupContext) { - String name = INTEGER_NO_UNITS_TEST__NAME + "::" + LIST_1_INTEGER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList1Integer_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList1Integer_Property(lookupContext)); - } - - // Lookup methods for integer_no_units_test::list_5_integer - - public static final String LIST_5_INTEGER__NAME = "list_5_integer"; - - public static boolean acceptsList5Integer(NamedElement lookupContext) { - return lookupContext.acceptsProperty(getList5Integer_Property(lookupContext)); - } - - public static Optional>>>>> getList5Integer(NamedElement lookupContext) { - return getList5Integer(lookupContext, Optional.empty()); - } - - public static Optional>>>>> getList5Integer(NamedElement lookupContext, Mode mode) { - return getList5Integer(lookupContext, Optional.of(mode)); - } - - public static Optional>>>>> getList5Integer(NamedElement lookupContext, Optional mode) { - Property property = getList5Integer_Property(lookupContext); - try { - PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); - return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2, lookupContext, mode); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3, lookupContext, mode); - return ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { - PropertyExpression resolved4 = CodeGenUtil.resolveNamedValue(element4, lookupContext, mode); - return ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { - PropertyExpression resolved5 = CodeGenUtil.resolveNamedValue(element5, lookupContext, mode); - return ((IntegerLiteral) resolved5).getValue(); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList())); - } catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { - return Optional.empty(); - } - } - - public static Property getList5Integer_Property(EObject lookupContext) { - String name = INTEGER_NO_UNITS_TEST__NAME + "::" + LIST_5_INTEGER__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); - } - - public static PropertyExpression getList5Integer_EObject(NamedElement lookupContext) { - return lookupContext.getNonModalPropertyValue(getList5Integer_Property(lookupContext)); - } - - // Lookup methods for integer_no_units_test::integer_constant - - public static final String INTEGER_CONSTANT__NAME = "integer_constant"; - - public static long getIntegerConstant(EObject lookupContext) { - PropertyConstant constant = getIntegerConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((IntegerLiteral) resolved).getValue(); - } - - public static PropertyConstant getIntegerConstant_PropertyConstant(EObject lookupContext) { - String name = INTEGER_NO_UNITS_TEST__NAME + "::" + INTEGER_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for integer_no_units_test::list_1_integer_constant - - public static final String LIST_1_INTEGER_CONSTANT__NAME = "list_1_integer_constant"; - - public static List getList1IntegerConstant(EObject lookupContext) { - PropertyConstant constant = getList1IntegerConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return ((IntegerLiteral) resolved1).getValue(); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList1IntegerConstant_PropertyConstant(EObject lookupContext) { - String name = INTEGER_NO_UNITS_TEST__NAME + "::" + LIST_1_INTEGER_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - - // Lookup methods for integer_no_units_test::list_5_integer_constant - - public static final String LIST_5_INTEGER_CONSTANT__NAME = "list_5_integer_constant"; - - public static List>>>> getList5IntegerConstant(EObject lookupContext) { - PropertyConstant constant = getList5IntegerConstant_PropertyConstant(lookupContext); - PropertyExpression resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); - return ((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { - PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1); - return ((ListValue) resolved1).getOwnedListElements().stream().map(element2 -> { - PropertyExpression resolved2 = CodeGenUtil.resolveNamedValue(element2); - return ((ListValue) resolved2).getOwnedListElements().stream().map(element3 -> { - PropertyExpression resolved3 = CodeGenUtil.resolveNamedValue(element3); - return ((ListValue) resolved3).getOwnedListElements().stream().map(element4 -> { - PropertyExpression resolved4 = CodeGenUtil.resolveNamedValue(element4); - return ((ListValue) resolved4).getOwnedListElements().stream().map(element5 -> { - PropertyExpression resolved5 = CodeGenUtil.resolveNamedValue(element5); - return ((IntegerLiteral) resolved5).getValue(); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - }).collect(Collectors.toList()); - } - - public static PropertyConstant getList5IntegerConstant_PropertyConstant(EObject lookupContext) { - String name = INTEGER_NO_UNITS_TEST__NAME + "::" + LIST_5_INTEGER_CONSTANT__NAME; - return Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); - } - } - ''' - val results = PropertiesCodeGen.generateJava(testHelper.parseString(integerNoUnitsTest, otherPs)) - assertEquals("src-gen/integernounitstest", results.packagePath) - assertEquals(1, results.classes.size) - - assertEquals("IntegerNoUnitsTest.java", results.classes.head.fileName) - assertEquals(integerNoUnitsTestClass.toString, results.classes.head.contents) - } -} \ No newline at end of file diff --git a/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerWithUnitsTest.java b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerWithUnitsTest.java new file mode 100644 index 00000000000..a7126368307 --- /dev/null +++ b/tools/org.osate.propertiescodegen.tests/src/org/osate/propertiescodegen/tests/IntegerWithUnitsTest.java @@ -0,0 +1,1668 @@ +/******************************************************************************* + * Copyright (c) 2004-2026 Carnegie Mellon University and others. (see Contributors file). + * All Rights Reserved. + * + * NO WARRANTY. ALL MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY + * KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE + * OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT + * MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + * + * This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * SPDX-License-Identifier: EPL-2.0 + * + * Created, in part, with funding and support from the United States Government. (see Acknowledgments file). + * + * This program includes and/or can make use of certain third party source code, object code, documentation and other + * files ("Third Party Software"). The Third Party Software that is used by this program is dependent upon your system + * configuration. By using this program, You agree to comply with any and all relevant Third Party Software terms and + * conditions contained in any such Third Party Software or separate license file distributed with such Third Party + * Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries + * to this license with respect to the terms applicable to their Third Party Software. Third Party Software licenses + * only apply to the Third Party Software and not any other portion of this program or this program as a whole. + *******************************************************************************/ +package org.osate.propertiescodegen.tests; + +import static org.junit.Assert.assertEquals; +import static org.osate.propertiescodegen.tests.GeneratedJavaCompiler.generateAndCompile; + +import org.eclipse.xtext.testing.InjectWith; +import org.eclipse.xtext.testing.XtextRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osate.aadl2.PropertySet; +import org.osate.testsupport.Aadl2InjectorProvider; +import org.osate.testsupport.TestHelper; + +import com.google.inject.Inject; + +/** Verifies exact generated Java for integer with units. */ +@RunWith(XtextRunner.class) +@InjectWith(Aadl2InjectorProvider.class) +public class IntegerWithUnitsTest { + @Inject + private TestHelper testHelper; + + @Test + public void testIntegerWithUnits() throws Exception { + var otherPs = """ + property set other_ps is + \tmass: type units (g, kg => g * 1000); + end other_ps; + """; + var integerWithUnitsTest = """ + property set integer_with_units_test is + \twith other_ps; + \t + \ttime: type units (sec, min => sec * 60, hr => min * 60, day => hr * 24); + \t + \towned: aadlinteger units (B, KiB => B * 1024) applies to (all); + \tsame_file: aadlinteger units integer_with_units_test::time applies to (all); + \tother_file: aadlinteger units other_ps::mass applies to (all); + \t + \tlist_1_owned: list of aadlinteger units (mg, g => mg * 1000) applies to (all); + \tlist_1_same_file: list of aadlinteger units integer_with_units_test::time applies to (all); + \tlist_1_other_file: list of aadlinteger units other_ps::mass applies to (all); + \t + \trecord_property: record ( + \t\towned: aadlinteger units (hour, day => hour * 24); + \t\tsame_file: aadlinteger units integer_with_units_test::time; + \t\tother_file: aadlinteger units other_ps::mass; + \t\t + \t\tlist_1_owned: list of aadlinteger units (ml, l => ml * 1000); + \t\tlist_1_same_file: list of aadlinteger units integer_with_units_test::time; + \t\tlist_1_other_file: list of aadlinteger units other_ps::mass; + \t) applies to (all); + \t + \towned_constant: constant aadlinteger units (B, KiB => B * 1024) => 1 B; + \tsame_file_constant: constant aadlinteger units integer_with_units_test::time => 2 sec; + \tother_file_constant: constant aadlinteger units other_ps::mass => 3 g; + \t + \tlist_1_owned_constant: constant list of aadlinteger units (mg, g => mg * 1000) => (4 mg, 5 g); + \tlist_1_same_file_constant: constant list of aadlinteger units integer_with_units_test::time => (6 sec, 7 min); + \tlist_1_other_file_constant: constant list of aadlinteger units other_ps::mass => (8 g, 9 kg); + \t + \trecord_constant: constant record ( + \t\towned: aadlinteger units (hour, day => hour * 24); + \t\tsame_file: aadlinteger units integer_with_units_test::time; + \t\tother_file: aadlinteger units other_ps::mass; + \t\t + \t\tlist_1_owned: list of aadlinteger units (ml, l => ml * 1000); + \t\tlist_1_same_file: list of aadlinteger units integer_with_units_test::time; + \t\tlist_1_other_file: list of aadlinteger units other_ps::mass; + \t) => [ + \t\towned => 1 hour; + \t\tsame_file => 2 sec; + \t\tother_file => 3 g; + \t\t + \t\tlist_1_owned => (4 ml, 5 l); + \t\tlist_1_same_file => (6 sec, 7 min); + \t\tlist_1_other_file => (8 g, 9 kg); + \t]; + end integer_with_units_test; + """; + var integerWithUnitsTestClass = """ + package integerwithunitstest; + + import java.util.List; + import java.util.Optional; + + import org.eclipse.emf.ecore.EObject; + import org.osate.aadl2.Aadl2Package; + import org.osate.aadl2.ListValue; + import org.osate.aadl2.Mode; + import org.osate.aadl2.NamedElement; + import org.osate.aadl2.Property; + import org.osate.aadl2.PropertyConstant; + import org.osate.aadl2.PropertyExpression; + import org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil; + import org.osate.aadl2.properties.PropertyDoesNotApplyToHolderException; + import org.osate.aadl2.properties.PropertyNotPresentException; + import org.osate.pluginsupport.properties.CodeGenUtil; + import org.osate.pluginsupport.properties.IntegerWithUnits; + + import otherps.Mass; + + public final class IntegerWithUnitsTest { + \tpublic static final String INTEGER_WITH_UNITS_TEST__NAME = "integer_with_units_test"; + + \tprivate IntegerWithUnitsTest() {} + + \t// Lookup methods for integer_with_units_test::owned + + \tpublic static final String OWNED__NAME = "owned"; + + \tpublic static boolean acceptsOwned(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getOwned_Property(lookupContext)); + \t} + + \tpublic static Optional> getOwned(NamedElement lookupContext) { + \t\treturn getOwned(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getOwned(NamedElement lookupContext, Mode mode) { + \t\treturn getOwned(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getOwned(NamedElement lookupContext, Optional mode) { + \t\tvar property = getOwned_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new IntegerWithUnits<>(resolved, Owned.class)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getOwned_Property(EObject lookupContext) { + \t\tvar name = INTEGER_WITH_UNITS_TEST__NAME + "::" + OWNED__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getOwned_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getOwned_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_with_units_test::same_file + + \tpublic static final String SAME_FILE__NAME = "same_file"; + + \tpublic static boolean acceptsSameFile(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getSameFile_Property(lookupContext)); + \t} + + \tpublic static Optional> getSameFile(NamedElement lookupContext) { + \t\treturn getSameFile(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getSameFile(NamedElement lookupContext, Mode mode) { + \t\treturn getSameFile(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getSameFile(NamedElement lookupContext, Optional mode) { + \t\tvar property = getSameFile_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new IntegerWithUnits<>(resolved, Time.class)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getSameFile_Property(EObject lookupContext) { + \t\tvar name = INTEGER_WITH_UNITS_TEST__NAME + "::" + SAME_FILE__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getSameFile_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getSameFile_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_with_units_test::other_file + + \tpublic static final String OTHER_FILE__NAME = "other_file"; + + \tpublic static boolean acceptsOtherFile(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getOtherFile_Property(lookupContext)); + \t} + + \tpublic static Optional> getOtherFile(NamedElement lookupContext) { + \t\treturn getOtherFile(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional> getOtherFile(NamedElement lookupContext, Mode mode) { + \t\treturn getOtherFile(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional> getOtherFile(NamedElement lookupContext, Optional mode) { + \t\tvar property = getOtherFile_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new IntegerWithUnits<>(resolved, Mass.class)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getOtherFile_Property(EObject lookupContext) { + \t\tvar name = INTEGER_WITH_UNITS_TEST__NAME + "::" + OTHER_FILE__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getOtherFile_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getOtherFile_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_with_units_test::list_1_owned + + \tpublic static final String LIST_1_OWNED__NAME = "list_1_owned"; + + \tpublic static boolean acceptsList1Owned(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList1Owned_Property(lookupContext)); + \t} + + \tpublic static Optional>> getList1Owned(NamedElement lookupContext) { + \t\treturn getList1Owned(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional>> getList1Owned(NamedElement lookupContext, Mode mode) { + \t\treturn getList1Owned(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional>> getList1Owned(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList1Owned_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn new IntegerWithUnits<>(resolved1, List1Owned.class); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList1Owned_Property(EObject lookupContext) { + \t\tvar name = INTEGER_WITH_UNITS_TEST__NAME + "::" + LIST_1_OWNED__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList1Owned_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList1Owned_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_with_units_test::list_1_same_file + + \tpublic static final String LIST_1_SAME_FILE__NAME = "list_1_same_file"; + + \tpublic static boolean acceptsList1SameFile(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList1SameFile_Property(lookupContext)); + \t} + + \tpublic static Optional>> getList1SameFile(NamedElement lookupContext) { + \t\treturn getList1SameFile(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional>> getList1SameFile(NamedElement lookupContext, Mode mode) { + \t\treturn getList1SameFile(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional>> getList1SameFile(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList1SameFile_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn new IntegerWithUnits<>(resolved1, Time.class); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList1SameFile_Property(EObject lookupContext) { + \t\tvar name = INTEGER_WITH_UNITS_TEST__NAME + "::" + LIST_1_SAME_FILE__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList1SameFile_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList1SameFile_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_with_units_test::list_1_other_file + + \tpublic static final String LIST_1_OTHER_FILE__NAME = "list_1_other_file"; + + \tpublic static boolean acceptsList1OtherFile(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getList1OtherFile_Property(lookupContext)); + \t} + + \tpublic static Optional>> getList1OtherFile(NamedElement lookupContext) { + \t\treturn getList1OtherFile(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional>> getList1OtherFile(NamedElement lookupContext, Mode mode) { + \t\treturn getList1OtherFile(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional>> getList1OtherFile(NamedElement lookupContext, Optional mode) { + \t\tvar property = getList1OtherFile_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> { + \t\t\t\tvar resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode); + \t\t\t\treturn new IntegerWithUnits<>(resolved1, Mass.class); + \t\t\t}).toList()); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getList1OtherFile_Property(EObject lookupContext) { + \t\tvar name = INTEGER_WITH_UNITS_TEST__NAME + "::" + LIST_1_OTHER_FILE__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getList1OtherFile_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getList1OtherFile_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_with_units_test::record_property + + \tpublic static final String RECORD_PROPERTY__NAME = "record_property"; + + \tpublic static boolean acceptsRecordProperty(NamedElement lookupContext) { + \t\treturn lookupContext.acceptsProperty(getRecordProperty_Property(lookupContext)); + \t} + + \tpublic static Optional getRecordProperty(NamedElement lookupContext) { + \t\treturn getRecordProperty(lookupContext, Optional.empty()); + \t} + + \tpublic static Optional getRecordProperty(NamedElement lookupContext, Mode mode) { + \t\treturn getRecordProperty(lookupContext, Optional.of(mode)); + \t} + + \tpublic static Optional getRecordProperty(NamedElement lookupContext, Optional mode) { + \t\tvar property = getRecordProperty_Property(lookupContext); + \t\ttry { + \t\t\tvar value = CodeGenUtil.lookupProperty(property, lookupContext, mode); + \t\t\tvar resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode); + \t\t\treturn Optional.of(new RecordProperty(resolved, lookupContext, mode)); + \t\t} catch (PropertyNotPresentException | PropertyDoesNotApplyToHolderException e) { + \t\t\treturn Optional.empty(); + \t\t} + \t} + + \tpublic static Property getRecordProperty_Property(EObject lookupContext) { + \t\tvar name = INTEGER_WITH_UNITS_TEST__NAME + "::" + RECORD_PROPERTY__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getProperty(), name); + \t} + + \tpublic static PropertyExpression getRecordProperty_EObject(NamedElement lookupContext) { + \t\treturn lookupContext.getNonModalPropertyValue(getRecordProperty_Property(lookupContext)); + \t} + + \t// Lookup methods for integer_with_units_test::owned_constant + + \tpublic static final String OWNED_CONSTANT__NAME = "owned_constant"; + + \tpublic static IntegerWithUnits getOwnedConstant(EObject lookupContext) { + \t\tvar constant = getOwnedConstant_PropertyConstant(lookupContext); + \t\tvar resolved = CodeGenUtil.resolveNamedValue(constant.getConstantValue()); + \t\treturn new IntegerWithUnits<>(resolved, OwnedConstant.class); + \t} + + \tpublic static PropertyConstant getOwnedConstant_PropertyConstant(EObject lookupContext) { + \t\tvar name = INTEGER_WITH_UNITS_TEST__NAME + "::" + OWNED_CONSTANT__NAME; + \t\treturn Aadl2GlobalScopeUtil.get(lookupContext, Aadl2Package.eINSTANCE.getPropertyConstant(), name); + \t} + + \t// Lookup methods for integer_with_units_test::same_file_constant + + \tpublic static final String SAME_FILE_CONSTANT__NAME = "same_file_constant"; + + \tpublic static IntegerWithUnits