Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
naomod
Model Driven Engineering (MDE)
Source Code Analyzer
Commits
5e189a60
Commit
5e189a60
authored
Nov 21, 2019
by
Gerson Sunyé
Browse files
new library: multithreading
parent
a763d117
Changes
3
Hide whitespace changes
Inline
Side-by-side
analysis.launch
View file @
5e189a60
...
...
@@ -10,6 +10,7 @@
<mapAttribute
key=
"Libs"
>
<mapEntry
key=
"codestyle"
value=
"/Source Code Analyzer/src/main/atl/codestyle.asm"
/>
<mapEntry
key=
"design"
value=
"/Source Code Analyzer/src/main/atl/design.asm"
/>
<mapEntry
key=
"multithreading"
value=
"/Source Code Analyzer/src/main/atl/multithreading.asm"
/>
<mapEntry
key=
"performance"
value=
"/Source Code Analyzer/src/main/atl/performance.asm"
/>
</mapAttribute>
<mapAttribute
key=
"Model Handler"
>
...
...
@@ -48,4 +49,7 @@
</mapAttribute>
<listAttribute
key=
"Superimpose"
/>
<stringAttribute
key=
"bad_container_name"
value=
"/Source Code Analyzer/analysis.launch"
/>
<listAttribute
key=
"org.eclipse.debug.ui.favoriteGroups"
>
<listEntry
value=
"org.eclipse.debug.ui.launchGroup.run"
/>
</listAttribute>
</launchConfiguration>
src/main/atl/analysis.atl
View file @
5e189a60
...
...
@@ -7,6 +7,7 @@ create OUT: smm from IN: java;
uses design;
uses codestyle;
uses multithreading;
uses performance;
rule Java2SMM {
...
...
@@ -127,43 +128,6 @@ rule MesureShortMethodName(method : java!MethodDeclaration) {
}
}
--------------------------------------------- DontCallThreadRun ---------------------------------------------
--Goes through all the methods to check if the following rule is followed:
--Don't call Thread.run()
helper def: dontCallThreadRun() : Set(smm!Measure) =
java!MethodInvocation.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} |
if (thisModule.isDontCallThreadRun(i))
then res->union(Set{thisModule.MeasureDontCallThreadRun(i)})
else res
endif
);
--Detect a wrong usage of the method Thread.run()
--return true if run() is called on a Thread variable or on a Thread instance creation
helper def:isDontCallThreadRun(s:java!MethodInvocation): Boolean =
if s.method.name = 'run' then
--check if the method is called like this:
--t.run() where t is of type Thread
if s.expression.oclType().toString() = 'java!SingleVariableAccess' then
if s.expression.variable.variablesContainer.type.type.name.toString() = 'Thread' then
true
else false
endif
--check if the method run is called like this:
--new Thread().run();
else
if s.expression.oclType().toString() = 'java!ClassInstanceCreation' then
if s.expression.method.name.toString() = 'Thread' then
true
else false
endif
else false
endif
endif
else false
endif;
-- creates a new Measure when Thread.run() is used instead of Thread.start()
rule MeasureDontCallThreadRun(method : java!MethodInvocation) {
...
...
@@ -347,28 +311,6 @@ rule MesureTooManyStaticImports(class : java!CompilationUnit) {
}
}
--------------------------------------------- AvoidThreadGroup ---------------------------------------------
--Goes through all the variables to check if the following rule is followed:
--Avoid using java.lang.ThreadGroup;
helper def: avoidThreadGroup() : Set(smm!Measure) =
java!VariableDeclarationFragment.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} |
if (thisModule.isThreadGroup(i))
then res->union(Set{thisModule.measureAvoidThreadGroup(i)})
else res
endif
);
--Detect a wrong usage of the variable type java.lang.ThreadGroup
--return true if the variable of type java.lang.ThreadGroup
helper def:isThreadGroup(s:java!VariableDeclarationFragment): Boolean =
if s.variablesContainer.type.type.name.toString() = 'ThreadGroup' then
true
else
false
endif;
-- creates a new Measure when Thread.run() is used instead of Thread.start()
rule measureAvoidThreadGroup(variable : java!VariableDeclarationFragment) {
...
...
src/main/atl/multithreading.atl
0 → 100644
View file @
5e189a60
library multithreading;
--------------------------------------------- DontCallThreadRun ---------------------------------------------
--Goes through all the methods to check if the following rule is followed:
--Don't call Thread.run()
helper def: dontCallThreadRun() : Set(smm!Measure) =
java!MethodInvocation.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} |
if (thisModule.isDontCallThreadRun(i))
then res->union(Set{thisModule.MeasureDontCallThreadRun(i)})
else res
endif
);
--Detect a wrong usage of the method Thread.run()
--return true if run() is called on a Thread variable or on a Thread instance creation
helper def:isDontCallThreadRun(s:java!MethodInvocation): Boolean =
if s.method.name = 'run' then
--check if the method is called like this:
--t.run() where t is of type Thread
if s.expression.oclType().toString() = 'java!SingleVariableAccess' then
if s.expression.variable.variablesContainer.type.type.name.toString() = 'Thread' then
true
else false
endif
--check if the method run is called like this:
--new Thread().run();
else
if s.expression.oclType().toString() = 'java!ClassInstanceCreation' then
if s.expression.method.name.toString() = 'Thread' then
true
else false
endif
else false
endif
endif
else false
endif;
--------------------------------------------- AvoidThreadGroup ---------------------------------------------
--Goes through all the variables to check if the following rule is followed:
--Avoid using java.lang.ThreadGroup;
helper def: avoidThreadGroup() : Set(smm!Measure) =
java!VariableDeclarationFragment.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} |
if (thisModule.isThreadGroup(i))
then res->union(Set{thisModule.measureAvoidThreadGroup(i)})
else res
endif
);
--Detect a wrong usage of the variable type java.lang.ThreadGroup
--return true if the variable of type java.lang.ThreadGroup
helper def:isThreadGroup(s:java!VariableDeclarationFragment): Boolean =
if s.variablesContainer.type.type.name.toString() = 'ThreadGroup' then
true
else
false
endif;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment