Skip to content

Commit

Permalink
Merge pull request #24 from IncQueryLabs/compunit_rule
Browse files Browse the repository at this point in the history
CompilationUnit based Java to UML transformation
  • Loading branch information
Dániel Segesdi committed Dec 11, 2015
2 parents 0317545 + f281a87 commit dd9652c
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 35 deletions.
1 change: 1 addition & 0 deletions com.incquerylabs.evm.jdt.uml.transformation/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="src" path="src-gen/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
6 changes: 6 additions & 0 deletions com.incquerylabs.evm.jdt.uml.transformation/.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.incquery.tooling.core.projectbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
Expand All @@ -30,5 +35,6 @@
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>org.eclipse.incquery.projectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
7 changes: 4 additions & 3 deletions com.incquerylabs.evm.jdt.uml.transformation/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source.. = src/,\
xtend-gen/
output.. = bin/
bin.includes = META-INF/,\
.
source.. = src/,\
xtend-gen/,\
src-gen/
output.. = bin/
1 change: 1 addition & 0 deletions com.incquerylabs.evm.jdt.uml.transformation/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><plugin/>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
}

}
3 changes: 2 additions & 1 deletion com.incquerylabs.evm.jdt/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dd9652c

Please sign in to comment.