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
Roxane MARECHAL
Source Code Analyzer
Commits
4864b383
Commit
4864b383
authored
Dec 22, 2019
by
Roxane Kang Maréchal
Browse files
Merge remote-tracking branch 'upstream/master'
parents
1500a413
d909aaff
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
src/main/atl/analysis.atl
View file @
4864b383
...
...
@@ -79,7 +79,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Performance rules
--
thisModule.addEmptyString(),
thisModule.avoidInstantiatingObjectsInLoops(),
-- #FIXME:
thisModule.avoidInstantiatingObjectsInLoops(),
thisModule.avoidPrintStackTrace(),
thisModule.avoidRethrowingException(),
thisModule.avoidUsingShortType(),
...
...
@@ -91,6 +91,7 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.integerInstantiation(),
-- #FIXME:
-- thisModule.startsWith(),
thisModule.stringToString(),
thisModule.tooFewBranchesForASwitchStatement(),
-- #FIXME: thisModule.useArraysAsList(),
thisModule.useIndexOfChar(),
...
...
@@ -131,12 +132,13 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.UseProperClassLoader(),
-- Best practices rules
thisModule.arrayIsStoredDirectly(),
-- #FIXME:
thisModule.arrayIsStoredDirectly(),
thisModule.avoidReassigningParameters(),
thisModule.avoidStringBufferField(),
thisModule.forLoopVariableCount(),
thisModule.oneDeclarationPerLine(),
thisModule.switchDensity(),
-- #FIXME: thisModule.unusedLocalVariable(),
thisModule.useAssertSameInsteadOfAssertTrue(),
thisModule.useAssertTrueInsteadOfAssertEquals()
...
...
@@ -151,7 +153,6 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- thisModule.replaceVectorToList()
-- thisModule.unusedPrivateMethod ()
-- thisModule.avoidThrowingNewInstanceOfSameException(),
-- thisModule.stringToString(),
-- thisModule.methodWithSameNameAsEnclosingClass(),
-- thisModule.dontUseFloatTypeForLoopIndices(),
-- thisModule.methodWithSameNameAsEnclosingClass(),
...
...
@@ -1892,6 +1893,25 @@ rule MesureShortVariableName(variable : java!VariableDeclaration) {
}
}
--- Creates a new Measure when the method toString() is unnecessarily invoked.
rule MeasureStringToString(method : java!MethodInvocation) {
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'StringToString',
shortDescription <- 'Avoid calling toString() on objects already known to be string instances; this is unnecessary.'
),
measurement: smm!DirectMeasurement (
error <- 'The Object ' + method.expression.variable.name + ' is already a String in ' + method.originalCompilationUnit.name
)
do {
noc;
}
}
--- A Measure instance if the class violates the rule 'TooManyFields'.
-- #FIXME: Typo
rule MesureTooManyFields(class : java!ClassDeclaration) {
...
...
@@ -1954,6 +1974,25 @@ rule MesureTooManyStaticImports(class : java!CompilationUnit) {
}
}
----------------------------------------- UnusedLocalVariable ------------------------------------------------------
--- Creates a measure when a local variable is declared but not used
rule MeasureUnusedLocalVariable(var : java!VariableDeclarationFragment){
to
om: smm!ObservedMeasure (
measure <- unusedLocalVariable,
measurements <- unusedLocalVariable
),
unusedLocalVariable: smm!DimensionalMeasure(
name <- 'UnusedLocalVariable',
shortDescription <- 'Detects when a local variable is declared and/or assigned, but not used'
)
do {
unusedLocalVariable;
}
}
-------------------------------------------UseAssertSameInsteadOfAssertTrue----------------------------------------------
--- A Measure instance if the class violate the rule AssertSameInsteadOfAssertTrue
-- #FIXME: Typo
...
...
@@ -2023,7 +2062,6 @@ rule numberOfClasses() {
}
}
-- Auxiliary helpers:
--- Returns the number of branches in the switch statement passed in parameter
...
...
@@ -2080,8 +2118,4 @@ helper context java!FieldDeclaration def: getBodyDeclarationName() : String =
-- ATTENTION !!!
-- Before adding a new rule in the end of the file, remember that rules respect an alphabetical order.
-- Before adding a new rule in the end of the file, remember that rules respect an alphabetical order.
\ No newline at end of file
src/main/atl/bestPractices.atl
View file @
4864b383
...
...
@@ -145,6 +145,14 @@ helper def: switchDensity() : Set (smm!Measure) =
->collect(switchStatement | thisModule.MeasureSwitchDensity(switchCase))
);
--- Rule for metrics UnusedLocalVariable :
helper def: unusedLocalVariable(): Set(ssm!Measures) =
java!VariableDeclarationFragment.allInstances()
-> select(variable | variable.originalCompilationUnit.name = 'LocalVariable.java')
-> select(variable | variable.usageInVariableAccess.isEmpty())
-> collect(variable | thisModule.MeasureUnusedLocalVariable(variable))
;
-- #TODO: Add comment
helper def: useAssertSameInsteadOfAssertTrue() : Set(smm!Measure) =
-- Browse through all methods use
...
...
@@ -165,6 +173,7 @@ helper def: useAssertTrueInsteadOfAssertEquals() : Set(smm!Measure) =
-- Attention !!!
-- Before adding a rule to the end of file, ensure that you are respecting the
-- alphabetical order for rule declarations.
src/main/atl/performance.atl
View file @
4864b383
This diff is collapsed.
Click to expand it.
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