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/JDTUMLTransformation.xtend b/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/JDTUMLTransformation.xtend index faaf874..22a5c9a 100644 --- a/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/JDTUMLTransformation.xtend +++ b/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/JDTUMLTransformation.xtend @@ -4,8 +4,7 @@ import com.incquerylabs.evm.jdt.JDTActivationLifeCycle import com.incquerylabs.evm.jdt.JDTEventSourceSpecification import com.incquerylabs.evm.jdt.JDTRealm import com.incquerylabs.evm.jdt.JDTRule -import com.incquerylabs.evm.jdt.uml.transformation.rules.AssociationRule -import com.incquerylabs.evm.jdt.uml.transformation.rules.ClassRule +import com.incquerylabs.evm.jdt.uml.transformation.rules.CompilationUnitRule import com.incquerylabs.evm.jdt.umlmanipulator.IUMLManipulator import com.incquerylabs.evm.jdt.umlmanipulator.impl.TransactionalManipulator import com.incquerylabs.evm.jdt.umlmanipulator.impl.UMLManipulator @@ -53,10 +52,12 @@ class JDTUMLTransformation { // val loggerRule = new LoggerRule(sourceSpec, lifeCycle, project) // addRule(loggerRule) - val classRule = new ClassRule(sourceSpec, lifeCycle, project, umlManipulator) - addRule(classRule) - val associationRule = new AssociationRule(sourceSpec, lifeCycle, project, umlManipulator) - addRule(associationRule) +// val classRule = new ClassRule(sourceSpec, lifeCycle, project, umlManipulator) +// addRule(classRule) +// val associationRule = new AssociationRule(sourceSpec, lifeCycle, project, umlManipulator) +// addRule(associationRule) + val compilationUnitRule = new CompilationUnitRule(sourceSpec, lifeCycle, project, umlManipulator) + addRule(compilationUnitRule) addTimedScheduler(100) } 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 new file mode 100644 index 0000000..40f1323 --- /dev/null +++ b/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/CompilationUnitRule.xtend @@ -0,0 +1,87 @@ +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 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 + this.filter = new CompilationUnitFilter(this.filter) + this.logger.level = Level.DEBUG + } + + override initialize() { + jobs.add(JDTJobFactory.createJob(JDTActivationState.APPEARED)[activation, context | + val atom = activation.atom + debug('''Compilation unit appeared: «atom.element»''') + ]) + + 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 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) + } + + 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.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/visitors/TypeVisitor.xtend b/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/visitors/TypeVisitor.xtend new file mode 100644 index 0000000..5e2e656 --- /dev/null +++ b/com.incquerylabs.evm.jdt.uml.transformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/visitors/TypeVisitor.xtend @@ -0,0 +1,24 @@ +package com.incquerylabs.evm.jdt.uml.transformation.rules.visitors + +import com.incquerylabs.evm.jdt.fqnutil.JDTQualifiedName +import com.incquerylabs.evm.jdt.umlmanipulator.IUMLManipulator +import org.eclipse.jdt.core.dom.ASTVisitor +import org.eclipse.jdt.core.dom.TypeDeclaration + +class TypeVisitor extends ASTVisitor { + val IUMLManipulator manipulator + + new(IUMLManipulator manipulator) { + this.manipulator = manipulator + } + + override visit(TypeDeclaration node) { + val fqn = JDTQualifiedName::create(node.resolveBinding.qualifiedName) + manipulator.createClass(fqn) + + + super.visit(node) + return false + } + +} \ 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",