Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
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
7f7099f9
Commit
7f7099f9
authored
Dec 13, 2019
by
Raphael
Browse files
REMOVED ALL IF THEN ELSE
parent
940f611e
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/atl/bestPractices.atl
View file @
7f7099f9
...
...
@@ -5,23 +5,10 @@ library bestPractices;
--Goes through all the methods to check if the following rule is followed:
--Avoid printStackTrace()
helper def: avoidPrintStackTrace() : Set(smm!Measure) =
java!MethodInvocation.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} |
-- Add a new measurement if the argument of String.indexOf() is not of type char when checking for the index of a single character
if thisModule.isAvoidPrintStackTrace(i) then
res->union(Set{thisModule.MeasureAvoidPrintStackTrace(i)})
else
res
endif
);
--Detect a wrong usage of the method printStackTrace()
--return true if the method is called printStackTrace
helper def:isAvoidPrintStackTrace(s:java!MethodInvocation): Boolean =
if s.method.name = 'printStackTrace' then
true
else
false
endif;
java!MethodInvocation.allInstances()
-> select (m | m.method.name = 'printStackTrace')
-> collect (m | thisModule.MeasureAvoidPrintStackTrace(m))
;
--------------------------------------------- AvoidFieldNameMatchingMethodName ---------------------------------------------
...
...
src/main/atl/multithreading.atl
View file @
7f7099f9
...
...
@@ -5,47 +5,37 @@ library multithreading;
--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
);
java!MethodInvocation.allInstances()
-> select (m | m.method.name='run' )
-> select (m | m.expression.isDontCallThreadRun() )
-> collect (m | thisModule.MeasureDontCallThreadRun(m));
--Detect a wrong usage of the method Thread.run()
--return true if run() is called on a Thread variable
helper context java!SingleVariableAccess def : isDontCallThreadRun(): Boolean =
--check if the method is called like this:
--t.run() where t is of type Thread
self.variable.variablesContainer.type.type.name.toString() = 'Thread';
--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;
--return true if run() is called on a Thread instance creation
helper context java!ClassInstanceCreation def : isDontCallThreadRun(): Boolean =
--check if the method run is called like this:
--new Thread().run();
self.method.name.toString() = 'Thread';
--------------------------------------------- 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() ->
select(i | i.variablesContainer.type.toString() <> 'OclUndefined')->
select(s|s.variablesContainer.type.type.name.toString() = 'ThreadGroup')->collect(i | thisModule.measureAvoidThreadGroup(i) );
java!VariableDeclarationFragment.allInstances()
-> select(i | i.variablesContainer.type.toString() <> 'OclUndefined')
-> select(s|s.variablesContainer.type.type.name.toString() = 'ThreadGroup')
-> collect(i | thisModule.measureAvoidThreadGroup(i) );
--------------------------------------------- UseNotifyAllInsteadOfNotify ---------------------------------------------
...
...
src/main/atl/performance.atl
View file @
7f7099f9
...
...
@@ -5,28 +5,10 @@ library performance;
--Goes through all the methods to check if the following rule is followed:
--No need to call String.valueOf to append to a string; just use the valueOf() argument directly.
helper def: uselessStringValueOf() : Set(smm!Measure) =
java!MethodInvocation.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} |
-- Add a new measurement if the argument of String.indexOf() is not of type char when checking for the index of a single character
if thisModule.isUselessStringValueOf(i) then
res->union(Set{thisModule.MeasureUselessStringValueOf(i)})
else
res
endif
);
--Detect a wrong usage of the method String.valueOf()
--return true if String.valueOf is used to append an argument to a String
helper def:isUselessStringValueOf(s:java!MethodInvocation): Boolean =
if s.method.name='valueOf' then
if s.refImmediateComposite().oclType().toString() = 'java!InfixExpression' then
true
else
false
endif
else
false
endif
;
java!MethodInvocation.allInstances()
-> select (m | m.method.name='valueOf' )
-> select (m | m.refImmediateComposite().oclIsTypeOf(java!InfixExpression))
-> collect (m | thisModule.MeasureUselessStringValueOf(m));
------------------------------------ TooFewBranchesForASwitchStatement--------------------------------------
...
...
@@ -41,30 +23,15 @@ helper def: tooFewBranchesForASwitchStatement(): Set(smm!Measure) =
--------------------------------------------- UseIndexOfChar---------------------------------------------
--Goes through all the
m
ethod
s
to check if the following rule is followed:
--Goes through all the
M
ethod
Invocation
to check if the following rule is followed:
--Use String.indexOf(char) when checking for the index of a single character; it executes faster.
helper def: useIndexOfChar() : Set(smm!Measure) =
java!MethodInvocation.allInstances() -> iterate(i; res : Set(smm!Measure) = Set{} |
-- Add a new measurement if the argument of String.indexOf() is not of type char when checking for the index of a single character
if thisModule.isWrongUsageIndexOfChar(i) then
res->union(Set{thisModule.MeasureUseIndexOfChar(i)})
else
res
endif
);
--Detect a wrong usage of the method String.indexOf(char)
--return true if the argument of String.indexOf(char) is not of type char when checking for the index of a single character
helper def:isWrongUsageIndexOfChar(s:java!MethodInvocation): Boolean =
if s.method.name = 'indexOf' then
if s.arguments.size() = 1 and s.arguments.first().oclType().toString() <> 'java!CharacterLiteral' then
true
else
false
endif
else
false
endif;
java!MethodInvocation.allInstances()
-> select (m | m.method.name='indexOf')
-> select (m | m.arguments.size() = 1)
-> select (m | not m.arguments.first().oclIsTypeOf(java!CharacterLiteral))
-> collect (m | thisModule.MeasureUseIndexOfChar(m))
;
--------------------------------------------- avoidThrowingNewInstanceOfSameException ---------------------------------------------
-- Returns a set of Measures for each catch block throws a new instance of the caught exception
...
...
Raphael PAGE
@E129054B
mentioned in commit
e13df261
·
Dec 19, 2019
mentioned in commit
e13df261
mentioned in commit e13df2615fd9ccee0160a3b919492524b9bbff6c
Toggle commit list
Raphael PAGE
@E129054B
mentioned in commit
f5bce021
·
Dec 20, 2019
mentioned in commit
f5bce021
mentioned in commit f5bce021c35640b3cde165dd2f4c657c8535c424
Toggle commit list
Raphael PAGE
@E129054B
mentioned in commit
f8815726
·
Dec 21, 2019
mentioned in commit
f8815726
mentioned in commit f8815726c9fefa8ce8c2fb5119da0e9fee5ccc66
Toggle commit list
Write
Preview
Supports
Markdown
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