From f281a8792218135c2b4c568279ca45cf92cfdb35 Mon Sep 17 00:00:00 2001 From: Daniel Segesdi Date: Fri, 11 Dec 2015 17:14:56 +0100 Subject: [PATCH] Implemented Java to UML Class transformation added IncQuery nature to transformation project --- .../.classpath | 1 + .../.project | 6 ++ .../META-INF/MANIFEST.MF | 7 ++- .../build.properties | 7 ++- .../plugin.xml | 1 + .../rules/CompilationUnitRule.xtend | 63 +++++++++++++------ .../rules/ResourceSaveRule.xtend | 22 ------- com.incquerylabs.evm.jdt/META-INF/MANIFEST.MF | 3 +- 8 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 com.incquerylabs.evm.jdt.uml.transformation/plugin.xml delete mode 100644 com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/ResourceSaveRule.xtend diff --git a/com.incquerylabs.evm.jdt.uml.transformation/.classpath b/com.incquerylabs.evm.jdt.uml.transformation/.classpath index 428337e..632be2f 100644 --- a/com.incquerylabs.evm.jdt.uml.transformation/.classpath +++ b/com.incquerylabs.evm.jdt.uml.transformation/.classpath @@ -4,5 +4,6 @@ + diff --git a/com.incquerylabs.evm.jdt.uml.transformation/.project b/com.incquerylabs.evm.jdt.uml.transformation/.project index c7df8a0..a47b7c5 100644 --- a/com.incquerylabs.evm.jdt.uml.transformation/.project +++ b/com.incquerylabs.evm.jdt.uml.transformation/.project @@ -5,6 +5,11 @@ + + org.eclipse.incquery.tooling.core.projectbuilder + + + org.eclipse.xtext.ui.shared.xtextBuilder @@ -30,5 +35,6 @@ org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature org.eclipse.xtext.ui.shared.xtextNature + org.eclipse.incquery.projectnature diff --git a/com.incquerylabs.evm.jdt.uml.transformation/META-INF/MANIFEST.MF b/com.incquerylabs.evm.jdt.uml.transformation/META-INF/MANIFEST.MF index e53603e..6e39761 100644 --- a/com.incquerylabs.evm.jdt.uml.transformation/META-INF/MANIFEST.MF +++ b/com.incquerylabs.evm.jdt.uml.transformation/META-INF/MANIFEST.MF @@ -4,7 +4,7 @@ Bundle-Name: Uml Bundle-SymbolicName: com.incquerylabs.evm.jdt.uml.transformation;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-Vendor: INCQUERYLABS -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Export-Package: com.incquerylabs.evm.jdt.uml.transformation Require-Bundle: org.eclipse.incquery.runtime.evm;bundle-version="1.0.1", org.eclipse.jdt.core;bundle-version="3.11.1", org.eclipse.xtend.lib, @@ -17,6 +17,7 @@ Require-Bundle: org.eclipse.incquery.runtime.evm;bundle-version="1.0.1", org.eclipse.emf.common;bundle-version="2.11.0", org.eclipse.core.runtime;bundle-version="3.11.1", org.eclipse.emf.transaction;bundle-version="1.9.0", - org.eclipse.papyrus.infra.core;bundle-version="1.1.0" -Export-Package: com.incquerylabs.evm.jdt.uml.transformation + org.eclipse.papyrus.infra.core;bundle-version="1.1.0", + org.eclipse.incquery.runtime;bundle-version="1.1.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Import-Package: org.apache.log4j;version="1.2.15" diff --git a/com.incquerylabs.evm.jdt.uml.transformation/build.properties b/com.incquerylabs.evm.jdt.uml.transformation/build.properties index d8e2f0e..dd1e7e5 100644 --- a/com.incquerylabs.evm.jdt.uml.transformation/build.properties +++ b/com.incquerylabs.evm.jdt.uml.transformation/build.properties @@ -1,5 +1,6 @@ -source.. = src/,\ - xtend-gen/ -output.. = bin/ bin.includes = META-INF/,\ . +source.. = src/,\ + xtend-gen/,\ + src-gen/ +output.. = bin/ diff --git a/com.incquerylabs.evm.jdt.uml.transformation/plugin.xml b/com.incquerylabs.evm.jdt.uml.transformation/plugin.xml new file mode 100644 index 0000000..c760d4e --- /dev/null +++ b/com.incquerylabs.evm.jdt.uml.transformation/plugin.xml @@ -0,0 +1 @@ + diff --git a/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/CompilationUnitRule.xtend b/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/CompilationUnitRule.xtend index 9ff4a61..40f1323 100644 --- a/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/CompilationUnitRule.xtend +++ b/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/CompilationUnitRule.xtend @@ -1,23 +1,28 @@ package com.incquerylabs.evm.jdt.uml.transformation.rules +import com.incquerylabs.evm.jdt.JDTActivationState +import com.incquerylabs.evm.jdt.JDTEventAtom import com.incquerylabs.evm.jdt.JDTEventSourceSpecification import com.incquerylabs.evm.jdt.JDTRule +import com.incquerylabs.evm.jdt.fqnutil.JDTQualifiedName +import com.incquerylabs.evm.jdt.fqnutil.UMLQualifiedName +import com.incquerylabs.evm.jdt.job.JDTJobFactory +import com.incquerylabs.evm.jdt.uml.transformation.rules.filters.CompilationUnitFilter +import com.incquerylabs.evm.jdt.uml.transformation.rules.visitors.TypeVisitor import com.incquerylabs.evm.jdt.umlmanipulator.IUMLManipulator +import org.apache.log4j.Level import org.apache.log4j.Logger import org.eclipse.incquery.runtime.evm.api.ActivationLifeCycle +import org.eclipse.jdt.core.ICompilationUnit +import org.eclipse.jdt.core.IJavaElementDelta import org.eclipse.jdt.core.IJavaProject -import com.incquerylabs.evm.jdt.job.JDTJobFactory -import com.incquerylabs.evm.jdt.JDTActivationState -import com.incquerylabs.evm.jdt.uml.transformation.rules.filters.CompilationUnitFilter -import org.apache.log4j.Level -import com.incquerylabs.evm.jdt.JDTEventAtom -import javax.management.RuntimeErrorException -import com.incquerylabs.evm.jdt.uml.transformation.rules.visitors.TypeVisitor +import org.eclipse.jdt.core.IPackageFragment class CompilationUnitRule extends JDTRule { extension Logger logger = Logger.getLogger(this.class) extension val IUMLManipulator umlManipulator + new(JDTEventSourceSpecification eventSourceSpecification, ActivationLifeCycle activationLifeCycle, IJavaProject project, IUMLManipulator umlManipulator) { super(eventSourceSpecification, activationLifeCycle, project) this.umlManipulator = umlManipulator @@ -29,32 +34,54 @@ class CompilationUnitRule extends JDTRule { jobs.add(JDTJobFactory.createJob(JDTActivationState.APPEARED)[activation, context | val atom = activation.atom debug('''Compilation unit appeared: «atom.element»''') - atom.transform ]) jobs.add(JDTJobFactory.createJob(JDTActivationState.DISAPPEARED)[activation, context | debug('''Compilation unit disappeared: «activation.atom.element»''') - + try { + val compilationUnit = activation.atom.element as ICompilationUnit + compilationUnit.deleteCorrespondingClass + } catch (IllegalArgumentException e) { + error('''Error during updating compilation unit''', e) + } ]) jobs.add(JDTJobFactory.createJob(JDTActivationState.UPDATED)[activation, context | + val atom = activation.atom debug('''Compilation unit updated: «activation.atom.element»''') - + try{ + atom.transform + } catch (IllegalArgumentException e) { + error('''Error during updating compilation unit''', e) + } ]) } def transform(JDTEventAtom atom) { - val element = atom.element - val delta = atom.delta - val ast = delta.compilationUnitAST - if(ast == null) { - error('''AST was null, compilation unit is not transformed: «element»''') - return + val element = atom.element as ICompilationUnit + var delta = atom.delta + var ast = delta.compilationUnitAST + if(delta.flags.bitwiseAnd(IJavaElementDelta.F_AST_AFFECTED) != 0) { + element.deleteCorrespondingClass + if(ast == null) { + throw new IllegalArgumentException('''AST was null, compilation unit is not transformed: «element»''') + } + val typeVisitor = new TypeVisitor(umlManipulator) + ast.accept(typeVisitor) } - val typeVisitor = new TypeVisitor(umlManipulator) - ast.accept(typeVisitor) return } + def deleteCorrespondingClass(ICompilationUnit element) { + val packageFragment = element.parent + if(!(packageFragment instanceof IPackageFragment)) { + throw new IllegalArgumentException('''Compilation unit is not in a package: «element»''') + } + val javaQualifiedName = JDTQualifiedName::create('''«packageFragment.elementName».«element.elementName»''').parent.get + val umlQualifiedName = UMLQualifiedName::create(javaQualifiedName) + + deleteClass(umlQualifiedName) + } + } diff --git a/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/ResourceSaveRule.xtend b/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/ResourceSaveRule.xtend deleted file mode 100644 index e305223..0000000 --- a/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/ResourceSaveRule.xtend +++ /dev/null @@ -1,22 +0,0 @@ -package com.incquerylabs.evm.jdt.uml.transformation.rules - -import com.incquerylabs.evm.jdt.JDTActivationState -import com.incquerylabs.evm.jdt.JDTEventSourceSpecification -import com.incquerylabs.evm.jdt.JDTRule -import com.incquerylabs.evm.jdt.job.JDTJobFactory -import org.eclipse.incquery.runtime.evm.api.ActivationLifeCycle -import org.eclipse.jdt.core.IJavaProject - -class ResourceSaveRule extends JDTRule { - - new(JDTEventSourceSpecification eventSourceSpecification, ActivationLifeCycle activationLifeCycle, IJavaProject project) { - super(eventSourceSpecification, activationLifeCycle, project) - } - - override initialize() { - jobs.add(JDTJobFactory.createJob(JDTActivationState.APPEARED)[activation, context | - val javaElement = activation.atom.element - ]) - } - -} \ No newline at end of file diff --git a/com.incquerylabs.evm.jdt/META-INF/MANIFEST.MF b/com.incquerylabs.evm.jdt/META-INF/MANIFEST.MF index 61233d0..2ea2ea9 100644 --- a/com.incquerylabs.evm.jdt/META-INF/MANIFEST.MF +++ b/com.incquerylabs.evm.jdt/META-INF/MANIFEST.MF @@ -5,7 +5,8 @@ Bundle-SymbolicName: com.incquerylabs.evm.jdt Bundle-Version: 1.0.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: com.incquerylabs.evm.jdt, - com.incquerylabs.evm.jdt.job + com.incquerylabs.evm.jdt.job, + com.incquerylabs.evm.jdt.util Require-Bundle: org.eclipse.incquery.runtime.evm;bundle-version="1.0.1", org.eclipse.jdt.core;bundle-version="3.11.1", com.google.guava;bundle-version="15.0.0",