Commit f6b2b05b authored by Nicolas VANNIER's avatar Nicolas VANNIER Committed by Gerson SUNYE
Browse files

Fixes #894 #639 #614 #887 #859

parent 1c1c51f2
<?xml version="1.0" encoding="ASCII"?>
<java:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java" name="ArrayIsStoredDirectly">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Foo">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
<modifier visibility="private"/>
<type type="//@orphanTypes.9"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="x" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@expression/@leftHandSide/@field"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="foo">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// Don't do this, make a copy of the array at least" prefixOfParent="true"/>
<expression xsi:type="java:Assignment" originalCompilationUnit="//@compilationUnits.0">
<leftHandSide xsi:type="java:FieldAccess" originalCompilationUnit="//@compilationUnits.0">
<field variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@fragments.0"/>
<expression xsi:type="java:ThisExpression" originalCompilationUnit="//@compilationUnits.0"/>
</leftHandSide>
<rightHandSide xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.0"/>
</expression>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="param" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@expression/@rightHandSide">
<modifier/>
<type type="//@orphanTypes.9"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@orphanTypes.9/@elementType">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.2"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int"/>
<orphanTypes xsi:type="java:PrimitiveTypeLong" name="long"/>
<orphanTypes xsi:type="java:PrimitiveTypeFloat" name="float"/>
<orphanTypes xsi:type="java:PrimitiveTypeDouble" name="double"/>
<orphanTypes xsi:type="java:PrimitiveTypeBoolean" name="boolean"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<orphanTypes xsi:type="java:ArrayType" name="java.lang.String[]" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@parameters.0/@type" dimensions="1">
<elementType type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</orphanTypes>
<compilationUnits name="Foo.java" originalFilePath="C:\Users\vanni\eclipse-workspace\ArrayIsStoredDirectly\src\Foo.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@body/@statements.0/@comments.0" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
<?xml version="1.0" encoding="ASCII"?>
<java:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java" name="AvoidInstantiatingObjectInLoops">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Main">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="main">
<modifier visibility="public" static="true"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ForStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="&lt;">
<rightOperand xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="10"/>
<leftOperand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@initializers.0/@fragments.0"/>
</expression>
<updaters xsi:type="java:PostfixExpression" originalCompilationUnit="//@compilationUnits.0">
<operand xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@initializers.0/@fragments.0"/>
</updaters>
<initializers xsi:type="java:VariableDeclarationExpression" originalCompilationUnit="//@compilationUnits.0">
<type type="//@orphanTypes.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="i" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@expression/@leftOperand //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@updaters.0/@operand">
<initializer xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="0"/>
</fragments>
<modifier/>
</initializers>
<body xsi:type="java:Block" originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:VariableDeclarationStatement" originalCompilationUnit="//@compilationUnits.0">
<type type="//@ownedElements.0/@ownedElements.1"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="f">
<initializer xsi:type="java:ClassInstanceCreation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.0/@ownedElements.1/@bodyDeclarations.0">
<type type="//@ownedElements.0/@ownedElements.1"/>
</initializer>
</fragments>
<modifier/>
</statements>
</body>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="args">
<modifier/>
<type type="//@orphanTypes.9"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.1" name="Foo" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@body/@statements.0/@type //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@body/@statements.0/@fragments.0/@initializer/@type">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:ConstructorDeclaration" name="Foo" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@body/@statements.0/@fragments.0/@initializer"/>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@orphanTypes.9/@elementType">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.2"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@initializers.0/@type"/>
<orphanTypes xsi:type="java:PrimitiveTypeLong" name="long"/>
<orphanTypes xsi:type="java:PrimitiveTypeFloat" name="float"/>
<orphanTypes xsi:type="java:PrimitiveTypeDouble" name="double"/>
<orphanTypes xsi:type="java:PrimitiveTypeBoolean" name="boolean"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<orphanTypes xsi:type="java:ArrayType" name="java.lang.String[]" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@parameters.0/@type" dimensions="1">
<elementType type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</orphanTypes>
<compilationUnits name="Main.java" originalFilePath="C:\Users\vanni\eclipse-workspace\AvoidInstantiatingObjectInLoops\src\Main.java" types="//@ownedElements.0/@ownedElements.0"/>
<compilationUnits name="Foo.java" originalFilePath="C:\Users\vanni\eclipse-workspace\AvoidInstantiatingObjectInLoops\src\Foo.java" types="//@ownedElements.0/@ownedElements.1"/>
</java:Model>
<?xml version="1.0" encoding="ASCII"?>
<java:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java" name="InefficientEmptyStringCheck">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Main">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="main">
<modifier visibility="public" static="true"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:VariableDeclarationStatement" originalCompilationUnit="//@compilationUnits.0">
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="str" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@expression/@leftOperand/@leftOperand/@expression/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@expression/@rightOperand/@expression/@expression">
<initializer xsi:type="java:StringLiteral" originalCompilationUnit="//@compilationUnits.0" escapedValue="&quot;test&quot;"/>
</fragments>
<modifier/>
</statements>
<statements xsi:type="java:IfStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="||">
<rightOperand xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0">
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@fragments.0"/>
</expression>
</rightOperand>
<leftOperand xsi:type="java:InfixExpression" originalCompilationUnit="//@compilationUnits.0" operator="==">
<rightOperand xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="0"/>
<leftOperand xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.1">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.0">
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@fragments.0"/>
</expression>
</leftOperand>
</leftOperand>
</expression>
<thenStatement xsi:type="java:Block" originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ExpressionStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:MethodInvocation" originalCompilationUnit="//@compilationUnits.0" method="//@ownedElements.1/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0">
<arguments xsi:type="java:StringLiteral" originalCompilationUnit="//@compilationUnits.0" escapedValue="&quot;string is empty&quot;"/>
<expression xsi:type="java:SingleVariableAccess" variable="//@ownedElements.1/@ownedPackages.0/@ownedElements.3/@bodyDeclarations.0/@fragments.0">
<qualifier xsi:type="java:TypeAccess" type="//@ownedElements.1/@ownedPackages.0/@ownedElements.3"/>
</expression>
</expression>
</statements>
</thenStatement>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="args">
<modifier/>
<type type="//@orphanTypes.9"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@orphanTypes.9/@elementType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@type //@ownedElements.1/@ownedPackages.1/@ownedElements.1/@bodyDeclarations.0/@parameters.0/@type">
<bodyDeclarations xsi:type="java:MethodDeclaration" name="trim" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@expression/@leftOperand/@leftOperand/@expression //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@expression/@rightOperand/@expression"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" name="length" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@expression/@leftOperand/@leftOperand"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" name="isEmpty" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@expression/@rightOperand"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.2"/>
<ownedElements xsi:type="java:ClassDeclaration" name="System" proxy="true" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@thenStatement/@statements.0/@expression/@expression/@qualifier">
<bodyDeclarations xsi:type="java:FieldDeclaration" proxy="true">
<fragments name="out" proxy="true" usageInVariableAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@thenStatement/@statements.0/@expression/@expression"/>
</bodyDeclarations>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="AutoCloseable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.4/@superInterfaces.0"/>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Appendable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.1/@superInterfaces.0"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
<ownedElements xsi:type="java:ClassDeclaration" name="PrintStream" proxy="true">
<bodyDeclarations xsi:type="java:MethodDeclaration" name="println" proxy="true" usages="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.1/@thenStatement/@statements.0/@expression">
<parameters name="arg0" proxy="true">
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</parameters>
</bodyDeclarations>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.5"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.4"/>
<superClass type="//@ownedElements.1/@ownedPackages.1/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="FilterOutputStream" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.1/@superClass">
<superClass type="//@ownedElements.1/@ownedPackages.1/@ownedElements.3"/>
</ownedElements>
<ownedElements xsi:type="java:ClassDeclaration" name="OutputStream" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.2/@superClass">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.4"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.5"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Closeable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.3/@superInterfaces.0 //@ownedElements.1/@ownedPackages.1/@ownedElements.1/@superInterfaces.1">
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.4"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Flushable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.1/@ownedElements.3/@superInterfaces.1"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int"/>
<orphanTypes xsi:type="java:PrimitiveTypeLong" name="long"/>
<orphanTypes xsi:type="java:PrimitiveTypeFloat" name="float"/>
<orphanTypes xsi:type="java:PrimitiveTypeDouble" name="double"/>
<orphanTypes xsi:type="java:PrimitiveTypeBoolean" name="boolean"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<orphanTypes xsi:type="java:ArrayType" name="java.lang.String[]" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@parameters.0/@type" dimensions="1">
<elementType type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</orphanTypes>
<compilationUnits name="Main.java" originalFilePath="C:\Users\vanni\eclipse-workspace\InefficientEmptyStringCheck\src\Main.java" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
<?xml version="1.0" encoding="ASCII"?>
<java:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java" name="OneDeclarationPerLine">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Main">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="main">
<modifier visibility="public" static="true"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:VariableDeclarationStatement" originalCompilationUnit="//@compilationUnits.0">
<type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="name"/>
<fragments originalCompilationUnit="//@compilationUnits.0" name="lastname"/>
<modifier/>
</statements>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="args">
<modifier/>
<type type="//@orphanTypes.9"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@orphanTypes.9/@elementType //@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@statements.0/@type">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.2"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int"/>
<orphanTypes xsi:type="java:PrimitiveTypeLong" name="long"/>
<orphanTypes xsi:type="java:PrimitiveTypeFloat" name="float"/>
<orphanTypes xsi:type="java:PrimitiveTypeDouble" name="double"/>
<orphanTypes xsi:type="java:PrimitiveTypeBoolean" name="boolean"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<orphanTypes xsi:type="java:ArrayType" name="java.lang.String[]" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@parameters.0/@type" dimensions="1">
<elementType type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</orphanTypes>
<compilationUnits name="Main.java" originalFilePath="C:\Users\vanni\eclipse-workspace\OneDeclarationPerLine\src\Main.java" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
<?xml version="1.0" encoding="ASCII"?>
<java:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java" name="SuspiciousHashcodeMethodName">
<ownedElements name="(default package)">
<ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Main">
<modifier visibility="public"/>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="main">
<modifier visibility="public" static="true"/>
<body originalCompilationUnit="//@compilationUnits.0">
<comments xsi:type="java:LineComment" originalCompilationUnit="//@compilationUnits.0" content="// TODO Auto-generated method stub" enclosedByParent="true"/>
</body>
<parameters originalCompilationUnit="//@compilationUnits.0" name="args">
<modifier/>
<type type="//@orphanTypes.9"/>
</parameters>
<returnType type="//@orphanTypes.5"/>
</bodyDeclarations>
<bodyDeclarations xsi:type="java:MethodDeclaration" originalCompilationUnit="//@compilationUnits.0" name="hashcode">
<modifier visibility="public"/>
<body originalCompilationUnit="//@compilationUnits.0">
<statements xsi:type="java:ReturnStatement" originalCompilationUnit="//@compilationUnits.0">
<expression xsi:type="java:NumberLiteral" originalCompilationUnit="//@compilationUnits.0" tokenValue="0"/>
</statements>
</body>
<returnType type="//@orphanTypes.0"/>
</bodyDeclarations>
</ownedElements>
</ownedElements>
<ownedElements name="java" proxy="true">
<ownedPackages name="lang" proxy="true">
<ownedElements xsi:type="java:ClassDeclaration" name="String" proxy="true" usagesInTypeAccess="//@orphanTypes.9/@elementType">
<superInterfaces type="//@ownedElements.1/@ownedPackages.1/@ownedElements.0"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.1"/>
<superInterfaces type="//@ownedElements.1/@ownedPackages.0/@ownedElements.2"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="Comparable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.1">
<typeParameters name="T" proxy="true"/>
</ownedElements>
<ownedElements xsi:type="java:InterfaceDeclaration" name="CharSequence" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.2"/>
</ownedPackages>
<ownedPackages name="io" proxy="true">
<ownedElements xsi:type="java:InterfaceDeclaration" name="Serializable" proxy="true" usagesInTypeAccess="//@ownedElements.1/@ownedPackages.0/@ownedElements.0/@superInterfaces.0"/>
</ownedPackages>
</ownedElements>
<orphanTypes xsi:type="java:PrimitiveTypeInt" name="int" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.1/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeLong" name="long"/>
<orphanTypes xsi:type="java:PrimitiveTypeFloat" name="float"/>
<orphanTypes xsi:type="java:PrimitiveTypeDouble" name="double"/>
<orphanTypes xsi:type="java:PrimitiveTypeBoolean" name="boolean"/>
<orphanTypes xsi:type="java:PrimitiveTypeVoid" name="void" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@returnType"/>
<orphanTypes xsi:type="java:PrimitiveTypeChar" name="char"/>
<orphanTypes xsi:type="java:PrimitiveTypeShort" name="short"/>
<orphanTypes xsi:type="java:PrimitiveTypeByte" name="byte"/>
<orphanTypes xsi:type="java:ArrayType" name="java.lang.String[]" usagesInTypeAccess="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@parameters.0/@type" dimensions="1">
<elementType type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
</orphanTypes>
<compilationUnits name="Main.java" originalFilePath="C:\Users\vanni\eclipse-workspace\SuspiciousHashcodeMethodName\src\Main.java" commentList="//@ownedElements.0/@ownedElements.0/@bodyDeclarations.0/@body/@comments.0" types="//@ownedElements.0/@ownedElements.0"/>
</java:Model>
...@@ -79,10 +79,13 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) = ...@@ -79,10 +79,13 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
-- Performance rules -- Performance rules
-- --
thisModule.addEmptyString(), thisModule.addEmptyString(),
thisModule.avoidInstantiatingObjectsInLoops(),
thisModule.avoidPrintStackTrace(), thisModule.avoidPrintStackTrace(),
thisModule.avoidRethrowingException(), thisModule.avoidRethrowingException(),
thisModule.avoidUsingShortType(), thisModule.avoidUsingShortType(),
thisModule.emptyStatementBlock(), thisModule.emptyStatementBlock(),
thisModule.inefficientEmptyStringCheck(),
thisModule.inefficientEmptyStringCheck2(),
-- #FIXME: -- #FIXME:
-- thisModule.insufficientStringBufferDeclaration(), -- thisModule.insufficientStringBufferDeclaration(),
thisModule.integerInstantiation(), thisModule.integerInstantiation(),
...@@ -122,14 +125,17 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) = ...@@ -122,14 +125,17 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.missingBreakInSwitch(), thisModule.missingBreakInSwitch(),
thisModule.nullAssignment(), thisModule.nullAssignment(),
thisModule.suspiciousEqualsMethodName(), thisModule.suspiciousEqualsMethodName(),
thisModule.suspiciousHashcodeMethodName(),
thisModule.testClassWithoutTest(), thisModule.testClassWithoutTest(),
thisModule.UnconditionalIfStatement(), thisModule.UnconditionalIfStatement(),
thisModule.UseProperClassLoader(), thisModule.UseProperClassLoader(),
-- Best practices rules -- Best practices rules
thisModule.arrayIsStoredDirectly(),
thisModule.avoidReassigningParameters(), thisModule.avoidReassigningParameters(),
thisModule.avoidStringBufferField(), thisModule.avoidStringBufferField(),
thisModule.forLoopVariableCount(), thisModule.forLoopVariableCount(),
thisModule.oneDeclarationPerLine(),
thisModule.switchDensity(), thisModule.switchDensity(),
thisModule.useAssertSameInsteadOfAssertTrue(), thisModule.useAssertSameInsteadOfAssertTrue(),
thisModule.useAssertTrueInsteadOfAssertEquals() thisModule.useAssertTrueInsteadOfAssertEquals()
...@@ -198,6 +204,26 @@ rule MeasureAbstractClassWithoutAnyMethod(i : java!ClassDeclaration) { ...@@ -198,6 +204,26 @@ rule MeasureAbstractClassWithoutAnyMethod(i : java!ClassDeclaration) {
} }
} }
-- ------------------------------------------- ArrayIsStoredDirectly ---------------------------------------------
--- creates a measure when an array parameter of a method is directly used as a reference instead of storing it first
rule MeasureArrayIsStoredDirectly(s: java!MethodDeclaration){
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'ArrayIsStoredDirectly',
shortDescription <- 'Constructors and methods receiving arrays should clone objects and store the copy'
),
measurement: smm!DirectMeasurement (
error <- s.name + ' has an array parameter that is not cloned before use'
)
do {
noc;
}
}
-- ------------------------------------------- AvoidCallingFinalize --------------------------------------------- -- ------------------------------------------- AvoidCallingFinalize ---------------------------------------------
--- A Measure instance if the class violates the rule LongVariable. --- A Measure instance if the class violates the rule LongVariable.
rule MeasureAvoidCallingFinalize(methode : java!MethodInvocation) { rule MeasureAvoidCallingFinalize(methode : java!MethodInvocation) {
...@@ -278,6 +304,26 @@ rule MeasureAvoidEnumAsIdentifier(w: java!VariableDeclaration) { ...@@ -278,6 +304,26 @@ rule MeasureAvoidEnumAsIdentifier(w: java!VariableDeclaration) {
} }
} }
-- ------------------------------------------- AvoidInstantiatingObjectInLoops ---------------------------------------------
--- creates a measure when an object is instantiated in a loop
rule MeasureAvoidInstantiatingObjectInLoops(s: java!Statement){
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'AvoidInstantiatingObjectsInLoops',
shortDescription <- 'New objects created within loops should be checked to see if they can created outside them and reused'
),
measurement: smm!DirectMeasurement (
error <- s.originalCompilationUnit.name + ' has a loop with object instantiation inside'
)
do {
noc;
}
}
-- ----------------------------------------- AvoidPrefixingMethodParameters---------------------------------------------- -- ----------------------------------------- AvoidPrefixingMethodParameters----------------------------------------------
--- A Measure instance if the class violates the rule AvoidPrefixingMethodParameters. --- A Measure instance if the class violates the rule AvoidPrefixingMethodParameters.
rule MeasureAvoidPrefixingMethodParameters(method: java!MethodDeclaration) { rule MeasureAvoidPrefixingMethodParameters(method: java!MethodDeclaration) {
...@@ -1049,6 +1095,26 @@ rule MeasureImportFromSamePackage(import : java!ImportDeclaration) { ...@@ -1049,6 +1095,26 @@ rule MeasureImportFromSamePackage(import : java!ImportDeclaration) {
} }
} }
-- ----------------------------------------- InefficientEmptyStringCheck ----------------------------------------------
--- creates a measure when String.trim().isEmpty() is used to check if a string is empty
rule MeasureInefficientEmptyStringCheck(mi: java!Expression){
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'InefficientEmptyStringCheck',
shortDescription <- 'Inefficient way to check if a String is really blank as it creates a new String object just to check its size.'
),
measurement: smm!DirectMeasurement (
error <- mi.originalCompilationUnit.name + ' has an inefficient empty string check'
)
do {
noc;
}
}
--- insufficientStringBufferDeclaration --- insufficientStringBufferDeclaration
--- #FIXME: Add comment --- #FIXME: Add comment
rule MeasureInsufficientStringBufferDeclaration(w: java!CompilationUnit) { rule MeasureInsufficientStringBufferDeclaration(w: java!CompilationUnit) {
...@@ -1171,6 +1237,26 @@ rule MeasureMisLeadingVariableName(variable :java!VariableDeclarationFragment) { ...@@ -1171,6 +1237,26 @@ rule MeasureMisLeadingVariableName(variable :java!VariableDeclarationFragment) {
} }
} }
-- ----------------------------------------- OneDeclarationPerLine ----------------------------------------------
--- creates a measure when several variables are declared on the same line
rule MeasureOneDeclarationPerLine(s: java!VariableDeclarationStatement){
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'OneDeclarationPerLine',
shortDescription <- 'Java allows the use of several variables declaration on one line, however it can lead to quite messy code.'
),
measurement: smm!DirectMeasurement (
error <- s.originalCompilationUnit.name + ' has more than one variable declaration per line.'
)
do {
noc;
}
}
-- ------------------------------------------- ShortInstantiation --------------------------------------------- -- ------------------------------------------- ShortInstantiation ---------------------------------------------
--- A Measure instance if the class violates the rule 'ShortInstantiation'. --- A Measure instance if the class violates the rule 'ShortInstantiation'.
rule MeasureShortInstantiation(variable : java!CompilationUnit) { rule MeasureShortInstantiation(variable : java!CompilationUnit) {
...@@ -1292,6 +1378,26 @@ rule MeasureSuspiciousEqualsMethodName(method : java!MethodDeclaration) { ...@@ -1292,6 +1378,26 @@ rule MeasureSuspiciousEqualsMethodName(method : java!MethodDeclaration) {
} }
} }
-- ------------------------------------------- SuspiciousHashcodeMethodName ---------------------------------------------
--- creates a measure when a method name is close to "hashCode" but not equal to "hashCode"
rule MeasureSuspiciousHashcodeMethodName(s: java!MethodDeclaration){
to
om: smm!ObservedMeasure (
measure <- noc,
measurements <- measurement
),
noc: smm!DimensionalMeasure (
name <- 'SuspiciousHashcodeMethodName',
shortDescription <- 'The method name and return type are suspiciously close to hashCode(), which may denote an intention to override the hashCode() method'
),
measurement: smm!DirectMeasurement (
error <- s.name + ' has a suspicously close name to hashCode()'
)
do {
noc;
}
}
-- ------------------------------------------- SwitchDensity --------------------------------------------- -- ------------------------------------------- SwitchDensity ---------------------------------------------
--- A Measure instance if the class violates the rule SwitchDensity. --- A Measure instance if the class violates the rule SwitchDensity.
rule MeasureSwitchDensity(switch : java!SwitchStatement) { rule MeasureSwitchDensity(switch : java!SwitchStatement) {
......
...@@ -140,4 +140,26 @@ helper def: avoidReassigningParameters(): Set(smm!Measure) = ...@@ -140,4 +140,26 @@ helper def: avoidReassigningParameters(): Set(smm!Measure) =
thisModule.MeasureAvoidReassigningParameters(assignment) thisModule.MeasureAvoidReassigningParameters(assignment)
) )
)->flatten(); )->flatten();
\ No newline at end of file
--------------------------------------------- OneDeclarationPerLine ---------------------------------------------
helper def: oneDeclarationPerLine(): Set(smm!Measure) =
java!VariableDeclarationStatement.allInstances()
->select(s | s.fragments.size()>1)
->collect(s | thisModule.MeasureOneDeclarationPerLine(s));
--------------------------------------------- ArrayIsStoredDirectly ---------------------------------------------
helper def: arrayIsStoredDirectly(): Set(smm!Measure) =
java!MethodDeclaration.allInstances()
->select( md | md.parameters.size()>0)
->select( md | md.parameters->exists(p | p.type.type.oclIsTypeOf(java!ArrayType)))
->select( md | md.parameters
->exists(p | p.methodDeclaration.body.statements
->select(s | s.oclIsTypeOf(java!ExpressionStatement))
->select(s | s.expression.oclIsTypeOf(java!Assignment))
->exists(s | s.expression.rightHandSide.variable.name = p.name)
)
)
->collect(md | thisModule.MeasureArrayIsStoredDirectly(md));
\ No newline at end of file
...@@ -433,4 +433,12 @@ helper context java!CompilationUnit def: hasJunitAnnotation() : Boolean = ...@@ -433,4 +433,12 @@ helper context java!CompilationUnit def: hasJunitAnnotation() : Boolean =