-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from IncQueryLabs/compunit_rule
CompilationUnit based Java to UML transformation
- Loading branch information
Showing
10 changed files
with
136 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><plugin/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...formation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/CompilationUnitRule.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
22 changes: 0 additions & 22 deletions
22
...ansformation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/ResourceSaveRule.xtend
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...ormation/src/com/incquerylabs/evm/jdt/uml/transformation/rules/visitors/TypeVisitor.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters