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
27803354
Commit
27803354
authored
Dec 23, 2019
by
Gerson SUNYE
Browse files
Merge branch 'master' into 'master'
Fix
#908
UseArraysAsList Closes
#908
See merge request
!167
parents
3db4ddec
b399a8a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/atl/analysis.atl
View file @
27803354
...
...
@@ -94,7 +94,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- thisModule.startsWith(),
thisModule.stringToString(),
thisModule.tooFewBranchesForASwitchStatement(),
-- #FIXME:
thisModule.useArraysAsList(),
thisModule.useArraysAsList(),
thisModule.useIndexOfChar(),
thisModule.uselessStringValueOf(),
...
...
@@ -1523,7 +1523,7 @@ rule MeasureUnnecessaryReturn(state : java!ReturnStatement) {
}
-- ----------------------------------------- UseArraysAsList ------------------------------------------------------------------------------------
--
#TODO: Add comment
--
- A measure triggered when a For loop is used to fill a List with values of an array[] instead of using List = Arrays.asList(array[]).
rule MeasureUseArraysAsList(w: java!CompilationUnit) {
to
om: smm!ObservedMeasure (
...
...
src/main/atl/performance.atl
View file @
27803354
...
...
@@ -188,17 +188,35 @@ helper def: tooFewBranchesForASwitchStatement(): Set(smm!Measure) =
--- UseArraysAsList
helper def: useArraysAsList() : Set(smm!Measure) =
java!ForStatement.allInstances()
->select(st | st.body.oclIsTypeOf(java!Block))
->select(st | st.body.statements.size() = 1)
->select(st | st.body.statements.get(0).oclIsTypeOf(java!ExpressionStatement))
->select(st | st.body.statements.get(0).expression.oclIsTypeOf(java!MethodInvocation))
->select(st | st.body.statements.get(0).expression.method.name = 'add')
->select(st | not st.body.statements.get(0).expression.method.abstractTypeDeclaration.oclIsUndefined())
->select(st | st.body.statements.get(0).expression.method.abstractTypeDeclaration.name = 'Collection'
or st.body.statements.get(0).expression.method.abstractTypeDeclaration.name = 'List'
or st.body.statements.get(0).expression.method.abstractTypeDeclaration.name = 'ArrayList')
->select(st | st.body.statements.get(0).expression.expression.variable.initializer.type.type.type.type.name = 'ArrayList')
->select(st | not st.body.statements.get(0).expression.expression.oclIsUndefined())
->select(st | st.body.statements.get(0).expression.expression.oclIsTypeOf(java!SingleVariableAccess))
->select(st | not st.body.statements.get(0).expression.expression.variable.initializer.oclIsUndefined())
->select(st | st.body.statements.get(0).expression.expression.variable.initializer.oclIsTypeOf(java!ClassInstanceCreation))
->select(st | st.body.statements.get(0).expression.expression.variable.initializer.type.type.getTypeName() = 'ArrayList')
->select(st | st.body.statements.get(0).expression.arguments.size() = 1
and st.body.statements.get(0).expression.arguments.get(0).oclIsTypeOf(java!ArrayAccess))
->select(st | st.body.statements.get(0).expression.arguments.get(0).array.oclIsTypeOf(java!SingleVariableAccess))
->select(st | st.body.statements.get(0).expression.arguments.get(0).array.variable.oclIsTypeOf(java!SingleVariableDeclaration))
->select(st | st.body.statements.get(0).expression.arguments.get(0).array.variable.type.type.oclIsTypeOf(java!ArrayType))
->collect(st | thisModule.MeasureUseArraysAsList(st.originalCompilationUnit))
;
->collect(st | thisModule.MeasureUseArraysAsList(st.originalCompilationUnit));
helper context java!ParameterizedType def: getTypeName() : String =
self.type.type.name;
helper context java!TypeAccess def: getTypeName() : String =
self.type.name;
helper context java!ClassDeclaration def: getTypeName() : String =
self.name;
--- Use ArrayList Instead Of Vector
helper def: UseArrayListInsteadOfVector() : Set(smm!Measure) =
...
...
@@ -231,4 +249,4 @@ helper def: uselessStringValueOf() : Set(smm!Measure) =
-> select (m | m.method.name='valueOf' )
-> select (m | m.refImmediateComposite().oclIsTypeOf(java!InfixExpression))
-> collect (m | thisModule.MeasureUselessStringValueOf(m))
;
\ No newline at end of file
;
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