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
e13df261
Commit
e13df261
authored
Dec 19, 2019
by
Raphael PAGE
Committed by
Gerson SUNYE
Dec 19, 2019
Browse files
Revert "REMOVED ALL IF THEN ELSE"
This reverts commit 7f7099f93e6bc4b785033b2ecdc1d38678335428.
parent
56ff07a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/atl/bestPractices.atl
View file @
e13df261
...
...
@@ -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 @
e13df261
...
...
@@ -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 @
e13df261
...
...
@@ -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
...
...
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