diff --git a/.gitignore b/.gitignore index 775fcc8d4..34d99ba2f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,9 +18,10 @@ xtend-gen/ # Maven target/ .mvn/wrapper/maven-wrapper.jar +*.polyglot.* # Custom EvaluationData *.DS_Store *.polyglot -*.pom.tycho \ No newline at end of file +*.pom.tycho diff --git a/bundles/tools.vitruv.applications.cbs.commonalities/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.cbs.commonalities/META-INF/MANIFEST.MF index 128067f70..cfcf9b9eb 100644 --- a/bundles/tools.vitruv.applications.cbs.commonalities/META-INF/MANIFEST.MF +++ b/bundles/tools.vitruv.applications.cbs.commonalities/META-INF/MANIFEST.MF @@ -16,7 +16,7 @@ Require-Bundle: tools.vitruv.framework.applications, org.eclipse.uml2.uml;visibility:=reexport, org.emftext.language.java;visibility:=reexport, edu.kit.ipd.sdq.activextendannotations, - tools.vitruv.applications.util.temporary, - edu.kit.ipd.sdq.commons.util.emf + edu.kit.ipd.sdq.commons.util.emf, + tools.vitruv.applications.cbs.testutils Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: tools.vitruv.applications.cbs.commonalities diff --git a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/JavaVisibilityHelper.xtend b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/JavaVisibilityHelper.xtend index 03b92c927..db74ef46b 100644 --- a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/JavaVisibilityHelper.xtend +++ b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/JavaVisibilityHelper.xtend @@ -14,7 +14,7 @@ import tools.vitruv.applications.cbs.commonalities.oo.Visibility import static com.google.common.base.Preconditions.* import static tools.vitruv.dsls.commonalities.runtime.helper.XtendAssertHelper.* -import static extension tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* +import static extension tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaModifierUtil.* /** * Helper class for the mapping between Java's visibility modifiers and diff --git a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaCompilationUnitNameOperator.xtend b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaCompilationUnitNameOperator.xtend index d9072daf4..119a044ad 100644 --- a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaCompilationUnitNameOperator.xtend +++ b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaCompilationUnitNameOperator.xtend @@ -1,7 +1,6 @@ package tools.vitruv.applications.cbs.commonalities.java.operators import org.apache.log4j.Logger -import org.emftext.language.java.JavaUniquePathConstructor import org.emftext.language.java.containers.CompilationUnit import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AbstractAttributeMappingOperator import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AttributeMappingOperator @@ -9,6 +8,7 @@ import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.Attri import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import static com.google.common.base.Preconditions.* +import org.emftext.language.java.JavaUniquePathConstructor // CompilationUnit name schema: '..java' @AttributeMappingOperator( diff --git a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaPackageCompilationUnitsOperator.xtend b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaPackageCompilationUnitsOperator.xtend index 3f2abebfa..2c98472be 100644 --- a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaPackageCompilationUnitsOperator.xtend +++ b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaPackageCompilationUnitsOperator.xtend @@ -2,21 +2,21 @@ package tools.vitruv.applications.cbs.commonalities.java.operators import org.apache.log4j.Logger import org.eclipse.emf.ecore.EObject -import org.emftext.language.java.JavaUniquePathConstructor import org.emftext.language.java.commons.NamespaceAwareElement import org.emftext.language.java.containers.CompilationUnit +import org.emftext.language.java.containers.ContainersPackage import org.emftext.language.java.containers.Package -import tools.vitruv.applications.util.temporary.java.JavaPersistenceHelper +import tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaPersistenceHelper import tools.vitruv.dsls.commonalities.runtime.operators.mapping.reference.AbstractReferenceMappingOperator import tools.vitruv.dsls.commonalities.runtime.operators.mapping.reference.ReferenceMappingOperator import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import static com.google.common.base.Preconditions.* import static tools.vitruv.dsls.commonalities.runtime.helper.XtendAssertHelper.* +import static extension tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaContainerAndClassifierUtil.* import static extension tools.vitruv.dsls.commonalities.runtime.helper.IntermediateModelHelper.* -import static extension tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil.* -import org.emftext.language.java.containers.ContainersPackage +import org.emftext.language.java.JavaUniquePathConstructor // TODO Some duplication with JavaSubPackagesOperator @ReferenceMappingOperator( @@ -50,6 +50,10 @@ class JavaPackageCompilationUnitsOperator extends AbstractReferenceMappingOperat logger.trace(''' Found compilation units in package '«package.packageString»': «package.compilationUnits»''') return package.compilationUnits } + + def Iterable compilationUnits(Package package1) { + package1.containedObjects.filter(CompilationUnit).toList + } override getContainer(EObject object) { val CompilationUnit compilationUnit = validateObject(object) diff --git a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaPackageResourcePathFromNameOperator.xtend b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaPackageResourcePathFromNameOperator.xtend index 4a43633c6..522fb681a 100644 --- a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaPackageResourcePathFromNameOperator.xtend +++ b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaPackageResourcePathFromNameOperator.xtend @@ -9,7 +9,7 @@ import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState import static com.google.common.base.Preconditions.* -import static extension tools.vitruv.applications.util.temporary.java.JavaPersistenceHelper.* +import static extension tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaPersistenceHelper.* import org.emftext.language.java.containers.ContainersPackage @AttributeMappingOperator( diff --git a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaSubPackagesOperator.xtend b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaSubPackagesOperator.xtend index 874d4f162..99763e179 100644 --- a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaSubPackagesOperator.xtend +++ b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaSubPackagesOperator.xtend @@ -7,7 +7,7 @@ import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.resource.ResourceSet import org.emftext.language.java.JavaUniquePathConstructor import org.emftext.language.java.containers.Package -import tools.vitruv.applications.util.temporary.java.JavaPersistenceHelper +import tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaPersistenceHelper import tools.vitruv.dsls.commonalities.runtime.operators.mapping.reference.AbstractReferenceMappingOperator import tools.vitruv.dsls.commonalities.runtime.operators.mapping.reference.ReferenceMappingOperator import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState @@ -20,7 +20,7 @@ import static tools.vitruv.dsls.commonalities.runtime.helper.XtendAssertHelper.* import static extension java.nio.file.Files.* import static extension tools.vitruv.dsls.commonalities.runtime.helper.IntermediateModelHelper.* -import static extension tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil.* +import static extension tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaContainerAndClassifierUtil.* import org.emftext.language.java.containers.ContainersPackage @ReferenceMappingOperator( diff --git a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaTypeReferenceOperator.xtend b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaTypeReferenceOperator.xtend index d75139c33..c545c9fdb 100644 --- a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaTypeReferenceOperator.xtend +++ b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaTypeReferenceOperator.xtend @@ -13,7 +13,7 @@ import org.emftext.language.java.types.TypesFactory import org.emftext.language.java.types.Void import tools.vitruv.applications.cbs.commonalities.domaincommon.CommonPrimitiveType import tools.vitruv.applications.cbs.commonalities.domaincommon.operators.AbstractTypeReferenceOperator -import tools.vitruv.applications.util.temporary.java.JavaModificationUtil +import tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaModificationUtil import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AttributeMappingOperator import tools.vitruv.dsls.commonalities.runtime.operators.mapping.attribute.AttributeType import tools.vitruv.dsls.reactions.runtime.state.ReactionExecutionState diff --git a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaVisibilityOperator.xtend b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaVisibilityOperator.xtend index ce81628b7..30a7af657 100644 --- a/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaVisibilityOperator.xtend +++ b/bundles/tools.vitruv.applications.cbs.commonalities/src/tools/vitruv/applications/cbs/commonalities/java/operators/JavaVisibilityOperator.xtend @@ -14,7 +14,7 @@ import static com.google.common.base.Preconditions.* import static tools.vitruv.dsls.commonalities.runtime.helper.XtendAssertHelper.* import static extension tools.vitruv.applications.cbs.commonalities.java.JavaVisibilityHelper.* -import static extension tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* +import static extension tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaModifierUtil.* @AttributeMappingOperator( name='javaVisibility', diff --git a/bundles/tools.vitruv.applications.cbs.testutils/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.cbs.testutils/META-INF/MANIFEST.MF index fa9cb7998..c241c42d5 100644 --- a/bundles/tools.vitruv.applications.cbs.testutils/META-INF/MANIFEST.MF +++ b/bundles/tools.vitruv.applications.cbs.testutils/META-INF/MANIFEST.MF @@ -26,7 +26,14 @@ Require-Bundle: tools.vitruv.testutils.vsum, org.hamcrest.core, org.opentest4j, tools.vitruv.framework.applications;visibility:=reexport, - tools.vitruv.applications.util.temporary + tools.vitruv.applications.util.temporary, + edu.kit.ipd.sdq.activextendannotations, + org.emftext.language.java.resource, + org.emftext.language.java, + org.apache.log4j, + edu.kit.ipd.sdq.commons.util.java, + edu.kit.ipd.sdq.commons.util.emf Export-Package: tools.vitruv.applications.cbs.testutils, tools.vitruv.applications.cbs.testutils.equivalencetest, - tools.vitruv.applications.cbs.testutils.junit + tools.vitruv.applications.cbs.testutils.junit, + tools.vitruv.applications.cbs.testutils.oldmetamodelutils diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JamoppLibraryHelper.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JamoppLibraryHelper.xtend new file mode 100644 index 000000000..948c37cc5 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JamoppLibraryHelper.xtend @@ -0,0 +1,73 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import org.emftext.language.java.JavaClasspath +import org.emftext.language.java.JavaClasspath.Initializer +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.common.util.URI +import static com.google.common.base.Preconditions.checkState +import java.nio.file.Path + +/** + * This helper class allows to load the Java standard library in JaMoPP also with + * Java versions 9 and above. + * In Java 9 the boot classpath was removed and the standard library is packaged + * differently, which is corrected by this patch. + */ +class JamoppLibraryHelper { + static String STANDARD_LIBRARY_FOLDER_IN_HOME = "/jmods/" + static String BASE_LIBRARY_NAME = "java.base" + + /** + * Registers the Java standard library. In case of Java 8 and below, this is the deployed standard library. + * In case of Java 9 and above, this is the "java.base" module. Further modules can be registered with + * the {@link #registerStdLibraryModule} method. + */ + static def void registerStdLib() { + val String javaVersion = System.getProperty("java.version") + + // Until Java 1.8 we can use the mechanism of JaMoPP + if (javaVersion.startsWith("1.")) { + JavaClasspath.get().registerStdLib(); + // From Java 9 on, we have to search for the Java base module instead of the rt.jar file. + // To do so, we disable automatic initialization of the standard library using the classpath + // (where library cannot be found in Java 9 and above) and manually load the base Java module + } else { + JavaClasspath.initializers.add(new Initializer() { + override initialize(Resource resource) {} + + override requiresLocalClasspath() { false } + + override requiresStdLib() { false } + }) + registerStdLibraryModule(BASE_LIBRARY_NAME) + } + } + + /** + * Registers the Java standard library module with the given name. + * This may only be called when using Java in version 9 or above. + * Otherwise, it will throw an {@link IllegalStateException}. + * @param name - the name of the module to register + */ + static def void registerStdLibraryModule(String name) { + val String javaVersion = System.getProperty("java.version"); + checkState(!javaVersion.startsWith("1."), "Modules can only be registered in Java version 9 and above") + + val modulePath = System.getProperty("java.home") + STANDARD_LIBRARY_FOLDER_IN_HOME + name + ".jmod" + val moduleUri = URI.createFileURI(modulePath) + // From java 9, the module files do not directly contain the classes in the package structure + // but are placed in the "classes" folder, so that prefix has to be removed. + JavaClasspath.get().registerClassifierJar(moduleUri, "classes/"); + } + + /** + * Registers the library placed at the given path to. The library must + * be an archive (like a ".jar" file) directly containing the package structure + * to be imported. + * @param pathToLibrary - the path to the library to register + */ + static def void registerLocalLibrary(Path pathToLibrary) { + JavaClasspath.get().registerClassifierJar(URI.createFileURI(pathToLibrary.toString), ""); + } + +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaContainerAndClassifierUtil.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaContainerAndClassifierUtil.xtend new file mode 100644 index 000000000..1f471d920 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaContainerAndClassifierUtil.xtend @@ -0,0 +1,351 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import edu.kit.ipd.sdq.activextendannotations.Utility +import java.io.File +import java.io.PrintWriter +import java.util.ArrayList +import java.util.Collections +import java.util.Iterator +import java.util.List +import org.emftext.language.java.classifiers.Class +import org.emftext.language.java.classifiers.Classifier +import org.emftext.language.java.classifiers.ClassifiersFactory +import org.emftext.language.java.classifiers.ConcreteClassifier +import org.emftext.language.java.classifiers.Enumeration +import org.emftext.language.java.classifiers.Interface +import org.emftext.language.java.commons.NamedElement +import org.emftext.language.java.containers.CompilationUnit +import org.emftext.language.java.containers.ContainersFactory +import org.emftext.language.java.containers.Package +import org.emftext.language.java.members.Constructor +import org.emftext.language.java.members.EnumConstant +import org.emftext.language.java.members.Field +import org.emftext.language.java.members.Member +import org.emftext.language.java.parameters.Parameter +import org.emftext.language.java.types.NamespaceClassifierReference +import org.emftext.language.java.types.TypeReference + +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaModifierUtil.* +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaTypeUtil.* +import java.util.Optional +import org.emftext.language.java.commons.NamespaceAwareElement +import static java.util.Collections.emptyList +import org.emftext.language.java.containers.ContainersPackage +import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util.URIUtil.isPathmap +import tools.vitruv.change.correspondence.view.EditableCorrespondenceModelView + +/** + * Class for java classifier, package and compilation unit util functions + * + * @author Fei + */ +@Utility +class JavaContainerAndClassifierUtil { + + /** + * Creates and return a new java class with the given name, visibility and modifiers + * The new class is not contained in a compilation unit. + * @param name the name of the class + * @param visibility the visibility of the class + * @param abstr if the class should be abstract + * @param fin if the class should be final + * @return the new class with the given attributes + */ + def static createJavaClass(String name, JavaVisibility visibility, boolean abstr, boolean fin) { + val jClass = ClassifiersFactory.eINSTANCE.createClass + setName(jClass, name) + setJavaVisibilityModifier(jClass, visibility) + setAbstract(jClass, abstr) + setFinal(jClass, fin) + return jClass + } + + /** + * Creates a new java package + * @param name the name of the new package + * @param containingPackage the super package of the new package or null if it is the default package + * @return the new package + */ + def static createJavaPackage(String name, Package containingPackage) { + val jPackage = ContainersFactory.eINSTANCE.createPackage + setName(jPackage, name) + jPackage.namespaces += getJavaPackageAsStringList(containingPackage) + return jPackage + } + + /** + * Creates a new java interface with the given name and list of super interfaces + * The created interface is not contained in a compilation unit. + * @param name the name of the interface + * @param superInterfaces the superinterfaces of the interface + * @return the new interface + */ + def static createJavaInterface(String name, List superInterfaces) { + val jInterface = ClassifiersFactory.eINSTANCE.createInterface + setName(jInterface, name) + jInterface.makePublic + if (!superInterfaces.nullOrEmpty) { + jInterface.extends.addAll(createNamespaceReferenceFromList(superInterfaces)) + } + return jInterface + } + + /** + * Creats a new java enum with the given properties + * The created Enum is not contained in a compilationunit. + * @param name the name of the enum + * @param visibility the visibility of the enum + * @param constantsList list of enum constants for the enum + * @return the new enum + */ + def static createJavaEnum(String name, JavaVisibility visibility, List constantsList) { + val jEnum = ClassifiersFactory.eINSTANCE.createEnumeration + setName(jEnum, name) + setJavaVisibilityModifier(jEnum, visibility) + addEnumConstantIfNotNull(jEnum, constantsList) + return jEnum + } + + /** + * Add constantList to the enum constants of the given jEnum if constantsList is not null or empty + * + */ + def static addEnumConstantIfNotNull(Enumeration jEnum, List constantsList) { + if (!constantsList.nullOrEmpty) { + jEnum.constants.addAll(constantsList) + } + } + + /** + * Creates a java compilation unit with the given naem + * The method automatically sets the .java FileExtension for the compilation unit name + * There are no classifiers in the compilation unit yet. + * @param nameWithoutFileExtension the name without .java file extension + * @return the new compilation unit + */ + def static createEmptyCompilationUnit(String nameWithoutFileExtension) { + val cu = ContainersFactory.eINSTANCE.createCompilationUnit + cu.name = nameWithoutFileExtension + ".java" + return cu + } + + def static createJavaCompilationUnitWithClassifierInPackage(ConcreteClassifier jClassifier, Package jPackage) { + val compUnit = createEmptyCompilationUnit(jClassifier.name) + compUnit.classifiers += jClassifier + compUnit.namespaces.addAll(getJavaPackageAsStringList(jPackage)) + return compUnit + } + + /** + * Removes all classifiers of the iterator which has the same name as the given classifier classif + * @param iter iterator of typreferences + * @param classif classifier that should be removed from the iterator + */ + def static removeClassifierFromIterator(Iterator iter, ConcreteClassifier classif) { + while (iter.hasNext) { + val type = (iter.next as NamespaceClassifierReference).classifierReferences.head.target + if (classif.name.equals(type.name)) { + iter.remove + } + } + } + + /** + * For org.example.package it will return [org, example, package] + * Returns empty list if jPackage is the default package. + */ + def static getJavaPackageAsStringList(Package jPackage) { + if (jPackage === null || jPackage.name.nullOrEmpty) { // Defaultpackage + return Collections.emptyList() + } + val packageStringList = new ArrayList() + packageStringList.addAll(jPackage.namespaces) + packageStringList += jPackage.name + return packageStringList + } + + def static Field getJavaAttributeByName(Class jClass, String attributeName) { + val candidates = jClass.members.filter(Field) + for (member : candidates) { + if (member.name == attributeName) { + return member + } + } + return null + } + + def static Constructor getFirstJavaConstructor(Class jClass) { + val candidates = jClass.members.filter(Constructor) + if (!candidates.nullOrEmpty) { + return candidates.head + } else { + return null + } + } + + def static removeJavaClassifierFromPackage(Package jPackage, ConcreteClassifier jClassifier) { + val iter = jPackage.compilationUnits.iterator + while (iter.hasNext) { + if (iter.next.name.equals(jClassifier.name)) { + iter.remove + } + } + } + + def static File createPackageInfo(String directory, String packageName) { + val file = new File(directory + "/package-info.java") + file.createNewFile + val writer = new PrintWriter(file) + writer.println("package " + packageName + ";") + writer.close + return file + } + + /** + * Finds and retrieves a specific {@link ConcreteClassifier} that is contained in a {@link Package}. + * The {@link ConcreteClassifier} is found by name, ignoring the capitalization of the first letter. + * @param name is the name of the desired {@link ConcreteClassifier}, the first letter can be upper and lower case. + * @param javaPackage is the specific {@link Package} to search in. + * @param classifierType specifies the class of the desired {@link ConcreteClassifier}, e.g. {@link Interface}. + * @return the found classifier, or null if there is no matching classifer. + * @throws IllegalStateException if there are multiple classifers in the package with a matching name. + */ + static def T findClassifier(String name, Package javaPackage, + java.lang.Class classifierType) { + val matchingClassifiers = javaPackage.compilationUnits.map[it.classifiers].flatten.filter(classifierType).filter [ + it.name.toFirstUpper == name.toFirstUpper + ] + if (matchingClassifiers.size > 1) + throw new IllegalStateException("Multiple matching classifers were found: " + matchingClassifiers) + return matchingClassifiers.head + } + + def static Package getContainingPackageFromCorrespondenceModel(Classifier classifier, + EditableCorrespondenceModelView correspondenceModel) { + var namespace = classifier.containingCompilationUnit.namespacesAsString + if (namespace.endsWith("$") || namespace.endsWith(".")) { + namespace = namespace.substring(0, namespace.length - 1) + } + val finalNamespace = namespace + var Iterable packagesWithCorrespondences = correspondenceModel.getCorrespondingEObjects( + ContainersPackage.Literals.PACKAGE).filter(Package) + val packagesWithNamespace = packagesWithCorrespondences.filter [ pack | + finalNamespace.equals(pack.namespacesAsString + pack.name) + ] + if (null !== packagesWithNamespace && 0 < packagesWithNamespace.size && + null !== packagesWithNamespace.iterator.next) { + return packagesWithNamespace.iterator.next + } + return null + } + + /** + * Returns the namespace of the compilation unit where the given object is directly or indirectly contained + */ + def static dispatch List getJavaNamespace(CompilationUnit compUnit) { + return compUnit.namespaces + } + + def static dispatch List getJavaNamespace(ConcreteClassifier classifier) { + return getJavaNamespace(classifier.eContainer as CompilationUnit) + } + + def static dispatch List getJavaNamespace(NamedElement element) { + throw new IllegalArgumentException("Unsupported type for retrieving namespace: " + element) + } + + def static dispatch List getJavaNamespace(Void element) { + throw new IllegalArgumentException("Can not retrieve namespace for " + element) + } + + def static dispatch CompilationUnit getContainingCompilationUnit(ConcreteClassifier classifier) { + return classifier.eContainer as CompilationUnit + } + + def static dispatch CompilationUnit getContainingCompilationUnit(Member mem) { + return getContainingCompilationUnit(mem.eContainer as ConcreteClassifier) + } + + def static dispatch CompilationUnit getContainingCompilationUnit(Parameter param) { + return getContainingCompilationUnit(param.eContainer as Member) + } + + def static dispatch CompilationUnit getContainingCompilationUnit(NamedElement element) { + throw new IllegalArgumentException("Unsupported type for retrieving compilation unit: " + element) + } + + def static dispatch CompilationUnit getContainingCompilationUnit(Void element) { + throw new IllegalArgumentException("Can not retrieve compilation unit for " + element) + } + + def static String getRootPackageName(String packageName) { // TODO TS technically not depending on Java domain + return packageName?.split("\\.")?.get(0) + } + + def static String getLastPackageName(String packageName) { // TODO TS technically not depending on Java domain + return packageName?.substring(packageName.indexOf('.') + 1) + } + + private def static String getCompilationUnitName(String namespacesAsString, String classifierName) { + namespacesAsString + classifierName + ".java" + } + + def static String getCompilationUnitName(Package containingPackage, String className) { + getCompilationUnitName('''«IF containingPackage !== null»«containingPackage.namespacesAsString»«containingPackage.name».«ENDIF»''', + className) + } + + def static String getCompilationUnitName(Optional containingPackage, String className) { + getCompilationUnitName(if(containingPackage.present) containingPackage.get else null, className) + } + + def static boolean updateNamespaces(NamespaceAwareElement elementToChange, List newNamespaces) { + if (newNamespaces != elementToChange.namespaces) { + elementToChange.namespaces.clear + elementToChange.namespaces += newNamespaces + return true + } + return false + } + + def static boolean updateNamespaces(NamespaceAwareElement elementToChange, Optional containingPackage) { + if (containingPackage.present) { + elementToChange.updateNamespaces(containingPackage.get) + } else { + elementToChange.updateNamespaces(emptyList) + } + } + + def static boolean updateNamespaces(NamespaceAwareElement elementToChange, Package containingPackage) { + return elementToChange.updateNamespaces(containingPackage.javaPackageAsStringList) + } + + def static boolean updateName(NamedElement elementToChange, String newName) { + if (newName != elementToChange.name) { + elementToChange.name = newName + return true + } + return false + } + + def static void updateCompilationUnitName(CompilationUnit compilationUnit, String simpleName) { + compilationUnit.name = getCompilationUnitName(compilationUnit.namespaces.join("", ".", ".", [it]), simpleName) + } + + /** + * Updates the classifier name together with the name of its compilation unit. + */ + def static void changeNameWithCompilationUnit(Classifier classifier, String newName) { + classifier.updateName(newName) + classifier.containingCompilationUnit?.updateCompilationUnitName(newName) + } + + def static boolean isInExistingLibrary(CompilationUnit compilationUnit) { + compilationUnit.eResource.URI.isPathmap + } + + def static boolean isInExistingLibrary(Classifier classifier) { + classifier.containingCompilationUnit.isInExistingLibrary + } + +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaMemberAndParameterUtil.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaMemberAndParameterUtil.xtend new file mode 100644 index 000000000..aa7768b34 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaMemberAndParameterUtil.xtend @@ -0,0 +1,479 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import edu.kit.ipd.sdq.activextendannotations.Utility +import java.util.ArrayList +import java.util.Collections +import java.util.Comparator +import java.util.List +import org.apache.log4j.Logger +import org.eclipse.emf.common.util.ECollections +import org.eclipse.emf.common.util.EList +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.util.EcoreUtil +import org.emftext.language.java.classifiers.Class +import org.emftext.language.java.classifiers.ConcreteClassifier +import org.emftext.language.java.expressions.AssignmentExpression +import org.emftext.language.java.expressions.ExpressionsFactory +import org.emftext.language.java.literals.LiteralsFactory +import org.emftext.language.java.members.ClassMethod +import org.emftext.language.java.members.Constructor +import org.emftext.language.java.members.EnumConstant +import org.emftext.language.java.members.Field +import org.emftext.language.java.members.MembersFactory +import org.emftext.language.java.members.Method +import org.emftext.language.java.modifiers.Modifier +import org.emftext.language.java.modifiers.ModifiersFactory +import org.emftext.language.java.modifiers.Public +import org.emftext.language.java.operators.OperatorsFactory +import org.emftext.language.java.parameters.Parameter +import org.emftext.language.java.parameters.ParametersFactory +import org.emftext.language.java.parameters.Parametrizable +import org.emftext.language.java.references.ReferencesFactory +import org.emftext.language.java.statements.ExpressionStatement +import org.emftext.language.java.statements.Return +import org.emftext.language.java.statements.StatementsFactory +import org.emftext.language.java.types.TypeReference +import org.emftext.language.java.types.TypesFactory + +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaModifierUtil.* +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaStatementUtil.* +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaTypeUtil.* +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaModificationUtil.* + +/** + * A util class for field, method and parameter related util functions. + * + * @author Fei + */ +@Utility +class JavaMemberAndParameterUtil { + static val logger = Logger.getLogger(JavaMemberAndParameterUtil.simpleName) + + /** + * @return public Operation with name no return, params or modifier + */ + def static createSimpleJavaOperation(String name) { + return createJavaClassMethod(name, null, JavaVisibility.PUBLIC, false, false, null) + } + + /** + * Creates a new java class method with the given properties. + * The class method is not contained in any classifiers. + * + * @param name the name of the class method + * @param returnType the return type of the class method + * @param visibility the visibility of the class method + * @param abstr if the class method should be abstract + * @param stat if the class method should be static + * @param params list of parameters for the class method + * @return the new class method + */ + def static createJavaClassMethod(String name, TypeReference returnType, JavaVisibility visibility, boolean abstr, boolean stat, List params) { + val jMethod = MembersFactory.eINSTANCE.createClassMethod + setName(jMethod, name) + setTypeReference(jMethod, returnType) + setJavaVisibilityModifier(jMethod, visibility) + setAbstract(jMethod, abstr) + setStatic(jMethod, stat) + addParametersIfNotNull(jMethod, params) + return jMethod + } + + /** + * Creates a new java interface method with the given properties. + * The interface method is not contained in any classifiers. + * The visibility of the interface method is set to public. + * + * @param name the name of the interface method + * @param returnType return type of the interface method + * @param params list of parameters for the interface method + * @return the new interface method + */ + def static createJavaInterfaceMethod(String name, TypeReference returnType, List params) { + val jMethod = MembersFactory.eINSTANCE.createInterfaceMethod + setName(jMethod, name) + setTypeReference(jMethod, returnType) + jMethod.makePublic + addParametersIfNotNull(jMethod, params) + return jMethod + } + + /** + * Creates a new java attribute with the given properties. + * The attribute is not contained in any classifiers. + * + * @param name the name of attribute + * @param visibility the visibility of the attribute + * @param fin if the attribute should be final + * @param stat if the attribute should be static + * @return the new attribute + */ + def static createJavaAttribute(String name, TypeReference type, JavaVisibility visibility, boolean fin, boolean stat) { + val jAttribute = MembersFactory.eINSTANCE.createField + setName(jAttribute, name) + setJavaVisibilityModifier(jAttribute, visibility) + setFinal(jAttribute, fin) + setStatic(jAttribute, stat) + setTypeReference(jAttribute, type) + return jAttribute + } + + def static createJavaParameter(String name, TypeReference type) { + val param = ParametersFactory.eINSTANCE.createOrdinaryParameter + param.name = name + param.typeReference = type + return param + } + + def static createJavaEnumConstant(String name) { + val constant = MembersFactory.eINSTANCE.createEnumConstant + constant.name = name + return constant + } + + def static List createJavaEnumConstantsFromList(List enumConstantNames) { + val enumConstantList = new ArrayList + for (name : enumConstantNames) { + enumConstantList += createJavaEnumConstant(name) + } + return enumConstantList + } + + /** + * Creates a getter for the attribute and adds it t its class. + * @param jAttribute the attribute for which a getter should be created + */ + def static createGetterForAttribute(Field jAttribute) { + createJavaGetterForAttribute(jAttribute, JavaVisibility.PUBLIC) + } + + /** + * Creates a setter for the attribute and adds it to its class. + * @param jAttribute the attribute for which a getter should be created + */ + def static createSetterForAttribute(Field jAttribute) { + createJavaSetterForAttribute(jAttribute, JavaVisibility.PUBLIC) + } + + /** + * Creates and adds a constructor to the given class + */ + def static Constructor addJavaConstructorToClass(Class jClass, JavaVisibility visibility, List params) { + val constructor = MembersFactory.eINSTANCE.createConstructor + setName(constructor, jClass.name) + addParametersIfNotNull(constructor, params) + setJavaVisibilityModifier(constructor, visibility) + jClass.members += constructor + + return constructor + } + + /** + * Creates a constructor with the given visibility and adds it to the given class. + * + * @param jClass the class for which the constructor should be created + * @param visibility the visibility of the constructor + * @return the new constructor + */ + def static createJavaConstructorAndAddToClass(Class jClass, JavaVisibility visibility) { + val constructor = MembersFactory.eINSTANCE.createConstructor + constructor.name = jClass.name + setJavaVisibilityModifier(constructor, visibility) + jClass.members += constructor + return constructor + } + + def static Constructor getOrCreateConstructorToClass(Class javaClass) { + val constructors = javaClass.members.filter[it instanceof Constructor].map[it as Constructor] + if (constructors.nullOrEmpty) { + val Constructor constructor = MembersFactory.eINSTANCE.createConstructor + return addConstructorToClass(constructor, javaClass) + } + return constructors.iterator.next + } + + /** + * @param visibility Visibility of the Getter + */ + def static ClassMethod createJavaGetterForAttribute(Field jAttribute, JavaVisibility visibility) { + val getterMethod = createJavaClassMethod(buildGetterName(jAttribute.name), EcoreUtil.copy(jAttribute.typeReference), visibility, false, false, null) + getterMethod.statements += createReturnStatement(createSelfReferenceToAttribute(jAttribute)) + return getterMethod + } + + /** + * @param visibility Visibility of the Setter + */ + def static createJavaSetterForAttribute(Field jAttribute, JavaVisibility visibility) { + val param = createJavaParameter(jAttribute.name.toFirstLower, EcoreUtil.copy(jAttribute.typeReference)) + val setterMethod = createJavaClassMethod(buildSetterName(jAttribute.name), null, visibility, false, false, #[param]) + val paramReference = createIdentifierReference(param) + val attributeAssignment = createAssignmentExpression(createSelfReferenceToAttribute(jAttribute), OperatorsFactory.eINSTANCE.createAssignment, + EcoreUtil.copy(paramReference)) + setterMethod.statements += wrapExpressionInExpressionStatement(attributeAssignment) + return setterMethod + } + + def static createSetter(Field field, ClassMethod method) { + method.name = "set" + field.name.toFirstUpper + method.annotationsAndModifiers.add(ModifiersFactory.eINSTANCE.createPublic) + method.typeReference = TypesFactory.eINSTANCE.createVoid + val parameter = ParametersFactory.eINSTANCE.createOrdinaryParameter + parameter.name = field.name + parameter.typeReference = EcoreUtil.copy(field.typeReference) + method.parameters.add(parameter) + val expressionStatement = StatementsFactory.eINSTANCE.createExpressionStatement + val assigmentExpression = ExpressionsFactory.eINSTANCE.createAssignmentExpression + + // this. + val selfReference = ReferencesFactory.eINSTANCE.createSelfReference + assigmentExpression.child = selfReference + + // .fieldname + val fieldReference = ReferencesFactory.eINSTANCE.createIdentifierReference + fieldReference.target = field + selfReference.next = fieldReference + selfReference.^self = LiteralsFactory.eINSTANCE.createThis() + // = + assigmentExpression.assignmentOperator = OperatorsFactory.eINSTANCE.createAssignment + + // name + val identifierReference = ReferencesFactory.eINSTANCE.createIdentifierReference + identifierReference.target = parameter + + assigmentExpression.value = identifierReference + expressionStatement.expression = assigmentExpression + method.statements.add(expressionStatement) + return method + } + + def static createGetter(Field field, ClassMethod method) { + method.name = "get" + field.name.toFirstUpper + method.annotationsAndModifiers.add(ModifiersFactory.eINSTANCE.createPublic) + method.typeReference = EcoreUtil.copy(field.typeReference) + + // this.fieldname + val identifierRef = ReferencesFactory.eINSTANCE.createIdentifierReference + identifierRef.target = field + + // return + val ret = StatementsFactory.eINSTANCE.createReturn + ret.returnValue = identifierRef + method.statements.add(ret) + return method + } + + def static addParametersIfNotNull(Parametrizable parametrizable, List params) { + if (!params.nullOrEmpty) { + parametrizable.parameters.addAll(params) + } + } + + /** + * Checks if a Java-Method is Getter for a given Java-Attribute by name. + * Returns true if the name is "getAttributeName" + */ + def static boolean javaGetterForAttributeExists(Field jAttribute) { + val possibleGetters = getJavaGettersOfAttribute(jAttribute) + if (!possibleGetters.nullOrEmpty) { + return true + } + return false + } + + /** + * Checks if a Java-Method is Setter for a given Java-Attribute by name. + * Returns true if the name is "setAttributeName" + */ + def static boolean javaSetterForAttributeExists(Field jAttribute) { + val possibleSetters = getJavaSettersOfAttribute(jAttribute) + if (!possibleSetters.nullOrEmpty) { + return true + } + return false + } + + /** + * Returns the the methods with the name getAttributeName + */ + def static List getJavaGettersOfAttribute(Field jAttribute) { + if (jAttribute === null) { + logger.warn("Cannot retrieve Getters for Java-Attribute null. Returning empty List.") + return Collections.emptyList + } + return getJavaGettersOfAttribute(jAttribute.containingConcreteClassifier, jAttribute.name) + } + + /** + * Returns the the methods with the name setAttributeName + */ + def static List getJavaSettersOfAttribute(Field jAttribute) { + if (jAttribute === null) { + logger.warn("Cannot retrieve Setters for Java-Attribute null. Returning empty List.") + return Collections.emptyList + } + return getJavaSettersOfAttribute(jAttribute.containingConcreteClassifier, jAttribute.name) + } + + def static List getJavaClassMethodsWithName(ConcreteClassifier jClass, String name) { + if (jClass === null) { + return Collections.emptyList + } + return jClass.members.filter(ClassMethod).filter[it.name.equals(name)].toList + } + + def static List getJavaSettersOfAttribute(ConcreteClassifier jClass, String jAttributeName) { + return getJavaClassMethodsWithName(jClass, buildSetterName(jAttributeName)) + } + + def static List getJavaGettersOfAttribute(ConcreteClassifier jClass, String jAttributeName) { + return getJavaClassMethodsWithName(jClass, buildGetterName(jAttributeName)) + } + + /** + * Renames the given setter so that it matches the name of the given attribute + * @param oldName the name of jAttribute before it was renamed + */ + def static renameSetter(ClassMethod setter, Field jAttribute, String oldName) { + setter.name = buildSetterName(jAttribute.name) + setter.parameters.head?.setName(jAttribute.name.toFirstLower) + for (expStatement : setter.statements.filter(ExpressionStatement)) { + val selfReference = getAttributeSelfReferenceInExpressionStatement(expStatement, oldName) + selfReference?.setTarget(jAttribute) + } + } + + /** + * Assumption: Setter has one parameter and one assignment for the attribute + * + */ + def static updateAttributeTypeInSetter(ClassMethod setter, Field jAttribute) { + val param = setter.parameters.head + if (param !== null) { + param.typeReference = EcoreUtil.copy(jAttribute.typeReference) + val expStatement = setter.statements.filter(ExpressionStatement).head + if (expressionHasAttributeSelfReference(expStatement, jAttribute)) { + (expStatement.expression as AssignmentExpression).value = createIdentifierReference(param) + } + } + } + + /** + * Renames the given getter so that it matches the name of the given attribute + * Assumption: standard getter that only returns the attribute + */ + def static renameGetterOfAttribute(ClassMethod getter, Field jAttribute) { + getter.name = buildGetterName(jAttribute.name) + val returnStatement = getter.statements.filter(Return).head + if (returnStatement !== null) { + returnStatement.returnValue = createSelfReferenceToAttribute(jAttribute) + } + } + + /** + * Updates the return type of the given getter to match the return type of the given attribute. + */ + def static updateAttributeTypeInGetter(ClassMethod getter, Field jAttribute) { + getter.typeReference = EcoreUtil.copy(jAttribute.typeReference) + } + + def static String buildSetterName(String attributeName) { + return "set" + attributeName.toFirstUpper + } + + def static String buildGetterName(String attributeName) { + return "get" + attributeName.toFirstUpper + } + + /** + * Signatures are considered equal if methods have the same name, the same parameter types and the same return type + * We do not consider modifiers (e.g. public or private here) + */ + def static boolean hasSameSignature(Method method1, Method method2) { + if (method1 == method2) { + return true + } + if (!method1.name.equals(method2.name)) { + return false + } + if (!hasSameTargetReference(method1.typeReference, method2.typeReference)) { + return false + } + if (method1.parameters.size != method2.parameters.size) { + return false + } + var int i = 0 + for (param1 : method1.parameters) { + if (!hasSameTargetReference(param1.typeReference, method2.parameters.get(i).typeReference)) { + return false + } + i++ + } + return true + } + + def static initializeClassMethod(ClassMethod classMethod, Method implementedMethod, boolean ensurePublic) { + initializeClassMethod(classMethod, implementedMethod.name, implementedMethod.typeReference, implementedMethod.modifiers, implementedMethod.parameters, + ensurePublic) + } + + def static initializeClassMethod(ClassMethod classMethod, String name, TypeReference typeReference, Modifier[] modifiers, + Parameter[] parameters, boolean ensurePublic) { + classMethod.name = name + if (null !== typeReference) { + classMethod.typeReference = EcoreUtil.copy(typeReference) + } + if (null !== modifiers) { + classMethod.annotationsAndModifiers.addAll(EcoreUtil.copyAll(modifiers)) + } + if (ensurePublic) { + val alreadyPublic = classMethod.annotationsAndModifiers.filter[modifier|modifier instanceof Public].size > 0 + if (!alreadyPublic) { + classMethod.annotationsAndModifiers.add(ModifiersFactory.eINSTANCE.createPublic) + } + } + if (null !== parameters) { + classMethod.parameters.addAll(EcoreUtil.copyAll(parameters)) + } + } + + def static ClassMethod findMethodInClass(ConcreteClassifier concreteClassifier, ClassMethod method) { + for (Method currentMethod : concreteClassifier.methods) { + if (currentMethod instanceof ClassMethod && currentMethod.name.equals(method.name) && + currentMethod.typeParameters.size == method.typeParameters.size) { + // TODO finish check by comparing type reference and type of each parameter + return currentMethod as ClassMethod + } + } + return null + } + + /** + * sorts the member list to ensure that fields are printed before constructors and constructors before methods + */ + def static sortMembers(EList members) { + ECollections.sort(members, new Comparator { + + override compare(EObject o1, EObject o2) { + // fields before constructors and methods + if (o1 instanceof Field && (o2 instanceof Method || o2 instanceof Constructor)) { + return -1 + } else if ((o1 instanceof Method || o1 instanceof Constructor) && o2 instanceof Field) { + return 1 + + // constructors before Methods + } else if (o1 instanceof Constructor && o2 instanceof Method) { + return -1 + } else if (o1 instanceof Method && o2 instanceof Constructor) { + return 1 + } + return 0 + } + + override equals(Object obj) { + return this == obj + } + + }) + } +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaModificationUtil.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaModificationUtil.xtend new file mode 100644 index 000000000..76b647bed --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaModificationUtil.xtend @@ -0,0 +1,331 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import edu.kit.ipd.sdq.activextendannotations.Utility +import org.apache.log4j.Logger +import org.emftext.language.java.types.NamespaceClassifierReference +import org.emftext.language.java.types.TypesFactory +import org.emftext.language.java.parameters.Parameter +import org.emftext.language.java.types.TypeReference +import org.emftext.language.java.parameters.ParametersFactory +import org.emftext.language.java.statements.StatementsFactory +import org.emftext.language.java.expressions.ExpressionsFactory +import org.emftext.language.java.members.Field +import org.emftext.language.java.statements.Statement +import org.emftext.language.java.references.ReferencesFactory +import org.emftext.language.java.literals.LiteralsFactory +import org.emftext.language.java.operators.OperatorsFactory +import org.emftext.language.java.imports.Import +import org.emftext.language.java.classifiers.ConcreteClassifier +import org.emftext.language.java.classifiers.Classifier +import org.emftext.language.java.imports.ImportsFactory +import org.emftext.language.java.types.PrimitiveType +import org.emftext.language.java.types.Char +import org.emftext.language.java.types.Int +import org.eclipse.emf.ecore.util.EcoreUtil +import org.emftext.language.java.modifiers.ModifiersFactory +import org.emftext.language.java.imports.ClassifierImport +import org.emftext.language.java.JavaClasspath +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaQueryUtil.* +import org.emftext.language.java.modifiers.AnnotableAndModifiable +import org.emftext.language.java.annotations.AnnotationsFactory +import org.emftext.language.java.classifiers.ClassifiersFactory +import java.util.List +import org.emftext.language.java.members.Constructor +import org.emftext.language.java.classifiers.Class +import org.emftext.language.java.members.MembersFactory +import org.emftext.language.java.instantiations.NewConstructorCall +import org.emftext.language.java.references.IdentifierReference +import java.util.ArrayList +import org.emftext.language.java.references.ReferenceableElement + +@Utility +class JavaModificationUtil { + static val Logger logger = Logger.getLogger(JavaModificationUtil) + + def static Parameter createOrdinaryParameter(TypeReference typeReference, String name) { + val parameter = ParametersFactory.eINSTANCE.createOrdinaryParameter + parameter.name = name + parameter.typeReference = typeReference + return parameter + } + + def static Statement createAssignmentFromParameterToField(Field field, Parameter parameter) { + val expressionStatement = StatementsFactory.eINSTANCE.createExpressionStatement + val assigmentExpression = ExpressionsFactory.eINSTANCE.createAssignmentExpression + + // this. + val selfReference = ReferencesFactory.eINSTANCE.createSelfReference + selfReference.self = LiteralsFactory.eINSTANCE.createThis + assigmentExpression.child = selfReference + + // .fieldname + val fieldReference = ReferencesFactory.eINSTANCE.createIdentifierReference + fieldReference.target = field + selfReference.next = fieldReference + + // = + assigmentExpression.assignmentOperator = OperatorsFactory.eINSTANCE.createAssignment + + // name + val identifierReference = ReferencesFactory.eINSTANCE.createIdentifierReference + identifierReference.target = parameter + + assigmentExpression.value = identifierReference + expressionStatement.expression = assigmentExpression + return expressionStatement + } + + def static NamespaceClassifierReference createNamespaceClassifierReference(ConcreteClassifier concreteClassifier) { + val namespaceClassifierReference = TypesFactory.eINSTANCE.createNamespaceClassifierReference + createNamespaceClassifierReference(namespaceClassifierReference, concreteClassifier) + return namespaceClassifierReference + } + + def static Import addImportToCompilationUnitOfClassifier(Classifier classifier, + ConcreteClassifier classifierToImport) { + val classifierImport = ImportsFactory.eINSTANCE.createClassifierImport + if (null !== classifierToImport.containingCompilationUnit) { + if (null !== classifierToImport.containingCompilationUnit.namespaces) { + classifierImport.namespaces.addAll(classifierToImport.containingCompilationUnit.namespaces) + } + classifier.containingCompilationUnit.imports.add(classifierImport) + } + classifierImport.classifier = classifierToImport + return classifierImport + } + + def static createNamespaceClassifierReference(NamespaceClassifierReference namespaceClassifierReference, + ConcreteClassifier concreteClassifier) { + val classifierRef = TypesFactory.eINSTANCE.createClassifierReference + classifierRef.target = concreteClassifier + namespaceClassifierReference.classifierReferences.add(classifierRef) + if (concreteClassifier.containingCompilationUnit !== null) { + namespaceClassifierReference.namespaces += concreteClassifier.containingCompilationUnit.namespaces + } + else if (concreteClassifier.eIsProxy) { + //extract namespaces for java default types + val uri = EcoreUtil.getURI(concreteClassifier) + val prefix = "/javaclass/" + val suffix = concreteClassifier.name + JavaPersistenceHelper.FILE_EXTENSION_SEPARATOR + JavaPersistenceHelper.JAVA_FILE_EXTENSION + if (uri.path.startsWith(prefix) && uri.path.endsWith(suffix)) { + val namespaces = uri.path.substring(prefix.length, uri.path.length - suffix.length).split("\\.") + namespaceClassifierReference.namespaces += namespaces + } + } + } + + def static createPrivateField(Field field, TypeReference reference, String name) { + field.typeReference = EcoreUtil.copy(reference) + field.annotationsAndModifiers.add(ModifiersFactory.eINSTANCE.createPrivate) + var String fieldName = name + if (fieldName.nullOrEmpty) { + fieldName = "field_" + getNameFromJaMoPPType(reference) + } + field.name = fieldName + } + + /** + * returns the class object for a primitive type, e.g, Integer for int + */ + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(PrimitiveType type) { + logger.warn("no dispatch method found for type: " + type) + return null + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(Boolean type) { + createNamespaceClassifierReferenceForName("java.lang", "Boolean") + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(Byte type) { + createNamespaceClassifierReferenceForName("java.lang", "Byte") + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(Char type) { + createNamespaceClassifierReferenceForName("java.lang", "Character") + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(Double type) { + createNamespaceClassifierReferenceForName("java.lang", "Double") + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(Float type) { + createNamespaceClassifierReferenceForName("java.lang", "Float") + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(Int type) { + createNamespaceClassifierReferenceForName("java.lang", "Integer") + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(Long type) { + createNamespaceClassifierReferenceForName("java.lang", "Long") + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType(Short type) { + createNamespaceClassifierReferenceForName("java.lang", "Short") + } + + def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType( + org.emftext.language.java.types.Void type) { + createNamespaceClassifierReferenceForName("java.lang", "Void") + } + + /** + * Creates a Java-ClassifierImport from a qualified name + */ + def static ClassifierImport createJavaClassImport(String name) { + val classifier = getClassifier(name); + val classifierImport = ImportsFactory.eINSTANCE.createClassifierImport(); + classifierImport.classifier = classifier; + return classifierImport + } + + def static NamespaceClassifierReference createNamespaceClassifierReferenceForName(String namespace, + String name) { + val classifier = getClassifier(namespace + "." + name) + return createNamespaceClassifierReference(classifier) + } + + def static NamespaceClassifierReference createNamespaceClassifierReferenceForName(String qualifiedName) { + createNamespaceClassifierReference(getClassifier(qualifiedName)) + } + + def static ConcreteClassifier getClassifier(String qualifiedName) { + // To resolve classifiers from the Java standard library, this requires the Java standard library to be + // registered (JavaClasspath.get().registerStdLib). Should be done by the domain by default. + JavaClasspath.get().getClassifier(qualifiedName) as ConcreteClassifier + } + + def static addAnnotationToAnnotableAndModifiable(AnnotableAndModifiable annotableAndModifiable, + String annotationName) { + val newAnnotation = AnnotationsFactory.eINSTANCE.createAnnotationInstance() + val jaMoPPClass = ClassifiersFactory.eINSTANCE.createClass + jaMoPPClass.setName(annotationName); + newAnnotation.setAnnotation(jaMoPPClass) + annotableAndModifiable.getAnnotationsAndModifiers().add(newAnnotation) + } + + def static addImportToClassFromString(ConcreteClassifier jaMoPPClass, List namespaceArray, + String entityToImport) { + for (Import import : jaMoPPClass.containingCompilationUnit.imports) { + if ((import as ClassifierImport).classifier.name == entityToImport) { + return // Import has already been added (in the case of inject.Inject could be from javax.inject package) + } + } + val guiceImport = ImportsFactory.eINSTANCE.createClassifierImport + val ConcreteClassifier cl = ClassifiersFactory.eINSTANCE.createClass + cl.name = entityToImport + guiceImport.classifier = cl + guiceImport.namespaces.addAll(namespaceArray) + jaMoPPClass.containingCompilationUnit.imports.add(guiceImport) + } + + def static addConstructorToClass(Class javaClass) { + val Constructor constructor = MembersFactory.eINSTANCE.createConstructor + addConstructorToClass(constructor, javaClass) + } + + + def static addConstructorToClass(Constructor constructor, Class javaClass) { + constructor.name = javaClass.name + constructor.annotationsAndModifiers.add(ModifiersFactory.eINSTANCE.createPublic) + javaClass.members.add(constructor) + return constructor + } + + def static addImportToCompilationUnitOfClassifier(ClassifierImport classifierImport, Classifier classifier, + ConcreteClassifier classifierToImport) { + if (null !== classifierToImport.containingCompilationUnit) { + if (null !== classifierToImport.containingCompilationUnit.namespaces) { + classifierImport.namespaces.addAll(classifierToImport.containingCompilationUnit.namespaces) + } + classifier.containingCompilationUnit.imports.add(classifierImport) + } + classifierImport.classifier = classifierToImport + } + + def static createNewForFieldInConstructor(NewConstructorCall newConstructorCall, Constructor constructor, + Field field) { + val classifier = field.containingConcreteClassifier + if (!(classifier instanceof Class)) { + return null + } + val jaMoPPClass = classifier as Class + + addNewStatementToConstructor(newConstructorCall, constructor, field, jaMoPPClass.fields, constructor.parameters) + } + + def static addNewStatementToConstructor(NewConstructorCall newConstructorCall, Constructor constructor, Field field, + Field[] fieldsToUseAsArgument, Parameter[] parametersToUseAsArgument) { + val expressionStatement = StatementsFactory.eINSTANCE.createExpressionStatement + val assigmentExpression = ExpressionsFactory.eINSTANCE.createAssignmentExpression + + // this. + val selfReference = ReferencesFactory.eINSTANCE.createSelfReference + selfReference.self = LiteralsFactory.eINSTANCE.createThis + assigmentExpression.child = selfReference + + // .fieldname + val fieldReference = ReferencesFactory.eINSTANCE.createIdentifierReference + fieldReference.target = field + selfReference.next = EcoreUtil.copy(fieldReference) + + // = + assigmentExpression.assignmentOperator = OperatorsFactory.eINSTANCE.createAssignment + + // new fieldType + newConstructorCall.typeReference = EcoreUtil.copy(field.typeReference) + + // get order of type references of the constructor + updateArgumentsOfConstructorCall(field, fieldsToUseAsArgument, parametersToUseAsArgument, newConstructorCall) + + assigmentExpression.value = newConstructorCall + expressionStatement.expression = assigmentExpression + constructor.statements.add(expressionStatement) + } + + private def static updateArgumentsOfConstructorCall(Field field, Field[] fieldsToUseAsArgument, + Parameter[] parametersToUseAsArgument, NewConstructorCall newConstructorCall) { + val List typeListForConstructor = new ArrayList + if (null !== field.typeReference && null !== field.typeReference.pureClassifierReference && + null !== field.typeReference.pureClassifierReference.target) { + val classifier = field.typeReference.pureClassifierReference.target + if (classifier instanceof Class) { + val jaMoPPClass = classifier + val constructorsForClass = jaMoPPClass.members.filter(typeof(Constructor)) + if (!constructorsForClass.nullOrEmpty) { + val constructorForClass = constructorsForClass.get(0) + for (parameter : constructorForClass.parameters) { + typeListForConstructor.add(parameter.typeReference) + } + } + } + } + + // find type with same name in fields or parameters (start with parameter) + for (typeRef : typeListForConstructor) { + val refElement = typeRef.findMatchingTypeInParametersOrFields(fieldsToUseAsArgument, + parametersToUseAsArgument) + if (refElement !== null) { + val IdentifierReference identifierReference = ReferencesFactory.eINSTANCE.createIdentifierReference + identifierReference.target = refElement + } else { + newConstructorCall.arguments.add(LiteralsFactory.eINSTANCE.createNullLiteral) + } + } + } + + private def static ReferenceableElement findMatchingTypeInParametersOrFields(TypeReference typeReferenceToFind, + Field[] fieldsToUseAsArgument, Parameter[] parametersToUseAsArgument) { + for (parameter : parametersToUseAsArgument) { + if (parameter.typeReference.target == typeReferenceToFind.target) { + return parameter + } + } + for (field : fieldsToUseAsArgument) { + if (field.typeReference.target == typeReferenceToFind.target) { + return field + } + } + return null + } +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaModifierUtil.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaModifierUtil.xtend new file mode 100644 index 000000000..4dfa8e846 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaModifierUtil.xtend @@ -0,0 +1,276 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import edu.kit.ipd.sdq.activextendannotations.Utility +import org.apache.log4j.Logger +import org.eclipse.uml2.uml.VisibilityKind +import org.emftext.language.java.commons.NamedElement +import org.emftext.language.java.modifiers.AnnotableAndModifiable +import org.emftext.language.java.modifiers.Modifier +import org.emftext.language.java.modifiers.ModifiersFactory +import org.emftext.language.java.modifiers.Private +import org.emftext.language.java.modifiers.Protected +import org.emftext.language.java.modifiers.Public +import java.util.List +import org.emftext.language.java.modifiers.AnnotationInstanceOrModifier +import java.util.Objects +import tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaVisibility + +/** + * Util class for java modifiers and visibilities. + * + * @author Fei + */ +@Utility +class JavaModifierUtil { + + static val logger = Logger.getLogger(JavaModifierUtil.simpleName) + + static val List> JAVA_VISIBILITY_MODIFIER_TYPES = #[Public, Protected, Private] + + /** + * Checks if the given {@link Modifier} is a Java visibility modifier. + */ + static def boolean isVisibilityModifier(Modifier modifier) { + return JAVA_VISIBILITY_MODIFIER_TYPES.exists[isInstance(modifier)] + } + + /** + * Checks if the given {@link AnnotationInstanceOrModifier} is a Java + * visibility modifier. + */ + static def boolean isVisibilityModifier(AnnotationInstanceOrModifier modifier) { + return modifier instanceof Modifier && (modifier as Modifier).isVisibilityModifier + } + + /** + * Maps the given modifiers to an {@link Iterable} of their contained + * visibility modifiers. + */ + static def Iterable getVisibilityModifiers(Iterable modifiers) { + return modifiers.filter(Modifier).filter[isVisibilityModifier] + } + + /** + * Produces a list of String representations of the given modifiers. + *

+ * This may for example be useful for debug or exception messages. + */ + static def List getModifierNames(Iterable modifiers) { + return modifiers.map[it.class.name].toList + } + + /** + * Checks if the given modifiers are considered equal. + *

+ * The modifiers are considered equal if they are either both + * null or of the same type. + */ + static def boolean isEqualModifier(Modifier modifier1, Modifier modifier2) { + // Comparing their EClasses should be sufficient. + return Objects.equals(modifier1?.eClass, modifier2?.eClass) + } + + /** + * Sets for the modifiable the java visibility modifier corresponding to the given JavaVisibility enum constant. + * If visibility is JavaVisibility.PACKAGE, all visibility modifiers will be removed from the + * modifiable. + * + * @param modifiable the AnnotableAndModifiable for which the visibility should be set + * @param visibility the java visibility to set + * + */ + def static setJavaVisibilityModifier(AnnotableAndModifiable modifiable, JavaVisibility visibility) { + if (visibility == JavaVisibility.PACKAGE) { + removeJavaVisibilityModifiers(modifiable) + } else { + val visibilityModifier = getJavaVisibilityModifierFromEnum(visibility) + if (visibilityModifier !== null) { + if (!modifiable.hasModifier(visibilityModifier.class)) { + removeJavaVisibilityModifiers(modifiable) + setJavaModifier(modifiable, visibilityModifier, true) + } + } else { + logger.warn("No corresponding Java-Visibility-Modifier found for " + visibility) + } + } + } + + /** + * Returns null if visibility is JavaVisibility.PACKAGE. + * + * @return the Java Modifier corresponding to the JavaVisibility enum constant. + * @throws IllegalArgumentException if visibility is invalid + */ + def static getJavaVisibilityModifierFromEnum(JavaVisibility visibility) { + switch visibility { + case JavaVisibility.PUBLIC: return ModifiersFactory.eINSTANCE.createPublic + case JavaVisibility.PRIVATE: return ModifiersFactory.eINSTANCE.createPrivate + case JavaVisibility.PROTECTED: return ModifiersFactory.eINSTANCE.createProtected + case JavaVisibility.PACKAGE: return null + default: throw new IllegalArgumentException("Invalid Visibility: " + visibility) + } + } + + /** + * Returns the corresponding JavaVisibility enum constant of the given + * modifier. If modifier is null, it will return JavaVisibility.PACKAGE. + * + * @return the corresponding JavaVisibility enum constant + * @throws IllegalArgumentException if modifier is not a visibility modifier + */ + def static JavaVisibility getEnumConstantFromJavaVisibility(Modifier modifier) { + if (modifier === null) { + return JavaVisibility.PACKAGE + } + switch (modifier.eClass.name) { + case Private.simpleName: return JavaVisibility.PRIVATE + case Protected.simpleName: return JavaVisibility.PROTECTED + case Public.simpleName: return JavaVisibility.PUBLIC + default: throw new IllegalArgumentException("Invalid VisibilityModifier: " + modifier) + } + } + + /** + * Adds modifier to jModifiable if add is true. + * Otherwise it will remove all instances of the modifier's class from jModifiable. + * + * @param jModifiable the AnnotableAndModifiable for which the modifier should be added or removed + * @param the modifier to add or remove + * @param add true to add the modifier, else remove + */ + def static setJavaModifier(AnnotableAndModifiable jModifiable, Modifier modifier, boolean add) { + if (add) { + if (!jModifiable.hasModifier(modifier.class)) { + jModifiable.addModifier(modifier) + } else { + logger.warn("The Java AnnotableAndModifiable " + jModifiable.class + " already has the modifier " + modifier.class) + } + } else { + jModifiable.removeModifier(modifier.class) + } + } + + /** + * Adds mod to jModifiable if mod is not null. + * + * @param jModifiable the AnnotableAndMidifiable + * @param mod the modifier to add + */ + def static addModifierIfNotNull(AnnotableAndModifiable jModifiable, Modifier mod) { + if (mod !== null) { + setJavaModifier(jModifiable, mod, true) + } + } + + /** + * Sets the name of namedElement to name if name is not null. + * + * @param namedElment the NamedElement + * @param the name to set + * @throws IllegalArgumentException if name is null + */ + def static setName(NamedElement namedElement, String name) { + if (name === null) { + throw new IllegalArgumentException("Cannot set name of " + namedElement + " to null") + } + namedElement.name = name + } + + /** + * Adds a final modifier to modifiable, if toAdd is true. + * Otherwise it removes all final modifiers from modifiable. + * + * @param modifiable the AnnotableAndModifiable + * @param toAdd true to add the modifier, otherwise remove + */ + def static setFinal(AnnotableAndModifiable modifiable, boolean toAdd) { + setJavaModifier(modifiable, ModifiersFactory.eINSTANCE.createFinal, toAdd) + } + + /** + * Adds a abstract modifier to modifiable, if toAdd is true. + * Otherwise it removes all abstract modifiers from modifiable. + * + * @param modifiable the AnnotableAndModifiable + * @param toAdd true to add the modifier, otherwise remove + */ + def static setAbstract(AnnotableAndModifiable modifiable, boolean toAdd) { + setJavaModifier(modifiable, ModifiersFactory.eINSTANCE.createAbstract, toAdd) + } + + /** + * Adds a static modifier to modifiable, if toAdd is true. + * Otherwise it removes all static modifiers from modifiable. + * + * @param modifiable the AnnotableAndModifiable + * @param toAdd true to add the modifier, otherwise remove + */ + def static setStatic(AnnotableAndModifiable modifiable, boolean toAdd) { + setJavaModifier(modifiable, ModifiersFactory.eINSTANCE.createStatic, toAdd) + } + + /** + * Removes all Private, Public and Protected modifiers from a modifiable. + * + * @param modifiable the AnnotableAndModifiable from which all visibility modifiers should be removed + */ + def static removeJavaVisibilityModifiers(AnnotableAndModifiable modifiable) { + if (modifiable.hasModifier(typeof(Private))) modifiable.removeModifier(typeof(Private)) + if (modifiable.hasModifier(typeof(Protected))) modifiable.removeModifier(typeof(Protected)) + if (modifiable.hasModifier(typeof(Public))) modifiable.removeModifier(typeof(Public)) + } + + /** + * Returns the corresponding JavaVisibility enum constant corresponding to + * the VisibilityKind enum constant. + */ + def static getJavaVisibilityConstantFromUmlVisibilityKind(VisibilityKind uVisibility) { + switch (uVisibility) { + case VisibilityKind.PUBLIC_LITERAL: return JavaVisibility.PUBLIC + case VisibilityKind.PROTECTED_LITERAL: return JavaVisibility.PROTECTED + case VisibilityKind.PACKAGE_LITERAL: return JavaVisibility.PACKAGE + case VisibilityKind.PRIVATE_LITERAL: return JavaVisibility.PRIVATE + default: throw new IllegalArgumentException("Unknown VisibilityKind: " + uVisibility) + } + } + + /** + * Returns the corresponding VisibilityKind enum constant corresponding to + * the JavaVisibility enum constant. This is the reverse function of + * {@link #getJavaVisibilityConstantFromUmlVisibilityKind(VisibilityKind)} + */ + def static getUmlVisibilityKindFromJavaVisibilityConstant(JavaVisibility jVisibility) { + switch (jVisibility) { + case JavaVisibility.PUBLIC: return VisibilityKind.PUBLIC_LITERAL + case JavaVisibility.PROTECTED: return VisibilityKind.PROTECTED_LITERAL + case JavaVisibility.PACKAGE: return VisibilityKind.PACKAGE_LITERAL + case JavaVisibility.PRIVATE: return VisibilityKind.PRIVATE_LITERAL + default: throw new IllegalArgumentException("Unknown Java-Visibility: " + jVisibility) + } + } + + /** + * Returns the corresponding VisibilityKind enum constant corresponding to + * the visibility of the given Java element. + */ + def static getUmlVisibilityKindFromJavaElement(AnnotableAndModifiable javaElement) { + for (modifier : javaElement.annotationsAndModifiers) { + switch (modifier) { + Public: return VisibilityKind.PUBLIC_LITERAL + Protected: return VisibilityKind.PROTECTED_LITERAL + Private: return VisibilityKind.PRIVATE_LITERAL + } + } + return VisibilityKind.PACKAGE_LITERAL + } + + /** + * Sets the java visibility modifier corresponding to uVisibility to jModifiable + * + * @param jModifiable the AnnotableAndModifiable for which a java visibility modifier should be set + * @param uVisibility the VisibilityKind + */ + def static setJavaVisibility(AnnotableAndModifiable jModifiable, VisibilityKind uVisibility) { + setJavaVisibilityModifier(jModifiable, getJavaVisibilityConstantFromUmlVisibilityKind(uVisibility)) + } +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaPersistenceHelper.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaPersistenceHelper.xtend new file mode 100644 index 000000000..0ab5c1598 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaPersistenceHelper.xtend @@ -0,0 +1,105 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import java.util.Arrays +import org.emftext.language.java.containers.CompilationUnit +import org.emftext.language.java.containers.Package +import static com.google.common.base.Preconditions.checkState + +class JavaPersistenceHelper { + + static val UNNAMED_PACKAGE = "unnamedPackage" + + public static val PATH_SEPARATOR = "/" + public static val FILE_EXTENSION_SEPARATOR = "." + public static val JAVA_FILE_EXTENSION = "java" + static val FILE_EXTENSION_WITH_SEPARATOR = FILE_EXTENSION_SEPARATOR + JAVA_FILE_EXTENSION + + static def String getJavaProjectSrc() { + return "src" + PATH_SEPARATOR; + } + + static def String getPackageInfoClassName() { + "package-info" + } + + // Ensures that the source path is either empty or ends with '/'. + private static def String normalizeSourcePath(String sourcePath) { + if (sourcePath.nullOrEmpty) return "" + if (sourcePath.endsWith(PATH_SEPARATOR)) { + return sourcePath + } else { + return sourcePath + PATH_SEPARATOR + } + } + + static def stripJavaSourcePath(String javaFilePath, String sourcePath) { + if (javaFilePath.nullOrEmpty) return javaFilePath // null -> null, '' -> '' + + // Get and return the path relative to the (normalized) source path: + val normalizedSourcePath = sourcePath.normalizeSourcePath + if (!normalizedSourcePath.empty && javaFilePath.startsWith(normalizedSourcePath)) { + return javaFilePath.substring(normalizedSourcePath.length) + } else { + // Ensure that the returned path is relative: + if (javaFilePath.startsWith(PATH_SEPARATOR)) { + return javaFilePath.substring(PATH_SEPARATOR.length) + } else { + return javaFilePath + } + } + } + + static def getSimpleName(CompilationUnit compilationUnit) { + var simpleName = compilationUnit.name + checkState(simpleName.endsWith(FILE_EXTENSION_WITH_SEPARATOR), "compilation unit has to end with '%s' but doesn't: %s", FILE_EXTENSION_WITH_SEPARATOR, compilationUnit.name) + simpleName = simpleName.substring(0, simpleName.length - 5) + simpleName = simpleName.substring(simpleName.lastIndexOf('.') + 1) + return simpleName + } + + static def String buildJavaPath(String sourcePath, Iterable namespaces) { + return buildJavaFilePath(sourcePath, namespaces, "", "") + } + + // fileExtension can be empty and is then omitted. + static def String buildJavaFilePath(String sourcePath, Iterable namespaces, String fileName, + String fileExtension) { + return '''«sourcePath.normalizeSourcePath»« + FOR namespace : namespaces SEPARATOR PATH_SEPARATOR AFTER PATH_SEPARATOR»«namespace»«ENDFOR»« + fileName»« + IF !fileExtension.nullOrEmpty»«FILE_EXTENSION_SEPARATOR»«fileExtension»«ENDIF»''' + } + + // Uses 'src/' as source path. + // The fileName is simply appended to the end of the file path. It may or may not contain additional path segments + // and may or may not include the file extension. + static def String buildJavaFilePath(String fileName, Iterable namespaces) { + return buildJavaFilePath(javaProjectSrc, namespaces, fileName, null) + } + + // Uses 'src/' as source path. + static def dispatch String buildJavaFilePath(CompilationUnit compilationUnit) { + return buildJavaFilePath(javaProjectSrc, compilationUnit.namespaces, compilationUnit.simpleName, JAVA_FILE_EXTENSION) + } + + // Uses 'src/' as source path. + static def dispatch String buildJavaFilePath(Package javaPackage) { + return buildJavaPackageFilePath(javaProjectSrc, javaPackage.namespaces, javaPackage.name) + } + + static def String buildJavaPackageFilePath(String sourcePath, Iterable namespaces, + String packageName) { + val fullNamespaces = getFullPackageNamespaces(namespaces, packageName) + return buildJavaFilePath(sourcePath, fullNamespaces, packageInfoClassName, JAVA_FILE_EXTENSION) + } + + static def String buildJavaPackagePath(String sourcePath, Iterable namespaces, + String packageName) { + val fullNamespaces = getFullPackageNamespaces(namespaces, packageName) + return buildJavaPath(sourcePath, fullNamespaces) + } + + private static def getFullPackageNamespaces(Iterable namespaces, String packageName) { + return namespaces + Arrays.asList(packageName ?: UNNAMED_PACKAGE) + } +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaQueryUtil.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaQueryUtil.xtend new file mode 100644 index 000000000..d5fc9ae8d --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaQueryUtil.xtend @@ -0,0 +1,57 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import org.emftext.language.java.types.Char +import org.emftext.language.java.types.Int +import org.emftext.language.java.types.ClassifierReference +import org.emftext.language.java.types.NamespaceClassifierReference + +class JavaQueryUtil { + + def dispatch static getNameFromJaMoPPType(ClassifierReference reference) { + return reference.target.name + } + + def dispatch static getNameFromJaMoPPType(NamespaceClassifierReference reference) { + val classRef = reference.pureClassifierReference + return classRef.target.name + + // is currently not possible: see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=404817 + // return getNameFromJaMoPPType(classRef) + } + + def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Boolean reference) { + return "boolean" + } + + def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Byte reference) { + return "byte" + } + + def dispatch static getNameFromJaMoPPType(Char reference) { + return "char" + } + + def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Double reference) { + return "double" + } + + def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Float reference) { + return "float" + } + + def dispatch static getNameFromJaMoPPType(Int reference) { + return "int" + } + + def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Long reference) { + return "long" + } + + def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Short reference) { + return "short" + } + + def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Void reference) { + return "void" + } +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaSetup.java b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaSetup.java new file mode 100644 index 000000000..5bee2f572 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaSetup.java @@ -0,0 +1,40 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils; + +import java.util.function.Supplier; + +import org.eclipse.emf.ecore.resource.Resource; +import org.emftext.language.java.JavaClasspath; +import org.emftext.language.java.resource.JavaSourceOrClassFileResourceFactoryImpl; + +public final class JavaSetup { + private JavaSetup() { + } + + /** + * Prepares for using Java without an OSGI environment registering file extensions for the given resource factory. + * @param resourceFactory the resource factory to use for loading Java and class files + */ + public static void prepareFactories(Supplier resourceFactoryProvider) { + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("java", resourceFactoryProvider.get()); + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("class", resourceFactoryProvider.get()); + } + + /** + * Prepares for using Java without an OSGI environment registering file extensions for the default resource factories. + */ + public static void prepareFactories() { + prepareFactories(() -> new JavaSourceOrClassFileResourceFactoryImpl()); + } + + /** + * Resets the JaMoPP classpath to remove any classifier referenced before and registers the standard library (jmods/java.base) + * for use with JaMoPP. + * @see JavaClasspath#reset() + * @see JamoppLibraryHelper#registerStdLib() + */ + public static void resetClasspathAndRegisterStandardLibrary() { + JavaClasspath.reset(); + JamoppLibraryHelper.registerStdLib(); + } + +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaStandardType.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaStandardType.xtend new file mode 100644 index 000000000..876aeb529 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaStandardType.xtend @@ -0,0 +1,97 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import edu.kit.ipd.sdq.activextendannotations.Utility +import org.emftext.language.java.types.Boolean +import org.emftext.language.java.types.Byte +import org.emftext.language.java.types.Char +import org.emftext.language.java.types.Double +import org.emftext.language.java.types.Float +import org.emftext.language.java.types.Int +import org.emftext.language.java.types.Long +import org.emftext.language.java.types.PrimitiveType +import org.emftext.language.java.types.Short +import org.emftext.language.java.types.TypesFactory +import org.emftext.language.java.types.Void + +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaContainerAndClassifierUtil.* +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaModificationUtil.* + +/** + * Util class with for Java-PrimitiveTypes and Java-String. + * + * @author Fei + */ +@Utility +class JavaStandardType { + public static val BOOLEAN = "boolean" + public static val BYTE = "byte" + public static val CHAR = "char" + public static val DOUBLE = "double" + public static val FLOAT = "float" + public static val INT = "int" + public static val LONG = "long" + public static val SHORT = "short" + public static val STRING = "String" + public static val VOID = "void" + + def static dispatch String getTypeKeyword(Boolean bool) { + return BOOLEAN + } + + def static dispatch String getTypeKeyword(Byte by) { + return BYTE + } + + def static dispatch String getTypeKeyword(Char chr) { + return CHAR + } + + def static dispatch String getTypeKeyword(Double dbl) { + return DOUBLE + } + + def static dispatch String getTypeKeyword(Float flt) { + return FLOAT + } + + def static dispatch String getTypeKeyword(Int in) { + return INT + } + + def static dispatch String getTypeKeyword(Long lng) { + return LONG + } + + def static dispatch String getTypeKeyword(Short shrt) { + return SHORT + } + + def static dispatch String getTypeKeyword(Void vd) { + return VOID + } + + def static dispatch String getTypeKeyword(java.lang.Void vd) { + throw new IllegalArgumentException("Unknown java primitive type: " + vd) + } + + def static dispatch String getTypeKeyword(PrimitiveType ptype) { + throw new IllegalArgumentException("Unknown java primitive type: " + ptype) + } + + def static createJavaPrimitiveType(String standardTypeName) { + switch (standardTypeName) { + case BOOLEAN: return TypesFactory.eINSTANCE.createBoolean + case BYTE: return TypesFactory.eINSTANCE.createByte + case CHAR: return TypesFactory.eINSTANCE.createChar + case DOUBLE: return TypesFactory.eINSTANCE.createDouble + case FLOAT: return TypesFactory.eINSTANCE.createFloat + case INT: return TypesFactory.eINSTANCE.createInt + case LONG: return TypesFactory.eINSTANCE.createLong + case SHORT: return TypesFactory.eINSTANCE.createShort + case VOID: return TypesFactory.eINSTANCE.createVoid + case STRING: return createNamespaceClassifierReference(createJavaClass(STRING, JavaVisibility.PUBLIC, false, false)) + default: throw new IllegalArgumentException("Unknown standard primitive type name: " + standardTypeName) + } + } + +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaStatementUtil.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaStatementUtil.xtend new file mode 100644 index 000000000..3a5f6d21a --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaStatementUtil.xtend @@ -0,0 +1,139 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import edu.kit.ipd.sdq.activextendannotations.Utility +import org.eclipse.emf.ecore.util.EcoreUtil +import org.emftext.language.java.expressions.AssignmentExpression +import org.emftext.language.java.expressions.AssignmentExpressionChild +import org.emftext.language.java.expressions.EqualityExpression +import org.emftext.language.java.expressions.EqualityExpressionChild +import org.emftext.language.java.expressions.Expression +import org.emftext.language.java.expressions.ExpressionsFactory +import org.emftext.language.java.literals.LiteralsFactory +import org.emftext.language.java.literals.This +import org.emftext.language.java.members.Field +import org.emftext.language.java.operators.AssignmentOperator +import org.emftext.language.java.operators.EqualityOperator +import org.emftext.language.java.references.IdentifierReference +import org.emftext.language.java.references.ReferenceableElement +import org.emftext.language.java.references.ReferencesFactory +import org.emftext.language.java.references.SelfReference +import org.emftext.language.java.statements.Condition +import org.emftext.language.java.statements.ExpressionStatement +import org.emftext.language.java.statements.Return +import org.emftext.language.java.statements.Statement +import org.emftext.language.java.statements.StatementsFactory + +/** + * Util class for the creation and retrieving of statements. + * + * @author Fei + */ +@Utility +class JavaStatementUtil { + + /** + * Creates: + * + * return + * + * @param returnValue the expression that should placed behind the return key word + */ + def static Return createReturnStatement(Expression returnValue) { + val returnStatement = StatementsFactory.eINSTANCE.createReturn + returnStatement.returnValue = returnValue + return returnStatement + } + + /** + * Creates a expression + */ + def static SelfReference createSelfReferenceToAttribute(Field jAttribute) { + val selfReference = ReferencesFactory.eINSTANCE.createSelfReference + selfReference.self = LiteralsFactory.eINSTANCE.createThis + + val fieldReference = ReferencesFactory.eINSTANCE.createIdentifierReference + fieldReference.target = jAttribute + selfReference.next = EcoreUtil.copy(fieldReference) + return selfReference + } + + /** + * Creates leftSide rightSide + */ + def static AssignmentExpression createAssignmentExpression(AssignmentExpressionChild leftSide, AssignmentOperator operator, Expression rightSide) { + val assignmentExpression = ExpressionsFactory.eINSTANCE.createAssignmentExpression + assignmentExpression.child = leftSide + assignmentExpression.assignmentOperator = operator + assignmentExpression.value = rightSide + return assignmentExpression + } + + def static boolean expressionHasAttributeSelfReference(ExpressionStatement expressionStatement, Field jAttribute) { + if (expressionStatement === null) { + return false + } + if (getAttributeSelfReferenceInExpressionStatement(expressionStatement, jAttribute.name) !== null) { + return true + } + return false + } + + def static getAttributeSelfReferenceInExpressionStatement(ExpressionStatement expressionStatement, String attributeName) { + if (expressionStatement.expression !== null && expressionStatement.expression instanceof AssignmentExpression) { + val assignmentExpression = expressionStatement.expression as AssignmentExpression + if ((assignmentExpression.child as SelfReference).self instanceof This) { + val selfReference = (assignmentExpression.child as SelfReference).next as IdentifierReference + if (selfReference.target.name == attributeName) { + return selfReference + } + return null + } + return null + } + return null + + } + + def static IdentifierReference createIdentifierReference(ReferenceableElement elem) { + val reference = ReferencesFactory.eINSTANCE.createIdentifierReference + reference.target = elem + return reference + } + + /** + * thenStatement and elseStatement can be null + */ + def static Condition createCondition(Expression ifCondition, Statement thenStatement, Statement elseStatement) { + if (ifCondition === null) { + throw new IllegalArgumentException("Cannot create If block with 'null' as condition") + } + val condition = StatementsFactory.eINSTANCE.createCondition + condition.condition = ifCondition + if (condition !== null) { + condition.statement = thenStatement + } + if (elseStatement !== null) { + condition.elseStatement = elseStatement + } + return condition + } + + /** + * Creates leftSide rightSide + * EqualityOperator can be equal or notEqual + */ + def static EqualityExpression createBinaryEqualityExpression(EqualityExpressionChild leftSide, EqualityOperator eqOperator, + EqualityExpressionChild rightSide) { + val eqExpression = ExpressionsFactory.eINSTANCE.createEqualityExpression + eqExpression.children += leftSide + eqExpression.children += rightSide + eqExpression.equalityOperators += eqOperator + return eqExpression + } + + def static ExpressionStatement wrapExpressionInExpressionStatement(Expression expressionToWrap) { + val expressionStatement = StatementsFactory.eINSTANCE.createExpressionStatement + expressionStatement.expression = expressionToWrap + return expressionStatement + } +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaTypeUtil.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaTypeUtil.xtend new file mode 100644 index 000000000..4b29ae839 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaTypeUtil.xtend @@ -0,0 +1,335 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +import edu.kit.ipd.sdq.activextendannotations.Utility +import java.util.ArrayList +import java.util.HashSet +import java.util.LinkedList +import java.util.List +import org.apache.log4j.Logger +import org.eclipse.emf.common.util.BasicEList +import org.eclipse.emf.common.util.EList +import org.eclipse.emf.ecore.util.EcoreUtil +import org.emftext.language.java.classifiers.Classifier +import org.emftext.language.java.classifiers.ConcreteClassifier +import org.emftext.language.java.classifiers.Interface +import org.emftext.language.java.containers.CompilationUnit +import org.emftext.language.java.generics.GenericsFactory +import org.emftext.language.java.generics.QualifiedTypeArgument +import org.emftext.language.java.imports.ClassifierImport +import org.emftext.language.java.imports.ImportsFactory +import org.emftext.language.java.types.ClassifierReference +import org.emftext.language.java.types.NamespaceClassifierReference +import org.emftext.language.java.types.PrimitiveType +import org.emftext.language.java.types.Type +import org.emftext.language.java.types.TypeReference +import org.emftext.language.java.types.TypedElement +import org.emftext.language.java.types.TypesFactory + +import static tools.vitruv.applications.util.temporary.other.UriUtil.normalizeURI +import static tools.vitruv.applications.cbs.testutils.oldmetamodelutils.JavaModificationUtil.* + +/** + * Class for type and typereference util function + * @author Fei + */ +@Utility +class JavaTypeUtil { + + static val logger = Logger.getLogger(JavaTypeUtil.simpleName) + + static val List> supportedCollectionTypes = #[ArrayList, LinkedList, HashSet] + + /** + * Retrieves the type referenced by a type reference. This can either be a classifier or a primitive type. + * @return the type wrapped in the type reference or null if it is a Void type or unknown type reference. + */ + def private static dispatch Type getTypeFromReference(TypeReference typeReference) { + logger.warn(typeReference + " is neither a NamespaceClassifierReference nor a PrimitiveType. Returning null.") + return null + } + + def private static dispatch Type getTypeFromReference(Void nullTypeReference) { + logger.warn("Cannot get Type of a null-TypeReference. Returning null.") + return null + } + + def private static dispatch Type getTypeFromReference(PrimitiveType primitiveType) { + return primitiveType + } + + def private static dispatch Type getTypeFromReference(ClassifierReference classifierReference) { + return classifierReference.target + } + + def private static dispatch Type getTypeFromReference(NamespaceClassifierReference namespace) { + if (namespace === null || namespace.classifierReferences.nullOrEmpty) { + return null + } + return getTypeFromReference(namespace.classifierReferences.head) + } + + /** + * Retrieves the classifier wrapped in a type reference. + * @return the classifier or null if the type reference does not contain any classifier. + */ + def static Classifier getClassifierFromTypeReference(TypeReference typeRef) { + val type = getTypeFromReference(typeRef) + if (type instanceof Classifier) { + return type + } + logger.warn("The TypeReference " + typeRef + " does not contain a Classifier. Returning null.") + return null + } + + /** + * Retrieves the classifier wrapped in a type reference. Proxys are resolved and the classifier URI is normalized. + * @return the classifier or null if the type reference does not contain any classifier. + */ + def static Classifier getNormalizedClassifierFromTypeReference(TypeReference typeRef) { + var type = getTypeFromReference(typeRef) + if (type instanceof Classifier) { + if (type.eIsProxy) { // resolve proxy + val resourceSet = type.eResource?.resourceSet // resource can be null, but EcoreUtil.resolve() can handle null as resource set + type = EcoreUtil.resolve(type, resourceSet) as Classifier + } + normalizeURI(type) + return type as Classifier + } + logger.warn("The TypeReference " + typeRef + " does not contain a Classifier. Returning null.") + return null + } + + /** + * Retrieves the interface wrapped in a type reference. + * @return the interface or null if the type reference does not contain any interfaces. + */ + def static Interface getInterfaceFromTypeReference(TypeReference typeRef) { + val type = getTypeFromReference(typeRef) + if (type instanceof Interface) { + return type + } + logger.warn("The TypeReference " + typeRef + " does not contain a Interface. Returning null.") + return null + } + + /** + * Converts a list with ConcreteClassifiers to a list with corresponding NamespaceClassifierRefrences. + */ + def static EList createNamespaceReferenceFromList(List list) { + val typeReferences = new BasicEList + for (ConcreteClassifier i : list) { + typeReferences += createNamespaceClassifierReference(i) + } + return typeReferences + } + + def static TypeReference createCollectiontypeReference(String collectionQualifiedName, ConcreteClassifier innerTypeClass) { + val innerTypeReference = createNamespaceClassifierReference(innerTypeClass) + val qualifiedTypeArgument = GenericsFactory.eINSTANCE.createQualifiedTypeArgument() + qualifiedTypeArgument.typeReference = innerTypeReference + val collectionClassNamespaceReference = createNamespaceClassifierReferenceForName(collectionQualifiedName) + collectionClassNamespaceReference.classifierReferences.get(0).typeArguments += qualifiedTypeArgument + return collectionClassNamespaceReference + } + + def static setTypeReference(TypedElement typedElement, TypeReference typeRef) { + if (typeRef !== null) { + typedElement.typeReference = typeRef + } else { + typedElement.typeReference = TypesFactory.eINSTANCE.createVoid + } + } + + /** + * Compares two type references. Both type references must be primitive types or + * namespaceclassifierreferences or null. + * If they are primitive types, it will check if they are same primitive type + * If they are NamespaceClassifierReferences, it will check the name of their wrapped classifiers for equality + */ + def static dispatch typeReferenceEquals(TypeReference typeRef1, TypeReference typeRef2) { + logger.warn("No dispatch Method found for the typeReferences " + typeRef1 + " and " + typeRef2 + ". Returning false.") + return false + } + + def static dispatch typeReferenceEquals(NamespaceClassifierReference typeRef1, NamespaceClassifierReference typeRef2) { + return getClassifierFromTypeReference(typeRef1).name.equals(getClassifierFromTypeReference(typeRef2).name) + } + + def static dispatch typeReferenceEquals(PrimitiveType primType1, PrimitiveType primtype2) { + return primType1.class.equals(primtype2.class) + } + + def static dispatch typeReferenceEquals(Void type1, Void typ22) { + logger.warn("Both TypeReferences to compare are null. Returning true.") + return true + } + + def static getInnerTypeReferenceOfCollectionTypeReference(TypeReference typeRef) { + if (typeRef instanceof NamespaceClassifierReference) { + return (typeRef.classifierReferences.head.typeArguments.head as QualifiedTypeArgument).typeReference + } + logger.warn("Cannot get inner TypeReference of a non-NamespaceClassifierReference. Returning null.") + return null + } + + def static boolean hasSameTargetReference(TypeReference reference1, TypeReference reference2) { + if (reference1 == reference2 || reference1.equals(reference2)) { + return true + } + val target1 = getClassifierFromTypeReference(reference1) + val target2 = getClassifierFromTypeReference(reference2) + return target1 == target2 || target1.equals(target2) + } + + def static findImplementingInterfacesFromTypeRefs(EList typeReferences) { + val implementingInterfaces = new ArrayList + for (typeRef : typeReferences) { + val classifier = getNormalizedClassifierFromTypeReference(typeRef) + if (classifier instanceof Interface) { + implementingInterfaces.add(classifier) + } + } + return implementingInterfaces + } + + def static String getQualifiedName(Classifier classifier) { + if (classifier instanceof ConcreteClassifier) { + val namespace = if (classifier.containingCompilationUnit !== null) classifier.containingCompilationUnit.namespaces.join(".") else "" + val qualifiedName = if (namespace != "") namespace + "." + classifier.name else classifier.name + return qualifiedName + } else { + // can't retrieve namespaces + return classifier.name + } + } + + def static boolean isCollectionTypeReference(TypeReference jRef) { + val classifier = getNormalizedClassifierFromTypeReference(jRef) + if (classifier !== null) { + val qualifiedName = getQualifiedName(classifier) + if (supportedCollectionTypes.exists[it.name == qualifiedName]) { + return true + } + } + return false + } + + def static dispatch TypeReference getInnerTypeRefOfCollectionReference(TypeReference collRef) { + return null + } + + def static dispatch TypeReference getInnerTypeRefOfCollectionReference(ClassifierReference collRef) { + val typeArgument = collRef.typeArguments.head + if (typeArgument !== null && typeArgument instanceof QualifiedTypeArgument) { + val typeRef = (typeArgument as QualifiedTypeArgument).typeReference + return typeRef + } + return null + } + + def static dispatch TypeReference getInnerTypeRefOfCollectionReference(NamespaceClassifierReference collRef) { + return if (!collRef.classifierReferences.nullOrEmpty) + getInnerTypeRefOfCollectionReference(collRef.classifierReferences.head) + else + null + } + + def static void addJavaImport(CompilationUnit compUnit, TypeReference jTypeRef) { + if (jTypeRef instanceof PrimitiveType) { + return // nothing to do + } else if (jTypeRef.target !== null && jTypeRef.target instanceof ConcreteClassifier) { + val jType = jTypeRef.target as ConcreteClassifier + addJavaImport(compUnit, jType) + // add imports for typeArguments if any exist + if (jTypeRef instanceof NamespaceClassifierReference) { + val typeArguments = jTypeRef.classifierReferences.get(0).typeArguments + for (typeArgument : typeArguments.filter(QualifiedTypeArgument).filter[it.typeReference !== null]) { + typeArgument.typeReference + addJavaImport(compUnit, typeArgument.typeReference) + } + } + } + } + + def static ClassifierImport addJavaImport(CompilationUnit compUnit, ConcreteClassifier jType) { + if (compUnit === null) { + return null + } + if (jType === null || jType instanceof PrimitiveType) { + return null // nothing to do + } + + /* + * If a referenced type lives in the same package as the concerned CompilationUnit, then an import + * is generally unnecessary. However, if the Compilation unit is then moved to another package, + * the transformation has to ensure that imports for types in the same package are added afterwards. + * + * TODO The samePackage check is disabled, because the required transformation implementation to support + * this feature is still missing. Until then, imports are added for every referenced Type, so that the + * CompilationUnit remains compilable after beeing moved. + */ + // val targetNamespace = if (jType.containingCompilationUnit !== null) jType.containingCompilationUnit.namespaces.join(".") else "" + // val samePackage = targetNamespace.equals(compUnit.namespaces.join(".")) + val samePackage = false + val alreadyImported = compUnit.imports.filterNull.filter(ClassifierImport).exists [ + it.classifier.name == jType.name + // TODO unclear how to handle name conflicts + /* It is possible that two Types have the same name but different namespaces. In this case + * at least one of the types has to be used fully qualified throughout the compilation unit. + * How should such a problem be communicated and how can the JaMoPP printer then be triggered + * to write TypeReferences fully qualified. + */ + ] + if (!samePackage && !alreadyImported) { + val classifierImport = ImportsFactory.eINSTANCE.createClassifierImport + if (null !== jType.containingCompilationUnit) { + if (null !== jType.containingCompilationUnit.namespaces) { + classifierImport.namespaces.addAll(jType.containingCompilationUnit.namespaces) + } + } + classifierImport.classifier = jType + compUnit.imports.add(classifierImport) + return classifierImport + } else { + return null // nothing to do + } + } + + def static NamespaceClassifierReference createCollectionTypeReference( + NamespaceClassifierReference collectionTypeReference, + TypeReference innerTypeReference + ) { + // wrap typeReference if necessary + var wrappedInnerReference = innerTypeReference + if (wrappedInnerReference instanceof PrimitiveType) { + wrappedInnerReference = getWrapperTypeReferenceForPrimitiveType(wrappedInnerReference) + } + + // set the inner type reference on the NamespaceClassifierReference of the Collection type + val qualifiedTypeArgument = GenericsFactory.eINSTANCE.createQualifiedTypeArgument() + qualifiedTypeArgument.typeReference = wrappedInnerReference + collectionTypeReference.classifierReferences.get(0).typeArguments += qualifiedTypeArgument + + return collectionTypeReference + } + + def static NamespaceClassifierReference createCollectionTypeReference( + ConcreteClassifier collectionTypeClassifier, + TypeReference innerTypeReference + ) { + val collectionTypeReference = createNamespaceClassifierReference(collectionTypeClassifier) + return createCollectionTypeReference(collectionTypeReference, innerTypeReference) + } + + def static NamespaceClassifierReference createCollectionTypeReference( + Class collectionType, + TypeReference innerTypeReference + ) { + val collectionNamespace = collectionType.name.replace("." + collectionType.simpleName, "") + val collectionSimpleName = collectionType.simpleName + val collectionTypeReference = createNamespaceClassifierReferenceForName(collectionNamespace, collectionSimpleName) + + return createCollectionTypeReference(collectionTypeReference, innerTypeReference) + } + +} diff --git a/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaVisibility.xtend b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaVisibility.xtend new file mode 100644 index 000000000..2a03fe280 --- /dev/null +++ b/bundles/tools.vitruv.applications.cbs.testutils/src/tools/vitruv/applications/cbs/testutils/oldmetamodelutils/JavaVisibility.xtend @@ -0,0 +1,12 @@ +package tools.vitruv.applications.cbs.testutils.oldmetamodelutils + +/** + * Enum for the four possible visibilities in java. We created this + * enum because the java metamodell does not have a explicit value for + * "package-private". + * + * @author Fei + */ +enum JavaVisibility { + PUBLIC, PRIVATE, PROTECTED, PACKAGE +} diff --git a/bundles/tools.vitruv.applications.pcmjava/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.pcmjava/META-INF/MANIFEST.MF index 559a5a3ed..bd066d787 100644 --- a/bundles/tools.vitruv.applications.pcmjava/META-INF/MANIFEST.MF +++ b/bundles/tools.vitruv.applications.pcmjava/META-INF/MANIFEST.MF @@ -9,12 +9,12 @@ Bundle-Vendor: vitruv.tools Export-Package: tools.vitruv.applications.pcmjava, tools.vitruv.applications.pcmjava.java2pcm, tools.vitruv.applications.pcmjava.pcm2java -Require-Bundle: org.emftext.language.java;visibility:=reexport, - org.palladiosimulator.pcm;visibility:=reexport, +Require-Bundle: org.palladiosimulator.pcm;visibility:=reexport, edu.kit.ipd.sdq.commons.util.emf, edu.kit.ipd.sdq.commons.util.java, edu.kit.ipd.sdq.commons.util.pcm, edu.kit.ipd.sdq.activextendannotations, tools.vitruv.framework.applications, tools.vitruv.dsls.reactions.runtime, - tools.vitruv.applications.util.temporary + tools.vitruv.applications.util.temporary, + tools.mdsd.jamopp.model;bundle-version="6.0.0" diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/PcmJavaTransformationUtil.xtend b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/PcmJavaTransformationUtil.xtend index e425d2401..ceffdda74 100644 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/PcmJavaTransformationUtil.xtend +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/PcmJavaTransformationUtil.xtend @@ -4,7 +4,7 @@ import edu.kit.ipd.sdq.activextendannotations.Utility import org.palladiosimulator.pcm.core.entity.Entity import org.palladiosimulator.pcm.repository.Repository import org.palladiosimulator.pcm.system.System -import org.emftext.language.java.containers.Package +import tools.mdsd.jamopp.model.java.containers.Package @Utility class PcmJavaTransformationUtil { diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2Pcm.reactions b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2Pcm.reactions index 68aa7feb7..f2a505696 100644 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2Pcm.reactions +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2Pcm.reactions @@ -1,4 +1,4 @@ -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java import "http://palladiosimulator.org/PalladioComponentModel/5.2" as pcm reactions: java2Pcm diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2PcmClassifier.reactions b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2PcmClassifier.reactions index 4c61fd0b2..495f8986c 100644 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2PcmClassifier.reactions +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2PcmClassifier.reactions @@ -1,8 +1,8 @@ import edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util.URIUtil -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.containers.ContainersPackage -import org.emftext.language.java.types.ClassifierReference -import org.emftext.language.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.containers.ContainersPackage +import tools.mdsd.jamopp.model.java.types.ClassifierReference +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference import org.palladiosimulator.pcm.repository.OperationInterface import org.palladiosimulator.pcm.repository.RepositoryPackage import org.palladiosimulator.pcm.system.SystemPackage @@ -17,7 +17,7 @@ import static tools.vitruv.applications.util.temporary.java.JavaPersistenceHelpe import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.claimNotMany import static extension tools.vitruv.applications.pcmjava.PcmJavaTransformationUtil.isPackageFor -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java import "http://palladiosimulator.org/PalladioComponentModel/5.2" as pcm reactions: java2PcmClassifier @@ -25,7 +25,7 @@ in reaction to changes in java execute actions in pcm ///Repository -reaction PackageCreated { +reaction JavaPackageCreated { after element java::Package inserted as root // This condition prevents another execution after automatically creating contracts and datatypes package. // The reaction is called because every package insert is a root insert. @@ -311,7 +311,7 @@ routine renameComponent(java::Package javaPackage) { } //Interface -reaction InterfaceCreated { +reaction JavaInterfaceCreated { after element java::Interface inserted in java::CompilationUnit[classifiers] call createOrFindPCMInterface(newValue, affectedEObject) } @@ -438,7 +438,7 @@ routine renameDataTypeFromClass(java::Class javaClass) { } } -reaction ClassCreated { +reaction JavaClassCreated { after element java::Class inserted in java::CompilationUnit[classifiers] call { val javaPackage = getContainingPackageFromCorrespondenceModel(newValue, correspondenceModel) diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2PcmMethod.reactions b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2PcmMethod.reactions index 8ef722b25..28c3c27cb 100644 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2PcmMethod.reactions +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/Java2PcmMethod.reactions @@ -1,12 +1,12 @@ import org.palladiosimulator.pcm.repository.OperationProvidedRole -import org.emftext.language.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier import static tools.vitruv.applications.util.temporary.java.JavaTypeUtil.* import static extension edu.kit.ipd.sdq.commons.util.org.palladiosimulator.pcm.repository.ParameterUtil.* import static extension tools.vitruv.applications.util.temporary.java.JavaMemberAndParameterUtil.hasSameSignature import static extension tools.vitruv.applications.pcmjava.java2pcm.TypeReferenceCorrespondenceHelper.getDataTypeFromTypeReference import static extension tools.vitruv.applications.pcmjava.java2pcm.TypeReferenceCorrespondenceHelper.getCorrespondingPCMDataTypeForTypeReference -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java import "http://palladiosimulator.org/PalladioComponentModel/5.2" as pcm reactions: java2PcmMethod @@ -322,7 +322,7 @@ routine changeReturnType(java::Method javaMethod, java::TypeReference typeRefere val repository = operationSignature.interface__OperationSignature.repository__Interface operationSignature.returnType__OperationSignature = if (typeReference !== null) { typeReference.getCorrespondingPCMDataTypeForTypeReference(correspondenceModel, userInteractor, repository, - javaMethod.arrayDimension) + javaMethod.typeReference.arrayDimension) } else { null } diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/TypeReferenceCorrespondenceHelper.xtend b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/TypeReferenceCorrespondenceHelper.xtend index c081d06df..f330d46c3 100644 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/TypeReferenceCorrespondenceHelper.xtend +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/java2pcm/TypeReferenceCorrespondenceHelper.xtend @@ -2,20 +2,20 @@ package tools.vitruv.applications.pcmjava.java2pcm import java.util.Set import org.apache.log4j.Logger -import org.emftext.language.java.classifiers.Classifier -import org.emftext.language.java.types.Boolean -import org.emftext.language.java.types.Byte -import org.emftext.language.java.types.Char -import org.emftext.language.java.types.ClassifierReference -import org.emftext.language.java.types.Double -import org.emftext.language.java.types.Float -import org.emftext.language.java.types.Int -import org.emftext.language.java.types.Long -import org.emftext.language.java.types.NamespaceClassifierReference -import org.emftext.language.java.types.PrimitiveType -import org.emftext.language.java.types.Short -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.types.Void +import tools.mdsd.jamopp.model.java.classifiers.Classifier +import tools.mdsd.jamopp.model.java.types.Boolean +import tools.mdsd.jamopp.model.java.types.Byte +import tools.mdsd.jamopp.model.java.types.Char +import tools.mdsd.jamopp.model.java.types.ClassifierReference +import tools.mdsd.jamopp.model.java.types.Double +import tools.mdsd.jamopp.model.java.types.Float +import tools.mdsd.jamopp.model.java.types.Int +import tools.mdsd.jamopp.model.java.types.Long +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.types.PrimitiveType +import tools.mdsd.jamopp.model.java.types.Short +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.Void import org.palladiosimulator.pcm.core.entity.NamedElement import org.palladiosimulator.pcm.repository.CollectionDataType import org.palladiosimulator.pcm.repository.CompositeDataType diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/DataTypeCorrespondenceHelper.xtend b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/DataTypeCorrespondenceHelper.xtend index f34a257c5..740a120a2 100644 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/DataTypeCorrespondenceHelper.xtend +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/DataTypeCorrespondenceHelper.xtend @@ -5,11 +5,11 @@ import org.palladiosimulator.pcm.repository.CompositeDataType import org.palladiosimulator.pcm.repository.DataType import org.palladiosimulator.pcm.repository.PrimitiveDataType import org.apache.log4j.Logger -import org.emftext.language.java.classifiers.ClassifiersFactory -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.types.Type -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.classifiers.ClassifiersFactory +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.types.Type +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.TypesFactory import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.claimOne import static tools.vitruv.applications.util.temporary.java.JavaModificationUtil.* diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2Java.reactions b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2Java.reactions index 03d0e52a9..ea4ecacf8 100755 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2Java.reactions +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2Java.reactions @@ -6,19 +6,19 @@ import java.util.List import java.util.Stack import java.util.Vector import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.classifiers.Interface -import org.emftext.language.java.containers.ContainersPackage -import org.emftext.language.java.expressions.AssignmentExpression -import org.emftext.language.java.generics.GenericsFactory -import org.emftext.language.java.imports.ClassifierImport -import org.emftext.language.java.instantiations.NewConstructorCall -import org.emftext.language.java.members.Constructor -import org.emftext.language.java.members.Field -import org.emftext.language.java.modifiers.ModifiersFactory -import org.emftext.language.java.references.IdentifierReference -import org.emftext.language.java.references.SelfReference -import org.emftext.language.java.statements.ExpressionStatement -import org.emftext.language.java.types.PrimitiveType +import tools.mdsd.jamopp.model.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.containers.ContainersPackage +import tools.mdsd.jamopp.model.java.expressions.AssignmentExpression +import tools.mdsd.jamopp.model.java.generics.GenericsFactory +import tools.mdsd.jamopp.model.java.imports.ClassifierImport +import tools.mdsd.jamopp.model.java.instantiations.NewConstructorCall +import tools.mdsd.jamopp.model.java.members.Constructor +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.modifiers.ModifiersFactory +import tools.mdsd.jamopp.model.java.references.IdentifierReference +import tools.mdsd.jamopp.model.java.references.SelfReference +import tools.mdsd.jamopp.model.java.statements.ExpressionStatement +import tools.mdsd.jamopp.model.java.types.PrimitiveType import org.palladiosimulator.pcm.repository.BasicComponent import org.palladiosimulator.pcm.repository.CollectionDataType import org.palladiosimulator.pcm.repository.CompositeDataType @@ -37,8 +37,10 @@ import static tools.vitruv.applications.util.temporary.java.JavaPersistenceHelpe import static extension tools.vitruv.applications.pcmjava.PcmJavaTransformationUtil.getCorrespondingPackageName import static extension tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil.* import static extension tools.vitruv.applications.util.temporary.java.JavaMemberAndParameterUtil.* +import tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil +import tools.mdsd.jamopp.model.java.statements.StatementsFactory -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java import "http://palladiosimulator.org/PalladioComponentModel/5.2" as pcm reactions: pcm2java @@ -260,6 +262,7 @@ routine createAssemblyContextConstructor(pcm::AssemblyContext assemblyContext, j val constructor = new java::Constructor } update { + constructor.block = StatementsFactory.eINSTANCE.createBlock createAssemblyContextStatement(assemblyContext, constructor, compositeComponentJavaClass) addConstructorToClass(constructor, compositeComponentJavaClass) } @@ -699,7 +702,7 @@ routine createOrFindJavaClass(pcm::NamedElement pcmElement, java::Package contai require absence of java::Class corresponding to pcmElement } update { - val foundClass = findClassifier(className, containingPackage, org.emftext.language.java.classifiers.Class) + val foundClass = findClassifier(className, containingPackage, tools.mdsd.jamopp.model.java.classifiers.Class) if (foundClass === null) { createJavaClass(pcmElement, containingPackage, className) } else { @@ -766,7 +769,7 @@ routine createCompilationUnit(pcm::NamedElement sourceElementMappedToClass, java classifier.name.toFirstUpper + ".java" compilationUnit.classifiers += classifier; persistProjectRelative(sourceElementMappedToClass, compilationUnit, buildJavaFilePath(compilationUnit)); - containingPackage.compilationUnits += compilationUnit + JavaContainerAndClassifierUtil.updateNamespaces(compilationUnit, containingPackage); } } @@ -1051,6 +1054,7 @@ routine createMethodForOperationSignature(pcm::OperationSignature operationSigna update { addCorrespondenceBetween(interfaceMethod, operationSignature) interfaceMethod.name = operationSignature.entityName; + interfaceMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement changeInterfaceMethodReturnType(interfaceMethod, operationSignature.returnType__OperationSignature); javaInterface.members += interfaceMethod; } diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2JavaChangePropagationSpecification.xtend b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2JavaChangePropagationSpecification.xtend index 33cc2354b..2b02f3972 100644 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2JavaChangePropagationSpecification.xtend +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2JavaChangePropagationSpecification.xtend @@ -1,4 +1,4 @@ package tools.vitruv.applications.pcmjava.pcm2java class Pcm2JavaChangePropagationSpecification extends mir.reactions.pcm2java.Pcm2javaChangePropagationSpecification { -} +} \ No newline at end of file diff --git a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2JavaHelper.xtend b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2JavaHelper.xtend index 17cbc7d65..ba85194fa 100644 --- a/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2JavaHelper.xtend +++ b/bundles/tools.vitruv.applications.pcmjava/src/tools/vitruv/applications/pcmjava/pcm2java/Pcm2JavaHelper.xtend @@ -2,10 +2,10 @@ package tools.vitruv.applications.pcmjava.pcm2java import java.util.Optional import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.palladiosimulator.pcm.repository.DataType import org.palladiosimulator.pcm.repository.PrimitiveDataType import edu.kit.ipd.sdq.activextendannotations.Utility diff --git a/bundles/tools.vitruv.applications.testutility/.project b/bundles/tools.vitruv.applications.testutility/.project index 7f1114af2..1e174e3fd 100644 --- a/bundles/tools.vitruv.applications.testutility/.project +++ b/bundles/tools.vitruv.applications.testutility/.project @@ -26,7 +26,7 @@ - org.emftext.language.java.resource.java.builder + tools.mdsd.jamopp.model.java.resource.java.builder @@ -35,6 +35,5 @@ org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature org.eclipse.xtext.ui.shared.xtextNature - org.emftext.language.java.resource.java.nature diff --git a/bundles/tools.vitruv.applications.umljava/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.umljava/META-INF/MANIFEST.MF index f21432806..7a4000db8 100644 --- a/bundles/tools.vitruv.applications.umljava/META-INF/MANIFEST.MF +++ b/bundles/tools.vitruv.applications.umljava/META-INF/MANIFEST.MF @@ -7,12 +7,12 @@ Bundle-Version: 3.0.1.qualifier Bundle-Vendor: vitruv.tools Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: org.eclipse.uml2.uml;visibility:=reexport, - org.emftext.language.java;visibility:=reexport, edu.kit.ipd.sdq.activextendannotations, edu.kit.ipd.sdq.commons.util.emf, edu.kit.ipd.sdq.commons.util.java, tools.vitruv.framework.applications, tools.vitruv.dsls.reactions.runtime, - tools.vitruv.applications.util.temporary;visibility:=reexport + tools.vitruv.applications.util.temporary;visibility:=reexport, + tools.mdsd.jamopp.model;bundle-version="6.0.0" Export-Package: tools.vitruv.applications.umljava, tools.vitruv.applications.umljava.util diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUml.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUml.reactions index 71f20a4ff..75cfe28ee 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUml.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUml.reactions @@ -1,5 +1,5 @@ import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: javaToUml in reaction to changes in java diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlAttribute.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlAttribute.reactions index 4e00ed234..1063a2421 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlAttribute.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlAttribute.reactions @@ -2,7 +2,7 @@ import static tools.vitruv.applications.umljava.util.CommonUtil.showMessage import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.claimNotMany import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: javaToUmlAttribute in reaction to changes in java diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlClassifier.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlClassifier.reactions index 4751ccb66..02ab8e7ce 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlClassifier.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlClassifier.reactions @@ -2,8 +2,8 @@ import edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util.URIUtil import org.eclipse.uml2.uml.Model import org.eclipse.uml2.uml.UMLFactory import org.eclipse.uml2.uml.UMLPackage -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.classifiers.Interface import tools.vitruv.dsls.reactions.runtime.helper.PersistenceHelper import static tools.vitruv.applications.util.temporary.uml.UmlClassifierAndPackageUtil.findUmlPackage import static tools.vitruv.applications.util.temporary.uml.UmlClassifierAndPackageUtil.findUmlClass @@ -17,7 +17,7 @@ import static tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* import java.util.ArrayList import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: javaToUmlClassifier in reaction to changes in java @@ -105,14 +105,10 @@ routine registerPredefinedUmlPrimitiveTypes(EObject alreadyPersistedEObject) { //=========================================== reaction JavaCompilationUnitInsertedAsRoot { after element java::CompilationUnit inserted as root - call newValue.classifiers.forEach[insertUmlClassifier(it, newValue)] -} - -reaction JavaCompilationUnitInsertedInPackage { - after element java::CompilationUnit inserted in java::Package[compilationUnits] call { + newValue.classifiers.forEach[insertUmlClassifier(it, newValue)] rootElementPreSetup(newValue) - newValue.classifiers.forEach[insertUmlClassifierIntoPackage(it, affectedEObject)] + newValue.classifiers.forEach[insertUmlClassifierIntoPackage(it, it.package)] } } diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlMethod.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlMethod.reactions index 84ae4e64d..0afeba2dd 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlMethod.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlMethod.reactions @@ -1,18 +1,18 @@ import org.eclipse.uml2.uml.LiteralUnlimitedNatural import org.eclipse.uml2.uml.OperationOwner import org.eclipse.uml2.uml.ParameterDirectionKind -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.classifiers.Enumeration -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.modifiers.Private -import org.emftext.language.java.modifiers.Protected -import org.emftext.language.java.modifiers.Public +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.classifiers.Enumeration +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.modifiers.Private +import tools.mdsd.jamopp.model.java.modifiers.Protected +import tools.mdsd.jamopp.model.java.modifiers.Public import tools.vitruv.applications.umljava.util.UmlJavaCorrespondenceTag import static tools.vitruv.applications.umljava.util.CommonUtil.showMessage import static tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: javaToUmlMethod in reaction to changes in java diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlTypePropagation.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlTypePropagation.reactions index a380a4c51..4d94007d3 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlTypePropagation.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/java2uml/JavaToUmlTypePropagation.reactions @@ -3,12 +3,12 @@ import static tools.vitruv.applications.umljava.util.UmlJavaTypePropagationHelpe import static tools.vitruv.applications.util.temporary.java.JavaTypeUtil.* import org.eclipse.emf.ecore.util.EcoreUtil import org.eclipse.uml2.uml.UMLPackage -import org.emftext.language.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.classifiers.Interface import static tools.vitruv.applications.util.temporary.uml.UmlClassifierAndPackageUtil.* -import org.emftext.language.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: javaToUmlTypePropagation in reaction to changes in java @@ -76,7 +76,7 @@ routine createExistingUmlClassifier(java::ConcreteClassifier existingJavaClassif createExistingUmlPackage(existingJavaClassifier.containingCompilationUnit.namespacesAsString) switch (existingJavaClassifier) { Interface: createExistingUmlInterface(existingJavaClassifier) - org.emftext.language.java.classifiers.Class: createExistingUmlClass(existingJavaClassifier) + tools.mdsd.jamopp.model.java.classifiers.Class: createExistingUmlClass(existingJavaClassifier) } } } diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJava.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJava.reactions index d2926b26d..082894e68 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJava.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJava.reactions @@ -1,5 +1,5 @@ import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: umlToJava in reaction to changes in uml diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaAttribute.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaAttribute.reactions index 9f1ec505c..76eeed3c7 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaAttribute.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaAttribute.reactions @@ -1,6 +1,6 @@ import org.eclipse.uml2.uml.Property -import org.emftext.language.java.members.ClassMethod -import org.emftext.language.java.members.Field +import tools.mdsd.jamopp.model.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.members.Field import tools.vitruv.applications.umljava.util.UmlJavaCorrespondenceTag import static tools.vitruv.applications.umljava.util.CommonUtil.showMessage import static tools.vitruv.applications.util.temporary.java.JavaMemberAndParameterUtil.* @@ -8,7 +8,7 @@ import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.clai import static extension tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: umlToJavaAttribute in reaction to changes in uml diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaClassifier.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaClassifier.reactions index 8b73621bd..3c823df0d 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaClassifier.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaClassifier.reactions @@ -5,7 +5,7 @@ import org.eclipse.uml2.uml.Interface import org.eclipse.uml2.uml.Model import org.eclipse.uml2.uml.PrimitiveType import org.eclipse.uml2.uml.UMLPackage -import org.emftext.language.java.containers.ContainersPackage +import tools.mdsd.jamopp.model.java.containers.ContainersPackage import tools.vitruv.change.interaction.UserInteractionOptions.NotificationType import tools.vitruv.change.interaction.UserInteractionOptions.WindowModality import static extension tools.vitruv.applications.umljava.util.UmlJavaTypePropagationHelper.* @@ -17,9 +17,10 @@ import static extension tools.vitruv.applications.util.temporary.java.JavaContai import static extension tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* import static java.util.List.copyOf import java.util.ArrayList +import tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: umlToJavaClassifier in reaction to changes in uml @@ -52,7 +53,7 @@ routine createOrFindJavaClass(uml::Classifier umlClassifier) { routine createOrFindJavaClassInPackage(uml::Classifier umlClassifier, java::Package javaPackage) { update { - val foundClass = findClassifier(umlClassifier.name, javaPackage, org.emftext.language.java.classifiers.Class) + val foundClass = findClassifier(umlClassifier.name, javaPackage, tools.mdsd.jamopp.model.java.classifiers.Class) if (foundClass === null) { createJavaClass(umlClassifier) } else { @@ -102,8 +103,8 @@ routine insertJavaClassifier(uml::Classifier umlClassifier, uml::Package umlPack persistProjectRelative(umlClassifier, javaCompilationUnit, buildJavaFilePath(javaCompilationUnit)) } javaPackage.ifPresent [ - if (!compilationUnits.contains(javaCompilationUnit)) { - compilationUnits += javaCompilationUnit + if (!javaCompilationUnit.containingPackageName.equals(JavaContainerAndClassifierUtil.getJavaPackageAsStringList(javaPackage.get))) { + JavaContainerAndClassifierUtil.updateNamespaces(javaCompilationUnit, javaPackage.get); } ] } @@ -329,7 +330,7 @@ routine createOrFindJavaInterface(uml::Interface umlInterface) { routine createOrFindJavaInterfaceInPackage(uml::Interface umlInterface, java::Package javaPackage) { update { val foundInterface = findClassifier(umlInterface.name, javaPackage, - org.emftext.language.java.classifiers.Interface) + tools.mdsd.jamopp.model.java.classifiers.Interface) if (foundInterface === null) { createJavaInterface(umlInterface) } else { @@ -559,7 +560,8 @@ routine renameJavaPackage(uml::Package uPackage, uml::Namespace uNamespace) { modified = jPackage.updateName(uPackage.name) || modified if (modified) { persistProjectRelative(uPackage, jPackage, buildJavaFilePath(jPackage)) - for (compUnit : copyOf(jPackage.compilationUnits)) { + for (compUnit : copyOf(jPackage.classifiers.map[it.containingCompilationUnit] + )) { changePackageOfJavaCompilationUnit(jPackage, compUnit, uNamespace) } // TODO TS This should be dealt with by the java domain, as this regards model specific persistence issues: diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaMethod.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaMethod.reactions index 46711f863..2ce8cc7ec 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaMethod.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaMethod.reactions @@ -5,16 +5,17 @@ import org.eclipse.uml2.uml.Parameter import org.eclipse.uml2.uml.ParameterDirectionKind import org.eclipse.uml2.uml.Property import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.members.ClassMethod -import org.emftext.language.java.members.Constructor -import org.emftext.language.java.members.InterfaceMethod -import org.emftext.language.java.members.Method -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.members.Constructor +import tools.mdsd.jamopp.model.java.members.InterfaceMethod +import tools.mdsd.jamopp.model.java.members.Method +import tools.mdsd.jamopp.model.java.types.TypesFactory import static tools.vitruv.applications.umljava.util.CommonUtil.showMessage import static extension tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* +import tools.mdsd.jamopp.model.java.statements.StatementsFactory import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: umlToJavaMethod in reaction to changes in uml @@ -75,6 +76,7 @@ routine createJavaConstructor(uml::Operation umlOperation) { val javaConstructor = new java::Constructor } update { + javaConstructor.block = StatementsFactory.eINSTANCE.createBlock javaConstructor.name = umlOperation.name setJavaVisibility(javaConstructor, umlOperation.visibility) addCorrespondenceBetween(umlOperation, javaConstructor) @@ -93,6 +95,9 @@ routine createOrFindJavaClassMethod(uml::Operation umlOperation, uml::Classifier if (foundMethod === null) { createJavaClassMethod(umlOperation) } else { + if (foundMethod.statement === null) { + foundMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement + } addMethodCorrespondence(foundMethod, umlOperation) } } @@ -104,6 +109,7 @@ routine createJavaClassMethod(uml::Operation umlOperation) { } update { javaMethod.name = umlOperation.name + javaMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement setJavaVisibility(javaMethod, umlOperation.visibility) addCorrespondenceBetween(umlOperation, javaMethod) setJavaMethodReturnType(umlOperation, umlOperation.getReturnResult) @@ -131,6 +137,7 @@ routine createJavaInterfaceMethod(uml::Operation umlOperation) { } update { javaMethod.name = umlOperation.name + javaMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement javaMethod.makePublic addCorrespondenceBetween(umlOperation, javaMethod) setJavaMethodReturnType(umlOperation, umlOperation.getReturnResult) diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaTypePropagation.reactions b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaTypePropagation.reactions index a49a91278..9519787e3 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaTypePropagation.reactions +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/uml2java/UmlToJavaTypePropagation.reactions @@ -1,6 +1,6 @@ import org.eclipse.uml2.uml.LiteralUnlimitedNatural -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.types.TypesFactory import tools.vitruv.applications.util.temporary.java.JavaModificationUtil import org.eclipse.uml2.uml.ParameterDirectionKind import static tools.vitruv.applications.umljava.util.UmlJavaTypePropagationHelper.* @@ -8,7 +8,7 @@ import static tools.vitruv.applications.util.temporary.java.JavaTypeUtil.* import org.eclipse.emf.ecore.util.EcoreUtil import "http://www.eclipse.org/uml2/5.0.0/UML" as uml -import "http://www.emftext.org/java" as java +import "https://mdsd.tools/jamopp/6.0.0/java" as java reactions: umlToJavaTypePropagation in reaction to changes in uml diff --git a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/util/UmlJavaTypePropagationHelper.xtend b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/util/UmlJavaTypePropagationHelper.xtend index 0753ed50b..98557546d 100644 --- a/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/util/UmlJavaTypePropagationHelper.xtend +++ b/bundles/tools.vitruv.applications.umljava/src/tools/vitruv/applications/umljava/util/UmlJavaTypePropagationHelper.xtend @@ -9,11 +9,11 @@ import org.apache.log4j.Logger import org.eclipse.uml2.uml.PrimitiveType import org.eclipse.uml2.uml.Type import org.eclipse.uml2.uml.UMLPackage -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.types.ClassifierReference -import org.emftext.language.java.types.NamespaceClassifierReference -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.types.ClassifierReference +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.TypesFactory import tools.vitruv.applications.util.temporary.java.JavaModificationUtil import tools.vitruv.change.interaction.UserInteractionOptions.WindowModality import tools.vitruv.change.interaction.UserInteractor @@ -58,7 +58,7 @@ class UmlJavaTypePropagationHelper { } def static dispatch Type getUmlTypeFromReference( - org.emftext.language.java.types.PrimitiveType jRef, + tools.mdsd.jamopp.model.java.types.PrimitiveType jRef, CorrespondenceRetriever correspondenceRetriever ) { return PrimitiveTypesPropagation.mapJavaPrimitiveTypeToUmlPrimitiveType(jRef, correspondenceRetriever) @@ -201,19 +201,19 @@ class UmlJavaTypePropagationHelper { * Returns null if there is no unified type for the given type. */ private def static UnifiedPrimitiveType getUnifiedNameForJavaPrimitiveTypeName( - org.emftext.language.java.types.PrimitiveType javaPrimitiveType) { + tools.mdsd.jamopp.model.java.types.PrimitiveType javaPrimitiveType) { switch (javaPrimitiveType) { - org.emftext.language.java.types.Boolean: UnifiedPrimitiveType.BOOLEAN - org.emftext.language.java.types.Char: UnifiedPrimitiveType.CHAR - org.emftext.language.java.types.Float: UnifiedPrimitiveType.FLOAT - org.emftext.language.java.types.Double: UnifiedPrimitiveType.DOUBLE - org.emftext.language.java.types.Int: UnifiedPrimitiveType.INT - org.emftext.language.java.types.Long: UnifiedPrimitiveType.LONG - org.emftext.language.java.types.Short: UnifiedPrimitiveType.SHORT + tools.mdsd.jamopp.model.java.types.Boolean: UnifiedPrimitiveType.BOOLEAN + tools.mdsd.jamopp.model.java.types.Char: UnifiedPrimitiveType.CHAR + tools.mdsd.jamopp.model.java.types.Float: UnifiedPrimitiveType.FLOAT + tools.mdsd.jamopp.model.java.types.Double: UnifiedPrimitiveType.DOUBLE + tools.mdsd.jamopp.model.java.types.Int: UnifiedPrimitiveType.INT + tools.mdsd.jamopp.model.java.types.Long: UnifiedPrimitiveType.LONG + tools.mdsd.jamopp.model.java.types.Short: UnifiedPrimitiveType.SHORT } } - private def static org.emftext.language.java.types.PrimitiveType unwrapWrappedPrimitiveType( + private def static tools.mdsd.jamopp.model.java.types.PrimitiveType unwrapWrappedPrimitiveType( TypeReference javaTypeReference) { val classifier = getNormalizedClassifierFromTypeReference(javaTypeReference) if(classifier === null) return null @@ -329,7 +329,7 @@ class UmlJavaTypePropagationHelper { } def static dispatch PrimitiveType mapJavaPrimitiveTypeToUmlPrimitiveType( - org.emftext.language.java.types.PrimitiveType javaTypeReference, + tools.mdsd.jamopp.model.java.types.PrimitiveType javaTypeReference, CorrespondenceRetriever correspondenceRetriever) { val unifiedPrimitiveType = javaTypeReference.unifiedNameForJavaPrimitiveTypeName if (unifiedPrimitiveType !== null) { diff --git a/bundles/tools.vitruv.applications.util.temporary/.project b/bundles/tools.vitruv.applications.util.temporary/.project index 9c10d9ddd..47976fbd8 100644 --- a/bundles/tools.vitruv.applications.util.temporary/.project +++ b/bundles/tools.vitruv.applications.util.temporary/.project @@ -26,7 +26,7 @@ - org.emftext.language.java.resource.java.builder + tools.mdsd.jamopp.model.java.resource.java.builder @@ -35,6 +35,5 @@ org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature org.eclipse.xtext.ui.shared.xtextNature - org.emftext.language.java.resource.java.nature diff --git a/bundles/tools.vitruv.applications.util.temporary/META-INF/MANIFEST.MF b/bundles/tools.vitruv.applications.util.temporary/META-INF/MANIFEST.MF index 229307f73..885fe11c7 100644 --- a/bundles/tools.vitruv.applications.util.temporary/META-INF/MANIFEST.MF +++ b/bundles/tools.vitruv.applications.util.temporary/META-INF/MANIFEST.MF @@ -9,8 +9,6 @@ Require-Bundle: com.google.guava, org.apache.log4j, org.eclipse.uml2.uml, org.eclipse.uml2.uml.resources, - org.emftext.language.java, - org.emftext.language.java.resource, org.eclipse.xtext.xbase.lib, org.eclipse.xtend.lib, org.eclipse.xtend.lib.macro, @@ -20,7 +18,9 @@ Require-Bundle: com.google.guava, edu.kit.ipd.sdq.commons.util.java, edu.kit.ipd.sdq.commons.util.emf, tools.vitruv.change.correspondence, - tools.vitruv.dsls.reactions.runtime + tools.vitruv.dsls.reactions.runtime, + tools.mdsd.jamopp.model;bundle-version="6.0.0", + tools.mdsd.jamopp.resource;bundle-version="6.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-17 Export-Package: tools.vitruv.applications.util.temporary.java, tools.vitruv.applications.util.temporary.uml, diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JamoppLibraryHelper.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JamoppLibraryHelper.xtend index 0197d4861..d490757ae 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JamoppLibraryHelper.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JamoppLibraryHelper.xtend @@ -1,11 +1,10 @@ package tools.vitruv.applications.util.temporary.java -import org.emftext.language.java.JavaClasspath -import org.emftext.language.java.JavaClasspath.Initializer -import org.eclipse.emf.ecore.resource.Resource +import java.nio.file.Path import org.eclipse.emf.common.util.URI +import tools.mdsd.jamopp.model.java.JavaClasspath + import static com.google.common.base.Preconditions.checkState -import java.nio.file.Path /** * This helper class allows to load the Java standard library in JaMoPP also with @@ -32,13 +31,6 @@ class JamoppLibraryHelper { // To do so, we disable automatic initialization of the standard library using the classpath // (where library cannot be found in Java 9 and above) and manually load the base Java module } else { - JavaClasspath.initializers.add(new Initializer() { - override initialize(Resource resource) {} - - override requiresLocalClasspath() { false } - - override requiresStdLib() { false } - }) registerStdLibraryModule(BASE_LIBRARY_NAME) } } @@ -55,9 +47,7 @@ class JamoppLibraryHelper { val modulePath = System.getProperty("java.home") + STANDARD_LIBRARY_FOLDER_IN_HOME + name + ".jmod" val moduleUri = URI.createFileURI(modulePath) - // From java 9, the module files do not directly contain the classes in the package structure - // but are placed in the "classes" folder, so that prefix has to be removed. - JavaClasspath.get().registerClassifierJar(moduleUri, "classes/"); + JavaClasspath.get().registerZip(moduleUri); } /** @@ -67,7 +57,7 @@ class JamoppLibraryHelper { * @param pathToLibrary - the path to the library to register */ static def void registerLocalLibrary(Path pathToLibrary) { - JavaClasspath.get().registerClassifierJar(URI.createFileURI(pathToLibrary.toString), ""); + JavaClasspath.get().registerZip(URI.createFileURI(pathToLibrary.toString)); } } diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaContainerAndClassifierUtil.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaContainerAndClassifierUtil.xtend index 80e12452d..abdbbb87c 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaContainerAndClassifierUtil.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaContainerAndClassifierUtil.xtend @@ -7,30 +7,30 @@ import java.util.ArrayList import java.util.Collections import java.util.Iterator import java.util.List -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.classifiers.Classifier -import org.emftext.language.java.classifiers.ClassifiersFactory -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.classifiers.Enumeration -import org.emftext.language.java.classifiers.Interface -import org.emftext.language.java.commons.NamedElement -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.ContainersFactory -import org.emftext.language.java.containers.Package -import org.emftext.language.java.members.Constructor -import org.emftext.language.java.members.EnumConstant -import org.emftext.language.java.members.Field -import org.emftext.language.java.members.Member -import org.emftext.language.java.parameters.Parameter -import org.emftext.language.java.types.NamespaceClassifierReference -import org.emftext.language.java.types.TypeReference +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.classifiers.Classifier +import tools.mdsd.jamopp.model.java.classifiers.ClassifiersFactory +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.classifiers.Enumeration +import tools.mdsd.jamopp.model.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.commons.NamedElement +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.ContainersFactory +import tools.mdsd.jamopp.model.java.containers.Package +import tools.mdsd.jamopp.model.java.members.Constructor +import tools.mdsd.jamopp.model.java.members.EnumConstant +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.members.Member +import tools.mdsd.jamopp.model.java.parameters.Parameter +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.types.TypeReference import static tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* import static tools.vitruv.applications.util.temporary.java.JavaTypeUtil.* import java.util.Optional -import org.emftext.language.java.commons.NamespaceAwareElement +import tools.mdsd.jamopp.model.java.commons.NamespaceAwareElement import static java.util.Collections.emptyList -import org.emftext.language.java.containers.ContainersPackage +import tools.mdsd.jamopp.model.java.containers.ContainersPackage import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util.URIUtil.isPathmap import tools.vitruv.change.correspondence.view.EditableCorrespondenceModelView @@ -183,13 +183,8 @@ class JavaContainerAndClassifierUtil { } } - def static removeJavaClassifierFromPackage(Package jPackage, ConcreteClassifier jClassifier) { - val iter = jPackage.compilationUnits.iterator - while (iter.hasNext) { - if (iter.next.name.equals(jClassifier.name)) { - iter.remove - } - } + def static removeJavaClassifierFromPackage(ConcreteClassifier jClassifier) { + jClassifier.package = null; } def static File createPackageInfo(String directory, String packageName) { @@ -212,7 +207,7 @@ class JavaContainerAndClassifierUtil { */ static def T findClassifier(String name, Package javaPackage, java.lang.Class classifierType) { - val matchingClassifiers = javaPackage.compilationUnits.map[it.classifiers].flatten.filter(classifierType).filter [ + val matchingClassifiers = javaPackage.classifiers.filter(classifierType).filter [ it.name.toFirstUpper == name.toFirstUpper ] if (matchingClassifiers.size > 1) diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaMemberAndParameterUtil.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaMemberAndParameterUtil.xtend index 3d5383ffd..ca9faa458 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaMemberAndParameterUtil.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaMemberAndParameterUtil.xtend @@ -10,30 +10,30 @@ import org.eclipse.emf.common.util.ECollections import org.eclipse.emf.common.util.EList import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.expressions.AssignmentExpression -import org.emftext.language.java.expressions.ExpressionsFactory -import org.emftext.language.java.literals.LiteralsFactory -import org.emftext.language.java.members.ClassMethod -import org.emftext.language.java.members.Constructor -import org.emftext.language.java.members.EnumConstant -import org.emftext.language.java.members.Field -import org.emftext.language.java.members.MembersFactory -import org.emftext.language.java.members.Method -import org.emftext.language.java.modifiers.Modifier -import org.emftext.language.java.modifiers.ModifiersFactory -import org.emftext.language.java.modifiers.Public -import org.emftext.language.java.operators.OperatorsFactory -import org.emftext.language.java.parameters.Parameter -import org.emftext.language.java.parameters.ParametersFactory -import org.emftext.language.java.parameters.Parametrizable -import org.emftext.language.java.references.ReferencesFactory -import org.emftext.language.java.statements.ExpressionStatement -import org.emftext.language.java.statements.Return -import org.emftext.language.java.statements.StatementsFactory -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.expressions.AssignmentExpression +import tools.mdsd.jamopp.model.java.expressions.ExpressionsFactory +import tools.mdsd.jamopp.model.java.literals.LiteralsFactory +import tools.mdsd.jamopp.model.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.members.Constructor +import tools.mdsd.jamopp.model.java.members.EnumConstant +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.members.MembersFactory +import tools.mdsd.jamopp.model.java.members.Method +import tools.mdsd.jamopp.model.java.modifiers.Modifier +import tools.mdsd.jamopp.model.java.modifiers.ModifiersFactory +import tools.mdsd.jamopp.model.java.modifiers.Public +import tools.mdsd.jamopp.model.java.operators.OperatorsFactory +import tools.mdsd.jamopp.model.java.parameters.Parameter +import tools.mdsd.jamopp.model.java.parameters.ParametersFactory +import tools.mdsd.jamopp.model.java.parameters.Parametrizable +import tools.mdsd.jamopp.model.java.references.ReferencesFactory +import tools.mdsd.jamopp.model.java.statements.ExpressionStatement +import tools.mdsd.jamopp.model.java.statements.Return +import tools.mdsd.jamopp.model.java.statements.StatementsFactory +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.TypesFactory import static tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* import static tools.vitruv.applications.util.temporary.java.JavaStatementUtil.* @@ -70,6 +70,7 @@ class JavaMemberAndParameterUtil { */ def static createJavaClassMethod(String name, TypeReference returnType, JavaVisibility visibility, boolean abstr, boolean stat, List params) { val jMethod = MembersFactory.eINSTANCE.createClassMethod + jMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement setName(jMethod, name) setTypeReference(jMethod, returnType) setJavaVisibilityModifier(jMethod, visibility) @@ -91,6 +92,7 @@ class JavaMemberAndParameterUtil { */ def static createJavaInterfaceMethod(String name, TypeReference returnType, List params) { val jMethod = MembersFactory.eINSTANCE.createInterfaceMethod + jMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement setName(jMethod, name) setTypeReference(jMethod, returnType) jMethod.makePublic @@ -160,6 +162,7 @@ class JavaMemberAndParameterUtil { */ def static Constructor addJavaConstructorToClass(Class jClass, JavaVisibility visibility, List params) { val constructor = MembersFactory.eINSTANCE.createConstructor + constructor.block = StatementsFactory.eINSTANCE.createBlock setName(constructor, jClass.name) addParametersIfNotNull(constructor, params) setJavaVisibilityModifier(constructor, visibility) @@ -177,6 +180,7 @@ class JavaMemberAndParameterUtil { */ def static createJavaConstructorAndAddToClass(Class jClass, JavaVisibility visibility) { val constructor = MembersFactory.eINSTANCE.createConstructor + constructor.block = StatementsFactory.eINSTANCE.createBlock constructor.name = jClass.name setJavaVisibilityModifier(constructor, visibility) jClass.members += constructor @@ -187,6 +191,7 @@ class JavaMemberAndParameterUtil { val constructors = javaClass.members.filter[it instanceof Constructor].map[it as Constructor] if (constructors.nullOrEmpty) { val Constructor constructor = MembersFactory.eINSTANCE.createConstructor + constructor.block = StatementsFactory.eINSTANCE.createBlock return addConstructorToClass(constructor, javaClass) } return constructors.iterator.next @@ -244,11 +249,16 @@ class JavaMemberAndParameterUtil { assigmentExpression.value = identifierReference expressionStatement.expression = assigmentExpression method.statements.add(expressionStatement) + + if (method.statement === null) { + method.statement = StatementsFactory.eINSTANCE.createEmptyStatement + } + return method } - def static createGetter(Field field, ClassMethod method) { - method.name = "get" + field.name.toFirstUpper + def static createGetter(Field field, ClassMethod method) { + method.name = "get" + field.name.toFirstUpper method.annotationsAndModifiers.add(ModifiersFactory.eINSTANCE.createPublic) method.typeReference = EcoreUtil.copy(field.typeReference) @@ -260,6 +270,11 @@ class JavaMemberAndParameterUtil { val ret = StatementsFactory.eINSTANCE.createReturn ret.returnValue = identifierRef method.statements.add(ret) + + if (method.statement === null) { + method.statement = StatementsFactory.eINSTANCE.createEmptyStatement + } + return method } @@ -420,6 +435,9 @@ class JavaMemberAndParameterUtil { def static initializeClassMethod(ClassMethod classMethod, String name, TypeReference typeReference, Modifier[] modifiers, Parameter[] parameters, boolean ensurePublic) { classMethod.name = name + if (null === classMethod.statement) { + classMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement + } if (null !== typeReference) { classMethod.typeReference = EcoreUtil.copy(typeReference) } diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaModificationUtil.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaModificationUtil.xtend index 03ed8548e..b54b10791 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaModificationUtil.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaModificationUtil.xtend @@ -2,41 +2,41 @@ package tools.vitruv.applications.util.temporary.java import edu.kit.ipd.sdq.activextendannotations.Utility import org.apache.log4j.Logger -import org.emftext.language.java.types.NamespaceClassifierReference -import org.emftext.language.java.types.TypesFactory -import org.emftext.language.java.parameters.Parameter -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.parameters.ParametersFactory -import org.emftext.language.java.statements.StatementsFactory -import org.emftext.language.java.expressions.ExpressionsFactory -import org.emftext.language.java.members.Field -import org.emftext.language.java.statements.Statement -import org.emftext.language.java.references.ReferencesFactory -import org.emftext.language.java.literals.LiteralsFactory -import org.emftext.language.java.operators.OperatorsFactory -import org.emftext.language.java.imports.Import -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.classifiers.Classifier -import org.emftext.language.java.imports.ImportsFactory -import org.emftext.language.java.types.PrimitiveType -import org.emftext.language.java.types.Char -import org.emftext.language.java.types.Int +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.parameters.Parameter +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.parameters.ParametersFactory +import tools.mdsd.jamopp.model.java.statements.StatementsFactory +import tools.mdsd.jamopp.model.java.expressions.ExpressionsFactory +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.statements.Statement +import tools.mdsd.jamopp.model.java.references.ReferencesFactory +import tools.mdsd.jamopp.model.java.literals.LiteralsFactory +import tools.mdsd.jamopp.model.java.operators.OperatorsFactory +import tools.mdsd.jamopp.model.java.imports.Import +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.classifiers.Classifier +import tools.mdsd.jamopp.model.java.imports.ImportsFactory +import tools.mdsd.jamopp.model.java.types.PrimitiveType +import tools.mdsd.jamopp.model.java.types.Char +import tools.mdsd.jamopp.model.java.types.Int import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.modifiers.ModifiersFactory -import org.emftext.language.java.imports.ClassifierImport -import org.emftext.language.java.JavaClasspath +import tools.mdsd.jamopp.model.java.modifiers.ModifiersFactory +import tools.mdsd.jamopp.model.java.imports.ClassifierImport +import tools.mdsd.jamopp.model.java.JavaClasspath import static tools.vitruv.applications.util.temporary.java.JavaQueryUtil.* -import org.emftext.language.java.modifiers.AnnotableAndModifiable -import org.emftext.language.java.annotations.AnnotationsFactory -import org.emftext.language.java.classifiers.ClassifiersFactory +import tools.mdsd.jamopp.model.java.modifiers.AnnotableAndModifiable +import tools.mdsd.jamopp.model.java.annotations.AnnotationsFactory +import tools.mdsd.jamopp.model.java.classifiers.ClassifiersFactory import java.util.List -import org.emftext.language.java.members.Constructor -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.members.MembersFactory -import org.emftext.language.java.instantiations.NewConstructorCall -import org.emftext.language.java.references.IdentifierReference +import tools.mdsd.jamopp.model.java.members.Constructor +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.members.MembersFactory +import tools.mdsd.jamopp.model.java.instantiations.NewConstructorCall +import tools.mdsd.jamopp.model.java.references.IdentifierReference import java.util.ArrayList -import org.emftext.language.java.references.ReferenceableElement +import tools.mdsd.jamopp.model.java.references.ReferenceableElement @Utility class JavaModificationUtil { @@ -165,7 +165,7 @@ class JavaModificationUtil { } def dispatch static TypeReference getWrapperTypeReferenceForPrimitiveType( - org.emftext.language.java.types.Void type) { + tools.mdsd.jamopp.model.java.types.Void type) { createNamespaceClassifierReferenceForName("java.lang", "Void") } @@ -192,7 +192,7 @@ class JavaModificationUtil { def static ConcreteClassifier getClassifier(String qualifiedName) { // To resolve classifiers from the Java standard library, this requires the Java standard library to be // registered (JavaClasspath.get().registerStdLib). Should be done by the domain by default. - JavaClasspath.get().getClassifier(qualifiedName) as ConcreteClassifier + JavaClasspath.get().getConcreteClassifier(qualifiedName) as ConcreteClassifier } def static addAnnotationToAnnotableAndModifiable(AnnotableAndModifiable annotableAndModifiable, @@ -221,6 +221,7 @@ class JavaModificationUtil { def static addConstructorToClass(Class javaClass) { val Constructor constructor = MembersFactory.eINSTANCE.createConstructor + constructor.block = StatementsFactory.eINSTANCE.createBlock addConstructorToClass(constructor, javaClass) } diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaModifierUtil.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaModifierUtil.xtend index 35c80d518..b378ba574 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaModifierUtil.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaModifierUtil.xtend @@ -3,15 +3,15 @@ package tools.vitruv.applications.util.temporary.java import edu.kit.ipd.sdq.activextendannotations.Utility import org.apache.log4j.Logger import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.commons.NamedElement -import org.emftext.language.java.modifiers.AnnotableAndModifiable -import org.emftext.language.java.modifiers.Modifier -import org.emftext.language.java.modifiers.ModifiersFactory -import org.emftext.language.java.modifiers.Private -import org.emftext.language.java.modifiers.Protected -import org.emftext.language.java.modifiers.Public +import tools.mdsd.jamopp.model.java.commons.NamedElement +import tools.mdsd.jamopp.model.java.modifiers.AnnotableAndModifiable +import tools.mdsd.jamopp.model.java.modifiers.Modifier +import tools.mdsd.jamopp.model.java.modifiers.ModifiersFactory +import tools.mdsd.jamopp.model.java.modifiers.Private +import tools.mdsd.jamopp.model.java.modifiers.Protected +import tools.mdsd.jamopp.model.java.modifiers.Public import java.util.List -import org.emftext.language.java.modifiers.AnnotationInstanceOrModifier +import tools.mdsd.jamopp.model.java.modifiers.AnnotationInstanceOrModifier import java.util.Objects /** diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaPersistenceHelper.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaPersistenceHelper.xtend index b810e9f8d..d737a7ba4 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaPersistenceHelper.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaPersistenceHelper.xtend @@ -1,8 +1,8 @@ package tools.vitruv.applications.util.temporary.java import java.util.Arrays -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.Package +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.Package import static com.google.common.base.Preconditions.checkState class JavaPersistenceHelper { diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaQueryUtil.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaQueryUtil.xtend index e5383b29a..add80f623 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaQueryUtil.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaQueryUtil.xtend @@ -1,9 +1,9 @@ package tools.vitruv.applications.util.temporary.java -import org.emftext.language.java.types.Char -import org.emftext.language.java.types.Int -import org.emftext.language.java.types.ClassifierReference -import org.emftext.language.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.types.Char +import tools.mdsd.jamopp.model.java.types.Int +import tools.mdsd.jamopp.model.java.types.ClassifierReference +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference class JavaQueryUtil { @@ -19,11 +19,11 @@ class JavaQueryUtil { // return getNameFromJaMoPPType(classRef) } - def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Boolean reference) { + def dispatch static getNameFromJaMoPPType(tools.mdsd.jamopp.model.java.types.Boolean reference) { return "boolean" } - def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Byte reference) { + def dispatch static getNameFromJaMoPPType(tools.mdsd.jamopp.model.java.types.Byte reference) { return "byte" } @@ -31,11 +31,11 @@ class JavaQueryUtil { return "char" } - def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Double reference) { + def dispatch static getNameFromJaMoPPType(tools.mdsd.jamopp.model.java.types.Double reference) { return "double" } - def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Float reference) { + def dispatch static getNameFromJaMoPPType(tools.mdsd.jamopp.model.java.types.Float reference) { return "float" } @@ -43,15 +43,15 @@ class JavaQueryUtil { return "int" } - def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Long reference) { + def dispatch static getNameFromJaMoPPType(tools.mdsd.jamopp.model.java.types.Long reference) { return "long" } - def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Short reference) { + def dispatch static getNameFromJaMoPPType(tools.mdsd.jamopp.model.java.types.Short reference) { return "short" } - def dispatch static getNameFromJaMoPPType(org.emftext.language.java.types.Void reference) { + def dispatch static getNameFromJaMoPPType(tools.mdsd.jamopp.model.java.types.Void reference) { return "void" } } \ No newline at end of file diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaSetup.java b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaSetup.java index 5059fdf7d..f7aa89bdb 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaSetup.java +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaSetup.java @@ -3,8 +3,8 @@ import java.util.function.Supplier; import org.eclipse.emf.ecore.resource.Resource; -import org.emftext.language.java.JavaClasspath; -import org.emftext.language.java.resource.JavaSourceOrClassFileResourceFactoryImpl; +import tools.mdsd.jamopp.model.java.JavaClasspath; +import tools.mdsd.jamopp.resource.JavaResource2Factory; public final class JavaSetup { private JavaSetup() { @@ -23,7 +23,7 @@ public static void prepareFactories(Supplier resourceFactoryPr * Prepares for using Java without an OSGI environment registering file extensions for the default resource factories. */ public static void prepareFactories() { - prepareFactories(() -> new JavaSourceOrClassFileResourceFactoryImpl()); + prepareFactories(() -> new JavaResource2Factory()); } /** @@ -33,7 +33,7 @@ public static void prepareFactories() { * @see JamoppLibraryHelper#registerStdLib() */ public static void resetClasspathAndRegisterStandardLibrary() { - JavaClasspath.reset(); + JavaClasspath.get().clear(); JamoppLibraryHelper.registerStdLib(); } diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaStandardType.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaStandardType.xtend index 5651a12d0..6953d40a6 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaStandardType.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaStandardType.xtend @@ -1,17 +1,17 @@ package tools.vitruv.applications.util.temporary.java import edu.kit.ipd.sdq.activextendannotations.Utility -import org.emftext.language.java.types.Boolean -import org.emftext.language.java.types.Byte -import org.emftext.language.java.types.Char -import org.emftext.language.java.types.Double -import org.emftext.language.java.types.Float -import org.emftext.language.java.types.Int -import org.emftext.language.java.types.Long -import org.emftext.language.java.types.PrimitiveType -import org.emftext.language.java.types.Short -import org.emftext.language.java.types.TypesFactory -import org.emftext.language.java.types.Void +import tools.mdsd.jamopp.model.java.types.Boolean +import tools.mdsd.jamopp.model.java.types.Byte +import tools.mdsd.jamopp.model.java.types.Char +import tools.mdsd.jamopp.model.java.types.Double +import tools.mdsd.jamopp.model.java.types.Float +import tools.mdsd.jamopp.model.java.types.Int +import tools.mdsd.jamopp.model.java.types.Long +import tools.mdsd.jamopp.model.java.types.PrimitiveType +import tools.mdsd.jamopp.model.java.types.Short +import tools.mdsd.jamopp.model.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.types.Void import static tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil.* import static tools.vitruv.applications.util.temporary.java.JavaModificationUtil.* diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaStatementUtil.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaStatementUtil.xtend index f0e1165dd..ff7c273d9 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaStatementUtil.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaStatementUtil.xtend @@ -2,26 +2,26 @@ package tools.vitruv.applications.util.temporary.java import edu.kit.ipd.sdq.activextendannotations.Utility import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.expressions.AssignmentExpression -import org.emftext.language.java.expressions.AssignmentExpressionChild -import org.emftext.language.java.expressions.EqualityExpression -import org.emftext.language.java.expressions.EqualityExpressionChild -import org.emftext.language.java.expressions.Expression -import org.emftext.language.java.expressions.ExpressionsFactory -import org.emftext.language.java.literals.LiteralsFactory -import org.emftext.language.java.literals.This -import org.emftext.language.java.members.Field -import org.emftext.language.java.operators.AssignmentOperator -import org.emftext.language.java.operators.EqualityOperator -import org.emftext.language.java.references.IdentifierReference -import org.emftext.language.java.references.ReferenceableElement -import org.emftext.language.java.references.ReferencesFactory -import org.emftext.language.java.references.SelfReference -import org.emftext.language.java.statements.Condition -import org.emftext.language.java.statements.ExpressionStatement -import org.emftext.language.java.statements.Return -import org.emftext.language.java.statements.Statement -import org.emftext.language.java.statements.StatementsFactory +import tools.mdsd.jamopp.model.java.expressions.AssignmentExpression +import tools.mdsd.jamopp.model.java.expressions.AssignmentExpressionChild +import tools.mdsd.jamopp.model.java.expressions.EqualityExpression +import tools.mdsd.jamopp.model.java.expressions.EqualityExpressionChild +import tools.mdsd.jamopp.model.java.expressions.Expression +import tools.mdsd.jamopp.model.java.expressions.ExpressionsFactory +import tools.mdsd.jamopp.model.java.literals.LiteralsFactory +import tools.mdsd.jamopp.model.java.literals.This +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.operators.AssignmentOperator +import tools.mdsd.jamopp.model.java.operators.EqualityOperator +import tools.mdsd.jamopp.model.java.references.IdentifierReference +import tools.mdsd.jamopp.model.java.references.ReferenceableElement +import tools.mdsd.jamopp.model.java.references.ReferencesFactory +import tools.mdsd.jamopp.model.java.references.SelfReference +import tools.mdsd.jamopp.model.java.statements.Condition +import tools.mdsd.jamopp.model.java.statements.ExpressionStatement +import tools.mdsd.jamopp.model.java.statements.Return +import tools.mdsd.jamopp.model.java.statements.Statement +import tools.mdsd.jamopp.model.java.statements.StatementsFactory /** * Util class for the creation and retrieving of statements. diff --git a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaTypeUtil.xtend b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaTypeUtil.xtend index 7e6028984..44c6fc87b 100644 --- a/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaTypeUtil.xtend +++ b/bundles/tools.vitruv.applications.util.temporary/src/tools/vitruv/applications/util/temporary/java/JavaTypeUtil.xtend @@ -9,21 +9,21 @@ import org.apache.log4j.Logger import org.eclipse.emf.common.util.BasicEList import org.eclipse.emf.common.util.EList import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.classifiers.Classifier -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.classifiers.Interface -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.generics.GenericsFactory -import org.emftext.language.java.generics.QualifiedTypeArgument -import org.emftext.language.java.imports.ClassifierImport -import org.emftext.language.java.imports.ImportsFactory -import org.emftext.language.java.types.ClassifierReference -import org.emftext.language.java.types.NamespaceClassifierReference -import org.emftext.language.java.types.PrimitiveType -import org.emftext.language.java.types.Type -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.types.TypedElement -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.classifiers.Classifier +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.generics.GenericsFactory +import tools.mdsd.jamopp.model.java.generics.QualifiedTypeArgument +import tools.mdsd.jamopp.model.java.imports.ClassifierImport +import tools.mdsd.jamopp.model.java.imports.ImportsFactory +import tools.mdsd.jamopp.model.java.types.ClassifierReference +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.types.PrimitiveType +import tools.mdsd.jamopp.model.java.types.Type +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.TypedElement +import tools.mdsd.jamopp.model.java.types.TypesFactory import static tools.vitruv.applications.util.temporary.other.UriUtil.normalizeURI import static tools.vitruv.applications.util.temporary.java.JavaModificationUtil.* diff --git a/releng/tools.vitruv.casestudies.dependencywrapper/META-INF/MANIFEST.MF b/releng/tools.vitruv.casestudies.dependencywrapper/META-INF/MANIFEST.MF index 20df567e6..05b6a638c 100644 --- a/releng/tools.vitruv.casestudies.dependencywrapper/META-INF/MANIFEST.MF +++ b/releng/tools.vitruv.casestudies.dependencywrapper/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: tools.vitruv.dsls.reactions, tools.vitruv.dsls.demo.insurancefamilies, tools.vitruv.dsls.demo.insurancefamilies.tests, tools.vitruv.dsls.demo.insurancepersons, + tools.vitruv.dsls.demo.insurancepersons.tests, + tools.mdsd.jamopp.model;bundle-version="6.0.0", edu.kit.ipd.sdq.metamodels.autosar, - edu.kit.ipd.sdq.metamodels.simulink, - tools.vitruv.dsls.demo.insurancepersons.tests + edu.kit.ipd.sdq.metamodels.simulink Bundle-Vendor: tools.vitruv diff --git a/releng/tools.vitruv.casestudies.parent/pom.xml b/releng/tools.vitruv.casestudies.parent/pom.xml index a0cfb89f7..c63e836fe 100644 --- a/releng/tools.vitruv.casestudies.parent/pom.xml +++ b/releng/tools.vitruv.casestudies.parent/pom.xml @@ -56,6 +56,11 @@ p2 https://kit-sdq.github.io/updatesite/release/p2-wrapper/latest/ + + JaMoPP Extended + p2 + https://updatesite.mdsd.tools/extended-java-model-parser-and-printer/nightly/ + Palladiosimulator p2 diff --git a/tests/tools.vitruv.applications.pcmjava.tests/META-INF/MANIFEST.MF b/tests/tools.vitruv.applications.pcmjava.tests/META-INF/MANIFEST.MF index 4ae77b6a4..d6d5c2042 100644 --- a/tests/tools.vitruv.applications.pcmjava.tests/META-INF/MANIFEST.MF +++ b/tests/tools.vitruv.applications.pcmjava.tests/META-INF/MANIFEST.MF @@ -9,7 +9,6 @@ Import-Package: org.junit.jupiter.api Require-Bundle: org.apache.log4j, com.google.guava, org.hamcrest.core, - org.emftext.language.java.resource.java, edu.kit.ipd.sdq.commons.util.java, tools.vitruv.testutils.vsum, tools.vitruv.applications.util.temporary, @@ -17,7 +16,9 @@ Require-Bundle: org.apache.log4j, org.eclipse.xtext.xbase.lib, org.eclipse.xtend.lib, org.eclipse.xtend.lib.macro, - edu.kit.ipd.sdq.activextendannotations + edu.kit.ipd.sdq.activextendannotations, + tools.mdsd.jamopp.model;bundle-version="6.0.0", + tools.mdsd.jamopp.resource;bundle-version="6.0.0" Export-Package: tools.vitruv.applications.pcmjava.tests.pcm2java, tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper Bundle-Vendor: vitruv.tools diff --git a/tests/tools.vitruv.applications.pcmjava.tests/build.properties b/tests/tools.vitruv.applications.pcmjava.tests/build.properties index 60db6405f..92c3f7646 100644 --- a/tests/tools.vitruv.applications.pcmjava.tests/build.properties +++ b/tests/tools.vitruv.applications.pcmjava.tests/build.properties @@ -3,11 +3,7 @@ source.. = src/,\ bin.includes = META-INF/,\ . bin = target/classes/ -additional.bundles = org.emftext.language.java.resource,\ - org.emftext.commons.antlr3_4_0,\ - org.emftext.language.java.resource.java,\ - org.emftext.language.java.resource.bcel,\ - org.palladiosimulator.pcm,\ +additional.bundles = org.palladiosimulator.pcm,\ org.palladiosimulator.pcm.resources,\ org.eclipse.emf.transaction,\ org.eclipse.core.expressions,\ diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/JaMoPPTest.java b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/JaMoPPTest.java index e42f72820..f3eeb6d50 100755 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/JaMoPPTest.java +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/JaMoPPTest.java @@ -11,20 +11,22 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.emftext.commons.layout.LayoutInformation; -import org.emftext.language.java.JavaPackage; -import org.emftext.language.java.classifiers.ClassifiersFactory; -import org.emftext.language.java.classifiers.ConcreteClassifier; -import org.emftext.language.java.classifiers.Interface; -import org.emftext.language.java.commons.NamedElement; -import org.emftext.language.java.containers.CompilationUnit; -import org.emftext.language.java.containers.ContainersFactory; -import org.emftext.language.java.containers.Package; -import org.emftext.language.java.members.InterfaceMethod; -import org.emftext.language.java.members.Member; -import org.emftext.language.java.members.MembersFactory; -import org.emftext.language.java.resource.java.mopp.JavaResourceFactory; -import org.emftext.language.java.types.TypesFactory; +import tools.mdsd.jamopp.model.java.JavaPackage; +import tools.mdsd.jamopp.model.java.classifiers.ClassifiersFactory; +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier; +import tools.mdsd.jamopp.model.java.classifiers.Interface; +import tools.mdsd.jamopp.model.java.commons.NamedElement; +import tools.mdsd.jamopp.model.java.containers.CompilationUnit; +import tools.mdsd.jamopp.model.java.containers.ContainersFactory; +import tools.mdsd.jamopp.model.java.containers.Package; +import tools.mdsd.jamopp.model.java.members.InterfaceMethod; +import tools.mdsd.jamopp.model.java.members.Member; +import tools.mdsd.jamopp.model.java.members.MembersFactory; +import tools.mdsd.jamopp.model.java.statements.StatementsFactory; +import tools.mdsd.jamopp.model.java.types.TypesFactory; +import tools.mdsd.jamopp.resource.JavaResource2Factory; +import tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,8 +39,8 @@ public void setUp() throws Exception { EPackage.Registry.INSTANCE.put(JavaPackage.eNS_URI, JavaPackage.eINSTANCE); final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; final Map m = reg.getExtensionToFactoryMap(); - m.put("java", new JavaResourceFactory()); - m.put("", new JavaResourceFactory()); + m.put("java", new JavaResource2Factory()); + m.put("", new JavaResource2Factory()); } @Test @@ -49,7 +51,7 @@ public void testJaMoPPRename() throws IOException { final CompilationUnit jaMoPPCompilationUnit = ContainersFactory.eINSTANCE.createCompilationUnit(); jaMoPPCompilationUnit.setName("TestJava.java"); jaMoPPCompilationUnit.getClassifiers().add(jaMoPPInterface); - jaMoPPPackage.getCompilationUnits().add(jaMoPPCompilationUnit); + JavaContainerAndClassifierUtil.updateNamespaces(jaMoPPCompilationUnit, jaMoPPPackage); jaMoPPPackage.setName("testJaMoPPPackage"); final ResourceSet resourceSet = new ResourceSetImpl(); String uriStr = "src/testpackage/" + jaMoPPCompilationUnit.getName(); @@ -98,6 +100,7 @@ public void testAddInterfaceMethod() throws IOException { final InterfaceMethod ifMethod = MembersFactory.eINSTANCE.createInterfaceMethod(); ifMethod.setName("testMethod"); ifMethod.setTypeReference(TypesFactory.eINSTANCE.createVoid()); + ifMethod.setStatement(StatementsFactory.eINSTANCE.createEmptyStatement()); resource.getContents().add(cu); resource.save(null); jaIf.getMembers().add(ifMethod); @@ -132,7 +135,7 @@ protected void assertLayoutInfosInResource(final Resource resource) { private void printLayoutInformation(final NamedElement namedElement) { LOGGER.trace("commenatable.getLayoutInformations(): " + namedElement.getLayoutInformations()); - for (final LayoutInformation layoutInformation : namedElement.getLayoutInformations()) { + for (final tools.mdsd.jamopp.model.commons.layout.LayoutInformation layoutInformation : namedElement.getLayoutInformations()) { final int startOffset = layoutInformation.getStartOffset(); LOGGER.trace("Start offset for " + namedElement.getName() + ": " + startOffset); } diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/JavaQueryUtil.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/JavaQueryUtil.xtend index 87ac421a7..43577ecd2 100755 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/JavaQueryUtil.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/JavaQueryUtil.xtend @@ -1,8 +1,8 @@ package tools.vitruv.applications.pcmjava.tests.pcm2java import edu.kit.ipd.sdq.activextendannotations.Utility -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.Package +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.Package import tools.vitruv.framework.views.View import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.claimOne diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/Pcm2JavaTransformationTest.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/Pcm2JavaTransformationTest.xtend index 01f55dbf6..c765e0863 100755 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/Pcm2JavaTransformationTest.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/Pcm2JavaTransformationTest.xtend @@ -10,9 +10,9 @@ import org.eclipse.emf.common.util.ECollections import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.util.EcoreUtil import org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper -import org.emftext.language.java.commons.NamedElement -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.Package +import tools.mdsd.jamopp.model.java.commons.NamedElement +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.Package import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach import org.palladiosimulator.pcm.repository.Repository diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/Pcm2JavaViewFactory.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/Pcm2JavaViewFactory.xtend index 14bb5a93f..97066c80e 100755 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/Pcm2JavaViewFactory.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/Pcm2JavaViewFactory.xtend @@ -1,8 +1,8 @@ package tools.vitruv.applications.pcmjava.tests.pcm2java import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.Package +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.Package import org.palladiosimulator.pcm.repository.Repository import org.palladiosimulator.pcm.system.System import tools.vitruv.framework.views.View diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/FluentJavaClassBuilder.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/FluentJavaClassBuilder.xtend index 31708bacd..402f55edc 100755 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/FluentJavaClassBuilder.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/FluentJavaClassBuilder.xtend @@ -4,25 +4,25 @@ import edu.kit.ipd.sdq.commons.util.java.Pair import java.util.ArrayList import java.util.List import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.expressions.ExpressionsFactory -import org.emftext.language.java.imports.Import -import org.emftext.language.java.imports.ImportsFactory -import org.emftext.language.java.instantiations.InstantiationsFactory -import org.emftext.language.java.literals.LiteralsFactory -import org.emftext.language.java.members.ClassMethod -import org.emftext.language.java.members.Constructor -import org.emftext.language.java.members.Field -import org.emftext.language.java.members.MembersFactory -import org.emftext.language.java.modifiers.ModifiersFactory -import org.emftext.language.java.operators.OperatorsFactory -import org.emftext.language.java.parameters.Parameter -import org.emftext.language.java.parameters.ParametersFactory -import org.emftext.language.java.references.ReferencesFactory -import org.emftext.language.java.statements.Statement -import org.emftext.language.java.statements.StatementsFactory -import org.emftext.language.java.types.TypeReference +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.expressions.ExpressionsFactory +import tools.mdsd.jamopp.model.java.imports.Import +import tools.mdsd.jamopp.model.java.imports.ImportsFactory +import tools.mdsd.jamopp.model.java.instantiations.InstantiationsFactory +import tools.mdsd.jamopp.model.java.literals.LiteralsFactory +import tools.mdsd.jamopp.model.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.members.Constructor +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.members.MembersFactory +import tools.mdsd.jamopp.model.java.modifiers.ModifiersFactory +import tools.mdsd.jamopp.model.java.operators.OperatorsFactory +import tools.mdsd.jamopp.model.java.parameters.Parameter +import tools.mdsd.jamopp.model.java.parameters.ParametersFactory +import tools.mdsd.jamopp.model.java.references.ReferencesFactory +import tools.mdsd.jamopp.model.java.statements.Statement +import tools.mdsd.jamopp.model.java.statements.StatementsFactory +import tools.mdsd.jamopp.model.java.types.TypeReference import static tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper.JavaCreatorsUtil.captialize import static tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper.JavaCreatorsUtil.createClass @@ -215,7 +215,7 @@ class FluentJavaClassBuilder { private def Constructor createConstructor_(Class classifier) { val constructor = MembersFactory.eINSTANCE.createConstructor - + constructor.block = StatementsFactory.eINSTANCE.createBlock constructor.name = classifier.name constructor.makePublic diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/FluentJavaInterfaceBuilder.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/FluentJavaInterfaceBuilder.xtend index c167d154b..3313cd5ef 100755 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/FluentJavaInterfaceBuilder.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/FluentJavaInterfaceBuilder.xtend @@ -3,11 +3,11 @@ package tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper import java.util.ArrayList import java.util.List import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.imports.Import -import org.emftext.language.java.imports.ImportsFactory -import org.emftext.language.java.modifiers.ModifiersFactory -import org.emftext.language.java.parameters.ParametersFactory +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.imports.Import +import tools.mdsd.jamopp.model.java.imports.ImportsFactory +import tools.mdsd.jamopp.model.java.modifiers.ModifiersFactory +import tools.mdsd.jamopp.model.java.parameters.ParametersFactory import static tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper.JavaCreatorsUtil.createCompilationUnit import static tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper.JavaCreatorsUtil.createInterface diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/JavaCreatorsUtil.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/JavaCreatorsUtil.xtend index 764e3f9bd..21df18bf8 100755 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/JavaCreatorsUtil.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/JavaCreatorsUtil.xtend @@ -1,26 +1,27 @@ package tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper import edu.kit.ipd.sdq.activextendannotations.Utility -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.classifiers.ClassifiersFactory -import org.emftext.language.java.classifiers.Interface -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.ContainersFactory -import org.emftext.language.java.containers.Package -import org.emftext.language.java.generics.GenericsFactory -import org.emftext.language.java.members.ClassMethod -import org.emftext.language.java.members.Field -import org.emftext.language.java.members.InterfaceMethod -import org.emftext.language.java.members.MembersFactory -import org.emftext.language.java.types.Boolean -import org.emftext.language.java.types.Int -import org.emftext.language.java.types.NamespaceClassifierReference -import org.emftext.language.java.types.PrimitiveType -import org.emftext.language.java.types.TypesFactory -import org.emftext.language.java.types.Void +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.classifiers.ClassifiersFactory +import tools.mdsd.jamopp.model.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.ContainersFactory +import tools.mdsd.jamopp.model.java.containers.Package +import tools.mdsd.jamopp.model.java.generics.GenericsFactory +import tools.mdsd.jamopp.model.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.members.InterfaceMethod +import tools.mdsd.jamopp.model.java.members.MembersFactory +import tools.mdsd.jamopp.model.java.types.Boolean +import tools.mdsd.jamopp.model.java.types.Int +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.types.PrimitiveType +import tools.mdsd.jamopp.model.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.types.Void import org.palladiosimulator.pcm.repository.PrimitiveTypeEnum import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.claimOne +import tools.mdsd.jamopp.model.java.statements.StatementsFactory // TODO: merge this class with similar classes in Java <-> UML tests and testutils @Utility @@ -52,6 +53,9 @@ class JavaCreatorsUtil { static def ClassMethod createClassMethod((ClassMethod)=>void initialization) { var classMethod = MembersFactory.eINSTANCE.createClassMethod + if (classMethod.statement === null) { + classMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement + } initialization.apply(classMethod) return classMethod } @@ -64,6 +68,9 @@ class JavaCreatorsUtil { static def InterfaceMethod createInterfaceMethod((InterfaceMethod)=>void initialization) { var interfaceMethod = MembersFactory.eINSTANCE.createInterfaceMethod + if (interfaceMethod.statement === null) { + interfaceMethod.statement = StatementsFactory.eINSTANCE.createEmptyStatement + } initialization.apply(interfaceMethod) return interfaceMethod } diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/JavaStdLibCompilationUnitHelper.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/JavaStdLibCompilationUnitHelper.xtend index bc975d11f..4a37c7b4a 100755 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/JavaStdLibCompilationUnitHelper.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/JavaStdLibCompilationUnitHelper.xtend @@ -1,7 +1,7 @@ package tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper import org.eclipse.emf.ecore.util.EcoreUtil -import org.emftext.language.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.CompilationUnit import tools.vitruv.framework.views.View import static tools.vitruv.applications.pcmjava.tests.pcm2java.JavaQueryUtil.getJavaCompilationUnits diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/MethodDescription.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/MethodDescription.xtend index d8b6e0b5d..c7cbdbe05 100644 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/MethodDescription.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/MethodDescription.xtend @@ -1,7 +1,7 @@ package tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper import java.util.List -import org.emftext.language.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.TypeReference class MethodDescription { public final String name diff --git a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/ParameterDescription.xtend b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/ParameterDescription.xtend index 75d79fb89..036f3d29f 100644 --- a/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/ParameterDescription.xtend +++ b/tests/tools.vitruv.applications.pcmjava.tests/src/tools/vitruv/applications/pcmjava/tests/pcm2java/javahelper/ParameterDescription.xtend @@ -1,6 +1,6 @@ package tools.vitruv.applications.pcmjava.tests.pcm2java.javahelper -import org.emftext.language.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.TypeReference class ParameterDescription { public final String name diff --git a/tests/tools.vitruv.applications.umljava.tests/.project b/tests/tools.vitruv.applications.umljava.tests/.project index 80ef7b277..f273eb762 100644 --- a/tests/tools.vitruv.applications.umljava.tests/.project +++ b/tests/tools.vitruv.applications.umljava.tests/.project @@ -26,7 +26,7 @@ - org.emftext.language.java.resource.java.builder + tools.mdsd.jamopp.model.java.resource.java.builder @@ -34,7 +34,6 @@ org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature - org.emftext.language.java.resource.java.nature org.eclipse.xtext.ui.shared.xtextNature diff --git a/tests/tools.vitruv.applications.umljava.tests/META-INF/MANIFEST.MF b/tests/tools.vitruv.applications.umljava.tests/META-INF/MANIFEST.MF index e6792176d..c08edf562 100644 --- a/tests/tools.vitruv.applications.umljava.tests/META-INF/MANIFEST.MF +++ b/tests/tools.vitruv.applications.umljava.tests/META-INF/MANIFEST.MF @@ -18,9 +18,9 @@ Require-Bundle: tools.vitruv.applications.umljava, edu.kit.ipd.sdq.commons.util.java, org.eclipse.xtend.lib, org.apache.log4j, - org.emftext.language.java.resource.java, - org.emftext.language.java.resource, - tools.vitruv.applications.testutility + tools.vitruv.applications.testutility, + tools.mdsd.jamopp.model;bundle-version="6.0.0", + tools.mdsd.jamopp.resource;bundle-version="6.0.0" Bundle-ClassPath: ., target/dependency/json.jar Bundle-Vendor: vitruv.tools diff --git a/tests/tools.vitruv.applications.umljava.tests/build.properties b/tests/tools.vitruv.applications.umljava.tests/build.properties index 6e7ab3b97..55d28de02 100644 --- a/tests/tools.vitruv.applications.umljava.tests/build.properties +++ b/tests/tools.vitruv.applications.umljava.tests/build.properties @@ -4,11 +4,7 @@ bin.includes = .,\ META-INF/,\ target/dependency/ bin = target/classes/ -additional.bundles = org.emftext.language.java.resource,\ - org.emftext.commons.antlr3_4_0,\ - org.emftext.language.java.resource.java,\ - org.emftext.language.java.resource.bcel,\ - org.eclipse.uml2.uml,\ +additional.bundles = org.eclipse.uml2.uml,\ org.eclipse.emf.transaction,\ org.eclipse.core.expressions,\ org.slf4j.api,\ diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/AbstractJavaToUmlTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/AbstractJavaToUmlTest.xtend index 93c374be4..03381f2e5 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/AbstractJavaToUmlTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/AbstractJavaToUmlTest.xtend @@ -2,12 +2,12 @@ package tools.vitruv.applications.umljava.tests.java2uml import java.nio.file.Path import java.util.List -import org.emftext.language.java.classifiers.ClassifiersFactory -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.ContainersFactory -import org.emftext.language.java.containers.JavaRoot -import org.emftext.language.java.containers.Package +import tools.mdsd.jamopp.model.java.classifiers.ClassifiersFactory +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.ContainersFactory +import tools.mdsd.jamopp.model.java.containers.JavaRoot +import tools.mdsd.jamopp.model.java.containers.Package import org.junit.jupiter.api.BeforeEach import tools.vitruv.applications.umljava.tests.UmlJavaTransformationTest import tools.vitruv.framework.views.View diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlAttributeTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlAttributeTest.xtend index 323e1363e..e6e9a4913 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlAttributeTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlAttributeTest.xtend @@ -2,10 +2,10 @@ package tools.vitruv.applications.umljava.tests.java2uml import org.eclipse.emf.ecore.util.EcoreUtil import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.JavaClasspath -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.members.MembersFactory -import org.emftext.language.java.types.TypeReference +import tools.mdsd.jamopp.model.java.JavaClasspath +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.members.MembersFactory +import tools.mdsd.jamopp.model.java.types.TypeReference import org.junit.jupiter.api.Test import tools.vitruv.applications.util.temporary.java.JavaStandardType import tools.vitruv.applications.util.temporary.java.JavaVisibility @@ -92,7 +92,7 @@ class JavaToUmlAttributeTest extends AbstractJavaToUmlTest { def void testCreateAttributeOfStandardLibraryClass() { createJavaClassInRootPackage(CLASS_NAME) changeJavaView [ - val standardLibraryClass = JavaClasspath.get().getClassifier("java.lang.Iterable") as ConcreteClassifier + val standardLibraryClass = JavaClasspath.get().getConcreteClassifier("java.lang.Iterable") as ConcreteClassifier claimJavaClass(CLASS_NAME) => [ members += MembersFactory.eINSTANCE.createField => [ name = ATTRIBUTE_NAME diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlClassMethodTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlClassMethodTest.xtend index e36408d8f..304a5e825 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlClassMethodTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlClassMethodTest.xtend @@ -2,10 +2,10 @@ package tools.vitruv.applications.umljava.tests.java2uml import org.eclipse.emf.ecore.util.EcoreUtil import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.members.ClassMethod -import org.emftext.language.java.members.MembersFactory -import org.emftext.language.java.parameters.ParametersFactory -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.members.MembersFactory +import tools.mdsd.jamopp.model.java.parameters.ParametersFactory +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.EnumSource @@ -20,6 +20,7 @@ import static tools.vitruv.applications.util.temporary.java.JavaStandardType.* import static extension tools.vitruv.applications.testutility.uml.UmlQueryUtil.* import static extension tools.vitruv.applications.umljava.tests.util.JavaQueryUtil.* import static extension tools.vitruv.applications.util.temporary.java.JavaModifierUtil.* +import tools.mdsd.jamopp.model.java.statements.StatementsFactory /** * A test class to test the class method reactions. @@ -119,7 +120,7 @@ class JavaToUmlClassMethodTest extends AbstractJavaToUmlTest { } private def void changeAndCheckPropertyOfMethod(String className, String methodName, - (org.emftext.language.java.members.ClassMethod)=>void changeJavaMethod, + (tools.mdsd.jamopp.model.java.members.ClassMethod)=>void changeJavaMethod, (org.eclipse.uml2.uml.Operation)=>void validateUmlMethod) { changeClassMethod(CLASS_NAME, OPERATION_NAME) [ changeJavaMethod.apply(it) @@ -291,6 +292,7 @@ class JavaToUmlClassMethodTest extends AbstractJavaToUmlTest { changeJavaView [ claimJavaClass(CLASS_NAME) => [ members += MembersFactory.eINSTANCE.createConstructor => [ + block = StatementsFactory.eINSTANCE.createBlock name = CLASS_NAME javaVisibilityModifier = JavaVisibility.PUBLIC ] @@ -304,6 +306,7 @@ class JavaToUmlClassMethodTest extends AbstractJavaToUmlTest { changeJavaView [ claimJavaClass(className) => [ members += MembersFactory.eINSTANCE.createClassMethod => [ + statement = StatementsFactory.eINSTANCE.createEmptyStatement name = methodName typeReference = TypesFactory.eINSTANCE.createVoid makePublic diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlClassTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlClassTest.xtend index 05538841a..9d8c982b2 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlClassTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlClassTest.xtend @@ -134,7 +134,7 @@ class JavaToUmlClassTest extends AbstractJavaToUmlTest { } private def void changeAndCheckPropertyOfClass(String className, - (org.emftext.language.java.classifiers.Class)=>void changeJavaClass, + (tools.mdsd.jamopp.model.java.classifiers.Class)=>void changeJavaClass, (org.eclipse.uml2.uml.Class)=>void validateUmlClass) { changeJavaView [ claimJavaClass(className) => [ diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlEnumTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlEnumTest.xtend index 05290e54f..a5a1580a1 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlEnumTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlEnumTest.xtend @@ -3,8 +3,8 @@ package tools.vitruv.applications.umljava.tests.java2uml import org.eclipse.emf.ecore.util.EcoreUtil import org.eclipse.uml2.uml.UMLFactory import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.members.MembersFactory -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.members.MembersFactory +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.junit.jupiter.api.Test import static org.hamcrest.CoreMatchers.* @@ -16,6 +16,7 @@ import static tools.vitruv.applications.util.temporary.java.JavaModificationUtil import static extension tools.vitruv.applications.testutility.uml.UmlQueryUtil.* import static extension tools.vitruv.applications.umljava.tests.util.JavaQueryUtil.* import static extension tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil.* +import tools.mdsd.jamopp.model.java.statements.StatementsFactory /** * This class contains Tests for creating, deleting and renaming enumerations. @@ -177,6 +178,7 @@ class JavaToUmlEnumTest extends AbstractJavaToUmlTest { changeJavaView [ claimJavaEnum(ENUM_NAME) => [ members += MembersFactory.eINSTANCE.createClassMethod => [ + statement = StatementsFactory.eINSTANCE.createEmptyStatement name = OPERATION_NAME typeReference = TypesFactory.eINSTANCE.createVoid makePublic diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlInterfaceMethodTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlInterfaceMethodTest.xtend index b1032e4ce..99a1151ef 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlInterfaceMethodTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/JavaToUmlInterfaceMethodTest.xtend @@ -2,9 +2,9 @@ package tools.vitruv.applications.umljava.tests.java2uml import org.eclipse.emf.ecore.util.EcoreUtil import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.members.MembersFactory -import org.emftext.language.java.parameters.ParametersFactory -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.members.MembersFactory +import tools.mdsd.jamopp.model.java.parameters.ParametersFactory +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.junit.jupiter.api.Test import static org.hamcrest.CoreMatchers.* @@ -14,6 +14,7 @@ import static tools.vitruv.applications.util.temporary.java.JavaModificationUtil import static extension tools.vitruv.applications.testutility.uml.UmlQueryUtil.* import static extension tools.vitruv.applications.umljava.tests.util.JavaQueryUtil.* +import tools.mdsd.jamopp.model.java.statements.StatementsFactory /** * This class contains test cases for the creation, renaming and deleting of interface methods. @@ -122,6 +123,7 @@ class JavaToUmlInterfaceMethodTest extends AbstractJavaToUmlTest { changeJavaView [ claimJavaInterface(INTERFACE_NAME) => [ members += MembersFactory.eINSTANCE.createInterfaceMethod => [ + statement = StatementsFactory.eINSTANCE.createEmptyStatement name = methodName typeReference = TypesFactory.eINSTANCE.createVoid ] diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend index 883fd6aee..1e0b76540 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaConstructionSimulationTest.xtend @@ -3,26 +3,27 @@ package tools.vitruv.applications.umljava.tests.java2uml.constructionsimulationt import java.io.File import java.nio.file.Path import java.util.List -import java.util.Map import org.apache.log4j.Logger import org.eclipse.emf.ecore.EObject import org.eclipse.emf.ecore.resource.ResourceSet import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.classifiers.Interface -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.expressions.Expression -import org.emftext.language.java.members.Field -import org.emftext.language.java.members.Member -import org.emftext.language.java.resource.java.IJavaOptions -import org.emftext.language.java.statements.Statement -import org.emftext.language.java.statements.StatementListContainer -import org.emftext.language.java.types.TypeReference import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.classifiers.Enumeration +import tools.mdsd.jamopp.model.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.Package +import tools.mdsd.jamopp.model.java.expressions.Expression +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.members.Member +import tools.mdsd.jamopp.model.java.statements.Statement +import tools.mdsd.jamopp.model.java.statements.StatementListContainer +import tools.mdsd.jamopp.model.java.types.TypeReference import tools.vitruv.applications.umljava.tests.java2uml.AbstractJavaToUmlTest import tools.vitruv.applications.util.temporary.java.JavaSetup @@ -41,6 +42,7 @@ import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.flat import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.mapFixed import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.common.util.URIUtil.isPathmap import static extension edu.kit.ipd.sdq.commons.util.org.eclipse.emf.ecore.resource.ResourceSetUtil.withGlobalFactories +import tools.vitruv.applications.util.temporary.java.JavaContainerAndClassifierUtil /** * Test class for the reconstruction of existing java models @@ -53,7 +55,8 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest { @BeforeEach def void prepareResourceSet() { resourceSetForLoading = new ResourceSetImpl().withGlobalFactories - resourceSetForLoading.loadOptions += Map.of(IJavaOptions.DISABLE_LAYOUT_INFORMATION_RECORDING, true) + //resourceSetForLoading.loadOptions += Map.of(IJavaOptions.DISABLE_LAYOUT_INFORMATION_RECORDING, true) + // IJavaOptions does no longer exist } @BeforeAll @@ -118,7 +121,7 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest { private def void transformJavaFilesAndValidateUmlModel(Iterable javaFiles) { val javaRoots = javaFiles.toList.loadRootObjects - val packages = javaRoots.filter(org.emftext.language.java.containers.Package) + val packages = javaRoots.filter(Package) val compilationUnits = javaRoots.filter(CompilationUnit) val compilationUnitExtractors = packages.mapFixed[new CompilationUnitExtractor(it)] @@ -163,11 +166,11 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest { for (classifier : classifiers) { val namespaces = classifier.containingCompilationUnit.namespaces switch (classifier) { - org.emftext.language.java.classifiers.Class: + Class: assertClassWithNameInPackage(namespaces, classifier.name) - org.emftext.language.java.classifiers.Interface: + Interface: assertInterfaceWithNameInPackage(namespaces, classifier.name) - org.emftext.language.java.classifiers.Enumeration: + Enumeration: assertEnumWithNameInPackage(namespaces, classifier.name) } } @@ -181,7 +184,7 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest { if (!file.isPackageInfoFile) { assertThat(contents.head, instanceOf(CompilationUnit)) } else if (file.isPackageInfoFile) { - assertThat(contents.head, instanceOf(org.emftext.language.java.containers.Package)) + assertThat(contents.head, instanceOf(Package)) } contents ] @@ -217,18 +220,20 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest { @FinalFieldsConstructor private static class CompilationUnitExtractor { - val org.emftext.language.java.containers.Package javaPackage + val Package javaPackage val List compilationUnits = newArrayList def void removeAndStoreCompilationUnits() { LOGGER.trace("Removing compilation units from " + javaPackage) - compilationUnits += javaPackage.compilationUnits - javaPackage.compilationUnits.clear() + compilationUnits += javaPackage.classifiers.map[it.containingCompilationUnit] + javaPackage.classifiers.clear() } def void reapplyStoredCompilationUnits() { LOGGER.trace("Adding compilation units to " + javaPackage) - javaPackage.compilationUnits += compilationUnits + for (CompilationUnit compUnit : compilationUnits) { + JavaContainerAndClassifierUtil.updateNamespaces(compUnit, javaPackage); + } compilationUnits.clear() } } @@ -300,7 +305,7 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest { extensions += classifier.extends classifier.extends.clear() } - org.emftext.language.java.classifiers.Class: { + Class: { extensions += classifier.extends classifier.extends = null implementations += classifier.implements @@ -316,7 +321,7 @@ class JavaConstructionSimulationTest extends AbstractJavaToUmlTest { classifier.extends += extensions extensions.clear() } - org.emftext.language.java.classifiers.Class: { + Class: { classifier.extends = extensions.claimOne extensions.clear() classifier.implements += implementations diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefault.java b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefault.java index 4c9e2be93..4973fad05 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefault.java +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefault.java @@ -5,21 +5,21 @@ import java.util.Map; import org.eclipse.emf.common.util.URI; -import org.emftext.language.java.containers.CompilationUnit; -import org.emftext.language.java.members.Field; -import org.emftext.language.java.members.MembersFactory; -import org.emftext.language.java.resource.JavaSourceOrClassFileResource; -import org.emftext.language.java.types.ClassifierReference; -import org.emftext.language.java.types.TypesFactory; +import tools.mdsd.jamopp.model.java.containers.CompilationUnit; +import tools.mdsd.jamopp.model.java.members.Field; +import tools.mdsd.jamopp.model.java.members.MembersFactory; +import tools.mdsd.jamopp.resource.JavaResource2; +import tools.mdsd.jamopp.model.java.types.ClassifierReference; +import tools.mdsd.jamopp.model.java.types.TypesFactory; -public class JavaSourceOrClassFileResourceWithArraysDefault extends JavaSourceOrClassFileResource { +public class JavaSourceOrClassFileResourceWithArraysDefault extends JavaResource2 { public JavaSourceOrClassFileResourceWithArraysDefault(URI uri) { super(uri); } @Override - protected void doLoad(InputStream inputStream, Map options) throws IOException { + public void doLoad(InputStream inputStream, Map options) throws IOException { super.doLoad(inputStream, options); addArrayLengthField(); } diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl.java b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl.java index a6f1f0598..7fe948e5f 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl.java +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/java2uml/constructionsimulationtest/JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl.java @@ -2,10 +2,10 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; -import org.emftext.language.java.resource.JavaSourceOrClassFileResourceFactoryImpl; +import tools.mdsd.jamopp.resource.JavaResource2Factory; public class JavaSourceOrClassFileResourceWithArraysDefaultFactoryImpl - extends JavaSourceOrClassFileResourceFactoryImpl { + extends JavaResource2Factory { @Override public Resource createResource(URI uri) { diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaAttributeTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaAttributeTest.xtend index f520b17b9..edecf4bd2 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaAttributeTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaAttributeTest.xtend @@ -6,8 +6,8 @@ import org.eclipse.uml2.uml.Property import org.eclipse.uml2.uml.Type import org.eclipse.uml2.uml.UMLFactory import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.members.Field -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.EnumSource diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaClassMethodTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaClassMethodTest.xtend index f3f90ae4a..79d075813 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaClassMethodTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaClassMethodTest.xtend @@ -3,9 +3,9 @@ package tools.vitruv.applications.umljava.tests.uml2java import org.eclipse.uml2.uml.Model import org.eclipse.uml2.uml.Operation import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.members.ClassMethod -import org.emftext.language.java.statements.StatementsFactory -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.statements.StatementsFactory +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.EnumSource diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaEnumTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaEnumTest.xtend index c272f81ae..06e940a5f 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaEnumTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaEnumTest.xtend @@ -2,7 +2,7 @@ package tools.vitruv.applications.umljava.tests.uml2java import org.eclipse.uml2.uml.UMLFactory import org.eclipse.uml2.uml.VisibilityKind -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.junit.jupiter.api.Test import tools.vitruv.applications.util.temporary.java.JavaVisibility diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaInterfaceMethodTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaInterfaceMethodTest.xtend index 4ce734386..24b181b3d 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaInterfaceMethodTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaInterfaceMethodTest.xtend @@ -2,7 +2,7 @@ package tools.vitruv.applications.umljava.tests.uml2java import org.eclipse.uml2.uml.Model import org.eclipse.uml2.uml.Operation -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.junit.jupiter.api.Test import static org.hamcrest.CoreMatchers.* diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaParameterTest.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaParameterTest.xtend index fb7537d99..6e8e4f7f2 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaParameterTest.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/uml2java/UmlToJavaParameterTest.xtend @@ -3,7 +3,7 @@ package tools.vitruv.applications.umljava.tests.uml2java import org.eclipse.uml2.uml.Model import org.eclipse.uml2.uml.Parameter import org.eclipse.uml2.uml.ParameterDirectionKind -import org.emftext.language.java.types.TypesFactory +import tools.mdsd.jamopp.model.java.types.TypesFactory import org.junit.jupiter.api.Test import static tools.vitruv.applications.umljava.tests.util.JavaElementsTestAssertions.* diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaElementsTestAssertions.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaElementsTestAssertions.xtend index 61cfc3ddf..3a373bb35 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaElementsTestAssertions.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaElementsTestAssertions.xtend @@ -1,28 +1,28 @@ package tools.vitruv.applications.umljava.tests.util -import org.emftext.language.java.modifiers.AnnotableAndModifiable +import tools.mdsd.jamopp.model.java.modifiers.AnnotableAndModifiable import tools.vitruv.applications.util.temporary.java.JavaVisibility -import org.emftext.language.java.modifiers.Public -import org.emftext.language.java.modifiers.Private -import org.emftext.language.java.modifiers.Protected -import org.emftext.language.java.modifiers.Modifier -import org.emftext.language.java.members.MemberContainer -import org.emftext.language.java.classifiers.Enumeration -import org.emftext.language.java.members.EnumConstant -import org.emftext.language.java.parameters.Parameter -import org.emftext.language.java.members.Method -import org.emftext.language.java.types.TypedElement -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.members.Field -import org.emftext.language.java.modifiers.Final -import org.emftext.language.java.modifiers.Static -import org.emftext.language.java.classifiers.Interface -import org.emftext.language.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.modifiers.Public +import tools.mdsd.jamopp.model.java.modifiers.Private +import tools.mdsd.jamopp.model.java.modifiers.Protected +import tools.mdsd.jamopp.model.java.modifiers.Modifier +import tools.mdsd.jamopp.model.java.members.MemberContainer +import tools.mdsd.jamopp.model.java.classifiers.Enumeration +import tools.mdsd.jamopp.model.java.members.EnumConstant +import tools.mdsd.jamopp.model.java.parameters.Parameter +import tools.mdsd.jamopp.model.java.members.Method +import tools.mdsd.jamopp.model.java.types.TypedElement +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.modifiers.Final +import tools.mdsd.jamopp.model.java.modifiers.Static +import tools.mdsd.jamopp.model.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier import java.util.List -import org.emftext.language.java.modifiers.Abstract -import org.emftext.language.java.members.InterfaceMethod -import org.emftext.language.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.modifiers.Abstract +import tools.mdsd.jamopp.model.java.members.InterfaceMethod +import tools.mdsd.jamopp.model.java.members.ClassMethod import static tools.vitruv.applications.util.temporary.java.JavaTypeUtil.* import static org.junit.jupiter.api.Assertions.assertEquals diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaQueryUtil.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaQueryUtil.xtend index 259dcaf6a..373387b8d 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaQueryUtil.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaQueryUtil.xtend @@ -1,19 +1,19 @@ package tools.vitruv.applications.umljava.tests.util import edu.kit.ipd.sdq.activextendannotations.Utility -import org.emftext.language.java.classifiers.Class -import org.emftext.language.java.classifiers.Classifier -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.classifiers.Enumeration -import org.emftext.language.java.classifiers.Interface -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.Package -import org.emftext.language.java.members.ClassMethod -import org.emftext.language.java.members.Constructor -import org.emftext.language.java.members.Field -import org.emftext.language.java.members.InterfaceMethod -import org.emftext.language.java.members.Method -import org.emftext.language.java.parameters.Parameter +import tools.mdsd.jamopp.model.java.classifiers.Class +import tools.mdsd.jamopp.model.java.classifiers.Classifier +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.classifiers.Enumeration +import tools.mdsd.jamopp.model.java.classifiers.Interface +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.Package +import tools.mdsd.jamopp.model.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.members.Constructor +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.members.InterfaceMethod +import tools.mdsd.jamopp.model.java.members.Method +import tools.mdsd.jamopp.model.java.parameters.Parameter import tools.vitruv.framework.views.View import static extension edu.kit.ipd.sdq.commons.util.java.lang.IterableUtil.claimOne diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlClassifierEqualityValidation.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlClassifierEqualityValidation.xtend index 41bb5a3f2..9a83082b2 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlClassifierEqualityValidation.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlClassifierEqualityValidation.xtend @@ -36,7 +36,7 @@ class JavaUmlClassifierEqualityValidation { } def assertClassWithNameInPackage(Iterable packageNamespaces, String className) { - assertClassifierWithName(org.emftext.language.java.classifiers.Class, org.eclipse.uml2.uml.Class, + assertClassifierWithName(tools.mdsd.jamopp.model.java.classifiers.Class, org.eclipse.uml2.uml.Class, packageNamespaces, className) } @@ -49,7 +49,7 @@ class JavaUmlClassifierEqualityValidation { } def assertSingleClassWithNameInPackage(Iterable packageNamespaces, String className) { - assertSingleClassifierWithName(org.emftext.language.java.classifiers.Class, org.eclipse.uml2.uml.Class, + assertSingleClassifierWithName(tools.mdsd.jamopp.model.java.classifiers.Class, org.eclipse.uml2.uml.Class, packageNamespaces, className) } @@ -62,7 +62,7 @@ class JavaUmlClassifierEqualityValidation { } def assertDataTypeWithNameInPackage(Iterable packageNamespaces, String dataTypeName) { - assertClassifierWithName(org.emftext.language.java.classifiers.Class, org.eclipse.uml2.uml.DataType, + assertClassifierWithName(tools.mdsd.jamopp.model.java.classifiers.Class, org.eclipse.uml2.uml.DataType, packageNamespaces, dataTypeName) } @@ -75,7 +75,7 @@ class JavaUmlClassifierEqualityValidation { } def assertSingleDataTypeWithNameInPackage(Iterable packageNamespaces, String dataTypeName) { - assertSingleClassifierWithName(org.emftext.language.java.classifiers.Class, org.eclipse.uml2.uml.DataType, + assertSingleClassifierWithName(tools.mdsd.jamopp.model.java.classifiers.Class, org.eclipse.uml2.uml.DataType, packageNamespaces, dataTypeName) } @@ -88,7 +88,7 @@ class JavaUmlClassifierEqualityValidation { } def assertEnumWithNameInPackage(Iterable packageNamespaces, String enumName) { - assertClassifierWithName(org.emftext.language.java.classifiers.Enumeration, org.eclipse.uml2.uml.Enumeration, + assertClassifierWithName(tools.mdsd.jamopp.model.java.classifiers.Enumeration, org.eclipse.uml2.uml.Enumeration, packageNamespaces, enumName) } @@ -101,7 +101,7 @@ class JavaUmlClassifierEqualityValidation { } def assertSingleEnumWithNameInPackage(Iterable packageNamespaces, String enumName) { - assertSingleClassifierWithName(org.emftext.language.java.classifiers.Enumeration, + assertSingleClassifierWithName(tools.mdsd.jamopp.model.java.classifiers.Enumeration, org.eclipse.uml2.uml.Enumeration, packageNamespaces, enumName) } @@ -114,7 +114,7 @@ class JavaUmlClassifierEqualityValidation { } def assertInterfaceWithNameInPackage(Iterable packageNamespaces, String interfaceName) { - assertClassifierWithName(org.emftext.language.java.classifiers.Interface, org.eclipse.uml2.uml.Interface, + assertClassifierWithName(tools.mdsd.jamopp.model.java.classifiers.Interface, org.eclipse.uml2.uml.Interface, packageNamespaces, interfaceName) } @@ -127,7 +127,7 @@ class JavaUmlClassifierEqualityValidation { } def assertSingleInterfaceWithNameInPackage(Iterable packageNamespaces, String interfaceName) { - assertSingleClassifierWithName(org.emftext.language.java.classifiers.Interface, org.eclipse.uml2.uml.Interface, + assertSingleClassifierWithName(tools.mdsd.jamopp.model.java.classifiers.Interface, org.eclipse.uml2.uml.Interface, packageNamespaces, interfaceName) } @@ -195,7 +195,7 @@ class JavaUmlClassifierEqualityValidation { * with equal properties both in the UML and in the Java model. */ private def void assertClassifierWithName( - Class javaClassifierType, + Class javaClassifierType, Class umlClassifierType, Iterable namespaces, String classifierName) { viewExecutor.apply [ @@ -216,7 +216,7 @@ class JavaUmlClassifierEqualityValidation { * This will fail if the package contains any further elements. */ private def void assertSingleClassifierWithName( - Class javaClassifierType, + Class javaClassifierType, Class umlClassifierType, Iterable namespaces, String classifierName) { viewExecutor.apply [ diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlElementEqualityValidation.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlElementEqualityValidation.xtend index 7eb56e6b1..4c208645e 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlElementEqualityValidation.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlElementEqualityValidation.xtend @@ -3,23 +3,23 @@ package tools.vitruv.applications.umljava.tests.util import org.eclipse.uml2.uml.Feature import org.eclipse.uml2.uml.Operation import org.eclipse.uml2.uml.Property -import org.emftext.language.java.members.Field -import org.emftext.language.java.members.Method -import org.emftext.language.java.modifiers.AnnotableAndModifiable -import org.emftext.language.java.modifiers.Final -import org.emftext.language.java.modifiers.Static -import org.emftext.language.java.modifiers.Abstract -import org.emftext.language.java.types.Void -import org.emftext.language.java.types.TypeReference -import org.emftext.language.java.types.NamespaceClassifierReference +import tools.mdsd.jamopp.model.java.members.Field +import tools.mdsd.jamopp.model.java.members.Method +import tools.mdsd.jamopp.model.java.modifiers.AnnotableAndModifiable +import tools.mdsd.jamopp.model.java.modifiers.Final +import tools.mdsd.jamopp.model.java.modifiers.Static +import tools.mdsd.jamopp.model.java.modifiers.Abstract +import tools.mdsd.jamopp.model.java.types.Void +import tools.mdsd.jamopp.model.java.types.TypeReference +import tools.mdsd.jamopp.model.java.types.NamespaceClassifierReference import java.util.List import org.eclipse.uml2.uml.ParameterDirectionKind import org.eclipse.uml2.uml.EnumerationLiteral -import org.emftext.language.java.members.EnumConstant +import tools.mdsd.jamopp.model.java.members.EnumConstant import org.apache.log4j.Logger import org.eclipse.uml2.uml.Model -import org.emftext.language.java.members.InterfaceMethod -import org.emftext.language.java.members.ClassMethod +import tools.mdsd.jamopp.model.java.members.InterfaceMethod +import tools.mdsd.jamopp.model.java.members.ClassMethod import org.eclipse.uml2.uml.VisibilityKind import tools.vitruv.applications.umljava.util.UmlJavaTypePropagationHelper @@ -35,13 +35,13 @@ import static org.junit.jupiter.api.Assertions.assertNotNull import static org.junit.jupiter.api.Assertions.assertNull import static org.junit.jupiter.api.Assertions.fail import edu.kit.ipd.sdq.activextendannotations.Utility -import org.emftext.language.java.members.Constructor +import tools.mdsd.jamopp.model.java.members.Constructor import org.eclipse.uml2.uml.Classifier -import org.emftext.language.java.classifiers.ConcreteClassifier -import org.emftext.language.java.parameters.Parametrizable +import tools.mdsd.jamopp.model.java.classifiers.ConcreteClassifier +import tools.mdsd.jamopp.model.java.parameters.Parametrizable import org.eclipse.uml2.uml.Enumeration import org.eclipse.uml2.uml.DataType -import org.emftext.language.java.parameters.VariableLengthParameter +import tools.mdsd.jamopp.model.java.parameters.VariableLengthParameter import org.eclipse.uml2.uml.LiteralUnlimitedNatural import static tools.vitruv.applications.umljava.tests.util.UmlElementsTestAssertions.* import static tools.vitruv.applications.umljava.tests.util.JavaElementsTestAssertions.* @@ -61,7 +61,7 @@ class JavaUmlElementEqualityValidation { * Does not compare the package contents */ def static dispatch void assertElementsEqual(org.eclipse.uml2.uml.Package uPackage, - org.emftext.language.java.containers.Package jPackage) { + tools.mdsd.jamopp.model.java.containers.Package jPackage) { assertEquals(uPackage.name, jPackage.name, "Package names must be equal") assertEquals(getUmlParentNamespaceAsStringList(uPackage), jPackage.namespaces, "Package namespaces names must be equal") @@ -86,24 +86,24 @@ class JavaUmlElementEqualityValidation { // CLASSIFIERS // ************** def static dispatch void assertElementsEqual(org.eclipse.uml2.uml.Class uClass, - org.emftext.language.java.classifiers.Class jClass) { + tools.mdsd.jamopp.model.java.classifiers.Class jClass) { assertClassifiersCommonDataEquals(uClass, jClass) assertAbstractClassEquals(uClass, jClass) assertFinalClassEquals(uClass, jClass) } def static dispatch void assertElementsEqual(org.eclipse.uml2.uml.DataType uDataType, - org.emftext.language.java.classifiers.Class jClass) { + tools.mdsd.jamopp.model.java.classifiers.Class jClass) { assertClassifiersCommonDataEquals(uDataType, jClass) } def static dispatch void assertElementsEqual(org.eclipse.uml2.uml.Interface uInterface, - org.emftext.language.java.classifiers.Interface jInterface) { + tools.mdsd.jamopp.model.java.classifiers.Interface jInterface) { assertClassifiersCommonDataEquals(uInterface, jInterface) } def static dispatch void assertElementsEqual(org.eclipse.uml2.uml.Enumeration uEnum, - org.emftext.language.java.classifiers.Enumeration jEnum) { + tools.mdsd.jamopp.model.java.classifiers.Enumeration jEnum) { assertClassifiersCommonDataEquals(uEnum, jEnum) assertEnumConstantListEquals(uEnum.ownedLiterals, jEnum.constants) } @@ -236,7 +236,7 @@ class JavaUmlElementEqualityValidation { } def static dispatch void assertElementsEqual(org.eclipse.uml2.uml.Parameter uParameter, - org.emftext.language.java.parameters.Parameter jParameter) { + tools.mdsd.jamopp.model.java.parameters.Parameter jParameter) { assertEquals(uParameter.name, jParameter.name, "Parameter names must be equal") if (jParameter instanceof VariableLengthParameter) { assertEquals(LiteralUnlimitedNatural.UNLIMITED, uParameter.upper, "UML parameter for Java variable length parameter must have multiplicity *") @@ -277,7 +277,7 @@ class JavaUmlElementEqualityValidation { } private def static void assertFinalClassEquals(org.eclipse.uml2.uml.Class uClass, - org.emftext.language.java.classifiers.Class jClass) { + tools.mdsd.jamopp.model.java.classifiers.Class jClass) { if (uClass.finalSpecialization) { assertTrue( jClass.hasModifier(Final), [String.format("Class %s is expected to be final but is not", jClass)]) @@ -300,7 +300,7 @@ class JavaUmlElementEqualityValidation { } private def static void assertAbstractClassEquals(org.eclipse.uml2.uml.Class uClass, - org.emftext.language.java.classifiers.Class jClass) { + tools.mdsd.jamopp.model.java.classifiers.Class jClass) { if (uClass.abstract) { assertTrue(jClass.hasModifier(Abstract), [ String.format("Class %s is expected to be abstract but is not", jClass) @@ -390,7 +390,7 @@ class JavaUmlElementEqualityValidation { } def static dispatch void assertTypeEquals(org.eclipse.uml2.uml.PrimitiveType uPrimType, - org.emftext.language.java.types.PrimitiveType jPrimType) { + tools.mdsd.jamopp.model.java.types.PrimitiveType jPrimType) { assertNotNull(uPrimType, "Primitive type to check must not be null") val jTypeMapped = UmlJavaTypePropagationHelper.getJavaTypeReferenceForUmlPrimitiveType(uPrimType) assertFalse(jTypeMapped instanceof Void, [ diff --git a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlViewFactory.xtend b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlViewFactory.xtend index 554f3e9a4..c9d5cc62c 100644 --- a/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlViewFactory.xtend +++ b/tests/tools.vitruv.applications.umljava.tests/src/tools/vitruv/applications/umljava/tests/util/JavaUmlViewFactory.xtend @@ -2,8 +2,8 @@ package tools.vitruv.applications.umljava.tests.util import org.eclipse.uml2.uml.Model import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor -import org.emftext.language.java.containers.CompilationUnit -import org.emftext.language.java.containers.Package +import tools.mdsd.jamopp.model.java.containers.CompilationUnit +import tools.mdsd.jamopp.model.java.containers.Package import tools.vitruv.framework.views.View import tools.vitruv.testutils.TestViewFactory